]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
add failed_xml_cdr magic variable
authorAnthony Minessale <anthony.minessale@gmail.com>
Fri, 30 May 2008 18:11:05 +0000 (18:11 +0000)
committerAnthony Minessale <anthony.minessale@gmail.com>
Fri, 30 May 2008 18:11:05 +0000 (18:11 +0000)
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@8730 d0543943-73ff-0310-b7d9-9358b9ac24b2

src/switch_ivr_originate.c

index 01870b09687dd661e77bba8ca7a0816676ad9c6c..3f1fc526038fc5e7e9ee5d0d576c4dbdb2d8036e 100644 (file)
@@ -1202,6 +1202,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_originate(switch_core_session_t *sess
                        }
 
                  done:
+                       
                        *cause = SWITCH_CAUSE_UNALLOCATED;
 
                        if (caller_channel && !switch_channel_ready(caller_channel)) {
@@ -1216,8 +1217,18 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_originate(switch_core_session_t *sess
                                *cause = SWITCH_CAUSE_SUCCESS;
 
                        } else {
+                               const char *cdr_var = NULL;
+                               int cdr_total = 0;
+                               switch_xml_t cdr;
+                               char *xml_text;
+                               char buf[128] = "", buf2[128] = "";
+
+                               if (caller_channel) {
+                                       cdr_var = switch_channel_get_variable(caller_channel, "failed_xml_cdr_prefix");
+                               }
+
                                if (peer_channel) {
-                                       *cause = switch_channel_get_cause(peer_channel);
+                                       *cause = switch_channel_get_cause(peer_channel);                                        
                                } else {
                                        for (i = 0; i < and_argc; i++) {
                                                if (!peer_channels[i]) {
@@ -1227,6 +1238,28 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_originate(switch_core_session_t *sess
                                                break;
                                        }
                                }
+                               
+                               if (cdr_var) {
+                                       for (i = 0; i < and_argc; i++) {
+                                               if (!peer_sessions[i]) {
+                            continue;
+                        }
+                                               
+                                               if (switch_ivr_generate_xml_cdr(peer_sessions[i], &cdr) == SWITCH_STATUS_SUCCESS) {
+                                                       if ((xml_text = switch_xml_toxml(cdr, SWITCH_FALSE))) {
+                                                               switch_snprintf(buf, sizeof(buf), "%s_%d", cdr_var, ++cdr_total);
+                                                               switch_channel_set_variable(caller_channel, buf, xml_text);
+                                                               switch_safe_free(xml_text);
+                                                       }
+                                                       switch_xml_free(cdr);
+                                                       cdr = NULL;
+                                               }
+
+                                       }
+                                       switch_snprintf(buf, sizeof(buf), "%s_total", cdr_var);
+                                       switch_snprintf(buf2, sizeof(buf2), "%d", cdr_total ? cdr_total : 0);
+                                       switch_channel_set_variable(caller_channel, buf, buf2);
+                               }
 
                                if (!*cause) {
                                        if (reason) {