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;\
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);
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);
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;
} 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) {
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