]>
git.saurik.com Git - apple/security.git/blob - SecuritySNACCRuntime/c++-lib/c++/meta.cpp
2 * Copyright (c) 2000-2001 Apple Computer, Inc. All Rights Reserved.
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
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.
19 // file: .../c++-lib/src/meta.C
21 // $Header: /cvs/Darwin/Security/SecuritySNACCRuntime/c++-lib/c++/meta.cpp,v 1.1.1.1 2001/05/18 23:14:06 mb Exp $
23 // Revision 1.1.1.1 2001/05/18 23:14:06 mb
24 // Move from private repository to open source repository
26 // Revision 1.2 2001/05/05 00:59:17 rmurphy
27 // Adding darwin license headers
29 // Revision 1.1 2000/06/15 18:44:58 dmitch
30 // These snacc-generated source files are now checked in to allow cross-platform build.
32 // Revision 1.2 2000/06/08 20:05:36 dmitch
33 // Mods for X port. These files are actually machine generated and probably don't need to be in CVS....
35 // Revision 1.1.1.1 2000/03/09 01:00:06 rmurphy
36 // Base Fortissimo Tree
38 // Revision 1.1 1999/02/25 05:21:56 mb
39 // Added snacc c++ library
41 // Revision 1.5 1997/02/28 13:39:47 wan
42 // Modifications collected for new version 1.3: Bug fixes, tk4.2.
44 // Revision 1.4 1995/08/17 15:23:51 rj
45 // introducing an AsnEnumTypeDesc class with its own TclGetDesc2 function that returns the value names but omits the numeric values.
46 // utility function AsnSe_TypeDesc::mandatmemberr added.
48 // Revision 1.3 1995/07/26 19:39:35 rj
49 // comment leader fixed
51 // Revision 1.2 1995/07/25 22:11:31 rj
52 // lots of new data types, and new data and function members in old ones.
54 // use memcmpeq that is defined in .../snacc.h to use either memcmp or bcmp.
56 // code extracted from AsnOcts::TclGetVal and AsnOcts::TclSetVal in asn-octs.C into ::debinify and ::binify.
58 // #if TCL ... #endif wrapped into #if META ... #endif
60 // call constructor with additional pdu and create arguments.
62 // changed `_' to `-' in file names.
68 AsnMemberDesc::AsnMemberDesc (const char *_name
, const AsnTypeDesc
*_desc
):
74 AsnMemberDesc::AsnMemberDesc():
75 name (NULL
), desc(NULL
)
79 int AsnMemberDesc::TclGetDesc (Tcl_DString
*desc
) const
83 Tcl_DStringStartSublist (desc
);
84 Tcl_DStringAppendElement (desc
, (char*)name
);
85 this->desc
->AsnTypeDesc::TclGetDesc (desc
);
87 Tcl_DStringEndSublist (desc
);
94 int AsnMemberDesc::TclGetDesc2 (Tcl_DString
*desc
) const
99 AsnSe_MemberDesc::AsnSe_MemberDesc (const char *name
, const AsnTypeDesc
*desc
, bool _optional
):
100 AsnMemberDesc (name
, desc
),
105 AsnSe_MemberDesc::AsnSe_MemberDesc():
110 int AsnSe_MemberDesc::TclGetDesc2 (Tcl_DString
*desc
) const
112 Tcl_DStringAppendElement (desc
, optional
? "optional" : "mandatory");
116 const char *const AsnTypeDesc::typenames
[] = // NOTE: keep this array in sync with the enum Type
138 AsnTypeDesc::AsnTypeDesc (const AsnModuleDesc
*_module
, const char *_name
, bool ispdu
, Type _type
, AsnType
*(*_create
)()):
147 const AsnModuleDesc
*AsnTypeDesc::getmodule() const
152 const char *AsnTypeDesc::getname() const
157 bool AsnTypeDesc::ispdu() const
162 AsnTypeDesc::Type
AsnTypeDesc::gettype() const
167 const AsnNameDesc
*AsnTypeDesc::getnames() const
169 Asn1Error
<< typenames
[type
] << "::getnames() called" << endl
;
174 //const AsnMemberDesc *AsnTypeDesc::getmembers() const
176 //Asn1Error << typenames[type] << "::getmembers() called" << endl;
180 //\[banner "names types (int, enum)"]-----------------------------------------------------------------------------------------------
181 AsnNamesTypeDesc::AsnNamesTypeDesc (const AsnModuleDesc
*module, const char *name
, bool ispdu
, Type type
, AsnType
*(*create
)(), const AsnNameDesc
*_names
):
182 AsnTypeDesc (module, name
, ispdu
, type
, create
),
187 const AsnNameDesc
*AsnNamesTypeDesc::getnames() const
192 //\[banner "enum type"]-------------------------------------------------------------------------------------------------------------
193 AsnEnumTypeDesc::AsnEnumTypeDesc (const AsnModuleDesc
*module, const char *name
, bool ispdu
, Type type
, AsnType
*(*create
)(), const AsnNameDesc
*names
):
194 AsnNamesTypeDesc (module, name
, ispdu
, type
, create
, names
)
198 //\[banner "members types (choice, set, sequence)"]---------------------------------------------------------------------------------
199 AsnMembersTypeDesc::AsnMembersTypeDesc (const AsnModuleDesc
*module, const char *name
, bool ispdu
, Type type
, AsnType
*(*create
)()):
200 AsnTypeDesc (module, name
, ispdu
, type
, create
)
204 //\[banner "choice type"]-----------------------------------------------------------------------------------------------------------
205 AsnChoiceTypeDesc::AsnChoiceTypeDesc (const AsnModuleDesc
*module, const char *name
, bool ispdu
, Type type
, AsnType
*(*create
)(), const AsnChoiceMemberDesc
*_members
):
206 AsnMembersTypeDesc (module, name
, ispdu
, type
, create
),
211 int AsnChoiceTypeDesc::choicebyname (const char *name
) const
213 for (int m
=0; members
[m
].name
; m
++)
214 if (!strcmp (members
[m
].name
, name
))
220 const char *AsnChoiceTypeDesc::choicebyvalue (int value
) const
222 return members
[value
].name
;
225 //\[banner "set/sequence type"]-----------------------------------------------------------------------------------------------------
226 AsnSe_TypeDesc::AsnSe_TypeDesc (const AsnModuleDesc
*module, const char *name
, bool ispdu
, Type type
, AsnType
*(*create
)(), const AsnSe_MemberDesc
*_members
):
227 AsnMembersTypeDesc (module, name
, ispdu
, type
, create
),
232 //\[banner "list type"]-------------------------------------------------------------------------------------------------------------
233 AsnListTypeDesc::AsnListTypeDesc (const AsnModuleDesc
*module, const char *name
, bool ispdu
, Type type
, AsnType
*(*create
)(), const AsnTypeDesc
*_base
):
234 AsnTypeDesc (module, name
, ispdu
, type
, create
),
239 //\[banner "alias type"]------------------------------------------------------------------------------------------------------------
240 AsnAliasTypeDesc::AsnAliasTypeDesc (const AsnModuleDesc
*module, const char *name
, bool ispdu
, Type type
, AsnType
*(*create
)(), const AsnTypeDesc
*_alias
):
241 AsnTypeDesc (module, name
, ispdu
, type
, create
),
246 const AsnModuleDesc
*AsnAliasTypeDesc::getmodule() const
251 const char *AsnAliasTypeDesc::getname() const
256 bool AsnAliasTypeDesc::ispdu() const
261 AsnTypeDesc::Type
AsnAliasTypeDesc::gettype() const
263 return alias
->gettype();
266 const AsnNameDesc
*AsnAliasTypeDesc::getnames() const
268 return alias
->getnames();
271 //const AsnMemberDesc *AsnAliasTypeDesc::getmembers() const
273 //return alias->getmembers();
276 //\[banner "Tcl routines"]----------------------------------------------------------------------------------------------------------
279 int AsnTypeDesc::TclGetDesc (Tcl_DString
*desc
) const
281 Tcl_DStringStartSublist (desc
);
282 Tcl_DStringAppendElement (desc
, getmodule() ? (char*) getmodule()->name
: "");
283 Tcl_DStringAppendElement (desc
, getname() ? (char*) getname() : "");
284 Tcl_DStringEndSublist (desc
);
285 Tcl_DStringAppendElement (desc
, ispdu() ? "pdu" : "sub");
286 Tcl_DStringAppendElement (desc
, (char*) typenames
[gettype()]);
291 int AsnTypeDesc::TclGetDesc2 (Tcl_DString
*desc
) const
296 int AsnNamesTypeDesc::TclGetDesc (Tcl_DString
*desc
) const
298 AsnTypeDesc::TclGetDesc (desc
);
299 return TclGetDesc2 (desc
);
302 // for BIT STRING and INTEGER:
303 int AsnNamesTypeDesc::TclGetDesc2 (Tcl_DString
*desc
) const
305 Tcl_DStringStartSublist (desc
);
306 const AsnNameDesc
*n
;
310 Tcl_DStringStartSublist (desc
);
311 Tcl_DStringAppendElement (desc
, (char*) n
->name
);
313 sprintf (buf
, "%d", n
->value
);
314 Tcl_DStringAppendElement (desc
, buf
);
315 Tcl_DStringEndSublist (desc
);
317 Tcl_DStringEndSublist (desc
);
322 int AsnEnumTypeDesc::TclGetDesc2 (Tcl_DString
*desc
) const
324 Tcl_DStringStartSublist (desc
);
325 const AsnNameDesc
*n
;
328 Tcl_DStringAppendElement (desc
, (char*) n
->name
);
329 Tcl_DStringEndSublist (desc
);
334 int AsnMembersTypeDesc::TclGetDesc (Tcl_DString
*desc
) const
336 AsnTypeDesc::TclGetDesc (desc
);
337 return TclGetDesc2 (desc
);
340 int AsnChoiceTypeDesc::TclGetDesc2 (Tcl_DString
*desc
) const
342 Tcl_DStringStartSublist (desc
);
343 const AsnChoiceMemberDesc
*m
;
345 for (; m
->TclGetDesc (desc
) == TCL_OK
; m
++)
347 Tcl_DStringEndSublist (desc
);
352 int AsnSe_TypeDesc::mandatmemberr (Tcl_Interp
*interp
, const char *membername
) const
354 sprintf (interp
->result
, "(in type %s.%s:) member %s is mandatory and can't be deleted", getmodule()->name
, getname(), membername
);
355 Tcl_SetErrorCode (interp
, "SNACC", "MANDMEMB", NULL
);
359 int AsnSe_TypeDesc::TclGetDesc2 (Tcl_DString
*desc
) const
361 Tcl_DStringStartSublist (desc
);
362 const AsnSe_MemberDesc
*m
;
364 for (; m
->TclGetDesc (desc
) == TCL_OK
; m
++)
366 Tcl_DStringEndSublist (desc
);
371 int AsnListTypeDesc::TclGetDesc (Tcl_DString
*desc
) const
373 AsnTypeDesc::TclGetDesc (desc
);
374 return base
->AsnTypeDesc::TclGetDesc (desc
);
377 int AsnAliasTypeDesc::TclGetDesc (Tcl_DString
*desc
) const
379 AsnTypeDesc::TclGetDesc (desc
);
380 return alias
->TclGetDesc2 (desc
);
383 //\[sep]----------------------------------------------------------------------------------------------------------------------------
384 // designed to be used with Tcl_SplitList(): argument list that automagically frees itself when it goes out of scope:
396 //\[sep]----------------------------------------------------------------------------------------------------------------------------
397 // since Tcl cannot handle binary strings, the following hack is needed:
399 int debinify (Tcl_Interp
*interp
, const char *bin
, size_t len
)
405 str
= new char[2*len
+1];
407 str
= (char *) mem_mgr_ptr
->Get (2*len
+2);
408 #endif /* _IBM_ENC_ */
411 for (o
=i
=0; i
<len
; i
++)
426 Tcl_SetResult (interp
, str
, TCL_VOLATILE
);
431 mem_mgr_ptr
->Put ((void*) str
);
432 #endif /* _IBM_ENC_ */
437 int binify (Tcl_Interp
*interp
, const char *str
, char *buf
, size_t *len
)
444 buf
[(*len
)++] = '\0';
448 buf
[(*len
)++] = *str
++;
451 Tcl_AppendResult (interp
, "illegal use of '\\' in string value", NULL
);
452 Tcl_SetErrorCode (interp
, "SNACC", "ILLESC", NULL
);
456 buf
[(*len
)++] = *str
++;
461 //\[sep]----------------------------------------------------------------------------------------------------------------------------