Index: apps/app_while.c =================================================================== --- apps/app_while.c (revision 22112) +++ apps/app_while.c (working copy) @@ -50,7 +50,7 @@ "Usage: ExecIF (||)\n" "If is true, execute and return the result of ().\n" "If is true, but is not found, then the application\n" -"will return a non-zero value."; +"will return a non-zero value.\n"; static char *exec_synopsis = "Conditional exec"; static char *start_app = "While"; @@ -59,16 +59,28 @@ "Start a While Loop. Execution will return to this point when\n" "EndWhile is called until expr is no longer true.\n"; -static char *start_synopsis = "Start A While Loop"; +static char *start_synopsis = "Start a While loop"; static char *stop_app = "EndWhile"; static char *stop_desc = "Usage: EndWhile()\n" -"Return to the previous called While\n\n"; +"Return to the previous called While\n"; -static char *stop_synopsis = "End A While Loop"; +static char *stop_synopsis = "End a While loop"; +static char *exit_app = "ExitWhile"; +static char *exit_desc = +"Usage: ExitWhile()\n" +"Exits a While loop, whether or not the conditional has been satisfied.\n"; +static char *exit_synopsis = "End a While loop"; + +static char *continue_app = "ContinueWhile"; +static char *continue_desc = +"Usage: ContinueWhile()\n" +"Returns to the top of the while loop and re-evaluates the conditional.\n"; +static char *continue_synopsis = "Restart a While loop"; + static char *tdesc = "While Loops and Conditional Execution"; @@ -122,7 +134,7 @@ #define VAR_SIZE 64 -static char *get_index(struct ast_channel *chan, const char *prefix, int index) { +static const char *get_index(struct ast_channel *chan, const char *prefix, int index) { char varname[VAR_SIZE]; snprintf(varname, VAR_SIZE, "%s_%d", prefix, index); @@ -269,7 +281,7 @@ } - if (!end && !ast_true(condition)) { + if ((!end && !ast_true(condition)) || (end == 2)) { /* Condition Met (clean up helper vars) */ pbx_builtin_setvar_helper(chan, varname, NULL); pbx_builtin_setvar_helper(chan, my_name, NULL); @@ -325,7 +337,29 @@ return _while_exec(chan, data, 1); } +static int while_exit_exec(struct ast_channel *chan, void *data) { + return _while_exec(chan, data, 2); +} +static int while_continue_exec(struct ast_channel *chan, void *data) +{ + int x; + const char *prefix = "WHILE", *while_pri=NULL; + + for (x = 0; ; x++) { + const char *tmp = get_index(chan, prefix, x); + if (tmp) + while_pri = tmp; + else + break; + } + + if (while_pri) + ast_parseable_goto(chan, while_pri); + + return 0; +} + int unload_module(void) { int res; @@ -333,6 +367,8 @@ res = ast_unregister_application(start_app); res |= ast_unregister_application(exec_app); res |= ast_unregister_application(stop_app); + res |= ast_unregister_application(exit_app); + res |= ast_unregister_application(continue_app); STANDARD_HANGUP_LOCALUSERS; @@ -346,6 +382,8 @@ res = ast_register_application(start_app, while_start_exec, start_synopsis, start_desc); res |= ast_register_application(exec_app, execif_exec, exec_synopsis, exec_desc); res |= ast_register_application(stop_app, while_end_exec, stop_synopsis, stop_desc); + res |= ast_register_application(exit_app, while_exit_exec, exit_synopsis, exit_desc); + res |= ast_register_application(continue_app, while_continue_exec, continue_synopsis, continue_desc); return res; }