Asterisk - The Open Source Telephony Project GIT-master-f36a736
Enumerations | Functions | Variables
app_senddtmf.c File Reference

App to send DTMF digits. More...

#include "asterisk.h"
#include "asterisk/pbx.h"
#include "asterisk/module.h"
#include "asterisk/app.h"
#include "asterisk/manager.h"
#include "asterisk/channel.h"
Include dependency graph for app_senddtmf.c:

Go to the source code of this file.

Enumerations

enum  { OPT_ARG_ARRAY_SIZE }
 
enum  read_option_flags {
  OPT_DELAY = (1 << 0) , OPT_MUTE = (1 << 1) , OPT_QUELCH = (1 << 2) , OPT_RELAXED = (1 << 3) ,
  OPT_LAX_KP = (1 << 4) , OPT_PROCESS = (1 << 5) , OPT_NO_KP = (1 << 6) , OPT_NO_ST = (1 << 7) ,
  OPT_KP_OVERRIDE = (1 << 8) , OPT_MAXDIGITS = (1 << 9) , OPT_SKIP = (1 << 0) , OPT_INDICATION = (1 << 1) ,
  OPT_NOANSWER = (1 << 2) , OPT_TERMINATOR = (1 << 3) , OPT_KEEP_TERMINATOR = (1 << 4) , OPT_ANSWER = (1 << 0) ,
  OPT_DELAY = (1 << 0) , OPT_MUTE = (1 << 1) , OPT_QUELCH = (1 << 2) , OPT_RELAXED = (1 << 3) ,
  OPT_EXTRAPULSES = (1 << 4)
}
 

Functions

static void __reg_module (void)
 
static void __unreg_module (void)
 
struct ast_moduleAST_MODULE_SELF_SYM (void)
 
static int load_module (void)
 
static int manager_play_dtmf (struct mansession *s, const struct message *m)
 
static int manager_send_flash (struct mansession *s, const struct message *m)
 
static int senddtmf_exec (struct ast_channel *chan, const char *vdata)
 
static int unload_module (void)
 

Variables

static struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_LOAD_ORDER , .description = "Send DTMF digits Application" , .key = "This paragraph is copyright (c) 2006 by Digium, Inc. \In order for your module to load, it must return this \key via a function called \"key\". Any code which \includes this paragraph must be licensed under the GNU \General Public License version 2 or later (at your \option). In addition to Digium's general reservations \of rights, Digium expressly reserves the right to \allow other parties to license this paragraph under \different terms. Any use of Digium, Inc. trademarks or \logos (including \"Asterisk\" or \"Digium\") without \express written permission of Digium, Inc. is prohibited.\n" , .buildopt_sum = AST_BUILDOPT_SUM, .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_DEFAULT, .support_level = AST_MODULE_SUPPORT_CORE, }
 
static const struct ast_module_infoast_module_info = &__mod_info
 
static const struct ast_app_option senddtmf_app_options [128] = { [ 'a' ] = { .flag = OPT_ANSWER }, }
 
static const char senddtmf_name [] = "SendDTMF"
 

Detailed Description

App to send DTMF digits.

Author
Mark Spencer marks.nosp@m.ter@.nosp@m.digiu.nosp@m.m.co.nosp@m.m

Definition in file app_senddtmf.c.

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
OPT_ARG_ARRAY_SIZE 

Definition at line 127 of file app_senddtmf.c.

127 {
128 /* note: this entry _MUST_ be the last one in the enum */
130};
@ OPT_ARG_ARRAY_SIZE
Definition: app_senddtmf.c:129

◆ read_option_flags

Enumerator
OPT_DELAY 
OPT_MUTE 
OPT_QUELCH 
OPT_RELAXED 
OPT_LAX_KP 
OPT_PROCESS 
OPT_NO_KP 
OPT_NO_ST 
OPT_KP_OVERRIDE 
OPT_MAXDIGITS 
OPT_SKIP 
OPT_INDICATION 
OPT_NOANSWER 
OPT_TERMINATOR 
OPT_KEEP_TERMINATOR 
OPT_ANSWER 
OPT_DELAY 
OPT_MUTE 
OPT_QUELCH 
OPT_RELAXED 
OPT_EXTRAPULSES 

Definition at line 119 of file app_senddtmf.c.

119 {
120 OPT_ANSWER = (1 << 0),
121};
@ OPT_ANSWER
Definition: app_senddtmf.c:120

Function Documentation

◆ __reg_module()

static void __reg_module ( void  )
static

Definition at line 288 of file app_senddtmf.c.

◆ __unreg_module()

static void __unreg_module ( void  )
static

Definition at line 288 of file app_senddtmf.c.

◆ AST_MODULE_SELF_SYM()

struct ast_module * AST_MODULE_SELF_SYM ( void  )

Definition at line 288 of file app_senddtmf.c.

◆ load_module()

static int load_module ( void  )
static

Definition at line 277 of file app_senddtmf.c.

278{
279 int res;
280
284
285 return res;
286}
static int manager_send_flash(struct mansession *s, const struct message *m)
Definition: app_senddtmf.c:238
static const char senddtmf_name[]
Definition: app_senddtmf.c:132
static int manager_play_dtmf(struct mansession *s, const struct message *m)
Definition: app_senddtmf.c:196
static int senddtmf_exec(struct ast_channel *chan, const char *vdata)
Definition: app_senddtmf.c:134
#define ast_manager_register_xml(action, authority, func)
Register a manager callback using XML documentation to describe the manager.
Definition: manager.h:191
#define EVENT_FLAG_CALL
Definition: manager.h:76
#define ast_register_application_xml(app, execute)
Register an application using XML documentation.
Definition: module.h:640

References ast_manager_register_xml, ast_register_application_xml, EVENT_FLAG_CALL, manager_play_dtmf(), manager_send_flash(), senddtmf_exec(), and senddtmf_name.

◆ manager_play_dtmf()

static int manager_play_dtmf ( struct mansession s,
const struct message m 
)
static

Definition at line 196 of file app_senddtmf.c.

197{
198 const char *channel = astman_get_header(m, "Channel");
199 const char *digit = astman_get_header(m, "Digit");
200 const char *duration = astman_get_header(m, "Duration");
201 const char *receive_s = astman_get_header(m, "Receive");
202 struct ast_channel *chan;
203 unsigned int duration_ms = 0;
204
205 if (!(chan = ast_channel_get_by_name(channel))) {
206 astman_send_error(s, m, "Channel not found");
207 return 0;
208 }
209
210 if (ast_strlen_zero(digit)) {
211 astman_send_error(s, m, "No digit specified");
212 chan = ast_channel_unref(chan);
213 return 0;
214 }
215
216 if (!ast_strlen_zero(duration) && (sscanf(duration, "%30u", &duration_ms) != 1)) {
217 astman_send_error(s, m, "Could not convert Duration parameter");
218 chan = ast_channel_unref(chan);
219 return 0;
220 }
221
222 if (ast_true(receive_s)) {
223 struct ast_frame f = { AST_FRAME_DTMF, };
224 f.len = duration_ms;
226 ast_queue_frame(chan, &f);
227 } else {
228 ast_senddigit_external(chan, *digit, duration_ms);
229 }
230
231 chan = ast_channel_unref(chan);
232
233 astman_send_ack(s, m, "DTMF successfully queued");
234
235 return 0;
236}
char digit
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_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:5006
#define ast_channel_unref(c)
Decrease channel reference count.
Definition: channel.h:3004
struct ast_channel * ast_channel_get_by_name(const char *name)
Find a channel by name.
Definition: channel.c:1473
void astman_send_error(struct mansession *s, const struct message *m, char *error)
Send error in manager transaction.
Definition: manager.c:1969
void astman_send_ack(struct mansession *s, const struct message *m, char *msg)
Send ack in manager transaction.
Definition: manager.c:2001
const char * astman_get_header(const struct message *m, char *var)
Get header from manager transaction.
Definition: manager.c:1630
#define AST_FRAME_DTMF
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.
Data structure associated with a single frame of data.
struct ast_frame_subclass subclass

References ast_channel_get_by_name(), ast_channel_unref, AST_FRAME_DTMF, ast_queue_frame(), ast_senddigit_external(), ast_strlen_zero(), ast_true(), astman_get_header(), astman_send_ack(), astman_send_error(), digit, ast_frame_subclass::integer, ast_frame::len, and ast_frame::subclass.

Referenced by load_module().

◆ manager_send_flash()

static int manager_send_flash ( struct mansession s,
const struct message m 
)
static

Definition at line 238 of file app_senddtmf.c.

239{
240 const char *channel = astman_get_header(m, "Channel");
241 const char *receive_s = astman_get_header(m, "Receive");
242 struct ast_channel *chan;
243
244 if (!(chan = ast_channel_get_by_name(channel))) {
245 astman_send_error(s, m, "Channel not found");
246 return 0;
247 }
248
249 if (ast_true(receive_s)) {
250 struct ast_frame f = { AST_FRAME_CONTROL, };
252 ast_queue_frame(chan, &f);
253 } else {
254 struct ast_frame f = { AST_FRAME_CONTROL, };
256 ast_channel_lock(chan);
257 ast_write(chan, &f);
258 ast_channel_unlock(chan);
259 }
260
261 chan = ast_channel_unref(chan);
262 astman_send_ack(s, m, "Flash successfully queued");
263 return 0;
264}
#define ast_channel_lock(chan)
Definition: channel.h:2968
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:5163
#define ast_channel_unlock(chan)
Definition: channel.h:2969
@ AST_FRAME_CONTROL
@ AST_CONTROL_FLASH

References ast_channel_get_by_name(), ast_channel_lock, ast_channel_unlock, ast_channel_unref, AST_CONTROL_FLASH, AST_FRAME_CONTROL, ast_queue_frame(), ast_true(), ast_write(), astman_get_header(), astman_send_ack(), astman_send_error(), ast_frame_subclass::integer, and ast_frame::subclass.

Referenced by load_module().

◆ senddtmf_exec()

static int senddtmf_exec ( struct ast_channel chan,
const char *  vdata 
)
static

Definition at line 134 of file app_senddtmf.c.

135{
136 int res;
137 char *data;
138 int dinterval = 0, duration = 0;
139 struct ast_channel *chan_found = NULL;
140 struct ast_channel *chan_dest = chan;
141 struct ast_channel *chan_autoservice = NULL;
142 char *opt_args[OPT_ARG_ARRAY_SIZE];
143 struct ast_flags flags = {0};
145 AST_APP_ARG(digits);
146 AST_APP_ARG(dinterval);
147 AST_APP_ARG(duration);
148 AST_APP_ARG(channel);
150 );
151
152 if (ast_strlen_zero(vdata)) {
153 ast_log(LOG_WARNING, "SendDTMF requires an argument\n");
154 return 0;
155 }
156
157 data = ast_strdupa(vdata);
159
160 if (ast_strlen_zero(args.digits)) {
161 ast_log(LOG_WARNING, "The digits argument is required (0-9,*#,a-d,A-D,wfF)\n");
162 return 0;
163 }
164 if (!ast_strlen_zero(args.dinterval)) {
165 ast_app_parse_timelen(args.dinterval, &dinterval, TIMELEN_MILLISECONDS);
166 }
167 if (!ast_strlen_zero(args.duration)) {
168 ast_app_parse_timelen(args.duration, &duration, TIMELEN_MILLISECONDS);
169 }
170 if (!ast_strlen_zero(args.channel)) {
171 chan_found = ast_channel_get_by_name(args.channel);
172 if (!chan_found) {
173 ast_log(LOG_WARNING, "No such channel: %s\n", args.channel);
174 return 0;
175 }
176 chan_dest = chan_found;
177 if (chan_found != chan) {
178 chan_autoservice = chan;
179 }
180 }
181 if (!ast_strlen_zero(args.options)) {
183 }
185 ast_auto_answer(chan_dest);
186 }
187 res = ast_dtmf_stream(chan_dest, chan_autoservice, args.digits,
188 dinterval <= 0 ? 250 : dinterval, duration);
189 if (chan_found) {
190 ast_channel_unref(chan_found);
191 }
192
193 return chan_autoservice ? 0 : res;
194}
static const struct ast_app_option senddtmf_app_options[128]
Definition: app_senddtmf.c:125
#define ast_strdupa(s)
duplicate a string in memory from the stack
Definition: astmm.h:298
#define ast_log
Definition: astobj2.c:42
int ast_auto_answer(struct ast_channel *chan)
Answer a channel, if it's not already answered.
Definition: channel.c:2830
#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_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
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 LOG_WARNING
#define NULL
Definition: resample.c:96
Structure used to handle boolean flags.
Definition: utils.h:199
unsigned int flags
Definition: utils.h:200
const char * args
static struct test_options options
#define ast_test_flag(p, flag)
Definition: utils.h:63

References args, AST_APP_ARG, ast_app_parse_options(), ast_app_parse_timelen(), ast_auto_answer(), ast_channel_get_by_name(), ast_channel_unref, AST_DECLARE_APP_ARGS, ast_dtmf_stream(), ast_log, AST_STANDARD_APP_ARGS, ast_strdupa, ast_strlen_zero(), ast_test_flag, ast_flags::flags, LOG_WARNING, NULL, OPT_ANSWER, OPT_ARG_ARRAY_SIZE, options, senddtmf_app_options, and TIMELEN_MILLISECONDS.

Referenced by load_module().

◆ unload_module()

static int unload_module ( void  )
static

Definition at line 266 of file app_senddtmf.c.

267{
268 int res;
269
271 res |= ast_manager_unregister("PlayDTMF");
272 res |= ast_manager_unregister("SendFlash");
273
274 return res;
275}
int ast_manager_unregister(const char *action)
Unregister a registered manager command.
Definition: manager.c:7608
int ast_unregister_application(const char *app)
Unregister an application.
Definition: pbx_app.c:392

References ast_manager_unregister(), ast_unregister_application(), and senddtmf_name.

Variable Documentation

◆ __mod_info

struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_LOAD_ORDER , .description = "Send DTMF digits Application" , .key = "This paragraph is copyright (c) 2006 by Digium, Inc. \In order for your module to load, it must return this \key via a function called \"key\". Any code which \includes this paragraph must be licensed under the GNU \General Public License version 2 or later (at your \option). In addition to Digium's general reservations \of rights, Digium expressly reserves the right to \allow other parties to license this paragraph under \different terms. Any use of Digium, Inc. trademarks or \logos (including \"Asterisk\" or \"Digium\") without \express written permission of Digium, Inc. is prohibited.\n" , .buildopt_sum = AST_BUILDOPT_SUM, .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_DEFAULT, .support_level = AST_MODULE_SUPPORT_CORE, }
static

Definition at line 288 of file app_senddtmf.c.

◆ ast_module_info

const struct ast_module_info* ast_module_info = &__mod_info
static

Definition at line 288 of file app_senddtmf.c.

◆ senddtmf_app_options

const struct ast_app_option senddtmf_app_options[128] = { [ 'a' ] = { .flag = OPT_ANSWER }, }
static

Definition at line 125 of file app_senddtmf.c.

Referenced by senddtmf_exec().

◆ senddtmf_name

const char senddtmf_name[] = "SendDTMF"
static

Definition at line 132 of file app_senddtmf.c.

Referenced by load_module(), and unload_module().