asn1-generator-pass.h revision 30d5bd8604e5b514b0e4f6360c0384ab1c7851fe
/** @file
* IPRT - ASN.1 Code Generator, One Pass.
*/
/*
* Copyright (C) 2006-2014 Oracle Corporation
*
* This file is part of VirtualBox Open Source Edition (OSE), as
* available from http://www.virtualbox.org. This file is free software;
* General Public License (GPL) as published by the Free Software
* Foundation, in version 2 as it comes in the "COPYING" file of the
* VirtualBox OSE distribution. VirtualBox OSE is distributed in the
* hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
*
* The contents of this file may alternatively be used under the terms
* of the Common Development and Distribution License Version 1.0
* (CDDL) only, as it comes in the "COPYING.CDDL" file of the
* VirtualBox OSE distribution, in which case the provisions of the
* CDDL are applicable instead of those of the GPL.
*
* You may elect to license modified versions of this file under the
* terms and conditions of either the GPL or the CDDL or both.
*/
#ifndef ___iprt_asn1_generator_pass_h
#define ___iprt_asn1_generator_pass_h
/** @def RTASN1TMPL_MEMBER_OPT_ANY
* Used for optional entries without any specific type at the end of a
* structure.
*
* For example PolicyQualifierInfo's qualifier member which is defined as:
* ANY DEFINED BY policyQualifierId
*
* Defaults to RTASN1TMPL_MEMBER_EX.
*/
/** @def RTASN1TMPL_MEMBER_OPT_ITAG_EX
* Optional member with implict tag, extended version.
*
* This is what all the other RTASN1TMPL_MEMBER_OPT_ITAG* macros defere to.
*/
/** @def RTASN1TMPL_MEMBER_OPT_ITAG_CP
* Optional member of a typical primitive type with an implicit context tag.
*
* Examples of this can be found in AuthorityKeyIdentifier where the first and
* last member are primitive types (normally anyways).:
* keyIdentifier [1] OCTET STRING OPTIONAL,
* authorityCertSerialNumber [3] INTEGER OPTIONAL
*/
/** @def RTASN1TMPL_MEMBER_OPT_ITAG_UC
* Optional member of a constructed type from the universal tag class.
*/
/** @def RTASN1TMPL_MEMBER_OPT_ITAG_UP
* Optional member of a primitive type from the universal tag class.
*/
/** @name Expansion Passes (RTASN1TMPL_PASS values)
* @{ */
#define RTASN1TMPL_PASS_INTERNAL_HEADER 1
#define RTASN1TMPL_PASS_VTABLE 2
#define RTASN1TMPL_PASS_ENUM 3
#define RTASN1TMPL_PASS_DELETE 4
#define RTASN1TMPL_PASS_COMPARE 5
#define RTASN1TMPL_PASS_CHECK_SANITY 8
#define RTASN1TMPL_PASS_INIT 16
#define RTASN1TMPL_PASS_CLONE 17
#define RTASN1TMPL_PASS_SETTERS_1 18
#define RTASN1TMPL_PASS_SETTERS_2 19
#define RTASN1TMPL_PASS_DECODE 24
/** @} */
/** @name ITAG clues
* @{ */
/** @} */
/** Expands the ITAG clues into tag flag and tag class. */
#define RTASN1TMPL_ITAG_F_EXPAND(a_fClue) \
: 0 )
#define RTASN1TMPL_SEMICOLON_DUMMY() typedef unsigned RTASN1TMPLSEMICOLONDUMMY
#endif /* !___iprt_asn1_generator_pass_h */
/*
*
* Internal header file.
*
*/
# define RTASN1TMPL_BEGIN_COMMON() extern DECLHIDDEN(RTASN1COREVTABLE const) RT_CONCAT3(g_,RTASN1TMPL_INT_NAME,_Vtable)
# define RTASN1TMPL_BEGIN_SEQCORE() RTASN1TMPL_BEGIN_COMMON()
# define RTASN1TMPL_BEGIN_SETCORE() RTASN1TMPL_BEGIN_COMMON()
# define RTASN1TMPL_MEMBER_DYN_BEGIN(a_enmType, a_enmMembNm, a_Allocation) RTASN1TMPL_SEMICOLON_DUMMY()
# define RTASN1TMPL_MEMBER_DYN_END(a_enmType, a_enmMembNm, a_Allocation) RTASN1TMPL_SEMICOLON_DUMMY()
# define RTASN1TMPL_END_SEQCORE() RTASN1TMPL_SEMICOLON_DUMMY()
# define RTASN1TMPL_END_SETCORE() RTASN1TMPL_SEMICOLON_DUMMY()
# define RTASN1TMPL_BEGIN_PCHOICE() RTASN1TMPL_BEGIN_COMMON()
# define RTASN1TMPL_PCHOICE_ITAG_EX(a_uTag, a_enmChoice, a_PtrName, a_Name, a_Type, a_Api, a_fClue, a_Constraints) \
# define RTASN1TMPL_PCHOICE_XTAG_EX(a_uTag, a_enmChoice, a_PtrTnNm, a_CtxTagN, a_Name, a_Type, a_Api, a_Constraints) \
# define RTASN1TMPL_END_PCHOICE() RTASN1TMPL_SEMICOLON_DUMMY()
/*
*
* Internal header file.
*
*/
# ifndef RTASN1TMPL_VTABLE_FN_ENCODE_PREP
# define RTASN1TMPL_VTABLE_FN_ENCODE_PREP NULL
# endif
# ifndef RTASN1TMPL_VTABLE_FN_ENCODE_WRITE
# define RTASN1TMPL_VTABLE_FN_ENCODE_WRITE NULL
# endif
{ \
/* When the Asn1Core is at the start of the structure, we can reuse the _Delete and _Enum APIs here. */ \
/* .cb = */ sizeof(RTASN1TMPL_TYPE), \
/* .uDefaultTag = */ a_uDefaultTag, \
/* .fDefaultClass = */ a_fDefaultClass, \
/* .uReserved = */ 0, \
}
# define RTASN1TMPL_BEGIN_SEQCORE() \
# define RTASN1TMPL_BEGIN_SETCORE() \
# define RTASN1TMPL_MEMBER_DYN_BEGIN(a_enmType, a_enmMembNm, a_Allocation) RTASN1TMPL_SEMICOLON_DUMMY()
# define RTASN1TMPL_MEMBER_DYN_END(a_enmType, a_enmMembNm, a_Allocation) RTASN1TMPL_SEMICOLON_DUMMY()
# define RTASN1TMPL_END_SEQCORE() RTASN1TMPL_SEMICOLON_DUMMY()
# define RTASN1TMPL_END_SETCORE() RTASN1TMPL_SEMICOLON_DUMMY()
# define RTASN1TMPL_BEGIN_PCHOICE() \
# define RTASN1TMPL_PCHOICE_ITAG_EX(a_uTag, a_enmChoice, a_PtrName, a_Name, a_Type, a_Api, a_fClue, a_Constraints) \
# define RTASN1TMPL_PCHOICE_XTAG_EX(a_uTag, a_enmChoice, a_PtrTnNm, a_CtxTagN, a_Name, a_Type, a_Api, a_Constraints) \
# define RTASN1TMPL_END_PCHOICE() RTASN1TMPL_SEMICOLON_DUMMY()
/*
*
* Initialization to standard / default values.
*
*/
# define RTASN1TMPL_BEGIN_COMMON() \
RTASN1TMPL_DECL(int) RT_CONCAT(RTASN1TMPL_EXT_NAME,_Init)(RT_CONCAT(P,RTASN1TMPL_TYPE) pThis, PCRTASN1ALLOCATORVTABLE pAllocator) \
{ \
# define RTASN1TMPL_END_COMMON() \
return rc; \
# define RTASN1TMPL_BEGIN_SEQCORE() \
# define RTASN1TMPL_BEGIN_SETCORE() \
if (RT_SUCCESS(rc)) \
# define RTASN1TMPL_MEMBER_DYN_COMMON(a_UnionNm, a_PtrName, a_Type, a_Api, a_Allocation, a_enmMembNm, a_enmValue, a_IfStmt) \
do { } while (0)
# define RTASN1TMPL_MEMBER_DEF_ITAG_EX(a_Name, a_Type, a_Api, a_uTag, a_fClue, a_DefVal, a_Constraints) \
if (RT_SUCCESS(rc)) \
{ \
if (RT_SUCCESS(rc)) \
}
# define RTASN1TMPL_MEMBER_OPT_EX(a_Name, a_Type, a_Api, a_Constraints) do { } while (0) /* All optional members are left as not-present. */
# define RTASN1TMPL_END_SEQCORE() \
if (RT_FAILURE(rc)) \
# define RTASN1TMPL_END_SETCORE() RTASN1TMPL_END_SEQCORE()
/* No choice, just an empty, non-present structure. */
# define RTASN1TMPL_PCHOICE_ITAG_EX(a_uTag, a_enmChoice, a_PtrName, a_Name, a_Type, a_Api, a_fClue, a_Constraints) \
do { } while (0)
# define RTASN1TMPL_PCHOICE_XTAG_EX(a_uTag, a_enmChoice, a_PtrTnNm, a_CtxTagN, a_Name, a_Type, a_Api, a_Constraints) \
do { } while (0)
# define RTASN1TMPL_END_PCHOICE() RTASN1TMPL_END_COMMON()
int rc = RT_CONCAT(a_OfApi,_Init)(&pThis->a_OfMember, &RT_CONCAT3(g_,RTASN1TMPL_INT_NAME,_Vtable)); \
if (RT_FAILURE(rc)) \
# define RTASN1TMPL_SEQ_OF(a_ItemType, a_ItemApi) RTASN1TMPL_SET_SEQ_OF_COMMON(a_ItemType, a_ItemApi, RTAsn1SeqOfCore, SeqCore)
# define RTASN1TMPL_SET_OF(a_ItemType, a_ItemApi) RTASN1TMPL_SET_SEQ_OF_COMMON(a_ItemType, a_ItemApi, RTAsn1SetOfCore, SetCore)
/*
*
* Decode ASN.1.
*
*/
# define RTASN1TMPL_BEGIN_COMMON() \
RTASN1TMPL_DECL(int) RT_CONCAT(RTASN1TMPL_EXT_NAME,_DecodeAsn1)(PRTASN1CURSOR pCursor, uint32_t fFlags, \
{ \
# define RTASN1TMPL_END_COMMON() \
return rc; \
# define RTASN1TMPL_BEGIN_SEQCORE() \
int rc = RTAsn1CursorGetSequenceCursor(pCursor, fFlags, &pThis->SeqCore, &ThisCursor, pszErrorTag); \
if (RT_FAILURE(rc)) \
return rc; \
pCursor = &ThisCursor; \
# define RTASN1TMPL_BEGIN_SETCORE() \
if (RT_FAILURE(rc)) \
return rc; \
pCursor = &ThisCursor; \
if (RT_SUCCESS(rc)) \
if (RT_SUCCESS(rc)) \
{ \
int rc2; /* not initialized! */ \
if (false) do { /*nothing*/ } while (0)
# define RTASN1TMPL_MEMBER_DYN_COMMON(a_UnionNm, a_PtrName, a_Type, a_Api, a_Allocation, a_enmMembNm, a_enmValue, a_IfStmt) \
else a_IfStmt \
do { \
if (RT_SUCCESS(rc2)) \
{ \
rc2 = RT_CONCAT(a_Api,_DecodeAsn1)(pCursor, 0, pThis->a_UnionNm.a_PtrName, #a_UnionNm "." #a_PtrName); \
} \
} while (0)
}
# define RTASN1TMPL_MEMBER_DEF_ITAG_EX(a_Name, a_Type, a_Api, a_uTag, a_fClue, a_DefVal, a_Constraints) \
if (RT_SUCCESS(rc)) \
{ \
else \
if (RT_SUCCESS(rc)) \
} do {} while (0)
if (RT_SUCCESS(rc) && RTAsn1CursorIsNextEx(pCursor, ASN1_TAG_UTF8_STRING, ASN1_TAGCLASS_CONTEXT | ASN1_TAGFLAG_PRIMITIVE)) \
if (RT_SUCCESS(rc) && RTAsn1CursorIsNextEx(pCursor, a_uTag, RTASN1TMPL_ITAG_F_EXPAND(a_fClue)) /** @todo || CER */) \
if (RT_SUCCESS(rc) && RTAsn1CursorIsNextEx(pCursor, a_uTag, ASN1_TAGCLASS_CONTEXT | ASN1_TAGFLAG_CONSTRUCTED)) \
rc = RTAsn1CursorGetBitStringEx(pCursor, RTASN1CURSOR_GET_F_IMPLICIT, a_cMaxBits, &pThis->a_Name, #a_Name)
# define RTASN1TMPL_MEMBER_OPT_XTAG_EX(a_TnNm, a_CtxTagN, a_Name, a_Type, a_Api, a_uTag, a_Constraints) \
if (RT_SUCCESS(rc) && RTAsn1CursorIsNextEx(pCursor, a_uTag, ASN1_TAGCLASS_CONTEXT | ASN1_TAGFLAG_CONSTRUCTED)) \
{ \
rc = RT_CONCAT3(RTAsn1CursorGetContextTag,a_uTag,Cursor)(pCursor, 0, &pThis->a_TnNm.a_CtxTagN, &CtxCursor, #a_TnNm); \
if (RT_SUCCESS(rc)) \
{ \
if (RT_SUCCESS(rc)) \
} \
} do { } while (0)
# define RTASN1TMPL_END_SEQCORE() \
if (RT_SUCCESS(rc)) \
if (RT_SUCCESS(rc)) \
return VINF_SUCCESS; \
# define RTASN1TMPL_END_SETCORE() RTASN1TMPL_END_SEQCORE()
# define RTASN1TMPL_BEGIN_PCHOICE() \
if (RT_SUCCESS(rc)) \
{ \
if (false) do {} while (0)
# define RTASN1TMPL_PCHOICE_ITAG_EX(a_uTag, a_enmChoice, a_PtrName, a_Name, a_Type, a_Api, a_fClue, a_Constraints) \
do { \
if (RT_SUCCESS(rc)) \
rc = RT_CONCAT(a_Api,_DecodeAsn1)(pCursor, RTASN1CURSOR_GET_F_IMPLICIT, pThis->a_PtrName, #a_PtrName); \
} while (0)
# define RTASN1TMPL_PCHOICE_XTAG_EX(a_uTag, a_enmChoice, a_PtrTnNm, a_CtxTagN, a_Name, a_Type, a_Api, a_Constraints) \
else if (Asn1Peek.uTag == (a_uTag) && Asn1Peek.fClass == (ASN1_TAGCLASS_CONTEXT | ASN1_TAGFLAG_CONSTRUCTED)) \
do { \
if (RT_SUCCESS(rc)) \
{ \
rc = RT_CONCAT3(RTAsn1CursorGetContextTag,a_uTag,Cursor)(pCursor, 0, &pThis->a_PtrTnNm->a_CtxTagN, \
if (RT_SUCCESS(rc)) \
if (RT_SUCCESS(rc)) \
} \
} while (0)
#define RTASN1TMPL_END_PCHOICE() \
else \
if (RT_SUCCESS(rc)) \
return VINF_SUCCESS; \
} \
if (RT_SUCCESS(rc)) \
{ \
pCursor = &ThisCursor; \
\
uint32_t i = 0; \
&& RT_SUCCESS(rc)) \
{ \
i, \
i + 1); \
if (RT_SUCCESS(rc)) \
{ \
if (RT_SUCCESS(rc)) \
{ \
i++; \
continue; \
} \
} \
break; \
} \
if (RT_SUCCESS(rc)) \
{ \
if (RT_SUCCESS(rc)) \
return VINF_SUCCESS; \
} \
} \
RTASN1TMPL_SET_SEQ_OF_COMMON(a_ItemType, a_ItemApi, RTAsn1SeqOfCore, SeqCore, RTAsn1CursorGetSequenceCursor)
RTASN1TMPL_SET_SEQ_OF_COMMON(a_ItemType, a_ItemApi, RTAsn1SetOfCore, SetCore, RTAsn1CursorGetSetCursor)
/*
*
* Enumeration.
*
*/
# define RTASN1TMPL_BEGIN_COMMON() \
{ \
return VINF_SUCCESS; \
uDepth++; \
int rc = VINF_SUCCESS
# define RTASN1TMPL_END_COMMON() \
return rc; \
# define RTASN1TMPL_BEGIN_SEQCORE() RTASN1TMPL_BEGIN_COMMON()
# define RTASN1TMPL_BEGIN_SETCORE() RTASN1TMPL_BEGIN_COMMON()
if (rc == VINF_SUCCESS) \
if (rc == VINF_SUCCESS) \
switch (pThis->a_enmMembNm) \
{ \
default: rc = VERR_INTERNAL_ERROR_3; break
# define RTASN1TMPL_MEMBER_DYN_COMMON(a_UnionNm, a_PtrName, a_Type, a_Api, a_Allocation, a_enmMembNm, a_enmValue, a_IfStmt) \
case a_enmValue: \
rc = pfnCallback(RT_CONCAT(a_Api,_GetAsn1Core)(pThis->a_UnionNm.a_PtrName), #a_UnionNm "." #a_PtrName, \
break
}
# define RTASN1TMPL_MEMBER_OPT_XTAG_EX(a_TnNm, a_CtxTagN, a_Name, a_Type, a_Api, a_uTag, a_Constraints) \
{ \
if (rc == VINF_SUCCESS) \
rc = pfnCallback(RT_CONCAT(a_Api,_GetAsn1Core)(&pThis->a_TnNm.a_Name), #a_TnNm "." #a_Name, uDepth, pvUser); \
} do {} while (0)
# define RTASN1TMPL_END_SEQCORE() RTASN1TMPL_END_COMMON()
# define RTASN1TMPL_END_SETCORE() RTASN1TMPL_END_COMMON()
# define RTASN1TMPL_BEGIN_PCHOICE() \
{ \
default: rc = VERR_INTERNAL_ERROR_3; break
# define RTASN1TMPL_PCHOICE_ITAG_EX(a_uTag, a_enmChoice, a_PtrName, a_Name, a_Type, a_Api, a_fClue, a_Constraints) \
case a_enmChoice: rc = pfnCallback(RT_CONCAT(a_Api,_GetAsn1Core)(pThis->a_PtrName), #a_PtrName, uDepth, pvUser); break
# define RTASN1TMPL_PCHOICE_XTAG_EX(a_uTag, a_enmChoice, a_PtrTnNm, a_CtxTagN, a_Name, a_Type, a_Api, a_Constraints) \
case a_enmChoice: \
rc = pfnCallback(&pThis->a_PtrTnNm->a_CtxTagN.Asn1Core, "T" #a_uTag "." #a_CtxTagN, uDepth, pvUser); \
if (rc == VINF_SUCCESS) \
break
#define RTASN1TMPL_END_PCHOICE() \
} \
rc = pfnCallback(RT_CONCAT(a_ItemApi,_GetAsn1Core)(&pThis->paItems[i]), "paItems[#]", uDepth, pvUser); \
# define RTASN1TMPL_SEQ_OF(a_ItemType, a_ItemApi) RTASN1TMPL_SET_SEQ_OF_COMMON(a_ItemType, a_ItemApi)
# define RTASN1TMPL_SET_OF(a_ItemType, a_ItemApi) RTASN1TMPL_SET_SEQ_OF_COMMON(a_ItemType, a_ItemApi)
/*
*
* Clone another instance of the type.
*
*/
# define RTASN1TMPL_BEGIN_COMMON() \
{ \
return VINF_SUCCESS; \
# define RTASN1TMPL_END_COMMON() \
return rc; \
# define RTASN1TMPL_BEGIN_SEQCORE() \
int rc = RTAsn1SequenceCore_Clone(&pThis->SeqCore, &RT_CONCAT3(g_, RTASN1TMPL_INT_NAME, _Vtable), &pSrc->SeqCore)
# define RTASN1TMPL_BEGIN_SETCORE() \
int rc = RTAsn1SetCore_Clone(&pThis->SetCore, &RT_CONCAT3(g_, RTASN1TMPL_INT_NAME, _Vtable), &pSrc->SetCore)
if (RT_SUCCESS(rc)) \
if (RT_SUCCESS(rc)) \
{ \
switch (pSrc->a_enmMembNm) \
{ \
default: rc = VERR_INTERNAL_ERROR_3; break
# define RTASN1TMPL_MEMBER_DYN_COMMON(a_UnionNm, a_PtrName, a_Type, a_Api, a_Allocation, a_enmMembNm, a_enmValue, a_IfStmt) \
case a_enmValue: \
if (RT_SUCCESS(rc)) \
break
} \
}
/* Optional members and members with defaults are the same as a normal member when cloning. */
# define RTASN1TMPL_MEMBER_OPT_XTAG_EX(a_TnNm, a_CtxTagN, a_Name, a_Type, a_Api, a_uTag, a_Constraints) \
{ \
rc = RT_CONCAT3(RTAsn1ContextTag,a_uTag,_Clone)(&pThis->a_TnNm.a_CtxTagN, &pSrc->a_TnNm.a_CtxTagN); \
if (RT_SUCCESS(rc)) \
} do { } while (0)
# define RTASN1TMPL_END_SEQCORE() \
if (RT_FAILURE(rc)) \
# define RTASN1TMPL_END_SETCORE() RTASN1TMPL_END_SEQCORE()
# define RTASN1TMPL_BEGIN_PCHOICE() \
int rc; \
{ \
default: rc = VERR_INTERNAL_ERROR_3; break
# define RTASN1TMPL_PCHOICE_ITAG_EX(a_uTag, a_enmChoice, a_PtrName, a_Name, a_Type, a_Api, a_fClue, a_Constraints) \
case a_enmChoice: \
if (RT_SUCCESS(rc)) \
# define RTASN1TMPL_PCHOICE_XTAG_EX(a_uTag, a_enmChoice, a_PtrTnNm, a_CtxTagN, a_Name, a_Type, a_Api, a_Constraints) \
case a_enmChoice: /* A bit of presence paranoia here, but better safe than sorry... */ \
{ \
RT_CONCAT3(RTAsn1ContextTag,a_uTag,_Clone)(&pThis->a_PtrTnNm->a_CtxTagN, &pSrc->a_PtrTnNm->a_CtxTagN); \
} \
break
#define RTASN1TMPL_END_PCHOICE() \
} \
if (RT_FAILURE(rc)) \
int rc = RT_CONCAT(a_OfApi,_Clone)(&pThis->a_OfMember, &RT_CONCAT3(g_,RTASN1TMPL_INT_NAME,_Vtable), &pSrc->a_OfMember); \
if (RT_SUCCESS(rc)) \
{ \
if (cItems > 0) \
{ \
rc = RTAsn1MemGrowArray(&pThis->Allocation, (void **)&pThis->paItems, sizeof(pThis->paItems[0]), 0, cItems); \
if (RT_SUCCESS(rc)) \
{ \
uint32_t i = 0; \
while (i < cItems) \
{ \
if (RT_SUCCESS(rc)) \
else \
{ \
return rc; \
} \
} \
} \
else \
} \
} \
# define RTASN1TMPL_SEQ_OF(a_ItemType, a_ItemApi) RTASN1TMPL_SET_SEQ_OF_COMMON(a_ItemType, a_ItemApi, RTAsn1SeqOfCore, SeqCore)
# define RTASN1TMPL_SET_OF(a_ItemType, a_ItemApi) RTASN1TMPL_SET_SEQ_OF_COMMON(a_ItemType, a_ItemApi, RTAsn1SetOfCore, SetCore)
/*
*
* Member setter helpers.
*
*/
# define RTASN1TMPL_BEGIN_SEQCORE() RTASN1TMPL_SEMICOLON_DUMMY()
# define RTASN1TMPL_BEGIN_SETCORE() RTASN1TMPL_SEMICOLON_DUMMY()
#if 1 /** @todo later */
#else
RTDECL(int) RT_CONCAT3(RTASN1TMPL_EXT_NAME,_Set,a_Name)(RTASN1TMPL_TYPE *pThis, a_Type const *pValue, \
{ \
#endif
# define RTASN1TMPL_MEMBER_DYN_BEGIN(a_enmType, a_enmMembNm, a_Allocation) RTASN1TMPL_SEMICOLON_DUMMY()
# define RTASN1TMPL_MEMBER_DYN_END(a_enmType, a_enmMembNm, a_Allocation) RTASN1TMPL_SEMICOLON_DUMMY()
# define RTASN1TMPL_END_SEQCORE() RTASN1TMPL_SEMICOLON_DUMMY()
# define RTASN1TMPL_END_SETCORE() RTASN1TMPL_SEMICOLON_DUMMY()
# define RTASN1TMPL_BEGIN_PCHOICE() RTASN1TMPL_SEMICOLON_DUMMY()
# define RTASN1TMPL_PCHOICE_ITAG_EX(a_uTag, a_enmChoice, a_PtrName, a_Name, a_Type, a_Api, a_fClue, a_Constraints) RTASN1TMPL_SEMICOLON_DUMMY()
# define RTASN1TMPL_PCHOICE_XTAG_EX(a_uTag, a_enmChoice, a_PtrTnNm, a_CtxTagN, a_Name, a_Type, a_Api, a_Constraints) RTASN1TMPL_SEMICOLON_DUMMY()
# define RTASN1TMPL_END_PCHOICE() RTASN1TMPL_SEMICOLON_DUMMY()
/*
*
* Member setters.
*
*/
# define RTASN1TMPL_BEGIN_SEQCORE() RTASN1TMPL_SEMICOLON_DUMMY()
# define RTASN1TMPL_BEGIN_SETCORE() RTASN1TMPL_SEMICOLON_DUMMY()
# define RTASN1TMPL_MEMBER_DYN_BEGIN(a_enmType, a_enmMembNm, a_Allocation) RTASN1TMPL_SEMICOLON_DUMMY()
# define RTASN1TMPL_MEMBER_DYN_END(a_enmType, a_enmMembNm, a_Allocation) RTASN1TMPL_SEMICOLON_DUMMY()
# define RTASN1TMPL_END_SEQCORE() RTASN1TMPL_SEMICOLON_DUMMY()
# define RTASN1TMPL_END_SETCORE() RTASN1TMPL_SEMICOLON_DUMMY()
# define RTASN1TMPL_BEGIN_PCHOICE() RTASN1TMPL_SEMICOLON_DUMMY()
# define RTASN1TMPL_PCHOICE_ITAG_EX(a_uTag, a_enmChoice, a_PtrName, a_Name, a_Type, a_Api, a_fClue, a_Constraints) \
RTASN1TMPL_DECL(int) RT_CONCAT3(RTASN1TMPL_EXT_NAME,_Set,a_Name)(RT_CONCAT(P,RTASN1TMPL_TYPE) pThis, RT_CONCAT(PC,a_Type) pSrc,\
{ \
int rc = RTAsn1MemAllocZ(&pThis->Allocation, (void **)&pThis->a_PtrName, sizeof(*pThis->a_PtrName)); \
if (RT_SUCCESS(rc)) \
{ \
if (RT_SUCCESS(rc)) \
{ \
} \
} \
return rc; \
# define RTASN1TMPL_PCHOICE_XTAG_EX(a_uTag, a_enmChoice, a_PtrTnNm, a_CtxTagN, a_Name, a_Type, a_Api, a_Constraints) \
RTASN1TMPL_DECL(int) RT_CONCAT3(RTASN1TMPL_EXT_NAME,_Set,a_Name)(RT_CONCAT(P,RTASN1TMPL_TYPE) pThis, RT_CONCAT(PC,a_Type) pSrc,\
{ \
int rc = RTAsn1MemAllocZ(&pThis->Allocation, (void **)&pThis->a_PtrTnNm, sizeof(*pThis->a_PtrTnNm)); \
if (RT_SUCCESS(rc)) \
{ \
if (RT_SUCCESS(rc)) \
{ \
if (RT_SUCCESS(rc)) \
} \
} \
return rc; \
#define RTASN1TMPL_END_PCHOICE() RTASN1TMPL_SEMICOLON_DUMMY()
/*
*
* Compare two instances of the type.
*
*/
# define RTASN1TMPL_BEGIN_COMMON() \
{ \
return -1; \
int iDiff = 0
# define RTASN1TMPL_END_COMMON() \
return iDiff; \
# define RTASN1TMPL_BEGIN_SEQCORE() RTASN1TMPL_BEGIN_COMMON()
# define RTASN1TMPL_BEGIN_SETCORE() RTASN1TMPL_BEGIN_COMMON()
if (!iDiff) \
else if (!iDiff) \
switch (pLeft->a_enmMembNm) \
{ \
default: break
# define RTASN1TMPL_MEMBER_DYN_COMMON(a_UnionNm, a_PtrName, a_Type, a_Api, a_Allocation, a_enmMembNm, a_enmValue, a_IfStmt) \
case a_enmValue: iDiff = RT_CONCAT(a_Api,_Compare)(pLeft->a_UnionNm.a_PtrName, pRight->a_UnionNm.a_PtrName); break
}
# define RTASN1TMPL_MEMBER_OPT_XTAG_EX(a_TnNm, a_CtxTagN, a_Name, a_Type, a_Api, a_uTag, a_Constraints) \
if (!iDiff) \
{ \
{ \
else \
iDiff = -1; \
} \
else \
} do { } while (0)
# define RTASN1TMPL_END_SEQCORE() RTASN1TMPL_END_COMMON()
# define RTASN1TMPL_END_SETCORE() RTASN1TMPL_END_COMMON()
# define RTASN1TMPL_BEGIN_PCHOICE() \
{ \
default: break
# define RTASN1TMPL_PCHOICE_ITAG_EX(a_uTag, a_enmChoice, a_PtrName, a_Name, a_Type, a_Api, a_fClue, a_Constraints) \
# define RTASN1TMPL_PCHOICE_XTAG_EX(a_uTag, a_enmChoice, a_PtrTnNm, a_CtxTagN, a_Name, a_Type, a_Api, a_Constraints) \
case a_enmChoice: iDiff = RT_CONCAT(a_Api,_Compare)(&pLeft->a_PtrTnNm->a_Name, &pRight->a_PtrTnNm->a_Name); break
#define RTASN1TMPL_END_PCHOICE() \
} \
else \
# define RTASN1TMPL_SEQ_OF(a_ItemType, a_ItemApi) RTASN1TMPL_SET_SEQ_OF_COMMON(a_ItemType, a_ItemApi)
# define RTASN1TMPL_SET_OF(a_ItemType, a_ItemApi) RTASN1TMPL_SET_SEQ_OF_COMMON(a_ItemType, a_ItemApi)
/*
*
* Checks the sanity of the type.
*
*/
# ifndef RTASN1TMPL_SANITY_CHECK_EXPR
# define RTASN1TMPL_SANITY_CHECK_EXPR() VINF_SUCCESS
# endif
# define RTASN1TMPL_BEGIN_COMMON() \
RTASN1TMPL_DECL(int) RT_CONCAT(RTASN1TMPL_EXT_NAME,_CheckSanity)(RT_CONCAT(PC,RTASN1TMPL_TYPE) pThis, uint32_t fFlags, \
{ \
return RTErrInfoSetF(pErrInfo, VERR_GENERAL_FAILURE, "%s: Missing (%s).", pszErrorTag, RT_XSTR(RTASN1TMPL_TYPE)); \
int rc = VINF_SUCCESS
# define RTASN1TMPL_END_COMMON() \
if (RT_SUCCESS(rc)) \
rc = (RTASN1TMPL_SANITY_CHECK_EXPR()); \
return rc; \
# define RTASN1TMPL_BEGIN_SEQCORE() RTASN1TMPL_BEGIN_COMMON()
# define RTASN1TMPL_BEGIN_SETCORE() RTASN1TMPL_BEGIN_COMMON()
if (RT_SUCCESS(rc)) \
{ \
{ \
{ a_Constraints } \
} \
else \
} do {} while (0)
if (RT_SUCCESS(rc)) \
switch (pThis->a_enmMembNm) \
{ \
default: \
break
# define RTASN1TMPL_MEMBER_DYN_COMMON(a_UnionNm, a_PtrName, a_Type, a_Api, a_Allocation, a_enmMembNm, a_enmValue, a_IfStmt) \
case a_enmValue: \
rc = RT_CONCAT(a_Api,_CheckSanity)(pThis->a_UnionNm.a_PtrName, fFlags & RTASN1_CHECK_SANITY_F_COMMON_MASK, \
break
break; \
}
{ \
{ a_Constraints } \
}
# define RTASN1TMPL_MEMBER_OPT_XTAG_EX(a_TnNm, a_CtxTagN, a_Name, a_Type, a_Api, a_uTag, a_Constraints) \
if (RT_SUCCESS(rc)) \
{ \
if (fOuterPresent && fInnerPresent) \
{ \
rc = RT_CONCAT(a_Api,_CheckSanity)(&pThis->a_TnNm.a_Name, fFlags & RTASN1_CHECK_SANITY_F_COMMON_MASK, \
{ a_Constraints } \
} \
} do { } while (0)
# define RTASN1TMPL_END_SEQCORE() RTASN1TMPL_END_COMMON()
# define RTASN1TMPL_END_SETCORE() RTASN1TMPL_END_COMMON()
# define RTASN1TMPL_BEGIN_PCHOICE() \
{ \
default: \
break
# define RTASN1TMPL_PCHOICE_ITAG_EX(a_uTag, a_enmChoice, a_PtrName, a_Name, a_Type, a_Api, a_fClue, a_Constraints) \
case a_enmChoice: \
{ \
{ \
{ a_Constraints } \
} \
else \
} \
else \
break
# define RTASN1TMPL_PCHOICE_XTAG_EX(a_uTag, a_enmChoice, a_PtrTnNm, a_CtxTagN, a_Name, a_Type, a_Api, a_Constraints) \
case a_enmChoice: \
{ \
rc = RT_CONCAT(a_Api,_CheckSanity)(&pThis->a_PtrTnNm->a_Name, fFlags & RTASN1_CHECK_SANITY_F_COMMON_MASK, \
{ a_Constraints } \
} \
else \
break
#define RTASN1TMPL_END_PCHOICE() \
} \
rc = RT_CONCAT(a_ItemApi,_CheckSanity)(&pThis->paItems[i], fFlags & RTASN1_CHECK_SANITY_F_COMMON_MASK, \
# define RTASN1TMPL_SEQ_OF(a_ItemType, a_ItemApi) RTASN1TMPL_SET_SEQ_OF_COMMON(a_ItemType, a_ItemApi)
# define RTASN1TMPL_SET_OF(a_ItemType, a_ItemApi) RTASN1TMPL_SET_SEQ_OF_COMMON(a_ItemType, a_ItemApi)
/* The constraints. */
{ \
} \
# define RTASN1TMPL_MEMBER_CONSTR_BITSTRING_MIN_MAX(a_Name, cMinBits, cMaxBits, a_MoreConstraints) \
{ \
if (RT_UNLIKELY( ((cMinBits) == 0 ? false : pThis->a_Name.cBits + 1U < (cMinBits) + 1U /* warning avoiding */) \
|| ((cMaxBits) == UINT32_MAX ? false : pThis->a_Name.cBits + 1U > (cMaxBits) + 1U /* ditto */) ) ) \
} \
/*
*
* Delete wrappers.
*
*/
# define RTASN1TMPL_BEGIN_COMMON() \
{ \
{ do { } while (0)
# define RTASN1TMPL_END_COMMON() \
} \
# define RTASN1TMPL_BEGIN_SEQCORE() RTASN1TMPL_BEGIN_COMMON()
# define RTASN1TMPL_BEGIN_SETCORE() RTASN1TMPL_BEGIN_COMMON()
# define RTASN1TMPL_MEMBER_EX(a_Name, a_Type, a_Api, a_Constraints) RT_CONCAT(a_Api,_Delete)(&pThis->a_Name)
switch (pThis->a_enmMembNm) \
{ \
default: break
# define RTASN1TMPL_MEMBER_DYN_COMMON(a_UnionNm, a_PtrName, a_Type, a_Api, a_Allocation, a_enmMembNm, a_enmValue, a_IfStmt) \
}
# define RTASN1TMPL_END_SEQCORE() RTASN1TMPL_END_COMMON()
# define RTASN1TMPL_END_SETCORE() RTASN1TMPL_END_COMMON()
# define RTASN1TMPL_BEGIN_PCHOICE() \
{ \
default: break
# define RTASN1TMPL_PCHOICE_ITAG_EX(a_uTag, a_enmChoice, a_PtrName, a_Name, a_Type, a_Api, a_fClue, a_Constraints) \
case a_enmChoice: \
break
# define RTASN1TMPL_PCHOICE_XTAG_EX(a_uTag, a_enmChoice, a_PtrTnNm, a_CtxTagN, a_Name, a_Type, a_Api, a_Constraints) \
case a_enmChoice: \
break
# define RTASN1TMPL_END_PCHOICE() \
} \
while (i-- > 0) \
# define RTASN1TMPL_SEQ_OF(a_ItemType, a_ItemApi) RTASN1TMPL_SET_SEQ_OF_COMMON(a_ItemType, a_ItemApi)
# define RTASN1TMPL_SET_OF(a_ItemType, a_ItemApi) RTASN1TMPL_SET_SEQ_OF_COMMON(a_ItemType, a_ItemApi)
#else
#endif
/*
* Default aliases for simplified versions of macros if no specialization
* was required above.
*/
/* Non-optional members. */
#ifndef RTASN1TMPL_MEMBER
#endif
# define RTASN1TMPL_MEMBER_UTF8_STRING_MIN_MAX(a_Name) \
#endif
#ifndef RTASN1TMPL_MEMBER_UTF8_STRING
# define RTASN1TMPL_MEMBER_UTF8_STRING(a_Name) \
#endif
#ifndef RTASN1TMPL_MEMBER_STRING_MIN_MAX
#endif
#ifndef RTASN1TMPL_MEMBER_STRING
# define RTASN1TMPL_MEMBER_STRING(a_Name) \
#endif
#ifndef RTASN1TMPL_MEMBER_XTAG_EX
# define RTASN1TMPL_MEMBER_XTAG_EX(a_TnNm, a_CtxTagN, a_Name, a_Type, a_Api, a_uTag, a_Constraints) \
#endif
#ifndef RTASN1TMPL_MEMBER_DYN_BEGIN
#endif
#ifndef RTASN1TMPL_MEMBER_DYN_END
#endif
#ifndef RTASN1TMPL_MEMBER_DYN_COMMON
# define RTASN1TMPL_MEMBER_DYN_COMMON(a_UnionNm, a_PtrName, a_Type, a_Api, a_Allocation, a_enmMembNm, a_enmValue, a_IfStmt) \
#endif
#ifndef RTASN1TMPL_MEMBER_DYN
# define RTASN1TMPL_MEMBER_DYN(a_UnionNm, a_PtrName, a_Type, a_Api, a_Allocation, a_enmMembNm, a_enmValue, a_WhenExpr) \
RTASN1TMPL_MEMBER_DYN_COMMON(a_UnionNm, a_PtrName, a_Type, a_Api, a_Allocation, a_enmMembNm, a_enmValue, if (a_WhenExpr))
#endif
#ifndef RTASN1TMPL_MEMBER_DYN_DEFAULT
# define RTASN1TMPL_MEMBER_DYN_DEFAULT(a_UnionNm, a_PtrName, a_Type, a_Api, a_Allocation, a_enmMembNm, a_enmValue) \
RTASN1TMPL_MEMBER_DYN_COMMON(a_UnionNm, a_PtrName, a_Type, a_Api, a_Allocation, a_enmMembNm, a_enmValue, RT_NOTHING)
#endif
/* Optional members. */
#ifndef RTASN1TMPL_MEMBER_OPT_EX
#endif
#ifndef RTASN1TMPL_MEMBER_OPT
#endif
#ifndef RTASN1TMPL_MEMBER_OPT_XTAG_EX
# define RTASN1TMPL_MEMBER_OPT_XTAG_EX(a_TnNm, a_CtxTagN, a_Name, a_Type, a_Api, a_uTag, a_Constraints) \
#endif
#ifndef RTASN1TMPL_MEMBER_OPT_XTAG
#endif
#ifndef RTASN1TMPL_MEMBER_OPT_ITAG_EX
#endif
#ifndef RTASN1TMPL_MEMBER_OPT_ITAG_UP
#endif
#ifndef RTASN1TMPL_MEMBER_OPT_ITAG_UC
#endif
#ifndef RTASN1TMPL_MEMBER_OPT_ITAG_CP
#endif
#ifndef RTASN1TMPL_MEMBER_OPT_ITAG
#endif
#ifndef RTASN1TMPL_MEMBER_OPT_ANY
#endif
#ifndef RTASN1TMPL_MEMBER_DEF_ITAG_EX
# define RTASN1TMPL_MEMBER_DEF_ITAG_EX(a_Name, a_Type, a_Api, a_uTag, a_fClue, a_DefVal, a_Constraints) \
#endif
#ifndef RTASN1TMPL_MEMBER_DEF_ITAG_UP
RTASN1TMPL_MEMBER_DEF_ITAG_EX(a_Name, a_Type, a_Api, a_uTag, RTASN1TMPL_ITAG_F_UP, a_DefVal, RT_NOTHING)
#endif
RTASN1TMPL_MEMBER_OPT_ITAG_EX(a_Name, RTASN1BITSTRING, RTAsn1BitString, a_uTag, RTASN1TMPL_ITAG_F_CP, \
#endif
#endif
# define RTASN1TMPL_MEMBER_OPT_UTF8_STRING(a_Name) \
#endif
#ifndef RTASN1TMPL_MEMBER_OPT_STRING_EX
#endif
#ifndef RTASN1TMPL_MEMBER_OPT_STRING
# define RTASN1TMPL_MEMBER_OPT_STRING(a_Name) \
#endif
/* Pointer choices. */
#ifndef RTASN1TMPL_PCHOICE_ITAG_UP
RTASN1TMPL_PCHOICE_ITAG_EX(a_uTag, a_enmChoice, a_PtrName, a_Name, a_Type, a_Api, RTASN1TMPL_ITAG_F_UP, RT_NOTHING)
#endif
#ifndef RTASN1TMPL_PCHOICE_ITAG_CP
RTASN1TMPL_PCHOICE_ITAG_EX(a_uTag, a_enmChoice, a_PtrName, a_Name, a_Type, a_Api, RTASN1TMPL_ITAG_F_CP, RT_NOTHING)
#endif
#ifndef RTASN1TMPL_PCHOICE_ITAG
RTASN1TMPL_PCHOICE_ITAG_EX(a_uTag, a_enmChoice, a_PtrName, a_Name, a_Type, a_Api, RTASN1TMPL_ITAG_F_CC, RT_NOTHING)
#endif
#ifndef RTASN1TMPL_PCHOICE_XTAG
# define RTASN1TMPL_PCHOICE_XTAG(a_uTag, a_enmChoice, a_PtrTnNm, a_CtxTagN, a_Name, a_Type, a_Api) \
RTASN1TMPL_PCHOICE_XTAG_EX(a_uTag, a_enmChoice, a_PtrTnNm, a_CtxTagN, a_Name, a_Type, a_Api, RT_NOTHING)
#endif
/*
* Constraints are only used in the sanity check pass, so provide subs for the
* others passes.
*/
#ifndef RTASN1TMPL_MEMBER_CONSTR_MIN_MAX
#endif
#endif
#ifndef RTASN1TMPL_MEMBER_CONSTR_PRESENT
#endif
/*
* Stub exec hacks.
*/
#ifndef RTASN1TMPL_EXEC_DECODE
#endif
#ifndef RTASN1TMPL_EXEC_CLONE
#endif
#ifndef RTASN1TMPL_EXEC_CHECK_SANITY
#endif
#define RTASN1TMPL_SET_SEQ_EXEC_CHECK_SANITY() do { } while (0)
/*
* Generate the requested code.
*/
#ifndef RTASN1TMPL_TEMPLATE_FILE
# error "No template file (RTASN1TMPL_TEMPLATE_FILE) is specified."
#endif
#include RTASN1TMPL_TEMPLATE_FILE
/*
* Undo all the macros.
*/