| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 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" |
| 42 |
#include "asterisk/devicestate.h" |
| 43 |
#include "asterisk/dial.h" |
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
static const char * const app_page= "Page"; |
| 134 |
|
| 135 |
enum page_opt_flags { |
| 136 |
PAGE_DUPLEX = (1 << 0), |
| 137 |
PAGE_QUIET = (1 << 1), |
| 138 |
PAGE_RECORD = (1 << 2), |
| 139 |
PAGE_SKIP = (1 << 3), |
| 140 |
PAGE_IGNORE_FORWARDS = (1 << 4), |
| 141 |
PAGE_ANNOUNCE = (1 << 5), |
| 142 |
PAGE_NOCALLERANNOUNCE = (1 << 6), |
| 143 |
PAGE_PREDIAL_CALLEE = (1 << 7), |
| 144 |
PAGE_PREDIAL_CALLER = (1 << 8), |
| 145 |
}; |
| 146 |
|
| 147 |
enum { |
| 148 |
OPT_ARG_ANNOUNCE = 0, |
| 149 |
OPT_ARG_PREDIAL_CALLEE = 1, |
| 150 |
OPT_ARG_PREDIAL_CALLER = 2, |
| 151 |
OPT_ARG_ARRAY_SIZE = 3, |
| 152 |
}; |
| 153 |
|
| 154 |
AST_APP_OPTIONS(page_opts, { |
| 155 |
AST_APP_OPTION_ARG('b', PAGE_PREDIAL_CALLEE, OPT_ARG_PREDIAL_CALLEE), |
| 156 |
AST_APP_OPTION_ARG('B', PAGE_PREDIAL_CALLER, OPT_ARG_PREDIAL_CALLER), |
| 157 |
AST_APP_OPTION('d', PAGE_DUPLEX), |
| 158 |
AST_APP_OPTION('q', PAGE_QUIET), |
| 159 |
AST_APP_OPTION('r', PAGE_RECORD), |
| 160 |
AST_APP_OPTION('s', PAGE_SKIP), |
| 161 |
AST_APP_OPTION('i', PAGE_IGNORE_FORWARDS), |
| 162 |
AST_APP_OPTION_ARG('A', PAGE_ANNOUNCE, OPT_ARG_ANNOUNCE), |
| 163 |
AST_APP_OPTION('n', PAGE_NOCALLERANNOUNCE), |
| 164 |
}); |
| 165 |
|
| 166 |
#define PAGE_BEEP "beep" |
| 167 |
|
| 168 |
|
| 169 |
struct page_options { |
| 170 |
char *opts[OPT_ARG_ARRAY_SIZE]; |
| 171 |
struct ast_flags flags; |
| 172 |
}; |
| 173 |
|
| 174 |
|
| 175 |
|
| 176 |
|
| 177 |
|
| 178 |
|
| 179 |
|
| 180 |
|
| 181 |
static void setup_profile_bridge(struct ast_channel *chan, struct page_options *options) |
| 182 |
{ |
| 183 |
|
| 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 |
|
| 192 |
|
| 193 |
|
| 194 |
|
| 195 |
|
| 196 |
|
| 197 |
static void setup_profile_paged(struct ast_channel *chan, struct page_options *options) |
| 198 |
{ |
| 199 |
|
| 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 |
} |
| 206 |
if (ast_test_flag(&options->flags, PAGE_ANNOUNCE) |
| 207 |
&& !ast_strlen_zero(options->opts[OPT_ARG_ANNOUNCE])) { |
| 208 |
ast_func_write(chan, "CONFBRIDGE(user,announcement)", options->opts[OPT_ARG_ANNOUNCE]); |
| 209 |
} |
| 210 |
} |
| 211 |
|
| 212 |
|
| 213 |
|
| 214 |
|
| 215 |
|
| 216 |
|
| 217 |
|
| 218 |
|
| 219 |
static void setup_profile_caller(struct ast_channel *chan, struct page_options *options) |
| 220 |
{ |
| 221 |
|
| 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"); |
| 225 |
if (!ast_test_flag(&options->flags, PAGE_NOCALLERANNOUNCE) |
| 226 |
&& ast_test_flag(&options->flags, PAGE_ANNOUNCE) |
| 227 |
&& !ast_strlen_zero(options->opts[OPT_ARG_ANNOUNCE])) { |
| 228 |
ast_func_write(chan, "CONFBRIDGE(user,announcement)", options->opts[OPT_ARG_ANNOUNCE]); |
| 229 |
} |
| 230 |
} |
| 231 |
|
| 232 |
static void page_state_callback(struct ast_dial *dial) |
| 233 |
{ |
| 234 |
struct ast_channel *chan; |
| 235 |
struct page_options *options; |
| 236 |
|
| 237 |
if (ast_dial_state(dial) != AST_DIAL_RESULT_ANSWERED || |
| 238 |
!(chan = ast_dial_answered(dial)) || |
| 239 |
!(options = ast_dial_get_user_data(dial))) { |
| 240 |
return; |
| 241 |
} |
| 242 |
|
| 243 |
setup_profile_bridge(chan, options); |
| 244 |
setup_profile_paged(chan, options); |
| 245 |
} |
| 246 |
|
| 247 |
static 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 |
|
| 266 |
AST_DECLARE_APP_ARGS(args, |
| 267 |
AST_APP_ARG(devices); |
| 268 |
AST_APP_ARG(options); |
| 269 |
AST_APP_ARG(timeout); |
| 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 |
|
| 279 |
AST_STANDARD_APP_ARGS(args, parse); |
| 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 |
|
| 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 |
|
| 312 |
if (ast_test_flag(&options.flags, PAGE_PREDIAL_CALLEE) |
| 313 |
&& !ast_strlen_zero(options.opts[OPT_ARG_PREDIAL_CALLEE])) { |
| 314 |
ast_replace_subargument_delimiter(options.opts[OPT_ARG_PREDIAL_CALLEE]); |
| 315 |
predial_callee = |
| 316 |
(char *) ast_app_expand_sub_args(chan, options.opts[OPT_ARG_PREDIAL_CALLEE]); |
| 317 |
} |
| 318 |
|
| 319 |
|
| 320 |
if (ast_test_flag(&options.flags, PAGE_PREDIAL_CALLER) |
| 321 |
&& !ast_strlen_zero(options.opts[OPT_ARG_PREDIAL_CALLER])) { |
| 322 |
ast_replace_subargument_delimiter(options.opts[OPT_ARG_PREDIAL_CALLER]); |
| 323 |
ast_app_exec_sub(NULL, chan, options.opts[OPT_ARG_PREDIAL_CALLER], 0); |
| 324 |
} |
| 325 |
|
| 326 |
|
| 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 |
|
| 334 |
continue; |
| 335 |
} |
| 336 |
|
| 337 |
|
| 338 |
if (!strcasecmp(tech, originator)) { |
| 339 |
continue; |
| 340 |
} |
| 341 |
|
| 342 |
|
| 343 |
if (!(resource = strchr(tech, '/'))) { |
| 344 |
ast_log(LOG_WARNING, "Incomplete destination: '%s' supplied.\n", tech); |
| 345 |
continue; |
| 346 |
} |
| 347 |
|
| 348 |
|
| 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 |
|
| 364 |
if (!(dial = ast_dial_create())) { |
| 365 |
ast_log(LOG_WARNING, "Failed to create dialing structure.\n"); |
| 366 |
continue; |
| 367 |
} |
| 368 |
|
| 369 |
|
| 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 |
|
| 377 |
ast_dial_option_global_enable(dial, AST_DIAL_OPTION_ANSWER_EXEC, confbridgeopts); |
| 378 |
|
| 379 |
if (predial_callee) { |
| 380 |
ast_dial_option_global_enable(dial, AST_DIAL_OPTION_PREDIAL, predial_callee); |
| 381 |
} |
| 382 |
|
| 383 |
if (timeout) { |
| 384 |
ast_dial_set_global_timeout(dial, timeout * 1000); |
| 385 |
} |
| 386 |
|
| 387 |
if (ast_test_flag(&options.flags, PAGE_IGNORE_FORWARDS)) { |
| 388 |
ast_dial_option_global_enable(dial, AST_DIAL_OPTION_DISABLE_CALL_FORWARDING, NULL); |
| 389 |
} |
| 390 |
|
| 391 |
ast_dial_set_state_callback(dial, &page_state_callback); |
| 392 |
ast_dial_set_user_data(dial, &options); |
| 393 |
|
| 394 |
|
| 395 |
ast_dial_run(dial, chan, 1); |
| 396 |
|
| 397 |
|
| 398 |
dial_list[pos++] = dial; |
| 399 |
} |
| 400 |
|
| 401 |
ast_free(predial_callee); |
| 402 |
|
| 403 |
if (!ast_test_flag(&options.flags, PAGE_QUIET)) { |
| 404 |
if (!ast_fileexists(PAGE_BEEP, NULL, NULL)) { |
| 405 |
ast_log(LOG_WARNING, "Missing required sound file: '" PAGE_BEEP "'\n"); |
| 406 |
} else { |
| 407 |
res = ast_streamfile(chan, PAGE_BEEP, ast_channel_language(chan)); |
| 408 |
if (!res) { |
| 409 |
res = ast_waitstream(chan, ""); |
| 410 |
} |
| 411 |
} |
| 412 |
} |
| 413 |
|
| 414 |
if (!res) { |
| 415 |
setup_profile_bridge(chan, &options); |
| 416 |
setup_profile_caller(chan, &options); |
| 417 |
|
| 418 |
snprintf(confbridgeopts, sizeof(confbridgeopts), "%u", confid); |
| 419 |
pbx_exec(chan, app, confbridgeopts); |
| 420 |
} |
| 421 |
|
| 422 |
|
| 423 |
for (i = 0; i < pos; i++) { |
| 424 |
struct ast_dial *dial = dial_list[i]; |
| 425 |
|
| 426 |
|
| 427 |
ast_dial_join(dial); |
| 428 |
|
| 429 |
|
| 430 |
ast_dial_hangup(dial); |
| 431 |
|
| 432 |
|
| 433 |
ast_dial_destroy(dial); |
| 434 |
} |
| 435 |
|
| 436 |
ast_free(dial_list); |
| 437 |
|
| 438 |
return -1; |
| 439 |
} |
| 440 |
|
| 441 |
static int unload_module(void) |
| 442 |
{ |
| 443 |
return ast_unregister_application(app_page); |
| 444 |
} |
| 445 |
|
| 446 |
static int load_module(void) |
| 447 |
{ |
| 448 |
return ast_register_application_xml(app_page, page_exec); |
| 449 |
} |
| 450 |
|
| 451 |
AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_DEFAULT, "Page Multiple Phones", |
| 452 |
.support_level = AST_MODULE_SUPPORT_CORE, |
| 453 |
.load = load_module, |
| 454 |
.unload = unload_module, |
| 455 |
.requires = "app_confbridge", |
| 456 |
); |