]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
set DP_REGEX_MATCH_1 .. DP_REGEX_MATCH_N to preserve captures into arrays
authorAnthony Minessale <anthm@freeswitch.org>
Wed, 2 Nov 2011 15:58:38 +0000 (10:58 -0500)
committerAnthony Minessale <anthm@freeswitch.org>
Wed, 2 Nov 2011 15:58:45 +0000 (10:58 -0500)
src/include/switch_channel.h
src/mod/dialplans/mod_dialplan_xml/mod_dialplan_xml.c
src/switch_channel.c

index d388777c339212210c0feaeeb73794317ba7773c..fdbb683b923a913f6976cd5aebcab11b49edc19f 100644 (file)
@@ -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)
 
index b17247d81d5c1a34462f273f7788befcd8303d71..b2fb858e31d6e3b13ce1d9283e1ee01fb3fa3fb8 100644 (file)
@@ -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);
index a55815e14437e332315f3e51339f6a6e9f1738b2..6902ac7ad892d090a49f3ef401148bdd09c00e35 100644 (file)
@@ -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)
 {