FS-5845 --resolve

This commit is contained in:
Raymond Chandler 2014-02-17 10:33:00 -05:00
parent 3162635dc9
commit f826b4b6de

View File

@ -244,14 +244,14 @@ static const char *do_cid(switch_memory_pool_t *pool, const char *cid, const cha
done: done:
switch_regex_safe_free(re); switch_regex_safe_free(re);
switch_safe_free(tmp_regex);
return number; return number;
} }
static char *get_bridge_data(switch_memory_pool_t *pool, char *dialed_number, char *caller_id, lcr_route cur_route, profile_t *profile, switch_core_session_t *session) static char *get_bridge_data(switch_memory_pool_t *pool, char *dialed_number, char *caller_id, lcr_route cur_route, profile_t *profile, switch_core_session_t *session, char *data)
{ {
size_t lstrip; size_t lstrip;
size_t tstrip; size_t tstrip;
char *data = NULL;
char *destination_number = NULL; char *destination_number = NULL;
char *codec = NULL; char *codec = NULL;
char *cid = NULL; char *cid = NULL;
@ -270,8 +270,8 @@ static char *get_bridge_data(switch_memory_pool_t *pool, char *dialed_number, ch
} }
else { else {
destination_number[0] = '\0'; destination_number[0] = '\0';
} }
} }
if (cur_route->lstrip > 0) { if (cur_route->lstrip > 0) {
if (strlen(destination_number) > lstrip) { if (strlen(destination_number) > lstrip) {
destination_number += lstrip; destination_number += lstrip;
@ -340,6 +340,7 @@ static char *get_bridge_data(switch_memory_pool_t *pool, char *dialed_number, ch
} }
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Returning Dialstring %s\n", data); switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Returning Dialstring %s\n", data);
return data; return data;
} }
@ -548,14 +549,12 @@ static char *expand_digits(switch_memory_pool_t *pool, char *digits, switch_bool
/* format the custom sql */ /* format the custom sql */
static char *format_custom_sql(const char *custom_sql, callback_t *cb_struct, const char *digits) static char *format_custom_sql(const char *custom_sql, callback_t *cb_struct, const char *digits)
{ {
char * tmpSQL = NULL;
char * newSQL = NULL; char * newSQL = NULL;
switch_channel_t *channel; switch_channel_t *channel;
/* first replace %s with digits to maintain backward compat */ /* first replace %s with digits to maintain backward compat */
if (cb_struct->profile->custom_sql_has_percent == SWITCH_TRUE) { if (cb_struct->profile->custom_sql_has_percent == SWITCH_TRUE) {
tmpSQL = switch_string_replace(custom_sql, "%q", digits); newSQL = switch_string_replace(custom_sql, "%q", digits);
newSQL = tmpSQL;
} }
/* expand the vars */ /* expand the vars */
@ -563,32 +562,22 @@ static char *format_custom_sql(const char *custom_sql, callback_t *cb_struct, co
if (cb_struct->session) { if (cb_struct->session) {
channel = switch_core_session_get_channel(cb_struct->session); channel = switch_core_session_get_channel(cb_struct->session);
switch_assert(channel); switch_assert(channel);
/* newSQL = switch_channel_expand_variables(channel, newSQL ? newSQL : custom_sql);
newSQL = switch_channel_expand_variables_escape(channel, custom_sql = newSQL;
tmpSQL ? tmpSQL : custom_sql,
escape_sql);
*/
newSQL = switch_channel_expand_variables(channel,
tmpSQL ? tmpSQL : custom_sql);
} else if (cb_struct->event) { } else if (cb_struct->event) {
/* use event system to expand vars */ /* use event system to expand vars */
newSQL = switch_event_expand_headers(cb_struct->event, tmpSQL ? tmpSQL : custom_sql); newSQL = switch_event_expand_headers(cb_struct->event, newSQL ? newSQL : custom_sql);
custom_sql = newSQL;
} else { } else {
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(cb_struct->session), SWITCH_LOG_CRIT, switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(cb_struct->session), SWITCH_LOG_CRIT,
"mod_lcr called without a valid session while using a custom_sql that has channel variables.\n"); "mod_lcr called without a valid session while using a custom_sql that has channel variables.\n");
} }
} }
if (tmpSQL != newSQL) {
switch_safe_free(tmpSQL);
}
if (newSQL == NULL) { if (newSQL == NULL) {
return (char *) custom_sql; switch_safe_free(newSQL);
} else {
return newSQL;
} }
return (char *) custom_sql;
} }
static switch_bool_t lcr_execute_sql_callback(char *sql, switch_core_db_callback_func_t callback, void *pdata) static switch_bool_t lcr_execute_sql_callback(char *sql, switch_core_db_callback_func_t callback, void *pdata)
@ -619,6 +608,7 @@ static int route_add_callback(void *pArg, int argc, char **argv, char **columnNa
char *key2 = NULL; char *key2 = NULL;
int i = 0; int i = 0;
int r = 0; int r = 0;
char *data = NULL;
switch_bool_t lcr_skipped = SWITCH_TRUE; /* assume we'll throw it away, paranoid about leak */ switch_bool_t lcr_skipped = SWITCH_TRUE; /* assume we'll throw it away, paranoid about leak */
switch_memory_pool_t *pool = cbt->pool; switch_memory_pool_t *pool = cbt->pool;
@ -675,7 +665,7 @@ static int route_add_callback(void *pArg, int argc, char **argv, char **columnNa
cbt->matches++; cbt->matches++;
additional->dialstring = get_bridge_data(pool, cbt->lookup_number, cbt->cid, additional, cbt->profile, cbt->session); additional->dialstring = get_bridge_data(pool, cbt->lookup_number, cbt->cid, additional, cbt->profile, cbt->session, data);
if (cbt->head == NULL) { if (cbt->head == NULL) {
if (cbt->max_rate && (cbt->max_rate < additional->rate)) { if (cbt->max_rate && (cbt->max_rate < additional->rate)) {
@ -806,15 +796,17 @@ static int route_add_callback(void *pArg, int argc, char **argv, char **columnNa
added to the route list */ added to the route list */
if (additional && additional->prev != NULL) { if (additional && additional->prev != NULL) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,
"additional->prev != NULL\n"); "additional->prev != NULL\n");
} }
if (current && current->next == additional) { if (current && current->next == additional) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,
"current->next == additional\n"); "current->next == additional\n");
} }
lcr_destroy(additional); lcr_destroy(additional);
} }
switch_safe_free(data);
return r; return r;
} }
@ -1207,14 +1199,14 @@ static switch_status_t lcr_load_config()
sql_stream.write_function(&sql_stream, sql_stream.write_function(&sql_stream,
"SELECT l.digits AS lcr_digits, c.carrier_name AS lcr_carrier_name, l.${lcr_rate_field} AS lcr_rate_field, \ "SELECT l.digits AS lcr_digits, c.carrier_name AS lcr_carrier_name, l.${lcr_rate_field} AS lcr_rate_field, \
cg.prefix AS lcr_gw_prefix, cg.suffix AS lcr_gw_suffix, l.lead_strip AS lcr_lead_strip, \ cg.prefix AS lcr_gw_prefix, cg.suffix AS lcr_gw_suffix, l.lead_strip AS lcr_lead_strip, \
l.trail_strip AS lcr_trail_strip, l.prefix AS lcr_prefix, l.suffix AS lcr_suffix, \ l.trail_strip AS lcr_trail_strip, l.prefix AS lcr_prefix, l.suffix AS lcr_suffix, \
cg.codec AS lcr_codec, l.cid AS lcr_cid "); cg.codec AS lcr_codec, l.cid AS lcr_cid ");
sql_stream.write_function(&sql_stream, "FROM lcr l JOIN carriers c ON l.carrier_id=c.id \ sql_stream.write_function(&sql_stream, "FROM lcr l JOIN carriers c ON l.carrier_id=c.id \
JOIN carrier_gateway cg ON c.id=cg.carrier_id \ JOIN carrier_gateway cg ON c.id=cg.carrier_id \
WHERE c.enabled = '1' AND cg.enabled = '1' AND l.enabled = '1' AND (\ WHERE c.enabled = '1' AND cg.enabled = '1' AND l.enabled = '1' AND (\
(digits IN (${lcr_query_expanded_digits}) AND lrn = false) OR \ (digits IN (${lcr_query_expanded_digits}) AND lrn = false) OR \
(digits IN (${lcr_query_expanded_lrn_digits}) AND lrn = true)"); (digits IN (${lcr_query_expanded_lrn_digits}) AND lrn = true)");
sql_stream.write_function(&sql_stream, ") AND CURRENT_TIMESTAMP BETWEEN date_start AND date_end "); sql_stream.write_function(&sql_stream, ") AND CURRENT_TIMESTAMP BETWEEN date_start AND date_end ");
if (profile->id > 0) { if (profile->id > 0) {
@ -1827,6 +1819,7 @@ SWITCH_STANDARD_API(dialplan_lcr_function)
char *event_str = NULL; char *event_str = NULL;
switch_xml_t event_xml = NULL; switch_xml_t event_xml = NULL;
int rowcount = 0; int rowcount = 0;
char *data = NULL;
if (zstr(cmd)) { if (zstr(cmd)) {
goto usage; goto usage;
@ -1946,7 +1939,7 @@ SWITCH_STANDARD_API(dialplan_lcr_function)
while (current) { while (current) {
//dialstring = //dialstring =
get_bridge_data(pool, cb_struct.lookup_number, cb_struct.cid, current, cb_struct.profile, cb_struct.session); get_bridge_data(pool, cb_struct.lookup_number, cb_struct.cid, current, cb_struct.profile, cb_struct.session, data);
rowcount++; rowcount++;
if (as_xml) { if (as_xml) {
@ -2010,6 +2003,7 @@ SWITCH_STANDARD_API(dialplan_lcr_function)
} }
end: end:
switch_safe_free(data);
lcr_destroy(cb_struct.head); lcr_destroy(cb_struct.head);
if (!session) { if (!session) {
if (pool) { if (pool) {