add more data to cdr_csv and debug option to dump all the vars
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@6677 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
parent
ce4755c362
commit
70c65fc3c2
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
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 @@ 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);
|
||||
|
|
|
@ -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);;
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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++;
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
Loading…
Reference in New Issue