| 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 |
|
| 34 |
#include "asterisk.h" |
| 35 |
|
| 36 |
#include <regex.h> |
| 37 |
#include <ctype.h> |
| 38 |
|
| 39 |
#include "asterisk/module.h" |
| 40 |
#include "asterisk/channel.h" |
| 41 |
#include "asterisk/pbx.h" |
| 42 |
#include "asterisk/utils.h" |
| 43 |
#include "asterisk/app.h" |
| 44 |
#include "asterisk/localtime.h" |
| 45 |
#include "asterisk/test.h" |
| 46 |
|
| 47 |
AST_THREADSTORAGE(result_buf); |
| 48 |
AST_THREADSTORAGE(tmp_buf); |
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
|
| 142 |
|
| 143 |
|
| 144 |
|
| 145 |
|
| 146 |
|
| 147 |
|
| 148 |
|
| 149 |
|
| 150 |
|
| 151 |
|
| 152 |
|
| 153 |
|
| 154 |
|
| 155 |
|
| 156 |
|
| 157 |
|
| 158 |
|
| 159 |
|
| 160 |
|
| 161 |
|
| 162 |
|
| 163 |
|
| 164 |
|
| 165 |
|
| 166 |
|
| 167 |
|
| 168 |
|
| 169 |
|
| 170 |
|
| 171 |
|
| 172 |
|
| 173 |
|
| 174 |
|
| 175 |
|
| 176 |
|
| 177 |
|
| 178 |
|
| 179 |
|
| 180 |
|
| 181 |
|
| 182 |
|
| 183 |
|
| 184 |
|
| 185 |
|
| 186 |
|
| 187 |
|
| 188 |
|
| 189 |
|
| 190 |
|
| 191 |
|
| 192 |
|
| 193 |
|
| 194 |
|
| 195 |
|
| 196 |
|
| 197 |
|
| 198 |
|
| 199 |
|
| 200 |
|
| 201 |
|
| 202 |
|
| 203 |
|
| 204 |
|
| 205 |
|
| 206 |
|
| 207 |
|
| 208 |
|
| 209 |
|
| 210 |
|
| 211 |
|
| 212 |
|
| 213 |
|
| 214 |
|
| 215 |
|
| 216 |
|
| 217 |
|
| 218 |
|
| 219 |
|
| 220 |
|
| 221 |
|
| 222 |
|
| 223 |
|
| 224 |
|
| 225 |
|
| 226 |
|
| 227 |
|
| 228 |
|
| 229 |
|
| 230 |
|
| 231 |
|
| 232 |
|
| 233 |
|
| 234 |
|
| 235 |
|
| 236 |
|
| 237 |
|
| 238 |
|
| 239 |
|
| 240 |
|
| 241 |
|
| 242 |
|
| 243 |
|
| 244 |
|
| 245 |
|
| 246 |
|
| 247 |
|
| 248 |
|
| 249 |
|
| 250 |
|
| 251 |
|
| 252 |
|
| 253 |
|
| 254 |
|
| 255 |
|
| 256 |
|
| 257 |
|
| 258 |
|
| 259 |
|
| 260 |
|
| 261 |
|
| 262 |
|
| 263 |
|
| 264 |
|
| 265 |
|
| 266 |
|
| 267 |
|
| 268 |
|
| 269 |
|
| 270 |
|
| 271 |
|
| 272 |
|
| 273 |
|
| 274 |
|
| 275 |
|
| 276 |
|
| 277 |
|
| 278 |
|
| 279 |
|
| 280 |
|
| 281 |
|
| 282 |
|
| 283 |
|
| 284 |
|
| 285 |
|
| 286 |
|
| 287 |
|
| 288 |
|
| 289 |
|
| 290 |
|
| 291 |
|
| 292 |
|
| 293 |
|
| 294 |
|
| 295 |
|
| 296 |
|
| 297 |
|
| 298 |
|
| 299 |
|
| 300 |
|
| 301 |
|
| 302 |
|
| 303 |
|
| 304 |
|
| 305 |
|
| 306 |
|
| 307 |
|
| 308 |
|
| 309 |
|
| 310 |
|
| 311 |
|
| 312 |
|
| 313 |
|
| 314 |
|
| 315 |
|
| 316 |
|
| 317 |
|
| 318 |
|
| 319 |
|
| 320 |
|
| 321 |
|
| 322 |
|
| 323 |
|
| 324 |
|
| 325 |
|
| 326 |
|
| 327 |
|
| 328 |
|
| 329 |
|
| 330 |
|
| 331 |
|
| 332 |
|
| 333 |
|
| 334 |
|
| 335 |
|
| 336 |
|
| 337 |
|
| 338 |
|
| 339 |
|
| 340 |
|
| 341 |
|
| 342 |
|
| 343 |
|
| 344 |
|
| 345 |
|
| 346 |
|
| 347 |
|
| 348 |
|
| 349 |
|
| 350 |
|
| 351 |
|
| 352 |
|
| 353 |
|
| 354 |
|
| 355 |
|
| 356 |
|
| 357 |
|
| 358 |
|
| 359 |
|
| 360 |
|
| 361 |
|
| 362 |
|
| 363 |
|
| 364 |
|
| 365 |
|
| 366 |
|
| 367 |
|
| 368 |
|
| 369 |
|
| 370 |
|
| 371 |
|
| 372 |
|
| 373 |
|
| 374 |
|
| 375 |
|
| 376 |
|
| 377 |
|
| 378 |
|
| 379 |
|
| 380 |
|
| 381 |
|
| 382 |
|
| 383 |
|
| 384 |
|
| 385 |
|
| 386 |
|
| 387 |
|
| 388 |
|
| 389 |
|
| 390 |
|
| 391 |
|
| 392 |
|
| 393 |
|
| 394 |
|
| 395 |
|
| 396 |
|
| 397 |
|
| 398 |
|
| 399 |
|
| 400 |
|
| 401 |
|
| 402 |
|
| 403 |
|
| 404 |
|
| 405 |
|
| 406 |
|
| 407 |
|
| 408 |
|
| 409 |
|
| 410 |
|
| 411 |
|
| 412 |
|
| 413 |
|
| 414 |
|
| 415 |
|
| 416 |
|
| 417 |
|
| 418 |
|
| 419 |
|
| 420 |
|
| 421 |
|
| 422 |
|
| 423 |
|
| 424 |
|
| 425 |
|
| 426 |
|
| 427 |
|
| 428 |
|
| 429 |
|
| 430 |
|
| 431 |
|
| 432 |
|
| 433 |
|
| 434 |
|
| 435 |
|
| 436 |
|
| 437 |
|
| 438 |
|
| 439 |
|
| 440 |
|
| 441 |
|
| 442 |
|
| 443 |
|
| 444 |
|
| 445 |
|
| 446 |
|
| 447 |
|
| 448 |
|
| 449 |
|
| 450 |
|
| 451 |
|
| 452 |
|
| 453 |
|
| 454 |
|
| 455 |
|
| 456 |
|
| 457 |
|
| 458 |
|
| 459 |
|
| 460 |
|
| 461 |
|
| 462 |
|
| 463 |
|
| 464 |
|
| 465 |
|
| 466 |
|
| 467 |
|
| 468 |
|
| 469 |
|
| 470 |
|
| 471 |
|
| 472 |
|
| 473 |
|
| 474 |
|
| 475 |
|
| 476 |
|
| 477 |
|
| 478 |
|
| 479 |
|
| 480 |
|
| 481 |
|
| 482 |
|
| 483 |
|
| 484 |
|
| 485 |
|
| 486 |
|
| 487 |
|
| 488 |
|
| 489 |
|
| 490 |
|
| 491 |
|
| 492 |
|
| 493 |
|
| 494 |
|
| 495 |
|
| 496 |
|
| 497 |
|
| 498 |
|
| 499 |
|
| 500 |
|
| 501 |
|
| 502 |
|
| 503 |
|
| 504 |
|
| 505 |
|
| 506 |
|
| 507 |
|
| 508 |
|
| 509 |
|
| 510 |
|
| 511 |
|
| 512 |
|
| 513 |
|
| 514 |
|
| 515 |
|
| 516 |
|
| 517 |
|
| 518 |
|
| 519 |
|
| 520 |
|
| 521 |
|
| 522 |
|
| 523 |
|
| 524 |
|
| 525 |
|
| 526 |
|
| 527 |
|
| 528 |
|
| 529 |
|
| 530 |
|
| 531 |
|
| 532 |
|
| 533 |
|
| 534 |
|
| 535 |
|
| 536 |
|
| 537 |
|
| 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 |
static int function_fieldqty_helper(struct ast_channel *chan, const char *cmd, |
| 631 |
char *parse, char *buf, struct ast_str **sbuf, ssize_t len) |
| 632 |
{ |
| 633 |
char *varsubst; |
| 634 |
struct ast_str *str = ast_str_thread_get(&result_buf, 16); |
| 635 |
int fieldcount = 0; |
| 636 |
AST_DECLARE_APP_ARGS(args, |
| 637 |
AST_APP_ARG(varname); |
| 638 |
AST_APP_ARG(delim); |
| 639 |
); |
| 640 |
char delim[2] = ""; |
| 641 |
size_t delim_used; |
| 642 |
|
| 643 |
if (!str) { |
| 644 |
return -1; |
| 645 |
} |
| 646 |
|
| 647 |
AST_STANDARD_APP_ARGS(args, parse); |
| 648 |
if (args.delim) { |
| 649 |
ast_get_encoded_char(args.delim, delim, &delim_used); |
| 650 |
|
| 651 |
varsubst = ast_alloca(strlen(args.varname) + 4); |
| 652 |
|
| 653 |
sprintf(varsubst, "${%s}", args.varname); |
| 654 |
ast_str_substitute_variables(&str, 0, chan, varsubst); |
| 655 |
if (ast_str_strlen(str) == 0) { |
| 656 |
fieldcount = 0; |
| 657 |
} else { |
| 658 |
char *varval = ast_str_buffer(str); |
| 659 |
while (strsep(&varval, delim)) { |
| 660 |
fieldcount++; |
| 661 |
} |
| 662 |
} |
| 663 |
} else { |
| 664 |
fieldcount = 1; |
| 665 |
} |
| 666 |
if (sbuf) { |
| 667 |
ast_str_set(sbuf, len, "%d", fieldcount); |
| 668 |
} else { |
| 669 |
snprintf(buf, len, "%d", fieldcount); |
| 670 |
} |
| 671 |
|
| 672 |
return 0; |
| 673 |
} |
| 674 |
|
| 675 |
static int function_fieldqty(struct ast_channel *chan, const char *cmd, |
| 676 |
char *parse, char *buf, size_t len) |
| 677 |
{ |
| 678 |
return function_fieldqty_helper(chan, cmd, parse, buf, NULL, len); |
| 679 |
} |
| 680 |
|
| 681 |
static int function_fieldqty_str(struct ast_channel *chan, const char *cmd, |
| 682 |
char *parse, struct ast_str **buf, ssize_t len) |
| 683 |
{ |
| 684 |
return function_fieldqty_helper(chan, cmd, parse, NULL, buf, len); |
| 685 |
} |
| 686 |
|
| 687 |
static struct ast_custom_function fieldqty_function = { |
| 688 |
.name = "FIELDQTY", |
| 689 |
.read = function_fieldqty, |
| 690 |
.read2 = function_fieldqty_str, |
| 691 |
}; |
| 692 |
|
| 693 |
static int function_fieldnum_helper(struct ast_channel *chan, const char *cmd, |
| 694 |
char *parse, char *buf, struct ast_str **sbuf, ssize_t len) |
| 695 |
{ |
| 696 |
char *varsubst, *field; |
| 697 |
struct ast_str *str = ast_str_thread_get(&result_buf, 16); |
| 698 |
int fieldindex = 0, res = 0; |
| 699 |
AST_DECLARE_APP_ARGS(args, |
| 700 |
AST_APP_ARG(varname); |
| 701 |
AST_APP_ARG(delim); |
| 702 |
AST_APP_ARG(field); |
| 703 |
); |
| 704 |
char delim[2] = ""; |
| 705 |
size_t delim_used; |
| 706 |
|
| 707 |
if (!str) { |
| 708 |
return -1; |
| 709 |
} |
| 710 |
|
| 711 |
AST_STANDARD_APP_ARGS(args, parse); |
| 712 |
|
| 713 |
if (args.argc < 3) { |
| 714 |
ast_log(LOG_ERROR, "Usage: FIELDNUM(<listname>,<delimiter>,<fieldvalue>)\n"); |
| 715 |
res = -1; |
| 716 |
} else { |
| 717 |
varsubst = ast_alloca(strlen(args.varname) + 4); |
| 718 |
sprintf(varsubst, "${%s}", args.varname); |
| 719 |
|
| 720 |
ast_str_substitute_variables(&str, 0, chan, varsubst); |
| 721 |
|
| 722 |
if (ast_str_strlen(str) == 0 || ast_strlen_zero(args.delim)) { |
| 723 |
fieldindex = 0; |
| 724 |
} else if (ast_get_encoded_char(args.delim, delim, &delim_used) == -1) { |
| 725 |
res = -1; |
| 726 |
} else { |
| 727 |
char *varval = ast_str_buffer(str); |
| 728 |
|
| 729 |
while ((field = strsep(&varval, delim)) != NULL) { |
| 730 |
fieldindex++; |
| 731 |
|
| 732 |
if (!strcasecmp(field, args.field)) { |
| 733 |
break; |
| 734 |
} |
| 735 |
} |
| 736 |
|
| 737 |
if (!field) { |
| 738 |
fieldindex = 0; |
| 739 |
} |
| 740 |
|
| 741 |
res = 0; |
| 742 |
} |
| 743 |
} |
| 744 |
|
| 745 |
if (sbuf) { |
| 746 |
ast_str_set(sbuf, len, "%d", fieldindex); |
| 747 |
} else { |
| 748 |
snprintf(buf, len, "%d", fieldindex); |
| 749 |
} |
| 750 |
|
| 751 |
return res; |
| 752 |
} |
| 753 |
|
| 754 |
static int function_fieldnum(struct ast_channel *chan, const char *cmd, |
| 755 |
char *parse, char *buf, size_t len) |
| 756 |
{ |
| 757 |
return function_fieldnum_helper(chan, cmd, parse, buf, NULL, len); |
| 758 |
} |
| 759 |
|
| 760 |
static int function_fieldnum_str(struct ast_channel *chan, const char *cmd, |
| 761 |
char *parse, struct ast_str **buf, ssize_t len) |
| 762 |
{ |
| 763 |
return function_fieldnum_helper(chan, cmd, parse, NULL, buf, len); |
| 764 |
} |
| 765 |
|
| 766 |
static struct ast_custom_function fieldnum_function = { |
| 767 |
.name = "FIELDNUM", |
| 768 |
.read = function_fieldnum, |
| 769 |
.read2 = function_fieldnum_str, |
| 770 |
}; |
| 771 |
|
| 772 |
static int listfilter(struct ast_channel *chan, const char *cmd, char *parse, char *buf, struct ast_str **bufstr, ssize_t len) |
| 773 |
{ |
| 774 |
AST_DECLARE_APP_ARGS(args, |
| 775 |
AST_APP_ARG(listname); |
| 776 |
AST_APP_ARG(delimiter); |
| 777 |
AST_APP_ARG(fieldvalue); |
| 778 |
); |
| 779 |
struct ast_str *orig_list = ast_str_thread_get(&tmp_buf, 16); |
| 780 |
const char *begin, *cur, *next; |
| 781 |
int dlen, flen, first = 1; |
| 782 |
struct ast_str *result, **result_ptr = &result; |
| 783 |
char *delim, *varsubst; |
| 784 |
|
| 785 |
AST_STANDARD_APP_ARGS(args, parse); |
| 786 |
|
| 787 |
if (buf) { |
| 788 |
if (!(result = ast_str_thread_get(&result_buf, 16))) { |
| 789 |
return -1; |
| 790 |
} |
| 791 |
} else { |
| 792 |
|
| 793 |
result_ptr = bufstr; |
| 794 |
} |
| 795 |
|
| 796 |
if (args.argc < 3) { |
| 797 |
ast_log(LOG_ERROR, "Usage: LISTFILTER(<listname>,<delimiter>,<fieldvalue>)\n"); |
| 798 |
return -1; |
| 799 |
} |
| 800 |
|
| 801 |
varsubst = ast_alloca(strlen(args.listname) + 4); |
| 802 |
sprintf(varsubst, "${%s}", args.listname); |
| 803 |
|
| 804 |
|
| 805 |
if (chan) { |
| 806 |
ast_channel_lock(chan); |
| 807 |
} |
| 808 |
ast_str_substitute_variables(&orig_list, 0, chan, varsubst); |
| 809 |
if (!ast_str_strlen(orig_list)) { |
| 810 |
if (chan) { |
| 811 |
ast_channel_unlock(chan); |
| 812 |
} |
| 813 |
return -1; |
| 814 |
} |
| 815 |
|
| 816 |
|
| 817 |
if (!strstr(ast_str_buffer(orig_list), args.fieldvalue)) { |
| 818 |
if (buf) { |
| 819 |
ast_copy_string(buf, ast_str_buffer(orig_list), len); |
| 820 |
} else { |
| 821 |
ast_str_set(result_ptr, len, "%s", ast_str_buffer(orig_list)); |
| 822 |
} |
| 823 |
if (chan) { |
| 824 |
ast_channel_unlock(chan); |
| 825 |
} |
| 826 |
return 0; |
| 827 |
} |
| 828 |
|
| 829 |
dlen = strlen(args.delimiter); |
| 830 |
delim = ast_alloca(dlen + 1); |
| 831 |
ast_get_encoded_str(args.delimiter, delim, dlen + 1); |
| 832 |
|
| 833 |
if ((dlen = strlen(delim)) == 0) { |
| 834 |
delim = ","; |
| 835 |
dlen = 1; |
| 836 |
} |
| 837 |
|
| 838 |
flen = strlen(args.fieldvalue); |
| 839 |
|
| 840 |
ast_str_reset(*result_ptr); |
| 841 |
|
| 842 |
if (len > -1) { |
| 843 |
ast_str_make_space(result_ptr, len ? len : ast_str_strlen(orig_list) + 1); |
| 844 |
} |
| 845 |
|
| 846 |
begin = ast_str_buffer(orig_list); |
| 847 |
next = strstr(begin, delim); |
| 848 |
|
| 849 |
do { |
| 850 |
|
| 851 |
if (next) { |
| 852 |
cur = next; |
| 853 |
next = strstr(cur + dlen, delim); |
| 854 |
} else { |
| 855 |
cur = strchr(begin + dlen, '\0'); |
| 856 |
} |
| 857 |
|
| 858 |
if (flen == cur - begin && !strncmp(begin, args.fieldvalue, flen)) { |
| 859 |
|
| 860 |
begin += flen + dlen; |
| 861 |
} else { |
| 862 |
|
| 863 |
if (!first) { |
| 864 |
ast_str_append(result_ptr, len, "%s", delim); |
| 865 |
} |
| 866 |
|
| 867 |
ast_str_append_substr(result_ptr, len, begin, cur - begin); |
| 868 |
first = 0; |
| 869 |
begin = cur + dlen; |
| 870 |
} |
| 871 |
} while (*cur != '\0'); |
| 872 |
if (chan) { |
| 873 |
ast_channel_unlock(chan); |
| 874 |
} |
| 875 |
|
| 876 |
if (buf) { |
| 877 |
ast_copy_string(buf, ast_str_buffer(result), len); |
| 878 |
} |
| 879 |
|
| 880 |
return 0; |
| 881 |
} |
| 882 |
|
| 883 |
static int listfilter_read(struct ast_channel *chan, const char *cmd, char *parse, char *buf, size_t len) |
| 884 |
{ |
| 885 |
return listfilter(chan, cmd, parse, buf, NULL, len); |
| 886 |
} |
| 887 |
|
| 888 |
static int listfilter_read2(struct ast_channel *chan, const char *cmd, char *parse, struct ast_str **buf, ssize_t len) |
| 889 |
{ |
| 890 |
return listfilter(chan, cmd, parse, NULL, buf, len); |
| 891 |
} |
| 892 |
|
| 893 |
static struct ast_custom_function listfilter_function = { |
| 894 |
.name = "LISTFILTER", |
| 895 |
.read = listfilter_read, |
| 896 |
.read2 = listfilter_read2, |
| 897 |
}; |
| 898 |
|
| 899 |
static int filter(struct ast_channel *chan, const char *cmd, char *parse, char *buf, |
| 900 |
size_t len) |
| 901 |
{ |
| 902 |
AST_DECLARE_APP_ARGS(args, |
| 903 |
AST_APP_ARG(allowed); |
| 904 |
AST_APP_ARG(string); |
| 905 |
); |
| 906 |
char *outbuf = buf; |
| 907 |
unsigned char ac; |
| 908 |
char allowed[256] = ""; |
| 909 |
size_t allowedlen = 0; |
| 910 |
int32_t bitfield[8] = { 0, }; |
| 911 |
|
| 912 |
AST_STANDARD_RAW_ARGS(args, parse); |
| 913 |
|
| 914 |
if (!args.string) { |
| 915 |
ast_log(LOG_ERROR, "Usage: FILTER(<allowed-chars>,<string>)\n"); |
| 916 |
return -1; |
| 917 |
} |
| 918 |
|
| 919 |
if (args.allowed[0] == '"' && !ast_opt_dont_warn) { |
| 920 |
ast_log(LOG_WARNING, "FILTER allowed characters includes the quote (\") character. This may not be what you want.\n"); |
| 921 |
} |
| 922 |
|
| 923 |
|
| 924 |
for (; *(args.allowed);) { |
| 925 |
char c1 = 0, c2 = 0; |
| 926 |
size_t consumed = 0; |
| 927 |
|
| 928 |
if (ast_get_encoded_char(args.allowed, &c1, &consumed)) |
| 929 |
return -1; |
| 930 |
args.allowed += consumed; |
| 931 |
|
| 932 |
if (*(args.allowed) == '-') { |
| 933 |
if (ast_get_encoded_char(args.allowed + 1, &c2, &consumed)) |
| 934 |
c2 = c1; |
| 935 |
args.allowed += consumed + 1; |
| 936 |
|
| 937 |
if ((unsigned char) c2 < (unsigned char) c1 && !ast_opt_dont_warn) { |
| 938 |
ast_log(LOG_WARNING, "Range wrapping in FILTER(%s,%s). This may not be what you want.\n", parse, args.string); |
| 939 |
} |
| 940 |
|
| 941 |
|
| 942 |
|
| 943 |
|
| 944 |
|
| 945 |
for (ac = (unsigned char) c1; ac != (unsigned char) c2; ac++) { |
| 946 |
bitfield[ac / 32] |= 1 << (ac % 32); |
| 947 |
} |
| 948 |
bitfield[ac / 32] |= 1 << (ac % 32); |
| 949 |
|
| 950 |
ast_debug(4, "c1=%d, c2=%d\n", c1, c2); |
| 951 |
} else { |
| 952 |
ac = (unsigned char) c1; |
| 953 |
ast_debug(4, "c1=%d, consumed=%d, args.allowed=%s\n", c1, (int) consumed, args.allowed - consumed); |
| 954 |
bitfield[ac / 32] |= 1 << (ac % 32); |
| 955 |
} |
| 956 |
} |
| 957 |
|
| 958 |
for (ac = 1; ac != 0; ac++) { |
| 959 |
if (bitfield[ac / 32] & (1 << (ac % 32))) { |
| 960 |
allowed[allowedlen++] = ac; |
| 961 |
} |
| 962 |
} |
| 963 |
|
| 964 |
ast_debug(1, "Allowed: %s\n", allowed); |
| 965 |
|
| 966 |
for (; *(args.string) && (buf + len - 1 > outbuf); (args.string)++) { |
| 967 |
if (strchr(allowed, *(args.string))) |
| 968 |
*outbuf++ = *(args.string); |
| 969 |
} |
| 970 |
*outbuf = '\0'; |
| 971 |
|
| 972 |
return 0; |
| 973 |
} |
| 974 |
|
| 975 |
static struct ast_custom_function filter_function = { |
| 976 |
.name = "FILTER", |
| 977 |
.read = filter, |
| 978 |
}; |
| 979 |
|
| 980 |
static int replace(struct ast_channel *chan, const char *cmd, char *data, struct ast_str **buf, ssize_t len) |
| 981 |
{ |
| 982 |
AST_DECLARE_APP_ARGS(args, |
| 983 |
AST_APP_ARG(varname); |
| 984 |
AST_APP_ARG(find); |
| 985 |
AST_APP_ARG(replace); |
| 986 |
); |
| 987 |
char *strptr, *varsubst; |
| 988 |
RAII_VAR(struct ast_str *, str, ast_str_create(16), ast_free); |
| 989 |
char find[256]; |
| 990 |
char replace[2] = ""; |
| 991 |
size_t unused; |
| 992 |
|
| 993 |
AST_STANDARD_APP_ARGS(args, data); |
| 994 |
|
| 995 |
if (!str) { |
| 996 |
return -1; |
| 997 |
} |
| 998 |
|
| 999 |
if (args.argc < 2) { |
| 1000 |
ast_log(LOG_ERROR, "Usage: %s(<varname>,<search-chars>[,<replace-char>])\n", cmd); |
| 1001 |
return -1; |
| 1002 |
} |
| 1003 |
|
| 1004 |
|
| 1005 |
ast_get_encoded_str(args.find, find, sizeof(find)); |
| 1006 |
ast_get_encoded_char(args.replace, replace, &unused); |
| 1007 |
|
| 1008 |
if (ast_strlen_zero(find) || ast_strlen_zero(args.varname)) { |
| 1009 |
ast_log(LOG_ERROR, "The characters to search for and the variable name must not be empty.\n"); |
| 1010 |
return -1; |
| 1011 |
} |
| 1012 |
|
| 1013 |
varsubst = ast_alloca(strlen(args.varname) + 4); |
| 1014 |
sprintf(varsubst, "${%s}", args.varname); |
| 1015 |
ast_str_substitute_variables(&str, 0, chan, varsubst); |
| 1016 |
|
| 1017 |
if (!ast_str_strlen(str)) { |
| 1018 |
|
| 1019 |
return -1; |
| 1020 |
} |
| 1021 |
|
| 1022 |
ast_debug(3, "String to search: (%s)\n", ast_str_buffer(str)); |
| 1023 |
ast_debug(3, "Characters to find: (%s)\n", find); |
| 1024 |
ast_debug(3, "Character to replace with: (%s)\n", replace); |
| 1025 |
|
| 1026 |
for (strptr = ast_str_buffer(str); *strptr; strptr++) { |
| 1027 |
|
| 1028 |
|
| 1029 |
if (strchr(find, *strptr)) { |
| 1030 |
if (ast_strlen_zero(replace)) { |
| 1031 |
memmove(strptr, strptr + 1, strlen(strptr + 1) + 1); |
| 1032 |
strptr--; |
| 1033 |
} else { |
| 1034 |
|
| 1035 |
*strptr = *replace; |
| 1036 |
} |
| 1037 |
} |
| 1038 |
} |
| 1039 |
|
| 1040 |
ast_str_set(buf, len, "%s", ast_str_buffer(str)); |
| 1041 |
return 0; |
| 1042 |
} |
| 1043 |
|
| 1044 |
static struct ast_custom_function replace_function = { |
| 1045 |
.name = "REPLACE", |
| 1046 |
.read2 = replace, |
| 1047 |
}; |
| 1048 |
|
| 1049 |
static int strreplace(struct ast_channel *chan, const char *cmd, char *data, struct ast_str **buf, ssize_t len) |
| 1050 |
{ |
| 1051 |
char *varsubstr; |
| 1052 |
char *start; |
| 1053 |
char *end; |
| 1054 |
int find_size; |
| 1055 |
unsigned max_matches; |
| 1056 |
unsigned count; |
| 1057 |
struct ast_str *str = ast_str_thread_get(&result_buf, 16); |
| 1058 |
|
| 1059 |
AST_DECLARE_APP_ARGS(args, |
| 1060 |
AST_APP_ARG(varname); |
| 1061 |
AST_APP_ARG(find_string); |
| 1062 |
AST_APP_ARG(replace_string); |
| 1063 |
AST_APP_ARG(max_replacements); |
| 1064 |
AST_APP_ARG(other); |
| 1065 |
); |
| 1066 |
|
| 1067 |
|
| 1068 |
ast_str_reset(*buf); |
| 1069 |
|
| 1070 |
if (!str) { |
| 1071 |
|
| 1072 |
return -1; |
| 1073 |
} |
| 1074 |
|
| 1075 |
|
| 1076 |
AST_STANDARD_APP_ARGS(args, data); |
| 1077 |
|
| 1078 |
if (args.argc < 2) { |
| 1079 |
|
| 1080 |
ast_log(LOG_ERROR, |
| 1081 |
"Usage: %s(<varname>,<find-string>[,<replace-string>,[<max-replacements>]])\n", |
| 1082 |
cmd); |
| 1083 |
return -1; |
| 1084 |
} |
| 1085 |
|
| 1086 |
|
| 1087 |
if (ast_strlen_zero(args.varname)) { |
| 1088 |
return -1; |
| 1089 |
} |
| 1090 |
|
| 1091 |
|
| 1092 |
if (ast_strlen_zero(args.find_string)) { |
| 1093 |
ast_log(LOG_ERROR, "No <find-string> specified\n"); |
| 1094 |
return -1; |
| 1095 |
} |
| 1096 |
find_size = strlen(args.find_string); |
| 1097 |
|
| 1098 |
|
| 1099 |
varsubstr = ast_alloca(strlen(args.varname) + 4); |
| 1100 |
sprintf(varsubstr, "${%s}", args.varname); |
| 1101 |
ast_str_substitute_variables(&str, 0, chan, varsubstr); |
| 1102 |
|
| 1103 |
|
| 1104 |
if (!args.max_replacements |
| 1105 |
|| (max_matches = atoi(args.max_replacements)) <= 0) { |
| 1106 |
|
| 1107 |
max_matches = -1; |
| 1108 |
} |
| 1109 |
|
| 1110 |
|
| 1111 |
start = ast_str_buffer(str); |
| 1112 |
for (count = 0; count < max_matches; ++count) { |
| 1113 |
end = strstr(start, args.find_string); |
| 1114 |
if (!end) { |
| 1115 |
|
| 1116 |
break; |
| 1117 |
} |
| 1118 |
|
| 1119 |
|
| 1120 |
*end = '\0'; |
| 1121 |
ast_str_append(buf, len, "%s", start); |
| 1122 |
if (args.replace_string) { |
| 1123 |
|
| 1124 |
ast_str_append(buf, len, "%s", args.replace_string); |
| 1125 |
} |
| 1126 |
start = end + find_size; |
| 1127 |
} |
| 1128 |
ast_str_append(buf, len, "%s", start); |
| 1129 |
|
| 1130 |
return 0; |
| 1131 |
} |
| 1132 |
|
| 1133 |
static struct ast_custom_function strreplace_function = { |
| 1134 |
.name = "STRREPLACE", |
| 1135 |
.read2 = strreplace, |
| 1136 |
}; |
| 1137 |
|
| 1138 |
static int strbetween(struct ast_channel *chan, const char *cmd, char *data, struct ast_str **buf, ssize_t len) |
| 1139 |
{ |
| 1140 |
int c, origsize; |
| 1141 |
char *varsubstr, *origstr; |
| 1142 |
struct ast_str *str = ast_str_thread_get(&result_buf, 16); |
| 1143 |
|
| 1144 |
AST_DECLARE_APP_ARGS(args, |
| 1145 |
AST_APP_ARG(varname); |
| 1146 |
AST_APP_ARG(insert_string); |
| 1147 |
AST_APP_ARG(other); |
| 1148 |
); |
| 1149 |
|
| 1150 |
ast_str_reset(*buf); |
| 1151 |
|
| 1152 |
if (!str) { |
| 1153 |
ast_log(LOG_ERROR, "Couldn't obtain string\n"); |
| 1154 |
return -1; |
| 1155 |
} |
| 1156 |
|
| 1157 |
AST_STANDARD_APP_ARGS(args, data); |
| 1158 |
|
| 1159 |
if (args.argc != 2 || ast_strlen_zero(args.varname)) { |
| 1160 |
ast_log(LOG_ERROR, "Usage: %s(<varname>,<insert-string>)\n", cmd); |
| 1161 |
return -1; |
| 1162 |
} |
| 1163 |
|
| 1164 |
varsubstr = ast_alloca(strlen(args.varname) + 4); |
| 1165 |
sprintf(varsubstr, "${%s}", args.varname); |
| 1166 |
ast_str_substitute_variables(&str, 0, chan, varsubstr); |
| 1167 |
origstr = ast_str_buffer(str); |
| 1168 |
origsize = strlen(origstr); |
| 1169 |
for (c = 0; c < origsize; c++) { |
| 1170 |
ast_str_append(buf, len, "%c", origstr[c]); |
| 1171 |
|
| 1172 |
if (c < (origsize - 1)) { |
| 1173 |
ast_str_append(buf, len, "%s", args.insert_string); |
| 1174 |
} |
| 1175 |
} |
| 1176 |
|
| 1177 |
return 0; |
| 1178 |
} |
| 1179 |
|
| 1180 |
static struct ast_custom_function strbetween_function = { |
| 1181 |
.name = "STRBETWEEN", |
| 1182 |
.read2 = strbetween, |
| 1183 |
}; |
| 1184 |
|
| 1185 |
#define ltrim(s) while (isspace(*s)) s++; |
| 1186 |
#define rtrim(s) { \ |
| 1187 |
if (s) { \ |
| 1188 |
char *back = s + strlen(s); \ |
| 1189 |
while (back != s && isspace(*--back)); \ |
| 1190 |
if (*s) { \ |
| 1191 |
*(back + 1) = '\0'; \ |
| 1192 |
} \ |
| 1193 |
} \ |
| 1194 |
} |
| 1195 |
|
| 1196 |
static int function_trim(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len) |
| 1197 |
{ |
| 1198 |
char *c; |
| 1199 |
|
| 1200 |
if (ast_strlen_zero(data)) { |
| 1201 |
return -1; |
| 1202 |
} |
| 1203 |
|
| 1204 |
c = ast_strdupa(data); |
| 1205 |
ltrim(c); |
| 1206 |
rtrim(c); |
| 1207 |
|
| 1208 |
ast_copy_string(buf, c, len); |
| 1209 |
|
| 1210 |
return 0; |
| 1211 |
} |
| 1212 |
|
| 1213 |
static int function_ltrim(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len) |
| 1214 |
{ |
| 1215 |
char *c; |
| 1216 |
|
| 1217 |
if (ast_strlen_zero(data)) { |
| 1218 |
return -1; |
| 1219 |
} |
| 1220 |
|
| 1221 |
c = data; |
| 1222 |
ltrim(c); |
| 1223 |
|
| 1224 |
ast_copy_string(buf, c, len); |
| 1225 |
|
| 1226 |
return 0; |
| 1227 |
} |
| 1228 |
|
| 1229 |
static int function_rtrim(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len) |
| 1230 |
{ |
| 1231 |
char *c; |
| 1232 |
|
| 1233 |
if (ast_strlen_zero(data)) { |
| 1234 |
return -1; |
| 1235 |
} |
| 1236 |
|
| 1237 |
c = ast_strdupa(data); |
| 1238 |
rtrim(c); |
| 1239 |
|
| 1240 |
ast_copy_string(buf, c, len); |
| 1241 |
|
| 1242 |
return 0; |
| 1243 |
} |
| 1244 |
|
| 1245 |
#undef ltrim |
| 1246 |
#undef rtrim |
| 1247 |
|
| 1248 |
static struct ast_custom_function trim_function = { |
| 1249 |
.name = "TRIM", |
| 1250 |
.read = function_trim, |
| 1251 |
}; |
| 1252 |
|
| 1253 |
static struct ast_custom_function ltrim_function = { |
| 1254 |
.name = "LTRIM", |
| 1255 |
.read = function_ltrim, |
| 1256 |
}; |
| 1257 |
|
| 1258 |
static struct ast_custom_function rtrim_function = { |
| 1259 |
.name = "RTRIM", |
| 1260 |
.read = function_rtrim, |
| 1261 |
}; |
| 1262 |
|
| 1263 |
static int regex(struct ast_channel *chan, const char *cmd, char *parse, char *buf, |
| 1264 |
size_t len) |
| 1265 |
{ |
| 1266 |
AST_DECLARE_APP_ARGS(args, |
| 1267 |
AST_APP_ARG(null); |
| 1268 |
AST_APP_ARG(reg); |
| 1269 |
AST_APP_ARG(str); |
| 1270 |
); |
| 1271 |
int errcode; |
| 1272 |
regex_t regexbuf; |
| 1273 |
|
| 1274 |
buf[0] = '\0'; |
| 1275 |
|
| 1276 |
AST_NONSTANDARD_APP_ARGS(args, parse, '"'); |
| 1277 |
|
| 1278 |
if (args.argc != 3) { |
| 1279 |
ast_log(LOG_ERROR, "Unexpected arguments: should have been in the form '\"<regex>\" <string>'\n"); |
| 1280 |
return -1; |
| 1281 |
} |
| 1282 |
if ((*args.str == ' ') || (*args.str == '\t')) |
| 1283 |
args.str++; |
| 1284 |
|
| 1285 |
ast_debug(1, "FUNCTION REGEX (%s)(%s)\n", args.reg, args.str); |
| 1286 |
|
| 1287 |
if ((errcode = regcomp(®exbuf, args.reg, REG_EXTENDED | REG_NOSUB))) { |
| 1288 |
regerror(errcode, ®exbuf, buf, len); |
| 1289 |
ast_log(LOG_WARNING, "Malformed input %s(%s): %s\n", cmd, parse, buf); |
| 1290 |
return -1; |
| 1291 |
} |
| 1292 |
|
| 1293 |
strcpy(buf, regexec(®exbuf, args.str, 0, NULL, 0) ? "0" : "1"); |
| 1294 |
|
| 1295 |
regfree(®exbuf); |
| 1296 |
|
| 1297 |
return 0; |
| 1298 |
} |
| 1299 |
|
| 1300 |
static struct ast_custom_function regex_function = { |
| 1301 |
.name = "REGEX", |
| 1302 |
.read = regex, |
| 1303 |
}; |
| 1304 |
|
| 1305 |
#define HASH_PREFIX "~HASH~%s~" |
| 1306 |
#define HASH_FORMAT HASH_PREFIX "%s~" |
| 1307 |
|
| 1308 |
static char *app_clearhash = "ClearHash"; |
| 1309 |
|
| 1310 |
|
| 1311 |
static void clearvar_prefix(struct ast_channel *chan, const char *prefix) |
| 1312 |
{ |
| 1313 |
struct ast_var_t *var; |
| 1314 |
int len = strlen(prefix); |
| 1315 |
AST_LIST_TRAVERSE_SAFE_BEGIN(ast_channel_varshead(chan), var, entries) { |
| 1316 |
if (strncmp(prefix, ast_var_name(var), len) == 0) { |
| 1317 |
AST_LIST_REMOVE_CURRENT(entries); |
| 1318 |
ast_free(var); |
| 1319 |
} |
| 1320 |
} |
| 1321 |
AST_LIST_TRAVERSE_SAFE_END |
| 1322 |
} |
| 1323 |
|
| 1324 |
static int exec_clearhash(struct ast_channel *chan, const char *data) |
| 1325 |
{ |
| 1326 |
char prefix[80]; |
| 1327 |
snprintf(prefix, sizeof(prefix), HASH_PREFIX, data ? (char *)data : "null"); |
| 1328 |
clearvar_prefix(chan, prefix); |
| 1329 |
return 0; |
| 1330 |
} |
| 1331 |
|
| 1332 |
static int array(struct ast_channel *chan, const char *cmd, char *var, |
| 1333 |
const char *value) |
| 1334 |
{ |
| 1335 |
AST_DECLARE_APP_ARGS(arg1, |
| 1336 |
AST_APP_ARG(var)[100]; |
| 1337 |
); |
| 1338 |
AST_DECLARE_APP_ARGS(arg2, |
| 1339 |
AST_APP_ARG(val)[100]; |
| 1340 |
); |
| 1341 |
char *origvar = "", *value2, varname[256]; |
| 1342 |
int i, ishash = 0; |
| 1343 |
|
| 1344 |
if (!var) { |
| 1345 |
return -1; |
| 1346 |
} |
| 1347 |
value2 = ast_strdupa(value); |
| 1348 |
|
| 1349 |
if (!strcmp(cmd, "HASH")) { |
| 1350 |
const char *var2 = pbx_builtin_getvar_helper(chan, "~ODBCFIELDS~"); |
| 1351 |
origvar = var; |
| 1352 |
if (var2) |
| 1353 |
var = ast_strdupa(var2); |
| 1354 |
else { |
| 1355 |
if (chan) |
| 1356 |
ast_autoservice_stop(chan); |
| 1357 |
return -1; |
| 1358 |
} |
| 1359 |
ishash = 1; |
| 1360 |
} |
| 1361 |
|
| 1362 |
|
| 1363 |
|
| 1364 |
|
| 1365 |
|
| 1366 |
|
| 1367 |
|
| 1368 |
ast_debug(1, "array (%s=%s)\n", var, S_OR(value2, "")); |
| 1369 |
AST_STANDARD_APP_ARGS(arg1, var); |
| 1370 |
|
| 1371 |
AST_STANDARD_APP_ARGS(arg2, value2); |
| 1372 |
|
| 1373 |
for (i = 0; i < arg1.argc; i++) { |
| 1374 |
ast_debug(1, "array set value (%s=%s)\n", arg1.var[i], |
| 1375 |
S_OR(arg2.val[i], "")); |
| 1376 |
if (i < arg2.argc) { |
| 1377 |
if (ishash) { |
| 1378 |
if (origvar[0] == '_') { |
| 1379 |
if (origvar[1] == '_') { |
| 1380 |
snprintf(varname, sizeof(varname), "__" HASH_FORMAT, origvar + 2, arg1.var[i]); |
| 1381 |
} else { |
| 1382 |
snprintf(varname, sizeof(varname), "_" HASH_FORMAT, origvar + 1, arg1.var[i]); |
| 1383 |
} |
| 1384 |
} else { |
| 1385 |
snprintf(varname, sizeof(varname), HASH_FORMAT, origvar, arg1.var[i]); |
| 1386 |
} |
| 1387 |
|
| 1388 |
pbx_builtin_setvar_helper(chan, varname, arg2.val[i]); |
| 1389 |
} else { |
| 1390 |
pbx_builtin_setvar_helper(chan, arg1.var[i], arg2.val[i]); |
| 1391 |
} |
| 1392 |
} else { |
| 1393 |
|
| 1394 |
|
| 1395 |
if (ishash) { |
| 1396 |
snprintf(varname, sizeof(varname), HASH_FORMAT, origvar, arg1.var[i]); |
| 1397 |
pbx_builtin_setvar_helper(chan, varname, ""); |
| 1398 |
} else { |
| 1399 |
pbx_builtin_setvar_helper(chan, arg1.var[i], ""); |
| 1400 |
} |
| 1401 |
} |
| 1402 |
} |
| 1403 |
|
| 1404 |
return 0; |
| 1405 |
} |
| 1406 |
|
| 1407 |
static const char *get_key(const struct ast_str *prefix, const struct ast_var_t *var) |
| 1408 |
{ |
| 1409 |
const char *prefix_name = ast_str_buffer(prefix); |
| 1410 |
const char *var_name = ast_var_name(var); |
| 1411 |
int prefix_len; |
| 1412 |
int var_len; |
| 1413 |
|
| 1414 |
if (ast_strlen_zero(var_name)) { |
| 1415 |
return NULL; |
| 1416 |
} |
| 1417 |
|
| 1418 |
prefix_len = ast_str_strlen(prefix); |
| 1419 |
var_len = strlen(var_name); |
| 1420 |
|
| 1421 |
|
| 1422 |
|
| 1423 |
|
| 1424 |
|
| 1425 |
return var_len > (prefix_len + 1) && var_name[var_len - 1] == '~' && |
| 1426 |
strncmp(prefix_name, var_name, prefix_len) == 0 ? var_name + prefix_len : NULL; |
| 1427 |
} |
| 1428 |
|
| 1429 |
static int hashkeys_read(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len) |
| 1430 |
{ |
| 1431 |
struct ast_var_t *newvar; |
| 1432 |
struct ast_str *prefix = ast_str_alloca(80); |
| 1433 |
size_t buf_len; |
| 1434 |
|
| 1435 |
if (!chan) { |
| 1436 |
ast_log(LOG_WARNING, "No channel was provided to %s function.\n", cmd); |
| 1437 |
return -1; |
| 1438 |
} |
| 1439 |
|
| 1440 |
ast_str_set(&prefix, -1, HASH_PREFIX, data); |
| 1441 |
memset(buf, 0, len); |
| 1442 |
|
| 1443 |
AST_LIST_TRAVERSE(ast_channel_varshead(chan), newvar, entries) { |
| 1444 |
const char *key = get_key(prefix, newvar); |
| 1445 |
|
| 1446 |
if (key) { |
| 1447 |
strncat(buf, key, len - strlen(buf) - 1); |
| 1448 |
|
| 1449 |
buf[strlen(buf) - 1] = ','; |
| 1450 |
} |
| 1451 |
} |
| 1452 |
|
| 1453 |
buf_len = strlen(buf); |
| 1454 |
if (buf_len) { |
| 1455 |
buf[buf_len - 1] = '\0'; |
| 1456 |
} |
| 1457 |
return 0; |
| 1458 |
} |
| 1459 |
|
| 1460 |
static int hashkeys_read2(struct ast_channel *chan, const char *cmd, char *data, struct ast_str **buf, ssize_t len) |
| 1461 |
{ |
| 1462 |
struct ast_var_t *newvar; |
| 1463 |
struct ast_str *prefix = ast_str_alloca(80); |
| 1464 |
|
| 1465 |
if (!chan) { |
| 1466 |
ast_log(LOG_WARNING, "No channel was provided to %s function.\n", cmd); |
| 1467 |
return -1; |
| 1468 |
} |
| 1469 |
|
| 1470 |
ast_str_set(&prefix, -1, HASH_PREFIX, data); |
| 1471 |
|
| 1472 |
AST_LIST_TRAVERSE(ast_channel_varshead(chan), newvar, entries) { |
| 1473 |
const char *key = get_key(prefix, newvar); |
| 1474 |
|
| 1475 |
if (key) { |
| 1476 |
char *tmp; |
| 1477 |
|
| 1478 |
ast_str_append(buf, len, "%s", key); |
| 1479 |
|
| 1480 |
tmp = ast_str_buffer(*buf); |
| 1481 |
tmp[ast_str_strlen(*buf) - 1] = ','; |
| 1482 |
} |
| 1483 |
} |
| 1484 |
|
| 1485 |
ast_str_truncate(*buf, -1); |
| 1486 |
return 0; |
| 1487 |
} |
| 1488 |
|
| 1489 |
static int hash_write(struct ast_channel *chan, const char *cmd, char *var, const char *value) |
| 1490 |
{ |
| 1491 |
char varname[256]; |
| 1492 |
AST_DECLARE_APP_ARGS(arg, |
| 1493 |
AST_APP_ARG(hashname); |
| 1494 |
AST_APP_ARG(hashkey); |
| 1495 |
); |
| 1496 |
|
| 1497 |
if (!strchr(var, ',')) { |
| 1498 |
|
| 1499 |
return array(chan, "HASH", var, value); |
| 1500 |
} |
| 1501 |
|
| 1502 |
AST_STANDARD_APP_ARGS(arg, var); |
| 1503 |
if (arg.hashname[0] == '_') { |
| 1504 |
if (arg.hashname[1] == '_') { |
| 1505 |
snprintf(varname, sizeof(varname), "__" HASH_FORMAT, arg.hashname + 2, arg.hashkey); |
| 1506 |
} else { |
| 1507 |
snprintf(varname, sizeof(varname), "_" HASH_FORMAT, arg.hashname + 1, arg.hashkey); |
| 1508 |
} |
| 1509 |
} else { |
| 1510 |
snprintf(varname, sizeof(varname), HASH_FORMAT, arg.hashname, arg.hashkey); |
| 1511 |
} |
| 1512 |
pbx_builtin_setvar_helper(chan, varname, value); |
| 1513 |
|
| 1514 |
return 0; |
| 1515 |
} |
| 1516 |
|
| 1517 |
static int hash_read(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len) |
| 1518 |
{ |
| 1519 |
char varname[256]; |
| 1520 |
const char *varvalue; |
| 1521 |
AST_DECLARE_APP_ARGS(arg, |
| 1522 |
AST_APP_ARG(hashname); |
| 1523 |
AST_APP_ARG(hashkey); |
| 1524 |
); |
| 1525 |
|
| 1526 |
AST_STANDARD_APP_ARGS(arg, data); |
| 1527 |
if (arg.argc == 2) { |
| 1528 |
snprintf(varname, sizeof(varname), HASH_FORMAT, arg.hashname, arg.hashkey); |
| 1529 |
varvalue = pbx_builtin_getvar_helper(chan, varname); |
| 1530 |
if (varvalue) |
| 1531 |
ast_copy_string(buf, varvalue, len); |
| 1532 |
else |
| 1533 |
*buf = '\0'; |
| 1534 |
} else if (arg.argc == 1) { |
| 1535 |
char colnames[4096]; |
| 1536 |
int i; |
| 1537 |
AST_DECLARE_APP_ARGS(arg2, |
| 1538 |
AST_APP_ARG(col)[100]; |
| 1539 |
); |
| 1540 |
|
| 1541 |
if (!chan) { |
| 1542 |
ast_log(LOG_WARNING, "No channel and only 1 parameter was provided to %s function.\n", cmd); |
| 1543 |
return -1; |
| 1544 |
} |
| 1545 |
|
| 1546 |
|
| 1547 |
hashkeys_read(chan, "HASHKEYS", arg.hashname, colnames, sizeof(colnames)); |
| 1548 |
pbx_builtin_setvar_helper(chan, "~ODBCFIELDS~", colnames); |
| 1549 |
|
| 1550 |
AST_STANDARD_APP_ARGS(arg2, colnames); |
| 1551 |
*buf = '\0'; |
| 1552 |
|
| 1553 |
|
| 1554 |
for (i = 0; i < arg2.argc; i++) { |
| 1555 |
snprintf(varname, sizeof(varname), HASH_FORMAT, arg.hashname, arg2.col[i]); |
| 1556 |
varvalue = pbx_builtin_getvar_helper(chan, varname); |
| 1557 |
|
| 1558 |
|
| 1559 |
|
| 1560 |
|
| 1561 |
|
| 1562 |
if (!varvalue) { |
| 1563 |
ast_log(LOG_WARNING, "No value found for '%s'\n", varname); |
| 1564 |
*buf = '\0'; |
| 1565 |
return -1; |
| 1566 |
} |
| 1567 |
strncat(buf, varvalue, len - strlen(buf) - 1); |
| 1568 |
strncat(buf, ",", len - strlen(buf) - 1); |
| 1569 |
} |
| 1570 |
|
| 1571 |
|
| 1572 |
buf[strlen(buf) - 1] = '\0'; |
| 1573 |
} |
| 1574 |
|
| 1575 |
return 0; |
| 1576 |
} |
| 1577 |
|
| 1578 |
static struct ast_custom_function hash_function = { |
| 1579 |
.name = "HASH", |
| 1580 |
.write = hash_write, |
| 1581 |
.read = hash_read, |
| 1582 |
}; |
| 1583 |
|
| 1584 |
static struct ast_custom_function hashkeys_function = { |
| 1585 |
.name = "HASHKEYS", |
| 1586 |
.read = hashkeys_read, |
| 1587 |
.read2 = hashkeys_read2, |
| 1588 |
}; |
| 1589 |
|
| 1590 |
static struct ast_custom_function array_function = { |
| 1591 |
.name = "ARRAY", |
| 1592 |
.write = array, |
| 1593 |
}; |
| 1594 |
|
| 1595 |
static int quote(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len) |
| 1596 |
{ |
| 1597 |
char *bufptr = buf, *dataptr = data; |
| 1598 |
|
| 1599 |
if (len < 3){ |
| 1600 |
ast_log(LOG_ERROR, "Not enough buffer\n"); |
| 1601 |
return -1; |
| 1602 |
} |
| 1603 |
|
| 1604 |
if (ast_strlen_zero(data)) { |
| 1605 |
ast_log(LOG_WARNING, "No argument specified!\n"); |
| 1606 |
ast_copy_string(buf, "\"\"", len); |
| 1607 |
return 0; |
| 1608 |
} |
| 1609 |
|
| 1610 |
*bufptr++ = '"'; |
| 1611 |
for (; bufptr < buf + len - 3; dataptr++) { |
| 1612 |
if (*dataptr == '\\') { |
| 1613 |
*bufptr++ = '\\'; |
| 1614 |
*bufptr++ = '\\'; |
| 1615 |
} else if (*dataptr == '"') { |
| 1616 |
*bufptr++ = '\\'; |
| 1617 |
*bufptr++ = '"'; |
| 1618 |
} else if (*dataptr == '\0') { |
| 1619 |
break; |
| 1620 |
} else { |
| 1621 |
*bufptr++ = *dataptr; |
| 1622 |
} |
| 1623 |
} |
| 1624 |
*bufptr++ = '"'; |
| 1625 |
*bufptr = '\0'; |
| 1626 |
return 0; |
| 1627 |
} |
| 1628 |
|
| 1629 |
static struct ast_custom_function quote_function = { |
| 1630 |
.name = "QUOTE", |
| 1631 |
.read = quote, |
| 1632 |
}; |
| 1633 |
|
| 1634 |
static int csv_quote(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len) |
| 1635 |
{ |
| 1636 |
char *bufptr = buf, *dataptr = data; |
| 1637 |
|
| 1638 |
if (len < 3) { |
| 1639 |
ast_log(LOG_ERROR, "Not enough buffer\n"); |
| 1640 |
return -1; |
| 1641 |
} |
| 1642 |
|
| 1643 |
if (ast_strlen_zero(data)) { |
| 1644 |
ast_copy_string(buf, "\"\"", len); |
| 1645 |
return 0; |
| 1646 |
} |
| 1647 |
|
| 1648 |
*bufptr++ = '"'; |
| 1649 |
for (; bufptr < buf + len - 3; dataptr++){ |
| 1650 |
if (*dataptr == '"') { |
| 1651 |
*bufptr++ = '"'; |
| 1652 |
*bufptr++ = '"'; |
| 1653 |
} else if (*dataptr == '\0') { |
| 1654 |
break; |
| 1655 |
} else { |
| 1656 |
*bufptr++ = *dataptr; |
| 1657 |
} |
| 1658 |
} |
| 1659 |
*bufptr++ = '"'; |
| 1660 |
*bufptr='\0'; |
| 1661 |
return 0; |
| 1662 |
} |
| 1663 |
|
| 1664 |
static struct ast_custom_function csv_quote_function = { |
| 1665 |
.name = "CSV_QUOTE", |
| 1666 |
.read = csv_quote, |
| 1667 |
}; |
| 1668 |
|
| 1669 |
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen) |
| 1670 |
{ |
| 1671 |
int length = 0; |
| 1672 |
|
| 1673 |
if (data) |
| 1674 |
length = strlen(data); |
| 1675 |
|
| 1676 |
snprintf(buf, buflen, "%d", length); |
| 1677 |
|
| 1678 |
return 0; |
| 1679 |
} |
| 1680 |
|
| 1681 |
static struct ast_custom_function len_function = { |
| 1682 |
.name = "LEN", |
| 1683 |
.read = len, |
| 1684 |
.read_max = 12, |
| 1685 |
}; |
| 1686 |
|
| 1687 |
static int acf_strftime(struct ast_channel *chan, const char *cmd, char *parse, |
| 1688 |
char *buf, size_t buflen) |
| 1689 |
{ |
| 1690 |
AST_DECLARE_APP_ARGS(args, |
| 1691 |
AST_APP_ARG(epoch); |
| 1692 |
AST_APP_ARG(timezone); |
| 1693 |
AST_APP_ARG(format); |
| 1694 |
); |
| 1695 |
struct timeval when; |
| 1696 |
struct ast_tm tm; |
| 1697 |
|
| 1698 |
buf[0] = '\0'; |
| 1699 |
|
| 1700 |
AST_STANDARD_APP_ARGS(args, parse); |
| 1701 |
|
| 1702 |
ast_get_timeval(args.epoch, &when, ast_tvnow(), NULL); |
| 1703 |
ast_localtime(&when, &tm, args.timezone); |
| 1704 |
|
| 1705 |
if (!args.format) |
| 1706 |
args.format = "%c"; |
| 1707 |
|
| 1708 |
if (ast_strftime(buf, buflen, args.format, &tm) <= 0) |
| 1709 |
ast_log(LOG_WARNING, "C function strftime() output nothing?!!\n"); |
| 1710 |
|
| 1711 |
buf[buflen - 1] = '\0'; |
| 1712 |
|
| 1713 |
return 0; |
| 1714 |
} |
| 1715 |
|
| 1716 |
static struct ast_custom_function strftime_function = { |
| 1717 |
.name = "STRFTIME", |
| 1718 |
.read = acf_strftime, |
| 1719 |
}; |
| 1720 |
|
| 1721 |
static int acf_strptime(struct ast_channel *chan, const char *cmd, char *data, |
| 1722 |
char *buf, size_t buflen) |
| 1723 |
{ |
| 1724 |
AST_DECLARE_APP_ARGS(args, |
| 1725 |
AST_APP_ARG(timestring); |
| 1726 |
AST_APP_ARG(timezone); |
| 1727 |
AST_APP_ARG(format); |
| 1728 |
); |
| 1729 |
struct ast_tm tm; |
| 1730 |
|
| 1731 |
buf[0] = '\0'; |
| 1732 |
|
| 1733 |
if (!data) { |
| 1734 |
ast_log(LOG_ERROR, |
| 1735 |
"Asterisk function STRPTIME() requires an argument.\n"); |
| 1736 |
return -1; |
| 1737 |
} |
| 1738 |
|
| 1739 |
AST_STANDARD_APP_ARGS(args, data); |
| 1740 |
|
| 1741 |
if (ast_strlen_zero(args.format)) { |
| 1742 |
ast_log(LOG_ERROR, |
| 1743 |
"No format supplied to STRPTIME(<timestring>,<timezone>,<format>)"); |
| 1744 |
return -1; |
| 1745 |
} |
| 1746 |
|
| 1747 |
if (!ast_strptime(args.timestring, args.format, &tm)) { |
| 1748 |
ast_log(LOG_WARNING, "STRPTIME() found no time specified within the string\n"); |
| 1749 |
} else { |
| 1750 |
struct timeval when; |
| 1751 |
when = ast_mktime(&tm, args.timezone); |
| 1752 |
snprintf(buf, buflen, "%d", (int) when.tv_sec); |
| 1753 |
} |
| 1754 |
|
| 1755 |
return 0; |
| 1756 |
} |
| 1757 |
|
| 1758 |
static struct ast_custom_function strptime_function = { |
| 1759 |
.name = "STRPTIME", |
| 1760 |
.read = acf_strptime, |
| 1761 |
}; |
| 1762 |
|
| 1763 |
static int function_eval(struct ast_channel *chan, const char *cmd, char *data, |
| 1764 |
char *buf, size_t buflen) |
| 1765 |
{ |
| 1766 |
if (ast_strlen_zero(data)) { |
| 1767 |
ast_log(LOG_WARNING, "EVAL requires an argument: EVAL(<string>)\n"); |
| 1768 |
return -1; |
| 1769 |
} |
| 1770 |
|
| 1771 |
pbx_substitute_variables_helper(chan, data, buf, buflen - 1); |
| 1772 |
|
| 1773 |
return 0; |
| 1774 |
} |
| 1775 |
|
| 1776 |
static int function_eval2(struct ast_channel *chan, const char *cmd, char *data, |
| 1777 |
struct ast_str **buf, ssize_t buflen) |
| 1778 |
{ |
| 1779 |
if (ast_strlen_zero(data)) { |
| 1780 |
ast_log(LOG_WARNING, "EVAL requires an argument: EVAL(<string>)\n"); |
| 1781 |
return -1; |
| 1782 |
} |
| 1783 |
|
| 1784 |
ast_str_substitute_variables(buf, buflen, chan, data); |
| 1785 |
|
| 1786 |
return 0; |
| 1787 |
} |
| 1788 |
|
| 1789 |
static struct ast_custom_function eval_function = { |
| 1790 |
.name = "EVAL", |
| 1791 |
.read = function_eval, |
| 1792 |
.read2 = function_eval2, |
| 1793 |
}; |
| 1794 |
|
| 1795 |
static int keypadhash(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen) |
| 1796 |
{ |
| 1797 |
char *bufptr, *dataptr; |
| 1798 |
|
| 1799 |
for (bufptr = buf, dataptr = data; bufptr < buf + buflen - 1; dataptr++) { |
| 1800 |
if (*dataptr == '\0') { |
| 1801 |
*bufptr++ = '\0'; |
| 1802 |
break; |
| 1803 |
} else if (*dataptr == '1') { |
| 1804 |
*bufptr++ = '1'; |
| 1805 |
} else if (strchr("AaBbCc2", *dataptr)) { |
| 1806 |
*bufptr++ = '2'; |
| 1807 |
} else if (strchr("DdEeFf3", *dataptr)) { |
| 1808 |
*bufptr++ = '3'; |
| 1809 |
} else if (strchr("GgHhIi4", *dataptr)) { |
| 1810 |
*bufptr++ = '4'; |
| 1811 |
} else if (strchr("JjKkLl5", *dataptr)) { |
| 1812 |
*bufptr++ = '5'; |
| 1813 |
} else if (strchr("MmNnOo6", *dataptr)) { |
| 1814 |
*bufptr++ = '6'; |
| 1815 |
} else if (strchr("PpQqRrSs7", *dataptr)) { |
| 1816 |
*bufptr++ = '7'; |
| 1817 |
} else if (strchr("TtUuVv8", *dataptr)) { |
| 1818 |
*bufptr++ = '8'; |
| 1819 |
} else if (strchr("WwXxYyZz9", *dataptr)) { |
| 1820 |
*bufptr++ = '9'; |
| 1821 |
} else if (*dataptr == '0') { |
| 1822 |
*bufptr++ = '0'; |
| 1823 |
} |
| 1824 |
} |
| 1825 |
buf[buflen - 1] = '\0'; |
| 1826 |
|
| 1827 |
return 0; |
| 1828 |
} |
| 1829 |
|
| 1830 |
static struct ast_custom_function keypadhash_function = { |
| 1831 |
.name = "KEYPADHASH", |
| 1832 |
.read = keypadhash, |
| 1833 |
}; |
| 1834 |
|
| 1835 |
static int string_toupper(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen) |
| 1836 |
{ |
| 1837 |
char *bufptr = buf, *dataptr = data; |
| 1838 |
|
| 1839 |
while ((bufptr < buf + buflen - 1) && (*bufptr++ = toupper(*dataptr++))); |
| 1840 |
|
| 1841 |
return 0; |
| 1842 |
} |
| 1843 |
|
| 1844 |
static int string_toupper2(struct ast_channel *chan, const char *cmd, char *data, struct ast_str **buf, ssize_t buflen) |
| 1845 |
{ |
| 1846 |
char *bufptr, *dataptr = data; |
| 1847 |
|
| 1848 |
if (buflen > -1) { |
| 1849 |
ast_str_make_space(buf, buflen > 0 ? buflen : strlen(data) + 1); |
| 1850 |
} |
| 1851 |
bufptr = ast_str_buffer(*buf); |
| 1852 |
while ((bufptr < ast_str_buffer(*buf) + ast_str_size(*buf) - 1) && (*bufptr++ = toupper(*dataptr++))); |
| 1853 |
ast_str_update(*buf); |
| 1854 |
|
| 1855 |
return 0; |
| 1856 |
} |
| 1857 |
|
| 1858 |
static struct ast_custom_function toupper_function = { |
| 1859 |
.name = "TOUPPER", |
| 1860 |
.read = string_toupper, |
| 1861 |
.read2 = string_toupper2, |
| 1862 |
}; |
| 1863 |
|
| 1864 |
static int string_tolower(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen) |
| 1865 |
{ |
| 1866 |
char *bufptr = buf, *dataptr = data; |
| 1867 |
|
| 1868 |
while ((bufptr < buf + buflen - 1) && (*bufptr++ = tolower(*dataptr++))); |
| 1869 |
|
| 1870 |
return 0; |
| 1871 |
} |
| 1872 |
|
| 1873 |
static int string_tolower2(struct ast_channel *chan, const char *cmd, char *data, struct ast_str **buf, ssize_t buflen) |
| 1874 |
{ |
| 1875 |
char *bufptr, *dataptr = data; |
| 1876 |
|
| 1877 |
if (buflen > -1) { |
| 1878 |
ast_str_make_space(buf, buflen > 0 ? buflen : strlen(data) + 1); |
| 1879 |
} |
| 1880 |
bufptr = ast_str_buffer(*buf); |
| 1881 |
while ((bufptr < ast_str_buffer(*buf) + ast_str_size(*buf) - 1) && (*bufptr++ = tolower(*dataptr++))); |
| 1882 |
ast_str_update(*buf); |
| 1883 |
|
| 1884 |
return 0; |
| 1885 |
} |
| 1886 |
|
| 1887 |
static struct ast_custom_function tolower_function = { |
| 1888 |
.name = "TOLOWER", |
| 1889 |
.read = string_tolower, |
| 1890 |
.read2 = string_tolower2, |
| 1891 |
}; |
| 1892 |
|
| 1893 |
static int shift_pop(struct ast_channel *chan, const char *cmd, char *data, struct ast_str **buf, ssize_t len) |
| 1894 |
{ |
| 1895 |
#define beginning (cmd[0] == 'S') |
| 1896 |
char *after, delimiter[2] = ",", *varsubst; |
| 1897 |
size_t unused; |
| 1898 |
struct ast_str *before = ast_str_thread_get(&result_buf, 16); |
| 1899 |
char *(*search_func)(const char *s, int c) = (beginning ? strchr : strrchr); |
| 1900 |
AST_DECLARE_APP_ARGS(args, |
| 1901 |
AST_APP_ARG(var); |
| 1902 |
AST_APP_ARG(delimiter); |
| 1903 |
); |
| 1904 |
|
| 1905 |
if (!before) { |
| 1906 |
return -1; |
| 1907 |
} |
| 1908 |
|
| 1909 |
AST_STANDARD_APP_ARGS(args, data); |
| 1910 |
|
| 1911 |
if (ast_strlen_zero(args.var)) { |
| 1912 |
ast_log(LOG_WARNING, "%s requires a variable name\n", cmd); |
| 1913 |
return -1; |
| 1914 |
} |
| 1915 |
|
| 1916 |
varsubst = ast_alloca(strlen(args.var) + 4); |
| 1917 |
sprintf(varsubst, "${%s}", args.var); |
| 1918 |
ast_str_substitute_variables(&before, 0, chan, varsubst); |
| 1919 |
|
| 1920 |
if (args.argc > 1 && !ast_strlen_zero(args.delimiter)) { |
| 1921 |
ast_get_encoded_char(args.delimiter, delimiter, &unused); |
| 1922 |
} |
| 1923 |
|
| 1924 |
if (!ast_str_strlen(before)) { |
| 1925 |
|
| 1926 |
return -1; |
| 1927 |
} |
| 1928 |
|
| 1929 |
if (!(after = search_func(ast_str_buffer(before), delimiter[0]))) { |
| 1930 |
|
| 1931 |
ast_str_set(buf, len, "%s", ast_str_buffer(before)); |
| 1932 |
pbx_builtin_setvar_helper(chan, args.var, ""); |
| 1933 |
} else { |
| 1934 |
*after++ = '\0'; |
| 1935 |
ast_str_set(buf, len, "%s", beginning ? ast_str_buffer(before) : after); |
| 1936 |
pbx_builtin_setvar_helper(chan, args.var, beginning ? after : ast_str_buffer(before)); |
| 1937 |
} |
| 1938 |
|
| 1939 |
return 0; |
| 1940 |
#undef beginning |
| 1941 |
} |
| 1942 |
|
| 1943 |
static struct ast_custom_function shift_function = { |
| 1944 |
.name = "SHIFT", |
| 1945 |
.read2 = shift_pop, |
| 1946 |
}; |
| 1947 |
|
| 1948 |
static struct ast_custom_function pop_function = { |
| 1949 |
.name = "POP", |
| 1950 |
.read2 = shift_pop, |
| 1951 |
}; |
| 1952 |
|
| 1953 |
static int unshift_push(struct ast_channel *chan, const char *cmd, char *data, const char *new_value) |
| 1954 |
{ |
| 1955 |
#define beginning (cmd[0] == 'U') |
| 1956 |
char delimiter[2] = ",", *varsubst; |
| 1957 |
size_t unused; |
| 1958 |
struct ast_str *buf, *previous_value; |
| 1959 |
AST_DECLARE_APP_ARGS(args, |
| 1960 |
AST_APP_ARG(var); |
| 1961 |
AST_APP_ARG(delimiter); |
| 1962 |
); |
| 1963 |
const char *stripped_var; |
| 1964 |
|
| 1965 |
if (!(buf = ast_str_thread_get(&result_buf, 16)) || |
| 1966 |
!(previous_value = ast_str_thread_get(&tmp_buf, 16))) { |
| 1967 |
return -1; |
| 1968 |
} |
| 1969 |
|
| 1970 |
AST_STANDARD_APP_ARGS(args, data); |
| 1971 |
|
| 1972 |
if (ast_strlen_zero(args.var)) { |
| 1973 |
ast_log(LOG_WARNING, "%s requires a variable name\n", cmd); |
| 1974 |
return -1; |
| 1975 |
} |
| 1976 |
|
| 1977 |
if (args.argc > 1 && !ast_strlen_zero(args.delimiter)) { |
| 1978 |
ast_get_encoded_char(args.delimiter, delimiter, &unused); |
| 1979 |
} |
| 1980 |
|
| 1981 |
|
| 1982 |
|
| 1983 |
|
| 1984 |
|
| 1985 |
|
| 1986 |
|
| 1987 |
stripped_var = args.var + MIN(strspn(args.var, "_"), 2); |
| 1988 |
varsubst = ast_alloca(strlen(stripped_var) + 4); |
| 1989 |
sprintf(varsubst, "${%s}", stripped_var); |
| 1990 |
ast_str_substitute_variables(&previous_value, 0, chan, varsubst); |
| 1991 |
|
| 1992 |
if (!ast_str_strlen(previous_value)) { |
| 1993 |
ast_str_set(&buf, 0, "%s", new_value); |
| 1994 |
} else { |
| 1995 |
ast_str_set(&buf, 0, "%s%c%s", |
| 1996 |
beginning ? new_value : ast_str_buffer(previous_value), |
| 1997 |
delimiter[0], |
| 1998 |
beginning ? ast_str_buffer(previous_value) : new_value); |
| 1999 |
} |
| 2000 |
|
| 2001 |
pbx_builtin_setvar_helper(chan, args.var, ast_str_buffer(buf)); |
| 2002 |
|
| 2003 |
return 0; |
| 2004 |
#undef beginning |
| 2005 |
} |
| 2006 |
|
| 2007 |
static struct ast_custom_function push_function = { |
| 2008 |
.name = "PUSH", |
| 2009 |
.write = unshift_push, |
| 2010 |
}; |
| 2011 |
|
| 2012 |
static struct ast_custom_function unshift_function = { |
| 2013 |
.name = "UNSHIFT", |
| 2014 |
.write = unshift_push, |
| 2015 |
}; |
| 2016 |
|
| 2017 |
static int passthru(struct ast_channel *chan, const char *cmd, char *data, struct ast_str **buf, ssize_t len) |
| 2018 |
{ |
| 2019 |
ast_str_set(buf, len, "%s", data); |
| 2020 |
return 0; |
| 2021 |
} |
| 2022 |
|
| 2023 |
static struct ast_custom_function passthru_function = { |
| 2024 |
.name = "PASSTHRU", |
| 2025 |
.read2 = passthru, |
| 2026 |
}; |
| 2027 |
|
| 2028 |
#ifdef TEST_FRAMEWORK |
| 2029 |
AST_TEST_DEFINE(test_FIELDNUM) |
| 2030 |
{ |
| 2031 |
int i, res = AST_TEST_PASS; |
| 2032 |
struct ast_channel *chan; |
| 2033 |
struct ast_str *str; |
| 2034 |
char expression[256]; |
| 2035 |
struct { |
| 2036 |
const char *fields; |
| 2037 |
const char *delim; |
| 2038 |
const char *field; |
| 2039 |
const char *expected; |
| 2040 |
} test_args[] = { |
| 2041 |
{"abc,def,ghi,jkl", "\\,", "ghi", "3"}, |
| 2042 |
{"abc def ghi jkl", " ", "abc", "1"}, |
| 2043 |
{"abc/def/ghi/jkl", "\\\\x2f", "def", "2"}, |
| 2044 |
{"abc$def$ghi$jkl", "", "ghi", "0"}, |
| 2045 |
{"abc,def,ghi,jkl", "-", "", "0"}, |
| 2046 |
{"abc-def-ghi-jkl", "-", "mno", "0"} |
| 2047 |
}; |
| 2048 |
|
| 2049 |
switch (cmd) { |
| 2050 |
case TEST_INIT: |
| 2051 |
info->name = "func_FIELDNUM_test"; |
| 2052 |
info->category = "/funcs/func_strings/"; |
| 2053 |
info->summary = "Test FIELDNUM function"; |
| 2054 |
info->description = "Verify FIELDNUM behavior"; |
| 2055 |
return AST_TEST_NOT_RUN; |
| 2056 |
case TEST_EXECUTE: |
| 2057 |
break; |
| 2058 |
} |
| 2059 |
|
| 2060 |
if (!(chan = ast_dummy_channel_alloc())) { |
| 2061 |
ast_test_status_update(test, "Unable to allocate dummy channel\n"); |
| 2062 |
return AST_TEST_FAIL; |
| 2063 |
} |
| 2064 |
|
| 2065 |
if (!(str = ast_str_create(16))) { |
| 2066 |
ast_test_status_update(test, "Unable to allocate dynamic string buffer\n"); |
| 2067 |
ast_channel_release(chan); |
| 2068 |
return AST_TEST_FAIL; |
| 2069 |
} |
| 2070 |
|
| 2071 |
for (i = 0; i < ARRAY_LEN(test_args); i++) { |
| 2072 |
struct ast_var_t *var = ast_var_assign("FIELDS", test_args[i].fields); |
| 2073 |
if (!var) { |
| 2074 |
ast_test_status_update(test, "Out of memory\n"); |
| 2075 |
res = AST_TEST_FAIL; |
| 2076 |
break; |
| 2077 |
} |
| 2078 |
|
| 2079 |
AST_LIST_INSERT_HEAD(ast_channel_varshead(chan), var, entries); |
| 2080 |
|
| 2081 |
snprintf(expression, sizeof(expression), "${FIELDNUM(%s,%s,%s)}", var->name, test_args[i].delim, test_args[i].field); |
| 2082 |
ast_str_substitute_variables(&str, 0, chan, expression); |
| 2083 |
|
| 2084 |
AST_LIST_REMOVE(ast_channel_varshead(chan), var, entries); |
| 2085 |
ast_var_delete(var); |
| 2086 |
|
| 2087 |
if (strcasecmp(ast_str_buffer(str), test_args[i].expected)) { |
| 2088 |
ast_test_status_update(test, "Evaluation of '%s' returned '%s' instead of the expected value '%s'\n", |
| 2089 |
expression, ast_str_buffer(str), test_args[i].expected); |
| 2090 |
res = AST_TEST_FAIL; |
| 2091 |
break; |
| 2092 |
} |
| 2093 |
} |
| 2094 |
|
| 2095 |
ast_free(str); |
| 2096 |
ast_channel_release(chan); |
| 2097 |
|
| 2098 |
return res; |
| 2099 |
} |
| 2100 |
|
| 2101 |
AST_TEST_DEFINE(test_REPLACE) |
| 2102 |
{ |
| 2103 |
int i, res = AST_TEST_PASS; |
| 2104 |
struct ast_channel *chan; |
| 2105 |
struct ast_str *str; |
| 2106 |
char expression[256]; |
| 2107 |
struct { |
| 2108 |
const char *test_string; |
| 2109 |
const char *find_chars; |
| 2110 |
const char *replace_char; |
| 2111 |
const char *expected; |
| 2112 |
} test_args[] = { |
| 2113 |
{"abc,def", "\\,", "-", "abc-def"}, |
| 2114 |
{"abc,abc", "bc", "a", "aaa,aaa"}, |
| 2115 |
{"abc,def", "x", "?", "abc,def"}, |
| 2116 |
{"abc,def", "\\,", "", "abcdef"} |
| 2117 |
}; |
| 2118 |
|
| 2119 |
switch (cmd) { |
| 2120 |
case TEST_INIT: |
| 2121 |
info->name = "func_REPLACE_test"; |
| 2122 |
info->category = "/funcs/func_strings/"; |
| 2123 |
info->summary = "Test REPLACE function"; |
| 2124 |
info->description = "Verify REPLACE behavior"; |
| 2125 |
return AST_TEST_NOT_RUN; |
| 2126 |
case TEST_EXECUTE: |
| 2127 |
break; |
| 2128 |
} |
| 2129 |
|
| 2130 |
if (!(chan = ast_dummy_channel_alloc())) { |
| 2131 |
ast_test_status_update(test, "Unable to allocate dummy channel\n"); |
| 2132 |
return AST_TEST_FAIL; |
| 2133 |
} |
| 2134 |
|
| 2135 |
if (!(str = ast_str_create(16))) { |
| 2136 |
ast_test_status_update(test, "Unable to allocate dynamic string buffer\n"); |
| 2137 |
ast_channel_release(chan); |
| 2138 |
return AST_TEST_FAIL; |
| 2139 |
} |
| 2140 |
|
| 2141 |
for (i = 0; i < ARRAY_LEN(test_args); i++) { |
| 2142 |
struct ast_var_t *var = ast_var_assign("TEST_STRING", test_args[i].test_string); |
| 2143 |
if (!var) { |
| 2144 |
ast_test_status_update(test, "Out of memory\n"); |
| 2145 |
res = AST_TEST_FAIL; |
| 2146 |
break; |
| 2147 |
} |
| 2148 |
|
| 2149 |
AST_LIST_INSERT_HEAD(ast_channel_varshead(chan), var, entries); |
| 2150 |
|
| 2151 |
snprintf(expression, sizeof(expression), "${REPLACE(%s,%s,%s)}", var->name, test_args[i].find_chars, test_args[i].replace_char); |
| 2152 |
ast_str_substitute_variables(&str, 0, chan, expression); |
| 2153 |
|
| 2154 |
AST_LIST_REMOVE(ast_channel_varshead(chan), var, entries); |
| 2155 |
ast_var_delete(var); |
| 2156 |
|
| 2157 |
if (strcasecmp(ast_str_buffer(str), test_args[i].expected)) { |
| 2158 |
ast_test_status_update(test, "Evaluation of '%s' returned '%s' instead of the expected value '%s'\n", |
| 2159 |
expression, ast_str_buffer(str), test_args[i].expected); |
| 2160 |
res = AST_TEST_FAIL; |
| 2161 |
break; |
| 2162 |
} |
| 2163 |
} |
| 2164 |
|
| 2165 |
ast_free(str); |
| 2166 |
ast_channel_release(chan); |
| 2167 |
|
| 2168 |
return res; |
| 2169 |
} |
| 2170 |
|
| 2171 |
AST_TEST_DEFINE(test_FILTER) |
| 2172 |
{ |
| 2173 |
int i, res = AST_TEST_PASS; |
| 2174 |
const char *test_strings[][2] = { |
| 2175 |
{"A-R", "DAHDI"}, |
| 2176 |
{"A\\-R", "A"}, |
| 2177 |
{"\\x41-R", "DAHDI"}, |
| 2178 |
{"0-9A-Ca-c", "0042133333A12212"}, |
| 2179 |
{"0-9a-cA-C_+\\-", "0042133333A12212"}, |
| 2180 |
{NULL, NULL}, |
| 2181 |
}; |
| 2182 |
|
| 2183 |
switch (cmd) { |
| 2184 |
case TEST_INIT: |
| 2185 |
info->name = "func_FILTER_test"; |
| 2186 |
info->category = "/funcs/func_strings/"; |
| 2187 |
info->summary = "Test FILTER function"; |
| 2188 |
info->description = "Verify FILTER behavior"; |
| 2189 |
return AST_TEST_NOT_RUN; |
| 2190 |
case TEST_EXECUTE: |
| 2191 |
break; |
| 2192 |
} |
| 2193 |
|
| 2194 |
for (i = 0; test_strings[i][0]; i++) { |
| 2195 |
char tmp[256], tmp2[256] = ""; |
| 2196 |
snprintf(tmp, sizeof(tmp), "${FILTER(%s,0042133333&DAHDI/g1/2212)}", test_strings[i][0]); |
| 2197 |
pbx_substitute_variables_helper(NULL, tmp, tmp2, sizeof(tmp2) - 1); |
| 2198 |
if (strcmp(test_strings[i][1], tmp2)) { |
| 2199 |
ast_test_status_update(test, "Format string '%s' substituted to '%s'. Expected '%s'.\n", test_strings[i][0], tmp2, test_strings[i][1]); |
| 2200 |
res = AST_TEST_FAIL; |
| 2201 |
} |
| 2202 |
} |
| 2203 |
return res; |
| 2204 |
} |
| 2205 |
|
| 2206 |
AST_TEST_DEFINE(test_STRREPLACE) |
| 2207 |
{ |
| 2208 |
int i, res = AST_TEST_PASS; |
| 2209 |
struct ast_channel *chan; |
| 2210 |
struct ast_str *str; |
| 2211 |
|
| 2212 |
const char *test_strings[][5] = { |
| 2213 |
{"Weasels have eaten my telephone system", "have eaten my", "are eating our", "", "Weasels are eating our telephone system"}, |
| 2214 |
{"Did you know twenty plus two is twenty-two?", "twenty", "thirty", NULL, "Did you know thirty plus two is thirty-two?"}, |
| 2215 |
{"foofoofoofoofoofoofoo", "foofoo", "bar", NULL, "barbarbarfoo"}, |
| 2216 |
{"My pet dog once ate a dog who sat on a dog while eating a corndog.", "dog", "cat", "3", "My pet cat once ate a cat who sat on a cat while eating a corndog."}, |
| 2217 |
{"One and one and one is three", "and", "plus", "1", "One plus one and one is three"}, |
| 2218 |
{"", "fhqwagads", "spelunker", NULL, ""}, |
| 2219 |
{"Part of this string is missing.", "missing", NULL, NULL, "Part of this string is ."}, |
| 2220 |
{"'Accidentally' left off a bunch of stuff.", NULL, NULL, NULL, ""}, |
| 2221 |
{"This test will also error.", "", "", "", ""}, |
| 2222 |
{"This is an \"escape character\" test.", "\\\"escape character\\\"", "evil", NULL, "This is an evil test."} |
| 2223 |
}; |
| 2224 |
|
| 2225 |
switch (cmd) { |
| 2226 |
case TEST_INIT: |
| 2227 |
info->name = "func_STRREPLACE_test"; |
| 2228 |
info->category = "/funcs/func_strings/"; |
| 2229 |
info->summary = "Test STRREPLACE function"; |
| 2230 |
info->description = "Verify STRREPLACE behavior"; |
| 2231 |
return AST_TEST_NOT_RUN; |
| 2232 |
case TEST_EXECUTE: |
| 2233 |
break; |
| 2234 |
} |
| 2235 |
|
| 2236 |
if (!(chan = ast_dummy_channel_alloc())) { |
| 2237 |
ast_test_status_update(test, "Unable to allocate dummy channel\n"); |
| 2238 |
return AST_TEST_FAIL; |
| 2239 |
} |
| 2240 |
|
| 2241 |
if (!(str = ast_str_create(64))) { |
| 2242 |
ast_test_status_update(test, "Unable to allocate dynamic string buffer\n"); |
| 2243 |
ast_channel_release(chan); |
| 2244 |
return AST_TEST_FAIL; |
| 2245 |
} |
| 2246 |
|
| 2247 |
for (i = 0; i < ARRAY_LEN(test_strings); i++) { |
| 2248 |
char tmp[512], tmp2[512] = ""; |
| 2249 |
|
| 2250 |
struct ast_var_t *var = ast_var_assign("test_string", test_strings[i][0]); |
| 2251 |
if (!var) { |
| 2252 |
ast_test_status_update(test, "Unable to allocate variable\n"); |
| 2253 |
ast_free(str); |
| 2254 |
ast_channel_release(chan); |
| 2255 |
return AST_TEST_FAIL; |
| 2256 |
} |
| 2257 |
|
| 2258 |
AST_LIST_INSERT_HEAD(ast_channel_varshead(chan), var, entries); |
| 2259 |
|
| 2260 |
if (test_strings[i][3]) { |
| 2261 |
snprintf(tmp, sizeof(tmp), "${STRREPLACE(%s,%s,%s,%s)}", "test_string", test_strings[i][1], test_strings[i][2], test_strings[i][3]); |
| 2262 |
} else if (test_strings[i][2]) { |
| 2263 |
snprintf(tmp, sizeof(tmp), "${STRREPLACE(%s,%s,%s)}", "test_string", test_strings[i][1], test_strings[i][2]); |
| 2264 |
} else if (test_strings[i][1]) { |
| 2265 |
snprintf(tmp, sizeof(tmp), "${STRREPLACE(%s,%s)}", "test_string", test_strings[i][1]); |
| 2266 |
} else { |
| 2267 |
snprintf(tmp, sizeof(tmp), "${STRREPLACE(%s)}", "test_string"); |
| 2268 |
} |
| 2269 |
ast_str_substitute_variables(&str, 0, chan, tmp); |
| 2270 |
if (strcmp(test_strings[i][4], ast_str_buffer(str))) { |
| 2271 |
ast_test_status_update(test, "Format string '%s' substituted to '%s'. Expected '%s'.\n", test_strings[i][0], tmp2, test_strings[i][4]); |
| 2272 |
res = AST_TEST_FAIL; |
| 2273 |
} |
| 2274 |
} |
| 2275 |
|
| 2276 |
ast_free(str); |
| 2277 |
ast_channel_release(chan); |
| 2278 |
|
| 2279 |
return res; |
| 2280 |
} |
| 2281 |
|
| 2282 |
AST_TEST_DEFINE(test_STRBETWEEN) |
| 2283 |
{ |
| 2284 |
int i, res = AST_TEST_PASS; |
| 2285 |
struct ast_channel *chan; |
| 2286 |
struct ast_str *str; |
| 2287 |
|
| 2288 |
const char *test_strings[][5] = { |
| 2289 |
{"0", "w", "0"}, |
| 2290 |
{"30", "w", "3w0"}, |
| 2291 |
{"212", "w", "2w1w2"}, |
| 2292 |
{"212", "55", "2551552"}, |
| 2293 |
{"212", " ", "2 1 2"}, |
| 2294 |
{"", "w", ""}, |
| 2295 |
{"555", "", "555"}, |
| 2296 |
{"abcdefg", "_", "a_b_c_d_e_f_g"}, |
| 2297 |
{"A", "A", "A"}, |
| 2298 |
{"AA", "B", "ABA"}, |
| 2299 |
{"AAA", "B", "ABABA"}, |
| 2300 |
}; |
| 2301 |
|
| 2302 |
switch (cmd) { |
| 2303 |
case TEST_INIT: |
| 2304 |
info->name = "func_STRBETWEEN"; |
| 2305 |
info->category = "/funcs/func_strings/"; |
| 2306 |
info->summary = "Test STRBETWEEN function"; |
| 2307 |
info->description = "Verify STRBETWEEN behavior"; |
| 2308 |
return AST_TEST_NOT_RUN; |
| 2309 |
case TEST_EXECUTE: |
| 2310 |
break; |
| 2311 |
} |
| 2312 |
|
| 2313 |
if (!(chan = ast_dummy_channel_alloc())) { |
| 2314 |
ast_test_status_update(test, "Unable to allocate dummy channel\n"); |
| 2315 |
return AST_TEST_FAIL; |
| 2316 |
} |
| 2317 |
|
| 2318 |
if (!(str = ast_str_create(64))) { |
| 2319 |
ast_test_status_update(test, "Unable to allocate dynamic string buffer\n"); |
| 2320 |
ast_channel_release(chan); |
| 2321 |
return AST_TEST_FAIL; |
| 2322 |
} |
| 2323 |
|
| 2324 |
for (i = 0; i < ARRAY_LEN(test_strings); i++) { |
| 2325 |
char tmp[512], tmp2[512] = ""; |
| 2326 |
|
| 2327 |
struct ast_var_t *var = ast_var_assign("test_string", test_strings[i][0]); |
| 2328 |
if (!var) { |
| 2329 |
ast_test_status_update(test, "Unable to allocate variable\n"); |
| 2330 |
ast_free(str); |
| 2331 |
ast_channel_release(chan); |
| 2332 |
return AST_TEST_FAIL; |
| 2333 |
} |
| 2334 |
|
| 2335 |
AST_LIST_INSERT_HEAD(ast_channel_varshead(chan), var, entries); |
| 2336 |
|
| 2337 |
if (test_strings[i][1]) { |
| 2338 |
snprintf(tmp, sizeof(tmp), "${STRBETWEEN(%s,%s)}", "test_string", test_strings[i][1]); |
| 2339 |
} else { |
| 2340 |
snprintf(tmp, sizeof(tmp), "${STRBETWEEN(%s)}", "test_string"); |
| 2341 |
} |
| 2342 |
ast_str_substitute_variables(&str, 0, chan, tmp); |
| 2343 |
if (strcmp(test_strings[i][2], ast_str_buffer(str))) { |
| 2344 |
ast_test_status_update(test, "Format string '%s' substituted to '%s'. Expected '%s'.\n", test_strings[i][0], tmp2, test_strings[i][2]); |
| 2345 |
res = AST_TEST_FAIL; |
| 2346 |
} |
| 2347 |
} |
| 2348 |
|
| 2349 |
ast_free(str); |
| 2350 |
ast_channel_release(chan); |
| 2351 |
|
| 2352 |
return res; |
| 2353 |
} |
| 2354 |
|
| 2355 |
AST_TEST_DEFINE(test_TRIM) |
| 2356 |
{ |
| 2357 |
int i, res = AST_TEST_PASS; |
| 2358 |
struct ast_channel *chan; |
| 2359 |
struct ast_str *str; |
| 2360 |
|
| 2361 |
const char *test_strings[][5] = { |
| 2362 |
{"TRIM", " abcd ", "abcd"}, |
| 2363 |
{"LTRIM", " abcd ", "abcd "}, |
| 2364 |
{"RTRIM", " abcd ", " abcd"}, |
| 2365 |
{"TRIM", "abcd", "abcd"}, |
| 2366 |
{"TRIM", " a b c d ", "a b c d"}, |
| 2367 |
}; |
| 2368 |
|
| 2369 |
switch (cmd) { |
| 2370 |
case TEST_INIT: |
| 2371 |
info->name = "func_TRIM"; |
| 2372 |
info->category = "/funcs/func_strings/"; |
| 2373 |
info->summary = "Test TRIM functions"; |
| 2374 |
info->description = "Verify TRIM behavior"; |
| 2375 |
return AST_TEST_NOT_RUN; |
| 2376 |
case TEST_EXECUTE: |
| 2377 |
break; |
| 2378 |
} |
| 2379 |
|
| 2380 |
if (!(chan = ast_dummy_channel_alloc())) { |
| 2381 |
ast_test_status_update(test, "Unable to allocate dummy channel\n"); |
| 2382 |
return AST_TEST_FAIL; |
| 2383 |
} |
| 2384 |
|
| 2385 |
if (!(str = ast_str_create(64))) { |
| 2386 |
ast_test_status_update(test, "Unable to allocate dynamic string buffer\n"); |
| 2387 |
ast_channel_release(chan); |
| 2388 |
return AST_TEST_FAIL; |
| 2389 |
} |
| 2390 |
|
| 2391 |
for (i = 0; i < ARRAY_LEN(test_strings); i++) { |
| 2392 |
char tmp[512], tmp2[512] = ""; |
| 2393 |
|
| 2394 |
snprintf(tmp, sizeof(tmp), "${%s(%s)}", test_strings[i][0], test_strings[i][1]); |
| 2395 |
ast_str_substitute_variables(&str, 0, chan, tmp); |
| 2396 |
if (strcmp(test_strings[i][2], ast_str_buffer(str))) { |
| 2397 |
ast_test_status_update(test, "Format string '%s' substituted to '%s'. Expected '%s'.\n", test_strings[i][0], tmp2, test_strings[i][2]); |
| 2398 |
res = AST_TEST_FAIL; |
| 2399 |
} |
| 2400 |
} |
| 2401 |
|
| 2402 |
ast_free(str); |
| 2403 |
ast_channel_release(chan); |
| 2404 |
|
| 2405 |
return res; |
| 2406 |
} |
| 2407 |
#endif |
| 2408 |
|
| 2409 |
static int unload_module(void) |
| 2410 |
{ |
| 2411 |
int res = 0; |
| 2412 |
|
| 2413 |
AST_TEST_UNREGISTER(test_FIELDNUM); |
| 2414 |
AST_TEST_UNREGISTER(test_REPLACE); |
| 2415 |
AST_TEST_UNREGISTER(test_FILTER); |
| 2416 |
AST_TEST_UNREGISTER(test_STRREPLACE); |
| 2417 |
AST_TEST_UNREGISTER(test_STRBETWEEN); |
| 2418 |
AST_TEST_UNREGISTER(test_TRIM); |
| 2419 |
res |= ast_custom_function_unregister(&fieldqty_function); |
| 2420 |
res |= ast_custom_function_unregister(&fieldnum_function); |
| 2421 |
res |= ast_custom_function_unregister(&filter_function); |
| 2422 |
res |= ast_custom_function_unregister(&replace_function); |
| 2423 |
res |= ast_custom_function_unregister(&strreplace_function); |
| 2424 |
res |= ast_custom_function_unregister(&strbetween_function); |
| 2425 |
res |= ast_custom_function_unregister(&listfilter_function); |
| 2426 |
res |= ast_custom_function_unregister(®ex_function); |
| 2427 |
res |= ast_custom_function_unregister(&array_function); |
| 2428 |
res |= ast_custom_function_unregister("e_function); |
| 2429 |
res |= ast_custom_function_unregister(&csv_quote_function); |
| 2430 |
res |= ast_custom_function_unregister(&len_function); |
| 2431 |
res |= ast_custom_function_unregister(&strftime_function); |
| 2432 |
res |= ast_custom_function_unregister(&strptime_function); |
| 2433 |
res |= ast_custom_function_unregister(&eval_function); |
| 2434 |
res |= ast_custom_function_unregister(&keypadhash_function); |
| 2435 |
res |= ast_custom_function_unregister(&hashkeys_function); |
| 2436 |
res |= ast_custom_function_unregister(&hash_function); |
| 2437 |
res |= ast_unregister_application(app_clearhash); |
| 2438 |
res |= ast_custom_function_unregister(&toupper_function); |
| 2439 |
res |= ast_custom_function_unregister(&tolower_function); |
| 2440 |
res |= ast_custom_function_unregister(&shift_function); |
| 2441 |
res |= ast_custom_function_unregister(&pop_function); |
| 2442 |
res |= ast_custom_function_unregister(&push_function); |
| 2443 |
res |= ast_custom_function_unregister(&unshift_function); |
| 2444 |
res |= ast_custom_function_unregister(&passthru_function); |
| 2445 |
res |= ast_custom_function_unregister(&trim_function); |
| 2446 |
res |= ast_custom_function_unregister(<rim_function); |
| 2447 |
res |= ast_custom_function_unregister(&rtrim_function); |
| 2448 |
|
| 2449 |
return res; |
| 2450 |
} |
| 2451 |
|
| 2452 |
static int load_module(void) |
| 2453 |
{ |
| 2454 |
int res = 0; |
| 2455 |
|
| 2456 |
AST_TEST_REGISTER(test_FIELDNUM); |
| 2457 |
AST_TEST_REGISTER(test_REPLACE); |
| 2458 |
AST_TEST_REGISTER(test_FILTER); |
| 2459 |
AST_TEST_REGISTER(test_STRREPLACE); |
| 2460 |
AST_TEST_REGISTER(test_STRBETWEEN); |
| 2461 |
AST_TEST_REGISTER(test_TRIM); |
| 2462 |
res |= ast_custom_function_register(&fieldqty_function); |
| 2463 |
res |= ast_custom_function_register(&fieldnum_function); |
| 2464 |
res |= ast_custom_function_register(&filter_function); |
| 2465 |
res |= ast_custom_function_register(&replace_function); |
| 2466 |
res |= ast_custom_function_register(&strreplace_function); |
| 2467 |
res |= ast_custom_function_register(&strbetween_function); |
| 2468 |
res |= ast_custom_function_register(&listfilter_function); |
| 2469 |
res |= ast_custom_function_register(®ex_function); |
| 2470 |
res |= ast_custom_function_register(&array_function); |
| 2471 |
res |= ast_custom_function_register("e_function); |
| 2472 |
res |= ast_custom_function_register(&csv_quote_function); |
| 2473 |
res |= ast_custom_function_register(&len_function); |
| 2474 |
res |= ast_custom_function_register(&strftime_function); |
| 2475 |
res |= ast_custom_function_register(&strptime_function); |
| 2476 |
res |= ast_custom_function_register(&eval_function); |
| 2477 |
res |= ast_custom_function_register(&keypadhash_function); |
| 2478 |
res |= ast_custom_function_register(&hashkeys_function); |
| 2479 |
res |= ast_custom_function_register(&hash_function); |
| 2480 |
res |= ast_register_application_xml(app_clearhash, exec_clearhash); |
| 2481 |
res |= ast_custom_function_register(&toupper_function); |
| 2482 |
res |= ast_custom_function_register(&tolower_function); |
| 2483 |
res |= ast_custom_function_register(&shift_function); |
| 2484 |
res |= ast_custom_function_register(&pop_function); |
| 2485 |
res |= ast_custom_function_register(&push_function); |
| 2486 |
res |= ast_custom_function_register(&unshift_function); |
| 2487 |
res |= ast_custom_function_register(&passthru_function); |
| 2488 |
res |= ast_custom_function_register(&trim_function); |
| 2489 |
res |= ast_custom_function_register(<rim_function); |
| 2490 |
res |= ast_custom_function_register(&rtrim_function); |
| 2491 |
|
| 2492 |
return res; |
| 2493 |
} |
| 2494 |
|
| 2495 |
AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "String handling dialplan functions"); |