| 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 |
#include "asterisk.h" |
| 32 |
|
| 33 |
#include "asterisk/module.h" |
| 34 |
#include "asterisk/channel.h" |
| 35 |
#include "asterisk/pbx.h" |
| 36 |
#include "asterisk/utils.h" |
| 37 |
#include "asterisk/app.h" |
| 38 |
#include "asterisk/callerid.h" |
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
|
| 142 |
|
| 143 |
|
| 144 |
|
| 145 |
|
| 146 |
|
| 147 |
|
| 148 |
|
| 149 |
|
| 150 |
|
| 151 |
|
| 152 |
|
| 153 |
|
| 154 |
|
| 155 |
|
| 156 |
|
| 157 |
|
| 158 |
|
| 159 |
|
| 160 |
|
| 161 |
|
| 162 |
|
| 163 |
|
| 164 |
|
| 165 |
|
| 166 |
|
| 167 |
|
| 168 |
|
| 169 |
|
| 170 |
|
| 171 |
|
| 172 |
|
| 173 |
|
| 174 |
|
| 175 |
|
| 176 |
|
| 177 |
|
| 178 |
|
| 179 |
|
| 180 |
|
| 181 |
|
| 182 |
|
| 183 |
|
| 184 |
|
| 185 |
|
| 186 |
|
| 187 |
|
| 188 |
|
| 189 |
|
| 190 |
|
| 191 |
|
| 192 |
|
| 193 |
|
| 194 |
|
| 195 |
|
| 196 |
|
| 197 |
|
| 198 |
|
| 199 |
|
| 200 |
|
| 201 |
|
| 202 |
|
| 203 |
|
| 204 |
|
| 205 |
|
| 206 |
|
| 207 |
|
| 208 |
|
| 209 |
|
| 210 |
|
| 211 |
|
| 212 |
|
| 213 |
|
| 214 |
|
| 215 |
|
| 216 |
|
| 217 |
|
| 218 |
|
| 219 |
|
| 220 |
|
| 221 |
|
| 222 |
|
| 223 |
|
| 224 |
|
| 225 |
|
| 226 |
|
| 227 |
|
| 228 |
|
| 229 |
|
| 230 |
|
| 231 |
|
| 232 |
|
| 233 |
|
| 234 |
|
| 235 |
|
| 236 |
|
| 237 |
|
| 238 |
|
| 239 |
|
| 240 |
|
| 241 |
|
| 242 |
|
| 243 |
|
| 244 |
|
| 245 |
|
| 246 |
|
| 247 |
|
| 248 |
|
| 249 |
|
| 250 |
|
| 251 |
|
| 252 |
|
| 253 |
|
| 254 |
|
| 255 |
|
| 256 |
|
| 257 |
|
| 258 |
|
| 259 |
|
| 260 |
|
| 261 |
|
| 262 |
|
| 263 |
|
| 264 |
|
| 265 |
|
| 266 |
|
| 267 |
|
| 268 |
|
| 269 |
|
| 270 |
|
| 271 |
|
| 272 |
|
| 273 |
|
| 274 |
|
| 275 |
|
| 276 |
|
| 277 |
|
| 278 |
|
| 279 |
|
| 280 |
|
| 281 |
|
| 282 |
|
| 283 |
|
| 284 |
|
| 285 |
|
| 286 |
|
| 287 |
|
| 288 |
|
| 289 |
|
| 290 |
|
| 291 |
|
| 292 |
|
| 293 |
|
| 294 |
|
| 295 |
|
| 296 |
|
| 297 |
|
| 298 |
|
| 299 |
|
| 300 |
|
| 301 |
|
| 302 |
|
| 303 |
|
| 304 |
|
| 305 |
|
| 306 |
|
| 307 |
|
| 308 |
|
| 309 |
|
| 310 |
|
| 311 |
|
| 312 |
|
| 313 |
|
| 314 |
|
| 315 |
|
| 316 |
|
| 317 |
|
| 318 |
|
| 319 |
|
| 320 |
|
| 321 |
|
| 322 |
|
| 323 |
|
| 324 |
|
| 325 |
|
| 326 |
|
| 327 |
|
| 328 |
|
| 329 |
|
| 330 |
|
| 331 |
|
| 332 |
|
| 333 |
|
| 334 |
|
| 335 |
|
| 336 |
|
| 337 |
|
| 338 |
|
| 339 |
|
| 340 |
|
| 341 |
|
| 342 |
|
| 343 |
|
| 344 |
|
| 345 |
|
| 346 |
|
| 347 |
|
| 348 |
|
| 349 |
|
| 350 |
|
| 351 |
|
| 352 |
|
| 353 |
|
| 354 |
|
| 355 |
|
| 356 |
|
| 357 |
|
| 358 |
|
| 359 |
|
| 360 |
|
| 361 |
|
| 362 |
|
| 363 |
|
| 364 |
|
| 365 |
|
| 366 |
|
| 367 |
|
| 368 |
|
| 369 |
|
| 370 |
|
| 371 |
|
| 372 |
|
| 373 |
|
| 374 |
|
| 375 |
|
| 376 |
|
| 377 |
|
| 378 |
|
| 379 |
|
| 380 |
|
| 381 |
|
| 382 |
|
| 383 |
|
| 384 |
|
| 385 |
|
| 386 |
|
| 387 |
|
| 388 |
|
| 389 |
|
| 390 |
|
| 391 |
|
| 392 |
|
| 393 |
|
| 394 |
|
| 395 |
|
| 396 |
|
| 397 |
|
| 398 |
|
| 399 |
|
| 400 |
|
| 401 |
|
| 402 |
|
| 403 |
|
| 404 |
|
| 405 |
|
| 406 |
|
| 407 |
|
| 408 |
|
| 409 |
|
| 410 |
|
| 411 |
|
| 412 |
|
| 413 |
|
| 414 |
|
| 415 |
|
| 416 |
|
| 417 |
|
| 418 |
|
| 419 |
|
| 420 |
|
| 421 |
|
| 422 |
|
| 423 |
|
| 424 |
|
| 425 |
|
| 426 |
|
| 427 |
|
| 428 |
|
| 429 |
|
| 430 |
|
| 431 |
|
| 432 |
|
| 433 |
|
| 434 |
|
| 435 |
|
| 436 |
|
| 437 |
|
| 438 |
|
| 439 |
|
| 440 |
|
| 441 |
|
| 442 |
|
| 443 |
|
| 444 |
|
| 445 |
|
| 446 |
|
| 447 |
|
| 448 |
|
| 449 |
|
| 450 |
|
| 451 |
|
| 452 |
|
| 453 |
|
| 454 |
|
| 455 |
|
| 456 |
|
| 457 |
|
| 458 |
|
| 459 |
|
| 460 |
|
| 461 |
|
| 462 |
|
| 463 |
|
| 464 |
enum ID_FIELD_STATUS { |
| 465 |
ID_FIELD_VALID, |
| 466 |
ID_FIELD_INVALID, |
| 467 |
ID_FIELD_UNKNOWN |
| 468 |
}; |
| 469 |
|
| 470 |
AST_DEFINE_APP_ARGS_TYPE(ast_party_func_args, |
| 471 |
AST_APP_ARG(member); |
| 472 |
AST_APP_ARG(opts); |
| 473 |
AST_APP_ARG(other); |
| 474 |
); |
| 475 |
|
| 476 |
AST_DEFINE_APP_ARGS_TYPE(ast_party_members, |
| 477 |
AST_APP_ARG(subnames[10]); |
| 478 |
); |
| 479 |
|
| 480 |
enum CONNECTED_LINE_OPT_FLAGS { |
| 481 |
CONNECTED_LINE_OPT_INHIBIT = (1 << 0), |
| 482 |
}; |
| 483 |
enum CONNECTED_LINE_OPT_ARGS { |
| 484 |
CONNECTED_LINE_OPT_DUMMY, |
| 485 |
|
| 486 |
|
| 487 |
CONNECTED_LINE_OPT_ARG_ARRAY_SIZE |
| 488 |
}; |
| 489 |
|
| 490 |
AST_APP_OPTIONS(connectedline_opts, BEGIN_OPTIONS |
| 491 |
AST_APP_OPTION('i', CONNECTED_LINE_OPT_INHIBIT), |
| 492 |
END_OPTIONS); |
| 493 |
|
| 494 |
enum REDIRECTING_OPT_FLAGS { |
| 495 |
REDIRECTING_OPT_INHIBIT = (1 << 0), |
| 496 |
}; |
| 497 |
enum REDIRECTING_OPT_ARGS { |
| 498 |
REDIRECTING_OPT_DUMMY, |
| 499 |
|
| 500 |
|
| 501 |
REDIRECTING_OPT_ARG_ARRAY_SIZE |
| 502 |
}; |
| 503 |
|
| 504 |
AST_APP_OPTIONS(redirecting_opts, BEGIN_OPTIONS |
| 505 |
AST_APP_OPTION('i', REDIRECTING_OPT_INHIBIT), |
| 506 |
END_OPTIONS); |
| 507 |
|
| 508 |
|
| 509 |
|
| 510 |
|
| 511 |
|
| 512 |
|
| 513 |
|
| 514 |
|
| 515 |
|
| 516 |
|
| 517 |
|
| 518 |
|
| 519 |
|
| 520 |
|
| 521 |
|
| 522 |
static enum ID_FIELD_STATUS party_name_read(char *buf, size_t len, int argc, char *argv[], const struct ast_party_name *name) |
| 523 |
{ |
| 524 |
enum ID_FIELD_STATUS status; |
| 525 |
|
| 526 |
status = ID_FIELD_VALID; |
| 527 |
|
| 528 |
if (argc == 0) { |
| 529 |
|
| 530 |
if (name->valid && name->str) { |
| 531 |
ast_copy_string(buf, name->str, len); |
| 532 |
} |
| 533 |
} else if (argc == 1 && !strcasecmp("valid", argv[0])) { |
| 534 |
snprintf(buf, len, "%d", name->valid); |
| 535 |
} else if (argc == 1 && !strcasecmp("charset", argv[0])) { |
| 536 |
ast_copy_string(buf, ast_party_name_charset_str(name->char_set), len); |
| 537 |
} else if (argc == 1 && !strncasecmp("pres", argv[0], 4)) { |
| 538 |
|
| 539 |
ast_copy_string(buf, ast_named_caller_presentation(name->presentation), len); |
| 540 |
} else { |
| 541 |
status = ID_FIELD_UNKNOWN; |
| 542 |
} |
| 543 |
|
| 544 |
return status; |
| 545 |
} |
| 546 |
|
| 547 |
|
| 548 |
|
| 549 |
|
| 550 |
|
| 551 |
|
| 552 |
|
| 553 |
|
| 554 |
|
| 555 |
|
| 556 |
|
| 557 |
|
| 558 |
|
| 559 |
|
| 560 |
|
| 561 |
static enum ID_FIELD_STATUS party_number_read(char *buf, size_t len, int argc, char *argv[], const struct ast_party_number *number) |
| 562 |
{ |
| 563 |
enum ID_FIELD_STATUS status; |
| 564 |
|
| 565 |
status = ID_FIELD_VALID; |
| 566 |
|
| 567 |
if (argc == 0) { |
| 568 |
|
| 569 |
if (number->valid && number->str) { |
| 570 |
ast_copy_string(buf, number->str, len); |
| 571 |
} |
| 572 |
} else if (argc == 1 && !strcasecmp("valid", argv[0])) { |
| 573 |
snprintf(buf, len, "%d", number->valid); |
| 574 |
} else if (argc == 1 && !strcasecmp("plan", argv[0])) { |
| 575 |
snprintf(buf, len, "%d", number->plan); |
| 576 |
} else if (argc == 1 && !strncasecmp("pres", argv[0], 4)) { |
| 577 |
|
| 578 |
ast_copy_string(buf, ast_named_caller_presentation(number->presentation), len); |
| 579 |
} else { |
| 580 |
status = ID_FIELD_UNKNOWN; |
| 581 |
} |
| 582 |
|
| 583 |
return status; |
| 584 |
} |
| 585 |
|
| 586 |
|
| 587 |
|
| 588 |
|
| 589 |
|
| 590 |
|
| 591 |
|
| 592 |
|
| 593 |
|
| 594 |
|
| 595 |
|
| 596 |
|
| 597 |
|
| 598 |
|
| 599 |
|
| 600 |
static enum ID_FIELD_STATUS party_subaddress_read(char *buf, size_t len, int argc, char *argv[], const struct ast_party_subaddress *subaddress) |
| 601 |
{ |
| 602 |
enum ID_FIELD_STATUS status; |
| 603 |
|
| 604 |
status = ID_FIELD_VALID; |
| 605 |
|
| 606 |
if (argc == 0) { |
| 607 |
|
| 608 |
if (subaddress->str) { |
| 609 |
ast_copy_string(buf, subaddress->str, len); |
| 610 |
} |
| 611 |
} else if (argc == 1 && !strcasecmp("valid", argv[0])) { |
| 612 |
snprintf(buf, len, "%d", subaddress->valid); |
| 613 |
} else if (argc == 1 && !strcasecmp("type", argv[0])) { |
| 614 |
snprintf(buf, len, "%d", subaddress->type); |
| 615 |
} else if (argc == 1 && !strcasecmp("odd", argv[0])) { |
| 616 |
snprintf(buf, len, "%d", subaddress->odd_even_indicator); |
| 617 |
} else { |
| 618 |
status = ID_FIELD_UNKNOWN; |
| 619 |
} |
| 620 |
|
| 621 |
return status; |
| 622 |
} |
| 623 |
|
| 624 |
|
| 625 |
|
| 626 |
|
| 627 |
|
| 628 |
|
| 629 |
|
| 630 |
|
| 631 |
|
| 632 |
|
| 633 |
|
| 634 |
|
| 635 |
|
| 636 |
|
| 637 |
|
| 638 |
static enum ID_FIELD_STATUS party_id_read(char *buf, size_t len, int argc, char *argv[], const struct ast_party_id *id) |
| 639 |
{ |
| 640 |
enum ID_FIELD_STATUS status; |
| 641 |
|
| 642 |
if (argc == 0) { |
| 643 |
|
| 644 |
return ID_FIELD_UNKNOWN; |
| 645 |
} |
| 646 |
|
| 647 |
status = ID_FIELD_VALID; |
| 648 |
|
| 649 |
if (argc == 1 && !strcasecmp("all", argv[0])) { |
| 650 |
snprintf(buf, len, "\"%s\" <%s>", |
| 651 |
S_COR(id->name.valid, id->name.str, ""), |
| 652 |
S_COR(id->number.valid, id->number.str, "")); |
| 653 |
} else if (!strcasecmp("name", argv[0])) { |
| 654 |
status = party_name_read(buf, len, argc - 1, argv + 1, &id->name); |
| 655 |
} else if (!strncasecmp("num", argv[0], 3)) { |
| 656 |
|
| 657 |
status = party_number_read(buf, len, argc - 1, argv + 1, &id->number); |
| 658 |
} else if (!strncasecmp("subaddr", argv[0], 7)) { |
| 659 |
|
| 660 |
status = party_subaddress_read(buf, len, argc - 1, argv + 1, &id->subaddress); |
| 661 |
} else if (argc == 1 && !strcasecmp("tag", argv[0])) { |
| 662 |
if (id->tag) { |
| 663 |
ast_copy_string(buf, id->tag, len); |
| 664 |
} |
| 665 |
} else if (argc == 1 && !strcasecmp("ton", argv[0])) { |
| 666 |
|
| 667 |
snprintf(buf, len, "%d", id->number.plan); |
| 668 |
} else if (argc == 1 && !strncasecmp("pres", argv[0], 4)) { |
| 669 |
|
| 670 |
|
| 671 |
|
| 672 |
|
| 673 |
ast_copy_string(buf, |
| 674 |
ast_named_caller_presentation(ast_party_id_presentation(id)), len); |
| 675 |
} else { |
| 676 |
status = ID_FIELD_UNKNOWN; |
| 677 |
} |
| 678 |
|
| 679 |
return status; |
| 680 |
} |
| 681 |
|
| 682 |
|
| 683 |
|
| 684 |
|
| 685 |
|
| 686 |
|
| 687 |
|
| 688 |
|
| 689 |
|
| 690 |
|
| 691 |
|
| 692 |
|
| 693 |
|
| 694 |
|
| 695 |
|
| 696 |
static enum ID_FIELD_STATUS party_name_write(struct ast_party_name *name, int argc, char *argv[], const char *value) |
| 697 |
{ |
| 698 |
char *val; |
| 699 |
enum ID_FIELD_STATUS status; |
| 700 |
|
| 701 |
status = ID_FIELD_VALID; |
| 702 |
|
| 703 |
if (argc == 0) { |
| 704 |
|
| 705 |
name->valid = 1; |
| 706 |
name->str = ast_strdup(value); |
| 707 |
ast_trim_blanks(name->str); |
| 708 |
} else if (argc == 1 && !strcasecmp("valid", argv[0])) { |
| 709 |
name->valid = atoi(value) ? 1 : 0; |
| 710 |
} else if (argc == 1 && !strcasecmp("charset", argv[0])) { |
| 711 |
int char_set; |
| 712 |
|
| 713 |
val = ast_strdupa(value); |
| 714 |
ast_trim_blanks(val); |
| 715 |
|
| 716 |
if (('0' <= val[0]) && (val[0] <= '9')) { |
| 717 |
char_set = atoi(val); |
| 718 |
} else { |
| 719 |
char_set = ast_party_name_charset_parse(val); |
| 720 |
} |
| 721 |
|
| 722 |
if (char_set < 0) { |
| 723 |
ast_log(LOG_ERROR, |
| 724 |
"Unknown name char-set '%s', value unchanged\n", val); |
| 725 |
status = ID_FIELD_INVALID; |
| 726 |
} else { |
| 727 |
name->char_set = char_set; |
| 728 |
} |
| 729 |
} else if (argc == 1 && !strncasecmp("pres", argv[0], 4)) { |
| 730 |
int pres; |
| 731 |
|
| 732 |
|
| 733 |
val = ast_strdupa(value); |
| 734 |
ast_trim_blanks(val); |
| 735 |
|
| 736 |
if (('0' <= val[0]) && (val[0] <= '9')) { |
| 737 |
pres = atoi(val); |
| 738 |
} else { |
| 739 |
pres = ast_parse_caller_presentation(val); |
| 740 |
} |
| 741 |
|
| 742 |
if (pres < 0) { |
| 743 |
ast_log(LOG_ERROR, |
| 744 |
"Unknown name presentation '%s', value unchanged\n", val); |
| 745 |
status = ID_FIELD_INVALID; |
| 746 |
} else { |
| 747 |
name->presentation = pres; |
| 748 |
} |
| 749 |
} else { |
| 750 |
status = ID_FIELD_UNKNOWN; |
| 751 |
} |
| 752 |
|
| 753 |
return status; |
| 754 |
} |
| 755 |
|
| 756 |
|
| 757 |
|
| 758 |
|
| 759 |
|
| 760 |
|
| 761 |
|
| 762 |
|
| 763 |
|
| 764 |
|
| 765 |
|
| 766 |
|
| 767 |
|
| 768 |
|
| 769 |
|
| 770 |
static enum ID_FIELD_STATUS party_number_write(struct ast_party_number *number, int argc, char *argv[], const char *value) |
| 771 |
{ |
| 772 |
char *val; |
| 773 |
enum ID_FIELD_STATUS status; |
| 774 |
|
| 775 |
status = ID_FIELD_VALID; |
| 776 |
|
| 777 |
if (argc == 0) { |
| 778 |
|
| 779 |
number->valid = 1; |
| 780 |
number->str = ast_strdup(value); |
| 781 |
ast_trim_blanks(number->str); |
| 782 |
} else if (argc == 1 && !strcasecmp("valid", argv[0])) { |
| 783 |
number->valid = atoi(value) ? 1 : 0; |
| 784 |
} else if (argc == 1 && !strcasecmp("plan", argv[0])) { |
| 785 |
val = ast_strdupa(value); |
| 786 |
ast_trim_blanks(val); |
| 787 |
|
| 788 |
if (('0' <= val[0]) && (val[0] <= '9')) { |
| 789 |
number->plan = atoi(val); |
| 790 |
} else { |
| 791 |
ast_log(LOG_ERROR, |
| 792 |
"Unknown type-of-number/numbering-plan '%s', value unchanged\n", val); |
| 793 |
status = ID_FIELD_INVALID; |
| 794 |
} |
| 795 |
} else if (argc == 1 && !strncasecmp("pres", argv[0], 4)) { |
| 796 |
int pres; |
| 797 |
|
| 798 |
|
| 799 |
val = ast_strdupa(value); |
| 800 |
ast_trim_blanks(val); |
| 801 |
|
| 802 |
if (('0' <= val[0]) && (val[0] <= '9')) { |
| 803 |
pres = atoi(val); |
| 804 |
} else { |
| 805 |
pres = ast_parse_caller_presentation(val); |
| 806 |
} |
| 807 |
|
| 808 |
if (pres < 0) { |
| 809 |
ast_log(LOG_ERROR, |
| 810 |
"Unknown number presentation '%s', value unchanged\n", val); |
| 811 |
status = ID_FIELD_INVALID; |
| 812 |
} else { |
| 813 |
number->presentation = pres; |
| 814 |
} |
| 815 |
} else { |
| 816 |
status = ID_FIELD_UNKNOWN; |
| 817 |
} |
| 818 |
|
| 819 |
return status; |
| 820 |
} |
| 821 |
|
| 822 |
|
| 823 |
|
| 824 |
|
| 825 |
|
| 826 |
|
| 827 |
|
| 828 |
|
| 829 |
|
| 830 |
|
| 831 |
|
| 832 |
|
| 833 |
|
| 834 |
|
| 835 |
|
| 836 |
static enum ID_FIELD_STATUS party_subaddress_write(struct ast_party_subaddress *subaddress, int argc, char *argv[], const char *value) |
| 837 |
{ |
| 838 |
enum ID_FIELD_STATUS status; |
| 839 |
|
| 840 |
status = ID_FIELD_VALID; |
| 841 |
|
| 842 |
if (argc == 0) { |
| 843 |
|
| 844 |
subaddress->str = ast_strdup(value); |
| 845 |
ast_trim_blanks(subaddress->str); |
| 846 |
} else if (argc == 1 && !strcasecmp("valid", argv[0])) { |
| 847 |
subaddress->valid = atoi(value) ? 1 : 0; |
| 848 |
} else if (argc == 1 && !strcasecmp("type", argv[0])) { |
| 849 |
subaddress->type = atoi(value) ? 2 : 0; |
| 850 |
} else if (argc == 1 && !strcasecmp("odd", argv[0])) { |
| 851 |
subaddress->odd_even_indicator = atoi(value) ? 1 : 0; |
| 852 |
} else { |
| 853 |
status = ID_FIELD_UNKNOWN; |
| 854 |
} |
| 855 |
|
| 856 |
return status; |
| 857 |
} |
| 858 |
|
| 859 |
|
| 860 |
|
| 861 |
|
| 862 |
|
| 863 |
|
| 864 |
|
| 865 |
|
| 866 |
|
| 867 |
|
| 868 |
|
| 869 |
|
| 870 |
|
| 871 |
|
| 872 |
|
| 873 |
static enum ID_FIELD_STATUS party_id_write(struct ast_party_id *id, int argc, char *argv[], const char *value) |
| 874 |
{ |
| 875 |
char *val; |
| 876 |
enum ID_FIELD_STATUS status; |
| 877 |
|
| 878 |
if (argc == 0) { |
| 879 |
|
| 880 |
return ID_FIELD_UNKNOWN; |
| 881 |
} |
| 882 |
|
| 883 |
status = ID_FIELD_VALID; |
| 884 |
|
| 885 |
if (argc == 1 && !strcasecmp("all", argv[0])) { |
| 886 |
char name[256]; |
| 887 |
char num[256]; |
| 888 |
|
| 889 |
ast_callerid_split(value, name, sizeof(name), num, sizeof(num)); |
| 890 |
id->name.valid = 1; |
| 891 |
id->name.str = ast_strdup(name); |
| 892 |
if (!id->name.str) { |
| 893 |
return ID_FIELD_INVALID; |
| 894 |
} |
| 895 |
id->number.valid = 1; |
| 896 |
id->number.str = ast_strdup(num); |
| 897 |
if (!id->number.str) { |
| 898 |
return ID_FIELD_INVALID; |
| 899 |
} |
| 900 |
} else if (!strcasecmp("name", argv[0])) { |
| 901 |
status = party_name_write(&id->name, argc - 1, argv + 1, value); |
| 902 |
} else if (!strncasecmp("num", argv[0], 3)) { |
| 903 |
|
| 904 |
status = party_number_write(&id->number, argc - 1, argv + 1, value); |
| 905 |
} else if (!strncasecmp("subaddr", argv[0], 7)) { |
| 906 |
|
| 907 |
status = party_subaddress_write(&id->subaddress, argc - 1, argv + 1, value); |
| 908 |
} else if (argc == 1 && !strcasecmp("tag", argv[0])) { |
| 909 |
id->tag = ast_strdup(value); |
| 910 |
ast_trim_blanks(id->tag); |
| 911 |
} else if (argc == 1 && !strcasecmp("ton", argv[0])) { |
| 912 |
|
| 913 |
argv[0] = "plan"; |
| 914 |
status = party_number_write(&id->number, argc, argv, value); |
| 915 |
} else if (argc == 1 && !strncasecmp("pres", argv[0], 4)) { |
| 916 |
int pres; |
| 917 |
|
| 918 |
|
| 919 |
|
| 920 |
|
| 921 |
|
| 922 |
val = ast_strdupa(value); |
| 923 |
ast_trim_blanks(val); |
| 924 |
|
| 925 |
if (('0' <= val[0]) && (val[0] <= '9')) { |
| 926 |
pres = atoi(val); |
| 927 |
} else { |
| 928 |
pres = ast_parse_caller_presentation(val); |
| 929 |
} |
| 930 |
|
| 931 |
if (pres < 0) { |
| 932 |
ast_log(LOG_ERROR, |
| 933 |
"Unknown combined presentation '%s', value unchanged\n", val); |
| 934 |
status = ID_FIELD_INVALID; |
| 935 |
} else { |
| 936 |
id->name.presentation = pres; |
| 937 |
id->number.presentation = pres; |
| 938 |
} |
| 939 |
} else { |
| 940 |
status = ID_FIELD_UNKNOWN; |
| 941 |
} |
| 942 |
|
| 943 |
return status; |
| 944 |
} |
| 945 |
|
| 946 |
|
| 947 |
|
| 948 |
|
| 949 |
|
| 950 |
|
| 951 |
|
| 952 |
|
| 953 |
|
| 954 |
|
| 955 |
|
| 956 |
|
| 957 |
|
| 958 |
|
| 959 |
static int callerid_read(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len) |
| 960 |
{ |
| 961 |
char *parms; |
| 962 |
struct ast_party_members member = { 0, }; |
| 963 |
AST_DECLARE_APP_ARGS(args, |
| 964 |
AST_APP_ARG(member); |
| 965 |
AST_APP_ARG(cid); |
| 966 |
); |
| 967 |
|
| 968 |
|
| 969 |
*buf = 0; |
| 970 |
|
| 971 |
if (!chan) { |
| 972 |
return -1; |
| 973 |
} |
| 974 |
|
| 975 |
parms = ast_strdupa(data); |
| 976 |
AST_STANDARD_APP_ARGS(args, parms); |
| 977 |
if (args.argc == 0) { |
| 978 |
|
| 979 |
return -1; |
| 980 |
} |
| 981 |
|
| 982 |
AST_NONSTANDARD_APP_ARGS(member, args.member, '-'); |
| 983 |
if (member.argc == 0 || ARRAY_LEN(member.subnames) <= member.argc) { |
| 984 |
|
| 985 |
return -1; |
| 986 |
} |
| 987 |
|
| 988 |
if (args.argc == 2) { |
| 989 |
char name[80]; |
| 990 |
char num[80]; |
| 991 |
|
| 992 |
ast_callerid_split(args.cid, name, sizeof(name), num, sizeof(num)); |
| 993 |
|
| 994 |
if (member.argc == 1 && !strcasecmp("all", member.subnames[0])) { |
| 995 |
snprintf(buf, len, "\"%s\" <%s>", name, num); |
| 996 |
} else if (member.argc == 1 && !strcasecmp("name", member.subnames[0])) { |
| 997 |
ast_copy_string(buf, name, len); |
| 998 |
} else if (member.argc == 1 && !strncasecmp("num", member.subnames[0], 3)) { |
| 999 |
|
| 1000 |
ast_copy_string(buf, num, len); |
| 1001 |
} else { |
| 1002 |
ast_log(LOG_ERROR, "Unknown callerid data type '%s'.\n", data); |
| 1003 |
} |
| 1004 |
} else { |
| 1005 |
enum ID_FIELD_STATUS status; |
| 1006 |
ast_channel_lock(chan); |
| 1007 |
|
| 1008 |
if (member.argc == 1 && !strcasecmp("rdnis", member.subnames[0])) { |
| 1009 |
if (ast_channel_redirecting(chan)->from.number.valid |
| 1010 |
&& ast_channel_redirecting(chan)->from.number.str) { |
| 1011 |
ast_copy_string(buf, ast_channel_redirecting(chan)->from.number.str, len); |
| 1012 |
} |
| 1013 |
} else if (!strcasecmp("dnid", member.subnames[0])) { |
| 1014 |
if (member.argc == 1) { |
| 1015 |
|
| 1016 |
member.argc = 2; |
| 1017 |
member.subnames[1] = "num"; |
| 1018 |
} |
| 1019 |
if (!strncasecmp("num", member.subnames[1], 3)) { |
| 1020 |
|
| 1021 |
|
| 1022 |
|
| 1023 |
|
| 1024 |
if (member.argc == 2) { |
| 1025 |
|
| 1026 |
if (ast_channel_dialed(chan)->number.str) { |
| 1027 |
ast_copy_string(buf, ast_channel_dialed(chan)->number.str, len); |
| 1028 |
} |
| 1029 |
} else if (member.argc == 3 && !strcasecmp("plan", member.subnames[2])) { |
| 1030 |
|
| 1031 |
snprintf(buf, len, "%d", ast_channel_dialed(chan)->number.plan); |
| 1032 |
} else { |
| 1033 |
ast_log(LOG_ERROR, "Unknown callerid data type '%s'.\n", data); |
| 1034 |
} |
| 1035 |
} else if (!strncasecmp("subaddr", member.subnames[1], 7)) { |
| 1036 |
|
| 1037 |
|
| 1038 |
|
| 1039 |
|
| 1040 |
status = party_subaddress_read(buf, len, member.argc - 2, member.subnames + 2, |
| 1041 |
&ast_channel_dialed(chan)->subaddress); |
| 1042 |
switch (status) { |
| 1043 |
case ID_FIELD_VALID: |
| 1044 |
case ID_FIELD_INVALID: |
| 1045 |
break; |
| 1046 |
default: |
| 1047 |
ast_log(LOG_ERROR, "Unknown callerid data type '%s'.\n", data); |
| 1048 |
break; |
| 1049 |
} |
| 1050 |
} else { |
| 1051 |
ast_log(LOG_ERROR, "Unknown callerid data type '%s'.\n", data); |
| 1052 |
} |
| 1053 |
} else if (member.argc == 1 && !strcasecmp("ani2", member.subnames[0])) { |
| 1054 |
snprintf(buf, len, "%d", ast_channel_caller(chan)->ani2); |
| 1055 |
} else if (!strcasecmp("ani", member.subnames[0])) { |
| 1056 |
if (member.argc == 1) { |
| 1057 |
|
| 1058 |
member.argc = 2; |
| 1059 |
member.subnames[1] = "num"; |
| 1060 |
} |
| 1061 |
status = party_id_read(buf, len, member.argc - 1, member.subnames + 1, |
| 1062 |
&ast_channel_caller(chan)->ani); |
| 1063 |
switch (status) { |
| 1064 |
case ID_FIELD_VALID: |
| 1065 |
case ID_FIELD_INVALID: |
| 1066 |
break; |
| 1067 |
default: |
| 1068 |
ast_log(LOG_ERROR, "Unknown callerid data type '%s'.\n", data); |
| 1069 |
break; |
| 1070 |
} |
| 1071 |
} else if (!strcasecmp("priv", member.subnames[0])) { |
| 1072 |
status = party_id_read(buf, len, member.argc - 1, member.subnames + 1, |
| 1073 |
&ast_channel_caller(chan)->priv); |
| 1074 |
switch (status) { |
| 1075 |
case ID_FIELD_VALID: |
| 1076 |
case ID_FIELD_INVALID: |
| 1077 |
break; |
| 1078 |
default: |
| 1079 |
ast_log(LOG_ERROR, "Unknown callerid data type '%s'.\n", data); |
| 1080 |
break; |
| 1081 |
} |
| 1082 |
} else { |
| 1083 |
status = party_id_read(buf, len, member.argc, member.subnames, &ast_channel_caller(chan)->id); |
| 1084 |
switch (status) { |
| 1085 |
case ID_FIELD_VALID: |
| 1086 |
case ID_FIELD_INVALID: |
| 1087 |
break; |
| 1088 |
default: |
| 1089 |
ast_log(LOG_ERROR, "Unknown callerid data type '%s'.\n", data); |
| 1090 |
break; |
| 1091 |
} |
| 1092 |
} |
| 1093 |
|
| 1094 |
ast_channel_unlock(chan); |
| 1095 |
} |
| 1096 |
|
| 1097 |
return 0; |
| 1098 |
} |
| 1099 |
|
| 1100 |
|
| 1101 |
|
| 1102 |
|
| 1103 |
|
| 1104 |
|
| 1105 |
|
| 1106 |
|
| 1107 |
|
| 1108 |
|
| 1109 |
|
| 1110 |
|
| 1111 |
|
| 1112 |
static int callerid_write(struct ast_channel *chan, const char *cmd, char *data, const char *value) |
| 1113 |
{ |
| 1114 |
struct ast_party_caller caller; |
| 1115 |
struct ast_party_dialed dialed; |
| 1116 |
enum ID_FIELD_STATUS status; |
| 1117 |
char *val; |
| 1118 |
char *parms; |
| 1119 |
struct ast_party_func_args args = { 0, }; |
| 1120 |
struct ast_party_members member = { 0, }; |
| 1121 |
|
| 1122 |
if (!value || !chan) { |
| 1123 |
return -1; |
| 1124 |
} |
| 1125 |
|
| 1126 |
parms = ast_strdupa(data); |
| 1127 |
AST_STANDARD_APP_ARGS(args, parms); |
| 1128 |
if (args.argc == 0) { |
| 1129 |
|
| 1130 |
return -1; |
| 1131 |
} |
| 1132 |
|
| 1133 |
AST_NONSTANDARD_APP_ARGS(member, args.member, '-'); |
| 1134 |
if (member.argc == 0 || ARRAY_LEN(member.subnames) <= member.argc) { |
| 1135 |
|
| 1136 |
return -1; |
| 1137 |
} |
| 1138 |
|
| 1139 |
value = ast_skip_blanks(value); |
| 1140 |
|
| 1141 |
ast_channel_lock(chan); |
| 1142 |
if (member.argc == 1 && !strcasecmp("rdnis", member.subnames[0])) { |
| 1143 |
ast_channel_redirecting(chan)->from.number.valid = 1; |
| 1144 |
ast_free(ast_channel_redirecting(chan)->from.number.str); |
| 1145 |
ast_channel_redirecting(chan)->from.number.str = ast_strdup(value); |
| 1146 |
} else if (!strcasecmp("dnid", member.subnames[0])) { |
| 1147 |
ast_party_dialed_set_init(&dialed, ast_channel_dialed(chan)); |
| 1148 |
if (member.argc == 1) { |
| 1149 |
|
| 1150 |
member.argc = 2; |
| 1151 |
member.subnames[1] = "num"; |
| 1152 |
} |
| 1153 |
if (!strncasecmp("num", member.subnames[1], 3)) { |
| 1154 |
|
| 1155 |
|
| 1156 |
|
| 1157 |
|
| 1158 |
if (member.argc == 2) { |
| 1159 |
|
| 1160 |
dialed.number.str = ast_strdup(value); |
| 1161 |
ast_trim_blanks(dialed.number.str); |
| 1162 |
ast_party_dialed_set(ast_channel_dialed(chan), &dialed); |
| 1163 |
} else if (member.argc == 3 && !strcasecmp("plan", member.subnames[2])) { |
| 1164 |
|
| 1165 |
val = ast_strdupa(value); |
| 1166 |
ast_trim_blanks(val); |
| 1167 |
|
| 1168 |
if (('0' <= val[0]) && (val[0] <= '9')) { |
| 1169 |
ast_channel_dialed(chan)->number.plan = atoi(val); |
| 1170 |
} else { |
| 1171 |
ast_log(LOG_ERROR, |
| 1172 |
"Unknown type-of-number/numbering-plan '%s', value unchanged\n", val); |
| 1173 |
} |
| 1174 |
} else { |
| 1175 |
ast_log(LOG_ERROR, "Unknown callerid data type '%s'.\n", data); |
| 1176 |
} |
| 1177 |
} else if (!strncasecmp("subaddr", member.subnames[1], 7)) { |
| 1178 |
|
| 1179 |
|
| 1180 |
|
| 1181 |
|
| 1182 |
status = party_subaddress_write(&dialed.subaddress, member.argc - 2, |
| 1183 |
member.subnames + 2, value); |
| 1184 |
switch (status) { |
| 1185 |
case ID_FIELD_VALID: |
| 1186 |
ast_party_dialed_set(ast_channel_dialed(chan), &dialed); |
| 1187 |
break; |
| 1188 |
case ID_FIELD_INVALID: |
| 1189 |
break; |
| 1190 |
default: |
| 1191 |
ast_log(LOG_ERROR, "Unknown callerid data type '%s'.\n", data); |
| 1192 |
break; |
| 1193 |
} |
| 1194 |
} else { |
| 1195 |
ast_log(LOG_ERROR, "Unknown callerid data type '%s'.\n", data); |
| 1196 |
} |
| 1197 |
ast_party_dialed_free(&dialed); |
| 1198 |
} else if (member.argc == 1 && !strcasecmp("ani2", member.subnames[0])) { |
| 1199 |
val = ast_strdupa(value); |
| 1200 |
ast_trim_blanks(val); |
| 1201 |
|
| 1202 |
if (('0' <= val[0]) && (val[0] <= '9')) { |
| 1203 |
ast_channel_caller(chan)->ani2 = atoi(val); |
| 1204 |
} else { |
| 1205 |
ast_log(LOG_ERROR, "Unknown callerid ani2 '%s', value unchanged\n", val); |
| 1206 |
} |
| 1207 |
} else if (!strcasecmp("ani", member.subnames[0])) { |
| 1208 |
ast_party_caller_set_init(&caller, ast_channel_caller(chan)); |
| 1209 |
if (member.argc == 1) { |
| 1210 |
|
| 1211 |
member.argc = 2; |
| 1212 |
member.subnames[1] = "num"; |
| 1213 |
} |
| 1214 |
status = party_id_write(&caller.ani, member.argc - 1, member.subnames + 1, value); |
| 1215 |
switch (status) { |
| 1216 |
case ID_FIELD_VALID: |
| 1217 |
ast_party_caller_set(ast_channel_caller(chan), &caller, NULL); |
| 1218 |
break; |
| 1219 |
case ID_FIELD_INVALID: |
| 1220 |
break; |
| 1221 |
default: |
| 1222 |
ast_log(LOG_ERROR, "Unknown callerid data type '%s'.\n", data); |
| 1223 |
break; |
| 1224 |
} |
| 1225 |
ast_party_caller_free(&caller); |
| 1226 |
} else if (!strcasecmp("priv", member.subnames[0])) { |
| 1227 |
ast_party_caller_set_init(&caller, ast_channel_caller(chan)); |
| 1228 |
status = party_id_write(&caller.priv, member.argc - 1, member.subnames + 1, value); |
| 1229 |
switch (status) { |
| 1230 |
case ID_FIELD_VALID: |
| 1231 |
ast_party_caller_set(ast_channel_caller(chan), &caller, NULL); |
| 1232 |
break; |
| 1233 |
case ID_FIELD_INVALID: |
| 1234 |
break; |
| 1235 |
default: |
| 1236 |
ast_log(LOG_ERROR, "Unknown callerid data type '%s'.\n", data); |
| 1237 |
break; |
| 1238 |
} |
| 1239 |
ast_party_caller_free(&caller); |
| 1240 |
} else { |
| 1241 |
ast_party_caller_set_init(&caller, ast_channel_caller(chan)); |
| 1242 |
status = party_id_write(&caller.id, member.argc, member.subnames, value); |
| 1243 |
switch (status) { |
| 1244 |
case ID_FIELD_VALID: |
| 1245 |
ast_channel_set_caller_event(chan, &caller, NULL); |
| 1246 |
break; |
| 1247 |
case ID_FIELD_INVALID: |
| 1248 |
break; |
| 1249 |
default: |
| 1250 |
ast_log(LOG_ERROR, "Unknown callerid data type '%s'.\n", data); |
| 1251 |
break; |
| 1252 |
} |
| 1253 |
ast_party_caller_free(&caller); |
| 1254 |
} |
| 1255 |
ast_channel_unlock(chan); |
| 1256 |
|
| 1257 |
return 0; |
| 1258 |
} |
| 1259 |
|
| 1260 |
|
| 1261 |
|
| 1262 |
|
| 1263 |
|
| 1264 |
|
| 1265 |
|
| 1266 |
|
| 1267 |
|
| 1268 |
|
| 1269 |
|
| 1270 |
|
| 1271 |
|
| 1272 |
|
| 1273 |
static int connectedline_read(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len) |
| 1274 |
{ |
| 1275 |
struct ast_party_members member = { 0, }; |
| 1276 |
char *read_what; |
| 1277 |
enum ID_FIELD_STATUS status; |
| 1278 |
|
| 1279 |
|
| 1280 |
*buf = 0; |
| 1281 |
|
| 1282 |
if (!chan) { |
| 1283 |
return -1; |
| 1284 |
} |
| 1285 |
|
| 1286 |
read_what = ast_strdupa(data); |
| 1287 |
AST_NONSTANDARD_APP_ARGS(member, read_what, '-'); |
| 1288 |
if (member.argc == 0 || ARRAY_LEN(member.subnames) <= member.argc) { |
| 1289 |
|
| 1290 |
return -1; |
| 1291 |
} |
| 1292 |
|
| 1293 |
ast_channel_lock(chan); |
| 1294 |
|
| 1295 |
if (member.argc == 1 && !strcasecmp("source", member.subnames[0])) { |
| 1296 |
ast_copy_string(buf, ast_connected_line_source_name(ast_channel_connected(chan)->source), len); |
| 1297 |
} else if (!strcasecmp("priv", member.subnames[0])) { |
| 1298 |
status = party_id_read(buf, len, member.argc - 1, member.subnames + 1, |
| 1299 |
&ast_channel_connected(chan)->priv); |
| 1300 |
switch (status) { |
| 1301 |
case ID_FIELD_VALID: |
| 1302 |
case ID_FIELD_INVALID: |
| 1303 |
break; |
| 1304 |
default: |
| 1305 |
ast_log(LOG_ERROR, "Unknown connectedline data type '%s'.\n", data); |
| 1306 |
break; |
| 1307 |
} |
| 1308 |
} else { |
| 1309 |
status = party_id_read(buf, len, member.argc, member.subnames, &ast_channel_connected(chan)->id); |
| 1310 |
switch (status) { |
| 1311 |
case ID_FIELD_VALID: |
| 1312 |
case ID_FIELD_INVALID: |
| 1313 |
break; |
| 1314 |
default: |
| 1315 |
ast_log(LOG_ERROR, "Unknown connectedline data type '%s'.\n", data); |
| 1316 |
break; |
| 1317 |
} |
| 1318 |
} |
| 1319 |
|
| 1320 |
ast_channel_unlock(chan); |
| 1321 |
|
| 1322 |
return 0; |
| 1323 |
} |
| 1324 |
|
| 1325 |
|
| 1326 |
|
| 1327 |
|
| 1328 |
|
| 1329 |
|
| 1330 |
|
| 1331 |
|
| 1332 |
|
| 1333 |
|
| 1334 |
|
| 1335 |
|
| 1336 |
|
| 1337 |
static int connectedline_write(struct ast_channel *chan, const char *cmd, char *data, const char *value) |
| 1338 |
{ |
| 1339 |
struct ast_party_connected_line connected; |
| 1340 |
char *val; |
| 1341 |
char *parms; |
| 1342 |
void (*set_it)(struct ast_channel *chan, const struct ast_party_connected_line *connected, const struct ast_set_party_connected_line *update); |
| 1343 |
struct ast_party_func_args args = { 0, }; |
| 1344 |
struct ast_party_members member = { 0, }; |
| 1345 |
struct ast_flags opts; |
| 1346 |
char *opt_args[CONNECTED_LINE_OPT_ARG_ARRAY_SIZE]; |
| 1347 |
enum ID_FIELD_STATUS status; |
| 1348 |
|
| 1349 |
if (!value || !chan) { |
| 1350 |
return -1; |
| 1351 |
} |
| 1352 |
|
| 1353 |
parms = ast_strdupa(data); |
| 1354 |
AST_STANDARD_APP_ARGS(args, parms); |
| 1355 |
if (args.argc == 0) { |
| 1356 |
|
| 1357 |
return -1; |
| 1358 |
} |
| 1359 |
|
| 1360 |
AST_NONSTANDARD_APP_ARGS(member, args.member, '-'); |
| 1361 |
if (member.argc == 0 || ARRAY_LEN(member.subnames) <= member.argc) { |
| 1362 |
|
| 1363 |
return -1; |
| 1364 |
} |
| 1365 |
|
| 1366 |
if (ast_app_parse_options(connectedline_opts, &opts, opt_args, args.opts)) { |
| 1367 |
|
| 1368 |
return -1; |
| 1369 |
} |
| 1370 |
|
| 1371 |
|
| 1372 |
if (ast_test_flag(&opts, CONNECTED_LINE_OPT_INHIBIT)) { |
| 1373 |
set_it = ast_channel_set_connected_line; |
| 1374 |
} else { |
| 1375 |
set_it = ast_channel_update_connected_line; |
| 1376 |
} |
| 1377 |
|
| 1378 |
ast_channel_lock(chan); |
| 1379 |
ast_party_connected_line_set_init(&connected, ast_channel_connected(chan)); |
| 1380 |
ast_channel_unlock(chan); |
| 1381 |
|
| 1382 |
value = ast_skip_blanks(value); |
| 1383 |
|
| 1384 |
if (member.argc == 1 && !strcasecmp("source", member.subnames[0])) { |
| 1385 |
int source; |
| 1386 |
|
| 1387 |
val = ast_strdupa(value); |
| 1388 |
ast_trim_blanks(val); |
| 1389 |
|
| 1390 |
if (('0' <= val[0]) && (val[0] <= '9')) { |
| 1391 |
source = atoi(val); |
| 1392 |
} else { |
| 1393 |
source = ast_connected_line_source_parse(val); |
| 1394 |
} |
| 1395 |
|
| 1396 |
if (source < 0) { |
| 1397 |
ast_log(LOG_ERROR, "Unknown connectedline source '%s', value unchanged\n", val); |
| 1398 |
} else { |
| 1399 |
connected.source = source; |
| 1400 |
set_it(chan, &connected, NULL); |
| 1401 |
} |
| 1402 |
} else if (!strcasecmp("priv", member.subnames[0])) { |
| 1403 |
status = party_id_write(&connected.priv, member.argc - 1, member.subnames + 1, value); |
| 1404 |
switch (status) { |
| 1405 |
case ID_FIELD_VALID: |
| 1406 |
set_it(chan, &connected, NULL); |
| 1407 |
break; |
| 1408 |
case ID_FIELD_INVALID: |
| 1409 |
break; |
| 1410 |
default: |
| 1411 |
ast_log(LOG_ERROR, "Unknown connectedline data type '%s'.\n", data); |
| 1412 |
break; |
| 1413 |
} |
| 1414 |
ast_party_connected_line_free(&connected); |
| 1415 |
} else { |
| 1416 |
status = party_id_write(&connected.id, member.argc, member.subnames, value); |
| 1417 |
switch (status) { |
| 1418 |
case ID_FIELD_VALID: |
| 1419 |
set_it(chan, &connected, NULL); |
| 1420 |
break; |
| 1421 |
case ID_FIELD_INVALID: |
| 1422 |
break; |
| 1423 |
default: |
| 1424 |
ast_log(LOG_ERROR, "Unknown connectedline data type '%s'.\n", data); |
| 1425 |
break; |
| 1426 |
} |
| 1427 |
ast_party_connected_line_free(&connected); |
| 1428 |
} |
| 1429 |
|
| 1430 |
return 0; |
| 1431 |
} |
| 1432 |
|
| 1433 |
|
| 1434 |
|
| 1435 |
|
| 1436 |
|
| 1437 |
|
| 1438 |
|
| 1439 |
|
| 1440 |
|
| 1441 |
|
| 1442 |
|
| 1443 |
|
| 1444 |
|
| 1445 |
|
| 1446 |
static int redirecting_read(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len) |
| 1447 |
{ |
| 1448 |
struct ast_party_members member = { 0, }; |
| 1449 |
char *read_what; |
| 1450 |
const struct ast_party_redirecting *ast_redirecting; |
| 1451 |
enum ID_FIELD_STATUS status; |
| 1452 |
|
| 1453 |
|
| 1454 |
*buf = 0; |
| 1455 |
|
| 1456 |
if (!chan) { |
| 1457 |
return -1; |
| 1458 |
} |
| 1459 |
|
| 1460 |
read_what = ast_strdupa(data); |
| 1461 |
AST_NONSTANDARD_APP_ARGS(member, read_what, '-'); |
| 1462 |
if (member.argc == 0 || ARRAY_LEN(member.subnames) <= member.argc) { |
| 1463 |
|
| 1464 |
return -1; |
| 1465 |
} |
| 1466 |
|
| 1467 |
ast_channel_lock(chan); |
| 1468 |
|
| 1469 |
ast_redirecting = ast_channel_redirecting(chan); |
| 1470 |
if (!strcasecmp("orig", member.subnames[0])) { |
| 1471 |
if (member.argc == 2 && !strcasecmp("reason", member.subnames[1])) { |
| 1472 |
ast_copy_string(buf, |
| 1473 |
ast_redirecting_reason_name(&ast_redirecting->orig_reason), len); |
| 1474 |
} else { |
| 1475 |
status = party_id_read(buf, len, member.argc - 1, member.subnames + 1, |
| 1476 |
&ast_redirecting->orig); |
| 1477 |
switch (status) { |
| 1478 |
case ID_FIELD_VALID: |
| 1479 |
case ID_FIELD_INVALID: |
| 1480 |
break; |
| 1481 |
default: |
| 1482 |
ast_log(LOG_ERROR, "Unknown redirecting data type '%s'.\n", data); |
| 1483 |
break; |
| 1484 |
} |
| 1485 |
} |
| 1486 |
} else if (!strcasecmp("from", member.subnames[0])) { |
| 1487 |
status = party_id_read(buf, len, member.argc - 1, member.subnames + 1, |
| 1488 |
&ast_redirecting->from); |
| 1489 |
switch (status) { |
| 1490 |
case ID_FIELD_VALID: |
| 1491 |
case ID_FIELD_INVALID: |
| 1492 |
break; |
| 1493 |
default: |
| 1494 |
ast_log(LOG_ERROR, "Unknown redirecting data type '%s'.\n", data); |
| 1495 |
break; |
| 1496 |
} |
| 1497 |
} else if (!strcasecmp("to", member.subnames[0])) { |
| 1498 |
status = party_id_read(buf, len, member.argc - 1, member.subnames + 1, |
| 1499 |
&ast_redirecting->to); |
| 1500 |
switch (status) { |
| 1501 |
case ID_FIELD_VALID: |
| 1502 |
case ID_FIELD_INVALID: |
| 1503 |
break; |
| 1504 |
default: |
| 1505 |
ast_log(LOG_ERROR, "Unknown redirecting data type '%s'.\n", data); |
| 1506 |
break; |
| 1507 |
} |
| 1508 |
} else if (member.argc == 1 && !strncasecmp("pres", member.subnames[0], 4)) { |
| 1509 |
|
| 1510 |
|
| 1511 |
|
| 1512 |
|
| 1513 |
ast_copy_string(buf, |
| 1514 |
ast_named_caller_presentation( |
| 1515 |
ast_party_id_presentation(&ast_redirecting->from)), len); |
| 1516 |
} else if (member.argc == 1 && !strcasecmp("reason", member.subnames[0])) { |
| 1517 |
ast_copy_string(buf, ast_redirecting_reason_name(&ast_redirecting->reason), len); |
| 1518 |
} else if (member.argc == 1 && !strcasecmp("count", member.subnames[0])) { |
| 1519 |
snprintf(buf, len, "%d", ast_redirecting->count); |
| 1520 |
} else if (1 < member.argc && !strcasecmp("priv", member.subnames[0])) { |
| 1521 |
if (!strcasecmp("orig", member.subnames[1])) { |
| 1522 |
status = party_id_read(buf, len, member.argc - 2, member.subnames + 2, |
| 1523 |
&ast_redirecting->priv_orig); |
| 1524 |
switch (status) { |
| 1525 |
case ID_FIELD_VALID: |
| 1526 |
case ID_FIELD_INVALID: |
| 1527 |
break; |
| 1528 |
default: |
| 1529 |
ast_log(LOG_ERROR, "Unknown redirecting data type '%s'.\n", data); |
| 1530 |
break; |
| 1531 |
} |
| 1532 |
} else if (!strcasecmp("from", member.subnames[1])) { |
| 1533 |
status = party_id_read(buf, len, member.argc - 2, member.subnames + 2, |
| 1534 |
&ast_redirecting->priv_from); |
| 1535 |
switch (status) { |
| 1536 |
case ID_FIELD_VALID: |
| 1537 |
case ID_FIELD_INVALID: |
| 1538 |
break; |
| 1539 |
default: |
| 1540 |
ast_log(LOG_ERROR, "Unknown redirecting data type '%s'.\n", data); |
| 1541 |
break; |
| 1542 |
} |
| 1543 |
} else if (!strcasecmp("to", member.subnames[1])) { |
| 1544 |
status = party_id_read(buf, len, member.argc - 2, member.subnames + 2, |
| 1545 |
&ast_redirecting->priv_to); |
| 1546 |
switch (status) { |
| 1547 |
case ID_FIELD_VALID: |
| 1548 |
case ID_FIELD_INVALID: |
| 1549 |
break; |
| 1550 |
default: |
| 1551 |
ast_log(LOG_ERROR, "Unknown redirecting data type '%s'.\n", data); |
| 1552 |
break; |
| 1553 |
} |
| 1554 |
} else { |
| 1555 |
ast_log(LOG_ERROR, "Unknown redirecting data type '%s'.\n", data); |
| 1556 |
} |
| 1557 |
} else { |
| 1558 |
ast_log(LOG_ERROR, "Unknown redirecting data type '%s'.\n", data); |
| 1559 |
} |
| 1560 |
|
| 1561 |
ast_channel_unlock(chan); |
| 1562 |
|
| 1563 |
return 0; |
| 1564 |
} |
| 1565 |
|
| 1566 |
|
| 1567 |
|
| 1568 |
|
| 1569 |
|
| 1570 |
|
| 1571 |
|
| 1572 |
|
| 1573 |
|
| 1574 |
|
| 1575 |
|
| 1576 |
|
| 1577 |
|
| 1578 |
static int redirecting_write(struct ast_channel *chan, const char *cmd, char *data, const char *value) |
| 1579 |
{ |
| 1580 |
struct ast_party_redirecting redirecting; |
| 1581 |
enum ID_FIELD_STATUS status; |
| 1582 |
char *val; |
| 1583 |
char *parms; |
| 1584 |
void (*set_it)(struct ast_channel *chan, const struct ast_party_redirecting *redirecting, const struct ast_set_party_redirecting *update); |
| 1585 |
struct ast_party_func_args args = { 0, }; |
| 1586 |
struct ast_party_members member = { 0, }; |
| 1587 |
struct ast_flags opts; |
| 1588 |
char *opt_args[REDIRECTING_OPT_ARG_ARRAY_SIZE]; |
| 1589 |
|
| 1590 |
if (!value || !chan) { |
| 1591 |
return -1; |
| 1592 |
} |
| 1593 |
|
| 1594 |
parms = ast_strdupa(data); |
| 1595 |
AST_STANDARD_APP_ARGS(args, parms); |
| 1596 |
if (args.argc == 0) { |
| 1597 |
|
| 1598 |
return -1; |
| 1599 |
} |
| 1600 |
|
| 1601 |
AST_NONSTANDARD_APP_ARGS(member, args.member, '-'); |
| 1602 |
if (member.argc == 0 || ARRAY_LEN(member.subnames) <= member.argc) { |
| 1603 |
|
| 1604 |
return -1; |
| 1605 |
} |
| 1606 |
|
| 1607 |
if (ast_app_parse_options(redirecting_opts, &opts, opt_args, args.opts)) { |
| 1608 |
|
| 1609 |
return -1; |
| 1610 |
} |
| 1611 |
|
| 1612 |
|
| 1613 |
if (ast_test_flag(&opts, REDIRECTING_OPT_INHIBIT)) { |
| 1614 |
set_it = ast_channel_set_redirecting; |
| 1615 |
} else { |
| 1616 |
set_it = ast_channel_update_redirecting; |
| 1617 |
} |
| 1618 |
|
| 1619 |
ast_channel_lock(chan); |
| 1620 |
ast_party_redirecting_set_init(&redirecting, ast_channel_redirecting(chan)); |
| 1621 |
ast_channel_unlock(chan); |
| 1622 |
|
| 1623 |
value = ast_skip_blanks(value); |
| 1624 |
|
| 1625 |
if (!strcasecmp("orig", member.subnames[0])) { |
| 1626 |
if (member.argc == 2 && !strcasecmp("reason", member.subnames[1])) { |
| 1627 |
int reason; |
| 1628 |
|
| 1629 |
val = ast_strdupa(value); |
| 1630 |
ast_trim_blanks(val); |
| 1631 |
|
| 1632 |
if (('0' <= val[0]) && (val[0] <= '9')) { |
| 1633 |
reason = atoi(val); |
| 1634 |
} else { |
| 1635 |
reason = ast_redirecting_reason_parse(val); |
| 1636 |
} |
| 1637 |
|
| 1638 |
if (reason < 0) { |
| 1639 |
|
| 1640 |
|
| 1641 |
|
| 1642 |
|
| 1643 |
ast_log(LOG_WARNING, "Unknown redirecting reason '%s', defaulting to unknown\n", val); |
| 1644 |
redirecting.orig_reason.code = AST_REDIRECTING_REASON_UNKNOWN; |
| 1645 |
redirecting.orig_reason.str = val; |
| 1646 |
set_it(chan, &redirecting, NULL); |
| 1647 |
} else { |
| 1648 |
redirecting.orig_reason.code = reason; |
| 1649 |
redirecting.orig_reason.str = ""; |
| 1650 |
set_it(chan, &redirecting, NULL); |
| 1651 |
} |
| 1652 |
} else { |
| 1653 |
status = party_id_write(&redirecting.orig, member.argc - 1, member.subnames + 1, |
| 1654 |
value); |
| 1655 |
switch (status) { |
| 1656 |
case ID_FIELD_VALID: |
| 1657 |
set_it(chan, &redirecting, NULL); |
| 1658 |
break; |
| 1659 |
case ID_FIELD_INVALID: |
| 1660 |
break; |
| 1661 |
default: |
| 1662 |
ast_log(LOG_ERROR, "Unknown redirecting data type '%s'.\n", data); |
| 1663 |
break; |
| 1664 |
} |
| 1665 |
ast_party_redirecting_free(&redirecting); |
| 1666 |
} |
| 1667 |
} else if (!strcasecmp("from", member.subnames[0])) { |
| 1668 |
status = party_id_write(&redirecting.from, member.argc - 1, member.subnames + 1, |
| 1669 |
value); |
| 1670 |
switch (status) { |
| 1671 |
case ID_FIELD_VALID: |
| 1672 |
set_it(chan, &redirecting, NULL); |
| 1673 |
break; |
| 1674 |
case ID_FIELD_INVALID: |
| 1675 |
break; |
| 1676 |
default: |
| 1677 |
ast_log(LOG_ERROR, "Unknown redirecting data type '%s'.\n", data); |
| 1678 |
break; |
| 1679 |
} |
| 1680 |
ast_party_redirecting_free(&redirecting); |
| 1681 |
} else if (!strcasecmp("to", member.subnames[0])) { |
| 1682 |
status = party_id_write(&redirecting.to, member.argc - 1, member.subnames + 1, value); |
| 1683 |
switch (status) { |
| 1684 |
case ID_FIELD_VALID: |
| 1685 |
set_it(chan, &redirecting, NULL); |
| 1686 |
break; |
| 1687 |
case ID_FIELD_INVALID: |
| 1688 |
break; |
| 1689 |
default: |
| 1690 |
ast_log(LOG_ERROR, "Unknown redirecting data type '%s'.\n", data); |
| 1691 |
break; |
| 1692 |
} |
| 1693 |
ast_party_redirecting_free(&redirecting); |
| 1694 |
} else if (member.argc == 1 && !strncasecmp("pres", member.subnames[0], 4)) { |
| 1695 |
int pres; |
| 1696 |
|
| 1697 |
val = ast_strdupa(value); |
| 1698 |
ast_trim_blanks(val); |
| 1699 |
|
| 1700 |
if (('0' <= val[0]) && (val[0] <= '9')) { |
| 1701 |
pres = atoi(val); |
| 1702 |
} else { |
| 1703 |
pres = ast_parse_caller_presentation(val); |
| 1704 |
} |
| 1705 |
|
| 1706 |
if (pres < 0) { |
| 1707 |
ast_log(LOG_ERROR, |
| 1708 |
"Unknown redirecting combined presentation '%s', value unchanged\n", val); |
| 1709 |
} else { |
| 1710 |
redirecting.from.name.presentation = pres; |
| 1711 |
redirecting.from.number.presentation = pres; |
| 1712 |
redirecting.to.name.presentation = pres; |
| 1713 |
redirecting.to.number.presentation = pres; |
| 1714 |
set_it(chan, &redirecting, NULL); |
| 1715 |
} |
| 1716 |
} else if (member.argc == 1 && !strcasecmp("reason", member.subnames[0])) { |
| 1717 |
int reason; |
| 1718 |
|
| 1719 |
val = ast_strdupa(value); |
| 1720 |
ast_trim_blanks(val); |
| 1721 |
|
| 1722 |
if (('0' <= val[0]) && (val[0] <= '9')) { |
| 1723 |
reason = atoi(val); |
| 1724 |
} else { |
| 1725 |
reason = ast_redirecting_reason_parse(val); |
| 1726 |
} |
| 1727 |
|
| 1728 |
if (reason < 0) { |
| 1729 |
|
| 1730 |
|
| 1731 |
|
| 1732 |
|
| 1733 |
ast_log(LOG_WARNING, "Unknown redirecting reason '%s', defaulting to unknown\n", val); |
| 1734 |
redirecting.reason.code = AST_REDIRECTING_REASON_UNKNOWN; |
| 1735 |
redirecting.reason.str = val; |
| 1736 |
set_it(chan, &redirecting, NULL); |
| 1737 |
} else { |
| 1738 |
redirecting.reason.code = reason; |
| 1739 |
redirecting.reason.str = ""; |
| 1740 |
set_it(chan, &redirecting, NULL); |
| 1741 |
} |
| 1742 |
} else if (member.argc == 1 && !strcasecmp("count", member.subnames[0])) { |
| 1743 |
val = ast_strdupa(value); |
| 1744 |
ast_trim_blanks(val); |
| 1745 |
|
| 1746 |
if (('0' <= val[0]) && (val[0] <= '9')) { |
| 1747 |
redirecting.count = atoi(val); |
| 1748 |
set_it(chan, &redirecting, NULL); |
| 1749 |
} else { |
| 1750 |
ast_log(LOG_ERROR, "Unknown redirecting count '%s', value unchanged\n", val); |
| 1751 |
} |
| 1752 |
} else if (1 < member.argc && !strcasecmp("priv", member.subnames[0])) { |
| 1753 |
if (!strcasecmp("orig", member.subnames[1])) { |
| 1754 |
status = party_id_write(&redirecting.priv_orig, member.argc - 2, member.subnames + 2, |
| 1755 |
value); |
| 1756 |
switch (status) { |
| 1757 |
case ID_FIELD_VALID: |
| 1758 |
set_it(chan, &redirecting, NULL); |
| 1759 |
break; |
| 1760 |
case ID_FIELD_INVALID: |
| 1761 |
break; |
| 1762 |
default: |
| 1763 |
ast_log(LOG_ERROR, "Unknown redirecting data type '%s'.\n", data); |
| 1764 |
break; |
| 1765 |
} |
| 1766 |
ast_party_redirecting_free(&redirecting); |
| 1767 |
} else if (!strcasecmp("from", member.subnames[1])) { |
| 1768 |
status = party_id_write(&redirecting.priv_from, member.argc - 2, member.subnames + 2, |
| 1769 |
value); |
| 1770 |
switch (status) { |
| 1771 |
case ID_FIELD_VALID: |
| 1772 |
set_it(chan, &redirecting, NULL); |
| 1773 |
break; |
| 1774 |
case ID_FIELD_INVALID: |
| 1775 |
break; |
| 1776 |
default: |
| 1777 |
ast_log(LOG_ERROR, "Unknown redirecting data type '%s'.\n", data); |
| 1778 |
break; |
| 1779 |
} |
| 1780 |
ast_party_redirecting_free(&redirecting); |
| 1781 |
} else if (!strcasecmp("to", member.subnames[1])) { |
| 1782 |
status = party_id_write(&redirecting.priv_to, member.argc - 2, member.subnames + 2, value); |
| 1783 |
switch (status) { |
| 1784 |
case ID_FIELD_VALID: |
| 1785 |
set_it(chan, &redirecting, NULL); |
| 1786 |
break; |
| 1787 |
case ID_FIELD_INVALID: |
| 1788 |
break; |
| 1789 |
default: |
| 1790 |
ast_log(LOG_ERROR, "Unknown redirecting data type '%s'.\n", data); |
| 1791 |
break; |
| 1792 |
} |
| 1793 |
ast_party_redirecting_free(&redirecting); |
| 1794 |
} else { |
| 1795 |
ast_log(LOG_ERROR, "Unknown redirecting data type '%s'.\n", data); |
| 1796 |
} |
| 1797 |
} else { |
| 1798 |
ast_log(LOG_ERROR, "Unknown redirecting data type '%s'.\n", data); |
| 1799 |
} |
| 1800 |
|
| 1801 |
return 0; |
| 1802 |
} |
| 1803 |
|
| 1804 |
static struct ast_custom_function callerid_function = { |
| 1805 |
.name = "CALLERID", |
| 1806 |
.read = callerid_read, |
| 1807 |
.read_max = 256, |
| 1808 |
.write = callerid_write, |
| 1809 |
}; |
| 1810 |
|
| 1811 |
static struct ast_custom_function connectedline_function = { |
| 1812 |
.name = "CONNECTEDLINE", |
| 1813 |
.read = connectedline_read, |
| 1814 |
.write = connectedline_write, |
| 1815 |
}; |
| 1816 |
|
| 1817 |
static struct ast_custom_function redirecting_function = { |
| 1818 |
.name = "REDIRECTING", |
| 1819 |
.read = redirecting_read, |
| 1820 |
.write = redirecting_write, |
| 1821 |
}; |
| 1822 |
|
| 1823 |
|
| 1824 |
|
| 1825 |
|
| 1826 |
|
| 1827 |
|
| 1828 |
|
| 1829 |
|
| 1830 |
static int unload_module(void) |
| 1831 |
{ |
| 1832 |
ast_custom_function_unregister(&callerid_function); |
| 1833 |
ast_custom_function_unregister(&connectedline_function); |
| 1834 |
ast_custom_function_unregister(&redirecting_function); |
| 1835 |
return 0; |
| 1836 |
} |
| 1837 |
|
| 1838 |
|
| 1839 |
|
| 1840 |
|
| 1841 |
|
| 1842 |
|
| 1843 |
|
| 1844 |
|
| 1845 |
static int load_module(void) |
| 1846 |
{ |
| 1847 |
int res; |
| 1848 |
|
| 1849 |
res = ast_custom_function_register(&callerid_function); |
| 1850 |
res |= ast_custom_function_register(&connectedline_function); |
| 1851 |
res |= ast_custom_function_register(&redirecting_function); |
| 1852 |
|
| 1853 |
if (res) { |
| 1854 |
unload_module(); |
| 1855 |
return AST_MODULE_LOAD_DECLINE; |
| 1856 |
} |
| 1857 |
|
| 1858 |
return AST_MODULE_LOAD_SUCCESS; |
| 1859 |
} |
| 1860 |
|
| 1861 |
|
| 1862 |
AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Party ID related dialplan functions (Caller-ID, Connected-line, Redirecting)"); |