]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
add more data to cdr_csv and debug option to dump all the vars
authorAnthony Minessale <anthony.minessale@gmail.com>
Tue, 11 Dec 2007 22:19:49 +0000 (22:19 +0000)
committerAnthony Minessale <anthony.minessale@gmail.com>
Tue, 11 Dec 2007 22:19:49 +0000 (22:19 +0000)
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@6677 d0543943-73ff-0310-b7d9-9358b9ac24b2

src/include/switch_event.h
src/mod/applications/mod_dptools/mod_dptools.c
src/mod/event_handlers/mod_cdr_csv/mod_cdr_csv.c
src/mod/event_handlers/mod_event_multicast/mod_event_multicast.c
src/mod/event_handlers/mod_event_socket/mod_event_socket.c
src/mod/event_handlers/mod_event_test/mod_event_test.c
src/mod/languages/mod_spidermonkey/mod_spidermonkey.c
src/switch_event.c

index 44837e8ba01e53815eb1ab5a753e9dbf7f12d823..64afb727883972da15a47f47c7431067606c60ad 100644 (file)
@@ -242,10 +242,11 @@ SWITCH_DECLARE(switch_status_t) switch_event_reserve_subclass_detailed(char *own
   \brief Render a string representation of an event sutable for printing or network transport 
   \param event the event to render
   \param str a string pointer to point at the allocated data
+  \param encode url encode the headers
   \return SWITCH_STATUS_SUCCESS if the operation was successful
   \note you must free the resulting string when you are finished with it
 */
-SWITCH_DECLARE(switch_status_t) switch_event_serialize(switch_event_t *event, char **str);
+SWITCH_DECLARE(switch_status_t) switch_event_serialize(switch_event_t *event, char **str, switch_bool_t encode);
 
 /*!
   \brief Render a XML representation of an event sutable for printing or network transport
index 66220670e18c96eaed98695c5d84364fc13bb689..fd0bfefcc07ffdabf63b5b3a95049e9f36a14f4e 100644 (file)
@@ -656,9 +656,11 @@ SWITCH_STANDARD_APP(info_function)
 
        if (switch_event_create(&event, SWITCH_EVENT_MESSAGE) == SWITCH_STATUS_SUCCESS) {
                switch_channel_event_set_data(channel, event);
-               switch_event_serialize(event, &buf);
+               switch_event_serialize(event, &buf, SWITCH_FALSE);
+               switch_assert(buf);
                switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "CHANNEL_DATA:\n%s\n", buf);
                switch_event_destroy(&event);
+               free(buf);
        }
 
 }
index 0982152acf4b1cb8ca633f3f810a7920214e1e5a..b2e164117bef41a8fbe18c7a77c9c92b5fc39439 100644 (file)
@@ -49,6 +49,7 @@ static struct {
        char *default_template;
        int shutdown;
        int rotate;
+       int debug;
 } globals;
 
 SWITCH_MODULE_LOAD_FUNCTION(mod_cdr_csv_load);
@@ -163,8 +164,10 @@ static switch_status_t my_on_hangup(switch_core_session_t *session)
        
        switch_app_log_t *app_log, *ap;
        char *last_app = NULL, *last_arg = NULL;
-       char start[80] = "", answer[80] = "", end[80] = "", tmp[30] = "";
-       int32_t duration = 0, billsec = 0;
+       char start[80] = "", answer[80] = "", end[80] = "", tmp[80] = "";
+       int32_t duration = 0, billsec = 0, mduration = 0, billmsec = 0;
+       switch_time_t uduration = 0, billusec = 0;
+       time_t tt_created = 0, tt_answered = 0, tt_hungup = 0, mtt_created = 0, mtt_answered = 0, mtt_hungup = 0;
 
        if (switch_channel_get_originator_caller_profile(channel)) {
                return SWITCH_STATUS_SUCCESS;
@@ -202,28 +205,50 @@ static switch_status_t my_on_hangup(switch_core_session_t *session)
 
                switch_time_exp_lt(&tm, caller_profile->times->created);
                switch_strftime(start, &retsize, sizeof(start), fmt, &tm);
+               switch_channel_set_variable(channel, "start_stamp", start);
 
                switch_time_exp_lt(&tm, caller_profile->times->answered);
                switch_strftime(answer, &retsize, sizeof(answer), fmt, &tm);
+               switch_channel_set_variable(channel, "answer_stamp", answer);
 
                switch_time_exp_lt(&tm, caller_profile->times->hungup);
                switch_strftime(end, &retsize, sizeof(end), fmt, &tm);
-       
-               duration = ((int32_t) caller_profile->times->hungup / 1000000) - ((int32_t) caller_profile->times->created / 1000000);
-               if (duration < 0) {
-                       duration = 0;
-               }
-
-               billsec = ((int32_t) caller_profile->times->hungup / 1000000) - ((int32_t) caller_profile->times->answered / 1000000);
-               if (billsec < 0) {
-                       billsec = 0;
-               }
+               switch_channel_set_variable(channel, "end_stamp", end);
+
+               tt_created = (time_t) (caller_profile->times->created / 1000000);
+               mtt_created = (time_t) (caller_profile->times->created / 1000);
+               snprintf(tmp, sizeof(tmp), "%" TIME_T_FMT, tt_created);
+               switch_channel_set_variable(channel, "start_epoch", tmp);
+               snprintf(tmp, sizeof(tmp), "%" SWITCH_TIME_T_FMT, caller_profile->times->created);
+               switch_channel_set_variable(channel, "start_uepoch", tmp);
+               
+               tt_answered = (time_t) (caller_profile->times->answered / 1000000);
+               mtt_answered = (time_t) (caller_profile->times->answered / 1000);
+               snprintf(tmp, sizeof(tmp), "%" TIME_T_FMT, tt_answered);
+               switch_channel_set_variable(channel, "answer_epoch", tmp);
+               snprintf(tmp, sizeof(tmp), "%" SWITCH_TIME_T_FMT, caller_profile->times->answered);
+               switch_channel_set_variable(channel, "answer_uepoch", tmp);             
+
+
+               tt_hungup = (time_t) (caller_profile->times->hungup / 1000000);
+               mtt_hungup = (time_t) (caller_profile->times->hungup / 1000);
+               snprintf(tmp, sizeof(tmp), "%" TIME_T_FMT, tt_hungup);
+               switch_channel_set_variable(channel, "end_epoch", tmp);
+               snprintf(tmp, sizeof(tmp), "%" SWITCH_TIME_T_FMT, caller_profile->times->hungup);
+               switch_channel_set_variable(channel, "end_uepoch", tmp);
+
+               uduration = caller_profile->times->hungup - caller_profile->times->created;
+               duration = tt_hungup - tt_created;
+               mduration = mtt_hungup - mtt_created;
                
+               if (caller_profile->times->answered) {
+                       billsec = tt_hungup - tt_answered;
+                       billmsec = mtt_hungup - mtt_answered;
+                       billusec = caller_profile->times->hungup - caller_profile->times->answered;
+               }
        }
        
-       switch_channel_set_variable(channel, "start_stamp", start);
-       switch_channel_set_variable(channel, "answer_stamp", answer);
-       switch_channel_set_variable(channel, "end_stamp", end);
+       
        switch_channel_set_variable(channel, "last_app", last_app);
        switch_channel_set_variable(channel, "last_arg", last_arg);
        switch_channel_set_variable(channel, "caller_id", cid_buf);
@@ -233,6 +258,31 @@ static switch_status_t my_on_hangup(switch_core_session_t *session)
 
        snprintf(tmp, sizeof(tmp), "%d", billsec);
        switch_channel_set_variable(channel, "billsec", tmp);
+       
+       snprintf(tmp, sizeof(tmp), "%d", mduration);
+       switch_channel_set_variable(channel, "mduration", tmp);
+
+       snprintf(tmp, sizeof(tmp), "%d", billmsec);
+       switch_channel_set_variable(channel, "billmsec", tmp);
+
+       snprintf(tmp, sizeof(tmp), "%" SWITCH_TIME_T_FMT, uduration);
+       switch_channel_set_variable(channel, "uduration", tmp);
+
+       snprintf(tmp, sizeof(tmp), "%" SWITCH_TIME_T_FMT, billusec);
+       switch_channel_set_variable(channel, "billusec", tmp);
+
+       if (globals.debug) {
+               switch_event_t *event;
+               if (switch_event_create(&event, SWITCH_EVENT_MESSAGE) == SWITCH_STATUS_SUCCESS) {
+                       char *buf;
+                       switch_channel_event_set_data(channel, event);
+                       switch_event_serialize(event, &buf, SWITCH_FALSE);
+                       switch_assert(buf);
+                       switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "CHANNEL_DATA:\n%s\n", buf);
+                       switch_event_destroy(&event);
+                       free(buf);
+               }
+       }
 
        g_template_str = (const char *) switch_core_hash_find(globals.template_hash, globals.default_template);
        
@@ -325,8 +375,9 @@ static switch_status_t load_config(switch_memory_pool_t *pool)
                        for (param = switch_xml_child(settings, "param"); param; param = param->next) {
                                char *var = (char *) switch_xml_attr_soft(param, "name");
                                char *val = (char *) switch_xml_attr_soft(param, "value");
-                       
-                               if (!strcasecmp(var, "log-base")) {
+                               if (!strcasecmp(var, "debug")) {
+                                       globals.debug = switch_true(val);
+                               } else if (!strcasecmp(var, "log-base")) {
                                        globals.log_dir = switch_core_sprintf(pool, "%s%scdr-csv", val, SWITCH_PATH_SEPARATOR);
                                } else if (!strcasecmp(var, "rotate-on-hup")) {
                                        globals.rotate = switch_true(val);
index 31244ed983fea4c8008862c556c665db5aa3ed73..1a69c22e963189d95cbf69019aca3622f0f16ba2 100644 (file)
@@ -162,7 +162,7 @@ static void event_handler(switch_event_t *event)
                        return;
                default:
                        switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Multicast-Sender", "%s", globals.hostname);
-                       if (switch_event_serialize(event, &packet) == SWITCH_STATUS_SUCCESS) {
+                       if (switch_event_serialize(event, &packet, SWITCH_TRUE) == SWITCH_STATUS_SUCCESS) {
                                memcpy(buf, &globals.host_hash, sizeof(globals.host_hash));
                                switch_copy_string(buf + sizeof(globals.host_hash), packet, sizeof(buf) - sizeof(globals.host_hash));
                                len = strlen(packet) + sizeof(globals.host_hash);;
index 98ecbb8377fadd5c66d3c47575322b0f938974c7..5b40dc721311fcc3216ea311d245f9ee77aea1e6 100644 (file)
@@ -471,7 +471,7 @@ static switch_status_t read_packet(listener_t * listener, switch_event_t **event
                                        do_sleep = 0;
                                        if (listener->format == EVENT_FORMAT_PLAIN) {
                                                etype = "plain";
-                                               switch_event_serialize(event, &listener->ebuf);
+                                               switch_event_serialize(event, &listener->ebuf, SWITCH_TRUE);
                                        } else {
                                                switch_xml_t xml;
                                                etype = "xml";
@@ -1049,7 +1049,7 @@ static void *SWITCH_THREAD_FUNC listener_run(switch_thread_t * thread, void *obj
                switch_event_add_header(call_event, SWITCH_STACK_BOTTOM, "Socket-Mode", switch_test_flag(listener, LFLAG_ASYNC) ? "async" : "static");
                switch_event_add_header(call_event, SWITCH_STACK_BOTTOM, "Control", switch_test_flag(listener, LFLAG_FULL) ? "full" : "single-channel");
 
-               switch_event_serialize(call_event, &event_str);
+               switch_event_serialize(call_event, &event_str, SWITCH_TRUE);
                if (!event_str) {
                        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Memory Error!\n");
                        switch_clear_flag_locked(listener, LFLAG_RUNNING);
index 7548bfa6e8bd8f2e5702c5f91fa4c3ef5b92ab41..4d065ba214e0f2926dfb2334cd153b9432830c73 100644 (file)
@@ -48,7 +48,7 @@ static void event_handler(switch_event_t *event)
        case SWITCH_EVENT_LOG:
                return;
        default:
-               switch_event_serialize(event, &buf);
+               switch_event_serialize(event, &buf, SWITCH_TRUE);
                if ((xml = switch_event_xmlize(event, NULL))) {
                        xmlstr = switch_xml_toxml(xml, SWITCH_FALSE);
                        dofree++;
index f6dd34c89103459141eb574279fdaa1148e9200e..b9780b2ab4f93779ef5fb1f9994fe453634a4330 100644 (file)
@@ -243,7 +243,7 @@ static JSBool request_dump_env(JSContext *cx, JSObject *obj, uintN argc, jsval *
         } 
        } else {
                char *buf;
-               switch_event_serialize(ro->stream->event, &buf);
+               switch_event_serialize(ro->stream->event, &buf, SWITCH_TRUE);
                if (buf) {
                        *rval = STRING_TO_JSVAL(JS_NewStringCopyZ(cx, buf));
                        free(buf);
@@ -654,7 +654,7 @@ static JSBool event_serialize(JSContext * cx, JSObject * obj, uintN argc, jsval
                        *rval = BOOLEAN_TO_JSVAL(JS_FALSE);
                }
        } else {
-               if (switch_event_serialize(eo->event, &buf) == SWITCH_STATUS_SUCCESS) {
+               if (switch_event_serialize(eo->event, &buf, SWITCH_TRUE) == SWITCH_STATUS_SUCCESS) {
                        *rval = STRING_TO_JSVAL(JS_NewStringCopyZ(cx, buf));
                        switch_safe_free(buf);
                }
index b5c80936627f8512d17c7ee85b114e90b1f1f599..5918dd1de3e793d071d7005518b98267cb8b6c7c 100644 (file)
@@ -706,7 +706,7 @@ SWITCH_DECLARE(switch_status_t) switch_event_dup(switch_event_t **event, switch_
        return SWITCH_STATUS_SUCCESS;
 }
 
-SWITCH_DECLARE(switch_status_t) switch_event_serialize(switch_event_t *event, char **str)
+SWITCH_DECLARE(switch_status_t) switch_event_serialize(switch_event_t *event, char **str, switch_bool_t encode)
 {
        switch_size_t len = 0;
        switch_event_header_t *hp;
@@ -758,7 +758,11 @@ SWITCH_DECLARE(switch_status_t) switch_event_serialize(switch_event_t *event, ch
                }
 
                /* handle any bad things in the string like newlines : etc that screw up the serialized format */
-               switch_url_encode(hp->value, encode_buf, encode_len - 1);
+               if (encode) {
+                       switch_url_encode(hp->value, encode_buf, encode_len - 1);
+               } else {
+                       snprintf(encode_buf, encode_len, "[%s]", hp->value);
+               }
 
                llen = strlen(hp->name) + strlen(encode_buf) + 8;