[Asterisk-cvs] asterisk pbx.c,1.138,1.139
markster at lists.digium.com
markster at lists.digium.com
Sun Jul 18 20:44:38 CDT 2004
Update of /usr/cvsroot/asterisk
In directory localhost.localdomain:/tmp/cvs-serv6969
Modified Files:
pbx.c
Log Message:
Add options to background (bug #2075) and update documentation
Index: pbx.c
===================================================================
RCS file: /usr/cvsroot/asterisk/pbx.c,v
retrieving revision 1.138
retrieving revision 1.139
diff -u -d -r1.138 -r1.139
--- pbx.c 17 Jul 2004 02:25:53 -0000 1.138
+++ pbx.c 19 Jul 2004 00:30:39 -0000 1.139
@@ -197,9 +197,17 @@
{ "BackGround", pbx_builtin_background,
"Play a file while awaiting extension",
- " Background(filename): Plays a given file, while simultaneously waiting for\n"
- "the user to begin typing an extension. The timeouts do not count until the\n"
- "last BackGround application has ended. Always returns 0.\n"
+ " Background(filename[|options]): Plays a given file, while simultaneously\n"
+ "waiting for the user to begin typing an extension. The timeouts do not\n"
+ "count until the last BackGround application has ended.\n"
+ "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"
+ "messages while still hook. Returns -1 if the channel was hung up, or if the\n"
+ "file does not exist. Returns 0 otherwise.\n"
},
{ "Busy", pbx_builtin_busy,
@@ -4431,20 +4439,51 @@
static int pbx_builtin_background(struct ast_channel *chan, void *data)
{
- int res;
+ int res = 0;
+ int option_skip = 0;
+ int option_noanswer = 0;
+ char filename[256] = "";
+ char* stringp;
+ char* options;
+
+ if (!data || ast_strlen_zero(data)) {
+ ast_log(LOG_WARNING, "Background requires an argument(filename)\n");
+ return -1;
+ }
+
+ strncpy(filename, (char*)data, sizeof(filename) - 1);
+ stringp = filename;
+ strsep(&stringp, "|");
+ options = strsep(&stringp, "|");
+
+ if (options && !strcasecmp(options, "skip"))
+ option_skip = 1;
+ if (options && !strcasecmp(options, "noanswer"))
+ option_noanswer = 1;
+
+ /* Answer if need be */
+ if (chan->_state != AST_STATE_UP) {
+ if (option_skip) {
+ return 0;
+ } else if (!option_noanswer) {
+ res = ast_answer(chan);
+ }
+ }
+
+ if (!res) {
+ /* Stop anything playing */
+ ast_stopstream(chan);
+ /* Stream a file */
+ res = ast_streamfile(chan, filename, chan->language);
+ if (!res) {
+ res = ast_waitstream(chan, AST_DIGIT_ANY);
+ ast_stopstream(chan);
+ } else {
+ ast_log(LOG_WARNING, "ast_streamfile failed on %s fro %s\n", chan->name, (char*)data);
+ res = 0;
+ }
+ }
- /* Answer if need be */
- if (chan->_state != AST_STATE_UP)
- if (ast_answer(chan))
- return -1;
- /* Stop anything playing */
- ast_stopstream(chan);
- /* Stream a file */
- res = ast_streamfile(chan, (char *)data, chan->language);
- if (!res) {
- res = ast_waitstream(chan, AST_DIGIT_ANY);
- ast_stopstream(chan);
- }
return res;
}
More information about the svn-commits
mailing list