blob: b52406e37bdd7558450614c851528da38e8a7c08 [file] [log] [blame]
Lev Walkinf15320b2004-06-03 03:38:44 +00001#include "asn1fix_internal.h"
Lev Walkin4efbfb72005-02-25 14:20:30 +00002#include "asn1fix.h"
Lev Walkinf15320b2004-06-03 03:38:44 +00003
4/* Print everything to stderr */
5static void _default_error_logger(int _severity, const char *fmt, ...);
6
7/*
8 * Internal check functions.
9 */
Lev Walkind24c62d2004-09-15 11:47:23 +000010static int asn1f_fix_module__phase_1(arg_t *arg);
11static int asn1f_fix_module__phase_2(arg_t *arg);
Lev Walkinf15320b2004-06-03 03:38:44 +000012static int asn1f_fix_simple(arg_t *arg); /* For INTEGER/ENUMERATED */
13static int asn1f_fix_constructed(arg_t *arg); /* For SEQUENCE/SET/CHOICE */
Lev Walkin1ef05162004-08-25 00:42:25 +000014static int asn1f_resolve_constraints(arg_t *arg); /* For subtype constraints */
15static int asn1f_check_constraints(arg_t *arg); /* For subtype constraints */
Lev Walkinf593f102005-02-22 07:59:59 +000016static int asn1f_check_duplicate(arg_t *arg);
Lev Walkin1dec5802005-03-04 09:02:27 +000017static int asn1f_apply_unique_index(arg_t *arg);
Lev Walkina00d6b32006-03-21 03:40:38 +000018static int phase_1_1(arg_t *arg, int prm2);
Lev Walkinf15320b2004-06-03 03:38:44 +000019
Lev Walkinb45e0672004-08-18 05:42:05 +000020arg_t a1f_replace_me_with_proper_interface_arg;
Lev Walkinf15320b2004-06-03 03:38:44 +000021
22/*
23 * Scan every module defined here in search for inconsistences.
24 */
25int
26asn1f_process(asn1p_t *asn, enum asn1f_flags flags,
27 error_logger_f error_logger) {
28 arg_t arg;
29 int fatals = 0;
30 int warnings = 0;
Lev Walkin4533a5f2005-03-18 04:22:41 +000031 int ret;
Lev Walkinf15320b2004-06-03 03:38:44 +000032
33 /*
34 * Check validity of arguments.
35 */
36 if(asn == NULL) {
37 errno = EINVAL;
38 return -1;
39 }
40
41 /*
42 * If errors handler is not specified, default to internal one.
43 */
44 if(error_logger == 0) {
45 error_logger = _default_error_logger;
46 }
47
48 memset(&arg, 0, sizeof(arg));
49 arg.asn = asn;
50 arg.eh = error_logger;
51
52 if(flags & A1F_DEBUG) {
53 arg.debug = arg.eh;
54 arg.debug(-1, "Called %s() with flags %d", __func__, flags);
55 flags &= ~A1F_DEBUG;
56 }
57
Lev Walkin5253da42004-08-20 13:25:56 +000058 /* Allow SIZE() constraint for INTEGER and other types */
59 if(flags & A1F_EXTENDED_SizeConstraint) {
60 arg.flags |= A1F_EXTENDED_SizeConstraint;
61 flags &= ~A1F_EXTENDED_SizeConstraint;
62 if(arg.debug) {
63 arg.debug(-1,
64 "Extended SizeConstraint support enabled");
65 }
66 }
67
Lev Walkinb45e0672004-08-18 05:42:05 +000068 a1f_replace_me_with_proper_interface_arg = arg;
69
Lev Walkinf15320b2004-06-03 03:38:44 +000070 /*
71 * Check that we haven't missed an unknown flag.
72 */
73 if(flags) {
74 errno = EINVAL;
75 return -1;
76 }
77
Lev Walkinc0e03b92017-08-22 01:48:23 -070078 /*
79 * Process each module in the list.
80 * PHASE I.
81 */
82 TQ_FOR(arg.mod, &(asn->modules), mod_next) {
83 arg.ns = asn1_namespace_new_from_module(arg.mod, 0);
84 ret = asn1f_fix_module__phase_1(&arg);
85 /*
86 * These lines are used for illustration purposes.
87 * RET2RVAL() is used everywhere else.
88 */
89 if(ret == -1) fatals++;
90 if(ret == 1) warnings++;
91 asn1_namespace_free(arg.ns);
92 arg.ns = 0;
93 }
94 /* PHASE II. */
95 TQ_FOR(arg.mod, &(asn->modules), mod_next) {
96 arg.ns = asn1_namespace_new_from_module(arg.mod, 0);
97 ret = asn1f_fix_module__phase_2(&arg);
98 if(ret == -1) fatals++;
99 if(ret == 1) warnings++;
100 asn1_namespace_free(arg.ns);
101 arg.ns = 0;
102 }
Lev Walkind24c62d2004-09-15 11:47:23 +0000103
Lev Walkinc0e03b92017-08-22 01:48:23 -0700104 memset(&a1f_replace_me_with_proper_interface_arg, 0, sizeof(arg_t));
Lev Walkinf15320b2004-06-03 03:38:44 +0000105
106 /*
107 * Compute a return value.
108 */
109 return fatals?-1:warnings?1:0;
110}
111
112/*
113 * Check the internals of a single module.
114 */
115static int
Lev Walkind24c62d2004-09-15 11:47:23 +0000116asn1f_fix_module__phase_1(arg_t *arg) {
Lev Walkinf15320b2004-06-03 03:38:44 +0000117 asn1p_expr_t *expr;
118 int rvalue = 0;
Lev Walkin1ef05162004-08-25 00:42:25 +0000119 int ret;
Lev Walkin4533a5f2005-03-18 04:22:41 +0000120 asn1p_module_t *omod;
121
122 /*
123 * Check that we don't have a similarly named module.
124 */
125 TQ_FOR(omod, &arg->asn->modules, mod_next) {
126 int sameNames;
127 if(omod == arg->mod) break;
Lev Walkinb36317c2005-08-12 10:09:10 +0000128 sameNames = strcmp(omod->ModuleName, arg->mod->ModuleName)?0:1;
Lev Walkin4533a5f2005-03-18 04:22:41 +0000129 if(omod->module_oid && arg->mod->module_oid) {
130 /* Compare only the OID. */
131 if(asn1p_oid_compare(omod->module_oid,
132 arg->mod->module_oid) == 0) {
Lev Walkin1a447952005-03-18 04:26:12 +0000133 FATAL("ASN.1 module %s in %s "
Lev Walkin4533a5f2005-03-18 04:22:41 +0000134 "has the same OBJECT IDENTIFIER"
Lev Walkin1a447952005-03-18 04:26:12 +0000135 " as module %s",
Lev Walkinb36317c2005-08-12 10:09:10 +0000136 omod->ModuleName,
Lev Walkin1a447952005-03-18 04:26:12 +0000137 omod->source_file_name,
Lev Walkinb36317c2005-08-12 10:09:10 +0000138 arg->mod->ModuleName
Lev Walkin4533a5f2005-03-18 04:22:41 +0000139 );
140 RET2RVAL(-1, rvalue);
141 } else if(sameNames) {
Lev Walkinb36317c2005-08-12 10:09:10 +0000142 WARNING("ASN.1 module %s is defined more than once, with different OIDs", omod->ModuleName);
Lev Walkin4533a5f2005-03-18 04:22:41 +0000143 RET2RVAL(1, rvalue);
144 }
145 } else if(sameNames) {
146 FATAL("ASN.1 module %s is defined more than once",
Lev Walkinb36317c2005-08-12 10:09:10 +0000147 omod->ModuleName);
Lev Walkin4533a5f2005-03-18 04:22:41 +0000148 RET2RVAL(-1, rvalue);
149 }
150 }
Lev Walkinf15320b2004-06-03 03:38:44 +0000151
Lev Walkinb45e0672004-08-18 05:42:05 +0000152 switch((arg->mod->module_flags & MSF_MASK_TAGS)) {
Lev Walkinf15320b2004-06-03 03:38:44 +0000153 case MSF_NOFLAGS:
154 case MSF_EXPLICIT_TAGS:
155 case MSF_IMPLICIT_TAGS:
156 case MSF_AUTOMATIC_TAGS:
157 break;
158 default:
159 FATAL("Module %s defined with ambiguous global tagging mode",
Lev Walkinb36317c2005-08-12 10:09:10 +0000160 arg->mod->ModuleName);
Lev Walkinf15320b2004-06-03 03:38:44 +0000161 RET2RVAL(-1, rvalue);
162 }
163
Lev Walkinb45e0672004-08-18 05:42:05 +0000164 switch((arg->mod->module_flags & MSF_MASK_INSTRUCTIONS)) {
165 case MSF_NOFLAGS:
Lev Walkin4ec3b4c2004-08-22 03:09:24 +0000166 /*
167 * arg->mod->module_flags |= MSF_TAG_INSTRUCTIONS;
168 */
Lev Walkinb45e0672004-08-18 05:42:05 +0000169 break;
170 case MSF_unk_INSTRUCTIONS:
171 WARNING("Module %s defined with unrecognized "
Lev Walkinb36317c2005-08-12 10:09:10 +0000172 "encoding reference", arg->mod->ModuleName);
Lev Walkinb45e0672004-08-18 05:42:05 +0000173 RET2RVAL(1, rvalue);
174 /* Fall through */
175 case MSF_TAG_INSTRUCTIONS:
176 case MSF_XER_INSTRUCTIONS:
177 break;
178 default:
179 FATAL("Module %s defined with ambiguous encoding reference",
Lev Walkinb36317c2005-08-12 10:09:10 +0000180 arg->mod->ModuleName);
Lev Walkinb45e0672004-08-18 05:42:05 +0000181 RET2RVAL(-1, rvalue);
182 }
183
Lev Walkinf15320b2004-06-03 03:38:44 +0000184 /*
185 * Do various non-recursive transformations.
Lev Walkinf15320b2004-06-03 03:38:44 +0000186 */
187 TQ_FOR(expr, &(arg->mod->members), next) {
Lev Walkinf15320b2004-06-03 03:38:44 +0000188 arg->expr = expr;
Lev Walkina00d6b32006-03-21 03:40:38 +0000189 ret = phase_1_1(arg, 0);
Lev Walkinf593f102005-02-22 07:59:59 +0000190 RET2RVAL(ret, rvalue);
Lev Walkinf15320b2004-06-03 03:38:44 +0000191 /*
192 * Make sure everybody's behaving well.
193 */
194 assert(arg->expr == expr);
195 }
Lev Walkina00d6b32006-03-21 03:40:38 +0000196 TQ_FOR(expr, &(arg->mod->members), next) {
197 arg->expr = expr;
198 ret = phase_1_1(arg, 1);
199 RET2RVAL(ret, rvalue);
200 assert(arg->expr == expr);
201 }
202
203
Lev Walkinf15320b2004-06-03 03:38:44 +0000204
205 /*
206 * 5. Automatic tagging
207 */
208 TQ_FOR(expr, &(arg->mod->members), next) {
Lev Walkinf15320b2004-06-03 03:38:44 +0000209
210 arg->expr = expr;
211
212 ret = asn1f_recurse_expr(arg, asn1f_fix_constr_autotag);
213 RET2RVAL(ret, rvalue);
214
215 assert(arg->expr == expr);
216 }
217
218 /*
219 * 8. fix BIT STRING
220 * 9. fix spaces in cstrings
221 */
222 TQ_FOR(expr, &(arg->mod->members), next) {
Lev Walkinf15320b2004-06-03 03:38:44 +0000223 arg->expr = expr;
224
225 ret = asn1f_recurse_expr(arg, asn1f_fix_bit_string);
226 RET2RVAL(ret, rvalue);
227
228 ret = asn1f_recurse_expr(arg, asn1f_fix_cstring);
229 RET2RVAL(ret, rvalue);
230
231 assert(arg->expr == expr);
232 }
233
234 /*
235 * ... Check for tags distinctness.
236 */
237 TQ_FOR(expr, &(arg->mod->members), next) {
Lev Walkinf15320b2004-06-03 03:38:44 +0000238 arg->expr = expr;
239
240 ret = asn1f_recurse_expr(arg, asn1f_check_constr_tags_distinct);
241 RET2RVAL(ret, rvalue);
242
243 assert(arg->expr == expr);
244 }
245
Lev Walkind24c62d2004-09-15 11:47:23 +0000246 return rvalue;
247}
248
249static int
250asn1f_fix_module__phase_2(arg_t *arg) {
251 asn1p_expr_t *expr;
252 int rvalue = 0;
253 int ret;
254
Lev Walkin1ef05162004-08-25 00:42:25 +0000255 TQ_FOR(expr, &(arg->mod->members), next) {
Bi-Ruei, Chiu80fd3062017-05-07 21:00:51 +0800256
Lev Walkin1ef05162004-08-25 00:42:25 +0000257 arg->expr = expr;
258
Lev Walkinb25fa062004-09-29 13:17:06 +0000259 /*
Lev Walkin3645c1c2004-10-31 00:11:50 +0000260 * Dereference DEFAULT values.
261 */
262 ret = asn1f_recurse_expr(arg, asn1f_fix_dereference_defaults);
263 RET2RVAL(ret, rvalue);
264
265 /*
Lev Walkinb25fa062004-09-29 13:17:06 +0000266 * Check semantic validity of constraints.
267 */
Lev Walkin1ef05162004-08-25 00:42:25 +0000268 ret = asn1f_recurse_expr(arg, asn1f_check_constraints);
269 RET2RVAL(ret, rvalue);
270
Lev Walkin1dec5802005-03-04 09:02:27 +0000271 /*
272 * Uniquely tag each inner type.
273 */
274 asn1f_apply_unique_index(0);
275 ret = asn1f_recurse_expr(arg, asn1f_apply_unique_index);
276 RET2RVAL(ret, rvalue);
277
Lev Walkin1ef05162004-08-25 00:42:25 +0000278 assert(arg->expr == expr);
279 }
280
Lev Walkinf15320b2004-06-03 03:38:44 +0000281 return rvalue;
282}
283
Lev Walkinf15320b2004-06-03 03:38:44 +0000284static int
Lev Walkina00d6b32006-03-21 03:40:38 +0000285phase_1_1(arg_t *arg, int prm2) {
286 asn1p_expr_t *expr = arg->expr;
287 int rvalue = 0;
288 int ret;
289
290 if(expr->lhs_params && expr->spec_index == -1) {
291 int i;
292 if(!prm2)
293 /* Do not process the parameterized type just yet */
294 return 0;
295 for(i = 0; i < expr->specializations.pspecs_count; i++) {
296 arg->expr = expr->specializations.pspec[i].my_clone;
297 ret = phase_1_1(arg, 0);
298 RET2RVAL(ret, rvalue);
299 }
300 arg->expr = expr; /* revert */
301 return rvalue;
302 } else if(prm2) {
303 return 0; /* Already done! */
304 }
305
306 /* Check whether this type is a duplicate */
307 if(!expr->lhs_params) {
308 ret = asn1f_check_duplicate(arg);
309 RET2RVAL(ret, rvalue);
310 }
311
312 DEBUG("=== Now processing \"%s\" (%d/0x%x) at line %d ===",
313 expr->Identifier, expr->meta_type, expr->expr_type,
314 expr->_lineno);
315 assert(expr->meta_type != AMT_INVALID);
316
317 /*
318 * 2.1 Pre-process simple types (ENUMERATED, INTEGER, etc).
319 */
320 ret = asn1f_recurse_expr(arg, asn1f_fix_simple);
321 RET2RVAL(ret, rvalue);
322
323 /*
324 * 2.5.4
325 */
326 ret = asn1f_recurse_expr(arg, asn1f_fix_dereference_types);
327 RET2RVAL(ret, rvalue);
328
329 /*
330 * Fix tagging of top-level types.
331 */
332 ret = asn1f_fix_constr_tag(arg, 1);
333 RET2RVAL(ret, rvalue);
334
335 /*
336 * 2.[234] Process SEQUENCE/SET/CHOICE types.
337 */
338 ret = asn1f_recurse_expr(arg, asn1f_fix_constructed);
339 RET2RVAL(ret, rvalue);
340
341 /*
342 * 2.5.5
343 */
344 ret = asn1f_recurse_expr(arg, asn1f_fix_dereference_values);
345 RET2RVAL(ret, rvalue);
346
347 /*
Lev Walkina00d6b32006-03-21 03:40:38 +0000348 * Resolve references in constraints.
349 */
350 ret = asn1f_recurse_expr(arg, asn1f_resolve_constraints);
351 RET2RVAL(ret, rvalue);
352
353 /*
Lev Walkinea6635b2017-08-06 23:23:04 -0700354 * Parse class information object sets.
355 */
356 ret = asn1f_parse_class_object(arg);
357 RET2RVAL(ret, rvalue);
358
359 /*
Lev Walkina00d6b32006-03-21 03:40:38 +0000360 * 6. INTEGER value processed at 2.5.4.
361 */
362
363 return rvalue;
364}
365
366static int
Lev Walkinf15320b2004-06-03 03:38:44 +0000367asn1f_fix_simple(arg_t *arg) {
368 int rvalue = 0;
369 int ret;
370
371 ret = asn1f_fix_enum(arg);
372 RET2RVAL(ret, rvalue);
373
374 ret = asn1f_fix_integer(arg);
375 RET2RVAL(ret, rvalue);
376
377 return rvalue;
378}
379
380static int
381asn1f_fix_constructed(arg_t *arg) {
382 int rvalue = 0;
383 int ret;
384
385 switch(arg->expr->expr_type) {
386 case ASN_CONSTR_SEQUENCE:
387 case ASN_CONSTR_SET:
388 case ASN_CONSTR_CHOICE:
389 break;
390 default:
391 return 0;
392 }
393
394 /* Check identifier distinctness */
Lev Walkinfbfc7bc2006-08-28 02:45:44 +0000395 ret = asn1f_check_unique_expr(arg);
Lev Walkinf15320b2004-06-03 03:38:44 +0000396 RET2RVAL(ret, rvalue);
397
398 /* Fix extensibility */
399 ret = asn1f_fix_constr_ext(arg);
400 RET2RVAL(ret, rvalue);
401
402 /* Fix tagging */
Lev Walkind541c252004-09-05 10:36:22 +0000403 ret = asn1f_fix_constr_tag(arg, 0);
Lev Walkinf15320b2004-06-03 03:38:44 +0000404 RET2RVAL(ret, rvalue);
405
Lev Walkin4ec3b4c2004-08-22 03:09:24 +0000406 /* Import COMPONENTS OF stuff */
407 ret = asn1f_pull_components_of(arg);
408 RET2RVAL(ret, rvalue);
409
Lev Walkinf15320b2004-06-03 03:38:44 +0000410 return rvalue;
411}
412
413static int
Lev Walkin1ef05162004-08-25 00:42:25 +0000414asn1f_resolve_constraints(arg_t *arg) {
Lev Walkinb45e0672004-08-18 05:42:05 +0000415 asn1p_expr_t *top_parent;
Lev Walkin5253da42004-08-20 13:25:56 +0000416 asn1p_expr_type_e etype;
Lev Walkinf15320b2004-06-03 03:38:44 +0000417 int rvalue = 0;
418 int ret;
419
Lev Walkin4ec3b4c2004-08-22 03:09:24 +0000420 top_parent = asn1f_find_terminal_type(arg, arg->expr);
Lev Walkin5253da42004-08-20 13:25:56 +0000421 if(top_parent)
422 etype = top_parent->expr_type;
423 else etype = A1TC_INVALID;
424
Lev Walkin03850182005-03-10 10:02:50 +0000425 DEBUG("(%s)", arg->expr->Identifier);
Lev Walkind541c252004-09-05 10:36:22 +0000426
Lev Walkinc0e03b92017-08-22 01:48:23 -0700427 ret = asn1constraint_resolve(arg, arg->expr->constraints, etype, 0);
428 RET2RVAL(ret, rvalue);
Lev Walkinf15320b2004-06-03 03:38:44 +0000429
Lev Walkin1ef05162004-08-25 00:42:25 +0000430 return rvalue;
431}
432
433static int
434asn1f_check_constraints(arg_t *arg) {
435 static enum asn1p_constraint_type_e test_types[] = {
436 ACT_EL_RANGE, ACT_CT_SIZE, ACT_CT_FROM };
437 asn1p_expr_t *top_parent;
438 asn1cnst_range_t *range;
439 asn1p_expr_type_e etype;
440 unsigned int i;
441 int rvalue = 0;
442 int ret;
443
Lev Walkin03850182005-03-10 10:02:50 +0000444 DEBUG("(%s{%d/%d})",
Lev Walkind541c252004-09-05 10:36:22 +0000445 arg->expr->Identifier,
446 arg->expr->meta_type, arg->expr->expr_type);
447
Lev Walkin1ef05162004-08-25 00:42:25 +0000448 top_parent = asn1f_find_terminal_type(arg, arg->expr);
449 if(!top_parent)
450 return 0;
451 etype = top_parent->expr_type;
452
Lev Walkinb45e0672004-08-18 05:42:05 +0000453 ret = asn1constraint_pullup(arg);
454 RET2RVAL(ret, rvalue);
455
Lev Walkin1ef05162004-08-25 00:42:25 +0000456 for(i = 0; i < sizeof(test_types)/sizeof(test_types[0]); i++) {
Lev Walkina28cbb92017-07-31 20:20:17 -0700457 range = asn1constraint_compute_constraint_range(
458 arg->expr->Identifier,
Lev Walkinb9fa7802004-08-25 02:04:39 +0000459 etype,
Lev Walkin1ef05162004-08-25 00:42:25 +0000460 arg->expr->combined_constraints,
Lev Walkin4b553412005-08-14 14:45:44 +0000461 test_types[i], 0, 0,
462 CPR_noflags /* ignore -fbless-SIZE */);
Lev Walkind541c252004-09-05 10:36:22 +0000463 if(!range && errno == EPERM) {
Lev Walkin9288d1c2005-03-10 11:27:13 +0000464 FATAL("This error happened for \"%s\" (meta %d) "
465 "at line %d",
Lev Walkind541c252004-09-05 10:36:22 +0000466 arg->expr->Identifier,
467 arg->expr->meta_type,
468 arg->expr->_lineno);
Lev Walkin1ef05162004-08-25 00:42:25 +0000469 return -1;
Lev Walkind541c252004-09-05 10:36:22 +0000470 }
Lev Walkin1ef05162004-08-25 00:42:25 +0000471 asn1constraint_range_free(range);
Lev Walkinb45e0672004-08-18 05:42:05 +0000472 }
Lev Walkin1ef05162004-08-25 00:42:25 +0000473
Lev Walkinf15320b2004-06-03 03:38:44 +0000474 return rvalue;
475}
476
Lev Walkinf593f102005-02-22 07:59:59 +0000477static int
478asn1f_check_duplicate(arg_t *arg) {
479 arg_t tmparg = *arg;
Lev Walkin9c2285a2006-03-09 08:49:26 +0000480 int rvalue = 0;
Lev Walkinf593f102005-02-22 07:59:59 +0000481
482 /*
483 * This is a linear scan in search of a similar type.
484 * The linear scan is just fine for the task, no need to over-optimize.
485 */
486 TQ_FOR(tmparg.mod, &arg->asn->modules, mod_next) {
Lev Walkin1a7cbd72006-03-07 10:39:42 +0000487 int critical = 1; /* FATAL */
488
489 if((arg->mod->_tags & MT_STANDARD_MODULE)
490 != (tmparg.mod->_tags & MT_STANDARD_MODULE)) {
491 /* Ignore clashes with standard module */
492 critical = 0; /* WARNING */
493 }
494
Lev Walkinf593f102005-02-22 07:59:59 +0000495 TQ_FOR(tmparg.expr, &(tmparg.mod->members), next) {
Lev Walkin1a7cbd72006-03-07 10:39:42 +0000496 int diff_files; /* different files */
497
Lev Walkinf593f102005-02-22 07:59:59 +0000498 assert(tmparg.expr->Identifier);
499 assert(arg->expr->Identifier);
Lev Walkin1a7cbd72006-03-07 10:39:42 +0000500
Lev Walkin0c0bca62006-03-21 04:48:15 +0000501 if(arg->expr->spec_index != -1)
502 continue;
503
Lev Walkinf593f102005-02-22 07:59:59 +0000504 if(tmparg.expr == arg->expr) break;
505
506 if(strcmp(tmparg.expr->Identifier,
Lev Walkin1a7cbd72006-03-07 10:39:42 +0000507 arg->expr->Identifier))
508 continue;
509
Bi-Ruei, Chiu80fd3062017-05-07 21:00:51 +0800510 /* resolve clash of Identifier in different modules */
511 int oid_exist = (tmparg.expr->module->module_oid && arg->expr->module->module_oid);
512 if ((!oid_exist && strcmp(tmparg.expr->module->ModuleName, arg->expr->module->ModuleName)) ||
513 (oid_exist && !asn1p_oid_compare(tmparg.expr->module->module_oid, arg->expr->module->module_oid))) {
514
515 tmparg.expr->_mark |= TM_NAMECLASH;
516 arg->expr->_mark |= TM_NAMECLASH;
517 continue;
518 }
519
Lev Walkin1a7cbd72006-03-07 10:39:42 +0000520 diff_files = strcmp(arg->mod->source_file_name,
521 tmparg.mod->source_file_name) ? 1 : 0;
522
523 LOG(critical,
524 "ASN.1 expression \"%s\" at line %d of module %s\n"
525 "clashes with expression \"%s\" at line %d of module %s"
526 "%s%s%s.\n"
Lev Walkin41635d32006-03-18 05:06:57 +0000527 "Rename or remove either instance "
528 "to resolve the conflict",
Lev Walkin1a7cbd72006-03-07 10:39:42 +0000529 arg->expr->Identifier,
530 arg->expr->_lineno,
531 arg->mod->ModuleName,
532 tmparg.expr->Identifier,
533 tmparg.expr->_lineno,
534 tmparg.mod->ModuleName,
535 diff_files ? " (" : "",
536 diff_files ? tmparg.mod->source_file_name : "",
537 diff_files ? ")" : "");
538 if(critical)
Lev Walkinf593f102005-02-22 07:59:59 +0000539 return -1;
Lev Walkin9c2285a2006-03-09 08:49:26 +0000540 RET2RVAL(1, rvalue);
Lev Walkinf593f102005-02-22 07:59:59 +0000541 }
542 if(tmparg.mod == arg->mod) break;
543 }
544
Lev Walkin9c2285a2006-03-09 08:49:26 +0000545 return rvalue;
Lev Walkinf593f102005-02-22 07:59:59 +0000546}
547
Lev Walkin1dec5802005-03-04 09:02:27 +0000548static int
549asn1f_apply_unique_index(arg_t *arg) {
550 static int unique_index;
551 if(!arg) { unique_index = 0; return 0; }
552
Lev Walkin1dec5802005-03-04 09:02:27 +0000553 arg->expr->_type_unique_index = ++unique_index;
554
555 return 0;
556}
557
Lev Walkinf15320b2004-06-03 03:38:44 +0000558/*
559 * Print everything to stderr
560 */
561static void
562_default_error_logger(int _severity, const char *fmt, ...) {
563 va_list ap;
564 char *pfx = "";
565
566 switch(_severity) {
567 case -1: pfx = "DEBUG: "; break;
568 case 0: pfx = "WARNING: "; break;
569 case 1: pfx = "FATAL: "; break;
570 }
571
572 fprintf(stderr, "%s", pfx);
573 va_start(ap, fmt);
574 vfprintf(stderr, fmt, ap);
575 va_end(ap);
576 fprintf(stderr, "\n");
577}