1999-11-21 21:15:14 +00:00
|
|
|
/*
|
|
|
|
* Asterisk -- A telephony toolkit for Linux.
|
|
|
|
*
|
|
|
|
* Trivial application to playback a sound file
|
|
|
|
*
|
1999-12-11 20:09:45 +00:00
|
|
|
* Copyright (C) 1999, Mark Spencer
|
1999-11-21 21:15:14 +00:00
|
|
|
*
|
|
|
|
* Mark Spencer <markster@linux-support.net>
|
|
|
|
*
|
|
|
|
* This program is free software, distributed under the terms of
|
|
|
|
* the GNU General Public License
|
|
|
|
*/
|
|
|
|
|
2002-05-13 22:29:39 +00:00
|
|
|
#include <asterisk/lock.h>
|
1999-11-21 21:15:14 +00:00
|
|
|
#include <asterisk/file.h>
|
|
|
|
#include <asterisk/logger.h>
|
|
|
|
#include <asterisk/channel.h>
|
|
|
|
#include <asterisk/pbx.h>
|
|
|
|
#include <asterisk/module.h>
|
|
|
|
#include <asterisk/translate.h>
|
2004-05-09 07:51:44 +00:00
|
|
|
#include <asterisk/utils.h>
|
1999-11-21 21:15:14 +00:00
|
|
|
#include <string.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
static char *tdesc = "Trivial Playback Application";
|
|
|
|
|
|
|
|
static char *app = "Playback";
|
|
|
|
|
2001-04-10 17:18:04 +00:00
|
|
|
static char *synopsis = "Play a file";
|
|
|
|
|
|
|
|
static char *descrip =
|
2001-06-19 07:19:07 +00:00
|
|
|
" Playback(filename[|option]): Plays back a given filename (do not put\n"
|
|
|
|
"extension). Options may also be included following a pipe symbol. The only\n"
|
|
|
|
"defined option at this time is 'skip', which causes the playback of the\n"
|
|
|
|
"message to be skipped if the channel is not in the 'up' state (i.e. it\n"
|
2001-11-10 02:55:10 +00:00
|
|
|
"hasn't been answered yet. If 'skip' is specified, the application will\n"
|
|
|
|
"return immediately should the channel not be off hook. Otherwise, unless\n"
|
|
|
|
"'noanswer' is specified, the channel channel will be answered before the sound\n"
|
|
|
|
"is played. Not all channels support playing messages while on hook. Returns -1\n"
|
|
|
|
"if the channel was hung up, or if the file does not exist. Returns 0 otherwise.\n";
|
2001-04-10 17:18:04 +00:00
|
|
|
|
1999-11-21 21:15:14 +00:00
|
|
|
STANDARD_LOCAL_USER;
|
|
|
|
|
|
|
|
LOCAL_USER_DECL;
|
|
|
|
|
|
|
|
static int playback_exec(struct ast_channel *chan, void *data)
|
|
|
|
{
|
2000-01-09 19:58:18 +00:00
|
|
|
int res = 0;
|
1999-11-21 21:15:14 +00:00
|
|
|
struct localuser *u;
|
2001-06-19 07:19:07 +00:00
|
|
|
char tmp[256];
|
|
|
|
char *options;
|
|
|
|
int option_skip=0;
|
2001-11-10 02:55:10 +00:00
|
|
|
int option_noanswer = 0;
|
2002-11-11 16:37:01 +00:00
|
|
|
char *stringp;
|
2004-05-09 07:51:44 +00:00
|
|
|
if (!data || ast_strlen_zero((char *)data)) {
|
1999-11-21 21:15:14 +00:00
|
|
|
ast_log(LOG_WARNING, "Playback requires an argument (filename)\n");
|
|
|
|
return -1;
|
|
|
|
}
|
2001-11-10 02:55:10 +00:00
|
|
|
strncpy(tmp, (char *)data, sizeof(tmp)-1);
|
2002-11-11 16:37:01 +00:00
|
|
|
stringp=tmp;
|
|
|
|
strsep(&stringp, "|");
|
|
|
|
options = strsep(&stringp, "|");
|
2001-06-19 07:19:07 +00:00
|
|
|
if (options && !strcasecmp(options, "skip"))
|
|
|
|
option_skip = 1;
|
2001-11-10 02:55:10 +00:00
|
|
|
if (options && !strcasecmp(options, "noanswer"))
|
|
|
|
option_noanswer = 1;
|
1999-11-21 21:15:14 +00:00
|
|
|
LOCAL_USER_ADD(u);
|
2002-07-12 09:03:50 +00:00
|
|
|
if (chan->_state != AST_STATE_UP) {
|
2001-06-19 07:19:07 +00:00
|
|
|
if (option_skip) {
|
|
|
|
/* At the user's option, skip if the line is not up */
|
|
|
|
LOCAL_USER_REMOVE(u);
|
|
|
|
return 0;
|
2001-11-10 02:55:10 +00:00
|
|
|
} else if (!option_noanswer)
|
|
|
|
/* Otherwise answer unless we're supposed to send this while on-hook */
|
2001-06-19 07:19:07 +00:00
|
|
|
res = ast_answer(chan);
|
|
|
|
}
|
2000-01-09 19:58:18 +00:00
|
|
|
if (!res) {
|
|
|
|
ast_stopstream(chan);
|
2001-06-19 07:19:07 +00:00
|
|
|
res = ast_streamfile(chan, tmp, chan->language);
|
2000-10-25 23:22:50 +00:00
|
|
|
if (!res)
|
2000-01-09 19:58:18 +00:00
|
|
|
res = ast_waitstream(chan, "");
|
2002-07-12 09:03:50 +00:00
|
|
|
else {
|
2000-10-25 23:22:50 +00:00
|
|
|
ast_log(LOG_WARNING, "ast_streamfile failed on %s for %s\n", chan->name, (char *)data);
|
2002-07-12 09:03:50 +00:00
|
|
|
res = 0;
|
|
|
|
}
|
2000-01-09 19:58:18 +00:00
|
|
|
ast_stopstream(chan);
|
|
|
|
}
|
1999-11-21 21:15:14 +00:00
|
|
|
LOCAL_USER_REMOVE(u);
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
int unload_module(void)
|
|
|
|
{
|
|
|
|
STANDARD_HANGUP_LOCALUSERS;
|
|
|
|
return ast_unregister_application(app);
|
|
|
|
}
|
|
|
|
|
|
|
|
int load_module(void)
|
|
|
|
{
|
2001-04-10 17:18:04 +00:00
|
|
|
return ast_register_application(app, playback_exec, synopsis, descrip);
|
1999-11-21 21:15:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
char *description(void)
|
|
|
|
{
|
|
|
|
return tdesc;
|
|
|
|
}
|
|
|
|
|
|
|
|
int usecount(void)
|
|
|
|
{
|
|
|
|
int res;
|
|
|
|
STANDARD_USECOUNT(res);
|
|
|
|
return res;
|
|
|
|
}
|
2001-03-07 00:52:22 +00:00
|
|
|
|
|
|
|
char *key()
|
|
|
|
{
|
|
|
|
return ASTERISK_GPL_KEY;
|
|
|
|
}
|