Lev Walkin | a9cc46e | 2004-09-22 16:06:28 +0000 | [diff] [blame] | 1 | /*- |
| 2 | * Copyright (c) 2003, 2004 Lev Walkin <vlm@lionet.info>. All rights reserved. |
| 3 | * Redistribution and modifications are permitted subject to BSD license. |
| 4 | */ |
| 5 | /* |
| 6 | * Declarations internally useful for the ASN.1 support code. |
| 7 | */ |
| 8 | #ifndef _ASN_INTERNAL_H_ |
| 9 | #define _ASN_INTERNAL_H_ |
| 10 | |
Lev Walkin | dc06f6b | 2004-10-20 15:50:55 +0000 | [diff] [blame] | 11 | #define ASN1C_ENVIRONMENT_VERSION 98 /* Compile-time version */ |
Lev Walkin | a9cc46e | 2004-09-22 16:06:28 +0000 | [diff] [blame] | 12 | int get_asn1c_environment_version(void); /* Run-time version */ |
| 13 | |
Lev Walkin | 8e55994 | 2004-09-24 20:57:56 +0000 | [diff] [blame] | 14 | #include <asn_application.h> /* Application-visible API */ |
Lev Walkin | a9cc46e | 2004-09-22 16:06:28 +0000 | [diff] [blame] | 15 | |
| 16 | #define CALLOC(nmemb, size) calloc(nmemb, size) |
| 17 | #define MALLOC(size) malloc(size) |
| 18 | #define REALLOC(oldptr, size) realloc(oldptr, size) |
| 19 | #define FREEMEM(ptr) free(ptr) |
| 20 | |
| 21 | /* |
| 22 | * A macro for debugging the ASN.1 internals. |
| 23 | * You may enable or override it. |
| 24 | */ |
| 25 | #ifndef ASN_DEBUG /* If debugging code is not defined elsewhere... */ |
| 26 | #if EMIT_ASN_DEBUG == 1 /* And it was asked to emit this code... */ |
| 27 | #ifdef __GNUC__ |
| 28 | #define ASN_DEBUG(fmt, args...) do { \ |
| 29 | fprintf(stderr, fmt, ##args); \ |
Lev Walkin | 8e55994 | 2004-09-24 20:57:56 +0000 | [diff] [blame] | 30 | fprintf(stderr, " (%s:%d)\n", \ |
| 31 | __FILE__, __LINE__); \ |
Lev Walkin | a9cc46e | 2004-09-22 16:06:28 +0000 | [diff] [blame] | 32 | } while(0) |
| 33 | #else /* !__GNUC__ */ |
Lev Walkin | 8e8078a | 2004-09-26 13:10:40 +0000 | [diff] [blame] | 34 | void ASN_DEBUG_f(const char *fmt, ...); |
Lev Walkin | a9cc46e | 2004-09-22 16:06:28 +0000 | [diff] [blame] | 35 | #define ASN_DEBUG ASN_DEBUG_f |
| 36 | #endif /* __GNUC__ */ |
| 37 | #else /* EMIT_ASN_DEBUG != 1 */ |
| 38 | #ifdef __GNUC__ |
| 39 | #define ASN_DEBUG(fmt, args...) ((void)0) /* Emit a no-op operator */ |
| 40 | #else /* __GNUC__ */ |
| 41 | static void ASN_DEBUG(const char *fmt, ...) { (void)fmt; }; |
| 42 | #endif /* __GNUC__ */ |
| 43 | #endif /* EMIT_ASN_DEBUG */ |
| 44 | #endif /* ASN_DEBUG */ |
| 45 | |
| 46 | /* |
| 47 | * Invoke the application-supplied callback and fail, if something is wrong. |
| 48 | */ |
Lev Walkin | 942fd08 | 2004-10-03 09:13:02 +0000 | [diff] [blame] | 49 | #define __ASN_E_cbc(buf, size) (cb((buf), (size), app_key) < 0) |
Lev Walkin | a9cc46e | 2004-09-22 16:06:28 +0000 | [diff] [blame] | 50 | #define _ASN_E_CALLBACK(foo) do { \ |
Lev Walkin | 942fd08 | 2004-10-03 09:13:02 +0000 | [diff] [blame] | 51 | if(foo) goto cb_failed; \ |
Lev Walkin | a9cc46e | 2004-09-22 16:06:28 +0000 | [diff] [blame] | 52 | } while(0) |
| 53 | #define _ASN_CALLBACK(buf, size) \ |
| 54 | _ASN_E_CALLBACK(__ASN_E_cbc(buf, size)) |
| 55 | #define _ASN_CALLBACK2(buf1, size1, buf2, size2) \ |
| 56 | _ASN_E_CALLBACK(__ASN_E_cbc(buf1, size1) || __ASN_E_cbc(buf2, size2)) |
| 57 | #define _ASN_CALLBACK3(buf1, size1, buf2, size2, buf3, size3) \ |
| 58 | _ASN_E_CALLBACK(__ASN_E_cbc(buf1, size1) \ |
| 59 | || __ASN_E_cbc(buf2, size2) \ |
| 60 | || __ASN_E_cbc(buf3, size3)) |
| 61 | |
| 62 | #define _i_ASN_TEXT_INDENT(nl, level) do { \ |
Lev Walkin | 8e8078a | 2004-09-26 13:10:40 +0000 | [diff] [blame] | 63 | int __level = (level); \ |
| 64 | int __nl = ((nl) != 0); \ |
| 65 | int __i; \ |
| 66 | if(__nl) _ASN_CALLBACK("\n", 1); \ |
| 67 | for(__i = 0; __i < __level; __i++) \ |
| 68 | _ASN_CALLBACK(" ", 4); \ |
| 69 | er.encoded += __nl + 4 * __level; \ |
| 70 | } while(0) |
| 71 | |
| 72 | #define _i_INDENT(nl) do { \ |
| 73 | int __i; \ |
| 74 | if((nl) && cb("\n", 1, app_key) < 0) return -1; \ |
| 75 | for(__i = 0; __i < ilevel; __i++) \ |
| 76 | if(cb(" ", 4, app_key) < 0) return -1; \ |
Lev Walkin | a9cc46e | 2004-09-22 16:06:28 +0000 | [diff] [blame] | 77 | } while(0) |
| 78 | |
| 79 | #endif /* _ASN_INTERNAL_H_ */ |