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
1 changed files with 9 additions and 14 deletions

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 *rule = NULL;
switch_regex_t *re = NULL;
int proceed = 0, ovector[30], subbedlen = 0;
char *substituted = NULL, *subbed = NULL, *session_malloc = NULL;
uint32_t len = 1024;
int proceed = 0, ovector[30];
char *substituted = NULL, *subbed = NULL;
uint32_t len = 0;
if (!profile) {
profile = "US";
@ -136,14 +136,14 @@ static void translate_number(char *number, char *profile, char **translated, swi
for (rule = hi; rule; rule = rule->next) {
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])))) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "%s matched %s, replacing with %s\n", number, rule->regex, rule->replace);
if (!(substituted = switch_core_session_alloc(session, len))) {
len = (uint32_t) (strlen(number) + strlen(rule->replace) + 10) * proceed;
if (!(substituted = malloc(len))) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Memory Error!\n");
switch_regex_safe_free(re);
goto end;
}
memset(substituted, 0, len);
switch_perform_substitution(re, proceed, rule->replace, number, substituted, len, ovector);
if ((switch_string_var_check_const(substituted) || switch_string_has_escaped_data(substituted))) {
@ -154,16 +154,11 @@ static void translate_number(char *number, char *profile, char **translated, swi
subbed = 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)
{
substituted = switch_core_session_strdup(session, subbed);
if (subbed != substituted) {
switch_safe_free(subbed);
}
substituted = session_malloc;
}
break;