]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
FS-6803 try this, less is more
authorBrian West <brian@freeswitch.org>
Thu, 25 Sep 2014 20:10:11 +0000 (15:10 -0500)
committerBrian West <brian@freeswitch.org>
Thu, 25 Sep 2014 20:10:11 +0000 (15:10 -0500)
src/mod/applications/mod_translate/mod_translate.c

index 7180ea1d6baf346d7d30b71304cea36412933404..61feecd36da06e3386e0b407dd967c0d6e060e49 100644 (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;