[Freeswitch-svn] [commit] r6677 - in freeswitch/trunk/src: . include mod/applications/mod_dptools mod/event_handlers/mod_cdr_csv mod/event_handlers/mod_event_multicast mod/event_handlers/mod_event_socket mod/event_handlers/mod_event_test mod/languages/mod_spidermonkey
Freeswitch SVN
anthm at freeswitch.org
Tue Dec 11 17:19:49 EST 2007
Author: anthm
Date: Tue Dec 11 17:19:49 2007
New Revision: 6677
Modified:
freeswitch/trunk/src/include/switch_event.h
freeswitch/trunk/src/mod/applications/mod_dptools/mod_dptools.c
freeswitch/trunk/src/mod/event_handlers/mod_cdr_csv/mod_cdr_csv.c
freeswitch/trunk/src/mod/event_handlers/mod_event_multicast/mod_event_multicast.c
freeswitch/trunk/src/mod/event_handlers/mod_event_socket/mod_event_socket.c
freeswitch/trunk/src/mod/event_handlers/mod_event_test/mod_event_test.c
freeswitch/trunk/src/mod/languages/mod_spidermonkey/mod_spidermonkey.c
freeswitch/trunk/src/switch_event.c
Log:
add more data to cdr_csv and debug option to dump all the vars
Modified: freeswitch/trunk/src/include/switch_event.h
==============================================================================
--- freeswitch/trunk/src/include/switch_event.h (original)
+++ freeswitch/trunk/src/include/switch_event.h Tue Dec 11 17:19:49 2007
@@ -242,10 +242,11 @@
\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
Modified: freeswitch/trunk/src/mod/applications/mod_dptools/mod_dptools.c
==============================================================================
--- freeswitch/trunk/src/mod/applications/mod_dptools/mod_dptools.c (original)
+++ freeswitch/trunk/src/mod/applications/mod_dptools/mod_dptools.c Tue Dec 11 17:19:49 2007
@@ -656,9 +656,11 @@
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);
}
}
Modified: freeswitch/trunk/src/mod/event_handlers/mod_cdr_csv/mod_cdr_csv.c
==============================================================================
--- freeswitch/trunk/src/mod/event_handlers/mod_cdr_csv/mod_cdr_csv.c (original)
+++ freeswitch/trunk/src/mod/event_handlers/mod_cdr_csv/mod_cdr_csv.c Tue Dec 11 17:19:49 2007
@@ -49,6 +49,7 @@
char *default_template;
int shutdown;
int rotate;
+ int debug;
} globals;
SWITCH_MODULE_LOAD_FUNCTION(mod_cdr_csv_load);
@@ -163,8 +164,10 @@
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 @@
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;
- }
+ switch_channel_set_variable(channel, "end_stamp", end);
- billsec = ((int32_t) caller_profile->times->hungup / 1000000) - ((int32_t) caller_profile->times->answered / 1000000);
- if (billsec < 0) {
- billsec = 0;
- }
+ 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 @@
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 @@
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);
Modified: freeswitch/trunk/src/mod/event_handlers/mod_event_multicast/mod_event_multicast.c
==============================================================================
--- freeswitch/trunk/src/mod/event_handlers/mod_event_multicast/mod_event_multicast.c (original)
+++ freeswitch/trunk/src/mod/event_handlers/mod_event_multicast/mod_event_multicast.c Tue Dec 11 17:19:49 2007
@@ -162,7 +162,7 @@
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);;
Modified: freeswitch/trunk/src/mod/event_handlers/mod_event_socket/mod_event_socket.c
==============================================================================
--- freeswitch/trunk/src/mod/event_handlers/mod_event_socket/mod_event_socket.c (original)
+++ freeswitch/trunk/src/mod/event_handlers/mod_event_socket/mod_event_socket.c Tue Dec 11 17:19:49 2007
@@ -471,7 +471,7 @@
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 @@
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);
Modified: freeswitch/trunk/src/mod/event_handlers/mod_event_test/mod_event_test.c
==============================================================================
--- freeswitch/trunk/src/mod/event_handlers/mod_event_test/mod_event_test.c (original)
+++ freeswitch/trunk/src/mod/event_handlers/mod_event_test/mod_event_test.c Tue Dec 11 17:19:49 2007
@@ -48,7 +48,7 @@
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++;
Modified: freeswitch/trunk/src/mod/languages/mod_spidermonkey/mod_spidermonkey.c
==============================================================================
--- freeswitch/trunk/src/mod/languages/mod_spidermonkey/mod_spidermonkey.c (original)
+++ freeswitch/trunk/src/mod/languages/mod_spidermonkey/mod_spidermonkey.c Tue Dec 11 17:19:49 2007
@@ -243,7 +243,7 @@
}
} 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 @@
*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);
}
Modified: freeswitch/trunk/src/switch_event.c
==============================================================================
--- freeswitch/trunk/src/switch_event.c (original)
+++ freeswitch/trunk/src/switch_event.c Tue Dec 11 17:19:49 2007
@@ -706,7 +706,7 @@
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 @@
}
/* 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;
More information about the Freeswitch-svn
mailing list