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
**************************************************************************/
26
* ospauthreq.c - OSP authorisation request functions
30
#include "osp/osperrno.h"
31
#include "osp/ospbfr.h"
32
#include "osp/ospxmlattr.h"
33
#include "osp/ospxmlelem.h"
34
#include "osp/ospmsgattr.h"
35
#include "osp/ospmsgelem.h"
36
#include "osp/ospcallid.h"
37
#include "osp/ospauthreq.h"
38
#include "osp/osputils.h"
39
#include "osp/osptrans.h"
42
/*-----------------------------------------------------------------------*
43
* OSPPAuthReqHasTimestamp() - Does authorisation request have a valid timestamp?
44
*-----------------------------------------------------------------------*/
45
unsigned /* returns non-zero if time */
46
OSPPAuthReqHasTimestamp(
47
OSPTAUTHREQ *ospvAuthReq /* authorisation request in question */
50
unsigned ospvHasTimestamp = OSPC_FALSE;
52
if (ospvAuthReq != OSPC_OSNULL)
54
ospvHasTimestamp = ((ospvAuthReq)->ospmAuthReqTimestamp != OSPC_TIMEMIN);
56
return(ospvHasTimestamp);
60
/*-----------------------------------------------------------------------*
61
* OSPPAuthReqSetTimestamp() - sets the timestamp for an authorisation request
62
*-----------------------------------------------------------------------*/
63
void /* nothing returned */
64
OSPPAuthReqSetTimestamp(
65
OSPTAUTHREQ *ospvAuthReq,
69
if (ospvAuthReq != OSPC_OSNULL)
71
(ospvAuthReq)->ospmAuthReqTimestamp = (ospvTime);
76
/*-----------------------------------------------------------------------*
77
* OSPPAuthReqGetTimestamp() - returns timestamp for an authorisation request
78
*-----------------------------------------------------------------------*/
79
OSPTTIME /* returns the time value */
80
OSPPAuthReqGetTimestamp(
81
OSPTAUTHREQ *ospvAuthReq /* authorisation request */
84
OSPTTIME ospvTimestamp = 0;
86
if (ospvAuthReq != OSPC_OSNULL)
88
ospvTimestamp = (ospvAuthReq)->ospmAuthReqTimestamp;
90
return(ospvTimestamp);
94
/*-----------------------------------------------------------------------*
95
* OSPPAuthReqHasCallId() - does an authorisation request have a Call ID?
96
*-----------------------------------------------------------------------*/
97
unsigned /* returns non-zero if exists */
99
OSPTAUTHREQ *ospvAuthReq /* authorisation request */
102
unsigned ospvHasCallId = OSPC_FALSE;
104
if (ospvAuthReq != OSPC_OSNULL)
106
ospvHasCallId = (OSPPAuthReqFirstCallId(ospvAuthReq) != OSPC_OSNULL);
108
return(ospvHasCallId);
112
/*-----------------------------------------------------------------------*
113
* OSPPAuthReqFirstCallId() - gets the First call ID for an authorisation request
114
*-----------------------------------------------------------------------*/
115
OSPTCALLID * /* returns call ID pointer */
116
OSPPAuthReqFirstCallId(
117
OSPTAUTHREQ *ospvAuthReq /* authorisation request */
120
OSPTCALLID *ospvCallId = OSPC_OSNULL;
122
if (ospvAuthReq != OSPC_OSNULL)
124
ospvCallId = (OSPTCALLID *)OSPPListFirst(&(ospvAuthReq->ospmAuthReqCallId));
130
/*-----------------------------------------------------------------------*
131
* OSPPAuthReqNextCallId() - gets the next call ID for an authorisation request
132
*-----------------------------------------------------------------------*/
133
OSPTCALLID * /* returns call ID pointer */
134
OSPPAuthReqNextCallId(
135
OSPTAUTHREQ *ospvAuthReq, /* authorisation request */
136
OSPTCALLID *ospvCallId /* current callid */
139
OSPTCALLID *nextcallid = OSPC_OSNULL;
141
if (ospvAuthReq != OSPC_OSNULL)
143
nextcallid = (OSPTCALLID *)OSPPListNext(&(ospvAuthReq->ospmAuthReqCallId), ospvCallId);
149
/*-----------------------------------------------------------------------*
150
* OSPPAuthReqHasSourceNumber() - does the authorisation request have
152
*-----------------------------------------------------------------------*/
153
unsigned /* returns non-zero if number exists */
154
OSPPAuthReqHasSourceNumber(
155
OSPTAUTHREQ *ospvAuthReq /* authorisation request effected */
158
unsigned ospvHasNumber = OSPC_FALSE;
160
if (ospvAuthReq != OSPC_OSNULL)
162
ospvHasNumber = ((ospvAuthReq)->ospmAuthReqSourceNumber[0] != '\0');
164
return(ospvHasNumber);
168
/*-----------------------------------------------------------------------*
169
* OSPPAuthReqSetSourceNumber() - set the source number for an
170
* authorisation request
171
*-----------------------------------------------------------------------*/
172
void /* nothing returned */
173
OSPPAuthReqSetSourceNumber(
174
OSPTAUTHREQ *ospvAuthReq, /* authorisation request to set */
175
const unsigned char *ospvNum /* source number (as string) */
178
if (ospvAuthReq != OSPC_OSNULL)
180
if (ospvNum != OSPC_OSNULL)
182
OSPM_STRNCPY((char *)(ospvAuthReq)->ospmAuthReqSourceNumber,
183
(const char *)(ospvNum),
184
tr_min(OSPM_STRLEN((const char *)ospvNum)+1,OSPC_E164NUMSIZE-1));
190
/*-----------------------------------------------------------------------*
191
* OSPPAuthReqGetSourceNumber() - returns the source number for an
192
* authorisation request
193
*-----------------------------------------------------------------------*/
194
unsigned char * /* returns number as string */
195
OSPPAuthReqGetSourceNumber(
196
OSPTAUTHREQ *ospvAuthReq /* authorisation request */
199
unsigned char *ospvNum = OSPC_OSNULL;
201
if (ospvAuthReq != OSPC_OSNULL)
203
ospvNum = (ospvAuthReq->ospmAuthReqSourceNumber);
209
/*-----------------------------------------------------------------------*
210
* OSPPAuthReqHasSourceAlt() - does an authorisation request have a
212
*-----------------------------------------------------------------------*/
213
unsigned /* returns non-zero if exists */
214
OSPPAuthReqHasSourceAlt(
215
OSPTAUTHREQ *ospvAuthReq /* authorisation request */
218
unsigned ospvHasSourceAlt = OSPC_FALSE;
220
if (ospvAuthReq != OSPC_OSNULL)
222
ospvHasSourceAlt = (OSPPAuthReqFirstSourceAlt(ospvAuthReq) != OSPC_OSNULL);
224
return(ospvHasSourceAlt);
228
/*-----------------------------------------------------------------------*
229
* OSPPAuthReqFirstSourceAlt() - gets the First Source alternate for an
230
* authorisation request
231
*-----------------------------------------------------------------------*/
232
OSPTALTINFO * /* returns alt info pointer */
233
OSPPAuthReqFirstSourceAlt(
234
OSPTAUTHREQ *ospvAuthReq /* authorisation request */
237
OSPTALTINFO *ospvAltInfo = OSPC_OSNULL;
239
if (ospvAuthReq != OSPC_OSNULL)
242
(OSPTALTINFO *)OSPPListFirst(&((ospvAuthReq)->ospmAuthReqSourceAlternate));
248
/*-----------------------------------------------------------------------*
249
* OSPPAuthReqNextSourceAlt() - gets the next source alternate for an
250
* authorisation request
251
*-----------------------------------------------------------------------*/
252
OSPTALTINFO * /* returns alt info pointer */
253
OSPPAuthReqNextSourceAlt(
254
OSPTAUTHREQ *ospvAuthReq, /* authorisation request */
255
OSPTALTINFO *ospvAltInfo
258
OSPTALTINFO *altinfo = OSPC_OSNULL;
260
if (ospvAuthReq != OSPC_OSNULL)
263
(OSPTALTINFO *)OSPPListNext(&((ospvAuthReq)->ospmAuthReqSourceAlternate),
270
/*-----------------------------------------------------------------------*
271
* OSPPAuthReqHasDestinationAlt() - does an authorisation request have a
272
* Destination Alternate?
273
*-----------------------------------------------------------------------*/
274
unsigned /* returns non-zero if exists */
275
OSPPAuthReqHasDestinationAlt(
276
OSPTAUTHREQ *ospvAuthReq /* authorisation request */
279
unsigned ospvHasDestinationAlt = OSPC_FALSE;
281
if (ospvAuthReq != OSPC_OSNULL)
283
ospvHasDestinationAlt = (OSPPAuthReqFirstDestinationAlt(ospvAuthReq) != OSPC_OSNULL);
285
return(ospvHasDestinationAlt);
289
/*-----------------------------------------------------------------------*
290
* OSPPAuthReqFirstDestinationAlt() - gets the First Destination alternate for an
291
* authorisation request
292
*-----------------------------------------------------------------------*/
293
OSPTALTINFO * /* returns alt info pointer */
294
OSPPAuthReqFirstDestinationAlt(
295
OSPTAUTHREQ *ospvAuthReq /* authorisation request */
298
OSPTALTINFO *ospvAltInfo = OSPC_OSNULL;
300
if (ospvAuthReq != OSPC_OSNULL)
303
(OSPTALTINFO *)OSPPListFirst(&((ospvAuthReq)->ospmAuthReqDestinationAlternate));
309
/*-----------------------------------------------------------------------*
310
* OSPPAuthReqNextDestinationAlt() - gets the next Destination alternate for an
311
* authorisation request
312
*-----------------------------------------------------------------------*/
313
OSPTALTINFO * /* returns alt info pointer */
314
OSPPAuthReqNextDestinationAlt(
315
OSPTAUTHREQ *ospvAuthReq, /* authorisation request */
316
OSPTALTINFO *ospvAltInfo
319
OSPTALTINFO *altinfo = OSPC_OSNULL;
321
if (ospvAuthReq != OSPC_OSNULL)
324
(OSPTALTINFO *)OSPPListNext(&((ospvAuthReq)->ospmAuthReqDestinationAlternate),
331
/*-----------------------------------------------------------------------*
332
* OSPPAuthReqHasDestNumber() - does the authorisation request include a
334
*-----------------------------------------------------------------------*/
335
unsigned /* returns non-zero if number exists */
336
OSPPAuthReqHasDestNumber(
337
OSPTAUTHREQ *ospvAuthReq /* authorisation request effected */
340
unsigned ospvHasNumber = OSPC_FALSE;
342
if (ospvAuthReq != OSPC_OSNULL)
344
ospvHasNumber = ((ospvAuthReq)->ospmAuthReqDestNumber[0] != '\0');
346
return(ospvHasNumber);
350
/*-----------------------------------------------------------------------*
351
* OSPPAuthReqSetDestNumber() - set the destination number for an
352
* authorisation request
353
*-----------------------------------------------------------------------*/
354
void /* nothing returned */
355
OSPPAuthReqSetDestNumber(
356
OSPTAUTHREQ *ospvAuthReq, /* authorisation request to set */
357
const unsigned char *ospvNum /* destination number (as string) */
360
if (ospvAuthReq != OSPC_OSNULL)
362
if (ospvNum != OSPC_OSNULL)
364
OSPM_STRNCPY((char *)(ospvAuthReq)->ospmAuthReqDestNumber,
365
(const char *)(ospvNum),
366
tr_min(OSPM_STRLEN((const char *)ospvNum)+1,OSPC_E164NUMSIZE-1));
372
/*-----------------------------------------------------------------------*
373
* OSPPAuthReqGetDestNumber() - returns the destination number for an
374
* authorisation request
375
*-----------------------------------------------------------------------*/
376
unsigned char * /* returns number as string */
377
OSPPAuthReqGetDestNumber(
378
OSPTAUTHREQ *ospvAuthReq /* authorisation request */
381
unsigned char *ospvDestNum = OSPC_OSNULL;
383
if (ospvAuthReq != OSPC_OSNULL)
385
ospvDestNum = ((ospvAuthReq)->ospmAuthReqDestNumber);
391
/*-----------------------------------------------------------------------*
392
* OSPPAuthReqSetMaxDest() - set the maximum destinations for an
393
* authorisation request
394
*-----------------------------------------------------------------------*/
395
void /* nothing returned */
396
OSPPAuthReqSetMaxDest(
397
OSPTAUTHREQ *ospvAuthReq, /* authorisation request to set */
398
unsigned ospvNum /* maximum destinations */
401
if (ospvAuthReq != OSPC_OSNULL)
405
(ospvAuthReq)->ospmAuthReqMaxDest = ospvNum;
411
/*-----------------------------------------------------------------------*
412
* OSPPAuthReqGetMaxDest() - returns the maximum destinations for an
413
* authorisation request
414
*-----------------------------------------------------------------------*/
415
unsigned /* returns maximum destionations */
416
OSPPAuthReqGetMaxDest(
417
OSPTAUTHREQ *ospvAuthReq /* authorisation request */
420
unsigned ospvNum = 0;
422
if (ospvAuthReq != OSPC_OSNULL)
424
ospvNum = ((ospvAuthReq)->ospmAuthReqMaxDest);
429
/*-----------------------------------------------------------------------*
430
* OSPPAuthReqHasTNCustId() - Does request have a TransNexus Customer Id?
431
*-----------------------------------------------------------------------*/
432
unsigned /* returns non-zero if time */
433
OSPPAuthReqHasTNCustId(
434
OSPTAUTHREQ *ospvAuthReq /* authorisation request in question */
437
unsigned ospvHasTNCustId = OSPC_FALSE;
439
if (ospvAuthReq != OSPC_OSNULL)
441
ospvHasTNCustId = ((ospvAuthReq)->ospmAuthReqTNCustId != 0L);
443
return(ospvHasTNCustId);
447
/*-----------------------------------------------------------------------*
448
* OSPPAuthReqSetTNCustId() - Set TransNexus Customer Id
449
*-----------------------------------------------------------------------*/
450
void /* nothing returned */
451
OSPPAuthReqSetTNCustId(
452
OSPTAUTHREQ *ospvAuthReq,
453
unsigned long ospvTNCustId
456
if (ospvAuthReq != OSPC_OSNULL)
458
(ospvAuthReq)->ospmAuthReqTNCustId = (ospvTNCustId);
463
/*-----------------------------------------------------------------------*
464
* OSPPAuthReqGetTNCustId() - returns TN Customer Id for an auth request
465
*-----------------------------------------------------------------------*/
466
unsigned long /* returns the time value */
467
OSPPAuthReqGetTNCustId(
468
OSPTAUTHREQ *ospvAuthReq /* authorisation request */
471
unsigned long ospvTNCustId = 0L;
473
if (ospvAuthReq != OSPC_OSNULL)
475
ospvTNCustId = (ospvAuthReq)->ospmAuthReqTNCustId;
477
return(ospvTNCustId);
481
/*-----------------------------------------------------------------------*
482
* OSPPAuthReqHasTNDeviceId() - Does request have a TransNexus Device Id?
483
*-----------------------------------------------------------------------*/
484
unsigned /* returns non-zero if time */
485
OSPPAuthReqHasTNDeviceId(
486
OSPTAUTHREQ *ospvAuthReq /* authorisation request in question */
489
unsigned ospvHasTNDeviceId = OSPC_FALSE;
491
if (ospvAuthReq != OSPC_OSNULL)
493
ospvHasTNDeviceId = ((ospvAuthReq)->ospmAuthReqTNDeviceId != 0L);
495
return(ospvHasTNDeviceId);
499
/*-----------------------------------------------------------------------*
500
* OSPPAuthReqSetTNDeviceId() - Set TransNexus Device Id
501
*-----------------------------------------------------------------------*/
502
void /* nothing returned */
503
OSPPAuthReqSetTNDeviceId(
504
OSPTAUTHREQ *ospvAuthReq,
505
unsigned long ospvTNDeviceId
508
if (ospvAuthReq != OSPC_OSNULL)
510
(ospvAuthReq)->ospmAuthReqTNDeviceId = (ospvTNDeviceId);
515
/*-----------------------------------------------------------------------*
516
* OSPPAuthReqGetTNDeviceId() - returns TN Device Id for an auth request
517
*-----------------------------------------------------------------------*/
518
unsigned long /* returns the time value */
519
OSPPAuthReqGetTNDeviceId(
520
OSPTAUTHREQ *ospvAuthReq /* authorisation request */
523
unsigned long ospvTNDeviceId = 0L;
525
if (ospvAuthReq != OSPC_OSNULL)
527
ospvTNDeviceId = (ospvAuthReq)->ospmAuthReqTNDeviceId;
529
return(ospvTNDeviceId);
533
/*-----------------------------------------------------------------------*
534
* OSPPAuthReqHasComponentId() - is the component id set ?
535
*-----------------------------------------------------------------------*/
536
unsigned /* returns non-zero if component id is set */
537
OSPPAuthReqHasComponentId(
538
OSPTAUTHREQ *ospvAuthReq
541
return (ospvAuthReq->ospmAuthReqComponentId != OSPC_OSNULL);
546
/*-----------------------------------------------------------------------*
547
* OSPPAuthReqNew() - creates a new (empty) authorisation request
548
*-----------------------------------------------------------------------*/
550
OSPTAUTHREQ * /* returns pointer or NULL */
553
OSPTAUTHREQ *ospvAuthReq = OSPC_OSNULL;
555
OSPM_MALLOC(ospvAuthReq, OSPTAUTHREQ,sizeof(OSPTAUTHREQ));
556
if (ospvAuthReq != OSPC_OSNULL)
558
OSPM_MEMSET(ospvAuthReq, 0,sizeof(OSPTAUTHREQ));
559
ospvAuthReq->ospmAuthReqTimestamp = OSPC_TIMEMIN;
564
/*-----------------------------------------------------------------------*
565
* OSPPAuthReqDelete() - deletes an authorisation request structure
566
*-----------------------------------------------------------------------*/
568
OSPPAuthReqDelete(OSPTAUTHREQ **ospvAuthReq)
570
OSPTCALLID *callid = OSPC_OSNULL;
571
OSPTALTINFO *altinfo = OSPC_OSNULL;
575
while(!OSPPListEmpty(&((*ospvAuthReq)->ospmAuthReqCallId)))
577
callid = (OSPTCALLID *)OSPPListRemove(&((*ospvAuthReq)->ospmAuthReqCallId));
579
if(callid != OSPC_OSNULL)
582
callid = OSPC_OSNULL;
586
OSPPListDelete(&((*ospvAuthReq)->ospmAuthReqCallId));
588
while(!OSPPListEmpty(&((*ospvAuthReq)->ospmAuthReqDeviceInfo)))
590
altinfo = (OSPTALTINFO *)OSPPListRemove(&((*ospvAuthReq)->ospmAuthReqDeviceInfo));
591
if(altinfo != OSPC_OSNULL)
594
altinfo = OSPC_OSNULL;
598
OSPPListDelete(&((*ospvAuthReq)->ospmAuthReqDeviceInfo));
600
while(!OSPPListEmpty(&((*ospvAuthReq)->ospmAuthReqSourceAlternate)))
602
altinfo = (OSPTALTINFO *)OSPPListRemove(&((*ospvAuthReq)->ospmAuthReqSourceAlternate));
603
if(altinfo != OSPC_OSNULL)
606
altinfo = OSPC_OSNULL;
610
OSPPListDelete(&((*ospvAuthReq)->ospmAuthReqSourceAlternate));
612
while(!OSPPListEmpty(&((*ospvAuthReq)->ospmAuthReqDestinationAlternate)))
614
altinfo = (OSPTALTINFO *)OSPPListRemove(&((*ospvAuthReq)->ospmAuthReqDestinationAlternate));
615
if(altinfo != OSPC_OSNULL)
618
altinfo = OSPC_OSNULL;
622
if(OSPPAuthReqHasComponentId(*ospvAuthReq))
624
OSPM_FREE((*ospvAuthReq)->ospmAuthReqComponentId);
628
if(OSPPAuthReqHasMessageId(*ospvAuthReq))
630
OSPM_FREE((*ospvAuthReq)->ospmAuthReqMessageId);
633
OSPPListDelete(&((*ospvAuthReq)->ospmAuthReqDestinationAlternate));
635
OSPM_FREE(*ospvAuthReq);
636
*ospvAuthReq = OSPC_OSNULL;
643
/*-----------------------------------------------------------------------*
644
* OSPPAuthReqAddServiceInfo() - Add service type to usage detail
645
*-----------------------------------------------------------------------*/
646
unsigned OSPPAuthReqAddServiceInfo(
647
OSPTXMLELEM **ospvElem, /* where to put XML element pointer */
648
OSPE_SERVICE_TYPE ServiceType
651
unsigned ospvErrCode = OSPC_ERR_NO_ERROR;
652
OSPTXMLELEM *elem = OSPC_OSNULL;
654
if (ospvElem == OSPC_OSNULL)
656
ospvErrCode = OSPC_ERR_XML_NO_ELEMENT;
659
if (ospvErrCode == OSPC_ERR_NO_ERROR)
661
/* create the parent element */
662
*ospvElem = OSPPXMLElemNew(OSPPMsgGetElemName(ospeElemService), "");
663
if (*ospvElem == OSPC_OSNULL)
665
ospvErrCode = OSPC_ERR_XML_NO_ELEMENT;
668
if (ospvErrCode == OSPC_ERR_NO_ERROR)
670
if (ServiceType == OSPC_VOICE)
672
elem = OSPPXMLElemNew(OSPPMsgGetElemName(ospeElemServiceType), "voice");
676
elem = OSPPXMLElemNew(OSPPMsgGetElemName(ospeElemServiceType), "data");
678
if (elem == OSPC_OSNULL)
680
ospvErrCode = OSPC_ERR_XML_NO_ELEMENT;
683
if (ospvErrCode == OSPC_ERR_NO_ERROR)
685
OSPPXMLElemAddChild(*ospvElem, elem);
688
/* if for any reason we found an error - destroy any elements created */
689
if ((ospvErrCode != OSPC_ERR_NO_ERROR) && (*ospvElem != OSPC_OSNULL))
691
OSPPXMLElemDelete(ospvElem);
700
/*-----------------------------------------------------------------------*
701
* OSPPAuthReqAddPricingInfo() - adds pricing info to an xml element
702
*-----------------------------------------------------------------------*/
703
unsigned OSPPAuthReqAddPricingInfo(
704
OSPTXMLELEM **ospvElem, /* where to put XML element pointer */
705
OSPT_PRICING_INFO PricingInfo
708
unsigned ospvErrCode = OSPC_ERR_NO_ERROR;
709
OSPTXMLELEM *elem = OSPC_OSNULL;
711
if (ospvElem == OSPC_OSNULL)
713
ospvErrCode = OSPC_ERR_XML_NO_ELEMENT;
716
if (ospvErrCode == OSPC_ERR_NO_ERROR)
718
/* create the parent element */
719
*ospvElem = OSPPXMLElemNew(OSPPMsgGetElemName(ospeElemPricingInd), "");
720
if (*ospvElem == OSPC_OSNULL)
722
ospvErrCode = OSPC_ERR_XML_NO_ELEMENT;
726
if (ospvErrCode == OSPC_ERR_NO_ERROR)
728
ospvErrCode = OSPPMsgFloatToElement(PricingInfo.amount,
729
(const unsigned char *)OSPPMsgGetElemName(ospeElemAmount), &elem);
731
if (ospvErrCode == OSPC_ERR_NO_ERROR)
733
OSPPXMLElemAddChild(*ospvElem, elem);
737
/* now add the increment */
738
if (ospvErrCode == OSPC_ERR_NO_ERROR)
740
ospvErrCode = OSPPMsgNumToElement(PricingInfo.increment,
741
(const unsigned char *)OSPPMsgGetElemName(ospeElemIncrement), &elem);
743
if (ospvErrCode == OSPC_ERR_NO_ERROR)
745
OSPPXMLElemAddChild(*ospvElem, elem);
749
/* now we need to add units */
750
if (ospvErrCode == OSPC_ERR_NO_ERROR)
752
elem = OSPPXMLElemNew(OSPPMsgGetElemName(ospeElemUnit),(const char *)PricingInfo.unit);
753
if (elem == OSPC_OSNULL)
755
ospvErrCode = OSPC_ERR_XML_NO_ELEMENT;
758
if (ospvErrCode == OSPC_ERR_NO_ERROR)
760
OSPPXMLElemAddChild(*ospvElem, elem);
765
if (ospvErrCode == OSPC_ERR_NO_ERROR)
767
elem = OSPPXMLElemNew(OSPPMsgGetElemName(ospeElemCurrency),(const char *)PricingInfo.currency);
768
if (elem == OSPC_OSNULL)
770
ospvErrCode = OSPC_ERR_XML_NO_ELEMENT;
773
if (ospvErrCode == OSPC_ERR_NO_ERROR)
775
OSPPXMLElemAddChild(*ospvElem, elem);
779
/* if for any reason we found an error - destroy any elements created */
780
if ((ospvErrCode != OSPC_ERR_NO_ERROR) && (*ospvElem != OSPC_OSNULL))
782
OSPPXMLElemDelete(ospvElem);
789
/*-----------------------------------------------------------------------*
790
* OSPPAuthReqToElement() - create an XML element from an authorisation request
791
*-----------------------------------------------------------------------*/
793
int /* returns error code */
794
OSPPAuthReqToElement(
795
OSPTAUTHREQ *ospvAuthReq, /* authorisation request value */
796
OSPTXMLELEM **ospvElem, /* where to put XML element pointer */
800
int ospvErrCode = OSPC_ERR_NO_ERROR;
801
OSPTXMLELEM *elem = OSPC_OSNULL,
802
*authreqelem = OSPC_OSNULL;
803
OSPTXMLATTR *attr = OSPC_OSNULL;
804
OSPTCALLID *callid = OSPC_OSNULL;
805
OSPTALTINFO *altinfo = OSPC_OSNULL;
806
char random[OSPC_MAX_RANDOM];
807
OSPTBOOL isbase64 = OSPC_TRUE;
808
OSPTTRANS *trans = (OSPTTRANS *)ospvtrans;
811
OSPM_MEMSET(random, 0, OSPC_MAX_RANDOM);
813
if (ospvElem == OSPC_OSNULL)
815
ospvErrCode = OSPC_ERR_XML_NO_ELEMENT;
817
if (ospvAuthReq == OSPC_OSNULL)
819
ospvErrCode = OSPC_ERR_DATA_NO_AUTHREQ;
822
/* create the "Message" element as the parent */
823
*ospvElem = OSPPXMLElemNew(OSPPMsgGetElemName(ospeElemMessage), "");
825
if(*ospvElem == OSPC_OSNULL)
827
ospvErrCode = OSPC_ERR_XML_NO_ELEMENT;
831
attr = OSPPXMLAttrNew((const unsigned char *)OSPPMsgGetAttrName(ospeAttrMessageId),
832
(OSPPAuthReqHasMessageId(ospvAuthReq))?(const unsigned char *)(ospvAuthReq->ospmAuthReqMessageId): (const unsigned char *)"NULL");
834
if (attr != OSPC_OSNULL)
836
OSPPXMLElemAddAttr(*ospvElem, attr);
841
ospvErrCode = OSPC_ERR_XML_NO_ATTR;
845
if((OSPPUtilGetRandom(random, 0) > 0) &&
846
(ospvErrCode == OSPC_ERR_NO_ERROR))
848
attr = OSPPXMLAttrNew((const unsigned char *)OSPPMsgGetAttrName(ospeAttrRandom),
849
(const unsigned char *)random);
851
if (attr != OSPC_OSNULL)
853
OSPPXMLElemAddAttr(*ospvElem, attr);
858
ospvErrCode = OSPC_ERR_XML_NO_ATTR;
863
if (ospvErrCode == OSPC_ERR_NO_ERROR)
865
/* create the authreq element */
866
authreqelem = OSPPXMLElemNew(OSPPMsgGetElemName(ospeElemAuthReq), "");
867
if (authreqelem == OSPC_OSNULL)
869
ospvErrCode = OSPC_ERR_XML_NO_ELEMENT;
871
/* now add the attributes to the parent -- in this case the component id
874
if (ospvErrCode == OSPC_ERR_NO_ERROR)
876
attr = OSPPXMLAttrNew((const unsigned char *)OSPPMsgGetAttrName(ospeAttrComponentId),
877
(OSPPAuthReqHasComponentId(ospvAuthReq))?(const unsigned char *)(ospvAuthReq->ospmAuthReqComponentId): (const unsigned char *)"NULL");
878
if (attr == OSPC_OSNULL)
880
ospvErrCode = OSPC_ERR_XML_NO_ATTR;
883
if (ospvErrCode == OSPC_ERR_NO_ERROR)
885
OSPPXMLElemAddAttr(authreqelem, attr);
889
/* now add the children */
891
if ((ospvErrCode == OSPC_ERR_NO_ERROR) && OSPPAuthReqHasTimestamp(ospvAuthReq))
893
ospvErrCode = OSPPMsgTimeToElement(OSPPAuthReqGetTimestamp(ospvAuthReq),
894
(const unsigned char *)OSPPMsgGetElemName(ospeElemTimestamp), &elem);
895
if (ospvErrCode == OSPC_ERR_NO_ERROR)
897
OSPPXMLElemAddChild(authreqelem, elem);
903
/* add the call ID */
904
if ((ospvErrCode == OSPC_ERR_NO_ERROR) && OSPPAuthReqHasCallId(ospvAuthReq))
906
for (callid = OSPPAuthReqFirstCallId(ospvAuthReq);
907
((callid != OSPC_OSNULL) && (ospvErrCode == OSPC_ERR_NO_ERROR));
908
callid = OSPPAuthReqNextCallId(ospvAuthReq, callid))
910
ospvErrCode = OSPPCallIdToElement(callid, &elem, isbase64);
911
if (ospvErrCode == OSPC_ERR_NO_ERROR)
913
OSPPXMLElemAddChild(authreqelem, elem);
919
/* add the source number */
920
if (ospvErrCode == OSPC_ERR_NO_ERROR)
922
elem = OSPPXMLElemNew(OSPPMsgGetElemName(ospeElemSrcInfo),
923
(const char *)OSPPAuthReqGetSourceNumber(ospvAuthReq));
924
if (elem == OSPC_OSNULL)
926
ospvErrCode = OSPC_ERR_XML_NO_ELEMENT;
929
if (ospvErrCode == OSPC_ERR_NO_ERROR)
931
if (trans->CallingNumberFormat == OSPC_E164)
933
attr = OSPPXMLAttrNew((const unsigned char *)OSPPMsgGetAttrName(ospeAttrType),
934
(const unsigned char *)"e164");
936
else if (trans->CallingNumberFormat == OSPC_SIP)
938
attr = OSPPXMLAttrNew((const unsigned char *)OSPPMsgGetAttrName(ospeAttrType),
939
(const unsigned char *)"sip");
941
else if (trans->CallingNumberFormat == OSPC_URL)
943
attr = OSPPXMLAttrNew((const unsigned char *)OSPPMsgGetAttrName(ospeAttrType),
944
(const unsigned char *)"url");
947
if (attr == OSPC_OSNULL)
949
ospvErrCode = OSPC_ERR_XML_NO_ATTR;
952
if (ospvErrCode == OSPC_ERR_NO_ERROR)
954
OSPPXMLElemAddAttr(elem, attr);
957
if (ospvErrCode == OSPC_ERR_NO_ERROR)
959
OSPPXMLElemAddChild(authreqelem, elem);
963
if ((ospvErrCode == OSPC_ERR_NO_ERROR) &&
964
(ospvAuthReq->ospmAuthReqDeviceInfo != NULL))
968
* Create/Add DeviceInfo elements
971
for(altinfo = (OSPTALTINFO *)OSPPListFirst( &(ospvAuthReq->ospmAuthReqDeviceInfo));
972
altinfo!= (OSPTALTINFO *)OSPC_OSNULL;
973
altinfo = (OSPTALTINFO *)OSPPListNext( &(ospvAuthReq->ospmAuthReqDeviceInfo), altinfo))
975
OSPPAltInfoToElement(altinfo, &elem, ospeElemDeviceInfo);
976
OSPPXMLElemAddChild(authreqelem, elem);
981
/* add the source alternates */
982
if ((ospvErrCode == OSPC_ERR_NO_ERROR) &&
983
OSPPAuthReqHasSourceAlt(ospvAuthReq))
985
for (altinfo = (OSPTALTINFO *)OSPPAuthReqFirstSourceAlt(ospvAuthReq);
986
((altinfo != (OSPTALTINFO *)OSPC_OSNULL) && (ospvErrCode == OSPC_ERR_NO_ERROR));
987
altinfo = (OSPTALTINFO *)OSPPAuthReqNextSourceAlt(ospvAuthReq, altinfo))
989
ospvErrCode = OSPPAltInfoToElement(altinfo, &elem, ospeElemSrcAlt);
990
if (ospvErrCode == OSPC_ERR_NO_ERROR)
992
OSPPXMLElemAddChild(authreqelem, elem);
998
/* add the dest number */
999
if (ospvErrCode == OSPC_ERR_NO_ERROR)
1001
elem = OSPPXMLElemNew(OSPPMsgGetElemName(ospeElemDestInfo),
1002
(const char *)OSPPAuthReqGetDestNumber(ospvAuthReq));
1003
if (elem == OSPC_OSNULL)
1005
ospvErrCode = OSPC_ERR_XML_NO_ELEMENT;
1008
if (ospvErrCode == OSPC_ERR_NO_ERROR)
1010
if (trans->CalledNumberFormat == OSPC_E164)
1012
attr = OSPPXMLAttrNew((const unsigned char *)OSPPMsgGetAttrName(ospeAttrType),
1013
(const unsigned char *)"e164");
1015
else if (trans->CalledNumberFormat == OSPC_SIP)
1017
attr = OSPPXMLAttrNew((const unsigned char *)OSPPMsgGetAttrName(ospeAttrType),
1018
(const unsigned char *)"sip");
1020
else if (trans->CalledNumberFormat == OSPC_URL)
1022
attr = OSPPXMLAttrNew((const unsigned char *)OSPPMsgGetAttrName(ospeAttrType),
1023
(const unsigned char *)"url");
1025
if (attr == OSPC_OSNULL)
1027
ospvErrCode = OSPC_ERR_XML_NO_ATTR;
1030
if (ospvErrCode == OSPC_ERR_NO_ERROR)
1032
OSPPXMLElemAddAttr(elem, attr);
1035
OSPPXMLElemAddChild(authreqelem, elem);
1039
/* add the destination alternates */
1040
if ((ospvErrCode == OSPC_ERR_NO_ERROR) &&
1041
OSPPAuthReqHasDestinationAlt(ospvAuthReq))
1043
altinfo = OSPC_OSNULL;
1044
for (altinfo = (OSPTALTINFO *)OSPPAuthReqFirstDestinationAlt(ospvAuthReq);
1045
((altinfo != (OSPTALTINFO *)OSPC_OSNULL) && (ospvErrCode == OSPC_ERR_NO_ERROR));
1046
altinfo = (OSPTALTINFO *)OSPPAuthReqNextDestinationAlt(ospvAuthReq, altinfo))
1048
ospvErrCode = OSPPAltInfoToElement(altinfo, &elem, ospeElemDestAlt);
1049
if (ospvErrCode == OSPC_ERR_NO_ERROR)
1051
OSPPXMLElemAddChild(authreqelem, elem);
1058
* Add the pricing information
1060
if ((ospvErrCode == OSPC_ERR_NO_ERROR) &&
1061
(trans->IsPricingInfoPresent))
1063
for (i=0;i<trans->NumOfPricingInfoElements;i++)
1065
ospvErrCode = OSPPAuthReqAddPricingInfo(&elem,trans->PricingInfo[i]);
1066
if (ospvErrCode == OSPC_ERR_NO_ERROR)
1068
OSPPXMLElemAddChild(authreqelem, elem);
1078
/* now add the service */
1079
if ((ospvErrCode == OSPC_ERR_NO_ERROR) && (trans->IsServiceInfoPresent == OSPC_TRUE))
1081
ospvErrCode = OSPPAuthReqAddServiceInfo(&elem,trans->ServiceType);
1082
if (ospvErrCode == OSPC_ERR_NO_ERROR)
1084
OSPPXMLElemAddChild(authreqelem, elem);
1090
if (ospvErrCode == OSPC_ERR_NO_ERROR)
1092
elem = OSPPXMLElemNew(OSPPMsgGetElemName(ospeElemService),"");
1093
if (elem == OSPC_OSNULL)
1095
ospvErrCode = OSPC_ERR_XML_NO_ELEMENT;
1098
if (ospvErrCode == OSPC_ERR_NO_ERROR)
1100
OSPPXMLElemAddChild(authreqelem, elem);
1105
/* now add the max destinations */
1106
if (ospvErrCode == OSPC_ERR_NO_ERROR)
1108
ospvErrCode = OSPPMsgNumToElement(
1109
OSPPAuthReqGetMaxDest(ospvAuthReq),
1110
(const unsigned char *)OSPPMsgGetElemName(ospeElemMaxDest),
1113
if (ospvErrCode == OSPC_ERR_NO_ERROR)
1115
OSPPXMLElemAddChild(authreqelem, elem);
1119
/* now add the transnexus extentions (if available) */
1120
if (ospvErrCode == OSPC_ERR_NO_ERROR)
1122
if (OSPPAuthReqHasTNCustId(ospvAuthReq))
1124
ospvErrCode = OSPPMsgNumToElement(
1125
OSPPAuthReqGetTNCustId(ospvAuthReq),
1126
(const unsigned char *) OSPPMsgGetElemName(ospeElemTNCustId),
1129
if (ospvErrCode == OSPC_ERR_NO_ERROR)
1132
attr = OSPPXMLAttrNew(
1133
(const unsigned char *)OSPPMsgGetAttrName(ospeAttrCritical),
1134
(const unsigned char *)"False");
1136
if (attr != OSPC_OSNULL)
1138
OSPPXMLElemAddAttr(elem, attr);
1143
ospvErrCode = OSPC_ERR_XML_NO_ATTR;
1146
if (ospvErrCode == OSPC_ERR_NO_ERROR)
1148
OSPPXMLElemAddChild(authreqelem, elem);
1152
if (OSPPAuthReqHasTNDeviceId(ospvAuthReq) && ospvErrCode == OSPC_ERR_NO_ERROR)
1154
ospvErrCode = OSPPMsgNumToElement(
1155
OSPPAuthReqGetTNDeviceId(ospvAuthReq),
1156
(const unsigned char *) OSPPMsgGetElemName(ospeElemTNDeviceId),
1159
if (ospvErrCode == OSPC_ERR_NO_ERROR)
1161
attr = OSPPXMLAttrNew(
1162
(const unsigned char *)OSPPMsgGetAttrName(ospeAttrCritical),
1163
(const unsigned char *)"False");
1165
if (attr != OSPC_OSNULL)
1167
OSPPXMLElemAddAttr(elem, attr);
1172
ospvErrCode = OSPC_ERR_XML_NO_ATTR;
1175
if (ospvErrCode == OSPC_ERR_NO_ERROR)
1177
OSPPXMLElemAddChild(authreqelem, elem);
1186
if(ospvErrCode == OSPC_ERR_NO_ERROR)
1188
/* Now add the authreqelem to the main elem */
1189
OSPPXMLElemAddChild(*ospvElem, authreqelem);
1190
authreqelem = OSPC_OSNULL;
1193
/* if for any reason we found an error - destroy any elements created */
1194
if (ospvErrCode != OSPC_ERR_NO_ERROR)
1197
if(elem != OSPC_OSNULL)
1199
OSPPXMLElemDelete(&elem);
1202
if(authreqelem != OSPC_OSNULL)
1204
OSPPXMLElemDelete(&authreqelem);
1207
if(attr != OSPC_OSNULL)
1209
OSPPXMLAttrDelete(&attr);
1212
if(*ospvElem != OSPC_OSNULL)
1214
OSPPXMLElemDelete(ospvElem);
1218
return(ospvErrCode);
1221
/*-----------------------------------------------------------------------*
1222
* OSPPAuthReqHasMessageId() - is the message id set ?
1223
*-----------------------------------------------------------------------*/
1224
unsigned /* returns non-zero if message id is set */
1225
OSPPAuthReqHasMessageId(
1226
OSPTAUTHREQ *ospvAuthReq
1229
return (ospvAuthReq->ospmAuthReqMessageId != OSPC_OSNULL);