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: 374030 $")
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             W for a one second pause, 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          <parameter name="Duration" required="false">
00083             <para>The duration, in milliseconds, of the digit to be played.</para>
00084          </parameter>
00085       </syntax>
00086       <description>
00087          <para>Plays a dtmf digit on the specified channel.</para>
00088       </description>
00089    </manager>
00090  ***/
00091 
00092 static const char senddtmf_name[] = "SendDTMF";
00093 
00094 static int senddtmf_exec(struct ast_channel *chan, const char *vdata)
00095 {
00096    int res;
00097    char *data;
00098    int dinterval = 0, duration = 0;
00099    struct ast_channel *chan_found = NULL;
00100    struct ast_channel *chan_dest = chan;
00101    struct ast_channel *chan_autoservice = NULL;
00102    AST_DECLARE_APP_ARGS(args,
00103       AST_APP_ARG(digits);
00104       AST_APP_ARG(dinterval);
00105       AST_APP_ARG(duration);
00106       AST_APP_ARG(channel);
00107    );
00108 
00109    if (ast_strlen_zero(vdata)) {
00110       ast_log(LOG_WARNING, "SendDTMF requires an argument\n");
00111       return 0;
00112    }
00113 
00114    data = ast_strdupa(vdata);
00115    AST_STANDARD_APP_ARGS(args, data);
00116 
00117    if (ast_strlen_zero(args.digits)) {
00118       ast_log(LOG_WARNING, "The digits argument is required (0-9,*#,a-d,A-D,wfF)\n");
00119       return 0;
00120    }
00121    if (!ast_strlen_zero(args.dinterval)) {
00122       ast_app_parse_timelen(args.dinterval, &dinterval, TIMELEN_MILLISECONDS);
00123    }
00124    if (!ast_strlen_zero(args.duration)) {
00125       ast_app_parse_timelen(args.duration, &duration, TIMELEN_MILLISECONDS);
00126    }
00127    if (!ast_strlen_zero(args.channel)) {
00128       chan_found = ast_channel_get_by_name(args.channel);
00129       if (!chan_found) {
00130          ast_log(LOG_WARNING, "No such channel: %s\n", args.channel);
00131          return 0;
00132       }
00133       chan_dest = chan_found;
00134       if (chan_found != chan) {
00135          chan_autoservice = chan;
00136       }
00137    }
00138    res = ast_dtmf_stream(chan_dest, chan_autoservice, args.digits,
00139       dinterval <= 0 ? 250 : dinterval, duration);
00140    if (chan_found) {
00141       ast_channel_unref(chan_found);
00142    }
00143 
00144    return chan_autoservice ? 0 : res;
00145 }
00146 
00147 static int manager_play_dtmf(struct mansession *s, const struct message *m)
00148 {
00149    const char *channel = astman_get_header(m, "Channel");
00150    const char *digit = astman_get_header(m, "Digit");
00151    const char *duration = astman_get_header(m, "Duration");
00152    struct ast_channel *chan;
00153    unsigned int duration_ms = 0;
00154 
00155    if (!(chan = ast_channel_get_by_name(channel))) {
00156       astman_send_error(s, m, "Channel not found");
00157       return 0;
00158    }
00159 
00160    if (ast_strlen_zero(digit)) {
00161       astman_send_error(s, m, "No digit specified");
00162       chan = ast_channel_unref(chan);
00163       return 0;
00164    }
00165    
00166    if (!ast_strlen_zero(duration) && (sscanf(duration, "%30u", &duration_ms) != 1)) {
00167       astman_send_error(s, m, "Could not convert Duration parameter");
00168       chan = ast_channel_unref(chan);
00169       return 0;
00170    }
00171 
00172    ast_senddigit(chan, *digit, duration_ms);
00173 
00174    chan = ast_channel_unref(chan);
00175 
00176    astman_send_ack(s, m, "DTMF successfully queued");
00177 
00178    return 0;
00179 }
00180 
00181 static int unload_module(void)
00182 {
00183    int res;
00184 
00185    res = ast_unregister_application(senddtmf_name);
00186    res |= ast_manager_unregister("PlayDTMF");
00187 
00188    return res;
00189 }
00190 
00191 static int load_module(void)
00192 {
00193    int res;
00194 
00195    res = ast_manager_register_xml("PlayDTMF", EVENT_FLAG_CALL, manager_play_dtmf);
00196    res |= ast_register_application_xml(senddtmf_name, senddtmf_exec);
00197 
00198    return res;
00199 }
00200 
00201 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Send DTMF digits Application");

Generated on Thu Apr 16 06:27:12 2015 for Asterisk - The Open Source Telephony Project by  doxygen 1.5.6