blob: 6a44cab5b6cd1cdb232ece104f7fbbe6be9f0379 [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
11#define ASN1C_ENVIRONMENT_VERSION 96 /* Compile-time version */
12int get_asn1c_environment_version(void); /* Run-time version */
13
14#include <asn_types.h>
15#include <constr_TYPE.h>
16
17#define CALLOC(nmemb, size) calloc(nmemb, size)
18#define MALLOC(size) malloc(size)
19#define REALLOC(oldptr, size) realloc(oldptr, size)
20#define FREEMEM(ptr) free(ptr)
21
22/*
23 * A macro for debugging the ASN.1 internals.
24 * You may enable or override it.
25 */
26#ifndef ASN_DEBUG /* If debugging code is not defined elsewhere... */
27#if EMIT_ASN_DEBUG == 1 /* And it was asked to emit this code... */
28#ifdef __GNUC__
29#define ASN_DEBUG(fmt, args...) do { \
30 fprintf(stderr, fmt, ##args); \
31 fprintf(stderr, "\n"); \
32 } while(0)
33#else /* !__GNUC__ */
34extern void ASN_DEBUG_f(const char *fmt, ...);
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__ */
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 */
49#define __ASN_E_cbc(buf, size) (cb((buf), (size), app_key) == -1)
50#define _ASN_E_CALLBACK(foo) do { \
51 if(foo) _ASN_ENCODE_FAILED; \
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 { \
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#endif /* _ASN_INTERNAL_H_ */