[Freeswitch-users] Cookbook example

Miha miha at softnet.si
Tue Apr 10 11:20:12 MSD 2012


I need a little help. I am trying to use example for inserting XML to 
mysql cdrtable. I have add id before caller_id_name as I need Id in 
mysql table. Problem is that I am getting random numbers in ID field, 
sometimes values for ID are the same, so sql perl script return error 
and values are not inserted.

Can you help me how can I modify so that this will work properly.

use strict;
use warnings;
use CGI;
use DBI;
use Data::Dump qw(dump);
my $q = CGI->new;
my $raw_cdr = $q->param('cdr');

my @all_fields = qw(id caller_id_name caller_id_number
destination_number context start_stamp answer_stamp end_stamp
duration billsec hangup_cause uuid bleg_uuid
accountcode domain_name);
my @fields;
my @values;
foreach my $field (@all_fields) {
next unless $raw_cdr =~ m/$field>(.*?)</;
push @fields, $field;
push @values, "'" . urldecode($1) . "'";
my $cdr_line;
my $query = sprintf(
"INSERT INTO %s (%s) VALUES (%s);",
'radacct_1', join(',', @fields), join(',', @values)
my $db = 
print $q->header();
sub urldecode {
my $url = shift;
$url =~ s/%([a-fA-F0-9]{2,2})/chr(hex($1))/eg;
return $url;
[root at fs1 cgi-bin]# cat /var/log/secure

Thank you!

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.freeswitch.org/pipermail/freeswitch-users/attachments/20120410/b3e38d29/attachment-0001.html 

Join us at ClueCon 2011 Aug 9-11, 2011
More information about the FreeSWITCH-users mailing list