--- ../asterisk-1.6.0.1/apps/app_readexten.c 2008-11-20 13:52:14.000000000 -0500 +++ apps/app_readexten.c 2008-11-21 11:40:19.000000000 -0500 @@ -1,9 +1,8 @@ /* * Asterisk -- An open source telephony toolkit. * - * Copyright (C) 2007 Dave Chappell - * - * David Chappell + * Copyright (C) 2008, Trinity College Computing Center + * Written by David Chappell * * See http://www.asterisk.org for more information about * the Asterisk project. Please do not directly contact @@ -29,10 +28,13 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision: 89522 $") +#include #include "asterisk/file.h" +#include "asterisk/logger.h" #include "asterisk/pbx.h" #include "asterisk/app.h" #include "asterisk/module.h" +#include "asterisk/options.h" #include "asterisk/indications.h" #include "asterisk/channel.h" @@ -66,8 +68,10 @@ " greater than 0, that value will override the default timeout.\n\n" "ReadExten will set READEXTENSTATUS on exit with one of the following statuses:\n" " OK A valid extension exists in ${variable}\n" -" TIMEOUT No extension was entered in the specified time\n" -" INVALID An invalid extension, ${INVALID_EXTEN}, was entered\n" +" TIMEOUT No extension was entered in the specified time, also sets\n" +" to 't'\n'" +" INVALID An invalid extension, ${INVALID_EXTEN}, was entered. Also sets\n" +" to 'i'\n" " SKIP Line was not up and the option 's' was specified\n" " ERROR Invalid arguments were passed\n"; @@ -93,7 +97,7 @@ if (ast_strlen_zero(data)) { ast_log(LOG_WARNING, "ReadExten requires at least one argument\n"); pbx_builtin_setvar_helper(chan, "READEXTENSTATUS", "ERROR"); - return 0; + return -1; } argcopy = ast_strdupa(data); @@ -102,7 +106,7 @@ if (ast_strlen_zero(arglist.variable)) { ast_log(LOG_WARNING, "Invalid! Usage: ReadExten(variable[|filename][|context][|options][|timeout])\n\n"); pbx_builtin_setvar_helper(chan, "READEXTENSTATUS", "ERROR"); - return 0; + return -1; } if (ast_strlen_zero(arglist.filename)) @@ -156,7 +160,8 @@ res = ast_streamfile(chan, arglist.filename, chan->language); for (x = 0; x < maxdigits; x++) { - ast_debug(3, "extension so far: '%s', timeout: %d\n", exten, timeout); + if (option_debug > 3) + ast_log(LOG_DEBUG, "extension so far: '%s', timeout: %d\n", exten, timeout); res = ast_waitfordigit(chan, timeout); ast_playtones_stop(chan); @@ -164,16 +169,19 @@ timeout = digit_timeout; if (res < 1) { /* timeout expired or hangup */ - if (ast_check_hangup(chan)) + if (ast_check_hangup(chan)) { status = "HANGUP"; - else + } else { + pbx_builtin_setvar_helper(chan, arglist.variable, "t"); status = "TIMEOUT"; + } break; } else if (res == '#') { break; } exten[x] = res; + exten[x+1] = '\0'; if (!ast_matchmore_extension(chan, arglist.context, exten, 1 /* priority */, chan->cid.cid_num)) { break; } @@ -183,11 +191,14 @@ break; if (ast_exists_extension(chan, arglist.context, exten, 1, chan->cid.cid_num)) { - ast_debug(3, "User entered valid extension '%s'\n", exten); + if (option_debug > 3) + ast_log(LOG_DEBUG, "User entered valid extension '%s'\n", exten); pbx_builtin_setvar_helper(chan, arglist.variable, exten); status = "OK"; } else { - ast_debug(3, "User dialed invalid extension '%s' in context '%s' on %s\n", exten, arglist.context, chan->name); + if (option_debug > 3) + ast_log(LOG_DEBUG, "User dialed invalid extension '%s' in context '%s' on %s\n", exten, arglist.context, chan->name); + pbx_builtin_setvar_helper(chan, arglist.variable, "i"); pbx_builtin_setvar_helper(chan, "INVALID_EXTEN", exten); status = "INVALID"; } @@ -244,7 +255,6 @@ { int res = ast_unregister_application(app); res |= ast_custom_function_unregister(&acf_isexten); - return res; } @@ -255,4 +265,4 @@ return res; } -AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Read and evaluate extension validity"); +AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Collect digits until extension is matched");