Asterisk - The Open Source Telephony Project GIT-master-754dea3
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Macros Modules Pages
app_senddtmf.c
Go to the documentation of this file.
1/*
2 * Asterisk -- An open source telephony toolkit.
3 *
4 * Copyright (C) 1999 - 2005, Digium, Inc.
5 *
6 * Mark Spencer <markster@digium.com>
7 *
8 * See http://www.asterisk.org for more information about
9 * the Asterisk project. Please do not directly contact
10 * any of the maintainers of this project for assistance;
11 * the project provides a web site, mailing lists and IRC
12 * channels for your use.
13 *
14 * This program is free software, distributed under the terms of
15 * the GNU General Public License Version 2. See the LICENSE file
16 * at the top of the source tree.
17 */
18
19/*! \file
20 *
21 * \brief App to send DTMF digits
22 *
23 * \author Mark Spencer <markster@digium.com>
24 *
25 * \ingroup applications
26 */
27
28/*** MODULEINFO
29 <support_level>core</support_level>
30 ***/
31
32#include "asterisk.h"
33
34#include "asterisk/pbx.h"
35#include "asterisk/module.h"
36#include "asterisk/app.h"
37#include "asterisk/manager.h"
38#include "asterisk/channel.h"
39
40/*** DOCUMENTATION
41 <application name="SendDTMF" language="en_US">
42 <since>
43 <version>0.3.0</version>
44 </since>
45 <synopsis>
46 Sends arbitrary DTMF digits
47 </synopsis>
48 <syntax>
49 <parameter name="digits" required="true">
50 <para>List of digits 0-9,*#,a-d,A-D to send also w for a half second pause,
51 W for a one second pause, and f or F for a flash-hook if the channel supports
52 flash-hook.</para>
53 </parameter>
54 <parameter name="timeout_ms" required="false">
55 <para>Amount of time to wait in ms between tones. (defaults to .25s)</para>
56 </parameter>
57 <parameter name="duration_ms" required="false">
58 <para>Duration of each digit</para>
59 </parameter>
60 <parameter name="channel" required="false">
61 <para>Channel where digits will be played</para>
62 </parameter>
63 <parameter name="options">
64 <optionlist>
65 <option name="a">
66 <para>Answer the channel specified by the <literal>channel</literal>
67 parameter if it is not already up. If no <literal>channel</literal>
68 parameter is provided, the current channel will be answered.</para>
69 </option>
70 </optionlist>
71 </parameter>
72 </syntax>
73 <description>
74 <para>It will send all digits or terminate if it encounters an error.</para>
75 </description>
76 <see-also>
77 <ref type="application">Read</ref>
78 </see-also>
79 </application>
80 <manager name="PlayDTMF" language="en_US">
81 <since>
82 <version>1.4.0</version>
83 </since>
84 <synopsis>
85 Play DTMF signal on a specific channel.
86 </synopsis>
87 <syntax>
88 <xi:include xpointer="xpointer(/docs/manager[@name='Login']/syntax/parameter[@name='ActionID'])" />
89 <parameter name="Channel" required="true">
90 <para>Channel name to send digit to.</para>
91 </parameter>
92 <parameter name="Digit" required="true">
93 <para>The DTMF digit to play.</para>
94 </parameter>
95 <parameter name="Duration" required="false">
96 <para>The duration, in milliseconds, of the digit to be played.</para>
97 </parameter>
98 <parameter name="Receive" required="false">
99 <para>Emulate receiving DTMF on this channel instead of sending it out.</para>
100 </parameter>
101 </syntax>
102 <description>
103 <para>Plays a dtmf digit on the specified channel.</para>
104 </description>
105 </manager>
106 <manager name="SendFlash" language="en_US">
107 <since>
108 <version>20.3.0</version>
109 <version>18.18.0</version>
110 </since>
111 <synopsis>
112 Send a hook flash on a specific channel.
113 </synopsis>
114 <syntax>
115 <xi:include xpointer="xpointer(/docs/manager[@name='Login']/syntax/parameter[@name='ActionID'])" />
116 <parameter name="Channel" required="true">
117 <para>Channel name to send hook flash to.</para>
118 </parameter>
119 <parameter name="Receive" required="false">
120 <para>Emulate receiving a hook flash on this channel instead of sending it out.</para>
121 </parameter>
122 </syntax>
123 <description>
124 <para>Sends a hook flash on the specified channel.</para>
125 </description>
126 </manager>
127 ***/
128
130 OPT_ANSWER = (1 << 0),
131};
132
135});
136
137enum {
138 /* note: this entry _MUST_ be the last one in the enum */
140};
141
142static const char senddtmf_name[] = "SendDTMF";
143
144static int senddtmf_exec(struct ast_channel *chan, const char *vdata)
145{
146 int res;
147 char *data;
148 int dinterval = 0, duration = 0;
149 struct ast_channel *chan_found = NULL;
150 struct ast_channel *chan_dest = chan;
151 struct ast_channel *chan_autoservice = NULL;
152 char *opt_args[OPT_ARG_ARRAY_SIZE];
153 struct ast_flags flags = {0};
155 AST_APP_ARG(digits);
156 AST_APP_ARG(dinterval);
157 AST_APP_ARG(duration);
158 AST_APP_ARG(channel);
160 );
161
162 if (ast_strlen_zero(vdata)) {
163 ast_log(LOG_WARNING, "SendDTMF requires an argument\n");
164 return 0;
165 }
166
167 data = ast_strdupa(vdata);
169
170 if (ast_strlen_zero(args.digits)) {
171 ast_log(LOG_WARNING, "The digits argument is required (0-9,*#,a-d,A-D,wfF)\n");
172 return 0;
173 }
174 if (!ast_strlen_zero(args.dinterval)) {
175 ast_app_parse_timelen(args.dinterval, &dinterval, TIMELEN_MILLISECONDS);
176 }
177 if (!ast_strlen_zero(args.duration)) {
178 ast_app_parse_timelen(args.duration, &duration, TIMELEN_MILLISECONDS);
179 }
180 if (!ast_strlen_zero(args.channel)) {
181 chan_found = ast_channel_get_by_name(args.channel);
182 if (!chan_found) {
183 ast_log(LOG_WARNING, "No such channel: %s\n", args.channel);
184 return 0;
185 }
186 chan_dest = chan_found;
187 if (chan_found != chan) {
188 chan_autoservice = chan;
189 }
190 }
191 if (!ast_strlen_zero(args.options)) {
193 }
195 ast_auto_answer(chan_dest);
196 }
197 res = ast_dtmf_stream(chan_dest, chan_autoservice, args.digits,
198 dinterval <= 0 ? 250 : dinterval, duration);
199 if (chan_found) {
200 ast_channel_unref(chan_found);
201 }
202
203 return chan_autoservice ? 0 : res;
204}
205
206static int manager_play_dtmf(struct mansession *s, const struct message *m)
207{
208 const char *channel = astman_get_header(m, "Channel");
209 const char *digit = astman_get_header(m, "Digit");
210 const char *duration = astman_get_header(m, "Duration");
211 const char *receive_s = astman_get_header(m, "Receive");
212 struct ast_channel *chan;
213 unsigned int duration_ms = 0;
214
215 if (!(chan = ast_channel_get_by_name(channel))) {
216 astman_send_error(s, m, "Channel not found");
217 return 0;
218 }
219
220 if (ast_strlen_zero(digit)) {
221 astman_send_error(s, m, "No digit specified");
222 chan = ast_channel_unref(chan);
223 return 0;
224 }
225
226 if (!ast_strlen_zero(duration) && (sscanf(duration, "%30u", &duration_ms) != 1)) {
227 astman_send_error(s, m, "Could not convert Duration parameter");
228 chan = ast_channel_unref(chan);
229 return 0;
230 }
231
232 if (ast_true(receive_s)) {
233 struct ast_frame f = { AST_FRAME_DTMF, };
234 f.len = duration_ms;
236 ast_queue_frame(chan, &f);
237 } else {
238 ast_senddigit_external(chan, *digit, duration_ms);
239 }
240
241 chan = ast_channel_unref(chan);
242
243 astman_send_ack(s, m, "DTMF successfully queued");
244
245 return 0;
246}
247
248static int manager_send_flash(struct mansession *s, const struct message *m)
249{
250 const char *channel = astman_get_header(m, "Channel");
251 const char *receive_s = astman_get_header(m, "Receive");
252 struct ast_channel *chan;
253
254 if (!(chan = ast_channel_get_by_name(channel))) {
255 astman_send_error(s, m, "Channel not found");
256 return 0;
257 }
258
259 if (ast_true(receive_s)) {
260 struct ast_frame f = { AST_FRAME_CONTROL, };
262 ast_queue_frame(chan, &f);
263 } else {
264 struct ast_frame f = { AST_FRAME_CONTROL, };
266 ast_channel_lock(chan);
267 ast_write(chan, &f);
268 ast_channel_unlock(chan);
269 }
270
271 chan = ast_channel_unref(chan);
272 astman_send_ack(s, m, "Flash successfully queued");
273 return 0;
274}
275
276static int unload_module(void)
277{
278 int res;
279
281 res |= ast_manager_unregister("PlayDTMF");
282 res |= ast_manager_unregister("SendFlash");
283
284 return res;
285}
286
287static int load_module(void)
288{
289 int res;
290
294
295 return res;
296}
297
298AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Send DTMF digits Application");
char digit
read_option_flags
Definition: app_mf.c:188
static int manager_send_flash(struct mansession *s, const struct message *m)
Definition: app_senddtmf.c:248
static const struct ast_app_option senddtmf_app_options[128]
Definition: app_senddtmf.c:135
static const char senddtmf_name[]
Definition: app_senddtmf.c:142
static int manager_play_dtmf(struct mansession *s, const struct message *m)
Definition: app_senddtmf.c:206
static int senddtmf_exec(struct ast_channel *chan, const char *vdata)
Definition: app_senddtmf.c:144
static int load_module(void)
Definition: app_senddtmf.c:287
static int unload_module(void)
Definition: app_senddtmf.c:276
@ OPT_ANSWER
Definition: app_senddtmf.c:130
@ OPT_ARG_ARRAY_SIZE
Definition: app_senddtmf.c:139
Asterisk main include file. File version handling, generic pbx functions.
#define ast_strdupa(s)
duplicate a string in memory from the stack
Definition: astmm.h:298
#define ast_log
Definition: astobj2.c:42
General Asterisk PBX channel definitions.
int ast_auto_answer(struct ast_channel *chan)
Answer a channel, if it's not already answered.
Definition: channel.c:2840
#define ast_channel_lock(chan)
Definition: channel.h:2970
int ast_queue_frame(struct ast_channel *chan, struct ast_frame *f)
Queue one or more frames to a channel's frame queue.
Definition: channel.c:1158
int ast_write(struct ast_channel *chan, struct ast_frame *frame)
Write a frame to a channel This function writes the given frame to the indicated channel.
Definition: channel.c:5161
int ast_senddigit_external(struct ast_channel *chan, char digit, unsigned int duration)
Send a DTMF digit to a channel from an external thread.
Definition: channel.c:5004
#define ast_channel_unref(c)
Decrease channel reference count.
Definition: channel.h:3006
struct ast_channel * ast_channel_get_by_name(const char *name)
Find a channel by name.
Definition: channel.c:1481
#define ast_channel_unlock(chan)
Definition: channel.h:2971
void astman_send_error(struct mansession *s, const struct message *m, char *error)
Send error in manager transaction.
Definition: manager.c:1986
void astman_send_ack(struct mansession *s, const struct message *m, char *msg)
Send ack in manager transaction.
Definition: manager.c:2018
const char * astman_get_header(const struct message *m, char *var)
Get header from manager transaction.
Definition: manager.c:1647
int ast_manager_unregister(const char *action)
Unregister a registered manager command.
Definition: manager.c:7697
Application convenience functions, designed to give consistent look and feel to Asterisk apps.
#define AST_APP_ARG(name)
Define an application argument.
int ast_app_parse_timelen(const char *timestr, int *result, enum ast_timelen defunit)
Common routine to parse time lengths, with optional time unit specifier.
Definition: main/app.c:3273
#define AST_APP_OPTIONS(holder, options...)
Declares an array of options for an application.
#define AST_DECLARE_APP_ARGS(name, arglist)
Declare a structure to hold an application's arguments.
#define AST_STANDARD_APP_ARGS(args, parse)
Performs the 'standard' argument separation process for an application.
@ TIMELEN_MILLISECONDS
#define AST_APP_OPTION(option, flagno)
Declares an application option that does not accept an argument.
int ast_dtmf_stream(struct ast_channel *chan, struct ast_channel *peer, const char *digits, int between, unsigned int duration)
Send a string of DTMF digits to a channel.
Definition: main/app.c:1127
int ast_app_parse_options(const struct ast_app_option *options, struct ast_flags *flags, char **args, char *optstr)
Parses a string containing application options and sets flags/arguments.
Definition: main/app.c:3066
#define AST_FRAME_DTMF
@ AST_FRAME_CONTROL
@ AST_CONTROL_FLASH
#define LOG_WARNING
The AMI - Asterisk Manager Interface - is a TCP protocol created to manage Asterisk with third-party ...
#define ast_manager_register_xml(action, authority, func)
Register a manager callback using XML documentation to describe the manager.
Definition: manager.h:192
#define EVENT_FLAG_CALL
Definition: manager.h:76
Asterisk module definitions.
#define AST_MODULE_INFO_STANDARD(keystr, desc)
Definition: module.h:581
#define ASTERISK_GPL_KEY
The text the key() function should return.
Definition: module.h:46
int ast_unregister_application(const char *app)
Unregister an application.
Definition: pbx_app.c:392
#define ast_register_application_xml(app, execute)
Register an application using XML documentation.
Definition: module.h:640
Core PBX routines and definitions.
#define NULL
Definition: resample.c:96
int attribute_pure ast_true(const char *val)
Make sure something is true. Determine if a string containing a boolean value is "true"....
Definition: utils.c:2199
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition: strings.h:65
Main Channel structure associated with a channel.
Structure used to handle boolean flags.
Definition: utils.h:199
unsigned int flags
Definition: utils.h:200
Data structure associated with a single frame of data.
struct ast_frame_subclass subclass
In case you didn't read that giant block of text above the mansession_session struct,...
Definition: manager.c:327
const char * args
static struct test_options options
#define ast_test_flag(p, flag)
Definition: utils.h:63