diff --git a/main/pbx_builtins.c b/main/pbx_builtins.c index b01eedee25..eda943a953 100644 --- a/main/pbx_builtins.c +++ b/main/pbx_builtins.c @@ -798,8 +798,11 @@ @@ -828,12 +831,21 @@ AST_APP_OPTIONS(background_opts, { AST_APP_OPTION('p', BACKGROUND_PLAYBACK), }); -#define WAITEXTEN_MOH (1 << 0) -#define WAITEXTEN_DIALTONE (1 << 1) +enum { + WAITEXTEN_MOH = (1 << 0), + WAITEXTEN_DIALTONE = (1 << 1), +}; + +enum read_option_flags { + WAITEXTEN_ARG_MOH, + WAITEXTEN_ARG_DIALTONE, + /* note: this entry _MUST_ be the last one in the enum */ + WAITEXTEN_ARRAY_SIZE, +}; AST_APP_OPTIONS(waitexten_opts, { - AST_APP_OPTION_ARG('m', WAITEXTEN_MOH, 0), - AST_APP_OPTION_ARG('d', WAITEXTEN_DIALTONE, 0), + AST_APP_OPTION_ARG('m', WAITEXTEN_MOH, WAITEXTEN_ARG_MOH), + AST_APP_OPTION_ARG('d', WAITEXTEN_DIALTONE, WAITEXTEN_ARG_DIALTONE), }); int pbx_builtin_raise_exception(struct ast_channel *chan, const char *reason) @@ -1203,7 +1215,7 @@ static int pbx_builtin_waitexten(struct ast_channel *chan, const char *data) { int ms, res; struct ast_flags flags = {0}; - char *opts[1] = { NULL }; + char *opt_args[WAITEXTEN_ARRAY_SIZE]; char *parse; AST_DECLARE_APP_ARGS(args, AST_APP_ARG(timeout); @@ -1217,15 +1229,17 @@ static int pbx_builtin_waitexten(struct ast_channel *chan, const char *data) memset(&args, 0, sizeof(args)); if (args.options) - ast_app_parse_options(waitexten_opts, &flags, opts, args.options); + ast_app_parse_options(waitexten_opts, &flags, opt_args, args.options); - if (ast_test_flag(&flags, WAITEXTEN_MOH) && !opts[0] ) { - ast_log(LOG_WARNING, "The 'm' option has been specified for WaitExten without a class.\n"); - } else if (ast_test_flag(&flags, WAITEXTEN_MOH)) { - ast_indicate_data(chan, AST_CONTROL_HOLD, S_OR(opts[0], NULL), - !ast_strlen_zero(opts[0]) ? strlen(opts[0]) + 1 : 0); + if (ast_test_flag(&flags, WAITEXTEN_MOH)) { + if (ast_strlen_zero(opt_args[WAITEXTEN_ARG_MOH])) { + ast_log(LOG_WARNING, "The 'm' option has been specified for WaitExten without a class.\n"); + } + ast_indicate_data(chan, AST_CONTROL_HOLD, S_OR(opt_args[WAITEXTEN_ARG_MOH], NULL), + !ast_strlen_zero(opt_args[WAITEXTEN_ARG_MOH]) ? strlen(opt_args[WAITEXTEN_ARG_MOH]) + 1 : 0); } else if (ast_test_flag(&flags, WAITEXTEN_DIALTONE)) { - struct ast_tone_zone_sound *ts = ast_get_indication_tone(ast_channel_zone(chan), "dial"); + const char *tone = !ast_strlen_zero(opt_args[WAITEXTEN_ARG_DIALTONE]) ? opt_args[WAITEXTEN_ARG_DIALTONE] : "dial"; + struct ast_tone_zone_sound *ts = ast_get_indication_tone(ast_channel_zone(chan), tone); if (ts) { ast_playtones_start(chan, 0, ts->data, 0); ts = ast_tone_zone_sound_unref(ts);