]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
pbx_builtins: Allow custom tone for WaitExten.
authorNaveen Albert <asterisk@phreaknet.org>
Mon, 25 Aug 2025 17:58:31 +0000 (13:58 -0400)
committerNaveen Albert <asterisk@phreaknet.org>
Thu, 4 Sep 2025 15:03:39 +0000 (15:03 +0000)
Currently, the 'd' option will play dial tone while waiting
for digits. Allow it to accept an argument for any tone from
indications.conf.

Resolves: #1396

UserNote: The tone used while waiting for digits in WaitExten
can now be overridden by specifying an argument for the 'd'
option.

main/pbx_builtins.c

index 859f93992111d8f282a30cb1a41a3516ab49f5cb..06ce9965ff7f9fdf25e992dcff0eadfab5fbcd44 100644 (file)
                                                </argument>
                                        </option>
                                        <option name="d">
-                                               <para>Play <literal>dial</literal> indications tone on channel while waiting
-                                               for digits.</para>
+                                               <para>Play indications tone on channel while waiting for digits.</para>
+                                               <argument name="x">
+                                                       <para>Specify the indications tone to play.
+                                                       Default is <literal>dial</literal> tone.</para>
+                                               </argument>
                                        </option>
                                </optionlist>
                        </parameter>
@@ -787,12 +790,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)
@@ -1129,7 +1141,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);
@@ -1143,15 +1155,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);