1
/**************************************************************************
2
*** COPYRIGHT (c) 2002 by TransNexus, Inc. ***
4
*** This software is property of TransNexus, Inc. ***
5
*** This software is freely available under license from TransNexus. ***
6
*** The license terms and conditions for free use of this software by ***
7
*** third parties are defined in the OSP Toolkit Software License ***
8
*** Agreement (LICENSE.txt). Any use of this software by third ***
9
*** parties, which does not comply with the terms and conditions of the ***
10
*** OSP Toolkit Software License Agreement is prohibited without ***
11
*** the prior, express, written consent of TransNexus, Inc. ***
13
*** Thank you for using the OSP ToolKit(TM). Please report any bugs, ***
14
*** suggestions or feedback to support@transnexus.com ***
16
**************************************************************************/
25
* ospreauthreq.c - OSP authorisation request functions
31
#include "osp/osperrno.h"
32
#include "osp/ospbfr.h"
33
#include "osp/osplist.h"
34
#include "osp/ospxmlattr.h"
35
#include "osp/ospxmlelem.h"
36
#include "osp/ospmsgattr.h"
37
#include "osp/ospmsgelem.h"
38
#include "osp/ospcallid.h"
39
#include "osp/osptoken.h"
40
#include "osp/ospdest.h"
41
#include "osp/ospusage.h"
42
#include "osp/ospreauthreq.h"
43
#include "osp/ospcallid.h"
44
#include "osp/osputils.h"
45
#include "osp/osptrans.h"
48
/*-----------------------------------------------------------------------*
49
* OSPPReauthReqHasTimestamp() - Does authorisation request have a valid timestamp?
50
*-----------------------------------------------------------------------*/
51
unsigned /* returns non-zero if time */
52
OSPPReauthReqHasTimestamp(
53
OSPTREAUTHREQ *ospvReauthReq /* authorisation request in question */
56
unsigned ospvHasTime = OSPC_FALSE;
58
if (ospvReauthReq != OSPC_OSNULL)
60
ospvHasTime = (ospvReauthReq->ospmReauthReqTimestamp != OSPC_TIMEMIN);
66
/*-----------------------------------------------------------------------*
67
* OSPPReauthReqSetTimestamp() - sets the timestamp for an authorisation request
68
*-----------------------------------------------------------------------*/
69
void /* nothing returned */
70
OSPPReauthReqSetTimestamp(
71
OSPTREAUTHREQ *ospvReauthReq,
75
if (ospvReauthReq != OSPC_OSNULL)
77
ospvReauthReq->ospmReauthReqTimestamp = ospvTime;
82
/*-----------------------------------------------------------------------*
83
* OSPPReauthReqGetTimestamp() - returns timestamp for an authorisation request
84
*-----------------------------------------------------------------------*/
85
OSPTTIME /* returns the time value */
86
OSPPReauthReqGetTimestamp(
87
OSPTREAUTHREQ *ospvReauthReq /* authorisation request */
90
OSPTTIME ospvTime = 0;
92
if (ospvReauthReq != OSPC_OSNULL)
94
ospvTime = ospvReauthReq->ospmReauthReqTimestamp;
100
/*-----------------------------------------------------------------------*
101
* OSPPReauthReqHasCallId() - does an authorisation request have a Call ID?
102
*-----------------------------------------------------------------------*/
103
unsigned /* returns non-zero if exists */
104
OSPPReauthReqHasCallId(
105
OSPTREAUTHREQ *ospvReauthReq /* authorisation request */
108
unsigned ospvHasId = OSPC_FALSE;
110
if (ospvReauthReq != OSPC_OSNULL)
112
ospvHasId = (ospvReauthReq->ospmReauthReqCallId != OSPC_OSNULL);
118
/*-----------------------------------------------------------------------*
119
* OSPPReauthReqGetCallId() - gets the call ID for an authorisation request
120
*-----------------------------------------------------------------------*/
121
OSPTCALLID * /* returns call ID pointer */
122
OSPPReauthReqGetCallId(
123
OSPTREAUTHREQ *ospvReauthReq /* authorisation request */
126
OSPTCALLID *ospvCallId = OSPC_OSNULL;
128
if (ospvReauthReq != OSPC_OSNULL)
130
ospvCallId = ospvReauthReq->ospmReauthReqCallId;
136
/*-----------------------------------------------------------------------*
137
* OSPPReauthReqSetSourceNumber() - set the source number for an
138
* authorisation request
139
*-----------------------------------------------------------------------*/
140
void /* nothing returned */
141
OSPPReauthReqSetSourceNumber(
142
OSPTREAUTHREQ *ospvReauthReq, /* authorisation request to set */
143
const unsigned char *ospvNum /* source number (as string) */
146
if (ospvReauthReq != OSPC_OSNULL)
148
if (ospvNum != OSPC_OSNULL)
150
if (OSPM_STRLEN((const char *)ospvNum) < OSPC_E164NUMSIZE)
152
OSPM_STRNCPY((char *) (ospvReauthReq->ospmReauthReqSourceNumber),
153
(const char *)ospvNum, OSPC_E164NUMSIZE-1);
160
/*-----------------------------------------------------------------------*
161
* OSPPReauthReqGetSourceNumber() - returns the source number for an
162
* authorisation request
163
*-----------------------------------------------------------------------*/
164
const unsigned char * /* returns number as string */
165
OSPPReauthReqGetSourceNumber(
166
OSPTREAUTHREQ *ospvReauthReq /* authorisation request */
169
const unsigned char *ospvNum = OSPC_OSNULL;
171
if (ospvReauthReq != OSPC_OSNULL)
173
ospvNum = ospvReauthReq->ospmReauthReqSourceNumber;
179
/*-----------------------------------------------------------------------*
180
* OSPPReauthReqSetDestNumber() - set the destination number for an
181
* authorisation request
182
*-----------------------------------------------------------------------*/
183
void /* nothing returned */
184
OSPPReauthReqSetDestNumber(
185
OSPTREAUTHREQ *ospvReauthReq, /* authorisation request to set */
186
const unsigned char *ospvNum /* destination number (as string) */
190
if (ospvReauthReq != OSPC_OSNULL)
192
if (ospvNum != OSPC_OSNULL)
194
if (OSPM_STRLEN((const char *)ospvNum) < OSPC_E164NUMSIZE)
196
OSPM_STRNCPY((char *) (ospvReauthReq->ospmReauthReqDestNumber),
197
(const char *)ospvNum, OSPC_E164NUMSIZE-1);
204
/*-----------------------------------------------------------------------*
205
* OSPPReauthReqGetDestNumber() - returns the destination number for an
206
* authorisation request
207
*-----------------------------------------------------------------------*/
208
const unsigned char * /* returns number as string */
209
OSPPReauthReqGetDestNumber(
210
OSPTREAUTHREQ *ospvReauthReq /* authorisation request */
213
const unsigned char *ospvNum = OSPC_OSNULL;
215
if (ospvReauthReq != OSPC_OSNULL)
217
ospvNum = ospvReauthReq->ospmReauthReqDestNumber;
223
/*-----------------------------------------------------------------------*
224
* OSPPReauthReqHasTrxId() - does an authorisation request have a Transaction ID?
225
*-----------------------------------------------------------------------*/
226
unsigned /* returns non-zero if exists */
227
OSPPReauthReqHasTrxId(
228
OSPTREAUTHREQ *ospvReauthReq /* authorisation request */
231
unsigned ospvHasId = OSPC_FALSE;
233
if (ospvReauthReq != OSPC_OSNULL)
235
ospvHasId = (ospvReauthReq->ospmReauthReqTrxId != 0);
241
/*-----------------------------------------------------------------------*
242
* OSPPReauthReqSetTrxId() - sets the transaction ID for an authorisation
243
*-----------------------------------------------------------------------*/
244
void /* nothing returned */
245
OSPPReauthReqSetTrxId(
246
OSPTREAUTHREQ *ospvReauthReq, /* authorisation request */
247
OSPTTRXID ospvTrxId /* transaction ID to set */
251
if (ospvReauthReq != OSPC_OSNULL)
253
ospvReauthReq->ospmReauthReqTrxId = ospvTrxId;
258
/*-----------------------------------------------------------------------*
259
* OSPPReauthReqGetTrxId() - gets the transaction ID for an authorisation request
260
*-----------------------------------------------------------------------*/
261
OSPTTRXID /* returns transaction ID pointer */
262
OSPPReauthReqGetTrxId(
263
OSPTREAUTHREQ *ospvReauthReq /* authorisation request */
266
OSPTTRXID ospvTrxId = 0;
268
if (ospvReauthReq != OSPC_OSNULL)
270
ospvTrxId = ospvReauthReq->ospmReauthReqTrxId;
276
/*-----------------------------------------------------------------------*
277
* OSPPReauthReqHasDuration() - is the duration set ?
278
*-----------------------------------------------------------------------*/
279
unsigned /* returns non-zero if number exists */
280
OSPPReauthReqHasDuration(
281
OSPTREAUTHREQ *ospvReauthReq /* Usage Indication effected */
284
unsigned ospvHasDuration = OSPC_FALSE;
286
if (ospvReauthReq != OSPC_OSNULL)
288
ospvHasDuration = (ospvReauthReq->ospmReauthReqDuration >= 0);
290
return ospvHasDuration;
294
/*-----------------------------------------------------------------------*
295
* OSPPReauthReqSetDuration() - set the duration
296
*-----------------------------------------------------------------------*/
297
void /* nothing returned */
298
OSPPReauthReqSetDuration(
299
OSPTREAUTHREQ *ospvReauthReq, /* usage indication to set */
300
int ospvDuration /* duration to set to */
303
if (ospvReauthReq != OSPC_OSNULL)
305
if (ospvDuration >= 0)
307
ospvReauthReq->ospmReauthReqDuration = ospvDuration;
314
/*-----------------------------------------------------------------------*
315
* OSPPReauthReqGetDuration() - returns the duration for a usage ind
316
*-----------------------------------------------------------------------*/
318
OSPPReauthReqGetDuration(
319
OSPTREAUTHREQ *ospvReauthReq /* usage ind */
322
int ospvDuration = 0;
324
if (ospvReauthReq != OSPC_OSNULL)
326
ospvDuration = ospvReauthReq->ospmReauthReqDuration;
332
/*-----------------------------------------------------------------------*
333
* OSPPReauthReqAddToken() - adds a token to an authorisation indication
334
*-----------------------------------------------------------------------*/
335
void /* nothing returned */
336
OSPPReauthReqAddToken(
337
OSPTREAUTHREQ *ospvReauthReq, /* authorisation indication */
338
OSPTTOKEN *ospvToken /* token to add */
341
if (ospvReauthReq != OSPC_OSNULL)
343
OSPPListAppend(&(ospvReauthReq->ospmReauthReqTokens), ospvToken);
348
/*-----------------------------------------------------------------------*
349
* OSPPReauthReqFirstToken() - gets first token for authorisation indication
350
*-----------------------------------------------------------------------*/
351
OSPTTOKEN * /* returns null if none */
352
OSPPReauthReqFirstToken(
353
OSPTREAUTHREQ *ospvReauthReq
356
OSPTTOKEN *ospvToken = OSPC_OSNULL;
358
if(ospvReauthReq != OSPC_OSNULL)
360
ospvToken = (OSPTTOKEN *)OSPPListFirst(&(ospvReauthReq->ospmReauthReqTokens));
366
/*-----------------------------------------------------------------------*
367
* OSPPReauthReqNextToken() - gets next token (in list) for authorisation indication
368
*-----------------------------------------------------------------------*/
369
OSPTTOKEN * /* returns NULL if no more */
370
OSPPReauthReqNextToken(
371
OSPTREAUTHREQ *ospvReauthReq, /* authorisation indication */
372
OSPTTOKEN *ospvToken /* current token */
375
OSPTTOKEN *ospvNextToken = OSPC_OSNULL;
377
if (ospvReauthReq != OSPC_OSNULL)
379
if (ospvToken != OSPC_OSNULL)
381
ospvNextToken = (OSPTTOKEN *)OSPPListNext(&(ospvReauthReq->ospmReauthReqTokens), ospvToken);
384
return(ospvNextToken);
388
/*-----------------------------------------------------------------------*
389
* OSPPReauthReqHasComponentId() - is the component id set ?
390
*-----------------------------------------------------------------------*/
391
unsigned /* returns non-zero if component id is set */
392
OSPPReauthReqHasComponentId(
393
OSPTREAUTHREQ *ospvReauthReq
396
return (ospvReauthReq->ospmReauthReqComponentId != OSPC_OSNULL);
400
/*-----------------------------------------------------------------------*
401
* OSPPReauthReqGetComponentId() - returns a new copy of the component id.
402
*-----------------------------------------------------------------------*/
404
OSPPReauthReqGetComponentId(
405
OSPTREAUTHREQ *ospvReauthReq
408
unsigned char *componentstring = OSPC_OSNULL;
411
if (OSPPReauthReqHasComponentId(ospvReauthReq))
413
len = OSPM_STRLEN((const char *)ospvReauthReq->ospmReauthReqComponentId);
414
OSPM_MALLOC(componentstring, unsigned char, len + 1);
415
OSPM_MEMSET(componentstring, 0, len + 1);
416
OSPM_MEMCPY(componentstring, ospvReauthReq->ospmReauthReqComponentId, len);
419
return componentstring;
423
/*-----------------------------------------------------------------------*
424
* OSPPReauthReqSetCallId() - sets the call ID for a reauthorisation
425
*-----------------------------------------------------------------------*/
426
void /* nothing returned */
427
OSPPReauthReqSetCallId(
428
OSPTREAUTHREQ *ospvReauthReq, /* authorisation request */
429
OSPTCALLID *ospvCallId /* call ID to set */
432
if (ospvReauthReq != OSPC_OSNULL)
434
if ((ospvCallId) != OSPC_OSNULL)
436
if ((ospvReauthReq)->ospmReauthReqCallId != OSPC_OSNULL)
438
OSPPCallIdDelete(&((ospvReauthReq)->ospmReauthReqCallId));
440
(ospvReauthReq)->ospmReauthReqCallId =
441
OSPPCallIdNew((ospvCallId)->ospmCallIdLen, (ospvCallId)->ospmCallIdVal);
447
/*-----------------------------------------------------------------------*
448
* OSPPReauthReqAddSourceAlt() - add a source alternate to an
449
* authorisation request
450
*-----------------------------------------------------------------------*/
452
OSPPReauthReqAddSourceAlt(
453
OSPTREAUTHREQ *ospvReauthReq, /* authorisation request */
454
OSPTALTINFO *ospvAltInfo /* altinfo to add */
457
if ((ospvReauthReq != OSPC_OSNULL) &&
458
(ospvAltInfo != OSPC_OSNULL))
461
OSPPListAppend(&(ospvReauthReq->ospmReauthReqSourceAlternate), (ospvAltInfo));
467
/*-----------------------------------------------------------------------*
468
* OSPPReauthReqHasSourceAlt() - does an authorisation request have a
470
*-----------------------------------------------------------------------*/
471
unsigned /* returns non-zero if exists */
472
OSPPReauthReqHasSourceAlt(
473
OSPTREAUTHREQ *ospvReauthReq /* authorisation request */
476
unsigned ospvHasSourceAlt = OSPC_FALSE;
478
if (ospvReauthReq != OSPC_OSNULL)
480
ospvHasSourceAlt = (OSPPReauthReqFirstSourceAlt(ospvReauthReq) != OSPC_OSNULL);
482
return(ospvHasSourceAlt);
486
/*-----------------------------------------------------------------------*
487
* OSPPReauthReqFirstSourceAlt() - gets the First Source alternate for an
488
* authorisation request
489
*-----------------------------------------------------------------------*/
490
OSPTALTINFO * /* returns alt info pointer */
491
OSPPReauthReqFirstSourceAlt(
492
OSPTREAUTHREQ *ospvReauthReq /* authorisation request */
495
OSPTALTINFO *ospvAltInfo = OSPC_OSNULL;
497
if (ospvReauthReq != OSPC_OSNULL)
500
(OSPTALTINFO *)OSPPListFirst(&((ospvReauthReq)->ospmReauthReqSourceAlternate));
506
/*-----------------------------------------------------------------------*
507
* OSPPReauthReqNextSourceAlt() - gets the next source alternate for an
508
* authorisation request
509
*-----------------------------------------------------------------------*/
510
OSPTALTINFO * /* returns alt info pointer */
511
OSPPReauthReqNextSourceAlt(
512
OSPTREAUTHREQ *ospvReauthReq, /* authorisation request */
513
OSPTALTINFO *ospvAltInfo
516
OSPTALTINFO *altinfo = OSPC_OSNULL;
518
if (ospvReauthReq != OSPC_OSNULL)
521
(OSPTALTINFO *)OSPPListNext(&((ospvReauthReq)->ospmReauthReqSourceAlternate),
528
/*-----------------------------------------------------------------------*
529
* OSPPReauthReqAddDestinationAlt() - add a destination alternate to an
530
* authorisation request
531
*-----------------------------------------------------------------------*/
533
OSPPReauthReqAddDestinationAlt(
534
OSPTREAUTHREQ *ospvReauthReq, /* authorisation request */
535
OSPTALTINFO *ospvAltInfo /* altinfo struct */
539
if ((ospvReauthReq != OSPC_OSNULL) &&
540
(ospvAltInfo != OSPC_OSNULL))
543
OSPPListAppend(&(ospvReauthReq->ospmReauthReqDestinationAlternate), (ospvAltInfo));
549
/*-----------------------------------------------------------------------*
550
* OSPPReauthReqHasDestinationAlt() - does an authorisation request have a
551
* Destination Alternate?
552
*-----------------------------------------------------------------------*/
553
unsigned /* returns non-zero if exists */
554
OSPPReauthReqHasDestinationAlt(
555
OSPTREAUTHREQ *ospvReauthReq /* authorisation request */
558
unsigned ospvHasDestinationAlt = OSPC_FALSE;
560
if (ospvReauthReq != OSPC_OSNULL)
562
ospvHasDestinationAlt = (OSPPReauthReqFirstDestinationAlt(ospvReauthReq) != OSPC_OSNULL);
564
return(ospvHasDestinationAlt);
568
/*-----------------------------------------------------------------------*
569
* OSPPReauthReqFirstDestinationAlt() - gets the First Destination alternate for an
570
* authorisation request
571
*-----------------------------------------------------------------------*/
572
OSPTALTINFO * /* returns alt info pointer */
573
OSPPReauthReqFirstDestinationAlt(
574
OSPTREAUTHREQ *ospvReauthReq /* authorisation request */
577
OSPTALTINFO *ospvAltInfo = OSPC_OSNULL;
579
if (ospvReauthReq != OSPC_OSNULL)
582
(OSPTALTINFO *)OSPPListFirst(&((ospvReauthReq)->ospmReauthReqDestinationAlternate));
588
/*-----------------------------------------------------------------------*
589
* OSPPReauthReqNextDestinationAlt() - gets the next Destination alternate for an
590
* authorisation request
591
*-----------------------------------------------------------------------*/
592
OSPTALTINFO * /* returns alt info pointer */
593
OSPPReauthReqNextDestinationAlt(
594
OSPTREAUTHREQ *ospvReauthReq, /* authorisation request */
595
OSPTALTINFO *ospvAltInfo
598
OSPTALTINFO *altinfo = OSPC_OSNULL;
600
if (ospvReauthReq != OSPC_OSNULL)
603
(OSPTALTINFO *)OSPPListNext(&((ospvReauthReq)->ospmReauthReqDestinationAlternate),
610
/*-----------------------------------------------------------------------*
611
* OSPPReauthReqGetDestinationAltValue() - gets the Destination alternate value for
612
* an authorisation request
613
*-----------------------------------------------------------------------*/
614
unsigned char * /* returns alt info value */
615
OSPPReauthReqGetDestinationAltValue(
616
OSPTALTINFO *ospvAltInfo /* Alt info ptr */
619
unsigned char *ospvAltInfoValue = OSPC_OSNULL;
621
if (ospvAltInfo != OSPC_OSNULL)
623
ospvAltInfoValue = (unsigned char *)OSPPAltInfoGetValue(ospvAltInfo);
625
return(ospvAltInfoValue);
628
/*-----------------------------------------------------------------------*
629
* OSPPReauthReqDelete() - deletes an authorisation request structure
630
*-----------------------------------------------------------------------*/
632
OSPPReauthReqDelete(OSPTREAUTHREQ **ospvReauthReq)
634
OSPTALTINFO *altinfo = OSPC_OSNULL;
635
OSPTTOKEN *token = OSPC_OSNULL;
639
if((*ospvReauthReq)->ospmReauthReqCallId != OSPC_OSNULL)
641
OSPPCallIdDelete(&((*ospvReauthReq)->ospmReauthReqCallId));
644
while(!OSPPListEmpty(&((*ospvReauthReq)->ospmReauthReqSourceAlternate)))
646
altinfo = (OSPTALTINFO *)OSPPListRemove(&((*ospvReauthReq)->ospmReauthReqSourceAlternate));
647
if(altinfo != OSPC_OSNULL)
650
altinfo = OSPC_OSNULL;
654
OSPPListDelete(&((*ospvReauthReq)->ospmReauthReqSourceAlternate));
656
while(!OSPPListEmpty(&((*ospvReauthReq)->ospmReauthReqDevInfo)))
658
altinfo = (OSPTALTINFO *)OSPPListRemove(&((*ospvReauthReq)->ospmReauthReqDevInfo));
659
if(altinfo != OSPC_OSNULL)
662
altinfo = OSPC_OSNULL;
666
OSPPListDelete(&((*ospvReauthReq)->ospmReauthReqDevInfo));
668
while(!OSPPListEmpty(&((*ospvReauthReq)->ospmReauthReqDestinationAlternate)))
670
altinfo = (OSPTALTINFO *)OSPPListRemove(&((*ospvReauthReq)->ospmReauthReqDestinationAlternate));
671
if(altinfo != OSPC_OSNULL)
674
altinfo = OSPC_OSNULL;
678
OSPPListDelete(&((*ospvReauthReq)->ospmReauthReqDestinationAlternate));
680
while(!OSPPListEmpty(&((*ospvReauthReq)->ospmReauthReqTokens)))
682
token = (OSPTTOKEN *)OSPPListRemove(&((*ospvReauthReq)->ospmReauthReqTokens));
683
if(token != OSPC_OSNULL)
685
OSPPTokenDelete(&token);
689
if(OSPPReauthReqHasMessageId(*ospvReauthReq))
691
OSPM_FREE((*ospvReauthReq)->ospmReauthReqMessageId);
694
if(OSPPReauthReqHasComponentId(*ospvReauthReq))
696
OSPM_FREE((*ospvReauthReq)->ospmReauthReqComponentId);
699
OSPPListDelete(&((*ospvReauthReq)->ospmReauthReqTokens));
701
OSPM_FREE(*ospvReauthReq);
702
*ospvReauthReq = OSPC_OSNULL;
709
/*-----------------------------------------------------------------------*
710
* OSPPReauthReqNew() - creates a new (empty) authorisation request
711
*-----------------------------------------------------------------------*/
713
OSPTREAUTHREQ * /* returns pointer or NULL */
716
OSPTREAUTHREQ *ospvReauthReq = OSPC_OSNULL;
718
OSPM_MALLOC(ospvReauthReq, OSPTREAUTHREQ,sizeof(OSPTREAUTHREQ));
719
if (ospvReauthReq != OSPC_OSNULL)
721
ospvReauthReq->ospmReauthReqTimestamp = OSPC_TIMEMIN;
722
ospvReauthReq->ospmReauthReqHasRole = OSPC_FALSE;
723
ospvReauthReq->ospmReauthReqCallId = OSPC_OSNULL;
724
ospvReauthReq->ospmReauthReqSourceNumber[0] = '\0';
725
ospvReauthReq->ospmReauthReqDestNumber[0] = '\0';
726
OSPPListNew(&ospvReauthReq->ospmReauthReqSourceAlternate);
727
OSPPListNew(&ospvReauthReq->ospmReauthReqDevInfo);
728
OSPPListNew(&ospvReauthReq->ospmReauthReqDestinationAlternate);
729
ospvReauthReq->ospmReauthReqTrxId = 0;
730
ospvReauthReq->ospmReauthReqDuration = -1;
731
OSPPListNew(&ospvReauthReq->ospmReauthReqTokens);
732
ospvReauthReq->ospmReauthReqTNCustId = 0;
733
ospvReauthReq->ospmReauthReqTNDeviceId = 0;
734
ospvReauthReq->ospmReauthReqComponentId = OSPC_OSNULL;
735
ospvReauthReq->ospmReauthReqMessageId = OSPC_OSNULL;
737
return(ospvReauthReq);
741
/*-----------------------------------------------------------------------*
742
* OSPPReauthReqToElement() - create an XML element from a reauthorisation
744
*-----------------------------------------------------------------------*/
745
int /* returns error code */
746
OSPPReauthReqToElement(
747
OSPTREAUTHREQ *ospvReauthReq, /* authorisation request value */
748
OSPTXMLELEM **ospvElem, /* where to put XML element pointer */
752
int ospvErrCode = OSPC_ERR_NO_ERROR;
753
OSPTXMLELEM *elem = OSPC_OSNULL,
754
*reauthelem = OSPC_OSNULL;
755
OSPTXMLATTR *attr = OSPC_OSNULL;
756
OSPTTOKEN *token = OSPC_OSNULL;
757
OSPTTRXID trxid = 0L;
758
OSPTALTINFO *altinfo = OSPC_OSNULL;
759
char random[OSPC_MAX_RANDOM];
760
OSPTBOOL isbase64 = OSPC_TRUE;
761
OSPTTRANS *trans=(OSPTTRANS *)ospvtrans;
763
OSPM_MEMSET(random, 0, OSPC_MAX_RANDOM);
765
if (ospvElem == OSPC_OSNULL)
767
ospvErrCode = OSPC_ERR_XML_NO_ELEMENT;
771
*ospvElem = OSPC_OSNULL;
773
if (ospvReauthReq == OSPC_OSNULL)
775
ospvErrCode = OSPC_ERR_DATA_NO_REAUTHREQ;
778
if(ospvErrCode == OSPC_ERR_NO_ERROR)
780
/* create the "Message" element as the parent */
781
*ospvElem = OSPPXMLElemNew(OSPPMsgGetElemName(ospeElemMessage), "");
783
if(*ospvElem == OSPC_OSNULL)
785
ospvErrCode = OSPC_ERR_XML_NO_ELEMENT;
789
attr = OSPPXMLAttrNew((const unsigned char *)OSPPMsgGetAttrName(ospeAttrMessageId),
790
(OSPPReauthReqHasMessageId(ospvReauthReq))?(const unsigned char *)(ospvReauthReq->ospmReauthReqMessageId): (const unsigned char *)"NULL");
792
if (attr != OSPC_OSNULL)
794
OSPPXMLElemAddAttr(*ospvElem, attr);
799
ospvErrCode = OSPC_ERR_XML_NO_ATTR;
803
if((OSPPUtilGetRandom(random, 0) > 0) &&
804
(ospvErrCode == OSPC_ERR_NO_ERROR))
806
attr = OSPPXMLAttrNew((const unsigned char *)OSPPMsgGetAttrName(ospeAttrRandom),
807
(const unsigned char *)random);
809
if (attr != OSPC_OSNULL)
811
OSPPXMLElemAddAttr(*ospvElem, attr);
816
ospvErrCode = OSPC_ERR_XML_NO_ATTR;
822
if (ospvErrCode == OSPC_ERR_NO_ERROR)
824
/* now the message type element */
825
reauthelem = OSPPXMLElemNew(OSPPMsgGetElemName(ospeElemReauthReq), "");
826
if (*ospvElem == OSPC_OSNULL)
828
ospvErrCode = OSPC_ERR_XML_NO_ELEMENT;
831
/* now add the attributes to the type element -- in this case the component id
834
if (ospvErrCode == OSPC_ERR_NO_ERROR)
836
attr = OSPPXMLAttrNew((const unsigned char *)OSPPMsgGetAttrName(ospeAttrComponentId),
837
(OSPPReauthReqHasComponentId(ospvReauthReq))?(const unsigned char *)(ospvReauthReq->ospmReauthReqComponentId): (const unsigned char *)"NULL");
839
if (attr == OSPC_OSNULL)
841
ospvErrCode = OSPC_ERR_XML_NO_ATTR;
844
if (ospvErrCode == OSPC_ERR_NO_ERROR)
846
OSPPXMLElemAddAttr(reauthelem, attr);
849
/* now add the children */
851
if ((ospvErrCode == OSPC_ERR_NO_ERROR) && OSPPReauthReqHasTimestamp(ospvReauthReq))
853
ospvErrCode = OSPPMsgTimeToElement(OSPPReauthReqGetTimestamp(ospvReauthReq),
854
(const unsigned char *)OSPPMsgGetElemName(ospeElemTimestamp), &elem);
856
if (ospvErrCode == OSPC_ERR_NO_ERROR)
858
OSPPXMLElemAddChild(reauthelem, elem);
862
if ((ospvErrCode == OSPC_ERR_NO_ERROR) && OSPPReauthReqHasRole(ospvReauthReq))
864
ospvErrCode = OSPPMsgRoleToElement(OSPPReauthReqGetRole(ospvReauthReq),
865
(const unsigned char *) OSPPMsgGetElemName(ospeElemRole), &elem);
866
if (ospvErrCode == OSPC_ERR_NO_ERROR)
868
OSPPXMLElemAddChild(reauthelem, elem);
873
/* add the call ID */
874
if ((ospvErrCode == OSPC_ERR_NO_ERROR) && OSPPReauthReqHasCallId(ospvReauthReq))
876
ospvErrCode = OSPPCallIdToElement(OSPPReauthReqGetCallId(ospvReauthReq),
879
if (ospvErrCode == OSPC_ERR_NO_ERROR)
881
OSPPXMLElemAddChild(reauthelem, elem);
884
/* add the source number */
885
if (ospvErrCode == OSPC_ERR_NO_ERROR)
887
elem = OSPPXMLElemNew(OSPPMsgGetElemName(ospeElemSrcInfo),
888
(const char *)OSPPReauthReqGetSourceNumber(ospvReauthReq));
889
if (elem == OSPC_OSNULL)
891
ospvErrCode = OSPC_ERR_XML_NO_ELEMENT;
894
if (ospvErrCode == OSPC_ERR_NO_ERROR)
896
if (trans->CallingNumberFormat == OSPC_E164)
898
attr = OSPPXMLAttrNew((const unsigned char *)OSPPMsgGetAttrName(ospeAttrType),
899
(const unsigned char *) "e164");
901
else if (trans->CallingNumberFormat == OSPC_SIP)
903
attr = OSPPXMLAttrNew((const unsigned char *)OSPPMsgGetAttrName(ospeAttrType),
904
(const unsigned char *) "sip");
906
else if (trans->CallingNumberFormat == OSPC_URL)
908
attr = OSPPXMLAttrNew((const unsigned char *)OSPPMsgGetAttrName(ospeAttrType),
909
(const unsigned char *) "url");
911
if (attr == OSPC_OSNULL)
913
ospvErrCode = OSPC_ERR_XML_NO_ATTR;
916
if (ospvErrCode == OSPC_ERR_NO_ERROR)
918
OSPPXMLElemAddAttr(elem, attr);
920
if (ospvErrCode == OSPC_ERR_NO_ERROR)
922
OSPPXMLElemAddChild(reauthelem, elem);
925
/* add the device info element */
926
if ((ospvErrCode == OSPC_ERR_NO_ERROR) &&
927
(ospvReauthReq->ospmReauthReqDevInfo != NULL))
929
for (altinfo = (OSPTALTINFO *)OSPPListFirst( &(ospvReauthReq->ospmReauthReqDevInfo));
930
((altinfo != OSPC_OSNULL) && (ospvErrCode == OSPC_ERR_NO_ERROR));
931
altinfo = (OSPTALTINFO *)OSPPListNext( &(ospvReauthReq->ospmReauthReqDevInfo), altinfo))
933
ospvErrCode = OSPPAltInfoToElement(altinfo, &elem, ospeElemDeviceInfo);
934
if (ospvErrCode == OSPC_ERR_NO_ERROR)
936
OSPPXMLElemAddChild(reauthelem, elem);
942
/* add the source alternates */
943
if ((ospvErrCode == OSPC_ERR_NO_ERROR) &&
944
OSPPReauthReqHasSourceAlt(ospvReauthReq))
946
for (altinfo = OSPPReauthReqFirstSourceAlt(ospvReauthReq);
947
((altinfo != OSPC_OSNULL) && (ospvErrCode == OSPC_ERR_NO_ERROR));
948
altinfo = OSPPReauthReqNextSourceAlt(ospvReauthReq, altinfo))
950
ospvErrCode = OSPPAltInfoToElement(altinfo, &elem, ospeElemSrcAlt);
951
if (ospvErrCode == OSPC_ERR_NO_ERROR)
953
OSPPXMLElemAddChild(reauthelem, elem);
959
/* add the dest number */
960
if (ospvErrCode == OSPC_ERR_NO_ERROR)
962
elem = OSPPXMLElemNew(OSPPMsgGetElemName(ospeElemDestInfo),
963
(const char *)OSPPReauthReqGetDestNumber(ospvReauthReq));
964
if (elem == OSPC_OSNULL)
966
ospvErrCode = OSPC_ERR_XML_NO_ELEMENT;
969
if (ospvErrCode == OSPC_ERR_NO_ERROR)
971
if (trans->CalledNumberFormat == OSPC_E164)
973
attr = OSPPXMLAttrNew((const unsigned char *)OSPPMsgGetAttrName(ospeAttrType),
974
(const unsigned char *)"e164");
976
else if (trans->CalledNumberFormat == OSPC_SIP)
978
attr = OSPPXMLAttrNew((const unsigned char *)OSPPMsgGetAttrName(ospeAttrType),
979
(const unsigned char *)"sip");
981
else if (trans->CalledNumberFormat == OSPC_URL)
983
attr = OSPPXMLAttrNew((const unsigned char *)OSPPMsgGetAttrName(ospeAttrType),
984
(const unsigned char *)"url");
987
if (attr == OSPC_OSNULL)
989
ospvErrCode = OSPC_ERR_XML_NO_ATTR;
992
if (ospvErrCode == OSPC_ERR_NO_ERROR)
994
OSPPXMLElemAddAttr(elem, attr);
996
if (ospvErrCode == OSPC_ERR_NO_ERROR)
998
OSPPXMLElemAddChild(reauthelem, elem);
1001
/* add the destination alternates */
1002
if ((ospvErrCode == OSPC_ERR_NO_ERROR) &&
1003
OSPPReauthReqHasDestinationAlt(ospvReauthReq))
1005
for (altinfo = OSPPReauthReqFirstDestinationAlt(ospvReauthReq);
1006
((altinfo != OSPC_OSNULL) && (ospvErrCode == OSPC_ERR_NO_ERROR));
1007
altinfo = OSPPReauthReqNextDestinationAlt(ospvReauthReq, altinfo))
1009
ospvErrCode = OSPPAltInfoToElement(altinfo, &elem, ospeElemDestAlt);
1010
if (ospvErrCode == OSPC_ERR_NO_ERROR)
1012
OSPPXMLElemAddChild(reauthelem, elem);
1018
/* add the transaction ID */
1019
if ((ospvErrCode == OSPC_ERR_NO_ERROR) && OSPPReauthReqHasTrxId(ospvReauthReq))
1021
trxid = OSPPReauthReqGetTrxId(ospvReauthReq);
1022
ospvErrCode = OSPPMsgTXToElement( trxid,
1023
(const unsigned char *)OSPPMsgGetElemName(ospeElemTransId),
1026
if (ospvErrCode == OSPC_ERR_NO_ERROR)
1028
OSPPXMLElemAddChild(reauthelem, elem);
1031
/* add usage detail (if appropriate) */
1032
if ((ospvErrCode == OSPC_ERR_NO_ERROR) && OSPPReauthReqHasDuration(ospvReauthReq))
1034
ospvErrCode = OSPPUsageToElement(
1035
(unsigned)OSPPReauthReqGetDuration(ospvReauthReq), 0, 0, 0, 0, 0, 0, 0, &elem);
1036
if (ospvErrCode == OSPC_ERR_NO_ERROR)
1038
OSPPXMLElemAddChild(reauthelem, elem);
1042
if (ospvErrCode == OSPC_ERR_NO_ERROR)
1044
/* add any tokens */
1045
for (token = (OSPTTOKEN *)OSPPReauthReqFirstToken(ospvReauthReq);
1046
((token != (OSPTTOKEN *)OSPC_OSNULL) && (ospvErrCode == OSPC_ERR_NO_ERROR));
1047
token = (OSPTTOKEN *)OSPPReauthReqNextToken(ospvReauthReq, token))
1049
ospvErrCode = OSPPTokenToElement(token, &elem);
1050
if (ospvErrCode == OSPC_ERR_NO_ERROR)
1052
OSPPXMLElemAddChild(reauthelem, elem);
1057
/* now add the transnexus extensions (if available) */
1058
if (ospvErrCode == OSPC_ERR_NO_ERROR)
1060
if (OSPPReauthReqHasTNCustId(ospvReauthReq))
1062
ospvErrCode = OSPPMsgNumToElement(
1063
OSPPReauthReqGetTNCustId(ospvReauthReq),
1064
(const unsigned char *)OSPPMsgGetElemName(ospeElemTNCustId),
1067
if (ospvErrCode == OSPC_ERR_NO_ERROR)
1069
OSPPXMLElemAddChild(reauthelem, elem);
1072
if (OSPPReauthReqHasTNDeviceId(ospvReauthReq))
1074
ospvErrCode = OSPPMsgNumToElement(
1075
OSPPReauthReqGetTNDeviceId(ospvReauthReq),
1076
(const unsigned char *)OSPPMsgGetElemName(ospeElemTNDeviceId),
1079
if (ospvErrCode == OSPC_ERR_NO_ERROR)
1081
OSPPXMLElemAddChild(reauthelem, elem);
1089
if(ospvErrCode == OSPC_ERR_NO_ERROR)
1091
/* Now add the reauthelem to the main elem */
1092
OSPPXMLElemAddChild(*ospvElem, reauthelem);
1093
reauthelem = OSPC_OSNULL;
1096
/* if for any reason we found an error - destroy any elements created */
1097
if (ospvErrCode != OSPC_ERR_NO_ERROR)
1099
if(*ospvElem != OSPC_OSNULL)
1101
OSPPXMLElemDelete(ospvElem);
1104
if(elem != OSPC_OSNULL)
1106
OSPPXMLElemDelete(&elem);
1109
if(reauthelem != OSPC_OSNULL)
1111
OSPPXMLElemDelete(&reauthelem);
1114
if(attr != OSPC_OSNULL)
1116
OSPPXMLAttrDelete(&attr);
1120
return(ospvErrCode);
1124
/*-----------------------------------------------------------------------*
1125
* OSPPReauthReqHasRole() - Does reauthrequest have role set?
1126
*-----------------------------------------------------------------------*/
1127
unsigned /* returns non-zero if time */
1128
OSPPReauthReqHasRole(
1129
OSPTREAUTHREQ *ospvReauthReq /* reauth request in question */
1132
unsigned ospvHasRole = OSPC_FALSE;
1133
if (ospvReauthReq != OSPC_OSNULL)
1135
ospvHasRole = ((ospvReauthReq)->ospmReauthReqHasRole != OSPC_FALSE);
1137
return(ospvHasRole);
1141
/*-----------------------------------------------------------------------*
1142
* OSPPReauthReqGetRole() - returns role for an reauth request
1143
*-----------------------------------------------------------------------*/
1144
OSPE_MSG_ROLETYPES /* returns the role (OGW/TGW) */
1145
OSPPReauthReqGetRole(
1146
OSPTREAUTHREQ *ospvReauthReq /* reauth request */
1149
OSPE_MSG_ROLETYPES ospvRole = OSPC_UNDEFINED_ROLE;
1151
if (ospvReauthReq != OSPC_OSNULL)
1153
ospvRole = (OSPE_MSG_ROLETYPES)ospvReauthReq->ospmReauthReqRole;
1160
/*-----------------------------------------------------------------------*
1161
* OSPPReauthReqSetRole() - sets value for role in reauthorisation request
1162
*-----------------------------------------------------------------------*/
1165
OSPPReauthReqSetRole(
1166
OSPTREAUTHREQ *ospvReauthReq,
1167
OSPE_MSG_ROLETYPES ospvRole)
1170
if (ospvReauthReq != OSPC_OSNULL)
1172
ospvReauthReq->ospmReauthReqHasRole = OSPC_TRUE;
1173
ospvReauthReq->ospmReauthReqRole = ospvRole;
1179
/*-----------------------------------------------------------------------*
1180
* OSPPReauthReqHasTNCustId() - Does reauthreq have a TransNexus Customer Id?
1181
*-----------------------------------------------------------------------*/
1182
unsigned /* returns non-zero if true */
1183
OSPPReauthReqHasTNCustId(
1184
OSPTREAUTHREQ *ospvReauthReq /* reauthreq in question */
1187
unsigned ospvHasTNCustId = OSPC_FALSE;
1189
if (ospvReauthReq != OSPC_OSNULL)
1191
ospvHasTNCustId = ((ospvReauthReq)->ospmReauthReqTNCustId != 0L);
1193
return(ospvHasTNCustId);
1197
/*-----------------------------------------------------------------------*
1198
* OSPPReauthReqSetTNCustId() - Set TransNexus Customer Id
1199
*-----------------------------------------------------------------------*/
1200
void /* nothing returned */
1201
OSPPReauthReqSetTNCustId(
1202
OSPTREAUTHREQ *ospvReauthReq,
1203
unsigned long ospvTNCustId
1206
if (ospvReauthReq != OSPC_OSNULL)
1208
(ospvReauthReq)->ospmReauthReqTNCustId = (ospvTNCustId);
1213
/*-----------------------------------------------------------------------*
1214
* OSPPReauthReqGetTNCustId() - returns TN Customer Id for a reauthreq
1215
*-----------------------------------------------------------------------*/
1216
unsigned long /* returns the cust id */
1217
OSPPReauthReqGetTNCustId(
1218
OSPTREAUTHREQ *ospvReauthReq /* usage request */
1221
unsigned long ospvTNCustId = 0L;
1223
if (ospvReauthReq != OSPC_OSNULL)
1225
ospvTNCustId = (ospvReauthReq)->ospmReauthReqTNCustId;
1227
return(ospvTNCustId);
1231
/*-----------------------------------------------------------------------*
1232
* OSPPReauthReqHasTNDeviceId() - Does request have a TransNexus Device Id?
1233
*-----------------------------------------------------------------------*/
1234
unsigned /* returns non-zero if true */
1235
OSPPReauthReqHasTNDeviceId(
1236
OSPTREAUTHREQ *ospvReauthReq /* reauthrequest in question */
1239
unsigned ospvHasTNDeviceId = OSPC_FALSE;
1241
if (ospvReauthReq != OSPC_OSNULL)
1243
ospvHasTNDeviceId = ((ospvReauthReq)->ospmReauthReqTNDeviceId != 0L);
1245
return(ospvHasTNDeviceId);
1249
/*-----------------------------------------------------------------------*
1250
* OSPPReauthReqSetTNDeviceId() - Set TransNexus Device Id
1251
*-----------------------------------------------------------------------*/
1252
void /* nothing returned */
1253
OSPPReauthReqSetTNDeviceId(
1254
OSPTREAUTHREQ *ospvReauthReq,
1255
unsigned long ospvTNDeviceId
1258
if (ospvReauthReq != OSPC_OSNULL)
1260
(ospvReauthReq)->ospmReauthReqTNDeviceId = (ospvTNDeviceId);
1265
/*-----------------------------------------------------------------------*
1266
* OSPPReauthReqGetTNDeviceId() - returns TN Device Id for an reauth request
1267
*-----------------------------------------------------------------------*/
1268
unsigned long /* returns the device id */
1269
OSPPReauthReqGetTNDeviceId(
1270
OSPTREAUTHREQ *ospvReauthReq /* reauth request */
1273
unsigned long ospvTNDeviceId = 0L;
1275
if (ospvReauthReq != OSPC_OSNULL)
1277
ospvTNDeviceId = (ospvReauthReq)->ospmReauthReqTNDeviceId;
1279
return(ospvTNDeviceId);
1282
/*-----------------------------------------------------------------------*
1283
* OSPPReauthReqHasMessageId() - is the message id set ?
1284
*-----------------------------------------------------------------------*/
1285
unsigned /* returns non-zero if message id is set */
1286
OSPPReauthReqHasMessageId(
1287
OSPTREAUTHREQ *ospvReauthReq
1290
return (ospvReauthReq->ospmReauthReqMessageId != OSPC_OSNULL);