mirror of
https://github.com/signalwire/freeswitch.git
synced 2025-04-15 16:39:14 +00:00
FS-5845 --resolve
This commit is contained in:
parent
3162635dc9
commit
f826b4b6de
@ -244,14 +244,14 @@ static const char *do_cid(switch_memory_pool_t *pool, const char *cid, const cha
|
||||
|
||||
done:
|
||||
switch_regex_safe_free(re);
|
||||
switch_safe_free(tmp_regex);
|
||||
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 tstrip;
|
||||
char *data = NULL;
|
||||
char *destination_number = NULL;
|
||||
char *codec = NULL;
|
||||
char *cid = NULL;
|
||||
@ -270,8 +270,8 @@ static char *get_bridge_data(switch_memory_pool_t *pool, char *dialed_number, ch
|
||||
}
|
||||
else {
|
||||
destination_number[0] = '\0';
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (cur_route->lstrip > 0) {
|
||||
if (strlen(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);
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
@ -548,14 +549,12 @@ static char *expand_digits(switch_memory_pool_t *pool, char *digits, switch_bool
|
||||
/* format the custom sql */
|
||||
static char *format_custom_sql(const char *custom_sql, callback_t *cb_struct, const char *digits)
|
||||
{
|
||||
char * tmpSQL = NULL;
|
||||
char * newSQL = NULL;
|
||||
switch_channel_t *channel;
|
||||
|
||||
/* first replace %s with digits to maintain backward compat */
|
||||
if (cb_struct->profile->custom_sql_has_percent == SWITCH_TRUE) {
|
||||
tmpSQL = switch_string_replace(custom_sql, "%q", digits);
|
||||
newSQL = tmpSQL;
|
||||
newSQL = switch_string_replace(custom_sql, "%q", digits);
|
||||
}
|
||||
|
||||
/* 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) {
|
||||
channel = switch_core_session_get_channel(cb_struct->session);
|
||||
switch_assert(channel);
|
||||
/*
|
||||
newSQL = switch_channel_expand_variables_escape(channel,
|
||||
tmpSQL ? tmpSQL : custom_sql,
|
||||
escape_sql);
|
||||
*/
|
||||
newSQL = switch_channel_expand_variables(channel,
|
||||
tmpSQL ? tmpSQL : custom_sql);
|
||||
newSQL = switch_channel_expand_variables(channel, newSQL ? newSQL : custom_sql);
|
||||
custom_sql = newSQL;
|
||||
} else if (cb_struct->event) {
|
||||
/* 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 {
|
||||
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");
|
||||
}
|
||||
}
|
||||
|
||||
if (tmpSQL != newSQL) {
|
||||
switch_safe_free(tmpSQL);
|
||||
}
|
||||
|
||||
if (newSQL == NULL) {
|
||||
return (char *) custom_sql;
|
||||
} else {
|
||||
return newSQL;
|
||||
switch_safe_free(newSQL);
|
||||
}
|
||||
return (char *) custom_sql;
|
||||
}
|
||||
|
||||
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;
|
||||
int i = 0;
|
||||
int r = 0;
|
||||
char *data = NULL;
|
||||
switch_bool_t lcr_skipped = SWITCH_TRUE; /* assume we'll throw it away, paranoid about leak */
|
||||
|
||||
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++;
|
||||
|
||||
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->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 */
|
||||
if (additional && additional->prev != NULL) {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,
|
||||
"additional->prev != NULL\n");
|
||||
"additional->prev != NULL\n");
|
||||
}
|
||||
if (current && current->next == additional) {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,
|
||||
"current->next == additional\n");
|
||||
"current->next == additional\n");
|
||||
}
|
||||
lcr_destroy(additional);
|
||||
}
|
||||
|
||||
switch_safe_free(data);
|
||||
|
||||
return r;
|
||||
|
||||
}
|
||||
@ -1207,14 +1199,14 @@ static switch_status_t lcr_load_config()
|
||||
|
||||
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, \
|
||||
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, \
|
||||
cg.codec AS lcr_codec, l.cid AS lcr_cid ");
|
||||
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, \
|
||||
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 \
|
||||
JOIN carrier_gateway cg ON c.id=cg.carrier_id \
|
||||
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_lrn_digits}) AND lrn = true)");
|
||||
JOIN carrier_gateway cg ON c.id=cg.carrier_id \
|
||||
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_lrn_digits}) AND lrn = true)");
|
||||
|
||||
sql_stream.write_function(&sql_stream, ") AND CURRENT_TIMESTAMP BETWEEN date_start AND date_end ");
|
||||
if (profile->id > 0) {
|
||||
@ -1827,6 +1819,7 @@ SWITCH_STANDARD_API(dialplan_lcr_function)
|
||||
char *event_str = NULL;
|
||||
switch_xml_t event_xml = NULL;
|
||||
int rowcount = 0;
|
||||
char *data = NULL;
|
||||
|
||||
if (zstr(cmd)) {
|
||||
goto usage;
|
||||
@ -1946,7 +1939,7 @@ SWITCH_STANDARD_API(dialplan_lcr_function)
|
||||
while (current) {
|
||||
|
||||
//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++;
|
||||
|
||||
if (as_xml) {
|
||||
@ -2010,6 +2003,7 @@ SWITCH_STANDARD_API(dialplan_lcr_function)
|
||||
}
|
||||
|
||||
end:
|
||||
switch_safe_free(data);
|
||||
lcr_destroy(cb_struct.head);
|
||||
if (!session) {
|
||||
if (pool) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user