this should handle all cases now

git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@13869 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
Raymond Chandler 2009-06-19 17:48:49 +00:00
parent 1688e31e6a
commit fa7b79e19c
1 changed files with 33 additions and 21 deletions

View File

@ -34,7 +34,7 @@
#include <switch_odbc.h> #include <switch_odbc.h>
#define LCR_SYNTAX "lcr <digits> [<lcr profile>] [caller_id]" #define LCR_SYNTAX "lcr <digits> [<lcr profile>] [caller_id] [intrastate]"
#define LCR_ADMIN_SYNTAX "lcr_admin show profiles" #define LCR_ADMIN_SYNTAX "lcr_admin show profiles"
/* SQL Query places */ /* SQL Query places */
@ -640,7 +640,6 @@ static switch_status_t lcr_do_lookup(callback_t *cb_struct)
switch_channel_t *channel; switch_channel_t *channel;
char *id_str; char *id_str;
char *safe_sql = NULL; char *safe_sql = NULL;
const char *intra = NULL;
char *rate_field = NULL; char *rate_field = NULL;
switch_assert(cb_struct->lookup_number != NULL); switch_assert(cb_struct->lookup_number != NULL);
@ -658,17 +657,19 @@ static switch_status_t lcr_do_lookup(callback_t *cb_struct)
digits_expanded = expand_digits(cb_struct->pool, digits_copy, cb_struct->profile->quote_in_list); digits_expanded = expand_digits(cb_struct->pool, digits_copy, cb_struct->profile->quote_in_list);
/* set our rate field based on env and profile */
if (cb_struct->intrastate == SWITCH_TRUE && profile->profile_has_intra == SWITCH_TRUE) {
rate_field = switch_core_strdup(cb_struct->pool, "intra");
} else {
rate_field = switch_core_strdup(cb_struct->pool, "rate");
}
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "intrastate routing [%d] so rate field is [%s]\n",
cb_struct->intrastate, rate_field);
/* set some channel vars if we have a session */ /* set some channel vars if we have a session */
if (cb_struct->session) { if (cb_struct->session) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "we have a session\n"); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "we have a session\n");
if ((channel = switch_core_session_get_channel(cb_struct->session))) { if ((channel = switch_core_session_get_channel(cb_struct->session))) {
intra = switch_channel_get_variable(channel, "intrastate");
if (switch_strlen_zero(intra) || strcasecmp((char *)intra, "true") || profile->profile_has_intra == SWITCH_FALSE) {
rate_field = switch_core_strdup(cb_struct->pool, "rate");
} else {
rate_field = switch_core_strdup(cb_struct->pool, "intra");
}
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "intrastate routing [%s] so rate field is [%s]\n", intra, rate_field);
switch_channel_set_variable_var_check(channel, "lcr_rate_field", rate_field, SWITCH_FALSE); switch_channel_set_variable_var_check(channel, "lcr_rate_field", rate_field, SWITCH_FALSE);
switch_channel_set_variable_var_check(channel, "lcr_query_digits", digits_copy, SWITCH_FALSE); switch_channel_set_variable_var_check(channel, "lcr_query_digits", digits_copy, SWITCH_FALSE);
id_str = switch_core_sprintf(cb_struct->pool, "%d", cb_struct->profile->id); id_str = switch_core_sprintf(cb_struct->pool, "%d", cb_struct->profile->id);
@ -677,14 +678,7 @@ static switch_status_t lcr_do_lookup(callback_t *cb_struct)
} }
} }
if (cb_struct->event) { if (cb_struct->event) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "we have an event"); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "we have an event\n");
intra = switch_event_get_header(cb_struct->event, "intrastate");
if (switch_strlen_zero(intra) || strcasecmp((char *)intra, "true") || profile->profile_has_intra == SWITCH_FALSE) {
rate_field = switch_core_strdup(cb_struct->pool, "rate");
} else {
rate_field = switch_core_strdup(cb_struct->pool, "intra");
}
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "intrastate routing [%s] so rate field is [%s]\n", intra, rate_field);
switch_event_add_header_string(cb_struct->event, SWITCH_STACK_BOTTOM, "lcr_rate_field", rate_field); switch_event_add_header_string(cb_struct->event, SWITCH_STACK_BOTTOM, "lcr_rate_field", rate_field);
switch_event_add_header_string(cb_struct->event, SWITCH_STACK_BOTTOM, "lcr_query_digits", digits_copy); switch_event_add_header_string(cb_struct->event, SWITCH_STACK_BOTTOM, "lcr_query_digits", digits_copy);
id_str = switch_core_sprintf(cb_struct->pool, "%d", cb_struct->profile->id); id_str = switch_core_sprintf(cb_struct->pool, "%d", cb_struct->profile->id);
@ -692,11 +686,7 @@ static switch_status_t lcr_do_lookup(callback_t *cb_struct)
switch_event_add_header_string(cb_struct->event, SWITCH_STACK_BOTTOM, "lcr_query_expanded_digits", digits_expanded); switch_event_add_header_string(cb_struct->event, SWITCH_STACK_BOTTOM, "lcr_query_expanded_digits", digits_expanded);
} }
if (!cb_struct->session && !cb_struct->session) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "We have no session and no event, we need to set rate_field somewhere now\n");
}
/* set up the query to be executed */ /* set up the query to be executed */
/* format the custom_sql */ /* format the custom_sql */
safe_sql = format_custom_sql(profile->custom_sql, cb_struct, digits_copy); safe_sql = format_custom_sql(profile->custom_sql, cb_struct, digits_copy);
if (!safe_sql) { if (!safe_sql) {
@ -997,6 +987,7 @@ SWITCH_STANDARD_DIALPLAN(lcr_dialplan_hunt)
char *lcr_profile = NULL; char *lcr_profile = NULL;
switch_memory_pool_t *pool = NULL; switch_memory_pool_t *pool = NULL;
switch_event_t *event = NULL; switch_event_t *event = NULL;
const char *intra = NULL;
if (session) { if (session) {
pool = switch_core_session_get_pool(session); pool = switch_core_session_get_pool(session);
@ -1011,6 +1002,16 @@ SWITCH_STANDARD_DIALPLAN(lcr_dialplan_hunt)
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Unknown profile: %s\n", lcr_profile); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Unknown profile: %s\n", lcr_profile);
goto end; goto end;
} }
intra = switch_channel_get_variable(channel, "intrastate");
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "intrastate channel var is [%s]\n", intra);
if (switch_strlen_zero(intra) || strcasecmp((char *)intra, "true")) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Select routes based on interstate rates\n");
routes.intrastate = SWITCH_FALSE;
} else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Select routes based on intrastate rates\n");
routes.intrastate = SWITCH_TRUE;
}
if (!caller_profile) { if (!caller_profile) {
caller_profile = switch_channel_get_caller_profile(channel); caller_profile = switch_channel_get_caller_profile(channel);
@ -1073,6 +1074,7 @@ SWITCH_STANDARD_APP(lcr_app_function)
lcr_route cur_route = { 0 }; lcr_route cur_route = { 0 };
switch_memory_pool_t *pool; switch_memory_pool_t *pool;
switch_event_t *event; switch_event_t *event;
const char *intra = NULL;
if (!(mydata = switch_core_session_strdup(session, data))) { if (!(mydata = switch_core_session_strdup(session, data))) {
return; return;
@ -1088,6 +1090,16 @@ SWITCH_STANDARD_APP(lcr_app_function)
} }
routes.pool = pool; routes.pool = pool;
intra = switch_channel_get_variable(channel, "intrastate");
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "intrastate channel var is [%s]\n", intra);
if (switch_strlen_zero(intra) || strcasecmp((char *)intra, "true")) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Select routes based on interstate rates\n");
routes.intrastate = SWITCH_FALSE;
} else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Select routes based on intrastate rates\n");
routes.intrastate = SWITCH_TRUE;
}
if (!caller_profile) { if (!caller_profile) {
if (!(caller_profile = switch_channel_get_caller_profile(channel))) { if (!(caller_profile = switch_channel_get_caller_profile(channel))) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Unable to locate caller_profile\n"); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Unable to locate caller_profile\n");