VirtualBox

source: vbox/trunk/include/iprt/asn1-generator-pass.h@ 95594

最後變更 在這個檔案從95594是 95594,由 vboxsync 提交於 3 年 前

IPRT/asn1-genrator-pass.h: RTASN1TMPL_BEGIN_PCHOICE must initialize the allocator when emitting the _Init code. bugref:8691

  • 屬性 svn:eol-style 設為 native
  • 屬性 svn:keywords 設為 Author Date Id Revision
檔案大小: 79.2 KB
 
1/** @file
2 * IPRT - ASN.1 Code Generator, One Pass.
3 */
4
5/*
6 * Copyright (C) 2006-2022 Oracle Corporation
7 *
8 * This file is part of VirtualBox Open Source Edition (OSE), as
9 * available from http://www.alldomusa.eu.org. This file is free software;
10 * you can redistribute it and/or modify it under the terms of the GNU
11 * General Public License (GPL) as published by the Free Software
12 * Foundation, in version 2 as it comes in the "COPYING" file of the
13 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
14 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
15 *
16 * The contents of this file may alternatively be used under the terms
17 * of the Common Development and Distribution License Version 1.0
18 * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
19 * VirtualBox OSE distribution, in which case the provisions of the
20 * CDDL are applicable instead of those of the GPL.
21 *
22 * You may elect to license modified versions of this file under the
23 * terms and conditions of either the GPL or the CDDL or both.
24 */
25
26#ifndef ___iprt_asn1_generator_pass_h /* (special, only part of the file) */
27#define ___iprt_asn1_generator_pass_h
28
29#include <iprt/formats/asn1.h>
30#include <iprt/err.h>
31
32
33/** @def RTASN1TMPL_MEMBER_OPT_ANY
34 * Used for optional entries without any specific type at the end of a
35 * structure.
36 *
37 * For example PolicyQualifierInfo's qualifier member which is defined as:
38 * ANY DEFINED BY policyQualifierId
39 *
40 * Defaults to RTASN1TMPL_MEMBER_EX.
41 */
42
43/** @def RTASN1TMPL_MEMBER_OPT_ITAG_EX
44 * Optional member with implict tag, extended version.
45 *
46 * This is what all the other RTASN1TMPL_MEMBER_OPT_ITAG* macros defere to.
47 */
48/** @def RTASN1TMPL_MEMBER_OPT_ITAG_CP
49 * Optional member of a typical primitive type with an implicit context tag.
50 *
51 * Examples of this can be found in AuthorityKeyIdentifier where the first and
52 * last member are primitive types (normally anyways).:
53 * keyIdentifier [1] OCTET STRING OPTIONAL,
54 * authorityCertSerialNumber [3] INTEGER OPTIONAL
55 */
56/** @def RTASN1TMPL_MEMBER_OPT_ITAG_UC
57 * Optional member of a constructed type from the universal tag class.
58 */
59/** @def RTASN1TMPL_MEMBER_OPT_ITAG_UP
60 * Optional member of a primitive type from the universal tag class.
61 */
62
63
64/** @name Expansion Passes (RTASN1TMPL_PASS values)
65 * @{ */
66#define RTASN1TMPL_PASS_INTERNAL_HEADER 1
67
68#define RTASN1TMPL_PASS_XTAG 2
69#define RTASN1TMPL_PASS_VTABLE 3
70#define RTASN1TMPL_PASS_ENUM 4
71#define RTASN1TMPL_PASS_DELETE 5
72#define RTASN1TMPL_PASS_COMPARE 6
73
74#define RTASN1TMPL_PASS_CHECK_SANITY 8
75
76#define RTASN1TMPL_PASS_INIT 16
77#define RTASN1TMPL_PASS_CLONE 17
78#define RTASN1TMPL_PASS_SETTERS_1 18
79#define RTASN1TMPL_PASS_SETTERS_2 19
80#define RTASN1TMPL_PASS_ARRAY 20
81
82#define RTASN1TMPL_PASS_DECODE 24
83/** @} */
84
85/** @name ITAG clues
86 * @{ */
87#define RTASN1TMPL_ITAG_F_CC 1 /**< context, constructed. */
88#define RTASN1TMPL_ITAG_F_CP 2 /**< context, probably primary. (w/ numeric value) */
89#define RTASN1TMPL_ITAG_F_UP 3 /**< universal, probably primary. (w/ ASN1_TAG_XXX value) */
90#define RTASN1TMPL_ITAG_F_UC 4 /**< universal, constructed. (w/ ASN1_TAG_XXX value) */
91/** @} */
92/** Expands the ITAG clues into tag flag and tag class. */
93#define RTASN1TMPL_ITAG_F_EXPAND(a_fClue) \
94 ( a_fClue == RTASN1TMPL_ITAG_F_CC ? (ASN1_TAGCLASS_CONTEXT | ASN1_TAGFLAG_CONSTRUCTED ) \
95 : a_fClue == RTASN1TMPL_ITAG_F_CP ? (ASN1_TAGCLASS_CONTEXT | ASN1_TAGFLAG_PRIMITIVE) \
96 : a_fClue == RTASN1TMPL_ITAG_F_UP ? (ASN1_TAGCLASS_UNIVERSAL | ASN1_TAGFLAG_PRIMITIVE) \
97 : a_fClue == RTASN1TMPL_ITAG_F_UC ? (ASN1_TAGCLASS_UNIVERSAL | ASN1_TAGFLAG_CONSTRUCTED) \
98 : 0 )
99
100#define RTASN1TMPL_SEMICOLON_DUMMY() typedef unsigned RTASN1TMPLSEMICOLONDUMMY
101
102#endif /* !___iprt_asn1_generator_pass_h */
103
104
105#if RTASN1TMPL_PASS == RTASN1TMPL_PASS_INTERNAL_HEADER
106/*
107 *
108 * Internal header file.
109 *
110 */
111# define RTASN1TMPL_BEGIN_COMMON() extern DECL_HIDDEN_DATA(RTASN1COREVTABLE const) RT_CONCAT3(g_,RTASN1TMPL_INT_NAME,_Vtable)
112
113# define RTASN1TMPL_BEGIN_SEQCORE() RTASN1TMPL_BEGIN_COMMON()
114# define RTASN1TMPL_BEGIN_SETCORE() RTASN1TMPL_BEGIN_COMMON()
115# define RTASN1TMPL_MEMBER_EX(a_Name, a_Type, a_Api, a_Constraints) RTASN1TMPL_SEMICOLON_DUMMY()
116# define RTASN1TMPL_MEMBER_OPT_XTAG_EX(a_TnNm, a_CtxTagN, a_Name, a_Type, a_Api, a_uTag, a_Constraints) \
117 extern "C" DECL_HIDDEN_DATA(RTASN1COREVTABLE const) RT_CONCAT5(g_,RTASN1TMPL_INT_NAME,_XTAG_,a_Name,_Vtable)
118
119# define RTASN1TMPL_MEMBER_DYN_BEGIN(a_enmType, a_enmMembNm, a_Allocation) RTASN1TMPL_SEMICOLON_DUMMY()
120# define RTASN1TMPL_MEMBER_DYN_END(a_enmType, a_enmMembNm, a_Allocation) RTASN1TMPL_SEMICOLON_DUMMY()
121# define RTASN1TMPL_END_SEQCORE() RTASN1TMPL_SEMICOLON_DUMMY()
122# define RTASN1TMPL_END_SETCORE() RTASN1TMPL_SEMICOLON_DUMMY()
123
124
125# define RTASN1TMPL_BEGIN_PCHOICE() RTASN1TMPL_BEGIN_COMMON()
126# define RTASN1TMPL_PCHOICE_ITAG_EX(a_uTag, a_enmChoice, a_PtrName, a_Name, a_Type, a_Api, a_fClue, a_Constraints) \
127 RTASN1TMPL_SEMICOLON_DUMMY()
128# define RTASN1TMPL_PCHOICE_XTAG_EX(a_uTag, a_enmChoice, a_PtrTnNm, a_CtxTagN, a_Name, a_Type, a_Api, a_Constraints) \
129 extern "C" DECL_HIDDEN_DATA(RTASN1COREVTABLE const) RT_CONCAT5(g_,RTASN1TMPL_INT_NAME,_PCHOICE_XTAG_,a_Name,_Vtable)
130
131# define RTASN1TMPL_END_PCHOICE() RTASN1TMPL_SEMICOLON_DUMMY()
132
133
134# define RTASN1TMPL_SEQ_OF(a_ItemType, a_ItemApi) RTASN1TMPL_BEGIN_COMMON()
135# define RTASN1TMPL_SET_OF(a_ItemType, a_ItemApi) RTASN1TMPL_BEGIN_COMMON()
136
137
138
139#elif RTASN1TMPL_PASS == RTASN1TMPL_PASS_XTAG
140/*
141 *
142 * Generate a vtable and associated methods for explicitly tagged items (XTAG).
143 *
144 * These turned out to be a little problematic during encoding since there are
145 * two tags, the first encapsulating the second, thus the enumeration has to be
146 * nested or we cannot calculate the size of the first tag.
147 *
148 *
149 */
150# define RTASN1TMPL_BEGIN_COMMON() RTASN1TMPL_SEMICOLON_DUMMY()
151# define RTASN1TMPL_BEGIN_SEQCORE() RTASN1TMPL_SEMICOLON_DUMMY()
152# define RTASN1TMPL_BEGIN_SETCORE() RTASN1TMPL_SEMICOLON_DUMMY()
153# define RTASN1TMPL_MEMBER_EX(a_Name, a_Type, a_Api, a_Constraints) RTASN1TMPL_SEMICOLON_DUMMY()
154# define RTASN1TMPL_MEMBER_DYN_BEGIN(a_enmType, a_enmMembNm, a_Allocation) RTASN1TMPL_SEMICOLON_DUMMY()
155# define RTASN1TMPL_MEMBER_DYN_END(a_enmType, a_enmMembNm, a_Allocation) RTASN1TMPL_SEMICOLON_DUMMY()
156# define RTASN1TMPL_MEMBER_OPT_XTAG_EX(a_TnNm, a_CtxTagN, a_Name, a_Type, a_Api, a_uTag, a_Constraints) \
157 /* This is the method we need to make it work. */ \
158 static DECLCALLBACK(int) RT_CONCAT4(RTASN1TMPL_INT_NAME,_XTAG_,a_Name,_Enum)(PRTASN1CORE pThisCore, \
159 PFNRTASN1ENUMCALLBACK pfnCallback, \
160 uint32_t uDepth, void *pvUser) \
161 { \
162 RTASN1TMPL_TYPE *pThis = RT_FROM_MEMBER(pThisCore, RTASN1TMPL_TYPE, a_TnNm.a_CtxTagN); \
163 if (RTASN1CORE_IS_PRESENT(&pThis->a_TnNm.a_CtxTagN.Asn1Core)) \
164 return pfnCallback(RT_CONCAT(a_Api,_GetAsn1Core)(&pThis->a_TnNm.a_Name), #a_TnNm "." #a_Name, uDepth + 1, pvUser); \
165 return VINF_SUCCESS; \
166 } \
167 /* The reminder of the methods shouldn't normally be needed, just stub them. */ \
168 static DECLCALLBACK(void) RT_CONCAT4(RTASN1TMPL_INT_NAME,_XTAG_,a_Name,_Delete)(PRTASN1CORE pThisCore) \
169 { AssertFailed(); RT_NOREF_PV(pThisCore); } \
170 static DECLCALLBACK(int) RT_CONCAT4(RTASN1TMPL_INT_NAME,_XTAG_,a_Name,_Clone)(PRTASN1CORE pThisCore, PCRTASN1CORE pSrcCore, \
171 PCRTASN1ALLOCATORVTABLE pAllocator) \
172 { AssertFailed(); RT_NOREF_PV(pThisCore); RT_NOREF_PV(pSrcCore); RT_NOREF_PV(pAllocator); return VERR_INTERNAL_ERROR_2; } \
173 static DECLCALLBACK(int) RT_CONCAT4(RTASN1TMPL_INT_NAME,_XTAG_,a_Name,_Compare)(PCRTASN1CORE pLeftCore, \
174 PCRTASN1CORE pRightCore) \
175 { AssertFailed(); RT_NOREF_PV(pLeftCore); RT_NOREF_PV(pRightCore); return VERR_INTERNAL_ERROR_2; } \
176 static DECLCALLBACK(int) RT_CONCAT4(RTASN1TMPL_INT_NAME,_XTAG_,a_Name,_CheckSanity)(PCRTASN1CORE pThisCore, uint32_t fFlags, \
177 PRTERRINFO pErrInfo, const char *pszErrorTag) \
178 { AssertFailed(); RT_NOREF_PV(pThisCore); RT_NOREF_PV(fFlags); RT_NOREF_PV(pErrInfo); RT_NOREF_PV(pszErrorTag); \
179 return VERR_INTERNAL_ERROR_2; } \
180 DECL_HIDDEN_CONST(RTASN1COREVTABLE const) RT_CONCAT5(g_,RTASN1TMPL_INT_NAME,_XTAG_,a_Name,_Vtable) = \
181 { \
182 /* When the Asn1Core is at the start of the structure, we can reuse the _Delete and _Enum APIs here. */ \
183 /* .pszName = */ RT_XSTR(RTASN1TMPL_INT_NAME) "_XTAG_" RT_XSTR(a_Name), \
184 /* .cb = */ RT_SIZEOFMEMB(RTASN1TMPL_TYPE, a_TnNm), \
185 /* .uDefaultTag = */ a_uTag, \
186 /* .fDefaultClass = */ ASN1_TAGCLASS_CONTEXT, \
187 /* .uReserved = */ 0, \
188 RT_CONCAT4(RTASN1TMPL_INT_NAME,_XTAG_,a_Name,_Delete), \
189 RT_CONCAT4(RTASN1TMPL_INT_NAME,_XTAG_,a_Name,_Enum), \
190 RT_CONCAT4(RTASN1TMPL_INT_NAME,_XTAG_,a_Name,_Clone), \
191 RT_CONCAT4(RTASN1TMPL_INT_NAME,_XTAG_,a_Name,_Compare), \
192 RT_CONCAT4(RTASN1TMPL_INT_NAME,_XTAG_,a_Name,_CheckSanity), \
193 /*.pfnEncodePrep */ NULL, \
194 /*.pfnEncodeWrite */ NULL \
195 }
196
197
198# define RTASN1TMPL_END_SEQCORE() RTASN1TMPL_SEMICOLON_DUMMY()
199# define RTASN1TMPL_END_SETCORE() RTASN1TMPL_SEMICOLON_DUMMY()
200# define RTASN1TMPL_BEGIN_PCHOICE() RTASN1TMPL_SEMICOLON_DUMMY()
201# define RTASN1TMPL_PCHOICE_ITAG_EX(a_uTag, a_enmChoice, a_PtrName, a_Name, a_Type, a_Api, a_fClue, a_Constraints) \
202 RTASN1TMPL_SEMICOLON_DUMMY()
203# define RTASN1TMPL_PCHOICE_XTAG_EX(a_uTag, a_enmChoice, a_PtrTnNm, a_CtxTagN, a_Name, a_Type, a_Api, a_Constraints) \
204 /* This is the method we need to make it work. */ \
205 static DECLCALLBACK(int) RT_CONCAT4(RTASN1TMPL_INT_NAME,_PC_XTAG_,a_Name,_Enum)(PRTASN1CORE pThisCore, \
206 PFNRTASN1ENUMCALLBACK pfnCallback, \
207 uint32_t uDepth, void *pvUser) \
208 { \
209 if (RTASN1CORE_IS_PRESENT(pThisCore)) \
210 { \
211 /** @todo optimize this one day, possibly change the PCHOICE+XTAG representation. */ \
212 RTASN1TMPL_TYPE Tmp; \
213 *(PRTASN1CORE *)&Tmp.a_PtrTnNm = pThisCore; \
214 Assert(&Tmp.a_PtrTnNm->a_CtxTagN.Asn1Core == pThisCore); \
215 return pfnCallback(RT_CONCAT(a_Api,_GetAsn1Core)(&Tmp.a_PtrTnNm->a_Name), "T" #a_uTag "." #a_Name, uDepth + 1, pvUser); \
216 } \
217 return VINF_SUCCESS; \
218 } \
219 /* The reminder of the methods shouldn't normally be needed, just stub them. */ \
220 static DECLCALLBACK(void) RT_CONCAT4(RTASN1TMPL_INT_NAME,_PC_XTAG_,a_Name,_Delete)(PRTASN1CORE pThisCore) \
221 { AssertFailed(); RT_NOREF_PV(pThisCore); } \
222 static DECLCALLBACK(int) RT_CONCAT4(RTASN1TMPL_INT_NAME,_PC_XTAG_,a_Name,_Clone)(PRTASN1CORE pThisCore, PCRTASN1CORE pSrcCore, \
223 PCRTASN1ALLOCATORVTABLE pAllocator) \
224 { AssertFailed(); RT_NOREF_PV(pThisCore); RT_NOREF_PV(pSrcCore); RT_NOREF_PV(pAllocator); return VERR_INTERNAL_ERROR_3; } \
225 static DECLCALLBACK(int) RT_CONCAT4(RTASN1TMPL_INT_NAME,_PC_XTAG_,a_Name,_Compare)(PCRTASN1CORE pLeftCore, \
226 PCRTASN1CORE pRightCore) \
227 { AssertFailed(); RT_NOREF_PV(pLeftCore); RT_NOREF_PV(pRightCore); return VERR_INTERNAL_ERROR_3; } \
228 static DECLCALLBACK(int) RT_CONCAT4(RTASN1TMPL_INT_NAME,_PC_XTAG_,a_Name,_CheckSanity)(PCRTASN1CORE pThisCore, uint32_t fFlags, \
229 PRTERRINFO pErrInfo, const char *pszErrorTag) \
230 { AssertFailed(); RT_NOREF_PV(pThisCore); RT_NOREF_PV(fFlags); RT_NOREF_PV(pErrInfo); RT_NOREF_PV(pszErrorTag); \
231 return VERR_INTERNAL_ERROR_3; } \
232 DECL_HIDDEN_CONST(RTASN1COREVTABLE const) RT_CONCAT5(g_,RTASN1TMPL_INT_NAME,_PCHOICE_XTAG_,a_Name,_Vtable) = \
233 { \
234 /* When the Asn1Core is at the start of the structure, we can reuse the _Delete and _Enum APIs here. */ \
235 /* .pszName = */ RT_XSTR(RTASN1TMPL_INT_NAME) "_PCHOICE_XTAG_" RT_XSTR(a_Name), \
236 /* .cb = */ sizeof(*((RTASN1TMPL_TYPE *)(void *)0)->a_PtrTnNm), \
237 /* .uDefaultTag = */ a_uTag, \
238 /* .fDefaultClass = */ ASN1_TAGCLASS_CONTEXT, \
239 /* .uReserved = */ 0, \
240 RT_CONCAT4(RTASN1TMPL_INT_NAME,_PC_XTAG_,a_Name,_Delete), \
241 RT_CONCAT4(RTASN1TMPL_INT_NAME,_PC_XTAG_,a_Name,_Enum), \
242 RT_CONCAT4(RTASN1TMPL_INT_NAME,_PC_XTAG_,a_Name,_Clone), \
243 RT_CONCAT4(RTASN1TMPL_INT_NAME,_PC_XTAG_,a_Name,_Compare), \
244 RT_CONCAT4(RTASN1TMPL_INT_NAME,_PC_XTAG_,a_Name,_CheckSanity), \
245 /*.pfnEncodePrep */ NULL, \
246 /*.pfnEncodeWrite */ NULL \
247 }
248
249
250
251# define RTASN1TMPL_END_PCHOICE() RTASN1TMPL_SEMICOLON_DUMMY()
252# define RTASN1TMPL_SEQ_OF(a_ItemType, a_ItemApi) RTASN1TMPL_SEMICOLON_DUMMY()
253# define RTASN1TMPL_SET_OF(a_ItemType, a_ItemApi) RTASN1TMPL_SEMICOLON_DUMMY()
254
255
256
257#elif RTASN1TMPL_PASS == RTASN1TMPL_PASS_VTABLE
258/*
259 *
260 * Internal header file.
261 *
262 */
263# ifndef RTASN1TMPL_VTABLE_FN_ENCODE_PREP
264# define RTASN1TMPL_VTABLE_FN_ENCODE_PREP NULL
265# endif
266# ifndef RTASN1TMPL_VTABLE_FN_ENCODE_WRITE
267# define RTASN1TMPL_VTABLE_FN_ENCODE_WRITE NULL
268# endif
269# define RTASN1TMPL_BEGIN_COMMON(a_uDefaultTag, a_fDefaultClass) \
270 DECL_HIDDEN_CONST(RTASN1COREVTABLE const) RT_CONCAT3(g_,RTASN1TMPL_INT_NAME,_Vtable) = \
271 { \
272 /* When the Asn1Core is at the start of the structure, we can reuse the _Delete and _Enum APIs here. */ \
273 /* .pszName = */ RT_XSTR(RTASN1TMPL_EXT_NAME), \
274 /* .cb = */ sizeof(RTASN1TMPL_TYPE), \
275 /* .uDefaultTag = */ a_uDefaultTag, \
276 /* .fDefaultClass = */ a_fDefaultClass, \
277 /* .uReserved = */ 0, \
278 (PFNRTASN1COREVTDTOR)RT_CONCAT(RTASN1TMPL_EXT_NAME,_Delete), \
279 (PFNRTASN1COREVTENUM)RT_CONCAT(RTASN1TMPL_EXT_NAME,_Enum), \
280 (PFNRTASN1COREVTCLONE)RT_CONCAT(RTASN1TMPL_EXT_NAME,_Clone), \
281 (PFNRTASN1COREVTCOMPARE)RT_CONCAT(RTASN1TMPL_EXT_NAME,_Compare), \
282 (PFNRTASN1COREVTCHECKSANITY)RT_CONCAT(RTASN1TMPL_EXT_NAME,_CheckSanity), \
283 RTASN1TMPL_VTABLE_FN_ENCODE_PREP, \
284 RTASN1TMPL_VTABLE_FN_ENCODE_WRITE \
285 }
286
287# define RTASN1TMPL_BEGIN_SEQCORE() \
288 AssertCompileMemberOffset(RTASN1TMPL_TYPE, SeqCore, 0); \
289 RTASN1TMPL_BEGIN_COMMON(ASN1_TAG_SEQUENCE, ASN1_TAGCLASS_UNIVERSAL | ASN1_TAGFLAG_CONSTRUCTED)
290# define RTASN1TMPL_BEGIN_SETCORE() \
291 AssertCompileMemberOffset(RTASN1TMPL_TYPE, SetCore, 0); \
292 RTASN1TMPL_BEGIN_COMMON(ASN1_TAG_SET, ASN1_TAGCLASS_UNIVERSAL | ASN1_TAGFLAG_CONSTRUCTED)
293# define RTASN1TMPL_MEMBER_EX(a_Name, a_Type, a_Api, a_Constraints) RTASN1TMPL_SEMICOLON_DUMMY()
294# define RTASN1TMPL_MEMBER_DYN_BEGIN(a_enmType, a_enmMembNm, a_Allocation) RTASN1TMPL_SEMICOLON_DUMMY()
295# define RTASN1TMPL_MEMBER_DYN_END(a_enmType, a_enmMembNm, a_Allocation) RTASN1TMPL_SEMICOLON_DUMMY()
296# define RTASN1TMPL_END_SEQCORE() RTASN1TMPL_SEMICOLON_DUMMY()
297# define RTASN1TMPL_END_SETCORE() RTASN1TMPL_SEMICOLON_DUMMY()
298
299# define RTASN1TMPL_BEGIN_PCHOICE() \
300 AssertCompileMemberOffset(RTASN1TMPL_TYPE, Dummy, 0); \
301 RTASN1TMPL_BEGIN_COMMON(UINT8_MAX, UINT8_MAX)
302# define RTASN1TMPL_PCHOICE_ITAG_EX(a_uTag, a_enmChoice, a_PtrName, a_Name, a_Type, a_Api, a_fClue, a_Constraints) \
303 RTASN1TMPL_SEMICOLON_DUMMY()
304# define RTASN1TMPL_PCHOICE_XTAG_EX(a_uTag, a_enmChoice, a_PtrTnNm, a_CtxTagN, a_Name, a_Type, a_Api, a_Constraints) \
305 RTASN1TMPL_SEMICOLON_DUMMY()
306# define RTASN1TMPL_END_PCHOICE() RTASN1TMPL_SEMICOLON_DUMMY()
307
308# define RTASN1TMPL_SEQ_OF(a_ItemType, a_ItemApi) \
309 AssertCompileMemberOffset(RTASN1TMPL_TYPE, SeqCore, 0); \
310 RTASN1TMPL_BEGIN_COMMON(ASN1_TAG_SEQUENCE, ASN1_TAGCLASS_UNIVERSAL | ASN1_TAGFLAG_CONSTRUCTED)
311# define RTASN1TMPL_SET_OF(a_ItemType, a_ItemApi) \
312 AssertCompileMemberOffset(RTASN1TMPL_TYPE, SetCore, 0); \
313 RTASN1TMPL_BEGIN_COMMON(ASN1_TAG_SET, ASN1_TAGCLASS_UNIVERSAL | ASN1_TAGFLAG_CONSTRUCTED)
314
315
316
317#elif RTASN1TMPL_PASS == RTASN1TMPL_PASS_INIT
318/*
319 *
320 * Initialization to standard / default values.
321 *
322 */
323# define RTASN1TMPL_BEGIN_COMMON() \
324RTASN1TMPL_DECL(int) RT_CONCAT(RTASN1TMPL_EXT_NAME,_Init)(RT_CONCAT(P,RTASN1TMPL_TYPE) pThis, PCRTASN1ALLOCATORVTABLE pAllocator) \
325{ \
326 RT_NOREF_PV(pAllocator); \
327 RT_ZERO(*pThis)
328# define RTASN1TMPL_END_COMMON() \
329 return rc; \
330} RTASN1TMPL_SEMICOLON_DUMMY()
331
332# define RTASN1TMPL_BEGIN_SEQCORE() \
333 RTASN1TMPL_BEGIN_COMMON(); \
334 int rc = RTAsn1SequenceCore_Init(&pThis->SeqCore, &RT_CONCAT3(g_,RTASN1TMPL_INT_NAME,_Vtable))
335# define RTASN1TMPL_BEGIN_SETCORE() \
336 RTASN1TMPL_BEGIN_COMMON(); \
337 int rc = RTAsn1SetCore_Init(&pThis->SetCore, &RT_CONCAT3(g_,RTASN1TMPL_INT_NAME,_Vtable))
338# define RTASN1TMPL_MEMBER_EX(a_Name, a_Type, a_Api, a_Constraints) \
339 if (RT_SUCCESS(rc)) \
340 rc = RT_CONCAT(a_Api,_Init)(&pThis->a_Name, pAllocator)
341
342# define RTASN1TMPL_MEMBER_DYN_BEGIN(a_enmType, a_enmMembNm, a_Allocation) \
343 RTAsn1MemInitAllocation(&pThis->Allocation, pAllocator); \
344 pThis->a_enmMembNm = RT_CONCAT(a_enmType,_NOT_PRESENT)
345# define RTASN1TMPL_MEMBER_DYN_COMMON(a_UnionNm, a_PtrName, a_Type, a_Api, a_Allocation, a_enmMembNm, a_enmValue, a_IfStmt) \
346 do { } while (0)
347# define RTASN1TMPL_MEMBER_DYN_END(a_enmType, a_enmMembNm, a_Allocation) do { } while (0)
348
349# define RTASN1TMPL_MEMBER_DEF_ITAG_EX(a_Name, a_Type, a_Api, a_uTag, a_fClue, a_DefVal, a_Constraints) \
350 if (RT_SUCCESS(rc)) \
351 { \
352 rc = RT_CONCAT(a_Api,_InitDefault)(&pThis->a_Name, a_DefVal, pAllocator); \
353 if (RT_SUCCESS(rc)) \
354 rc = RTAsn1Core_SetTagAndFlags(RT_CONCAT(a_Api,_GetAsn1Core)(&pThis->a_Name), \
355 a_uTag, RTASN1TMPL_ITAG_F_EXPAND(a_fClue)); \
356 }
357# define RTASN1TMPL_MEMBER_OPT_EX(a_Name, a_Type, a_Api, a_Constraints) do { } while (0) /* All optional members are left as not-present. */
358# define RTASN1TMPL_END_SEQCORE() \
359 if (RT_FAILURE(rc)) \
360 RT_CONCAT(RTASN1TMPL_EXT_NAME,_Delete)(pThis); \
361 RTASN1TMPL_END_COMMON()
362# define RTASN1TMPL_END_SETCORE() RTASN1TMPL_END_SEQCORE()
363
364/* No choice, just an empty, non-present structure. */
365# define RTASN1TMPL_BEGIN_PCHOICE() \
366 RTASN1TMPL_BEGIN_COMMON(); \
367 RTAsn1MemInitAllocation(&pThis->Allocation, pAllocator); \
368 int rc = VINF_SUCCESS
369# define RTASN1TMPL_PCHOICE_ITAG_EX(a_uTag, a_enmChoice, a_PtrName, a_Name, a_Type, a_Api, a_fClue, a_Constraints) \
370 do { } while (0)
371# define RTASN1TMPL_PCHOICE_XTAG_EX(a_uTag, a_enmChoice, a_PtrTnNm, a_CtxTagN, a_Name, a_Type, a_Api, a_Constraints) \
372 do { } while (0)
373# define RTASN1TMPL_END_PCHOICE() RTASN1TMPL_END_COMMON()
374
375
376# define RTASN1TMPL_SET_SEQ_OF_COMMON(a_ItemType, a_ItemApi, a_OfApi, a_OfMember) \
377 RTASN1TMPL_BEGIN_COMMON(); \
378 RTAsn1MemInitArrayAllocation(&pThis->Allocation, pAllocator, sizeof(a_ItemType)); \
379 int rc = RT_CONCAT(a_OfApi,_Init)(&pThis->a_OfMember, &RT_CONCAT3(g_,RTASN1TMPL_INT_NAME,_Vtable)); \
380 if (RT_FAILURE(rc)) \
381 RT_ZERO(*pThis); \
382 RTASN1TMPL_END_COMMON()
383# define RTASN1TMPL_SEQ_OF(a_ItemType, a_ItemApi) RTASN1TMPL_SET_SEQ_OF_COMMON(a_ItemType, a_ItemApi, RTAsn1SeqOfCore, SeqCore)
384# define RTASN1TMPL_SET_OF(a_ItemType, a_ItemApi) RTASN1TMPL_SET_SEQ_OF_COMMON(a_ItemType, a_ItemApi, RTAsn1SetOfCore, SetCore)
385
386
387
388#elif RTASN1TMPL_PASS == RTASN1TMPL_PASS_DECODE
389/*
390 *
391 * Decode ASN.1.
392 *
393 */
394# define RTASN1TMPL_BEGIN_COMMON() \
395RTASN1TMPL_DECL(int) RT_CONCAT(RTASN1TMPL_EXT_NAME,_DecodeAsn1)(PRTASN1CURSOR pCursor, uint32_t fFlags, \
396 RT_CONCAT(P,RTASN1TMPL_TYPE) pThis, const char *pszErrorTag) \
397{ \
398 RT_ZERO(*pThis);
399
400# define RTASN1TMPL_END_COMMON() \
401 return rc; \
402} RTASN1TMPL_SEMICOLON_DUMMY()
403
404
405# define RTASN1TMPL_BEGIN_SEQCORE() \
406 RTASN1TMPL_BEGIN_COMMON(); \
407 RTASN1CURSOR ThisCursor; \
408 int rc = RTAsn1CursorGetSequenceCursor(pCursor, fFlags, &pThis->SeqCore, &ThisCursor, pszErrorTag); \
409 if (RT_FAILURE(rc)) \
410 return rc; \
411 pCursor = &ThisCursor; \
412 pThis->SeqCore.Asn1Core.pOps = &RT_CONCAT3(g_,RTASN1TMPL_INT_NAME,_Vtable)
413# define RTASN1TMPL_BEGIN_SETCORE() \
414 RTASN1TMPL_BEGIN_COMMON(); \
415 RTASN1CURSOR ThisCursor; \
416 int rc = RTAsn1CursorGetSetCursor(pCursor, fFlags, &pThis->SetCore, &ThisCursor, pszErrorTag); \
417 if (RT_FAILURE(rc)) \
418 return rc; \
419 pCursor = &ThisCursor; \
420 pThis->SetCore.Asn1Core.pOps = &RT_CONCAT3(g_,RTASN1TMPL_INT_NAME,_Vtable)
421
422# define RTASN1TMPL_MEMBER_EX(a_Name, a_Type, a_Api, a_Constraints) \
423 if (RT_SUCCESS(rc)) \
424 rc = RT_CONCAT(a_Api,_DecodeAsn1)(pCursor, 0, &pThis->a_Name, #a_Name)
425
426# define RTASN1TMPL_MEMBER_DYN_BEGIN(a_enmType, a_enmMembNm, a_Allocation) \
427 if (RT_SUCCESS(rc)) \
428 { \
429 int rc2; /* not initialized! */ \
430 RTAsn1CursorInitAllocation(pCursor, &pThis->a_Allocation); \
431 pThis->a_enmMembNm = RT_CONCAT(a_enmType, _INVALID); \
432 if (false) do { /*nothing*/ } while (0)
433# define RTASN1TMPL_MEMBER_DYN_COMMON(a_UnionNm, a_PtrName, a_Type, a_Api, a_Allocation, a_enmMembNm, a_enmValue, a_IfStmt) \
434 else a_IfStmt \
435 do { \
436 rc2 = RTAsn1MemAllocZ(&pThis->a_Allocation, (void **)&pThis->a_UnionNm.a_PtrName, \
437 sizeof(*pThis->a_UnionNm.a_PtrName)); \
438 if (RT_SUCCESS(rc2)) \
439 { \
440 pThis->a_enmMembNm = a_enmValue; \
441 rc2 = RT_CONCAT(a_Api,_DecodeAsn1)(pCursor, 0, pThis->a_UnionNm.a_PtrName, #a_UnionNm "." #a_PtrName); \
442 } \
443 } while (0)
444# define RTASN1TMPL_MEMBER_DYN_END(a_enmType, a_enmMembNm, a_Allocation) \
445 rc = rc2; /* Should trigger warning if a _DEFAULT is missing. */ \
446 }
447
448# define RTASN1TMPL_MEMBER_OPT_EX(a_Name, a_Type, a_Api, a_Constraints) \
449 Error_Missing_Specific_Macro_In_Decode_Pass()
450
451# define RTASN1TMPL_MEMBER_DEF_ITAG_EX(a_Name, a_Type, a_Api, a_uTag, a_fClue, a_DefVal, a_Constraints) \
452 if (RT_SUCCESS(rc)) \
453 { \
454 if (RTAsn1CursorIsNextEx(pCursor, a_uTag, RTASN1TMPL_ITAG_F_EXPAND(a_fClue))) \
455 rc = RT_CONCAT(a_Api,_DecodeAsn1)(pCursor, 0, &pThis->a_Name, #a_Name); \
456 else \
457 rc = RT_CONCAT(a_Api,_InitDefault)(&pThis->a_Name, a_DefVal, pCursor->pPrimary->pAllocator); \
458 if (RT_SUCCESS(rc)) \
459 rc = RTAsn1Core_SetTagAndFlags(RT_CONCAT(a_Api,_GetAsn1Core)(&pThis->a_Name), \
460 a_uTag, RTASN1TMPL_ITAG_F_EXPAND(a_fClue)); \
461 } do {} while (0)
462
463# define RTASN1TMPL_MEMBER_OPT_UTF8_STRING_EX(a_Name, a_Constraints) \
464 if (RT_SUCCESS(rc) && RTAsn1CursorIsNextEx(pCursor, ASN1_TAG_UTF8_STRING, ASN1_TAGCLASS_CONTEXT | ASN1_TAGFLAG_PRIMITIVE)) \
465 rc = RTAsn1CursorGetUtf8String(pCursor, 0, &pThis->a_Name, #a_Name)
466
467# define RTASN1TMPL_MEMBER_OPT_ITAG_EX(a_Name, a_Type, a_Api, a_uTag, a_fClue, a_Constraints) \
468 if (RT_SUCCESS(rc) && RTAsn1CursorIsNextEx(pCursor, a_uTag, RTASN1TMPL_ITAG_F_EXPAND(a_fClue)) /** @todo || CER */) \
469 rc = RT_CONCAT(a_Api,_DecodeAsn1)(pCursor, RTASN1CURSOR_GET_F_IMPLICIT, &pThis->a_Name, #a_Name)
470
471# define RTASN1TMPL_MEMBER_OPT_ITAG_BITSTRING(a_Name, a_cMaxBits, a_uTag) \
472 if (RT_SUCCESS(rc) && RTAsn1CursorIsNextEx(pCursor, a_uTag, ASN1_TAGCLASS_CONTEXT | ASN1_TAGFLAG_CONSTRUCTED)) \
473 rc = RTAsn1CursorGetBitStringEx(pCursor, RTASN1CURSOR_GET_F_IMPLICIT, a_cMaxBits, &pThis->a_Name, #a_Name)
474
475# define RTASN1TMPL_MEMBER_OPT_XTAG_EX(a_TnNm, a_CtxTagN, a_Name, a_Type, a_Api, a_uTag, a_Constraints) \
476 if (RT_SUCCESS(rc) && RTAsn1CursorIsNextEx(pCursor, a_uTag, ASN1_TAGCLASS_CONTEXT | ASN1_TAGFLAG_CONSTRUCTED)) \
477 { \
478 RTASN1CURSOR CtxCursor; \
479 rc = RT_CONCAT3(RTAsn1CursorGetContextTag,a_uTag,Cursor)(pCursor, 0, \
480 &RT_CONCAT5(g_,RTASN1TMPL_INT_NAME,_XTAG_,a_Name,_Vtable), \
481 &pThis->a_TnNm.a_CtxTagN, &CtxCursor, #a_TnNm); \
482 if (RT_SUCCESS(rc)) \
483 { \
484 rc = RT_CONCAT(a_Api,_DecodeAsn1)(&CtxCursor, 0, &pThis->a_TnNm.a_Name, #a_Name); \
485 if (RT_SUCCESS(rc)) \
486 rc = RTAsn1CursorCheckEnd(&CtxCursor); \
487 } \
488 } do { } while (0)
489
490# define RTASN1TMPL_MEMBER_OPT_ANY(a_Name, a_Type, a_Api) \
491 if (RT_SUCCESS(rc) && pCursor->cbLeft > 0) \
492 RTASN1TMPL_MEMBER_EX(a_Name, a_Type, a_Api, RT_NOTHING)
493
494# define RTASN1TMPL_END_SEQCORE() \
495 if (RT_SUCCESS(rc)) \
496 rc = RTAsn1CursorCheckSeqEnd(&ThisCursor, &pThis->SeqCore); \
497 if (RT_SUCCESS(rc)) \
498 return VINF_SUCCESS; \
499 RT_CONCAT(RTASN1TMPL_EXT_NAME,_Delete)(pThis); \
500 RTASN1TMPL_END_COMMON()
501# define RTASN1TMPL_END_SETCORE() \
502 if (RT_SUCCESS(rc)) \
503 rc = RTAsn1CursorCheckSetEnd(&ThisCursor, &pThis->SetCore); \
504 if (RT_SUCCESS(rc)) \
505 return VINF_SUCCESS; \
506 RT_CONCAT(RTASN1TMPL_EXT_NAME,_Delete)(pThis); \
507 RTASN1TMPL_END_COMMON()
508
509# define RTASN1TMPL_BEGIN_PCHOICE() \
510 RTASN1TMPL_BEGIN_COMMON(); \
511 RT_NOREF_PV(fFlags); \
512 RTAsn1Dummy_InitEx(&pThis->Dummy); \
513 pThis->Dummy.Asn1Core.pOps = &RT_CONCAT3(g_,RTASN1TMPL_INT_NAME,_Vtable); \
514 RTAsn1CursorInitAllocation(pCursor, &pThis->Allocation); \
515 RTASN1CORE Asn1Peek; \
516 int rc = RTAsn1CursorPeek(pCursor, &Asn1Peek); \
517 if (RT_SUCCESS(rc)) \
518 { \
519 if (false) do {} while (0)
520# define RTASN1TMPL_PCHOICE_ITAG_EX(a_uTag, a_enmChoice, a_PtrName, a_Name, a_Type, a_Api, a_fClue, a_Constraints) \
521 else if ( Asn1Peek.uTag == (a_uTag) \
522 && (Asn1Peek.fClass == RTASN1TMPL_ITAG_F_EXPAND(a_fClue) /** @todo || CER */ ) ) \
523 do { \
524 pThis->enmChoice = a_enmChoice; \
525 rc = RTAsn1MemAllocZ(&pThis->Allocation, (void **)&pThis->a_PtrName, sizeof(*pThis->a_PtrName)); \
526 if (RT_SUCCESS(rc)) \
527 rc = RT_CONCAT(a_Api,_DecodeAsn1)(pCursor, RTASN1CURSOR_GET_F_IMPLICIT, pThis->a_PtrName, #a_PtrName); \
528 } while (0)
529# define RTASN1TMPL_PCHOICE_XTAG_EX(a_uTag, a_enmChoice, a_PtrTnNm, a_CtxTagN, a_Name, a_Type, a_Api, a_Constraints) \
530 else if (Asn1Peek.uTag == (a_uTag) && Asn1Peek.fClass == (ASN1_TAGCLASS_CONTEXT | ASN1_TAGFLAG_CONSTRUCTED)) \
531 do { \
532 pThis->enmChoice = a_enmChoice; \
533 rc = RTAsn1MemAllocZ(&pThis->Allocation, (void **)&pThis->a_PtrTnNm, sizeof(*pThis->a_PtrTnNm)); \
534 if (RT_SUCCESS(rc)) \
535 { \
536 RTASN1CURSOR CtxCursor; \
537 rc = RT_CONCAT3(RTAsn1CursorGetContextTag,a_uTag,Cursor)(pCursor, 0, \
538 &RT_CONCAT5(g_,RTASN1TMPL_INT_NAME,_PCHOICE_XTAG_,a_Name,_Vtable), \
539 &pThis->a_PtrTnNm->a_CtxTagN, &CtxCursor, "T" #a_uTag); \
540 if (RT_SUCCESS(rc)) \
541 rc = RT_CONCAT(a_Api,_DecodeAsn1)(&CtxCursor, RTASN1CURSOR_GET_F_IMPLICIT, \
542 &pThis->a_PtrTnNm->a_Name, #a_Name); \
543 if (RT_SUCCESS(rc)) \
544 rc = RTAsn1CursorCheckEnd(&CtxCursor); \
545 } \
546 } while (0)
547#define RTASN1TMPL_END_PCHOICE() \
548 else \
549 rc = RTAsn1CursorSetInfo(pCursor, VERR_GENERAL_FAILURE, "%s: Unknown choice: tag=%#x fClass=%#x", \
550 pszErrorTag, Asn1Peek.uTag, Asn1Peek.fClass); \
551 if (RT_SUCCESS(rc)) \
552 return VINF_SUCCESS; \
553 } \
554 RT_CONCAT(RTASN1TMPL_EXT_NAME,_Delete)(pThis); \
555 RTASN1TMPL_END_COMMON()
556
557
558# define RTASN1TMPL_SET_SEQ_OF_COMMON(a_ItemType, a_ItemApi, a_OfApi, a_OfMember, a_fnGetCursor) \
559 RTASN1TMPL_BEGIN_COMMON(); \
560 RTASN1CURSOR ThisCursor; \
561 int rc = a_fnGetCursor(pCursor, fFlags, &pThis->a_OfMember, &ThisCursor, pszErrorTag); \
562 if (RT_SUCCESS(rc)) \
563 { \
564 pCursor = &ThisCursor; \
565 pThis->a_OfMember.Asn1Core.pOps = &RT_CONCAT3(g_,RTASN1TMPL_INT_NAME,_Vtable); \
566 RTAsn1CursorInitArrayAllocation(pCursor, &pThis->Allocation, sizeof(a_ItemType)); \
567 \
568 uint32_t i = 0; \
569 while ( pCursor->cbLeft > 0 \
570 && RT_SUCCESS(rc)) \
571 { \
572 rc = RTAsn1MemResizeArray(&pThis->Allocation, (void ***)&pThis->papItems, i, i + 1); \
573 if (RT_SUCCESS(rc)) \
574 { \
575 rc = RT_CONCAT(a_ItemApi,_DecodeAsn1)(pCursor, 0, pThis->papItems[i], "papItems[#]"); \
576 if (RT_SUCCESS(rc)) \
577 { \
578 i++; \
579 pThis->cItems = i; \
580 continue; \
581 } \
582 } \
583 break; \
584 } \
585 if (RT_SUCCESS(rc)) \
586 { \
587 rc = RTAsn1CursorCheckEnd(pCursor); \
588 if (RT_SUCCESS(rc)) \
589 return VINF_SUCCESS; \
590 } \
591 RT_CONCAT(RTASN1TMPL_EXT_NAME,_Delete)(pThis); \
592 } \
593 RTASN1TMPL_END_COMMON()
594# define RTASN1TMPL_SEQ_OF(a_ItemType, a_ItemApi) \
595 RTASN1TMPL_SET_SEQ_OF_COMMON(a_ItemType, a_ItemApi, RTAsn1SeqOfCore, SeqCore, RTAsn1CursorGetSequenceCursor)
596# define RTASN1TMPL_SET_OF(a_ItemType, a_ItemApi) \
597 RTASN1TMPL_SET_SEQ_OF_COMMON(a_ItemType, a_ItemApi, RTAsn1SetOfCore, SetCore, RTAsn1CursorGetSetCursor)
598
599
600# define RTASN1TMPL_EXEC_DECODE(a_Expr) if (RT_SUCCESS(rc)) { a_Expr; }
601
602
603
604#elif RTASN1TMPL_PASS == RTASN1TMPL_PASS_ENUM
605/*
606 *
607 * Enumeration.
608 *
609 */
610# define RTASN1TMPL_BEGIN_COMMON() \
611RTASN1TMPL_DECL(int) RT_CONCAT(RTASN1TMPL_EXT_NAME,_Enum)(RT_CONCAT(P,RTASN1TMPL_TYPE) pThis, \
612 PFNRTASN1ENUMCALLBACK pfnCallback, \
613 uint32_t uDepth, void *pvUser) \
614{ \
615 if (!RT_CONCAT(RTASN1TMPL_EXT_NAME,_IsPresent)(pThis)) \
616 return VINF_SUCCESS; \
617 uDepth++; \
618 int rc = VINF_SUCCESS
619
620# define RTASN1TMPL_END_COMMON() \
621 return rc; \
622} RTASN1TMPL_SEMICOLON_DUMMY()
623
624# define RTASN1TMPL_BEGIN_SEQCORE() RTASN1TMPL_BEGIN_COMMON()
625# define RTASN1TMPL_BEGIN_SETCORE() RTASN1TMPL_BEGIN_COMMON()
626# define RTASN1TMPL_MEMBER_EX(a_Name, a_Type, a_Api, a_Constraints) \
627 if (rc == VINF_SUCCESS) \
628 rc = pfnCallback(RT_CONCAT(a_Api,_GetAsn1Core)(&pThis->a_Name), #a_Name, uDepth, pvUser)
629# define RTASN1TMPL_MEMBER_DYN_BEGIN(a_enmType, a_enmMembNm, a_Allocation) \
630 if (rc == VINF_SUCCESS) \
631 switch (pThis->a_enmMembNm) \
632 { \
633 default: rc = VERR_INTERNAL_ERROR_3; break
634# define RTASN1TMPL_MEMBER_DYN_COMMON(a_UnionNm, a_PtrName, a_Type, a_Api, a_Allocation, a_enmMembNm, a_enmValue, a_IfStmt) \
635 case a_enmValue: \
636 rc = pfnCallback(RT_CONCAT(a_Api,_GetAsn1Core)(pThis->a_UnionNm.a_PtrName), #a_UnionNm "." #a_PtrName, \
637 uDepth, pvUser); \
638 break
639# define RTASN1TMPL_MEMBER_DYN_END(a_enmType, a_enmMembNm, a_Allocation) \
640 case RT_CONCAT(a_enmType,_NOT_PRESENT): break; \
641 }
642# define RTASN1TMPL_MEMBER_OPT_EX(a_Name, a_Type, a_Api, a_Constraints) \
643 if (rc == VINF_SUCCESS && RT_CONCAT(a_Api,_IsPresent)(&pThis->a_Name)) \
644 rc = pfnCallback(RT_CONCAT(a_Api,_GetAsn1Core)(&pThis->a_Name), #a_Name, uDepth, pvUser)
645# define RTASN1TMPL_MEMBER_OPT_XTAG_EX(a_TnNm, a_CtxTagN, a_Name, a_Type, a_Api, a_uTag, a_Constraints) \
646 if (rc == VINF_SUCCESS && RTASN1CORE_IS_PRESENT(&pThis->a_TnNm.a_CtxTagN.Asn1Core)) \
647 { \
648 rc = pfnCallback(&pThis->a_TnNm.a_CtxTagN.Asn1Core, #a_Name, uDepth, pvUser); \
649 } do {} while (0)
650# define RTASN1TMPL_END_SEQCORE() RTASN1TMPL_END_COMMON()
651# define RTASN1TMPL_END_SETCORE() RTASN1TMPL_END_COMMON()
652
653
654# define RTASN1TMPL_BEGIN_PCHOICE() \
655 RTASN1TMPL_BEGIN_COMMON(); \
656 switch (pThis->enmChoice) \
657 { \
658 default: rc = VERR_INTERNAL_ERROR_3; break
659# define RTASN1TMPL_PCHOICE_ITAG_EX(a_uTag, a_enmChoice, a_PtrName, a_Name, a_Type, a_Api, a_fClue, a_Constraints) \
660 case a_enmChoice: rc = pfnCallback(RT_CONCAT(a_Api,_GetAsn1Core)(pThis->a_PtrName), #a_PtrName, uDepth, pvUser); break
661# define RTASN1TMPL_PCHOICE_XTAG_EX(a_uTag, a_enmChoice, a_PtrTnNm, a_CtxTagN, a_Name, a_Type, a_Api, a_Constraints) \
662 case a_enmChoice: rc = pfnCallback(&pThis->a_PtrTnNm->a_CtxTagN.Asn1Core, "T" #a_uTag "." #a_CtxTagN, uDepth, pvUser); break
663#define RTASN1TMPL_END_PCHOICE() \
664 } \
665 RTASN1TMPL_END_COMMON()
666
667# define RTASN1TMPL_SET_SEQ_OF_COMMON(a_ItemType, a_ItemApi) \
668 RTASN1TMPL_BEGIN_COMMON(); \
669 for (uint32_t i = 0; i < pThis->cItems && rc == VINF_SUCCESS; i++) \
670 rc = pfnCallback(RT_CONCAT(a_ItemApi,_GetAsn1Core)(pThis->papItems[i]), "papItems[#]", uDepth, pvUser); \
671 RTASN1TMPL_END_COMMON()
672# define RTASN1TMPL_SEQ_OF(a_ItemType, a_ItemApi) RTASN1TMPL_SET_SEQ_OF_COMMON(a_ItemType, a_ItemApi)
673# define RTASN1TMPL_SET_OF(a_ItemType, a_ItemApi) RTASN1TMPL_SET_SEQ_OF_COMMON(a_ItemType, a_ItemApi)
674
675
676
677#elif RTASN1TMPL_PASS == RTASN1TMPL_PASS_CLONE
678/*
679 *
680 * Clone another instance of the type.
681 *
682 */
683# define RTASN1TMPL_BEGIN_COMMON() \
684RTASN1TMPL_DECL(int) RT_CONCAT(RTASN1TMPL_EXT_NAME,_Clone)(RT_CONCAT(P,RTASN1TMPL_TYPE) pThis, \
685 RT_CONCAT(PC,RTASN1TMPL_TYPE) pSrc, \
686 PCRTASN1ALLOCATORVTABLE pAllocator) \
687{ \
688 RT_ZERO(*pThis); \
689 if (!RT_CONCAT(RTASN1TMPL_EXT_NAME,_IsPresent)(pSrc)) \
690 return VINF_SUCCESS; \
691
692# define RTASN1TMPL_END_COMMON() \
693 return rc; \
694} RTASN1TMPL_SEMICOLON_DUMMY()
695
696# define RTASN1TMPL_BEGIN_SEQCORE() \
697 RTASN1TMPL_BEGIN_COMMON(); \
698 int rc = RTAsn1SequenceCore_Clone(&pThis->SeqCore, &RT_CONCAT3(g_, RTASN1TMPL_INT_NAME, _Vtable), &pSrc->SeqCore)
699# define RTASN1TMPL_BEGIN_SETCORE() \
700 RTASN1TMPL_BEGIN_COMMON(); \
701 int rc = RTAsn1SetCore_Clone(&pThis->SetCore, &RT_CONCAT3(g_, RTASN1TMPL_INT_NAME, _Vtable), &pSrc->SetCore)
702
703# define RTASN1TMPL_MEMBER_EX(a_Name, a_Type, a_Api, a_Constraints) \
704 if (RT_SUCCESS(rc)) \
705 rc = RT_CONCAT(a_Api,_Clone)(&pThis->a_Name, &pSrc->a_Name, pAllocator); \
706
707# define RTASN1TMPL_MEMBER_DYN_BEGIN(a_enmType, a_enmMembNm, a_Allocation) \
708 if (RT_SUCCESS(rc)) \
709 { \
710 RTAsn1MemInitAllocation(&pThis->Allocation, pAllocator); \
711 pThis->a_enmMembNm = pSrc->a_enmMembNm; \
712 switch (pSrc->a_enmMembNm) \
713 { \
714 default: rc = VERR_INTERNAL_ERROR_3; break
715# define RTASN1TMPL_MEMBER_DYN_COMMON(a_UnionNm, a_PtrName, a_Type, a_Api, a_Allocation, a_enmMembNm, a_enmValue, a_IfStmt) \
716 case a_enmValue: \
717 rc = RTAsn1MemAllocZ(&pThis->a_Allocation, (void **)&pThis->a_UnionNm.a_PtrName, \
718 sizeof(*pThis->a_UnionNm.a_PtrName)); \
719 if (RT_SUCCESS(rc)) \
720 rc = RT_CONCAT(a_Api,_Clone)(pThis->a_UnionNm.a_PtrName, pSrc->a_UnionNm.a_PtrName, pAllocator); \
721 break
722# define RTASN1TMPL_MEMBER_DYN_END(a_enmType, a_enmMembNm, a_Allocation) \
723 case RT_CONCAT(a_enmType,_NOT_PRESENT): break; \
724 } \
725 }
726
727/* Optional members and members with defaults are the same as a normal member when cloning. */
728# define RTASN1TMPL_MEMBER_OPT_UTF8_STRING_EX(a_Name, a_Constraints) \
729 RTASN1TMPL_MEMBER_OPT_EX(a_Name, RTASN1STRING, RTAsn1Utf8String, a_Constraints RT_NOTHING)
730# define RTASN1TMPL_MEMBER_OPT_XTAG_EX(a_TnNm, a_CtxTagN, a_Name, a_Type, a_Api, a_uTag, a_Constraints) \
731 if (RTASN1CORE_IS_PRESENT(&pSrc->a_TnNm.a_CtxTagN.Asn1Core) && RT_SUCCESS(rc)) \
732 { \
733 rc = RT_CONCAT3(RTAsn1ContextTag,a_uTag,_Clone)(&pThis->a_TnNm.a_CtxTagN, &pSrc->a_TnNm.a_CtxTagN); \
734 if (RT_SUCCESS(rc)) \
735 rc = RT_CONCAT(a_Api,_Clone)(&pThis->a_TnNm.a_Name, &pSrc->a_TnNm.a_Name, pAllocator); \
736 } do { } while (0)
737
738# define RTASN1TMPL_END_SEQCORE() \
739 if (RT_FAILURE(rc)) \
740 RT_CONCAT(RTASN1TMPL_EXT_NAME,_Delete)(pThis); \
741 RTASN1TMPL_END_COMMON()
742# define RTASN1TMPL_END_SETCORE() RTASN1TMPL_END_SEQCORE()
743
744
745# define RTASN1TMPL_BEGIN_PCHOICE() \
746 RTASN1TMPL_BEGIN_COMMON(); \
747 RTAsn1Dummy_InitEx(&pThis->Dummy); \
748 pThis->Dummy.Asn1Core.pOps = &RT_CONCAT3(g_,RTASN1TMPL_INT_NAME,_Vtable); \
749 RTAsn1MemInitAllocation(&pThis->Allocation, pAllocator); \
750 int rc; \
751 pThis->enmChoice = pSrc->enmChoice; \
752 switch (pSrc->enmChoice) \
753 { \
754 default: rc = VERR_INTERNAL_ERROR_3; break
755# define RTASN1TMPL_PCHOICE_ITAG_EX(a_uTag, a_enmChoice, a_PtrName, a_Name, a_Type, a_Api, a_fClue, a_Constraints) \
756 case a_enmChoice: \
757 rc = RTAsn1MemAllocZ(&pThis->Allocation, (void **)&pThis->a_PtrName, sizeof(*pThis->a_PtrName)); \
758 if (RT_SUCCESS(rc)) \
759 rc = RT_CONCAT(a_Api,_Clone)(pThis->a_PtrName, pSrc->a_PtrName, pAllocator); \
760 break
761# define RTASN1TMPL_PCHOICE_XTAG_EX(a_uTag, a_enmChoice, a_PtrTnNm, a_CtxTagN, a_Name, a_Type, a_Api, a_Constraints) \
762 case a_enmChoice: /* A bit of presence paranoia here, but better safe than sorry... */ \
763 rc = RTAsn1MemAllocZ(&pThis->Allocation, (void **)&pThis->a_PtrTnNm, sizeof(*pThis->a_PtrTnNm)); \
764 if (RT_SUCCESS(rc) && RTASN1CORE_IS_PRESENT(&pSrc->a_PtrTnNm->a_CtxTagN.Asn1Core)) \
765 { \
766 RT_CONCAT3(RTAsn1ContextTag,a_uTag,_Clone)(&pThis->a_PtrTnNm->a_CtxTagN, &pSrc->a_PtrTnNm->a_CtxTagN); \
767 rc = RT_CONCAT(a_Api,_Clone)(&pThis->a_PtrTnNm->a_Name, &pSrc->a_PtrTnNm->a_Name, pAllocator); \
768 } \
769 break
770#define RTASN1TMPL_END_PCHOICE() \
771 } \
772 if (RT_FAILURE(rc)) \
773 RT_CONCAT(RTASN1TMPL_EXT_NAME,_Delete)(pThis); \
774 RTASN1TMPL_END_COMMON()
775
776
777# define RTASN1TMPL_SET_SEQ_OF_COMMON(a_ItemType, a_ItemApi, a_OfApi, a_OfMember) \
778 RTASN1TMPL_BEGIN_COMMON(); \
779 int rc = RT_CONCAT(a_OfApi,_Clone)(&pThis->a_OfMember, &RT_CONCAT3(g_,RTASN1TMPL_INT_NAME,_Vtable), &pSrc->a_OfMember); \
780 if (RT_SUCCESS(rc)) \
781 { \
782 RTAsn1MemInitArrayAllocation(&pThis->Allocation, pAllocator, sizeof(a_ItemType)); \
783 uint32_t const cItems = pSrc->cItems; \
784 if (cItems > 0) \
785 { \
786 rc = RTAsn1MemResizeArray(&pThis->Allocation, (void ***)&pThis->papItems, 0, cItems); \
787 if (RT_SUCCESS(rc)) \
788 { \
789 uint32_t i = 0; \
790 while (i < cItems) \
791 { \
792 rc = RT_CONCAT(a_ItemApi,_Clone)(pThis->papItems[i], pSrc->papItems[i], pAllocator); \
793 if (RT_SUCCESS(rc)) \
794 pThis->cItems = ++i; \
795 else \
796 { \
797 pThis->cItems = i; \
798 RT_CONCAT(RTASN1TMPL_EXT_NAME,_Delete)(pThis); \
799 return rc; \
800 } \
801 } \
802 } \
803 else \
804 RT_ZERO(*pThis); \
805 } \
806 } \
807 RTASN1TMPL_END_COMMON()
808# define RTASN1TMPL_SEQ_OF(a_ItemType, a_ItemApi) RTASN1TMPL_SET_SEQ_OF_COMMON(a_ItemType, a_ItemApi, RTAsn1SeqOfCore, SeqCore)
809# define RTASN1TMPL_SET_OF(a_ItemType, a_ItemApi) RTASN1TMPL_SET_SEQ_OF_COMMON(a_ItemType, a_ItemApi, RTAsn1SetOfCore, SetCore)
810
811# define RTASN1TMPL_EXEC_CLONE(a_Expr) if (RT_SUCCESS(rc)) { a_Expr; }
812
813
814
815#elif RTASN1TMPL_PASS == RTASN1TMPL_PASS_SETTERS_1
816/*
817 *
818 * Member setter helpers.
819 *
820 */
821# define RTASN1TMPL_BEGIN_SEQCORE() RTASN1TMPL_SEMICOLON_DUMMY()
822# define RTASN1TMPL_BEGIN_SETCORE() RTASN1TMPL_SEMICOLON_DUMMY()
823#if 1 /** @todo later */
824# define RTASN1TMPL_MEMBER_EX(a_Name, a_Type, a_Api, a_Constraints) RTASN1TMPL_SEMICOLON_DUMMY()
825#else
826# define RTASN1TMPL_MEMBER_EX(a_Name, a_Type, a_Api, a_Constraints) \
827 RTDECL(int) RT_CONCAT3(RTASN1TMPL_EXT_NAME,_Set,a_Name)(RTASN1TMPL_TYPE *pThis, a_Type const *pValue, \
828 PCRTASN1ALLOCATORVTABLE pAllocator) \
829 { \
830 if (RT_CONCAT(a_Api,_IsPresent)(&pThis->a_Name)) \
831 RT_CONCAT(a_Api,_Delete)(&pThis->a_Name); \
832 return RT_CONCAT(a_Api,_Clone)(&pThis->a_Name, pValue, pAllocator, true /* fResetImplicit */); \
833 } RTASN1TMPL_SEMICOLON_DUMMY()
834#endif
835
836# define RTASN1TMPL_MEMBER_DYN_BEGIN(a_enmType, a_enmMembNm, a_Allocation) RTASN1TMPL_SEMICOLON_DUMMY()
837# define RTASN1TMPL_MEMBER_DYN_END(a_enmType, a_enmMembNm, a_Allocation) RTASN1TMPL_SEMICOLON_DUMMY()
838# define RTASN1TMPL_END_SEQCORE() RTASN1TMPL_SEMICOLON_DUMMY()
839# define RTASN1TMPL_END_SETCORE() RTASN1TMPL_SEMICOLON_DUMMY()
840
841
842# define RTASN1TMPL_BEGIN_PCHOICE() RTASN1TMPL_SEMICOLON_DUMMY()
843# define RTASN1TMPL_PCHOICE_ITAG_EX(a_uTag, a_enmChoice, a_PtrName, a_Name, a_Type, a_Api, a_fClue, a_Constraints) RTASN1TMPL_SEMICOLON_DUMMY()
844# define RTASN1TMPL_PCHOICE_XTAG_EX(a_uTag, a_enmChoice, a_PtrTnNm, a_CtxTagN, a_Name, a_Type, a_Api, a_Constraints) RTASN1TMPL_SEMICOLON_DUMMY()
845# define RTASN1TMPL_END_PCHOICE() RTASN1TMPL_SEMICOLON_DUMMY()
846
847
848# define RTASN1TMPL_SEQ_OF(a_ItemType, a_ItemApi) RTASN1TMPL_SEMICOLON_DUMMY()
849# define RTASN1TMPL_SET_OF(a_ItemType, a_ItemApi) RTASN1TMPL_SEMICOLON_DUMMY()
850
851
852
853#elif RTASN1TMPL_PASS == RTASN1TMPL_PASS_SETTERS_2
854/*
855 *
856 * Member setters.
857 *
858 */
859# define RTASN1TMPL_BEGIN_SEQCORE() RTASN1TMPL_SEMICOLON_DUMMY()
860# define RTASN1TMPL_BEGIN_SETCORE() RTASN1TMPL_SEMICOLON_DUMMY()
861# define RTASN1TMPL_MEMBER_EX(a_Name, a_Type, a_Api, a_Constraints) RTASN1TMPL_SEMICOLON_DUMMY()
862# define RTASN1TMPL_MEMBER_DYN_BEGIN(a_enmType, a_enmMembNm, a_Allocation) RTASN1TMPL_SEMICOLON_DUMMY()
863# define RTASN1TMPL_MEMBER_DYN_END(a_enmType, a_enmMembNm, a_Allocation) RTASN1TMPL_SEMICOLON_DUMMY()
864# define RTASN1TMPL_END_SEQCORE() RTASN1TMPL_SEMICOLON_DUMMY()
865# define RTASN1TMPL_END_SETCORE() RTASN1TMPL_SEMICOLON_DUMMY()
866
867
868# define RTASN1TMPL_BEGIN_PCHOICE() RTASN1TMPL_SEMICOLON_DUMMY()
869
870# define RTASN1TMPL_PCHOICE_ITAG_EX(a_uTag, a_enmChoice, a_PtrName, a_Name, a_Type, a_Api, a_fClue, a_Constraints) \
871RTASN1TMPL_DECL(int) RT_CONCAT3(RTASN1TMPL_EXT_NAME,_Set,a_Name)(RT_CONCAT(P,RTASN1TMPL_TYPE) pThis, RT_CONCAT(PC,a_Type) pSrc,\
872 PCRTASN1ALLOCATORVTABLE pAllocator) \
873{ \
874 AssertPtr(pSrc); AssertPtr(pThis); \
875 RT_CONCAT(RTASN1TMPL_EXT_NAME,_Delete)(pThis); /* See _Init. */ \
876 RTAsn1Dummy_InitEx(&pThis->Dummy); \
877 pThis->Dummy.Asn1Core.pOps = &RT_CONCAT3(g_,RTASN1TMPL_INT_NAME,_Vtable); \
878 RTAsn1MemInitAllocation(&pThis->Allocation, pAllocator); \
879 pThis->enmChoice = a_enmChoice; \
880 int rc = RTAsn1MemAllocZ(&pThis->Allocation, (void **)&pThis->a_PtrName, sizeof(*pThis->a_PtrName)); \
881 if (RT_SUCCESS(rc)) \
882 { \
883 rc = RT_CONCAT(a_Api,_Clone)(pThis->a_PtrName, pSrc, pAllocator); \
884 if (RT_SUCCESS(rc)) \
885 { \
886 RTAsn1Core_ResetImplict(RT_CONCAT(a_Api,_GetAsn1Core)(pThis->a_PtrName)); \
887 rc = RTAsn1Core_SetTagAndFlags(RT_CONCAT(a_Api,_GetAsn1Core)(pThis->a_PtrName), \
888 a_uTag, RTASN1TMPL_ITAG_F_EXPAND(a_fClue)); \
889 } \
890 } \
891 return rc; \
892} RTASN1TMPL_SEMICOLON_DUMMY()
893
894# define RTASN1TMPL_PCHOICE_XTAG_EX(a_uTag, a_enmChoice, a_PtrTnNm, a_CtxTagN, a_Name, a_Type, a_Api, a_Constraints) \
895RTASN1TMPL_DECL(int) RT_CONCAT3(RTASN1TMPL_EXT_NAME,_Set,a_Name)(RT_CONCAT(P,RTASN1TMPL_TYPE) pThis, RT_CONCAT(PC,a_Type) pSrc,\
896 PCRTASN1ALLOCATORVTABLE pAllocator) \
897{ \
898 AssertPtr(pThis); AssertPtr(pSrc); Assert(RT_CONCAT(a_Api,_IsPresent)(pSrc)); \
899 RT_CONCAT(RTASN1TMPL_EXT_NAME,_Delete)(pThis); /* See _Init. */ \
900 RTAsn1Dummy_InitEx(&pThis->Dummy); \
901 pThis->Dummy.Asn1Core.pOps = &RT_CONCAT3(g_,RTASN1TMPL_INT_NAME,_Vtable); \
902 RTAsn1MemInitAllocation(&pThis->Allocation, pAllocator); \
903 pThis->enmChoice = a_enmChoice; \
904 int rc = RTAsn1MemAllocZ(&pThis->Allocation, (void **)&pThis->a_PtrTnNm, sizeof(*pThis->a_PtrTnNm)); \
905 if (RT_SUCCESS(rc)) \
906 { \
907 rc = RT_CONCAT3(RTAsn1ContextTag,a_uTag,_Init)(&pThis->a_PtrTnNm->a_CtxTagN, \
908 &RT_CONCAT5(g_,RTASN1TMPL_INT_NAME,_PCHOICE_XTAG_,a_Name,_Vtable), \
909 pAllocator); \
910 if (RT_SUCCESS(rc)) \
911 { \
912 rc = RT_CONCAT(a_Api,_Clone)(&pThis->a_PtrTnNm->a_Name, pSrc, pAllocator); \
913 if (RT_SUCCESS(rc)) \
914 RTAsn1Core_ResetImplict(RT_CONCAT(a_Api,_GetAsn1Core)(&pThis->a_PtrTnNm->a_Name)); \
915 } \
916 } \
917 return rc; \
918} RTASN1TMPL_SEMICOLON_DUMMY()
919
920# define RTASN1TMPL_END_PCHOICE() RTASN1TMPL_SEMICOLON_DUMMY()
921
922
923# define RTASN1TMPL_SEQ_OF(a_ItemType, a_ItemApi) RTASN1TMPL_SEMICOLON_DUMMY()
924# define RTASN1TMPL_SET_OF(a_ItemType, a_ItemApi) RTASN1TMPL_SEMICOLON_DUMMY()
925
926
927#elif RTASN1TMPL_PASS == RTASN1TMPL_PASS_ARRAY
928/*
929 *
930 * Array operations.
931 *
932 */
933# define RTASN1TMPL_BEGIN_SEQCORE() RTASN1TMPL_SEMICOLON_DUMMY()
934# define RTASN1TMPL_BEGIN_SETCORE() RTASN1TMPL_SEMICOLON_DUMMY()
935# define RTASN1TMPL_MEMBER_EX(a_Name, a_Type, a_Api, a_Constraints) RTASN1TMPL_SEMICOLON_DUMMY()
936# define RTASN1TMPL_MEMBER_DYN_BEGIN(a_enmType, a_enmMembNm, a_Allocation) RTASN1TMPL_SEMICOLON_DUMMY()
937# define RTASN1TMPL_MEMBER_DYN_END(a_enmType, a_enmMembNm, a_Allocation) RTASN1TMPL_SEMICOLON_DUMMY()
938# define RTASN1TMPL_END_SEQCORE() RTASN1TMPL_SEMICOLON_DUMMY()
939# define RTASN1TMPL_END_SETCORE() RTASN1TMPL_SEMICOLON_DUMMY()
940# define RTASN1TMPL_BEGIN_PCHOICE() RTASN1TMPL_SEMICOLON_DUMMY()
941# define RTASN1TMPL_PCHOICE_ITAG_EX(a_uTag, a_enmChoice, a_PtrName, a_Name, a_Type, a_Api, a_fClue, a_Constraints) \
942 RTASN1TMPL_SEMICOLON_DUMMY()
943# define RTASN1TMPL_PCHOICE_XTAG_EX(a_uTag, a_enmChoice, a_PtrTnNm, a_CtxTagN, a_Name, a_Type, a_Api, a_Constraints) \
944 RTASN1TMPL_SEMICOLON_DUMMY()
945# define RTASN1TMPL_END_PCHOICE() RTASN1TMPL_SEMICOLON_DUMMY()
946
947# define RTASN1TMPL_SET_SEQ_OF_COMMON(a_ItemType, a_ItemApi) \
948 RTASN1TMPL_DECL(int) RT_CONCAT(RTASN1TMPL_EXT_NAME,_Erase)(RT_CONCAT(P,RTASN1TMPL_TYPE) pThis, uint32_t iPosition) \
949 { \
950 /* Check and adjust iPosition. */ \
951 uint32_t const cItems = pThis->cItems; \
952 if (iPosition < cItems) \
953 { /* likely */ } \
954 else \
955 { \
956 AssertReturn(iPosition == UINT32_MAX, VERR_OUT_OF_RANGE); \
957 AssertReturn(cItems > 0, VERR_OUT_OF_RANGE); \
958 iPosition = cItems - 1; \
959 } \
960 \
961 /* Delete the entry instance. */ \
962 RT_CONCAT(P, a_ItemType) pErased = pThis->papItems[iPosition]; \
963 if (RT_CONCAT(a_ItemApi,_IsPresent)(pErased)) \
964 RT_CONCAT(a_ItemApi,_Delete)(pErased); \
965 \
966 /* If not the final entry, shift the other entries up and place the erased on at the end. */ \
967 if (iPosition < cItems - 1) \
968 { \
969 memmove(&pThis->papItems[iPosition], &pThis->papItems[iPosition + 1], (cItems - iPosition - 1) * sizeof(void *)); \
970 pThis->papItems[cItems - 1] = pErased; \
971 } \
972 /* Commit the new array size. */ \
973 pThis->cItems = cItems - 1; \
974 \
975 /* Call the allocator to resize the array (ignore return). */ \
976 RTAsn1MemResizeArray(&pThis->Allocation, (void ***)&pThis->papItems, cItems - 1, cItems); \
977 return VINF_SUCCESS; \
978 } \
979 \
980 RTASN1TMPL_DECL(int) RT_CONCAT(RTASN1TMPL_EXT_NAME,_InsertEx)(RT_CONCAT(P,RTASN1TMPL_TYPE) pThis, uint32_t iPosition, \
981 RT_CONCAT(PC, a_ItemType) pToClone, \
982 PCRTASN1ALLOCATORVTABLE pAllocator, uint32_t *piActualPos) \
983 { \
984 /* Check and adjust iPosition. */ \
985 uint32_t const cItems = pThis->cItems; \
986 if (iPosition <= cItems) \
987 { /* likely */ } \
988 else \
989 { \
990 AssertReturn(iPosition == UINT32_MAX, VERR_OUT_OF_RANGE); \
991 iPosition = cItems; \
992 } \
993 \
994 /* Ensure we've got space in the array. */ \
995 int rc = RTAsn1MemResizeArray(&pThis->Allocation, (void ***)&pThis->papItems, cItems, cItems + 1); \
996 if (RT_SUCCESS(rc)) \
997 { \
998 /* Initialize the new entry (which is currently at the end of the array) either with defaults or as a clone. */ \
999 RT_CONCAT(P,a_ItemType) pInserted = pThis->papItems[cItems]; \
1000 if (RT_CONCAT(a_ItemApi,_IsPresent)(pToClone)) \
1001 rc = RT_CONCAT(a_ItemApi,_Clone)(pInserted, pToClone, pAllocator); \
1002 else \
1003 rc = RT_CONCAT(a_ItemApi,_Init)(pInserted, pAllocator); \
1004 if (RT_SUCCESS(rc)) \
1005 { \
1006 pThis->cItems = cItems + 1; \
1007 \
1008 /* If not inserting at the end of the array, shift existing items out of the way and insert the new as req. */ \
1009 if (iPosition != cItems) \
1010 { \
1011 memmove(&pThis->papItems[iPosition + 1], &pThis->papItems[iPosition], (cItems - iPosition) * sizeof(void *)); \
1012 pThis->papItems[iPosition] = pInserted; \
1013 } \
1014 \
1015 /* Done! */ \
1016 if (piActualPos) \
1017 *piActualPos = iPosition; \
1018 return VINF_SUCCESS; \
1019 } \
1020 RTAsn1MemResizeArray(&pThis->Allocation, (void ***)&pThis->papItems, cItems + 1, cItems); \
1021 } \
1022 return rc; \
1023 } RTASN1TMPL_SEMICOLON_DUMMY()
1024
1025# define RTASN1TMPL_SEQ_OF(a_ItemType, a_ItemApi) RTASN1TMPL_SET_SEQ_OF_COMMON(a_ItemType, a_ItemApi)
1026# define RTASN1TMPL_SET_OF(a_ItemType, a_ItemApi) RTASN1TMPL_SET_SEQ_OF_COMMON(a_ItemType, a_ItemApi)
1027
1028
1029#elif RTASN1TMPL_PASS == RTASN1TMPL_PASS_COMPARE
1030/*
1031 *
1032 * Compare two instances of the type.
1033 *
1034 */
1035# define RTASN1TMPL_BEGIN_COMMON() \
1036RTASN1TMPL_DECL(int) RT_CONCAT(RTASN1TMPL_EXT_NAME,_Compare)(RT_CONCAT(PC,RTASN1TMPL_TYPE) pLeft, \
1037 RT_CONCAT(PC,RTASN1TMPL_TYPE) pRight) \
1038{ \
1039 if (!RT_CONCAT(RTASN1TMPL_EXT_NAME,_IsPresent)(pLeft)) \
1040 return 0 - (int)RT_CONCAT(RTASN1TMPL_EXT_NAME,_IsPresent)(pRight); \
1041 if (!RT_CONCAT(RTASN1TMPL_EXT_NAME,_IsPresent)(pRight)) \
1042 return -1; \
1043 int iDiff = 0
1044
1045# define RTASN1TMPL_END_COMMON() \
1046 return iDiff; \
1047} RTASN1TMPL_SEMICOLON_DUMMY()
1048
1049# define RTASN1TMPL_BEGIN_SEQCORE() RTASN1TMPL_BEGIN_COMMON()
1050# define RTASN1TMPL_BEGIN_SETCORE() RTASN1TMPL_BEGIN_COMMON()
1051# define RTASN1TMPL_MEMBER_EX(a_Name, a_Type, a_Api, a_Constraints) \
1052 if (!iDiff) \
1053 iDiff = RT_CONCAT(a_Api,_Compare)(&pLeft->a_Name, &pRight->a_Name)
1054# define RTASN1TMPL_MEMBER_DYN_BEGIN(a_enmType, a_enmMembNm, a_Allocation) \
1055 if (!iDiff && pLeft->a_enmMembNm != pRight->a_enmMembNm) \
1056 iDiff = pLeft->a_enmMembNm < pRight->a_enmMembNm ? -1 : 1; \
1057 else if (!iDiff) \
1058 switch (pLeft->a_enmMembNm) \
1059 { \
1060 default: break
1061# define RTASN1TMPL_MEMBER_DYN_COMMON(a_UnionNm, a_PtrName, a_Type, a_Api, a_Allocation, a_enmMembNm, a_enmValue, a_IfStmt) \
1062 case a_enmValue: iDiff = RT_CONCAT(a_Api,_Compare)(pLeft->a_UnionNm.a_PtrName, pRight->a_UnionNm.a_PtrName); break
1063# define RTASN1TMPL_MEMBER_DYN_END(a_enmType, a_enmMembNm, a_Allocation) \
1064 case RT_CONCAT(a_enmType,_NOT_PRESENT): break; \
1065 }
1066# define RTASN1TMPL_MEMBER_OPT_XTAG_EX(a_TnNm, a_CtxTagN, a_Name, a_Type, a_Api, a_uTag, a_Constraints) \
1067 if (!iDiff) \
1068 { \
1069 if (RTASN1CORE_IS_PRESENT(&pLeft->a_TnNm.a_CtxTagN.Asn1Core)) \
1070 { \
1071 if (RTASN1CORE_IS_PRESENT(&pRight->a_TnNm.a_CtxTagN.Asn1Core)) \
1072 iDiff = RT_CONCAT(a_Api,_Compare)(&pLeft->a_TnNm.a_Name, &pRight->a_TnNm.a_Name); \
1073 else \
1074 iDiff = -1; \
1075 } \
1076 else \
1077 iDiff = 0 - (int)RTASN1CORE_IS_PRESENT(&pRight->a_TnNm.a_CtxTagN.Asn1Core); \
1078 } do { } while (0)
1079# define RTASN1TMPL_END_SEQCORE() RTASN1TMPL_END_COMMON()
1080# define RTASN1TMPL_END_SETCORE() RTASN1TMPL_END_COMMON()
1081
1082# define RTASN1TMPL_BEGIN_PCHOICE() \
1083 RTASN1TMPL_BEGIN_COMMON(); \
1084 if (pLeft->enmChoice != pRight->enmChoice) \
1085 return pLeft->enmChoice < pRight->enmChoice ? -1 : 1; \
1086 switch (pLeft->enmChoice) \
1087 { \
1088 default: break
1089# define RTASN1TMPL_PCHOICE_ITAG_EX(a_uTag, a_enmChoice, a_PtrName, a_Name, a_Type, a_Api, a_fClue, a_Constraints) \
1090 case a_enmChoice: iDiff = RT_CONCAT(a_Api,_Compare)(pLeft->a_PtrName, pRight->a_PtrName); break
1091# define RTASN1TMPL_PCHOICE_XTAG_EX(a_uTag, a_enmChoice, a_PtrTnNm, a_CtxTagN, a_Name, a_Type, a_Api, a_Constraints) \
1092 case a_enmChoice: iDiff = RT_CONCAT(a_Api,_Compare)(&pLeft->a_PtrTnNm->a_Name, &pRight->a_PtrTnNm->a_Name); break
1093#define RTASN1TMPL_END_PCHOICE() \
1094 } \
1095 RTASN1TMPL_END_COMMON()
1096
1097
1098# define RTASN1TMPL_SET_SEQ_OF_COMMON(a_ItemType, a_ItemApi) \
1099 RTASN1TMPL_BEGIN_COMMON(); \
1100 uint32_t cItems = pLeft->cItems; \
1101 if (cItems == pRight->cItems) \
1102 for (uint32_t i = 0; iDiff == 0 && i < cItems; i++) \
1103 iDiff = RT_CONCAT(a_ItemApi,_Compare)(pLeft->papItems[i], pRight->papItems[i]); \
1104 else \
1105 iDiff = cItems < pRight->cItems ? -1 : 1; \
1106 RTASN1TMPL_END_COMMON()
1107# define RTASN1TMPL_SEQ_OF(a_ItemType, a_ItemApi) RTASN1TMPL_SET_SEQ_OF_COMMON(a_ItemType, a_ItemApi)
1108# define RTASN1TMPL_SET_OF(a_ItemType, a_ItemApi) RTASN1TMPL_SET_SEQ_OF_COMMON(a_ItemType, a_ItemApi)
1109
1110
1111
1112#elif RTASN1TMPL_PASS == RTASN1TMPL_PASS_CHECK_SANITY
1113/*
1114 *
1115 * Checks the sanity of the type.
1116 *
1117 */
1118# ifndef RTASN1TMPL_SANITY_CHECK_EXPR
1119# define RTASN1TMPL_SANITY_CHECK_EXPR() VINF_SUCCESS
1120# endif
1121# define RTASN1TMPL_BEGIN_COMMON() \
1122RTASN1TMPL_DECL(int) RT_CONCAT(RTASN1TMPL_EXT_NAME,_CheckSanity)(RT_CONCAT(PC,RTASN1TMPL_TYPE) pThis, uint32_t fFlags, \
1123 PRTERRINFO pErrInfo, const char *pszErrorTag) \
1124{ \
1125 if (RT_LIKELY(RT_CONCAT(RTASN1TMPL_EXT_NAME,_IsPresent)(pThis))) \
1126 { /* likely */ } \
1127 else \
1128 return RTErrInfoSetF(pErrInfo, VERR_GENERAL_FAILURE, "%s: Missing (%s).", pszErrorTag, RT_XSTR(RTASN1TMPL_TYPE)); \
1129 int rc = VINF_SUCCESS
1130
1131# define RTASN1TMPL_END_COMMON() \
1132 if (RT_SUCCESS(rc)) \
1133 rc = (RTASN1TMPL_SANITY_CHECK_EXPR()); \
1134 return rc; \
1135} RTASN1TMPL_SEMICOLON_DUMMY()
1136
1137# define RTASN1TMPL_BEGIN_SEQCORE() RTASN1TMPL_BEGIN_COMMON()
1138# define RTASN1TMPL_BEGIN_SETCORE() RTASN1TMPL_BEGIN_COMMON()
1139# define RTASN1TMPL_MEMBER_EX(a_Name, a_Type, a_Api, a_Constraints) \
1140 if (RT_SUCCESS(rc)) \
1141 { \
1142 if (RT_LIKELY(RT_CONCAT(a_Api,_IsPresent)(&pThis->a_Name))) \
1143 { \
1144 rc = RT_CONCAT(a_Api,_CheckSanity)(&pThis->a_Name, fFlags & RTASN1_CHECK_SANITY_F_COMMON_MASK, \
1145 pErrInfo, RT_XSTR(RTASN1TMPL_TYPE) "::" #a_Name); \
1146 { a_Constraints } \
1147 } \
1148 else \
1149 rc = RTErrInfoSetF(pErrInfo, VERR_GENERAL_FAILURE, "%s: Missing member %s (%s).", \
1150 pszErrorTag, #a_Name, RT_XSTR(RTASN1TMPL_TYPE)); \
1151 } do {} while (0)
1152# define RTASN1TMPL_MEMBER_DYN_BEGIN(a_enmType, a_enmMembNm, a_Allocation) \
1153 if (RT_SUCCESS(rc)) \
1154 switch (pThis->a_enmMembNm) \
1155 { \
1156 default: \
1157 rc = RTErrInfoSetF(pErrInfo, VERR_GENERAL_FAILURE, \
1158 "%s: Invalid " #a_enmMembNm " value: %d", pszErrorTag, pThis->a_enmMembNm); \
1159 break
1160# define RTASN1TMPL_MEMBER_DYN_COMMON(a_UnionNm, a_PtrName, a_Type, a_Api, a_Allocation, a_enmMembNm, a_enmValue, a_IfStmt) \
1161 case a_enmValue: \
1162 rc = RT_CONCAT(a_Api,_CheckSanity)(pThis->a_UnionNm.a_PtrName, fFlags & RTASN1_CHECK_SANITY_F_COMMON_MASK, \
1163 pErrInfo, RT_XSTR(RTASN1TMPL_TYPE) "::" #a_UnionNm "." #a_PtrName); \
1164 break
1165# define RTASN1TMPL_MEMBER_DYN_END(a_enmType, a_enmMembNm, a_Allocation) \
1166 case RT_CONCAT(a_enmType,_NOT_PRESENT): \
1167 rc = RTErrInfoSetF(pErrInfo, VERR_GENERAL_FAILURE, \
1168 "%s: Invalid " #a_enmMembNm " value: " #a_enmType "_NOT_PRESENT", pszErrorTag); \
1169 break; \
1170 }
1171# define RTASN1TMPL_MEMBER_OPT_EX(a_Name, a_Type, a_Api, a_Constraints) \
1172 if (RT_SUCCESS(rc) && RT_CONCAT(a_Api,_IsPresent)(&pThis->a_Name)) \
1173 { \
1174 rc = RT_CONCAT(a_Api,_CheckSanity)(&pThis->a_Name, fFlags & RTASN1_CHECK_SANITY_F_COMMON_MASK, \
1175 pErrInfo, RT_XSTR(RTASN1TMPL_TYPE) "::" #a_Name); \
1176 { a_Constraints } \
1177 }
1178# define RTASN1TMPL_MEMBER_OPT_XTAG_EX(a_TnNm, a_CtxTagN, a_Name, a_Type, a_Api, a_uTag, a_Constraints) \
1179 if (RT_SUCCESS(rc)) \
1180 { \
1181 bool const fOuterPresent = RTASN1CORE_IS_PRESENT(&pThis->a_TnNm.a_CtxTagN.Asn1Core); \
1182 bool const fInnerPresent = RT_CONCAT(a_Api,_IsPresent)(&pThis->a_TnNm.a_Name); \
1183 if (fOuterPresent && fInnerPresent) \
1184 { \
1185 rc = RT_CONCAT(a_Api,_CheckSanity)(&pThis->a_TnNm.a_Name, fFlags & RTASN1_CHECK_SANITY_F_COMMON_MASK, \
1186 pErrInfo, RT_XSTR(RTASN1TMPL_TYPE) "::" #a_Name); \
1187 { a_Constraints } \
1188 } \
1189 else if (RT_LIKELY(RTASN1CORE_IS_PRESENT(&pThis->a_TnNm.a_CtxTagN.Asn1Core) == fInnerPresent)) \
1190 { /* likely */ } \
1191 else \
1192 rc = RTErrInfoSetF(pErrInfo, VERR_GENERAL_FAILURE, \
1193 "%s::" #a_TnNm "." #a_Name ": Explict tag precense mixup; " #a_CtxTagN "=%d " #a_Name "=%d.", \
1194 pszErrorTag, fOuterPresent, fInnerPresent); \
1195 } do { } while (0)
1196# define RTASN1TMPL_END_SEQCORE() RTASN1TMPL_END_COMMON()
1197# define RTASN1TMPL_END_SETCORE() RTASN1TMPL_END_COMMON()
1198
1199
1200# define RTASN1TMPL_BEGIN_PCHOICE() \
1201 RTASN1TMPL_BEGIN_COMMON(); \
1202 switch (pThis->enmChoice) \
1203 { \
1204 default: \
1205 rc = RTErrInfoSetF(pErrInfo, VERR_GENERAL_FAILURE, \
1206 "%s: Invalid enmChoice value: %d", pszErrorTag, pThis->enmChoice); \
1207 break
1208# define RTASN1TMPL_PCHOICE_ITAG_EX(a_uTag, a_enmChoice, a_PtrName, a_Name, a_Type, a_Api, a_fClue, a_Constraints) \
1209 case a_enmChoice: \
1210 if (pThis->a_PtrName && RT_CONCAT(a_Api,_IsPresent)(pThis->a_PtrName)) \
1211 { \
1212 PCRTASN1CORE pCore = RT_CONCAT(a_Api,_GetAsn1Core)(pThis->a_PtrName); \
1213 if (pCore->uTag == a_uTag && pCore->fClass == RTASN1TMPL_ITAG_F_EXPAND(a_fClue)) \
1214 { \
1215 rc = RT_CONCAT(a_Api,_CheckSanity)(pThis->a_PtrName, fFlags & RTASN1_CHECK_SANITY_F_COMMON_MASK, \
1216 pErrInfo, RT_XSTR(RTASN1TMPL_TYPE) "::" #a_Name); \
1217 { a_Constraints } \
1218 } \
1219 else \
1220 rc = RTErrInfoSetF(pErrInfo, VERR_GENERAL_FAILURE, \
1221 "%s::" #a_Name ": Tag/class mismatch: expected %#x/%#x, actual %#x/%x.", \
1222 pszErrorTag, a_uTag, RTASN1TMPL_ITAG_F_EXPAND(a_fClue), pCore->uTag, pCore->fClass); \
1223 } \
1224 else \
1225 rc = RTErrInfoSetF(pErrInfo, VERR_GENERAL_FAILURE, "%s::" #a_Name ": Not present.", pszErrorTag); \
1226 break
1227# define RTASN1TMPL_PCHOICE_XTAG_EX(a_uTag, a_enmChoice, a_PtrTnNm, a_CtxTagN, a_Name, a_Type, a_Api, a_Constraints) \
1228 case a_enmChoice: \
1229 if ( pThis->a_PtrTnNm \
1230 && RTASN1CORE_IS_PRESENT(&(pThis->a_PtrTnNm->a_CtxTagN.Asn1Core)) \
1231 && RT_CONCAT(a_Api,_IsPresent)(&pThis->a_PtrTnNm->a_Name) ) \
1232 { \
1233 rc = RT_CONCAT(a_Api,_CheckSanity)(&pThis->a_PtrTnNm->a_Name, fFlags & RTASN1_CHECK_SANITY_F_COMMON_MASK, \
1234 pErrInfo, RT_XSTR(RTASN1TMPL_TYPE) "::" #a_Name); \
1235 { a_Constraints } \
1236 } \
1237 else \
1238 rc = RTErrInfoSetF(pErrInfo, VERR_GENERAL_FAILURE, "%s::" #a_Name ": Not present.", pszErrorTag); \
1239 break
1240#define RTASN1TMPL_END_PCHOICE() \
1241 } \
1242 RTASN1TMPL_END_COMMON()
1243
1244
1245# define RTASN1TMPL_SET_SEQ_OF_COMMON(a_ItemType, a_ItemApi) \
1246 RTASN1TMPL_BEGIN_COMMON(); \
1247 for (uint32_t i = 0; RT_SUCCESS(rc) && i < pThis->cItems; i++) \
1248 rc = RT_CONCAT(a_ItemApi,_CheckSanity)(pThis->papItems[i], fFlags & RTASN1_CHECK_SANITY_F_COMMON_MASK, \
1249 pErrInfo, RT_XSTR(RTASN1TMPL_TYPE) "::papItems[#]"); \
1250 if (RT_SUCCESS(rc)) { RTASN1TMPL_SET_SEQ_EXEC_CHECK_SANITY(); } \
1251 RTASN1TMPL_END_COMMON()
1252# define RTASN1TMPL_SEQ_OF(a_ItemType, a_ItemApi) RTASN1TMPL_SET_SEQ_OF_COMMON(a_ItemType, a_ItemApi)
1253# define RTASN1TMPL_SET_OF(a_ItemType, a_ItemApi) RTASN1TMPL_SET_SEQ_OF_COMMON(a_ItemType, a_ItemApi)
1254
1255/* The constraints. */
1256# define RTASN1TMPL_MEMBER_CONSTR_MIN_MAX(a_Name, a_Type, a_Api, cbMin, cbMax, a_MoreConstraints) \
1257 if (RT_SUCCESS(rc) && ((cbMin) != 0 || (cbMax) != UINT32_MAX)) \
1258 { \
1259 PCRTASN1CORE pCore = RT_CONCAT(a_Api,_GetAsn1Core)(&pThis->a_Name); \
1260 if (RT_LIKELY(pCore->cb >= (cbMin) && pCore->cb <= (cbMax))) \
1261 { /* likely */ } \
1262 else \
1263 rc = RTErrInfoSetF(pErrInfo, VERR_GENERAL_FAILURE, \
1264 "%s::" #a_Name ": Content size is out of range: %#x not in {%#x..%#x}", \
1265 pszErrorTag, pCore->cb, cbMin, cbMax); \
1266 } \
1267 { a_MoreConstraints }
1268
1269# define RTASN1TMPL_MEMBER_CONSTR_BITSTRING_MIN_MAX(a_Name, cMinBits, cMaxBits, a_MoreConstraints) \
1270 if (RT_SUCCESS(rc) && ((cMinBits) != 0 || (cMaxBits) != UINT32_MAX)) \
1271 { \
1272 if (RT_LIKELY( ((cMinBits) == 0 ? true : pThis->a_Name.cBits + 1U >= (cMinBits) + 1U /* warning avoiding */) \
1273 && ((cMaxBits) == UINT32_MAX ? true : pThis->a_Name.cBits + 1U <= (cMaxBits) + 1U /* ditto */) ) ) \
1274 { /* likely */ } \
1275 else \
1276 rc = RTErrInfoSetF(pErrInfo, VERR_GENERAL_FAILURE, \
1277 "%s::" #a_Name ": Bit size is out of range: %#x not in {%#x..%#x}", \
1278 pszErrorTag, pThis->a_Name.cBits, cMinBits, cMaxBits); \
1279 } \
1280 { a_MoreConstraints }
1281
1282# define RTASN1TMPL_MEMBER_CONSTR_U64_MIN_MAX(a_Name, uMin, uMax, a_MoreConstraints) \
1283 if (RT_SUCCESS(rc)) \
1284 { \
1285 if (RT_LIKELY( RTAsn1Integer_UnsignedCompareWithU64(&pThis->a_Name, uMin) >= 0 \
1286 && RTAsn1Integer_UnsignedCompareWithU64(&pThis->a_Name, uMax) <= 0) ) \
1287 { /* likely */ } \
1288 else \
1289 rc = RTErrInfoSetF(pErrInfo, VERR_GENERAL_FAILURE, \
1290 "%s::" #a_Name ": Out of range: %#x not in {%#llx..%#llx}", \
1291 pszErrorTag, pThis->a_Name.Asn1Core.cb > 8 ? UINT64_MAX : pThis->a_Name.uValue.u, \
1292 (uint64_t)(uMin), (uint64_t)(uMax)); \
1293 } \
1294 { a_MoreConstraints }
1295
1296# define RTASN1TMPL_MEMBER_CONSTR_PRESENT(a_Name, a_Api, a_MoreConstraints) \
1297 if (RT_SUCCESS(rc)) \
1298 { \
1299 if (RT_LIKELY(RT_CONCAT(a_Api,_IsPresent)(&pThis->a_Name))) \
1300 { /* likely */ } \
1301 else \
1302 rc = RTErrInfoSetF(pErrInfo, VERR_GENERAL_FAILURE, "%s::" #a_Name ": Missing.", pszErrorTag); \
1303 } \
1304 { a_MoreConstraints }
1305
1306
1307
1308# define RTASN1TMPL_EXEC_CHECK_SANITY(a_Expr) if (RT_SUCCESS(rc)) { a_Expr; }
1309
1310
1311#elif RTASN1TMPL_PASS == RTASN1TMPL_PASS_DELETE
1312/*
1313 *
1314 * Delete wrappers.
1315 *
1316 */
1317# define RTASN1TMPL_BEGIN_COMMON() \
1318RTASN1TMPL_DECL(void) RT_CONCAT(RTASN1TMPL_EXT_NAME,_Delete)(RT_CONCAT(P,RTASN1TMPL_TYPE) pThis) \
1319{ \
1320 if (RT_CONCAT(RTASN1TMPL_EXT_NAME,_IsPresent)(pThis)) \
1321 { do { } while (0)
1322
1323# define RTASN1TMPL_END_COMMON() \
1324 } \
1325 RT_ZERO(*pThis); \
1326} RTASN1TMPL_SEMICOLON_DUMMY()
1327
1328# define RTASN1TMPL_BEGIN_SEQCORE() RTASN1TMPL_BEGIN_COMMON()
1329# define RTASN1TMPL_BEGIN_SETCORE() RTASN1TMPL_BEGIN_COMMON()
1330# define RTASN1TMPL_MEMBER_EX(a_Name, a_Type, a_Api, a_Constraints) RT_CONCAT(a_Api,_Delete)(&pThis->a_Name)
1331# define RTASN1TMPL_MEMBER_DYN_BEGIN(a_enmType, a_enmMembNm, a_Allocation) \
1332 switch (pThis->a_enmMembNm) \
1333 { \
1334 default: break
1335# define RTASN1TMPL_MEMBER_DYN_COMMON(a_UnionNm, a_PtrName, a_Type, a_Api, a_Allocation, a_enmMembNm, a_enmValue, a_IfStmt) \
1336 case a_enmValue: \
1337 if (pThis->a_UnionNm.a_PtrName) \
1338 { \
1339 RT_CONCAT(a_Api,_Delete)(pThis->a_UnionNm.a_PtrName); \
1340 RTAsn1MemFree(&pThis->Allocation, pThis->a_UnionNm.a_PtrName); \
1341 pThis->a_UnionNm.a_PtrName = NULL; \
1342 } \
1343 break
1344# define RTASN1TMPL_MEMBER_DYN_END(a_enmType, a_enmMembNm, a_Allocation) \
1345 }
1346# define RTASN1TMPL_END_SEQCORE() RTASN1TMPL_END_COMMON()
1347# define RTASN1TMPL_END_SETCORE() RTASN1TMPL_END_COMMON()
1348
1349
1350# define RTASN1TMPL_BEGIN_PCHOICE() \
1351 RTASN1TMPL_BEGIN_COMMON(); \
1352 switch (pThis->enmChoice) \
1353 { \
1354 default: break
1355# define RTASN1TMPL_PCHOICE_ITAG_EX(a_uTag, a_enmChoice, a_PtrName, a_Name, a_Type, a_Api, a_fClue, a_Constraints) \
1356 case a_enmChoice: \
1357 if (pThis->a_PtrName) \
1358 { \
1359 RT_CONCAT(a_Api,_Delete)(pThis->a_PtrName); \
1360 RTAsn1MemFree(&pThis->Allocation, pThis->a_PtrName); \
1361 pThis->a_PtrName = NULL; \
1362 } \
1363 break
1364# define RTASN1TMPL_PCHOICE_XTAG_EX(a_uTag, a_enmChoice, a_PtrTnNm, a_CtxTagN, a_Name, a_Type, a_Api, a_Constraints) \
1365 case a_enmChoice: \
1366 if (pThis->a_PtrTnNm) \
1367 { \
1368 RT_CONCAT(a_Api,_Delete)(&pThis->a_PtrTnNm->a_Name); \
1369 RTAsn1MemFree(&pThis->Allocation, pThis->a_PtrTnNm); \
1370 pThis->a_PtrTnNm = NULL; \
1371 } \
1372 break
1373# define RTASN1TMPL_END_PCHOICE() \
1374 } \
1375 RTASN1TMPL_END_COMMON()
1376
1377
1378# define RTASN1TMPL_SET_SEQ_OF_COMMON(a_ItemType, a_ItemApi) \
1379 RTASN1TMPL_BEGIN_COMMON(); \
1380 uint32_t i = pThis->cItems; \
1381 while (i-- > 0) \
1382 RT_CONCAT(a_ItemApi,_Delete)(pThis->papItems[i]); \
1383 RTAsn1MemFreeArray(&pThis->Allocation, (void **)pThis->papItems); \
1384 pThis->papItems = NULL; \
1385 pThis->cItems = 0; \
1386 RTASN1TMPL_END_COMMON()
1387# define RTASN1TMPL_SEQ_OF(a_ItemType, a_ItemApi) RTASN1TMPL_SET_SEQ_OF_COMMON(a_ItemType, a_ItemApi)
1388# define RTASN1TMPL_SET_OF(a_ItemType, a_ItemApi) RTASN1TMPL_SET_SEQ_OF_COMMON(a_ItemType, a_ItemApi)
1389
1390
1391#else
1392# error "Invalid/missing RTASN1TMPL_PASS value."
1393#endif
1394
1395
1396
1397/*
1398 * Default aliases for simplified versions of macros if no specialization
1399 * was required above.
1400 */
1401/* Non-optional members. */
1402#ifndef RTASN1TMPL_MEMBER
1403# define RTASN1TMPL_MEMBER(a_Name, a_Type, a_Api) \
1404 RTASN1TMPL_MEMBER_EX(a_Name, a_Type, a_Api, RT_NOTHING)
1405#endif
1406
1407#ifndef RTASN1TMPL_MEMBER_UTF8_STRING_MIN_MAX
1408# define RTASN1TMPL_MEMBER_UTF8_STRING_MIN_MAX(a_Name) \
1409 RTASN1TMPL_MEMBER(a_Name, RTASN1STRING, RTAsn1String)
1410#endif
1411#ifndef RTASN1TMPL_MEMBER_UTF8_STRING
1412# define RTASN1TMPL_MEMBER_UTF8_STRING(a_Name) \
1413 RTASN1TMPL_MEMBER_UTF8_STRING_MIN_MAX(a_Name, 0, UINT32_MAX)
1414#endif
1415
1416#ifndef RTASN1TMPL_MEMBER_STRING_MIN_MAX
1417# define RTASN1TMPL_MEMBER_STRING_MIN_MAX(a_Name, a_cbMin, a_cbMax) \
1418 RTASN1TMPL_MEMBER(a_Name, RTASN1STRING, RTAsn1String)
1419#endif
1420#ifndef RTASN1TMPL_MEMBER_STRING
1421# define RTASN1TMPL_MEMBER_STRING(a_Name) \
1422 RTASN1TMPL_MEMBER_STRING_MIN_MAX(a_Name, 0, UINT32_MAX)
1423#endif
1424#ifndef RTASN1TMPL_MEMBER_XTAG_EX
1425# define RTASN1TMPL_MEMBER_XTAG_EX(a_TnNm, a_CtxTagN, a_Name, a_Type, a_Api, a_uTag, a_Constraints) \
1426 RTASN1TMPL_MEMBER_EX(a_TnNm.a_Name, a_Type, a_Api, a_Constraints RT_NOTHING)
1427#endif
1428
1429/* Any/dynamic members. */
1430#ifndef RTASN1TMPL_MEMBER_DYN_BEGIN
1431# define RTASN1TMPL_MEMBER_DYN_BEGIN(a_enmType, a_enmMembNm, a_Allocation) do { } while (0)
1432#endif
1433#ifndef RTASN1TMPL_MEMBER_DYN_END
1434# define RTASN1TMPL_MEMBER_DYN_END(a_enmType, a_enmMembNm, a_Allocation) do { } while (0)
1435#endif
1436#ifndef RTASN1TMPL_MEMBER_DYN_COMMON
1437# define RTASN1TMPL_MEMBER_DYN_COMMON(a_UnionNm, a_PtrName, a_Type, a_Api, a_Allocation, a_enmMembNm, a_enmValue, a_IfStmt) \
1438 RTASN1TMPL_MEMBER(a_UnionNm.a_PtrName, a_Type, a_Api)
1439#endif
1440#ifndef RTASN1TMPL_MEMBER_DYN
1441# define RTASN1TMPL_MEMBER_DYN(a_UnionNm, a_PtrName, a_Type, a_Api, a_Allocation, a_enmMembNm, a_enmValue, a_WhenExpr) \
1442 RTASN1TMPL_MEMBER_DYN_COMMON(a_UnionNm, a_PtrName, a_Type, a_Api, a_Allocation, a_enmMembNm, a_enmValue, if (a_WhenExpr))
1443#endif
1444#ifndef RTASN1TMPL_MEMBER_DYN_DEFAULT
1445# define RTASN1TMPL_MEMBER_DYN_DEFAULT(a_UnionNm, a_PtrName, a_Type, a_Api, a_Allocation, a_enmMembNm, a_enmValue) \
1446 RTASN1TMPL_MEMBER_DYN_COMMON(a_UnionNm, a_PtrName, a_Type, a_Api, a_Allocation, a_enmMembNm, a_enmValue, RT_NOTHING)
1447#endif
1448
1449/* Optional members. */
1450#ifndef RTASN1TMPL_MEMBER_OPT_EX
1451# define RTASN1TMPL_MEMBER_OPT_EX(a_Name, a_Type, a_Api, a_Constraints) \
1452 RTASN1TMPL_MEMBER_EX(a_Name, a_Type, a_Api, a_Constraints RT_NOTHING)
1453#endif
1454#ifndef RTASN1TMPL_MEMBER_OPT
1455# define RTASN1TMPL_MEMBER_OPT(a_Name, a_Type, a_Api) \
1456 RTASN1TMPL_MEMBER_OPT_EX(a_Name, a_Type, a_Api, RT_NOTHING)
1457#endif
1458
1459#ifndef RTASN1TMPL_MEMBER_OPT_XTAG_EX
1460# define RTASN1TMPL_MEMBER_OPT_XTAG_EX(a_TnNm, a_CtxTagN, a_Name, a_Type, a_Api, a_uTag, a_Constraints) \
1461 RTASN1TMPL_MEMBER_OPT_EX(a_TnNm.a_Name, a_Type, a_Api, a_Constraints RT_NOTHING)
1462#endif
1463#ifndef RTASN1TMPL_MEMBER_OPT_XTAG
1464# define RTASN1TMPL_MEMBER_OPT_XTAG(a_TnNm, a_CtxTagN, a_Name, a_Type, a_Api, a_uTag) \
1465 RTASN1TMPL_MEMBER_OPT_XTAG_EX(a_TnNm, a_CtxTagN, a_Name, a_Type, a_Api, a_uTag, RT_NOTHING)
1466#endif
1467
1468#ifndef RTASN1TMPL_MEMBER_OPT_ITAG_EX
1469# define RTASN1TMPL_MEMBER_OPT_ITAG_EX(a_Name, a_Type, a_Api, a_uTag, a_fClue, a_Constraints) \
1470 RTASN1TMPL_MEMBER_OPT_EX(a_Name, a_Type, a_Api, a_Constraints RT_NOTHING)
1471#endif
1472#ifndef RTASN1TMPL_MEMBER_OPT_ITAG_UP
1473# define RTASN1TMPL_MEMBER_OPT_ITAG_UP(a_Name, a_Type, a_Api, a_uTag) \
1474 RTASN1TMPL_MEMBER_OPT_ITAG_EX(a_Name, a_Type, a_Api, a_uTag, RTASN1TMPL_ITAG_F_UP, RT_NOTHING)
1475#endif
1476#ifndef RTASN1TMPL_MEMBER_OPT_ITAG_UC
1477# define RTASN1TMPL_MEMBER_OPT_ITAG_UC(a_Name, a_Type, a_Api, a_uTag) \
1478 RTASN1TMPL_MEMBER_OPT_ITAG_EX(a_Name, a_Type, a_Api, a_uTag, RTASN1TMPL_ITAG_F_UC, RT_NOTHING)
1479#endif
1480#ifndef RTASN1TMPL_MEMBER_OPT_ITAG_CP
1481# define RTASN1TMPL_MEMBER_OPT_ITAG_CP(a_Name, a_Type, a_Api, a_uTag) \
1482 RTASN1TMPL_MEMBER_OPT_ITAG_EX(a_Name, a_Type, a_Api, a_uTag, RTASN1TMPL_ITAG_F_CP, RT_NOTHING)
1483#endif
1484#ifndef RTASN1TMPL_MEMBER_OPT_ITAG
1485# define RTASN1TMPL_MEMBER_OPT_ITAG(a_Name, a_Type, a_Api, a_uTag) \
1486 RTASN1TMPL_MEMBER_OPT_ITAG_EX(a_Name, a_Type, a_Api, a_uTag, RTASN1TMPL_ITAG_F_CC, RT_NOTHING)
1487#endif
1488#ifndef RTASN1TMPL_MEMBER_OPT_ANY
1489# define RTASN1TMPL_MEMBER_OPT_ANY(a_Name, a_Type, a_Api) \
1490 RTASN1TMPL_MEMBER_OPT_EX(a_Name, a_Type, a_Api, RT_NOTHING)
1491#endif
1492
1493#ifndef RTASN1TMPL_MEMBER_DEF_ITAG_EX
1494# define RTASN1TMPL_MEMBER_DEF_ITAG_EX(a_Name, a_Type, a_Api, a_uTag, a_fClue, a_DefVal, a_Constraints) \
1495 RTASN1TMPL_MEMBER_OPT_ITAG_EX(a_Name, a_Type, a_Api, a_uTag, a_fClue, a_Constraints RT_NOTHING)
1496#endif
1497#ifndef RTASN1TMPL_MEMBER_DEF_ITAG_UP
1498# define RTASN1TMPL_MEMBER_DEF_ITAG_UP(a_Name, a_Type, a_Api, a_uTag, a_DefVal) \
1499 RTASN1TMPL_MEMBER_DEF_ITAG_EX(a_Name, a_Type, a_Api, a_uTag, RTASN1TMPL_ITAG_F_UP, a_DefVal, RT_NOTHING)
1500#endif
1501
1502#ifndef RTASN1TMPL_MEMBER_OPT_ITAG_BITSTRING
1503# define RTASN1TMPL_MEMBER_OPT_ITAG_BITSTRING(a_Name, a_cMaxBits, a_uTag) \
1504 RTASN1TMPL_MEMBER_OPT_ITAG_EX(a_Name, RTASN1BITSTRING, RTAsn1BitString, a_uTag, RTASN1TMPL_ITAG_F_CP, \
1505 RTASN1TMPL_MEMBER_CONSTR_BITSTRING_MIN_MAX(a_Name, 0, a_cMaxBits, RT_NOTHING))
1506#endif
1507
1508#ifndef RTASN1TMPL_MEMBER_OPT_UTF8_STRING_EX
1509# define RTASN1TMPL_MEMBER_OPT_UTF8_STRING_EX(a_Name, a_Constraints) \
1510 RTASN1TMPL_MEMBER_OPT_EX(a_Name, RTASN1STRING, RTAsn1String, a_Constraints RT_NOTHING)
1511#endif
1512#ifndef RTASN1TMPL_MEMBER_OPT_UTF8_STRING
1513# define RTASN1TMPL_MEMBER_OPT_UTF8_STRING(a_Name) \
1514 RTASN1TMPL_MEMBER_OPT_UTF8_STRING_EX(a_Name, RT_NOTHING)
1515#endif
1516
1517#ifndef RTASN1TMPL_MEMBER_OPT_STRING_EX
1518# define RTASN1TMPL_MEMBER_OPT_STRING_EX(a_Name, a_Constraints) \
1519 RTASN1TMPL_MEMBER_OPT_EX(a_Name, RTASN1STRING, RTAsn1String, a_Constraints RT_NOTHING)
1520#endif
1521#ifndef RTASN1TMPL_MEMBER_OPT_STRING
1522# define RTASN1TMPL_MEMBER_OPT_STRING(a_Name) \
1523 RTASN1TMPL_MEMBER_OPT_STRING_EX(a_Name, RT_NOTHING)
1524#endif
1525
1526/* Pointer choices. */
1527#ifndef RTASN1TMPL_PCHOICE_ITAG_UP
1528# define RTASN1TMPL_PCHOICE_ITAG_UP(a_uTag, a_enmChoice, a_PtrName, a_Name, a_Type, a_Api) \
1529 RTASN1TMPL_PCHOICE_ITAG_EX(a_uTag, a_enmChoice, a_PtrName, a_Name, a_Type, a_Api, RTASN1TMPL_ITAG_F_UP, RT_NOTHING)
1530#endif
1531#ifndef RTASN1TMPL_PCHOICE_ITAG_UC
1532# define RTASN1TMPL_PCHOICE_ITAG_UC(a_uTag, a_enmChoice, a_PtrName, a_Name, a_Type, a_Api) \
1533 RTASN1TMPL_PCHOICE_ITAG_EX(a_uTag, a_enmChoice, a_PtrName, a_Name, a_Type, a_Api, RTASN1TMPL_ITAG_F_UC, RT_NOTHING)
1534#endif
1535#ifndef RTASN1TMPL_PCHOICE_ITAG_CP
1536# define RTASN1TMPL_PCHOICE_ITAG_CP(a_uTag, a_enmChoice, a_PtrName, a_Name, a_Type, a_Api) \
1537 RTASN1TMPL_PCHOICE_ITAG_EX(a_uTag, a_enmChoice, a_PtrName, a_Name, a_Type, a_Api, RTASN1TMPL_ITAG_F_CP, RT_NOTHING)
1538#endif
1539#ifndef RTASN1TMPL_PCHOICE_ITAG
1540# define RTASN1TMPL_PCHOICE_ITAG(a_uTag, a_enmChoice, a_PtrName, a_Name, a_Type, a_Api) \
1541 RTASN1TMPL_PCHOICE_ITAG_EX(a_uTag, a_enmChoice, a_PtrName, a_Name, a_Type, a_Api, RTASN1TMPL_ITAG_F_CC, RT_NOTHING)
1542#endif
1543
1544#ifndef RTASN1TMPL_PCHOICE_XTAG
1545# define RTASN1TMPL_PCHOICE_XTAG(a_uTag, a_enmChoice, a_PtrTnNm, a_CtxTagN, a_Name, a_Type, a_Api) \
1546 RTASN1TMPL_PCHOICE_XTAG_EX(a_uTag, a_enmChoice, a_PtrTnNm, a_CtxTagN, a_Name, a_Type, a_Api, RT_NOTHING)
1547#endif
1548
1549
1550/*
1551 * Constraints are only used in the sanity check pass, so provide subs for the
1552 * others passes.
1553 */
1554#ifndef RTASN1TMPL_MEMBER_CONSTR_MIN_MAX
1555# define RTASN1TMPL_MEMBER_CONSTR_MIN_MAX(a_Name, a_Type, a_Api, cbMin, cbMax, a_MoreConstraints)
1556#endif
1557#ifndef RTASN1TMPL_MEMBER_CONSTR_BITSTRING_MIN_MAX
1558# define RTASN1TMPL_MEMBER_CONSTR_BITSTRING_MIN_MAX(a_Name, cMinBits, cMaxBits, a_MoreConstraints)
1559#endif
1560#ifndef RTASN1TMPL_MEMBER_CONSTR_U64_MIN_MAX
1561# define RTASN1TMPL_MEMBER_CONSTR_U64_MIN_MAX(a_Name, uMin, uMax, a_MoreConstraints)
1562#endif
1563#ifndef RTASN1TMPL_MEMBER_CONSTR_PRESENT
1564# define RTASN1TMPL_MEMBER_CONSTR_PRESENT(a_Name, a_Api, a_MoreConstraints)
1565#endif
1566
1567
1568/*
1569 * Stub exec hacks.
1570 */
1571#ifndef RTASN1TMPL_EXEC_DECODE
1572# define RTASN1TMPL_EXEC_DECODE(a_Expr) /* no semi colon allowed after this */
1573#endif
1574#ifndef RTASN1TMPL_EXEC_CLONE
1575# define RTASN1TMPL_EXEC_CLONE(a_Expr) /* no semi colon allowed after this */
1576#endif
1577#ifndef RTASN1TMPL_EXEC_CHECK_SANITY
1578# define RTASN1TMPL_EXEC_CHECK_SANITY(a_Expr) /* no semi colon allowed after this */
1579#endif
1580
1581#define RTASN1TMPL_SET_SEQ_EXEC_CHECK_SANITY() do { } while (0)
1582
1583
1584/*
1585 * Generate the requested code.
1586 */
1587#ifndef RTASN1TMPL_TEMPLATE_FILE
1588# error "No template file (RTASN1TMPL_TEMPLATE_FILE) is specified."
1589#endif
1590#include RTASN1TMPL_TEMPLATE_FILE
1591
1592
1593
1594/*
1595 * Undo all the macros.
1596 */
1597#undef RTASN1TMPL_DECL
1598#undef RTASN1TMPL_TYPE
1599#undef RTASN1TMPL_EXT_NAME
1600#undef RTASN1TMPL_INT_NAME
1601
1602#undef RTASN1TMPL_PASS
1603
1604#undef RTASN1TMPL_BEGIN_COMMON
1605#undef RTASN1TMPL_END_COMMON
1606#undef RTASN1TMPL_BEGIN_SEQCORE
1607#undef RTASN1TMPL_BEGIN_SETCORE
1608#undef RTASN1TMPL_MEMBER
1609#undef RTASN1TMPL_MEMBER_EX
1610#undef RTASN1TMPL_MEMBER_DYN_BEGIN
1611#undef RTASN1TMPL_MEMBER_DYN
1612#undef RTASN1TMPL_MEMBER_DYN_DEFAULT
1613#undef RTASN1TMPL_MEMBER_DYN_COMMON
1614#undef RTASN1TMPL_MEMBER_DYN_END
1615#undef RTASN1TMPL_MEMBER_OPT
1616#undef RTASN1TMPL_MEMBER_OPT_EX
1617#undef RTASN1TMPL_MEMBER_OPT_ITAG
1618#undef RTASN1TMPL_MEMBER_OPT_ITAG_EX
1619#undef RTASN1TMPL_MEMBER_OPT_ITAG_CP
1620#undef RTASN1TMPL_MEMBER_OPT_ITAG_UC
1621#undef RTASN1TMPL_MEMBER_OPT_ITAG_UP
1622#undef RTASN1TMPL_MEMBER_OPT_ITAG_BITSTRING
1623#undef RTASN1TMPL_MEMBER_OPT_UTF8_STRING
1624#undef RTASN1TMPL_MEMBER_OPT_UTF8_STRING_EX
1625#undef RTASN1TMPL_MEMBER_OPT_XTAG
1626#undef RTASN1TMPL_MEMBER_OPT_XTAG_EX
1627#undef RTASN1TMPL_MEMBER_OPT_ANY
1628#undef RTASN1TMPL_MEMBER_DEF_ITAG_UP
1629#undef RTASN1TMPL_MEMBER_DEF_ITAG_EX
1630#undef RTASN1TMPL_END_SEQCORE
1631#undef RTASN1TMPL_END_SETCORE
1632
1633#undef RTASN1TMPL_BEGIN_PCHOICE
1634#undef RTASN1TMPL_PCHOICE_ITAG
1635#undef RTASN1TMPL_PCHOICE_ITAG_UP
1636#undef RTASN1TMPL_PCHOICE_ITAG_CP
1637#undef RTASN1TMPL_PCHOICE_ITAG_EX
1638#undef RTASN1TMPL_PCHOICE_XTAG
1639#undef RTASN1TMPL_PCHOICE_XTAG_EX
1640#undef RTASN1TMPL_END_PCHOICE
1641
1642#undef RTASN1TMPL_SET_SEQ_OF_COMMON
1643#undef RTASN1TMPL_SEQ_OF
1644#undef RTASN1TMPL_SET_OF
1645
1646#undef RTASN1TMPL_VTABLE_FN_ENCODE_PREP
1647#undef RTASN1TMPL_VTABLE_FN_ENCODE_WRITE
1648
1649#undef RTASN1TMPL_MEMBER_CONSTR_MIN_MAX
1650#undef RTASN1TMPL_MEMBER_CONSTR_BITSTRING_MIN_MAX
1651#undef RTASN1TMPL_MEMBER_CONSTR_U64_MIN_MAX
1652#undef RTASN1TMPL_MEMBER_CONSTR_PRESENT
1653
1654#undef RTASN1TMPL_SANITY_CHECK_EXPR
1655
1656#undef RTASN1TMPL_EXEC_DECODE
1657#undef RTASN1TMPL_EXEC_CLONE
1658#undef RTASN1TMPL_EXEC_CHECK_SANITY
1659
1660#undef RTASN1TMPL_SET_SEQ_EXEC_CHECK_SANITY
1661
注意: 瀏覽 TracBrowser 來幫助您使用儲存庫瀏覽器

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette