]> git.saurik.com Git - apple/security.git/blob - SecuritySNACCRuntime/compiler/back-ends/idl-gen/gen-vals.c
Security-54.1.3.tar.gz
[apple/security.git] / SecuritySNACCRuntime / compiler / back-ends / idl-gen / gen-vals.c
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 /*
20 * compiler/back_ends/idl_gen/gen_vals.c - prints ASN.1 values in IDL format
21 *
22 * MS 92
23 * Copyright (C) 1991, 1992 Michael Sample
24 * and the University of British Columbia
25 *
26 * This program is free software; you can redistribute it and/or modify
27 * it under the terms of the GNU General Public License as published by
28 * the Free Software Foundation; either version 2 of the License, or
29 * (at your option) any later version.
30 *
31 * $Header: /cvs/Darwin/src/live/Security/SecuritySNACCRuntime/compiler/back-ends/idl-gen/gen-vals.c,v 1.1.1.1 2001/05/18 23:14:09 mb Exp $
32 * $Log: gen-vals.c,v $
33 * Revision 1.1.1.1 2001/05/18 23:14:09 mb
34 * Move from private repository to open source repository
35 *
36 * Revision 1.2 2001/05/05 00:59:29 rmurphy
37 * Adding darwin license headers
38 *
39 * Revision 1.1.1.1 1999/03/16 18:06:45 aram
40 * Originals from SMIME Free Library.
41 *
42 * Revision 1.1 1997/01/01 20:25:36 rj
43 * first draft
44 *
45 */
46
47 #include <stdio.h>
48
49 #include "asn-incl.h"
50 #include "asn1module.h"
51 #include "oid.h"
52 #include "mem.h"
53 #include "define.h"
54 #include "lib-types.h"
55 #include "str-util.h"
56 #include "snacc-util.h"
57 #include "rules.h"
58 #include "gen-vals.h"
59
60 /* non-exported routines' prototypes */
61
62 static void PrintIDLValueDefsName PROTO ((FILE *f, IDLRules *r, ValueDef *v));
63
64
65
66
67 void
68 PrintIDLValueDef PARAMS ((idl, r, v),
69 FILE *idl _AND_
70 IDLRules *r _AND_
71 ValueDef *v)
72 {
73 /* just do oid's, ints and bools for now */
74 if ((v->value->basicValue->choiceId != BASICVALUE_OID) &&
75 (v->value->basicValue->choiceId != BASICVALUE_INTEGER) &&
76 (v->value->basicValue->choiceId != BASICVALUE_BOOLEAN))
77 return;
78
79 /*
80 * put instantiation in idl file
81 */
82 fprintf (idl, " const ");
83 PrintIDLValuesClass (idl, r, v->value);
84 fprintf (idl, " ");
85 PrintIDLValueDefsName (idl, r, v);
86 fprintf (idl, " = ");
87 PrintIDLValueInstatiation (idl, r, v->value);
88 fprintf (idl, ";\n\n");
89
90 } /* PrintIDLValueDef */
91
92
93 static void
94 PrintIDLValueDefsName PARAMS ((f, r, v),
95 FILE *f _AND_
96 IDLRules *r _AND_
97 ValueDef *v)
98 {
99 char *cName;
100 cName = Asn1ValueName2CValueName (v->definedName);
101 fprintf (f, "%s", cName);
102 Free (cName);
103 }
104
105 void
106 PrintIDLValuesClass PARAMS ((f, r, v),
107 FILE *f _AND_
108 IDLRules *r _AND_
109 Value *v)
110 {
111 /* needs work - just do ints bools and oid's for now */
112 switch (v->basicValue->choiceId)
113 {
114 case BASICVALUE_OID:
115 fprintf (f, "%s", r->typeConvTbl[BASICTYPE_OID].typeName);
116 break;
117
118 case BASICVALUE_INTEGER:
119 fprintf (f, "%s", r->typeConvTbl[BASICTYPE_INTEGER].typeName);
120 break;
121
122 case BASICVALUE_BOOLEAN:
123 fprintf (f, "%s", r->typeConvTbl[BASICTYPE_BOOLEAN].typeName);
124 break;
125
126 default:
127 break;
128 }
129 }
130
131
132 void
133 PrintIDLValueInstatiation PARAMS ((f, r, v),
134 FILE *f _AND_
135 IDLRules *r _AND_
136 Value *v)
137 {
138 /* needs work - just do oids, ints and bools for now */
139 switch (v->basicValue->choiceId)
140 {
141 case BASICVALUE_OID:
142 PrintIDLOidValue (f, r, v->basicValue->a.oid);
143 break;
144
145 case BASICVALUE_INTEGER:
146 PrintIDLIntValue (f, r, v->basicValue->a.integer);
147 break;
148
149 case BASICVALUE_BOOLEAN:
150 fprintf (f, v->basicValue->a.boolean ? "TRUE" : "FALSE");
151 break;
152
153 default:
154 break;
155 }
156 }
157
158
159
160 /*
161 * given an AOID, c++ AOID constructors params are produced.
162 * This is used for turning ASN.1 OBJECT ID values
163 * into usable c++ values.
164 *
165 * eg for the oid { 0 1 2 } (in AOID format)
166 * (0,1,2)
167 * is produced.
168 */
169 void
170 PrintIDLOidValue PARAMS ((f, r, v),
171 FILE *f _AND_
172 IDLRules *r _AND_
173 AsnOid *v)
174 {
175 unsigned short int firstArcNum;
176 unsigned long int arcNum;
177 int i;
178
179 fprintf (f, "(");
180
181 /* un-munge first two arc numbers */
182 for (arcNum = 0, i=0; (i < v->octetLen) && (v->octs[i] & 0x80);i++)
183 arcNum = (arcNum << 7) + (v->octs[i] & 0x7f);
184
185 arcNum = (arcNum << 7) + (v->octs[i] & 0x7f);
186 i++;
187 firstArcNum = arcNum/40;
188 if (firstArcNum > 2)
189 firstArcNum = 2;
190
191 fprintf (f, "%u, %u", firstArcNum, arcNum - (firstArcNum * 40));
192
193 for (; i < v->octetLen; )
194 {
195 for (arcNum = 0; (i < v->octetLen) && (v->octs[i] & 0x80);i++)
196 arcNum = (arcNum << 7) + (v->octs[i] & 0x7f);
197
198 arcNum = (arcNum << 7) + (v->octs[i] & 0x7f);
199 i++;
200
201 fprintf (f, ", %u", arcNum);
202 }
203 fprintf (f, ")");
204
205 } /* PrintIDLOidValue */
206
207
208
209 void
210 PrintIDLIntValue PARAMS ((f, r, v),
211 FILE *f _AND_
212 IDLRules *r _AND_
213 AsnInt v)
214 {
215 fprintf (f, "%d", v);
216
217 } /* PrintIDLIntValue */