2 * Asterisk -- An open source telephony toolkit.
4 * Copyright (c) 2004 - 2006 Digium, Inc. All rights reserved.
6 * Mark Spencer <markster@digium.com>
8 * This code is released under the GNU General Public License
9 * version 2.0. See LICENSE for more information.
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.
21 * \brief page() - Paging application
23 * \author Mark Spencer <markster@digium.com>
25 * \ingroup applications
29 <depend>dahdi</depend>
30 <depend>app_meetme</depend>
31 <support_level>core</support_level>
36 ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
38 #include "asterisk/channel.h"
39 #include "asterisk/pbx.h"
40 #include "asterisk/module.h"
41 #include "asterisk/file.h"
42 #include "asterisk/app.h"
43 #include "asterisk/chanvars.h"
44 #include "asterisk/utils.h"
45 #include "asterisk/devicestate.h"
46 #include "asterisk/dial.h"
49 <application name="Page" language="en_US">
54 <parameter name="Technology/Resource" required="true" argsep="&">
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>
61 <argument name="Technology2/Resource2" multiple="true">
62 <para>Optional extra devices to dial inparallel</para>
63 <para>If you need more then one enter them as Technology2/Resource2&
64 Technology3/Resourse3&.....</para>
67 <parameter name="options">
70 <para>Full duplex audio</para>
73 <para>Ignore attempts to forward the call</para>
76 <para>Quiet, do not play beep to caller</para>
79 <para>Record the page into a file (meetme option <literal>r</literal>)</para>
82 <para>Only dial a channel if its device state says that it is <literal>NOT_INUSE</literal></para>
85 <argument name="x" required="true">
86 <para>The announcement to playback in all devices</para>
88 <para>Play an announcement simultaneously to all paged participants</para>
91 <para>Do not play simultaneous announcement to caller (implies <literal>A(x)</literal>)</para>
95 <parameter name="timeout">
96 <para>Specify the length of time that the system will attempt to connect a call.
97 After this duration, any intercom calls that have not been answered will be hung up by the
102 <para>Places outbound calls to the given <replaceable>technology</replaceable>/<replaceable>resource</replaceable>
103 and dumps them into a conference bridge as muted participants. The original
104 caller is dumped into the conference as a speaker and the room is
105 destroyed when the original callers leaves.</para>
108 <ref type="application">MeetMe</ref>
112 static const char * const app_page= "Page";
114 enum page_opt_flags {
115 PAGE_DUPLEX = (1 << 0),
116 PAGE_QUIET = (1 << 1),
117 PAGE_RECORD = (1 << 2),
118 PAGE_SKIP = (1 << 3),
119 PAGE_IGNORE_FORWARDS = (1 << 4),
120 PAGE_ANNOUNCE = (1 << 5),
121 PAGE_NOCALLERANNOUNCE = (1 << 6),
125 OPT_ARG_ANNOUNCE = 0,
126 OPT_ARG_ARRAY_SIZE = 1,
129 AST_APP_OPTIONS(page_opts, {
130 AST_APP_OPTION('d', PAGE_DUPLEX),
131 AST_APP_OPTION('q', PAGE_QUIET),
132 AST_APP_OPTION('r', PAGE_RECORD),
133 AST_APP_OPTION('s', PAGE_SKIP),
134 AST_APP_OPTION('i', PAGE_IGNORE_FORWARDS),
135 AST_APP_OPTION('i', PAGE_IGNORE_FORWARDS),
136 AST_APP_OPTION_ARG('A', PAGE_ANNOUNCE, OPT_ARG_ANNOUNCE),
137 AST_APP_OPTION('n', PAGE_NOCALLERANNOUNCE),
141 static int page_exec(struct ast_channel *chan, const char *data)
143 char *tech, *resource, *tmp;
144 char meetmeopts[128], originator[AST_CHANNEL_NAME], *opts[OPT_ARG_ARRAY_SIZE];
145 struct ast_flags flags = { 0 };
146 unsigned int confid = ast_random();
148 int res = 0, pos = 0, i = 0;
149 struct ast_dial **dial_list;
150 unsigned int num_dials;
154 AST_DECLARE_APP_ARGS(args,
155 AST_APP_ARG(devices);
156 AST_APP_ARG(options);
157 AST_APP_ARG(timeout);
160 if (ast_strlen_zero(data)) {
161 ast_log(LOG_WARNING, "This application requires at least one argument (destination(s) to page)\n");
165 if (!(app = pbx_findapp("MeetMe"))) {
166 ast_log(LOG_WARNING, "There is no MeetMe application available!\n");
170 parse = ast_strdupa(data);
172 AST_STANDARD_APP_ARGS(args, parse);
174 ast_copy_string(originator, ast_channel_name(chan), sizeof(originator));
175 if ((tmp = strchr(originator, '-'))) {
179 if (!ast_strlen_zero(args.options)) {
180 ast_app_parse_options(page_opts, &flags, opts, args.options);
183 if (!ast_strlen_zero(args.timeout)) {
184 timeout = atoi(args.timeout);
187 if (ast_test_flag(&flags, PAGE_ANNOUNCE) && !ast_strlen_zero(opts[OPT_ARG_ANNOUNCE])) {
188 snprintf(meetmeopts, sizeof(meetmeopts), "MeetMe,%ud,%s%sqxdw(5)G(%s)", confid, (ast_test_flag(&flags, PAGE_DUPLEX) ? "" : "m"),
189 (ast_test_flag(&flags, PAGE_RECORD) ? "r" : ""), opts[OPT_ARG_ANNOUNCE] );
191 snprintf(meetmeopts, sizeof(meetmeopts), "MeetMe,%ud,%s%sqxdw(5)", confid, (ast_test_flag(&flags, PAGE_DUPLEX) ? "" : "m"),
192 (ast_test_flag(&flags, PAGE_RECORD) ? "r" : "") );
195 /* Count number of extensions in list by number of ampersands + 1 */
205 if (!(dial_list = ast_calloc(num_dials, sizeof(struct ast_dial *)))) {
206 ast_log(LOG_ERROR, "Can't allocate %ld bytes for dial list\n", (long)(sizeof(struct ast_dial *) * num_dials));
210 /* Go through parsing/calling each device */
211 while ((tech = strsep(&args.devices, "&"))) {
213 struct ast_dial *dial = NULL;
215 /* don't call the originating device */
216 if (!strcasecmp(tech, originator))
219 /* If no resource is available, continue on */
220 if (!(resource = strchr(tech, '/'))) {
221 ast_log(LOG_WARNING, "Incomplete destination '%s' supplied.\n", tech);
225 /* Ensure device is not in use if skip option is enabled */
226 if (ast_test_flag(&flags, PAGE_SKIP)) {
227 state = ast_device_state(tech);
228 if (state == AST_DEVICE_UNKNOWN) {
229 ast_log(LOG_WARNING, "Destination '%s' has device state '%s'. Paging anyway.\n", tech, ast_devstate2str(state));
230 } else if (state != AST_DEVICE_NOT_INUSE) {
231 ast_log(LOG_WARNING, "Destination '%s' has device state '%s'.\n", tech, ast_devstate2str(state));
238 /* Create a dialing structure */
239 if (!(dial = ast_dial_create())) {
240 ast_log(LOG_WARNING, "Failed to create dialing structure.\n");
244 /* Append technology and resource */
245 if (ast_dial_append(dial, tech, resource) == -1) {
246 ast_log(LOG_ERROR, "Failed to add %s to outbound dial\n", tech);
250 /* Set ANSWER_EXEC as global option */
251 ast_dial_option_global_enable(dial, AST_DIAL_OPTION_ANSWER_EXEC, meetmeopts);
254 ast_dial_set_global_timeout(dial, timeout * 1000);
257 if (ast_test_flag(&flags, PAGE_IGNORE_FORWARDS)) {
258 ast_dial_option_global_enable(dial, AST_DIAL_OPTION_DISABLE_CALL_FORWARDING, NULL);
261 /* Run this dial in async mode */
262 ast_dial_run(dial, chan, 1);
264 /* Put in our dialing array */
265 dial_list[pos++] = dial;
268 if (!ast_test_flag(&flags, PAGE_QUIET)) {
269 res = ast_streamfile(chan, "beep", ast_channel_language(chan));
271 res = ast_waitstream(chan, "");
275 /* Default behaviour */
276 snprintf(meetmeopts, sizeof(meetmeopts), "%ud,A%s%sqxd", confid, (ast_test_flag(&flags, PAGE_DUPLEX) ? "" : "t"),
277 (ast_test_flag(&flags, PAGE_RECORD) ? "r" : "") );
278 if (ast_test_flag(&flags, PAGE_ANNOUNCE) && !ast_strlen_zero(opts[OPT_ARG_ANNOUNCE]) &&
279 !ast_test_flag(&flags, PAGE_NOCALLERANNOUNCE)) {
280 snprintf(meetmeopts, sizeof(meetmeopts), "%ud,A%s%sqxdG(%s)", confid, (ast_test_flag(&flags, PAGE_DUPLEX) ? "" : "t"),
281 (ast_test_flag(&flags, PAGE_RECORD) ? "r" : ""), opts[OPT_ARG_ANNOUNCE] );
283 pbx_exec(chan, app, meetmeopts);
286 /* Go through each dial attempt cancelling, joining, and destroying */
287 for (i = 0; i < pos; i++) {
288 struct ast_dial *dial = dial_list[i];
290 /* We have to wait for the async thread to exit as it's possible Meetme won't throw them out immediately */
293 /* Hangup all channels */
294 ast_dial_hangup(dial);
296 /* Destroy dialing structure */
297 ast_dial_destroy(dial);
303 static int unload_module(void)
305 return ast_unregister_application(app_page);
308 static int load_module(void)
310 return ast_register_application_xml(app_page, page_exec);
313 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Page Multiple Phones");