Revision
16885
Author
anthm
Date
2010-03-03 14:49:38 -0600 (Wed, 03 Mar 2010)

Log Message

add an event to phrases to be used as possible variables in parsing

Modified Paths

Diff

Modified: freeswitch/trunk/src/include/switch_ivr.h (16884 => 16885)


--- freeswitch/trunk/src/include/switch_ivr.h	2010-03-03 19:55:15 UTC (rev 16884)
+++ freeswitch/trunk/src/include/switch_ivr.h	2010-03-03 20:49:38 UTC (rev 16885)
@@ -790,8 +790,9 @@
  */
 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);

Modified: freeswitch/trunk/src/switch_ivr_play_say.c (16884 => 16885)


--- freeswitch/trunk/src/switch_ivr_play_say.c	2010-03-03 19:55:15 UTC (rev 16884)
+++ freeswitch/trunk/src/switch_ivr_play_say.c	2010-03-03 20:49:38 UTC (rev 16885)
@@ -90,7 +90,7 @@
 	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_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,9 +224,28 @@
 	}
 
 	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;
 			int proceed = 0, ovector[30];
@@ -235,7 +257,7 @@
 
 			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 @@
 							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_safe_free(field_expanded_alloc);
+
 		if (status != SWITCH_STATUS_SUCCESS) {
 			done = 1;
 			break;