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); 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); assert(cloned_profile);
switch_channel_set_originator_caller_profile(other_channel, 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);
assert(cloned_profile->next == NULL);
switch_channel_set_originatee_caller_profile(channel, cloned_profile); switch_channel_set_originatee_caller_profile(channel, cloned_profile);
switch_ivr_multi_threaded_bridge(session, other_session, on_dtmf, other_session, session); switch_ivr_multi_threaded_bridge(session, other_session, on_dtmf, other_session, session);

View File

@ -36,8 +36,8 @@
static struct { static struct {
char *cred; char *cred;
char *url; char *url;
char *logDir; char *log_dir;
char *errLogDir; char *err_log_dir;
uint32_t delay; uint32_t delay;
uint32_t retries; uint32_t retries;
uint32_t shutdown; 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) { if (switch_ivr_generate_xml_cdr(session, &cdr) == SWITCH_STATUS_SUCCESS) {
/* build the XML */ /* 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"); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Memory Error!\n");
goto error; goto error;
} }
@ -84,11 +84,11 @@ static switch_status_t my_on_hangup(switch_core_session_t *session)
/* all previous functionality is retained */ /* all previous functionality is retained */
if (!(logdir = switch_channel_get_variable(channel, "xml_cdr_base"))) { if (!(logdir = switch_channel_get_variable(channel, "xml_cdr_base"))) {
logdir = globals.logDir; logdir = globals.log_dir;
} }
if(!switch_strlen_zero(logdir)) { 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) { if ((fd = open(path, O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR)) > -1) {
int wrote; int wrote;
wrote = write(fd, xml_text, (unsigned) strlen(xml_text)); 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 #else
strerror_r(errno, ebuf, sizeof(ebuf)); strerror_r(errno, ebuf, sizeof(ebuf));
#endif #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); 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 */ /* 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"); 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) { if ((fd = open(path, O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR)) > -1) {
int wrote; int wrote;
wrote = write(fd, xml_text, (unsigned) strlen(xml_text)); wrote = write(fd, xml_text, (unsigned) strlen(xml_text));
@ -230,6 +230,9 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_xml_cdr_load)
return SWITCH_STATUS_TERM; 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"))) { if ((settings = switch_xml_child(cfg, "settings"))) {
for (param = switch_xml_child(settings, "param"); param; param = param->next) { for (param = switch_xml_child(settings, "param"); param; param = param->next) {
char *var = (char *) switch_xml_attr_soft(param, "name"); char *var = (char *) switch_xml_attr_soft(param, "name");
@ -243,14 +246,20 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_xml_cdr_load)
globals.delay = (uint32_t) atoi(val); globals.delay = (uint32_t) atoi(val);
} else if (!strcasecmp(var, "retries")) { } else if (!strcasecmp(var, "retries")) {
globals.retries = (uint32_t) atoi(val); globals.retries = (uint32_t) atoi(val);
} else if (!strcasecmp(var, "logDir")) { } else if (!strcasecmp(var, "log-dir")) {
if (switch_strlen_zero(val)) { switch_safe_free(globals.log_dir);
globals.logDir = SWITCH_GLOBAL_dirs.log_dir; if (switch_is_file_path(val)) {
globals.log_dir = strdup(val);
} else { } 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);
} }
} }
@ -266,16 +275,6 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_xml_cdr_load)
globals.delay = 5000; 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); switch_xml_free(xml);
return status; 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; caller_profile->next = channel->caller_profile->originator_caller_profile;
channel->caller_profile->originator_caller_profile = 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); 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; caller_profile->next = channel->caller_profile->originatee_caller_profile;
channel->caller_profile->originatee_caller_profile = 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); 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); 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_DECLARE(switch_status_t) switch_ivr_generate_xml_cdr(switch_core_session_t *session, switch_xml_t * xml_cdr)
{ {
switch_channel_t *channel; switch_channel_t *channel;
switch_caller_profile_t *caller_profile; switch_caller_profile_t *caller_profile;
switch_xml_t variable, variables, cdr, x_caller_profile, x_caller_extension, x_times, time_tag, 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_application, x_callflow, x_inner_extension, x_apps, x_o;
switch_app_log_t *app_log; switch_app_log_t *app_log;
switch_event_header_t *hi; switch_event_header_t *hi;
char tmp[512]; char tmp[512];
@ -1343,6 +1343,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_generate_xml_cdr(switch_core_session_
while (caller_profile) { while (caller_profile) {
int cf_off = 0; int cf_off = 0;
int cp_off = 0;
if (!(x_callflow = switch_xml_add_child_d(cdr, "callflow", cdr_off++))) { if (!(x_callflow = switch_xml_add_child_d(cdr, "callflow", cdr_off++))) {
goto error; 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++))) { if (!(x_caller_extension = switch_xml_add_child_d(x_callflow, "extension", cf_off++))) {
goto error; 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, "name", caller_profile->caller_extension->extension_name);
switch_xml_set_attr_d(x_caller_extension, "number", caller_profile->caller_extension->extension_number); switch_xml_set_attr_d(x_caller_extension, "number", caller_profile->caller_extension->extension_number);
if (caller_profile->caller_extension->current_application) { if (caller_profile->caller_extension->current_application) {
@ -1413,24 +1415,40 @@ 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; 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 (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; 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 (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;
}
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; goto error;
} }
set_profile_data(x_caller_profile, caller_profile->originatee_caller_profile, 0); set_profile_data(x_caller_profile, caller_profile->originatee_caller_profile, 0);
} }
}
if (caller_profile->times) { if (caller_profile->times) {

View File

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