<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[Freeswitch-trunk][16687] </title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<div id="header">FreeSWITCH Subversion</div>
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://fisheye.freeswitch.org/changelog/FreeSWITCH?cs=16687">16687</a></dd>
<dt>Author</dt> <dd>cseket</dd>
<dt>Date</dt> <dd>2010-02-18 09:48:36 -0600 (Thu, 18 Feb 2010)</dd>
</dl>

<h3>Log Message</h3>
<pre>add json hack. maybe we need a refactor for elegent solution...</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#freeswitchbranchescseketsrcmodxml_intmod_xml_cdrMakefile">freeswitch/branches/cseket/src/mod/xml_int/mod_xml_cdr/Makefile</a></li>
<li><a href="#freeswitchbranchescseketsrcmodxml_intmod_xml_cdrmod_xml_cdrc">freeswitch/branches/cseket/src/mod/xml_int/mod_xml_cdr/mod_xml_cdr.c</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="freeswitchbranchescseketsrcmodxml_intmod_xml_cdrMakefile"></a>
<div class="modfile"><h4>Modified: freeswitch/branches/cseket/src/mod/xml_int/mod_xml_cdr/Makefile (16686 => 16687)</h4>
<pre class="diff"><span>
<span class="info">--- freeswitch/branches/cseket/src/mod/xml_int/mod_xml_cdr/Makefile        2010-02-18 15:45:04 UTC (rev 16686)
+++ freeswitch/branches/cseket/src/mod/xml_int/mod_xml_cdr/Makefile        2010-02-18 15:48:36 UTC (rev 16687)
</span><span class="lines">@@ -1,2 +1,27 @@
</span><ins>+json-c=json-c-0.8
+BASE=../../../..
</ins><span class="cx"> WANT_CURL=yes
</span><del>-include ../../../../build/modmake.rules
</del><ins>+
+JSON_DIR=$(switch_srcdir)/libs/$(json-c)
+JSON_BUILDDIR=$(switch_builddir)/libs/$(json-c)
+
+JSONLA=$(JSON_BUILDDIR)/libjson.la
+
+LOCAL_CFLAGS=-I$(JSON_DIR)
+LOCAL_LIBADD=$(JSONLA)
+
+include $(BASE)/build/modmake.rules
+
+$(JSON_DIR):
+        $(GETLIB) $(json-c).tar.gz
+
+$(JSON_BUILDDIR)/Makefile: $(JSON_DIR)
+        mkdir -p $(JSON_BUILDDIR)
+        cd $(JSON_BUILDDIR) &amp;&amp; $(DEFAULT_VARS) $(JSON_DIR)/configure $(DEFAULT_ARGS) --srcdir=$(JSON_DIR) CPPFLAGS= LDFLAGS=
+        $(TOUCH_TARGET)
+
+$(JSONLA): $(JSON_BUILDDIR)/Makefile
+        cd $(JSON_BUILDDIR) &amp;&amp; $(MAKE)
+        $(TOUCH_TARGET)
+
+
</ins></span></pre></div>
<a id="freeswitchbranchescseketsrcmodxml_intmod_xml_cdrmod_xml_cdrc"></a>
<div class="modfile"><h4>Modified: freeswitch/branches/cseket/src/mod/xml_int/mod_xml_cdr/mod_xml_cdr.c (16686 => 16687)</h4>
<pre class="diff"><span>
<span class="info">--- freeswitch/branches/cseket/src/mod/xml_int/mod_xml_cdr/mod_xml_cdr.c        2010-02-18 15:45:04 UTC (rev 16686)
+++ freeswitch/branches/cseket/src/mod/xml_int/mod_xml_cdr/mod_xml_cdr.c        2010-02-18 15:48:36 UTC (rev 16687)
</span><span class="lines">@@ -33,6 +33,8 @@
</span><span class="cx"> #include &lt;sys/stat.h&gt;
</span><span class="cx"> #include &lt;switch.h&gt;
</span><span class="cx"> #include &lt;curl/curl.h&gt;
</span><ins>+#include &lt;json.h&gt;
+
</ins><span class="cx"> #define MAX_URLS 20
</span><span class="cx"> 
</span><span class="cx"> #define ENCODING_NONE 0
</span><span class="lines">@@ -67,6 +69,7 @@
</span><span class="cx">         int disable100continue;
</span><span class="cx">         int rotate;
</span><span class="cx">         int auth_scheme;
</span><ins>+        int json;
</ins><span class="cx">         switch_memory_pool_t *pool;
</span><span class="cx"> } globals;
</span><span class="cx"> 
</span><span class="lines">@@ -175,9 +178,427 @@
</span><span class="cx">         return status;
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+#define JSON_ENSURE_SUCCESS(obj) if (is_error(obj)) { return; }
+SWITCH_DECLARE(void) set_json_profile_data(struct json_object *json, switch_caller_profile_t *caller_profile)
+{
+        struct json_object *param = NULL;
+
+        param = json_object_new_string((char *)caller_profile-&gt;username);
+        JSON_ENSURE_SUCCESS(param);
+        json_object_object_add(json, &quot;username&quot;, param);
+
+        param = json_object_new_string((char *)caller_profile-&gt;dialplan);
+        JSON_ENSURE_SUCCESS(param);
+        json_object_object_add(json, &quot;dialplan&quot;, param);
+
+        param = json_object_new_string((char *)caller_profile-&gt;caller_id_name);
+        JSON_ENSURE_SUCCESS(param);
+        json_object_object_add(json, &quot;caller_id_name&quot;, param);
+
+        param = json_object_new_string((char *)caller_profile-&gt;ani);
+        JSON_ENSURE_SUCCESS(param);
+        json_object_object_add(json, &quot;ani&quot;, param);
+
+        param = json_object_new_string((char *)caller_profile-&gt;aniii);
+        JSON_ENSURE_SUCCESS(param);
+        json_object_object_add(json, &quot;aniii&quot;, param);
+
+        param = json_object_new_string((char *)caller_profile-&gt;caller_id_number);
+        JSON_ENSURE_SUCCESS(param);
+        json_object_object_add(json, &quot;caller_id_number&quot;, param);
+
+        param = json_object_new_string((char *)caller_profile-&gt;network_addr);
+        JSON_ENSURE_SUCCESS(param);
+        json_object_object_add(json, &quot;network_addr&quot;, param);
+
+        param = json_object_new_string((char *)caller_profile-&gt;rdnis);
+        JSON_ENSURE_SUCCESS(param);
+        json_object_object_add(json, &quot;rdnis&quot;, param);
+
+        param = json_object_new_string(caller_profile-&gt;destination_number);
+        JSON_ENSURE_SUCCESS(param);
+        json_object_object_add(json, &quot;destination_number&quot;, param);
+
+        param = json_object_new_string(caller_profile-&gt;uuid);
+        JSON_ENSURE_SUCCESS(param);
+        json_object_object_add(json, &quot;uuid&quot;, param);
+
+        param = json_object_new_string((char *)caller_profile-&gt;source);
+        JSON_ENSURE_SUCCESS(param);
+        json_object_object_add(json, &quot;source&quot;, param);
+
+        param = json_object_new_string((char *)caller_profile-&gt;context);
+        JSON_ENSURE_SUCCESS(param);
+        json_object_object_add(json, &quot;context&quot;, param);
+
+        param = json_object_new_string(caller_profile-&gt;chan_name);
+        JSON_ENSURE_SUCCESS(param);
+        json_object_object_add(json, &quot;chan_name&quot;, param);
+
+}
+
+SWITCH_DECLARE(void) set_json_chan_vars(struct json_object *json, switch_channel_t *channel)
+{
+        struct json_object *variable = NULL;
+        switch_event_header_t *hi = switch_channel_variable_first(channel);
+
+        if (!hi)
+                return;
+
+        for (; hi; hi = hi-&gt;next) {
+                if (!zstr(hi-&gt;name) &amp;&amp; !zstr(hi-&gt;value)) {
+                        char *data;
+                        switch_size_t dlen = strlen(hi-&gt;value) * 3;
+
+                        if ((data = malloc(dlen))) {
+                                memset(data, 0, dlen);
+                                switch_url_encode(hi-&gt;value, data, dlen);
+
+                                variable = json_object_new_string(data);
+                                if (!is_error(variable)) {
+                                        json_object_object_add(json, hi-&gt;name, variable);
+                                }
+                                free(data);
+                        }
+                }
+        }
+        switch_channel_variable_last(channel);
+
+        return;
+}
+
+
+
+SWITCH_DECLARE(switch_status_t) generate_json_cdr(switch_core_session_t *session, struct json_object **json_cdr)
+{
+
+        struct json_object *cdr = json_object_new_object();
+        switch_channel_t *channel = switch_core_session_get_channel(session);
+        switch_caller_profile_t *caller_profile;
+        struct json_object *variables, *j_main_cp, *j_caller_profile, *j_caller_extension, *j_times, *time_tag,
+                *j_application, *j_callflow, *j_inner_extension, *j_apps, *j_o, *j_channel_data, *j_field;
+        switch_app_log_t *app_log;
+        char tmp[512], *f;
+        
+        if (is_error(cdr)) {
+                return SWITCH_STATUS_FALSE;
+        }
+
+        j_channel_data = json_object_new_object();
+        if (is_error(j_channel_data)) {
+                goto error;
+        }
+        json_object_object_add(cdr, &quot;channel_data&quot;, j_channel_data);
+
+        
+        j_field = json_object_new_string((char *) switch_channel_state_name(switch_channel_get_state(channel)));
+        json_object_object_add(j_channel_data, &quot;state&quot;, j_field);
+
+        j_field = json_object_new_string(switch_channel_direction(channel) == SWITCH_CALL_DIRECTION_OUTBOUND ? &quot;outbound&quot; : &quot;inbound&quot;);
+
+        json_object_object_add(j_channel_data, &quot;direction&quot;, j_field);
+
+
+        switch_snprintf(tmp, sizeof(tmp), &quot;%d&quot;, switch_channel_get_state(channel));
+        j_field = json_object_new_string((char *) tmp);
+        json_object_object_add(j_channel_data, &quot;state_number&quot;, j_field);
+        
+
+        if ((f = switch_channel_get_flag_string(channel))) {
+                j_field = json_object_new_string((char *) f);
+                json_object_object_add(j_channel_data, &quot;flags&quot;, j_field);
+                free(f);
+        }
+
+        if ((f = switch_channel_get_cap_string(channel))) {
+                j_field = json_object_new_string((char *) f);
+                json_object_object_add(j_channel_data, &quot;caps&quot;, j_field);
+                free(f);
+        }
+
+
+        variables = json_object_new_object();
+        json_object_object_add(cdr, &quot;variables&quot;, variables);
+
+        if (is_error(variables)) {
+                goto error;
+        }
+
+        set_json_chan_vars(variables, channel);
+
+
+        if ((app_log = switch_core_session_get_app_log(session))) {
+                switch_app_log_t *ap;
+
+                j_apps = json_object_new_object();
+
+                if (is_error(j_apps)) {
+                        goto error;
+                }
+
+                json_object_object_add(cdr, &quot;app_log&quot;, j_apps);
+
+                for (ap = app_log; ap; ap = ap-&gt;next) {
+                        j_application = json_object_new_object();
+
+                        if (is_error(j_application)) {
+                                goto error;
+                        }
+
+                        json_object_object_add(j_application, &quot;app_name&quot;, json_object_new_string(ap-&gt;app));
+                        json_object_object_add(j_application, &quot;app_data&quot;, json_object_new_string(ap-&gt;arg));
+
+                        json_object_object_add(j_apps, &quot;application&quot;, j_application);
+                }
+        }
+
+
+        caller_profile = switch_channel_get_caller_profile(channel);
+
+        while (caller_profile) {
+
+                j_callflow = json_object_new_object();
+
+                if (is_error(j_callflow)) {
+                        goto error;
+                }
+
+                json_object_object_add(cdr, &quot;callflow&quot;, j_callflow);
+
+                if (!zstr(caller_profile-&gt;dialplan)) {
+                        json_object_object_add(j_callflow, &quot;dialplan&quot;, json_object_new_string((char *)caller_profile-&gt;dialplan));
+                }
+
+                if (!zstr(caller_profile-&gt;profile_index)) {
+                        json_object_object_add(j_callflow, &quot;profile_index&quot;, json_object_new_string((char *)caller_profile-&gt;profile_index));
+                }
+
+                if (caller_profile-&gt;caller_extension) {
+                        switch_caller_application_t *ap;
+
+                        j_caller_extension = json_object_new_object();
+
+                        if (is_error(j_caller_extension)) {
+                                goto error;
+                        }
+
+                        json_object_object_add(j_callflow, &quot;extension&quot;, j_caller_extension);
+
+                        json_object_object_add(j_caller_extension, &quot;name&quot;, json_object_new_string(caller_profile-&gt;caller_extension-&gt;extension_name));
+                        json_object_object_add(j_caller_extension, &quot;number&quot;, json_object_new_string(caller_profile-&gt;caller_extension-&gt;extension_number));
+
+                        if (caller_profile-&gt;caller_extension-&gt;current_application) {
+                                json_object_object_add(j_caller_extension, &quot;current_app&quot;, json_object_new_string(caller_profile-&gt;caller_extension-&gt;current_application-&gt;application_name));
+                        }
+
+                        for (ap = caller_profile-&gt;caller_extension-&gt;applications; ap; ap = ap-&gt;next) {
+                                j_application = json_object_new_object();
+
+                                if (is_error(j_application)) {
+                                        goto error;
+                                }
+
+
+                                json_object_object_add(j_caller_extension, &quot;application&quot;, j_application);
+
+                                if (ap == caller_profile-&gt;caller_extension-&gt;current_application) {
+                                        json_object_object_add(j_application, &quot;last_executed&quot;, json_object_new_string(&quot;true&quot;));
+                                }
+                                json_object_object_add(j_application, &quot;app_name&quot;, json_object_new_string(ap-&gt;application_name));
+                                json_object_object_add(j_application, &quot;app_data&quot;, json_object_new_string(ap-&gt;application_data));
+                        }
+
+                        if (caller_profile-&gt;caller_extension-&gt;children) {
+                                switch_caller_profile_t *cp = NULL;
+                                for (cp = caller_profile-&gt;caller_extension-&gt;children; cp; cp = cp-&gt;next) {
+
+                                        if (!cp-&gt;caller_extension) {
+                                                continue;
+                                        }
+
+                                        j_inner_extension = json_object_new_object();
+                                        if (is_error(j_inner_extension)) {
+                                                goto error;
+                                        }
+
+                                        json_object_object_add(j_caller_extension, &quot;sub_extensions&quot;, j_inner_extension);
+
+
+                                        j_caller_extension = json_object_new_object();
+                                        if (is_error(j_caller_extension)) {
+                                                goto error;
+                                        }
+
+                                        json_object_object_add(j_inner_extension, &quot;extension&quot;, j_caller_extension);
+
+                                        json_object_object_add(j_caller_extension, &quot;name&quot;, json_object_new_string(cp-&gt;caller_extension-&gt;extension_name));
+                                        json_object_object_add(j_caller_extension, &quot;number&quot;, json_object_new_string(cp-&gt;caller_extension-&gt;extension_number));
+
+                                        json_object_object_add(j_caller_extension, &quot;dialplan&quot;, json_object_new_string((char *)cp-&gt;dialplan));
+
+                                        if (cp-&gt;caller_extension-&gt;current_application) {
+                                                json_object_object_add(j_caller_extension, &quot;current_app&quot;, json_object_new_string(cp-&gt;caller_extension-&gt;current_application-&gt;application_name));
+                                        }
+
+                                        for (ap = cp-&gt;caller_extension-&gt;applications; ap; ap = ap-&gt;next) {
+                                                j_application = json_object_new_object();
+                                                
+                                                if (is_error(j_application)) {
+                                                        goto error;
+                                                }
+                                                json_object_object_add(j_caller_extension, &quot;application&quot;, j_application);
+
+                                                if (ap == cp-&gt;caller_extension-&gt;current_application) {
+                                                        json_object_object_add(j_application, &quot;last_executed&quot;, json_object_new_string(&quot;true&quot;));
+                                                }
+                                                json_object_object_add(j_application, &quot;app_name&quot;, json_object_new_string(ap-&gt;application_name));
+                                                json_object_object_add(j_application, &quot;app_data&quot;, json_object_new_string(ap-&gt;application_data));
+                                        }
+                                }
+                        }
+                }
+
+                j_main_cp = json_object_new_object();
+                if (is_error(j_main_cp)) {
+                        goto error;
+                }
+
+                json_object_object_add(j_callflow, &quot;caller_profile&quot;, j_main_cp);
+
+                set_json_profile_data(j_main_cp, caller_profile);
+
+                if (caller_profile-&gt;originator_caller_profile) {
+                        switch_caller_profile_t *cp = NULL;
+
+                        j_o = json_object_new_object();
+                        if (is_error(j_o)) {
+                                goto error;
+                        }
+                        
+                        json_object_object_add(j_main_cp, &quot;originator&quot;, j_o);
+
+                        for (cp = caller_profile-&gt;originator_caller_profile; cp; cp = cp-&gt;next) {
+                                j_caller_profile = json_object_new_object();
+                                if (is_error(j_caller_profile)) {
+                                        goto error;
+                                }
+
+                                json_object_object_add(j_o, &quot;originator_caller_profile&quot;, j_caller_profile);
+
+                                set_json_profile_data(j_caller_profile, cp);
+                        }
+                }
+
+                if (caller_profile-&gt;originatee_caller_profile) {
+                        switch_caller_profile_t *cp = NULL;
+
+                        j_o = json_object_new_object();
+                        if (is_error(j_o)) {
+                                goto error;
+                        }
+
+                        json_object_object_add(j_main_cp, &quot;originatee&quot;, j_o);
+
+                        for (cp = caller_profile-&gt;originatee_caller_profile; cp; cp = cp-&gt;next) {
+
+                                j_caller_profile = json_object_new_object();
+                                if (is_error(j_caller_profile)) {
+                                        goto error;
+                                }
+                                
+                                json_object_object_add(j_o, &quot;originatee_caller_profile&quot;, j_caller_profile);
+                                set_json_profile_data(j_caller_profile, cp);
+                        }
+                }
+
+                if (caller_profile-&gt;times) {
+
+                        j_times = json_object_new_object();
+                        if (is_error(j_times)) {
+                                goto error;
+                        }
+
+                        json_object_object_add(j_callflow, &quot;times&quot;, j_times);
+
+                        switch_snprintf(tmp, sizeof(tmp), &quot;%&quot; SWITCH_TIME_T_FMT, caller_profile-&gt;times-&gt;created);
+                        time_tag = json_object_new_string(tmp);
+                        if (is_error(time_tag)) {
+                                goto error;
+                        }
+                        json_object_object_add(j_times, &quot;created_time&quot;, time_tag);
+
+                        switch_snprintf(tmp, sizeof(tmp), &quot;%&quot; SWITCH_TIME_T_FMT, caller_profile-&gt;times-&gt;profile_created);
+                        time_tag = json_object_new_string(tmp);
+                        if (is_error(time_tag)) {
+                                goto error;
+                        }
+                        json_object_object_add(j_times, &quot;profile_created_time&quot;, time_tag);
+
+                        switch_snprintf(tmp, sizeof(tmp), &quot;%&quot; SWITCH_TIME_T_FMT, caller_profile-&gt;times-&gt;progress);
+                        time_tag = json_object_new_string(tmp);
+                        if (is_error(time_tag)) {
+                                goto error;
+                        }
+                        json_object_object_add(j_times, &quot;progress_time&quot;, time_tag);
+
+                        switch_snprintf(tmp, sizeof(tmp), &quot;%&quot; SWITCH_TIME_T_FMT, caller_profile-&gt;times-&gt;progress_media);
+                        time_tag = json_object_new_string(tmp);
+                        if (is_error(time_tag)) {
+                                goto error;
+                        }
+                        json_object_object_add(j_times, &quot;progress_media_time&quot;, time_tag);
+
+
+                        switch_snprintf(tmp, sizeof(tmp), &quot;%&quot; SWITCH_TIME_T_FMT, caller_profile-&gt;times-&gt;answered);
+                        time_tag = json_object_new_string(tmp);
+                        if (is_error(time_tag)) {
+                                goto error;
+                        }
+                        json_object_object_add(j_times, &quot;answered_time&quot;, time_tag);
+
+                        switch_snprintf(tmp, sizeof(tmp), &quot;%&quot; SWITCH_TIME_T_FMT, caller_profile-&gt;times-&gt;hungup);
+                        time_tag = json_object_new_string(tmp);
+                        if (is_error(time_tag)) {
+                                goto error;
+                        }
+                        json_object_object_add(j_times, &quot;hangup_time&quot;, time_tag);
+
+                        switch_snprintf(tmp, sizeof(tmp), &quot;%&quot; SWITCH_TIME_T_FMT, caller_profile-&gt;times-&gt;resurrected);
+                        time_tag = json_object_new_string(tmp);
+                        if (is_error(time_tag)) {
+                                goto error;
+                        }
+                        json_object_object_add(j_times, &quot;resurrect_time&quot;, time_tag);
+
+                        switch_snprintf(tmp, sizeof(tmp), &quot;%&quot; SWITCH_TIME_T_FMT, caller_profile-&gt;times-&gt;transferred);
+                        time_tag = json_object_new_string(tmp);
+                        if (is_error(time_tag)) {
+                                goto error;
+                        }
+                        json_object_object_add(j_times, &quot;transfer_time&quot;, time_tag);
+
+                }
+
+                caller_profile = caller_profile-&gt;next;
+        }
+
+        *json_cdr = cdr;
+
+        return SWITCH_STATUS_SUCCESS;
+        
+  error:
+
+        if (cdr) {
+                json_object_put(cdr);
+        }
+
+        return SWITCH_STATUS_FALSE;
+}
+
+
</ins><span class="cx"> static switch_status_t my_on_reporting(switch_core_session_t *session)
</span><span class="cx"> {
</span><del>-        switch_xml_t cdr;
</del><ins>+        switch_xml_t cdr = NULL;
</ins><span class="cx">         char *xml_text = NULL;
</span><span class="cx">         char *path = NULL;
</span><span class="cx">         char *curl_xml_text = NULL;
</span><span class="lines">@@ -193,6 +614,7 @@
</span><span class="cx">         switch_status_t status = SWITCH_STATUS_FALSE;
</span><span class="cx">         int is_b;
</span><span class="cx">         const char *a_prefix = &quot;&quot;;
</span><ins>+        struct json_object *json_cdr = NULL;
</ins><span class="cx"> 
</span><span class="cx">         if (globals.shutdown) {
</span><span class="cx">                 return SWITCH_STATUS_SUCCESS;
</span><span class="lines">@@ -205,13 +627,23 @@
</span><span class="cx">         if (!is_b &amp;&amp; globals.prefix_a)
</span><span class="cx">                 a_prefix = &quot;a_&quot;;
</span><span class="cx"> 
</span><del>-        if (switch_ivr_generate_xml_cdr(session, &amp;cdr) != SWITCH_STATUS_SUCCESS) {
-                switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, &quot;Error Generating Data!\n&quot;);
-                return SWITCH_STATUS_FALSE;
</del><ins>+        if (globals.json) {
+                if (generate_json_cdr(session, &amp;json_cdr) != SWITCH_STATUS_SUCCESS) {
+                        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, &quot;Error Generating Data!\n&quot;);
+                        return SWITCH_STATUS_FALSE;
+                }
+
+                xml_text = json_object_to_json_string(json_cdr);
</ins><span class="cx">         }
</span><ins>+        else {
+                if (switch_ivr_generate_xml_cdr(session, &amp;cdr) != SWITCH_STATUS_SUCCESS) {
+                        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, &quot;Error Generating Data!\n&quot;);
+                        return SWITCH_STATUS_FALSE;
+                }
</ins><span class="cx"> 
</span><del>-        /* build the XML */
-        xml_text = switch_xml_toxml(cdr, SWITCH_TRUE);
</del><ins>+                /* build the XML */
+                xml_text = switch_xml_toxml(cdr, SWITCH_TRUE);
+        }
</ins><span class="cx">         if (!xml_text) {
</span><span class="cx">                 switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, &quot;Memory Error!\n&quot;);
</span><span class="cx">                 goto error;
</span><span class="lines">@@ -417,7 +849,11 @@
</span><span class="cx">         if (curl_xml_text != xml_text) {
</span><span class="cx">                 switch_safe_free(curl_xml_text);
</span><span class="cx">         }
</span><del>-        switch_safe_free(xml_text);
</del><ins>+        if (globals.json) {
+                json_object_put(json_cdr);
+        } else {
+                switch_safe_free(xml_text);
+        }
</ins><span class="cx">         switch_safe_free(path);
</span><span class="cx">         switch_xml_free(cdr);
</span><span class="cx"> 
</span><span class="lines">@@ -566,6 +1002,8 @@
</span><span class="cx">                                 } else if (!strcasecmp(val, &quot;any&quot;)) {
</span><span class="cx">                                         globals.auth_scheme = CURLAUTH_ANY;
</span><span class="cx">                                 }
</span><ins>+                        } else if (!strcasecmp(var, &quot;json&quot;)) {
+                                globals.json = switch_true(val);
</ins><span class="cx">                         }
</span><span class="cx"> 
</span><span class="cx">                         if (zstr(globals.base_err_log_dir)) {
</span></span></pre>
</div>
</div>
<div id="footer">See you at ClueCon</div>

</body>
</html>