00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034 #include "asterisk.h"
00035
00036 ASTERISK_FILE_VERSION(__FILE__, "$Revision: 382513 $")
00037
00038 #include "asterisk/channel.h"
00039 #include "asterisk/pbx.h"
00040 #include "asterisk/module.h"
00041 #include "asterisk/file.h"
00042 #include "asterisk/app.h"
00043 #include "asterisk/chanvars.h"
00044 #include "asterisk/utils.h"
00045 #include "asterisk/devicestate.h"
00046 #include "asterisk/dial.h"
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112 static const char * const app_page= "Page";
00113
00114 enum page_opt_flags {
00115 PAGE_DUPLEX = (1 << 0),
00116 PAGE_QUIET = (1 << 1),
00117 PAGE_RECORD = (1 << 2),
00118 PAGE_SKIP = (1 << 3),
00119 PAGE_IGNORE_FORWARDS = (1 << 4),
00120 PAGE_ANNOUNCE = (1 << 5),
00121 PAGE_NOCALLERANNOUNCE = (1 << 6),
00122 };
00123
00124 enum {
00125 OPT_ARG_ANNOUNCE = 0,
00126 OPT_ARG_ARRAY_SIZE = 1,
00127 };
00128
00129 AST_APP_OPTIONS(page_opts, {
00130 AST_APP_OPTION('d', PAGE_DUPLEX),
00131 AST_APP_OPTION('q', PAGE_QUIET),
00132 AST_APP_OPTION('r', PAGE_RECORD),
00133 AST_APP_OPTION('s', PAGE_SKIP),
00134 AST_APP_OPTION('i', PAGE_IGNORE_FORWARDS),
00135 AST_APP_OPTION_ARG('A', PAGE_ANNOUNCE, OPT_ARG_ANNOUNCE),
00136 AST_APP_OPTION('n', PAGE_NOCALLERANNOUNCE),
00137 });
00138
00139
00140 static int page_exec(struct ast_channel *chan, const char *data)
00141 {
00142 char *tech, *resource, *tmp;
00143 char meetmeopts[128], originator[AST_CHANNEL_NAME], *opts[OPT_ARG_ARRAY_SIZE];
00144 struct ast_flags flags = { 0 };
00145 unsigned int confid = ast_random();
00146 struct ast_app *app;
00147 int res = 0, pos = 0, i = 0;
00148 struct ast_dial **dial_list;
00149 unsigned int num_dials;
00150 int timeout = 0;
00151 char *parse;
00152
00153 AST_DECLARE_APP_ARGS(args,
00154 AST_APP_ARG(devices);
00155 AST_APP_ARG(options);
00156 AST_APP_ARG(timeout);
00157 );
00158
00159 if (ast_strlen_zero(data)) {
00160 ast_log(LOG_WARNING, "This application requires at least one argument (destination(s) to page)\n");
00161 return -1;
00162 }
00163
00164 if (!(app = pbx_findapp("MeetMe"))) {
00165 ast_log(LOG_WARNING, "There is no MeetMe application available!\n");
00166 return -1;
00167 };
00168
00169 parse = ast_strdupa(data);
00170
00171 AST_STANDARD_APP_ARGS(args, parse);
00172
00173 ast_copy_string(originator, chan->name, sizeof(originator));
00174 if ((tmp = strchr(originator, '-'))) {
00175 *tmp = '\0';
00176 }
00177
00178 if (!ast_strlen_zero(args.options)) {
00179 ast_app_parse_options(page_opts, &flags, opts, args.options);
00180 } else {
00181
00182 for (i = 0; i < OPT_ARG_ARRAY_SIZE; i++) {
00183 opts[i] = NULL;
00184 }
00185 }
00186
00187 if (!ast_strlen_zero(args.timeout)) {
00188 timeout = atoi(args.timeout);
00189 }
00190
00191 if (ast_test_flag(&flags, PAGE_ANNOUNCE) && !ast_strlen_zero(opts[OPT_ARG_ANNOUNCE])) {
00192 snprintf(meetmeopts, sizeof(meetmeopts), "MeetMe,%ud,%s%sqxdw(5)G(%s)", confid, (ast_test_flag(&flags, PAGE_DUPLEX) ? "" : "m"),
00193 (ast_test_flag(&flags, PAGE_RECORD) ? "r" : ""), opts[OPT_ARG_ANNOUNCE] );
00194 } else {
00195 snprintf(meetmeopts, sizeof(meetmeopts), "MeetMe,%ud,%s%sqxdw(5)", confid, (ast_test_flag(&flags, PAGE_DUPLEX) ? "" : "m"),
00196 (ast_test_flag(&flags, PAGE_RECORD) ? "r" : "") );
00197 }
00198
00199
00200 num_dials = 1;
00201 tmp = args.devices;
00202 while (*tmp) {
00203 if (*tmp == '&') {
00204 num_dials++;
00205 }
00206 tmp++;
00207 }
00208
00209 if (!(dial_list = ast_calloc(num_dials, sizeof(struct ast_dial *)))) {
00210 ast_log(LOG_ERROR, "Can't allocate %ld bytes for dial list\n", (long)(sizeof(struct ast_dial *) * num_dials));
00211 return -1;
00212 }
00213
00214
00215 while ((tech = strsep(&args.devices, "&"))) {
00216 int state = 0;
00217 struct ast_dial *dial = NULL;
00218
00219
00220 if (!strcasecmp(tech, originator))
00221 continue;
00222
00223
00224 if (!(resource = strchr(tech, '/'))) {
00225 ast_log(LOG_WARNING, "Incomplete destination '%s' supplied.\n", tech);
00226 continue;
00227 }
00228
00229
00230 if (ast_test_flag(&flags, PAGE_SKIP)) {
00231 state = ast_device_state(tech);
00232 if (state == AST_DEVICE_UNKNOWN) {
00233 ast_log(LOG_WARNING, "Destination '%s' has device state '%s'. Paging anyway.\n", tech, ast_devstate2str(state));
00234 } else if (state != AST_DEVICE_NOT_INUSE) {
00235 ast_log(LOG_WARNING, "Destination '%s' has device state '%s'.\n", tech, ast_devstate2str(state));
00236 continue;
00237 }
00238 }
00239
00240 *resource++ = '\0';
00241
00242
00243 if (!(dial = ast_dial_create())) {
00244 ast_log(LOG_WARNING, "Failed to create dialing structure.\n");
00245 continue;
00246 }
00247
00248
00249 if (ast_dial_append(dial, tech, resource) == -1) {
00250 ast_log(LOG_ERROR, "Failed to add %s to outbound dial\n", tech);
00251 ast_dial_destroy(dial);
00252 continue;
00253 }
00254
00255
00256 ast_dial_option_global_enable(dial, AST_DIAL_OPTION_ANSWER_EXEC, meetmeopts);
00257
00258 if (timeout) {
00259 ast_dial_set_global_timeout(dial, timeout * 1000);
00260 }
00261
00262 if (ast_test_flag(&flags, PAGE_IGNORE_FORWARDS)) {
00263 ast_dial_option_global_enable(dial, AST_DIAL_OPTION_DISABLE_CALL_FORWARDING, NULL);
00264 }
00265
00266
00267 ast_dial_run(dial, chan, 1);
00268
00269
00270 dial_list[pos++] = dial;
00271 }
00272
00273 if (!ast_test_flag(&flags, PAGE_QUIET)) {
00274 res = ast_streamfile(chan, "beep", chan->language);
00275 if (!res)
00276 res = ast_waitstream(chan, "");
00277 }
00278
00279 if (!res) {
00280
00281 snprintf(meetmeopts, sizeof(meetmeopts), "%ud,A%s%sqxd", confid, (ast_test_flag(&flags, PAGE_DUPLEX) ? "" : "t"),
00282 (ast_test_flag(&flags, PAGE_RECORD) ? "r" : "") );
00283 if (ast_test_flag(&flags, PAGE_ANNOUNCE) && !ast_strlen_zero(opts[OPT_ARG_ANNOUNCE]) &&
00284 !ast_test_flag(&flags, PAGE_NOCALLERANNOUNCE)) {
00285 snprintf(meetmeopts, sizeof(meetmeopts), "%ud,A%s%sqxdG(%s)", confid, (ast_test_flag(&flags, PAGE_DUPLEX) ? "" : "t"),
00286 (ast_test_flag(&flags, PAGE_RECORD) ? "r" : ""), opts[OPT_ARG_ANNOUNCE] );
00287 }
00288 pbx_exec(chan, app, meetmeopts);
00289 }
00290
00291
00292 for (i = 0; i < pos; i++) {
00293 struct ast_dial *dial = dial_list[i];
00294
00295
00296 ast_dial_join(dial);
00297
00298
00299 ast_dial_hangup(dial);
00300
00301
00302 ast_dial_destroy(dial);
00303 }
00304
00305 ast_free(dial_list);
00306
00307 return -1;
00308 }
00309
00310 static int unload_module(void)
00311 {
00312 return ast_unregister_application(app_page);
00313 }
00314
00315 static int load_module(void)
00316 {
00317 return ast_register_application_xml(app_page, page_exec);
00318 }
00319
00320 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Page Multiple Phones");
00321