]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
add an event to phrases to be used as possible variables in parsing
authorAnthony Minessale <anthony.minessale@gmail.com>
Wed, 3 Mar 2010 20:49:38 +0000 (20:49 +0000)
committerAnthony Minessale <anthony.minessale@gmail.com>
Wed, 3 Mar 2010 20:49:38 +0000 (20:49 +0000)
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@16885 d0543943-73ff-0310-b7d9-9358b9ac24b2

src/include/switch_ivr.h
src/switch_ivr_play_say.c

index ba7a7a1a73c0074ed52151c88235ec51a2f1cb67..bd9e4b7e99dd960ce78804a7a64dc3237be1d531 100644 (file)
@@ -790,8 +790,9 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_menu_stack_xml_add_custom(switch_ivr_
  */
 SWITCH_DECLARE(switch_status_t) switch_ivr_menu_stack_xml_init(switch_ivr_menu_xml_ctx_t ** xml_menu_ctx, switch_memory_pool_t *pool);
 
-SWITCH_DECLARE(switch_status_t) switch_ivr_phrase_macro(switch_core_session_t *session, const char *macro_name, const char *data, const char *lang,
+SWITCH_DECLARE(switch_status_t) switch_ivr_phrase_macro_event(switch_core_session_t *session, const char *macro_name, const char *data, switch_event_t *event, const char *lang,
                                                                                                                switch_input_args_t *args);
+#define switch_ivr_phrase_macro(session, macro_name, data, lang, args) switch_ivr_phrase_macro_event(session, macro_name, data, NULL, lang, args)
 SWITCH_DECLARE(void) switch_ivr_delay_echo(switch_core_session_t *session, uint32_t delay_ms);
 SWITCH_DECLARE(switch_status_t) switch_ivr_find_bridged_uuid(const char *uuid, char *b_uuid, switch_size_t blen);
 SWITCH_DECLARE(void) switch_ivr_intercept_session(switch_core_session_t *session, const char *uuid, switch_bool_t bleg);
index 0b5049d1f47adbbb271aeccc3cddc294d103cc67..710ce61a5d0e22156788d62a98ffa213934f0703 100644 (file)
@@ -90,7 +90,7 @@ SWITCH_DECLARE(switch_say_type_t) switch_ivr_get_say_type_by_name(const char *na
        return (switch_say_type_t) x;
 }
 
-SWITCH_DECLARE(switch_status_t) switch_ivr_phrase_macro(switch_core_session_t *session, const char *macro_name, const char *data, const char *lang,
+SWITCH_DECLARE(switch_status_t) switch_ivr_phrase_macro_event(switch_core_session_t *session, const char *macro_name, const char *data, switch_event_t *event, const char *lang,
                                                                                                                switch_input_args_t *args)
 {
        switch_event_t *hint_data;
@@ -129,6 +129,9 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_phrase_macro(switch_core_session_t *s
        switch_event_add_header_string(hint_data, SWITCH_STACK_BOTTOM, "lang", chan_lang);
        if (data) {
                switch_event_add_header_string(hint_data, SWITCH_STACK_BOTTOM, "data", data);
+               if (event) {
+                       switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "data", data);
+               }
        } else {
                data = "";
        }
@@ -221,8 +224,27 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_phrase_macro(switch_core_session_t *s
        }
 
        while (input && !done) {
+               char *field = (char *) switch_xml_attr(input, "field");
                char *pattern = (char *) switch_xml_attr(input, "pattern");
                const char *do_break = switch_xml_attr_soft(input, "break_on_match");
+               char *field_expanded = NULL;
+               char *field_expanded_alloc = NULL;
+
+               if (!field) {
+                       field = (char *) data;
+               }
+               if (event) {
+                       field_expanded_alloc = switch_event_expand_headers(event, field);
+               } else {
+                       field_expanded_alloc = switch_channel_expand_variables(channel, field);
+               }
+
+               if (field_expanded_alloc == field) {
+                       field_expanded_alloc = NULL;
+                       field_expanded = field;
+               } else {
+                       field_expanded = field_expanded_alloc;
+               }
 
                if (pattern) {
                        switch_regex_t *re = NULL;
@@ -235,7 +257,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_phrase_macro(switch_core_session_t *s
 
                        status = SWITCH_STATUS_SUCCESS;
 
-                       if ((proceed = switch_regex_perform(data, pattern, &re, ovector, sizeof(ovector) / sizeof(ovector[0])))) {
+                       if ((proceed = switch_regex_perform(field_expanded, pattern, &re, ovector, sizeof(ovector) / sizeof(ovector[0])))) {
                                match = switch_xml_child(input, "match");
                        } else {
                                match = switch_xml_child(input, "nomatch");
@@ -256,13 +278,17 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_phrase_macro(switch_core_session_t *s
                                                        goto done;
                                                }
                                                memset(substituted, 0, len);
-                                               switch_perform_substitution(re, proceed, adata, data, substituted, len, ovector);
+                                               switch_perform_substitution(re, proceed, adata, field_expanded, substituted, len, ovector);
                                                odata = substituted;
                                        } else {
                                                odata = adata;
                                        }
 
-                                       expanded = switch_channel_expand_variables(channel, odata);
+                                       if (event) {
+                                               expanded = switch_event_expand_headers(event, odata);
+                                       } else {
+                                               expanded = switch_channel_expand_variables(channel, odata);
+                                       }
 
                                        if (expanded == odata) {
                                                expanded = NULL;
@@ -344,6 +370,8 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_phrase_macro(switch_core_session_t *s
 
                }
 
+               switch_safe_free(field_expanded_alloc);
+
                if (status != SWITCH_STATUS_SUCCESS) {
                        done = 1;
                        break;