| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
#ifndef _ASN_INTERNAL_H_ |
| 10 |
#define _ASN_INTERNAL_H_ |
| 11 |
|
| 12 |
#include "asn_application.h" |
| 13 |
|
| 14 |
#ifndef __NO_ASSERT_H__ |
| 15 |
#include <assert.h> |
| 16 |
#endif |
| 17 |
|
| 18 |
#ifdef __cplusplus |
| 19 |
extern "C" { |
| 20 |
#endif |
| 21 |
|
| 22 |
|
| 23 |
#define ASN1C_ENVIRONMENT_VERSION 922 |
| 24 |
int get_asn1c_environment_version(void); |
| 25 |
|
| 26 |
#define CALLOC(nmemb, size) calloc(nmemb, size) |
| 27 |
#define MALLOC(size) malloc(size) |
| 28 |
#define REALLOC(oldptr, size) realloc(oldptr, size) |
| 29 |
#define FREEMEM(ptr) free(ptr) |
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
#ifndef ASN_DEBUG |
| 36 |
#if EMIT_ASN_DEBUG == 1 |
| 37 |
#ifdef __GNUC__ |
| 38 |
#ifdef ASN_THREAD_SAFE |
| 39 |
#define asn_debug_indent 0 |
| 40 |
#else |
| 41 |
int asn_debug_indent; |
| 42 |
#endif |
| 43 |
#define ASN_DEBUG(fmt, args...) do { \ |
| 44 |
int adi = asn_debug_indent; \ |
| 45 |
while(adi--) fprintf(stderr, " "); \ |
| 46 |
fprintf(stderr, fmt, ##args); \ |
| 47 |
fprintf(stderr, " (%s:%d)\n", \ |
| 48 |
__FILE__, __LINE__); \ |
| 49 |
} while(0) |
| 50 |
#else |
| 51 |
void ASN_DEBUG_f(const char *fmt, ...); |
| 52 |
#define ASN_DEBUG ASN_DEBUG_f |
| 53 |
#endif |
| 54 |
#else |
| 55 |
static inline void ASN_DEBUG(const char *fmt, ...) { (void)fmt; } |
| 56 |
#endif |
| 57 |
#endif |
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
#define __ASN_E_cbc(buf, size) (cb((buf), (size), app_key) < 0) |
| 63 |
#define _ASN_E_CALLBACK(foo) do { \ |
| 64 |
if(foo) goto cb_failed; \ |
| 65 |
} while(0) |
| 66 |
#define _ASN_CALLBACK(buf, size) \ |
| 67 |
_ASN_E_CALLBACK(__ASN_E_cbc(buf, size)) |
| 68 |
#define _ASN_CALLBACK2(buf1, size1, buf2, size2) \ |
| 69 |
_ASN_E_CALLBACK(__ASN_E_cbc(buf1, size1) || __ASN_E_cbc(buf2, size2)) |
| 70 |
#define _ASN_CALLBACK3(buf1, size1, buf2, size2, buf3, size3) \ |
| 71 |
_ASN_E_CALLBACK(__ASN_E_cbc(buf1, size1) \ |
| 72 |
|| __ASN_E_cbc(buf2, size2) \ |
| 73 |
|| __ASN_E_cbc(buf3, size3)) |
| 74 |
|
| 75 |
#define _i_ASN_TEXT_INDENT(nl, level) do { \ |
| 76 |
int __level = (level); \ |
| 77 |
int __nl = ((nl) != 0); \ |
| 78 |
int __i; \ |
| 79 |
if(__nl) _ASN_CALLBACK("\n", 1); \ |
| 80 |
if(__level < 0) __level = 0; \ |
| 81 |
for(__i = 0; __i < __level; __i++) \ |
| 82 |
_ASN_CALLBACK(" ", 4); \ |
| 83 |
er.encoded += __nl + 4 * __level; \ |
| 84 |
} while(0) |
| 85 |
|
| 86 |
#define _i_INDENT(nl) do { \ |
| 87 |
int __i; \ |
| 88 |
if((nl) && cb("\n", 1, app_key) < 0) return -1; \ |
| 89 |
for(__i = 0; __i < ilevel; __i++) \ |
| 90 |
if(cb(" ", 4, app_key) < 0) return -1; \ |
| 91 |
} while(0) |
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
#define _ASN_DEFAULT_STACK_MAX (30000) |
| 97 |
static inline int |
| 98 |
_ASN_STACK_OVERFLOW_CHECK(asn_codec_ctx_t *ctx) { |
| 99 |
if(ctx && ctx->max_stack_size) { |
| 100 |
|
| 101 |
|
| 102 |
ptrdiff_t usedstack = ((char *)ctx - (char *)&ctx); |
| 103 |
if(usedstack > 0) usedstack = -usedstack; |
| 104 |
|
| 105 |
|
| 106 |
if(usedstack < -(ptrdiff_t)ctx->max_stack_size) { |
| 107 |
ASN_DEBUG("Stack limit %ld reached", |
| 108 |
(long)ctx->max_stack_size); |
| 109 |
return -1; |
| 110 |
} |
| 111 |
} |
| 112 |
return 0; |
| 113 |
} |
| 114 |
|
| 115 |
#ifdef __cplusplus |
| 116 |
} |
| 117 |
#endif |
| 118 |
|
| 119 |
#endif |