refactor in mod_dialplan_xml. Factor out a function for the hint string generation/xml_locate so that we do not need to generate the xml hint string when using a static file. Dont add blank items from the caller profile to the hint string.

git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@4766 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
Michael Jerris 2007-03-25 15:21:22 +00:00
parent b65f2273d0
commit 880f17d33b
1 changed files with 57 additions and 37 deletions

View File

@ -34,11 +34,8 @@
#include <sys/stat.h> #include <sys/stat.h>
#include <fcntl.h> #include <fcntl.h>
static const char modname[] = "mod_dialplan_xml"; static const char modname[] = "mod_dialplan_xml";
typedef enum { typedef enum {
BREAK_ON_TRUE, BREAK_ON_TRUE,
BREAK_ON_FALSE, BREAK_ON_FALSE,
@ -193,36 +190,26 @@ static int parse_exten(switch_core_session_t *session, switch_xml_t xexten, swit
return proceed; return proceed;
} }
static switch_caller_extension_t *dialplan_hunt(switch_core_session_t *session, void *arg) static switch_status_t dialplan_xml_locate(switch_core_session_t *session,
switch_caller_profile_t *caller_profile,
switch_xml_t *root,
switch_xml_t *node)
{ {
switch_caller_profile_t *caller_profile; switch_status_t status = SWITCH_STATUS_GENERR;
switch_caller_extension_t *extension = NULL;
switch_channel_t *channel; switch_channel_t *channel;
switch_xml_t alt_root = NULL, cfg, xml, xcontext, xexten;
char *context = NULL;
switch_stream_handle_t stream = {0}; switch_stream_handle_t stream = {0};
switch_size_t encode_len = 1024, new_len = 0; switch_size_t encode_len = 1024, new_len = 0;
char *encode_buf = NULL; char *encode_buf = NULL;
char *prof[12] = {0}, *prof_names[12] = {0}, *e = NULL; char *prof[12] = {0}, *prof_names[12] = {0}, *e = NULL;
switch_hash_index_t *hi; switch_hash_index_t *hi;
uint32_t x = 0; uint32_t x = 0;
char *alt_path = (char *) arg;
channel = switch_core_session_get_channel(session); channel = switch_core_session_get_channel(session);
if ((caller_profile = switch_channel_get_caller_profile(channel))) {
context = caller_profile->context ? caller_profile->context : "default";
} else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error Obtaining Profile!\n");
return NULL;
}
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Processing %s->%s!\n", caller_profile->caller_id_name,
caller_profile->destination_number);
SWITCH_STANDARD_STREAM(stream); SWITCH_STANDARD_STREAM(stream);
if (!(encode_buf = malloc(encode_len))) { if (!(encode_buf = malloc(encode_len))) {
return NULL; goto done;
} }
prof[0] = caller_profile->context; prof[0] = caller_profile->context;
@ -250,6 +237,9 @@ static switch_caller_extension_t *dialplan_hunt(switch_core_session_t *session,
prof_names[10] = "uuid"; prof_names[10] = "uuid";
for (x = 0; prof[x]; x++) { for (x = 0; prof[x]; x++) {
if (switch_strlen_zero(prof[x])) {
continue;
}
new_len = (strlen(prof[x]) * 3) + 1; new_len = (strlen(prof[x]) * 3) + 1;
if (encode_len < new_len) { if (encode_len < new_len) {
char *tmp; char *tmp;
@ -257,8 +247,7 @@ static switch_caller_extension_t *dialplan_hunt(switch_core_session_t *session,
encode_len = new_len; encode_len = new_len;
if (!(tmp = realloc(encode_buf, encode_len))) { if (!(tmp = realloc(encode_buf, encode_len))) {
switch_safe_free(encode_buf); goto done;
return NULL;
} }
encode_buf = tmp; encode_buf = tmp;
@ -280,8 +269,7 @@ static switch_caller_extension_t *dialplan_hunt(switch_core_session_t *session,
encode_len = new_len; encode_len = new_len;
if (!(tmp = realloc(encode_buf, encode_len))) { if (!(tmp = realloc(encode_buf, encode_len))) {
switch_safe_free(encode_buf); goto done;
return NULL;
} }
encode_buf = tmp; encode_buf = tmp;
@ -298,11 +286,43 @@ static switch_caller_extension_t *dialplan_hunt(switch_core_session_t *session,
*e = '\0'; *e = '\0';
} }
status = switch_xml_locate("dialplan", NULL, NULL, NULL, root, node, stream.data);
done:
switch_safe_free(stream.data);
switch_safe_free(encode_buf);
return status;
}
static switch_caller_extension_t *dialplan_hunt(switch_core_session_t *session, void *arg)
{
switch_caller_profile_t *caller_profile;
switch_caller_extension_t *extension = NULL;
switch_channel_t *channel;
switch_xml_t alt_root = NULL, cfg, xml = NULL, xcontext, xexten;
char *alt_path = (char *) arg;
channel = switch_core_session_get_channel(session);
if ((caller_profile = switch_channel_get_caller_profile(channel))) {
if (!caller_profile->context) {
caller_profile->context = "default";
}
} else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error Obtaining Profile!\n");
goto done;
}
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Processing %s->%s!\n", caller_profile->caller_id_name,
caller_profile->destination_number);
/* get our handle to the "dialplan" section of the config */
if (!switch_strlen_zero(alt_path)) { if (!switch_strlen_zero(alt_path)) {
switch_xml_t conf = NULL, tag = NULL; switch_xml_t conf = NULL, tag = NULL;
if (!(alt_root = switch_xml_parse_file(alt_path))) { if (!(alt_root = switch_xml_parse_file(alt_path))) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "open of [%s] failed\n", alt_path); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "open of [%s] failed\n", alt_path);
return NULL; goto done;
} }
if ((conf = switch_xml_find_child(alt_root, "section", "name", "dialplan")) && if ((conf = switch_xml_find_child(alt_root, "section", "name", "dialplan")) &&
@ -312,22 +332,20 @@ static switch_caller_extension_t *dialplan_hunt(switch_core_session_t *session,
cfg = tag; cfg = tag;
} else { } else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "open of dialplan failed\n"); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "open of dialplan failed\n");
return NULL; goto done;
} }
} else if (switch_xml_locate("dialplan", NULL, NULL, NULL, &xml, &cfg, stream.data) != SWITCH_STATUS_SUCCESS) { } else {
if (dialplan_xml_locate(session, caller_profile, &xml, &cfg) != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "open of dialplan failed\n"); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "open of dialplan failed\n");
return NULL; goto done;
}
} }
/* get a handle to the context tag */
switch_safe_free(stream.data); if (!(xcontext = switch_xml_find_child(cfg, "context", "name", caller_profile->context))) {
switch_safe_free(encode_buf);
if (!(xcontext = switch_xml_find_child(cfg, "context", "name", context))) {
if (!(xcontext = switch_xml_find_child(cfg, "context", "name", "global"))) { if (!(xcontext = switch_xml_find_child(cfg, "context", "name", "global"))) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "context %s not found\n", context); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "context %s not found\n", caller_profile->context);
switch_xml_free(xml); goto done;
return NULL;
} }
} }
@ -355,6 +373,8 @@ static switch_caller_extension_t *dialplan_hunt(switch_core_session_t *session,
switch_channel_set_state(channel, CS_EXECUTE); switch_channel_set_state(channel, CS_EXECUTE);
} }
done:
switch_xml_free(xml);
return extension; return extension;
} }