Wed Jan 27 20:02:02 2016

Asterisk developer's documentation


app_senddtmf.c

Go to the documentation of this file.
00001 /*
00002  * Asterisk -- An open source telephony toolkit.
00003  *
00004  * Copyright (C) 1999 - 2005, Digium, Inc.
00005  *
00006  * Mark Spencer <markster@digium.com>
00007  *
00008  * See http://www.asterisk.org for more information about
00009  * the Asterisk project. Please do not directly contact
00010  * any of the maintainers of this project for assistance;
00011  * the project provides a web site, mailing lists and IRC
00012  * channels for your use.
00013  *
00014  * This program is free software, distributed under the terms of
00015  * the GNU General Public License Version 2. See the LICENSE file
00016  * at the top of the source tree.
00017  */
00018 
00019 /*! \file
00020  *
00021  * \brief App to send DTMF digits
00022  *
00023  * \author Mark Spencer <markster@digium.com>
00024  *
00025  * \ingroup applications
00026  */
00027 
00028 /*** MODULEINFO
00029    <support_level>core</support_level>
00030  ***/
00031 
00032 #include "asterisk.h"
00033 
00034 ASTERISK_FILE_VERSION(__FILE__, "$Revision: 373945 $")
00035 
00036 #include "asterisk/pbx.h"
00037 #include "asterisk/module.h"
00038 #include "asterisk/app.h"
00039 #include "asterisk/manager.h"
00040 #include "asterisk/channel.h"
00041 
00042 /*** DOCUMENTATION
00043    <application name="SendDTMF" language="en_US">
00044       <synopsis>
00045          Sends arbitrary DTMF digits
00046       </synopsis>
00047       <syntax>
00048          <parameter name="digits" required="true">
00049             <para>List of digits 0-9,*#,a-d,A-D to send also w for a half second pause,
00050             and f or F for a flash-hook if the channel supports
00051             flash-hook.</para>
00052          </parameter>
00053          <parameter name="timeout_ms" required="false">
00054             <para>Amount of time to wait in ms between tones. (defaults to .25s)</para>
00055          </parameter>
00056          <parameter name="duration_ms" required="false">
00057             <para>Duration of each digit</para>
00058          </parameter>
00059          <parameter name="channel" required="false">
00060             <para>Channel where digits will be played</para>
00061          </parameter>
00062       </syntax>
00063       <description>
00064          <para>It will send all digits or terminate if it encounters an error.</para>
00065       </description>
00066       <see-also>
00067          <ref type="application">Read</ref>
00068       </see-also>
00069    </application>
00070    <manager name="PlayDTMF" language="en_US">
00071       <synopsis>
00072          Play DTMF signal on a specific channel.
00073       </synopsis>
00074       <syntax>
00075          <xi:include xpointer="xpointer(/docs/manager[@name='Login']/syntax/parameter[@name='ActionID'])" />
00076          <parameter name="Channel" required="true">
00077             <para>Channel name to send digit to.</para>
00078          </parameter>
00079          <parameter name="Digit" required="true">
00080             <para>The DTMF digit to play.</para>
00081          </parameter>
00082       </syntax>
00083       <description>
00084          <para>Plays a dtmf digit on the specified channel.</para>
00085       </description>
00086    </manager>
00087  ***/
00088 
00089 static const char senddtmf_name[] = "SendDTMF";
00090 
00091 static int senddtmf_exec(struct ast_channel *chan, const char *vdata)
00092 {
00093    int res;
00094    char *data;
00095    int dinterval = 0, duration = 0;
00096    struct ast_channel *chan_found = NULL;
00097    struct ast_channel *chan_dest = chan;
00098    struct ast_channel *chan_autoservice = NULL;
00099    AST_DECLARE_APP_ARGS(args,
00100       AST_APP_ARG(digits);
00101       AST_APP_ARG(dinterval);
00102       AST_APP_ARG(duration);
00103       AST_APP_ARG(channel);
00104    );
00105 
00106    if (ast_strlen_zero(vdata)) {
00107       ast_log(LOG_WARNING, "SendDTMF requires an argument\n");
00108       return 0;
00109    }
00110 
00111    data = ast_strdupa(vdata);
00112    AST_STANDARD_APP_ARGS(args, data);
00113 
00114    if (ast_strlen_zero(args.digits)) {
00115       ast_log(LOG_WARNING, "The digits argument is required (0-9,*#,a-d,A-D,wfF)\n");
00116       return 0;
00117    }
00118    if (!ast_strlen_zero(args.dinterval)) {
00119       ast_app_parse_timelen(args.dinterval, &dinterval, TIMELEN_MILLISECONDS);
00120    }
00121    if (!ast_strlen_zero(args.duration)) {
00122       ast_app_parse_timelen(args.duration, &duration, TIMELEN_MILLISECONDS);
00123    }
00124    if (!ast_strlen_zero(args.channel)) {
00125       chan_found = ast_channel_get_by_name(args.channel);
00126       if (!chan_found) {
00127          ast_log(LOG_WARNING, "No such channel: %s\n", args.channel);
00128          return 0;
00129       }
00130       chan_dest = chan_found;
00131       if (chan_found != chan) {
00132          chan_autoservice = chan;
00133       }
00134    }
00135    res = ast_dtmf_stream(chan_dest, chan_autoservice, args.digits,
00136       dinterval <= 0 ? 250 : dinterval, duration);
00137    if (chan_found) {
00138       ast_channel_unref(chan_found);
00139    }
00140 
00141    return chan_autoservice ? 0 : res;
00142 }
00143 
00144 static int manager_play_dtmf(struct mansession *s, const struct message *m)
00145 {
00146    const char *channel = astman_get_header(m, "Channel");
00147    const char *digit = astman_get_header(m, "Digit");
00148    struct ast_channel *chan;
00149 
00150    if (!(chan = ast_channel_get_by_name(channel))) {
00151       astman_send_error(s, m, "Channel not found");
00152       return 0;
00153    }
00154 
00155    if (ast_strlen_zero(digit)) {
00156       astman_send_error(s, m, "No digit specified");
00157       chan = ast_channel_unref(chan);
00158       return 0;
00159    }
00160 
00161    ast_senddigit(chan, *digit, 0);
00162 
00163    chan = ast_channel_unref(chan);
00164 
00165    astman_send_ack(s, m, "DTMF successfully queued");
00166 
00167    return 0;
00168 }
00169 
00170 static int unload_module(void)
00171 {
00172    int res;
00173 
00174    res = ast_unregister_application(senddtmf_name);
00175    res |= ast_manager_unregister("PlayDTMF");
00176 
00177    return res;
00178 }
00179 
00180 static int load_module(void)
00181 {
00182    int res;
00183 
00184    res = ast_manager_register_xml("PlayDTMF", EVENT_FLAG_CALL, manager_play_dtmf);
00185    res |= ast_register_application_xml(senddtmf_name, senddtmf_exec);
00186 
00187    return res;
00188 }
00189 
00190 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Send DTMF digits Application");

Generated on 27 Jan 2016 for Asterisk - The Open Source Telephony Project by  doxygen 1.6.1