refactor xml cdr and some cleanup

git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@5778 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
Anthony Minessale 2007-10-02 16:38:15 +00:00
parent ff61ecfc73
commit cbac77fa9f
5 changed files with 57 additions and 36 deletions

View File

@ -229,12 +229,13 @@ SWITCH_STANDARD_APP(fifo_function)
}
switch_channel_answer(channel);
cloned_profile = switch_caller_profile_clone(session, switch_channel_get_caller_profile(channel));
cloned_profile = switch_caller_profile_clone(other_session, switch_channel_get_caller_profile(channel));
assert(cloned_profile);
switch_channel_set_originator_caller_profile(other_channel, cloned_profile);
cloned_profile = switch_caller_profile_clone(other_session, switch_channel_get_caller_profile(channel));
cloned_profile = switch_caller_profile_clone(session, switch_channel_get_caller_profile(other_channel));
assert(cloned_profile);
assert(cloned_profile->next == NULL);
switch_channel_set_originatee_caller_profile(channel, cloned_profile);
switch_ivr_multi_threaded_bridge(session, other_session, on_dtmf, other_session, session);

View File

@ -36,8 +36,8 @@
static struct {
char *cred;
char *url;
char *logDir;
char *errLogDir;
char *log_dir;
char *err_log_dir;
uint32_t delay;
uint32_t retries;
uint32_t shutdown;
@ -75,7 +75,7 @@ static switch_status_t my_on_hangup(switch_core_session_t *session)
if (switch_ivr_generate_xml_cdr(session, &cdr) == SWITCH_STATUS_SUCCESS) {
/* build the XML */
if(!(xml_text = switch_mprintf("<?xml version=\"1.0\"?>\n%s",switch_xml_toxml(cdr)) )) {
if(!(xml_text = switch_xml_toxml(cdr))) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Memory Error!\n");
goto error;
}
@ -84,11 +84,11 @@ static switch_status_t my_on_hangup(switch_core_session_t *session)
/* all previous functionality is retained */
if (!(logdir = switch_channel_get_variable(channel, "xml_cdr_base"))) {
logdir = globals.logDir;
logdir = globals.log_dir;
}
if(!switch_strlen_zero(logdir)) {
if ((path = switch_mprintf("%s/xml_cdr/%s.cdr.xml", logdir, switch_core_session_get_uuid(session)))) {
if ((path = switch_mprintf("%s/%s.cdr.xml", logdir, switch_core_session_get_uuid(session)))) {
if ((fd = open(path, O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR)) > -1) {
int wrote;
wrote = write(fd, xml_text, (unsigned) strlen(xml_text));
@ -101,7 +101,7 @@ static switch_status_t my_on_hangup(switch_core_session_t *session)
#else
strerror_r(errno, ebuf, sizeof(ebuf));
#endif
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error![%s]\n", ebuf);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error writing [%s][%s]\n", path, ebuf);
}
switch_safe_free(path);
}
@ -163,7 +163,7 @@ static switch_status_t my_on_hangup(switch_core_session_t *session)
/* if we are here the web post failed for some reason */
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Unable to post to web server, writing to file\n");
if ((path = switch_mprintf("%s/%s.cdr.xml", globals.errLogDir, switch_core_session_get_uuid(session)))) {
if ((path = switch_mprintf("%s/%s.cdr.xml", globals.err_log_dir, switch_core_session_get_uuid(session)))) {
if ((fd = open(path, O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR)) > -1) {
int wrote;
wrote = write(fd, xml_text, (unsigned) strlen(xml_text));
@ -229,6 +229,9 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_xml_cdr_load)
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "open of %s failed\n", cf);
return SWITCH_STATUS_TERM;
}
globals.log_dir = switch_mprintf("%s/xml_cdr", SWITCH_GLOBAL_dirs.log_dir);
globals.err_log_dir = strdup(globals.log_dir);
if ((settings = switch_xml_child(cfg, "settings"))) {
for (param = switch_xml_child(settings, "param"); param; param = param->next) {
@ -243,14 +246,20 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_xml_cdr_load)
globals.delay = (uint32_t) atoi(val);
} else if (!strcasecmp(var, "retries")) {
globals.retries = (uint32_t) atoi(val);
} else if (!strcasecmp(var, "logDir")) {
if (switch_strlen_zero(val)) {
globals.logDir = SWITCH_GLOBAL_dirs.log_dir;
} else if (!strcasecmp(var, "log-dir")) {
switch_safe_free(globals.log_dir);
if (switch_is_file_path(val)) {
globals.log_dir = strdup(val);
} else {
globals.logDir = strdup(val);
globals.log_dir = switch_mprintf("%s/%s", SWITCH_GLOBAL_dirs.log_dir, val);
}
} else if (!strcasecmp(var, "err-log-dir")) {
switch_safe_free(globals.err_log_dir);
if (switch_is_file_path(val)) {
globals.err_log_dir = strdup(val);
} else {
globals.err_log_dir = switch_mprintf("%s/%s", SWITCH_GLOBAL_dirs.log_dir, val);
}
} else if (!strcasecmp(var, "errLogDir")) {
globals.errLogDir = strdup(val);
}
}
@ -265,17 +274,7 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_xml_cdr_load)
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "retries set but delay 0 setting to 5000ms\n");
globals.delay = 5000;
}
if(!switch_strlen_zero(globals.url) && switch_strlen_zero(globals.errLogDir)) {
if ((globals.errLogDir = switch_mprintf("%s/xml_cdr", SWITCH_GLOBAL_dirs.log_dir))) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Memory Error!\n");
status = SWITCH_STATUS_FALSE;
goto done;
}
}
done:
switch_xml_free(xml);
return status;
}

View File

@ -886,6 +886,7 @@ SWITCH_DECLARE(void) switch_channel_set_originator_caller_profile(switch_channel
caller_profile->next = channel->caller_profile->originator_caller_profile;
channel->caller_profile->originator_caller_profile = caller_profile;
}
assert(channel->caller_profile->originator_caller_profile->next != channel->caller_profile->originator_caller_profile);
switch_mutex_unlock(channel->profile_mutex);
}
@ -898,6 +899,7 @@ SWITCH_DECLARE(void) switch_channel_set_originatee_caller_profile(switch_channel
caller_profile->next = channel->caller_profile->originatee_caller_profile;
channel->caller_profile->originatee_caller_profile = caller_profile;
}
assert(channel->caller_profile->originatee_caller_profile->next != channel->caller_profile->originatee_caller_profile);
switch_mutex_unlock(channel->profile_mutex);
}

View File

@ -1275,15 +1275,15 @@ static int set_profile_data(switch_xml_t xml, switch_caller_profile_t *caller_pr
}
switch_xml_set_txt(param, caller_profile->chan_name);
return 0;
return off;
}
SWITCH_DECLARE(switch_status_t) switch_ivr_generate_xml_cdr(switch_core_session_t *session, switch_xml_t * xml_cdr)
{
switch_channel_t *channel;
switch_caller_profile_t *caller_profile;
switch_xml_t variable, variables, cdr, x_caller_profile, x_caller_extension, x_times, time_tag,
x_application, x_callflow, x_inner_extension, x_apps;
switch_xml_t variable, 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;
switch_app_log_t *app_log;
switch_event_header_t *hi;
char tmp[512];
@ -1343,6 +1343,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_generate_xml_cdr(switch_core_session_
while (caller_profile) {
int cf_off = 0;
int cp_off = 0;
if (!(x_callflow = switch_xml_add_child_d(cdr, "callflow", cdr_off++))) {
goto error;
@ -1356,6 +1357,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_generate_xml_cdr(switch_core_session_
if (!(x_caller_extension = switch_xml_add_child_d(x_callflow, "extension", cf_off++))) {
goto error;
}
switch_xml_set_attr_d(x_caller_extension, "name", caller_profile->caller_extension->extension_name);
switch_xml_set_attr_d(x_caller_extension, "number", caller_profile->caller_extension->extension_number);
if (caller_profile->caller_extension->current_application) {
@ -1413,23 +1415,39 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_generate_xml_cdr(switch_core_session_
}
if (!(x_caller_profile = switch_xml_add_child_d(x_callflow, "caller_profile", cf_off++))) {
if (!(x_main_cp = switch_xml_add_child_d(x_callflow, "caller_profile", cf_off++))) {
goto error;
}
set_profile_data(x_caller_profile, caller_profile, 0);
cp_off += set_profile_data(x_main_cp, caller_profile, 0);
if (caller_profile->originator_caller_profile) {
if (!(x_caller_profile = switch_xml_add_child_d(x_callflow, "originator_caller_profile", cf_off++))) {
switch_caller_profile_t *cp = NULL;
int off = 0;
if (!(x_o = switch_xml_add_child_d(x_main_cp, "originator", cp_off++))) {
goto error;
}
set_profile_data(x_caller_profile, caller_profile->originator_caller_profile, 0);
for (cp = caller_profile->originator_caller_profile; cp; cp = cp->next) {
if (!(x_caller_profile = switch_xml_add_child_d(x_o, "originator_caller_profile", off++))) {
goto error;
}
set_profile_data(x_caller_profile, cp, 0);
}
}
if (caller_profile->originatee_caller_profile) {
if (!(x_caller_profile = switch_xml_add_child_d(x_callflow, "originatee_caller_profile", cf_off++))) {
switch_caller_profile_t *cp = NULL;
int off = 0;
if (!(x_o = switch_xml_add_child_d(x_main_cp, "originatee", cp_off++))) {
goto error;
}
set_profile_data(x_caller_profile, caller_profile->originatee_caller_profile, 0);
for (cp = caller_profile->originatee_caller_profile; cp; cp = cp->next) {
if (!(x_caller_profile = switch_xml_add_child_d(x_o, "originatee_caller_profile", off++))) {
goto error;
}
set_profile_data(x_caller_profile, caller_profile->originatee_caller_profile, 0);
}
}

View File

@ -1523,8 +1523,9 @@ SWITCH_DECLARE(char *) switch_xml_toxml(switch_xml_t xml)
s = malloc(max);
assert(s != NULL);
memset(s, 0, max);
len = sprintf(s, "<?xml version=\"1.0\"?>\n");
if (!xml || !xml->name) {
if (!(r = realloc(s, len + 1))) {
abort();