blob: e21235951b48a89daa13c6172d98ae586953f9c6 [file] [log] [blame]
Lev Walkinc6cac8e2016-03-14 02:57:07 -07001#ifndef ASN1FIX_INTERNAL_H
2#define ASN1FIX_INTERNAL_H
Lev Walkinf15320b2004-06-03 03:38:44 +00003
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
Frank Morgnercab30af2013-05-21 14:28:35 +020030#if defined HAVE_DECL_STRCASECMP && !HAVE_DECL_STRCASECMP
Lev Walkin4efbfb72005-02-25 14:20:30 +000031#define strcasecmp stricmp
32#endif
Frank Morgnercab30af2013-05-21 14:28:35 +020033#endif
Lev Walkin4efbfb72005-02-25 14:20:30 +000034
35#ifndef ETOOMANYREFS
36#define ETOOMANYREFS 144
37#endif
Lev Walkinf15320b2004-06-03 03:38:44 +000038
39/*
40 * A definition of a function that will log error messages.
41 */
42typedef void (*error_logger_f)(int _is_fatal, const char *fmt, ...);
43
44/*
45 * Universal argument.
46 */
47typedef struct arg_s {
48 asn1p_t *asn;
49 asn1p_module_t *mod;
50 asn1p_expr_t *expr;
51 error_logger_f eh;
52 error_logger_f debug;
53 void *key; /* The next level key */
Lev Walkinb45e0672004-08-18 05:42:05 +000054 enum asn1f_flags flags;
Lev Walkinf15320b2004-06-03 03:38:44 +000055} arg_t;
56
57/*
58 * Functions performing normalization of various types.
59 */
60#include "asn1fix_misc.h" /* Support functions */
61#include "asn1fix_value.h" /* Value processing */
62#include "asn1fix_cstring.h" /* Fix cstring values */
63#include "asn1fix_compat.h" /* Data compatibility */
64#include "asn1fix_constr.h" /* Constructed types */
65#include "asn1fix_class.h" /* CLASS support */
Lev Walkin9d542d22006-03-14 16:31:37 +000066#include "asn1fix_cws.h" /* CLASS WITH SYNTAX support */
Lev Walkina00d6b32006-03-21 03:40:38 +000067#include "asn1fix_param.h" /* Parameterization */
Lev Walkinf15320b2004-06-03 03:38:44 +000068#include "asn1fix_retrieve.h" /* Data retrieval */
69#include "asn1fix_enum.h" /* Process ENUMERATED */
70#include "asn1fix_integer.h" /* Process INTEGER */
71#include "asn1fix_bitstring.h" /* Process BIT STRING */
72#include "asn1fix_dereft.h" /* Dereference types */
73#include "asn1fix_derefv.h" /* Dereference values */
74#include "asn1fix_tags.h" /* Tags-related stuff */
Lev Walkinb45e0672004-08-18 05:42:05 +000075#include "asn1fix_constraint.h" /* Constraint manipulation */
76#include "asn1fix_crange.h" /* Constraint groking, exportable */
77#include "asn1fix_export.h" /* Exported functions */
Lev Walkinf15320b2004-06-03 03:38:44 +000078
79
80/*
81 * Merge the return value of the called function with the already
82 * partially computed return value of the current function.
83 */
84#define RET2RVAL(ret,rv) do { \
85 int __ret = ret; \
86 switch(__ret) { \
87 case 0: break; \
88 case 1: if(rv) break; \
89 case -1: rv = __ret; break; \
90 default: \
91 assert(__ret >= -1 && __ret <= 1); \
92 rv = -1; \
93 } \
94 } while(0)
95
96/*
97 * Temporary substitute module for the purposes of evaluating expression.
98 */
99#define WITH_MODULE(tmp_mod, expr) do { \
100 void *_saved_mod = arg->mod; \
101 arg->mod = tmp_mod; \
102 do { expr; } while(0); \
103 arg->mod = _saved_mod; \
104 } while(0)
105
106#define LOG(code, fmt, args...) do { \
107 int _save_errno = errno; \
108 if(code < 0) { \
109 if(arg->debug) \
Lev Walkin03850182005-03-10 10:02:50 +0000110 arg->debug(code, \
111 "%s: " fmt " in %s (%s:%d)", \
112 __func__, ##args, \
Lev Walkin4d89c262005-03-10 09:36:03 +0000113 arg->mod->source_file_name, \
114 __FILE__, __LINE__); \
Lev Walkin906654e2004-09-10 15:49:15 +0000115 } else if(arg->eh) { \
Lev Walkinf15320b2004-06-03 03:38:44 +0000116 arg->eh(code, fmt " in %s", ##args, \
117 arg->mod->source_file_name); \
118 } \
119 errno = _save_errno; \
120 } while(0)
121
122#define DEBUG(fmt, args...) LOG(-1, fmt, ##args)
123#define FATAL(fmt, args...) LOG( 1, fmt, ##args)
124#define WARNING(fmt, args...) LOG( 0, fmt, ##args)
125
126
127/*
128 * Define the symbol corresponding to the name of the current function.
129 */
130#if __STDC_VERSION__ < 199901
131#if !(__GNUC__ == 2 && __GNUC_MINOR__ >= 7 || __GNUC__ >= 3)
132#define __func__ (char *)0 /* Name of the current function */
133#endif /* GNUC */
134/* __func__ is supposed to be defined */
135#endif
136
137
Lev Walkinc6cac8e2016-03-14 02:57:07 -0700138#endif /* ASN1FIX_INTERNAL_H */