blob: 98d47f445a253e42e19b6d16953eaf5304691a6c [file] [log] [blame]
vlmfa67ddc2004-06-03 03:38:44 +00001#include "asn1fix_internal.h"
2
3typedef enum field_category {
4 OFC_INVALID, /* Invalid object field category */
5 OFC_TYPE,
6 OFC_FIXED_TYPE_VALUE,
7 OFC_VARIABLE_TYPE_VALUE,
8 OFC_FIXED_TYPE_VALUE_SET,
9 OFC_VARIABLE_TYPE_VALUE_SET,
10 OFC_INFORMATION_OBJECT,
11 OFC_INFORMATION_OBJECT_SET,
12} field_category_e;
13
14typedef enum object_category {
15 OC_INVALID,
16 OC_OBJECT,
17 OC_OBJECTSET,
18} object_category_e;
19
20static field_category_e asn1f_class_field_category(asn1p_expr_t *ofield);
21static object_category_e asn1f_class_object_category(asn1p_expr_t *expr);
22static asn1p_expr_t *
23asn1f_class_dot_lookup(arg_t *arg, asn1p_expr_t *obj, asn1p_ref_t *ref);
24
25asn1p_expr_t *
vlm2e0c1942004-08-22 03:10:23 +000026asn1f_class_access(arg_t *arg, asn1p_module_t *mod, asn1p_ref_t *ref) {
vlmfa67ddc2004-06-03 03:38:44 +000027 asn1p_expr_t *obj; /* Information Object or Object Set */
28 object_category_e obj_cat; /* Object category */
29 //field_category_e field_cat; /* Field category */
30 asn1p_expr_t *result;
31 asn1p_ref_t tmpref;
32
vlmfa67ddc2004-06-03 03:38:44 +000033 assert(ref->comp_count > 1);
34
35 DEBUG("%s(%s) for line %d", __func__,
36 asn1f_printable_reference(ref),
37 ref->_lineno);
38
39 /*
40 * Fetch the first part of the reference (OBJECT or ObjectSet).
41 * OBJECT.&<something>...
42 * ObjectSet.&<something>...
43 */
44 assert(isupper(ref->components[0].name[0]));
45
46 tmpref = *ref;
47 tmpref.comp_count = 1;
vlm2e0c1942004-08-22 03:10:23 +000048 obj = asn1f_lookup_symbol(arg, mod, &tmpref);
vlmfa67ddc2004-06-03 03:38:44 +000049 if(obj == NULL) {
50 errno = ESRCH;
51 return NULL;
52 }
53
54 /*
55 * Make sure the symbol lexical property (upper-case, lower-case)
56 * corresponds to the type of the expression returned by
57 * lookup_symbol().
58 */
59 obj_cat = asn1f_class_object_category(obj);
60 switch(obj_cat) {
61 case OC_OBJECT:
62 case OC_OBJECTSET:
63 if(ref->components[0].lex_type
64 == (obj_cat==OC_OBJECT)
65 ? RLT_CAPITALS
66 : RLT_Uppercase)
67 break;
68 /* Fall through */
69 case OC_INVALID:
70 WARNING("Symbol \"%s\" is not compatible "
71 "with referenced expression \"%s\" at line %d",
72 ref->components[0].name,
73 obj->Identifier, obj->_lineno);
74 errno = EPERM;
75 return NULL;
76 }
77
78 /*
79 * Find the specified field within the object.
80 */
81 result = asn1f_class_dot_lookup(arg, obj, ref);
82 if(result == NULL) {
83 return NULL;
84 }
85
86 //field_cat = asn1f_class_field_category(result);
87
88 DEBUG("FILLME: %s", result->Identifier);
89
90 return result;
91}
92
93static object_category_e
94asn1f_class_object_category(asn1p_expr_t *expr) {
95
96 switch(expr->meta_type) {
97 case AMT_OBJECT:
98 return OC_OBJECT;
99 case AMT_OBJECTSET:
100 return OC_OBJECTSET;
101 case AMT_VALUESET:
102 if(expr->expr_type == A1TC_REFERENCE
103 && expr->reference
104 && expr->reference->comp_count == 1
105 && expr->reference->components[0].lex_type == RLT_CAPITALS)
106 {
107 /* FIXME: use find_terminal_type instead! */
108 return OC_OBJECTSET;
109 }
110 break;
111 default:
112 break;
113 }
114
115 return OC_INVALID;
116}
117
118static field_category_e
119asn1f_class_field_category(asn1p_expr_t *ofield) {
120 if(ofield->Identifier[0] != '&') {
121 assert(ofield->Identifier[0] == '&');
122 return OFC_INVALID;
123 }
124
125 if(isupper(ofield->Identifier[1])) {
126 if(ofield->reference) {
127 enum asn1p_ref_lex_type_e lex_type
128 = ofield->reference->components[0].lex_type;
129
130 switch(lex_type) {
131 case RLT_CAPITALS:
132 return OFC_INFORMATION_OBJECT_SET;
133 case RLT_Uppercase:
134 return OFC_FIXED_TYPE_VALUE_SET;
135 case RLT_AmpUppercase:
136 return OFC_VARIABLE_TYPE_VALUE_SET;
137 default:
138 break;
139 }
140 } else {
141 if(ofield->expr_type == A1TC_CLASSFIELD)
142 return OFC_TYPE;
143
144 switch(ofield->meta_type) {
145 case AMT_TYPE:
146 case AMT_TYPEREF:
147 return OFC_FIXED_TYPE_VALUE_SET;
148 default:
149 break;
150 }
151
152 }
153 } else {
154 if(ofield->reference) {
155 enum asn1p_ref_lex_type_e lex_type
156 = ofield->reference->components[0].lex_type;
157
158 switch(lex_type) {
159 case RLT_CAPITALS:
160 return OFC_INFORMATION_OBJECT;
161 case RLT_Uppercase:
162 return OFC_FIXED_TYPE_VALUE;
163 case RLT_AmpUppercase:
164 return OFC_VARIABLE_TYPE_VALUE;
165 default:
166 break;
167 }
168 } else {
169 switch(ofield->meta_type) {
170 case AMT_TYPE:
171 case AMT_TYPEREF:
172 return OFC_FIXED_TYPE_VALUE;
173 default:
174 break;
175 }
176 }
177 }
178
179 return OFC_INVALID;
180}
181
182
183static asn1p_expr_t *
184asn1f_class_dot_lookup(arg_t *arg, asn1p_expr_t *obj, asn1p_ref_t *ref) {
185 asn1p_expr_t *ofield = NULL; /* Information Object's Field */
186 field_category_e field_cat; /* Field category */
187 int comp;
188
189 assert(ref->comp_count >= 2);
190
191 for(comp = 1 /* sic! */; comp < ref->comp_count; comp++) {
192 int is_last_component = (comp + 1 == ref->comp_count);
193 char *comp_name = ref->components[comp].name;
194
195 ofield = asn1f_lookup_child(obj, comp_name);
196 if(ofield == NULL) {
197 DEBUG("Cannot find field \"%s\" in \"%s\" at line %d",
198 ref->components[1].name,
199 obj->Identifier,
200 obj->_lineno);
201 }
202
203 /*
204 * Compute the category of the field of
205 * the information object class.
206 */
207 field_cat = asn1f_class_field_category(ofield);
208
209 switch(field_cat) {
210 case OFC_INVALID:
211 WARNING("Invalid field category of \"%s\" at line %d",
212 ofield->Identifier, ofield->_lineno);
213 errno = EPERM;
214 return NULL;
215 case OFC_TYPE:
216 case OFC_FIXED_TYPE_VALUE:
217 case OFC_VARIABLE_TYPE_VALUE:
218 case OFC_FIXED_TYPE_VALUE_SET:
219 case OFC_VARIABLE_TYPE_VALUE_SET:
220 if(!is_last_component) {
221 FATAL("Field name component \"%s\" at line %d "
222 "specifies non-dereferenceable thing",
223 comp_name, ref->_lineno);
224 errno = EPERM;
225 return NULL;
226 }
227 break;
228 case OFC_INFORMATION_OBJECT:
229 case OFC_INFORMATION_OBJECT_SET:
230 obj = ofield;
231 break;
232 }
233 }
234
235 assert(ofield);
236 return ofield;
237}