From 302a768c9f12ad349b23f9d7b87e92b0b163f91f Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Fri, 22 Dec 2006 14:50:48 +0000 Subject: [PATCH] make substitution dynamic git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@3794 d0543943-73ff-0310-b7d9-9358b9ac24b2 --- .../mod_dialplan_xml/mod_dialplan_xml.c | 13 +++++++++++-- src/switch_ivr.c | 16 +++++++++++++--- 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/src/mod/dialplans/mod_dialplan_xml/mod_dialplan_xml.c b/src/mod/dialplans/mod_dialplan_xml/mod_dialplan_xml.c index 0714144009..fd1e10e3fe 100644 --- a/src/mod/dialplans/mod_dialplan_xml/mod_dialplan_xml.c +++ b/src/mod/dialplans/mod_dialplan_xml/mod_dialplan_xml.c @@ -150,11 +150,19 @@ static int parse_exten(switch_core_session_t *session, switch_xml_t xexten, swit for (xaction = switch_xml_child(xcond, "action"); xaction; xaction = xaction->next) { char *application = (char*) switch_xml_attr_soft(xaction, "application"); char *data = (char *) switch_xml_attr_soft(xaction, "data"); - char substituted[1024] = ""; + char *substituted = NULL; + switch_size_t len = 0; char *app_data = NULL; if (field && strchr(expression, '(')) { - switch_perform_substitution(re, proceed, data, field_data, substituted, sizeof(substituted), ovector); + len = strlen(data) + strlen(field_data) + 10; + if (!(substituted = malloc(len))) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "memory error!\n"); + proceed = 0; + goto done; + } + memset(substituted, 0, len); + switch_perform_substitution(re, proceed, data, field_data, substituted, len, ovector); app_data = substituted; } else { app_data = data; @@ -170,6 +178,7 @@ static int parse_exten(switch_core_session_t *session, switch_xml_t xexten, swit } switch_caller_extension_add_application(session, *extension, application, app_data); + switch_safe_free(substituted); } switch_clean_re(re); diff --git a/src/switch_ivr.c b/src/switch_ivr.c index 28c16363ee..75ecc3bf0d 100644 --- a/src/switch_ivr.c +++ b/src/switch_ivr.c @@ -4487,17 +4487,26 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_phrase_macro(switch_core_session_t *s if (pattern) { pcre *re = NULL; int proceed = 0, ovector[30]; - char substituted[1024] = ""; + char *substituted = NULL; + switch_size_t len = 0; char *odata = NULL; char *expanded = NULL; - + if ((proceed = switch_perform_regex(data, pattern, &re, ovector, sizeof(ovector) / sizeof(ovector[0])))) { for (action = switch_xml_child(input, "action"); action; action = action->next) { char *adata = (char *) switch_xml_attr_soft(action, "data"); char *func = (char *) switch_xml_attr_soft(action, "function"); if (strchr(pattern, '(') && strchr(adata, '$')) { - switch_perform_substitution(re, proceed, adata, data, substituted, sizeof(substituted), ovector); + len = strlen(data) + strlen(adata) + 10; + if (!(substituted = malloc(len))) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Memory Error!\n"); + switch_clean_re(re); + switch_safe_free(expanded); + goto done; + } + memset(substituted, 0, len); + switch_perform_substitution(re, proceed, adata, data, substituted, len, ovector); odata = substituted; } else { odata = adata; @@ -4566,6 +4575,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_phrase_macro(switch_core_session_t *s switch_clean_re(re); switch_safe_free(expanded); + switch_safe_free(substituted); } input = input->next;