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>zaptel</depend>
30 <depend>app_meetme</depend>
35 ASTERISK_FILE_VERSION(__FILE__
, "$Revision$")
37 #include "asterisk/channel.h"
38 #include "asterisk/pbx.h"
39 #include "asterisk/module.h"
40 #include "asterisk/file.h"
41 #include "asterisk/app.h"
42 #include "asterisk/chanvars.h"
43 #include "asterisk/utils.h"
44 #include "asterisk/devicestate.h"
45 #include "asterisk/dial.h"
47 static const char *app_page
= "Page";
49 static const char *page_synopsis
= "Pages phones";
51 static const char *page_descrip
=
52 "Page(Technology/Resource&Technology2/Resource2[,options])\n"
53 " Places outbound calls to the given technology / resource and dumps\n"
54 "them into a conference bridge as muted participants. The original\n"
55 "caller is dumped into the conference as a speaker and the room is\n"
56 "destroyed when the original caller leaves. Valid options are:\n"
57 " d - full duplex audio\n"
58 " q - quiet, do not play beep to caller\n"
59 " r - record the page into a file (see 'r' for app_meetme)\n"
60 " s - only dial channel if devicestate says it is not in use\n";
63 PAGE_DUPLEX
= (1 << 0),
64 PAGE_QUIET
= (1 << 1),
65 PAGE_RECORD
= (1 << 2),
69 AST_APP_OPTIONS(page_opts
, {
70 AST_APP_OPTION('d', PAGE_DUPLEX
),
71 AST_APP_OPTION('q', PAGE_QUIET
),
72 AST_APP_OPTION('r', PAGE_RECORD
),
73 AST_APP_OPTION('s', PAGE_SKIP
),
78 static int page_exec(struct ast_channel
*chan
, void *data
)
80 char *options
, *tech
, *resource
, *tmp
;
81 char meetmeopts
[88], originator
[AST_CHANNEL_NAME
], *opts
[0];
82 struct ast_flags flags
= { 0 };
83 unsigned int confid
= ast_random();
85 int res
= 0, pos
= 0, i
= 0;
86 struct ast_dial
*dials
[MAX_DIALS
];
88 if (ast_strlen_zero(data
)) {
89 ast_log(LOG_WARNING
, "This application requires at least one argument (destination(s) to page)\n");
93 if (!(app
= pbx_findapp("MeetMe"))) {
94 ast_log(LOG_WARNING
, "There is no MeetMe application available!\n");
98 options
= ast_strdupa(data
);
100 ast_copy_string(originator
, chan
->name
, sizeof(originator
));
101 if ((tmp
= strchr(originator
, '-')))
104 tmp
= strsep(&options
, ",");
106 ast_app_parse_options(page_opts
, &flags
, opts
, options
);
108 snprintf(meetmeopts
, sizeof(meetmeopts
), "MeetMe,%ud,%s%sqxdw(5)", confid
, (ast_test_flag(&flags
, PAGE_DUPLEX
) ? "" : "m"),
109 (ast_test_flag(&flags
, PAGE_RECORD
) ? "r" : "") );
111 /* Go through parsing/calling each device */
112 while ((tech
= strsep(&tmp
, "&"))) {
114 struct ast_dial
*dial
= NULL
;
116 /* don't call the originating device */
117 if (!strcasecmp(tech
, originator
))
120 /* If no resource is available, continue on */
121 if (!(resource
= strchr(tech
, '/'))) {
122 ast_log(LOG_WARNING
, "Incomplete destination '%s' supplied.\n", tech
);
126 /* Ensure device is not in use if skip option is enabled */
127 if (ast_test_flag(&flags
, PAGE_SKIP
)) {
128 state
= ast_device_state(tech
);
129 if (state
== AST_DEVICE_UNKNOWN
) {
130 ast_log(LOG_WARNING
, "Destination '%s' has device state '%s'. Paging anyway.\n", tech
, devstate2str(state
));
131 } else if (state
!= AST_DEVICE_NOT_INUSE
) {
132 ast_log(LOG_WARNING
, "Destination '%s' has device state '%s'.\n", tech
, devstate2str(state
));
139 /* Create a dialing structure */
140 if (!(dial
= ast_dial_create())) {
141 ast_log(LOG_WARNING
, "Failed to create dialing structure.\n");
145 /* Append technology and resource */
146 ast_dial_append(dial
, tech
, resource
);
148 /* Set ANSWER_EXEC as global option */
149 ast_dial_option_global_enable(dial
, AST_DIAL_OPTION_ANSWER_EXEC
, meetmeopts
);
151 /* Run this dial in async mode */
152 ast_dial_run(dial
, chan
, 1);
154 /* Put in our dialing array */
158 if (!ast_test_flag(&flags
, PAGE_QUIET
)) {
159 res
= ast_streamfile(chan
, "beep", chan
->language
);
161 res
= ast_waitstream(chan
, "");
165 snprintf(meetmeopts
, sizeof(meetmeopts
), "%ud,A%s%sqxd", confid
, (ast_test_flag(&flags
, PAGE_DUPLEX
) ? "" : "t"),
166 (ast_test_flag(&flags
, PAGE_RECORD
) ? "r" : "") );
167 pbx_exec(chan
, app
, meetmeopts
);
170 /* Go through each dial attempt cancelling, joining, and destroying */
171 for (i
= 0; i
< pos
; i
++) {
172 struct ast_dial
*dial
= dials
[i
];
174 /* We have to wait for the async thread to exit as it's possible Meetme won't throw them out immediately */
177 /* Hangup all channels */
178 ast_dial_hangup(dial
);
180 /* Destroy dialing structure */
181 ast_dial_destroy(dial
);
187 static int unload_module(void)
189 return ast_unregister_application(app_page
);
192 static int load_module(void)
194 return ast_register_application(app_page
, page_exec
, page_synopsis
, page_descrip
);
197 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY
, "Page Multiple Phones");