| 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 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
#include "asterisk.h" |
| 41 |
|
| 42 |
#include "asterisk/_private.h" |
| 43 |
#include "features_config.h" |
| 44 |
|
| 45 |
#include <pthread.h> |
| 46 |
#include <signal.h> |
| 47 |
#include <sys/time.h> |
| 48 |
#include <signal.h> |
| 49 |
#include <netinet/in.h> |
| 50 |
|
| 51 |
#include "asterisk/lock.h" |
| 52 |
#include "asterisk/file.h" |
| 53 |
#include "asterisk/channel.h" |
| 54 |
#include "asterisk/pbx.h" |
| 55 |
#include "asterisk/causes.h" |
| 56 |
#include "asterisk/module.h" |
| 57 |
#include "asterisk/translate.h" |
| 58 |
#include "asterisk/app.h" |
| 59 |
#include "asterisk/say.h" |
| 60 |
#include "asterisk/features.h" |
| 61 |
#include "asterisk/musiconhold.h" |
| 62 |
#include "asterisk/config.h" |
| 63 |
#include "asterisk/cli.h" |
| 64 |
#include "asterisk/manager.h" |
| 65 |
#include "asterisk/utils.h" |
| 66 |
#include "asterisk/devicestate.h" |
| 67 |
#include "asterisk/audiohook.h" |
| 68 |
#include "asterisk/global_datastores.h" |
| 69 |
#include "asterisk/astobj2.h" |
| 70 |
#include "asterisk/test.h" |
| 71 |
#include "asterisk/bridge.h" |
| 72 |
#include "asterisk/bridge_features.h" |
| 73 |
#include "asterisk/bridge_basic.h" |
| 74 |
#include "asterisk/bridge_after.h" |
| 75 |
#include "asterisk/stasis.h" |
| 76 |
#include "asterisk/stasis_channels.h" |
| 77 |
#include "asterisk/features_config.h" |
| 78 |
#include "asterisk/max_forwards.h" |
| 79 |
#include "asterisk/stream.h" |
| 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 |
|
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
|
| 142 |
|
| 143 |
|
| 144 |
|
| 145 |
|
| 146 |
|
| 147 |
|
| 148 |
|
| 149 |
|
| 150 |
|
| 151 |
|
| 152 |
|
| 153 |
|
| 154 |
|
| 155 |
|
| 156 |
|
| 157 |
|
| 158 |
|
| 159 |
|
| 160 |
|
| 161 |
|
| 162 |
|
| 163 |
|
| 164 |
|
| 165 |
|
| 166 |
|
| 167 |
|
| 168 |
|
| 169 |
|
| 170 |
|
| 171 |
|
| 172 |
|
| 173 |
|
| 174 |
|
| 175 |
|
| 176 |
|
| 177 |
|
| 178 |
|
| 179 |
|
| 180 |
|
| 181 |
|
| 182 |
|
| 183 |
|
| 184 |
|
| 185 |
|
| 186 |
|
| 187 |
|
| 188 |
|
| 189 |
|
| 190 |
|
| 191 |
|
| 192 |
|
| 193 |
|
| 194 |
|
| 195 |
|
| 196 |
|
| 197 |
|
| 198 |
|
| 199 |
|
| 200 |
|
| 201 |
|
| 202 |
|
| 203 |
|
| 204 |
|
| 205 |
|
| 206 |
|
| 207 |
|
| 208 |
|
| 209 |
|
| 210 |
|
| 211 |
|
| 212 |
|
| 213 |
|
| 214 |
|
| 215 |
|
| 216 |
|
| 217 |
|
| 218 |
|
| 219 |
|
| 220 |
|
| 221 |
|
| 222 |
|
| 223 |
|
| 224 |
|
| 225 |
|
| 226 |
|
| 227 |
|
| 228 |
|
| 229 |
|
| 230 |
|
| 231 |
|
| 232 |
|
| 233 |
|
| 234 |
|
| 235 |
|
| 236 |
|
| 237 |
|
| 238 |
|
| 239 |
|
| 240 |
|
| 241 |
|
| 242 |
|
| 243 |
|
| 244 |
|
| 245 |
|
| 246 |
|
| 247 |
|
| 248 |
|
| 249 |
|
| 250 |
|
| 251 |
|
| 252 |
|
| 253 |
|
| 254 |
|
| 255 |
|
| 256 |
|
| 257 |
|
| 258 |
|
| 259 |
|
| 260 |
|
| 261 |
|
| 262 |
|
| 263 |
|
| 264 |
typedef enum { |
| 265 |
FEATURE_INTERPRET_DETECT, |
| 266 |
FEATURE_INTERPRET_DO, |
| 267 |
FEATURE_INTERPRET_CHECK, |
| 268 |
} feature_interpret_op; |
| 269 |
|
| 270 |
struct ast_dial_features { |
| 271 |
|
| 272 |
struct ast_flags my_features; |
| 273 |
|
| 274 |
struct ast_flags peer_features; |
| 275 |
}; |
| 276 |
|
| 277 |
static void *dial_features_duplicate(void *data) |
| 278 |
{ |
| 279 |
struct ast_dial_features *df = data, *df_copy; |
| 280 |
|
| 281 |
if (!(df_copy = ast_calloc(1, sizeof(*df)))) { |
| 282 |
return NULL; |
| 283 |
} |
| 284 |
|
| 285 |
memcpy(df_copy, df, sizeof(*df)); |
| 286 |
|
| 287 |
return df_copy; |
| 288 |
} |
| 289 |
|
| 290 |
static const struct ast_datastore_info dial_features_info = { |
| 291 |
.type = "dial-features", |
| 292 |
.destroy = ast_free_ptr, |
| 293 |
.duplicate = dial_features_duplicate, |
| 294 |
}; |
| 295 |
|
| 296 |
|
| 297 |
|
| 298 |
|
| 299 |
|
| 300 |
|
| 301 |
|
| 302 |
|
| 303 |
|
| 304 |
|
| 305 |
|
| 306 |
static int add_features_datastore(struct ast_channel *chan, const struct ast_flags *my_features, const struct ast_flags *peer_features) |
| 307 |
{ |
| 308 |
struct ast_datastore *datastore; |
| 309 |
struct ast_dial_features *dialfeatures; |
| 310 |
|
| 311 |
ast_channel_lock(chan); |
| 312 |
datastore = ast_channel_datastore_find(chan, &dial_features_info, NULL); |
| 313 |
ast_channel_unlock(chan); |
| 314 |
if (datastore) { |
| 315 |
|
| 316 |
return 1; |
| 317 |
} |
| 318 |
|
| 319 |
|
| 320 |
datastore = ast_datastore_alloc(&dial_features_info, NULL); |
| 321 |
if (!datastore) { |
| 322 |
ast_log(LOG_WARNING, "Unable to create channel features datastore.\n"); |
| 323 |
return 0; |
| 324 |
} |
| 325 |
dialfeatures = ast_calloc(1, sizeof(*dialfeatures)); |
| 326 |
if (!dialfeatures) { |
| 327 |
ast_log(LOG_WARNING, "Unable to allocate memory for feature flags.\n"); |
| 328 |
ast_datastore_free(datastore); |
| 329 |
return 0; |
| 330 |
} |
| 331 |
ast_copy_flags(&dialfeatures->my_features, my_features, AST_FLAGS_ALL); |
| 332 |
ast_copy_flags(&dialfeatures->peer_features, peer_features, AST_FLAGS_ALL); |
| 333 |
datastore->inheritance = DATASTORE_INHERIT_FOREVER; |
| 334 |
datastore->data = dialfeatures; |
| 335 |
ast_channel_lock(chan); |
| 336 |
ast_channel_datastore_add(chan, datastore); |
| 337 |
ast_channel_unlock(chan); |
| 338 |
return 0; |
| 339 |
} |
| 340 |
|
| 341 |
struct ast_bridge_thread_obj |
| 342 |
{ |
| 343 |
struct ast_bridge_config bconfig; |
| 344 |
struct ast_channel *chan; |
| 345 |
struct ast_channel *peer; |
| 346 |
unsigned int return_to_pbx:1; |
| 347 |
}; |
| 348 |
|
| 349 |
static void set_config_flags(struct ast_channel *chan, struct ast_bridge_config *config) |
| 350 |
{ |
| 351 |
ast_clear_flag(config, AST_FLAGS_ALL); |
| 352 |
|
| 353 |
if (ast_test_flag(&config->features_caller, AST_FEATURE_DTMF_MASK)) { |
| 354 |
ast_set_flag(config, AST_BRIDGE_DTMF_CHANNEL_0); |
| 355 |
} |
| 356 |
if (ast_test_flag(&config->features_callee, AST_FEATURE_DTMF_MASK)) { |
| 357 |
ast_set_flag(config, AST_BRIDGE_DTMF_CHANNEL_1); |
| 358 |
} |
| 359 |
|
| 360 |
if (!(ast_test_flag(config, AST_BRIDGE_DTMF_CHANNEL_0) && ast_test_flag(config, AST_BRIDGE_DTMF_CHANNEL_1))) { |
| 361 |
RAII_VAR(struct ao2_container *, applicationmap, NULL, ao2_cleanup); |
| 362 |
|
| 363 |
ast_channel_lock(chan); |
| 364 |
applicationmap = ast_get_chan_applicationmap(chan); |
| 365 |
ast_channel_unlock(chan); |
| 366 |
|
| 367 |
if (!applicationmap) { |
| 368 |
return; |
| 369 |
} |
| 370 |
|
| 371 |
|
| 372 |
ast_set_flag(config, AST_BRIDGE_DTMF_CHANNEL_0); |
| 373 |
} |
| 374 |
} |
| 375 |
|
| 376 |
void ast_channel_log(char *title, struct ast_channel *chan); |
| 377 |
|
| 378 |
void ast_channel_log(char *title, struct ast_channel *chan) |
| 379 |
{ |
| 380 |
ast_log(LOG_NOTICE, "______ %s (%lx)______\n", title, (unsigned long) chan); |
| 381 |
ast_log(LOG_NOTICE, "CHAN: name: %s; appl: %s; data: %s; contxt: %s; exten: %s; pri: %d;\n", |
| 382 |
ast_channel_name(chan), ast_channel_appl(chan), ast_channel_data(chan), |
| 383 |
ast_channel_context(chan), ast_channel_exten(chan), ast_channel_priority(chan)); |
| 384 |
ast_log(LOG_NOTICE, "CHAN: acctcode: %s; dialcontext: %s; amaflags: %x;\n", |
| 385 |
ast_channel_accountcode(chan), ast_channel_dialcontext(chan), ast_channel_amaflags(chan)); |
| 386 |
ast_log(LOG_NOTICE, "CHAN: masq: %p; masqr: %p; uniqueID: %s; linkedID:%s\n", |
| 387 |
ast_channel_masq(chan), ast_channel_masqr(chan), |
| 388 |
ast_channel_uniqueid(chan), ast_channel_linkedid(chan)); |
| 389 |
if (ast_channel_masqr(chan)) { |
| 390 |
ast_log(LOG_NOTICE, "CHAN: masquerading as: %s; cdr: %p;\n", |
| 391 |
ast_channel_name(ast_channel_masqr(chan)), ast_channel_cdr(ast_channel_masqr(chan))); |
| 392 |
} |
| 393 |
|
| 394 |
ast_log(LOG_NOTICE, "===== done ====\n"); |
| 395 |
} |
| 396 |
|
| 397 |
static void set_bridge_features_on_config(struct ast_bridge_config *config, const char *features) |
| 398 |
{ |
| 399 |
const char *feature; |
| 400 |
|
| 401 |
if (ast_strlen_zero(features)) { |
| 402 |
return; |
| 403 |
} |
| 404 |
|
| 405 |
for (feature = features; *feature; feature++) { |
| 406 |
struct ast_flags *party; |
| 407 |
|
| 408 |
if (isupper(*feature)) { |
| 409 |
party = &config->features_caller; |
| 410 |
} else { |
| 411 |
party = &config->features_callee; |
| 412 |
} |
| 413 |
|
| 414 |
switch (tolower(*feature)) { |
| 415 |
case 't' : |
| 416 |
ast_set_flag(party, AST_FEATURE_REDIRECT); |
| 417 |
break; |
| 418 |
case 'k' : |
| 419 |
ast_set_flag(party, AST_FEATURE_PARKCALL); |
| 420 |
break; |
| 421 |
case 'h' : |
| 422 |
ast_set_flag(party, AST_FEATURE_DISCONNECT); |
| 423 |
break; |
| 424 |
case 'w' : |
| 425 |
ast_set_flag(party, AST_FEATURE_AUTOMON); |
| 426 |
break; |
| 427 |
case 'x' : |
| 428 |
ast_set_flag(party, AST_FEATURE_AUTOMIXMON); |
| 429 |
break; |
| 430 |
default : |
| 431 |
ast_log(LOG_WARNING, "Skipping unknown feature code '%c'\n", *feature); |
| 432 |
break; |
| 433 |
} |
| 434 |
} |
| 435 |
} |
| 436 |
|
| 437 |
static void add_features_datastores(struct ast_channel *caller, struct ast_channel *callee, struct ast_bridge_config *config) |
| 438 |
{ |
| 439 |
if (add_features_datastore(caller, &config->features_caller, &config->features_callee)) { |
| 440 |
|
| 441 |
|
| 442 |
|
| 443 |
|
| 444 |
|
| 445 |
return; |
| 446 |
} |
| 447 |
|
| 448 |
add_features_datastore(callee, &config->features_callee, &config->features_caller); |
| 449 |
} |
| 450 |
|
| 451 |
static void bridge_config_set_limits_warning_values(struct ast_bridge_config *config, struct ast_bridge_features_limits *limits) |
| 452 |
{ |
| 453 |
if (config->end_sound) { |
| 454 |
ast_string_field_set(limits, duration_sound, config->end_sound); |
| 455 |
} |
| 456 |
|
| 457 |
if (config->warning_sound) { |
| 458 |
ast_string_field_set(limits, warning_sound, config->warning_sound); |
| 459 |
} |
| 460 |
|
| 461 |
if (config->start_sound) { |
| 462 |
ast_string_field_set(limits, connect_sound, config->start_sound); |
| 463 |
} |
| 464 |
|
| 465 |
limits->frequency = config->warning_freq; |
| 466 |
limits->warning = config->play_warning; |
| 467 |
} |
| 468 |
|
| 469 |
|
| 470 |
|
| 471 |
|
| 472 |
|
| 473 |
|
| 474 |
|
| 475 |
|
| 476 |
static void bridge_config_set_limits(struct ast_bridge_config *config, struct ast_bridge_features_limits *caller_limits, struct ast_bridge_features_limits *callee_limits) |
| 477 |
{ |
| 478 |
if (ast_test_flag(&config->features_caller, AST_FEATURE_PLAY_WARNING)) { |
| 479 |
bridge_config_set_limits_warning_values(config, caller_limits); |
| 480 |
} |
| 481 |
|
| 482 |
if (ast_test_flag(&config->features_callee, AST_FEATURE_PLAY_WARNING)) { |
| 483 |
bridge_config_set_limits_warning_values(config, callee_limits); |
| 484 |
} |
| 485 |
|
| 486 |
caller_limits->duration = config->timelimit; |
| 487 |
callee_limits->duration = config->timelimit; |
| 488 |
} |
| 489 |
|
| 490 |
|
| 491 |
|
| 492 |
|
| 493 |
|
| 494 |
|
| 495 |
|
| 496 |
|
| 497 |
|
| 498 |
static void bridge_failed_peer_goto(struct ast_channel *chan, struct ast_channel *peer) |
| 499 |
{ |
| 500 |
if (ast_bridge_setup_after_goto(peer) |
| 501 |
|| ast_pbx_start(peer)) { |
| 502 |
ast_autoservice_chan_hangup_peer(chan, peer); |
| 503 |
} |
| 504 |
} |
| 505 |
|
| 506 |
static int pre_bridge_setup(struct ast_channel *chan, struct ast_channel *peer, struct ast_bridge_config *config, |
| 507 |
struct ast_bridge_features *chan_features, struct ast_bridge_features *peer_features, int noanswer) |
| 508 |
{ |
| 509 |
int res; |
| 510 |
SCOPE_TRACE(1, "%s Peer: %s\n", ast_channel_name(chan), ast_channel_name(peer)); |
| 511 |
|
| 512 |
set_bridge_features_on_config(config, pbx_builtin_getvar_helper(chan, "BRIDGE_FEATURES")); |
| 513 |
add_features_datastores(chan, peer, config); |
| 514 |
|
| 515 |
|
| 516 |
|
| 517 |
|
| 518 |
|
| 519 |
|
| 520 |
|
| 521 |
|
| 522 |
if (ast_channel_state(chan) == AST_STATE_RINGING |
| 523 |
&& ast_channel_visible_indication(peer) != AST_CONTROL_RINGING) { |
| 524 |
ast_indicate(peer, AST_CONTROL_RINGING); |
| 525 |
} |
| 526 |
|
| 527 |
set_config_flags(chan, config); |
| 528 |
|
| 529 |
|
| 530 |
|
| 531 |
res = 0; |
| 532 |
|
| 533 |
if (noanswer) { |
| 534 |
ast_debug(1, "Skipping answer on %s due to no answer directive\n", ast_channel_name(chan)); |
| 535 |
} else if (ast_channel_state(chan) != AST_STATE_UP) { |
| 536 |
ast_debug(1, "Answering channel for bridge: %s\n", ast_channel_name(chan)); |
| 537 |
res = ast_raw_answer_with_stream_topology(chan, config->answer_topology); |
| 538 |
if (res != 0) { |
| 539 |
return -1; |
| 540 |
} |
| 541 |
} |
| 542 |
|
| 543 |
|
| 544 |
#ifdef FOR_DEBUG |
| 545 |
|
| 546 |
ast_channel_log("Pre-bridge CHAN Channel info", chan); |
| 547 |
ast_channel_log("Pre-bridge PEER Channel info", peer); |
| 548 |
#endif |
| 549 |
|
| 550 |
res = 0; |
| 551 |
ast_channel_lock(chan); |
| 552 |
ast_max_forwards_reset(chan); |
| 553 |
res |= ast_bridge_features_ds_append(chan, &config->features_caller); |
| 554 |
ast_channel_unlock(chan); |
| 555 |
ast_channel_lock(peer); |
| 556 |
ast_max_forwards_reset(peer); |
| 557 |
res |= ast_bridge_features_ds_append(peer, &config->features_callee); |
| 558 |
ast_channel_unlock(peer); |
| 559 |
|
| 560 |
if (res) { |
| 561 |
return -1; |
| 562 |
} |
| 563 |
|
| 564 |
if (config->timelimit) { |
| 565 |
struct ast_bridge_features_limits call_duration_limits_chan; |
| 566 |
struct ast_bridge_features_limits call_duration_limits_peer; |
| 567 |
int abandon_call = 0; |
| 568 |
|
| 569 |
if (ast_bridge_features_limits_construct(&call_duration_limits_chan)) { |
| 570 |
ast_log(LOG_ERROR, "Could not construct caller duration limits. Bridge canceled.\n"); |
| 571 |
|
| 572 |
return -1; |
| 573 |
} |
| 574 |
|
| 575 |
if (ast_bridge_features_limits_construct(&call_duration_limits_peer)) { |
| 576 |
ast_log(LOG_ERROR, "Could not construct callee duration limits. Bridge canceled.\n"); |
| 577 |
ast_bridge_features_limits_destroy(&call_duration_limits_chan); |
| 578 |
|
| 579 |
return -1; |
| 580 |
} |
| 581 |
|
| 582 |
bridge_config_set_limits(config, &call_duration_limits_chan, &call_duration_limits_peer); |
| 583 |
|
| 584 |
if (ast_bridge_features_set_limits(chan_features, &call_duration_limits_chan, 0)) { |
| 585 |
abandon_call = 1; |
| 586 |
} |
| 587 |
if (ast_bridge_features_set_limits(peer_features, &call_duration_limits_peer, 0)) { |
| 588 |
abandon_call = 1; |
| 589 |
} |
| 590 |
|
| 591 |
|
| 592 |
ast_bridge_features_limits_destroy(&call_duration_limits_chan); |
| 593 |
ast_bridge_features_limits_destroy(&call_duration_limits_peer); |
| 594 |
|
| 595 |
if (abandon_call) { |
| 596 |
ast_log(LOG_ERROR, "Could not set duration limits on one or more sides of the call. Bridge canceled.\n"); |
| 597 |
return -1; |
| 598 |
} |
| 599 |
} |
| 600 |
|
| 601 |
return 0; |
| 602 |
} |
| 603 |
|
| 604 |
int ast_bridge_call_with_flags(struct ast_channel *chan, struct ast_channel *peer, struct ast_bridge_config *config, unsigned int flags) |
| 605 |
{ |
| 606 |
int res; |
| 607 |
struct ast_bridge *bridge; |
| 608 |
struct ast_bridge_features chan_features; |
| 609 |
struct ast_bridge_features *peer_features; |
| 610 |
const char *value; |
| 611 |
int noanswer; |
| 612 |
SCOPE_TRACE(1, "%s Peer: %s\n", ast_channel_name(chan), ast_channel_name(peer)); |
| 613 |
|
| 614 |
|
| 615 |
res = ast_bridge_features_init(&chan_features); |
| 616 |
peer_features = ast_bridge_features_new(); |
| 617 |
if (res || !peer_features) { |
| 618 |
ast_bridge_features_destroy(peer_features); |
| 619 |
ast_bridge_features_cleanup(&chan_features); |
| 620 |
bridge_failed_peer_goto(chan, peer); |
| 621 |
return -1; |
| 622 |
} |
| 623 |
|
| 624 |
ast_channel_lock(chan); |
| 625 |
value = pbx_builtin_getvar_helper(chan, "BRIDGE_NOANSWER"); |
| 626 |
noanswer = !ast_strlen_zero(value) ? 1 : 0; |
| 627 |
ast_channel_unlock(chan); |
| 628 |
|
| 629 |
if (pre_bridge_setup(chan, peer, config, &chan_features, peer_features, noanswer)) { |
| 630 |
ast_bridge_features_destroy(peer_features); |
| 631 |
ast_bridge_features_cleanup(&chan_features); |
| 632 |
bridge_failed_peer_goto(chan, peer); |
| 633 |
return -1; |
| 634 |
} |
| 635 |
|
| 636 |
|
| 637 |
bridge = ast_bridge_basic_new(); |
| 638 |
if (!bridge) { |
| 639 |
ast_bridge_features_destroy(peer_features); |
| 640 |
ast_bridge_features_cleanup(&chan_features); |
| 641 |
bridge_failed_peer_goto(chan, peer); |
| 642 |
return -1; |
| 643 |
} |
| 644 |
|
| 645 |
ast_bridge_basic_set_flags(bridge, flags); |
| 646 |
|
| 647 |
|
| 648 |
if (ast_bridge_impart(bridge, peer, NULL, peer_features, |
| 649 |
AST_BRIDGE_IMPART_CHAN_INDEPENDENT | AST_BRIDGE_IMPART_INHIBIT_JOIN_COLP)) { |
| 650 |
ast_bridge_destroy(bridge, 0); |
| 651 |
ast_bridge_features_cleanup(&chan_features); |
| 652 |
bridge_failed_peer_goto(chan, peer); |
| 653 |
return -1; |
| 654 |
} |
| 655 |
|
| 656 |
|
| 657 |
ast_bridge_join(bridge, chan, NULL, &chan_features, NULL, |
| 658 |
AST_BRIDGE_JOIN_PASS_REFERENCE | AST_BRIDGE_JOIN_INHIBIT_JOIN_COLP); |
| 659 |
|
| 660 |
|
| 661 |
|
| 662 |
|
| 663 |
|
| 664 |
|
| 665 |
|
| 666 |
res = -1; |
| 667 |
ast_channel_lock(chan); |
| 668 |
if (ast_channel_softhangup_internal_flag(chan) & AST_SOFTHANGUP_ASYNCGOTO) { |
| 669 |
res = 0; |
| 670 |
} |
| 671 |
ast_channel_unlock(chan); |
| 672 |
|
| 673 |
ast_bridge_features_cleanup(&chan_features); |
| 674 |
|
| 675 |
if (res && config->end_bridge_callback) { |
| 676 |
config->end_bridge_callback(config->end_bridge_callback_data); |
| 677 |
} |
| 678 |
|
| 679 |
return res; |
| 680 |
} |
| 681 |
|
| 682 |
|
| 683 |
|
| 684 |
|
| 685 |
|
| 686 |
|
| 687 |
|
| 688 |
|
| 689 |
|
| 690 |
|
| 691 |
|
| 692 |
|
| 693 |
|
| 694 |
int ast_bridge_call(struct ast_channel *chan, struct ast_channel *peer, struct ast_bridge_config *config) |
| 695 |
{ |
| 696 |
return ast_bridge_call_with_flags(chan, peer, config, 0); |
| 697 |
} |
| 698 |
|
| 699 |
enum play_tone_action { |
| 700 |
PLAYTONE_NONE = 0, |
| 701 |
PLAYTONE_CHANNEL1 = (1 << 0), |
| 702 |
PLAYTONE_CHANNEL2 = (1 << 1), |
| 703 |
PLAYTONE_BOTH = PLAYTONE_CHANNEL1 | PLAYTONE_CHANNEL2, |
| 704 |
}; |
| 705 |
|
| 706 |
static enum play_tone_action parse_playtone(const char *playtone_val) |
| 707 |
{ |
| 708 |
if (ast_strlen_zero(playtone_val) || ast_false(playtone_val)) { |
| 709 |
return PLAYTONE_NONE; |
| 710 |
} if (!strcasecmp(playtone_val, "channel1")) { |
| 711 |
return PLAYTONE_CHANNEL1; |
| 712 |
} else if (!strcasecmp(playtone_val, "channel2") || ast_true(playtone_val)) { |
| 713 |
return PLAYTONE_CHANNEL2; |
| 714 |
} else if (!strcasecmp(playtone_val, "both")) { |
| 715 |
return PLAYTONE_BOTH; |
| 716 |
} else { |
| 717 |
|
| 718 |
return PLAYTONE_NONE; |
| 719 |
} |
| 720 |
} |
| 721 |
|
| 722 |
|
| 723 |
|
| 724 |
|
| 725 |
|
| 726 |
|
| 727 |
|
| 728 |
|
| 729 |
|
| 730 |
|
| 731 |
|
| 732 |
|
| 733 |
|
| 734 |
|
| 735 |
static int action_bridge(struct mansession *s, const struct message *m) |
| 736 |
{ |
| 737 |
const char *channela = astman_get_header(m, "Channel1"); |
| 738 |
const char *channelb = astman_get_header(m, "Channel2"); |
| 739 |
enum play_tone_action playtone = parse_playtone(astman_get_header(m, "Tone")); |
| 740 |
RAII_VAR(struct ast_channel *, chana, NULL, ao2_cleanup); |
| 741 |
RAII_VAR(struct ast_channel *, chanb, NULL, ao2_cleanup); |
| 742 |
const char *chana_exten; |
| 743 |
const char *chana_context; |
| 744 |
int chana_priority; |
| 745 |
const char *chanb_exten; |
| 746 |
const char *chanb_context; |
| 747 |
int chanb_priority; |
| 748 |
struct ast_bridge *bridge; |
| 749 |
char buf[256]; |
| 750 |
RAII_VAR(struct ast_features_xfer_config *, xfer_cfg_a, NULL, ao2_cleanup); |
| 751 |
RAII_VAR(struct ast_features_xfer_config *, xfer_cfg_b, NULL, ao2_cleanup); |
| 752 |
|
| 753 |
|
| 754 |
if (ast_strlen_zero(channela) || ast_strlen_zero(channelb)) { |
| 755 |
astman_send_error(s, m, "Missing channel parameter in request"); |
| 756 |
return 0; |
| 757 |
} |
| 758 |
|
| 759 |
ast_debug(1, "Performing Bridge action on %s and %s\n", channela, channelb); |
| 760 |
|
| 761 |
|
| 762 |
chana = ast_channel_get_by_name_prefix(channela, strlen(channela)); |
| 763 |
if (!chana) { |
| 764 |
snprintf(buf, sizeof(buf), "Channel1 does not exist: %s", channela); |
| 765 |
astman_send_error(s, m, buf); |
| 766 |
return 0; |
| 767 |
} |
| 768 |
ast_channel_lock(chana); |
| 769 |
xfer_cfg_a = ast_get_chan_features_xfer_config(chana); |
| 770 |
chana_exten = ast_strdupa(ast_channel_exten(chana)); |
| 771 |
chana_context = ast_strdupa(ast_channel_context(chana)); |
| 772 |
chana_priority = ast_channel_priority(chana); |
| 773 |
if (ast_test_flag(ast_channel_flags(chana), AST_FLAG_IN_AUTOLOOP)) { |
| 774 |
chana_priority++; |
| 775 |
} |
| 776 |
ast_channel_unlock(chana); |
| 777 |
|
| 778 |
chanb = ast_channel_get_by_name_prefix(channelb, strlen(channelb)); |
| 779 |
if (!chanb) { |
| 780 |
snprintf(buf, sizeof(buf), "Channel2 does not exist: %s", channelb); |
| 781 |
astman_send_error(s, m, buf); |
| 782 |
return 0; |
| 783 |
} |
| 784 |
ast_channel_lock(chanb); |
| 785 |
xfer_cfg_b = ast_get_chan_features_xfer_config(chanb); |
| 786 |
chanb_exten = ast_strdupa(ast_channel_exten(chanb)); |
| 787 |
chanb_context = ast_strdupa(ast_channel_context(chanb)); |
| 788 |
chanb_priority = ast_channel_priority(chanb); |
| 789 |
if (ast_test_flag(ast_channel_flags(chanb), AST_FLAG_IN_AUTOLOOP)) { |
| 790 |
chanb_priority++; |
| 791 |
} |
| 792 |
ast_channel_unlock(chanb); |
| 793 |
|
| 794 |
bridge = ast_bridge_basic_new(); |
| 795 |
if (!bridge) { |
| 796 |
astman_send_error(s, m, "Unable to create bridge\n"); |
| 797 |
return 0; |
| 798 |
} |
| 799 |
|
| 800 |
ast_bridge_set_after_goto(chana, chana_context, chana_exten, chana_priority); |
| 801 |
if (ast_bridge_add_channel(bridge, chana, NULL, playtone & PLAYTONE_CHANNEL1, xfer_cfg_a ? xfer_cfg_a->xfersound : NULL)) { |
| 802 |
snprintf(buf, sizeof(buf), "Unable to add Channel1 to bridge: %s", ast_channel_name(chana)); |
| 803 |
astman_send_error(s, m, buf); |
| 804 |
ast_bridge_destroy(bridge, 0); |
| 805 |
return 0; |
| 806 |
} |
| 807 |
|
| 808 |
ast_bridge_set_after_goto(chanb, chanb_context, chanb_exten, chanb_priority); |
| 809 |
if (ast_bridge_add_channel(bridge, chanb, NULL, playtone & PLAYTONE_CHANNEL2, xfer_cfg_b ? xfer_cfg_b->xfersound : NULL)) { |
| 810 |
snprintf(buf, sizeof(buf), "Unable to add Channel2 to bridge: %s", ast_channel_name(chanb)); |
| 811 |
astman_send_error(s, m, buf); |
| 812 |
ast_bridge_destroy(bridge, 0); |
| 813 |
return 0; |
| 814 |
} |
| 815 |
|
| 816 |
astman_send_ack(s, m, "Channels have been bridged"); |
| 817 |
ao2_cleanup(bridge); |
| 818 |
|
| 819 |
return 0; |
| 820 |
} |
| 821 |
|
| 822 |
static char *app_bridge = "Bridge"; |
| 823 |
|
| 824 |
enum { |
| 825 |
BRIDGE_OPT_PLAYTONE = (1 << 0), |
| 826 |
OPT_CALLEE_HANGUP = (1 << 1), |
| 827 |
OPT_CALLER_HANGUP = (1 << 2), |
| 828 |
OPT_DURATION_LIMIT = (1 << 3), |
| 829 |
OPT_DURATION_STOP = (1 << 4), |
| 830 |
OPT_CALLEE_TRANSFER = (1 << 5), |
| 831 |
OPT_CALLER_TRANSFER = (1 << 6), |
| 832 |
OPT_CALLEE_MONITOR = (1 << 7), |
| 833 |
OPT_CALLER_MONITOR = (1 << 8), |
| 834 |
OPT_CALLEE_PARK = (1 << 9), |
| 835 |
OPT_CALLER_PARK = (1 << 10), |
| 836 |
OPT_CALLEE_KILL = (1 << 11), |
| 837 |
OPT_CALLEE_GO_ON = (1 << 12), |
| 838 |
OPT_NOANSWER = (1 << 13), |
| 839 |
}; |
| 840 |
|
| 841 |
enum { |
| 842 |
OPT_ARG_DURATION_LIMIT = 0, |
| 843 |
OPT_ARG_DURATION_STOP, |
| 844 |
OPT_ARG_CALLEE_GO_ON, |
| 845 |
|
| 846 |
OPT_ARG_ARRAY_SIZE, |
| 847 |
}; |
| 848 |
|
| 849 |
AST_APP_OPTIONS(bridge_exec_options, BEGIN_OPTIONS |
| 850 |
AST_APP_OPTION('p', BRIDGE_OPT_PLAYTONE), |
| 851 |
AST_APP_OPTION_ARG('F', OPT_CALLEE_GO_ON, OPT_ARG_CALLEE_GO_ON), |
| 852 |
AST_APP_OPTION('h', OPT_CALLEE_HANGUP), |
| 853 |
AST_APP_OPTION('H', OPT_CALLER_HANGUP), |
| 854 |
AST_APP_OPTION('k', OPT_CALLEE_PARK), |
| 855 |
AST_APP_OPTION('K', OPT_CALLER_PARK), |
| 856 |
AST_APP_OPTION_ARG('L', OPT_DURATION_LIMIT, OPT_ARG_DURATION_LIMIT), |
| 857 |
AST_APP_OPTION('n', OPT_NOANSWER), |
| 858 |
AST_APP_OPTION_ARG('S', OPT_DURATION_STOP, OPT_ARG_DURATION_STOP), |
| 859 |
AST_APP_OPTION('t', OPT_CALLEE_TRANSFER), |
| 860 |
AST_APP_OPTION('T', OPT_CALLER_TRANSFER), |
| 861 |
AST_APP_OPTION('w', OPT_CALLEE_MONITOR), |
| 862 |
AST_APP_OPTION('W', OPT_CALLER_MONITOR), |
| 863 |
AST_APP_OPTION('x', OPT_CALLEE_KILL), |
| 864 |
END_OPTIONS ); |
| 865 |
|
| 866 |
int ast_bridge_timelimit(struct ast_channel *chan, struct ast_bridge_config *config, |
| 867 |
char *parse, struct timeval *calldurationlimit) |
| 868 |
{ |
| 869 |
char *stringp = ast_strdupa(parse); |
| 870 |
char *limit_str, *warning_str, *warnfreq_str; |
| 871 |
const char *var; |
| 872 |
int play_to_caller = 0, play_to_callee = 0; |
| 873 |
int delta; |
| 874 |
|
| 875 |
limit_str = strsep(&stringp, ":"); |
| 876 |
warning_str = strsep(&stringp, ":"); |
| 877 |
warnfreq_str = strsep(&stringp, ":"); |
| 878 |
|
| 879 |
config->timelimit = atol(limit_str); |
| 880 |
if (warning_str) |
| 881 |
config->play_warning = atol(warning_str); |
| 882 |
if (warnfreq_str) |
| 883 |
config->warning_freq = atol(warnfreq_str); |
| 884 |
|
| 885 |
if (!config->timelimit) { |
| 886 |
ast_log(LOG_WARNING, "Bridge does not accept L(%s)\n", limit_str); |
| 887 |
config->timelimit = config->play_warning = config->warning_freq = 0; |
| 888 |
config->warning_sound = NULL; |
| 889 |
return -1; |
| 890 |
} else if ( (delta = config->play_warning - config->timelimit) > 0) { |
| 891 |
int w = config->warning_freq; |
| 892 |
|
| 893 |
|
| 894 |
|
| 895 |
|
| 896 |
|
| 897 |
|
| 898 |
|
| 899 |
|
| 900 |
|
| 901 |
|
| 902 |
|
| 903 |
|
| 904 |
|
| 905 |
|
| 906 |
|
| 907 |
if (w == 0) { |
| 908 |
config->play_warning = 0; |
| 909 |
} else { |
| 910 |
config->play_warning -= w * ( 1 + (delta-1)/w ); |
| 911 |
if (config->play_warning < 1) |
| 912 |
config->play_warning = config->warning_freq = 0; |
| 913 |
} |
| 914 |
} |
| 915 |
|
| 916 |
ast_channel_lock(chan); |
| 917 |
|
| 918 |
var = pbx_builtin_getvar_helper(chan, "LIMIT_PLAYAUDIO_CALLER"); |
| 919 |
play_to_caller = var ? ast_true(var) : 1; |
| 920 |
|
| 921 |
var = pbx_builtin_getvar_helper(chan, "LIMIT_PLAYAUDIO_CALLEE"); |
| 922 |
play_to_callee = var ? ast_true(var) : 0; |
| 923 |
|
| 924 |
if (!play_to_caller && !play_to_callee) |
| 925 |
play_to_caller = 1; |
| 926 |
|
| 927 |
var = pbx_builtin_getvar_helper(chan, "LIMIT_WARNING_FILE"); |
| 928 |
config->warning_sound = !ast_strlen_zero(var) ? ast_strdup(var) : ast_strdup("timeleft"); |
| 929 |
|
| 930 |
|
| 931 |
|
| 932 |
|
| 933 |
|
| 934 |
|
| 935 |
|
| 936 |
var = pbx_builtin_getvar_helper(chan, "LIMIT_TIMEOUT_FILE"); |
| 937 |
config->end_sound = !ast_strlen_zero(var) ? ast_strdup(var) : NULL; |
| 938 |
|
| 939 |
var = pbx_builtin_getvar_helper(chan, "LIMIT_CONNECT_FILE"); |
| 940 |
config->start_sound = !ast_strlen_zero(var) ? ast_strdup(var) : NULL; |
| 941 |
|
| 942 |
ast_channel_unlock(chan); |
| 943 |
|
| 944 |
|
| 945 |
calldurationlimit->tv_sec = 0; |
| 946 |
calldurationlimit->tv_usec = 0; |
| 947 |
|
| 948 |
|
| 949 |
if (!config->play_warning && !config->start_sound && !config->end_sound && config->timelimit) { |
| 950 |
calldurationlimit->tv_sec = config->timelimit / 1000; |
| 951 |
calldurationlimit->tv_usec = (config->timelimit % 1000) * 1000; |
| 952 |
ast_verb(3, "Setting call duration limit to %.3lf seconds.\n", |
| 953 |
calldurationlimit->tv_sec + calldurationlimit->tv_usec / 1000000.0); |
| 954 |
play_to_caller = 0; |
| 955 |
play_to_callee = 0; |
| 956 |
config->timelimit = 0; |
| 957 |
config->play_warning = 0; |
| 958 |
config->warning_freq = 0; |
| 959 |
} else { |
| 960 |
ast_verb(4, "Limit Data for this call:\n"); |
| 961 |
ast_verb(4, "timelimit = %ld ms (%.3lf s)\n", config->timelimit, config->timelimit / 1000.0); |
| 962 |
ast_verb(4, "play_warning = %ld ms (%.3lf s)\n", config->play_warning, config->play_warning / 1000.0); |
| 963 |
ast_verb(4, "play_to_caller = %s\n", play_to_caller ? "yes" : "no"); |
| 964 |
ast_verb(4, "play_to_callee = %s\n", play_to_callee ? "yes" : "no"); |
| 965 |
ast_verb(4, "warning_freq = %ld ms (%.3lf s)\n", config->warning_freq, config->warning_freq / 1000.0); |
| 966 |
ast_verb(4, "start_sound = %s\n", S_OR(config->start_sound, "")); |
| 967 |
ast_verb(4, "warning_sound = %s\n", config->warning_sound); |
| 968 |
ast_verb(4, "end_sound = %s\n", S_OR(config->end_sound, "")); |
| 969 |
} |
| 970 |
if (play_to_caller) |
| 971 |
ast_set_flag(&(config->features_caller), AST_FEATURE_PLAY_WARNING); |
| 972 |
if (play_to_callee) |
| 973 |
ast_set_flag(&(config->features_callee), AST_FEATURE_PLAY_WARNING); |
| 974 |
return 0; |
| 975 |
} |
| 976 |
|
| 977 |
|
| 978 |
|
| 979 |
|
| 980 |
|
| 981 |
|
| 982 |
|
| 983 |
|
| 984 |
|
| 985 |
|
| 986 |
|
| 987 |
static int bridge_exec(struct ast_channel *chan, const char *data) |
| 988 |
{ |
| 989 |
struct ast_channel *current_dest_chan = NULL; |
| 990 |
char *tmp_data = NULL; |
| 991 |
struct ast_flags opts = { 0, }; |
| 992 |
struct ast_bridge_config bconfig = { { 0, }, }; |
| 993 |
char *opt_args[OPT_ARG_ARRAY_SIZE]; |
| 994 |
struct timeval calldurationlimit = { 0, }; |
| 995 |
const char *context; |
| 996 |
const char *extension; |
| 997 |
int priority; |
| 998 |
int bridge_add_failed; |
| 999 |
int res = -1; |
| 1000 |
struct ast_bridge_features chan_features; |
| 1001 |
struct ast_bridge_features *peer_features; |
| 1002 |
struct ast_bridge *bridge; |
| 1003 |
struct ast_features_xfer_config *xfer_cfg; |
| 1004 |
int noanswer; |
| 1005 |
|
| 1006 |
AST_DECLARE_APP_ARGS(args, |
| 1007 |
AST_APP_ARG(dest_chan); |
| 1008 |
AST_APP_ARG(options); |
| 1009 |
); |
| 1010 |
|
| 1011 |
tmp_data = ast_strdupa(data ?: ""); |
| 1012 |
AST_STANDARD_APP_ARGS(args, tmp_data); |
| 1013 |
if (!ast_strlen_zero(args.options)) { |
| 1014 |
ast_app_parse_options(bridge_exec_options, &opts, opt_args, args.options); |
| 1015 |
} |
| 1016 |
|
| 1017 |
|
| 1018 |
if (!ast_strlen_zero(args.dest_chan)) { |
| 1019 |
current_dest_chan = ast_channel_get_by_name_prefix(args.dest_chan, |
| 1020 |
strlen(args.dest_chan)); |
| 1021 |
} |
| 1022 |
if (!current_dest_chan) { |
| 1023 |
ast_verb(4, "Bridge failed because channel '%s' does not exist\n", |
| 1024 |
args.dest_chan ?: ""); |
| 1025 |
pbx_builtin_setvar_helper(chan, "BRIDGERESULT", "NONEXISTENT"); |
| 1026 |
return 0; |
| 1027 |
} |
| 1028 |
|
| 1029 |
|
| 1030 |
if (chan == current_dest_chan) { |
| 1031 |
ast_channel_unref(current_dest_chan); |
| 1032 |
ast_log(LOG_WARNING, "Unable to bridge channel %s with itself\n", ast_channel_name(chan)); |
| 1033 |
pbx_builtin_setvar_helper(chan, "BRIDGERESULT", "LOOP"); |
| 1034 |
return 0; |
| 1035 |
} |
| 1036 |
|
| 1037 |
if (ast_test_flag(&opts, OPT_DURATION_LIMIT) |
| 1038 |
&& !ast_strlen_zero(opt_args[OPT_ARG_DURATION_LIMIT]) |
| 1039 |
&& ast_bridge_timelimit(chan, &bconfig, opt_args[OPT_ARG_DURATION_LIMIT], &calldurationlimit)) { |
| 1040 |
goto done; |
| 1041 |
} |
| 1042 |
|
| 1043 |
if (ast_test_flag(&opts, OPT_CALLEE_TRANSFER)) |
| 1044 |
ast_set_flag(&(bconfig.features_callee), AST_FEATURE_REDIRECT); |
| 1045 |
if (ast_test_flag(&opts, OPT_CALLER_TRANSFER)) |
| 1046 |
ast_set_flag(&(bconfig.features_caller), AST_FEATURE_REDIRECT); |
| 1047 |
if (ast_test_flag(&opts, OPT_CALLEE_HANGUP)) |
| 1048 |
ast_set_flag(&(bconfig.features_callee), AST_FEATURE_DISCONNECT); |
| 1049 |
if (ast_test_flag(&opts, OPT_CALLER_HANGUP)) |
| 1050 |
ast_set_flag(&(bconfig.features_caller), AST_FEATURE_DISCONNECT); |
| 1051 |
if (ast_test_flag(&opts, OPT_CALLEE_MONITOR)) |
| 1052 |
ast_set_flag(&(bconfig.features_callee), AST_FEATURE_AUTOMON); |
| 1053 |
if (ast_test_flag(&opts, OPT_CALLER_MONITOR)) |
| 1054 |
ast_set_flag(&(bconfig.features_caller), AST_FEATURE_AUTOMON); |
| 1055 |
if (ast_test_flag(&opts, OPT_CALLEE_PARK)) |
| 1056 |
ast_set_flag(&(bconfig.features_callee), AST_FEATURE_PARKCALL); |
| 1057 |
if (ast_test_flag(&opts, OPT_CALLER_PARK)) |
| 1058 |
ast_set_flag(&(bconfig.features_caller), AST_FEATURE_PARKCALL); |
| 1059 |
noanswer = ast_test_flag(&opts, OPT_NOANSWER); |
| 1060 |
|
| 1061 |
|
| 1062 |
if (ast_test_flag(&opts, OPT_CALLEE_GO_ON)) { |
| 1063 |
ast_channel_lock(chan); |
| 1064 |
context = ast_strdupa(ast_channel_context(chan)); |
| 1065 |
extension = ast_strdupa(ast_channel_exten(chan)); |
| 1066 |
priority = ast_channel_priority(chan); |
| 1067 |
ast_channel_unlock(chan); |
| 1068 |
ast_bridge_set_after_go_on(current_dest_chan, context, extension, priority, |
| 1069 |
opt_args[OPT_ARG_CALLEE_GO_ON]); |
| 1070 |
} else if (!ast_test_flag(&opts, OPT_CALLEE_KILL)) { |
| 1071 |
ast_channel_lock(current_dest_chan); |
| 1072 |
context = ast_strdupa(ast_channel_context(current_dest_chan)); |
| 1073 |
extension = ast_strdupa(ast_channel_exten(current_dest_chan)); |
| 1074 |
priority = ast_channel_priority(current_dest_chan); |
| 1075 |
ast_channel_unlock(current_dest_chan); |
| 1076 |
ast_bridge_set_after_go_on(current_dest_chan, context, extension, priority, NULL); |
| 1077 |
} |
| 1078 |
|
| 1079 |
if (ast_bridge_features_init(&chan_features)) { |
| 1080 |
ast_bridge_features_cleanup(&chan_features); |
| 1081 |
goto done; |
| 1082 |
} |
| 1083 |
|
| 1084 |
peer_features = ast_bridge_features_new(); |
| 1085 |
if (!peer_features) { |
| 1086 |
ast_bridge_features_cleanup(&chan_features); |
| 1087 |
goto done; |
| 1088 |
} |
| 1089 |
|
| 1090 |
if (pre_bridge_setup(chan, current_dest_chan, &bconfig, &chan_features, peer_features, noanswer)) { |
| 1091 |
ast_bridge_features_destroy(peer_features); |
| 1092 |
ast_bridge_features_cleanup(&chan_features); |
| 1093 |
goto done; |
| 1094 |
} |
| 1095 |
|
| 1096 |
bridge = ast_bridge_basic_new(); |
| 1097 |
if (!bridge) { |
| 1098 |
ast_bridge_features_destroy(peer_features); |
| 1099 |
ast_bridge_features_cleanup(&chan_features); |
| 1100 |
goto done; |
| 1101 |
} |
| 1102 |
|
| 1103 |
ast_channel_lock(current_dest_chan); |
| 1104 |
xfer_cfg = ast_get_chan_features_xfer_config(current_dest_chan); |
| 1105 |
ast_channel_unlock(current_dest_chan); |
| 1106 |
bridge_add_failed = ast_bridge_add_channel(bridge, current_dest_chan, peer_features, |
| 1107 |
ast_test_flag(&opts, BRIDGE_OPT_PLAYTONE), |
| 1108 |
xfer_cfg ? xfer_cfg->xfersound : NULL); |
| 1109 |
ao2_cleanup(xfer_cfg); |
| 1110 |
if (bridge_add_failed) { |
| 1111 |
ast_bridge_features_cleanup(&chan_features); |
| 1112 |
ast_bridge_destroy(bridge, 0); |
| 1113 |
goto done; |
| 1114 |
} |
| 1115 |
|
| 1116 |
|
| 1117 |
current_dest_chan = ast_channel_unref(current_dest_chan); |
| 1118 |
|
| 1119 |
res = ast_bridge_join(bridge, chan, NULL, &chan_features, NULL, |
| 1120 |
AST_BRIDGE_JOIN_PASS_REFERENCE); |
| 1121 |
|
| 1122 |
ast_bridge_features_cleanup(&chan_features); |
| 1123 |
|
| 1124 |
done: |
| 1125 |
if (res == -1) { |
| 1126 |
pbx_builtin_setvar_helper(chan, "BRIDGERESULT", "FAILURE"); |
| 1127 |
} else { |
| 1128 |
pbx_builtin_setvar_helper(chan, "BRIDGERESULT", "SUCCESS"); |
| 1129 |
} |
| 1130 |
|
| 1131 |
ast_free((char *) bconfig.warning_sound); |
| 1132 |
ast_free((char *) bconfig.end_sound); |
| 1133 |
ast_free((char *) bconfig.start_sound); |
| 1134 |
|
| 1135 |
ast_channel_cleanup(current_dest_chan); |
| 1136 |
return 0; |
| 1137 |
} |
| 1138 |
|
| 1139 |
static int unload_module(void) |
| 1140 |
{ |
| 1141 |
unload_features_config(); |
| 1142 |
|
| 1143 |
ast_manager_unregister("Bridge"); |
| 1144 |
|
| 1145 |
ast_unregister_application(app_bridge); |
| 1146 |
|
| 1147 |
return 0; |
| 1148 |
} |
| 1149 |
|
| 1150 |
static int load_module(void) |
| 1151 |
{ |
| 1152 |
int res; |
| 1153 |
|
| 1154 |
res = load_features_config(); |
| 1155 |
res |= ast_register_application2(app_bridge, bridge_exec, NULL, NULL, NULL); |
| 1156 |
res |= ast_manager_register_xml_core("Bridge", EVENT_FLAG_CALL, action_bridge); |
| 1157 |
|
| 1158 |
return res ? AST_MODULE_LOAD_FAILURE : AST_MODULE_LOAD_SUCCESS; |
| 1159 |
} |
| 1160 |
|
| 1161 |
AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_GLOBAL_SYMBOLS | AST_MODFLAG_LOAD_ORDER, "Call Features", |
| 1162 |
.support_level = AST_MODULE_SUPPORT_CORE, |
| 1163 |
.load = load_module, |
| 1164 |
.unload = unload_module, |
| 1165 |
.reload = reload_features_config, |
| 1166 |
.load_pri = AST_MODPRI_CORE, |
| 1167 |
.requires = "extconfig", |
| 1168 |
); |