| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
#include "asterisk.h" |
| 34 |
|
| 35 |
#include <sys/time.h> |
| 36 |
#include <signal.h> |
| 37 |
#include <sys/stat.h> |
| 38 |
#include <netinet/in.h> |
| 39 |
|
| 40 |
#include "asterisk/paths.h" |
| 41 |
#include "asterisk/lock.h" |
| 42 |
#include "asterisk/file.h" |
| 43 |
#include "asterisk/channel.h" |
| 44 |
#include "asterisk/pbx.h" |
| 45 |
#include "asterisk/module.h" |
| 46 |
#include "asterisk/translate.h" |
| 47 |
#include "asterisk/say.h" |
| 48 |
#include "asterisk/config.h" |
| 49 |
#include "asterisk/features.h" |
| 50 |
#include "asterisk/musiconhold.h" |
| 51 |
#include "asterisk/callerid.h" |
| 52 |
#include "asterisk/utils.h" |
| 53 |
#include "asterisk/app.h" |
| 54 |
#include "asterisk/causes.h" |
| 55 |
#include "asterisk/rtp_engine.h" |
| 56 |
#include "asterisk/manager.h" |
| 57 |
#include "asterisk/privacy.h" |
| 58 |
#include "asterisk/stringfields.h" |
| 59 |
#include "asterisk/dsp.h" |
| 60 |
#include "asterisk/aoc.h" |
| 61 |
#include "asterisk/ccss.h" |
| 62 |
#include "asterisk/indications.h" |
| 63 |
#include "asterisk/framehook.h" |
| 64 |
#include "asterisk/dial.h" |
| 65 |
#include "asterisk/stasis_channels.h" |
| 66 |
#include "asterisk/bridge_after.h" |
| 67 |
#include "asterisk/features_config.h" |
| 68 |
#include "asterisk/max_forwards.h" |
| 69 |
#include "asterisk/stream.h" |
| 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 |
|
| 538 |
|
| 539 |
|
| 540 |
|
| 541 |
|
| 542 |
|
| 543 |
|
| 544 |
|
| 545 |
|
| 546 |
|
| 547 |
|
| 548 |
|
| 549 |
|
| 550 |
|
| 551 |
|
| 552 |
|
| 553 |
|
| 554 |
|
| 555 |
|
| 556 |
|
| 557 |
|
| 558 |
|
| 559 |
|
| 560 |
|
| 561 |
|
| 562 |
|
| 563 |
|
| 564 |
|
| 565 |
|
| 566 |
|
| 567 |
|
| 568 |
|
| 569 |
|
| 570 |
|
| 571 |
|
| 572 |
|
| 573 |
|
| 574 |
|
| 575 |
|
| 576 |
|
| 577 |
|
| 578 |
|
| 579 |
|
| 580 |
|
| 581 |
|
| 582 |
|
| 583 |
|
| 584 |
|
| 585 |
|
| 586 |
|
| 587 |
|
| 588 |
|
| 589 |
|
| 590 |
|
| 591 |
|
| 592 |
|
| 593 |
|
| 594 |
|
| 595 |
|
| 596 |
|
| 597 |
|
| 598 |
|
| 599 |
|
| 600 |
|
| 601 |
|
| 602 |
|
| 603 |
|
| 604 |
|
| 605 |
|
| 606 |
|
| 607 |
|
| 608 |
|
| 609 |
|
| 610 |
|
| 611 |
|
| 612 |
|
| 613 |
|
| 614 |
|
| 615 |
|
| 616 |
|
| 617 |
|
| 618 |
|
| 619 |
|
| 620 |
|
| 621 |
|
| 622 |
|
| 623 |
|
| 624 |
|
| 625 |
|
| 626 |
|
| 627 |
|
| 628 |
|
| 629 |
|
| 630 |
|
| 631 |
|
| 632 |
|
| 633 |
|
| 634 |
|
| 635 |
|
| 636 |
|
| 637 |
|
| 638 |
|
| 639 |
|
| 640 |
|
| 641 |
|
| 642 |
|
| 643 |
|
| 644 |
|
| 645 |
|
| 646 |
|
| 647 |
|
| 648 |
|
| 649 |
|
| 650 |
|
| 651 |
|
| 652 |
|
| 653 |
|
| 654 |
|
| 655 |
|
| 656 |
|
| 657 |
|
| 658 |
|
| 659 |
|
| 660 |
|
| 661 |
|
| 662 |
|
| 663 |
|
| 664 |
|
| 665 |
|
| 666 |
|
| 667 |
|
| 668 |
|
| 669 |
|
| 670 |
static const char app[] = "Dial"; |
| 671 |
static const char rapp[] = "RetryDial"; |
| 672 |
|
| 673 |
enum { |
| 674 |
OPT_ANNOUNCE = (1 << 0), |
| 675 |
OPT_RESETCDR = (1 << 1), |
| 676 |
OPT_DTMF_EXIT = (1 << 2), |
| 677 |
OPT_SENDDTMF = (1 << 3), |
| 678 |
OPT_FORCECLID = (1 << 4), |
| 679 |
OPT_GO_ON = (1 << 5), |
| 680 |
OPT_CALLEE_HANGUP = (1 << 6), |
| 681 |
OPT_CALLER_HANGUP = (1 << 7), |
| 682 |
OPT_ORIGINAL_CLID = (1 << 8), |
| 683 |
OPT_DURATION_LIMIT = (1 << 9), |
| 684 |
OPT_MUSICBACK = (1 << 10), |
| 685 |
OPT_SCREEN_NOINTRO = (1 << 12), |
| 686 |
OPT_SCREEN_NOCALLERID = (1 << 13), |
| 687 |
OPT_IGNORE_CONNECTEDLINE = (1 << 14), |
| 688 |
OPT_SCREENING = (1 << 15), |
| 689 |
OPT_PRIVACY = (1 << 16), |
| 690 |
OPT_RINGBACK = (1 << 17), |
| 691 |
OPT_DURATION_STOP = (1 << 18), |
| 692 |
OPT_CALLEE_TRANSFER = (1 << 19), |
| 693 |
OPT_CALLER_TRANSFER = (1 << 20), |
| 694 |
OPT_CALLEE_MONITOR = (1 << 21), |
| 695 |
OPT_CALLER_MONITOR = (1 << 22), |
| 696 |
OPT_GOTO = (1 << 23), |
| 697 |
OPT_OPERMODE = (1 << 24), |
| 698 |
OPT_CALLEE_PARK = (1 << 25), |
| 699 |
OPT_CALLER_PARK = (1 << 26), |
| 700 |
OPT_IGNORE_FORWARDING = (1 << 27), |
| 701 |
OPT_CALLEE_GOSUB = (1 << 28), |
| 702 |
OPT_CALLEE_MIXMONITOR = (1 << 29), |
| 703 |
OPT_CALLER_MIXMONITOR = (1 << 30), |
| 704 |
}; |
| 705 |
|
| 706 |
|
| 707 |
#define DIAL_STILLGOING (1LLU << 31) |
| 708 |
#define DIAL_NOFORWARDHTML (1LLU << 32) |
| 709 |
#define DIAL_CALLERID_ABSENT (1LLU << 33) |
| 710 |
#define OPT_CANCEL_ELSEWHERE (1LLU << 34) |
| 711 |
#define OPT_PEER_H (1LLU << 35) |
| 712 |
#define OPT_CALLEE_GO_ON (1LLU << 36) |
| 713 |
#define OPT_CANCEL_TIMEOUT (1LLU << 37) |
| 714 |
#define OPT_FORCE_CID_TAG (1LLU << 38) |
| 715 |
#define OPT_FORCE_CID_PRES (1LLU << 39) |
| 716 |
#define OPT_CALLER_ANSWER (1LLU << 40) |
| 717 |
#define OPT_PREDIAL_CALLEE (1LLU << 41) |
| 718 |
#define OPT_PREDIAL_CALLER (1LLU << 42) |
| 719 |
#define OPT_RING_WITH_EARLY_MEDIA (1LLU << 43) |
| 720 |
#define OPT_HANGUPCAUSE (1LLU << 44) |
| 721 |
#define OPT_HEARPULSING (1LLU << 45) |
| 722 |
#define OPT_TOPOLOGY_PRESERVE (1LLU << 46) |
| 723 |
|
| 724 |
enum { |
| 725 |
OPT_ARG_ANNOUNCE = 0, |
| 726 |
OPT_ARG_SENDDTMF, |
| 727 |
OPT_ARG_GOTO, |
| 728 |
OPT_ARG_DURATION_LIMIT, |
| 729 |
OPT_ARG_MUSICBACK, |
| 730 |
OPT_ARG_RINGBACK, |
| 731 |
OPT_ARG_CALLEE_GOSUB, |
| 732 |
OPT_ARG_CALLEE_GO_ON, |
| 733 |
OPT_ARG_PRIVACY, |
| 734 |
OPT_ARG_DURATION_STOP, |
| 735 |
OPT_ARG_OPERMODE, |
| 736 |
OPT_ARG_SCREEN_NOINTRO, |
| 737 |
OPT_ARG_ORIGINAL_CLID, |
| 738 |
OPT_ARG_FORCECLID, |
| 739 |
OPT_ARG_FORCE_CID_TAG, |
| 740 |
OPT_ARG_FORCE_CID_PRES, |
| 741 |
OPT_ARG_PREDIAL_CALLEE, |
| 742 |
OPT_ARG_PREDIAL_CALLER, |
| 743 |
OPT_ARG_HANGUPCAUSE, |
| 744 |
|
| 745 |
OPT_ARG_ARRAY_SIZE |
| 746 |
}; |
| 747 |
|
| 748 |
AST_APP_OPTIONS(dial_exec_options, BEGIN_OPTIONS |
| 749 |
AST_APP_OPTION_ARG('A', OPT_ANNOUNCE, OPT_ARG_ANNOUNCE), |
| 750 |
AST_APP_OPTION('a', OPT_CALLER_ANSWER), |
| 751 |
AST_APP_OPTION_ARG('b', OPT_PREDIAL_CALLEE, OPT_ARG_PREDIAL_CALLEE), |
| 752 |
AST_APP_OPTION_ARG('B', OPT_PREDIAL_CALLER, OPT_ARG_PREDIAL_CALLER), |
| 753 |
AST_APP_OPTION('C', OPT_RESETCDR), |
| 754 |
AST_APP_OPTION('c', OPT_CANCEL_ELSEWHERE), |
| 755 |
AST_APP_OPTION('d', OPT_DTMF_EXIT), |
| 756 |
AST_APP_OPTION_ARG('D', OPT_SENDDTMF, OPT_ARG_SENDDTMF), |
| 757 |
AST_APP_OPTION('E', OPT_HEARPULSING), |
| 758 |
AST_APP_OPTION('e', OPT_PEER_H), |
| 759 |
AST_APP_OPTION_ARG('f', OPT_FORCECLID, OPT_ARG_FORCECLID), |
| 760 |
AST_APP_OPTION_ARG('F', OPT_CALLEE_GO_ON, OPT_ARG_CALLEE_GO_ON), |
| 761 |
AST_APP_OPTION('g', OPT_GO_ON), |
| 762 |
AST_APP_OPTION_ARG('G', OPT_GOTO, OPT_ARG_GOTO), |
| 763 |
AST_APP_OPTION('h', OPT_CALLEE_HANGUP), |
| 764 |
AST_APP_OPTION('H', OPT_CALLER_HANGUP), |
| 765 |
AST_APP_OPTION('i', OPT_IGNORE_FORWARDING), |
| 766 |
AST_APP_OPTION('I', OPT_IGNORE_CONNECTEDLINE), |
| 767 |
AST_APP_OPTION('j', OPT_TOPOLOGY_PRESERVE), |
| 768 |
AST_APP_OPTION('k', OPT_CALLEE_PARK), |
| 769 |
AST_APP_OPTION('K', OPT_CALLER_PARK), |
| 770 |
AST_APP_OPTION_ARG('L', OPT_DURATION_LIMIT, OPT_ARG_DURATION_LIMIT), |
| 771 |
AST_APP_OPTION_ARG('m', OPT_MUSICBACK, OPT_ARG_MUSICBACK), |
| 772 |
AST_APP_OPTION_ARG('n', OPT_SCREEN_NOINTRO, OPT_ARG_SCREEN_NOINTRO), |
| 773 |
AST_APP_OPTION('N', OPT_SCREEN_NOCALLERID), |
| 774 |
AST_APP_OPTION_ARG('o', OPT_ORIGINAL_CLID, OPT_ARG_ORIGINAL_CLID), |
| 775 |
AST_APP_OPTION_ARG('O', OPT_OPERMODE, OPT_ARG_OPERMODE), |
| 776 |
AST_APP_OPTION('p', OPT_SCREENING), |
| 777 |
AST_APP_OPTION_ARG('P', OPT_PRIVACY, OPT_ARG_PRIVACY), |
| 778 |
AST_APP_OPTION_ARG('Q', OPT_HANGUPCAUSE, OPT_ARG_HANGUPCAUSE), |
| 779 |
AST_APP_OPTION_ARG('r', OPT_RINGBACK, OPT_ARG_RINGBACK), |
| 780 |
AST_APP_OPTION('R', OPT_RING_WITH_EARLY_MEDIA), |
| 781 |
AST_APP_OPTION_ARG('S', OPT_DURATION_STOP, OPT_ARG_DURATION_STOP), |
| 782 |
AST_APP_OPTION_ARG('s', OPT_FORCE_CID_TAG, OPT_ARG_FORCE_CID_TAG), |
| 783 |
AST_APP_OPTION('t', OPT_CALLEE_TRANSFER), |
| 784 |
AST_APP_OPTION('T', OPT_CALLER_TRANSFER), |
| 785 |
AST_APP_OPTION_ARG('u', OPT_FORCE_CID_PRES, OPT_ARG_FORCE_CID_PRES), |
| 786 |
AST_APP_OPTION_ARG('U', OPT_CALLEE_GOSUB, OPT_ARG_CALLEE_GOSUB), |
| 787 |
AST_APP_OPTION('w', OPT_CALLEE_MONITOR), |
| 788 |
AST_APP_OPTION('W', OPT_CALLER_MONITOR), |
| 789 |
AST_APP_OPTION('x', OPT_CALLEE_MIXMONITOR), |
| 790 |
AST_APP_OPTION('X', OPT_CALLER_MIXMONITOR), |
| 791 |
AST_APP_OPTION('z', OPT_CANCEL_TIMEOUT), |
| 792 |
END_OPTIONS ); |
| 793 |
|
| 794 |
#define CAN_EARLY_BRIDGE(flags,chan,peer) (!ast_test_flag64(flags, OPT_CALLEE_HANGUP | \ |
| 795 |
OPT_CALLER_HANGUP | OPT_CALLEE_TRANSFER | OPT_CALLER_TRANSFER | \ |
| 796 |
OPT_CALLEE_MONITOR | OPT_CALLER_MONITOR | OPT_CALLEE_PARK | \ |
| 797 |
OPT_CALLER_PARK | OPT_ANNOUNCE | OPT_CALLEE_GOSUB) && \ |
| 798 |
!ast_channel_audiohooks(chan) && !ast_channel_audiohooks(peer) && \ |
| 799 |
ast_framehook_list_is_empty(ast_channel_framehooks(chan)) && ast_framehook_list_is_empty(ast_channel_framehooks(peer))) |
| 800 |
|
| 801 |
|
| 802 |
|
| 803 |
|
| 804 |
struct chanlist { |
| 805 |
AST_LIST_ENTRY(chanlist) node; |
| 806 |
struct ast_channel *chan; |
| 807 |
|
| 808 |
const char *interface; |
| 809 |
|
| 810 |
const char *tech; |
| 811 |
|
| 812 |
const char *number; |
| 813 |
|
| 814 |
char *orig_chan_name; |
| 815 |
uint64_t flags; |
| 816 |
|
| 817 |
struct ast_party_connected_line connected; |
| 818 |
|
| 819 |
unsigned int pending_connected_update:1; |
| 820 |
struct ast_aoc_decoded *aoc_s_rate_list; |
| 821 |
|
| 822 |
char stuff[0]; |
| 823 |
}; |
| 824 |
|
| 825 |
AST_LIST_HEAD_NOLOCK(dial_head, chanlist); |
| 826 |
|
| 827 |
static void topology_ds_destroy(void *data) { |
| 828 |
struct ast_stream_topology *top = data; |
| 829 |
ast_stream_topology_free(top); |
| 830 |
} |
| 831 |
|
| 832 |
static const struct ast_datastore_info topology_ds_info = { |
| 833 |
.type = "app_dial_topology_preserve", |
| 834 |
.destroy = topology_ds_destroy, |
| 835 |
}; |
| 836 |
|
| 837 |
static int detect_disconnect(struct ast_channel *chan, char code, struct ast_str **featurecode); |
| 838 |
|
| 839 |
static void chanlist_free(struct chanlist *outgoing) |
| 840 |
{ |
| 841 |
ast_party_connected_line_free(&outgoing->connected); |
| 842 |
ast_aoc_destroy_decoded(outgoing->aoc_s_rate_list); |
| 843 |
ast_free(outgoing->orig_chan_name); |
| 844 |
ast_free(outgoing); |
| 845 |
} |
| 846 |
|
| 847 |
static void hanguptree(struct dial_head *out_chans, struct ast_channel *exception, int hangupcause) |
| 848 |
{ |
| 849 |
|
| 850 |
struct chanlist *outgoing; |
| 851 |
|
| 852 |
while ((outgoing = AST_LIST_REMOVE_HEAD(out_chans, node))) { |
| 853 |
|
| 854 |
if (outgoing->chan && (outgoing->chan != exception)) { |
| 855 |
if (hangupcause >= 0) { |
| 856 |
|
| 857 |
ast_channel_hangupcause_set(outgoing->chan, hangupcause); |
| 858 |
} |
| 859 |
ast_hangup(outgoing->chan); |
| 860 |
} |
| 861 |
chanlist_free(outgoing); |
| 862 |
} |
| 863 |
} |
| 864 |
|
| 865 |
#define AST_MAX_WATCHERS 256 |
| 866 |
|
| 867 |
|
| 868 |
|
| 869 |
|
| 870 |
struct cause_args { |
| 871 |
struct ast_channel *chan; |
| 872 |
int busy; |
| 873 |
int congestion; |
| 874 |
int nochan; |
| 875 |
}; |
| 876 |
|
| 877 |
static void handle_cause(int cause, struct cause_args *num) |
| 878 |
{ |
| 879 |
switch(cause) { |
| 880 |
case AST_CAUSE_BUSY: |
| 881 |
num->busy++; |
| 882 |
break; |
| 883 |
case AST_CAUSE_CONGESTION: |
| 884 |
num->congestion++; |
| 885 |
break; |
| 886 |
case AST_CAUSE_NO_ROUTE_DESTINATION: |
| 887 |
case AST_CAUSE_UNREGISTERED: |
| 888 |
num->nochan++; |
| 889 |
break; |
| 890 |
case AST_CAUSE_NO_ANSWER: |
| 891 |
case AST_CAUSE_NORMAL_CLEARING: |
| 892 |
break; |
| 893 |
default: |
| 894 |
num->nochan++; |
| 895 |
break; |
| 896 |
} |
| 897 |
} |
| 898 |
|
| 899 |
static int onedigit_goto(struct ast_channel *chan, const char *context, char exten, int pri) |
| 900 |
{ |
| 901 |
char rexten[2] = { exten, '\0' }; |
| 902 |
|
| 903 |
if (context) { |
| 904 |
if (!ast_goto_if_exists(chan, context, rexten, pri)) |
| 905 |
return 1; |
| 906 |
} else { |
| 907 |
if (!ast_goto_if_exists(chan, ast_channel_context(chan), rexten, pri)) |
| 908 |
return 1; |
| 909 |
} |
| 910 |
return 0; |
| 911 |
} |
| 912 |
|
| 913 |
|
| 914 |
static const char *get_cid_name(char *name, int namelen, struct ast_channel *chan) |
| 915 |
{ |
| 916 |
const char *context; |
| 917 |
const char *exten; |
| 918 |
|
| 919 |
ast_channel_lock(chan); |
| 920 |
context = ast_strdupa(ast_channel_context(chan)); |
| 921 |
exten = ast_strdupa(ast_channel_exten(chan)); |
| 922 |
ast_channel_unlock(chan); |
| 923 |
|
| 924 |
return ast_get_hint(NULL, 0, name, namelen, chan, context, exten) ? name : ""; |
| 925 |
} |
| 926 |
|
| 927 |
|
| 928 |
|
| 929 |
|
| 930 |
|
| 931 |
|
| 932 |
|
| 933 |
|
| 934 |
|
| 935 |
|
| 936 |
|
| 937 |
|
| 938 |
|
| 939 |
|
| 940 |
|
| 941 |
|
| 942 |
|
| 943 |
|
| 944 |
static void do_forward(struct chanlist *o, struct cause_args *num, |
| 945 |
struct ast_flags64 *peerflags, int single, int caller_entertained, int *to, |
| 946 |
struct ast_party_id *forced_clid, struct ast_party_id *stored_clid) |
| 947 |
{ |
| 948 |
char tmpchan[256]; |
| 949 |
char forwarder[AST_CHANNEL_NAME]; |
| 950 |
struct ast_channel *original = o->chan; |
| 951 |
struct ast_channel *c = o->chan; |
| 952 |
struct ast_channel *in = num->chan; |
| 953 |
char *stuff; |
| 954 |
const char *tech; |
| 955 |
int cause; |
| 956 |
struct ast_party_caller caller; |
| 957 |
|
| 958 |
ast_copy_string(forwarder, ast_channel_name(c), sizeof(forwarder)); |
| 959 |
ast_copy_string(tmpchan, ast_channel_call_forward(c), sizeof(tmpchan)); |
| 960 |
if ((stuff = strchr(tmpchan, '/'))) { |
| 961 |
*stuff++ = '\0'; |
| 962 |
tech = tmpchan; |
| 963 |
} else { |
| 964 |
const char *forward_context; |
| 965 |
ast_channel_lock(c); |
| 966 |
forward_context = pbx_builtin_getvar_helper(c, "FORWARD_CONTEXT"); |
| 967 |
if (ast_strlen_zero(forward_context)) { |
| 968 |
forward_context = NULL; |
| 969 |
} |
| 970 |
snprintf(tmpchan, sizeof(tmpchan), "%s@%s", ast_channel_call_forward(c), forward_context ? forward_context : ast_channel_context(c)); |
| 971 |
ast_channel_unlock(c); |
| 972 |
stuff = tmpchan; |
| 973 |
tech = "Local"; |
| 974 |
} |
| 975 |
if (!strcasecmp(tech, "Local")) { |
| 976 |
|
| 977 |
|
| 978 |
|
| 979 |
|
| 980 |
|
| 981 |
ast_clear_flag64(o, OPT_IGNORE_CONNECTEDLINE); |
| 982 |
} |
| 983 |
|
| 984 |
|
| 985 |
ast_verb(3, "Now forwarding %s to '%s/%s' (thanks to %s)\n", ast_channel_name(in), tech, stuff, ast_channel_name(c)); |
| 986 |
|
| 987 |
if (ast_test_flag64(peerflags, OPT_IGNORE_FORWARDING)) { |
| 988 |
ast_verb(3, "Forwarding %s to '%s/%s' prevented.\n", ast_channel_name(in), tech, stuff); |
| 989 |
ast_channel_publish_dial_forward(in, original, NULL, NULL, "CANCEL", |
| 990 |
ast_channel_call_forward(original)); |
| 991 |
c = o->chan = NULL; |
| 992 |
cause = AST_CAUSE_BUSY; |
| 993 |
} else { |
| 994 |
struct ast_stream_topology *topology; |
| 995 |
|
| 996 |
ast_channel_lock(in); |
| 997 |
topology = ast_stream_topology_clone(ast_channel_get_stream_topology(in)); |
| 998 |
ast_channel_unlock(in); |
| 999 |
|
| 1000 |
|
| 1001 |
c = o->chan = ast_request_with_stream_topology(tech, topology, NULL, in, stuff, &cause); |
| 1002 |
|
| 1003 |
ast_stream_topology_free(topology); |
| 1004 |
|
| 1005 |
if (c) { |
| 1006 |
if (single && !caller_entertained) { |
| 1007 |
ast_channel_make_compatible(in, o->chan); |
| 1008 |
} |
| 1009 |
ast_channel_lock_both(in, o->chan); |
| 1010 |
ast_channel_inherit_variables(in, o->chan); |
| 1011 |
ast_channel_datastore_inherit(in, o->chan); |
| 1012 |
pbx_builtin_setvar_helper(o->chan, "FORWARDERNAME", forwarder); |
| 1013 |
ast_max_forwards_decrement(o->chan); |
| 1014 |
ast_channel_unlock(in); |
| 1015 |
ast_channel_unlock(o->chan); |
| 1016 |
|
| 1017 |
|
| 1018 |
|
| 1019 |
|
| 1020 |
ast_ignore_cc(o->chan); |
| 1021 |
ast_verb(3, "Not accepting call completion offers from call-forward recipient %s\n", |
| 1022 |
ast_channel_name(o->chan)); |
| 1023 |
} else |
| 1024 |
ast_log(LOG_NOTICE, |
| 1025 |
"Forwarding failed to create channel to dial '%s/%s' (cause = %d)\n", |
| 1026 |
tech, stuff, cause); |
| 1027 |
} |
| 1028 |
if (!c) { |
| 1029 |
ast_channel_publish_dial(in, original, stuff, "BUSY"); |
| 1030 |
ast_clear_flag64(o, DIAL_STILLGOING); |
| 1031 |
handle_cause(cause, num); |
| 1032 |
ast_hangup(original); |
| 1033 |
} else { |
| 1034 |
ast_channel_lock_both(c, original); |
| 1035 |
ast_party_redirecting_copy(ast_channel_redirecting(c), |
| 1036 |
ast_channel_redirecting(original)); |
| 1037 |
ast_channel_unlock(c); |
| 1038 |
ast_channel_unlock(original); |
| 1039 |
|
| 1040 |
ast_channel_lock_both(c, in); |
| 1041 |
|
| 1042 |
if (single && !caller_entertained && CAN_EARLY_BRIDGE(peerflags, c, in)) { |
| 1043 |
ast_rtp_instance_early_bridge_make_compatible(c, in); |
| 1044 |
} |
| 1045 |
|
| 1046 |
if (!ast_channel_redirecting(c)->from.number.valid |
| 1047 |
|| ast_strlen_zero(ast_channel_redirecting(c)->from.number.str)) { |
| 1048 |
|
| 1049 |
|
| 1050 |
|
| 1051 |
|
| 1052 |
ast_party_number_free(&ast_channel_redirecting(c)->from.number); |
| 1053 |
ast_party_number_init(&ast_channel_redirecting(c)->from.number); |
| 1054 |
ast_channel_redirecting(c)->from.number.valid = 1; |
| 1055 |
ast_channel_redirecting(c)->from.number.str = |
| 1056 |
ast_strdup(ast_channel_exten(in)); |
| 1057 |
} |
| 1058 |
|
| 1059 |
ast_channel_dialed(c)->transit_network_select = ast_channel_dialed(in)->transit_network_select; |
| 1060 |
|
| 1061 |
|
| 1062 |
ast_party_caller_set_init(&caller, ast_channel_caller(c)); |
| 1063 |
if (ast_test_flag64(peerflags, OPT_ORIGINAL_CLID)) { |
| 1064 |
caller.id = *stored_clid; |
| 1065 |
ast_channel_set_caller_event(c, &caller, NULL); |
| 1066 |
ast_set_flag64(o, DIAL_CALLERID_ABSENT); |
| 1067 |
} else if (ast_strlen_zero(S_COR(ast_channel_caller(c)->id.number.valid, |
| 1068 |
ast_channel_caller(c)->id.number.str, NULL))) { |
| 1069 |
|
| 1070 |
|
| 1071 |
|
| 1072 |
|
| 1073 |
caller.id = *stored_clid; |
| 1074 |
ast_channel_set_caller_event(c, &caller, NULL); |
| 1075 |
ast_set_flag64(o, DIAL_CALLERID_ABSENT); |
| 1076 |
} else { |
| 1077 |
ast_clear_flag64(o, DIAL_CALLERID_ABSENT); |
| 1078 |
} |
| 1079 |
|
| 1080 |
|
| 1081 |
if (ast_test_flag64(o, OPT_FORCECLID)) { |
| 1082 |
struct ast_party_connected_line connected; |
| 1083 |
|
| 1084 |
ast_party_connected_line_init(&connected); |
| 1085 |
connected.id = *forced_clid; |
| 1086 |
ast_party_connected_line_copy(ast_channel_connected(c), &connected); |
| 1087 |
} else { |
| 1088 |
ast_connected_line_copy_from_caller(ast_channel_connected(c), ast_channel_caller(in)); |
| 1089 |
} |
| 1090 |
|
| 1091 |
ast_channel_req_accountcodes(c, in, AST_CHANNEL_REQUESTOR_BRIDGE_PEER); |
| 1092 |
|
| 1093 |
ast_channel_appl_set(c, "AppDial"); |
| 1094 |
ast_channel_data_set(c, "(Outgoing Line)"); |
| 1095 |
ast_channel_publish_snapshot(c); |
| 1096 |
|
| 1097 |
ast_channel_unlock(in); |
| 1098 |
if (single && !ast_test_flag64(o, OPT_IGNORE_CONNECTEDLINE)) { |
| 1099 |
struct ast_party_redirecting redirecting; |
| 1100 |
|
| 1101 |
|
| 1102 |
|
| 1103 |
|
| 1104 |
|
| 1105 |
|
| 1106 |
|
| 1107 |
ast_party_redirecting_init(&redirecting); |
| 1108 |
ast_party_redirecting_copy(&redirecting, ast_channel_redirecting(c)); |
| 1109 |
ast_channel_unlock(c); |
| 1110 |
if (ast_channel_redirecting_sub(c, in, &redirecting, 0)) { |
| 1111 |
ast_channel_update_redirecting(in, &redirecting, NULL); |
| 1112 |
} |
| 1113 |
ast_party_redirecting_free(&redirecting); |
| 1114 |
} else { |
| 1115 |
ast_channel_unlock(c); |
| 1116 |
} |
| 1117 |
|
| 1118 |
if (ast_test_flag64(peerflags, OPT_CANCEL_TIMEOUT)) { |
| 1119 |
*to = -1; |
| 1120 |
} |
| 1121 |
|
| 1122 |
if (ast_call(c, stuff, 0)) { |
| 1123 |
ast_log(LOG_NOTICE, "Forwarding failed to dial '%s/%s'\n", |
| 1124 |
tech, stuff); |
| 1125 |
ast_channel_publish_dial(in, original, stuff, "CONGESTION"); |
| 1126 |
ast_clear_flag64(o, DIAL_STILLGOING); |
| 1127 |
ast_hangup(original); |
| 1128 |
ast_hangup(c); |
| 1129 |
c = o->chan = NULL; |
| 1130 |
num->nochan++; |
| 1131 |
} else { |
| 1132 |
ast_channel_publish_dial_forward(in, original, c, NULL, "CANCEL", |
| 1133 |
ast_channel_call_forward(original)); |
| 1134 |
|
| 1135 |
ast_channel_publish_dial(in, c, stuff, NULL); |
| 1136 |
|
| 1137 |
|
| 1138 |
ast_hangup(original); |
| 1139 |
} |
| 1140 |
if (single && !caller_entertained) { |
| 1141 |
ast_indicate(in, -1); |
| 1142 |
} |
| 1143 |
} |
| 1144 |
} |
| 1145 |
|
| 1146 |
|
| 1147 |
struct privacy_args { |
| 1148 |
int sentringing; |
| 1149 |
int privdb_val; |
| 1150 |
char privcid[256]; |
| 1151 |
char privintro[1024]; |
| 1152 |
char status[256]; |
| 1153 |
int canceled; |
| 1154 |
}; |
| 1155 |
|
| 1156 |
static void publish_dial_end_event(struct ast_channel *in, struct dial_head *out_chans, struct ast_channel *exception, const char *status) |
| 1157 |
{ |
| 1158 |
struct chanlist *outgoing; |
| 1159 |
AST_LIST_TRAVERSE(out_chans, outgoing, node) { |
| 1160 |
if (!outgoing->chan || outgoing->chan == exception) { |
| 1161 |
continue; |
| 1162 |
} |
| 1163 |
ast_channel_publish_dial(in, outgoing->chan, NULL, status); |
| 1164 |
} |
| 1165 |
} |
| 1166 |
|
| 1167 |
|
| 1168 |
|
| 1169 |
|
| 1170 |
|
| 1171 |
|
| 1172 |
|
| 1173 |
|
| 1174 |
|
| 1175 |
|
| 1176 |
static void update_connected_line_from_peer(struct ast_channel *chan, struct ast_channel *peer, int is_caller) |
| 1177 |
{ |
| 1178 |
struct ast_party_connected_line connected_caller; |
| 1179 |
|
| 1180 |
ast_party_connected_line_init(&connected_caller); |
| 1181 |
|
| 1182 |
ast_channel_lock(peer); |
| 1183 |
ast_connected_line_copy_from_caller(&connected_caller, ast_channel_caller(peer)); |
| 1184 |
ast_channel_unlock(peer); |
| 1185 |
connected_caller.source = AST_CONNECTED_LINE_UPDATE_SOURCE_ANSWER; |
| 1186 |
if (ast_channel_connected_line_sub(peer, chan, &connected_caller, 0)) { |
| 1187 |
ast_channel_update_connected_line(chan, &connected_caller, NULL); |
| 1188 |
} |
| 1189 |
ast_party_connected_line_free(&connected_caller); |
| 1190 |
} |
| 1191 |
|
| 1192 |
|
| 1193 |
|
| 1194 |
|
| 1195 |
|
| 1196 |
static void set_duration_var(struct ast_channel *chan, const char *var_base, int64_t duration) |
| 1197 |
{ |
| 1198 |
char buf[32]; |
| 1199 |
char full_var_name[128]; |
| 1200 |
|
| 1201 |
snprintf(buf, sizeof(buf), "%" PRId64, duration / 1000); |
| 1202 |
pbx_builtin_setvar_helper(chan, var_base, buf); |
| 1203 |
|
| 1204 |
snprintf(full_var_name, sizeof(full_var_name), "%s_MS", var_base); |
| 1205 |
snprintf(buf, sizeof(buf), "%" PRId64, duration); |
| 1206 |
pbx_builtin_setvar_helper(chan, full_var_name, buf); |
| 1207 |
} |
| 1208 |
|
| 1209 |
static struct ast_channel *wait_for_answer(struct ast_channel *in, |
| 1210 |
struct dial_head *out_chans, int *to_answer, int *to_progress, struct ast_flags64 *peerflags, |
| 1211 |
char *opt_args[], |
| 1212 |
struct privacy_args *pa, |
| 1213 |
const struct cause_args *num_in, int *result, char *dtmf_progress, |
| 1214 |
char *mf_progress, char *mf_wink, |
| 1215 |
char *sf_progress, char *sf_wink, |
| 1216 |
const int hearpulsing, |
| 1217 |
const int ignore_cc, |
| 1218 |
struct ast_party_id *forced_clid, struct ast_party_id *stored_clid, |
| 1219 |
struct ast_bridge_config *config) |
| 1220 |
{ |
| 1221 |
struct cause_args num = *num_in; |
| 1222 |
int prestart = num.busy + num.congestion + num.nochan; |
| 1223 |
int orig_answer_to = *to_answer; |
| 1224 |
int orig_progress_to = *to_progress; |
| 1225 |
struct ast_channel *peer = NULL; |
| 1226 |
struct chanlist *outgoing = AST_LIST_FIRST(out_chans); |
| 1227 |
|
| 1228 |
int single = outgoing && !AST_LIST_NEXT(outgoing, node); |
| 1229 |
int caller_entertained = outgoing |
| 1230 |
&& ast_test_flag64(outgoing, OPT_MUSICBACK | OPT_RINGBACK); |
| 1231 |
struct ast_str *featurecode = ast_str_alloca(AST_FEATURE_MAX_LEN + 1); |
| 1232 |
int cc_recall_core_id; |
| 1233 |
int is_cc_recall; |
| 1234 |
int cc_frame_received = 0; |
| 1235 |
int num_ringing = 0; |
| 1236 |
int sent_ring = 0; |
| 1237 |
int sent_progress = 0, sent_wink = 0; |
| 1238 |
struct timeval start = ast_tvnow(); |
| 1239 |
SCOPE_ENTER(3, "%s\n", ast_channel_name(in)); |
| 1240 |
|
| 1241 |
if (single) { |
| 1242 |
|
| 1243 |
if (!caller_entertained) { |
| 1244 |
ast_deactivate_generator(in); |
| 1245 |
|
| 1246 |
|
| 1247 |
if (ast_channel_make_compatible(in, outgoing->chan) < 0) { |
| 1248 |
|
| 1249 |
|
| 1250 |
|
| 1251 |
|
| 1252 |
*to_answer = -1; |
| 1253 |
strcpy(pa->status, "CONGESTION"); |
| 1254 |
ast_channel_publish_dial(in, outgoing->chan, NULL, pa->status); |
| 1255 |
SCOPE_EXIT_RTN_VALUE(NULL, "%s: can't be made compat with %s\n", |
| 1256 |
ast_channel_name(in), ast_channel_name(outgoing->chan)); |
| 1257 |
} |
| 1258 |
} |
| 1259 |
|
| 1260 |
if (!ast_test_flag64(outgoing, OPT_IGNORE_CONNECTEDLINE) |
| 1261 |
&& !ast_test_flag64(outgoing, DIAL_CALLERID_ABSENT)) { |
| 1262 |
update_connected_line_from_peer(in, outgoing->chan, 1); |
| 1263 |
} |
| 1264 |
} |
| 1265 |
|
| 1266 |
is_cc_recall = ast_cc_is_recall(in, &cc_recall_core_id, NULL); |
| 1267 |
|
| 1268 |
while ((*to_answer = ast_remaining_ms(start, orig_answer_to)) && (*to_progress = ast_remaining_ms(start, orig_progress_to)) && !peer) { |
| 1269 |
struct chanlist *o; |
| 1270 |
int pos = 0; |
| 1271 |
int numlines = prestart; |
| 1272 |
struct ast_channel *winner; |
| 1273 |
struct ast_channel *watchers[AST_MAX_WATCHERS]; |
| 1274 |
|
| 1275 |
watchers[pos++] = in; |
| 1276 |
AST_LIST_TRAVERSE(out_chans, o, node) { |
| 1277 |
|
| 1278 |
if (ast_test_flag64(o, DIAL_STILLGOING) && o->chan) |
| 1279 |
watchers[pos++] = o->chan; |
| 1280 |
numlines++; |
| 1281 |
} |
| 1282 |
if (pos == 1) { |
| 1283 |
if (numlines == (num.busy + num.congestion + num.nochan)) { |
| 1284 |
ast_verb(2, "Everyone is busy/congested at this time (%d:%d/%d/%d)\n", numlines, num.busy, num.congestion, num.nochan); |
| 1285 |
if (num.busy) |
| 1286 |
strcpy(pa->status, "BUSY"); |
| 1287 |
else if (num.congestion) |
| 1288 |
strcpy(pa->status, "CONGESTION"); |
| 1289 |
else if (num.nochan) |
| 1290 |
strcpy(pa->status, "CHANUNAVAIL"); |
| 1291 |
} else { |
| 1292 |
ast_verb(3, "No one is available to answer at this time (%d:%d/%d/%d)\n", numlines, num.busy, num.congestion, num.nochan); |
| 1293 |
} |
| 1294 |
*to_answer = 0; |
| 1295 |
if (is_cc_recall) { |
| 1296 |
ast_cc_failed(cc_recall_core_id, "Everyone is busy/congested for the recall. How sad"); |
| 1297 |
} |
| 1298 |
SCOPE_EXIT_RTN_VALUE(NULL, "%s: No outgoing channels available\n", ast_channel_name(in)); |
| 1299 |
} |
| 1300 |
|
| 1301 |
|
| 1302 |
winner = ast_waitfor_n(watchers, pos, *to_progress > 0 && (*to_answer < 0 || *to_progress < *to_answer) ? to_progress : to_answer); |
| 1303 |
|
| 1304 |
AST_LIST_TRAVERSE(out_chans, o, node) { |
| 1305 |
int res = 0; |
| 1306 |
struct ast_frame *f; |
| 1307 |
struct ast_channel *c = o->chan; |
| 1308 |
|
| 1309 |
if (c == NULL) |
| 1310 |
continue; |
| 1311 |
if (ast_test_flag64(o, DIAL_STILLGOING) && ast_channel_state(c) == AST_STATE_UP) { |
| 1312 |
if (!peer) { |
| 1313 |
ast_verb(3, "%s answered %s\n", ast_channel_name(c), ast_channel_name(in)); |
| 1314 |
if (o->orig_chan_name |
| 1315 |
&& strcmp(o->orig_chan_name, ast_channel_name(c))) { |
| 1316 |
|
| 1317 |
|
| 1318 |
|
| 1319 |
|
| 1320 |
update_connected_line_from_peer(in, c, 1); |
| 1321 |
} else if (!single && !ast_test_flag64(o, OPT_IGNORE_CONNECTEDLINE)) { |
| 1322 |
if (o->pending_connected_update) { |
| 1323 |
if (ast_channel_connected_line_sub(c, in, &o->connected, 0)) { |
| 1324 |
ast_channel_update_connected_line(in, &o->connected, NULL); |
| 1325 |
} |
| 1326 |
} else if (!ast_test_flag64(o, DIAL_CALLERID_ABSENT)) { |
| 1327 |
update_connected_line_from_peer(in, c, 1); |
| 1328 |
} |
| 1329 |
} |
| 1330 |
if (o->aoc_s_rate_list) { |
| 1331 |
size_t encoded_size; |
| 1332 |
struct ast_aoc_encoded *encoded; |
| 1333 |
if ((encoded = ast_aoc_encode(o->aoc_s_rate_list, &encoded_size, o->chan))) { |
| 1334 |
ast_indicate_data(in, AST_CONTROL_AOC, encoded, encoded_size); |
| 1335 |
ast_aoc_destroy_encoded(encoded); |
| 1336 |
} |
| 1337 |
} |
| 1338 |
peer = c; |
| 1339 |
publish_dial_end_event(in, out_chans, peer, "CANCEL"); |
| 1340 |
ast_copy_flags64(peerflags, o, |
| 1341 |
OPT_CALLEE_TRANSFER | OPT_CALLER_TRANSFER | |
| 1342 |
OPT_CALLEE_HANGUP | OPT_CALLER_HANGUP | |
| 1343 |
OPT_CALLEE_MONITOR | OPT_CALLER_MONITOR | |
| 1344 |
OPT_CALLEE_PARK | OPT_CALLER_PARK | |
| 1345 |
OPT_CALLEE_MIXMONITOR | OPT_CALLER_MIXMONITOR | |
| 1346 |
DIAL_NOFORWARDHTML); |
| 1347 |
ast_channel_dialcontext_set(c, ""); |
| 1348 |
ast_channel_exten_set(c, ""); |
| 1349 |
} |
| 1350 |
continue; |
| 1351 |
} |
| 1352 |
if (c != winner) |
| 1353 |
continue; |
| 1354 |
|
| 1355 |
if (!ast_strlen_zero(ast_channel_call_forward(c))) { |
| 1356 |
pa->sentringing = 0; |
| 1357 |
if (!ignore_cc && (f = ast_read(c))) { |
| 1358 |
if (f->frametype == AST_FRAME_CONTROL && f->subclass.integer == AST_CONTROL_CC) { |
| 1359 |
|
| 1360 |
|
| 1361 |
|
| 1362 |
ast_handle_cc_control_frame(in, c, f->data.ptr); |
| 1363 |
} |
| 1364 |
ast_frfree(f); |
| 1365 |
} |
| 1366 |
|
| 1367 |
if (o->pending_connected_update) { |
| 1368 |
|
| 1369 |
|
| 1370 |
|
| 1371 |
|
| 1372 |
|
| 1373 |
|
| 1374 |
o->pending_connected_update = 0; |
| 1375 |
ast_channel_lock(in); |
| 1376 |
ast_party_connected_line_copy(&o->connected, ast_channel_connected(in)); |
| 1377 |
ast_channel_unlock(in); |
| 1378 |
} |
| 1379 |
|
| 1380 |
do_forward(o, &num, peerflags, single, caller_entertained, &orig_answer_to, |
| 1381 |
forced_clid, stored_clid); |
| 1382 |
|
| 1383 |
if (o->chan) { |
| 1384 |
ast_free(o->orig_chan_name); |
| 1385 |
o->orig_chan_name = ast_strdup(ast_channel_name(o->chan)); |
| 1386 |
if (single |
| 1387 |
&& !ast_test_flag64(o, OPT_IGNORE_CONNECTEDLINE) |
| 1388 |
&& !ast_test_flag64(o, DIAL_CALLERID_ABSENT)) { |
| 1389 |
update_connected_line_from_peer(in, o->chan, 1); |
| 1390 |
} |
| 1391 |
} |
| 1392 |
continue; |
| 1393 |
} |
| 1394 |
f = ast_read(winner); |
| 1395 |
if (!f) { |
| 1396 |
ast_channel_hangupcause_set(in, ast_channel_hangupcause(c)); |
| 1397 |
ast_channel_publish_dial(in, c, NULL, ast_hangup_cause_to_dial_status(ast_channel_hangupcause(c))); |
| 1398 |
ast_hangup(c); |
| 1399 |
c = o->chan = NULL; |
| 1400 |
ast_clear_flag64(o, DIAL_STILLGOING); |
| 1401 |
handle_cause(ast_channel_hangupcause(in), &num); |
| 1402 |
continue; |
| 1403 |
} |
| 1404 |
switch (f->frametype) { |
| 1405 |
case AST_FRAME_CONTROL: |
| 1406 |
switch (f->subclass.integer) { |
| 1407 |
case AST_CONTROL_ANSWER: |
| 1408 |
|
| 1409 |
if (!peer) { |
| 1410 |
ast_trace(-1, "%s answered %s\n", ast_channel_name(c), ast_channel_name(in)); |
| 1411 |
ast_verb(3, "%s answered %s\n", ast_channel_name(c), ast_channel_name(in)); |
| 1412 |
if (o->orig_chan_name |
| 1413 |
&& strcmp(o->orig_chan_name, ast_channel_name(c))) { |
| 1414 |
|
| 1415 |
|
| 1416 |
|
| 1417 |
|
| 1418 |
update_connected_line_from_peer(in, c, 1); |
| 1419 |
} else if (!single && !ast_test_flag64(o, OPT_IGNORE_CONNECTEDLINE)) { |
| 1420 |
if (o->pending_connected_update) { |
| 1421 |
if (ast_channel_connected_line_sub(c, in, &o->connected, 0)) { |
| 1422 |
ast_channel_update_connected_line(in, &o->connected, NULL); |
| 1423 |
} |
| 1424 |
} else if (!ast_test_flag64(o, DIAL_CALLERID_ABSENT)) { |
| 1425 |
update_connected_line_from_peer(in, c, 1); |
| 1426 |
} |
| 1427 |
} |
| 1428 |
if (o->aoc_s_rate_list) { |
| 1429 |
size_t encoded_size; |
| 1430 |
struct ast_aoc_encoded *encoded; |
| 1431 |
if ((encoded = ast_aoc_encode(o->aoc_s_rate_list, &encoded_size, o->chan))) { |
| 1432 |
ast_indicate_data(in, AST_CONTROL_AOC, encoded, encoded_size); |
| 1433 |
ast_aoc_destroy_encoded(encoded); |
| 1434 |
} |
| 1435 |
} |
| 1436 |
peer = c; |
| 1437 |
|
| 1438 |
if (f->subclass.topology) { |
| 1439 |
|
| 1440 |
|
| 1441 |
|
| 1442 |
|
| 1443 |
config->answer_topology = ao2_bump(f->subclass.topology); |
| 1444 |
ast_trace(-1, "%s Found topology in frame: %p %p %s\n", |
| 1445 |
ast_channel_name(peer), f, config->answer_topology, |
| 1446 |
ast_str_tmp(256, ast_stream_topology_to_str(config->answer_topology, &STR_TMP))); |
| 1447 |
} |
| 1448 |
|
| 1449 |
|
| 1450 |
|
| 1451 |
|
| 1452 |
|
| 1453 |
publish_dial_end_event(in, out_chans, peer, "CANCEL"); |
| 1454 |
ast_copy_flags64(peerflags, o, |
| 1455 |
OPT_CALLEE_TRANSFER | OPT_CALLER_TRANSFER | |
| 1456 |
OPT_CALLEE_HANGUP | OPT_CALLER_HANGUP | |
| 1457 |
OPT_CALLEE_MONITOR | OPT_CALLER_MONITOR | |
| 1458 |
OPT_CALLEE_PARK | OPT_CALLER_PARK | |
| 1459 |
OPT_CALLEE_MIXMONITOR | OPT_CALLER_MIXMONITOR | |
| 1460 |
DIAL_NOFORWARDHTML); |
| 1461 |
ast_channel_dialcontext_set(c, ""); |
| 1462 |
ast_channel_exten_set(c, ""); |
| 1463 |
if (CAN_EARLY_BRIDGE(peerflags, in, peer)) { |
| 1464 |
|
| 1465 |
ast_channel_early_bridge(in, peer); |
| 1466 |
} |
| 1467 |
} |
| 1468 |
|
| 1469 |
ast_channel_hangupcause_set(in, AST_CAUSE_NORMAL_CLEARING); |
| 1470 |
ast_channel_hangupcause_set(c, AST_CAUSE_NORMAL_CLEARING); |
| 1471 |
break; |
| 1472 |
case AST_CONTROL_BUSY: |
| 1473 |
ast_verb(3, "%s is busy\n", ast_channel_name(c)); |
| 1474 |
ast_channel_hangupcause_set(in, ast_channel_hangupcause(c)); |
| 1475 |
ast_channel_publish_dial(in, c, NULL, "BUSY"); |
| 1476 |
ast_hangup(c); |
| 1477 |
c = o->chan = NULL; |
| 1478 |
ast_clear_flag64(o, DIAL_STILLGOING); |
| 1479 |
handle_cause(AST_CAUSE_BUSY, &num); |
| 1480 |
break; |
| 1481 |
case AST_CONTROL_CONGESTION: |
| 1482 |
ast_verb(3, "%s is circuit-busy\n", ast_channel_name(c)); |
| 1483 |
ast_channel_hangupcause_set(in, ast_channel_hangupcause(c)); |
| 1484 |
ast_channel_publish_dial(in, c, NULL, "CONGESTION"); |
| 1485 |
ast_hangup(c); |
| 1486 |
c = o->chan = NULL; |
| 1487 |
ast_clear_flag64(o, DIAL_STILLGOING); |
| 1488 |
handle_cause(AST_CAUSE_CONGESTION, &num); |
| 1489 |
break; |
| 1490 |
case AST_CONTROL_RINGING: |
| 1491 |
|
| 1492 |
|
| 1493 |
|
| 1494 |
|
| 1495 |
|
| 1496 |
|
| 1497 |
|
| 1498 |
|
| 1499 |
|
| 1500 |
|
| 1501 |
|
| 1502 |
|
| 1503 |
|
| 1504 |
|
| 1505 |
|
| 1506 |
|
| 1507 |
|
| 1508 |
|
| 1509 |
|
| 1510 |
|
| 1511 |
|
| 1512 |
|
| 1513 |
|
| 1514 |
|
| 1515 |
|
| 1516 |
++num_ringing; |
| 1517 |
*to_progress = -1; |
| 1518 |
orig_progress_to = -1; |
| 1519 |
if (ignore_cc || cc_frame_received || num_ringing == numlines) { |
| 1520 |
ast_verb(3, "%s is ringing\n", ast_channel_name(c)); |
| 1521 |
|
| 1522 |
if (single && !caller_entertained |
| 1523 |
&& CAN_EARLY_BRIDGE(peerflags, in, c)) { |
| 1524 |
ast_channel_early_bridge(in, c); |
| 1525 |
} |
| 1526 |
if (!(pa->sentringing) && !ast_test_flag64(outgoing, OPT_MUSICBACK) && ast_strlen_zero(opt_args[OPT_ARG_RINGBACK])) { |
| 1527 |
ast_indicate(in, AST_CONTROL_RINGING); |
| 1528 |
pa->sentringing++; |
| 1529 |
} |
| 1530 |
if (!sent_ring) { |
| 1531 |
struct timeval now, then; |
| 1532 |
int64_t diff; |
| 1533 |
|
| 1534 |
now = ast_tvnow(); |
| 1535 |
|
| 1536 |
ast_channel_lock(in); |
| 1537 |
ast_channel_stage_snapshot(in); |
| 1538 |
|
| 1539 |
then = ast_channel_creationtime(c); |
| 1540 |
diff = ast_tvzero(then) ? 0 : ast_tvdiff_ms(now, then); |
| 1541 |
set_duration_var(in, "RINGTIME", diff); |
| 1542 |
|
| 1543 |
ast_channel_stage_snapshot_done(in); |
| 1544 |
ast_channel_unlock(in); |
| 1545 |
sent_ring = 1; |
| 1546 |
} |
| 1547 |
} |
| 1548 |
ast_channel_publish_dial(in, c, NULL, "RINGING"); |
| 1549 |
break; |
| 1550 |
case AST_CONTROL_PROGRESS: |
| 1551 |
ast_verb(3, "%s is making progress passing it to %s\n", ast_channel_name(c), ast_channel_name(in)); |
| 1552 |
|
| 1553 |
if (single && !caller_entertained |
| 1554 |
&& CAN_EARLY_BRIDGE(peerflags, in, c)) { |
| 1555 |
ast_channel_early_bridge(in, c); |
| 1556 |
} |
| 1557 |
if (!ast_test_flag64(outgoing, OPT_RINGBACK)) { |
| 1558 |
if (single || (!single && !pa->sentringing)) { |
| 1559 |
ast_indicate(in, AST_CONTROL_PROGRESS); |
| 1560 |
} |
| 1561 |
} |
| 1562 |
*to_progress = -1; |
| 1563 |
orig_progress_to = -1; |
| 1564 |
if (!sent_progress) { |
| 1565 |
struct timeval now, then; |
| 1566 |
int64_t diff; |
| 1567 |
|
| 1568 |
now = ast_tvnow(); |
| 1569 |
|
| 1570 |
ast_channel_lock(in); |
| 1571 |
ast_channel_stage_snapshot(in); |
| 1572 |
|
| 1573 |
then = ast_channel_creationtime(c); |
| 1574 |
diff = ast_tvzero(then) ? 0 : ast_tvdiff_ms(now, then); |
| 1575 |
set_duration_var(in, "PROGRESSTIME", diff); |
| 1576 |
|
| 1577 |
ast_channel_stage_snapshot_done(in); |
| 1578 |
ast_channel_unlock(in); |
| 1579 |
sent_progress = 1; |
| 1580 |
|
| 1581 |
if (!ast_strlen_zero(mf_progress)) { |
| 1582 |
ast_verb(3, |
| 1583 |
"Sending MF '%s' to %s as result of " |
| 1584 |
"receiving a PROGRESS message.\n", |
| 1585 |
mf_progress, hearpulsing ? "parties" : "called party"); |
| 1586 |
res |= ast_mf_stream(c, (hearpulsing ? NULL : in), |
| 1587 |
(hearpulsing ? in : NULL), mf_progress, 50, 55, 120, 65, 0); |
| 1588 |
} |
| 1589 |
if (!ast_strlen_zero(sf_progress)) { |
| 1590 |
ast_verb(3, |
| 1591 |
"Sending SF '%s' to %s as result of " |
| 1592 |
"receiving a PROGRESS message.\n", |
| 1593 |
sf_progress, (hearpulsing ? "parties" : "called party")); |
| 1594 |
res |= ast_sf_stream(c, (hearpulsing ? NULL : in), |
| 1595 |
(hearpulsing ? in : NULL), sf_progress, 0, 0); |
| 1596 |
} |
| 1597 |
if (!ast_strlen_zero(dtmf_progress)) { |
| 1598 |
ast_verb(3, |
| 1599 |
"Sending DTMF '%s' to the called party as result of " |
| 1600 |
"receiving a PROGRESS message.\n", |
| 1601 |
dtmf_progress); |
| 1602 |
res |= ast_dtmf_stream(c, in, dtmf_progress, 250, 0); |
| 1603 |
} |
| 1604 |
if (res) { |
| 1605 |
ast_log(LOG_WARNING, "Called channel %s hung up post-progress before all digits could be sent\n", ast_channel_name(c)); |
| 1606 |
if (ast_channel_state(c) == AST_STATE_UP) { |
| 1607 |
|
| 1608 |
|
| 1609 |
ast_debug(1, "Channel %s answered while we were sending it digits, answering %s retroactively\n", ast_channel_name(c), ast_channel_name(in)); |
| 1610 |
|
| 1611 |
|
| 1612 |
ast_raw_answer(in); |
| 1613 |
strcpy(pa->status, "ANSWER"); |
| 1614 |
} else { |
| 1615 |
*to_answer = 0; |
| 1616 |
} |
| 1617 |
goto wait_over; |
| 1618 |
} |
| 1619 |
} |
| 1620 |
ast_channel_publish_dial(in, c, NULL, "PROGRESS"); |
| 1621 |
break; |
| 1622 |
case AST_CONTROL_WINK: |
| 1623 |
ast_verb(3, "%s winked, passing it to %s\n", ast_channel_name(c), ast_channel_name(in)); |
| 1624 |
if (!sent_wink) { |
| 1625 |
sent_wink = 1; |
| 1626 |
if (!ast_strlen_zero(mf_wink)) { |
| 1627 |
ast_verb(3, |
| 1628 |
"Sending MF '%s' to %s as result of " |
| 1629 |
"receiving a WINK message.\n", |
| 1630 |
mf_wink, (hearpulsing ? "parties" : "called party")); |
| 1631 |
res |= ast_mf_stream(c, (hearpulsing ? NULL : in), |
| 1632 |
(hearpulsing ? in : NULL), mf_wink, 50, 55, 120, 65, 0); |
| 1633 |
} |
| 1634 |
if (!ast_strlen_zero(sf_wink)) { |
| 1635 |
ast_verb(3, |
| 1636 |
"Sending SF '%s' to %s as result of " |
| 1637 |
"receiving a WINK message.\n", |
| 1638 |
sf_wink, (hearpulsing ? "parties" : "called party")); |
| 1639 |
res |= ast_sf_stream(c, (hearpulsing ? NULL : in), |
| 1640 |
(hearpulsing ? in : NULL), sf_wink, 0, 0); |
| 1641 |
} |
| 1642 |
if (res) { |
| 1643 |
ast_log(LOG_WARNING, "Called channel %s hung up post-wink before all digits could be sent\n", ast_channel_name(c)); |
| 1644 |
if (ast_channel_state(c) == AST_STATE_UP) { |
| 1645 |
|
| 1646 |
ast_debug(1, "Channel %s answered while we were sending it digits, answering %s retroactively\n", ast_channel_name(c), ast_channel_name(in)); |
| 1647 |
ast_raw_answer(in); |
| 1648 |
strcpy(pa->status, "ANSWER"); |
| 1649 |
} else { |
| 1650 |
*to_answer = 0; |
| 1651 |
} |
| 1652 |
goto wait_over; |
| 1653 |
} |
| 1654 |
} |
| 1655 |
ast_indicate(in, AST_CONTROL_WINK); |
| 1656 |
break; |
| 1657 |
case AST_CONTROL_VIDUPDATE: |
| 1658 |
case AST_CONTROL_SRCUPDATE: |
| 1659 |
case AST_CONTROL_SRCCHANGE: |
| 1660 |
if (!single || caller_entertained) { |
| 1661 |
break; |
| 1662 |
} |
| 1663 |
ast_verb(3, "%s requested media update control %d, passing it to %s\n", |
| 1664 |
ast_channel_name(c), f->subclass.integer, ast_channel_name(in)); |
| 1665 |
ast_indicate(in, f->subclass.integer); |
| 1666 |
break; |
| 1667 |
case AST_CONTROL_CONNECTED_LINE: |
| 1668 |
if (ast_test_flag64(o, OPT_IGNORE_CONNECTEDLINE)) { |
| 1669 |
ast_verb(3, "Connected line update to %s prevented.\n", ast_channel_name(in)); |
| 1670 |
break; |
| 1671 |
} |
| 1672 |
if (!single) { |
| 1673 |
struct ast_party_connected_line connected; |
| 1674 |
|
| 1675 |
ast_verb(3, "%s connected line has changed. Saving it until answer for %s\n", |
| 1676 |
ast_channel_name(c), ast_channel_name(in)); |
| 1677 |
ast_party_connected_line_set_init(&connected, &o->connected); |
| 1678 |
ast_connected_line_parse_data(f->data.ptr, f->datalen, &connected); |
| 1679 |
ast_party_connected_line_set(&o->connected, &connected, NULL); |
| 1680 |
ast_party_connected_line_free(&connected); |
| 1681 |
o->pending_connected_update = 1; |
| 1682 |
break; |
| 1683 |
} |
| 1684 |
if (ast_channel_connected_line_sub(c, in, f, 1)) { |
| 1685 |
ast_indicate_data(in, AST_CONTROL_CONNECTED_LINE, f->data.ptr, f->datalen); |
| 1686 |
} |
| 1687 |
break; |
| 1688 |
case AST_CONTROL_AOC: |
| 1689 |
{ |
| 1690 |
struct ast_aoc_decoded *decoded = ast_aoc_decode(f->data.ptr, f->datalen, o->chan); |
| 1691 |
if (decoded && (ast_aoc_get_msg_type(decoded) == AST_AOC_S)) { |
| 1692 |
ast_aoc_destroy_decoded(o->aoc_s_rate_list); |
| 1693 |
o->aoc_s_rate_list = decoded; |
| 1694 |
} else { |
| 1695 |
ast_aoc_destroy_decoded(decoded); |
| 1696 |
} |
| 1697 |
} |
| 1698 |
break; |
| 1699 |
case AST_CONTROL_REDIRECTING: |
| 1700 |
if (!single) { |
| 1701 |
|
| 1702 |
|
| 1703 |
|
| 1704 |
|
| 1705 |
break; |
| 1706 |
} |
| 1707 |
if (ast_test_flag64(o, OPT_IGNORE_CONNECTEDLINE)) { |
| 1708 |
ast_verb(3, "Redirecting update to %s prevented.\n", ast_channel_name(in)); |
| 1709 |
break; |
| 1710 |
} |
| 1711 |
ast_verb(3, "%s redirecting info has changed, passing it to %s\n", |
| 1712 |
ast_channel_name(c), ast_channel_name(in)); |
| 1713 |
if (ast_channel_redirecting_sub(c, in, f, 1)) { |
| 1714 |
ast_indicate_data(in, AST_CONTROL_REDIRECTING, f->data.ptr, f->datalen); |
| 1715 |
} |
| 1716 |
pa->sentringing = 0; |
| 1717 |
break; |
| 1718 |
case AST_CONTROL_PROCEEDING: |
| 1719 |
ast_verb(3, "%s is proceeding passing it to %s\n", ast_channel_name(c), ast_channel_name(in)); |
| 1720 |
if (single && !caller_entertained |
| 1721 |
&& CAN_EARLY_BRIDGE(peerflags, in, c)) { |
| 1722 |
ast_channel_early_bridge(in, c); |
| 1723 |
} |
| 1724 |
if (!ast_test_flag64(outgoing, OPT_RINGBACK)) |
| 1725 |
ast_indicate(in, AST_CONTROL_PROCEEDING); |
| 1726 |
ast_channel_publish_dial(in, c, NULL, "PROCEEDING"); |
| 1727 |
break; |
| 1728 |
case AST_CONTROL_HOLD: |
| 1729 |
|
| 1730 |
ast_verb(3, "Call on %s placed on hold\n", ast_channel_name(c)); |
| 1731 |
ast_indicate_data(in, AST_CONTROL_HOLD, f->data.ptr, f->datalen); |
| 1732 |
break; |
| 1733 |
case AST_CONTROL_UNHOLD: |
| 1734 |
|
| 1735 |
ast_verb(3, "Call on %s left from hold\n", ast_channel_name(c)); |
| 1736 |
ast_indicate(in, AST_CONTROL_UNHOLD); |
| 1737 |
break; |
| 1738 |
case AST_CONTROL_OFFHOOK: |
| 1739 |
case AST_CONTROL_FLASH: |
| 1740 |
|
| 1741 |
break; |
| 1742 |
case AST_CONTROL_CC: |
| 1743 |
if (!ignore_cc) { |
| 1744 |
ast_handle_cc_control_frame(in, c, f->data.ptr); |
| 1745 |
cc_frame_received = 1; |
| 1746 |
} |
| 1747 |
break; |
| 1748 |
case AST_CONTROL_PVT_CAUSE_CODE: |
| 1749 |
ast_indicate_data(in, AST_CONTROL_PVT_CAUSE_CODE, f->data.ptr, f->datalen); |
| 1750 |
break; |
| 1751 |
case AST_CONTROL_PLAYBACK_BEGIN: |
| 1752 |
if (!f->data.ptr) { |
| 1753 |
ast_log(LOG_WARNING, "Got playback begin directive without filename on %s\n", ast_channel_name(c)); |
| 1754 |
} else { |
| 1755 |
const char *filename = f->data.ptr; |
| 1756 |
ast_verb(3, "Playing audio file %s on %s\n", filename, ast_channel_name(in)); |
| 1757 |
ast_streamfile(in, filename, ast_channel_language(in)); |
| 1758 |
} |
| 1759 |
break; |
| 1760 |
case -1: |
| 1761 |
if (single && !caller_entertained) { |
| 1762 |
ast_verb(3, "%s stopped sounds\n", ast_channel_name(c)); |
| 1763 |
ast_indicate(in, -1); |
| 1764 |
pa->sentringing = 0; |
| 1765 |
} |
| 1766 |
break; |
| 1767 |
default: |
| 1768 |
ast_debug(1, "Dunno what to do with control type %d on %s\n", f->subclass.integer, ast_channel_name(in)); |
| 1769 |
break; |
| 1770 |
} |
| 1771 |
break; |
| 1772 |
case AST_FRAME_VIDEO: |
| 1773 |
case AST_FRAME_VOICE: |
| 1774 |
case AST_FRAME_IMAGE: |
| 1775 |
case AST_FRAME_DTMF_BEGIN: |
| 1776 |
case AST_FRAME_DTMF_END: |
| 1777 |
if (caller_entertained) { |
| 1778 |
break; |
| 1779 |
} |
| 1780 |
*to_progress = -1; |
| 1781 |
orig_progress_to = -1; |
| 1782 |
|
| 1783 |
case AST_FRAME_TEXT: |
| 1784 |
if (single && ast_write(in, f)) { |
| 1785 |
ast_log(LOG_WARNING, "Unable to write frametype %u on %s\n", |
| 1786 |
f->frametype, ast_channel_name(in)); |
| 1787 |
} |
| 1788 |
break; |
| 1789 |
case AST_FRAME_HTML: |
| 1790 |
if (single && !ast_test_flag64(outgoing, DIAL_NOFORWARDHTML) |
| 1791 |
&& ast_channel_sendhtml(in, f->subclass.integer, f->data.ptr, f->datalen) == -1) { |
| 1792 |
ast_log(LOG_WARNING, "Unable to send URL on %s\n", ast_channel_name(in)); |
| 1793 |
} |
| 1794 |
break; |
| 1795 |
default: |
| 1796 |
break; |
| 1797 |
} |
| 1798 |
ast_frfree(f); |
| 1799 |
} |
| 1800 |
if (winner == in) { |
| 1801 |
struct ast_frame *f = ast_read(in); |
| 1802 |
if (!f || ((f->frametype == AST_FRAME_CONTROL) && (f->subclass.integer == AST_CONTROL_HANGUP))) { |
| 1803 |
|
| 1804 |
*to_answer = -1; |
| 1805 |
strcpy(pa->status, "CANCEL"); |
| 1806 |
pa->canceled = 1; |
| 1807 |
publish_dial_end_event(in, out_chans, NULL, pa->status); |
| 1808 |
if (f) { |
| 1809 |
if (f->data.uint32) { |
| 1810 |
ast_channel_hangupcause_set(in, f->data.uint32); |
| 1811 |
} |
| 1812 |
ast_frfree(f); |
| 1813 |
} |
| 1814 |
if (is_cc_recall) { |
| 1815 |
ast_cc_completed(in, "CC completed, although the caller hung up (cancelled)"); |
| 1816 |
} |
| 1817 |
SCOPE_EXIT_RTN_VALUE(NULL, "%s: Caller hung up\n", ast_channel_name(in)); |
| 1818 |
} |
| 1819 |
|
| 1820 |
|
| 1821 |
if (f->frametype == AST_FRAME_DTMF) { |
| 1822 |
if (ast_test_flag64(peerflags, OPT_DTMF_EXIT)) { |
| 1823 |
const char *context; |
| 1824 |
ast_channel_lock(in); |
| 1825 |
if ((context = pbx_builtin_getvar_helper(in, "EXITCONTEXT"))) { |
| 1826 |
context = ast_strdupa(context); |
| 1827 |
} |
| 1828 |
ast_channel_unlock(in); |
| 1829 |
if (onedigit_goto(in, context, (char) f->subclass.integer, 1)) { |
| 1830 |
ast_verb(3, "User hit %c to disconnect call.\n", f->subclass.integer); |
| 1831 |
*to_answer = 0; |
| 1832 |
*result = f->subclass.integer; |
| 1833 |
strcpy(pa->status, "CANCEL"); |
| 1834 |
pa->canceled = 1; |
| 1835 |
publish_dial_end_event(in, out_chans, NULL, pa->status); |
| 1836 |
ast_frfree(f); |
| 1837 |
if (is_cc_recall) { |
| 1838 |
ast_cc_completed(in, "CC completed, but the caller used DTMF to exit"); |
| 1839 |
} |
| 1840 |
SCOPE_EXIT_RTN_VALUE(NULL, "%s: Caller pressed %c to end call\n", |
| 1841 |
ast_channel_name(in), f->subclass.integer); |
| 1842 |
} |
| 1843 |
} |
| 1844 |
|
| 1845 |
if (ast_test_flag64(peerflags, OPT_CALLER_HANGUP) && |
| 1846 |
detect_disconnect(in, f->subclass.integer, &featurecode)) { |
| 1847 |
ast_verb(3, "User requested call disconnect.\n"); |
| 1848 |
*to_answer = 0; |
| 1849 |
strcpy(pa->status, "CANCEL"); |
| 1850 |
pa->canceled = 1; |
| 1851 |
publish_dial_end_event(in, out_chans, NULL, pa->status); |
| 1852 |
ast_frfree(f); |
| 1853 |
if (is_cc_recall) { |
| 1854 |
ast_cc_completed(in, "CC completed, but the caller hung up with DTMF"); |
| 1855 |
} |
| 1856 |
SCOPE_EXIT_RTN_VALUE(NULL, "%s: Caller requested disconnect\n", |
| 1857 |
ast_channel_name(in)); |
| 1858 |
} |
| 1859 |
} |
| 1860 |
|
| 1861 |
|
| 1862 |
AST_LIST_TRAVERSE(out_chans, o, node) { |
| 1863 |
if (!o->chan || !ast_test_flag64(o, DIAL_STILLGOING)) { |
| 1864 |
|
| 1865 |
continue; |
| 1866 |
} |
| 1867 |
switch (f->frametype) { |
| 1868 |
case AST_FRAME_HTML: |
| 1869 |
|
| 1870 |
if (!ast_test_flag64(o, DIAL_NOFORWARDHTML) |
| 1871 |
&& ast_channel_sendhtml(o->chan, f->subclass.integer, f->data.ptr, f->datalen) == -1) { |
| 1872 |
ast_log(LOG_WARNING, "Unable to send URL on %s\n", ast_channel_name(o->chan)); |
| 1873 |
} |
| 1874 |
break; |
| 1875 |
case AST_FRAME_VIDEO: |
| 1876 |
case AST_FRAME_VOICE: |
| 1877 |
case AST_FRAME_IMAGE: |
| 1878 |
if (!single || caller_entertained) { |
| 1879 |
|
| 1880 |
|
| 1881 |
|
| 1882 |
|
| 1883 |
|
| 1884 |
goto skip_frame; |
| 1885 |
} |
| 1886 |
|
| 1887 |
case AST_FRAME_TEXT: |
| 1888 |
case AST_FRAME_DTMF_BEGIN: |
| 1889 |
case AST_FRAME_DTMF_END: |
| 1890 |
if (ast_write(o->chan, f)) { |
| 1891 |
ast_log(LOG_WARNING, "Unable to forward frametype %u on %s\n", |
| 1892 |
f->frametype, ast_channel_name(o->chan)); |
| 1893 |
} |
| 1894 |
break; |
| 1895 |
case AST_FRAME_CONTROL: |
| 1896 |
switch (f->subclass.integer) { |
| 1897 |
case AST_CONTROL_HOLD: |
| 1898 |
ast_verb(3, "Call on %s placed on hold\n", ast_channel_name(o->chan)); |
| 1899 |
ast_indicate_data(o->chan, AST_CONTROL_HOLD, f->data.ptr, f->datalen); |
| 1900 |
break; |
| 1901 |
case AST_CONTROL_UNHOLD: |
| 1902 |
ast_verb(3, "Call on %s left from hold\n", ast_channel_name(o->chan)); |
| 1903 |
ast_indicate(o->chan, AST_CONTROL_UNHOLD); |
| 1904 |
break; |
| 1905 |
case AST_CONTROL_FLASH: |
| 1906 |
ast_verb(3, "Hook flash on %s\n", ast_channel_name(o->chan)); |
| 1907 |
ast_indicate(o->chan, AST_CONTROL_FLASH); |
| 1908 |
break; |
| 1909 |
case AST_CONTROL_VIDUPDATE: |
| 1910 |
case AST_CONTROL_SRCUPDATE: |
| 1911 |
case AST_CONTROL_SRCCHANGE: |
| 1912 |
if (!single || caller_entertained) { |
| 1913 |
|
| 1914 |
|
| 1915 |
|
| 1916 |
|
| 1917 |
|
| 1918 |
goto skip_frame; |
| 1919 |
} |
| 1920 |
ast_verb(3, "%s requested media update control %d, passing it to %s\n", |
| 1921 |
ast_channel_name(in), f->subclass.integer, ast_channel_name(o->chan)); |
| 1922 |
ast_indicate(o->chan, f->subclass.integer); |
| 1923 |
break; |
| 1924 |
case AST_CONTROL_CONNECTED_LINE: |
| 1925 |
if (ast_test_flag64(o, OPT_IGNORE_CONNECTEDLINE)) { |
| 1926 |
ast_verb(3, "Connected line update to %s prevented.\n", ast_channel_name(o->chan)); |
| 1927 |
break; |
| 1928 |
} |
| 1929 |
if (ast_channel_connected_line_sub(in, o->chan, f, 1)) { |
| 1930 |
ast_indicate_data(o->chan, f->subclass.integer, f->data.ptr, f->datalen); |
| 1931 |
} |
| 1932 |
break; |
| 1933 |
case AST_CONTROL_REDIRECTING: |
| 1934 |
if (ast_test_flag64(o, OPT_IGNORE_CONNECTEDLINE)) { |
| 1935 |
ast_verb(3, "Redirecting update to %s prevented.\n", ast_channel_name(o->chan)); |
| 1936 |
break; |
| 1937 |
} |
| 1938 |
if (ast_channel_redirecting_sub(in, o->chan, f, 1)) { |
| 1939 |
ast_indicate_data(o->chan, f->subclass.integer, f->data.ptr, f->datalen); |
| 1940 |
} |
| 1941 |
break; |
| 1942 |
default: |
| 1943 |
|
| 1944 |
goto skip_frame; |
| 1945 |
} |
| 1946 |
break; |
| 1947 |
default: |
| 1948 |
|
| 1949 |
goto skip_frame; |
| 1950 |
} |
| 1951 |
} |
| 1952 |
skip_frame:; |
| 1953 |
ast_frfree(f); |
| 1954 |
} |
| 1955 |
} |
| 1956 |
|
| 1957 |
wait_over: |
| 1958 |
if (!*to_answer || ast_check_hangup(in)) { |
| 1959 |
if (orig_answer_to != -1) { |
| 1960 |
ast_verb(3, "Nobody picked up in %d ms\n", orig_answer_to); |
| 1961 |
} else { |
| 1962 |
ast_verb(3, "Call terminated without answer\n"); |
| 1963 |
} |
| 1964 |
publish_dial_end_event(in, out_chans, NULL, "NOANSWER"); |
| 1965 |
} else if (!*to_progress) { |
| 1966 |
ast_verb(3, "No early media received in %d ms\n", orig_progress_to); |
| 1967 |
publish_dial_end_event(in, out_chans, NULL, "CHANUNAVAIL"); |
| 1968 |
strcpy(pa->status, "CHANUNAVAIL"); |
| 1969 |
*to_answer = 0; |
| 1970 |
} |
| 1971 |
|
| 1972 |
if (is_cc_recall) { |
| 1973 |
ast_cc_completed(in, "Recall completed!"); |
| 1974 |
} |
| 1975 |
SCOPE_EXIT_RTN_VALUE(peer, "%s: %s%s\n", ast_channel_name(in), |
| 1976 |
peer ? "Answered by " : "No answer", peer ? ast_channel_name(peer) : ""); |
| 1977 |
} |
| 1978 |
|
| 1979 |
static int detect_disconnect(struct ast_channel *chan, char code, struct ast_str **featurecode) |
| 1980 |
{ |
| 1981 |
char disconnect_code[AST_FEATURE_MAX_LEN]; |
| 1982 |
int res; |
| 1983 |
|
| 1984 |
ast_str_append(featurecode, 1, "%c", code); |
| 1985 |
|
| 1986 |
res = ast_get_builtin_feature(chan, "disconnect", disconnect_code, sizeof(disconnect_code)); |
| 1987 |
if (res) { |
| 1988 |
ast_str_reset(*featurecode); |
| 1989 |
return 0; |
| 1990 |
} |
| 1991 |
|
| 1992 |
if (strlen(disconnect_code) > ast_str_strlen(*featurecode)) { |
| 1993 |
|
| 1994 |
if (strncmp(disconnect_code, ast_str_buffer(*featurecode), ast_str_strlen(*featurecode))) { |
| 1995 |
ast_str_reset(*featurecode); |
| 1996 |
} |
| 1997 |
return 0; |
| 1998 |
} |
| 1999 |
|
| 2000 |
if (strcmp(disconnect_code, ast_str_buffer(*featurecode))) { |
| 2001 |
ast_str_reset(*featurecode); |
| 2002 |
return 0; |
| 2003 |
} |
| 2004 |
|
| 2005 |
return 1; |
| 2006 |
} |
| 2007 |
|
| 2008 |
|
| 2009 |
static int valid_priv_reply(struct ast_flags64 *opts, int res) |
| 2010 |
{ |
| 2011 |
if (res < '1') |
| 2012 |
return 0; |
| 2013 |
if (ast_test_flag64(opts, OPT_PRIVACY) && res <= '5') |
| 2014 |
return 1; |
| 2015 |
if (ast_test_flag64(opts, OPT_SCREENING) && res <= '4') |
| 2016 |
return 1; |
| 2017 |
return 0; |
| 2018 |
} |
| 2019 |
|
| 2020 |
static int do_privacy(struct ast_channel *chan, struct ast_channel *peer, |
| 2021 |
struct ast_flags64 *opts, char **opt_args, struct privacy_args *pa) |
| 2022 |
{ |
| 2023 |
|
| 2024 |
int res2; |
| 2025 |
int loopcount = 0; |
| 2026 |
|
| 2027 |
|
| 2028 |
|
| 2029 |
|
| 2030 |
|
| 2031 |
|
| 2032 |
|
| 2033 |
|
| 2034 |
|
| 2035 |
if (ast_test_flag64(opts, OPT_MUSICBACK) && !ast_strlen_zero(opt_args[OPT_ARG_MUSICBACK])) { |
| 2036 |
char *original_moh = ast_strdupa(ast_channel_musicclass(chan)); |
| 2037 |
ast_indicate(chan, -1); |
| 2038 |
ast_channel_musicclass_set(chan, opt_args[OPT_ARG_MUSICBACK]); |
| 2039 |
ast_moh_start(chan, opt_args[OPT_ARG_MUSICBACK], NULL); |
| 2040 |
ast_channel_musicclass_set(chan, original_moh); |
| 2041 |
} else if (ast_test_flag64(opts, OPT_RINGBACK) || ast_test_flag64(opts, OPT_RING_WITH_EARLY_MEDIA)) { |
| 2042 |
ast_indicate(chan, AST_CONTROL_RINGING); |
| 2043 |
pa->sentringing++; |
| 2044 |
} |
| 2045 |
|
| 2046 |
|
| 2047 |
res2 = ast_autoservice_start(chan); |
| 2048 |
|
| 2049 |
for (loopcount = 0; loopcount < 3; loopcount++) { |
| 2050 |
if (res2 && loopcount == 0) |
| 2051 |
break; |
| 2052 |
if (!res2) |
| 2053 |
res2 = ast_play_and_wait(peer, "priv-callpending"); |
| 2054 |
if (!valid_priv_reply(opts, res2)) |
| 2055 |
res2 = 0; |
| 2056 |
|
| 2057 |
|
| 2058 |
|
| 2059 |
if (!res2) |
| 2060 |
res2 = ast_play_and_wait(peer, pa->privintro); |
| 2061 |
if (!valid_priv_reply(opts, res2)) |
| 2062 |
res2 = 0; |
| 2063 |
|
| 2064 |
if (!res2) { |
| 2065 |
|
| 2066 |
if (ast_test_flag64(opts, OPT_PRIVACY)) |
| 2067 |
res2 = ast_play_and_wait(peer, "priv-callee-options"); |
| 2068 |
if (ast_test_flag64(opts, OPT_SCREENING)) |
| 2069 |
res2 = ast_play_and_wait(peer, "screen-callee-options"); |
| 2070 |
} |
| 2071 |
|
| 2072 |
|
| 2073 |
|
| 2074 |
|
| 2075 |
|
| 2076 |
|
| 2077 |
|
| 2078 |
|
| 2079 |
|
| 2080 |
|
| 2081 |
|
| 2082 |
|
| 2083 |
|
| 2084 |
|
| 2085 |
|
| 2086 |
|
| 2087 |
|
| 2088 |
if (valid_priv_reply(opts, res2)) |
| 2089 |
break; |
| 2090 |
|
| 2091 |
res2 = ast_play_and_wait(peer, "vm-sorry"); |
| 2092 |
} |
| 2093 |
|
| 2094 |
if (ast_test_flag64(opts, OPT_MUSICBACK)) { |
| 2095 |
ast_moh_stop(chan); |
| 2096 |
} else if (ast_test_flag64(opts, OPT_RINGBACK) || ast_test_flag64(opts, OPT_RING_WITH_EARLY_MEDIA)) { |
| 2097 |
ast_indicate(chan, -1); |
| 2098 |
pa->sentringing = 0; |
| 2099 |
} |
| 2100 |
ast_autoservice_stop(chan); |
| 2101 |
if (ast_test_flag64(opts, OPT_PRIVACY) && (res2 >= '1' && res2 <= '5')) { |
| 2102 |
|
| 2103 |
static const char * const _val[] = { "ALLOW", "DENY", "TORTURE", "KILL", "ALLOW" }; |
| 2104 |
static const int _flag[] = { AST_PRIVACY_ALLOW, AST_PRIVACY_DENY, AST_PRIVACY_TORTURE, AST_PRIVACY_KILL, AST_PRIVACY_ALLOW}; |
| 2105 |
int i = res2 - '1'; |
| 2106 |
ast_verb(3, "--Set privacy database entry %s/%s to %s\n", |
| 2107 |
opt_args[OPT_ARG_PRIVACY], pa->privcid, _val[i]); |
| 2108 |
ast_privacy_set(opt_args[OPT_ARG_PRIVACY], pa->privcid, _flag[i]); |
| 2109 |
} |
| 2110 |
switch (res2) { |
| 2111 |
case '1': |
| 2112 |
break; |
| 2113 |
case '2': |
| 2114 |
ast_copy_string(pa->status, "NOANSWER", sizeof(pa->status)); |
| 2115 |
break; |
| 2116 |
case '3': |
| 2117 |
ast_copy_string(pa->status, "TORTURE", sizeof(pa->status)); |
| 2118 |
break; |
| 2119 |
case '4': |
| 2120 |
ast_copy_string(pa->status, "DONTCALL", sizeof(pa->status)); |
| 2121 |
break; |
| 2122 |
case '5': |
| 2123 |
if (ast_test_flag64(opts, OPT_PRIVACY)) { |
| 2124 |
ast_copy_string(pa->status, "NOANSWER", sizeof(pa->status)); |
| 2125 |
break; |
| 2126 |
} |
| 2127 |
|
| 2128 |
default: |
| 2129 |
|
| 2130 |
|
| 2131 |
|
| 2132 |
|
| 2133 |
ast_verb(3, "privacy: no valid response from the callee. Sending the caller to voicemail, the callee isn't responding\n"); |
| 2134 |
|
| 2135 |
|
| 2136 |
break; |
| 2137 |
} |
| 2138 |
|
| 2139 |
if (res2 == '1') { |
| 2140 |
|
| 2141 |
|
| 2142 |
if (strncmp(pa->privcid, "NOCALLERID", 10) == 0 || ast_test_flag64(opts, OPT_SCREEN_NOINTRO)) { |
| 2143 |
ast_filedelete(pa->privintro, NULL); |
| 2144 |
if (ast_fileexists(pa->privintro, NULL, NULL) > 0) |
| 2145 |
ast_log(LOG_NOTICE, "privacy: ast_filedelete didn't do its job on %s\n", pa->privintro); |
| 2146 |
else |
| 2147 |
ast_verb(3, "Successfully deleted %s intro file\n", pa->privintro); |
| 2148 |
} |
| 2149 |
return 0; |
| 2150 |
} else { |
| 2151 |
return -1; |
| 2152 |
} |
| 2153 |
} |
| 2154 |
|
| 2155 |
|
| 2156 |
static int setup_privacy_args(struct privacy_args *pa, |
| 2157 |
struct ast_flags64 *opts, char *opt_args[], struct ast_channel *chan) |
| 2158 |
{ |
| 2159 |
char callerid[60]; |
| 2160 |
int res; |
| 2161 |
char *l; |
| 2162 |
|
| 2163 |
if (ast_channel_caller(chan)->id.number.valid |
| 2164 |
&& !ast_strlen_zero(ast_channel_caller(chan)->id.number.str)) { |
| 2165 |
l = ast_strdupa(ast_channel_caller(chan)->id.number.str); |
| 2166 |
ast_shrink_phone_number(l); |
| 2167 |
if (ast_test_flag64(opts, OPT_PRIVACY) ) { |
| 2168 |
ast_verb(3, "Privacy DB is '%s', clid is '%s'\n", opt_args[OPT_ARG_PRIVACY], l); |
| 2169 |
pa->privdb_val = ast_privacy_check(opt_args[OPT_ARG_PRIVACY], l); |
| 2170 |
} else { |
| 2171 |
ast_verb(3, "Privacy Screening, clid is '%s'\n", l); |
| 2172 |
pa->privdb_val = AST_PRIVACY_UNKNOWN; |
| 2173 |
} |
| 2174 |
} else { |
| 2175 |
char *tnam, *tn2; |
| 2176 |
|
| 2177 |
tnam = ast_strdupa(ast_channel_name(chan)); |
| 2178 |
|
| 2179 |
for (tn2 = tnam; *tn2; tn2++) { |
| 2180 |
if (*tn2 == '/') |
| 2181 |
*tn2 = '='; |
| 2182 |
} |
| 2183 |
ast_verb(3, "Privacy-- callerid is empty\n"); |
| 2184 |
|
| 2185 |
snprintf(callerid, sizeof(callerid), "NOCALLERID_%s%s", ast_channel_exten(chan), tnam); |
| 2186 |
l = callerid; |
| 2187 |
pa->privdb_val = AST_PRIVACY_UNKNOWN; |
| 2188 |
} |
| 2189 |
|
| 2190 |
ast_copy_string(pa->privcid, l, sizeof(pa->privcid)); |
| 2191 |
|
| 2192 |
if (strncmp(pa->privcid, "NOCALLERID", 10) != 0 && ast_test_flag64(opts, OPT_SCREEN_NOCALLERID)) { |
| 2193 |
|
| 2194 |
ast_verb(3, "CallerID set (%s); N option set; Screening should be off\n", pa->privcid); |
| 2195 |
pa->privdb_val = AST_PRIVACY_ALLOW; |
| 2196 |
} else if (ast_test_flag64(opts, OPT_SCREEN_NOCALLERID) && strncmp(pa->privcid, "NOCALLERID", 10) == 0) { |
| 2197 |
ast_verb(3, "CallerID blank; N option set; Screening should happen; dbval is %d\n", pa->privdb_val); |
| 2198 |
} |
| 2199 |
|
| 2200 |
if (pa->privdb_val == AST_PRIVACY_DENY) { |
| 2201 |
ast_verb(3, "Privacy DB reports PRIVACY_DENY for this callerid. Dial reports unavailable\n"); |
| 2202 |
ast_copy_string(pa->status, "NOANSWER", sizeof(pa->status)); |
| 2203 |
return 0; |
| 2204 |
} else if (pa->privdb_val == AST_PRIVACY_KILL) { |
| 2205 |
ast_copy_string(pa->status, "DONTCALL", sizeof(pa->status)); |
| 2206 |
return 0; |
| 2207 |
} else if (pa->privdb_val == AST_PRIVACY_TORTURE) { |
| 2208 |
ast_copy_string(pa->status, "TORTURE", sizeof(pa->status)); |
| 2209 |
return 0; |
| 2210 |
} else if (pa->privdb_val == AST_PRIVACY_UNKNOWN) { |
| 2211 |
|
| 2212 |
|
| 2213 |
|
| 2214 |
|
| 2215 |
|
| 2216 |
snprintf(pa->privintro, sizeof(pa->privintro), "%s/sounds/priv-callerintros", ast_config_AST_DATA_DIR); |
| 2217 |
if ((res = ast_mkdir(pa->privintro, 0755))) { |
| 2218 |
ast_log(LOG_WARNING, "privacy: can't create directory priv-callerintros: %s\n", strerror(res)); |
| 2219 |
return -1; |
| 2220 |
} |
| 2221 |
|
| 2222 |
snprintf(pa->privintro, sizeof(pa->privintro), "priv-callerintros/%s", pa->privcid); |
| 2223 |
if (ast_fileexists(pa->privintro, NULL, NULL ) > 0 && strncmp(pa->privcid, "NOCALLERID", 10) != 0) { |
| 2224 |
|
| 2225 |
|
| 2226 |
|
| 2227 |
} else { |
| 2228 |
int duration; |
| 2229 |
|
| 2230 |
|
| 2231 |
|
| 2232 |
|
| 2233 |
|
| 2234 |
int silencethreshold = ast_dsp_get_threshold_from_settings(THRESHOLD_SILENCE); |
| 2235 |
ast_answer(chan); |
| 2236 |
res = ast_play_and_record(chan, "priv-recordintro", pa->privintro, 4, "sln", &duration, NULL, silencethreshold, 2000, 0); |
| 2237 |
|
| 2238 |
|
| 2239 |
if (res == -1) { |
| 2240 |
|
| 2241 |
ast_filedelete(pa->privintro, NULL); |
| 2242 |
if (ast_fileexists(pa->privintro, NULL, NULL) > 0) |
| 2243 |
ast_log(LOG_NOTICE, "privacy: ast_filedelete didn't do its job on %s\n", pa->privintro); |
| 2244 |
else |
| 2245 |
ast_verb(3, "Successfully deleted %s intro file\n", pa->privintro); |
| 2246 |
return -1; |
| 2247 |
} |
| 2248 |
if (!ast_streamfile(chan, "vm-dialout", ast_channel_language(chan)) ) |
| 2249 |
ast_waitstream(chan, ""); |
| 2250 |
} |
| 2251 |
} |
| 2252 |
return 1; |
| 2253 |
} |
| 2254 |
|
| 2255 |
static void end_bridge_callback(void *data) |
| 2256 |
{ |
| 2257 |
struct ast_channel *chan = data; |
| 2258 |
|
| 2259 |
ast_channel_lock(chan); |
| 2260 |
ast_channel_stage_snapshot(chan); |
| 2261 |
set_duration_var(chan, "ANSWEREDTIME", ast_channel_get_up_time_ms(chan)); |
| 2262 |
set_duration_var(chan, "DIALEDTIME", ast_channel_get_duration_ms(chan)); |
| 2263 |
ast_channel_stage_snapshot_done(chan); |
| 2264 |
ast_channel_unlock(chan); |
| 2265 |
} |
| 2266 |
|
| 2267 |
static void end_bridge_callback_data_fixup(struct ast_bridge_config *bconfig, struct ast_channel *originator, struct ast_channel *terminator) { |
| 2268 |
bconfig->end_bridge_callback_data = originator; |
| 2269 |
} |
| 2270 |
|
| 2271 |
static int dial_handle_playtones(struct ast_channel *chan, const char *data) |
| 2272 |
{ |
| 2273 |
struct ast_tone_zone_sound *ts = NULL; |
| 2274 |
int res; |
| 2275 |
const char *str = data; |
| 2276 |
|
| 2277 |
if (ast_strlen_zero(str)) { |
| 2278 |
ast_debug(1,"Nothing to play\n"); |
| 2279 |
return -1; |
| 2280 |
} |
| 2281 |
|
| 2282 |
ts = ast_get_indication_tone(ast_channel_zone(chan), str); |
| 2283 |
|
| 2284 |
if (ts && ts->data[0]) { |
| 2285 |
res = ast_playtones_start(chan, 0, ts->data, 0); |
| 2286 |
} else { |
| 2287 |
res = -1; |
| 2288 |
} |
| 2289 |
|
| 2290 |
if (ts) { |
| 2291 |
ts = ast_tone_zone_sound_unref(ts); |
| 2292 |
} |
| 2293 |
|
| 2294 |
if (res) { |
| 2295 |
ast_log(LOG_WARNING, "Unable to start playtone \'%s\'\n", str); |
| 2296 |
} |
| 2297 |
|
| 2298 |
return res; |
| 2299 |
} |
| 2300 |
|
| 2301 |
|
| 2302 |
|
| 2303 |
|
| 2304 |
|
| 2305 |
|
| 2306 |
|
| 2307 |
|
| 2308 |
|
| 2309 |
|
| 2310 |
|
| 2311 |
static void setup_peer_after_bridge_goto(struct ast_channel *chan, struct ast_channel *peer, struct ast_flags64 *opts, char *opt_args[]) |
| 2312 |
{ |
| 2313 |
const char *context; |
| 2314 |
const char *extension; |
| 2315 |
int priority; |
| 2316 |
|
| 2317 |
if (ast_test_flag64(opts, OPT_PEER_H)) { |
| 2318 |
ast_channel_lock(chan); |
| 2319 |
context = ast_strdupa(ast_channel_context(chan)); |
| 2320 |
ast_channel_unlock(chan); |
| 2321 |
ast_bridge_set_after_h(peer, context); |
| 2322 |
} else if (ast_test_flag64(opts, OPT_CALLEE_GO_ON)) { |
| 2323 |
ast_channel_lock(chan); |
| 2324 |
context = ast_strdupa(ast_channel_context(chan)); |
| 2325 |
extension = ast_strdupa(ast_channel_exten(chan)); |
| 2326 |
priority = ast_channel_priority(chan); |
| 2327 |
ast_channel_unlock(chan); |
| 2328 |
ast_bridge_set_after_go_on(peer, context, extension, priority, |
| 2329 |
opt_args[OPT_ARG_CALLEE_GO_ON]); |
| 2330 |
} |
| 2331 |
} |
| 2332 |
|
| 2333 |
static int dial_exec_full(struct ast_channel *chan, const char *data, struct ast_flags64 *peerflags, int *continue_exec) |
| 2334 |
{ |
| 2335 |
int res = -1; |
| 2336 |
char *rest, *cur; |
| 2337 |
struct dial_head out_chans = AST_LIST_HEAD_NOLOCK_INIT_VALUE; |
| 2338 |
struct chanlist *outgoing; |
| 2339 |
struct chanlist *tmp; |
| 2340 |
struct ast_channel *peer = NULL; |
| 2341 |
int to_answer, to_progress; |
| 2342 |
struct cause_args num = { chan, 0, 0, 0 }; |
| 2343 |
int cause, hanguptreecause = -1; |
| 2344 |
|
| 2345 |
struct ast_bridge_config config = { { 0, } }; |
| 2346 |
struct timeval calldurationlimit = { 0, }; |
| 2347 |
char *dtmfcalled = NULL, *dtmfcalling = NULL, *dtmf_progress = NULL; |
| 2348 |
char *mf_progress = NULL, *mf_wink = NULL; |
| 2349 |
char *sf_progress = NULL, *sf_wink = NULL; |
| 2350 |
struct privacy_args pa = { |
| 2351 |
.sentringing = 0, |
| 2352 |
.privdb_val = 0, |
| 2353 |
.status = "INVALIDARGS", |
| 2354 |
.canceled = 0, |
| 2355 |
}; |
| 2356 |
int sentringing = 0, moh = 0; |
| 2357 |
const char *outbound_group = NULL; |
| 2358 |
int result = 0; |
| 2359 |
char *parse; |
| 2360 |
int opermode = 0; |
| 2361 |
int delprivintro = 0; |
| 2362 |
AST_DECLARE_APP_ARGS(args, |
| 2363 |
AST_APP_ARG(peers); |
| 2364 |
AST_APP_ARG(timeout); |
| 2365 |
AST_APP_ARG(options); |
| 2366 |
AST_APP_ARG(url); |
| 2367 |
); |
| 2368 |
struct ast_flags64 opts = { 0, }; |
| 2369 |
char *opt_args[OPT_ARG_ARRAY_SIZE]; |
| 2370 |
int fulldial = 0, num_dialed = 0; |
| 2371 |
int ignore_cc = 0; |
| 2372 |
char device_name[AST_CHANNEL_NAME]; |
| 2373 |
char forced_clid_name[AST_MAX_EXTENSION]; |
| 2374 |
char stored_clid_name[AST_MAX_EXTENSION]; |
| 2375 |
int force_forwards_only; |
| 2376 |
|
| 2377 |
|
| 2378 |
|
| 2379 |
|
| 2380 |
struct ast_party_id forced_clid; |
| 2381 |
|
| 2382 |
|
| 2383 |
|
| 2384 |
|
| 2385 |
|
| 2386 |
|
| 2387 |
|
| 2388 |
|
| 2389 |
|
| 2390 |
struct ast_party_id stored_clid; |
| 2391 |
|
| 2392 |
|
| 2393 |
|
| 2394 |
|
| 2395 |
struct ast_party_caller caller; |
| 2396 |
int max_forwards; |
| 2397 |
struct ast_datastore *topology_ds = NULL; |
| 2398 |
SCOPE_ENTER(1, "%s: Data: %s\n", ast_channel_name(chan), data); |
| 2399 |
|
| 2400 |
|
| 2401 |
ast_channel_lock(chan); |
| 2402 |
ast_channel_stage_snapshot(chan); |
| 2403 |
pbx_builtin_setvar_helper(chan, "DIALSTATUS", ""); |
| 2404 |
pbx_builtin_setvar_helper(chan, "DIALEDPEERNUMBER", ""); |
| 2405 |
pbx_builtin_setvar_helper(chan, "DIALEDPEERNAME", ""); |
| 2406 |
pbx_builtin_setvar_helper(chan, "ANSWEREDTIME", ""); |
| 2407 |
pbx_builtin_setvar_helper(chan, "ANSWEREDTIME_MS", ""); |
| 2408 |
pbx_builtin_setvar_helper(chan, "DIALEDTIME", ""); |
| 2409 |
pbx_builtin_setvar_helper(chan, "DIALEDTIME_MS", ""); |
| 2410 |
pbx_builtin_setvar_helper(chan, "RINGTIME", ""); |
| 2411 |
pbx_builtin_setvar_helper(chan, "RINGTIME_MS", ""); |
| 2412 |
pbx_builtin_setvar_helper(chan, "PROGRESSTIME", ""); |
| 2413 |
pbx_builtin_setvar_helper(chan, "PROGRESSTIME_MS", ""); |
| 2414 |
ast_channel_stage_snapshot_done(chan); |
| 2415 |
max_forwards = ast_max_forwards_get(chan); |
| 2416 |
ast_channel_unlock(chan); |
| 2417 |
|
| 2418 |
if (max_forwards <= 0) { |
| 2419 |
ast_log(LOG_WARNING, "Cannot place outbound call from channel '%s'. Max forwards exceeded\n", |
| 2420 |
ast_channel_name(chan)); |
| 2421 |
pbx_builtin_setvar_helper(chan, "DIALSTATUS", "BUSY"); |
| 2422 |
SCOPE_EXIT_RTN_VALUE(-1, "%s: Max forwards exceeded\n", ast_channel_name(chan)); |
| 2423 |
} |
| 2424 |
|
| 2425 |
if (ast_check_hangup_locked(chan)) { |
| 2426 |
|
| 2427 |
|
| 2428 |
|
| 2429 |
|
| 2430 |
|
| 2431 |
|
| 2432 |
|
| 2433 |
|
| 2434 |
|
| 2435 |
|
| 2436 |
|
| 2437 |
|
| 2438 |
ast_verb(3, "Caller hung up before dial.\n"); |
| 2439 |
pbx_builtin_setvar_helper(chan, "DIALSTATUS", "CANCEL"); |
| 2440 |
SCOPE_EXIT_RTN_VALUE(-1, "%s: Caller hung up before dial\n", ast_channel_name(chan)); |
| 2441 |
} |
| 2442 |
|
| 2443 |
parse = ast_strdupa(data ?: ""); |
| 2444 |
|
| 2445 |
AST_STANDARD_APP_ARGS(args, parse); |
| 2446 |
|
| 2447 |
if (!ast_strlen_zero(args.options) && |
| 2448 |
ast_app_parse_options64(dial_exec_options, &opts, opt_args, args.options)) { |
| 2449 |
pbx_builtin_setvar_helper(chan, "DIALSTATUS", pa.status); |
| 2450 |
goto done; |
| 2451 |
} |
| 2452 |
|
| 2453 |
if (ast_cc_call_init(chan, &ignore_cc)) { |
| 2454 |
goto done; |
| 2455 |
} |
| 2456 |
|
| 2457 |
if (ast_test_flag64(&opts, OPT_SCREEN_NOINTRO) && !ast_strlen_zero(opt_args[OPT_ARG_SCREEN_NOINTRO])) { |
| 2458 |
delprivintro = atoi(opt_args[OPT_ARG_SCREEN_NOINTRO]); |
| 2459 |
|
| 2460 |
if (delprivintro < 0 || delprivintro > 1) { |
| 2461 |
ast_log(LOG_WARNING, "Unknown argument %d specified to n option, ignoring\n", delprivintro); |
| 2462 |
delprivintro = 0; |
| 2463 |
} |
| 2464 |
} |
| 2465 |
|
| 2466 |
if (!ast_test_flag64(&opts, OPT_RINGBACK)) { |
| 2467 |
opt_args[OPT_ARG_RINGBACK] = NULL; |
| 2468 |
} |
| 2469 |
|
| 2470 |
if (ast_test_flag64(&opts, OPT_OPERMODE)) { |
| 2471 |
opermode = ast_strlen_zero(opt_args[OPT_ARG_OPERMODE]) ? 1 : atoi(opt_args[OPT_ARG_OPERMODE]); |
| 2472 |
ast_verb(3, "Setting operator services mode to %d.\n", opermode); |
| 2473 |
} |
| 2474 |
|
| 2475 |
if (ast_test_flag64(&opts, OPT_DURATION_STOP) && !ast_strlen_zero(opt_args[OPT_ARG_DURATION_STOP])) { |
| 2476 |
calldurationlimit.tv_sec = atoi(opt_args[OPT_ARG_DURATION_STOP]); |
| 2477 |
if (!calldurationlimit.tv_sec) { |
| 2478 |
ast_log(LOG_WARNING, "Dial does not accept S(%s)\n", opt_args[OPT_ARG_DURATION_STOP]); |
| 2479 |
pbx_builtin_setvar_helper(chan, "DIALSTATUS", pa.status); |
| 2480 |
goto done; |
| 2481 |
} |
| 2482 |
ast_verb(3, "Setting call duration limit to %.3lf seconds.\n", calldurationlimit.tv_sec + calldurationlimit.tv_usec / 1000000.0); |
| 2483 |
} |
| 2484 |
|
| 2485 |
if (ast_test_flag64(&opts, OPT_SENDDTMF) && !ast_strlen_zero(opt_args[OPT_ARG_SENDDTMF])) { |
| 2486 |
sf_wink = opt_args[OPT_ARG_SENDDTMF]; |
| 2487 |
dtmfcalled = strsep(&sf_wink, ":"); |
| 2488 |
dtmfcalling = strsep(&sf_wink, ":"); |
| 2489 |
dtmf_progress = strsep(&sf_wink, ":"); |
| 2490 |
mf_progress = strsep(&sf_wink, ":"); |
| 2491 |
mf_wink = strsep(&sf_wink, ":"); |
| 2492 |
sf_progress = strsep(&sf_wink, ":"); |
| 2493 |
} |
| 2494 |
|
| 2495 |
if (ast_test_flag64(&opts, OPT_DURATION_LIMIT) && !ast_strlen_zero(opt_args[OPT_ARG_DURATION_LIMIT])) { |
| 2496 |
if (ast_bridge_timelimit(chan, &config, opt_args[OPT_ARG_DURATION_LIMIT], &calldurationlimit)) |
| 2497 |
goto done; |
| 2498 |
} |
| 2499 |
|
| 2500 |
|
| 2501 |
ast_party_id_init(&forced_clid); |
| 2502 |
force_forwards_only = 0; |
| 2503 |
if (ast_test_flag64(&opts, OPT_FORCECLID)) { |
| 2504 |
if (ast_strlen_zero(opt_args[OPT_ARG_FORCECLID])) { |
| 2505 |
ast_channel_lock(chan); |
| 2506 |
forced_clid.number.str = ast_strdupa(ast_channel_exten(chan)); |
| 2507 |
ast_channel_unlock(chan); |
| 2508 |
forced_clid_name[0] = '\0'; |
| 2509 |
forced_clid.name.str = (char *) get_cid_name(forced_clid_name, |
| 2510 |
sizeof(forced_clid_name), chan); |
| 2511 |
force_forwards_only = 1; |
| 2512 |
} else { |
| 2513 |
|
| 2514 |
ast_callerid_parse(opt_args[OPT_ARG_FORCECLID], &forced_clid.name.str, |
| 2515 |
&forced_clid.number.str); |
| 2516 |
} |
| 2517 |
if (!ast_strlen_zero(forced_clid.name.str)) { |
| 2518 |
forced_clid.name.valid = 1; |
| 2519 |
} |
| 2520 |
if (!ast_strlen_zero(forced_clid.number.str)) { |
| 2521 |
forced_clid.number.valid = 1; |
| 2522 |
} |
| 2523 |
} |
| 2524 |
if (ast_test_flag64(&opts, OPT_FORCE_CID_TAG) |
| 2525 |
&& !ast_strlen_zero(opt_args[OPT_ARG_FORCE_CID_TAG])) { |
| 2526 |
forced_clid.tag = opt_args[OPT_ARG_FORCE_CID_TAG]; |
| 2527 |
} |
| 2528 |
forced_clid.number.presentation = AST_PRES_ALLOWED_USER_NUMBER_PASSED_SCREEN; |
| 2529 |
if (ast_test_flag64(&opts, OPT_FORCE_CID_PRES) |
| 2530 |
&& !ast_strlen_zero(opt_args[OPT_ARG_FORCE_CID_PRES])) { |
| 2531 |
int pres; |
| 2532 |
|
| 2533 |
pres = ast_parse_caller_presentation(opt_args[OPT_ARG_FORCE_CID_PRES]); |
| 2534 |
if (0 <= pres) { |
| 2535 |
forced_clid.number.presentation = pres; |
| 2536 |
} |
| 2537 |
} |
| 2538 |
|
| 2539 |
|
| 2540 |
ast_party_id_init(&stored_clid); |
| 2541 |
if (ast_test_flag64(&opts, OPT_ORIGINAL_CLID)) { |
| 2542 |
if (ast_strlen_zero(opt_args[OPT_ARG_ORIGINAL_CLID])) { |
| 2543 |
ast_channel_lock(chan); |
| 2544 |
ast_party_id_set_init(&stored_clid, &ast_channel_caller(chan)->id); |
| 2545 |
if (!ast_strlen_zero(ast_channel_caller(chan)->id.name.str)) { |
| 2546 |
stored_clid.name.str = ast_strdupa(ast_channel_caller(chan)->id.name.str); |
| 2547 |
} |
| 2548 |
if (!ast_strlen_zero(ast_channel_caller(chan)->id.number.str)) { |
| 2549 |
stored_clid.number.str = ast_strdupa(ast_channel_caller(chan)->id.number.str); |
| 2550 |
} |
| 2551 |
if (!ast_strlen_zero(ast_channel_caller(chan)->id.subaddress.str)) { |
| 2552 |
stored_clid.subaddress.str = ast_strdupa(ast_channel_caller(chan)->id.subaddress.str); |
| 2553 |
} |
| 2554 |
if (!ast_strlen_zero(ast_channel_caller(chan)->id.tag)) { |
| 2555 |
stored_clid.tag = ast_strdupa(ast_channel_caller(chan)->id.tag); |
| 2556 |
} |
| 2557 |
ast_channel_unlock(chan); |
| 2558 |
} else { |
| 2559 |
|
| 2560 |
ast_callerid_parse(opt_args[OPT_ARG_ORIGINAL_CLID], &stored_clid.name.str, |
| 2561 |
&stored_clid.number.str); |
| 2562 |
if (!ast_strlen_zero(stored_clid.name.str)) { |
| 2563 |
stored_clid.name.valid = 1; |
| 2564 |
} |
| 2565 |
if (!ast_strlen_zero(stored_clid.number.str)) { |
| 2566 |
stored_clid.number.valid = 1; |
| 2567 |
} |
| 2568 |
} |
| 2569 |
} else { |
| 2570 |
|
| 2571 |
|
| 2572 |
|
| 2573 |
|
| 2574 |
stored_clid_name[0] = '\0'; |
| 2575 |
stored_clid.name.str = (char *) get_cid_name(stored_clid_name, |
| 2576 |
sizeof(stored_clid_name), chan); |
| 2577 |
if (ast_strlen_zero(stored_clid.name.str)) { |
| 2578 |
stored_clid.name.str = NULL; |
| 2579 |
} else { |
| 2580 |
stored_clid.name.valid = 1; |
| 2581 |
} |
| 2582 |
ast_channel_lock(chan); |
| 2583 |
stored_clid.number.str = ast_strdupa(ast_channel_exten(chan)); |
| 2584 |
stored_clid.number.valid = 1; |
| 2585 |
ast_channel_unlock(chan); |
| 2586 |
} |
| 2587 |
|
| 2588 |
if (ast_test_flag64(&opts, OPT_RESETCDR)) { |
| 2589 |
ast_cdr_reset(ast_channel_name(chan), 0); |
| 2590 |
} |
| 2591 |
if (ast_test_flag64(&opts, OPT_PRIVACY) && ast_strlen_zero(opt_args[OPT_ARG_PRIVACY])) |
| 2592 |
opt_args[OPT_ARG_PRIVACY] = ast_strdupa(ast_channel_exten(chan)); |
| 2593 |
|
| 2594 |
if (ast_test_flag64(&opts, OPT_PRIVACY) || ast_test_flag64(&opts, OPT_SCREENING)) { |
| 2595 |
res = setup_privacy_args(&pa, &opts, opt_args, chan); |
| 2596 |
if (res <= 0) |
| 2597 |
goto out; |
| 2598 |
res = -1; |
| 2599 |
} |
| 2600 |
|
| 2601 |
if (continue_exec) |
| 2602 |
*continue_exec = 0; |
| 2603 |
|
| 2604 |
|
| 2605 |
|
| 2606 |
ast_channel_lock(chan); |
| 2607 |
if ((outbound_group = pbx_builtin_getvar_helper(chan, "OUTBOUND_GROUP_ONCE"))) { |
| 2608 |
outbound_group = ast_strdupa(outbound_group); |
| 2609 |
pbx_builtin_setvar_helper(chan, "OUTBOUND_GROUP_ONCE", NULL); |
| 2610 |
} else if ((outbound_group = pbx_builtin_getvar_helper(chan, "OUTBOUND_GROUP"))) { |
| 2611 |
outbound_group = ast_strdupa(outbound_group); |
| 2612 |
} |
| 2613 |
ast_channel_unlock(chan); |
| 2614 |
|
| 2615 |
|
| 2616 |
ast_copy_flags64(peerflags, &opts, OPT_DTMF_EXIT | OPT_GO_ON | OPT_ORIGINAL_CLID |
| 2617 |
| OPT_CALLER_HANGUP | OPT_IGNORE_FORWARDING | OPT_CANCEL_TIMEOUT |
| 2618 |
| OPT_ANNOUNCE | OPT_CALLEE_GOSUB | OPT_FORCECLID); |
| 2619 |
|
| 2620 |
|
| 2621 |
if (ast_test_flag64(&opts, OPT_PREDIAL_CALLER) |
| 2622 |
&& !ast_strlen_zero(opt_args[OPT_ARG_PREDIAL_CALLER])) { |
| 2623 |
ast_replace_subargument_delimiter(opt_args[OPT_ARG_PREDIAL_CALLER]); |
| 2624 |
ast_app_exec_sub(NULL, chan, opt_args[OPT_ARG_PREDIAL_CALLER], 0); |
| 2625 |
} |
| 2626 |
|
| 2627 |
|
| 2628 |
rest = args.peers; |
| 2629 |
while ((cur = strsep(&rest, "&"))) { |
| 2630 |
struct ast_channel *tc; |
| 2631 |
char *number; |
| 2632 |
char *tech; |
| 2633 |
int i; |
| 2634 |
size_t tech_len; |
| 2635 |
size_t number_len; |
| 2636 |
struct ast_stream_topology *topology; |
| 2637 |
struct ast_stream *stream; |
| 2638 |
|
| 2639 |
cur = ast_strip(cur); |
| 2640 |
if (ast_strlen_zero(cur)) { |
| 2641 |
|
| 2642 |
continue; |
| 2643 |
} |
| 2644 |
|
| 2645 |
|
| 2646 |
number = cur; |
| 2647 |
tech = strsep(&number, "/"); |
| 2648 |
|
| 2649 |
num_dialed++; |
| 2650 |
if (ast_strlen_zero(number)) { |
| 2651 |
ast_log(LOG_WARNING, "Dial argument takes format (technology/resource)\n"); |
| 2652 |
goto out; |
| 2653 |
} |
| 2654 |
|
| 2655 |
tech_len = strlen(tech) + 1; |
| 2656 |
number_len = strlen(number) + 1; |
| 2657 |
tmp = ast_calloc(1, sizeof(*tmp) + (2 * tech_len) + number_len); |
| 2658 |
if (!tmp) { |
| 2659 |
goto out; |
| 2660 |
} |
| 2661 |
|
| 2662 |
|
| 2663 |
cur = tmp->stuff; |
| 2664 |
strcpy(cur, tech); |
| 2665 |
tmp->tech = cur; |
| 2666 |
cur += tech_len; |
| 2667 |
strcpy(cur, tech); |
| 2668 |
cur[tech_len - 1] = '/'; |
| 2669 |
tmp->interface = cur; |
| 2670 |
cur += tech_len; |
| 2671 |
strcpy(cur, number); |
| 2672 |
tmp->number = cur; |
| 2673 |
|
| 2674 |
if (opts.flags) { |
| 2675 |
|
| 2676 |
ast_copy_flags64(tmp, &opts, |
| 2677 |
OPT_CANCEL_ELSEWHERE | |
| 2678 |
OPT_CALLEE_TRANSFER | OPT_CALLER_TRANSFER | |
| 2679 |
OPT_CALLEE_HANGUP | OPT_CALLER_HANGUP | |
| 2680 |
OPT_CALLEE_MONITOR | OPT_CALLER_MONITOR | |
| 2681 |
OPT_CALLEE_PARK | OPT_CALLER_PARK | |
| 2682 |
OPT_CALLEE_MIXMONITOR | OPT_CALLER_MIXMONITOR | |
| 2683 |
OPT_RINGBACK | OPT_MUSICBACK | OPT_FORCECLID | OPT_IGNORE_CONNECTEDLINE | |
| 2684 |
OPT_RING_WITH_EARLY_MEDIA); |
| 2685 |
ast_set2_flag64(tmp, args.url, DIAL_NOFORWARDHTML); |
| 2686 |
} |
| 2687 |
|
| 2688 |
|
| 2689 |
|
| 2690 |
ast_channel_lock(chan); |
| 2691 |
|
| 2692 |
|
| 2693 |
|
| 2694 |
|
| 2695 |
|
| 2696 |
|
| 2697 |
ast_party_connected_line_copy(&tmp->connected, ast_channel_connected(chan)); |
| 2698 |
|
| 2699 |
if (ast_test_flag64(&opts, OPT_TOPOLOGY_PRESERVE)) { |
| 2700 |
topology_ds = ast_channel_datastore_find(chan, &topology_ds_info, NULL); |
| 2701 |
|
| 2702 |
if (!topology_ds && (topology_ds = ast_datastore_alloc(&topology_ds_info, NULL))) { |
| 2703 |
topology_ds->data = ast_stream_topology_clone(ast_channel_get_stream_topology(chan)); |
| 2704 |
ast_channel_datastore_add(chan, topology_ds); |
| 2705 |
} |
| 2706 |
} |
| 2707 |
|
| 2708 |
if (topology_ds) { |
| 2709 |
ao2_ref(topology_ds->data, +1); |
| 2710 |
topology = topology_ds->data; |
| 2711 |
} else { |
| 2712 |
topology = ast_stream_topology_clone(ast_channel_get_stream_topology(chan)); |
| 2713 |
} |
| 2714 |
|
| 2715 |
ast_channel_unlock(chan); |
| 2716 |
|
| 2717 |
for (i = 0; i < ast_stream_topology_get_count(topology); ++i) { |
| 2718 |
stream = ast_stream_topology_get_stream(topology, i); |
| 2719 |
|
| 2720 |
|
| 2721 |
|
| 2722 |
|
| 2723 |
|
| 2724 |
|
| 2725 |
if (ast_stream_get_state(stream) == AST_STREAM_STATE_RECVONLY) { |
| 2726 |
ast_stream_set_state(stream, AST_STREAM_STATE_SENDONLY); |
| 2727 |
} else if (ast_stream_get_state(stream) == AST_STREAM_STATE_SENDONLY) { |
| 2728 |
ast_stream_set_state(stream, AST_STREAM_STATE_RECVONLY); |
| 2729 |
} |
| 2730 |
} |
| 2731 |
|
| 2732 |
tc = ast_request_with_stream_topology(tmp->tech, topology, NULL, chan, tmp->number, &cause); |
| 2733 |
|
| 2734 |
ast_stream_topology_free(topology); |
| 2735 |
|
| 2736 |
if (!tc) { |
| 2737 |
|
| 2738 |
|
| 2739 |
ast_log(LOG_NOTICE, "Unable to create channel of type '%s' (cause %d - %s)\n", |
| 2740 |
tmp->tech, cause, ast_cause2str(cause)); |
| 2741 |
handle_cause(cause, &num); |
| 2742 |
if (!rest) { |
| 2743 |
|
| 2744 |
ast_channel_hangupcause_set(chan, cause); |
| 2745 |
} |
| 2746 |
if (!ignore_cc && (cause == AST_CAUSE_BUSY || cause == AST_CAUSE_CONGESTION)) { |
| 2747 |
if (!ast_cc_callback(chan, tmp->tech, tmp->number, ast_cc_busy_interface)) { |
| 2748 |
ast_cc_extension_monitor_add_dialstring(chan, tmp->interface, ""); |
| 2749 |
} |
| 2750 |
} |
| 2751 |
chanlist_free(tmp); |
| 2752 |
continue; |
| 2753 |
} |
| 2754 |
|
| 2755 |
ast_channel_get_device_name(tc, device_name, sizeof(device_name)); |
| 2756 |
if (!ignore_cc) { |
| 2757 |
ast_cc_extension_monitor_add_dialstring(chan, tmp->interface, device_name); |
| 2758 |
} |
| 2759 |
|
| 2760 |
ast_channel_lock_both(tc, chan); |
| 2761 |
ast_channel_stage_snapshot(tc); |
| 2762 |
|
| 2763 |
pbx_builtin_setvar_helper(tc, "DIALEDPEERNUMBER", tmp->number); |
| 2764 |
|
| 2765 |
|
| 2766 |
if (!AST_LIST_FIRST(&out_chans) && !rest && CAN_EARLY_BRIDGE(peerflags, chan, tc)) { |
| 2767 |
|
| 2768 |
ast_rtp_instance_early_bridge_make_compatible(tc, chan); |
| 2769 |
} |
| 2770 |
|
| 2771 |
|
| 2772 |
ast_channel_inherit_variables(chan, tc); |
| 2773 |
ast_channel_datastore_inherit(chan, tc); |
| 2774 |
ast_max_forwards_decrement(tc); |
| 2775 |
|
| 2776 |
ast_channel_appl_set(tc, "AppDial"); |
| 2777 |
ast_channel_data_set(tc, "(Outgoing Line)"); |
| 2778 |
|
| 2779 |
memset(ast_channel_whentohangup(tc), 0, sizeof(*ast_channel_whentohangup(tc))); |
| 2780 |
|
| 2781 |
|
| 2782 |
ast_party_caller_set_init(&caller, ast_channel_caller(tc)); |
| 2783 |
if (ast_test_flag64(peerflags, OPT_ORIGINAL_CLID)) { |
| 2784 |
caller.id = stored_clid; |
| 2785 |
ast_channel_set_caller_event(tc, &caller, NULL); |
| 2786 |
ast_set_flag64(tmp, DIAL_CALLERID_ABSENT); |
| 2787 |
} else if (ast_strlen_zero(S_COR(ast_channel_caller(tc)->id.number.valid, |
| 2788 |
ast_channel_caller(tc)->id.number.str, NULL))) { |
| 2789 |
|
| 2790 |
|
| 2791 |
|
| 2792 |
|
| 2793 |
caller.id = stored_clid; |
| 2794 |
if (!caller.id.name.valid |
| 2795 |
&& !ast_strlen_zero(S_COR(ast_channel_connected(chan)->id.name.valid, |
| 2796 |
ast_channel_connected(chan)->id.name.str, NULL))) { |
| 2797 |
|
| 2798 |
|
| 2799 |
|
| 2800 |
|
| 2801 |
caller.id.name.valid = 1; |
| 2802 |
caller.id.name = ast_channel_connected(chan)->id.name; |
| 2803 |
} |
| 2804 |
ast_channel_set_caller_event(tc, &caller, NULL); |
| 2805 |
ast_set_flag64(tmp, DIAL_CALLERID_ABSENT); |
| 2806 |
} else if (ast_strlen_zero(S_COR(ast_channel_caller(tc)->id.name.valid, ast_channel_caller(tc)->id.name.str, |
| 2807 |
NULL))) { |
| 2808 |
|
| 2809 |
if (!ast_strlen_zero(S_COR(ast_channel_connected(chan)->id.name.valid, |
| 2810 |
ast_channel_connected(chan)->id.name.str, NULL))) { |
| 2811 |
|
| 2812 |
|
| 2813 |
|
| 2814 |
|
| 2815 |
caller.id.name.valid = 1; |
| 2816 |
caller.id.name = ast_channel_connected(chan)->id.name; |
| 2817 |
ast_channel_set_caller_event(tc, &caller, NULL); |
| 2818 |
} |
| 2819 |
} |
| 2820 |
|
| 2821 |
|
| 2822 |
if (ast_test_flag64(peerflags, OPT_FORCECLID) && !force_forwards_only) { |
| 2823 |
struct ast_party_connected_line connected; |
| 2824 |
|
| 2825 |
ast_party_connected_line_set_init(&connected, ast_channel_connected(tc)); |
| 2826 |
connected.id = forced_clid; |
| 2827 |
ast_channel_set_connected_line(tc, &connected, NULL); |
| 2828 |
} else { |
| 2829 |
ast_connected_line_copy_from_caller(ast_channel_connected(tc), ast_channel_caller(chan)); |
| 2830 |
} |
| 2831 |
|
| 2832 |
ast_party_redirecting_copy(ast_channel_redirecting(tc), ast_channel_redirecting(chan)); |
| 2833 |
|
| 2834 |
ast_channel_dialed(tc)->transit_network_select = ast_channel_dialed(chan)->transit_network_select; |
| 2835 |
|
| 2836 |
ast_channel_req_accountcodes(tc, chan, AST_CHANNEL_REQUESTOR_BRIDGE_PEER); |
| 2837 |
if (ast_strlen_zero(ast_channel_musicclass(tc))) { |
| 2838 |
ast_channel_musicclass_set(tc, ast_channel_musicclass(chan)); |
| 2839 |
} |
| 2840 |
|
| 2841 |
|
| 2842 |
ast_channel_adsicpe_set(tc, ast_channel_adsicpe(chan)); |
| 2843 |
ast_channel_transfercapability_set(tc, ast_channel_transfercapability(chan)); |
| 2844 |
|
| 2845 |
|
| 2846 |
if (outbound_group) |
| 2847 |
ast_app_group_set_channel(tc, outbound_group); |
| 2848 |
|
| 2849 |
if (ast_channel_hangupcause(chan) == AST_CAUSE_ANSWERED_ELSEWHERE) |
| 2850 |
ast_channel_hangupcause_set(tc, AST_CAUSE_ANSWERED_ELSEWHERE); |
| 2851 |
|
| 2852 |
|
| 2853 |
if (ast_test_flag64(&opts, OPT_CANCEL_ELSEWHERE)) |
| 2854 |
ast_channel_hangupcause_set(tc, AST_CAUSE_ANSWERED_ELSEWHERE); |
| 2855 |
|
| 2856 |
|
| 2857 |
|
| 2858 |
ast_channel_dialcontext_set(tc, ast_channel_context(chan)); |
| 2859 |
ast_channel_exten_set(tc, ast_channel_exten(chan)); |
| 2860 |
|
| 2861 |
ast_channel_stage_snapshot_done(tc); |
| 2862 |
|
| 2863 |
|
| 2864 |
tmp->orig_chan_name = ast_strdup(ast_channel_name(tc)); |
| 2865 |
|
| 2866 |
ast_channel_unlock(tc); |
| 2867 |
ast_channel_unlock(chan); |
| 2868 |
|
| 2869 |
|
| 2870 |
tmp->chan = tc; |
| 2871 |
AST_LIST_INSERT_TAIL(&out_chans, tmp, node); |
| 2872 |
} |
| 2873 |
|
| 2874 |
|
| 2875 |
|
| 2876 |
if (!num_dialed) { |
| 2877 |
ast_verb(3, "No devices or endpoints to dial (technology/resource)\n"); |
| 2878 |
if (continue_exec) { |
| 2879 |
|
| 2880 |
*continue_exec = 1; |
| 2881 |
} |
| 2882 |
strcpy(pa.status, "CHANUNAVAIL"); |
| 2883 |
res = 0; |
| 2884 |
goto out; |
| 2885 |
} |
| 2886 |
|
| 2887 |
|
| 2888 |
|
| 2889 |
|
| 2890 |
|
| 2891 |
|
| 2892 |
|
| 2893 |
|
| 2894 |
|
| 2895 |
|
| 2896 |
|
| 2897 |
|
| 2898 |
|
| 2899 |
if (ast_test_flag64(&opts, OPT_PREDIAL_CALLEE) |
| 2900 |
&& !ast_strlen_zero(opt_args[OPT_ARG_PREDIAL_CALLEE]) |
| 2901 |
&& !AST_LIST_EMPTY(&out_chans)) { |
| 2902 |
const char *predial_callee; |
| 2903 |
|
| 2904 |
ast_replace_subargument_delimiter(opt_args[OPT_ARG_PREDIAL_CALLEE]); |
| 2905 |
predial_callee = ast_app_expand_sub_args(chan, opt_args[OPT_ARG_PREDIAL_CALLEE]); |
| 2906 |
if (predial_callee) { |
| 2907 |
ast_autoservice_start(chan); |
| 2908 |
AST_LIST_TRAVERSE(&out_chans, tmp, node) { |
| 2909 |
ast_pre_call(tmp->chan, predial_callee); |
| 2910 |
} |
| 2911 |
ast_autoservice_stop(chan); |
| 2912 |
ast_free((char *) predial_callee); |
| 2913 |
} |
| 2914 |
} |
| 2915 |
|
| 2916 |
|
| 2917 |
AST_LIST_TRAVERSE_SAFE_BEGIN(&out_chans, tmp, node) { |
| 2918 |
res = ast_call(tmp->chan, tmp->number, 0); |
| 2919 |
ast_channel_lock(chan); |
| 2920 |
|
| 2921 |
|
| 2922 |
if (res) { |
| 2923 |
|
| 2924 |
ast_debug(1, "ast call on peer returned %d\n", res); |
| 2925 |
ast_verb(3, "Couldn't call %s\n", tmp->interface); |
| 2926 |
if (ast_channel_hangupcause(tmp->chan)) { |
| 2927 |
ast_channel_hangupcause_set(chan, ast_channel_hangupcause(tmp->chan)); |
| 2928 |
} |
| 2929 |
ast_channel_unlock(chan); |
| 2930 |
ast_cc_call_failed(chan, tmp->chan, tmp->interface); |
| 2931 |
ast_hangup(tmp->chan); |
| 2932 |
tmp->chan = NULL; |
| 2933 |
AST_LIST_REMOVE_CURRENT(node); |
| 2934 |
chanlist_free(tmp); |
| 2935 |
continue; |
| 2936 |
} |
| 2937 |
|
| 2938 |
ast_channel_publish_dial(chan, tmp->chan, tmp->number, NULL); |
| 2939 |
ast_channel_unlock(chan); |
| 2940 |
|
| 2941 |
ast_verb(3, "Called %s\n", tmp->interface); |
| 2942 |
ast_set_flag64(tmp, DIAL_STILLGOING); |
| 2943 |
|
| 2944 |
|
| 2945 |
if (ast_channel_state(tmp->chan) == AST_STATE_UP) { |
| 2946 |
break; |
| 2947 |
} |
| 2948 |
} |
| 2949 |
AST_LIST_TRAVERSE_SAFE_END; |
| 2950 |
|
| 2951 |
if (ast_strlen_zero(args.timeout)) { |
| 2952 |
to_answer = -1; |
| 2953 |
to_progress = -1; |
| 2954 |
} else { |
| 2955 |
double tmp; |
| 2956 |
char *anstimeout = strsep(&args.timeout, "^"); |
| 2957 |
if (!ast_strlen_zero(anstimeout)) { |
| 2958 |
if (sscanf(anstimeout, "%30lf", &tmp) == 1 && tmp > 0) { |
| 2959 |
to_answer = tmp * 1000; |
| 2960 |
ast_debug(3, "Dial timeout set to %d ms\n", to_answer); |
| 2961 |
} else { |
| 2962 |
ast_log(LOG_WARNING, "Invalid answer timeout specified: '%s'. Setting timeout to infinite\n", anstimeout); |
| 2963 |
to_answer = -1; |
| 2964 |
} |
| 2965 |
} else { |
| 2966 |
to_answer = -1; |
| 2967 |
} |
| 2968 |
if (!ast_strlen_zero(args.timeout)) { |
| 2969 |
if (sscanf(args.timeout, "%30lf", &tmp) == 1 && tmp > 0) { |
| 2970 |
to_progress = tmp * 1000; |
| 2971 |
ast_debug(3, "Dial progress timeout set to %d ms\n", to_progress); |
| 2972 |
} else { |
| 2973 |
ast_log(LOG_WARNING, "Invalid progress timeout specified: '%s'. Setting timeout to infinite\n", args.timeout); |
| 2974 |
to_progress = -1; |
| 2975 |
} |
| 2976 |
} else { |
| 2977 |
to_progress = -1; |
| 2978 |
} |
| 2979 |
} |
| 2980 |
|
| 2981 |
outgoing = AST_LIST_FIRST(&out_chans); |
| 2982 |
if (!outgoing) { |
| 2983 |
strcpy(pa.status, "CHANUNAVAIL"); |
| 2984 |
if (fulldial == num_dialed) { |
| 2985 |
res = -1; |
| 2986 |
goto out; |
| 2987 |
} |
| 2988 |
} else { |
| 2989 |
|
| 2990 |
strcpy(pa.status, "NOANSWER"); |
| 2991 |
if (ast_test_flag64(outgoing, OPT_MUSICBACK)) { |
| 2992 |
moh = 1; |
| 2993 |
if (!ast_strlen_zero(opt_args[OPT_ARG_MUSICBACK])) { |
| 2994 |
char *original_moh = ast_strdupa(ast_channel_musicclass(chan)); |
| 2995 |
ast_channel_musicclass_set(chan, opt_args[OPT_ARG_MUSICBACK]); |
| 2996 |
ast_moh_start(chan, opt_args[OPT_ARG_MUSICBACK], NULL); |
| 2997 |
ast_channel_musicclass_set(chan, original_moh); |
| 2998 |
} else { |
| 2999 |
ast_moh_start(chan, NULL, NULL); |
| 3000 |
} |
| 3001 |
ast_indicate(chan, AST_CONTROL_PROGRESS); |
| 3002 |
} else if (ast_test_flag64(outgoing, OPT_RINGBACK) || ast_test_flag64(outgoing, OPT_RING_WITH_EARLY_MEDIA)) { |
| 3003 |
if (!ast_strlen_zero(opt_args[OPT_ARG_RINGBACK])) { |
| 3004 |
if (dial_handle_playtones(chan, opt_args[OPT_ARG_RINGBACK])){ |
| 3005 |
ast_indicate(chan, AST_CONTROL_RINGING); |
| 3006 |
sentringing++; |
| 3007 |
} else { |
| 3008 |
ast_indicate(chan, AST_CONTROL_PROGRESS); |
| 3009 |
} |
| 3010 |
} else { |
| 3011 |
ast_indicate(chan, AST_CONTROL_RINGING); |
| 3012 |
sentringing++; |
| 3013 |
} |
| 3014 |
} |
| 3015 |
} |
| 3016 |
|
| 3017 |
peer = wait_for_answer(chan, &out_chans, &to_answer, &to_progress, peerflags, opt_args, &pa, &num, &result, |
| 3018 |
dtmf_progress, mf_progress, mf_wink, sf_progress, sf_wink, |
| 3019 |
(ast_test_flag64(&opts, OPT_HEARPULSING) ? 1 : 0), |
| 3020 |
ignore_cc, &forced_clid, &stored_clid, &config); |
| 3021 |
|
| 3022 |
if (!peer) { |
| 3023 |
if (result) { |
| 3024 |
res = result; |
| 3025 |
} else if (to_answer) { |
| 3026 |
|
| 3027 |
|
| 3028 |
res = -1; |
| 3029 |
} else { |
| 3030 |
res = 0; |
| 3031 |
} |
| 3032 |
} else { |
| 3033 |
const char *number; |
| 3034 |
const char *name; |
| 3035 |
int dial_end_raised = 0; |
| 3036 |
int cause = -1; |
| 3037 |
|
| 3038 |
if (ast_test_flag64(&opts, OPT_CALLER_ANSWER)) { |
| 3039 |
ast_answer(chan); |
| 3040 |
} |
| 3041 |
|
| 3042 |
|
| 3043 |
|
| 3044 |
|
| 3045 |
|
| 3046 |
if (ast_test_flag64(&opts, OPT_HANGUPCAUSE) |
| 3047 |
&& !ast_strlen_zero(opt_args[OPT_ARG_HANGUPCAUSE])) { |
| 3048 |
cause = ast_str2cause(opt_args[OPT_ARG_HANGUPCAUSE]); |
| 3049 |
if (cause <= 0) { |
| 3050 |
if (!strcasecmp(opt_args[OPT_ARG_HANGUPCAUSE], "NONE")) { |
| 3051 |
cause = 0; |
| 3052 |
} else if (sscanf(opt_args[OPT_ARG_HANGUPCAUSE], "%30d", &cause) != 1 |
| 3053 |
|| cause < 0) { |
| 3054 |
ast_log(LOG_WARNING, "Invalid cause given to Dial(...Q(<cause>)): \"%s\"\n", |
| 3055 |
opt_args[OPT_ARG_HANGUPCAUSE]); |
| 3056 |
cause = -1; |
| 3057 |
} |
| 3058 |
} |
| 3059 |
} |
| 3060 |
hanguptree(&out_chans, peer, cause >= 0 ? cause : AST_CAUSE_ANSWERED_ELSEWHERE); |
| 3061 |
|
| 3062 |
|
| 3063 |
|
| 3064 |
ast_channel_lock(peer); |
| 3065 |
name = ast_strdupa(ast_channel_name(peer)); |
| 3066 |
|
| 3067 |
number = pbx_builtin_getvar_helper(peer, "DIALEDPEERNUMBER"); |
| 3068 |
if (ast_strlen_zero(number)) { |
| 3069 |
number = NULL; |
| 3070 |
} else { |
| 3071 |
number = ast_strdupa(number); |
| 3072 |
} |
| 3073 |
ast_channel_unlock(peer); |
| 3074 |
|
| 3075 |
ast_channel_lock(chan); |
| 3076 |
ast_channel_stage_snapshot(chan); |
| 3077 |
|
| 3078 |
strcpy(pa.status, "ANSWER"); |
| 3079 |
pbx_builtin_setvar_helper(chan, "DIALSTATUS", pa.status); |
| 3080 |
|
| 3081 |
pbx_builtin_setvar_helper(chan, "DIALEDPEERNAME", name); |
| 3082 |
pbx_builtin_setvar_helper(chan, "DIALEDPEERNUMBER", number); |
| 3083 |
|
| 3084 |
ast_channel_stage_snapshot_done(chan); |
| 3085 |
ast_channel_unlock(chan); |
| 3086 |
|
| 3087 |
if (!ast_strlen_zero(args.url) && ast_channel_supports_html(peer) ) { |
| 3088 |
ast_debug(1, "app_dial: sendurl=%s.\n", args.url); |
| 3089 |
ast_channel_sendurl( peer, args.url ); |
| 3090 |
} |
| 3091 |
if ( (ast_test_flag64(&opts, OPT_PRIVACY) || ast_test_flag64(&opts, OPT_SCREENING)) && pa.privdb_val == AST_PRIVACY_UNKNOWN) { |
| 3092 |
if (do_privacy(chan, peer, &opts, opt_args, &pa)) { |
| 3093 |
ast_channel_publish_dial(chan, peer, NULL, pa.status); |
| 3094 |
|
| 3095 |
ast_autoservice_chan_hangup_peer(chan, peer); |
| 3096 |
res = 0; |
| 3097 |
goto out; |
| 3098 |
} |
| 3099 |
} |
| 3100 |
if (!ast_test_flag64(&opts, OPT_ANNOUNCE) || ast_strlen_zero(opt_args[OPT_ARG_ANNOUNCE])) { |
| 3101 |
res = 0; |
| 3102 |
} else { |
| 3103 |
int digit = 0; |
| 3104 |
struct ast_channel *chans[2]; |
| 3105 |
struct ast_channel *active_chan; |
| 3106 |
char *calledfile = NULL, *callerfile = NULL; |
| 3107 |
int calledstream = 0, callerstream = 0; |
| 3108 |
|
| 3109 |
chans[0] = chan; |
| 3110 |
chans[1] = peer; |
| 3111 |
|
| 3112 |
|
| 3113 |
callerfile = opt_args[OPT_ARG_ANNOUNCE]; |
| 3114 |
calledfile = strsep(&callerfile, ":"); |
| 3115 |
|
| 3116 |
|
| 3117 |
if (!ast_strlen_zero(calledfile)) { |
| 3118 |
res = ast_streamfile(peer, calledfile, ast_channel_language(peer)); |
| 3119 |
if (res) { |
| 3120 |
res = 0; |
| 3121 |
ast_log(LOG_ERROR, "error streaming file '%s' to callee\n", calledfile); |
| 3122 |
} else { |
| 3123 |
calledstream = 1; |
| 3124 |
} |
| 3125 |
} |
| 3126 |
if (!ast_strlen_zero(callerfile)) { |
| 3127 |
res = ast_streamfile(chan, callerfile, ast_channel_language(chan)); |
| 3128 |
if (res) { |
| 3129 |
res = 0; |
| 3130 |
ast_log(LOG_ERROR, "error streaming file '%s' to caller\n", callerfile); |
| 3131 |
} else { |
| 3132 |
callerstream = 1; |
| 3133 |
} |
| 3134 |
} |
| 3135 |
|
| 3136 |
|
| 3137 |
|
| 3138 |
|
| 3139 |
ast_channel_set_flag(peer, AST_FLAG_END_DTMF_ONLY); |
| 3140 |
while (ast_channel_stream(peer) || ast_channel_stream(chan)) { |
| 3141 |
int mspeer, mschan; |
| 3142 |
|
| 3143 |
mspeer = ast_sched_wait(ast_channel_sched(peer)); |
| 3144 |
mschan = ast_sched_wait(ast_channel_sched(chan)); |
| 3145 |
|
| 3146 |
if (calledstream) { |
| 3147 |
if (mspeer < 0 && !ast_channel_timingfunc(peer)) { |
| 3148 |
ast_stopstream(peer); |
| 3149 |
calledstream = 0; |
| 3150 |
} |
| 3151 |
} |
| 3152 |
if (callerstream) { |
| 3153 |
if (mschan < 0 && !ast_channel_timingfunc(chan)) { |
| 3154 |
ast_stopstream(chan); |
| 3155 |
callerstream = 0; |
| 3156 |
} |
| 3157 |
} |
| 3158 |
|
| 3159 |
if (!calledstream && !callerstream) { |
| 3160 |
break; |
| 3161 |
} |
| 3162 |
|
| 3163 |
if (mspeer < 0) |
| 3164 |
mspeer = 1000; |
| 3165 |
|
| 3166 |
if (mschan < 0) |
| 3167 |
mschan = 1000; |
| 3168 |
|
| 3169 |
|
| 3170 |
active_chan = ast_waitfor_n(chans, 2, (mspeer > mschan ? &mschan : &mspeer)); |
| 3171 |
if (active_chan) { |
| 3172 |
struct ast_channel *other_chan; |
| 3173 |
struct ast_frame *fr = ast_read(active_chan); |
| 3174 |
|
| 3175 |
if (!fr) { |
| 3176 |
ast_autoservice_chan_hangup_peer(chan, peer); |
| 3177 |
res = -1; |
| 3178 |
goto done; |
| 3179 |
} |
| 3180 |
switch (fr->frametype) { |
| 3181 |
case AST_FRAME_DTMF_END: |
| 3182 |
digit = fr->subclass.integer; |
| 3183 |
if (active_chan == peer && strchr(AST_DIGIT_ANY, res)) { |
| 3184 |
ast_stopstream(peer); |
| 3185 |
res = ast_senddigit(chan, digit, 0); |
| 3186 |
} |
| 3187 |
break; |
| 3188 |
case AST_FRAME_CONTROL: |
| 3189 |
switch (fr->subclass.integer) { |
| 3190 |
case AST_CONTROL_HANGUP: |
| 3191 |
ast_frfree(fr); |
| 3192 |
ast_autoservice_chan_hangup_peer(chan, peer); |
| 3193 |
res = -1; |
| 3194 |
goto done; |
| 3195 |
case AST_CONTROL_CONNECTED_LINE: |
| 3196 |
|
| 3197 |
if (active_chan == chan) { |
| 3198 |
other_chan = peer; |
| 3199 |
} else { |
| 3200 |
other_chan = chan; |
| 3201 |
} |
| 3202 |
if (ast_channel_connected_line_sub(active_chan, other_chan, fr, 1)) { |
| 3203 |
ast_indicate_data(other_chan, fr->subclass.integer, |
| 3204 |
fr->data.ptr, fr->datalen); |
| 3205 |
} |
| 3206 |
break; |
| 3207 |
default: |
| 3208 |
break; |
| 3209 |
} |
| 3210 |
break; |
| 3211 |
default: |
| 3212 |
|
| 3213 |
break; |
| 3214 |
} |
| 3215 |
ast_frfree(fr); |
| 3216 |
} |
| 3217 |
ast_sched_runq(ast_channel_sched(peer)); |
| 3218 |
ast_sched_runq(ast_channel_sched(chan)); |
| 3219 |
} |
| 3220 |
ast_channel_clear_flag(peer, AST_FLAG_END_DTMF_ONLY); |
| 3221 |
} |
| 3222 |
|
| 3223 |
if (chan && peer && ast_test_flag64(&opts, OPT_GOTO) && !ast_strlen_zero(opt_args[OPT_ARG_GOTO])) { |
| 3224 |
|
| 3225 |
|
| 3226 |
ast_channel_clear_flag(chan, AST_FLAG_OUTGOING); |
| 3227 |
|
| 3228 |
ast_replace_subargument_delimiter(opt_args[OPT_ARG_GOTO]); |
| 3229 |
ast_parseable_goto(chan, opt_args[OPT_ARG_GOTO]); |
| 3230 |
|
| 3231 |
ast_channel_lock(peer); |
| 3232 |
ast_channel_stage_snapshot(peer); |
| 3233 |
ast_clear_flag(ast_channel_flags(peer), AST_FLAG_OUTGOING); |
| 3234 |
ast_channel_context_set(peer, ast_channel_context(chan)); |
| 3235 |
ast_channel_exten_set(peer, ast_channel_exten(chan)); |
| 3236 |
ast_channel_priority_set(peer, ast_channel_priority(chan) + 2); |
| 3237 |
ast_channel_stage_snapshot_done(peer); |
| 3238 |
ast_channel_unlock(peer); |
| 3239 |
if (ast_pbx_start(peer)) { |
| 3240 |
ast_autoservice_chan_hangup_peer(chan, peer); |
| 3241 |
} |
| 3242 |
if (continue_exec) |
| 3243 |
*continue_exec = 1; |
| 3244 |
res = 0; |
| 3245 |
ast_channel_publish_dial(chan, peer, NULL, "ANSWER"); |
| 3246 |
goto done; |
| 3247 |
} |
| 3248 |
|
| 3249 |
if (ast_test_flag64(&opts, OPT_CALLEE_GOSUB) && !ast_strlen_zero(opt_args[OPT_ARG_CALLEE_GOSUB])) { |
| 3250 |
const char *gosub_result_peer; |
| 3251 |
char *gosub_argstart; |
| 3252 |
char *gosub_args = NULL; |
| 3253 |
int gosub_res = -1; |
| 3254 |
|
| 3255 |
ast_replace_subargument_delimiter(opt_args[OPT_ARG_CALLEE_GOSUB]); |
| 3256 |
gosub_argstart = strchr(opt_args[OPT_ARG_CALLEE_GOSUB], ','); |
| 3257 |
if (gosub_argstart) { |
| 3258 |
const char *what_is_s = "s"; |
| 3259 |
*gosub_argstart = 0; |
| 3260 |
if (!ast_exists_extension(peer, opt_args[OPT_ARG_CALLEE_GOSUB], "s", 1, S_COR(ast_channel_caller(peer)->id.number.valid, ast_channel_caller(peer)->id.number.str, NULL)) && |
| 3261 |
ast_exists_extension(peer, opt_args[OPT_ARG_CALLEE_GOSUB], "~~s~~", 1, S_COR(ast_channel_caller(peer)->id.number.valid, ast_channel_caller(peer)->id.number.str, NULL))) { |
| 3262 |
what_is_s = "~~s~~"; |
| 3263 |
} |
| 3264 |
if (ast_asprintf(&gosub_args, "%s,%s,1(%s)", opt_args[OPT_ARG_CALLEE_GOSUB], what_is_s, gosub_argstart + 1) < 0) { |
| 3265 |
gosub_args = NULL; |
| 3266 |
} |
| 3267 |
*gosub_argstart = ','; |
| 3268 |
} else { |
| 3269 |
const char *what_is_s = "s"; |
| 3270 |
if (!ast_exists_extension(peer, opt_args[OPT_ARG_CALLEE_GOSUB], "s", 1, S_COR(ast_channel_caller(peer)->id.number.valid, ast_channel_caller(peer)->id.number.str, NULL)) && |
| 3271 |
ast_exists_extension(peer, opt_args[OPT_ARG_CALLEE_GOSUB], "~~s~~", 1, S_COR(ast_channel_caller(peer)->id.number.valid, ast_channel_caller(peer)->id.number.str, NULL))) { |
| 3272 |
what_is_s = "~~s~~"; |
| 3273 |
} |
| 3274 |
if (ast_asprintf(&gosub_args, "%s,%s,1", opt_args[OPT_ARG_CALLEE_GOSUB], what_is_s) < 0) { |
| 3275 |
gosub_args = NULL; |
| 3276 |
} |
| 3277 |
} |
| 3278 |
if (gosub_args) { |
| 3279 |
gosub_res = ast_app_exec_sub(chan, peer, gosub_args, 0); |
| 3280 |
ast_free(gosub_args); |
| 3281 |
} else { |
| 3282 |
ast_log(LOG_ERROR, "Could not Allocate string for Gosub arguments -- Gosub Call Aborted!\n"); |
| 3283 |
} |
| 3284 |
|
| 3285 |
ast_channel_lock_both(chan, peer); |
| 3286 |
|
| 3287 |
if (!gosub_res && (gosub_result_peer = pbx_builtin_getvar_helper(peer, "GOSUB_RESULT"))) { |
| 3288 |
char *gosub_transfer_dest; |
| 3289 |
char *gosub_result = ast_strdupa(gosub_result_peer); |
| 3290 |
const char *gosub_retval = pbx_builtin_getvar_helper(peer, "GOSUB_RETVAL"); |
| 3291 |
|
| 3292 |
|
| 3293 |
if (gosub_retval) { |
| 3294 |
pbx_builtin_setvar_helper(chan, "GOSUB_RETVAL", gosub_retval); |
| 3295 |
} |
| 3296 |
|
| 3297 |
ast_channel_unlock(peer); |
| 3298 |
ast_channel_unlock(chan); |
| 3299 |
|
| 3300 |
if (!strcasecmp(gosub_result, "BUSY")) { |
| 3301 |
ast_copy_string(pa.status, gosub_result, sizeof(pa.status)); |
| 3302 |
ast_set_flag64(peerflags, OPT_GO_ON); |
| 3303 |
gosub_res = -1; |
| 3304 |
} else if (!strcasecmp(gosub_result, "CONGESTION") || !strcasecmp(gosub_result, "CHANUNAVAIL")) { |
| 3305 |
ast_copy_string(pa.status, gosub_result, sizeof(pa.status)); |
| 3306 |
ast_set_flag64(peerflags, OPT_GO_ON); |
| 3307 |
gosub_res = -1; |
| 3308 |
} else if (!strcasecmp(gosub_result, "CONTINUE")) { |
| 3309 |
|
| 3310 |
ast_set_flag64(peerflags, OPT_GO_ON); |
| 3311 |
gosub_res = -1; |
| 3312 |
} else if (!strcasecmp(gosub_result, "ABORT")) { |
| 3313 |
|
| 3314 |
gosub_res = -1; |
| 3315 |
} else if (!strncasecmp(gosub_result, "GOTO:", 5)) { |
| 3316 |
gosub_transfer_dest = gosub_result + 5; |
| 3317 |
gosub_res = -1; |
| 3318 |
|
| 3319 |
if (strchr(gosub_transfer_dest, '^')) { |
| 3320 |
ast_replace_subargument_delimiter(gosub_transfer_dest); |
| 3321 |
} |
| 3322 |
if (!ast_parseable_goto(chan, gosub_transfer_dest)) { |
| 3323 |
ast_set_flag64(peerflags, OPT_GO_ON); |
| 3324 |
} |
| 3325 |
} |
| 3326 |
if (gosub_res) { |
| 3327 |
res = gosub_res; |
| 3328 |
if (!dial_end_raised) { |
| 3329 |
ast_channel_publish_dial(chan, peer, NULL, gosub_result); |
| 3330 |
dial_end_raised = 1; |
| 3331 |
} |
| 3332 |
} |
| 3333 |
} else { |
| 3334 |
ast_channel_unlock(peer); |
| 3335 |
ast_channel_unlock(chan); |
| 3336 |
} |
| 3337 |
} |
| 3338 |
|
| 3339 |
if (!res) { |
| 3340 |
|
| 3341 |
|
| 3342 |
|
| 3343 |
|
| 3344 |
if (!dial_end_raised) { |
| 3345 |
ast_channel_publish_dial(chan, peer, NULL, "ANSWER"); |
| 3346 |
dial_end_raised = 1; |
| 3347 |
} |
| 3348 |
|
| 3349 |
if (!ast_tvzero(calldurationlimit)) { |
| 3350 |
struct timeval whentohangup = ast_tvadd(ast_tvnow(), calldurationlimit); |
| 3351 |
ast_channel_lock(peer); |
| 3352 |
ast_channel_whentohangup_set(peer, &whentohangup); |
| 3353 |
ast_channel_unlock(peer); |
| 3354 |
} |
| 3355 |
if (!ast_strlen_zero(dtmfcalled)) { |
| 3356 |
ast_verb(3, "Sending DTMF '%s' to the called party.\n", dtmfcalled); |
| 3357 |
res = ast_dtmf_stream(peer, chan, dtmfcalled, 250, 0); |
| 3358 |
} |
| 3359 |
if (!ast_strlen_zero(dtmfcalling)) { |
| 3360 |
ast_verb(3, "Sending DTMF '%s' to the calling party.\n", dtmfcalling); |
| 3361 |
res = ast_dtmf_stream(chan, peer, dtmfcalling, 250, 0); |
| 3362 |
} |
| 3363 |
} |
| 3364 |
|
| 3365 |
if (res) { |
| 3366 |
if (!ast_check_hangup(chan) && ast_check_hangup(peer)) { |
| 3367 |
ast_channel_hangupcause_set(chan, ast_channel_hangupcause(peer)); |
| 3368 |
} |
| 3369 |
setup_peer_after_bridge_goto(chan, peer, &opts, opt_args); |
| 3370 |
if (ast_bridge_setup_after_goto(peer) |
| 3371 |
|| ast_pbx_start(peer)) { |
| 3372 |
ast_autoservice_chan_hangup_peer(chan, peer); |
| 3373 |
} |
| 3374 |
res = -1; |
| 3375 |
} else { |
| 3376 |
if (ast_test_flag64(peerflags, OPT_CALLEE_TRANSFER)) |
| 3377 |
ast_set_flag(&(config.features_callee), AST_FEATURE_REDIRECT); |
| 3378 |
if (ast_test_flag64(peerflags, OPT_CALLER_TRANSFER)) |
| 3379 |
ast_set_flag(&(config.features_caller), AST_FEATURE_REDIRECT); |
| 3380 |
if (ast_test_flag64(peerflags, OPT_CALLEE_HANGUP)) |
| 3381 |
ast_set_flag(&(config.features_callee), AST_FEATURE_DISCONNECT); |
| 3382 |
if (ast_test_flag64(peerflags, OPT_CALLER_HANGUP)) |
| 3383 |
ast_set_flag(&(config.features_caller), AST_FEATURE_DISCONNECT); |
| 3384 |
if (ast_test_flag64(peerflags, OPT_CALLEE_MONITOR)) |
| 3385 |
ast_set_flag(&(config.features_callee), AST_FEATURE_AUTOMON); |
| 3386 |
if (ast_test_flag64(peerflags, OPT_CALLER_MONITOR)) |
| 3387 |
ast_set_flag(&(config.features_caller), AST_FEATURE_AUTOMON); |
| 3388 |
if (ast_test_flag64(peerflags, OPT_CALLEE_PARK)) |
| 3389 |
ast_set_flag(&(config.features_callee), AST_FEATURE_PARKCALL); |
| 3390 |
if (ast_test_flag64(peerflags, OPT_CALLER_PARK)) |
| 3391 |
ast_set_flag(&(config.features_caller), AST_FEATURE_PARKCALL); |
| 3392 |
if (ast_test_flag64(peerflags, OPT_CALLEE_MIXMONITOR)) |
| 3393 |
ast_set_flag(&(config.features_callee), AST_FEATURE_AUTOMIXMON); |
| 3394 |
if (ast_test_flag64(peerflags, OPT_CALLER_MIXMONITOR)) |
| 3395 |
ast_set_flag(&(config.features_caller), AST_FEATURE_AUTOMIXMON); |
| 3396 |
|
| 3397 |
config.end_bridge_callback = end_bridge_callback; |
| 3398 |
config.end_bridge_callback_data = chan; |
| 3399 |
config.end_bridge_callback_data_fixup = end_bridge_callback_data_fixup; |
| 3400 |
|
| 3401 |
if (moh) { |
| 3402 |
moh = 0; |
| 3403 |
ast_moh_stop(chan); |
| 3404 |
} else if (sentringing) { |
| 3405 |
sentringing = 0; |
| 3406 |
ast_indicate(chan, -1); |
| 3407 |
} |
| 3408 |
|
| 3409 |
ast_deactivate_generator(chan); |
| 3410 |
ast_channel_visible_indication_set(chan, 0); |
| 3411 |
|
| 3412 |
res = ast_channel_make_compatible(chan, peer); |
| 3413 |
if (res < 0) { |
| 3414 |
ast_log(LOG_WARNING, "Had to drop call because I couldn't make %s compatible with %s\n", ast_channel_name(chan), ast_channel_name(peer)); |
| 3415 |
ast_autoservice_chan_hangup_peer(chan, peer); |
| 3416 |
res = -1; |
| 3417 |
goto done; |
| 3418 |
} |
| 3419 |
if (opermode) { |
| 3420 |
struct oprmode oprmode; |
| 3421 |
|
| 3422 |
oprmode.peer = peer; |
| 3423 |
oprmode.mode = opermode; |
| 3424 |
|
| 3425 |
ast_channel_setoption(chan, AST_OPTION_OPRMODE, &oprmode, sizeof(oprmode), 0); |
| 3426 |
} |
| 3427 |
setup_peer_after_bridge_goto(chan, peer, &opts, opt_args); |
| 3428 |
|
| 3429 |
res = ast_bridge_call(chan, peer, &config); |
| 3430 |
} |
| 3431 |
} |
| 3432 |
out: |
| 3433 |
if (moh) { |
| 3434 |
moh = 0; |
| 3435 |
ast_moh_stop(chan); |
| 3436 |
} else if (sentringing) { |
| 3437 |
sentringing = 0; |
| 3438 |
ast_indicate(chan, -1); |
| 3439 |
} |
| 3440 |
|
| 3441 |
if (delprivintro && ast_fileexists(pa.privintro, NULL, NULL) > 0) { |
| 3442 |
ast_filedelete(pa.privintro, NULL); |
| 3443 |
if (ast_fileexists(pa.privintro, NULL, NULL) > 0) { |
| 3444 |
ast_log(LOG_NOTICE, "privacy: ast_filedelete didn't do its job on %s\n", pa.privintro); |
| 3445 |
} else { |
| 3446 |
ast_verb(3, "Successfully deleted %s intro file\n", pa.privintro); |
| 3447 |
} |
| 3448 |
} |
| 3449 |
|
| 3450 |
ast_channel_early_bridge(chan, NULL); |
| 3451 |
|
| 3452 |
if (ast_channel_hangupcause(chan) == AST_CAUSE_ANSWERED_ELSEWHERE || ast_test_flag64(&opts, OPT_CANCEL_ELSEWHERE)) { |
| 3453 |
hanguptreecause = AST_CAUSE_ANSWERED_ELSEWHERE; |
| 3454 |
} else if (pa.canceled) { |
| 3455 |
if (ast_channel_hangupcause(chan)) |
| 3456 |
hanguptreecause = ast_channel_hangupcause(chan); |
| 3457 |
else |
| 3458 |
hanguptreecause = AST_CAUSE_NORMAL_CLEARING; |
| 3459 |
} |
| 3460 |
hanguptree(&out_chans, NULL, hanguptreecause); |
| 3461 |
pbx_builtin_setvar_helper(chan, "DIALSTATUS", pa.status); |
| 3462 |
ast_debug(1, "Exiting with DIALSTATUS=%s.\n", pa.status); |
| 3463 |
|
| 3464 |
if ((ast_test_flag64(peerflags, OPT_GO_ON)) && !ast_check_hangup(chan) && (res != AST_PBX_INCOMPLETE)) { |
| 3465 |
if (!ast_tvzero(calldurationlimit)) |
| 3466 |
memset(ast_channel_whentohangup(chan), 0, sizeof(*ast_channel_whentohangup(chan))); |
| 3467 |
res = 0; |
| 3468 |
} |
| 3469 |
|
| 3470 |
done: |
| 3471 |
if (config.answer_topology) { |
| 3472 |
ast_trace(2, "%s Cleaning up topology: %p %s\n", |
| 3473 |
peer ? ast_channel_name(peer) : "<no channel>", &config.answer_topology, |
| 3474 |
ast_str_tmp(256, ast_stream_topology_to_str(config.answer_topology, &STR_TMP))); |
| 3475 |
|
| 3476 |
|
| 3477 |
|
| 3478 |
|
| 3479 |
|
| 3480 |
|
| 3481 |
ast_stream_topology_free(config.answer_topology); |
| 3482 |
} |
| 3483 |
if (config.warning_sound) { |
| 3484 |
ast_free((char *)config.warning_sound); |
| 3485 |
} |
| 3486 |
if (config.end_sound) { |
| 3487 |
ast_free((char *)config.end_sound); |
| 3488 |
} |
| 3489 |
if (config.start_sound) { |
| 3490 |
ast_free((char *)config.start_sound); |
| 3491 |
} |
| 3492 |
ast_ignore_cc(chan); |
| 3493 |
SCOPE_EXIT_RTN_VALUE(res, "%s: Done\n", ast_channel_name(chan)); |
| 3494 |
} |
| 3495 |
|
| 3496 |
static int dial_exec(struct ast_channel *chan, const char *data) |
| 3497 |
{ |
| 3498 |
struct ast_flags64 peerflags; |
| 3499 |
|
| 3500 |
memset(&peerflags, 0, sizeof(peerflags)); |
| 3501 |
|
| 3502 |
return dial_exec_full(chan, data, &peerflags, NULL); |
| 3503 |
} |
| 3504 |
|
| 3505 |
static int retrydial_exec(struct ast_channel *chan, const char *data) |
| 3506 |
{ |
| 3507 |
char *parse; |
| 3508 |
const char *context = NULL; |
| 3509 |
int sleepms = 0, loops = 0, res = -1; |
| 3510 |
struct ast_flags64 peerflags = { 0, }; |
| 3511 |
AST_DECLARE_APP_ARGS(args, |
| 3512 |
AST_APP_ARG(announce); |
| 3513 |
AST_APP_ARG(sleep); |
| 3514 |
AST_APP_ARG(retries); |
| 3515 |
AST_APP_ARG(dialdata); |
| 3516 |
); |
| 3517 |
|
| 3518 |
if (ast_strlen_zero(data)) { |
| 3519 |
ast_log(LOG_WARNING, "RetryDial requires an argument!\n"); |
| 3520 |
return -1; |
| 3521 |
} |
| 3522 |
|
| 3523 |
parse = ast_strdupa(data); |
| 3524 |
AST_STANDARD_APP_ARGS(args, parse); |
| 3525 |
|
| 3526 |
if (!ast_strlen_zero(args.sleep) && (sleepms = atoi(args.sleep))) |
| 3527 |
sleepms *= 1000; |
| 3528 |
|
| 3529 |
if (!ast_strlen_zero(args.retries)) { |
| 3530 |
loops = atoi(args.retries); |
| 3531 |
} |
| 3532 |
|
| 3533 |
if (!args.dialdata) { |
| 3534 |
ast_log(LOG_ERROR, "%s requires a 4th argument (dialdata)\n", rapp); |
| 3535 |
goto done; |
| 3536 |
} |
| 3537 |
|
| 3538 |
if (sleepms < 1000) |
| 3539 |
sleepms = 10000; |
| 3540 |
|
| 3541 |
if (!loops) |
| 3542 |
loops = -1; |
| 3543 |
|
| 3544 |
ast_channel_lock(chan); |
| 3545 |
context = pbx_builtin_getvar_helper(chan, "EXITCONTEXT"); |
| 3546 |
context = !ast_strlen_zero(context) ? ast_strdupa(context) : NULL; |
| 3547 |
ast_channel_unlock(chan); |
| 3548 |
|
| 3549 |
res = 0; |
| 3550 |
while (loops) { |
| 3551 |
int continue_exec; |
| 3552 |
|
| 3553 |
ast_channel_data_set(chan, "Retrying"); |
| 3554 |
if (ast_test_flag(ast_channel_flags(chan), AST_FLAG_MOH)) |
| 3555 |
ast_moh_stop(chan); |
| 3556 |
|
| 3557 |
res = dial_exec_full(chan, args.dialdata, &peerflags, &continue_exec); |
| 3558 |
if (continue_exec) |
| 3559 |
break; |
| 3560 |
|
| 3561 |
if (res == 0) { |
| 3562 |
if (ast_test_flag64(&peerflags, OPT_DTMF_EXIT)) { |
| 3563 |
if (!ast_strlen_zero(args.announce)) { |
| 3564 |
if (ast_fileexists(args.announce, NULL, ast_channel_language(chan)) > 0) { |
| 3565 |
if (!(res = ast_streamfile(chan, args.announce, ast_channel_language(chan)))) |
| 3566 |
ast_waitstream(chan, AST_DIGIT_ANY); |
| 3567 |
} else |
| 3568 |
ast_log(LOG_WARNING, "Announce file \"%s\" specified in Retrydial does not exist\n", args.announce); |
| 3569 |
} |
| 3570 |
if (!res && sleepms) { |
| 3571 |
if (!ast_test_flag(ast_channel_flags(chan), AST_FLAG_MOH)) |
| 3572 |
ast_moh_start(chan, NULL, NULL); |
| 3573 |
res = ast_waitfordigit(chan, sleepms); |
| 3574 |
} |
| 3575 |
} else { |
| 3576 |
if (!ast_strlen_zero(args.announce)) { |
| 3577 |
if (ast_fileexists(args.announce, NULL, ast_channel_language(chan)) > 0) { |
| 3578 |
if (!(res = ast_streamfile(chan, args.announce, ast_channel_language(chan)))) |
| 3579 |
res = ast_waitstream(chan, ""); |
| 3580 |
} else |
| 3581 |
ast_log(LOG_WARNING, "Announce file \"%s\" specified in Retrydial does not exist\n", args.announce); |
| 3582 |
} |
| 3583 |
if (sleepms) { |
| 3584 |
if (!ast_test_flag(ast_channel_flags(chan), AST_FLAG_MOH)) |
| 3585 |
ast_moh_start(chan, NULL, NULL); |
| 3586 |
if (!res) |
| 3587 |
res = ast_waitfordigit(chan, sleepms); |
| 3588 |
} |
| 3589 |
} |
| 3590 |
} |
| 3591 |
|
| 3592 |
if (res < 0 || res == AST_PBX_INCOMPLETE) { |
| 3593 |
break; |
| 3594 |
} else if (res > 0) { |
| 3595 |
if (onedigit_goto(chan, context, (char) res, 1)) { |
| 3596 |
res = 0; |
| 3597 |
break; |
| 3598 |
} |
| 3599 |
} |
| 3600 |
loops--; |
| 3601 |
} |
| 3602 |
if (loops == 0) |
| 3603 |
res = 0; |
| 3604 |
else if (res == 1) |
| 3605 |
res = 0; |
| 3606 |
|
| 3607 |
if (ast_test_flag(ast_channel_flags(chan), AST_FLAG_MOH)) |
| 3608 |
ast_moh_stop(chan); |
| 3609 |
done: |
| 3610 |
return res; |
| 3611 |
} |
| 3612 |
|
| 3613 |
static int unload_module(void) |
| 3614 |
{ |
| 3615 |
int res; |
| 3616 |
|
| 3617 |
res = ast_unregister_application(app); |
| 3618 |
res |= ast_unregister_application(rapp); |
| 3619 |
|
| 3620 |
return res; |
| 3621 |
} |
| 3622 |
|
| 3623 |
static int load_module(void) |
| 3624 |
{ |
| 3625 |
int res; |
| 3626 |
|
| 3627 |
res = ast_register_application_xml(app, dial_exec); |
| 3628 |
res |= ast_register_application_xml(rapp, retrydial_exec); |
| 3629 |
|
| 3630 |
return res; |
| 3631 |
} |
| 3632 |
|
| 3633 |
AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_DEFAULT, "Dialing Application", |
| 3634 |
.support_level = AST_MODULE_SUPPORT_CORE, |
| 3635 |
.load = load_module, |
| 3636 |
.unload = unload_module, |
| 3637 |
); |