[go: up one dir, main page]

Menu

[r740]: / main / src / ospdest.c  Maximize  Restore  History

Download this file

1142 lines (1000 with data), 34.1 kB

   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
  35
  36
  37
  38
  39
  40
  41
  42
  43
  44
  45
  46
  47
  48
  49
  50
  51
  52
  53
  54
  55
  56
  57
  58
  59
  60
  61
  62
  63
  64
  65
  66
  67
  68
  69
  70
  71
  72
  73
  74
  75
  76
  77
  78
  79
  80
  81
  82
  83
  84
  85
  86
  87
  88
  89
  90
  91
  92
  93
  94
  95
  96
  97
  98
  99
 100
 101
 102
 103
 104
 105
 106
 107
 108
 109
 110
 111
 112
 113
 114
 115
 116
 117
 118
 119
 120
 121
 122
 123
 124
 125
 126
 127
 128
 129
 130
 131
 132
 133
 134
 135
 136
 137
 138
 139
 140
 141
 142
 143
 144
 145
 146
 147
 148
 149
 150
 151
 152
 153
 154
 155
 156
 157
 158
 159
 160
 161
 162
 163
 164
 165
 166
 167
 168
 169
 170
 171
 172
 173
 174
 175
 176
 177
 178
 179
 180
 181
 182
 183
 184
 185
 186
 187
 188
 189
 190
 191
 192
 193
 194
 195
 196
 197
 198
 199
 200
 201
 202
 203
 204
 205
 206
 207
 208
 209
 210
 211
 212
 213
 214
 215
 216
 217
 218
 219
 220
 221
 222
 223
 224
 225
 226
 227
 228
 229
 230
 231
 232
 233
 234
 235
 236
 237
 238
 239
 240
 241
 242
 243
 244
 245
 246
 247
 248
 249
 250
 251
 252
 253
 254
 255
 256
 257
 258
 259
 260
 261
 262
 263
 264
 265
 266
 267
 268
 269
 270
 271
 272
 273
 274
 275
 276
 277
 278
 279
 280
 281
 282
 283
 284
 285
 286
 287
 288
 289
 290
 291
 292
 293
 294
 295
 296
 297
 298
 299
 300
 301
 302
 303
 304
 305
 306
 307
 308
 309
 310
 311
 312
 313
 314
 315
 316
 317
 318
 319
 320
 321
 322
 323
 324
 325
 326
 327
 328
 329
 330
 331
 332
 333
 334
 335
 336
 337
 338
 339
 340
 341
 342
 343
 344
 345
 346
 347
 348
 349
 350
 351
 352
 353
 354
 355
 356
 357
 358
 359
 360
 361
 362
 363
 364
 365
 366
 367
 368
 369
 370
 371
 372
 373
 374
 375
 376
 377
 378
 379
 380
 381
 382
 383
 384
 385
 386
 387
 388
 389
 390
 391
 392
 393
 394
 395
 396
 397
 398
 399
 400
 401
 402
 403
 404
 405
 406
 407
 408
 409
 410
 411
 412
 413
 414
 415
 416
 417
 418
 419
 420
 421
 422
 423
 424
 425
 426
 427
 428
 429
 430
 431
 432
 433
 434
 435
 436
 437
 438
 439
 440
 441
 442
 443
 444
 445
 446
 447
 448
 449
 450
 451
 452
 453
 454
 455
 456
 457
 458
 459
 460
 461
 462
 463
 464
 465
 466
 467
 468
 469
 470
 471
 472
 473
 474
 475
 476
 477
 478
 479
 480
 481
 482
 483
 484
 485
 486
 487
 488
 489
 490
 491
 492
 493
 494
 495
 496
 497
 498
 499
 500
 501
 502
 503
 504
 505
 506
 507
 508
 509
 510
 511
 512
 513
 514
 515
 516
 517
 518
 519
 520
 521
 522
 523
 524
 525
 526
 527
 528
 529
 530
 531
 532
 533
 534
 535
 536
 537
 538
 539
 540
 541
 542
 543
 544
 545
 546
 547
 548
 549
 550
 551
 552
 553
 554
 555
 556
 557
 558
 559
 560
 561
 562
 563
 564
 565
 566
 567
 568
 569
 570
 571
 572
 573
 574
 575
 576
 577
 578
 579
 580
 581
 582
 583
 584
 585
 586
 587
 588
 589
 590
 591
 592
 593
 594
 595
 596
 597
 598
 599
 600
 601
 602
 603
 604
 605
 606
 607
 608
 609
 610
 611
 612
 613
 614
 615
 616
 617
 618
 619
 620
 621
 622
 623
 624
 625
 626
 627
 628
 629
 630
 631
 632
 633
 634
 635
 636
 637
 638
 639
 640
 641
 642
 643
 644
 645
 646
 647
 648
 649
 650
 651
 652
 653
 654
 655
 656
 657
 658
 659
 660
 661
 662
 663
 664
 665
 666
 667
 668
 669
 670
 671
 672
 673
 674
 675
 676
 677
 678
 679
 680
 681
 682
 683
 684
 685
 686
 687
 688
 689
 690
 691
 692
 693
 694
 695
 696
 697
 698
 699
 700
 701
 702
 703
 704
 705
 706
 707
 708
 709
 710
 711
 712
 713
 714
 715
 716
 717
 718
 719
 720
 721
 722
 723
 724
 725
 726
 727
 728
 729
 730
 731
 732
 733
 734
 735
 736
 737
 738
 739
 740
 741
 742
 743
 744
 745
 746
 747
 748
 749
 750
 751
 752
 753
 754
 755
 756
 757
 758
 759
 760
 761
 762
 763
 764
 765
 766
 767
 768
 769
 770
 771
 772
 773
 774
 775
 776
 777
 778
 779
 780
 781
 782
 783
 784
 785
 786
 787
 788
 789
 790
 791
 792
 793
 794
 795
 796
 797
 798
 799
 800
 801
 802
 803
 804
 805
 806
 807
 808
 809
 810
 811
 812
 813
 814
 815
 816
 817
 818
 819
 820
 821
 822
 823
 824
 825
 826
 827
 828
 829
 830
 831
 832
 833
 834
 835
 836
 837
 838
 839
 840
 841
 842
 843
 844
 845
 846
 847
 848
 849
 850
 851
 852
 853
 854
 855
 856
 857
 858
 859
 860
 861
 862
 863
 864
 865
 866
 867
 868
 869
 870
 871
 872
 873
 874
 875
 876
 877
 878
 879
 880
 881
 882
 883
 884
 885
 886
 887
 888
 889
 890
 891
 892
 893
 894
 895
 896
 897
 898
 899
 900
 901
 902
 903
 904
 905
 906
 907
 908
 909
 910
 911
 912
 913
 914
 915
 916
 917
 918
 919
 920
 921
 922
 923
 924
 925
 926
 927
 928
 929
 930
 931
 932
 933
 934
 935
 936
 937
 938
 939
 940
 941
 942
 943
 944
 945
 946
 947
 948
 949
 950
 951
 952
 953
 954
 955
 956
 957
 958
 959
 960
 961
 962
 963
 964
 965
 966
 967
 968
 969
 970
 971
 972
 973
 974
 975
 976
 977
 978
 979
 980
 981
 982
 983
 984
 985
 986
 987
 988
 989
 990
 991
 992
 993
 994
 995
 996
 997
 998
 999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
/**************************************************************************
*** COPYRIGHT (c) 2002 by TransNexus, Inc. ***
*** ***
*** This software is property of TransNexus, Inc. ***
*** This software is freely available under license from TransNexus. ***
*** The license terms and conditions for free use of this software by ***
*** third parties are defined in the OSP Toolkit Software License ***
*** Agreement (LICENSE.txt). Any use of this software by third ***
*** parties, which does not comply with the terms and conditions of the ***
*** OSP Toolkit Software License Agreement is prohibited without ***
*** the prior, express, written consent of TransNexus, Inc. ***
*** ***
*** Thank you for using the OSP ToolKit(TM). Please report any bugs, ***
*** suggestions or feedback to support@transnexus.com ***
*** ***
**************************************************************************/
/* ospdest.c - OSP destination functions */
#include "osp/osp.h"
#include "osp/osperrno.h"
#include "osp/ospbfr.h"
#include "osp/osplist.h"
#include "osp/ospxmlattr.h"
#include "osp/ospxmlelem.h"
#include "osp/ospmsgattr.h"
#include "osp/ospmsgelem.h"
#include "osp/ospcallid.h"
#include "osp/osptoken.h"
#include "osp/ospdest.h"
#include "osp/ospusage.h"
#include "osp/ospaltinfo.h"
/* Array that associates protocols and names */
const OSPT_MSG_DESC OSPV_PROTNAME_DESCS[OSPC_PROTNAME_NUMBER] = {
{ OSPC_PROTNAME_SIP, "sip" },
{ OSPC_PROTNAME_Q931, "h323-Q931" },
{ OSPC_PROTNAME_LRQ, "h323-LRQ" },
{ OSPC_PROTNAME_IAX, "iax" },
{ OSPC_PROTNAME_T37, "fax-T37" },
{ OSPC_PROTNAME_T38, "fax-T38" },
{ OSPC_PROTNAME_SKYPE, "skype" },
{ OSPC_PROTNAME_SMPP, "smpp" },
{ OSPC_PROTNAME_XMPP, "xmpp" },
{ OSPC_PROTNAME_SMS, "sms" }
};
/*
* OSPPDestSetOSPVersion() - set the OSP Version for a destination
*/
void OSPPDestSetOSPVersion( /* nothing returned */
OSPT_DEST *ospvDest, /* destination to set */
const char *ospvVersion) /* Version (as string) */
{
if (ospvDest != OSPC_OSNULL) {
if (!(OSPM_STRCMP(ospvVersion, DEST_OSP_DIABLED))) {
ospvDest->OSPVersion = OSPC_DOSP_FALSE;
} else {
if (!(OSPM_STRCMP(ospvVersion, DEST_OSP_UNKNOWN))) {
ospvDest->OSPVersion = OSPC_DOSP_UNKNOWN;
} else {
ospvDest->OSPVersion = OSPC_DOSP_TRUE;
}
}
}
}
/*
* OSPPDestSetProtocol() - set the protocol for a destination
*/
void OSPPDestSetProtocol( /* Nothing returned */
OSPT_DEST *ospvDest, /* Destination to set */
const char *ospvProt) /* Protocol (as string) */
{
if (ospvDest != OSPC_OSNULL) {
ospvDest->Protocol = OSPPDestProtocolGetPart(ospvProt);
}
}
/*
* OSPPDestHasNumber() - does the destination include a called number?
*/
OSPTBOOL OSPPDestHasNumber( /* returns non-zero if number exists */
OSPT_DEST *ospvDest) /* destination effected */
{
OSPTBOOL has = OSPC_FALSE;
if (ospvDest != OSPC_OSNULL) {
has = (ospvDest->DestinationNumber[0] != '\0');
}
return has;
}
/*
* OSPPDestHasSrcNumber() - does the destination include a calling number?
*/
OSPTBOOL OSPPDestHasSrcNumber( /* returns non-zero if number exists */
OSPT_DEST *ospvDest) /* destination effected */
{
OSPTBOOL has = OSPC_FALSE;
if (ospvDest != OSPC_OSNULL) {
has = (ospvDest->SourceNumber[0] != '\0');
}
return has;
}
/*
* OSPPDestSetSrcNumber() - set the calling number for a destination
*/
void OSPPDestSetSrcNumber( /* nothing returned */
OSPT_DEST *ospvDest, /* destination to set */
const char *ospvNum) /* calling number (as string) */
{
if (ospvDest != OSPC_OSNULL) {
if (ospvNum != OSPC_OSNULL) {
OSPM_MEMCPY(ospvDest->SourceNumber, ospvNum, tr_min(OSPC_SIZE_E164NUM, OSPM_STRLEN(ospvNum) + 1));
}
}
}
/*
* OSPPDestGetSrcNumber() - returns the calling number for a destination
*/
const char *OSPPDestGetSrcNumber( /* returns number as string */
OSPT_DEST *ospvDest) /* destination */
{
const char *num = OSPC_OSNULL;
if (ospvDest != OSPC_OSNULL) {
num = ospvDest->SourceNumber;
}
return num;
}
/*
* OSPPDestSetNumber() - set the called number for a destination
*/
void OSPPDestSetNumber( /* nothing returned */
OSPT_DEST *ospvDest, /* destination to set */
const char *ospvNum) /* called number (as string) */
{
if (ospvDest != OSPC_OSNULL) {
if (ospvNum != OSPC_OSNULL) {
OSPM_MEMCPY(ospvDest->DestinationNumber, ospvNum, tr_min(OSPC_SIZE_E164NUM, OSPM_STRLEN(ospvNum) + 1));
}
}
}
/*
* OSPPDestGetNumber() - returns the called number for a destination
*/
const char *OSPPDestGetNumber( /* returns number as string */
OSPT_DEST *ospvDest) /* destination */
{
const char *num = OSPC_OSNULL;
if (ospvDest != OSPC_OSNULL) {
num = ospvDest->DestinationNumber;
}
return num;
}
/*
* OSPPDestHasAddr() - does a destination have a Addr?
*/
OSPTBOOL OSPPDestHasAddr( /* returns non-zero if exists */
OSPT_DEST *ospvDest) /* destination in question */
{
OSPTBOOL has = OSPC_FALSE;
if (ospvDest != OSPC_OSNULL) {
has = (ospvDest->DestinationAddr[0] != '\0');
}
return has;
}
/*
* OSPPDestSetAddr() - sets the signalling address for a destination
*/
void OSPPDestSetAddr( /* nothing returned */
OSPT_DEST *ospvDest, /* destination */
const char *ospvAddr) /* signal address as string */
{
if (ospvDest != OSPC_OSNULL) {
if (ospvAddr != OSPC_OSNULL) {
OSPM_MEMCPY(ospvDest->DestinationAddr, ospvAddr, tr_min(OSPC_SIZE_SIGNALADDR, OSPM_STRLEN(ospvAddr) + 1));
}
}
}
/*
* OSPPDestGetAddr() - returns the signalling address for a destination
*/
const char *OSPPDestGetAddr( /* returns address as string */
OSPT_DEST *ospvDest) /* destination in question */
{
const char *addr = OSPC_OSNULL;
if (ospvDest != OSPC_OSNULL) {
addr = ospvDest->DestinationAddr;
}
return addr;
}
/*
* OSPPDestDevHasAddr() - does a destination have a Dev Addr?
*/
OSPTBOOL OSPPDestDevHasAddr( /* returns non-zero if exists */
OSPT_DEST *ospvDest) /* destination in question */
{
OSPTBOOL has = OSPC_FALSE;
if (ospvDest != OSPC_OSNULL) {
has = (ospvDest->DestinationDevAddr[0] != '\0');
}
return has;
}
/*
* OSPPDestHasNetworkAddr() - does a destination have a Network Addr?
*/
OSPTBOOL OSPPDestHasNetworkAddr( /* returns non-zero if exists */
OSPT_DEST *ospvDest) /* destination in question */
{
OSPTBOOL has = OSPC_FALSE;
if (ospvDest != OSPC_OSNULL) {
has = (ospvDest->NetworkId[0] != '\0');
}
return has;
}
/*
* OSPPDestSetNetworkAddr() - sets the network address for a destination
* device
*/
void OSPPDestSetNetworkAddr( /* nothing returned */
OSPT_DEST *ospvDest, /* destination */
const char *ospvAddr) /* network address as string */
{
if (ospvDest != OSPC_OSNULL) {
if (ospvAddr != OSPC_OSNULL) {
OSPM_MEMCPY(ospvDest->NetworkId, ospvAddr, tr_min(OSPC_SIZE_NORID, OSPM_STRLEN(ospvAddr) + 1));
}
}
}
/*
* OSPPDestGetNetworkAddr() - returns the network address for a destination device
*/
const char *OSPPDestGetNetworkAddr( /* returns address as string */
OSPT_DEST *ospvDest) /* destination in question */
{
const char *nid = OSPC_OSNULL;
if (ospvDest != OSPC_OSNULL) {
nid = ospvDest->NetworkId;
}
return nid;
}
/*
* OSPPDestDevSetAddr() - sets the signalling address for a destination device
*/
void OSPPDestDevSetAddr( /* nothing returned */
OSPT_DEST *ospvDest, /* destination */
const char *ospvAddr) /* signal address as string */
{
if (ospvDest != OSPC_OSNULL) {
if (ospvAddr != OSPC_OSNULL) {
OSPM_MEMCPY(ospvDest->DestinationDevAddr, ospvAddr, tr_min(OSPC_SIZE_SIGNALADDR, OSPM_STRLEN(ospvAddr) + 1));
}
}
}
/*
* OSPPDestDevGetAddr() - returns the signaling address for a destination device
*/
const char *OSPPDestDevGetAddr( /* returns address as string */
OSPT_DEST *ospvDest) /* destination in question */
{
const char *addr = OSPC_OSNULL;
if (ospvDest != OSPC_OSNULL) {
addr = ospvDest->DestinationDevAddr;
}
return addr;
}
/*
* OSPPDestHasValidAfter() - Does a destination have a valid after time?
*/
OSPTBOOL OSPPDestHasValidAfter( /* returns non-zero if time */
OSPT_DEST *ospvDest) /* destination in question */
{
OSPTBOOL has = OSPC_FALSE;
if (ospvDest != OSPC_OSNULL) {
has = (ospvDest->ValidAfter != OSPC_TIMEMIN);
}
return has;
}
/*
* OSPPDestSetValidAfter() - sets the valid after time for a destination
*/
void OSPPDestSetValidAfter( /* nothing returned */
OSPT_DEST *ospvDest,
OSPTTIME ospvTime)
{
if (ospvDest != OSPC_OSNULL) {
ospvDest->ValidAfter = (ospvTime);
}
}
/*
* OSPPDestGetValidAfter() - returns valid after time for a destination
*/
OSPTTIME OSPPDestGetValidAfter( /* returns the time value */
OSPT_DEST *ospvDest) /* destination in question */
{
OSPTTIME time = 0;
if (ospvDest != OSPC_OSNULL) {
time = ospvDest->ValidAfter;
}
return time;
}
/*
* OSPPDestHasValidUntil() - does destination have a valid until time?
*/
OSPTBOOL OSPPDestHasValidUntil( /* returns non-zero if time */
OSPT_DEST *ospvDest) /* destination in question */
{
OSPTBOOL has = OSPC_FALSE;
if (ospvDest != OSPC_OSNULL) {
has = (ospvDest->ValidUntil != OSPC_TIMEMAX);
}
return has;
}
/*
* OSPPDestSetValidUntil() - sets valid until time for destination
*/
void OSPPDestSetValidUntil( /* nothing returned */
OSPT_DEST *ospvDest, /* destination in question */
OSPTTIME ospvTime) /* time to set */
{
if (ospvDest != OSPC_OSNULL) {
ospvDest->ValidUntil = ospvTime;
}
}
/*
* OSPPDestGetValidUntil() - returns valid until time for destination
*/
OSPTTIME OSPPDestGetValidUntil( /* returns time */
OSPT_DEST *ospvDest) /* destination in question */
{
OSPTTIME time = 0;
if (ospvDest != OSPC_OSNULL) {
time = ospvDest->ValidUntil;
}
return time;
}
/*
* OSPPDestHasAuthority() - does an authority URL exist for destination?
*/
OSPTBOOL OSPPDestHasAuthority( /* returns non-zero if exists */
OSPT_DEST *ospvDest) /* destination in question */
{
OSPTBOOL has = OSPC_FALSE;
if (ospvDest != OSPC_OSNULL) {
has = (ospvDest->Authority[0] != '\0');
}
return has;
}
/*
* OSPPDestSetAuthority() - sets authority URL for destination
*/
void OSPPDestSetAuthority( /* nothing returned */
OSPT_DEST *ospvDest, /* destination in question */
const char *ospvAuth) /* authority URL */
{
if (ospvDest != OSPC_OSNULL) {
if (ospvAuth != OSPC_OSNULL) {
OSPM_STRNCPY(ospvDest->Authority, ospvAuth, tr_min(OSPM_STRLEN(ospvAuth) + 1, OSPC_SIZE_URL - 1));
}
}
}
/*
* OSPPDestHasCallId() - does a destination have a Call ID?
*/
OSPTBOOL OSPPDestHasCallId( /* returns non-zero if exists */
OSPT_DEST *ospvDest) /* destination in question */
{
OSPTBOOL has = OSPC_FALSE;
if (ospvDest != OSPC_OSNULL) {
has = (ospvDest->CallId != OSPC_OSNULL);
}
return has;
}
/*
* OSPPDestGetCallId() - gets the call ID for a destination
*/
OSPT_CALL_ID *OSPPDestGetCallId(/* returns call ID pointer */
OSPT_DEST *ospvDest) /* destination in question */
{
OSPT_CALL_ID *callid = OSPC_OSNULL;
if (ospvDest != OSPC_OSNULL) {
callid = ospvDest->CallId;
}
return callid;
}
/*
* OSPPDestHasToken() - does a destination have a Token?
*/
OSPTBOOL OSPPDestHasToken( /* returns non-zero if exists */
OSPT_DEST *ospvDest) /* destination in question */
{
OSPTBOOL has = OSPC_FALSE;
if (ospvDest != OSPC_OSNULL) {
has = (OSPPListFirst(&(ospvDest->Tokens)) != OSPC_OSNULL);
}
return has;
}
/*
* OSPPDestAddToken() - adds a token to a destination
*/
void OSPPDestAddToken( /* nothing returned */
OSPT_DEST *ospvDest, /* destination in question */
OSPT_TOKEN *ospvToken) /* token to add */
{
if (ospvDest != OSPC_OSNULL) {
OSPPListAppend(&(ospvDest->Tokens), ospvToken);
}
}
/*
* OSPPDestFirstToken() - gets first token for destination
*/
OSPT_TOKEN *OSPPDestFirstToken( /* returns null if none */
OSPT_DEST *ospvDest)
{
OSPT_TOKEN *token = OSPC_OSNULL;
if (ospvDest != OSPC_OSNULL) {
token = (OSPT_TOKEN *)OSPPListFirst(&ospvDest->Tokens);
}
return token;
}
/*
* OSPPDestNextToken() - gets next token (in list) for destination
*/
OSPT_TOKEN *OSPPDestNextToken( /* returns NULL if no more */
OSPT_DEST *ospvDest, /* destination in question */
OSPT_TOKEN *ospvToken) /* current token */
{
OSPT_TOKEN *token = OSPC_OSNULL;
if (ospvDest != OSPC_OSNULL) {
if (ospvToken != OSPC_OSNULL) {
token = (OSPT_TOKEN *)OSPPListNext(&ospvDest->Tokens, ospvToken);
}
}
return token;
}
/*
* OSPPDestHasLimit() - does a destination have a usage limit?
*/
OSPTBOOL OSPPDestHasLimit( /* returns non-zero if limit */
OSPT_DEST *ospvDest) /* destination in question */
{
OSPTBOOL has = OSPC_FALSE;
if (ospvDest != OSPC_OSNULL) {
has = ospvDest->HasLimit;
}
return has;
}
/*
* OSPPDestSetLimit() - sets usage limit for a destination
*/
void OSPPDestSetLimit( /* nothing returned */
OSPT_DEST *ospvDest, /* destination in question */
unsigned ospvLimit) /* limit to set */
{
if (ospvDest != OSPC_OSNULL) {
ospvDest->Limit = ospvLimit;
ospvDest->HasLimit = OSPC_TRUE;
}
}
/*
* OSPPDestGetLimit() - returns the usage limit for a destination
*/
unsigned OSPPDestGetLimit( /* returns usage limit */
OSPT_DEST *ospvDest) /* destination in question */
{
unsigned limit = 0;
if (ospvDest != OSPC_OSNULL) {
limit = ospvDest->Limit;
}
return limit;
}
/*
* OSPPDestHasTermCause() - Does destination have the Fail Reason
*/
OSPTBOOL OSPPDestHasTermCause( /* Returns non-zero if time */
OSPT_DEST *ospvDest, /* Destination in question */
OSPE_TERM_CAUSE ospvType) /* Termination cause type */
{
OSPTBOOL has = OSPC_FALSE;
if (ospvDest != OSPC_OSNULL) {
has = OSPPHasTermCause(&ospvDest->TermCause, ospvType);
}
return has;
}
/*
* OSPPDestHasTermCauseAny() - Does dest have a Fail Reason
*/
OSPTBOOL OSPPDestHasTermCauseAny( /* returns non-zero if time */
OSPT_DEST *ospvDest) /* dest in question */
{
OSPTBOOL has = OSPC_FALSE;
if (ospvDest != OSPC_OSNULL) {
has = OSPPHasTermCauseAny(&ospvDest->TermCause);
}
return has;
}
/*
* OSPPDestSetTermCause() - Set Fail Reason
*/
void OSPPDestSetTermCause( /* nothing returned */
OSPT_DEST *ospvDest,
OSPE_TERM_CAUSE ospvType,
unsigned ospvTCCode,
const char *ospvTCDesc)
{
if (ospvDest != OSPC_OSNULL) {
OSPPSetTermCause(&ospvDest->TermCause, ospvType, ospvTCCode, ospvTCDesc);
}
}
/*
* OSPPDestGetTermCause() - returns Fail Reason structure for an destination
*/
OSPT_TERM_CAUSE *OSPPDestGetTermCause(
OSPT_DEST *ospvDest) /* destination */
{
OSPT_TERM_CAUSE *cause = OSPC_OSNULL;
if (ospvDest != OSPC_OSNULL) {
cause = &ospvDest->TermCause;
}
return cause;
}
/*
* OSPPDestGetTCCode() - returns Fail Reason value for an destination
*/
unsigned OSPPDestGetTCCode(
OSPT_DEST *ospvDest, /* destination */
OSPE_TERM_CAUSE ospvType) /* fail reason type */
{
unsigned code = 0;
if (ospvDest != OSPC_OSNULL) {
code = OSPPGetTCCode(&ospvDest->TermCause, ospvType);
}
return code;
}
/*
* OSPPDestGetTCDesc() - returns Fail Reason description for an destination
*/
const char *OSPPDestGetTCDesc(
OSPT_DEST *ospvDest, /* destination */
OSPE_TERM_CAUSE ospvType) /* fail reason type */
{
const char *desc = OSPC_OSNULL;
if (ospvDest != OSPC_OSNULL) {
desc = OSPPGetTCDesc(&ospvDest->TermCause, ospvType);
}
return desc;
}
/*
* OSPPDestNew() - creates a new (empty) destination
*/
OSPT_DEST *OSPPDestNew(void) /* returns pointer or NULL */
{
OSPT_DEST *dest = OSPC_OSNULL;
OSPM_MALLOC(dest, OSPT_DEST, sizeof(OSPT_DEST));
if (dest != OSPC_OSNULL) {
/* start with setting all to 0 */
OSPM_MEMSET(dest, 0, sizeof(OSPT_DEST));
OSPPListLinkNew(&(dest->Link));
dest->ValidAfter = OSPC_TIMEMIN;
dest->ValidUntil = OSPC_TIMEMAX;
dest->Protocol = OSPC_PROTNAME_UNDEFINED;
dest->OSPVersion = OSPC_DOSP_UNDEFINED;
OSPPListNew(&(dest->Tokens));
OSPPListNew(&(dest->UpdatedSourceAddr));
OSPPListNew(&(dest->UpdatedDeviceInfo));
dest->HasLimit = OSPC_FALSE;
dest->Count = 0;
dest->SetupAttempt = -1;
dest->RoleState = OSPC_RSTATE_UNKNOWN;
dest->RoleFormat = OSPC_RFORMAT_UNKNOWN;
dest->RoleVendor = OSPC_RVENDOR_UNKNOWN;
dest->TransferStatus = OSPC_TSTATUS_UNKNOWN;
dest->ProviderPDD = -1;
dest->ServiceType = OSPC_SERVICE_UNKNOWN;
}
return dest;
}
/*
* OSPPDestDelete() - deletes a Destination structure
*/
void OSPPDestDelete(
OSPT_DEST **ospvDest)
{
OSPT_TOKEN *tmptoken = OSPC_OSNULL;
OSPT_ALTINFO *altinfo = OSPC_OSNULL;
if (*ospvDest != OSPC_OSNULL) {
/* first delete the callid */
if (((*ospvDest)->CallId) != OSPC_OSNULL) {
OSPPCallIdDelete(&((*ospvDest)->CallId));
}
while (!OSPPListEmpty((OSPTLIST *)&((*ospvDest)->Tokens))) {
tmptoken = (OSPT_TOKEN *)OSPPListRemove((OSPTLIST *)&((*ospvDest)->Tokens));
if (tmptoken != OSPC_OSNULL) {
OSPPTokenDelete(&tmptoken);
}
}
OSPPListDelete((OSPTLIST *)&((*ospvDest)->Tokens));
while (!OSPPListEmpty((OSPTLIST *)&((*ospvDest)->UpdatedSourceAddr))) {
altinfo = (OSPT_ALTINFO *)OSPPListRemove((OSPTLIST *)&((*ospvDest)->UpdatedSourceAddr));
if (altinfo != OSPC_OSNULL) {
OSPM_FREE(altinfo);
altinfo = OSPC_OSNULL;
}
}
OSPPListDelete((OSPTLIST *)&((*ospvDest)->UpdatedSourceAddr));
while (!OSPPListEmpty((OSPTLIST *)&((*ospvDest)->UpdatedDeviceInfo))) {
altinfo = (OSPT_ALTINFO *)OSPPListRemove((OSPTLIST *)&((*ospvDest)->UpdatedDeviceInfo));
if (altinfo != OSPC_OSNULL) {
OSPM_FREE(altinfo);
altinfo = OSPC_OSNULL;
}
}
OSPPListDelete((OSPTLIST *)&((*ospvDest)->UpdatedDeviceInfo));
/* finally delete the object */
OSPM_FREE(*ospvDest);
*ospvDest = OSPC_OSNULL;
}
}
/*
* OSPPDestFromElement() - get destination from an XML element
*/
int OSPPDestFromElement( /* returns error code */
OSPT_XML_ELEM *ospvElem, /* input is XML element */
OSPT_DEST **ospvDest) /* where to put destination pointer */
{
int error = OSPC_ERR_NO_ERROR;
OSPT_XML_ELEM *elem = OSPC_OSNULL;
OSPT_DEST *dest = OSPC_OSNULL;
OSPT_TOKEN *token = OSPC_OSNULL;
OSPT_CALL_ID *callid = OSPC_OSNULL;
unsigned long failure = 0L;
OSPTTIME t = 0L;
if (ospvElem == OSPC_OSNULL) {
error = OSPC_ERR_XML_NO_ELEMENT;
}
if (ospvDest == OSPC_OSNULL) {
error = OSPC_ERR_DATA_NO_DEST;
}
if (error == OSPC_ERR_NO_ERROR) {
/* create the destination object */
dest = OSPPDestNew();
if (dest == OSPC_OSNULL) {
error = OSPC_ERR_DATA_NO_DEST;
}
/*
* The Destination element should consist of several child
* elements. We'll run through what's there and pick out
* the information we need.
*/
for (elem = OSPPXMLElemFirstChild(ospvElem);
(elem != OSPC_OSNULL) && (error == OSPC_ERR_NO_ERROR);
elem = OSPPXMLElemNextChild(ospvElem, elem))
{
switch (OSPPMsgElemGetPart(OSPPXMLElemGetName(elem))) {
case OSPC_MELEM_PROTOCOL:
OSPPDestProtocolFromElement(elem, dest);
break;
case OSPC_MELEM_DESTOSPVERSION:
OSPPDestSetOSPVersion(dest, OSPPXMLElemGetValue(elem));
break;
case OSPC_MELEM_SRCINFO:
OSPPSrcInfoFromElement(elem, dest);
break;
case OSPC_MELEM_DESTINFO:
OSPPDestInfoFromElement(elem, dest);
break;
case OSPC_MELEM_DESTALT:
OSPPDestSetNetworkAddr(dest, OSPPXMLElemGetValue(elem));
break;
case OSPC_MELEM_DESTSIGADDR:
OSPPDestSetAddr(dest, OSPPXMLElemGetValue(elem));
break;
case OSPC_MELEM_TOKEN:
if ((error = OSPPTokenFromElement(elem, &token)) == OSPC_ERR_NO_ERROR) {
OSPPDestAddToken(dest, token);
}
break;
case OSPC_MELEM_VALIDAFTER:
t = 0;
if (*(OSPPXMLElemGetValue(elem)) != 0) {
error = OSPPMsgTimeFromElement(elem, &t);
} else {
t = OSPC_TIMEMIN;
}
if (error == OSPC_ERR_NO_ERROR) {
OSPPDestSetValidAfter(dest, t);
}
break;
case OSPC_MELEM_VALIDUNTIL:
t = 0;
if (*(OSPPXMLElemGetValue(elem)) != 0) {
error = OSPPMsgTimeFromElement(elem, &t);
} else {
t = OSPC_TIMEMAX;
}
if (error == OSPC_ERR_NO_ERROR) {
OSPPDestSetValidUntil(dest, t);
}
break;
case OSPC_MELEM_USAGEDETAIL:
error = OSPPUsageDetailFromElement(elem, dest);
break;
case OSPC_MELEM_AUTHURL:
OSPPDestSetAuthority(dest, OSPPXMLElemGetValue(elem));
break;
case OSPC_MELEM_CALLID:
if ((error = OSPPCallIdFromElement(elem, &callid)) == OSPC_ERR_NO_ERROR) {
OSPPDestSetCallId(dest, callid->Value, callid->Length);
OSPPCallIdDelete(&callid);
}
break;
case OSPC_MELEM_TERMCAUSE:
if ((error = OSPPMsgNumFromElement(elem, &failure)) == OSPC_ERR_NO_ERROR) {
OSPPDestSetTermCause(dest, OSPC_TCAUSE_Q850, (unsigned)failure, OSPC_OSNULL);
}
break;
default:
/*
* This is an element we don't understand. If it's
* critical, then we have to report an error.
* Otherwise we can ignore it.
*/
if (OSPPMsgElemIsCritical(elem)) {
error = OSPC_ERR_XML_BAD_ELEMENT;
}
break;
}
}
if (error == OSPC_ERR_NO_ERROR) {
*ospvDest = dest;
}
}
return error;
}
/*
* OSPPDestSetCallId() - sets the call ID for a destination
*/
void OSPPDestSetCallId( /* nothing returned */
OSPT_DEST *ospvDest, /* destination */
const unsigned char *ospvValue, /* call ID value */
unsigned ospvLen)
{
if (ospvDest != OSPC_OSNULL) {
if (ospvValue != OSPC_OSNULL) {
if (ospvDest->CallId != OSPC_OSNULL) {
OSPPCallIdDelete(&(ospvDest->CallId));
}
ospvDest->CallId = OSPPCallIdNew(ospvLen, ospvValue);
}
}
}
void OSPPDestSetDestinationCount(
OSPT_DEST *ospvDest,
unsigned ospvCount)
{
if (ospvDest != OSPC_OSNULL) {
ospvDest->Count = ospvCount;
}
}
unsigned OSPPDestGetDestinationCount(
OSPT_DEST *ospvDest)
{
unsigned count = 0;
if (ospvDest != OSPC_OSNULL) {
count = ospvDest->Count;
}
return count;
}
void OSPPDestSetSetupAttempt(
OSPT_DEST *ospvDest,
int ospvAttempt)
{
if (ospvDest != OSPC_OSNULL) {
ospvDest->SetupAttempt = ospvAttempt;
}
}
int OSPPDestGetSetupAttempt(
OSPT_DEST *ospvDest)
{
int attempt = -1;
if (ospvDest != OSPC_OSNULL) {
attempt = ospvDest->SetupAttempt;
}
return attempt;
}
OSPE_PROTOCOL_NAME OSPPDestProtocolGetPart(
const char *ospvName)
{
OSPE_PROTOCOL_NAME part = OSPC_PROTNAME_UNKNOWN;
if (ospvName != OSPC_OSNULL) {
part = (OSPE_PROTOCOL_NAME)OSPPMsgDescGetPart(ospvName, OSPV_PROTNAME_DESCS, OSPC_PROTNAME_NUMBER);
}
return part;
}
const char *OSPPDestProtocolGetName(
OSPE_PROTOCOL_NAME ospvPart)
{
const char *name = OSPC_OSNULL;
if ((ospvPart >= OSPC_PROTNAME_START) && (ospvPart < OSPC_PROTNAME_NUMBER)) {
name = OSPPMsgDescGetName((OSPT_MSG_PART)ospvPart, OSPV_PROTNAME_DESCS, OSPC_PROTNAME_NUMBER);
}
return name;
}
void OSPPDestProtocolFromElement(
OSPT_XML_ELEM *ospvElem,
OSPT_DEST *ospvDest)
{
OSPT_XML_ATTR* attr = OSPC_OSNULL;
OSPE_ALTINFO type = OSPC_ALTINFO_DESTINATION;
for (attr = (OSPT_XML_ATTR*)OSPPXMLElemFirstAttr(ospvElem);
(attr != OSPC_OSNULL);
attr = (OSPT_XML_ATTR*)OSPPXMLElemNextAttr(ospvElem, attr))
{
if (OSPPMsgAttrGetPart(OSPPXMLAttrGetName(attr)) == OSPC_MATTR_TYPE) {
type = OSPPAltInfoTypeGetPart(OSPPXMLAttrGetValue(attr));
}
}
switch (type) {
case OSPC_ALTINFO_DESTINATION:
case OSPC_ALTINFO_NA:
OSPPDestSetProtocol(ospvDest, OSPPXMLElemGetValue(ospvElem));
break;
case OSPC_ALTINFO_SOURCE:
default:
break;
}
}
void OSPPSrcInfoFromElement(
OSPT_XML_ELEM *ospvElem,
OSPT_DEST *ospvDest)
{
OSPT_XML_ATTR* attr = OSPC_OSNULL;
for (attr = (OSPT_XML_ATTR*)OSPPXMLElemFirstAttr(ospvElem);
(attr != OSPC_OSNULL);
attr = (OSPT_XML_ATTR*)OSPPXMLElemNextAttr(ospvElem, attr))
{
if (OSPPMsgAttrGetPart(OSPPXMLAttrGetName(attr)) == OSPC_MATTR_TYPE) {
switch (OSPPAltInfoTypeGetPart(OSPPXMLAttrGetValue(attr))) {
case OSPC_ALTINFO_E164:
OSPPDestSetSrcNumber(ospvDest, OSPPXMLElemGetValue(ospvElem));
break;
case OSPC_ALTINFO_CNAM:
OSPM_STRNCPY(ospvDest->CNAM, OSPPXMLElemGetValue(ospvElem), sizeof(ospvDest->CNAM) - 1);
break;
default:
break;
}
}
}
}
void OSPPDestInfoFromElement(
OSPT_XML_ELEM *ospvElem,
OSPT_DEST *ospvDest)
{
OSPT_XML_ATTR* attr = OSPC_OSNULL;
for (attr = (OSPT_XML_ATTR*)OSPPXMLElemFirstAttr(ospvElem);
(attr != OSPC_OSNULL);
attr = (OSPT_XML_ATTR*)OSPPXMLElemNextAttr(ospvElem, attr))
{
if (OSPPMsgAttrGetPart(OSPPXMLAttrGetName(attr)) == OSPC_MATTR_TYPE) {
switch (OSPPAltInfoTypeGetPart(OSPPXMLAttrGetValue(attr))) {
case OSPC_ALTINFO_E164:
OSPM_STRNCPY(ospvDest->DestinationNumber, OSPPXMLElemGetValue(ospvElem), sizeof(ospvDest->DestinationNumber) - 1);
break;
case OSPC_ALTINFO_NPRN:
OSPM_STRNCPY(ospvDest->NPRn, OSPPXMLElemGetValue(ospvElem), sizeof(ospvDest->NPRn) - 1);
break;
case OSPC_ALTINFO_NPCIC:
OSPM_STRNCPY(ospvDest->NPCic, OSPPXMLElemGetValue(ospvElem), sizeof(ospvDest->NPCic) - 1);
break;
case OSPC_ALTINFO_NPDI:
if (OSPM_STRCASECMP(OSPPXMLElemGetValue(ospvElem), OSPPAltInfoTypeGetName(OSPC_ALTINFO_TRUE)) == 0) {
ospvDest->NPNpdi = OSPC_TRUE;
} else {
ospvDest->NPNpdi = OSPC_FALSE;
}
break;
case OSPC_ALTINFO_SPID:
OSPM_STRNCPY(ospvDest->OpName[OSPC_OPNAME_SPID], OSPPXMLElemGetValue(ospvElem), sizeof(ospvDest->OpName[OSPC_OPNAME_SPID]) - 1);
break;
case OSPC_ALTINFO_OCN:
OSPM_STRNCPY(ospvDest->OpName[OSPC_OPNAME_OCN], OSPPXMLElemGetValue(ospvElem), sizeof(ospvDest->OpName[OSPC_OPNAME_OCN]) - 1);
break;
case OSPC_ALTINFO_SPN:
OSPM_STRNCPY(ospvDest->OpName[OSPC_OPNAME_SPN], OSPPXMLElemGetValue(ospvElem), sizeof(ospvDest->OpName[OSPC_OPNAME_SPN]) - 1);
break;
case OSPC_ALTINFO_ALTSPN:
OSPM_STRNCPY(ospvDest->OpName[OSPC_OPNAME_ALTSPN], OSPPXMLElemGetValue(ospvElem), sizeof(ospvDest->OpName[OSPC_OPNAME_ALTSPN]) - 1);
break;
case OSPC_ALTINFO_MCC:
OSPM_STRNCPY(ospvDest->OpName[OSPC_OPNAME_MCC], OSPPXMLElemGetValue(ospvElem), sizeof(ospvDest->OpName[OSPC_OPNAME_MCC]) - 1);
break;
case OSPC_ALTINFO_MNC:
OSPM_STRNCPY(ospvDest->OpName[OSPC_OPNAME_MNC], OSPPXMLElemGetValue(ospvElem), sizeof(ospvDest->OpName[OSPC_OPNAME_MNC]) - 1);
break;
case OSPC_ALTINFO_SIP:
OSPM_STRNCPY(ospvDest->URL[OSPC_URL_SIP], OSPPXMLElemGetValue(ospvElem), sizeof(ospvDest->URL[OSPC_URL_SIP]) - 1);
break;
case OSPC_ALTINFO_SMS:
OSPM_STRNCPY(ospvDest->URL[OSPC_URL_SMS], OSPPXMLElemGetValue(ospvElem), sizeof(ospvDest->URL[OSPC_URL_SMS]) - 1);
break;
case OSPC_ALTINFO_MMS:
OSPM_STRNCPY(ospvDest->URL[OSPC_URL_MMS], OSPPXMLElemGetValue(ospvElem), sizeof(ospvDest->URL[OSPC_URL_MMS]) - 1);
break;
default:
break;
}
}
}
}
int OSPPUsageDetailFromElement(
OSPT_XML_ELEM *ospvElem,
OSPT_DEST *ospvDest)
{
int error = OSPC_ERR_NO_ERROR;
OSPT_XML_ELEM *elem = OSPC_OSNULL;
OSPTBOOL hasamount = OSPC_FALSE;
OSPTBOOL hasincrement = OSPC_FALSE;
OSPTBOOL hasunit = OSPC_FALSE;
unsigned long amount = 0;
unsigned long increment = 0;
if (ospvElem == OSPC_OSNULL) {
error = OSPC_ERR_XML_NO_ELEMENT;
}
if (error == OSPC_ERR_NO_ERROR) {
if (ospvDest == OSPC_OSNULL) {
error = OSPC_ERR_DATA_NO_DEST;
}
}
if (error == OSPC_ERR_NO_ERROR) {
for (elem = OSPPXMLElemFirstChild(ospvElem);
(elem != OSPC_OSNULL) && (error == OSPC_ERR_NO_ERROR);
elem = OSPPXMLElemNextChild(ospvElem, elem))
{
switch (OSPPMsgElemGetPart(OSPPXMLElemGetName(elem))) {
case OSPC_MELEM_AMOUNT:
if ((error = OSPPMsgNumFromElement(elem, &amount)) == OSPC_ERR_NO_ERROR) {
hasamount = OSPC_TRUE;
}
break;
case OSPC_MELEM_INCREMENT:
if ((error = OSPPMsgNumFromElement(elem, &increment)) == OSPC_ERR_NO_ERROR) {
hasincrement = OSPC_TRUE;
}
break;
case OSPC_MELEM_UNIT:
/* The only unit we support is seconds. If this is different, then we declare an error. */
if (OSPM_STRCMP(OSPPXMLElemGetValue(elem), "s") != 0) {
error = OSPC_ERR_BAD_SERVICE;
} else {
hasunit = OSPC_TRUE;
}
break;
case OSPC_MELEM_SERVICE:
OSPPServiceFromElement(elem, ospvDest);
break;
default:
/*
* This is an element we don't understand. If it's
* critical, then we have to report an error.
* Otherwise we can ignore it.
*/
if (OSPPMsgElemIsCritical(elem)) {
error = OSPC_ERR_XML_BAD_ELEMENT;
}
break;
}
}
}
if (error == OSPC_ERR_NO_ERROR) {
if (hasamount && hasincrement && hasunit) {
OSPPDestSetLimit(ospvDest, (unsigned)(increment * amount));
} else {
if ((ospvDest->ServiceType == OSPC_SERVICE_NPQUERY) || (ospvDest->ServiceType == OSPC_SERVICE_CNAMQUERY)) {
OSPPDestSetLimit(ospvDest, 0);
} else {
error = OSPC_ERR_XML_BAD_ELEMENT;
}
}
}
return error;
}
void OSPPServiceFromElement(
OSPT_XML_ELEM *ospvElem,
OSPT_DEST *ospvDest)
{
int error = OSPC_ERR_NO_ERROR;
OSPT_XML_ELEM *elem = OSPC_OSNULL;
OSPT_XML_ATTR* attr = OSPC_OSNULL;
for (elem = OSPPXMLElemFirstChild(ospvElem);
(elem != OSPC_OSNULL) && (error == OSPC_ERR_NO_ERROR);
elem = OSPPXMLElemNextChild(ospvElem, elem))
{
switch (OSPPMsgElemGetPart(OSPPXMLElemGetName(elem))) {
case OSPC_MELEM_SERVICETYPE:
for (attr = OSPPXMLElemFirstAttr(elem); (attr != OSPC_OSNULL); attr = OSPPXMLElemNextAttr(elem, attr)) {
if (OSPPMsgAttrGetPart(OSPPXMLAttrGetName(attr)) == OSPC_MATTR_TYPE) {
ospvDest->ServiceType = OSPPServiceGetPart(OSPPXMLAttrGetValue(attr));
break;
}
}
break;
default:
break;
}
}
}