Wed Jan 8 2020 09:49:40

Asterisk developer's documentation


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 ASTERISK_FILE_VERSION(__FILE__, "$Revision: 373945 $")
35 
36 #include "asterisk/pbx.h"
37 #include "asterisk/module.h"
38 #include "asterisk/app.h"
39 #include "asterisk/manager.h"
40 #include "asterisk/channel.h"
41 
42 /*** DOCUMENTATION
43  <application name="SendDTMF" language="en_US">
44  <synopsis>
45  Sends arbitrary DTMF digits
46  </synopsis>
47  <syntax>
48  <parameter name="digits" required="true">
49  <para>List of digits 0-9,*#,a-d,A-D to send also w for a half second pause,
50  and f or F for a flash-hook if the channel supports
51  flash-hook.</para>
52  </parameter>
53  <parameter name="timeout_ms" required="false">
54  <para>Amount of time to wait in ms between tones. (defaults to .25s)</para>
55  </parameter>
56  <parameter name="duration_ms" required="false">
57  <para>Duration of each digit</para>
58  </parameter>
59  <parameter name="channel" required="false">
60  <para>Channel where digits will be played</para>
61  </parameter>
62  </syntax>
63  <description>
64  <para>It will send all digits or terminate if it encounters an error.</para>
65  </description>
66  <see-also>
67  <ref type="application">Read</ref>
68  </see-also>
69  </application>
70  <manager name="PlayDTMF" language="en_US">
71  <synopsis>
72  Play DTMF signal on a specific channel.
73  </synopsis>
74  <syntax>
75  <xi:include xpointer="xpointer(/docs/manager[@name='Login']/syntax/parameter[@name='ActionID'])" />
76  <parameter name="Channel" required="true">
77  <para>Channel name to send digit to.</para>
78  </parameter>
79  <parameter name="Digit" required="true">
80  <para>The DTMF digit to play.</para>
81  </parameter>
82  </syntax>
83  <description>
84  <para>Plays a dtmf digit on the specified channel.</para>
85  </description>
86  </manager>
87  ***/
88 
89 static const char senddtmf_name[] = "SendDTMF";
90 
91 static int senddtmf_exec(struct ast_channel *chan, const char *vdata)
92 {
93  int res;
94  char *data;
95  int dinterval = 0, duration = 0;
96  struct ast_channel *chan_found = NULL;
97  struct ast_channel *chan_dest = chan;
98  struct ast_channel *chan_autoservice = NULL;
100  AST_APP_ARG(digits);
101  AST_APP_ARG(dinterval);
102  AST_APP_ARG(duration);
103  AST_APP_ARG(channel);
104  );
105 
106  if (ast_strlen_zero(vdata)) {
107  ast_log(LOG_WARNING, "SendDTMF requires an argument\n");
108  return 0;
109  }
110 
111  data = ast_strdupa(vdata);
113 
114  if (ast_strlen_zero(args.digits)) {
115  ast_log(LOG_WARNING, "The digits argument is required (0-9,*#,a-d,A-D,wfF)\n");
116  return 0;
117  }
118  if (!ast_strlen_zero(args.dinterval)) {
119  ast_app_parse_timelen(args.dinterval, &dinterval, TIMELEN_MILLISECONDS);
120  }
121  if (!ast_strlen_zero(args.duration)) {
122  ast_app_parse_timelen(args.duration, &duration, TIMELEN_MILLISECONDS);
123  }
124  if (!ast_strlen_zero(args.channel)) {
125  chan_found = ast_channel_get_by_name(args.channel);
126  if (!chan_found) {
127  ast_log(LOG_WARNING, "No such channel: %s\n", args.channel);
128  return 0;
129  }
130  chan_dest = chan_found;
131  if (chan_found != chan) {
132  chan_autoservice = chan;
133  }
134  }
135  res = ast_dtmf_stream(chan_dest, chan_autoservice, args.digits,
136  dinterval <= 0 ? 250 : dinterval, duration);
137  if (chan_found) {
138  ast_channel_unref(chan_found);
139  }
140 
141  return chan_autoservice ? 0 : res;
142 }
143 
144 static int manager_play_dtmf(struct mansession *s, const struct message *m)
145 {
146  const char *channel = astman_get_header(m, "Channel");
147  const char *digit = astman_get_header(m, "Digit");
148  struct ast_channel *chan;
149 
150  if (!(chan = ast_channel_get_by_name(channel))) {
151  astman_send_error(s, m, "Channel not found");
152  return 0;
153  }
154 
155  if (ast_strlen_zero(digit)) {
156  astman_send_error(s, m, "No digit specified");
157  chan = ast_channel_unref(chan);
158  return 0;
159  }
160 
161  ast_senddigit(chan, *digit, 0);
162 
163  chan = ast_channel_unref(chan);
164 
165  astman_send_ack(s, m, "DTMF successfully queued");
166 
167  return 0;
168 }
169 
170 static int unload_module(void)
171 {
172  int res;
173 
174  res = ast_unregister_application(senddtmf_name);
175  res |= ast_manager_unregister("PlayDTMF");
176 
177  return res;
178 }
179 
180 static int load_module(void)
181 {
182  int res;
183 
185  res |= ast_register_application_xml(senddtmf_name, senddtmf_exec);
186 
187  return res;
188 }
189 
190 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Send DTMF digits Application");
Main Channel structure associated with a channel.
Definition: channel.h:742
#define AST_MODULE_INFO_STANDARD(keystr, desc)
Definition: module.h:396
Asterisk main include file. File version handling, generic pbx functions.
#define ast_channel_unref(c)
Decrease channel reference count.
Definition: channel.h:2502
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: app.c:2311
#define LOG_WARNING
Definition: logger.h:144
#define AST_DECLARE_APP_ARGS(name, arglist)
Declare a structure to hold an application&#39;s arguments.
Definition: app.h:572
#define EVENT_FLAG_CALL
Definition: manager.h:72
void astman_send_ack(struct mansession *s, const struct message *m, char *msg)
Send ack in manager transaction.
Definition: manager.c:2135
int ast_senddigit(struct ast_channel *chan, char digit, unsigned int duration)
Send a DTMF digit to a channel.
Definition: channel.c:4774
static int manager_play_dtmf(struct mansession *s, const struct message *m)
Definition: app_senddtmf.c:144
int ast_unregister_application(const char *app)
Unregister an application.
Definition: pbx.c:7705
const char * astman_get_header(const struct message *m, char *var)
Get header from mananger transaction.
Definition: manager.c:1860
static int load_module(void)
Definition: app_senddtmf.c:180
General Asterisk PBX channel definitions.
#define ast_manager_register_xml(a, b, c)
Register a manager callback using XML documentation to describe the manager.
Definition: manager.h:172
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition: strings.h:63
The AMI - Asterisk Manager Interface - is a TCP protocol created to manage Asterisk with third-party ...
#define ast_strdupa(s)
duplicate a string in memory from the stack
Definition: utils.h:663
static int senddtmf_exec(struct ast_channel *chan, const char *vdata)
Definition: app_senddtmf.c:91
static struct @350 args
void ast_log(int level, const char *file, int line, const char *function, const char *fmt,...)
Used for sending a log message This is the standard logger function. Probably the only way you will i...
Definition: logger.c:1207
static int unload_module(void)
Definition: app_senddtmf.c:170
static const char senddtmf_name[]
Definition: app_senddtmf.c:89
Application convenience functions, designed to give consistent look and feel to Asterisk apps...
#define AST_APP_ARG(name)
Define an application argument.
Definition: app.h:555
#define AST_STANDARD_APP_ARGS(args, parse)
Performs the &#39;standard&#39; argument separation process for an application.
Definition: app.h:604
int ast_dtmf_stream(struct ast_channel *chan, struct ast_channel *peer, const char *digits, int between, unsigned int duration)
Send DTMF to a channel.
Definition: app.c:501
#define ASTERISK_GPL_KEY
The text the key() function should return.
Definition: module.h:38
struct ast_channel * ast_channel_get_by_name(const char *name)
Find a channel by name.
Definition: channel.c:1803
void astman_send_error(struct mansession *s, const struct message *m, char *error)
Send error in manager transaction.
Definition: manager.c:2130
Asterisk module definitions.
#define ast_register_application_xml(app, execute)
Register an application using XML documentation.
Definition: module.h:437
int ast_manager_unregister(char *action)
Unregister a registered manager command.
Definition: manager.c:5355
#define ASTERISK_FILE_VERSION(file, version)
Register/unregister a source code file with the core.
Definition: asterisk.h:180