Asterisk - The Open Source Telephony Project GIT-master-27fb039
Loading...
Searching...
No Matches
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_ANSWER = (1 << 0) }
 

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 = ASTERISK_GPL_KEY , .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 137 of file app_senddtmf.c.

137 {
138 /* note: this entry _MUST_ be the last one in the enum */
140};
@ OPT_ARG_ARRAY_SIZE

◆ read_option_flags

Enumerator
OPT_ANSWER 

Definition at line 129 of file app_senddtmf.c.

129 {
130 OPT_ANSWER = (1 << 0),
131};
@ OPT_ANSWER

Function Documentation

◆ __reg_module()

static void __reg_module ( void  )
static

Definition at line 298 of file app_senddtmf.c.

◆ __unreg_module()

static void __unreg_module ( void  )
static

Definition at line 298 of file app_senddtmf.c.

◆ AST_MODULE_SELF_SYM()

struct ast_module * AST_MODULE_SELF_SYM ( void  )

Definition at line 298 of file app_senddtmf.c.

◆ load_module()

static int load_module ( void  )
static

Definition at line 287 of file app_senddtmf.c.

288{
289 int res;
290
294
295 return res;
296}
static int manager_send_flash(struct mansession *s, const struct message *m)
static const char senddtmf_name[]
static int manager_play_dtmf(struct mansession *s, const struct message *m)
static int senddtmf_exec(struct ast_channel *chan, const char *vdata)
#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
#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 206 of file app_senddtmf.c.

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}
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:1170
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:4982
struct ast_channel * ast_channel_get_by_name(const char *search)
Find a channel by name or uniqueid.
Definition channel.c:1416
#define ast_channel_unref(c)
Decrease channel reference count.
Definition channel.h:3018
void astman_send_error(struct mansession *s, const struct message *m, char *error)
Send error in manager transaction.
Definition manager.c:1982
void astman_send_ack(struct mansession *s, const struct message *m, char *msg)
Send ack in manager transaction.
Definition manager.c:2014
const char * astman_get_header(const struct message *m, char *var)
Get header from manager transaction.
Definition manager.c:1643
#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:2235
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 248 of file app_senddtmf.c.

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}
#define ast_channel_lock(chan)
Definition channel.h:2982
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:5139
#define ast_channel_unlock(chan)
Definition channel.h:2983
@ 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 144 of file app_senddtmf.c.

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}
static const struct ast_app_option senddtmf_app_options[128]
#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:2809
#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
static struct @519 args
#define NULL
Definition resample.c:96
Structure used to handle boolean flags.
Definition utils.h:220
unsigned int flags
Definition utils.h:221
static struct test_options options
#define ast_test_flag(p, flag)
Definition utils.h:64

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 276 of file app_senddtmf.c.

277{
278 int res;
279
281 res |= ast_manager_unregister("PlayDTMF");
282 res |= ast_manager_unregister("SendFlash");
283
284 return res;
285}
int ast_manager_unregister(const char *action)
Unregister a registered manager command.
Definition manager.c:7698
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 = ASTERISK_GPL_KEY , .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 298 of file app_senddtmf.c.

◆ ast_module_info

const struct ast_module_info* ast_module_info = &__mod_info
static

Definition at line 298 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 135 of file app_senddtmf.c.

Referenced by senddtmf_exec().

◆ senddtmf_name

const char senddtmf_name[] = "SendDTMF"
static

Definition at line 142 of file app_senddtmf.c.

Referenced by load_module(), and unload_module().