diff --git a/src/include/switch_regex.h b/src/include/switch_regex.h index 4c5f14961f..15b54aa09e 100644 --- a/src/include/switch_regex.h +++ b/src/include/switch_regex.h @@ -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;\ diff --git a/src/mod/applications/mod_dptools/mod_dptools.c b/src/mod/applications/mod_dptools/mod_dptools.c index 88bcaf86b6..e0b8e0aa93 100755 --- a/src/mod/applications/mod_dptools/mod_dptools.c +++ b/src/mod/applications/mod_dptools/mod_dptools.c @@ -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, "||", 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); 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 3b5f6995e4..5f042fbf26 100644 --- a/src/mod/dialplans/mod_dialplan_xml/mod_dialplan_xml.c +++ b/src/mod/dialplans/mod_dialplan_xml/mod_dialplan_xml.c @@ -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) { diff --git a/src/switch_regex.c b/src/switch_regex.c index 7bce6ce461..3cfa01e116 100644 --- a/src/switch_regex.c +++ b/src/switch_regex.c @@ -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