FS-6803 #resolve

This commit is contained in:
Brian West 2014-09-08 11:25:48 -05:00 committed by Anthony Minessale
parent 9d68e99268
commit 51f4742087
1 changed files with 15 additions and 4 deletions

View File

@ -118,9 +118,9 @@ static void translate_number(char *number, char *profile, char **translated, swi
translate_rule_t *hi = NULL; translate_rule_t *hi = NULL;
translate_rule_t *rule = NULL; translate_rule_t *rule = NULL;
switch_regex_t *re = NULL; switch_regex_t *re = NULL;
int proceed = 0, ovector[30]; int proceed = 0, ovector[30], subbedlen = 0;
char *substituted = NULL; char *substituted = NULL, *subbed = NULL, *session_malloc = NULL;
uint32_t len = 0; uint32_t len = 1024;
if (!profile) { if (!profile) {
profile = "US"; profile = "US";
@ -138,7 +138,7 @@ static void translate_number(char *number, char *profile, char **translated, swi
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "%s =~ /%s/\n", number, rule->regex); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "%s =~ /%s/\n", number, rule->regex);
if ((proceed = switch_regex_perform(number, rule->regex, &re, ovector, sizeof(ovector) / sizeof(ovector[0])))) { if ((proceed = switch_regex_perform(number, rule->regex, &re, ovector, sizeof(ovector) / sizeof(ovector[0])))) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "%s matched %s, replacing with %s\n", number, rule->regex, rule->replace); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "%s matched %s, replacing with %s\n", number, rule->regex, rule->replace);
if (!(substituted = malloc(len))) { if (!(substituted = switch_core_session_alloc(session, len))) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Memory Error!\n"); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Memory Error!\n");
switch_regex_safe_free(re); switch_regex_safe_free(re);
goto end; goto end;
@ -154,6 +154,17 @@ static void translate_number(char *number, char *profile, char **translated, swi
} else if (event) { } else if (event) {
substituted = switch_event_expand_headers(event, substituted); substituted = switch_event_expand_headers(event, substituted);
} }
subbedlen = strlen(subbed) + 1;
session_malloc = (char *)switch_core_session_alloc(session, subbedlen);
memset(session_malloc, 0, subbedlen);
strncpy(session_malloc, subbed, subbedlen);
if (subbed != substituted)
{
switch_safe_free(subbed);
}
substituted = session_malloc;
} }
break; break;