]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
add capture dp app
authorAnthony Minessale <anthm@freeswitch.org>
Wed, 25 May 2011 21:12:42 +0000 (16:12 -0500)
committerAnthony Minessale <anthm@freeswitch.org>
Wed, 25 May 2011 21:12:42 +0000 (16:12 -0500)
src/include/switch_regex.h
src/mod/applications/mod_dptools/mod_dptools.c
src/mod/dialplans/mod_dialplan_xml/mod_dialplan_xml.c
src/switch_regex.c

index 4c5f14961f47dec5d8cb2e804c728573261b5ae3..15b54aa09e975bb903dd02e3b0f0dbc45045b752 100644 (file)
@@ -73,6 +73,8 @@ SWITCH_DECLARE(switch_status_t) switch_regex_match_partial(const char *target, c
 SWITCH_DECLARE(void) switch_capture_regex(switch_regex_t *re, int match_count, const char *field_data, 
                                                                                  int *ovector, const char *var, switch_cap_callback_t callback, void *user_data);
 
+SWITCH_DECLARE(void) switch_regex_set_var_callback(const char *var, const char *val, void *user_data);
+
 #define switch_regex_safe_free(re)     if (re) {\
                                switch_regex_free(re);\
                                re = NULL;\
index 88bcaf86b62963fa08f4e5f6b4587a2ffe6b3b66..e0b8e0aa93cdf08d6ee5effe4618b8e9f739bbef 100755 (executable)
@@ -2308,6 +2308,26 @@ SWITCH_STANDARD_APP(stop_displace_session_function)
        switch_ivr_stop_displace_session(session, data);
 }
 
+SWITCH_STANDARD_APP(capture_function)
+{
+       char *argv[3] = { 0 };
+       int argc;
+       switch_regex_t *re = NULL;
+       int ovector[30] = {0};
+       char *lbuf;
+       int proceed;
+       
+       if (!zstr(data) && (lbuf = switch_core_session_strdup(session, data))
+               && (argc = switch_separate_string(lbuf, '|', argv, (sizeof(argv) / sizeof(argv[0])))) == 3) {
+               if ((proceed = switch_regex_perform(argv[1], argv[2], &re, ovector, sizeof(ovector) / sizeof(ovector[0])))) {
+                       switch_capture_regex(re, proceed, argv[1], ovector, argv[0], switch_regex_set_var_callback, session);
+               }
+               switch_regex_safe_free(re);
+       } else {
+               switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "No data specified.\n");
+       }       
+}
+
 SWITCH_STANDARD_APP(record_function)
 {
        switch_channel_t *channel = switch_core_session_get_channel(session);
@@ -3740,6 +3760,9 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_dptools_load)
        SWITCH_ADD_APP(app_interface, "bind_digit_action", "bind a key sequence or regex to an action", 
                                   "bind a key sequence or regex to an action", bind_digit_action_function, BIND_DIGIT_ACTION_USAGE, SAF_SUPPORT_NOMEDIA);
 
+       SWITCH_ADD_APP(app_interface, "capture", "capture data into a var", "capture data into a var", 
+                                  capture_function, "<varname>|<data>|<regex>", SAF_SUPPORT_NOMEDIA);
+
        SWITCH_ADD_APP(app_interface, "clear_digit_action", "clear all digit bindings", "", 
                                   clear_digit_action_function, CLEAR_DIGIT_ACTION_USAGE, SAF_SUPPORT_NOMEDIA);
 
index 3b5f6995e497b467e2a50ae2203ea9773f478fba..5f042fbf26cc6c473a09705b536c78b090a305f5 100644 (file)
@@ -79,13 +79,6 @@ static switch_status_t exec_app(switch_core_session_t *session, const char *app,
        return status;
 }
 
-static void set_var_callback(const char *var, const char *val, void *user_data)
-{
-       switch_core_session_t *session = (switch_core_session_t *) user_data;
-       switch_channel_t *channel = switch_core_session_get_channel(session);
-       switch_channel_add_variable_var_check(channel, var, val, SWITCH_FALSE, SWITCH_STACK_PUSH);
-}
-
 static int parse_exten(switch_core_session_t *session, switch_caller_profile_t *caller_profile, switch_xml_t xexten, switch_caller_extension_t **extension)
 {
        switch_xml_t xcond, xaction, xexpression;
@@ -231,7 +224,7 @@ static int parse_exten(switch_core_session_t *session, switch_caller_profile_t *
                } else {
                        if (field && strchr(expression, '(')) {
                                switch_channel_set_variable(channel, "DP_MATCH", NULL);
-                               switch_capture_regex(re, proceed, field_data, ovector, "DP_MATCH", set_var_callback, session);
+                               switch_capture_regex(re, proceed, field_data, ovector, "DP_MATCH", switch_regex_set_var_callback, session);
                        }
 
                        for (xaction = switch_xml_child(xcond, "action"); xaction; xaction = xaction->next) {
index 7bce6ce461426f6d41697b899ed1a3428b1087ce..3cfa01e116b8c02aa7121b23c525f0a199179c2e 100644 (file)
@@ -249,6 +249,15 @@ SWITCH_DECLARE(switch_status_t) switch_regex_match(const char *target, const cha
        return switch_regex_match_partial(target, expression, &partial);
 }
 
+SWITCH_DECLARE(void) switch_regex_set_var_callback(const char *var, const char *val, void *user_data)
+{
+       switch_core_session_t *session = (switch_core_session_t *) user_data;
+       switch_channel_t *channel = switch_core_session_get_channel(session);
+       switch_channel_add_variable_var_check(channel, var, val, SWITCH_FALSE, SWITCH_STACK_PUSH);
+}
+
+
+
 /* For Emacs:
  * Local Variables:
  * mode:c