From c285db54737b5f496516d8142e92af7863eaa530 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Wed, 2 Nov 2011 10:58:38 -0500 Subject: [PATCH] set DP_REGEX_MATCH_1 .. DP_REGEX_MATCH_N to preserve captures into arrays --- src/include/switch_channel.h | 2 ++ .../mod_dialplan_xml/mod_dialplan_xml.c | 7 ++++++ src/switch_channel.c | 22 +++++++++++++++++++ 3 files changed, 31 insertions(+) diff --git a/src/include/switch_channel.h b/src/include/switch_channel.h index d388777c33..fdbb683b92 100644 --- a/src/include/switch_channel.h +++ b/src/include/switch_channel.h @@ -271,6 +271,8 @@ SWITCH_DECLARE(const char *) switch_channel_get_variable_partner(switch_channel_ SWITCH_DECLARE(const char *) switch_channel_get_hold_music(switch_channel_t *channel); SWITCH_DECLARE(const char *) switch_channel_get_hold_music_partner(switch_channel_t *channel); +SWITCH_DECLARE(uint32_t) switch_channel_del_variable_prefix(switch_channel_t *channel, const char *prefix); + #define switch_channel_set_variable(_channel, _var, _val) switch_channel_set_variable_var_check(_channel, _var, _val, SWITCH_TRUE) #define switch_channel_set_variable_partner(_channel, _var, _val) switch_channel_set_variable_partner_var_check(_channel, _var, _val, SWITCH_TRUE) 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 b17247d81d..b2fb858e31 100644 --- a/src/mod/dialplans/mod_dialplan_xml/mod_dialplan_xml.c +++ b/src/mod/dialplans/mod_dialplan_xml/mod_dialplan_xml.c @@ -149,6 +149,8 @@ static int parse_exten(switch_core_session_t *session, switch_caller_profile_t * int fail = 0; int total = 0; + switch_channel_del_variable_prefix(channel, "DP_REGEX_MATCH"); + for (xregex = switch_xml_child(xcond, "regex"); xregex; xregex = xregex->next) { time_match = switch_xml_std_datetime_check(xregex); @@ -219,6 +221,11 @@ static int parse_exten(switch_core_session_t *session, switch_caller_profile_t * } if (field && strchr(expression, '(')) { + char var[256]; + switch_snprintf(var, sizeof(var), "DP_REGEX_MATCH_%d", total); + + switch_channel_set_variable(channel, var, NULL); + switch_capture_regex(re, proceed, field_data, ovector, var, switch_regex_set_var_callback, session); switch_safe_free(save_expression); switch_safe_free(save_field_data); diff --git a/src/switch_channel.c b/src/switch_channel.c index a55815e144..6902ac7ad8 100644 --- a/src/switch_channel.c +++ b/src/switch_channel.c @@ -1127,6 +1127,28 @@ SWITCH_DECLARE(switch_status_t) switch_channel_export_variable_printf(switch_cha return status; } + +SWITCH_DECLARE(uint32_t) switch_channel_del_variable_prefix(switch_channel_t *channel, const char *prefix) +{ + switch_event_t *event; + switch_event_header_t *hp; + uint32_t r = 0; + + switch_channel_get_variables(channel, &event); + + if (event) { + for (hp = event->headers; hp; hp = hp->next) { + if (zstr(prefix) || !strncasecmp(hp->name, prefix, strlen(prefix))) { + switch_channel_set_variable(channel, hp->name, NULL); + } + } + } + + switch_event_destroy(&event); + + return r; +} + SWITCH_DECLARE(switch_status_t) switch_channel_set_variable_var_check(switch_channel_t *channel, const char *varname, const char *value, switch_bool_t var_check) {