Allow SendDTMF to play digits to a specified channel.
authorMark Michelson <mmichelson@digium.com>
Mon, 24 May 2010 22:16:29 +0000 (22:16 +0000)
committerMark Michelson <mmichelson@digium.com>
Mon, 24 May 2010 22:16:29 +0000 (22:16 +0000)
Patch supplied by reporter was modified to use autoservice and
prevent a potential channel ref leak but is otherwise as the
reporter uploaded it.

(closes issue #17182)
Reported by: rcasas
Patches:
      app_senddtmf.c.patch_trunk uploaded by rcasas (license 641)

git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@265453 65c4cc65-6c06-0410-ace0-fbb531ad65f3

apps/app_senddtmf.c

index 16ca4b5..2af67a2 100644 (file)
@@ -50,6 +50,9 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
                        <parameter name="duration_ms" required="false">
                                <para>Duration of each digit</para>
                        </parameter>
+                        <parameter name="channel" required="false">
+                                <para>Channel where digits will be played</para>
+                        </parameter>
                </syntax>
                <description>
                        <para>DTMF digits sent to a channel with half second pause</para>
@@ -84,10 +87,12 @@ static int senddtmf_exec(struct ast_channel *chan, const char *vdata)
        int res = 0;
        char *data;
        int dinterval = 0, duration = 0;
+       struct ast_channel *dchan;
        AST_DECLARE_APP_ARGS(args,
                AST_APP_ARG(digits);
                AST_APP_ARG(dinterval);
                AST_APP_ARG(duration);
+               AST_APP_ARG(channel);
        );
 
        if (ast_strlen_zero(vdata)) {
@@ -95,6 +100,8 @@ static int senddtmf_exec(struct ast_channel *chan, const char *vdata)
                return 0;
        }
 
+       dchan = chan;
+
        data = ast_strdupa(vdata);
        AST_STANDARD_APP_ARGS(args, data);
 
@@ -104,8 +111,17 @@ static int senddtmf_exec(struct ast_channel *chan, const char *vdata)
        if (!ast_strlen_zero(args.duration)) {
                ast_app_parse_timelen(args.duration, &duration, TIMELEN_MILLISECONDS);
        }
-
-       res = ast_dtmf_stream(chan, NULL, args.digits, dinterval <= 0 ? 250 : dinterval, duration);
+       if (!ast_strlen_zero(args.channel)) {
+               dchan = ast_channel_get_by_name(args.channel);
+       }
+       if (dchan != chan) {
+               ast_autoservice_start(chan);
+       }
+       res = ast_dtmf_stream(dchan, NULL, args.digits, dinterval <= 0 ? 250 : dinterval, duration);
+       if (dchan != chan) {
+               ast_autoservice_stop(chan);
+               ast_channel_unref(dchan);
+       }
 
        return res;
 }