Wed Jan 8 2020 09:49:55

Asterisk developer's documentation


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"

Go to the source code of this file.

Functions

static void __reg_module (void)
 
static void __unreg_module (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 = "ac1f6a56484a8820659555499174e588" , .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_DEFAULT, }
 
static 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

static void __reg_module ( void  )
static

Definition at line 190 of file app_senddtmf.c.

static void __unreg_module ( void  )
static

Definition at line 190 of file app_senddtmf.c.

static int load_module ( void  )
static

Definition at line 180 of file app_senddtmf.c.

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

181 {
182  int res;
183 
186 
187  return res;
188 }
#define EVENT_FLAG_CALL
Definition: manager.h:72
static int manager_play_dtmf(struct mansession *s, const struct message *m)
Definition: app_senddtmf.c:144
#define ast_manager_register_xml(a, b, c)
Register a manager callback using XML documentation to describe the manager.
Definition: manager.h:172
static int senddtmf_exec(struct ast_channel *chan, const char *vdata)
Definition: app_senddtmf.c:91
static const char senddtmf_name[]
Definition: app_senddtmf.c:89
#define ast_register_application_xml(app, execute)
Register an application using XML documentation.
Definition: module.h:437
static int manager_play_dtmf ( struct mansession s,
const struct message m 
)
static

Definition at line 144 of file app_senddtmf.c.

References ast_channel_get_by_name(), ast_channel_unref, ast_senddigit(), ast_strlen_zero(), astman_get_header(), astman_send_ack(), and astman_send_error().

Referenced by load_module().

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 }
Main Channel structure associated with a channel.
Definition: channel.h:742
#define ast_channel_unref(c)
Decrease channel reference count.
Definition: channel.h:2502
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
const char * astman_get_header(const struct message *m, char *var)
Get header from mananger transaction.
Definition: manager.c:1860
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition: strings.h:63
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
static int senddtmf_exec ( struct ast_channel chan,
const char *  vdata 
)
static

Definition at line 91 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, and TIMELEN_MILLISECONDS.

Referenced by load_module().

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 }
Main Channel structure associated with a channel.
Definition: channel.h:742
#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
const char * data
Definition: channel.h:755
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition: strings.h:63
#define ast_strdupa(s)
duplicate a string in memory from the stack
Definition: utils.h:663
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
#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
struct ast_channel * ast_channel_get_by_name(const char *name)
Find a channel by name.
Definition: channel.c:1803
static int unload_module ( void  )
static

Definition at line 170 of file app_senddtmf.c.

References ast_manager_unregister(), and ast_unregister_application().

171 {
172  int res;
173 
175  res |= ast_manager_unregister("PlayDTMF");
176 
177  return res;
178 }
int ast_unregister_application(const char *app)
Unregister an application.
Definition: pbx.c:7705
static const char senddtmf_name[]
Definition: app_senddtmf.c:89
int ast_manager_unregister(char *action)
Unregister a registered manager command.
Definition: manager.c:5355

Variable Documentation

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

Definition at line 190 of file app_senddtmf.c.

Definition at line 190 of file app_senddtmf.c.

const char senddtmf_name[] = "SendDTMF"
static

Definition at line 89 of file app_senddtmf.c.