FS-6803 try this, less is more

This commit is contained in:
Brian West 2014-09-25 15:10:11 -05:00
parent 7d7223e931
commit 0767191769

View File

@ -117,9 +117,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], subbedlen = 0; int proceed = 0, ovector[30];
char *substituted = NULL, *subbed = NULL, *session_malloc = NULL; char *substituted = NULL, *subbed = NULL;
uint32_t len = 1024; uint32_t len = 0;
if (!profile) { if (!profile) {
profile = "US"; profile = "US";
@ -136,8 +136,8 @@ static void translate_number(char *number, char *profile, char **translated, swi
for (rule = hi; rule; rule = rule->next) { for (rule = hi; rule; rule = rule->next) {
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); len = (uint32_t) (strlen(number) + strlen(rule->replace) + 10) * proceed;
if (!(substituted = switch_core_session_alloc(session, len))) { if (!(substituted = malloc(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,16 +154,11 @@ static void translate_number(char *number, char *profile, char **translated, swi
subbed = switch_event_expand_headers(event, substituted); subbed = switch_event_expand_headers(event, substituted);
} }
subbedlen = strlen(subbed) + 1; substituted = switch_core_session_strdup(session, subbed);
session_malloc = (char *)switch_core_session_alloc(session, subbedlen);
memset(session_malloc, 0, subbedlen); if (subbed != substituted) {
strncpy(session_malloc, subbed, subbedlen);
if (subbed != substituted)
{
switch_safe_free(subbed); switch_safe_free(subbed);
} }
substituted = session_malloc;
} }
break; break;