[Astpp-commit] SF.net SVN: astpp:[2274] trunk/freeswitch/astpp-fs-xml.pl
Brought to you by:
darrenkw
|
From: <dar...@us...> - 2009-10-04 20:17:15
|
Revision: 2274
http://astpp.svn.sourceforge.net/astpp/?rev=2274&view=rev
Author: darrenkw
Date: 2009-10-04 20:16:28 +0000 (Sun, 04 Oct 2009)
Log Message:
-----------
Merge astpp-fs-cdr-xml.pl into astpp-fs-xml.pl.
Modified Paths:
--------------
trunk/freeswitch/astpp-fs-xml.pl
Modified: trunk/freeswitch/astpp-fs-xml.pl
===================================================================
--- trunk/freeswitch/astpp-fs-xml.pl 2009-10-03 05:17:07 UTC (rev 2273)
+++ trunk/freeswitch/astpp-fs-xml.pl 2009-10-04 20:16:28 UTC (rev 2274)
@@ -38,6 +38,7 @@
$config = &load_config_db( $astpp_db, $config ) if $astpp_db;
$freeswitch_db = &connect_freeswitch_db( $config, @output );
$ASTPP->set_freeswitch_db($freeswitch_db);
+ $config->{cdr_table} = $config->{freeswitch_cdr_table};
}
################# Programs start here #######################################
@@ -302,5 +303,206 @@
}
$ASTPP->debug( debug => $xml );
print $xml;
+} elsif ( $params->{cdr} ) {
+
+# create object
+my $xml = new XML::Simple;
+
+# read XML file
+my $data = $xml->XMLin($params->{cdr});
+
+# print output
+print STDERR Dumper($data);
+
+
+my $tmp = "INSERT INTO " . $config->{freeswitch_cdr_table} . "(accountcode,src,dst,dcontext,clid,channel,dstchannel,lastapp,"
+ . "lastdata,calldate,answerdate,enddate,duration,billsec,disposition,amaflags,uniqueid,userfield,read_codec,"
+ . "write_codec,cost,vendor,provider,trunk,outbound_route,progressmsec,answermsec,progress_mediamsec) VALUES ("
+ . "'"
+ . $data->{variables}->{accountcode}
+ . "'"
+ . ","
+ . "'"
+ . $data->{callflow}->{caller_profile}->{username}
+ . "'"
+ . ","
+# . $cdr_db->quote($data->{callflow}->{caller_profile}->{originatee}->{originatee_caller_profile}->{destination_number})
+ . "'"
+ . $data->{callflow}->{caller_profile}->{destination_number}
+ . "'"
+ . ","
+# . $cdr_db->quote($data->{callflow}->{caller_profile}->{originatee}->{originatee_caller_profile}->{context})
+ . "'"
+ . $data->{callflow}->{caller_profile}->{context}
+ . "'"
+ . ","
+ . "'"
+ . uri_unescape($data->{variables}->{caller_id})
+ . "'"
+# . "\"" . $cdr_db->quote($data->{callflow}->{caller_profile}->{originatee}->{originatee_caller_profile}->{caller_id_name}) . "\""
+# . "<" . $cdr_db->quote($data->{callflow}->{caller_profile}->{originatee}->{originatee_caller_profile}->{caller_id_number}) . ">"
+# . "\"" . $data->{callflow}->{caller_profile}->{caller_id_name} . "\""
+# . "<" . $data->{callflow}->{caller_profile}->{caller_id_number} . ">"
+ . ","
+ . "'"
+ . uri_unescape($data->{variables}->{channel_name})
+ . "'"
+ . ","
+ . "''"
+ . ","
+ . "'" . $data->{variables}->{last_app} . "'"
+ . ","
+ . "'" . uri_unescape($data->{variables}->{last_arg}) . "'"
+ . ","
+ . "'"
+ . uri_unescape($data->{variables}->{start_stamp})
+ . "'"
+ . ","
+ . "'" . uri_unescape($data->{variables}->{answer_stamp}) . "'"
+ . ","
+ . "'"
+ . uri_unescape($data->{variables}->{end_stamp})
+ . "'"
+ . ","
+ . "'"
+ . $data->{variables}->{duration}
+ . "'"
+ . ","
+ . "'"
+ . $data->{variables}->{billsec}
+ . "'"
+ . ","
+ . "'"
+ . $data->{variables}->{hangup_cause}
+ . "'"
+ . ","
+ . "''"
+ . ","
+ . "'"
+ . $data->{callflow}->{caller_profile}->{uuid}
+ . "'"
+ . ","
+ . "''"
+ . ","
+ . "'" . $data->{variables}->{read_code} . "'"
+ . ","
+ . "'" . $data->{variables}->{write_code} . "'"
+ . ",'none','none'"
+ . ","
+ . "'" . $data->{variables}->{provider} . "'"
+ . ","
+ . "'" . $data->{variables}->{trunk} . "'"
+ . ","
+ . "'" . $data->{variables}->{outbound_route} . "'"
+ . ","
+ . "'" . $data->{variables}->{progressmsec} . "'"
+ . ","
+ . "'" . $data->{variables}->{answermsec} . "'"
+ . ","
+ . "'" . $data->{variables}->{progress_mediamsec} . "'"
+ . ")";
+
+print STDERR "\n" . $tmp . "\n";
+$cdr_db->do($tmp);
+print "Wrote CDR";
+my (@chargelist);
+push @chargelist, $data->{callflow}->{caller_profile}->{uuid};
+&processlist( $astpp_db, $cdr_db, $config, \@chargelist );
+print STDERR "VENDOR CHARGES: " . $config->{trackvendorcharges} . "\n";
+&vendor_process_rating_fs( $astpp_db, $cdr_db, $config, "none", $data->{callflow}->{caller_profile}->{uuid},"" ) if $config->{trackvendorcharges} == 1;
+
+&process_callingcard_cdr if $data->{variables}->{callingcard};
+
+sub process_callingcard_cdr() {
+ my ( $cardinfo, $brandinfo, $numberinfo, $pricelistinfo,$cc );
+ my $destination = $data->{callflow}->{caller_profile}->{destination_number};
+ $destination =~ s/@.*//g;
+ my $cardnumber = $data->{variables}->{callingcard};
+ $cardinfo = &get_callingcard( $astpp_db, $cardnumber, $config );
+ if ( !$cardinfo ) {
+ $cardinfo = &get_account_cc( $astpp_db, $cardnumber );
+ $cc = 1 if $cardinfo;
+ }
+ $brandinfo = &get_cc_brand( $astpp_db, $cardinfo->{brand} ) if $cc == 0;
+ if ($brandinfo->{reseller}) {
+ $config = &load_config_db_reseller($astpp_db,$config,$brandinfo->{reseller});
+ }
+ $config = &load_config_db_brand($astpp_db,$config,$cardinfo->{brand});
+ $pricelistinfo = &get_pricelist( $astpp_db, $brandinfo->{pricelist} )
+ if $cc == 0;
+ $pricelistinfo = &get_pricelist( $astpp_db, $cardinfo->{pricelist} )
+ if $cc == 1;
+
+ print STDERR "THIS IS A CALLINGCARD CALL! \n";
+ print STDERR "CARD: $cardinfo->{cardnumber} \n";
+ print STDERR "CARD: $cardnumber \n";
+ $numberinfo = &get_route(
+ $astpp_db, $config,
+ $destination,
+ $brandinfo->{pricelist}, $cardinfo
+ );
+ if ( $data->{variables}->{billsec} > 0 )
+ {
+ $ASTPP->debug(
+ debug => "CALL ANSWERED",
+ verbosity => $verbosity
+ );
+ my $increment;
+ if ( $numberinfo->{inc} > 0 ) {
+ $increment = $numberinfo->{inc};
+ }
+ else {
+ $increment = $pricelistinfo->{inc};
+ }
+ $ASTPP->debug(
+ debug =>
+"$numberinfo->{connectcost}, $numberinfo->{cost}, $data->{variables}->{billsec}, $increment, $numberinfo->{includedseconds}",
+ verbosity => $verbosity
+ );
+ my $charge = &calc_call_cost(
+ $numberinfo->{connectcost},
+ $numberinfo->{cost},
+ $data->{variables}->{billsec},
+ $increment,
+ $numberinfo->{includedseconds}
+ );
+ $ASTPP->debug(
+ debug => "Cost $charge ",
+ verbosity => $verbosity
+ );
+ if ( $cardinfo->{minute_fee_pennies} > 0 ) {
+ $charge =
+ ( ( $cardinfo->{minute_fee_pennies} * 100 ) +
+ $charge )
+ if $cardinfo->{timeused} +
+ $data->{variables}->{billsec} =>
+ $cardinfo->{minute_fee_minutes};
+ }
+ if ( $cardinfo->{min_length_pennies} > 0
+ && ( $cardinfo->{min_length_minutes} * 60 ) >
+ $data->{variables}->{billsec} )
+ {
+ $charge =
+ ( ( $cardinfo->{min_length_pennies} * 100 ) +
+ $charge );
+ }
+ print STDERR "CARDNUMBER: " . $cardinfo->{cardnumber};
+ &write_callingcard_cdr(
+ $astpp_db,
+ $config,
+ $cardinfo,
+ uri_unescape($data->{variables}->{caller_id}),
+ $destination,
+ uri_unescape($data->{variables}->{hangup_cause}),
+ uri_unescape($data->{variables}->{start_stamp}),
+ $charge,
+ $data->{variables}->{billsec}
+ );
+ &callingcard_set_in_use($astpp_db,$cardinfo,0);
+ &callingcard_update_balance($astpp_db,$cardinfo,$charge);
+ }
+ }
+
+
}
exit(0);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|