Asterisk - The Open Source Telephony Project GIT-master-754dea3
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Macros Modules Pages
app_page.c
Go to the documentation of this file.
1/*
2 * Asterisk -- An open source telephony toolkit.
3 *
4 * Copyright (c) 2004 - 2006 Digium, Inc. All rights reserved.
5 *
6 * Mark Spencer <markster@digium.com>
7 *
8 * This code is released under the GNU General Public License
9 * version 2.0. See LICENSE for more information.
10 *
11 * See http://www.asterisk.org for more information about
12 * the Asterisk project. Please do not directly contact
13 * any of the maintainers of this project for assistance;
14 * the project provides a web site, mailing lists and IRC
15 * channels for your use.
16 *
17 */
18
19/*! \file
20 *
21 * \brief page() - Paging application
22 *
23 * \author Mark Spencer <markster@digium.com>
24 *
25 * \ingroup applications
26 */
27
28/*** MODULEINFO
29 <depend>app_confbridge</depend>
30 <support_level>core</support_level>
31 ***/
32
33#include "asterisk.h"
34
35#include "asterisk/channel.h"
36#include "asterisk/pbx.h"
37#include "asterisk/module.h"
38#include "asterisk/file.h"
39#include "asterisk/app.h"
40#include "asterisk/chanvars.h"
41#include "asterisk/utils.h"
43#include "asterisk/dial.h"
44
45/*** DOCUMENTATION
46 <application name="Page" language="en_US">
47 <since>
48 <version>1.2.0</version>
49 </since>
50 <synopsis>
51 Page series of phones
52 </synopsis>
53 <syntax>
54 <parameter name="Technology/Resource" required="false" argsep="&amp;">
55 <argument name="Technology/Resource" required="true">
56 <para>Specification of the device(s) to dial. These must be in the format of
57 <literal>Technology/Resource</literal>, where <replaceable>Technology</replaceable>
58 represents a particular channel driver, and <replaceable>Resource</replaceable> represents a resource
59 available to that particular channel driver.</para>
60 </argument>
61 <argument name="Technology2/Resource2" multiple="true">
62 <para>Optional extra devices to dial in parallel</para>
63 <para>If you need more than one, enter them as Technology2/Resource2&amp;
64 Technology3/Resource3&amp;.....</para>
65 </argument>
66 </parameter>
67 <parameter name="options">
68 <optionlist>
69 <option name="b" argsep="^">
70 <para>Before initiating an outgoing call, Gosub to the specified
71 location using the newly created channel. The Gosub will be
72 executed for each destination channel.</para>
73 <argument name="context" required="false" />
74 <argument name="exten" required="false" />
75 <argument name="priority" required="true" hasparams="optional" argsep="^">
76 <argument name="arg1" multiple="true" required="true" />
77 <argument name="argN" />
78 </argument>
79 </option>
80 <option name="B" argsep="^">
81 <para>Before initiating the outgoing call(s), Gosub to the specified
82 location using the current channel.</para>
83 <argument name="context" required="false" />
84 <argument name="exten" required="false" />
85 <argument name="priority" required="true" hasparams="optional" argsep="^">
86 <argument name="arg1" multiple="true" required="true" />
87 <argument name="argN" />
88 </argument>
89 </option>
90 <option name="d">
91 <para>Full duplex audio</para>
92 </option>
93 <option name="i">
94 <para>Ignore attempts to forward the call</para>
95 </option>
96 <option name="q">
97 <para>Quiet, do not play beep to caller</para>
98 </option>
99 <option name="r">
100 <para>Record the page into a file (<literal>CONFBRIDGE(bridge,record_conference)</literal>)</para>
101 </option>
102 <option name="s">
103 <para>Only dial a channel if its device state says that it is <literal>NOT_INUSE</literal></para>
104 </option>
105 <option name="A">
106 <argument name="x" required="true">
107 <para>The announcement to playback to all devices</para>
108 </argument>
109 <para>Play an announcement to all paged participants</para>
110 </option>
111 <option name="n">
112 <para>Do not play announcement to caller (alters <literal>A(x)</literal> behavior)</para>
113 </option>
114 </optionlist>
115 </parameter>
116 <parameter name="timeout">
117 <para>Specify the length of time that the system will attempt to connect a call.
118 After this duration, any page calls that have not been answered will be hung up by the
119 system.</para>
120 </parameter>
121 </syntax>
122 <description>
123 <para>Places outbound calls to the given <replaceable>technology</replaceable>/<replaceable>resource</replaceable>
124 and dumps them into a conference bridge as muted participants. The original
125 caller is dumped into the conference as a speaker and the room is
126 destroyed when the original caller leaves.</para>
127 </description>
128 <see-also>
129 <ref type="application">ConfBridge</ref>
130 </see-also>
131 </application>
132 ***/
133static const char * const app_page= "Page";
134
136 PAGE_DUPLEX = (1 << 0),
137 PAGE_QUIET = (1 << 1),
138 PAGE_RECORD = (1 << 2),
139 PAGE_SKIP = (1 << 3),
141 PAGE_ANNOUNCE = (1 << 5),
145};
146
147enum {
152};
153
164});
165
166#define PAGE_BEEP "beep"
167
168/* We use this structure as a way to pass this to all dialed channels */
172};
173
174/*!
175 * \internal
176 * \brief Setup the page bridge profile.
177 *
178 * \param chan Setup bridge profile on this channel.
179 * \param options Options to setup bridge profile.
180 */
181static void setup_profile_bridge(struct ast_channel *chan, struct page_options *options)
182{
183 /* Use default_bridge as a starting point */
184 ast_func_write(chan, "CONFBRIDGE(bridge,template)", "");
185 if (ast_test_flag(&options->flags, PAGE_RECORD)) {
186 ast_func_write(chan, "CONFBRIDGE(bridge,record_conference)", "yes");
187 }
188}
189
190/*!
191 * \internal
192 * \brief Setup the paged user profile.
193 *
194 * \param chan Setup user profile on this channel.
195 * \param options Options to setup paged user profile.
196 */
197static void setup_profile_paged(struct ast_channel *chan, struct page_options *options)
198{
199 /* Use default_user as a starting point */
200 ast_func_write(chan, "CONFBRIDGE(user,template)", "");
201 ast_func_write(chan, "CONFBRIDGE(user,quiet)", "yes");
202 ast_func_write(chan, "CONFBRIDGE(user,end_marked)", "yes");
203 if (!ast_test_flag(&options->flags, PAGE_DUPLEX)) {
204 ast_func_write(chan, "CONFBRIDGE(user,startmuted)", "yes");
205 }
208 ast_func_write(chan, "CONFBRIDGE(user,announcement)", options->opts[OPT_ARG_ANNOUNCE]);
209 }
210}
211
212/*!
213 * \internal
214 * \brief Setup the caller user profile.
215 *
216 * \param chan Setup user profile on this channel.
217 * \param options Options to setup caller user profile.
218 */
219static void setup_profile_caller(struct ast_channel *chan, struct page_options *options)
220{
221 /* Use default_user as a starting point if not already setup. */
222 ast_func_write(chan, "CONFBRIDGE(user,template)", "");
223 ast_func_write(chan, "CONFBRIDGE(user,quiet)", "yes");
224 ast_func_write(chan, "CONFBRIDGE(user,marked)", "yes");
228 ast_func_write(chan, "CONFBRIDGE(user,announcement)", options->opts[OPT_ARG_ANNOUNCE]);
229 }
230}
231
232static void page_state_callback(struct ast_dial *dial)
233{
234 struct ast_channel *chan;
235 struct page_options *options;
236
238 !(chan = ast_dial_answered(dial)) ||
239 !(options = ast_dial_get_user_data(dial))) {
240 return;
241 }
242
245}
246
247static int page_exec(struct ast_channel *chan, const char *data)
248{
249 char *tech;
250 char *resource;
251 char *tmp;
252 char *predial_callee = NULL;
253 char confbridgeopts[128];
254 char originator[AST_CHANNEL_NAME];
255 struct page_options options = { { 0, }, { 0, } };
256 unsigned int confid = ast_random();
257 struct ast_app *app;
258 int res = 0;
259 int pos = 0;
260 int i = 0;
261 struct ast_dial **dial_list;
262 unsigned int num_dials;
263 int timeout = 0;
264 char *parse;
265
270 );
271
272 if (!(app = pbx_findapp("ConfBridge"))) {
273 ast_log(LOG_WARNING, "There is no ConfBridge application available!\n");
274 return -1;
275 };
276
277 parse = ast_strdupa(data ?: "");
278
280
281 ast_copy_string(originator, ast_channel_name(chan), sizeof(originator));
282 if ((tmp = strchr(originator, '-'))) {
283 *tmp = '\0';
284 }
285
286 if (!ast_strlen_zero(args.options)) {
287 ast_app_parse_options(page_opts, &options.flags, options.opts, args.options);
288 }
289
290 if (!ast_strlen_zero(args.timeout)) {
291 timeout = atoi(args.timeout);
292 }
293
294 snprintf(confbridgeopts, sizeof(confbridgeopts), "ConfBridge,%u", confid);
295
296 /* Count number of extensions in list by number of ampersands + 1 */
297 num_dials = 1;
298 tmp = args.devices ?: "";
299 while (*tmp) {
300 if (*tmp == '&') {
301 num_dials++;
302 }
303 tmp++;
304 }
305
306 if (!(dial_list = ast_calloc(num_dials, sizeof(struct ast_dial *)))) {
307 ast_log(LOG_ERROR, "Can't allocate %ld bytes for dial list\n", (long)(sizeof(struct ast_dial *) * num_dials));
308 return -1;
309 }
310
311 /* PREDIAL: Preprocess any callee gosub arguments. */
315 predial_callee =
317 }
318
319 /* PREDIAL: Run gosub on the caller's channel */
324 }
325
326 /* Go through parsing/calling each device */
327 while ((tech = strsep(&args.devices, "&"))) {
328 int state = 0;
329 struct ast_dial *dial = NULL;
330
331 tech = ast_strip(tech);
332 if (ast_strlen_zero(tech)) {
333 /* No tech/resource in this position. */
334 continue;
335 }
336
337 /* don't call the originating device */
338 if (!strcasecmp(tech, originator)) {
339 continue;
340 }
341
342 /* If no resource is available, continue on */
343 if (!(resource = strchr(tech, '/'))) {
344 ast_log(LOG_WARNING, "Incomplete destination: '%s' supplied.\n", tech);
345 continue;
346 }
347
348 /* Ensure device is not in use if skip option is enabled */
349 if (ast_test_flag(&options.flags, PAGE_SKIP)) {
350 state = ast_device_state(tech);
351 if (state == AST_DEVICE_UNKNOWN) {
352 ast_verb(3, "Destination '%s' has device state '%s'. Paging anyway.\n",
353 tech, ast_devstate2str(state));
354 } else if (state != AST_DEVICE_NOT_INUSE) {
355 ast_verb(3, "Destination '%s' has device state '%s'.\n",
356 tech, ast_devstate2str(state));
357 continue;
358 }
359 }
360
361 *resource++ = '\0';
362
363 /* Create a dialing structure */
364 if (!(dial = ast_dial_create())) {
365 ast_log(LOG_WARNING, "Failed to create dialing structure.\n");
366 continue;
367 }
368
369 /* Append technology and resource */
370 if (ast_dial_append(dial, tech, resource, NULL) == -1) {
371 ast_log(LOG_ERROR, "Failed to add %s/%s to outbound dial\n", tech, resource);
372 ast_dial_destroy(dial);
373 continue;
374 }
375
376 /* Set ANSWER_EXEC as global option */
378
379 if (predial_callee) {
381 }
382
383 if (timeout) {
385 }
386
389 }
390
393
394 /* Run this dial in async mode */
395 ast_dial_run(dial, chan, 1);
396
397 /* Put in our dialing array */
398 dial_list[pos++] = dial;
399 }
400
401 ast_free(predial_callee);
402
403 if (!ast_test_flag(&options.flags, PAGE_QUIET)) {
405 ast_log(LOG_WARNING, "Missing required sound file: '" PAGE_BEEP "'\n");
406 } else {
408 if (!res) {
409 res = ast_waitstream(chan, "");
410 }
411 }
412 }
413
414 if (!res) {
417
418 snprintf(confbridgeopts, sizeof(confbridgeopts), "%u", confid);
419 pbx_exec(chan, app, confbridgeopts);
420 }
421
422 /* Go through each dial attempt cancelling, joining, and destroying */
423 for (i = 0; i < pos; i++) {
424 struct ast_dial *dial = dial_list[i];
425
426 /* We have to wait for the async thread to exit as it's possible ConfBridge won't throw them out immediately */
427 ast_dial_join(dial);
428
429 /* Hangup all channels */
430 ast_dial_hangup(dial);
431
432 /* Destroy dialing structure */
433 ast_dial_destroy(dial);
434 }
435
436 ast_free(dial_list);
437
438 return -1;
439}
440
441static int unload_module(void)
442{
444}
445
446static int load_module(void)
447{
449}
450
452 .support_level = AST_MODULE_SUPPORT_CORE,
453 .load = load_module,
454 .unload = unload_module,
455 .requires = "app_confbridge",
static const char app[]
Definition: app_adsiprog.c:56
@ OPT_ARG_PREDIAL_CALLEE
Definition: app_page.c:149
@ OPT_ARG_ANNOUNCE
Definition: app_page.c:148
@ OPT_ARG_PREDIAL_CALLER
Definition: app_page.c:150
@ OPT_ARG_ARRAY_SIZE
Definition: app_page.c:151
static void page_state_callback(struct ast_dial *dial)
Definition: app_page.c:232
static int page_exec(struct ast_channel *chan, const char *data)
Definition: app_page.c:247
static const char *const app_page
Definition: app_page.c:133
static void setup_profile_caller(struct ast_channel *chan, struct page_options *options)
Definition: app_page.c:219
static void setup_profile_paged(struct ast_channel *chan, struct page_options *options)
Definition: app_page.c:197
static void setup_profile_bridge(struct ast_channel *chan, struct page_options *options)
Definition: app_page.c:181
#define PAGE_BEEP
Definition: app_page.c:166
page_opt_flags
Definition: app_page.c:135
@ PAGE_NOCALLERANNOUNCE
Definition: app_page.c:142
@ PAGE_PREDIAL_CALLEE
Definition: app_page.c:143
@ PAGE_IGNORE_FORWARDS
Definition: app_page.c:140
@ PAGE_ANNOUNCE
Definition: app_page.c:141
@ PAGE_RECORD
Definition: app_page.c:138
@ PAGE_DUPLEX
Definition: app_page.c:136
@ PAGE_PREDIAL_CALLER
Definition: app_page.c:144
@ PAGE_SKIP
Definition: app_page.c:139
@ PAGE_QUIET
Definition: app_page.c:137
static int load_module(void)
Definition: app_page.c:446
static const struct ast_app_option page_opts[128]
Definition: app_page.c:164
static int unload_module(void)
Definition: app_page.c:441
char * strsep(char **str, const char *delims)
Asterisk main include file. File version handling, generic pbx functions.
#define ast_free(a)
Definition: astmm.h:180
#define ast_strdupa(s)
duplicate a string in memory from the stack
Definition: astmm.h:298
#define ast_calloc(num, len)
A wrapper for calloc()
Definition: astmm.h:202
#define ast_log
Definition: astobj2.c:42
General Asterisk PBX channel definitions.
const char * ast_channel_name(const struct ast_channel *chan)
#define AST_CHANNEL_NAME
Definition: channel.h:173
const char * ast_channel_language(const struct ast_channel *chan)
Channel Variables.
Device state management.
const char * ast_devstate2str(enum ast_device_state devstate) attribute_pure
Convert device state to text string for output.
Definition: devicestate.c:240
ast_device_state
Device States.
Definition: devicestate.h:52
@ AST_DEVICE_UNKNOWN
Definition: devicestate.h:53
@ AST_DEVICE_NOT_INUSE
Definition: devicestate.h:54
Dialing API.
enum ast_dial_result ast_dial_state(struct ast_dial *dial)
Return state of dial.
Definition: dial.c:1008
@ AST_DIAL_RESULT_ANSWERED
Definition: dial.h:61
void ast_dial_set_state_callback(struct ast_dial *dial, ast_dial_state_callback callback)
Set a callback for state changes.
Definition: dial.c:1269
int ast_dial_append(struct ast_dial *dial, const char *tech, const char *device, const struct ast_assigned_ids *assignedids)
Append a channel.
Definition: dial.c:280
struct ast_dial * ast_dial_create(void)
New dialing structure.
Definition: dial.c:223
struct ast_channel * ast_dial_answered(struct ast_dial *dial)
Return channel that answered.
Definition: dial.c:977
void ast_dial_set_user_data(struct ast_dial *dial, void *user_data)
Set user data on a dial structure.
Definition: dial.c:1274
void ast_dial_set_global_timeout(struct ast_dial *dial, int timeout)
Set the maximum time (globally) allowed for trying to ring phones.
Definition: dial.c:1284
void ast_dial_hangup(struct ast_dial *dial)
Hangup channels.
Definition: dial.c:1074
enum ast_dial_result ast_dial_run(struct ast_dial *dial, struct ast_channel *chan, int async)
Execute dialing synchronously or asynchronously.
Definition: dial.c:935
enum ast_dial_result ast_dial_join(struct ast_dial *dial)
Cancel async thread.
Definition: dial.c:1017
void * ast_dial_get_user_data(struct ast_dial *dial)
Return the user data on a dial structure.
Definition: dial.c:1279
@ AST_DIAL_OPTION_ANSWER_EXEC
Definition: dial.h:44
@ AST_DIAL_OPTION_PREDIAL
Definition: dial.h:47
@ AST_DIAL_OPTION_DISABLE_CALL_FORWARDING
Definition: dial.h:46
int ast_dial_destroy(struct ast_dial *dial)
Destroys a dialing structure.
Definition: dial.c:1091
int ast_dial_option_global_enable(struct ast_dial *dial, enum ast_dial_option option, void *data)
Enables an option globally.
Definition: dial.c:1145
Generic File Format Support. Should be included by clients of the file handling routines....
int ast_streamfile(struct ast_channel *c, const char *filename, const char *preflang)
Streams a file.
Definition: file.c:1301
int ast_fileexists(const char *filename, const char *fmt, const char *preflang)
Checks for the existence of a given file.
Definition: file.c:1137
int ast_waitstream(struct ast_channel *c, const char *breakon)
Waits for a stream to stop or digit to be pressed.
Definition: file.c:1848
Application convenience functions, designed to give consistent look and feel to Asterisk apps.
const char * ast_app_expand_sub_args(struct ast_channel *chan, const char *args)
Add missing context/exten to subroutine argument string.
Definition: main/app.c:278
#define AST_APP_ARG(name)
Define an application argument.
#define AST_APP_OPTIONS(holder, options...)
Declares an array of options for an application.
#define AST_APP_OPTION_ARG(option, flagno, argno)
Declares an application option that accepts an argument.
#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.
#define AST_APP_OPTION(option, flagno)
Declares an application option that does not accept an argument.
int ast_app_exec_sub(struct ast_channel *autoservice_chan, struct ast_channel *sub_chan, const char *sub_args, int ignore_hangup)
Run a subroutine on a channel, placing an optional second channel into autoservice.
Definition: main/app.c:297
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_ERROR
#define ast_verb(level,...)
#define LOG_WARNING
Asterisk module definitions.
@ AST_MODFLAG_DEFAULT
Definition: module.h:329
#define AST_MODULE_INFO(keystr, flags_to_set, desc, fields...)
Definition: module.h:557
@ AST_MODULE_SUPPORT_CORE
Definition: module.h:121
#define ASTERISK_GPL_KEY
The text the key() function should return.
Definition: module.h:46
int ast_unregister_application(const char *app)
Unregister an application.
Definition: pbx_app.c:392
#define ast_register_application_xml(app, execute)
Register an application using XML documentation.
Definition: module.h:640
Core PBX routines and definitions.
int pbx_exec(struct ast_channel *c, struct ast_app *app, const char *data)
Execute an application.
Definition: pbx_app.c:471
struct ast_app * pbx_findapp(const char *app)
Look up an application.
Definition: ael_main.c:165
int ast_func_write(struct ast_channel *chan, const char *function, const char *value)
executes a write operation on a function
#define NULL
Definition: resample.c:96
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition: strings.h:65
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
Definition: strings.h:425
char * ast_strip(char *s)
Strip leading/trailing whitespace from a string.
Definition: strings.h:223
ast_app: A registered application
Definition: pbx_app.c:45
Main Channel structure associated with a channel.
Main dialing structure. Contains global options, channels being dialed, and more!
Definition: dial.c:48
int timeout
Definition: dial.c:50
Structure used to handle boolean flags.
Definition: utils.h:199
struct ast_flags flags
Definition: app_page.c:171
char * opts[OPT_ARG_ARRAY_SIZE]
Definition: app_page.c:170
const char * args
static struct test_options options
Utility functions.
#define ast_test_flag(p, flag)
Definition: utils.h:63
long int ast_random(void)
Definition: utils.c:2312
void ast_replace_subargument_delimiter(char *s)
Replace '^' in a string with ','.
Definition: utils.c:2343