]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
xml formatting for call detail
authorAnthony Minessale <anthony.minessale@gmail.com>
Thu, 15 Feb 2007 19:20:14 +0000 (19:20 +0000)
committerAnthony Minessale <anthony.minessale@gmail.com>
Thu, 15 Feb 2007 19:20:14 +0000 (19:20 +0000)
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@4289 d0543943-73ff-0310-b7d9-9358b9ac24b2

src/switch_ivr.c
src/switch_xml.c

index 2701b3d40b9f1d41e4ec02c8aa9ea9f1acb1d066..347628c6d85580b4bcddf343ac23ff5c379c0fe4 100644 (file)
@@ -4921,6 +4921,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_generate_xml_cdr(switch_core_session_
                x_caller_profile,
                x_caller_extension,
                x_times,
+               time_tag,
                x_application,
                x_callflow;
        char tmp[512];
@@ -5004,29 +5005,33 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_generate_xml_cdr(switch_core_session_
 
 
                if (caller_profile->times) {
-                       if (!(x_times = switch_xml_add_child_d(x_callflow, "created_time", cf_off++))) {
+                       int t_off = 0;
+                       if (!(x_times = switch_xml_add_child_d(x_callflow, "times", cf_off++))) {
+                               goto error;
+                       }
+                       if (!(time_tag = switch_xml_add_child_d(x_times, "created_time", t_off++))) {
                                goto error;
                        }
                        snprintf(tmp, sizeof(tmp), "%"APR_TIME_T_FMT, caller_profile->times->created);
-                       switch_xml_set_txt_d(x_times, tmp);
+                       switch_xml_set_txt_d(time_tag, tmp);
 
-                       if (!(x_times = switch_xml_add_child_d(x_callflow, "answered_time", cf_off++))) {
+                       if (!(time_tag = switch_xml_add_child_d(x_times, "answered_time", t_off++))) {
                                goto error;
                        }
                        snprintf(tmp, sizeof(tmp), "%"APR_TIME_T_FMT, caller_profile->times->answered);
-                       switch_xml_set_txt_d(x_times, tmp);
+                       switch_xml_set_txt_d(time_tag, tmp);
 
-                       if (!(x_times = switch_xml_add_child_d(x_callflow, "hangup_time", cf_off++))) {
+                       if (!(time_tag = switch_xml_add_child_d(x_times, "hangup_time", t_off++))) {
                                goto error;
                        }
                        snprintf(tmp, sizeof(tmp), "%"APR_TIME_T_FMT, caller_profile->times->hungup);
-                       switch_xml_set_txt_d(x_times, tmp);
+                       switch_xml_set_txt_d(time_tag, tmp);
 
-                       if (!(x_times = switch_xml_add_child_d(x_callflow, "transfer_time", cf_off++))) {
+                       if (!(time_tag = switch_xml_add_child_d(x_times, "transfer_time", t_off++))) {
                                goto error;
                        }
                        snprintf(tmp, sizeof(tmp), "%"APR_TIME_T_FMT, caller_profile->times->transferred);
-                       switch_xml_set_txt_d(x_times, tmp);
+                       switch_xml_set_txt_d(time_tag, tmp);
                }
 
                caller_profile = caller_profile->next;
index 303007006421c24eb531f3aa7d4c84b0b5ada7da..516937902841f592f7a47008269cc9775038b37c 100644 (file)
@@ -1223,9 +1223,12 @@ static char *switch_xml_toxml_r(switch_xml_t xml, char **s, switch_size_t *len,
     // parent character content up to this tag
     *s = switch_xml_ampencode(txt + start, xml->off - start, s, len, max, 0);
 
-    while (*len + strlen(xml->name) + 5 + (strlen(XML_INDENT) * (*count)) > *max) // reallocate s
+    while (*len + strlen(xml->name) + 5 + (strlen(XML_INDENT) * (*count)) + 1 > *max) // reallocate s
         *s = realloc(*s, *max += SWITCH_XML_BUFSIZE);
 
+       if (*(*s+(*len)-1) == '>') {
+               *len += sprintf(*s + *len, "\n"); // indent
+       }
        for (lcount = 0; lcount < *count; lcount++) {
                *len += sprintf(*s + *len, "%s", XML_INDENT); // indent
        }
@@ -1253,7 +1256,7 @@ static char *switch_xml_toxml_r(switch_xml_t xml, char **s, switch_size_t *len,
         *len += sprintf(*s + *len, "\"");
     }
 
-    *len += sprintf(*s + *len, (xml->child || xml->txt) ? ">" : "/>\n");
+       *len += sprintf(*s + *len, (xml->child || xml->txt) ? ">" : "/>\n");
 
        if (xml->child) {
                (*count)++;
@@ -1268,9 +1271,11 @@ static char *switch_xml_toxml_r(switch_xml_t xml, char **s, switch_size_t *len,
 
 
        if (xml->child || xml->txt) {
-               //for (lcount = 0; lcount < *count; lcount++) {
-               //*len += sprintf(*s + *len, "%s", XML_INDENT); // indent
-               //}
+               if (*(*s+(*len)-1) == '\n') {
+                       for (lcount = 0; lcount < *count; lcount++) {
+                               *len += sprintf(*s + *len, "%s", XML_INDENT); // indent
+                       }
+               }
                *len += sprintf(*s + (*len), "</%s>\n", xml->name); // close tag
        }