Index: include/asterisk/channel.h =================================================================== --- include/asterisk/channel.h (revision 7786) +++ include/asterisk/channel.h (working copy) @@ -408,6 +408,9 @@ /*! Raw write format */ int rawwriteformat; + /*! Max timeout before hangup */ + int maxtimeout; + /*! Chan Spy stuff */ struct ast_channel_spy_list *spies; Index: pbx.c =================================================================== --- pbx.c (revision 7786) +++ pbx.c (working copy) @@ -433,13 +433,14 @@ { "WaitExten", pbx_builtin_waitexten, "Waits for an extension to be entered", - " WaitExten([seconds][|options]): This application waits for the user to enter\n" + " WaitExten([seconds][|options][|maxtimeout]): This application waits for the user to enter\n" "a new extension for a specified number of seconds.\n" " Note that the seconds can be passed with fractions of a second. For example,\n" "'1.5' will ask the application to wait for 1.5 seconds.\n" " Options:\n" " m[(x)] - Provide music on hold to the caller while waiting for an extension.\n" " Optionally, specify the class for music on hold within parenthesis.\n" + " the channel will hangup after maxtimeout times timeout, maxtimeout default to 3\n" }, }; @@ -5496,11 +5497,12 @@ */ static int pbx_builtin_waitexten(struct ast_channel *chan, void *data) { - int ms, res, argc; + int ms, res, argc, maxtimeout; char *args; - char *argv[2]; + char *argv[3]; char *options = NULL; char *timeout = NULL; + char *_maxtimeout = NULL; struct ast_flags flags = {0}; char *opts[1] = { NULL }; @@ -5510,7 +5512,11 @@ if (argc > 0) { timeout = argv[0]; if (argc > 1) + { options = argv[1]; + if (argc > 2) + _maxtimeout = argv[2]; + } } } @@ -5527,9 +5533,20 @@ ms = chan->pbx->rtimeout * 1000; else ms = 10000; + + if (_maxtimeout && atoi((char*)_maxtimeout)) + maxtimeout = atoi((char*)_maxtimeout); + else + maxtimeout = 3; + res = ast_waitfordigit(chan, ms); if (!res) { - if (ast_exists_extension(chan, chan->context, chan->exten, chan->priority + 1, chan->cid.cid_num)) { + chan->maxtimeout += 1; + if(chan->maxtimeout >= maxtimeout) + { + ast_log(LOG_WARNING, "max Timeout %d times, hangup\n", chan->maxtimeout); + res = -1; + } else if (ast_exists_extension(chan, chan->context, chan->exten, chan->priority + 1, chan->cid.cid_num)) { if (option_verbose > 2) ast_verbose(VERBOSE_PREFIX_3 "Timeout on %s, continuing...\n", chan->name); } else if (ast_exists_extension(chan, chan->context, "t", 1, chan->cid.cid_num)) {