From 47abf96957e1a8a513f80dbbc47734128d8ebc8b Mon Sep 17 00:00:00 2001 From: Jason Parker Date: Wed, 27 Sep 2006 20:03:23 +0000 Subject: [PATCH] Add BACKGROUNDSTATUS to Background() Issue #7835, original patch by bcnit - redone by me. git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@43814 65c4cc65-6c06-0410-ace0-fbb531ad65f3 --- main/pbx.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/main/pbx.c b/main/pbx.c index a800ae8739..480c41a78e 100644 --- a/main/pbx.c +++ b/main/pbx.c @@ -284,6 +284,9 @@ static struct pbx_builtin { " n - Don't answer the channel before playing the files.\n" " m - Only break if a digit hit matches a one digit\n" " extension in the destination context.\n" + "This application sets the following channel variable upon completion:\n" + " BACKGROUNDSTATUS The status of the background attempt as a text string, one of\n" + " SUCCESS | FAILED\n" }, { "Busy", pbx_builtin_busy, @@ -5283,6 +5286,7 @@ static int pbx_builtin_waitexten(struct ast_channel *chan, void *data) static int pbx_builtin_background(struct ast_channel *chan, void *data) { int res = 0; + int mres = 0; struct ast_flags flags = {0}; char *parse; AST_DECLARE_APP_ARGS(args, @@ -5319,7 +5323,7 @@ static int pbx_builtin_background(struct ast_channel *chan, void *data) /* Answer if need be */ if (chan->_state != AST_STATE_UP) { if (ast_test_flag(&flags, BACKGROUND_SKIP)) { - return 0; + goto done; } else if (!ast_test_flag(&flags, BACKGROUND_NOANSWER)) { res = ast_answer(chan); } @@ -5328,12 +5332,14 @@ static int pbx_builtin_background(struct ast_channel *chan, void *data) if (!res) { char *back = args.filename; char *front; + ast_stopstream(chan); /* Stop anything playing */ /* Stream the list of files */ while (!res && (front = strsep(&back, "&")) ) { if ( (res = ast_streamfile(chan, front, args.lang)) ) { ast_log(LOG_WARNING, "ast_streamfile failed on %s for %s\n", chan->name, (char*)data); res = 0; + mres = 1; break; } if (ast_test_flag(&flags, BACKGROUND_PLAYBACK)) { @@ -5352,6 +5358,8 @@ static int pbx_builtin_background(struct ast_channel *chan, void *data) chan->priority = 0; res = 0; } +done: + pbx_builtin_setvar_helper(chan, "BACKGROUNDSTATUS", mres ? "FAILED" : "SUCCESS"); return res; }