00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031 #include "asterisk.h"
00032
00033 ASTERISK_FILE_VERSION(__FILE__, "$Revision: 328209 $")
00034
00035 #include "asterisk/module.h"
00036 #include "asterisk/channel.h"
00037 #include "asterisk/pbx.h"
00038 #include "asterisk/utils.h"
00039 #include "asterisk/app.h"
00040 #include "asterisk/callerid.h"
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216
00217
00218
00219
00220
00221
00222
00223
00224
00225
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235
00236
00237
00238
00239
00240
00241
00242
00243
00244
00245
00246
00247
00248
00249
00250
00251
00252
00253
00254
00255
00256
00257
00258
00259
00260
00261
00262
00263
00264
00265
00266
00267
00268
00269
00270
00271
00272
00273
00274
00275
00276
00277
00278
00279
00280
00281
00282
00283
00284
00285
00286
00287
00288
00289
00290
00291
00292
00293
00294
00295
00296
00297
00298
00299
00300
00301
00302
00303
00304
00305
00306
00307
00308
00309
00310
00311
00312
00313
00314 enum ID_FIELD_STATUS {
00315 ID_FIELD_VALID,
00316 ID_FIELD_INVALID,
00317 ID_FIELD_UNKNOWN
00318 };
00319
00320 AST_DEFINE_APP_ARGS_TYPE(ast_party_func_args,
00321 AST_APP_ARG(member);
00322 AST_APP_ARG(opts);
00323 AST_APP_ARG(other);
00324 );
00325
00326 AST_DEFINE_APP_ARGS_TYPE(ast_party_members,
00327 AST_APP_ARG(subnames[10]);
00328 );
00329
00330 enum CONNECTED_LINE_OPT_FLAGS {
00331 CONNECTED_LINE_OPT_INHIBIT = (1 << 0),
00332 };
00333 enum CONNECTED_LINE_OPT_ARGS {
00334 CONNECTED_LINE_OPT_DUMMY,
00335
00336
00337 CONNECTED_LINE_OPT_ARG_ARRAY_SIZE
00338 };
00339
00340 AST_APP_OPTIONS(connectedline_opts, BEGIN_OPTIONS
00341 AST_APP_OPTION('i', CONNECTED_LINE_OPT_INHIBIT),
00342 END_OPTIONS);
00343
00344 enum REDIRECTING_OPT_FLAGS {
00345 REDIRECTING_OPT_INHIBIT = (1 << 0),
00346 };
00347 enum REDIRECTING_OPT_ARGS {
00348 REDIRECTING_OPT_DUMMY,
00349
00350
00351 REDIRECTING_OPT_ARG_ARRAY_SIZE
00352 };
00353
00354 AST_APP_OPTIONS(redirecting_opts, BEGIN_OPTIONS
00355 AST_APP_OPTION('i', REDIRECTING_OPT_INHIBIT),
00356 END_OPTIONS);
00357
00358
00359
00360
00361
00362
00363
00364
00365
00366
00367
00368
00369
00370
00371
00372 static enum ID_FIELD_STATUS party_name_read(char *buf, size_t len, int argc, char *argv[], const struct ast_party_name *name)
00373 {
00374 enum ID_FIELD_STATUS status;
00375
00376 status = ID_FIELD_VALID;
00377
00378 if (argc == 0) {
00379
00380 if (name->valid && name->str) {
00381 ast_copy_string(buf, name->str, len);
00382 }
00383 } else if (argc == 1 && !strcasecmp("valid", argv[0])) {
00384 snprintf(buf, len, "%d", name->valid);
00385 } else if (argc == 1 && !strcasecmp("charset", argv[0])) {
00386 ast_copy_string(buf, ast_party_name_charset_str(name->char_set), len);
00387 } else if (argc == 1 && !strncasecmp("pres", argv[0], 4)) {
00388
00389 ast_copy_string(buf, ast_named_caller_presentation(name->presentation), len);
00390 } else {
00391 status = ID_FIELD_UNKNOWN;
00392 }
00393
00394 return status;
00395 }
00396
00397
00398
00399
00400
00401
00402
00403
00404
00405
00406
00407
00408
00409
00410
00411 static enum ID_FIELD_STATUS party_number_read(char *buf, size_t len, int argc, char *argv[], const struct ast_party_number *number)
00412 {
00413 enum ID_FIELD_STATUS status;
00414
00415 status = ID_FIELD_VALID;
00416
00417 if (argc == 0) {
00418
00419 if (number->valid && number->str) {
00420 ast_copy_string(buf, number->str, len);
00421 }
00422 } else if (argc == 1 && !strcasecmp("valid", argv[0])) {
00423 snprintf(buf, len, "%d", number->valid);
00424 } else if (argc == 1 && !strcasecmp("plan", argv[0])) {
00425 snprintf(buf, len, "%d", number->plan);
00426 } else if (argc == 1 && !strncasecmp("pres", argv[0], 4)) {
00427
00428 ast_copy_string(buf, ast_named_caller_presentation(number->presentation), len);
00429 } else {
00430 status = ID_FIELD_UNKNOWN;
00431 }
00432
00433 return status;
00434 }
00435
00436
00437
00438
00439
00440
00441
00442
00443
00444
00445
00446
00447
00448
00449
00450 static enum ID_FIELD_STATUS party_subaddress_read(char *buf, size_t len, int argc, char *argv[], const struct ast_party_subaddress *subaddress)
00451 {
00452 enum ID_FIELD_STATUS status;
00453
00454 status = ID_FIELD_VALID;
00455
00456 if (argc == 0) {
00457
00458 if (subaddress->str) {
00459 ast_copy_string(buf, subaddress->str, len);
00460 }
00461 } else if (argc == 1 && !strcasecmp("valid", argv[0])) {
00462 snprintf(buf, len, "%d", subaddress->valid);
00463 } else if (argc == 1 && !strcasecmp("type", argv[0])) {
00464 snprintf(buf, len, "%d", subaddress->type);
00465 } else if (argc == 1 && !strcasecmp("odd", argv[0])) {
00466 snprintf(buf, len, "%d", subaddress->odd_even_indicator);
00467 } else {
00468 status = ID_FIELD_UNKNOWN;
00469 }
00470
00471 return status;
00472 }
00473
00474
00475
00476
00477
00478
00479
00480
00481
00482
00483
00484
00485
00486
00487
00488 static enum ID_FIELD_STATUS party_id_read(char *buf, size_t len, int argc, char *argv[], const struct ast_party_id *id)
00489 {
00490 enum ID_FIELD_STATUS status;
00491
00492 if (argc == 0) {
00493
00494 return ID_FIELD_UNKNOWN;
00495 }
00496
00497 status = ID_FIELD_VALID;
00498
00499 if (argc == 1 && !strcasecmp("all", argv[0])) {
00500 snprintf(buf, len, "\"%s\" <%s>",
00501 S_COR(id->name.valid, id->name.str, ""),
00502 S_COR(id->number.valid, id->number.str, ""));
00503 } else if (!strcasecmp("name", argv[0])) {
00504 status = party_name_read(buf, len, argc - 1, argv + 1, &id->name);
00505 } else if (!strncasecmp("num", argv[0], 3)) {
00506
00507 status = party_number_read(buf, len, argc - 1, argv + 1, &id->number);
00508 } else if (!strncasecmp("subaddr", argv[0], 7)) {
00509
00510 status = party_subaddress_read(buf, len, argc - 1, argv + 1, &id->subaddress);
00511 } else if (argc == 1 && !strcasecmp("tag", argv[0])) {
00512 if (id->tag) {
00513 ast_copy_string(buf, id->tag, len);
00514 }
00515 } else if (argc == 1 && !strcasecmp("ton", argv[0])) {
00516
00517 snprintf(buf, len, "%d", id->number.plan);
00518 } else if (argc == 1 && !strncasecmp("pres", argv[0], 4)) {
00519
00520
00521
00522
00523 ast_copy_string(buf,
00524 ast_named_caller_presentation(ast_party_id_presentation(id)), len);
00525 } else {
00526 status = ID_FIELD_UNKNOWN;
00527 }
00528
00529 return status;
00530 }
00531
00532
00533
00534
00535
00536
00537
00538
00539
00540
00541
00542
00543
00544
00545
00546 static enum ID_FIELD_STATUS party_name_write(struct ast_party_name *name, int argc, char *argv[], const char *value)
00547 {
00548 char *val;
00549 enum ID_FIELD_STATUS status;
00550
00551 status = ID_FIELD_VALID;
00552
00553 if (argc == 0) {
00554
00555 name->valid = 1;
00556 name->str = ast_strdup(value);
00557 ast_trim_blanks(name->str);
00558 } else if (argc == 1 && !strcasecmp("valid", argv[0])) {
00559 name->valid = atoi(value) ? 1 : 0;
00560 } else if (argc == 1 && !strcasecmp("charset", argv[0])) {
00561 int char_set;
00562
00563 val = ast_strdupa(value);
00564 ast_trim_blanks(val);
00565
00566 if (('0' <= val[0]) && (val[0] <= '9')) {
00567 char_set = atoi(val);
00568 } else {
00569 char_set = ast_party_name_charset_parse(val);
00570 }
00571
00572 if (char_set < 0) {
00573 ast_log(LOG_ERROR,
00574 "Unknown name char-set '%s', value unchanged\n", val);
00575 status = ID_FIELD_INVALID;
00576 } else {
00577 name->char_set = char_set;
00578 }
00579 } else if (argc == 1 && !strncasecmp("pres", argv[0], 4)) {
00580 int pres;
00581
00582
00583 val = ast_strdupa(value);
00584 ast_trim_blanks(val);
00585
00586 if (('0' <= val[0]) && (val[0] <= '9')) {
00587 pres = atoi(val);
00588 } else {
00589 pres = ast_parse_caller_presentation(val);
00590 }
00591
00592 if (pres < 0) {
00593 ast_log(LOG_ERROR,
00594 "Unknown name presentation '%s', value unchanged\n", val);
00595 status = ID_FIELD_INVALID;
00596 } else {
00597 name->presentation = pres;
00598 }
00599 } else {
00600 status = ID_FIELD_UNKNOWN;
00601 }
00602
00603 return status;
00604 }
00605
00606
00607
00608
00609
00610
00611
00612
00613
00614
00615
00616
00617
00618
00619
00620 static enum ID_FIELD_STATUS party_number_write(struct ast_party_number *number, int argc, char *argv[], const char *value)
00621 {
00622 char *val;
00623 enum ID_FIELD_STATUS status;
00624
00625 status = ID_FIELD_VALID;
00626
00627 if (argc == 0) {
00628
00629 number->valid = 1;
00630 number->str = ast_strdup(value);
00631 ast_trim_blanks(number->str);
00632 } else if (argc == 1 && !strcasecmp("valid", argv[0])) {
00633 number->valid = atoi(value) ? 1 : 0;
00634 } else if (argc == 1 && !strcasecmp("plan", argv[0])) {
00635 val = ast_strdupa(value);
00636 ast_trim_blanks(val);
00637
00638 if (('0' <= val[0]) && (val[0] <= '9')) {
00639 number->plan = atoi(val);
00640 } else {
00641 ast_log(LOG_ERROR,
00642 "Unknown type-of-number/numbering-plan '%s', value unchanged\n", val);
00643 status = ID_FIELD_INVALID;
00644 }
00645 } else if (argc == 1 && !strncasecmp("pres", argv[0], 4)) {
00646 int pres;
00647
00648
00649 val = ast_strdupa(value);
00650 ast_trim_blanks(val);
00651
00652 if (('0' <= val[0]) && (val[0] <= '9')) {
00653 pres = atoi(val);
00654 } else {
00655 pres = ast_parse_caller_presentation(val);
00656 }
00657
00658 if (pres < 0) {
00659 ast_log(LOG_ERROR,
00660 "Unknown number presentation '%s', value unchanged\n", val);
00661 status = ID_FIELD_INVALID;
00662 } else {
00663 number->presentation = pres;
00664 }
00665 } else {
00666 status = ID_FIELD_UNKNOWN;
00667 }
00668
00669 return status;
00670 }
00671
00672
00673
00674
00675
00676
00677
00678
00679
00680
00681
00682
00683
00684
00685
00686 static enum ID_FIELD_STATUS party_subaddress_write(struct ast_party_subaddress *subaddress, int argc, char *argv[], const char *value)
00687 {
00688 enum ID_FIELD_STATUS status;
00689
00690 status = ID_FIELD_VALID;
00691
00692 if (argc == 0) {
00693
00694 subaddress->str = ast_strdup(value);
00695 ast_trim_blanks(subaddress->str);
00696 } else if (argc == 1 && !strcasecmp("valid", argv[0])) {
00697 subaddress->valid = atoi(value) ? 1 : 0;
00698 } else if (argc == 1 && !strcasecmp("type", argv[0])) {
00699 subaddress->type = atoi(value) ? 2 : 0;
00700 } else if (argc == 1 && !strcasecmp("odd", argv[0])) {
00701 subaddress->odd_even_indicator = atoi(value) ? 1 : 0;
00702 } else {
00703 status = ID_FIELD_UNKNOWN;
00704 }
00705
00706 return status;
00707 }
00708
00709
00710
00711
00712
00713
00714
00715
00716
00717
00718
00719
00720
00721
00722
00723 static enum ID_FIELD_STATUS party_id_write(struct ast_party_id *id, int argc, char *argv[], const char *value)
00724 {
00725 char *val;
00726 enum ID_FIELD_STATUS status;
00727
00728 if (argc == 0) {
00729
00730 return ID_FIELD_UNKNOWN;
00731 }
00732
00733 status = ID_FIELD_VALID;
00734
00735 if (argc == 1 && !strcasecmp("all", argv[0])) {
00736 char name[256];
00737 char num[256];
00738
00739 ast_callerid_split(value, name, sizeof(name), num, sizeof(num));
00740 id->name.valid = 1;
00741 id->name.str = ast_strdup(name);
00742 if (!id->name.str) {
00743 return ID_FIELD_INVALID;
00744 }
00745 id->number.valid = 1;
00746 id->number.str = ast_strdup(num);
00747 if (!id->number.str) {
00748 return ID_FIELD_INVALID;
00749 }
00750 } else if (!strcasecmp("name", argv[0])) {
00751 status = party_name_write(&id->name, argc - 1, argv + 1, value);
00752 } else if (!strncasecmp("num", argv[0], 3)) {
00753
00754 status = party_number_write(&id->number, argc - 1, argv + 1, value);
00755 } else if (!strncasecmp("subaddr", argv[0], 7)) {
00756
00757 status = party_subaddress_write(&id->subaddress, argc - 1, argv + 1, value);
00758 } else if (argc == 1 && !strcasecmp("tag", argv[0])) {
00759 id->tag = ast_strdup(value);
00760 ast_trim_blanks(id->tag);
00761 } else if (argc == 1 && !strcasecmp("ton", argv[0])) {
00762
00763 argv[0] = "plan";
00764 status = party_number_write(&id->number, argc, argv, value);
00765 } else if (argc == 1 && !strncasecmp("pres", argv[0], 4)) {
00766 int pres;
00767
00768
00769
00770
00771
00772 val = ast_strdupa(value);
00773 ast_trim_blanks(val);
00774
00775 if (('0' <= val[0]) && (val[0] <= '9')) {
00776 pres = atoi(val);
00777 } else {
00778 pres = ast_parse_caller_presentation(val);
00779 }
00780
00781 if (pres < 0) {
00782 ast_log(LOG_ERROR,
00783 "Unknown combined presentation '%s', value unchanged\n", val);
00784 status = ID_FIELD_INVALID;
00785 } else {
00786 id->name.presentation = pres;
00787 id->number.presentation = pres;
00788 }
00789 } else {
00790 status = ID_FIELD_UNKNOWN;
00791 }
00792
00793 return status;
00794 }
00795
00796
00797 static int callerpres_deprecate_notify;
00798
00799
00800
00801
00802
00803
00804
00805
00806
00807
00808
00809
00810
00811
00812 static int callerpres_read(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len)
00813 {
00814 if (!callerpres_deprecate_notify) {
00815 callerpres_deprecate_notify = 1;
00816 ast_log(LOG_WARNING, "CALLERPRES is deprecated."
00817 " Use CALLERID(name-pres) or CALLERID(num-pres) instead.\n");
00818 }
00819 ast_copy_string(buf,
00820 ast_named_caller_presentation(ast_party_id_presentation(&chan->caller.id)), len);
00821 return 0;
00822 }
00823
00824
00825
00826
00827
00828
00829
00830
00831
00832
00833
00834
00835
00836 static int callerpres_write(struct ast_channel *chan, const char *cmd, char *data, const char *value)
00837 {
00838 int pres;
00839
00840 if (!callerpres_deprecate_notify) {
00841 callerpres_deprecate_notify = 1;
00842 ast_log(LOG_WARNING, "CALLERPRES is deprecated."
00843 " Use CALLERID(name-pres) or CALLERID(num-pres) instead.\n");
00844 }
00845
00846 pres = ast_parse_caller_presentation(value);
00847 if (pres < 0) {
00848 ast_log(LOG_WARNING, "'%s' is not a valid presentation (see 'show function CALLERPRES')\n", value);
00849 } else {
00850 chan->caller.id.name.presentation = pres;
00851 chan->caller.id.number.presentation = pres;
00852 }
00853 return 0;
00854 }
00855
00856
00857
00858
00859
00860
00861
00862
00863
00864
00865
00866
00867
00868
00869 static int callerid_read(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len)
00870 {
00871 enum ID_FIELD_STATUS status;
00872 char *parms;
00873 struct ast_party_members member;
00874 AST_DECLARE_APP_ARGS(args,
00875 AST_APP_ARG(member);
00876 AST_APP_ARG(cid);
00877 );
00878
00879
00880 *buf = 0;
00881
00882 if (!chan) {
00883 return -1;
00884 }
00885
00886 parms = ast_strdupa(data);
00887 AST_STANDARD_APP_ARGS(args, parms);
00888 if (args.argc == 0) {
00889
00890 return -1;
00891 }
00892
00893 AST_NONSTANDARD_APP_ARGS(member, args.member, '-');
00894 if (member.argc == 0 || ARRAY_LEN(member.subnames) <= member.argc) {
00895
00896 return -1;
00897 }
00898
00899 if (args.argc == 2) {
00900 char name[80];
00901 char num[80];
00902
00903 ast_callerid_split(args.cid, name, sizeof(name), num, sizeof(num));
00904
00905 if (member.argc == 1 && !strcasecmp("all", member.argv[0])) {
00906 snprintf(buf, len, "\"%s\" <%s>", name, num);
00907 } else if (member.argc == 1 && !strcasecmp("name", member.argv[0])) {
00908 ast_copy_string(buf, name, len);
00909 } else if (member.argc == 1 && !strncasecmp("num", member.argv[0], 3)) {
00910
00911 ast_copy_string(buf, num, len);
00912 } else {
00913 ast_log(LOG_ERROR, "Unknown callerid data type '%s'.\n", data);
00914 }
00915 } else {
00916 ast_channel_lock(chan);
00917
00918 if (member.argc == 1 && !strcasecmp("rdnis", member.argv[0])) {
00919 if (chan->redirecting.from.number.valid
00920 && chan->redirecting.from.number.str) {
00921 ast_copy_string(buf, chan->redirecting.from.number.str, len);
00922 }
00923 } else if (!strcasecmp("dnid", member.argv[0])) {
00924 if (member.argc == 1) {
00925
00926 member.argc = 2;
00927 member.argv[1] = "num";
00928 }
00929 if (!strncasecmp("num", member.argv[1], 3)) {
00930
00931
00932
00933
00934 if (member.argc == 2) {
00935
00936 if (chan->dialed.number.str) {
00937 ast_copy_string(buf, chan->dialed.number.str, len);
00938 }
00939 } else if (member.argc == 3 && !strcasecmp("plan", member.argv[2])) {
00940
00941 snprintf(buf, len, "%d", chan->dialed.number.plan);
00942 } else {
00943 ast_log(LOG_ERROR, "Unknown callerid data type '%s'.\n", data);
00944 }
00945 } else if (!strncasecmp("subaddr", member.argv[1], 7)) {
00946
00947
00948
00949
00950 status = party_subaddress_read(buf, len, member.argc - 2, member.argv + 2,
00951 &chan->dialed.subaddress);
00952 switch (status) {
00953 case ID_FIELD_VALID:
00954 case ID_FIELD_INVALID:
00955 break;
00956 default:
00957 ast_log(LOG_ERROR, "Unknown callerid data type '%s'.\n", data);
00958 break;
00959 }
00960 } else {
00961 ast_log(LOG_ERROR, "Unknown callerid data type '%s'.\n", data);
00962 }
00963 } else if (member.argc == 1 && !strcasecmp("ani2", member.argv[0])) {
00964 snprintf(buf, len, "%d", chan->caller.ani2);
00965 } else if (!strcasecmp("ani", member.argv[0])) {
00966 if (member.argc == 1) {
00967
00968 member.argc = 2;
00969 member.argv[1] = "num";
00970 }
00971 status = party_id_read(buf, len, member.argc - 1, member.argv + 1,
00972 &chan->caller.ani);
00973 switch (status) {
00974 case ID_FIELD_VALID:
00975 case ID_FIELD_INVALID:
00976 break;
00977 default:
00978 ast_log(LOG_ERROR, "Unknown callerid data type '%s'.\n", data);
00979 break;
00980 }
00981 } else {
00982 status = party_id_read(buf, len, member.argc, member.argv, &chan->caller.id);
00983 switch (status) {
00984 case ID_FIELD_VALID:
00985 case ID_FIELD_INVALID:
00986 break;
00987 default:
00988 ast_log(LOG_ERROR, "Unknown callerid data type '%s'.\n", data);
00989 break;
00990 }
00991 }
00992
00993 ast_channel_unlock(chan);
00994 }
00995
00996 return 0;
00997 }
00998
00999
01000
01001
01002
01003
01004
01005
01006
01007
01008
01009
01010
01011 static int callerid_write(struct ast_channel *chan, const char *cmd, char *data, const char *value)
01012 {
01013 struct ast_party_caller caller;
01014 struct ast_party_dialed dialed;
01015 enum ID_FIELD_STATUS status;
01016 char *val;
01017 char *parms;
01018 struct ast_party_func_args args;
01019 struct ast_party_members member;
01020
01021 if (!value || !chan) {
01022 return -1;
01023 }
01024
01025 parms = ast_strdupa(data);
01026 AST_STANDARD_APP_ARGS(args, parms);
01027 if (args.argc == 0) {
01028
01029 return -1;
01030 }
01031
01032 AST_NONSTANDARD_APP_ARGS(member, args.member, '-');
01033 if (member.argc == 0 || ARRAY_LEN(member.subnames) <= member.argc) {
01034
01035 return -1;
01036 }
01037
01038 value = ast_skip_blanks(value);
01039
01040 ast_channel_lock(chan);
01041 if (member.argc == 1 && !strcasecmp("rdnis", member.argv[0])) {
01042 chan->redirecting.from.number.valid = 1;
01043 ast_free(chan->redirecting.from.number.str);
01044 chan->redirecting.from.number.str = ast_strdup(value);
01045 if (chan->cdr) {
01046 ast_cdr_setcid(chan->cdr, chan);
01047 }
01048 } else if (!strcasecmp("dnid", member.argv[0])) {
01049 ast_party_dialed_set_init(&dialed, &chan->dialed);
01050 if (member.argc == 1) {
01051
01052 member.argc = 2;
01053 member.argv[1] = "num";
01054 }
01055 if (!strncasecmp("num", member.argv[1], 3)) {
01056
01057
01058
01059
01060 if (member.argc == 2) {
01061
01062 dialed.number.str = ast_strdup(value);
01063 ast_trim_blanks(dialed.number.str);
01064 ast_party_dialed_set(&chan->dialed, &dialed);
01065 if (chan->cdr) {
01066 ast_cdr_setcid(chan->cdr, chan);
01067 }
01068 } else if (member.argc == 3 && !strcasecmp("plan", member.argv[2])) {
01069
01070 val = ast_strdupa(value);
01071 ast_trim_blanks(val);
01072
01073 if (('0' <= val[0]) && (val[0] <= '9')) {
01074 chan->dialed.number.plan = atoi(val);
01075 if (chan->cdr) {
01076 ast_cdr_setcid(chan->cdr, chan);
01077 }
01078 } else {
01079 ast_log(LOG_ERROR,
01080 "Unknown type-of-number/numbering-plan '%s', value unchanged\n", val);
01081 }
01082 } else {
01083 ast_log(LOG_ERROR, "Unknown callerid data type '%s'.\n", data);
01084 }
01085 } else if (!strncasecmp("subaddr", member.argv[1], 7)) {
01086
01087
01088
01089
01090 status = party_subaddress_write(&dialed.subaddress, member.argc - 2,
01091 member.argv + 2, value);
01092 switch (status) {
01093 case ID_FIELD_VALID:
01094 ast_party_dialed_set(&chan->dialed, &dialed);
01095 if (chan->cdr) {
01096 ast_cdr_setcid(chan->cdr, chan);
01097 }
01098 break;
01099 case ID_FIELD_INVALID:
01100 break;
01101 default:
01102 ast_log(LOG_ERROR, "Unknown callerid data type '%s'.\n", data);
01103 break;
01104 }
01105 } else {
01106 ast_log(LOG_ERROR, "Unknown callerid data type '%s'.\n", data);
01107 }
01108 ast_party_dialed_free(&dialed);
01109 } else if (member.argc == 1 && !strcasecmp("ani2", member.argv[0])) {
01110 val = ast_strdupa(value);
01111 ast_trim_blanks(val);
01112
01113 if (('0' <= val[0]) && (val[0] <= '9')) {
01114 chan->caller.ani2 = atoi(val);
01115 if (chan->cdr) {
01116 ast_cdr_setcid(chan->cdr, chan);
01117 }
01118 } else {
01119 ast_log(LOG_ERROR, "Unknown callerid ani2 '%s', value unchanged\n", val);
01120 }
01121 } else if (!strcasecmp("ani", member.argv[0])) {
01122 ast_party_caller_set_init(&caller, &chan->caller);
01123 if (member.argc == 1) {
01124
01125 member.argc = 2;
01126 member.argv[1] = "num";
01127 }
01128 status = party_id_write(&caller.ani, member.argc - 1, member.argv + 1, value);
01129 switch (status) {
01130 case ID_FIELD_VALID:
01131 ast_party_caller_set(&chan->caller, &caller, NULL);
01132 if (chan->cdr) {
01133 ast_cdr_setcid(chan->cdr, chan);
01134 }
01135 break;
01136 case ID_FIELD_INVALID:
01137 break;
01138 default:
01139 ast_log(LOG_ERROR, "Unknown callerid data type '%s'.\n", data);
01140 break;
01141 }
01142 ast_party_caller_free(&caller);
01143 } else {
01144 ast_party_caller_set_init(&caller, &chan->caller);
01145 status = party_id_write(&caller.id, member.argc, member.argv, value);
01146 switch (status) {
01147 case ID_FIELD_VALID:
01148 ast_channel_set_caller_event(chan, &caller, NULL);
01149 if (chan->cdr) {
01150 ast_cdr_setcid(chan->cdr, chan);
01151 }
01152 break;
01153 case ID_FIELD_INVALID:
01154 break;
01155 default:
01156 ast_log(LOG_ERROR, "Unknown callerid data type '%s'.\n", data);
01157 break;
01158 }
01159 ast_party_caller_free(&caller);
01160 }
01161 ast_channel_unlock(chan);
01162
01163 return 0;
01164 }
01165
01166
01167
01168
01169
01170
01171
01172
01173
01174
01175
01176
01177
01178
01179 static int connectedline_read(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len)
01180 {
01181 struct ast_party_members member;
01182 char *read_what;
01183 enum ID_FIELD_STATUS status;
01184
01185
01186 *buf = 0;
01187
01188 if (!chan) {
01189 return -1;
01190 }
01191
01192 read_what = ast_strdupa(data);
01193 AST_NONSTANDARD_APP_ARGS(member, read_what, '-');
01194 if (member.argc == 0 || ARRAY_LEN(member.subnames) <= member.argc) {
01195
01196 return -1;
01197 }
01198
01199 ast_channel_lock(chan);
01200
01201 if (member.argc == 1 && !strcasecmp("source", member.argv[0])) {
01202 ast_copy_string(buf, ast_connected_line_source_name(chan->connected.source), len);
01203 } else {
01204 status = party_id_read(buf, len, member.argc, member.argv, &chan->connected.id);
01205 switch (status) {
01206 case ID_FIELD_VALID:
01207 case ID_FIELD_INVALID:
01208 break;
01209 default:
01210 ast_log(LOG_ERROR, "Unknown connectedline data type '%s'.\n", data);
01211 break;
01212 }
01213 }
01214
01215 ast_channel_unlock(chan);
01216
01217 return 0;
01218 }
01219
01220
01221
01222
01223
01224
01225
01226
01227
01228
01229
01230
01231
01232 static int connectedline_write(struct ast_channel *chan, const char *cmd, char *data, const char *value)
01233 {
01234 struct ast_party_connected_line connected;
01235 enum ID_FIELD_STATUS status;
01236 char *val;
01237 char *parms;
01238 void (*set_it)(struct ast_channel *chan, const struct ast_party_connected_line *connected, const struct ast_set_party_connected_line *update);
01239 struct ast_party_func_args args;
01240 struct ast_party_members member;
01241 struct ast_flags opts;
01242 char *opt_args[CONNECTED_LINE_OPT_ARG_ARRAY_SIZE];
01243
01244 if (!value || !chan) {
01245 return -1;
01246 }
01247
01248 parms = ast_strdupa(data);
01249 AST_STANDARD_APP_ARGS(args, parms);
01250 if (args.argc == 0) {
01251
01252 return -1;
01253 }
01254
01255 AST_NONSTANDARD_APP_ARGS(member, args.member, '-');
01256 if (member.argc == 0 || ARRAY_LEN(member.subnames) <= member.argc) {
01257
01258 return -1;
01259 }
01260
01261 if (ast_app_parse_options(connectedline_opts, &opts, opt_args, args.opts)) {
01262
01263 return -1;
01264 }
01265
01266
01267 if (ast_test_flag(&opts, CONNECTED_LINE_OPT_INHIBIT)) {
01268 set_it = ast_channel_set_connected_line;
01269 } else {
01270 set_it = ast_channel_update_connected_line;
01271 }
01272
01273 ast_channel_lock(chan);
01274 ast_party_connected_line_set_init(&connected, &chan->connected);
01275 ast_channel_unlock(chan);
01276
01277 value = ast_skip_blanks(value);
01278
01279 if (member.argc == 1 && !strcasecmp("source", member.argv[0])) {
01280 int source;
01281
01282 val = ast_strdupa(value);
01283 ast_trim_blanks(val);
01284
01285 if (('0' <= val[0]) && (val[0] <= '9')) {
01286 source = atoi(val);
01287 } else {
01288 source = ast_connected_line_source_parse(val);
01289 }
01290
01291 if (source < 0) {
01292 ast_log(LOG_ERROR, "Unknown connectedline source '%s', value unchanged\n", val);
01293 } else {
01294 connected.source = source;
01295 set_it(chan, &connected, NULL);
01296 }
01297 } else {
01298 status = party_id_write(&connected.id, member.argc, member.argv, value);
01299 switch (status) {
01300 case ID_FIELD_VALID:
01301 set_it(chan, &connected, NULL);
01302 break;
01303 case ID_FIELD_INVALID:
01304 break;
01305 default:
01306 ast_log(LOG_ERROR, "Unknown connectedline data type '%s'.\n", data);
01307 break;
01308 }
01309 ast_party_connected_line_free(&connected);
01310 }
01311
01312 return 0;
01313 }
01314
01315
01316
01317
01318
01319
01320
01321
01322
01323
01324
01325
01326
01327
01328 static int redirecting_read(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len)
01329 {
01330 struct ast_party_members member;
01331 char *read_what;
01332 enum ID_FIELD_STATUS status;
01333
01334
01335 *buf = 0;
01336
01337 if (!chan) {
01338 return -1;
01339 }
01340
01341 read_what = ast_strdupa(data);
01342 AST_NONSTANDARD_APP_ARGS(member, read_what, '-');
01343 if (member.argc == 0 || ARRAY_LEN(member.subnames) <= member.argc) {
01344
01345 return -1;
01346 }
01347
01348 ast_channel_lock(chan);
01349
01350 if (!strcasecmp("from", member.argv[0])) {
01351 status = party_id_read(buf, len, member.argc - 1, member.argv + 1,
01352 &chan->redirecting.from);
01353 switch (status) {
01354 case ID_FIELD_VALID:
01355 case ID_FIELD_INVALID:
01356 break;
01357 default:
01358 ast_log(LOG_ERROR, "Unknown redirecting data type '%s'.\n", data);
01359 break;
01360 }
01361 } else if (!strcasecmp("to", member.argv[0])) {
01362 status = party_id_read(buf, len, member.argc - 1, member.argv + 1,
01363 &chan->redirecting.to);
01364 switch (status) {
01365 case ID_FIELD_VALID:
01366 case ID_FIELD_INVALID:
01367 break;
01368 default:
01369 ast_log(LOG_ERROR, "Unknown redirecting data type '%s'.\n", data);
01370 break;
01371 }
01372 } else if (member.argc == 1 && !strncasecmp("pres", member.argv[0], 4)) {
01373
01374
01375
01376
01377 ast_copy_string(buf,
01378 ast_named_caller_presentation(
01379 ast_party_id_presentation(&chan->redirecting.from)), len);
01380 } else if (member.argc == 1 && !strcasecmp("reason", member.argv[0])) {
01381 ast_copy_string(buf, ast_redirecting_reason_name(chan->redirecting.reason), len);
01382 } else if (member.argc == 1 && !strcasecmp("count", member.argv[0])) {
01383 snprintf(buf, len, "%d", chan->redirecting.count);
01384 } else {
01385 ast_log(LOG_ERROR, "Unknown redirecting data type '%s'.\n", data);
01386 }
01387
01388 ast_channel_unlock(chan);
01389
01390 return 0;
01391 }
01392
01393
01394
01395
01396
01397
01398
01399
01400
01401
01402
01403
01404
01405 static int redirecting_write(struct ast_channel *chan, const char *cmd, char *data, const char *value)
01406 {
01407 struct ast_party_redirecting redirecting;
01408 enum ID_FIELD_STATUS status;
01409 char *val;
01410 char *parms;
01411 void (*set_it)(struct ast_channel *chan, const struct ast_party_redirecting *redirecting, const struct ast_set_party_redirecting *update);
01412 struct ast_party_func_args args;
01413 struct ast_party_members member;
01414 struct ast_flags opts;
01415 char *opt_args[REDIRECTING_OPT_ARG_ARRAY_SIZE];
01416
01417 if (!value || !chan) {
01418 return -1;
01419 }
01420
01421 parms = ast_strdupa(data);
01422 AST_STANDARD_APP_ARGS(args, parms);
01423 if (args.argc == 0) {
01424
01425 return -1;
01426 }
01427
01428 AST_NONSTANDARD_APP_ARGS(member, args.member, '-');
01429 if (member.argc == 0 || ARRAY_LEN(member.subnames) <= member.argc) {
01430
01431 return -1;
01432 }
01433
01434 if (ast_app_parse_options(redirecting_opts, &opts, opt_args, args.opts)) {
01435
01436 return -1;
01437 }
01438
01439
01440 if (ast_test_flag(&opts, REDIRECTING_OPT_INHIBIT)) {
01441 set_it = ast_channel_set_redirecting;
01442 } else {
01443 set_it = ast_channel_update_redirecting;
01444 }
01445
01446 ast_channel_lock(chan);
01447 ast_party_redirecting_set_init(&redirecting, &chan->redirecting);
01448 ast_channel_unlock(chan);
01449
01450 value = ast_skip_blanks(value);
01451
01452 if (!strcasecmp("from", member.argv[0])) {
01453 status = party_id_write(&redirecting.from, member.argc - 1, member.argv + 1,
01454 value);
01455 switch (status) {
01456 case ID_FIELD_VALID:
01457 set_it(chan, &redirecting, NULL);
01458 break;
01459 case ID_FIELD_INVALID:
01460 break;
01461 default:
01462 ast_log(LOG_ERROR, "Unknown redirecting data type '%s'.\n", data);
01463 break;
01464 }
01465 ast_party_redirecting_free(&redirecting);
01466 } else if (!strcasecmp("to", member.argv[0])) {
01467 status = party_id_write(&redirecting.to, member.argc - 1, member.argv + 1, value);
01468 switch (status) {
01469 case ID_FIELD_VALID:
01470 set_it(chan, &redirecting, NULL);
01471 break;
01472 case ID_FIELD_INVALID:
01473 break;
01474 default:
01475 ast_log(LOG_ERROR, "Unknown redirecting data type '%s'.\n", data);
01476 break;
01477 }
01478 ast_party_redirecting_free(&redirecting);
01479 } else if (member.argc == 1 && !strncasecmp("pres", member.argv[0], 4)) {
01480 int pres;
01481
01482 val = ast_strdupa(value);
01483 ast_trim_blanks(val);
01484
01485 if (('0' <= val[0]) && (val[0] <= '9')) {
01486 pres = atoi(val);
01487 } else {
01488 pres = ast_parse_caller_presentation(val);
01489 }
01490
01491 if (pres < 0) {
01492 ast_log(LOG_ERROR,
01493 "Unknown redirecting combined presentation '%s', value unchanged\n", val);
01494 } else {
01495 redirecting.from.name.presentation = pres;
01496 redirecting.from.number.presentation = pres;
01497 redirecting.to.name.presentation = pres;
01498 redirecting.to.number.presentation = pres;
01499 set_it(chan, &redirecting, NULL);
01500 }
01501 } else if (member.argc == 1 && !strcasecmp("reason", member.argv[0])) {
01502 int reason;
01503
01504 val = ast_strdupa(value);
01505 ast_trim_blanks(val);
01506
01507 if (('0' <= val[0]) && (val[0] <= '9')) {
01508 reason = atoi(val);
01509 } else {
01510 reason = ast_redirecting_reason_parse(val);
01511 }
01512
01513 if (reason < 0) {
01514 ast_log(LOG_ERROR, "Unknown redirecting reason '%s', value unchanged\n", val);
01515 } else {
01516 redirecting.reason = reason;
01517 set_it(chan, &redirecting, NULL);
01518 }
01519 } else if (member.argc == 1 && !strcasecmp("count", member.argv[0])) {
01520 val = ast_strdupa(value);
01521 ast_trim_blanks(val);
01522
01523 if (('0' <= val[0]) && (val[0] <= '9')) {
01524 redirecting.count = atoi(val);
01525 set_it(chan, &redirecting, NULL);
01526 } else {
01527 ast_log(LOG_ERROR, "Unknown redirecting count '%s', value unchanged\n", val);
01528 }
01529 } else {
01530 ast_log(LOG_ERROR, "Unknown redirecting data type '%s'.\n", data);
01531 }
01532
01533 return 0;
01534 }
01535
01536 static struct ast_custom_function callerid_function = {
01537 .name = "CALLERID",
01538 .read = callerid_read,
01539 .read_max = 256,
01540 .write = callerid_write,
01541 };
01542
01543 static struct ast_custom_function callerpres_function = {
01544 .name = "CALLERPRES",
01545 .read = callerpres_read,
01546 .read_max = 50,
01547 .write = callerpres_write,
01548 };
01549
01550 static struct ast_custom_function connectedline_function = {
01551 .name = "CONNECTEDLINE",
01552 .read = connectedline_read,
01553 .write = connectedline_write,
01554 };
01555
01556 static struct ast_custom_function redirecting_function = {
01557 .name = "REDIRECTING",
01558 .read = redirecting_read,
01559 .write = redirecting_write,
01560 };
01561
01562
01563
01564
01565
01566
01567
01568
01569 static int unload_module(void)
01570 {
01571 int res;
01572
01573 res = ast_custom_function_unregister(&callerpres_function);
01574 res |= ast_custom_function_unregister(&callerid_function);
01575 res |= ast_custom_function_unregister(&connectedline_function);
01576 res |= ast_custom_function_unregister(&redirecting_function);
01577 return res;
01578 }
01579
01580
01581
01582
01583
01584
01585
01586
01587 static int load_module(void)
01588 {
01589 int res;
01590
01591 res = ast_custom_function_register(&callerpres_function);
01592 res |= ast_custom_function_register(&callerid_function);
01593 res |= ast_custom_function_register(&connectedline_function);
01594 res |= ast_custom_function_register(&redirecting_function);
01595 return res ? AST_MODULE_LOAD_DECLINE : AST_MODULE_LOAD_SUCCESS;
01596 }
01597
01598
01599 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Party ID related dialplan functions (Caller-ID, Connected-line, Redirecting)");