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>
35 ASTERISK_FILE_VERSION(__FILE__
, "$Revision$")
43 #include "asterisk/options.h"
44 #include "asterisk/logger.h"
45 #include "asterisk/channel.h"
46 #include "asterisk/pbx.h"
47 #include "asterisk/module.h"
48 #include "asterisk/file.h"
49 #include "asterisk/app.h"
50 #include "asterisk/chanvars.h"
51 #include "asterisk/utils.h"
52 #include "asterisk/dial.h"
53 #include "asterisk/devicestate.h"
55 static const char *app_page
= "Page";
57 static const char *page_synopsis
= "Pages phones";
59 static const char *page_descrip
=
60 "Page(Technology/Resource&Technology2/Resource2[|options])\n"
61 " Places outbound calls to the given technology / resource and dumps\n"
62 "them into a conference bridge as muted participants. The original\n"
63 "caller is dumped into the conference as a speaker and the room is\n"
64 "destroyed when the original caller leaves. Valid options are:\n"
65 " d - full duplex audio\n"
66 " q - quiet, do not play beep to caller\n"
67 " r - record the page into a file (see 'r' for app_meetme)\n";
70 PAGE_DUPLEX
= (1 << 0),
71 PAGE_QUIET
= (1 << 1),
72 PAGE_RECORD
= (1 << 2),
75 AST_APP_OPTIONS(page_opts
, {
76 AST_APP_OPTION('d', PAGE_DUPLEX
),
77 AST_APP_OPTION('q', PAGE_QUIET
),
78 AST_APP_OPTION('r', PAGE_RECORD
),
83 static int page_exec(struct ast_channel
*chan
, void *data
)
85 struct ast_module_user
*u
;
86 char *options
, *tech
, *resource
, *tmp
;
87 char meetmeopts
[88], originator
[AST_CHANNEL_NAME
];
88 struct ast_flags flags
= { 0 };
89 unsigned int confid
= ast_random();
91 int res
= 0, pos
= 0, i
= 0;
92 struct ast_dial
*dials
[MAX_DIALS
];
94 if (ast_strlen_zero(data
)) {
95 ast_log(LOG_WARNING
, "This application requires at least one argument (destination(s) to page)\n");
99 u
= ast_module_user_add(chan
);
101 if (!(app
= pbx_findapp("MeetMe"))) {
102 ast_log(LOG_WARNING
, "There is no MeetMe application available!\n");
103 ast_module_user_remove(u
);
107 options
= ast_strdupa(data
);
109 ast_copy_string(originator
, chan
->name
, sizeof(originator
));
110 if ((tmp
= strchr(originator
, '-')))
113 tmp
= strsep(&options
, "|");
115 ast_app_parse_options(page_opts
, &flags
, NULL
, options
);
117 snprintf(meetmeopts
, sizeof(meetmeopts
), "MeetMe|%ud|%s%sqxdw(5)", confid
, (ast_test_flag(&flags
, PAGE_DUPLEX
) ? "" : "m"),
118 (ast_test_flag(&flags
, PAGE_RECORD
) ? "r" : "") );
120 /* Go through parsing/calling each device */
121 while ((tech
= strsep(&tmp
, "&"))) {
122 struct ast_dial
*dial
= NULL
;
124 /* don't call the originating device */
125 if (!strcasecmp(tech
, originator
))
128 /* If no resource is available, continue on */
129 if (!(resource
= strchr(tech
, '/'))) {
130 ast_log(LOG_WARNING
, "Incomplete destination '%s' supplied.\n", tech
);
136 /* Create a dialing structure */
137 if (!(dial
= ast_dial_create())) {
138 ast_log(LOG_WARNING
, "Failed to create dialing structure.\n");
142 /* Append technology and resource */
143 ast_dial_append(dial
, tech
, resource
);
145 /* Set ANSWER_EXEC as global option */
146 ast_dial_option_global_enable(dial
, AST_DIAL_OPTION_ANSWER_EXEC
, meetmeopts
);
148 /* Run this dial in async mode */
149 ast_dial_run(dial
, chan
, 1);
151 /* Put in our dialing array */
155 if (!ast_test_flag(&flags
, PAGE_QUIET
)) {
156 res
= ast_streamfile(chan
, "beep", chan
->language
);
158 res
= ast_waitstream(chan
, "");
162 snprintf(meetmeopts
, sizeof(meetmeopts
), "%ud|A%s%sqxd", confid
, (ast_test_flag(&flags
, PAGE_DUPLEX
) ? "" : "t"),
163 (ast_test_flag(&flags
, PAGE_RECORD
) ? "r" : "") );
164 pbx_exec(chan
, app
, meetmeopts
);
167 /* Go through each dial attempt cancelling, joining, and destroying */
168 for (i
= 0; i
< pos
; i
++) {
169 struct ast_dial
*dial
= dials
[i
];
171 /* We have to wait for the async thread to exit as it's possible Meetme won't throw them out immediately */
174 /* Hangup all channels */
175 ast_dial_hangup(dial
);
177 /* Destroy dialing structure */
178 ast_dial_destroy(dial
);
181 ast_module_user_remove(u
);
186 static int unload_module(void)
190 res
= ast_unregister_application(app_page
);
192 ast_module_user_hangup_all();
197 static int load_module(void)
199 return ast_register_application(app_page
, page_exec
, page_synopsis
, page_descrip
);
202 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY
, "Page Multiple Phones");