[Freeswitch-svn] [commit] r7179 - in freeswitch/trunk/src: . include

Freeswitch SVN anthm at freeswitch.org
Fri Jan 11 13:46:23 EST 2008


Author: anthm
Date: Fri Jan 11 13:46:22 2008
New Revision: 7179

Modified:
   freeswitch/trunk/src/include/switch_ivr.h
   freeswitch/trunk/src/switch_ivr_menu.c

Log:
fix for FSCORE-85

Modified: freeswitch/trunk/src/include/switch_ivr.h
==============================================================================
--- freeswitch/trunk/src/include/switch_ivr.h	(original)
+++ freeswitch/trunk/src/include/switch_ivr.h	Fri Jan 11 13:46:22 2008
@@ -719,7 +719,7 @@
  *\return SWITCH_STATUS_SUCCESS if all is well
  */
 SWITCH_DECLARE(switch_status_t) switch_ivr_menu_stack_xml_add_custom(switch_ivr_menu_xml_ctx_t * xml_menu_ctx,
-																	 char *name, switch_ivr_menu_action_function_t * function);
+																	 const char *name, switch_ivr_menu_action_function_t * function);
 
 /*!
  *\param xml_menu_ctx A pointer of a XML menu parser context to be created

Modified: freeswitch/trunk/src/switch_ivr_menu.c
==============================================================================
--- freeswitch/trunk/src/switch_ivr_menu.c	(original)
+++ freeswitch/trunk/src/switch_ivr_menu.c	Fri Jan 11 13:46:22 2008
@@ -468,7 +468,7 @@
 	int autocreated;
 };
 
-static switch_ivr_menu_xml_map_t *switch_ivr_menu_stack_xml_find(switch_ivr_menu_xml_ctx_t * xml_ctx, char *name)
+static switch_ivr_menu_xml_map_t *switch_ivr_menu_stack_xml_find(switch_ivr_menu_xml_ctx_t * xml_ctx, const char *name)
 {
 	switch_ivr_menu_xml_map_t *map = (xml_ctx != NULL ? xml_ctx->map : NULL);
 	int rc = -1;
@@ -480,7 +480,7 @@
 	return (rc == 0 ? map : NULL);
 }
 
-static switch_status_t switch_ivr_menu_stack_xml_add(switch_ivr_menu_xml_ctx_t * xml_ctx, char *name, int action,
+static switch_status_t switch_ivr_menu_stack_xml_add(switch_ivr_menu_xml_ctx_t * xml_ctx, const char *name, int action,
 													 switch_ivr_menu_action_function_t * function)
 {
 	switch_status_t status = SWITCH_STATUS_FALSE;
@@ -512,6 +512,44 @@
 	return status;
 }
 
+
+static struct iam_s {
+	const char *name;
+	switch_ivr_action_t action;
+} iam[] = {
+	{ "menu-exit", SWITCH_IVR_ACTION_DIE }, 
+	{ "menu-sub", SWITCH_IVR_ACTION_EXECMENU},
+	{ "menu-exec-app", SWITCH_IVR_ACTION_EXECAPP}, 
+	{ "menu-play-sound", SWITCH_IVR_ACTION_PLAYSOUND}, 
+	{ "menu-say-text", SWITCH_IVR_ACTION_SAYTEXT}, 
+	{ "menu-say-phrase", SWITCH_IVR_ACTION_SAYPHRASE}, 
+	{ "menu-back", SWITCH_IVR_ACTION_BACK}, 
+	{ "menu-top", SWITCH_IVR_ACTION_TOMAIN}, 
+	{ "menu-call-transfer", SWITCH_IVR_ACTION_TRANSFER},
+	{ NULL, 0}
+};
+
+
+static switch_bool_t is_valid_action(const char *action)
+{
+	int i;
+	
+	if (!switch_strlen_zero(action)) {
+		for(i = 0;;i++) {
+			if (!iam[i].name) {
+				break;
+			}
+
+			if (!strcmp(iam[i].name, action)) {
+				return SWITCH_TRUE;
+			}
+		}
+	}
+
+	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Invalid Action [%s]\n", switch_str_nil(action));
+	return SWITCH_FALSE;
+}
+
 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_status_t status = SWITCH_STATUS_FALSE;
@@ -537,20 +575,6 @@
 	}
 	// build the standard/default xml menu handler mappings
 	if (status == SWITCH_STATUS_SUCCESS && xml_menu_ctx != NULL && *xml_menu_ctx != NULL) {
-		struct iam_s {
-			char *name;
-			switch_ivr_action_t action;
-		} iam[] = {
-			{
-				"menu-exit", SWITCH_IVR_ACTION_DIE}, {
-				"menu-sub", SWITCH_IVR_ACTION_EXECMENU}, {
-				"menu-exec-app", SWITCH_IVR_ACTION_EXECAPP}, {
-				"menu-play-sound", SWITCH_IVR_ACTION_PLAYSOUND}, {
-				"menu-say-text", SWITCH_IVR_ACTION_SAYTEXT}, {
-				"menu-say-phrase", SWITCH_IVR_ACTION_SAYPHRASE}, {
-				"menu-back", SWITCH_IVR_ACTION_BACK}, {
-				"menu-top", SWITCH_IVR_ACTION_TOMAIN}, {
-				"menu-call-transfer", SWITCH_IVR_ACTION_TRANSFER},};
 		int iam_qty = (sizeof(iam) / sizeof(iam[0]));
 		int i;
 
@@ -563,7 +587,7 @@
 }
 
 SWITCH_DECLARE(switch_status_t) switch_ivr_menu_stack_xml_add_custom(switch_ivr_menu_xml_ctx_t * xml_menu_ctx,
-																	 char *name, switch_ivr_menu_action_function_t * function)
+																	 const char *name, switch_ivr_menu_action_function_t * function)
 {
 	return switch_ivr_menu_stack_xml_add(xml_menu_ctx, name, -1, function);
 }
@@ -608,7 +632,7 @@
 				const char *digits = switch_xml_attr(xml_kvp, "digits");
 				const char *param = switch_xml_attr_soft(xml_kvp, "param");
 
-				if (!switch_strlen_zero(action) && !switch_strlen_zero(digits)) {
+				if (is_valid_action(action) && !switch_strlen_zero(digits)) {
 					switch_ivr_menu_xml_map_t *xml_map = xml_menu_ctx->map;
 					int found = 0;
 



More information about the Freeswitch-svn mailing list