-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathasn1fix_internal.h
158 lines (140 loc) · 5.7 KB
/
asn1fix_internal.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
#ifndef ASN1FIX_INTERNAL_H
#define ASN1FIX_INTERNAL_H
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
/*
* System headers required in various modules.
*/
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
#include <ctype.h> /* isupper() */
#include <errno.h>
#include <assert.h>
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
#include <asn1parser.h> /* Our lovely ASN.1 parser module */
#include <asn1_namespace.h>
#include <genhash.h>
#include "asn1fix.h"
#ifdef _WIN32
#define EX_NOINPUT 66
#define EX_DATAERR 65
#define snprintf _snprintf
#if defined HAVE_DECL_STRCASECMP && !HAVE_DECL_STRCASECMP
#define strcasecmp stricmp
#endif
#endif
#ifndef ETOOMANYREFS
#define ETOOMANYREFS 144
#endif
/*
* A definition of a function that will log error messages.
*/
typedef void (*error_logger_f)(int _is_fatal, const char *fmt, ...);
/*
* Universal argument.
*/
typedef struct arg_s {
asn1p_t *asn;
asn1_namespace_t *ns;
asn1p_module_t *mod;
asn1p_expr_t *expr;
error_logger_f eh;
error_logger_f debug;
void *key; /* The next level key */
enum asn1f_flags flags;
} arg_t;
/*
* Functions performing normalization of various types.
*/
#include "asn1fix_misc.h" /* Support functions */
#include "asn1fix_value.h" /* Value processing */
#include "asn1fix_cstring.h" /* Fix cstring values */
#include "asn1fix_compat.h" /* Data compatibility */
#include "asn1fix_constr.h" /* Constructed types */
#include "asn1fix_class.h" /* CLASS support */
#include "asn1fix_cws.h" /* CLASS WITH SYNTAX support */
#include "asn1fix_param.h" /* Parameterization */
#include "asn1fix_retrieve.h" /* Data retrieval */
#include "asn1fix_enum.h" /* Process ENUMERATED */
#include "asn1fix_integer.h" /* Process INTEGER */
#include "asn1fix_bitstring.h" /* Process BIT STRING */
#include "asn1fix_dereft.h" /* Dereference types */
#include "asn1fix_derefv.h" /* Dereference values */
#include "asn1fix_tags.h" /* Tags-related stuff */
#include "asn1fix_constraint.h" /* Constraint manipulation */
#include "asn1fix_crange.h" /* Constraint groking, exportable */
#include "asn1fix_export.h" /* Exported functions */
/*
* Merge the return value of the called function with the already
* partially computed return value of the current function.
*/
#define RET2RVAL(ret, rv) \
do { \
int __ret = ret; \
switch(__ret) { \
case 0: \
break; \
case 1: \
if(rv) break; \
/* Fall through */ \
case -1: \
rv = __ret; \
break; \
default: \
assert(__ret >= -1 && __ret <= 1); \
rv = -1; \
} \
} while(0)
/*
* Temporary substitute module for the purposes of evaluating expression.
*/
#define WITH_MODULE(tmp_mod, code) \
({ \
void *_saved_mod = arg->mod; \
asn1_namespace_t *_saved_ns = arg->ns; \
arg->mod = tmp_mod; \
arg->ns = asn1_namespace_new_from_module(tmp_mod, 1); \
typeof(code) ret = code; \
asn1_namespace_free(arg->ns); \
arg->ns = _saved_ns; \
arg->mod = _saved_mod; \
ret; \
})
#define LOG(code, fmt, args...) \
do { \
int _save_errno = errno; \
if(code < 0) { \
if(arg->debug) { \
arg->debug(code, "%s: " fmt " in %s (%s:%d)", __func__, \
##args, arg->mod->source_file_name, __FILE__, \
__LINE__); \
} \
} else if(arg->eh) { \
if(arg->debug) { \
arg->eh(code, fmt " in %s (%s:%d)", ##args, \
arg->mod->source_file_name, __FILE__, __LINE__); \
} else { \
arg->eh(code, fmt " in %s", ##args, \
arg->mod->source_file_name); \
} \
errno = _save_errno; \
} \
} while(0)
#define DEBUG(fmt, args...) LOG(-1, fmt, ##args)
#define FATAL(fmt, args...) LOG( 1, fmt, ##args)
#define WARNING(fmt, args...) LOG( 0, fmt, ##args)
/*
* Define the symbol corresponding to the name of the current function.
*/
#if __STDC_VERSION__ < 199901
#if !(__GNUC__ == 2 && __GNUC_MINOR__ >= 7 || __GNUC__ >= 3)
#define __func__ (char *)0 /* Name of the current function */
#endif /* GNUC */
/* __func__ is supposed to be defined */
#endif
#endif /* ASN1FIX_INTERNAL_H */