]> git.saurik.com Git - apple/security.git/blob - SecuritySNACCRuntime/c++-lib/inc/meta.h
Security-54.1.9.tar.gz
[apple/security.git] / SecuritySNACCRuntime / c++-lib / inc / meta.h
1 /*
2 * Copyright (c) 2000-2001 Apple Computer, Inc. All Rights Reserved.
3 *
4 * The contents of this file constitute Original Code as defined in and are
5 * subject to the Apple Public Source License Version 1.2 (the 'License').
6 * You may not use this file except in compliance with the License. Please obtain
7 * a copy of the License at http://www.apple.com/publicsource and read it before
8 * using this file.
9 *
10 * This Original Code and all software distributed under the License are
11 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS
12 * OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, INCLUDING WITHOUT
13 * LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
14 * PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. Please see the License for the
15 * specific language governing rights and limitations under the License.
16 */
17
18
19 // file: .../c++-lib/inc/meta.h
20 //
21 // $Header: /cvs/root/Security/SecuritySNACCRuntime/c++-lib/inc/Attic/meta.h,v 1.1.1.1 2001/05/18 23:14:06 mb Exp $
22 // $Log: meta.h,v $
23 // Revision 1.1.1.1 2001/05/18 23:14:06 mb
24 // Move from private repository to open source repository
25 //
26 // Revision 1.3 2001/05/05 00:59:18 rmurphy
27 // Adding darwin license headers
28 //
29 // Revision 1.2 2000/06/15 18:48:25 dmitch
30 // Snacc-generated source files, now part of CVS tree to allow for cross-platform build of snaccRuntime.
31 //
32 // Revision 1.1.1.1 2000/03/09 01:00:05 rmurphy
33 // Base Fortissimo Tree
34 //
35 // Revision 1.1 1999/02/25 05:21:47 mb
36 // Added snacc c++ library
37 //
38 // Revision 1.6 1997/02/28 13:39:43 wan
39 // Modifications collected for new version 1.3: Bug fixes, tk4.2.
40 //
41 // Revision 1.5 1995/09/07 18:50:04 rj
42 // long int replaced by newly introduced AsnIntType.
43 // it shall provide a 32 bit integer type on all platforms.
44 //
45 // Revision 1.4 1995/08/17 15:23:47 rj
46 // introducing an AsnEnumTypeDesc class with its own TclGetDesc2 function that returns the value names but omits the numeric values.
47 // utility function AsnSe_TypeDesc::mandatmemberr added.
48 //
49
50 #include <unistd.h>
51 #include <stdlib.h>
52
53 struct AsnNameDesc
54 {
55 const char *const name;
56 const AsnIntType value;
57 };
58
59 struct AsnTypeDesc;
60
61 struct AsnMemberDesc // description of CHOICE member; base class for AsnSe_MemberDesc
62 {
63 const char *const name;
64 const AsnTypeDesc *const desc;
65
66 AsnMemberDesc (const char *, const AsnTypeDesc *);
67 AsnMemberDesc();
68
69 #if TCL
70 virtual int TclGetDesc (Tcl_DString *) const;
71 virtual int TclGetDesc2 (Tcl_DString *) const;
72 #endif
73 };
74
75 struct AsnSe_MemberDesc: AsnMemberDesc // _ == t/quence; description of SET or SEQUENCE member
76 {
77 bool optional;
78
79 AsnSe_MemberDesc (const char *, const AsnTypeDesc *, bool);
80 AsnSe_MemberDesc();
81
82 #if TCL
83 int TclGetDesc2 (Tcl_DString *) const;
84 #endif
85 };
86
87 typedef AsnMemberDesc AsnChoiceMemberDesc;
88 typedef AsnSe_MemberDesc AsnSetMemberDesc;
89 typedef AsnSe_MemberDesc AsnSequenceMemberDesc;
90
91 struct AsnModuleDesc;
92
93 class AsnType;
94
95 struct AsnTypeDesc
96 {
97 const AsnModuleDesc *module;
98 const char *const name; // NULL for basic types
99 const bool pdu;
100 const enum Type // NOTE: keep this enum in sync with the typenames[]
101 {
102 VOID,
103 ALIAS,
104
105 INTEGER,
106 REAL,
107 NUL_, // sic! (can't fight the ubiquitous NULL #define)
108 BOOLEAN,
109 ENUMERATED,
110 BIT_STRING,
111 OCTET_STRING,
112 OBJECT_IDENTIFIER,
113
114 SET,
115 SEQUENCE,
116 SET_OF,
117 SEQUENCE_OF,
118 CHOICE,
119 ANY
120 } type;
121
122 AsnType *(*create)();
123
124 static const char *const typenames[];
125
126 AsnTypeDesc (const AsnModuleDesc *, const char *, bool ispdu, Type, AsnType *(*create)());
127
128 virtual const AsnModuleDesc *getmodule() const;
129 virtual const char *getname() const;
130 virtual bool ispdu() const;
131 virtual Type gettype() const;
132 virtual const AsnNameDesc *getnames() const;
133 //virtual const AsnMemberDesc *getmembers() const;
134
135 #if TCL
136 virtual int TclGetDesc (Tcl_DString *) const;
137 virtual int TclGetDesc2 (Tcl_DString *) const;
138 #endif
139 };
140
141 struct AsnNamesTypeDesc: AsnTypeDesc
142 {
143 const AsnNameDesc *const names;
144
145 AsnNamesTypeDesc (const AsnModuleDesc *, const char *, bool ispdu, Type, AsnType *(*create)(), const AsnNameDesc *);
146
147 const AsnNameDesc *getnames() const;
148
149 #if TCL
150 int TclGetDesc (Tcl_DString *) const;
151 // for BIT STRING and INTEGER, ENUMERATED has its own:
152 int TclGetDesc2 (Tcl_DString *) const;
153 #endif
154 };
155
156 struct AsnEnumTypeDesc: AsnNamesTypeDesc
157 {
158 AsnEnumTypeDesc (const AsnModuleDesc *, const char *, bool ispdu, Type, AsnType *(*create)(), const AsnNameDesc *);
159
160 #if TCL
161 int TclGetDesc2 (Tcl_DString *) const;
162 #endif
163 };
164
165 struct AsnMembersTypeDesc: AsnTypeDesc
166 {
167 AsnMembersTypeDesc (const AsnModuleDesc *, const char *, bool ispdu, Type, AsnType *(*create)());
168
169 #if TCL
170 int TclGetDesc (Tcl_DString *) const;
171 #endif
172 };
173
174 struct AsnChoiceTypeDesc: AsnMembersTypeDesc
175 {
176 const AsnChoiceMemberDesc *const members;
177
178 AsnChoiceTypeDesc (const AsnModuleDesc *, const char *, bool ispdu, Type, AsnType *(*create)(), const AsnChoiceMemberDesc *);
179
180 int choicebyname (const char *name) const;
181 const char *choicebyvalue (int value) const;
182
183 #if TCL
184 int TclGetDesc2 (Tcl_DString *) const;
185 #endif
186 };
187
188 struct AsnSe_TypeDesc: AsnMembersTypeDesc
189 {
190 const AsnSe_MemberDesc *const members;
191
192 AsnSe_TypeDesc (const AsnModuleDesc *, const char *, bool ispdu, Type, AsnType *(*create)(), const AsnSe_MemberDesc *);
193
194 #if TCL
195 int mandatmemberr (Tcl_Interp *interp, const char *membername) const;
196 int TclGetDesc2 (Tcl_DString *) const;
197 #endif
198 };
199
200 struct AsnListTypeDesc: AsnTypeDesc
201 {
202 const AsnTypeDesc *const base;
203
204 AsnListTypeDesc (const AsnModuleDesc *, const char *, bool ispdu, Type, AsnType *(*create)(), const AsnTypeDesc *);
205
206 #if TCL
207 int TclGetDesc (Tcl_DString *) const;
208 #endif
209 };
210
211 struct AsnAliasTypeDesc: AsnTypeDesc
212 {
213 const AsnTypeDesc *const alias;
214
215 AsnAliasTypeDesc (const AsnModuleDesc *, const char *, bool ispdu, Type, AsnType *(*create)(), const AsnTypeDesc *);
216
217 const AsnModuleDesc *getmodule() const;
218 const char *getname() const;
219 bool ispdu() const;
220 Type gettype() const;
221
222 const AsnNameDesc *getnames() const;
223 //const AsnMemberDesc *getmembers() const;
224
225 #if TCL
226 int TclGetDesc (Tcl_DString *) const;
227 #endif
228 };
229
230 typedef AsnTypeDesc AsnRealTypeDesc;
231 typedef AsnTypeDesc AsnNullTypeDesc;
232 typedef AsnTypeDesc AsnBoolTypeDesc;
233 typedef AsnNamesTypeDesc AsnIntTypeDesc;
234 typedef AsnNamesTypeDesc AsnBitsTypeDesc;
235 typedef AsnTypeDesc AsnOctsTypeDesc;
236 typedef AsnTypeDesc AsnOidTypeDesc;
237 typedef AsnSe_TypeDesc AsnSetTypeDesc;
238 typedef AsnSe_TypeDesc AsnSequenceTypeDesc;
239
240 struct AsnModuleDesc
241 {
242 const char *const name;
243 const AsnTypeDesc **const types;
244 };
245
246 extern const AsnModuleDesc *asnModuleDescs[];
247
248 #if TCL
249
250 //\[sep]----------------------------------------------------------------------------------------------------------------------------
251 // designed to be used with Tcl_SplitList(): argument list that automagically frees itself when it goes out of scope:
252
253 struct Args
254 {
255 int c;
256 char **v;
257
258 Args();
259 virtual ~Args();
260 };
261
262 //\[sep]----------------------------------------------------------------------------------------------------------------------------
263 // file that automagically closes itself when it goes out of scope:
264
265 struct TmpFD
266 {
267 int fd;
268
269 TmpFD() { fd = -1; }
270 TmpFD (int _fd) { fd = _fd; }
271 ~TmpFD() { if (fd > 0) ::close (fd); }
272
273 int operator = (int _fd){ return fd = _fd; }
274 // operator int() { return fd; }
275 };
276
277 //\[sep]----------------------------------------------------------------------------------------------------------------------------
278 // hack to cope with Tcl's inability to handle binary strings:
279
280 extern int debinify (Tcl_Interp *interp, const char *in, size_t len);
281 extern int binify (Tcl_Interp *interp, const char *str, char *buf, size_t *len);
282
283 //\[sep]----------------------------------------------------------------------------------------------------------------------------
284 #endif /* TCL */