Thu Apr 28 2011 17:15:15

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 #include "asterisk.h"
00029 
00030 ASTERISK_FILE_VERSION(__FILE__, "$Revision: 184082 $")
00031 
00032 #include "asterisk/pbx.h"
00033 #include "asterisk/module.h"
00034 #include "asterisk/app.h"
00035 #include "asterisk/manager.h"
00036 #include "asterisk/channel.h"
00037 
00038 /*** DOCUMENTATION
00039    <application name="SendDTMF" language="en_US">
00040       <synopsis>
00041          Sends arbitrary DTMF digits
00042       </synopsis>
00043       <syntax>
00044          <parameter name="digits" required="true">
00045             <para>List of digits 0-9,*#,abcd</para>
00046          </parameter>
00047          <parameter name="timeout_ms" required="false">
00048             <para>Amount of time to wait in ms between tones. (defaults to .25s)</para>
00049          </parameter>
00050          <parameter name="duration_ms" required="false">
00051             <para>Duration of each digit</para>
00052          </parameter>
00053       </syntax>
00054       <description>
00055          <para>DTMF digits sent to a channel with half second pause</para>
00056          <para>It will pass all digits or terminate if it encounters an error.</para>
00057       </description>
00058       <see-also>
00059          <ref type="application">Read</ref>
00060       </see-also>
00061    </application>
00062  ***/
00063 static char *app = "SendDTMF";
00064 
00065 static int senddtmf_exec(struct ast_channel *chan, void *vdata)
00066 {
00067    int res = 0;
00068    char *data;
00069    int timeout = 0, duration = 0;
00070    AST_DECLARE_APP_ARGS(args,
00071       AST_APP_ARG(digits);
00072       AST_APP_ARG(timeout);
00073       AST_APP_ARG(duration);
00074    );
00075 
00076    if (ast_strlen_zero(vdata)) {
00077       ast_log(LOG_WARNING, "SendDTMF requires an argument (digits or *#aAbBcCdD)\n");
00078       return 0;
00079    }
00080 
00081    data = ast_strdupa(vdata);
00082    AST_STANDARD_APP_ARGS(args, data);
00083 
00084    if (!ast_strlen_zero(args.timeout))
00085       timeout = atoi(args.timeout);
00086    if (!ast_strlen_zero(args.duration))
00087       duration = atoi(args.duration);
00088    res = ast_dtmf_stream(chan, NULL, args.digits, timeout <= 0 ? 250 : timeout, duration);
00089 
00090    return res;
00091 }
00092 
00093 static char mandescr_playdtmf[] =
00094 "Description: Plays a dtmf digit on the specified channel.\n"
00095 "Variables: (all are required)\n"
00096 "  Channel: Channel name to send digit to\n"
00097 "  Digit: The dtmf digit to play\n";
00098 
00099 static int manager_play_dtmf(struct mansession *s, const struct message *m)
00100 {
00101    const char *channel = astman_get_header(m, "Channel");
00102    const char *digit = astman_get_header(m, "Digit");
00103    struct ast_channel *chan = ast_get_channel_by_name_locked(channel);
00104    
00105    if (!chan) {
00106       astman_send_error(s, m, "Channel not specified");
00107       return 0;
00108    }
00109    if (ast_strlen_zero(digit)) {
00110       astman_send_error(s, m, "No digit specified");
00111       ast_channel_unlock(chan);
00112       return 0;
00113    }
00114 
00115    ast_senddigit(chan, *digit, 0);
00116 
00117    ast_channel_unlock(chan);
00118    astman_send_ack(s, m, "DTMF successfully queued");
00119    
00120    return 0;
00121 }
00122 
00123 static int unload_module(void)
00124 {
00125    int res;
00126 
00127    res = ast_unregister_application(app);
00128    res |= ast_manager_unregister("PlayDTMF");
00129 
00130    return res; 
00131 }
00132 
00133 static int load_module(void)
00134 {
00135    int res;
00136 
00137    res = ast_manager_register2( "PlayDTMF", EVENT_FLAG_CALL, manager_play_dtmf, "Play DTMF signal on a specific channel.", mandescr_playdtmf );
00138    res |= ast_register_application_xml(app, senddtmf_exec);
00139 
00140    return res;
00141 }
00142 
00143 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Send DTMF digits Application");