blob: 781f10bc33824bfe5379b13d9fbff155c899257b [file] [log] [blame]
vlm39ba4c42004-09-22 16:06:28 +00001/*-
vlmd98cbfb2005-08-03 07:01:32 +00002 * Copyright (c) 2003, 2004, 2005 Lev Walkin <vlm@lionet.info>.
3 * All rights reserved.
vlm39ba4c42004-09-22 16:06:28 +00004 * Redistribution and modifications are permitted subject to BSD license.
5 */
6/*
7 * Declarations internally useful for the ASN.1 support code.
8 */
9#ifndef _ASN_INTERNAL_H_
10#define _ASN_INTERNAL_H_
11
vlm22dcbd12004-09-24 20:57:56 +000012#include <asn_application.h> /* Application-visible API */
vlm39ba4c42004-09-22 16:06:28 +000013
vlmad96ab22005-04-19 09:19:17 +000014#ifndef __NO_ASSERT_H__ /* Include assert.h only for internal use. */
15#include <assert.h> /* for assert() macro */
16#endif
17
vlmc1e72a92005-07-28 08:39:46 +000018#ifdef __cplusplus
19extern "C" {
20#endif
21
22#define ASN1C_ENVIRONMENT_VERSION 98 /* Compile-time version */
23int get_asn1c_environment_version(void); /* Run-time version */
24
vlm39ba4c42004-09-22 16:06:28 +000025#define CALLOC(nmemb, size) calloc(nmemb, size)
26#define MALLOC(size) malloc(size)
27#define REALLOC(oldptr, size) realloc(oldptr, size)
28#define FREEMEM(ptr) free(ptr)
29
30/*
31 * A macro for debugging the ASN.1 internals.
32 * You may enable or override it.
33 */
34#ifndef ASN_DEBUG /* If debugging code is not defined elsewhere... */
35#if EMIT_ASN_DEBUG == 1 /* And it was asked to emit this code... */
36#ifdef __GNUC__
37#define ASN_DEBUG(fmt, args...) do { \
38 fprintf(stderr, fmt, ##args); \
vlm22dcbd12004-09-24 20:57:56 +000039 fprintf(stderr, " (%s:%d)\n", \
40 __FILE__, __LINE__); \
vlm39ba4c42004-09-22 16:06:28 +000041 } while(0)
42#else /* !__GNUC__ */
vlm6678cb12004-09-26 13:10:40 +000043void ASN_DEBUG_f(const char *fmt, ...);
vlm39ba4c42004-09-22 16:06:28 +000044#define ASN_DEBUG ASN_DEBUG_f
45#endif /* __GNUC__ */
46#else /* EMIT_ASN_DEBUG != 1 */
vlme66fd8a2005-07-21 09:32:49 +000047static inline void ASN_DEBUG(const char *fmt, ...) { (void)fmt; }
vlm39ba4c42004-09-22 16:06:28 +000048#endif /* EMIT_ASN_DEBUG */
49#endif /* ASN_DEBUG */
50
51/*
52 * Invoke the application-supplied callback and fail, if something is wrong.
53 */
vlm84d551b2004-10-03 09:13:02 +000054#define __ASN_E_cbc(buf, size) (cb((buf), (size), app_key) < 0)
vlm39ba4c42004-09-22 16:06:28 +000055#define _ASN_E_CALLBACK(foo) do { \
vlm84d551b2004-10-03 09:13:02 +000056 if(foo) goto cb_failed; \
vlm39ba4c42004-09-22 16:06:28 +000057 } while(0)
58#define _ASN_CALLBACK(buf, size) \
59 _ASN_E_CALLBACK(__ASN_E_cbc(buf, size))
60#define _ASN_CALLBACK2(buf1, size1, buf2, size2) \
61 _ASN_E_CALLBACK(__ASN_E_cbc(buf1, size1) || __ASN_E_cbc(buf2, size2))
62#define _ASN_CALLBACK3(buf1, size1, buf2, size2, buf3, size3) \
63 _ASN_E_CALLBACK(__ASN_E_cbc(buf1, size1) \
64 || __ASN_E_cbc(buf2, size2) \
65 || __ASN_E_cbc(buf3, size3))
66
67#define _i_ASN_TEXT_INDENT(nl, level) do { \
vlm6678cb12004-09-26 13:10:40 +000068 int __level = (level); \
69 int __nl = ((nl) != 0); \
70 int __i; \
71 if(__nl) _ASN_CALLBACK("\n", 1); \
72 for(__i = 0; __i < __level; __i++) \
73 _ASN_CALLBACK(" ", 4); \
74 er.encoded += __nl + 4 * __level; \
75} while(0)
76
77#define _i_INDENT(nl) do { \
78 int __i; \
79 if((nl) && cb("\n", 1, app_key) < 0) return -1; \
80 for(__i = 0; __i < ilevel; __i++) \
81 if(cb(" ", 4, app_key) < 0) return -1; \
vlm39ba4c42004-09-22 16:06:28 +000082} while(0)
83
vlmc1e72a92005-07-28 08:39:46 +000084#ifdef __cplusplus
85}
86#endif
87
vlm39ba4c42004-09-22 16:06:28 +000088#endif /* _ASN_INTERNAL_H_ */