| 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/channel.h" |
| 29 |
#include "asterisk/bridge.h" |
| 30 |
#include "asterisk/stasis.h" |
| 31 |
#include "asterisk/stasis_channels.h" |
| 32 |
#include "asterisk/stasis_bridges.h" |
| 33 |
#include "asterisk/manager.h" |
| 34 |
#include "asterisk/stasis_message_router.h" |
| 35 |
#include "include/confbridge.h" |
| 36 |
#include "asterisk/message.h" |
| 37 |
#include "asterisk/stream.h" |
| 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 |
|
| 256 |
static struct stasis_message_router *bridge_state_router; |
| 257 |
static struct stasis_message_router *channel_state_router; |
| 258 |
|
| 259 |
STASIS_MESSAGE_TYPE_DEFN(confbridge_start_type); |
| 260 |
STASIS_MESSAGE_TYPE_DEFN(confbridge_end_type); |
| 261 |
STASIS_MESSAGE_TYPE_DEFN(confbridge_join_type); |
| 262 |
STASIS_MESSAGE_TYPE_DEFN(confbridge_leave_type); |
| 263 |
STASIS_MESSAGE_TYPE_DEFN(confbridge_start_record_type); |
| 264 |
STASIS_MESSAGE_TYPE_DEFN(confbridge_stop_record_type); |
| 265 |
STASIS_MESSAGE_TYPE_DEFN(confbridge_mute_type); |
| 266 |
STASIS_MESSAGE_TYPE_DEFN(confbridge_unmute_type); |
| 267 |
STASIS_MESSAGE_TYPE_DEFN(confbridge_talking_type); |
| 268 |
|
| 269 |
|
| 270 |
|
| 271 |
|
| 272 |
|
| 273 |
|
| 274 |
STASIS_MESSAGE_TYPE_DEFN(confbridge_welcome_type); |
| 275 |
|
| 276 |
const char *confbridge_event_type_to_string(struct stasis_message_type *event_type) |
| 277 |
{ |
| 278 |
if (event_type == confbridge_start_type()) { |
| 279 |
return "ConfbridgeStart"; |
| 280 |
} else if (event_type == confbridge_end_type()) { |
| 281 |
return "ConfbridgeEnd"; |
| 282 |
} else if (event_type == confbridge_join_type()) { |
| 283 |
return "ConfbridgeJoin"; |
| 284 |
} else if (event_type == confbridge_leave_type()) { |
| 285 |
return "ConfbridgeLeave"; |
| 286 |
} else if (event_type == confbridge_start_record_type()) { |
| 287 |
return "ConfbridgeRecord"; |
| 288 |
} else if (event_type == confbridge_stop_record_type()) { |
| 289 |
return "ConfbridgeStopRecord"; |
| 290 |
} else if (event_type == confbridge_mute_type()) { |
| 291 |
return "ConfbridgeMute"; |
| 292 |
} else if (event_type == confbridge_unmute_type()) { |
| 293 |
return "ConfbridgeUnmute"; |
| 294 |
} else if (event_type == confbridge_talking_type()) { |
| 295 |
return "ConfbridgeTalking"; |
| 296 |
} else if (event_type == confbridge_welcome_type()) { |
| 297 |
return "ConfbridgeWelcome"; |
| 298 |
} else { |
| 299 |
return "unknown"; |
| 300 |
} |
| 301 |
} |
| 302 |
|
| 303 |
static struct ast_json *channel_to_json(struct ast_channel_snapshot *channel_snapshot, |
| 304 |
struct ast_json *conf_blob, struct ast_json *labels_blob) |
| 305 |
{ |
| 306 |
struct ast_json *json_channel = ast_channel_snapshot_to_json(channel_snapshot, NULL); |
| 307 |
|
| 308 |
if (!json_channel) { |
| 309 |
return NULL; |
| 310 |
} |
| 311 |
|
| 312 |
|
| 313 |
ast_json_object_del(json_channel, "dialplan"); |
| 314 |
ast_json_object_del(json_channel, "connected"); |
| 315 |
ast_json_object_del(json_channel, "accountcode"); |
| 316 |
|
| 317 |
|
| 318 |
if (conf_blob) { |
| 319 |
struct ast_json *conf_copy = ast_json_copy(conf_blob); |
| 320 |
|
| 321 |
if (!conf_copy) { |
| 322 |
ast_json_unref(json_channel); |
| 323 |
return NULL; |
| 324 |
} |
| 325 |
ast_json_object_del(conf_copy, "conference"); |
| 326 |
ast_json_object_update(json_channel, conf_copy); |
| 327 |
ast_json_unref(conf_copy); |
| 328 |
} |
| 329 |
|
| 330 |
|
| 331 |
if (labels_blob) { |
| 332 |
ast_json_object_update(json_channel, labels_blob); |
| 333 |
} |
| 334 |
|
| 335 |
return json_channel; |
| 336 |
} |
| 337 |
|
| 338 |
static struct ast_json *bridge_to_json(struct ast_bridge_snapshot *bridge_snapshot) |
| 339 |
{ |
| 340 |
struct ast_json *json_bridge = ast_bridge_snapshot_to_json(bridge_snapshot, NULL); |
| 341 |
|
| 342 |
if (!json_bridge) { |
| 343 |
return NULL; |
| 344 |
} |
| 345 |
|
| 346 |
|
| 347 |
ast_json_object_del(json_bridge, "technology"); |
| 348 |
ast_json_object_del(json_bridge, "bridge_type"); |
| 349 |
ast_json_object_del(json_bridge, "bridge_class"); |
| 350 |
ast_json_object_del(json_bridge, "creator"); |
| 351 |
ast_json_object_del(json_bridge, "channels"); |
| 352 |
|
| 353 |
return json_bridge; |
| 354 |
} |
| 355 |
|
| 356 |
static struct ast_json *pack_bridge_and_channel( |
| 357 |
struct ast_json *json_bridge, struct ast_json *json_channel, |
| 358 |
struct stasis_message *msg) |
| 359 |
{ |
| 360 |
const struct timeval *tv = stasis_message_timestamp(msg); |
| 361 |
const char *msg_name = confbridge_event_type_to_string(stasis_message_type(msg)); |
| 362 |
|
| 363 |
return ast_json_pack("{s: s, s: o, s: o, s: [o*]}", |
| 364 |
"type", msg_name, |
| 365 |
"timestamp", ast_json_timeval(*tv, NULL), |
| 366 |
"bridge", json_bridge, |
| 367 |
"channels", json_channel); |
| 368 |
} |
| 369 |
|
| 370 |
static struct ast_json *pack_bridge_and_channels( |
| 371 |
struct ast_json *json_bridge, struct ast_json *json_channels, |
| 372 |
struct stasis_message *msg) |
| 373 |
{ |
| 374 |
const struct timeval *tv = stasis_message_timestamp(msg); |
| 375 |
const char *msg_name = confbridge_event_type_to_string(stasis_message_type(msg)); |
| 376 |
|
| 377 |
return ast_json_pack("{s: s, s: o, s: o, s: o}", |
| 378 |
"type", msg_name, |
| 379 |
"timestamp", ast_json_timeval(*tv, NULL), |
| 380 |
"bridge", json_bridge, |
| 381 |
"channels", json_channels); |
| 382 |
} |
| 383 |
|
| 384 |
static struct ast_json *pack_snapshots( struct ast_bridge_snapshot *bridge_snapshot, |
| 385 |
struct ast_channel_snapshot *channel_snapshot, struct ast_json *conf_blob, |
| 386 |
struct ast_json *labels_blob, struct stasis_message * msg) |
| 387 |
{ |
| 388 |
struct ast_json *json_bridge; |
| 389 |
struct ast_json *json_channel; |
| 390 |
|
| 391 |
json_bridge = bridge_to_json(bridge_snapshot); |
| 392 |
json_channel = channel_to_json(channel_snapshot, conf_blob, labels_blob); |
| 393 |
|
| 394 |
return pack_bridge_and_channel(json_bridge, json_channel, msg); |
| 395 |
} |
| 396 |
|
| 397 |
static void send_message(const char *msg_name, char *conf_name, struct ast_json *json_object, |
| 398 |
struct ast_channel *chan) |
| 399 |
{ |
| 400 |
struct ast_msg_data *data_msg; |
| 401 |
struct ast_msg_data_attribute attrs[] = { |
| 402 |
{ .type = AST_MSG_DATA_ATTR_FROM, conf_name }, |
| 403 |
{ .type = AST_MSG_DATA_ATTR_CONTENT_TYPE, .value = "application/x-asterisk-confbridge-event+json"}, |
| 404 |
{ .type = AST_MSG_DATA_ATTR_BODY, }, |
| 405 |
}; |
| 406 |
char *json; |
| 407 |
int rc = 0; |
| 408 |
struct ast_frame f; |
| 409 |
RAII_VAR(struct ast_bridge_channel *, bridge_chan, NULL, ao2_cleanup); |
| 410 |
|
| 411 |
bridge_chan = ast_channel_get_bridge_channel(chan); |
| 412 |
if (!bridge_chan) { |
| 413 |
|
| 414 |
return; |
| 415 |
} |
| 416 |
|
| 417 |
json = ast_json_dump_string_format(json_object, AST_JSON_PRETTY); |
| 418 |
if (!json) { |
| 419 |
ast_log(LOG_ERROR, "Unable to convert json_object for %s message to string\n", msg_name); |
| 420 |
return; |
| 421 |
} |
| 422 |
attrs[2].value = json; |
| 423 |
|
| 424 |
data_msg = ast_msg_data_alloc(AST_MSG_DATA_SOURCE_TYPE_IN_DIALOG, attrs, ARRAY_LEN(attrs)); |
| 425 |
if (!data_msg) { |
| 426 |
ast_log(LOG_ERROR, "Unable to create %s message for channel '%s'\n", msg_name, |
| 427 |
ast_channel_name(chan)); |
| 428 |
ast_json_free(json); |
| 429 |
return; |
| 430 |
} |
| 431 |
|
| 432 |
memset(&f, 0, sizeof(f)); |
| 433 |
f.frametype = AST_FRAME_TEXT_DATA; |
| 434 |
f.data.ptr = data_msg; |
| 435 |
f.datalen = ast_msg_data_get_length(data_msg); |
| 436 |
|
| 437 |
rc = ast_bridge_channel_queue_frame(bridge_chan, &f); |
| 438 |
ast_free(data_msg); |
| 439 |
if (rc != 0) { |
| 440 |
|
| 441 |
if (strcmp(confbridge_event_type_to_string(confbridge_leave_type()), msg_name) != 0) { |
| 442 |
ast_log(LOG_ERROR, "Failed to queue %s message to '%s'\n%s\n", msg_name, |
| 443 |
ast_channel_name(chan), json); |
| 444 |
} |
| 445 |
ast_json_free(json); |
| 446 |
return; |
| 447 |
} |
| 448 |
|
| 449 |
ast_debug(3, "Queued %s message to '%s'\n%s\n", msg_name, ast_channel_name(chan), json); |
| 450 |
ast_json_free(json); |
| 451 |
} |
| 452 |
|
| 453 |
void conf_send_event_to_participants(struct confbridge_conference *conference, |
| 454 |
struct ast_channel *chan, struct stasis_message *msg) |
| 455 |
{ |
| 456 |
struct ast_bridge_blob *obj = stasis_message_data(msg); |
| 457 |
struct ast_json *extras = obj->blob; |
| 458 |
struct user_profile u_profile = {{0}}; |
| 459 |
int source_send_events = 0; |
| 460 |
int source_echo_events = 0; |
| 461 |
struct ast_json* json_channels = NULL; |
| 462 |
struct confbridge_user *user; |
| 463 |
const char *msg_name = confbridge_event_type_to_string(stasis_message_type(msg)); |
| 464 |
|
| 465 |
ast_debug(3, "Distributing %s event to participants\n", msg_name); |
| 466 |
|
| 467 |
|
| 468 |
if (chan) { |
| 469 |
if (!conf_find_user_profile(chan, NULL, &u_profile)) { |
| 470 |
ast_log(LOG_ERROR, "Unable to retrieve user profile for channel '%s'\n", |
| 471 |
ast_channel_name(chan)); |
| 472 |
return; |
| 473 |
} |
| 474 |
source_send_events = ast_test_flag(&u_profile, USER_OPT_SEND_EVENTS); |
| 475 |
source_echo_events = ast_test_flag(&u_profile, USER_OPT_ECHO_EVENTS); |
| 476 |
ast_debug(3, "send_events: %d echo_events: %d for profile %s\n", |
| 477 |
source_send_events, source_echo_events, u_profile.name); |
| 478 |
} |
| 479 |
|
| 480 |
|
| 481 |
ao2_lock(conference); |
| 482 |
AST_LIST_TRAVERSE(&conference->active_list, user, list) { |
| 483 |
struct ast_json *json_object; |
| 484 |
|
| 485 |
|
| 486 |
|
| 487 |
|
| 488 |
|
| 489 |
if (source_send_events && stasis_message_type(msg) == confbridge_join_type()) { |
| 490 |
struct ast_channel_snapshot *target_snapshot; |
| 491 |
struct ast_json *target_json_channel; |
| 492 |
|
| 493 |
target_snapshot = ast_channel_snapshot_get_latest(ast_channel_uniqueid(user->chan)); |
| 494 |
if (!target_snapshot) { |
| 495 |
ast_log(LOG_ERROR, "Unable to get a channel snapshot for '%s'\n", |
| 496 |
ast_channel_name(user->chan)); |
| 497 |
continue; |
| 498 |
} |
| 499 |
|
| 500 |
target_json_channel = channel_to_json(target_snapshot, extras, NULL); |
| 501 |
ao2_ref(target_snapshot, -1); |
| 502 |
|
| 503 |
if (!json_channels) { |
| 504 |
json_channels = ast_json_array_create(); |
| 505 |
if (!json_channels) { |
| 506 |
ast_log(LOG_ERROR, "Unable to allocate json array\n"); |
| 507 |
ast_json_unref(target_json_channel); |
| 508 |
return; |
| 509 |
} |
| 510 |
} |
| 511 |
|
| 512 |
ast_json_array_append(json_channels, target_json_channel); |
| 513 |
} |
| 514 |
|
| 515 |
|
| 516 |
if (!source_echo_events && user->chan == chan) { |
| 517 |
ast_debug(3, "Skipping queueing %s message to '%s'. Same channel.\n", msg_name, |
| 518 |
ast_channel_name(user->chan)); |
| 519 |
continue; |
| 520 |
} |
| 521 |
|
| 522 |
|
| 523 |
if (!ast_test_flag(&user->u_profile, USER_OPT_SEND_EVENTS)) { |
| 524 |
ast_debug(3, "Skipping queueing %s message to '%s'. Not receiving events.\n", msg_name, |
| 525 |
ast_channel_name(user->chan)); |
| 526 |
continue; |
| 527 |
} |
| 528 |
|
| 529 |
json_object = pack_snapshots(obj->bridge, obj->channel, extras, NULL, msg); |
| 530 |
|
| 531 |
if (!json_object) { |
| 532 |
ast_log(LOG_ERROR, "Unable to convert %s message to json\n", msg_name); |
| 533 |
continue; |
| 534 |
} |
| 535 |
|
| 536 |
send_message(msg_name, conference->name, json_object, user->chan); |
| 537 |
ast_json_unref(json_object); |
| 538 |
} |
| 539 |
ao2_unlock(conference); |
| 540 |
|
| 541 |
|
| 542 |
|
| 543 |
|
| 544 |
|
| 545 |
if (source_send_events && json_channels |
| 546 |
&& stasis_message_type(msg) == confbridge_join_type()) { |
| 547 |
struct ast_json *json_object; |
| 548 |
struct ast_json *json_bridge; |
| 549 |
const char *welcome_msg_name = confbridge_event_type_to_string(confbridge_welcome_type()); |
| 550 |
|
| 551 |
json_bridge = bridge_to_json(obj->bridge); |
| 552 |
json_object = pack_bridge_and_channels(json_bridge, json_channels, msg); |
| 553 |
if (!json_object) { |
| 554 |
ast_log(LOG_ERROR, "Unable to convert ConfbridgeWelcome message to json\n"); |
| 555 |
return; |
| 556 |
} |
| 557 |
ast_json_string_set(ast_json_object_get(json_object, "type"), welcome_msg_name); |
| 558 |
|
| 559 |
send_message(welcome_msg_name, conference->name, json_object, chan); |
| 560 |
ast_json_unref(json_object); |
| 561 |
} |
| 562 |
} |
| 563 |
|
| 564 |
static void confbridge_publish_manager_event( |
| 565 |
struct stasis_message *message, |
| 566 |
struct ast_str *extra_text) |
| 567 |
{ |
| 568 |
struct ast_bridge_blob *blob = stasis_message_data(message); |
| 569 |
const char *event = confbridge_event_type_to_string(stasis_message_type(message)); |
| 570 |
const char *conference_name; |
| 571 |
RAII_VAR(struct ast_str *, bridge_text, NULL, ast_free); |
| 572 |
RAII_VAR(struct ast_str *, channel_text, NULL, ast_free); |
| 573 |
|
| 574 |
ast_assert(blob != NULL); |
| 575 |
ast_assert(event != NULL); |
| 576 |
|
| 577 |
bridge_text = ast_manager_build_bridge_state_string(blob->bridge); |
| 578 |
if (!bridge_text) { |
| 579 |
return; |
| 580 |
} |
| 581 |
|
| 582 |
conference_name = ast_json_string_get(ast_json_object_get(blob->blob, "conference")); |
| 583 |
ast_assert(conference_name != NULL); |
| 584 |
|
| 585 |
if (blob->channel) { |
| 586 |
struct confbridge_conference *conference = conf_find_bridge(conference_name); |
| 587 |
|
| 588 |
channel_text = ast_manager_build_channel_state_string(blob->channel); |
| 589 |
ao2_cleanup(conference); |
| 590 |
} |
| 591 |
|
| 592 |
manager_event(EVENT_FLAG_CALL, event, |
| 593 |
"Conference: %s\r\n" |
| 594 |
"%s" |
| 595 |
"%s" |
| 596 |
"%s", |
| 597 |
conference_name, |
| 598 |
ast_str_buffer(bridge_text), |
| 599 |
channel_text ? ast_str_buffer(channel_text) : "", |
| 600 |
extra_text ? ast_str_buffer(extra_text) : ""); |
| 601 |
} |
| 602 |
|
| 603 |
static int get_bool_header(struct ast_str **extra_text, struct stasis_message *message, |
| 604 |
const char *json_key, const char *ami_header) |
| 605 |
{ |
| 606 |
const struct ast_bridge_blob *blob = stasis_message_data(message); |
| 607 |
const struct ast_json *obj; |
| 608 |
|
| 609 |
obj = ast_json_object_get(blob->blob, json_key); |
| 610 |
if (!obj) { |
| 611 |
return -1; |
| 612 |
} |
| 613 |
|
| 614 |
return ast_str_append_event_header(extra_text, ami_header, |
| 615 |
AST_YESNO(ast_json_is_true(obj))); |
| 616 |
} |
| 617 |
|
| 618 |
static int get_admin_header(struct ast_str **extra_text, struct stasis_message *message) |
| 619 |
{ |
| 620 |
return get_bool_header(extra_text, message, "admin", "Admin"); |
| 621 |
} |
| 622 |
|
| 623 |
static int get_muted_header(struct ast_str **extra_text, struct stasis_message *message) |
| 624 |
{ |
| 625 |
return get_bool_header(extra_text, message, "muted", "Muted"); |
| 626 |
} |
| 627 |
|
| 628 |
static void confbridge_start_cb(void *data, struct stasis_subscription *sub, |
| 629 |
struct stasis_message *message) |
| 630 |
{ |
| 631 |
confbridge_publish_manager_event(message, NULL); |
| 632 |
} |
| 633 |
|
| 634 |
static void confbridge_end_cb(void *data, struct stasis_subscription *sub, |
| 635 |
struct stasis_message *message) |
| 636 |
{ |
| 637 |
confbridge_publish_manager_event(message, NULL); |
| 638 |
} |
| 639 |
|
| 640 |
static void confbridge_leave_cb(void *data, struct stasis_subscription *sub, |
| 641 |
struct stasis_message *message) |
| 642 |
{ |
| 643 |
struct ast_str *extra_text = NULL; |
| 644 |
|
| 645 |
if (!get_admin_header(&extra_text, message)) { |
| 646 |
confbridge_publish_manager_event(message, extra_text); |
| 647 |
} |
| 648 |
ast_free(extra_text); |
| 649 |
} |
| 650 |
|
| 651 |
static void confbridge_join_cb(void *data, struct stasis_subscription *sub, |
| 652 |
struct stasis_message *message) |
| 653 |
{ |
| 654 |
struct ast_str *extra_text = NULL; |
| 655 |
|
| 656 |
if (!get_admin_header(&extra_text, message) |
| 657 |
&& !get_muted_header(&extra_text, message)) { |
| 658 |
confbridge_publish_manager_event(message, extra_text); |
| 659 |
} |
| 660 |
ast_free(extra_text); |
| 661 |
} |
| 662 |
|
| 663 |
static void confbridge_atxfer_cb(void *data, struct stasis_subscription *sub, |
| 664 |
struct stasis_message *message) |
| 665 |
{ |
| 666 |
struct ast_attended_transfer_message *msg = stasis_message_data(message); |
| 667 |
|
| 668 |
if (msg->result != AST_BRIDGE_TRANSFER_SUCCESS) { |
| 669 |
return; |
| 670 |
} |
| 671 |
|
| 672 |
|
| 673 |
|
| 674 |
|
| 675 |
|
| 676 |
|
| 677 |
if (msg->dest_type == AST_ATTENDED_TRANSFER_DEST_APP |
| 678 |
&& strcmp(msg->dest.app, "ConfBridge") == 0) { |
| 679 |
confbridge_handle_atxfer(msg); |
| 680 |
} |
| 681 |
} |
| 682 |
|
| 683 |
static void confbridge_start_record_cb(void *data, struct stasis_subscription *sub, |
| 684 |
struct stasis_message *message) |
| 685 |
{ |
| 686 |
confbridge_publish_manager_event(message, NULL); |
| 687 |
} |
| 688 |
|
| 689 |
static void confbridge_stop_record_cb(void *data, struct stasis_subscription *sub, |
| 690 |
struct stasis_message *message) |
| 691 |
{ |
| 692 |
confbridge_publish_manager_event(message, NULL); |
| 693 |
} |
| 694 |
|
| 695 |
static void confbridge_mute_cb(void *data, struct stasis_subscription *sub, |
| 696 |
struct stasis_message *message) |
| 697 |
{ |
| 698 |
struct ast_str *extra_text = NULL; |
| 699 |
|
| 700 |
if (!get_admin_header(&extra_text, message)) { |
| 701 |
confbridge_publish_manager_event(message, extra_text); |
| 702 |
} |
| 703 |
ast_free(extra_text); |
| 704 |
} |
| 705 |
|
| 706 |
static void confbridge_unmute_cb(void *data, struct stasis_subscription *sub, |
| 707 |
struct stasis_message *message) |
| 708 |
{ |
| 709 |
struct ast_str *extra_text = NULL; |
| 710 |
|
| 711 |
if (!get_admin_header(&extra_text, message)) { |
| 712 |
confbridge_publish_manager_event(message, extra_text); |
| 713 |
} |
| 714 |
ast_free(extra_text); |
| 715 |
} |
| 716 |
|
| 717 |
static void confbridge_talking_cb(void *data, struct stasis_subscription *sub, |
| 718 |
struct stasis_message *message) |
| 719 |
{ |
| 720 |
RAII_VAR(struct ast_str *, extra_text, NULL, ast_free); |
| 721 |
const struct ast_bridge_blob *blob = stasis_message_data(message); |
| 722 |
const char *talking_status = ast_json_string_get(ast_json_object_get(blob->blob, "talking_status")); |
| 723 |
if (!talking_status) { |
| 724 |
return; |
| 725 |
} |
| 726 |
|
| 727 |
ast_str_append_event_header(&extra_text, "TalkingStatus", talking_status); |
| 728 |
if (!extra_text) { |
| 729 |
return; |
| 730 |
} |
| 731 |
|
| 732 |
if (!get_admin_header(&extra_text, message)) { |
| 733 |
confbridge_publish_manager_event(message, extra_text); |
| 734 |
} |
| 735 |
} |
| 736 |
|
| 737 |
void manager_confbridge_shutdown(void) { |
| 738 |
STASIS_MESSAGE_TYPE_CLEANUP(confbridge_start_type); |
| 739 |
STASIS_MESSAGE_TYPE_CLEANUP(confbridge_end_type); |
| 740 |
STASIS_MESSAGE_TYPE_CLEANUP(confbridge_join_type); |
| 741 |
STASIS_MESSAGE_TYPE_CLEANUP(confbridge_leave_type); |
| 742 |
STASIS_MESSAGE_TYPE_CLEANUP(confbridge_start_record_type); |
| 743 |
STASIS_MESSAGE_TYPE_CLEANUP(confbridge_stop_record_type); |
| 744 |
STASIS_MESSAGE_TYPE_CLEANUP(confbridge_mute_type); |
| 745 |
STASIS_MESSAGE_TYPE_CLEANUP(confbridge_unmute_type); |
| 746 |
STASIS_MESSAGE_TYPE_CLEANUP(confbridge_talking_type); |
| 747 |
STASIS_MESSAGE_TYPE_CLEANUP(confbridge_welcome_type); |
| 748 |
|
| 749 |
if (bridge_state_router) { |
| 750 |
stasis_message_router_unsubscribe(bridge_state_router); |
| 751 |
bridge_state_router = NULL; |
| 752 |
} |
| 753 |
|
| 754 |
if (channel_state_router) { |
| 755 |
stasis_message_router_unsubscribe(channel_state_router); |
| 756 |
channel_state_router = NULL; |
| 757 |
} |
| 758 |
} |
| 759 |
|
| 760 |
int manager_confbridge_init(void) |
| 761 |
{ |
| 762 |
STASIS_MESSAGE_TYPE_INIT(confbridge_start_type); |
| 763 |
STASIS_MESSAGE_TYPE_INIT(confbridge_end_type); |
| 764 |
STASIS_MESSAGE_TYPE_INIT(confbridge_join_type); |
| 765 |
STASIS_MESSAGE_TYPE_INIT(confbridge_leave_type); |
| 766 |
STASIS_MESSAGE_TYPE_INIT(confbridge_start_record_type); |
| 767 |
STASIS_MESSAGE_TYPE_INIT(confbridge_stop_record_type); |
| 768 |
STASIS_MESSAGE_TYPE_INIT(confbridge_mute_type); |
| 769 |
STASIS_MESSAGE_TYPE_INIT(confbridge_unmute_type); |
| 770 |
STASIS_MESSAGE_TYPE_INIT(confbridge_talking_type); |
| 771 |
STASIS_MESSAGE_TYPE_INIT(confbridge_welcome_type); |
| 772 |
|
| 773 |
bridge_state_router = stasis_message_router_create( |
| 774 |
ast_bridge_topic_all()); |
| 775 |
|
| 776 |
if (!bridge_state_router) { |
| 777 |
return -1; |
| 778 |
} |
| 779 |
|
| 780 |
if (stasis_message_router_add(bridge_state_router, |
| 781 |
confbridge_start_type(), |
| 782 |
confbridge_start_cb, |
| 783 |
NULL)) { |
| 784 |
manager_confbridge_shutdown(); |
| 785 |
return -1; |
| 786 |
} |
| 787 |
if (stasis_message_router_add(bridge_state_router, |
| 788 |
confbridge_end_type(), |
| 789 |
confbridge_end_cb, |
| 790 |
NULL)) { |
| 791 |
manager_confbridge_shutdown(); |
| 792 |
return -1; |
| 793 |
} |
| 794 |
if (stasis_message_router_add(bridge_state_router, |
| 795 |
confbridge_join_type(), |
| 796 |
confbridge_join_cb, |
| 797 |
NULL)) { |
| 798 |
manager_confbridge_shutdown(); |
| 799 |
return -1; |
| 800 |
} |
| 801 |
if (stasis_message_router_add(bridge_state_router, |
| 802 |
ast_attended_transfer_type(), |
| 803 |
confbridge_atxfer_cb, |
| 804 |
NULL)) { |
| 805 |
manager_confbridge_shutdown(); |
| 806 |
return -1; |
| 807 |
} |
| 808 |
if (stasis_message_router_add(bridge_state_router, |
| 809 |
confbridge_leave_type(), |
| 810 |
confbridge_leave_cb, |
| 811 |
NULL)) { |
| 812 |
manager_confbridge_shutdown(); |
| 813 |
return -1; |
| 814 |
} |
| 815 |
if (stasis_message_router_add(bridge_state_router, |
| 816 |
confbridge_start_record_type(), |
| 817 |
confbridge_start_record_cb, |
| 818 |
NULL)) { |
| 819 |
manager_confbridge_shutdown(); |
| 820 |
return -1; |
| 821 |
} |
| 822 |
if (stasis_message_router_add(bridge_state_router, |
| 823 |
confbridge_stop_record_type(), |
| 824 |
confbridge_stop_record_cb, |
| 825 |
NULL)) { |
| 826 |
manager_confbridge_shutdown(); |
| 827 |
return -1; |
| 828 |
} |
| 829 |
if (stasis_message_router_add(bridge_state_router, |
| 830 |
confbridge_mute_type(), |
| 831 |
confbridge_mute_cb, |
| 832 |
NULL)) { |
| 833 |
manager_confbridge_shutdown(); |
| 834 |
return -1; |
| 835 |
} |
| 836 |
if (stasis_message_router_add(bridge_state_router, |
| 837 |
confbridge_unmute_type(), |
| 838 |
confbridge_unmute_cb, |
| 839 |
NULL)) { |
| 840 |
manager_confbridge_shutdown(); |
| 841 |
return -1; |
| 842 |
} |
| 843 |
if (stasis_message_router_add(bridge_state_router, |
| 844 |
confbridge_talking_type(), |
| 845 |
confbridge_talking_cb, |
| 846 |
NULL)) { |
| 847 |
manager_confbridge_shutdown(); |
| 848 |
return -1; |
| 849 |
} |
| 850 |
|
| 851 |
channel_state_router = stasis_message_router_create( |
| 852 |
ast_channel_topic_all()); |
| 853 |
|
| 854 |
if (!channel_state_router) { |
| 855 |
manager_confbridge_shutdown(); |
| 856 |
return -1; |
| 857 |
} |
| 858 |
|
| 859 |
if (stasis_message_router_add(channel_state_router, |
| 860 |
confbridge_start_type(), |
| 861 |
confbridge_start_cb, |
| 862 |
NULL)) { |
| 863 |
manager_confbridge_shutdown(); |
| 864 |
return -1; |
| 865 |
} |
| 866 |
if (stasis_message_router_add(channel_state_router, |
| 867 |
confbridge_end_type(), |
| 868 |
confbridge_end_cb, |
| 869 |
NULL)) { |
| 870 |
manager_confbridge_shutdown(); |
| 871 |
return -1; |
| 872 |
} |
| 873 |
if (stasis_message_router_add(channel_state_router, |
| 874 |
confbridge_join_type(), |
| 875 |
confbridge_join_cb, |
| 876 |
NULL)) { |
| 877 |
manager_confbridge_shutdown(); |
| 878 |
return -1; |
| 879 |
} |
| 880 |
if (stasis_message_router_add(channel_state_router, |
| 881 |
confbridge_leave_type(), |
| 882 |
confbridge_leave_cb, |
| 883 |
NULL)) { |
| 884 |
manager_confbridge_shutdown(); |
| 885 |
return -1; |
| 886 |
} |
| 887 |
if (stasis_message_router_add(channel_state_router, |
| 888 |
confbridge_start_record_type(), |
| 889 |
confbridge_start_record_cb, |
| 890 |
NULL)) { |
| 891 |
manager_confbridge_shutdown(); |
| 892 |
return -1; |
| 893 |
} |
| 894 |
if (stasis_message_router_add(channel_state_router, |
| 895 |
confbridge_stop_record_type(), |
| 896 |
confbridge_stop_record_cb, |
| 897 |
NULL)) { |
| 898 |
manager_confbridge_shutdown(); |
| 899 |
return -1; |
| 900 |
} |
| 901 |
if (stasis_message_router_add(channel_state_router, |
| 902 |
confbridge_mute_type(), |
| 903 |
confbridge_mute_cb, |
| 904 |
NULL)) { |
| 905 |
manager_confbridge_shutdown(); |
| 906 |
return -1; |
| 907 |
} |
| 908 |
if (stasis_message_router_add(channel_state_router, |
| 909 |
confbridge_unmute_type(), |
| 910 |
confbridge_unmute_cb, |
| 911 |
NULL)) { |
| 912 |
manager_confbridge_shutdown(); |
| 913 |
return -1; |
| 914 |
} |
| 915 |
if (stasis_message_router_add(channel_state_router, |
| 916 |
confbridge_talking_type(), |
| 917 |
confbridge_talking_cb, |
| 918 |
NULL)) { |
| 919 |
manager_confbridge_shutdown(); |
| 920 |
return -1; |
| 921 |
} |
| 922 |
|
| 923 |
|
| 924 |
|
| 925 |
return 0; |
| 926 |
} |