blob: 79a5cf270da98b301509b1932ee55bf96c4e7714 [file] [log] [blame]
Lev Walkinf15320b2004-06-03 03:38:44 +00001#ifndef _ASN1FIX_INTERNAL_H_
2#define _ASN1FIX_INTERNAL_H_
3
Lev Walkin97bdee22004-06-28 21:21:24 +00004#ifdef HAVE_CONFIG_H
5#include <config.h>
6#endif
7
Lev Walkinf15320b2004-06-03 03:38:44 +00008/*
9 * System headers required in various modules.
10 */
11#include <stdio.h>
12#include <stdlib.h>
Lev Walkin4efbfb72005-02-25 14:20:30 +000013#include <stdarg.h>
Lev Walkinf15320b2004-06-03 03:38:44 +000014#include <string.h>
15#include <ctype.h> /* isupper() */
16#include <errno.h>
17#include <assert.h>
18
Lev Walkin4efbfb72005-02-25 14:20:30 +000019#ifdef HAVE_UNISTD_H
20#include <unistd.h>
21#endif
22
Lev Walkinf15320b2004-06-03 03:38:44 +000023#include <asn1parser.h> /* Our lovely ASN.1 parser module */
Lev Walkin4efbfb72005-02-25 14:20:30 +000024#include "asn1fix.h"
25
26#ifdef WIN32
27#define EX_NOINPUT 66
28#define EX_DATAERR 65
29#define snprintf _snprintf
30#define strcasecmp stricmp
31#endif
32
33#ifndef ETOOMANYREFS
34#define ETOOMANYREFS 144
35#endif
Lev Walkinf15320b2004-06-03 03:38:44 +000036
37/*
38 * A definition of a function that will log error messages.
39 */
40typedef void (*error_logger_f)(int _is_fatal, const char *fmt, ...);
41
42/*
43 * Universal argument.
44 */
45typedef struct arg_s {
46 asn1p_t *asn;
47 asn1p_module_t *mod;
48 asn1p_expr_t *expr;
49 error_logger_f eh;
50 error_logger_f debug;
51 void *key; /* The next level key */
Lev Walkinb45e0672004-08-18 05:42:05 +000052 enum asn1f_flags flags;
Lev Walkinf15320b2004-06-03 03:38:44 +000053} arg_t;
54
55/*
56 * Functions performing normalization of various types.
57 */
58#include "asn1fix_misc.h" /* Support functions */
59#include "asn1fix_value.h" /* Value processing */
60#include "asn1fix_cstring.h" /* Fix cstring values */
61#include "asn1fix_compat.h" /* Data compatibility */
62#include "asn1fix_constr.h" /* Constructed types */
63#include "asn1fix_class.h" /* CLASS support */
64#include "asn1fix_param.h" /* Parametrization */
65#include "asn1fix_retrieve.h" /* Data retrieval */
66#include "asn1fix_enum.h" /* Process ENUMERATED */
67#include "asn1fix_integer.h" /* Process INTEGER */
68#include "asn1fix_bitstring.h" /* Process BIT STRING */
69#include "asn1fix_dereft.h" /* Dereference types */
70#include "asn1fix_derefv.h" /* Dereference values */
71#include "asn1fix_tags.h" /* Tags-related stuff */
Lev Walkinb45e0672004-08-18 05:42:05 +000072#include "asn1fix_constraint.h" /* Constraint manipulation */
73#include "asn1fix_crange.h" /* Constraint groking, exportable */
74#include "asn1fix_export.h" /* Exported functions */
Lev Walkinf15320b2004-06-03 03:38:44 +000075
76
77/*
78 * Merge the return value of the called function with the already
79 * partially computed return value of the current function.
80 */
81#define RET2RVAL(ret,rv) do { \
82 int __ret = ret; \
83 switch(__ret) { \
84 case 0: break; \
85 case 1: if(rv) break; \
86 case -1: rv = __ret; break; \
87 default: \
88 assert(__ret >= -1 && __ret <= 1); \
89 rv = -1; \
90 } \
91 } while(0)
92
93/*
94 * Temporary substitute module for the purposes of evaluating expression.
95 */
96#define WITH_MODULE(tmp_mod, expr) do { \
97 void *_saved_mod = arg->mod; \
98 arg->mod = tmp_mod; \
99 do { expr; } while(0); \
100 arg->mod = _saved_mod; \
101 } while(0)
102
103#define LOG(code, fmt, args...) do { \
104 int _save_errno = errno; \
105 if(code < 0) { \
106 if(arg->debug) \
Lev Walkin4d89c262005-03-10 09:36:03 +0000107 arg->debug(code, fmt " in %s (%s@%d)", \
108 ##args, \
109 arg->mod->source_file_name, \
110 __FILE__, __LINE__); \
Lev Walkin906654e2004-09-10 15:49:15 +0000111 } else if(arg->eh) { \
Lev Walkinf15320b2004-06-03 03:38:44 +0000112 arg->eh(code, fmt " in %s", ##args, \
113 arg->mod->source_file_name); \
114 } \
115 errno = _save_errno; \
116 } while(0)
117
118#define DEBUG(fmt, args...) LOG(-1, fmt, ##args)
119#define FATAL(fmt, args...) LOG( 1, fmt, ##args)
120#define WARNING(fmt, args...) LOG( 0, fmt, ##args)
121
122
123/*
124 * Define the symbol corresponding to the name of the current function.
125 */
126#if __STDC_VERSION__ < 199901
127#if !(__GNUC__ == 2 && __GNUC_MINOR__ >= 7 || __GNUC__ >= 3)
128#define __func__ (char *)0 /* Name of the current function */
129#endif /* GNUC */
130/* __func__ is supposed to be defined */
131#endif
132
133
134#endif /* _ASN1FIX_INTERNAL_H_ */