2 * Asterisk -- A telephony toolkit for Linux.
4 * Trivial application to playback a sound file
6 * Copyright (C) 1999-2005, Mark Spencer
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/module.h>
20 #include <asterisk/translate.h>
21 #include <asterisk/utils.h>
25 static char *tdesc = "Sound File Playback Application";
27 static char *app = "Playback";
29 static char *synopsis = "Play a file";
31 static char *descrip =
32 " Playback(filename[&filename2...][|option]): Plays back given filenames (do not put\n"
33 "extension). Options may also be included following a pipe symbol. The 'skip'\n"
34 "option causes the playback of the message to be skipped if the channel\n"
35 "is not in the 'up' state (i.e. it hasn't been answered yet. If 'skip' is \n"
36 "specified, the application will return immediately should the channel not be\n"
37 "off hook. Otherwise, unless 'noanswer' is specified, the channel channel will\n"
38 "be answered before the sound is played. Not all channels support playing\n"
39 "messages while still hook. Returns -1 if the channel was hung up. If the\n"
40 "file does not exist, will jump to priority n+101 if present.\n";
46 static int playback_exec(struct ast_channel *chan, void *data)
53 int option_noanswer = 0;
55 char *front = NULL, *back = NULL;
56 if (!data || ast_strlen_zero((char *)data) || !(tmp = ast_strdupa(data))) {
57 ast_log(LOG_WARNING, "Playback requires an argument (filename)\n");
61 strsep(&stringp, "|");
62 options = strsep(&stringp, "|");
63 if (options && !strcasecmp(options, "skip"))
65 if (options && !strcasecmp(options, "noanswer"))
68 if (chan->_state != AST_STATE_UP) {
70 /* At the user's option, skip if the line is not up */
73 } else if (!option_noanswer)
74 /* Otherwise answer unless we're supposed to send this while on-hook */
75 res = ast_answer(chan);
80 while (!res && front) {
81 if ((back = strchr(front, '&'))) {
85 res = ast_streamfile(chan, front, chan->language);
87 res = ast_waitstream(chan, "");
90 ast_log(LOG_WARNING, "ast_streamfile failed on %s for %s\n", chan->name, (char *)data);
91 if (ast_exists_extension(chan, chan->context, chan->exten, chan->priority + 101, chan->cid.cid_num))
102 int unload_module(void)
104 STANDARD_HANGUP_LOCALUSERS;
105 return ast_unregister_application(app);
108 int load_module(void)
110 return ast_register_application(app, playback_exec, synopsis, descrip);
113 char *description(void)
121 STANDARD_USECOUNT(res);
127 return ASTERISK_GPL_KEY;