]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
mod_translate
authorAndrey Volk <andywolk@gmail.com>
Sat, 12 Jul 2025 19:10:09 +0000 (19:10 +0000)
committerAndrey Volk <andywolk@gmail.com>
Sat, 12 Jul 2025 22:35:22 +0000 (01:35 +0300)
src/mod/applications/mod_translate/mod_translate.c

index 34b1ad54fc9f9d973c64d884c69a8fed6b77b91b..cc31b1f8ea32324f8f1a5f4052bacf2f88621554 100644 (file)
@@ -117,7 +117,8 @@ 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];
+       switch_regex_match_t *match_data = NULL;
+       int proceed = 0;
        char *substituted = NULL, *subbed = NULL;
        uint32_t len = 0;
 
@@ -136,17 +137,18 @@ 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])))) {
+               if ((proceed = switch_regex_perform(number, rule->regex, &re, &match_data))) {
                        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_match_safe_free(match_data);
                                switch_regex_safe_free(re);
                                goto end;
                        }
 
                        memset(substituted, 0, len);
 
-                       switch_perform_substitution(re, proceed, rule->replace, number, substituted, len, ovector);
+                       switch_perform_substitution(match_data, rule->replace, substituted, len);
 
                        if ((switch_string_var_check_const(substituted) || switch_string_has_escaped_data(substituted))) {
                                switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "perform variable expansion\n");
@@ -169,6 +171,7 @@ static void translate_number(char *number, char *profile, char **translated, swi
                                switch_safe_free(subbed);
                        }
 
+                       switch_regex_match_safe_free(match_data);
                        switch_regex_safe_free(re);
                        break;
                }