2002-10-14 05:30:28 +00:00
|
|
|
/*
|
2005-09-14 20:46:50 +00:00
|
|
|
* Asterisk -- An open source telephony toolkit.
|
2002-10-14 05:30:28 +00:00
|
|
|
*
|
2005-09-14 20:46:50 +00:00
|
|
|
* Copyright (C) 1999 - 2005, Digium, Inc.
|
|
|
|
|
*
|
|
|
|
|
* Mark Spencer <markster@digium.com>
|
2002-10-14 05:30:28 +00:00
|
|
|
*
|
2005-09-14 20:46:50 +00:00
|
|
|
* See http://www.asterisk.org for more information about
|
|
|
|
|
* the Asterisk project. Please do not directly contact
|
|
|
|
|
* any of the maintainers of this project for assistance;
|
|
|
|
|
* the project provides a web site, mailing lists and IRC
|
|
|
|
|
* channels for your use.
|
2002-10-14 05:30:28 +00:00
|
|
|
*
|
|
|
|
|
* This program is free software, distributed under the terms of
|
2005-09-14 20:46:50 +00:00
|
|
|
* the GNU General Public License Version 2. See the LICENSE file
|
|
|
|
|
* at the top of the source tree.
|
|
|
|
|
*/
|
|
|
|
|
|
2005-10-24 20:12:06 +00:00
|
|
|
/*! \file
|
2005-09-14 20:46:50 +00:00
|
|
|
*
|
2005-10-24 20:12:06 +00:00
|
|
|
* \brief App to send DTMF digits
|
2005-12-30 21:18:06 +00:00
|
|
|
*
|
|
|
|
|
* \author Mark Spencer <markster@digium.com>
|
2012-09-27 22:25:34 +00:00
|
|
|
*
|
2005-11-06 15:09:47 +00:00
|
|
|
* \ingroup applications
|
2002-10-14 05:30:28 +00:00
|
|
|
*/
|
2011-07-14 20:28:54 +00:00
|
|
|
|
|
|
|
|
/*** MODULEINFO
|
|
|
|
|
<support_level>core</support_level>
|
|
|
|
|
***/
|
2012-09-27 22:25:34 +00:00
|
|
|
|
2005-06-06 22:39:32 +00:00
|
|
|
#include "asterisk.h"
|
|
|
|
|
|
2005-04-21 06:02:45 +00:00
|
|
|
#include "asterisk/pbx.h"
|
|
|
|
|
#include "asterisk/module.h"
|
|
|
|
|
#include "asterisk/app.h"
|
2006-05-04 21:33:45 +00:00
|
|
|
#include "asterisk/manager.h"
|
2007-11-22 03:50:04 +00:00
|
|
|
#include "asterisk/channel.h"
|
2002-10-14 05:30:28 +00:00
|
|
|
|
2008-11-01 21:10:07 +00:00
|
|
|
/*** DOCUMENTATION
|
|
|
|
|
<application name="SendDTMF" language="en_US">
|
|
|
|
|
<synopsis>
|
|
|
|
|
Sends arbitrary DTMF digits
|
|
|
|
|
</synopsis>
|
|
|
|
|
<syntax>
|
|
|
|
|
<parameter name="digits" required="true">
|
2012-09-27 22:25:34 +00:00
|
|
|
<para>List of digits 0-9,*#,a-d,A-D to send also w for a half second pause,
|
2012-09-28 18:27:02 +00:00
|
|
|
W for a one second pause, and f or F for a flash-hook if the channel supports
|
2012-09-27 22:25:34 +00:00
|
|
|
flash-hook.</para>
|
2008-11-01 21:10:07 +00:00
|
|
|
</parameter>
|
|
|
|
|
<parameter name="timeout_ms" required="false">
|
|
|
|
|
<para>Amount of time to wait in ms between tones. (defaults to .25s)</para>
|
|
|
|
|
</parameter>
|
|
|
|
|
<parameter name="duration_ms" required="false">
|
|
|
|
|
<para>Duration of each digit</para>
|
|
|
|
|
</parameter>
|
2012-09-27 22:25:34 +00:00
|
|
|
<parameter name="channel" required="false">
|
|
|
|
|
<para>Channel where digits will be played</para>
|
|
|
|
|
</parameter>
|
2008-11-01 21:10:07 +00:00
|
|
|
</syntax>
|
|
|
|
|
<description>
|
2012-09-27 22:25:34 +00:00
|
|
|
<para>It will send all digits or terminate if it encounters an error.</para>
|
2008-11-01 21:10:07 +00:00
|
|
|
</description>
|
2008-11-05 12:13:57 +00:00
|
|
|
<see-also>
|
|
|
|
|
<ref type="application">Read</ref>
|
|
|
|
|
</see-also>
|
2008-11-01 21:10:07 +00:00
|
|
|
</application>
|
2009-05-22 17:52:35 +00:00
|
|
|
<manager name="PlayDTMF" language="en_US">
|
|
|
|
|
<synopsis>
|
|
|
|
|
Play DTMF signal on a specific channel.
|
|
|
|
|
</synopsis>
|
|
|
|
|
<syntax>
|
|
|
|
|
<xi:include xpointer="xpointer(/docs/manager[@name='Login']/syntax/parameter[@name='ActionID'])" />
|
|
|
|
|
<parameter name="Channel" required="true">
|
|
|
|
|
<para>Channel name to send digit to.</para>
|
|
|
|
|
</parameter>
|
|
|
|
|
<parameter name="Digit" required="true">
|
|
|
|
|
<para>The DTMF digit to play.</para>
|
|
|
|
|
</parameter>
|
2012-09-28 03:06:53 +00:00
|
|
|
<parameter name="Duration" required="false">
|
|
|
|
|
<para>The duration, in milliseconds, of the digit to be played.</para>
|
|
|
|
|
</parameter>
|
2009-05-22 17:52:35 +00:00
|
|
|
</syntax>
|
|
|
|
|
<description>
|
|
|
|
|
<para>Plays a dtmf digit on the specified channel.</para>
|
|
|
|
|
</description>
|
|
|
|
|
</manager>
|
2008-11-01 21:10:07 +00:00
|
|
|
***/
|
2012-09-27 22:25:34 +00:00
|
|
|
|
|
|
|
|
static const char senddtmf_name[] = "SendDTMF";
|
2002-10-14 05:30:28 +00:00
|
|
|
|
2009-05-21 21:13:09 +00:00
|
|
|
static int senddtmf_exec(struct ast_channel *chan, const char *vdata)
|
2002-10-14 05:30:28 +00:00
|
|
|
{
|
2012-09-27 22:25:34 +00:00
|
|
|
int res;
|
2007-07-31 01:10:47 +00:00
|
|
|
char *data;
|
2010-01-26 20:49:57 +00:00
|
|
|
int dinterval = 0, duration = 0;
|
2012-09-27 22:25:34 +00:00
|
|
|
struct ast_channel *chan_found = NULL;
|
|
|
|
|
struct ast_channel *chan_dest = chan;
|
|
|
|
|
struct ast_channel *chan_autoservice = NULL;
|
2007-07-31 01:10:47 +00:00
|
|
|
AST_DECLARE_APP_ARGS(args,
|
|
|
|
|
AST_APP_ARG(digits);
|
2010-01-26 20:49:57 +00:00
|
|
|
AST_APP_ARG(dinterval);
|
2007-08-06 21:52:30 +00:00
|
|
|
AST_APP_ARG(duration);
|
2010-05-24 22:16:29 +00:00
|
|
|
AST_APP_ARG(channel);
|
2007-07-31 01:10:47 +00:00
|
|
|
);
|
2004-05-07 20:39:14 +00:00
|
|
|
|
2007-07-31 14:54:46 +00:00
|
|
|
if (ast_strlen_zero(vdata)) {
|
2012-09-27 22:25:34 +00:00
|
|
|
ast_log(LOG_WARNING, "SendDTMF requires an argument\n");
|
2005-10-19 18:19:02 +00:00
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2007-07-31 01:10:47 +00:00
|
|
|
data = ast_strdupa(vdata);
|
|
|
|
|
AST_STANDARD_APP_ARGS(args, data);
|
2005-10-19 18:19:02 +00:00
|
|
|
|
2012-09-27 22:25:34 +00:00
|
|
|
if (ast_strlen_zero(args.digits)) {
|
|
|
|
|
ast_log(LOG_WARNING, "The digits argument is required (0-9,*#,a-d,A-D,wfF)\n");
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
2010-01-26 20:49:57 +00:00
|
|
|
if (!ast_strlen_zero(args.dinterval)) {
|
|
|
|
|
ast_app_parse_timelen(args.dinterval, &dinterval, TIMELEN_MILLISECONDS);
|
|
|
|
|
}
|
|
|
|
|
if (!ast_strlen_zero(args.duration)) {
|
|
|
|
|
ast_app_parse_timelen(args.duration, &duration, TIMELEN_MILLISECONDS);
|
|
|
|
|
}
|
2010-05-24 22:16:29 +00:00
|
|
|
if (!ast_strlen_zero(args.channel)) {
|
2012-09-27 22:25:34 +00:00
|
|
|
chan_found = ast_channel_get_by_name(args.channel);
|
|
|
|
|
if (!chan_found) {
|
|
|
|
|
ast_log(LOG_WARNING, "No such channel: %s\n", args.channel);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
chan_dest = chan_found;
|
|
|
|
|
if (chan_found != chan) {
|
|
|
|
|
chan_autoservice = chan;
|
|
|
|
|
}
|
2010-05-24 22:16:29 +00:00
|
|
|
}
|
2012-09-27 22:25:34 +00:00
|
|
|
res = ast_dtmf_stream(chan_dest, chan_autoservice, args.digits,
|
|
|
|
|
dinterval <= 0 ? 250 : dinterval, duration);
|
|
|
|
|
if (chan_found) {
|
|
|
|
|
ast_channel_unref(chan_found);
|
2010-05-24 22:16:29 +00:00
|
|
|
}
|
2005-10-19 18:19:02 +00:00
|
|
|
|
2012-09-27 22:25:34 +00:00
|
|
|
return chan_autoservice ? 0 : res;
|
2002-10-14 05:30:28 +00:00
|
|
|
}
|
|
|
|
|
|
2007-01-05 22:43:18 +00:00
|
|
|
static int manager_play_dtmf(struct mansession *s, const struct message *m)
|
2006-05-04 21:33:45 +00:00
|
|
|
{
|
2007-01-05 22:43:18 +00:00
|
|
|
const char *channel = astman_get_header(m, "Channel");
|
|
|
|
|
const char *digit = astman_get_header(m, "Digit");
|
2012-09-28 03:06:53 +00:00
|
|
|
const char *duration = astman_get_header(m, "Duration");
|
2009-04-24 14:04:26 +00:00
|
|
|
struct ast_channel *chan;
|
2012-09-28 03:06:53 +00:00
|
|
|
unsigned int duration_ms = 0;
|
2009-04-24 14:04:26 +00:00
|
|
|
|
|
|
|
|
if (!(chan = ast_channel_get_by_name(channel))) {
|
|
|
|
|
astman_send_error(s, m, "Channel not found");
|
2006-05-04 21:33:45 +00:00
|
|
|
return 0;
|
|
|
|
|
}
|
2009-04-24 14:04:26 +00:00
|
|
|
|
2009-03-24 22:40:39 +00:00
|
|
|
if (ast_strlen_zero(digit)) {
|
2006-05-04 21:33:45 +00:00
|
|
|
astman_send_error(s, m, "No digit specified");
|
2009-04-24 14:04:26 +00:00
|
|
|
chan = ast_channel_unref(chan);
|
2006-05-04 21:33:45 +00:00
|
|
|
return 0;
|
|
|
|
|
}
|
2017-12-22 09:23:22 -05:00
|
|
|
|
2012-09-28 03:06:53 +00:00
|
|
|
if (!ast_strlen_zero(duration) && (sscanf(duration, "%30u", &duration_ms) != 1)) {
|
|
|
|
|
astman_send_error(s, m, "Could not convert Duration parameter");
|
|
|
|
|
chan = ast_channel_unref(chan);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
2006-05-05 00:43:28 +00:00
|
|
|
|
2012-09-28 03:06:53 +00:00
|
|
|
ast_senddigit(chan, *digit, duration_ms);
|
2006-05-05 00:43:28 +00:00
|
|
|
|
2009-04-24 14:04:26 +00:00
|
|
|
chan = ast_channel_unref(chan);
|
|
|
|
|
|
2006-05-04 21:33:45 +00:00
|
|
|
astman_send_ack(s, m, "DTMF successfully queued");
|
2009-04-24 14:04:26 +00:00
|
|
|
|
2006-05-04 21:33:45 +00:00
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2006-08-21 02:11:39 +00:00
|
|
|
static int unload_module(void)
|
2002-10-14 05:30:28 +00:00
|
|
|
{
|
2005-10-18 22:52:21 +00:00
|
|
|
int res;
|
|
|
|
|
|
2012-09-27 22:25:34 +00:00
|
|
|
res = ast_unregister_application(senddtmf_name);
|
2006-05-04 21:33:45 +00:00
|
|
|
res |= ast_manager_unregister("PlayDTMF");
|
2005-10-18 22:52:21 +00:00
|
|
|
|
2012-09-27 22:25:34 +00:00
|
|
|
return res;
|
2002-10-14 05:30:28 +00:00
|
|
|
}
|
|
|
|
|
|
2006-08-21 02:11:39 +00:00
|
|
|
static int load_module(void)
|
2002-10-14 05:30:28 +00:00
|
|
|
{
|
2006-05-05 00:43:28 +00:00
|
|
|
int res;
|
|
|
|
|
|
2009-05-22 17:52:35 +00:00
|
|
|
res = ast_manager_register_xml("PlayDTMF", EVENT_FLAG_CALL, manager_play_dtmf);
|
2012-09-27 22:25:34 +00:00
|
|
|
res |= ast_register_application_xml(senddtmf_name, senddtmf_exec);
|
2006-05-05 00:43:28 +00:00
|
|
|
|
|
|
|
|
return res;
|
2002-10-14 05:30:28 +00:00
|
|
|
}
|
|
|
|
|
|
2006-08-21 02:11:39 +00:00
|
|
|
AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Send DTMF digits Application");
|