~ubuntu-branches/ubuntu/oneiric/osptoolkit/oneiric

« back to all changes in this revision

Viewing changes to src/ospreauthreq.c

  • Committer: Bazaar Package Importer
  • Author(s): TransNexus, Inc.
  • Date: 2007-12-30 20:37:26 UTC
  • Revision ID: james.westby@ubuntu.com-20071230203726-dysah2e93yqd3vbp
Tags: upstream-3.4.2
ImportĀ upstreamĀ versionĀ 3.4.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/**************************************************************************
 
2
*** COPYRIGHT (c) 2002 by TransNexus, Inc.                              ***
 
3
***                                                                     ***
 
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.             ***
 
12
***                                                                     ***
 
13
*** Thank you for using the OSP ToolKit(TM).  Please report any bugs,   ***
 
14
*** suggestions or feedback to support@transnexus.com                   ***
 
15
***                                                                     ***
 
16
**************************************************************************/
 
17
 
 
18
 
 
19
 
 
20
 
 
21
 
 
22
 
 
23
 
 
24
/*
 
25
 * ospreauthreq.c - OSP authorisation request functions
 
26
 */
 
27
 
 
28
#include <assert.h>
 
29
 
 
30
#include "osp/osp.h"
 
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"
 
46
 
 
47
/* */
 
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 */
 
54
)
 
55
{
 
56
    unsigned ospvHasTime = OSPC_FALSE;
 
57
 
 
58
    if (ospvReauthReq != OSPC_OSNULL)
 
59
    {
 
60
        ospvHasTime = (ospvReauthReq->ospmReauthReqTimestamp != OSPC_TIMEMIN);
 
61
    }
 
62
    return(ospvHasTime);
 
63
}
 
64
 
 
65
/* */
 
66
/*-----------------------------------------------------------------------*
 
67
 * OSPPReauthReqSetTimestamp() - sets the timestamp for an authorisation request
 
68
 *-----------------------------------------------------------------------*/
 
69
void                                       /* nothing returned */
 
70
OSPPReauthReqSetTimestamp(
 
71
    OSPTREAUTHREQ *ospvReauthReq,
 
72
    OSPTTIME  ospvTime
 
73
)
 
74
{
 
75
    if (ospvReauthReq != OSPC_OSNULL)
 
76
    {
 
77
        ospvReauthReq->ospmReauthReqTimestamp = ospvTime;
 
78
    }
 
79
}
 
80
 
 
81
/* */
 
82
/*-----------------------------------------------------------------------*
 
83
 * OSPPReauthReqGetTimestamp() - returns timestamp for an authorisation request
 
84
 *-----------------------------------------------------------------------*/
 
85
OSPTTIME                                   /* returns the time value */
 
86
    OSPPReauthReqGetTimestamp(
 
87
    OSPTREAUTHREQ *ospvReauthReq               /* authorisation request */
 
88
    )
 
89
{
 
90
    OSPTTIME ospvTime = 0;
 
91
 
 
92
    if (ospvReauthReq != OSPC_OSNULL)
 
93
    {
 
94
        ospvTime = ospvReauthReq->ospmReauthReqTimestamp;
 
95
    }
 
96
    return(ospvTime);
 
97
}
 
98
 
 
99
/* */
 
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 */
 
106
)
 
107
{
 
108
    unsigned ospvHasId = OSPC_FALSE;
 
109
 
 
110
    if (ospvReauthReq != OSPC_OSNULL)
 
111
    {
 
112
        ospvHasId = (ospvReauthReq->ospmReauthReqCallId != OSPC_OSNULL);
 
113
    }
 
114
    return(ospvHasId);
 
115
}
 
116
 
 
117
/* */
 
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 */
 
124
    )
 
125
{
 
126
    OSPTCALLID *ospvCallId = OSPC_OSNULL;
 
127
 
 
128
    if (ospvReauthReq != OSPC_OSNULL)
 
129
    {
 
130
        ospvCallId = ospvReauthReq->ospmReauthReqCallId;
 
131
    }
 
132
    return(ospvCallId);
 
133
}
 
134
 
 
135
/* */
 
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) */
 
144
)
 
145
{
 
146
    if (ospvReauthReq != OSPC_OSNULL)
 
147
    {
 
148
        if (ospvNum  != OSPC_OSNULL)
 
149
        {
 
150
            if (OSPM_STRLEN((const char *)ospvNum) < OSPC_E164NUMSIZE)
 
151
            {
 
152
                OSPM_STRNCPY((char *) (ospvReauthReq->ospmReauthReqSourceNumber), 
 
153
                    (const char *)ospvNum, OSPC_E164NUMSIZE-1);
 
154
            }
 
155
        }
 
156
    }
 
157
}
 
158
 
 
159
/* */
 
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 */
 
167
)
 
168
{
 
169
    const unsigned char *ospvNum = OSPC_OSNULL;
 
170
 
 
171
    if (ospvReauthReq != OSPC_OSNULL)
 
172
    {
 
173
        ospvNum = ospvReauthReq->ospmReauthReqSourceNumber;
 
174
    }
 
175
    return(ospvNum);
 
176
}
 
177
 
 
178
/* */
 
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) */
 
187
)
 
188
{
 
189
 
 
190
    if (ospvReauthReq != OSPC_OSNULL)
 
191
    {
 
192
        if (ospvNum  != OSPC_OSNULL)
 
193
        {
 
194
            if (OSPM_STRLEN((const char *)ospvNum) < OSPC_E164NUMSIZE)
 
195
            {
 
196
                OSPM_STRNCPY((char *) (ospvReauthReq->ospmReauthReqDestNumber), 
 
197
                    (const char *)ospvNum, OSPC_E164NUMSIZE-1);
 
198
            }
 
199
        }
 
200
    }
 
201
}
 
202
 
 
203
/* */
 
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 */
 
211
)
 
212
{
 
213
    const unsigned char *ospvNum = OSPC_OSNULL;
 
214
 
 
215
    if (ospvReauthReq != OSPC_OSNULL)
 
216
    {
 
217
        ospvNum = ospvReauthReq->ospmReauthReqDestNumber;
 
218
    }
 
219
    return(ospvNum);
 
220
}
 
221
 
 
222
/* */
 
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 */
 
229
)
 
230
{
 
231
    unsigned ospvHasId = OSPC_FALSE;
 
232
 
 
233
    if (ospvReauthReq != OSPC_OSNULL)
 
234
    {
 
235
        ospvHasId = (ospvReauthReq->ospmReauthReqTrxId != 0);
 
236
    }
 
237
    return(ospvHasId);
 
238
}
 
239
 
 
240
/* */
 
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 */
 
248
)
 
249
{
 
250
 
 
251
    if (ospvReauthReq   != OSPC_OSNULL)
 
252
    {
 
253
        ospvReauthReq->ospmReauthReqTrxId = ospvTrxId;
 
254
    }
 
255
}
 
256
 
 
257
/* */
 
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 */
 
264
    )
 
265
{
 
266
    OSPTTRXID ospvTrxId = 0;
 
267
 
 
268
    if (ospvReauthReq != OSPC_OSNULL)
 
269
    {
 
270
        ospvTrxId = ospvReauthReq->ospmReauthReqTrxId;
 
271
    }
 
272
    return(ospvTrxId);
 
273
}
 
274
 
 
275
/* */
 
276
/*-----------------------------------------------------------------------*
 
277
 * OSPPReauthReqHasDuration() - is the duration set ?
 
278
 *-----------------------------------------------------------------------*/
 
279
unsigned                            /* returns non-zero if number exists */
 
280
OSPPReauthReqHasDuration(
 
281
    OSPTREAUTHREQ *ospvReauthReq              /* Usage Indication effected */
 
282
)
 
283
{
 
284
    unsigned ospvHasDuration = OSPC_FALSE;
 
285
 
 
286
    if (ospvReauthReq != OSPC_OSNULL)
 
287
    {
 
288
        ospvHasDuration = (ospvReauthReq->ospmReauthReqDuration >= 0);
 
289
    }
 
290
    return ospvHasDuration;
 
291
}
 
292
 
 
293
/* */
 
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 */
 
301
)
 
302
{
 
303
    if (ospvReauthReq != OSPC_OSNULL)
 
304
    {
 
305
        if (ospvDuration  >= 0)
 
306
        {
 
307
            ospvReauthReq->ospmReauthReqDuration = ospvDuration;
 
308
        }
 
309
    }
 
310
    return;
 
311
}
 
312
 
 
313
/* */
 
314
/*-----------------------------------------------------------------------*
 
315
 * OSPPReauthReqGetDuration() - returns the duration for a usage ind
 
316
 *-----------------------------------------------------------------------*/
 
317
int
 
318
OSPPReauthReqGetDuration(
 
319
    OSPTREAUTHREQ *ospvReauthReq                     /* usage ind */
 
320
)
 
321
{
 
322
    int ospvDuration = 0;
 
323
 
 
324
    if (ospvReauthReq != OSPC_OSNULL)
 
325
    {
 
326
        ospvDuration = ospvReauthReq->ospmReauthReqDuration;
 
327
    }
 
328
    return ospvDuration;
 
329
}
 
330
 
 
331
/* */
 
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 */
 
339
)
 
340
{
 
341
    if (ospvReauthReq != OSPC_OSNULL)
 
342
    {
 
343
        OSPPListAppend(&(ospvReauthReq->ospmReauthReqTokens), ospvToken);
 
344
    }
 
345
}
 
346
 
 
347
/* */
 
348
/*-----------------------------------------------------------------------*
 
349
 * OSPPReauthReqFirstToken() - gets first token for authorisation indication
 
350
 *-----------------------------------------------------------------------*/
 
351
OSPTTOKEN *                                /* returns null if none */
 
352
    OSPPReauthReqFirstToken(
 
353
    OSPTREAUTHREQ *ospvReauthReq
 
354
    )
 
355
{
 
356
    OSPTTOKEN *ospvToken = OSPC_OSNULL;
 
357
 
 
358
    if(ospvReauthReq != OSPC_OSNULL)
 
359
    {
 
360
        ospvToken = (OSPTTOKEN *)OSPPListFirst(&(ospvReauthReq->ospmReauthReqTokens));
 
361
    }
 
362
    return(ospvToken);
 
363
}
 
364
 
 
365
/* */
 
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 */
 
373
    )
 
374
{
 
375
    OSPTTOKEN *ospvNextToken = OSPC_OSNULL;
 
376
 
 
377
    if (ospvReauthReq  != OSPC_OSNULL)
 
378
    {
 
379
        if (ospvToken != OSPC_OSNULL)
 
380
        {
 
381
            ospvNextToken = (OSPTTOKEN *)OSPPListNext(&(ospvReauthReq->ospmReauthReqTokens), ospvToken);
 
382
        }
 
383
    }
 
384
    return(ospvNextToken);
 
385
}
 
386
 
 
387
/* */
 
388
/*-----------------------------------------------------------------------*
 
389
 * OSPPReauthReqHasComponentId() - is the component id set ?
 
390
 *-----------------------------------------------------------------------*/
 
391
unsigned                    /* returns non-zero if component id is set */
 
392
OSPPReauthReqHasComponentId(
 
393
    OSPTREAUTHREQ *ospvReauthReq
 
394
)
 
395
{
 
396
  return (ospvReauthReq->ospmReauthReqComponentId != OSPC_OSNULL);
 
397
}
 
398
 
 
399
/* */
 
400
/*-----------------------------------------------------------------------*
 
401
 * OSPPReauthReqGetComponentId() - returns a new copy of the component id.
 
402
 *-----------------------------------------------------------------------*/
 
403
unsigned char  *
 
404
OSPPReauthReqGetComponentId(
 
405
    OSPTREAUTHREQ *ospvReauthReq
 
406
)
 
407
{
 
408
    unsigned char   *componentstring   = OSPC_OSNULL;
 
409
    int             len                = 0;
 
410
 
 
411
    if (OSPPReauthReqHasComponentId(ospvReauthReq))
 
412
    {
 
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);
 
417
    }
 
418
 
 
419
    return componentstring;
 
420
}
 
421
 
 
422
/* */
 
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 */
 
430
)
 
431
{
 
432
    if (ospvReauthReq   != OSPC_OSNULL) 
 
433
    {
 
434
        if ((ospvCallId) != OSPC_OSNULL)
 
435
        {
 
436
            if ((ospvReauthReq)->ospmReauthReqCallId != OSPC_OSNULL)
 
437
            {
 
438
                OSPPCallIdDelete(&((ospvReauthReq)->ospmReauthReqCallId));
 
439
            }
 
440
            (ospvReauthReq)->ospmReauthReqCallId = 
 
441
                OSPPCallIdNew((ospvCallId)->ospmCallIdLen, (ospvCallId)->ospmCallIdVal); 
 
442
        }
 
443
    }
 
444
}
 
445
 
 
446
/* */
 
447
/*-----------------------------------------------------------------------*
 
448
 * OSPPReauthReqAddSourceAlt() - add a source alternate to an 
 
449
 * authorisation request
 
450
 *-----------------------------------------------------------------------*/
 
451
void 
 
452
OSPPReauthReqAddSourceAlt(
 
453
    OSPTREAUTHREQ *ospvReauthReq,           /* authorisation request */
 
454
    OSPTALTINFO *ospvAltInfo            /* altinfo to add */
 
455
    )
 
456
{
 
457
    if ((ospvReauthReq != OSPC_OSNULL) &&
 
458
        (ospvAltInfo != OSPC_OSNULL))
 
459
    {
 
460
 
 
461
        OSPPListAppend(&(ospvReauthReq->ospmReauthReqSourceAlternate), (ospvAltInfo));
 
462
    }
 
463
    return;
 
464
}
 
465
 
 
466
/* */
 
467
/*-----------------------------------------------------------------------*
 
468
 * OSPPReauthReqHasSourceAlt() - does an authorisation request have a 
 
469
 * Source Alternate?
 
470
 *-----------------------------------------------------------------------*/
 
471
unsigned                                   /* returns non-zero if exists */
 
472
OSPPReauthReqHasSourceAlt(
 
473
    OSPTREAUTHREQ *ospvReauthReq                  /* authorisation request */
 
474
)
 
475
{
 
476
    unsigned ospvHasSourceAlt = OSPC_FALSE;
 
477
 
 
478
    if (ospvReauthReq != OSPC_OSNULL)
 
479
    {
 
480
        ospvHasSourceAlt = (OSPPReauthReqFirstSourceAlt(ospvReauthReq) != OSPC_OSNULL);
 
481
    }
 
482
    return(ospvHasSourceAlt);
 
483
}
 
484
 
 
485
/* */
 
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 */
 
493
    )
 
494
{
 
495
    OSPTALTINFO *ospvAltInfo = OSPC_OSNULL;
 
496
 
 
497
    if (ospvReauthReq != OSPC_OSNULL)
 
498
    {
 
499
        ospvAltInfo = 
 
500
            (OSPTALTINFO *)OSPPListFirst(&((ospvReauthReq)->ospmReauthReqSourceAlternate));
 
501
    }
 
502
    return(ospvAltInfo);
 
503
}
 
504
 
 
505
/* */
 
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
 
514
    )
 
515
{
 
516
    OSPTALTINFO *altinfo = OSPC_OSNULL;
 
517
 
 
518
    if (ospvReauthReq != OSPC_OSNULL)
 
519
    {
 
520
        altinfo = 
 
521
            (OSPTALTINFO *)OSPPListNext(&((ospvReauthReq)->ospmReauthReqSourceAlternate), 
 
522
            ospvAltInfo);
 
523
    }
 
524
    return(altinfo);
 
525
}
 
526
 
 
527
/* */
 
528
/*-----------------------------------------------------------------------*
 
529
 * OSPPReauthReqAddDestinationAlt() - add a destination alternate to an 
 
530
 * authorisation request
 
531
 *-----------------------------------------------------------------------*/
 
532
void 
 
533
OSPPReauthReqAddDestinationAlt(
 
534
    OSPTREAUTHREQ *ospvReauthReq,   /* authorisation request */
 
535
    OSPTALTINFO *ospvAltInfo    /* altinfo struct */        
 
536
    )
 
537
{
 
538
 
 
539
    if ((ospvReauthReq != OSPC_OSNULL) &&
 
540
        (ospvAltInfo != OSPC_OSNULL))
 
541
    {
 
542
 
 
543
        OSPPListAppend(&(ospvReauthReq->ospmReauthReqDestinationAlternate), (ospvAltInfo));
 
544
    }
 
545
    return;
 
546
}
 
547
 
 
548
/* */
 
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 */
 
556
)
 
557
{
 
558
    unsigned ospvHasDestinationAlt = OSPC_FALSE;
 
559
 
 
560
    if (ospvReauthReq != OSPC_OSNULL)
 
561
    {
 
562
        ospvHasDestinationAlt = (OSPPReauthReqFirstDestinationAlt(ospvReauthReq) != OSPC_OSNULL);
 
563
    }
 
564
    return(ospvHasDestinationAlt);
 
565
}
 
566
 
 
567
/* */
 
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 */
 
575
    )
 
576
{
 
577
    OSPTALTINFO *ospvAltInfo = OSPC_OSNULL;
 
578
 
 
579
    if (ospvReauthReq != OSPC_OSNULL)
 
580
    {
 
581
        ospvAltInfo = 
 
582
            (OSPTALTINFO *)OSPPListFirst(&((ospvReauthReq)->ospmReauthReqDestinationAlternate));
 
583
    }
 
584
    return(ospvAltInfo);
 
585
}
 
586
 
 
587
/* */
 
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
 
596
    )
 
597
{
 
598
    OSPTALTINFO *altinfo = OSPC_OSNULL;
 
599
 
 
600
    if (ospvReauthReq != OSPC_OSNULL)
 
601
    {
 
602
        altinfo = 
 
603
            (OSPTALTINFO *)OSPPListNext(&((ospvReauthReq)->ospmReauthReqDestinationAlternate), 
 
604
            ospvAltInfo);
 
605
    }
 
606
    return(altinfo);
 
607
}
 
608
 
 
609
/* */
 
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 */
 
617
    )
 
618
{
 
619
    unsigned char *ospvAltInfoValue = OSPC_OSNULL;
 
620
 
 
621
    if (ospvAltInfo != OSPC_OSNULL)
 
622
    {
 
623
        ospvAltInfoValue = (unsigned char *)OSPPAltInfoGetValue(ospvAltInfo);
 
624
    }
 
625
    return(ospvAltInfoValue);
 
626
}
 
627
 
 
628
/*-----------------------------------------------------------------------*
 
629
 * OSPPReauthReqDelete() - deletes an authorisation request structure
 
630
 *-----------------------------------------------------------------------*/
 
631
void 
 
632
OSPPReauthReqDelete(OSPTREAUTHREQ **ospvReauthReq)
 
633
{
 
634
    OSPTALTINFO *altinfo    = OSPC_OSNULL;
 
635
    OSPTTOKEN   *token      = OSPC_OSNULL;
 
636
 
 
637
    if (*ospvReauthReq)
 
638
    {
 
639
        if((*ospvReauthReq)->ospmReauthReqCallId != OSPC_OSNULL)
 
640
        {
 
641
            OSPPCallIdDelete(&((*ospvReauthReq)->ospmReauthReqCallId));
 
642
        }  
 
643
 
 
644
        while(!OSPPListEmpty(&((*ospvReauthReq)->ospmReauthReqSourceAlternate)))
 
645
        {
 
646
            altinfo = (OSPTALTINFO *)OSPPListRemove(&((*ospvReauthReq)->ospmReauthReqSourceAlternate));
 
647
            if(altinfo != OSPC_OSNULL)
 
648
            {
 
649
                OSPM_FREE(altinfo);
 
650
                altinfo = OSPC_OSNULL;
 
651
            }
 
652
        }  
 
653
 
 
654
        OSPPListDelete(&((*ospvReauthReq)->ospmReauthReqSourceAlternate));
 
655
 
 
656
        while(!OSPPListEmpty(&((*ospvReauthReq)->ospmReauthReqDevInfo)))
 
657
        {
 
658
            altinfo = (OSPTALTINFO *)OSPPListRemove(&((*ospvReauthReq)->ospmReauthReqDevInfo));
 
659
            if(altinfo != OSPC_OSNULL)
 
660
            {
 
661
                OSPM_FREE(altinfo);
 
662
                altinfo = OSPC_OSNULL;
 
663
            }
 
664
        }  
 
665
 
 
666
        OSPPListDelete(&((*ospvReauthReq)->ospmReauthReqDevInfo));
 
667
 
 
668
        while(!OSPPListEmpty(&((*ospvReauthReq)->ospmReauthReqDestinationAlternate)))
 
669
        {
 
670
            altinfo = (OSPTALTINFO *)OSPPListRemove(&((*ospvReauthReq)->ospmReauthReqDestinationAlternate));
 
671
            if(altinfo != OSPC_OSNULL)
 
672
            {
 
673
                OSPM_FREE(altinfo);
 
674
                altinfo = OSPC_OSNULL;
 
675
            }
 
676
        }  
 
677
 
 
678
        OSPPListDelete(&((*ospvReauthReq)->ospmReauthReqDestinationAlternate));
 
679
 
 
680
        while(!OSPPListEmpty(&((*ospvReauthReq)->ospmReauthReqTokens)))
 
681
        {
 
682
            token = (OSPTTOKEN *)OSPPListRemove(&((*ospvReauthReq)->ospmReauthReqTokens));
 
683
            if(token != OSPC_OSNULL)
 
684
            {
 
685
                OSPPTokenDelete(&token);
 
686
            }
 
687
        }  
 
688
 
 
689
        if(OSPPReauthReqHasMessageId(*ospvReauthReq))
 
690
        {
 
691
            OSPM_FREE((*ospvReauthReq)->ospmReauthReqMessageId);
 
692
        }
 
693
 
 
694
        if(OSPPReauthReqHasComponentId(*ospvReauthReq))
 
695
        {
 
696
            OSPM_FREE((*ospvReauthReq)->ospmReauthReqComponentId);
 
697
        }
 
698
 
 
699
        OSPPListDelete(&((*ospvReauthReq)->ospmReauthReqTokens));
 
700
 
 
701
        OSPM_FREE(*ospvReauthReq);
 
702
        *ospvReauthReq = OSPC_OSNULL;
 
703
    }
 
704
 
 
705
    return;
 
706
}
 
707
 
 
708
/* */
 
709
/*-----------------------------------------------------------------------*
 
710
 * OSPPReauthReqNew() - creates a new (empty) authorisation request
 
711
 *-----------------------------------------------------------------------*/
 
712
 
 
713
OSPTREAUTHREQ *                              /* returns pointer or NULL */
 
714
    OSPPReauthReqNew()
 
715
{
 
716
    OSPTREAUTHREQ *ospvReauthReq = OSPC_OSNULL;
 
717
 
 
718
    OSPM_MALLOC(ospvReauthReq, OSPTREAUTHREQ,sizeof(OSPTREAUTHREQ));
 
719
    if (ospvReauthReq != OSPC_OSNULL)
 
720
    {
 
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;
 
736
    }
 
737
    return(ospvReauthReq);
 
738
}
 
739
 
 
740
/* */
 
741
/*-----------------------------------------------------------------------*
 
742
 * OSPPReauthReqToElement() - create an XML element from a reauthorisation 
 
743
 * request
 
744
 *-----------------------------------------------------------------------*/
 
745
int                                     /* returns error code */
 
746
OSPPReauthReqToElement(
 
747
    OSPTREAUTHREQ  *ospvReauthReq,      /* authorisation request value */
 
748
    OSPTXMLELEM    **ospvElem,           /* where to put XML element pointer */
 
749
    void           *ospvtrans
 
750
)
 
751
{
 
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;
 
762
 
 
763
    OSPM_MEMSET(random, 0, OSPC_MAX_RANDOM);
 
764
 
 
765
    if (ospvElem == OSPC_OSNULL)
 
766
    {
 
767
        ospvErrCode = OSPC_ERR_XML_NO_ELEMENT;
 
768
    }
 
769
    else
 
770
    {
 
771
        *ospvElem = OSPC_OSNULL;
 
772
    }
 
773
    if (ospvReauthReq == OSPC_OSNULL)
 
774
    {
 
775
        ospvErrCode = OSPC_ERR_DATA_NO_REAUTHREQ;
 
776
    }
 
777
 
 
778
    if(ospvErrCode == OSPC_ERR_NO_ERROR)
 
779
    {
 
780
        /* create the "Message" element as the parent */
 
781
    *ospvElem = OSPPXMLElemNew(OSPPMsgGetElemName(ospeElemMessage), "");
 
782
 
 
783
        if(*ospvElem == OSPC_OSNULL)
 
784
        {
 
785
            ospvErrCode = OSPC_ERR_XML_NO_ELEMENT;
 
786
        }
 
787
        else
 
788
        {
 
789
            attr = OSPPXMLAttrNew((const unsigned char *)OSPPMsgGetAttrName(ospeAttrMessageId), 
 
790
                (OSPPReauthReqHasMessageId(ospvReauthReq))?(const unsigned char *)(ospvReauthReq->ospmReauthReqMessageId): (const unsigned char *)"NULL");
 
791
 
 
792
            if (attr != OSPC_OSNULL) 
 
793
            {
 
794
                OSPPXMLElemAddAttr(*ospvElem, attr);
 
795
                attr = OSPC_OSNULL;
 
796
            }
 
797
            else
 
798
            {
 
799
                ospvErrCode = OSPC_ERR_XML_NO_ATTR;
 
800
            }
 
801
 
 
802
            /* random */
 
803
            if((OSPPUtilGetRandom(random, 0) > 0) &&
 
804
                (ospvErrCode == OSPC_ERR_NO_ERROR))
 
805
            {
 
806
                attr = OSPPXMLAttrNew((const unsigned char *)OSPPMsgGetAttrName(ospeAttrRandom),
 
807
                    (const unsigned char *)random);
 
808
 
 
809
                if (attr != OSPC_OSNULL) 
 
810
                {
 
811
                    OSPPXMLElemAddAttr(*ospvElem, attr);
 
812
                    attr = OSPC_OSNULL;
 
813
                }
 
814
                else
 
815
                {
 
816
                    ospvErrCode = OSPC_ERR_XML_NO_ATTR;
 
817
                }
 
818
            }
 
819
        }
 
820
    }
 
821
 
 
822
    if (ospvErrCode == OSPC_ERR_NO_ERROR)
 
823
    {
 
824
        /* now the message type element */
 
825
        reauthelem = OSPPXMLElemNew(OSPPMsgGetElemName(ospeElemReauthReq), "");
 
826
        if (*ospvElem == OSPC_OSNULL)
 
827
        {
 
828
            ospvErrCode = OSPC_ERR_XML_NO_ELEMENT;
 
829
        }
 
830
    }
 
831
    /* now add the attributes to the type element -- in this case the component id
 
832
     *
 
833
     */
 
834
    if (ospvErrCode == OSPC_ERR_NO_ERROR)
 
835
    {
 
836
        attr = OSPPXMLAttrNew((const unsigned char *)OSPPMsgGetAttrName(ospeAttrComponentId), 
 
837
            (OSPPReauthReqHasComponentId(ospvReauthReq))?(const unsigned char *)(ospvReauthReq->ospmReauthReqComponentId): (const unsigned char *)"NULL");
 
838
 
 
839
        if (attr == OSPC_OSNULL)
 
840
        {
 
841
            ospvErrCode = OSPC_ERR_XML_NO_ATTR;
 
842
        }
 
843
    }
 
844
    if (ospvErrCode == OSPC_ERR_NO_ERROR)
 
845
    {
 
846
        OSPPXMLElemAddAttr(reauthelem, attr);
 
847
    }
 
848
 
 
849
    /* now add the children */
 
850
    /* add timestamp  */
 
851
    if ((ospvErrCode == OSPC_ERR_NO_ERROR) && OSPPReauthReqHasTimestamp(ospvReauthReq))
 
852
    {
 
853
        ospvErrCode = OSPPMsgTimeToElement(OSPPReauthReqGetTimestamp(ospvReauthReq),
 
854
            (const unsigned char *)OSPPMsgGetElemName(ospeElemTimestamp), &elem);
 
855
    }
 
856
    if (ospvErrCode == OSPC_ERR_NO_ERROR)
 
857
    {
 
858
        OSPPXMLElemAddChild(reauthelem, elem);
 
859
    }
 
860
 
 
861
    /* add role  */
 
862
    if ((ospvErrCode == OSPC_ERR_NO_ERROR) && OSPPReauthReqHasRole(ospvReauthReq))
 
863
    {
 
864
        ospvErrCode = OSPPMsgRoleToElement(OSPPReauthReqGetRole(ospvReauthReq),
 
865
            (const unsigned char *) OSPPMsgGetElemName(ospeElemRole), &elem);
 
866
        if (ospvErrCode == OSPC_ERR_NO_ERROR)
 
867
        {
 
868
            OSPPXMLElemAddChild(reauthelem, elem);
 
869
            elem = OSPC_OSNULL;
 
870
        }
 
871
    }
 
872
 
 
873
    /* add the call ID */
 
874
    if ((ospvErrCode == OSPC_ERR_NO_ERROR) && OSPPReauthReqHasCallId(ospvReauthReq))
 
875
    {
 
876
        ospvErrCode = OSPPCallIdToElement(OSPPReauthReqGetCallId(ospvReauthReq),
 
877
            &elem, isbase64);
 
878
    }
 
879
    if (ospvErrCode == OSPC_ERR_NO_ERROR)
 
880
    {
 
881
        OSPPXMLElemAddChild(reauthelem, elem);
 
882
    }
 
883
 
 
884
    /* add the source number */
 
885
    if (ospvErrCode == OSPC_ERR_NO_ERROR)
 
886
    {
 
887
        elem = OSPPXMLElemNew(OSPPMsgGetElemName(ospeElemSrcInfo),
 
888
            (const char *)OSPPReauthReqGetSourceNumber(ospvReauthReq));
 
889
        if (elem == OSPC_OSNULL)
 
890
        {
 
891
            ospvErrCode = OSPC_ERR_XML_NO_ELEMENT;
 
892
        }
 
893
    }
 
894
    if (ospvErrCode == OSPC_ERR_NO_ERROR)
 
895
    {
 
896
        if (trans->CallingNumberFormat == OSPC_E164)
 
897
        {
 
898
            attr = OSPPXMLAttrNew((const unsigned char *)OSPPMsgGetAttrName(ospeAttrType), 
 
899
                (const unsigned char *) "e164");
 
900
        }
 
901
        else if (trans->CallingNumberFormat == OSPC_SIP)
 
902
        {
 
903
            attr = OSPPXMLAttrNew((const unsigned char *)OSPPMsgGetAttrName(ospeAttrType), 
 
904
                (const unsigned char *) "sip");
 
905
        }
 
906
        else if (trans->CallingNumberFormat == OSPC_URL)
 
907
        {
 
908
            attr = OSPPXMLAttrNew((const unsigned char *)OSPPMsgGetAttrName(ospeAttrType), 
 
909
                (const unsigned char *) "url");
 
910
        }
 
911
        if (attr == OSPC_OSNULL)
 
912
        {
 
913
            ospvErrCode = OSPC_ERR_XML_NO_ATTR;
 
914
        }
 
915
    }
 
916
    if (ospvErrCode == OSPC_ERR_NO_ERROR)
 
917
    {
 
918
        OSPPXMLElemAddAttr(elem, attr);
 
919
    }
 
920
    if (ospvErrCode == OSPC_ERR_NO_ERROR)
 
921
    {
 
922
        OSPPXMLElemAddChild(reauthelem, elem);
 
923
    }
 
924
 
 
925
    /* add the device info element */
 
926
    if ((ospvErrCode == OSPC_ERR_NO_ERROR) && 
 
927
        (ospvReauthReq->ospmReauthReqDevInfo != NULL))
 
928
    {
 
929
        for (altinfo = (OSPTALTINFO *)OSPPListFirst( &(ospvReauthReq->ospmReauthReqDevInfo));
 
930
            ((altinfo != OSPC_OSNULL) && (ospvErrCode == OSPC_ERR_NO_ERROR));
 
931
            altinfo =  (OSPTALTINFO *)OSPPListNext( &(ospvReauthReq->ospmReauthReqDevInfo), altinfo))
 
932
        {
 
933
            ospvErrCode = OSPPAltInfoToElement(altinfo, &elem, ospeElemDeviceInfo);
 
934
            if (ospvErrCode == OSPC_ERR_NO_ERROR)
 
935
            {
 
936
                OSPPXMLElemAddChild(reauthelem, elem);
 
937
                elem = OSPC_OSNULL;
 
938
            }
 
939
        }
 
940
    }
 
941
 
 
942
    /* add the source alternates */
 
943
    if ((ospvErrCode == OSPC_ERR_NO_ERROR) && 
 
944
        OSPPReauthReqHasSourceAlt(ospvReauthReq))
 
945
    {
 
946
        for (altinfo = OSPPReauthReqFirstSourceAlt(ospvReauthReq);
 
947
            ((altinfo != OSPC_OSNULL) && (ospvErrCode == OSPC_ERR_NO_ERROR));
 
948
            altinfo = OSPPReauthReqNextSourceAlt(ospvReauthReq, altinfo))
 
949
        {
 
950
            ospvErrCode = OSPPAltInfoToElement(altinfo, &elem, ospeElemSrcAlt);
 
951
            if (ospvErrCode == OSPC_ERR_NO_ERROR)
 
952
            {
 
953
                OSPPXMLElemAddChild(reauthelem, elem);
 
954
                elem = OSPC_OSNULL;
 
955
            }
 
956
        }
 
957
    }
 
958
 
 
959
    /* add the dest number */
 
960
    if (ospvErrCode == OSPC_ERR_NO_ERROR)
 
961
    {
 
962
        elem = OSPPXMLElemNew(OSPPMsgGetElemName(ospeElemDestInfo),
 
963
            (const char *)OSPPReauthReqGetDestNumber(ospvReauthReq));
 
964
        if (elem == OSPC_OSNULL)
 
965
        {
 
966
            ospvErrCode = OSPC_ERR_XML_NO_ELEMENT;
 
967
        }
 
968
    }
 
969
    if (ospvErrCode == OSPC_ERR_NO_ERROR)
 
970
    {
 
971
        if (trans->CalledNumberFormat == OSPC_E164)
 
972
        {
 
973
            attr = OSPPXMLAttrNew((const unsigned char *)OSPPMsgGetAttrName(ospeAttrType), 
 
974
                (const unsigned char *)"e164");
 
975
        }
 
976
        else if (trans->CalledNumberFormat == OSPC_SIP)
 
977
        {
 
978
            attr = OSPPXMLAttrNew((const unsigned char *)OSPPMsgGetAttrName(ospeAttrType), 
 
979
                (const unsigned char *)"sip");
 
980
        }
 
981
        else if (trans->CalledNumberFormat == OSPC_URL)
 
982
        {
 
983
            attr = OSPPXMLAttrNew((const unsigned char *)OSPPMsgGetAttrName(ospeAttrType), 
 
984
                (const unsigned char *)"url");
 
985
        }
 
986
 
 
987
        if (attr == OSPC_OSNULL)
 
988
        {
 
989
            ospvErrCode = OSPC_ERR_XML_NO_ATTR;
 
990
        }
 
991
    }
 
992
    if (ospvErrCode == OSPC_ERR_NO_ERROR)
 
993
    {
 
994
        OSPPXMLElemAddAttr(elem, attr);
 
995
    }
 
996
    if (ospvErrCode == OSPC_ERR_NO_ERROR)
 
997
    {
 
998
        OSPPXMLElemAddChild(reauthelem, elem);
 
999
    }
 
1000
 
 
1001
    /* add the destination alternates */
 
1002
    if ((ospvErrCode == OSPC_ERR_NO_ERROR) && 
 
1003
        OSPPReauthReqHasDestinationAlt(ospvReauthReq))
 
1004
    {
 
1005
        for (altinfo = OSPPReauthReqFirstDestinationAlt(ospvReauthReq);
 
1006
            ((altinfo != OSPC_OSNULL) && (ospvErrCode == OSPC_ERR_NO_ERROR));
 
1007
            altinfo = OSPPReauthReqNextDestinationAlt(ospvReauthReq, altinfo))
 
1008
        {
 
1009
            ospvErrCode = OSPPAltInfoToElement(altinfo, &elem, ospeElemDestAlt);
 
1010
            if (ospvErrCode == OSPC_ERR_NO_ERROR)
 
1011
            {
 
1012
                OSPPXMLElemAddChild(reauthelem, elem);
 
1013
                elem = OSPC_OSNULL;
 
1014
            }
 
1015
        }
 
1016
    }
 
1017
 
 
1018
    /* add the transaction ID */
 
1019
    if ((ospvErrCode == OSPC_ERR_NO_ERROR) && OSPPReauthReqHasTrxId(ospvReauthReq))
 
1020
    {
 
1021
        trxid = OSPPReauthReqGetTrxId(ospvReauthReq);
 
1022
        ospvErrCode = OSPPMsgTXToElement( trxid,
 
1023
            (const unsigned char *)OSPPMsgGetElemName(ospeElemTransId),
 
1024
            &elem);
 
1025
    }
 
1026
    if (ospvErrCode == OSPC_ERR_NO_ERROR)
 
1027
    {
 
1028
        OSPPXMLElemAddChild(reauthelem, elem);
 
1029
    }
 
1030
 
 
1031
    /* add usage detail (if appropriate) */
 
1032
    if ((ospvErrCode == OSPC_ERR_NO_ERROR) && OSPPReauthReqHasDuration(ospvReauthReq))
 
1033
    {
 
1034
        ospvErrCode = OSPPUsageToElement(
 
1035
            (unsigned)OSPPReauthReqGetDuration(ospvReauthReq), 0, 0, 0, 0, 0, 0, 0, &elem);
 
1036
        if (ospvErrCode == OSPC_ERR_NO_ERROR)
 
1037
        {
 
1038
            OSPPXMLElemAddChild(reauthelem, elem);
 
1039
        }
 
1040
    }
 
1041
 
 
1042
    if (ospvErrCode == OSPC_ERR_NO_ERROR)
 
1043
    {
 
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))
 
1048
        {
 
1049
            ospvErrCode = OSPPTokenToElement(token, &elem);
 
1050
            if (ospvErrCode == OSPC_ERR_NO_ERROR)
 
1051
            {
 
1052
                OSPPXMLElemAddChild(reauthelem, elem);
 
1053
            }
 
1054
        }
 
1055
    }
 
1056
 
 
1057
    /* now add the transnexus extensions (if available) */
 
1058
    if (ospvErrCode == OSPC_ERR_NO_ERROR)
 
1059
    {
 
1060
        if (OSPPReauthReqHasTNCustId(ospvReauthReq))
 
1061
        {
 
1062
            ospvErrCode = OSPPMsgNumToElement( 
 
1063
                OSPPReauthReqGetTNCustId(ospvReauthReq),
 
1064
                (const unsigned char *)OSPPMsgGetElemName(ospeElemTNCustId),
 
1065
                &elem);
 
1066
 
 
1067
            if (ospvErrCode == OSPC_ERR_NO_ERROR)
 
1068
            {
 
1069
                OSPPXMLElemAddChild(reauthelem, elem);
 
1070
                elem = OSPC_OSNULL;
 
1071
 
 
1072
                if (OSPPReauthReqHasTNDeviceId(ospvReauthReq))
 
1073
                {
 
1074
                    ospvErrCode = OSPPMsgNumToElement( 
 
1075
                        OSPPReauthReqGetTNDeviceId(ospvReauthReq),
 
1076
                        (const unsigned char *)OSPPMsgGetElemName(ospeElemTNDeviceId),
 
1077
                        &elem);
 
1078
 
 
1079
                    if (ospvErrCode == OSPC_ERR_NO_ERROR)
 
1080
                    {
 
1081
                        OSPPXMLElemAddChild(reauthelem, elem);
 
1082
                        elem = OSPC_OSNULL;
 
1083
                    }
 
1084
                }
 
1085
            }
 
1086
        }
 
1087
    }
 
1088
 
 
1089
    if(ospvErrCode == OSPC_ERR_NO_ERROR)
 
1090
    {
 
1091
        /* Now add the reauthelem to the main elem */
 
1092
        OSPPXMLElemAddChild(*ospvElem, reauthelem);
 
1093
        reauthelem = OSPC_OSNULL;
 
1094
    }
 
1095
 
 
1096
    /* if for any reason we found an error - destroy any elements created */
 
1097
    if (ospvErrCode != OSPC_ERR_NO_ERROR)
 
1098
    {
 
1099
        if(*ospvElem != OSPC_OSNULL)
 
1100
        {
 
1101
            OSPPXMLElemDelete(ospvElem);
 
1102
        }
 
1103
 
 
1104
        if(elem != OSPC_OSNULL)
 
1105
        {
 
1106
            OSPPXMLElemDelete(&elem);
 
1107
        }
 
1108
    
 
1109
        if(reauthelem != OSPC_OSNULL)
 
1110
        {
 
1111
            OSPPXMLElemDelete(&reauthelem);
 
1112
        }
 
1113
    
 
1114
        if(attr != OSPC_OSNULL)
 
1115
        {
 
1116
            OSPPXMLAttrDelete(&attr);
 
1117
        }
 
1118
    }
 
1119
 
 
1120
    return(ospvErrCode);
 
1121
}
 
1122
 
 
1123
/* */
 
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 */
 
1130
)
 
1131
{
 
1132
    unsigned ospvHasRole = OSPC_FALSE;
 
1133
    if (ospvReauthReq != OSPC_OSNULL)
 
1134
    {
 
1135
        ospvHasRole = ((ospvReauthReq)->ospmReauthReqHasRole != OSPC_FALSE);
 
1136
    }
 
1137
    return(ospvHasRole);
 
1138
}
 
1139
 
 
1140
/* */
 
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 */
 
1147
    )
 
1148
{
 
1149
    OSPE_MSG_ROLETYPES ospvRole = OSPC_UNDEFINED_ROLE;
 
1150
 
 
1151
    if (ospvReauthReq != OSPC_OSNULL)
 
1152
    {
 
1153
        ospvRole = (OSPE_MSG_ROLETYPES)ospvReauthReq->ospmReauthReqRole;
 
1154
    }
 
1155
    return(ospvRole);
 
1156
}
 
1157
 
 
1158
 
 
1159
/* */
 
1160
/*-----------------------------------------------------------------------*
 
1161
 * OSPPReauthReqSetRole() - sets value for role in reauthorisation request
 
1162
 *-----------------------------------------------------------------------*/
 
1163
 
 
1164
void                              
 
1165
OSPPReauthReqSetRole(
 
1166
    OSPTREAUTHREQ       *ospvReauthReq,
 
1167
    OSPE_MSG_ROLETYPES  ospvRole)
 
1168
{
 
1169
 
 
1170
    if (ospvReauthReq != OSPC_OSNULL)
 
1171
    {
 
1172
        ospvReauthReq->ospmReauthReqHasRole = OSPC_TRUE;
 
1173
        ospvReauthReq->ospmReauthReqRole = ospvRole;
 
1174
    }
 
1175
    return;
 
1176
}
 
1177
 
 
1178
/* */
 
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 */
 
1185
)
 
1186
{
 
1187
    unsigned ospvHasTNCustId = OSPC_FALSE;
 
1188
 
 
1189
    if (ospvReauthReq != OSPC_OSNULL)
 
1190
    {
 
1191
        ospvHasTNCustId = ((ospvReauthReq)->ospmReauthReqTNCustId != 0L);
 
1192
    }
 
1193
    return(ospvHasTNCustId);
 
1194
}
 
1195
 
 
1196
/* */
 
1197
/*-----------------------------------------------------------------------*
 
1198
 * OSPPReauthReqSetTNCustId() - Set TransNexus Customer Id
 
1199
 *-----------------------------------------------------------------------*/
 
1200
void                                       /* nothing returned */
 
1201
OSPPReauthReqSetTNCustId(
 
1202
    OSPTREAUTHREQ   *ospvReauthReq,
 
1203
    unsigned long ospvTNCustId
 
1204
)
 
1205
{
 
1206
    if (ospvReauthReq != OSPC_OSNULL)
 
1207
    {
 
1208
        (ospvReauthReq)->ospmReauthReqTNCustId = (ospvTNCustId);
 
1209
    }
 
1210
}
 
1211
 
 
1212
/* */
 
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 */
 
1219
    )
 
1220
{
 
1221
    unsigned long ospvTNCustId = 0L;
 
1222
 
 
1223
    if (ospvReauthReq != OSPC_OSNULL)
 
1224
    {
 
1225
        ospvTNCustId = (ospvReauthReq)->ospmReauthReqTNCustId;
 
1226
    }
 
1227
    return(ospvTNCustId);
 
1228
}
 
1229
 
 
1230
/* */
 
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 */
 
1237
)
 
1238
{
 
1239
    unsigned ospvHasTNDeviceId = OSPC_FALSE;
 
1240
 
 
1241
    if (ospvReauthReq != OSPC_OSNULL)
 
1242
    {
 
1243
        ospvHasTNDeviceId = ((ospvReauthReq)->ospmReauthReqTNDeviceId != 0L);
 
1244
    }
 
1245
    return(ospvHasTNDeviceId);
 
1246
}
 
1247
 
 
1248
/* */
 
1249
/*-----------------------------------------------------------------------*
 
1250
 * OSPPReauthReqSetTNDeviceId() - Set TransNexus Device Id
 
1251
 *-----------------------------------------------------------------------*/
 
1252
void                                       /* nothing returned */
 
1253
OSPPReauthReqSetTNDeviceId(
 
1254
    OSPTREAUTHREQ    *ospvReauthReq,
 
1255
    unsigned long  ospvTNDeviceId
 
1256
)
 
1257
{
 
1258
    if (ospvReauthReq != OSPC_OSNULL)
 
1259
    {
 
1260
        (ospvReauthReq)->ospmReauthReqTNDeviceId = (ospvTNDeviceId);
 
1261
    }
 
1262
}
 
1263
 
 
1264
/* */
 
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 */
 
1271
    )
 
1272
{
 
1273
    unsigned long ospvTNDeviceId = 0L;
 
1274
 
 
1275
    if (ospvReauthReq != OSPC_OSNULL)
 
1276
    {
 
1277
        ospvTNDeviceId = (ospvReauthReq)->ospmReauthReqTNDeviceId;
 
1278
    }
 
1279
    return(ospvTNDeviceId);
 
1280
}
 
1281
 
 
1282
/*-----------------------------------------------------------------------*
 
1283
 * OSPPReauthReqHasMessageId() - is the message id set ?
 
1284
 *-----------------------------------------------------------------------*/
 
1285
unsigned                   /* returns non-zero if message id is set */
 
1286
OSPPReauthReqHasMessageId(
 
1287
    OSPTREAUTHREQ *ospvReauthReq
 
1288
)
 
1289
{
 
1290
  return (ospvReauthReq->ospmReauthReqMessageId != OSPC_OSNULL);
 
1291
}
 
1292
 
 
1293