Asterisk - The Open Source Telephony Project  18.5.0
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.

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 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 = "30ef0c93b36035ec78c9cfd712d36d9b" , .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 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.

Function Documentation

◆ __reg_module()

static void __reg_module ( void  )
static

Definition at line 210 of file app_senddtmf.c.

◆ __unreg_module()

static void __unreg_module ( void  )
static

Definition at line 210 of file app_senddtmf.c.

◆ AST_MODULE_SELF_SYM()

struct ast_module* AST_MODULE_SELF_SYM ( void  )

Definition at line 210 of file app_senddtmf.c.

◆ load_module()

static int load_module ( void  )
static

Definition at line 200 of file app_senddtmf.c.

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

201 {
202  int res;
203 
206 
207  return res;
208 }
#define EVENT_FLAG_CALL
Definition: manager.h:72
static int manager_play_dtmf(struct mansession *s, const struct message *m)
Definition: app_senddtmf.c:148
static int senddtmf_exec(struct ast_channel *chan, const char *vdata)
Definition: app_senddtmf.c:95
static const char senddtmf_name[]
Definition: app_senddtmf.c:93
#define ast_manager_register_xml(action, authority, func)
Register a manager callback using XML documentation to describe the manager.
Definition: manager.h:186
#define ast_register_application_xml(app, execute)
Register an application using XML documentation.
Definition: module.h:626

◆ manager_play_dtmf()

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

Definition at line 148 of file app_senddtmf.c.

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().

149 {
150  const char *channel = astman_get_header(m, "Channel");
151  const char *digit = astman_get_header(m, "Digit");
152  const char *duration = astman_get_header(m, "Duration");
153  const char *receive_s = astman_get_header(m, "Receive");
154  struct ast_channel *chan;
155  unsigned int duration_ms = 0;
156 
157  if (!(chan = ast_channel_get_by_name(channel))) {
158  astman_send_error(s, m, "Channel not found");
159  return 0;
160  }
161 
162  if (ast_strlen_zero(digit)) {
163  astman_send_error(s, m, "No digit specified");
164  chan = ast_channel_unref(chan);
165  return 0;
166  }
167 
168  if (!ast_strlen_zero(duration) && (sscanf(duration, "%30u", &duration_ms) != 1)) {
169  astman_send_error(s, m, "Could not convert Duration parameter");
170  chan = ast_channel_unref(chan);
171  return 0;
172  }
173 
174  if (ast_true(receive_s)) {
175  struct ast_frame f = { AST_FRAME_DTMF, };
176  f.len = duration_ms;
177  f.subclass.integer = *digit;
178  ast_queue_frame(chan, &f);
179  } else {
180  ast_senddigit_external(chan, *digit, duration_ms);
181  }
182 
183  chan = ast_channel_unref(chan);
184 
185  astman_send_ack(s, m, "DTMF successfully queued");
186 
187  return 0;
188 }
char digit
Main Channel structure associated with a channel.
#define ast_channel_unref(c)
Decrease channel reference count.
Definition: channel.h:2981
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:5032
void astman_send_ack(struct mansession *s, const struct message *m, char *msg)
Send ack in manager transaction.
Definition: manager.c:3191
Definition: muted.c:95
#define AST_FRAME_DTMF
struct ast_frame_subclass subclass
const char * astman_get_header(const struct message *m, char *var)
Get header from mananger transaction.
Definition: manager.c:2820
#define ast_strlen_zero(foo)
Definition: strings.h:52
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:1139
int attribute_pure ast_true(const char *val)
Make sure something is true. Determine if a string containing a boolean value is "true". This function checks to see whether a string passed to it is an indication of an "true" value. It checks to see if the string is "yes", "true", "y", "t", "on" or "1".
Definition: main/utils.c:1951
Data structure associated with a single frame of data.
struct ast_channel * ast_channel_get_by_name(const char *name)
Find a channel by name.
Definition: channel.c:1454
void astman_send_error(struct mansession *s, const struct message *m, char *error)
Send error in manager transaction.
Definition: manager.c:3159

◆ senddtmf_exec()

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

Definition at line 95 of file app_senddtmf.c.

References args, AST_APP_ARG, ast_app_parse_timelen(), 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, LOG_WARNING, NULL, and TIMELEN_MILLISECONDS.

Referenced by load_module().

96 {
97  int res;
98  char *data;
99  int dinterval = 0, duration = 0;
100  struct ast_channel *chan_found = NULL;
101  struct ast_channel *chan_dest = chan;
102  struct ast_channel *chan_autoservice = NULL;
104  AST_APP_ARG(digits);
105  AST_APP_ARG(dinterval);
106  AST_APP_ARG(duration);
108  );
109 
110  if (ast_strlen_zero(vdata)) {
111  ast_log(LOG_WARNING, "SendDTMF requires an argument\n");
112  return 0;
113  }
114 
115  data = ast_strdupa(vdata);
117 
118  if (ast_strlen_zero(args.digits)) {
119  ast_log(LOG_WARNING, "The digits argument is required (0-9,*#,a-d,A-D,wfF)\n");
120  return 0;
121  }
122  if (!ast_strlen_zero(args.dinterval)) {
123  ast_app_parse_timelen(args.dinterval, &dinterval, TIMELEN_MILLISECONDS);
124  }
125  if (!ast_strlen_zero(args.duration)) {
126  ast_app_parse_timelen(args.duration, &duration, TIMELEN_MILLISECONDS);
127  }
128  if (!ast_strlen_zero(args.channel)) {
129  chan_found = ast_channel_get_by_name(args.channel);
130  if (!chan_found) {
131  ast_log(LOG_WARNING, "No such channel: %s\n", args.channel);
132  return 0;
133  }
134  chan_dest = chan_found;
135  if (chan_found != chan) {
136  chan_autoservice = chan;
137  }
138  }
139  res = ast_dtmf_stream(chan_dest, chan_autoservice, args.digits,
140  dinterval <= 0 ? 250 : dinterval, duration);
141  if (chan_found) {
142  ast_channel_unref(chan_found);
143  }
144 
145  return chan_autoservice ? 0 : res;
146 }
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:981
Main Channel structure associated with a channel.
#define ast_channel_unref(c)
Decrease channel reference count.
Definition: channel.h:2981
#define AST_STANDARD_APP_ARGS(args, parse)
Performs the &#39;standard&#39; argument separation process for an application.
#define LOG_WARNING
Definition: logger.h:274
Definition: muted.c:95
const char * args
#define NULL
Definition: resample.c:96
#define ast_strlen_zero(foo)
Definition: strings.h:52
#define ast_log
Definition: astobj2.c:42
#define ast_strdupa(s)
duplicate a string in memory from the stack
Definition: astmm.h:300
union ast_frame::@263 data
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:3113
struct ast_channel * ast_channel_get_by_name(const char *name)
Find a channel by name.
Definition: channel.c:1454
#define AST_DECLARE_APP_ARGS(name, arglist)
Declare a structure to hold an application&#39;s arguments.
#define AST_APP_ARG(name)
Define an application argument.

◆ unload_module()

static int unload_module ( void  )
static

Definition at line 190 of file app_senddtmf.c.

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

191 {
192  int res;
193 
195  res |= ast_manager_unregister("PlayDTMF");
196 
197  return res;
198 }
int ast_unregister_application(const char *app)
Unregister an application.
Definition: pbx_app.c:392
int ast_manager_unregister(const char *action)
Unregister a registered manager command.
Definition: manager.c:7258
static const char senddtmf_name[]
Definition: app_senddtmf.c:93

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 = "30ef0c93b36035ec78c9cfd712d36d9b" , .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_DEFAULT, .support_level = AST_MODULE_SUPPORT_CORE, }
static

Definition at line 210 of file app_senddtmf.c.

◆ ast_module_info

const struct ast_module_info* ast_module_info = &__mod_info
static

Definition at line 210 of file app_senddtmf.c.

◆ senddtmf_name

const char senddtmf_name[] = "SendDTMF"
static

Definition at line 93 of file app_senddtmf.c.

Referenced by load_module(), and unload_module().