#include "asterisk.h"
#include "asterisk/file.h"
#include "asterisk/pbx.h"
#include "asterisk/app.h"
#include "asterisk/module.h"
#include "asterisk/indications.h"
#include "asterisk/channel.h"
Go to the source code of this file.
Enumerations | |
enum | { OPT_SKIP = (1 << 0), OPT_INDICATION = (1 << 1), OPT_NOANSWER = (1 << 2) } |
Functions | |
static void | __reg_module (void) |
static void | __unreg_module (void) |
static int | acf_isexten_exec (struct ast_channel *chan, const char *cmd, char *parse, char *buffer, size_t buflen) |
static int | load_module (void) |
static int | readexten_exec (struct ast_channel *chan, void *data) |
static int | unload_module (void) |
Variables | |
static struct ast_module_info | __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_DEFAULT , .description = "Read and evaluate extension validity" , .key = "This paragraph is copyright (c) 2006 by Digium, Inc. \In order for your module to load, it must return this \key via a function called \"key\". Any code which \includes this paragraph must be licensed under the GNU \General Public License version 2 or later (at your \option). In addition to Digium's general reservations \of rights, Digium expressly reserves the right to \allow other parties to license this paragraph under \different terms. Any use of Digium, Inc. trademarks or \logos (including \"Asterisk\" or \"Digium\") without \express written permission of Digium, Inc. is prohibited.\n" , .buildopt_sum = "068e67f60f50dd9ee86464c05884a49d" , .load = load_module, .unload = unload_module, } |
static struct ast_custom_function | acf_isexten |
static char * | app = "ReadExten" |
static const struct ast_module_info * | ast_module_info = &__mod_info |
static char * | descrip |
static struct ast_app_option | readexten_app_options [128] = { [ 's' ] = { .flag = OPT_SKIP }, [ 'i' ] = { .flag = OPT_INDICATION }, [ 'n' ] = { .flag = OPT_NOANSWER },} |
enum { ... } | readexten_option_flags |
static char * | synopsis = "Read an extension into a variable" |
Definition in file app_readexten.c.
anonymous enum |
Definition at line 39 of file app_readexten.c.
00039 { 00040 OPT_SKIP = (1 << 0), 00041 OPT_INDICATION = (1 << 1), 00042 OPT_NOANSWER = (1 << 2), 00043 } readexten_option_flags;
static void __reg_module | ( | void | ) | [static] |
Definition at line 258 of file app_readexten.c.
static void __unreg_module | ( | void | ) | [static] |
Definition at line 258 of file app_readexten.c.
static int acf_isexten_exec | ( | struct ast_channel * | chan, | |
const char * | cmd, | |||
char * | parse, | |||
char * | buffer, | |||
size_t | buflen | |||
) | [static] |
Definition at line 201 of file app_readexten.c.
References AST_APP_ARG, ast_copy_string(), AST_DECLARE_APP_ARGS, ast_exists_extension(), ast_log(), AST_STANDARD_APP_ARGS, ast_strlen_zero(), chan, ast_channel::cid, ast_callerid::cid_num, ast_channel::context, context, and LOG_WARNING.
00202 { 00203 int priority_int; 00204 AST_DECLARE_APP_ARGS(args, 00205 AST_APP_ARG(context); 00206 AST_APP_ARG(extension); 00207 AST_APP_ARG(priority); 00208 ); 00209 00210 AST_STANDARD_APP_ARGS(args, parse); 00211 00212 if (ast_strlen_zero(args.context)) 00213 args.context = chan->context; 00214 00215 if (ast_strlen_zero(args.extension)) { 00216 ast_log(LOG_WARNING, "Syntax: VALID_EXTEN([<context>],<extension>[,<priority>]) - missing argument <extension>!\n"); 00217 return -1; 00218 } 00219 00220 if (ast_strlen_zero(args.priority)) 00221 priority_int = 1; 00222 else 00223 priority_int = atoi(args.priority); 00224 00225 if (ast_exists_extension(chan, args.context, args.extension, priority_int, chan->cid.cid_num)) 00226 ast_copy_string(buffer, "1", buflen); 00227 else 00228 ast_copy_string(buffer, "0", buflen); 00229 00230 return 0; 00231 }
static int load_module | ( | void | ) | [static] |
Definition at line 251 of file app_readexten.c.
References acf_isexten, ast_custom_function_register, ast_register_application, and readexten_exec().
00252 { 00253 int res = ast_register_application(app, readexten_exec, synopsis, descrip); 00254 res |= ast_custom_function_register(&acf_isexten); 00255 return res; 00256 }
static int readexten_exec | ( | struct ast_channel * | chan, | |
void * | data | |||
) | [static] |
Definition at line 75 of file app_readexten.c.
References ast_channel::_state, ast_answer(), AST_APP_ARG, ast_app_parse_options(), ast_check_hangup(), ast_debug, AST_DECLARE_APP_ARGS, ast_exists_extension(), ast_get_indication_tone(), ast_log(), ast_matchmore_extension(), ast_playtones_start(), ast_playtones_stop(), AST_STANDARD_APP_ARGS, AST_STATE_UP, ast_stopstream(), ast_strdupa, ast_streamfile(), ast_strlen_zero(), ast_test_flag, ast_waitfordigit(), chan, ast_channel::cid, ast_callerid::cid_num, ast_channel::context, context, tone_zone_sound::data, ast_pbx::dtimeout, exten, ast_flags::flags, ast_channel::language, LOG_WARNING, ast_channel::name, OPT_INDICATION, OPT_NOANSWER, OPT_SKIP, ast_channel::pbx, pbx_builtin_setvar_helper(), ast_pbx::rtimeout, status, and ast_channel::zone.
Referenced by load_module().
00076 { 00077 int res = 0; 00078 char exten[256] = ""; 00079 int maxdigits = sizeof(exten) - 1; 00080 int timeout = 0, digit_timeout = 0, x = 0; 00081 char *argcopy = NULL, *status = ""; 00082 struct tone_zone_sound *ts = NULL; 00083 struct ast_flags flags = {0}; 00084 00085 AST_DECLARE_APP_ARGS(arglist, 00086 AST_APP_ARG(variable); 00087 AST_APP_ARG(filename); 00088 AST_APP_ARG(context); 00089 AST_APP_ARG(options); 00090 AST_APP_ARG(timeout); 00091 ); 00092 00093 if (ast_strlen_zero(data)) { 00094 ast_log(LOG_WARNING, "ReadExten requires at least one argument\n"); 00095 pbx_builtin_setvar_helper(chan, "READEXTENSTATUS", "ERROR"); 00096 return 0; 00097 } 00098 00099 argcopy = ast_strdupa(data); 00100 AST_STANDARD_APP_ARGS(arglist, argcopy); 00101 00102 if (ast_strlen_zero(arglist.variable)) { 00103 ast_log(LOG_WARNING, "Invalid! Usage: ReadExten(variable[|filename][|context][|options][|timeout])\n\n"); 00104 pbx_builtin_setvar_helper(chan, "READEXTENSTATUS", "ERROR"); 00105 return 0; 00106 } 00107 00108 if (ast_strlen_zero(arglist.filename)) 00109 arglist.filename = NULL; 00110 00111 if (ast_strlen_zero(arglist.context)) 00112 arglist.context = chan->context; 00113 00114 if (!ast_strlen_zero(arglist.options)) 00115 ast_app_parse_options(readexten_app_options, &flags, NULL, arglist.options); 00116 00117 if (!ast_strlen_zero(arglist.timeout)) { 00118 timeout = atoi(arglist.timeout); 00119 if (timeout > 0) 00120 timeout *= 1000; 00121 } 00122 00123 if (timeout <= 0) 00124 timeout = chan->pbx ? chan->pbx->rtimeout * 1000 : 10000; 00125 00126 if (digit_timeout <= 0) 00127 digit_timeout = chan->pbx ? chan->pbx->dtimeout * 1000 : 5000; 00128 00129 if (ast_test_flag(&flags, OPT_INDICATION) && !ast_strlen_zero(arglist.filename)) 00130 ts = ast_get_indication_tone(chan->zone, arglist.filename); 00131 00132 do { 00133 if (chan->_state != AST_STATE_UP) { 00134 if (ast_test_flag(&flags, OPT_SKIP)) { 00135 /* At the user's option, skip if the line is not up */ 00136 pbx_builtin_setvar_helper(chan, arglist.variable, ""); 00137 status = "SKIP"; 00138 break; 00139 } else if (!ast_test_flag(&flags, OPT_NOANSWER)) { 00140 /* Otherwise answer unless we're supposed to read while on-hook */ 00141 res = ast_answer(chan); 00142 } 00143 } 00144 00145 if (res < 0) { 00146 status = "HANGUP"; 00147 break; 00148 } 00149 00150 ast_playtones_stop(chan); 00151 ast_stopstream(chan); 00152 00153 if (ts && ts->data[0]) 00154 res = ast_playtones_start(chan, 0, ts->data, 0); 00155 else if (arglist.filename) 00156 res = ast_streamfile(chan, arglist.filename, chan->language); 00157 00158 for (x = 0; x < maxdigits; x++) { 00159 ast_debug(3, "extension so far: '%s', timeout: %d\n", exten, timeout); 00160 res = ast_waitfordigit(chan, timeout); 00161 00162 ast_playtones_stop(chan); 00163 ast_stopstream(chan); 00164 timeout = digit_timeout; 00165 00166 if (res < 1) { /* timeout expired or hangup */ 00167 if (ast_check_hangup(chan)) 00168 status = "HANGUP"; 00169 else 00170 status = "TIMEOUT"; 00171 break; 00172 } else if (res == '#') { 00173 break; 00174 } 00175 00176 exten[x] = res; 00177 if (!ast_matchmore_extension(chan, arglist.context, exten, 1 /* priority */, chan->cid.cid_num)) { 00178 break; 00179 } 00180 } 00181 00182 if (!ast_strlen_zero(status)) 00183 break; 00184 00185 if (ast_exists_extension(chan, arglist.context, exten, 1, chan->cid.cid_num)) { 00186 ast_debug(3, "User entered valid extension '%s'\n", exten); 00187 pbx_builtin_setvar_helper(chan, arglist.variable, exten); 00188 status = "OK"; 00189 } else { 00190 ast_debug(3, "User dialed invalid extension '%s' in context '%s' on %s\n", exten, arglist.context, chan->name); 00191 pbx_builtin_setvar_helper(chan, "INVALID_EXTEN", exten); 00192 status = "INVALID"; 00193 } 00194 } while (0); 00195 00196 pbx_builtin_setvar_helper(chan, "READEXTENSTATUS", status); 00197 00198 return status[0] == 'H' ? -1 : 0; 00199 }
static int unload_module | ( | void | ) | [static] |
Definition at line 243 of file app_readexten.c.
References acf_isexten, ast_custom_function_unregister(), and ast_unregister_application().
00244 { 00245 int res = ast_unregister_application(app); 00246 res |= ast_custom_function_unregister(&acf_isexten); 00247 00248 return res; 00249 }
struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_DEFAULT , .description = "Read and evaluate extension validity" , .key = "This paragraph is copyright (c) 2006 by Digium, Inc. \In order for your module to load, it must return this \key via a function called \"key\". Any code which \includes this paragraph must be licensed under the GNU \General Public License version 2 or later (at your \option). In addition to Digium's general reservations \of rights, Digium expressly reserves the right to \allow other parties to license this paragraph under \different terms. Any use of Digium, Inc. trademarks or \logos (including \"Asterisk\" or \"Digium\") without \express written permission of Digium, Inc. is prohibited.\n" , .buildopt_sum = "068e67f60f50dd9ee86464c05884a49d" , .load = load_module, .unload = unload_module, } [static] |
Definition at line 258 of file app_readexten.c.
struct ast_custom_function acf_isexten [static] |
char* app = "ReadExten" [static] |
Definition at line 51 of file app_readexten.c.
const struct ast_module_info* ast_module_info = &__mod_info [static] |
Definition at line 258 of file app_readexten.c.
char* descrip [static] |
Definition at line 55 of file app_readexten.c.
struct ast_app_option readexten_app_options[128] = { [ 's' ] = { .flag = OPT_SKIP }, [ 'i' ] = { .flag = OPT_INDICATION }, [ 'n' ] = { .flag = OPT_NOANSWER },} [static] |
Definition at line 49 of file app_readexten.c.
enum { ... } readexten_option_flags |
char* synopsis = "Read an extension into a variable" [static] |
Definition at line 53 of file app_readexten.c.