blob: c2aa9e5140a65a4c1cb260d50c1db50e5ac3b937 [file] [log] [blame]
Lev Walkina9cc46e2004-09-22 16:06:28 +00001/*-
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 Walkindc06f6b2004-10-20 15:50:55 +000011#define ASN1C_ENVIRONMENT_VERSION 98 /* Compile-time version */
Lev Walkina9cc46e2004-09-22 16:06:28 +000012int get_asn1c_environment_version(void); /* Run-time version */
13
Lev Walkin8e559942004-09-24 20:57:56 +000014#include <asn_application.h> /* Application-visible API */
Lev Walkina9cc46e2004-09-22 16:06:28 +000015
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 Walkin8e559942004-09-24 20:57:56 +000030 fprintf(stderr, " (%s:%d)\n", \
31 __FILE__, __LINE__); \
Lev Walkina9cc46e2004-09-22 16:06:28 +000032 } while(0)
33#else /* !__GNUC__ */
Lev Walkin8e8078a2004-09-26 13:10:40 +000034void ASN_DEBUG_f(const char *fmt, ...);
Lev Walkina9cc46e2004-09-22 16:06:28 +000035#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__ */
41static 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 Walkin942fd082004-10-03 09:13:02 +000049#define __ASN_E_cbc(buf, size) (cb((buf), (size), app_key) < 0)
Lev Walkina9cc46e2004-09-22 16:06:28 +000050#define _ASN_E_CALLBACK(foo) do { \
Lev Walkin942fd082004-10-03 09:13:02 +000051 if(foo) goto cb_failed; \
Lev Walkina9cc46e2004-09-22 16:06:28 +000052 } 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 Walkin8e8078a2004-09-26 13:10:40 +000063 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 Walkina9cc46e2004-09-22 16:06:28 +000077} while(0)
78
79#endif /* _ASN_INTERNAL_H_ */