1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
|
/* obj2prim.c - object identifier to presentation element */
/*
* isode/psap/obj2prim.c
*/
/*
* NOTICE
*
* Acquisition, use, and distribution of this module and related
* materials are subject to the restrictions of a license agreement.
* Consult the Preface in the User's Manual for the full terms of
* this agreement.
*
*/
/* LINTLIBRARY */
#include <stdio.h>
#include "psap.h"
/* */
PE obj2prim (o, class, id)
register OID o;
PElementClass class;
PElementID id;
{
register int i,
m,
n,
*mp,
*np;
register unsigned int j,
*ip;
register PElementData dp,
ep;
register PE pe;
if (o == NULLOID
|| o -> oid_nelem <= 1
|| o -> oid_elements[0] > 2
|| (o -> oid_elements[0] < 2 && o -> oid_elements[1] > 39))
return NULLPE;
if ((pe = pe_alloc (class, PE_FORM_PRIM, id)) == NULLPE)
return NULLPE;
if ((np = (int *) malloc ((unsigned) (o -> oid_nelem) * sizeof *np))
== NULL) {
pe_free (pe);
return NULLPE;
}
for (i = n = 0, ip = o -> oid_elements, mp = np;
i < o -> oid_nelem;
i++, ip++) {
if (ip == o -> oid_elements)
j = *ip++ * 40, i++, j+= *ip;
else
j = *ip;
m = 0;
do {
m++;
j >>= 7;
}
while (j);
n += (*mp++ = m);
}
if ((pe -> pe_prim = PEDalloc (pe -> pe_len = n)) == NULLPED) {
free ((char *) np);
pe_free (pe);
return NULLPE;
}
dp = pe -> pe_prim;
for (i = 0, ip = o -> oid_elements, mp = np;
i < o -> oid_nelem;
i++, ip++) {
if (ip == o -> oid_elements)
j = *ip++ * 40, i++, j += *ip;
else
j = *ip;
ep = dp + (m = *mp++) - 1;
for (dp = ep; m-- > 0; j >>= 7)
*dp-- = (j & 0x7f) | 0x80;
*ep &= ~0x80;
dp = ep + 1;
}
free ((char *) np);
return pe;
}
|