| 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 |
#include "asterisk.h" |
| 27 |
|
| 28 |
#include "asterisk/stasis_bridges.h" |
| 29 |
#include "asterisk/stasis_channels.h" |
| 30 |
#include "asterisk/manager.h" |
| 31 |
#include "asterisk/stasis_message_router.h" |
| 32 |
|
| 33 |
|
| 34 |
static struct stasis_message_router *bridge_state_router; |
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 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 |
|
| 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 |
static struct stasis_forward *topic_forwarder; |
| 256 |
|
| 257 |
struct ast_str *ast_manager_build_bridge_state_string_prefix( |
| 258 |
const struct ast_bridge_snapshot *snapshot, |
| 259 |
const char *prefix) |
| 260 |
{ |
| 261 |
struct ast_str *out = ast_str_create(128); |
| 262 |
int res; |
| 263 |
|
| 264 |
if (!out) { |
| 265 |
return NULL; |
| 266 |
} |
| 267 |
|
| 268 |
res = ast_str_set(&out, 0, |
| 269 |
"%sBridgeUniqueid: %s\r\n" |
| 270 |
"%sBridgeType: %s\r\n" |
| 271 |
"%sBridgeTechnology: %s\r\n" |
| 272 |
"%sBridgeCreator: %s\r\n" |
| 273 |
"%sBridgeName: %s\r\n" |
| 274 |
"%sBridgeNumChannels: %u\r\n" |
| 275 |
"%sBridgeVideoSourceMode: %s\r\n", |
| 276 |
prefix, snapshot->uniqueid, |
| 277 |
prefix, snapshot->subclass, |
| 278 |
prefix, snapshot->technology, |
| 279 |
prefix, ast_strlen_zero(snapshot->creator) ? "<unknown>": snapshot->creator, |
| 280 |
prefix, ast_strlen_zero(snapshot->name) ? "<unknown>": snapshot->name, |
| 281 |
prefix, snapshot->num_channels, |
| 282 |
prefix, ast_bridge_video_mode_to_string(snapshot->video_mode)); |
| 283 |
if (!res) { |
| 284 |
ast_free(out); |
| 285 |
return NULL; |
| 286 |
} |
| 287 |
|
| 288 |
if (snapshot->video_mode != AST_BRIDGE_VIDEO_MODE_NONE |
| 289 |
&& !ast_strlen_zero(snapshot->video_source_id)) { |
| 290 |
res = ast_str_append(&out, 0, "%sBridgeVideoSource: %s\r\n", |
| 291 |
prefix, snapshot->video_source_id); |
| 292 |
if (!res) { |
| 293 |
ast_free(out); |
| 294 |
return NULL; |
| 295 |
} |
| 296 |
} |
| 297 |
|
| 298 |
return out; |
| 299 |
} |
| 300 |
|
| 301 |
struct ast_str *ast_manager_build_bridge_state_string( |
| 302 |
const struct ast_bridge_snapshot *snapshot) |
| 303 |
{ |
| 304 |
return ast_manager_build_bridge_state_string_prefix(snapshot, ""); |
| 305 |
} |
| 306 |
|
| 307 |
|
| 308 |
typedef struct ast_manager_event_blob *(*bridge_snapshot_monitor)( |
| 309 |
struct ast_bridge_snapshot *old_snapshot, |
| 310 |
struct ast_bridge_snapshot *new_snapshot); |
| 311 |
|
| 312 |
|
| 313 |
static struct ast_manager_event_blob *bridge_create( |
| 314 |
struct ast_bridge_snapshot *old_snapshot, |
| 315 |
struct ast_bridge_snapshot *new_snapshot) |
| 316 |
{ |
| 317 |
if (!new_snapshot || old_snapshot) { |
| 318 |
return NULL; |
| 319 |
} |
| 320 |
|
| 321 |
return ast_manager_event_blob_create( |
| 322 |
EVENT_FLAG_CALL, "BridgeCreate", NO_EXTRA_FIELDS); |
| 323 |
} |
| 324 |
|
| 325 |
|
| 326 |
static struct ast_manager_event_blob *bridge_video_update( |
| 327 |
struct ast_bridge_snapshot *old_snapshot, |
| 328 |
struct ast_bridge_snapshot *new_snapshot) |
| 329 |
{ |
| 330 |
if (!new_snapshot || !old_snapshot) { |
| 331 |
return NULL; |
| 332 |
} |
| 333 |
|
| 334 |
if (!strcmp(old_snapshot->video_source_id, new_snapshot->video_source_id)) { |
| 335 |
return NULL; |
| 336 |
} |
| 337 |
|
| 338 |
return ast_manager_event_blob_create( |
| 339 |
EVENT_FLAG_CALL, "BridgeVideoSourceUpdate", |
| 340 |
"BridgePreviousVideoSource: %s\r\n", |
| 341 |
old_snapshot->video_source_id); |
| 342 |
} |
| 343 |
|
| 344 |
|
| 345 |
static struct ast_manager_event_blob *bridge_destroy( |
| 346 |
struct ast_bridge_snapshot *old_snapshot, |
| 347 |
struct ast_bridge_snapshot *new_snapshot) |
| 348 |
{ |
| 349 |
if (new_snapshot || !old_snapshot) { |
| 350 |
return NULL; |
| 351 |
} |
| 352 |
|
| 353 |
return ast_manager_event_blob_create( |
| 354 |
EVENT_FLAG_CALL, "BridgeDestroy", NO_EXTRA_FIELDS); |
| 355 |
} |
| 356 |
|
| 357 |
bridge_snapshot_monitor bridge_monitors[] = { |
| 358 |
bridge_create, |
| 359 |
bridge_video_update, |
| 360 |
bridge_destroy, |
| 361 |
}; |
| 362 |
|
| 363 |
static void bridge_snapshot_update(void *data, struct stasis_subscription *sub, |
| 364 |
struct stasis_message *message) |
| 365 |
{ |
| 366 |
RAII_VAR(struct ast_str *, bridge_event_string, NULL, ast_free); |
| 367 |
struct ast_bridge_snapshot_update *update; |
| 368 |
size_t i; |
| 369 |
|
| 370 |
update = stasis_message_data(message); |
| 371 |
|
| 372 |
for (i = 0; i < ARRAY_LEN(bridge_monitors); ++i) { |
| 373 |
RAII_VAR(struct ast_manager_event_blob *, event, NULL, ao2_cleanup); |
| 374 |
|
| 375 |
event = bridge_monitors[i](update->old_snapshot, update->new_snapshot); |
| 376 |
if (!event) { |
| 377 |
continue; |
| 378 |
} |
| 379 |
|
| 380 |
|
| 381 |
if (!bridge_event_string) { |
| 382 |
bridge_event_string = |
| 383 |
ast_manager_build_bridge_state_string( |
| 384 |
update->new_snapshot ? update->new_snapshot : update->old_snapshot); |
| 385 |
if (!bridge_event_string) { |
| 386 |
return; |
| 387 |
} |
| 388 |
} |
| 389 |
|
| 390 |
manager_event(event->event_flags, event->manager_event, "%s%s", |
| 391 |
ast_str_buffer(bridge_event_string), |
| 392 |
event->extra_fields); |
| 393 |
} |
| 394 |
} |
| 395 |
|
| 396 |
static void bridge_merge_cb(void *data, struct stasis_subscription *sub, |
| 397 |
struct stasis_message *message) |
| 398 |
{ |
| 399 |
struct ast_bridge_merge_message *merge_msg = stasis_message_data(message); |
| 400 |
RAII_VAR(struct ast_str *, to_text, NULL, ast_free); |
| 401 |
RAII_VAR(struct ast_str *, from_text, NULL, ast_free); |
| 402 |
|
| 403 |
ast_assert(merge_msg->to != NULL); |
| 404 |
ast_assert(merge_msg->from != NULL); |
| 405 |
|
| 406 |
to_text = ast_manager_build_bridge_state_string_prefix(merge_msg->to, "To"); |
| 407 |
from_text = ast_manager_build_bridge_state_string_prefix(merge_msg->from, "From"); |
| 408 |
if (!to_text || !from_text) { |
| 409 |
return; |
| 410 |
} |
| 411 |
|
| 412 |
|
| 413 |
|
| 414 |
|
| 415 |
|
| 416 |
|
| 417 |
|
| 418 |
|
| 419 |
|
| 420 |
|
| 421 |
|
| 422 |
|
| 423 |
|
| 424 |
|
| 425 |
|
| 426 |
|
| 427 |
|
| 428 |
manager_event(EVENT_FLAG_CALL, "BridgeMerge", |
| 429 |
"%s" |
| 430 |
"%s", |
| 431 |
ast_str_buffer(to_text), |
| 432 |
ast_str_buffer(from_text)); |
| 433 |
} |
| 434 |
|
| 435 |
static void channel_enter_cb(void *data, struct stasis_subscription *sub, |
| 436 |
struct stasis_message *message) |
| 437 |
{ |
| 438 |
static const char *swap_name = "SwapUniqueid: "; |
| 439 |
struct ast_bridge_blob *blob = stasis_message_data(message); |
| 440 |
RAII_VAR(struct ast_str *, bridge_text, NULL, ast_free); |
| 441 |
RAII_VAR(struct ast_str *, channel_text, NULL, ast_free); |
| 442 |
const char *swap_id; |
| 443 |
|
| 444 |
bridge_text = ast_manager_build_bridge_state_string(blob->bridge); |
| 445 |
channel_text = ast_manager_build_channel_state_string(blob->channel); |
| 446 |
if (!bridge_text || !channel_text) { |
| 447 |
return; |
| 448 |
} |
| 449 |
|
| 450 |
swap_id = ast_json_string_get(ast_json_object_get(blob->blob, "swap")); |
| 451 |
|
| 452 |
manager_event(EVENT_FLAG_CALL, "BridgeEnter", |
| 453 |
"%s" |
| 454 |
"%s" |
| 455 |
"%s%s%s", |
| 456 |
ast_str_buffer(bridge_text), |
| 457 |
ast_str_buffer(channel_text), |
| 458 |
swap_id ? swap_name : "", |
| 459 |
S_OR(swap_id, ""), |
| 460 |
swap_id ? "\r\n" : ""); |
| 461 |
} |
| 462 |
|
| 463 |
static void channel_leave_cb(void *data, struct stasis_subscription *sub, |
| 464 |
struct stasis_message *message) |
| 465 |
{ |
| 466 |
struct ast_bridge_blob *blob = stasis_message_data(message); |
| 467 |
RAII_VAR(struct ast_str *, bridge_text, NULL, ast_free); |
| 468 |
RAII_VAR(struct ast_str *, channel_text, NULL, ast_free); |
| 469 |
|
| 470 |
bridge_text = ast_manager_build_bridge_state_string(blob->bridge); |
| 471 |
channel_text = ast_manager_build_channel_state_string(blob->channel); |
| 472 |
if (!bridge_text || !channel_text) { |
| 473 |
return; |
| 474 |
} |
| 475 |
|
| 476 |
manager_event(EVENT_FLAG_CALL, "BridgeLeave", |
| 477 |
"%s" |
| 478 |
"%s", |
| 479 |
ast_str_buffer(bridge_text), |
| 480 |
ast_str_buffer(channel_text)); |
| 481 |
} |
| 482 |
|
| 483 |
struct bridge_list_data { |
| 484 |
struct ast_str *id_text; |
| 485 |
const char *type_filter; |
| 486 |
int count; |
| 487 |
}; |
| 488 |
|
| 489 |
static int send_bridge_list_item_cb(void *obj, void *arg, void *data, int flags) |
| 490 |
{ |
| 491 |
struct ast_bridge *bridge = obj; |
| 492 |
RAII_VAR(struct ast_bridge_snapshot *, snapshot, ast_bridge_get_snapshot(bridge), ao2_cleanup); |
| 493 |
struct mansession *s = arg; |
| 494 |
struct bridge_list_data *list_data = data; |
| 495 |
struct ast_str * bridge_info; |
| 496 |
|
| 497 |
if (!snapshot) { |
| 498 |
return 0; |
| 499 |
} |
| 500 |
|
| 501 |
if (!ast_strlen_zero(list_data->type_filter) |
| 502 |
&& strcmp(list_data->type_filter, snapshot->technology)) { |
| 503 |
return 0; |
| 504 |
} |
| 505 |
|
| 506 |
bridge_info = ast_manager_build_bridge_state_string(snapshot); |
| 507 |
if (!bridge_info) { |
| 508 |
return 0; |
| 509 |
} |
| 510 |
|
| 511 |
astman_append(s, |
| 512 |
"Event: BridgeListItem\r\n" |
| 513 |
"%s" |
| 514 |
"%s" |
| 515 |
"\r\n", |
| 516 |
ast_str_buffer(list_data->id_text), |
| 517 |
ast_str_buffer(bridge_info)); |
| 518 |
++list_data->count; |
| 519 |
|
| 520 |
ast_free(bridge_info); |
| 521 |
|
| 522 |
return 0; |
| 523 |
} |
| 524 |
|
| 525 |
static int manager_bridges_list(struct mansession *s, const struct message *m) |
| 526 |
{ |
| 527 |
const char *id = astman_get_header(m, "ActionID"); |
| 528 |
const char *type_filter = astman_get_header(m, "BridgeType"); |
| 529 |
struct ao2_container *bridges; |
| 530 |
struct bridge_list_data list_data = { 0 }; |
| 531 |
|
| 532 |
bridges = ast_bridges(); |
| 533 |
if (!bridges) { |
| 534 |
astman_send_error(s, m, "Internal error"); |
| 535 |
return -1; |
| 536 |
} |
| 537 |
|
| 538 |
list_data.id_text = ast_str_create(128); |
| 539 |
if (!list_data.id_text) { |
| 540 |
ao2_ref(bridges, -1); |
| 541 |
astman_send_error(s, m, "Internal error"); |
| 542 |
return -1; |
| 543 |
} |
| 544 |
|
| 545 |
if (!ast_strlen_zero(id)) { |
| 546 |
ast_str_set(&list_data.id_text, 0, "ActionID: %s\r\n", id); |
| 547 |
} |
| 548 |
list_data.type_filter = type_filter; |
| 549 |
|
| 550 |
astman_send_listack(s, m, "Bridge listing will follow", "start"); |
| 551 |
|
| 552 |
ao2_callback_data(bridges, OBJ_NODATA, send_bridge_list_item_cb, s, &list_data); |
| 553 |
|
| 554 |
astman_send_list_complete_start(s, m, "BridgeListComplete", list_data.count); |
| 555 |
astman_send_list_complete_end(s); |
| 556 |
|
| 557 |
ast_free(list_data.id_text); |
| 558 |
ao2_ref(bridges, -1); |
| 559 |
|
| 560 |
return 0; |
| 561 |
} |
| 562 |
|
| 563 |
static int send_bridge_info_item_cb(void *obj, void *arg, void *data, int flags) |
| 564 |
{ |
| 565 |
char *uniqueid = obj; |
| 566 |
struct mansession *s = arg; |
| 567 |
struct bridge_list_data *list_data = data; |
| 568 |
RAII_VAR(struct ast_channel_snapshot *, snapshot, NULL, ao2_cleanup); |
| 569 |
RAII_VAR(struct ast_str *, channel_text, NULL, ast_free); |
| 570 |
|
| 571 |
snapshot = ast_channel_snapshot_get_latest(uniqueid); |
| 572 |
if (!snapshot) { |
| 573 |
return 0; |
| 574 |
} |
| 575 |
|
| 576 |
if (snapshot->base->tech_properties & AST_CHAN_TP_INTERNAL) { |
| 577 |
return 0; |
| 578 |
} |
| 579 |
|
| 580 |
channel_text = ast_manager_build_channel_state_string(snapshot); |
| 581 |
if (!channel_text) { |
| 582 |
return 0; |
| 583 |
} |
| 584 |
|
| 585 |
astman_append(s, |
| 586 |
"Event: BridgeInfoChannel\r\n" |
| 587 |
"%s" |
| 588 |
"%s" |
| 589 |
"\r\n", |
| 590 |
ast_str_buffer(list_data->id_text), |
| 591 |
ast_str_buffer(channel_text)); |
| 592 |
++list_data->count; |
| 593 |
return 0; |
| 594 |
} |
| 595 |
|
| 596 |
static int manager_bridge_info(struct mansession *s, const struct message *m) |
| 597 |
{ |
| 598 |
const char *id = astman_get_header(m, "ActionID"); |
| 599 |
const char *bridge_uniqueid = astman_get_header(m, "BridgeUniqueid"); |
| 600 |
RAII_VAR(struct ast_str *, bridge_info, NULL, ast_free); |
| 601 |
RAII_VAR(struct ast_bridge_snapshot *, snapshot, NULL, ao2_cleanup); |
| 602 |
struct bridge_list_data list_data = { 0 }; |
| 603 |
|
| 604 |
if (ast_strlen_zero(bridge_uniqueid)) { |
| 605 |
astman_send_error(s, m, "BridgeUniqueid must be provided"); |
| 606 |
return 0; |
| 607 |
} |
| 608 |
|
| 609 |
snapshot = ast_bridge_get_snapshot_by_uniqueid(bridge_uniqueid); |
| 610 |
if (!snapshot) { |
| 611 |
astman_send_error(s, m, "Specified BridgeUniqueid not found"); |
| 612 |
return 0; |
| 613 |
} |
| 614 |
|
| 615 |
bridge_info = ast_manager_build_bridge_state_string(snapshot); |
| 616 |
if (!bridge_info) { |
| 617 |
astman_send_error(s, m, "Internal error"); |
| 618 |
return -1; |
| 619 |
} |
| 620 |
|
| 621 |
list_data.id_text = ast_str_create(128); |
| 622 |
if (!list_data.id_text) { |
| 623 |
astman_send_error(s, m, "Internal error"); |
| 624 |
return -1; |
| 625 |
} |
| 626 |
|
| 627 |
if (!ast_strlen_zero(id)) { |
| 628 |
ast_str_set(&list_data.id_text, 0, "ActionID: %s\r\n", id); |
| 629 |
} |
| 630 |
|
| 631 |
astman_send_listack(s, m, "Bridge channel listing will follow", "start"); |
| 632 |
|
| 633 |
ao2_callback_data(snapshot->channels, OBJ_NODATA, send_bridge_info_item_cb, s, &list_data); |
| 634 |
|
| 635 |
astman_send_list_complete_start(s, m, "BridgeInfoComplete", list_data.count); |
| 636 |
if (!ast_strlen_zero(ast_str_buffer(bridge_info))) { |
| 637 |
astman_append(s, "%s", ast_str_buffer(bridge_info)); |
| 638 |
} |
| 639 |
astman_send_list_complete_end(s); |
| 640 |
ast_free(list_data.id_text); |
| 641 |
|
| 642 |
return 0; |
| 643 |
} |
| 644 |
|
| 645 |
static int manager_bridge_destroy(struct mansession *s, const struct message *m) |
| 646 |
{ |
| 647 |
const char *bridge_uniqueid = astman_get_header(m, "BridgeUniqueid"); |
| 648 |
struct ast_bridge *bridge; |
| 649 |
|
| 650 |
if (ast_strlen_zero(bridge_uniqueid)) { |
| 651 |
astman_send_error(s, m, "BridgeUniqueid must be provided"); |
| 652 |
return 0; |
| 653 |
} |
| 654 |
|
| 655 |
bridge = ast_bridge_find_by_id(bridge_uniqueid); |
| 656 |
if (!bridge) { |
| 657 |
astman_send_error(s, m, "Specified BridgeUniqueid not found"); |
| 658 |
return 0; |
| 659 |
} |
| 660 |
ast_bridge_destroy(bridge, 0); |
| 661 |
|
| 662 |
astman_send_ack(s, m, "Bridge has been destroyed"); |
| 663 |
|
| 664 |
return 0; |
| 665 |
} |
| 666 |
|
| 667 |
static int manager_bridge_kick(struct mansession *s, const struct message *m) |
| 668 |
{ |
| 669 |
const char *bridge_uniqueid = astman_get_header(m, "BridgeUniqueid"); |
| 670 |
const char *channel_name = astman_get_header(m, "Channel"); |
| 671 |
RAII_VAR(struct ast_bridge *, bridge, NULL, ao2_cleanup); |
| 672 |
RAII_VAR(struct ast_channel *, channel, NULL, ao2_cleanup); |
| 673 |
|
| 674 |
if (ast_strlen_zero(channel_name)) { |
| 675 |
astman_send_error(s, m, "Channel must be provided"); |
| 676 |
return 0; |
| 677 |
} |
| 678 |
|
| 679 |
channel = ast_channel_get_by_name(channel_name); |
| 680 |
if (!channel) { |
| 681 |
astman_send_error(s, m, "Channel does not exist"); |
| 682 |
return 0; |
| 683 |
} |
| 684 |
|
| 685 |
if (ast_strlen_zero(bridge_uniqueid)) { |
| 686 |
|
| 687 |
ast_channel_lock(channel); |
| 688 |
bridge = ast_channel_get_bridge(channel); |
| 689 |
ast_channel_unlock(channel); |
| 690 |
if (!bridge) { |
| 691 |
astman_send_error(s, m, "Channel is not in a bridge"); |
| 692 |
return 0; |
| 693 |
} |
| 694 |
} else { |
| 695 |
bridge = ast_bridge_find_by_id(bridge_uniqueid); |
| 696 |
if (!bridge || ast_test_flag(&bridge->feature_flags, AST_BRIDGE_FLAG_INVISIBLE)) { |
| 697 |
astman_send_error(s, m, "Bridge not found"); |
| 698 |
return 0; |
| 699 |
} |
| 700 |
} |
| 701 |
|
| 702 |
if (ast_bridge_kick(bridge, channel)) { |
| 703 |
astman_send_error(s, m, "Channel kick from bridge failed"); |
| 704 |
return 0; |
| 705 |
} |
| 706 |
|
| 707 |
astman_send_ack(s, m, "Channel has been kicked"); |
| 708 |
return 0; |
| 709 |
} |
| 710 |
|
| 711 |
static void manager_bridging_cleanup(void) |
| 712 |
{ |
| 713 |
stasis_forward_cancel(topic_forwarder); |
| 714 |
topic_forwarder = NULL; |
| 715 |
|
| 716 |
ast_manager_unregister("BridgeList"); |
| 717 |
ast_manager_unregister("BridgeInfo"); |
| 718 |
ast_manager_unregister("BridgeDestroy"); |
| 719 |
ast_manager_unregister("BridgeKick"); |
| 720 |
} |
| 721 |
|
| 722 |
int manager_bridging_init(void) |
| 723 |
{ |
| 724 |
int ret = 0; |
| 725 |
struct stasis_topic *manager_topic; |
| 726 |
struct stasis_topic *bridge_topic; |
| 727 |
|
| 728 |
if (bridge_state_router) { |
| 729 |
|
| 730 |
return 0; |
| 731 |
} |
| 732 |
|
| 733 |
ast_register_cleanup(manager_bridging_cleanup); |
| 734 |
|
| 735 |
manager_topic = ast_manager_get_topic(); |
| 736 |
if (!manager_topic) { |
| 737 |
return -1; |
| 738 |
} |
| 739 |
|
| 740 |
bridge_topic = ast_bridge_topic_all(); |
| 741 |
if (!bridge_topic) { |
| 742 |
return -1; |
| 743 |
} |
| 744 |
|
| 745 |
topic_forwarder = stasis_forward_all(bridge_topic, manager_topic); |
| 746 |
if (!topic_forwarder) { |
| 747 |
return -1; |
| 748 |
} |
| 749 |
|
| 750 |
bridge_state_router = ast_manager_get_message_router(); |
| 751 |
if (!bridge_state_router) { |
| 752 |
return -1; |
| 753 |
} |
| 754 |
|
| 755 |
ret |= stasis_message_router_add(bridge_state_router, |
| 756 |
ast_bridge_snapshot_type(), bridge_snapshot_update, NULL); |
| 757 |
|
| 758 |
ret |= stasis_message_router_add(bridge_state_router, |
| 759 |
ast_bridge_merge_message_type(), bridge_merge_cb, NULL); |
| 760 |
|
| 761 |
ret |= stasis_message_router_add(bridge_state_router, |
| 762 |
ast_channel_entered_bridge_type(), channel_enter_cb, NULL); |
| 763 |
|
| 764 |
ret |= stasis_message_router_add(bridge_state_router, |
| 765 |
ast_channel_left_bridge_type(), channel_leave_cb, NULL); |
| 766 |
|
| 767 |
ret |= ast_manager_register_xml_core("BridgeList", 0, manager_bridges_list); |
| 768 |
ret |= ast_manager_register_xml_core("BridgeInfo", 0, manager_bridge_info); |
| 769 |
ret |= ast_manager_register_xml_core("BridgeDestroy", 0, manager_bridge_destroy); |
| 770 |
ret |= ast_manager_register_xml_core("BridgeKick", 0, manager_bridge_kick); |
| 771 |
|
| 772 |
|
| 773 |
|
| 774 |
|
| 775 |
if (ret) { |
| 776 |
manager_bridging_cleanup(); |
| 777 |
return -1; |
| 778 |
} |
| 779 |
|
| 780 |
return 0; |
| 781 |
} |