mirror of
https://github.com/asterisk/asterisk.git
synced 2025-10-23 13:09:00 +00:00
use arg parsing macros for WaitExten and Background (issue #6185)
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@8687 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
97
pbx.c
97
pbx.c
@@ -5268,33 +5268,31 @@ static int pbx_builtin_wait(struct ast_channel *chan, void *data)
|
|||||||
*/
|
*/
|
||||||
static int pbx_builtin_waitexten(struct ast_channel *chan, void *data)
|
static int pbx_builtin_waitexten(struct ast_channel *chan, void *data)
|
||||||
{
|
{
|
||||||
int ms, res, argc;
|
int ms, res;
|
||||||
char *args;
|
|
||||||
char *argv[2];
|
|
||||||
char *options = NULL;
|
|
||||||
char *timeout = NULL;
|
|
||||||
struct ast_flags flags = {0};
|
struct ast_flags flags = {0};
|
||||||
char *opts[1] = { NULL };
|
char *opts[1] = { NULL };
|
||||||
|
char *parse;
|
||||||
|
AST_DECLARE_APP_ARGS(args,
|
||||||
|
AST_APP_ARG(timeout);
|
||||||
|
AST_APP_ARG(options);
|
||||||
|
);
|
||||||
|
|
||||||
args = ast_strdupa(data);
|
if (!ast_strlen_zero(data)) {
|
||||||
|
if (!(parse = ast_strdupa(data)))
|
||||||
|
return -1;
|
||||||
|
AST_STANDARD_APP_ARGS(args, parse);
|
||||||
|
} else
|
||||||
|
memset(&args, 0, sizeof(args));
|
||||||
|
|
||||||
if ((argc = ast_app_separate_args(args, '|', argv, sizeof(argv) / sizeof(argv[0])))) {
|
if (args.options)
|
||||||
if (argc > 0) {
|
ast_app_parse_options(waitexten_opts, &flags, opts, args.options);
|
||||||
timeout = argv[0];
|
|
||||||
if (argc > 1)
|
|
||||||
options = argv[1];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (options)
|
|
||||||
ast_app_parse_options(waitexten_opts, &flags, opts, options);
|
|
||||||
|
|
||||||
if (ast_test_flag(&flags, WAITEXTEN_MOH))
|
if (ast_test_flag(&flags, WAITEXTEN_MOH))
|
||||||
ast_moh_start(chan, opts[0]);
|
ast_moh_start(chan, opts[0]);
|
||||||
|
|
||||||
/* Wait for "n" seconds */
|
/* Wait for "n" seconds */
|
||||||
if (timeout && atof((char *)timeout))
|
if (args.timeout && atof((char *)args.timeout))
|
||||||
ms = atof((char *)timeout) * 1000;
|
ms = atof((char *)args.timeout) * 1000;
|
||||||
else if (chan->pbx)
|
else if (chan->pbx)
|
||||||
ms = chan->pbx->rtimeout * 1000;
|
ms = chan->pbx->rtimeout * 1000;
|
||||||
else
|
else
|
||||||
@@ -5327,48 +5325,37 @@ static int pbx_builtin_waitexten(struct ast_channel *chan, void *data)
|
|||||||
static int pbx_builtin_background(struct ast_channel *chan, void *data)
|
static int pbx_builtin_background(struct ast_channel *chan, void *data)
|
||||||
{
|
{
|
||||||
int res = 0;
|
int res = 0;
|
||||||
int argc;
|
|
||||||
char *parse;
|
|
||||||
char *argv[4];
|
|
||||||
char *options = NULL;
|
|
||||||
char *filename = NULL;
|
|
||||||
char *front = NULL, *back = NULL;
|
char *front = NULL, *back = NULL;
|
||||||
char *lang = NULL;
|
|
||||||
char *context = NULL;
|
|
||||||
struct ast_flags flags = {0};
|
struct ast_flags flags = {0};
|
||||||
|
char *parse;
|
||||||
|
AST_DECLARE_APP_ARGS(args,
|
||||||
|
AST_APP_ARG(filename);
|
||||||
|
AST_APP_ARG(options);
|
||||||
|
AST_APP_ARG(lang);
|
||||||
|
AST_APP_ARG(context);
|
||||||
|
);
|
||||||
|
|
||||||
parse = ast_strdupa(data);
|
if (ast_strlen_zero(data))
|
||||||
|
ast_log(LOG_WARNING, "Background requires an argument (filename)\n");
|
||||||
|
|
||||||
if ((argc = ast_app_separate_args(parse, '|', argv, sizeof(argv) / sizeof(argv[0])))) {
|
if (!(parse = ast_strdupa(data)))
|
||||||
switch (argc) {
|
return -1;
|
||||||
case 4:
|
|
||||||
context = argv[3];
|
AST_STANDARD_APP_ARGS(args, parse);
|
||||||
case 3:
|
|
||||||
lang = argv[2];
|
|
||||||
case 2:
|
|
||||||
options = argv[1];
|
|
||||||
case 1:
|
|
||||||
filename = argv[0];
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
ast_log(LOG_WARNING, "Background requires an argument (filename)\n");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!lang)
|
if (!args.lang)
|
||||||
lang = chan->language;
|
args.lang = chan->language;
|
||||||
|
|
||||||
if (!context)
|
if (!args.context)
|
||||||
context = chan->context;
|
args.context = chan->context;
|
||||||
|
|
||||||
if (options) {
|
if (args.options) {
|
||||||
if (!strcasecmp(options, "skip"))
|
if (!strcasecmp(args.options, "skip"))
|
||||||
flags.flags = BACKGROUND_SKIP;
|
flags.flags = BACKGROUND_SKIP;
|
||||||
else if (!strcasecmp(options, "noanswer"))
|
else if (!strcasecmp(args.options, "noanswer"))
|
||||||
flags.flags = BACKGROUND_NOANSWER;
|
flags.flags = BACKGROUND_NOANSWER;
|
||||||
else
|
else
|
||||||
ast_app_parse_options(background_opts, &flags, NULL, options);
|
ast_app_parse_options(background_opts, &flags, NULL, args.options);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Answer if need be */
|
/* Answer if need be */
|
||||||
@@ -5384,19 +5371,19 @@ static int pbx_builtin_background(struct ast_channel *chan, void *data)
|
|||||||
/* Stop anything playing */
|
/* Stop anything playing */
|
||||||
ast_stopstream(chan);
|
ast_stopstream(chan);
|
||||||
/* Stream a file */
|
/* Stream a file */
|
||||||
front = filename;
|
front = args.filename;
|
||||||
while(!res && front) {
|
while(!res && front) {
|
||||||
if((back = strchr(front, '&'))) {
|
if((back = strchr(front, '&'))) {
|
||||||
*back = '\0';
|
*back = '\0';
|
||||||
back++;
|
back++;
|
||||||
}
|
}
|
||||||
res = ast_streamfile(chan, front, lang);
|
res = ast_streamfile(chan, front, args.lang);
|
||||||
if (!res) {
|
if (!res) {
|
||||||
if (ast_test_flag(&flags, BACKGROUND_PLAYBACK)) {
|
if (ast_test_flag(&flags, BACKGROUND_PLAYBACK)) {
|
||||||
res = ast_waitstream(chan, "");
|
res = ast_waitstream(chan, "");
|
||||||
} else {
|
} else {
|
||||||
if (ast_test_flag(&flags, BACKGROUND_MATCHEXTEN)) {
|
if (ast_test_flag(&flags, BACKGROUND_MATCHEXTEN)) {
|
||||||
res = ast_waitstream_exten(chan, context);
|
res = ast_waitstream_exten(chan, args.context);
|
||||||
} else {
|
} else {
|
||||||
res = ast_waitstream(chan, AST_DIGIT_ANY);
|
res = ast_waitstream(chan, AST_DIGIT_ANY);
|
||||||
}
|
}
|
||||||
@@ -5410,9 +5397,9 @@ static int pbx_builtin_background(struct ast_channel *chan, void *data)
|
|||||||
front = back;
|
front = back;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (context != chan->context && res) {
|
if (args.context != chan->context && res) {
|
||||||
snprintf(chan->exten, sizeof(chan->exten), "%c", res);
|
snprintf(chan->exten, sizeof(chan->exten), "%c", res);
|
||||||
ast_copy_string(chan->context, context, sizeof(chan->context));
|
ast_copy_string(chan->context, args.context, sizeof(chan->context));
|
||||||
chan->priority = 0;
|
chan->priority = 0;
|
||||||
return 0;
|
return 0;
|
||||||
} else {
|
} else {
|
||||||
|
Reference in New Issue
Block a user