1999-11-21 21:15:14 +00:00
|
|
|
/*
|
|
|
|
* Asterisk -- A telephony toolkit for Linux.
|
|
|
|
*
|
|
|
|
* Trivial application to playback a sound file
|
|
|
|
*
|
2005-03-10 07:47:02 +00:00
|
|
|
* Copyright (C) 1999-2005, Mark Spencer
|
1999-11-21 21:15:14 +00:00
|
|
|
*
|
2005-03-10 07:47:02 +00:00
|
|
|
* Mark Spencer <markster@digium.com>
|
1999-11-21 21:15:14 +00:00
|
|
|
*
|
|
|
|
* This program is free software, distributed under the terms of
|
|
|
|
* the GNU General Public License
|
|
|
|
*/
|
|
|
|
|
2005-06-06 22:39:32 +00:00
|
|
|
#include <string.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
#include "asterisk.h"
|
|
|
|
|
|
|
|
ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
|
|
|
|
|
2005-04-21 06:02:45 +00:00
|
|
|
#include "asterisk/lock.h"
|
|
|
|
#include "asterisk/file.h"
|
|
|
|
#include "asterisk/logger.h"
|
|
|
|
#include "asterisk/channel.h"
|
|
|
|
#include "asterisk/pbx.h"
|
|
|
|
#include "asterisk/module.h"
|
|
|
|
#include "asterisk/translate.h"
|
|
|
|
#include "asterisk/utils.h"
|
1999-11-21 21:15:14 +00:00
|
|
|
|
2005-03-10 07:47:02 +00:00
|
|
|
static char *tdesc = "Sound File Playback Application";
|
1999-11-21 21:15:14 +00:00
|
|
|
|
|
|
|
static char *app = "Playback";
|
|
|
|
|
2001-04-10 17:18:04 +00:00
|
|
|
static char *synopsis = "Play a file";
|
|
|
|
|
|
|
|
static char *descrip =
|
2005-03-10 07:47:02 +00:00
|
|
|
" Playback(filename[&filename2...][|option]): Plays back given filenames (do not put\n"
|
2004-07-19 02:18:11 +00:00
|
|
|
"extension). Options may also be included following a pipe symbol. The 'skip'\n"
|
|
|
|
"option causes the playback of the message to be skipped if the channel\n"
|
|
|
|
"is not in the 'up' state (i.e. it hasn't been answered yet. If 'skip' is \n"
|
|
|
|
"specified, the application will return immediately should the channel not be\n"
|
|
|
|
"off hook. Otherwise, unless 'noanswer' is specified, the channel channel will\n"
|
|
|
|
"be answered before the sound is played. Not all channels support playing\n"
|
2004-10-26 02:25:50 +00:00
|
|
|
"messages while still hook. Returns -1 if the channel was hung up. If the\n"
|
|
|
|
"file does not exist, will jump to priority n+101 if present.\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;
|
2005-03-10 07:47:02 +00:00
|
|
|
char *tmp = NULL;
|
|
|
|
char *options = NULL;
|
2001-06-19 07:19:07 +00:00
|
|
|
int option_skip=0;
|
2001-11-10 02:55:10 +00:00
|
|
|
int option_noanswer = 0;
|
2005-03-10 07:47:02 +00:00
|
|
|
char *stringp = NULL;
|
|
|
|
char *front = NULL, *back = NULL;
|
|
|
|
if (!data || ast_strlen_zero((char *)data) || !(tmp = ast_strdupa(data))) {
|
1999-11-21 21:15:14 +00:00
|
|
|
ast_log(LOG_WARNING, "Playback requires an argument (filename)\n");
|
|
|
|
return -1;
|
|
|
|
}
|
2005-03-10 07:47:02 +00:00
|
|
|
stringp = tmp;
|
2002-11-11 16:37:01 +00:00
|
|
|
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);
|
2005-03-10 07:47:02 +00:00
|
|
|
front = tmp;
|
|
|
|
while (!res && front) {
|
|
|
|
if ((back = strchr(front, '&'))) {
|
|
|
|
*back = '\0';
|
|
|
|
back++;
|
|
|
|
}
|
|
|
|
res = ast_streamfile(chan, front, chan->language);
|
|
|
|
if (!res) {
|
|
|
|
res = ast_waitstream(chan, "");
|
|
|
|
ast_stopstream(chan);
|
|
|
|
} else {
|
|
|
|
ast_log(LOG_WARNING, "ast_streamfile failed on %s for %s\n", chan->name, (char *)data);
|
2005-09-07 19:13:00 +00:00
|
|
|
ast_goto_if_exists(chan, chan->context, chan->exten, chan->priority + 101);
|
2005-03-10 07:47:02 +00:00
|
|
|
res = 0;
|
|
|
|
}
|
|
|
|
front = back;
|
2002-07-12 09:03:50 +00:00
|
|
|
}
|
2000-01-09 19:58:18 +00:00
|
|
|
}
|
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;
|
|
|
|
}
|