| 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 |
#include "asterisk.h" |
| 30 |
|
| 31 |
#include "asterisk/callerid.h" |
| 32 |
#include "asterisk/channel.h" |
| 33 |
#include "asterisk/manager.h" |
| 34 |
#include "asterisk/stasis_message_router.h" |
| 35 |
#include "asterisk/pbx.h" |
| 36 |
#include "asterisk/stasis_channels.h" |
| 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 |
|
| 256 |
|
| 257 |
|
| 258 |
|
| 259 |
|
| 260 |
|
| 261 |
|
| 262 |
|
| 263 |
|
| 264 |
|
| 265 |
|
| 266 |
|
| 267 |
|
| 268 |
|
| 269 |
|
| 270 |
|
| 271 |
|
| 272 |
|
| 273 |
|
| 274 |
|
| 275 |
|
| 276 |
|
| 277 |
|
| 278 |
|
| 279 |
|
| 280 |
|
| 281 |
|
| 282 |
|
| 283 |
|
| 284 |
|
| 285 |
|
| 286 |
|
| 287 |
|
| 288 |
|
| 289 |
|
| 290 |
|
| 291 |
|
| 292 |
|
| 293 |
|
| 294 |
|
| 295 |
|
| 296 |
|
| 297 |
|
| 298 |
|
| 299 |
|
| 300 |
|
| 301 |
|
| 302 |
|
| 303 |
|
| 304 |
|
| 305 |
|
| 306 |
|
| 307 |
|
| 308 |
|
| 309 |
|
| 310 |
|
| 311 |
|
| 312 |
|
| 313 |
|
| 314 |
|
| 315 |
|
| 316 |
|
| 317 |
|
| 318 |
|
| 319 |
|
| 320 |
|
| 321 |
|
| 322 |
|
| 323 |
|
| 324 |
|
| 325 |
|
| 326 |
|
| 327 |
|
| 328 |
|
| 329 |
|
| 330 |
|
| 331 |
|
| 332 |
|
| 333 |
|
| 334 |
|
| 335 |
|
| 336 |
|
| 337 |
|
| 338 |
|
| 339 |
|
| 340 |
|
| 341 |
|
| 342 |
|
| 343 |
|
| 344 |
|
| 345 |
|
| 346 |
|
| 347 |
|
| 348 |
|
| 349 |
|
| 350 |
|
| 351 |
|
| 352 |
|
| 353 |
|
| 354 |
|
| 355 |
|
| 356 |
|
| 357 |
|
| 358 |
|
| 359 |
|
| 360 |
|
| 361 |
|
| 362 |
|
| 363 |
|
| 364 |
|
| 365 |
|
| 366 |
|
| 367 |
|
| 368 |
|
| 369 |
|
| 370 |
|
| 371 |
|
| 372 |
|
| 373 |
|
| 374 |
|
| 375 |
|
| 376 |
|
| 377 |
|
| 378 |
|
| 379 |
|
| 380 |
|
| 381 |
|
| 382 |
|
| 383 |
|
| 384 |
|
| 385 |
|
| 386 |
|
| 387 |
|
| 388 |
|
| 389 |
|
| 390 |
|
| 391 |
|
| 392 |
|
| 393 |
|
| 394 |
|
| 395 |
|
| 396 |
|
| 397 |
|
| 398 |
|
| 399 |
|
| 400 |
|
| 401 |
|
| 402 |
|
| 403 |
|
| 404 |
|
| 405 |
|
| 406 |
|
| 407 |
|
| 408 |
|
| 409 |
|
| 410 |
|
| 411 |
|
| 412 |
|
| 413 |
|
| 414 |
|
| 415 |
|
| 416 |
|
| 417 |
|
| 418 |
|
| 419 |
|
| 420 |
|
| 421 |
|
| 422 |
|
| 423 |
|
| 424 |
|
| 425 |
|
| 426 |
|
| 427 |
|
| 428 |
|
| 429 |
|
| 430 |
|
| 431 |
|
| 432 |
|
| 433 |
|
| 434 |
|
| 435 |
|
| 436 |
|
| 437 |
|
| 438 |
|
| 439 |
|
| 440 |
|
| 441 |
|
| 442 |
|
| 443 |
|
| 444 |
|
| 445 |
|
| 446 |
|
| 447 |
|
| 448 |
|
| 449 |
|
| 450 |
|
| 451 |
|
| 452 |
|
| 453 |
|
| 454 |
|
| 455 |
|
| 456 |
|
| 457 |
|
| 458 |
|
| 459 |
|
| 460 |
|
| 461 |
|
| 462 |
|
| 463 |
|
| 464 |
|
| 465 |
|
| 466 |
|
| 467 |
|
| 468 |
|
| 469 |
|
| 470 |
|
| 471 |
|
| 472 |
|
| 473 |
|
| 474 |
|
| 475 |
|
| 476 |
|
| 477 |
|
| 478 |
|
| 479 |
|
| 480 |
|
| 481 |
|
| 482 |
|
| 483 |
|
| 484 |
|
| 485 |
|
| 486 |
|
| 487 |
|
| 488 |
|
| 489 |
|
| 490 |
|
| 491 |
|
| 492 |
|
| 493 |
|
| 494 |
|
| 495 |
|
| 496 |
|
| 497 |
|
| 498 |
|
| 499 |
|
| 500 |
|
| 501 |
|
| 502 |
|
| 503 |
|
| 504 |
|
| 505 |
|
| 506 |
|
| 507 |
|
| 508 |
|
| 509 |
|
| 510 |
|
| 511 |
|
| 512 |
|
| 513 |
|
| 514 |
|
| 515 |
|
| 516 |
|
| 517 |
|
| 518 |
|
| 519 |
|
| 520 |
|
| 521 |
|
| 522 |
|
| 523 |
|
| 524 |
|
| 525 |
|
| 526 |
|
| 527 |
|
| 528 |
|
| 529 |
|
| 530 |
|
| 531 |
|
| 532 |
|
| 533 |
|
| 534 |
|
| 535 |
|
| 536 |
|
| 537 |
static struct stasis_forward *topic_forwarder; |
| 538 |
|
| 539 |
struct ast_str *ast_manager_build_channel_state_string_prefix( |
| 540 |
const struct ast_channel_snapshot *snapshot, |
| 541 |
const char *prefix) |
| 542 |
{ |
| 543 |
struct ast_str *out; |
| 544 |
char *caller_name; |
| 545 |
char *connected_name; |
| 546 |
int res; |
| 547 |
|
| 548 |
if (!snapshot || (snapshot->base->tech_properties & AST_CHAN_TP_INTERNAL)) { |
| 549 |
return NULL; |
| 550 |
} |
| 551 |
|
| 552 |
out = ast_str_create(1024); |
| 553 |
if (!out) { |
| 554 |
return NULL; |
| 555 |
} |
| 556 |
|
| 557 |
caller_name = ast_escape_c_alloc(snapshot->caller->name); |
| 558 |
connected_name = ast_escape_c_alloc(snapshot->connected->name); |
| 559 |
|
| 560 |
res = ast_str_set(&out, 0, |
| 561 |
"%sChannel: %s\r\n" |
| 562 |
"%sChannelState: %u\r\n" |
| 563 |
"%sChannelStateDesc: %s\r\n" |
| 564 |
"%sCallerIDNum: %s\r\n" |
| 565 |
"%sCallerIDName: %s\r\n" |
| 566 |
"%sConnectedLineNum: %s\r\n" |
| 567 |
"%sConnectedLineName: %s\r\n" |
| 568 |
"%sLanguage: %s\r\n" |
| 569 |
"%sAccountCode: %s\r\n" |
| 570 |
"%sContext: %s\r\n" |
| 571 |
"%sExten: %s\r\n" |
| 572 |
"%sPriority: %d\r\n" |
| 573 |
"%sUniqueid: %s\r\n" |
| 574 |
"%sLinkedid: %s\r\n", |
| 575 |
prefix, snapshot->base->name, |
| 576 |
prefix, snapshot->state, |
| 577 |
prefix, ast_state2str(snapshot->state), |
| 578 |
prefix, S_OR(snapshot->caller->number, "<unknown>"), |
| 579 |
prefix, S_OR(caller_name, "<unknown>"), |
| 580 |
prefix, S_OR(snapshot->connected->number, "<unknown>"), |
| 581 |
prefix, S_OR(connected_name, "<unknown>"), |
| 582 |
prefix, snapshot->base->language, |
| 583 |
prefix, snapshot->base->accountcode, |
| 584 |
prefix, snapshot->dialplan->context, |
| 585 |
prefix, snapshot->dialplan->exten, |
| 586 |
prefix, snapshot->dialplan->priority, |
| 587 |
prefix, snapshot->base->uniqueid, |
| 588 |
prefix, snapshot->peer->linkedid); |
| 589 |
|
| 590 |
ast_free(caller_name); |
| 591 |
ast_free(connected_name); |
| 592 |
|
| 593 |
if (!res) { |
| 594 |
ast_free(out); |
| 595 |
return NULL; |
| 596 |
} |
| 597 |
|
| 598 |
if (!ast_strlen_zero(snapshot->base->tenantid)) { |
| 599 |
ast_str_append(&out, 0, "%sTenantid: %s\r\n", prefix, snapshot->base->tenantid); |
| 600 |
} |
| 601 |
|
| 602 |
if (snapshot->manager_vars) { |
| 603 |
struct ast_var_t *var; |
| 604 |
char *val; |
| 605 |
AST_LIST_TRAVERSE(snapshot->manager_vars, var, entries) { |
| 606 |
val = ast_escape_c_alloc(var->value); |
| 607 |
ast_str_append(&out, 0, "%sChanVariable: %s=%s\r\n", |
| 608 |
prefix, |
| 609 |
var->name, S_OR(val, "")); |
| 610 |
ast_free(val); |
| 611 |
} |
| 612 |
} |
| 613 |
|
| 614 |
return out; |
| 615 |
} |
| 616 |
|
| 617 |
struct ast_str *ast_manager_build_channel_state_string( |
| 618 |
const struct ast_channel_snapshot *snapshot) |
| 619 |
{ |
| 620 |
return ast_manager_build_channel_state_string_prefix(snapshot, ""); |
| 621 |
} |
| 622 |
|
| 623 |
|
| 624 |
typedef struct ast_manager_event_blob *(*channel_snapshot_monitor)( |
| 625 |
struct ast_channel_snapshot *old_snapshot, |
| 626 |
struct ast_channel_snapshot *new_snapshot); |
| 627 |
|
| 628 |
|
| 629 |
static struct ast_manager_event_blob *channel_state_change( |
| 630 |
struct ast_channel_snapshot *old_snapshot, |
| 631 |
struct ast_channel_snapshot *new_snapshot) |
| 632 |
{ |
| 633 |
int is_hungup, was_hungup; |
| 634 |
|
| 635 |
|
| 636 |
|
| 637 |
|
| 638 |
|
| 639 |
|
| 640 |
if (!old_snapshot) { |
| 641 |
return ast_manager_event_blob_create( |
| 642 |
EVENT_FLAG_CALL, "Newchannel", NO_EXTRA_FIELDS); |
| 643 |
} |
| 644 |
|
| 645 |
was_hungup = ast_test_flag(&old_snapshot->flags, AST_FLAG_DEAD) ? 1 : 0; |
| 646 |
is_hungup = ast_test_flag(&new_snapshot->flags, AST_FLAG_DEAD) ? 1 : 0; |
| 647 |
|
| 648 |
if (!was_hungup && is_hungup) { |
| 649 |
if (new_snapshot->hangup->tech_cause) { |
| 650 |
return ast_manager_event_blob_create( |
| 651 |
EVENT_FLAG_CALL, "Hangup", |
| 652 |
"Cause: %d\r\n" |
| 653 |
"Cause-txt: %s\r\n" |
| 654 |
"TechCause: %d\r\n", |
| 655 |
new_snapshot->hangup->cause, |
| 656 |
ast_cause2str(new_snapshot->hangup->cause), |
| 657 |
new_snapshot->hangup->tech_cause); |
| 658 |
} else { |
| 659 |
return ast_manager_event_blob_create( |
| 660 |
EVENT_FLAG_CALL, "Hangup", |
| 661 |
"Cause: %d\r\n" |
| 662 |
"Cause-txt: %s\r\n", |
| 663 |
new_snapshot->hangup->cause, |
| 664 |
ast_cause2str(new_snapshot->hangup->cause)); |
| 665 |
} |
| 666 |
} |
| 667 |
|
| 668 |
if (old_snapshot->state != new_snapshot->state) { |
| 669 |
return ast_manager_event_blob_create( |
| 670 |
EVENT_FLAG_CALL, "Newstate", NO_EXTRA_FIELDS); |
| 671 |
} |
| 672 |
|
| 673 |
|
| 674 |
return NULL; |
| 675 |
} |
| 676 |
|
| 677 |
static struct ast_manager_event_blob *channel_newexten( |
| 678 |
struct ast_channel_snapshot *old_snapshot, |
| 679 |
struct ast_channel_snapshot *new_snapshot) |
| 680 |
{ |
| 681 |
|
| 682 |
if (ast_strlen_zero(new_snapshot->dialplan->appl)) { |
| 683 |
return NULL; |
| 684 |
} |
| 685 |
|
| 686 |
|
| 687 |
if (ast_test_flag(&new_snapshot->flags, AST_FLAG_DEAD)) { |
| 688 |
return NULL; |
| 689 |
} |
| 690 |
|
| 691 |
|
| 692 |
if (old_snapshot && ast_channel_snapshot_cep_equal(old_snapshot, new_snapshot)) { |
| 693 |
return NULL; |
| 694 |
} |
| 695 |
|
| 696 |
|
| 697 |
return ast_manager_event_blob_create( |
| 698 |
EVENT_FLAG_DIALPLAN, "Newexten", |
| 699 |
"Extension: %s\r\n" |
| 700 |
"Application: %s\r\n" |
| 701 |
"AppData: %s\r\n", |
| 702 |
new_snapshot->dialplan->exten, |
| 703 |
new_snapshot->dialplan->appl, |
| 704 |
new_snapshot->dialplan->data); |
| 705 |
} |
| 706 |
|
| 707 |
static struct ast_manager_event_blob *channel_new_callerid( |
| 708 |
struct ast_channel_snapshot *old_snapshot, |
| 709 |
struct ast_channel_snapshot *new_snapshot) |
| 710 |
{ |
| 711 |
struct ast_manager_event_blob *res; |
| 712 |
char *callerid; |
| 713 |
|
| 714 |
|
| 715 |
if (!old_snapshot) { |
| 716 |
return NULL; |
| 717 |
} |
| 718 |
|
| 719 |
if (ast_channel_snapshot_caller_id_equal(old_snapshot, new_snapshot)) { |
| 720 |
return NULL; |
| 721 |
} |
| 722 |
|
| 723 |
if (!(callerid = ast_escape_c_alloc( |
| 724 |
ast_describe_caller_presentation(new_snapshot->caller->pres)))) { |
| 725 |
return NULL; |
| 726 |
} |
| 727 |
|
| 728 |
res = ast_manager_event_blob_create( |
| 729 |
EVENT_FLAG_CALL, "NewCallerid", |
| 730 |
"CID-CallingPres: %d (%s)\r\n", |
| 731 |
new_snapshot->caller->pres, |
| 732 |
callerid); |
| 733 |
|
| 734 |
ast_free(callerid); |
| 735 |
return res; |
| 736 |
} |
| 737 |
|
| 738 |
static struct ast_manager_event_blob *channel_new_connected_line( |
| 739 |
struct ast_channel_snapshot *old_snapshot, |
| 740 |
struct ast_channel_snapshot *new_snapshot) |
| 741 |
{ |
| 742 |
|
| 743 |
if (!old_snapshot) { |
| 744 |
return NULL; |
| 745 |
} |
| 746 |
|
| 747 |
if (ast_channel_snapshot_connected_line_equal(old_snapshot, new_snapshot)) { |
| 748 |
return NULL; |
| 749 |
} |
| 750 |
|
| 751 |
return ast_manager_event_blob_create( |
| 752 |
EVENT_FLAG_CALL, "NewConnectedLine", "%s", ""); |
| 753 |
} |
| 754 |
|
| 755 |
static struct ast_manager_event_blob *channel_new_accountcode( |
| 756 |
struct ast_channel_snapshot *old_snapshot, |
| 757 |
struct ast_channel_snapshot *new_snapshot) |
| 758 |
{ |
| 759 |
if (!old_snapshot) { |
| 760 |
return NULL; |
| 761 |
} |
| 762 |
|
| 763 |
if (!strcmp(old_snapshot->base->accountcode, new_snapshot->base->accountcode)) { |
| 764 |
return NULL; |
| 765 |
} |
| 766 |
|
| 767 |
return ast_manager_event_blob_create( |
| 768 |
EVENT_FLAG_CALL, "NewAccountCode", |
| 769 |
"OldAccountCode: %s\r\n", old_snapshot->base->accountcode); |
| 770 |
} |
| 771 |
|
| 772 |
channel_snapshot_monitor channel_monitors[] = { |
| 773 |
channel_state_change, |
| 774 |
channel_newexten, |
| 775 |
channel_new_callerid, |
| 776 |
channel_new_accountcode, |
| 777 |
channel_new_connected_line, |
| 778 |
}; |
| 779 |
|
| 780 |
static void channel_snapshot_update(void *data, struct stasis_subscription *sub, |
| 781 |
struct stasis_message *message) |
| 782 |
{ |
| 783 |
RAII_VAR(struct ast_str *, channel_event_string, NULL, ast_free); |
| 784 |
struct ast_channel_snapshot_update *update; |
| 785 |
size_t i; |
| 786 |
|
| 787 |
update = stasis_message_data(message); |
| 788 |
|
| 789 |
for (i = 0; i < ARRAY_LEN(channel_monitors); ++i) { |
| 790 |
RAII_VAR(struct ast_manager_event_blob *, ev, NULL, ao2_cleanup); |
| 791 |
ev = channel_monitors[i](update->old_snapshot, update->new_snapshot); |
| 792 |
|
| 793 |
if (!ev) { |
| 794 |
continue; |
| 795 |
} |
| 796 |
|
| 797 |
|
| 798 |
if (!channel_event_string) { |
| 799 |
channel_event_string = |
| 800 |
ast_manager_build_channel_state_string(update->new_snapshot); |
| 801 |
if (!channel_event_string) { |
| 802 |
return; |
| 803 |
} |
| 804 |
} |
| 805 |
|
| 806 |
manager_event(ev->event_flags, ev->manager_event, "%s%s", |
| 807 |
ast_str_buffer(channel_event_string), |
| 808 |
ev->extra_fields); |
| 809 |
} |
| 810 |
} |
| 811 |
|
| 812 |
static void publish_basic_channel_event(const char *event, int class, struct ast_channel_snapshot *snapshot) |
| 813 |
{ |
| 814 |
RAII_VAR(struct ast_str *, channel_event_string, NULL, ast_free); |
| 815 |
|
| 816 |
channel_event_string = ast_manager_build_channel_state_string(snapshot); |
| 817 |
if (!channel_event_string) { |
| 818 |
return; |
| 819 |
} |
| 820 |
|
| 821 |
manager_event(class, event, |
| 822 |
"%s", |
| 823 |
ast_str_buffer(channel_event_string)); |
| 824 |
} |
| 825 |
|
| 826 |
static void channel_hangup_request_cb(void *data, |
| 827 |
struct stasis_subscription *sub, |
| 828 |
struct stasis_message *message) |
| 829 |
{ |
| 830 |
struct ast_channel_blob *obj = stasis_message_data(message); |
| 831 |
struct ast_str *extra; |
| 832 |
struct ast_str *channel_event_string; |
| 833 |
struct ast_json *cause; |
| 834 |
struct ast_json *tech_cause; |
| 835 |
int is_soft; |
| 836 |
char *manager_event = "HangupRequest"; |
| 837 |
|
| 838 |
if (!obj->snapshot) { |
| 839 |
|
| 840 |
return; |
| 841 |
} |
| 842 |
|
| 843 |
extra = ast_str_create(20); |
| 844 |
if (!extra) { |
| 845 |
return; |
| 846 |
} |
| 847 |
|
| 848 |
channel_event_string = ast_manager_build_channel_state_string(obj->snapshot); |
| 849 |
if (!channel_event_string) { |
| 850 |
ast_free(extra); |
| 851 |
return; |
| 852 |
} |
| 853 |
|
| 854 |
cause = ast_json_object_get(obj->blob, "cause"); |
| 855 |
if (cause) { |
| 856 |
ast_str_append(&extra, 0, |
| 857 |
"Cause: %jd\r\n", |
| 858 |
ast_json_integer_get(cause)); |
| 859 |
} |
| 860 |
|
| 861 |
tech_cause = ast_json_object_get(obj->blob, "tech_cause"); |
| 862 |
if (tech_cause) { |
| 863 |
ast_str_append(&extra, 0, |
| 864 |
"TechCause: %jd\r\n", |
| 865 |
ast_json_integer_get(tech_cause)); |
| 866 |
} |
| 867 |
|
| 868 |
is_soft = ast_json_is_true(ast_json_object_get(obj->blob, "soft")); |
| 869 |
if (is_soft) { |
| 870 |
manager_event = "SoftHangupRequest"; |
| 871 |
} |
| 872 |
|
| 873 |
manager_event(EVENT_FLAG_CALL, manager_event, |
| 874 |
"%s%s", |
| 875 |
ast_str_buffer(channel_event_string), |
| 876 |
ast_str_buffer(extra)); |
| 877 |
|
| 878 |
ast_free(channel_event_string); |
| 879 |
ast_free(extra); |
| 880 |
} |
| 881 |
|
| 882 |
static void channel_chanspy_stop_cb(void *data, struct stasis_subscription *sub, |
| 883 |
struct stasis_message *message) |
| 884 |
{ |
| 885 |
RAII_VAR(struct ast_str *, spyer_channel_string, NULL, ast_free); |
| 886 |
RAII_VAR(struct ast_str *, spyee_channel_string, NULL, ast_free); |
| 887 |
struct ast_channel_snapshot *spyer; |
| 888 |
struct ast_channel_snapshot *spyee; |
| 889 |
const char *spyee_info = ""; |
| 890 |
struct ast_multi_channel_blob *payload = stasis_message_data(message); |
| 891 |
|
| 892 |
spyer = ast_multi_channel_blob_get_channel(payload, "spyer_channel"); |
| 893 |
if (!spyer) { |
| 894 |
ast_log(AST_LOG_WARNING, "Received ChanSpy Stop event with no spyer channel!\n"); |
| 895 |
return; |
| 896 |
} |
| 897 |
|
| 898 |
spyer_channel_string = ast_manager_build_channel_state_string_prefix(spyer, "Spyer"); |
| 899 |
if (!spyer_channel_string) { |
| 900 |
return; |
| 901 |
} |
| 902 |
|
| 903 |
spyee = ast_multi_channel_blob_get_channel(payload, "spyee_channel"); |
| 904 |
if (spyee) { |
| 905 |
spyee_channel_string = ast_manager_build_channel_state_string_prefix(spyee, "Spyee"); |
| 906 |
if (spyee_channel_string) { |
| 907 |
spyee_info = ast_str_buffer(spyee_channel_string); |
| 908 |
} |
| 909 |
} |
| 910 |
|
| 911 |
manager_event(EVENT_FLAG_CALL, "ChanSpyStop", |
| 912 |
"%s%s", |
| 913 |
ast_str_buffer(spyer_channel_string), |
| 914 |
spyee_info); |
| 915 |
} |
| 916 |
|
| 917 |
static void channel_chanspy_start_cb(void *data, struct stasis_subscription *sub, |
| 918 |
struct stasis_message *message) |
| 919 |
{ |
| 920 |
RAII_VAR(struct ast_str *, spyer_channel_string, NULL, ast_free); |
| 921 |
RAII_VAR(struct ast_str *, spyee_channel_string, NULL, ast_free); |
| 922 |
struct ast_channel_snapshot *spyer; |
| 923 |
struct ast_channel_snapshot *spyee; |
| 924 |
struct ast_multi_channel_blob *payload = stasis_message_data(message); |
| 925 |
|
| 926 |
spyer = ast_multi_channel_blob_get_channel(payload, "spyer_channel"); |
| 927 |
if (!spyer) { |
| 928 |
ast_log(AST_LOG_WARNING, "Received ChanSpy Start event with no spyer channel!\n"); |
| 929 |
return; |
| 930 |
} |
| 931 |
spyee = ast_multi_channel_blob_get_channel(payload, "spyee_channel"); |
| 932 |
if (!spyee) { |
| 933 |
ast_log(AST_LOG_WARNING, "Received ChanSpy Start event with no spyee channel!\n"); |
| 934 |
return; |
| 935 |
} |
| 936 |
|
| 937 |
spyer_channel_string = ast_manager_build_channel_state_string_prefix(spyer, "Spyer"); |
| 938 |
if (!spyer_channel_string) { |
| 939 |
return; |
| 940 |
} |
| 941 |
spyee_channel_string = ast_manager_build_channel_state_string_prefix(spyee, "Spyee"); |
| 942 |
if (!spyee_channel_string) { |
| 943 |
return; |
| 944 |
} |
| 945 |
|
| 946 |
manager_event(EVENT_FLAG_CALL, "ChanSpyStart", |
| 947 |
"%s%s", |
| 948 |
ast_str_buffer(spyer_channel_string), |
| 949 |
ast_str_buffer(spyee_channel_string)); |
| 950 |
} |
| 951 |
|
| 952 |
static void channel_dtmf_begin_cb(void *data, struct stasis_subscription *sub, |
| 953 |
struct stasis_message *message) |
| 954 |
{ |
| 955 |
struct ast_channel_blob *obj = stasis_message_data(message); |
| 956 |
RAII_VAR(struct ast_str *, channel_event_string, NULL, ast_free); |
| 957 |
const char *digit = |
| 958 |
ast_json_string_get(ast_json_object_get(obj->blob, "digit")); |
| 959 |
const char *direction = |
| 960 |
ast_json_string_get(ast_json_object_get(obj->blob, "direction")); |
| 961 |
|
| 962 |
channel_event_string = ast_manager_build_channel_state_string(obj->snapshot); |
| 963 |
|
| 964 |
if (!channel_event_string) { |
| 965 |
return; |
| 966 |
} |
| 967 |
|
| 968 |
|
| 969 |
|
| 970 |
|
| 971 |
|
| 972 |
|
| 973 |
|
| 974 |
|
| 975 |
|
| 976 |
|
| 977 |
|
| 978 |
|
| 979 |
|
| 980 |
|
| 981 |
|
| 982 |
|
| 983 |
|
| 984 |
|
| 985 |
|
| 986 |
|
| 987 |
|
| 988 |
|
| 989 |
|
| 990 |
|
| 991 |
|
| 992 |
|
| 993 |
|
| 994 |
|
| 995 |
manager_event(EVENT_FLAG_DTMF, "DTMFBegin", |
| 996 |
"%s" |
| 997 |
"Digit: %s\r\n" |
| 998 |
"Direction: %s\r\n", |
| 999 |
ast_str_buffer(channel_event_string), |
| 1000 |
digit, direction); |
| 1001 |
} |
| 1002 |
|
| 1003 |
static void channel_dtmf_end_cb(void *data, struct stasis_subscription *sub, |
| 1004 |
struct stasis_message *message) |
| 1005 |
{ |
| 1006 |
struct ast_channel_blob *obj = stasis_message_data(message); |
| 1007 |
RAII_VAR(struct ast_str *, channel_event_string, NULL, ast_free); |
| 1008 |
const char *digit = |
| 1009 |
ast_json_string_get(ast_json_object_get(obj->blob, "digit")); |
| 1010 |
const char *direction = |
| 1011 |
ast_json_string_get(ast_json_object_get(obj->blob, "direction")); |
| 1012 |
long duration_ms = |
| 1013 |
ast_json_integer_get(ast_json_object_get(obj->blob, "duration_ms")); |
| 1014 |
|
| 1015 |
channel_event_string = ast_manager_build_channel_state_string(obj->snapshot); |
| 1016 |
|
| 1017 |
if (!channel_event_string) { |
| 1018 |
return; |
| 1019 |
} |
| 1020 |
|
| 1021 |
|
| 1022 |
|
| 1023 |
|
| 1024 |
|
| 1025 |
|
| 1026 |
|
| 1027 |
|
| 1028 |
|
| 1029 |
|
| 1030 |
|
| 1031 |
|
| 1032 |
|
| 1033 |
|
| 1034 |
|
| 1035 |
|
| 1036 |
|
| 1037 |
|
| 1038 |
|
| 1039 |
|
| 1040 |
|
| 1041 |
|
| 1042 |
|
| 1043 |
|
| 1044 |
|
| 1045 |
|
| 1046 |
|
| 1047 |
|
| 1048 |
|
| 1049 |
|
| 1050 |
|
| 1051 |
manager_event(EVENT_FLAG_DTMF, "DTMFEnd", |
| 1052 |
"%s" |
| 1053 |
"Digit: %s\r\n" |
| 1054 |
"DurationMs: %ld\r\n" |
| 1055 |
"Direction: %s\r\n", |
| 1056 |
ast_str_buffer(channel_event_string), |
| 1057 |
digit, duration_ms, direction); |
| 1058 |
} |
| 1059 |
|
| 1060 |
static void channel_flash_cb(void *data, struct stasis_subscription *sub, |
| 1061 |
struct stasis_message *message) |
| 1062 |
{ |
| 1063 |
struct ast_channel_blob *obj = stasis_message_data(message); |
| 1064 |
struct ast_str *channel_event_string; |
| 1065 |
|
| 1066 |
channel_event_string = ast_manager_build_channel_state_string(obj->snapshot); |
| 1067 |
if (!channel_event_string) { |
| 1068 |
return; |
| 1069 |
} |
| 1070 |
|
| 1071 |
|
| 1072 |
|
| 1073 |
|
| 1074 |
|
| 1075 |
|
| 1076 |
|
| 1077 |
|
| 1078 |
|
| 1079 |
|
| 1080 |
|
| 1081 |
|
| 1082 |
|
| 1083 |
|
| 1084 |
|
| 1085 |
|
| 1086 |
manager_event(EVENT_FLAG_CALL, "Flash", |
| 1087 |
"%s", |
| 1088 |
ast_str_buffer(channel_event_string)); |
| 1089 |
|
| 1090 |
ast_free(channel_event_string); |
| 1091 |
} |
| 1092 |
|
| 1093 |
static void channel_wink_cb(void *data, struct stasis_subscription *sub, |
| 1094 |
struct stasis_message *message) |
| 1095 |
{ |
| 1096 |
struct ast_channel_blob *obj = stasis_message_data(message); |
| 1097 |
struct ast_str *channel_event_string; |
| 1098 |
|
| 1099 |
channel_event_string = ast_manager_build_channel_state_string(obj->snapshot); |
| 1100 |
if (!channel_event_string) { |
| 1101 |
return; |
| 1102 |
} |
| 1103 |
|
| 1104 |
|
| 1105 |
|
| 1106 |
|
| 1107 |
|
| 1108 |
|
| 1109 |
|
| 1110 |
|
| 1111 |
|
| 1112 |
|
| 1113 |
|
| 1114 |
|
| 1115 |
|
| 1116 |
|
| 1117 |
|
| 1118 |
|
| 1119 |
manager_event(EVENT_FLAG_CALL, "Wink", |
| 1120 |
"%s", |
| 1121 |
ast_str_buffer(channel_event_string)); |
| 1122 |
|
| 1123 |
ast_free(channel_event_string); |
| 1124 |
} |
| 1125 |
|
| 1126 |
static void channel_hangup_handler_cb(void *data, struct stasis_subscription *sub, |
| 1127 |
struct stasis_message *message) |
| 1128 |
{ |
| 1129 |
RAII_VAR(struct ast_str *, channel_event_string, NULL, ast_free); |
| 1130 |
struct ast_channel_blob *payload = stasis_message_data(message); |
| 1131 |
const char *action = ast_json_string_get(ast_json_object_get(payload->blob, "type")); |
| 1132 |
const char *handler = ast_json_string_get(ast_json_object_get(payload->blob, "handler")); |
| 1133 |
const char *event; |
| 1134 |
|
| 1135 |
channel_event_string = ast_manager_build_channel_state_string(payload->snapshot); |
| 1136 |
|
| 1137 |
if (!channel_event_string) { |
| 1138 |
return; |
| 1139 |
} |
| 1140 |
|
| 1141 |
if (!strcmp(action, "run")) { |
| 1142 |
event = "HangupHandlerRun"; |
| 1143 |
} else if (!strcmp(action, "pop")) { |
| 1144 |
event = "HangupHandlerPop"; |
| 1145 |
} else if (!strcmp(action, "push")) { |
| 1146 |
event = "HangupHandlerPush"; |
| 1147 |
} else { |
| 1148 |
return; |
| 1149 |
} |
| 1150 |
manager_event(EVENT_FLAG_DIALPLAN, event, |
| 1151 |
"%s" |
| 1152 |
"Handler: %s\r\n", |
| 1153 |
ast_str_buffer(channel_event_string), |
| 1154 |
handler); |
| 1155 |
} |
| 1156 |
|
| 1157 |
static void channel_fax_cb(void *data, struct stasis_subscription *sub, |
| 1158 |
struct stasis_message *message) |
| 1159 |
{ |
| 1160 |
RAII_VAR(struct ast_str *, channel_event_string, NULL, ast_free); |
| 1161 |
RAII_VAR(struct ast_str *, event_buffer, ast_str_create(256), ast_free); |
| 1162 |
struct ast_channel_blob *payload = stasis_message_data(message); |
| 1163 |
const char *type = ast_json_string_get(ast_json_object_get(payload->blob, "type")); |
| 1164 |
struct ast_json *operation = ast_json_object_get(payload->blob, "operation"); |
| 1165 |
struct ast_json *status = ast_json_object_get(payload->blob, "status"); |
| 1166 |
struct ast_json *local_station_id = ast_json_object_get(payload->blob, "local_station_id"); |
| 1167 |
struct ast_json *remote_station_id = ast_json_object_get(payload->blob, "remote_station_id"); |
| 1168 |
struct ast_json *fax_pages = ast_json_object_get(payload->blob, "fax_pages"); |
| 1169 |
struct ast_json *fax_resolution = ast_json_object_get(payload->blob, "fax_resolution"); |
| 1170 |
struct ast_json *fax_bitrate = ast_json_object_get(payload->blob, "fax_bitrate"); |
| 1171 |
struct ast_json *filenames = ast_json_object_get(payload->blob, "filenames"); |
| 1172 |
const char *event; |
| 1173 |
size_t array_len; |
| 1174 |
size_t i; |
| 1175 |
|
| 1176 |
if (!event_buffer) { |
| 1177 |
return; |
| 1178 |
} |
| 1179 |
|
| 1180 |
channel_event_string = ast_manager_build_channel_state_string(payload->snapshot); |
| 1181 |
if (!channel_event_string) { |
| 1182 |
return; |
| 1183 |
} |
| 1184 |
|
| 1185 |
if (!strcmp(type, "status")) { |
| 1186 |
event = "FAXStatus"; |
| 1187 |
} else if (!strcmp(type, "receive")) { |
| 1188 |
event = "ReceiveFAX"; |
| 1189 |
} else if (!strcmp(type, "send")) { |
| 1190 |
event = "SendFAX"; |
| 1191 |
} else { |
| 1192 |
return; |
| 1193 |
} |
| 1194 |
|
| 1195 |
if (operation) { |
| 1196 |
ast_str_append(&event_buffer, 0, "Operation: %s\r\n", ast_json_string_get(operation)); |
| 1197 |
} |
| 1198 |
if (status) { |
| 1199 |
ast_str_append(&event_buffer, 0, "Status: %s\r\n", ast_json_string_get(status)); |
| 1200 |
} |
| 1201 |
if (local_station_id) { |
| 1202 |
ast_str_append(&event_buffer, 0, "LocalStationID: %s\r\n", ast_json_string_get(local_station_id)); |
| 1203 |
} |
| 1204 |
if (remote_station_id) { |
| 1205 |
ast_str_append(&event_buffer, 0, "RemoteStationID: %s\r\n", ast_json_string_get(remote_station_id)); |
| 1206 |
} |
| 1207 |
if (fax_pages) { |
| 1208 |
ast_str_append(&event_buffer, 0, "PagesTransferred: %s\r\n", ast_json_string_get(fax_pages)); |
| 1209 |
} |
| 1210 |
if (fax_resolution) { |
| 1211 |
ast_str_append(&event_buffer, 0, "Resolution: %s\r\n", ast_json_string_get(fax_resolution)); |
| 1212 |
} |
| 1213 |
if (fax_bitrate) { |
| 1214 |
ast_str_append(&event_buffer, 0, "TransferRate: %s\r\n", ast_json_string_get(fax_bitrate)); |
| 1215 |
} |
| 1216 |
if (filenames) { |
| 1217 |
array_len = ast_json_array_size(filenames); |
| 1218 |
for (i = 0; i < array_len; i++) { |
| 1219 |
ast_str_append(&event_buffer, 0, "FileName: %s\r\n", ast_json_string_get(ast_json_array_get(filenames, i))); |
| 1220 |
} |
| 1221 |
} |
| 1222 |
|
| 1223 |
manager_event(EVENT_FLAG_CALL, event, |
| 1224 |
"%s" |
| 1225 |
"%s", |
| 1226 |
ast_str_buffer(channel_event_string), |
| 1227 |
ast_str_buffer(event_buffer)); |
| 1228 |
} |
| 1229 |
|
| 1230 |
static void channel_moh_start_cb(void *data, struct stasis_subscription *sub, |
| 1231 |
struct stasis_message *message) |
| 1232 |
{ |
| 1233 |
struct ast_channel_blob *payload = stasis_message_data(message); |
| 1234 |
struct ast_json *blob = payload->blob; |
| 1235 |
RAII_VAR(struct ast_str *, channel_event_string, NULL, ast_free); |
| 1236 |
|
| 1237 |
channel_event_string = ast_manager_build_channel_state_string(payload->snapshot); |
| 1238 |
if (!channel_event_string) { |
| 1239 |
return; |
| 1240 |
} |
| 1241 |
|
| 1242 |
manager_event(EVENT_FLAG_CALL, "MusicOnHoldStart", |
| 1243 |
"%s" |
| 1244 |
"Class: %s\r\n", |
| 1245 |
ast_str_buffer(channel_event_string), |
| 1246 |
ast_json_string_get(ast_json_object_get(blob, "class"))); |
| 1247 |
|
| 1248 |
} |
| 1249 |
|
| 1250 |
static void channel_moh_stop_cb(void *data, struct stasis_subscription *sub, |
| 1251 |
struct stasis_message *message) |
| 1252 |
{ |
| 1253 |
struct ast_channel_blob *payload = stasis_message_data(message); |
| 1254 |
|
| 1255 |
publish_basic_channel_event("MusicOnHoldStop", EVENT_FLAG_CALL, payload->snapshot); |
| 1256 |
} |
| 1257 |
|
| 1258 |
static void channel_mixmonitor_start_cb(void *data, struct stasis_subscription *sub, |
| 1259 |
struct stasis_message *message) |
| 1260 |
{ |
| 1261 |
struct ast_channel_blob *payload = stasis_message_data(message); |
| 1262 |
|
| 1263 |
publish_basic_channel_event("MixMonitorStart", EVENT_FLAG_CALL, payload->snapshot); |
| 1264 |
} |
| 1265 |
|
| 1266 |
static void channel_mixmonitor_stop_cb(void *data, struct stasis_subscription *sub, |
| 1267 |
struct stasis_message *message) |
| 1268 |
{ |
| 1269 |
struct ast_channel_blob *payload = stasis_message_data(message); |
| 1270 |
|
| 1271 |
publish_basic_channel_event("MixMonitorStop", EVENT_FLAG_CALL, payload->snapshot); |
| 1272 |
} |
| 1273 |
|
| 1274 |
static void channel_mixmonitor_mute_cb(void *data, struct stasis_subscription *sub, |
| 1275 |
struct stasis_message *message) |
| 1276 |
{ |
| 1277 |
RAII_VAR(struct ast_str *, channel_event_string, NULL, ast_free); |
| 1278 |
RAII_VAR(struct ast_str *, event_buffer, ast_str_create(64), ast_free); |
| 1279 |
struct ast_channel_blob *payload = stasis_message_data(message); |
| 1280 |
struct ast_json *direction = ast_json_object_get(payload->blob, "direction"); |
| 1281 |
const int state = ast_json_is_true(ast_json_object_get(payload->blob, "state")); |
| 1282 |
|
| 1283 |
if (!event_buffer) { |
| 1284 |
return; |
| 1285 |
} |
| 1286 |
|
| 1287 |
channel_event_string = ast_manager_build_channel_state_string(payload->snapshot); |
| 1288 |
if (!channel_event_string) { |
| 1289 |
return; |
| 1290 |
} |
| 1291 |
|
| 1292 |
if (direction) { |
| 1293 |
ast_str_append(&event_buffer, 0, "Direction: %s\r\n", ast_json_string_get(direction)); |
| 1294 |
} |
| 1295 |
ast_str_append(&event_buffer, 0, "State: %s\r\n", state ? "1" : "0"); |
| 1296 |
|
| 1297 |
manager_event(EVENT_FLAG_CALL, "MixMonitorMute", |
| 1298 |
"%s" |
| 1299 |
"%s", |
| 1300 |
ast_str_buffer(channel_event_string), |
| 1301 |
ast_str_buffer(event_buffer)); |
| 1302 |
|
| 1303 |
} |
| 1304 |
|
| 1305 |
static int dial_status_end(const char *dialstatus) |
| 1306 |
{ |
| 1307 |
return (strcmp(dialstatus, "RINGING") && |
| 1308 |
strcmp(dialstatus, "PROCEEDING") && |
| 1309 |
strcmp(dialstatus, "PROGRESS")); |
| 1310 |
} |
| 1311 |
|
| 1312 |
|
| 1313 |
|
| 1314 |
|
| 1315 |
static void channel_dial_cb(void *data, struct stasis_subscription *sub, |
| 1316 |
struct stasis_message *message) |
| 1317 |
{ |
| 1318 |
struct ast_multi_channel_blob *obj = stasis_message_data(message); |
| 1319 |
const char *dialstatus; |
| 1320 |
const char *dialstring; |
| 1321 |
const char *forward; |
| 1322 |
struct ast_channel_snapshot *caller; |
| 1323 |
struct ast_channel_snapshot *peer; |
| 1324 |
RAII_VAR(struct ast_str *, caller_event_string, NULL, ast_free); |
| 1325 |
RAII_VAR(struct ast_str *, peer_event_string, NULL, ast_free); |
| 1326 |
|
| 1327 |
caller = ast_multi_channel_blob_get_channel(obj, "caller"); |
| 1328 |
peer = ast_multi_channel_blob_get_channel(obj, "peer"); |
| 1329 |
|
| 1330 |
|
| 1331 |
ast_assert(peer != NULL); |
| 1332 |
peer_event_string = ast_manager_build_channel_state_string_prefix(peer, "Dest"); |
| 1333 |
if (!peer_event_string) { |
| 1334 |
return; |
| 1335 |
} |
| 1336 |
|
| 1337 |
if (caller && !(caller_event_string = ast_manager_build_channel_state_string(caller))) { |
| 1338 |
return; |
| 1339 |
} |
| 1340 |
|
| 1341 |
dialstatus = ast_json_string_get(ast_json_object_get(ast_multi_channel_blob_get_json(obj), "dialstatus")); |
| 1342 |
dialstring = ast_json_string_get(ast_json_object_get(ast_multi_channel_blob_get_json(obj), "dialstring")); |
| 1343 |
forward = ast_json_string_get(ast_json_object_get(ast_multi_channel_blob_get_json(obj), "forward")); |
| 1344 |
if (ast_strlen_zero(dialstatus)) { |
| 1345 |
manager_event(EVENT_FLAG_CALL, "DialBegin", |
| 1346 |
"%s" |
| 1347 |
"%s" |
| 1348 |
"DialString: %s\r\n", |
| 1349 |
caller_event_string ? ast_str_buffer(caller_event_string) : "", |
| 1350 |
ast_str_buffer(peer_event_string), |
| 1351 |
S_OR(dialstring, "unknown")); |
| 1352 |
} else { |
| 1353 |
int forwarded = !ast_strlen_zero(forward); |
| 1354 |
|
| 1355 |
manager_event(EVENT_FLAG_CALL, dial_status_end(dialstatus) ? "DialEnd" : "DialState", |
| 1356 |
"%s" |
| 1357 |
"%s" |
| 1358 |
"%s%s%s" |
| 1359 |
"DialStatus: %s\r\n", |
| 1360 |
caller_event_string ? ast_str_buffer(caller_event_string) : "", |
| 1361 |
ast_str_buffer(peer_event_string), |
| 1362 |
forwarded ? "Forward: " : "", S_OR(forward, ""), forwarded ? "\r\n" : "", |
| 1363 |
S_OR(dialstatus, "unknown")); |
| 1364 |
} |
| 1365 |
|
| 1366 |
} |
| 1367 |
|
| 1368 |
static void channel_hold_cb(void *data, struct stasis_subscription *sub, |
| 1369 |
struct stasis_message *message) |
| 1370 |
{ |
| 1371 |
struct ast_channel_blob *obj = stasis_message_data(message); |
| 1372 |
struct ast_str *musicclass_string = ast_str_create(32); |
| 1373 |
struct ast_str *channel_event_string; |
| 1374 |
|
| 1375 |
if (!musicclass_string) { |
| 1376 |
return; |
| 1377 |
} |
| 1378 |
|
| 1379 |
channel_event_string = ast_manager_build_channel_state_string(obj->snapshot); |
| 1380 |
if (!channel_event_string) { |
| 1381 |
ast_free(musicclass_string); |
| 1382 |
return; |
| 1383 |
} |
| 1384 |
|
| 1385 |
if (obj->blob) { |
| 1386 |
const char *musicclass; |
| 1387 |
|
| 1388 |
musicclass = ast_json_string_get(ast_json_object_get(obj->blob, "musicclass")); |
| 1389 |
|
| 1390 |
if (!ast_strlen_zero(musicclass)) { |
| 1391 |
ast_str_set(&musicclass_string, 0, "MusicClass: %s\r\n", musicclass); |
| 1392 |
} |
| 1393 |
} |
| 1394 |
|
| 1395 |
manager_event(EVENT_FLAG_CALL, "Hold", |
| 1396 |
"%s" |
| 1397 |
"%s", |
| 1398 |
ast_str_buffer(channel_event_string), |
| 1399 |
ast_str_buffer(musicclass_string)); |
| 1400 |
|
| 1401 |
ast_free(musicclass_string); |
| 1402 |
ast_free(channel_event_string); |
| 1403 |
} |
| 1404 |
|
| 1405 |
static void channel_unhold_cb(void *data, struct stasis_subscription *sub, |
| 1406 |
struct stasis_message *message) |
| 1407 |
{ |
| 1408 |
struct ast_channel_blob *obj = stasis_message_data(message); |
| 1409 |
struct ast_str *channel_event_string; |
| 1410 |
|
| 1411 |
channel_event_string = ast_manager_build_channel_state_string(obj->snapshot); |
| 1412 |
if (!channel_event_string) { |
| 1413 |
return; |
| 1414 |
} |
| 1415 |
|
| 1416 |
manager_event(EVENT_FLAG_CALL, "Unhold", |
| 1417 |
"%s", |
| 1418 |
ast_str_buffer(channel_event_string)); |
| 1419 |
|
| 1420 |
ast_free(channel_event_string); |
| 1421 |
} |
| 1422 |
|
| 1423 |
static void manager_channels_shutdown(void) |
| 1424 |
{ |
| 1425 |
stasis_forward_cancel(topic_forwarder); |
| 1426 |
topic_forwarder = NULL; |
| 1427 |
} |
| 1428 |
|
| 1429 |
int manager_channels_init(void) |
| 1430 |
{ |
| 1431 |
int ret = 0; |
| 1432 |
struct stasis_topic *manager_topic; |
| 1433 |
struct stasis_topic *channel_topic; |
| 1434 |
struct stasis_message_router *message_router; |
| 1435 |
|
| 1436 |
manager_topic = ast_manager_get_topic(); |
| 1437 |
if (!manager_topic) { |
| 1438 |
return -1; |
| 1439 |
} |
| 1440 |
message_router = ast_manager_get_message_router(); |
| 1441 |
if (!message_router) { |
| 1442 |
return -1; |
| 1443 |
} |
| 1444 |
channel_topic = ast_channel_topic_all(); |
| 1445 |
if (!channel_topic) { |
| 1446 |
return -1; |
| 1447 |
} |
| 1448 |
|
| 1449 |
topic_forwarder = stasis_forward_all(channel_topic, manager_topic); |
| 1450 |
if (!topic_forwarder) { |
| 1451 |
return -1; |
| 1452 |
} |
| 1453 |
|
| 1454 |
ast_register_cleanup(manager_channels_shutdown); |
| 1455 |
|
| 1456 |
|
| 1457 |
|
| 1458 |
|
| 1459 |
|
| 1460 |
ret |= stasis_message_router_add(message_router, |
| 1461 |
ast_channel_snapshot_type(), channel_snapshot_update, NULL); |
| 1462 |
|
| 1463 |
ret |= stasis_message_router_add(message_router, |
| 1464 |
ast_channel_dtmf_begin_type(), channel_dtmf_begin_cb, NULL); |
| 1465 |
|
| 1466 |
ret |= stasis_message_router_add(message_router, |
| 1467 |
ast_channel_dtmf_end_type(), channel_dtmf_end_cb, NULL); |
| 1468 |
|
| 1469 |
ret |= stasis_message_router_add(message_router, |
| 1470 |
ast_channel_flash_type(), channel_flash_cb, NULL); |
| 1471 |
|
| 1472 |
ret |= stasis_message_router_add(message_router, |
| 1473 |
ast_channel_wink_type(), channel_wink_cb, NULL); |
| 1474 |
|
| 1475 |
ret |= stasis_message_router_add(message_router, |
| 1476 |
ast_channel_hangup_request_type(), channel_hangup_request_cb, |
| 1477 |
NULL); |
| 1478 |
|
| 1479 |
ret |= stasis_message_router_add(message_router, |
| 1480 |
ast_channel_dial_type(), channel_dial_cb, NULL); |
| 1481 |
|
| 1482 |
ret |= stasis_message_router_add(message_router, |
| 1483 |
ast_channel_hold_type(), channel_hold_cb, NULL); |
| 1484 |
|
| 1485 |
ret |= stasis_message_router_add(message_router, |
| 1486 |
ast_channel_unhold_type(), channel_unhold_cb, NULL); |
| 1487 |
|
| 1488 |
ret |= stasis_message_router_add(message_router, |
| 1489 |
ast_channel_fax_type(), channel_fax_cb, NULL); |
| 1490 |
|
| 1491 |
ret |= stasis_message_router_add(message_router, |
| 1492 |
ast_channel_chanspy_start_type(), channel_chanspy_start_cb, |
| 1493 |
NULL); |
| 1494 |
|
| 1495 |
ret |= stasis_message_router_add(message_router, |
| 1496 |
ast_channel_chanspy_stop_type(), channel_chanspy_stop_cb, NULL); |
| 1497 |
|
| 1498 |
ret |= stasis_message_router_add(message_router, |
| 1499 |
ast_channel_hangup_handler_type(), channel_hangup_handler_cb, |
| 1500 |
NULL); |
| 1501 |
|
| 1502 |
ret |= stasis_message_router_add(message_router, |
| 1503 |
ast_channel_moh_start_type(), channel_moh_start_cb, NULL); |
| 1504 |
|
| 1505 |
ret |= stasis_message_router_add(message_router, |
| 1506 |
ast_channel_moh_stop_type(), channel_moh_stop_cb, NULL); |
| 1507 |
|
| 1508 |
ret |= stasis_message_router_add(message_router, |
| 1509 |
ast_channel_mixmonitor_start_type(), channel_mixmonitor_start_cb, NULL); |
| 1510 |
|
| 1511 |
ret |= stasis_message_router_add(message_router, |
| 1512 |
ast_channel_mixmonitor_stop_type(), channel_mixmonitor_stop_cb, NULL); |
| 1513 |
|
| 1514 |
ret |= stasis_message_router_add(message_router, |
| 1515 |
ast_channel_mixmonitor_mute_type(), channel_mixmonitor_mute_cb, NULL); |
| 1516 |
|
| 1517 |
|
| 1518 |
|
| 1519 |
|
| 1520 |
if (ret) { |
| 1521 |
manager_channels_shutdown(); |
| 1522 |
return -1; |
| 1523 |
} |
| 1524 |
|
| 1525 |
return 0; |
| 1526 |
} |