From 4a2940d81bf20013936b657577d91c01bf20d8a2 Mon Sep 17 00:00:00 2001 From: Yossi Neiman Date: Wed, 28 Feb 2007 22:28:03 +0000 Subject: [PATCH] Minor changes for MikeJ's switch_strlen_zero() and a minor refactor of BaseCDR::BaseCDR(switch_mod_cdr_newchannel_t*). Added a sample config file, perhaps somebody can edit the makefile to copy this into the configuration when this module is enabled for build. git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@4415 d0543943-73ff-0310-b7d9-9358b9ac24b2 --- src/mod/event_handlers/mod_cdr/basecdr.cpp | 89 +++++++++---------- .../event_handlers/mod_cdr/mod_cdr.conf.xml | 32 +++++++ 2 files changed, 74 insertions(+), 47 deletions(-) create mode 100644 src/mod/event_handlers/mod_cdr/mod_cdr.conf.xml diff --git a/src/mod/event_handlers/mod_cdr/basecdr.cpp b/src/mod/event_handlers/mod_cdr/basecdr.cpp index 969095939c..63ab6ca6d5 100644 --- a/src/mod/event_handlers/mod_cdr/basecdr.cpp +++ b/src/mod/event_handlers/mod_cdr/basecdr.cpp @@ -89,76 +89,71 @@ BaseCDR::BaseCDR(switch_mod_cdr_newchannel_t *newchannel) calltransferdate = newchannel->callerprofile->times->transferred; callenddate = newchannel->callerprofile->times->hungup; - if(newchannel->callerprofile->caller_id_name != 0) - { + if(!switch_strlen_zero(newchannel->callerprofile->caller_id_name)) strncpy(clid,newchannel->callerprofile->caller_id_name,strlen(newchannel->callerprofile->caller_id_name)); - strncat(clid," <",2); - if(newchannel->callerprofile->caller_id_number != 0 ) - strncat(clid,newchannel->callerprofile->caller_id_number,strlen(clid)+strlen(newchannel->callerprofile->caller_id_number)); - strncat(clid,">",1); - } // Get the ANI information if it's set - if(newchannel->callerprofile->ani != 0) + if(!switch_strlen_zero(newchannel->callerprofile->ani)) strncpy(ani,newchannel->callerprofile->ani,strlen(newchannel->callerprofile->ani)); - if(newchannel->callerprofile->aniii != 0) + if(!switch_strlen_zero(newchannel->callerprofile->aniii)) strncpy(aniii,newchannel->callerprofile->aniii,strlen(newchannel->callerprofile->aniii)); - if(newchannel->callerprofile->dialplan != 0) + if(!switch_strlen_zero(newchannel->callerprofile->dialplan)) strncpy(dialplan,newchannel->callerprofile->dialplan,strlen(newchannel->callerprofile->dialplan)); - if(newchannel->callerprofile->network_addr != 0) + if(!switch_strlen_zero(newchannel->callerprofile->network_addr)) strncpy(network_addr,newchannel->callerprofile->network_addr,strlen(newchannel->callerprofile->network_addr)); - } - //switch_caller_profile_t *originateprofile = switch_channel_get_originator_caller_profile(newchannel->channel->callerprofile); - - // Were we the receiver of the call? - if(newchannel->callerprofile->originator_caller_profile) - { - originated = 0; - if(newchannel->callerprofile->originator_caller_profile->uuid != 0) - strncpy(destuuid,newchannel->callerprofile->originator_caller_profile->uuid,strlen(newchannel->callerprofile->originator_caller_profile->uuid)); - if(newchannel->callerprofile) + // Were we the receiver of the call? + if(newchannel->callerprofile->originator_caller_profile) { - if(newchannel->callerprofile->destination_number) + originated = 0; + if(!switch_strlen_zero(newchannel->callerprofile->originator_caller_profile->uuid)) + strncpy(destuuid,newchannel->callerprofile->originator_caller_profile->uuid,strlen(newchannel->callerprofile->originator_caller_profile->uuid)); + + if(!switch_strlen_zero(newchannel->callerprofile->destination_number)) strncpy(src,newchannel->callerprofile->destination_number,strlen(newchannel->callerprofile->destination_number)); - if(newchannel->callerprofile->caller_id_number != 0) + if(!switch_strlen_zero(newchannel->callerprofile->caller_id_number)) strncpy(dst,newchannel->callerprofile->caller_id_number,strlen(newchannel->callerprofile->caller_id_number)); } - } - else - { - //originateprofile = switch_channel_get_originatee_profile(newchannel->channel->callerprofile); - // Or were we maybe we were the caller? - if(newchannel->callerprofile->originatee_caller_profile) + else { - if (newchannel->callerprofile) { - if(newchannel->callerprofile->caller_id_number != 0) + //originateprofile = switch_channel_get_originatee_profile(newchannel->channel->callerprofile); + // Or were we maybe we were the caller? + if(newchannel->callerprofile->originatee_caller_profile) + { + if(!switch_strlen_zero(newchannel->callerprofile->caller_id_number)) strncpy(src,newchannel->callerprofile->caller_id_number,strlen(newchannel->callerprofile->caller_id_number)); - if(newchannel->callerprofile->destination_number != 0) + if(!switch_strlen_zero(newchannel->callerprofile->destination_number)) strncpy(dst,newchannel->callerprofile->destination_number,strlen(newchannel->callerprofile->destination_number)); + if(!switch_strlen_zero(newchannel->callerprofile->originatee_caller_profile->chan_name)) + strncpy(dstchannel,newchannel->callerprofile->originatee_caller_profile->chan_name,strlen(newchannel->callerprofile->originatee_caller_profile->chan_name)); } - if(newchannel->callerprofile->originatee_caller_profile->chan_name != 0) - strncpy(dstchannel,newchannel->callerprofile->originatee_caller_profile->chan_name,strlen(newchannel->callerprofile->originatee_caller_profile->chan_name)); } } - strncpy(myuuid,newchannel->callerprofile->uuid,strlen(newchannel->callerprofile->uuid)); - strncpy(srcchannel,newchannel->callerprofile->chan_name,strlen(newchannel->callerprofile->chan_name)); + if(!switch_strlen_zero(newchannel->callerprofile->uuid)) + strncpy(myuuid,newchannel->callerprofile->uuid,strlen(newchannel->callerprofile->uuid)); + + if(!switch_strlen_zero(newchannel->callerprofile->chan_name)) + strncpy(srcchannel,newchannel->callerprofile->chan_name,strlen(newchannel->callerprofile->chan_name)); if(switch_channel_test_flag(newchannel->channel,CF_ANSWERED)) { disposition=1; - if(callstartdate) - billusec = callenddate - callanswerdate; - else - billusec = callenddate - calltransferdate; + if(callstartdate && callanswerdate) + { + if(callenddate) + billusec = callenddate - callanswerdate; + else if(calltransferdate) + billusec = calltransferdate - callanswerdate; + } } else if(switch_channel_test_flag(newchannel->channel,CF_TRANSFER)) { disposition=1; - billusec = callenddate - calltransferdate; + if(callanswerdate && calltransferdate) + billusec = calltransferdate - callanswerdate; } else { @@ -170,12 +165,12 @@ BaseCDR::BaseCDR(switch_mod_cdr_newchannel_t *newchannel) hangupcause = switch_channel_get_cause(newchannel->channel); hangupcause_text = switch_channel_cause2str(hangupcause); - if(newchannel->callerextension != 0) - if(newchannel->callerextension->last_application != 0) + if(newchannel->callerextension) + if(!newchannel->callerextension->last_application) { - if(newchannel->callerextension->last_application->application_name != 0) + if(!switch_strlen_zero(newchannel->callerextension->last_application->application_name)) strncpy(lastapp,newchannel->callerextension->last_application->application_name,strlen(newchannel->callerextension->last_application->application_name)); - if(newchannel->callerextension->last_application->application_data != 0) + if(!switch_strlen_zero(newchannel->callerextension->last_application->application_data)) strncpy(lastdata,newchannel->callerextension->last_application->application_data,strlen(newchannel->callerextension->last_application->application_data)); } @@ -320,7 +315,7 @@ void BaseCDR::process_channel_variables(const std::list& stringlist std::pair temppair; temppair.first = *iItr; - if(tempvariable != 0) + if(!switch_strlen_zero(tempvariable)) temppair.second = tempvariable; chanvars_fixed.push_back(temppair); @@ -359,7 +354,7 @@ void BaseCDR::process_channel_variables(const std::list& stringlist char *tempvariable; tempvariable = switch_channel_get_variable(channel,tempstring); - if(tempvariable != 0) + if(!switch_strlen_zero(tempvariable)) chanvars_supp[*iItr] = tempvariable; } } diff --git a/src/mod/event_handlers/mod_cdr/mod_cdr.conf.xml b/src/mod/event_handlers/mod_cdr/mod_cdr.conf.xml new file mode 100644 index 0000000000..dcdea890c4 --- /dev/null +++ b/src/mod/event_handlers/mod_cdr/mod_cdr.conf.xml @@ -0,0 +1,32 @@ + + + + + + + + + + + + + + + + + + + + +