Commit | Line | Data |
---|---|---|
9e8e5516 C |
1 | /* prim2oid.c - presentation element to object identifier */ |
2 | ||
3 | #ifndef lint | |
4 | static char *rcsid = "$Header: /f/osi/psap/RCS/prim2oid.c,v 7.2 91/02/22 09:36:23 mrose Interim $"; | |
5 | #endif | |
6 | ||
7 | /* | |
8 | * $Header: /f/osi/psap/RCS/prim2oid.c,v 7.2 91/02/22 09:36:23 mrose Interim $ | |
9 | * | |
10 | * | |
11 | * $Log: prim2oid.c,v $ | |
12 | * Revision 7.2 91/02/22 09:36:23 mrose | |
13 | * Interim 6.8 | |
14 | * | |
15 | * Revision 7.1 90/05/22 20:30:03 mrose | |
16 | * bug-fix | |
17 | * | |
18 | * Revision 7.0 89/11/23 22:13:12 mrose | |
19 | * Release 6.0 | |
20 | * | |
21 | */ | |
22 | ||
23 | /* | |
24 | * NOTICE | |
25 | * | |
26 | * Acquisition, use, and distribution of this module and related | |
27 | * materials are subject to the restrictions of a license agreement. | |
28 | * Consult the Preface in the User's Manual for the full terms of | |
29 | * this agreement. | |
30 | * | |
31 | */ | |
32 | ||
33 | ||
34 | /* LINTLIBRARY */ | |
35 | ||
36 | #include <stdio.h> | |
37 | #include "psap.h" | |
38 | ||
39 | /* \f */ | |
40 | ||
41 | static int once_only = 1; | |
42 | static OIDentifier oid; | |
43 | ||
44 | /* \f */ | |
45 | ||
46 | OID prim2oid (pe) | |
47 | register PE pe; | |
48 | { | |
49 | register unsigned int i, | |
50 | *ip; | |
51 | register PElementData dp, | |
52 | ep; | |
53 | register OID o = &oid; | |
54 | ||
55 | if (once_only) { | |
56 | bzero ((char *) o, sizeof *o); | |
57 | once_only = 0; | |
58 | } | |
59 | ||
60 | if (pe -> pe_form != PE_FORM_PRIM | |
61 | || (dp = pe -> pe_prim) == NULLPED | |
62 | || pe -> pe_len == 0) | |
63 | return pe_seterr (pe, PE_ERR_PRIM, NULLOID); | |
64 | ep = dp + pe -> pe_len; | |
65 | ||
66 | if (o -> oid_elements) { | |
67 | free ((char *) o -> oid_elements); | |
68 | o -> oid_elements = NULL; | |
69 | } | |
70 | ||
71 | for (i = 1; dp < ep; i++) { /* another whacko OSI encoding... */ | |
72 | if (*dp == 0x80) | |
73 | return pe_seterr (pe, PE_ERR_OID, NULLOID); | |
74 | ||
75 | while (*dp++ & 0x80) | |
76 | if (dp > ep) | |
77 | return pe_seterr (pe, PE_ERR_OID, NULLOID); | |
78 | } | |
79 | ||
80 | if ((ip = (unsigned int *) malloc ((i + 1) * sizeof *ip)) == NULL) | |
81 | return pe_seterr (pe, PE_ERR_NMEM, NULLOID); | |
82 | o -> oid_elements = ip, o -> oid_nelem = i; | |
83 | ||
84 | for (dp = pe -> pe_prim; dp < ep; ) { | |
85 | i = 0; | |
86 | do { | |
87 | i <<= 7; | |
88 | i |= *dp & 0x7f; | |
89 | } while (*dp++ & 0x80); | |
90 | ||
91 | if (ip != o -> oid_elements) | |
92 | *ip++ = i; | |
93 | else | |
94 | if (i < 40) | |
95 | *ip++ = 0, *ip++ = i; | |
96 | else | |
97 | if (i < 80) | |
98 | *ip++ = 1, *ip++ = i - 40; | |
99 | else | |
100 | *ip++ = 2, *ip++ = i - 80; | |
101 | } | |
102 | ||
103 | return o; | |
104 | } | |
105 | ||
106 | /* \f */ | |
107 | ||
108 | #ifdef PEP_TEST | |
109 | free_oid () | |
110 | { | |
111 | if (!once_only && oid.oid_elements) { | |
112 | free ((char *) oid.oid_elements); | |
113 | oid.oid_elements = NULL; | |
114 | } | |
115 | } | |
116 | #endif |