2 * Asterisk -- A telephony toolkit for Linux.
4 * Trivial application to read a variable
6 * Copyright (C) 2003, Digium
8 * Mark Spencer <markster@digium.com>
10 * This program is free software, distributed under the terms of
11 * the GNU General Public License
14 #include <asterisk/lock.h>
15 #include <asterisk/file.h>
16 #include <asterisk/logger.h>
17 #include <asterisk/channel.h>
18 #include <asterisk/pbx.h>
19 #include <asterisk/app.h>
20 #include <asterisk/module.h>
21 #include <asterisk/translate.h>
26 static char *tdesc = "Read Variable Application";
28 static char *app = "Read";
30 static char *synopsis = "Read a variable";
32 static char *descrip =
33 " Read(variable[|filename]): Reads a '#' terminated string of digits from\n"
34 "the user, optionally playing a given filename first. Returns -1 on hangup or\n"
35 "error and 0 otherwise.\n";
41 static int read_exec(struct ast_channel *chan, void *data)
49 if (!data || !strlen((char *)data)) {
50 ast_log(LOG_WARNING, "Read requires an argument (variable)\n");
53 strncpy(tmp, (char *)data, sizeof(tmp)-1);
55 strsep(&stringp, "|");
56 filename = strsep(&stringp, "|");
58 if (chan->_state != AST_STATE_UP) {
59 /* Answer if the line isn't up. */
60 res = ast_answer(chan);
64 res = ast_app_getdata(chan, filename, tmp2, sizeof(tmp2) - 1, 0);
65 ast_verbose("You entered '%s'\n", tmp2);
71 int unload_module(void)
73 STANDARD_HANGUP_LOCALUSERS;
74 return ast_unregister_application(app);
79 return ast_register_application(app, read_exec, synopsis, descrip);
82 char *description(void)
90 STANDARD_USECOUNT(res);
96 return ASTERISK_GPL_KEY;