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