aboutsummaryrefslogtreecommitdiffstats
path: root/libasn1fix/asn1fix_internal.h
blob: c3739633991a77d8d002d75046d212e5678cce4b (plain)
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
#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 <string.h>
#include <ctype.h>		/* isupper() */
#include <errno.h>
#include <assert.h>

#include <asn1parser.h>		/* Our lovely ASN.1 parser module */
#include <asn1fix.h>

/*
 * 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;
	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_param.h"		/* Parametrization */
#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;				\
		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, expr)	do {			\
		void *_saved_mod = arg->mod;			\
		arg->mod = tmp_mod;				\
		do { expr; } while(0);				\
		arg->mod = _saved_mod;				\
	} while(0)

#define	LOG(code, fmt, args...) do {				\
		int _save_errno = errno;			\
		if(code < 0) {					\
			if(arg->debug)				\
				arg->debug(code, fmt, ##args);	\
		} 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_ */