]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
[Core] Fix XML generation
authorNorm Brandinger <n.brandinger@gmail.com>
Tue, 17 Nov 2020 18:23:21 +0000 (13:23 -0500)
committerGitHub <noreply@github.com>
Tue, 17 Nov 2020 18:23:21 +0000 (22:23 +0400)
src/switch_ivr.c

index c1d232e1b7bd6636e01214225466fb668d783447..8d215133887c822f410a6772e01ca9d83e7943ff 100644 (file)
@@ -2663,6 +2663,7 @@ SWITCH_DECLARE(int) switch_ivr_set_xml_call_stats(switch_xml_t xml, switch_core_
 {
        const char *name = (type == SWITCH_MEDIA_TYPE_VIDEO) ? "video" : "audio";
        switch_xml_t x_stat, x_in, x_out, x_tmp = NULL;
+       int xoff = 0;
        int loff = 0;
        switch_rtp_stats_t *stats = switch_core_media_get_stats(session, type, NULL);
        char var_val[35] = "";
@@ -2673,11 +2674,11 @@ SWITCH_DECLARE(int) switch_ivr_set_xml_call_stats(switch_xml_t xml, switch_core_
                abort();
        }
 
-       if (!(x_in = switch_xml_add_child_d(x_stat, "inbound", off++))) {
+       if (!(x_in = switch_xml_add_child_d(x_stat, "inbound", xoff++))) {
                abort();
        }
 
-       if (!(x_out = switch_xml_add_child_d(x_stat, "outbound", off++))) {
+       if (!(x_out = switch_xml_add_child_d(x_stat, "outbound", xoff++))) {
                abort();
        }
 
@@ -2708,7 +2709,7 @@ SWITCH_DECLARE(int) switch_ivr_set_xml_call_stats(switch_xml_t xml, switch_core_
                switch_error_period_t *ep;
                int eoff = 0;
 
-               if (!(x_err_log = switch_xml_add_child_d(x_stat, "error-log", off++))) {
+               if (!(x_err_log = switch_xml_add_child_d(x_stat, "error-log", xoff++))) {
                        abort();
                }
 
@@ -2729,19 +2730,20 @@ SWITCH_DECLARE(int) switch_ivr_set_xml_call_stats(switch_xml_t xml, switch_core_
                        switch_xml_set_txt_d(x_tmp, var_val);
 
                        switch_snprintf(var_val, sizeof(var_val), "%" SWITCH_TIME_T_FMT, ep->flaws);
-                       x_tmp = switch_xml_add_child_d(x_err, "flaws", 1);
+                       x_tmp = switch_xml_add_child_d(x_err, "flaws", 2);
                        switch_xml_set_txt_d(x_tmp, var_val);
 
                        switch_snprintf(var_val, sizeof(var_val), "%" SWITCH_TIME_T_FMT, ep->consecutive_flaws);
-                       x_tmp = switch_xml_add_child_d(x_err, "consecutive-flaws", 1);
+                       x_tmp = switch_xml_add_child_d(x_err, "consecutive-flaws", 3);
                        switch_xml_set_txt_d(x_tmp, var_val);
 
                        switch_snprintf(var_val, sizeof(var_val), "%" SWITCH_TIME_T_FMT, (ep->stop - ep->start) / 1000);
-                       x_tmp = switch_xml_add_child_d(x_err, "duration-msec", 2);
+                       x_tmp = switch_xml_add_child_d(x_err, "duration-msec", 4);
                        switch_xml_set_txt_d(x_tmp, var_val);
                }
        }
 
+       loff=0;
        add_stat(x_out, stats->outbound.raw_bytes, "raw_bytes");
        add_stat(x_out, stats->outbound.media_bytes, "media_bytes");
        add_stat(x_out, stats->outbound.packet_count, "packet_count");
@@ -2805,11 +2807,11 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_generate_xml_cdr(switch_core_session_
 {
        switch_channel_t *channel = switch_core_session_get_channel(session);
        switch_caller_profile_t *caller_profile;
-       switch_xml_t variables, cdr, x_main_cp, x_caller_profile, x_caller_extension, x_times, time_tag,
+       switch_xml_t call_stats, variables, cdr, x_main_cp, x_caller_profile, x_caller_extension, x_times, time_tag,
                x_application, x_callflow, x_inner_extension, x_apps, x_o, x_channel_data, x_field, xhr, x_hold;
        switch_app_log_t *app_log;
        char tmp[512], *f;
-       int cdr_off = 0, v_off = 0, cd_off = 0;
+       int cdr_off = 0, cd_off = 0;
        switch_hold_record_t *hold_record = switch_channel_get_hold_record(channel), *hr;
        const char *text_buffer = NULL;
 
@@ -2856,19 +2858,19 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_generate_xml_cdr(switch_core_session_
                free(f);
        }
 
-       if (!(variables = switch_xml_add_child_d(cdr, "call-stats", cdr_off++))) {
+       if (!(call_stats = switch_xml_add_child_d(cdr, "call-stats", cdr_off++))) {
                goto error;
        }
 
-       switch_ivr_set_xml_call_stats(variables, session, v_off, SWITCH_MEDIA_TYPE_AUDIO);
-       switch_ivr_set_xml_call_stats(variables, session, v_off, SWITCH_MEDIA_TYPE_VIDEO);
+       switch_ivr_set_xml_call_stats(call_stats, session, 0, SWITCH_MEDIA_TYPE_AUDIO);
+       switch_ivr_set_xml_call_stats(call_stats, session, 0, SWITCH_MEDIA_TYPE_VIDEO);
 
 
        if (!(variables = switch_xml_add_child_d(cdr, "variables", cdr_off++))) {
                goto error;
        }
 
-       switch_ivr_set_xml_chan_vars(variables, channel, v_off);
+       switch_ivr_set_xml_chan_vars(variables, channel, 0);
 
 
        if ((app_log = switch_core_session_get_app_log(session))) {