blob: 3ccae8181663fad04ed9ed22cae6c03faf8f56fd [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
Lev Walkin93659562010-11-20 09:47:13 -080026#ifdef _WIN32
Lev Walkin4efbfb72005-02-25 14:20:30 +000027#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 */
Lev Walkin9d542d22006-03-14 16:31:37 +000064#include "asn1fix_cws.h" /* CLASS WITH SYNTAX support */
Lev Walkina00d6b32006-03-21 03:40:38 +000065#include "asn1fix_param.h" /* Parameterization */
Lev Walkinf15320b2004-06-03 03:38:44 +000066#include "asn1fix_retrieve.h" /* Data retrieval */
67#include "asn1fix_enum.h" /* Process ENUMERATED */
68#include "asn1fix_integer.h" /* Process INTEGER */
69#include "asn1fix_bitstring.h" /* Process BIT STRING */
70#include "asn1fix_dereft.h" /* Dereference types */
71#include "asn1fix_derefv.h" /* Dereference values */
72#include "asn1fix_tags.h" /* Tags-related stuff */
Lev Walkinb45e0672004-08-18 05:42:05 +000073#include "asn1fix_constraint.h" /* Constraint manipulation */
74#include "asn1fix_crange.h" /* Constraint groking, exportable */
75#include "asn1fix_export.h" /* Exported functions */
Lev Walkinf15320b2004-06-03 03:38:44 +000076
77
78/*
79 * Merge the return value of the called function with the already
80 * partially computed return value of the current function.
81 */
82#define RET2RVAL(ret,rv) do { \
83 int __ret = ret; \
84 switch(__ret) { \
85 case 0: break; \
86 case 1: if(rv) break; \
87 case -1: rv = __ret; break; \
88 default: \
89 assert(__ret >= -1 && __ret <= 1); \
90 rv = -1; \
91 } \
92 } while(0)
93
94/*
95 * Temporary substitute module for the purposes of evaluating expression.
96 */
97#define WITH_MODULE(tmp_mod, expr) do { \
98 void *_saved_mod = arg->mod; \
99 arg->mod = tmp_mod; \
100 do { expr; } while(0); \
101 arg->mod = _saved_mod; \
102 } while(0)
103
104#define LOG(code, fmt, args...) do { \
105 int _save_errno = errno; \
106 if(code < 0) { \
107 if(arg->debug) \
Lev Walkin03850182005-03-10 10:02:50 +0000108 arg->debug(code, \
109 "%s: " fmt " in %s (%s:%d)", \
110 __func__, ##args, \
Lev Walkin4d89c262005-03-10 09:36:03 +0000111 arg->mod->source_file_name, \
112 __FILE__, __LINE__); \
Lev Walkin906654e2004-09-10 15:49:15 +0000113 } else if(arg->eh) { \
Lev Walkinf15320b2004-06-03 03:38:44 +0000114 arg->eh(code, fmt " in %s", ##args, \
115 arg->mod->source_file_name); \
116 } \
117 errno = _save_errno; \
118 } while(0)
119
120#define DEBUG(fmt, args...) LOG(-1, fmt, ##args)
121#define FATAL(fmt, args...) LOG( 1, fmt, ##args)
122#define WARNING(fmt, args...) LOG( 0, fmt, ##args)
123
124
125/*
126 * Define the symbol corresponding to the name of the current function.
127 */
128#if __STDC_VERSION__ < 199901
129#if !(__GNUC__ == 2 && __GNUC_MINOR__ >= 7 || __GNUC__ >= 3)
130#define __func__ (char *)0 /* Name of the current function */
131#endif /* GNUC */
132/* __func__ is supposed to be defined */
133#endif
134
135
136#endif /* _ASN1FIX_INTERNAL_H_ */