[Freeswitch-branches] [commit] r3338 - in freeswitch/branches/knhor/trunk/src: . include
Author: knhor Date: Mon Nov 13 00:14:29 2006 New Revision: 3338 Modified: freeswitch/branches/knhor/trunk/src/include/switch_ivr.h freeswitch/branches/knhor/trunk/src/switch_ivr.c Log: fix docs for switch_ivr_menu_init. add switch_ivr_build_xml_menu_stack function, it expects xml like in the following example; <menus> <menu name="main" greet-long="greet-long.wav" greet-short="greet-short.wav" invalid-sound="invalid.wav" timeout ="15000" max-failures="3"> <entry action="exit" digits="*"/> <entry action="menu-sub" digits="2" param="menu2"/> <entry action="exec-api" digits="3" param="api arg"/> <entry action="play-sound" digits="4" param="asound.wav"/> <entry action="call-transfer" digits="7" param="888"/> <entry action="menu-sub" digits="8" param="menu8"/>> </menu> <menu name="menu8" greet-long="greet-long.wav" greet-short="greet-short.wav" invalid-sound="invalid.wav" timeout ="15000" max-failures="3"> <entry action="menu-back" digits="#"/> <entry action="play-sound" digits="4" param="asound.wav"/> <entry action="menu-top" digits="*"/> </menu> <menu name="menu2" greet-long="greet-long.wav" greet-short="greet-short.wav" invalid-sound="invalid.wav" timeout ="15000" max-failures="3"> <entry action="menu-back" digits="#"/> <entry action="play-sound" digits="4" param="asound.wav"/> <entry action="menu-top" digits="*"/> </menu> </menus> Modified: freeswitch/branches/knhor/trunk/src/include/switch_ivr.h ============================================================================== --- freeswitch/branches/knhor/trunk/src/include/switch_ivr.h (original) +++ freeswitch/branches/knhor/trunk/src/include/switch_ivr.h Mon Nov 13 00:14:29 2006 @@ -499,10 +499,12 @@ *\param greeting_sound Optional pointer to a main sound (press 1 for this 2 for that). *\param short_greeting_sound Optional pointer to a shorter main sound for subsequent loops. *\param invalid_sound Optional pointer to a sound to play after invalid input. + *\param tts_engine Text To Speech engine name + *\param tts_voice Text To Speech engine voice name *\param timeout A number of milliseconds to pause before looping. *\param max_failures Maximum number of failures to withstand before hangingup This resets everytime you enter the menu. *\param pool memory pool (NULL to create one) - *\return SWUTCH_STATUS_SUCCESS if the menu was created + *\return SWITCH_STATUS_SUCCESS if the menu was created */ SWITCH_DECLARE(switch_status_t) switch_ivr_menu_init(switch_ivr_menu_t **new_menu, switch_ivr_menu_t *main, @@ -557,6 +559,18 @@ */ SWITCH_DECLARE(switch_status_t) switch_ivr_menu_free_stack(switch_ivr_menu_t *stack); +/*! + *\brief build a menu stack from an xml source + *\param menu_stack The menu stack object that will be created for you + *\param xml_menus The xml Menus source + *\param xml_menu The xml Menu source of the menu to be created + *\param pool memory pool (NULL to create one) + *\return SWITCH_STATUS_SUCCESS if all is well + */ +SWITCH_DECLARE(switch_status_t) switch_ivr_build_xml_menu_stack(switch_ivr_menu_t **menu_stack, + switch_xml_t xml_menus, + switch_xml_t xml_menu, + switch_memory_pool_t *pool); /** @} */ SWITCH_END_EXTERN_C Modified: freeswitch/branches/knhor/trunk/src/switch_ivr.c ============================================================================== --- freeswitch/branches/knhor/trunk/src/switch_ivr.c (original) +++ freeswitch/branches/knhor/trunk/src/switch_ivr.c Mon Nov 13 00:14:29 2006 @@ -3695,15 +3695,16 @@ if (!strcmp(menu->buf, ap->bind)) { char *membuf; - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "IVR menu %s matched %s\n", menu->name, menu->buf); match++; errs = 0; if (ap->function) { todo = ap->function(menu, arg, sizeof(arg), obj); aptr = arg; + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "IVR function on menu '%s' matched '%s'\n", menu->name, menu->buf); } else { todo = ap->ivr_action; aptr = ap->arg; + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "IVR action on menu '%s' matched '%s' param '%s'\n", menu->name, menu->buf,aptr); } switch(todo) { @@ -3728,6 +3729,7 @@ break; case SWITCH_IVR_ACTION_EXECAPP: { const switch_application_interface_t *application_interface; + if ((membuf = strdup(aptr))) { char *app_name = membuf; char *app_arg = strchr(app_name, ' '); @@ -3788,6 +3790,95 @@ } switch_safe_free(menu->buf); + + return status; +} + +SWITCH_DECLARE(switch_status_t) switch_ivr_build_xml_menu_stack(switch_ivr_menu_t **menu_stack, + switch_xml_t xml_menus, + switch_xml_t xml_menu, + switch_memory_pool_t *pool) +{ + switch_status_t status = SWITCH_STATUS_FALSE; + char *menu_name = (char *)switch_xml_attr_soft(xml_menu,"name"); // if the attr doesn't exist, return "" + char *greet_long = (char *)switch_xml_attr(xml_menu,"greet-long"); // if the attr doesn't exist, return NULL + char *greet_short = (char *)switch_xml_attr(xml_menu,"greet-short"); // if the attr doesn't exist, return NULL + char *invalid_sound = (char *)switch_xml_attr(xml_menu,"invalid-sound"); // if the attr doesn't exist, return NULL + char *tts_engine = (char *)switch_xml_attr(xml_menu,"tts-engine"); // if the attr doesn't exist, return NULL + char *tts_voice = (char *)switch_xml_attr(xml_menu,"tts-voice"); // if the attr doesn't exist, return NULL + char *timeout = (char *)switch_xml_attr_soft(xml_menu,"timeout"); // if the attr doesn't exist, return "" + char *max_failures = (char *)switch_xml_attr_soft(xml_menu,"max-failures"); // if the attr doesn't exist, return "" + switch_ivr_menu_t *menu = NULL; + + status = switch_ivr_menu_init(&menu, + *menu_stack, + menu_name, + greet_long, + greet_short, + invalid_sound, + tts_engine, + tts_voice, + atoi(timeout)*1000, + atoi(max_failures), + pool + ); + if (status == SWITCH_STATUS_SUCCESS) { + switch_xml_t xml_kvp; + struct ivr_action_map { + char *name; + switch_ivr_action_t action; + } iam [] = { + {"exit", SWITCH_IVR_ACTION_DIE}, + {"menu-sub", SWITCH_IVR_ACTION_EXECMENU}, + {"exec-api", SWITCH_IVR_ACTION_EXECAPP}, + {"play-sound", SWITCH_IVR_ACTION_PLAYSOUND}, + {"say-text", SWITCH_IVR_ACTION_SAYTEXT}, + {"menu-back", SWITCH_IVR_ACTION_BACK}, + {"menu-top", SWITCH_IVR_ACTION_TOMAIN}, + {"call-transfer", SWITCH_IVR_ACTION_TRANSFER}, + }; + int iam_qty = sizeof(iam)/sizeof(iam[0]); + + // set the menu stack for the caller + if (*menu_stack == NULL) { + *menu_stack = menu; + } + + // build menu entries + for(xml_kvp = switch_xml_child(xml_menu, "entry"); xml_kvp != NULL && status == SWITCH_STATUS_SUCCESS; xml_kvp = xml_kvp->next) { + char *action = (char *)switch_xml_attr(xml_kvp, "action"); + char *digits = (char *)switch_xml_attr(xml_kvp, "digits"); + char *param = (char *)switch_xml_attr_soft(xml_kvp, "param"); + + if (!switch_strlen_zero(action) && !switch_strlen_zero(digits)) { + int i,found; + + for(i=0,found=0; i<iam_qty && !found; i++) { + found = (strcasecmp(iam[i].name,action) == 0); + } + + if (found) { + i--; + // do we need to build a new sub-menu ? + if (iam[i].action == SWITCH_IVR_ACTION_EXECMENU && switch_ivr_find_menu(*menu_stack, param) == NULL) { + if ((xml_menu = switch_xml_find_child(xml_menus, "menu", "name", param)) != NULL) { + status = switch_ivr_build_xml_menu_stack(menu_stack, xml_menus, xml_menu, pool); + } + } + // finally bind the menu entry + if (status == SWITCH_STATUS_SUCCESS) { + status = switch_ivr_menu_bind_action(menu, iam[i].action, param, digits); + } + } + } else { + status = SWITCH_STATUS_FALSE; + } + } + } + + if (status != SWITCH_STATUS_SUCCESS) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Unable to build xml menu '%s'\n",menu_name); + } return status; }
participants (1)
-
Freeswitch SVN