mirror of
https://github.com/reactos/wine.git
synced 2024-11-25 20:59:54 +00:00
crypt32: Moved context desatructor to vtbl.
This commit is contained in:
parent
17e1dfef9b
commit
993691bef5
@ -109,6 +109,18 @@ BOOL WINAPI CertAddEncodedCertificateToSystemStoreW(LPCWSTR pszCertStoreName,
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void Cert_free(context_t *context)
|
||||||
|
{
|
||||||
|
cert_t *cert = (cert_t*)context;
|
||||||
|
|
||||||
|
CryptMemFree(cert->ctx.pbCertEncoded);
|
||||||
|
LocalFree(cert->ctx.pCertInfo);
|
||||||
|
}
|
||||||
|
|
||||||
|
static const context_vtbl_t cert_vtbl = {
|
||||||
|
Cert_free
|
||||||
|
};
|
||||||
|
|
||||||
BOOL WINAPI CertAddCertificateLinkToStore(HCERTSTORE hCertStore,
|
BOOL WINAPI CertAddCertificateLinkToStore(HCERTSTORE hCertStore,
|
||||||
PCCERT_CONTEXT pCertContext, DWORD dwAddDisposition,
|
PCCERT_CONTEXT pCertContext, DWORD dwAddDisposition,
|
||||||
PCCERT_CONTEXT *ppCertContext)
|
PCCERT_CONTEXT *ppCertContext)
|
||||||
@ -154,7 +166,7 @@ PCCERT_CONTEXT WINAPI CertCreateCertificateContext(DWORD dwCertEncodingType,
|
|||||||
{
|
{
|
||||||
BYTE *data = NULL;
|
BYTE *data = NULL;
|
||||||
|
|
||||||
cert = Context_CreateDataContext(sizeof(CERT_CONTEXT));
|
cert = Context_CreateDataContext(sizeof(CERT_CONTEXT), &cert_vtbl);
|
||||||
if (!cert)
|
if (!cert)
|
||||||
goto end;
|
goto end;
|
||||||
data = CryptMemAlloc(cbCertEncoded);
|
data = CryptMemAlloc(cbCertEncoded);
|
||||||
@ -187,14 +199,6 @@ PCCERT_CONTEXT WINAPI CertDuplicateCertificateContext(PCCERT_CONTEXT pCertContex
|
|||||||
return pCertContext;
|
return pCertContext;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void CertDataContext_Free(void *context)
|
|
||||||
{
|
|
||||||
PCERT_CONTEXT certContext = context;
|
|
||||||
|
|
||||||
CryptMemFree(certContext->pbCertEncoded);
|
|
||||||
LocalFree(certContext->pCertInfo);
|
|
||||||
}
|
|
||||||
|
|
||||||
BOOL WINAPI CertFreeCertificateContext(PCCERT_CONTEXT pCertContext)
|
BOOL WINAPI CertFreeCertificateContext(PCCERT_CONTEXT pCertContext)
|
||||||
{
|
{
|
||||||
BOOL ret = TRUE;
|
BOOL ret = TRUE;
|
||||||
@ -202,7 +206,7 @@ BOOL WINAPI CertFreeCertificateContext(PCCERT_CONTEXT pCertContext)
|
|||||||
TRACE("(%p)\n", pCertContext);
|
TRACE("(%p)\n", pCertContext);
|
||||||
|
|
||||||
if (pCertContext)
|
if (pCertContext)
|
||||||
ret = Context_Release(&cert_from_ptr(pCertContext)->base, CertDataContext_Free);
|
ret = Context_Release(&cert_from_ptr(pCertContext)->base);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -29,7 +29,7 @@ WINE_DEFAULT_DEBUG_CHANNEL(context);
|
|||||||
#define CONTEXT_FROM_BASE_CONTEXT(p) (void*)(p+1)
|
#define CONTEXT_FROM_BASE_CONTEXT(p) (void*)(p+1)
|
||||||
#define BASE_CONTEXT_FROM_CONTEXT(p) ((BASE_CONTEXT*)(p)-1)
|
#define BASE_CONTEXT_FROM_CONTEXT(p) ((BASE_CONTEXT*)(p)-1)
|
||||||
|
|
||||||
void *Context_CreateDataContext(size_t contextSize)
|
void *Context_CreateDataContext(size_t contextSize, const context_vtbl_t *vtbl)
|
||||||
{
|
{
|
||||||
BASE_CONTEXT *context;
|
BASE_CONTEXT *context;
|
||||||
|
|
||||||
@ -37,6 +37,7 @@ void *Context_CreateDataContext(size_t contextSize)
|
|||||||
if (!context)
|
if (!context)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
|
context->vtbl = vtbl;
|
||||||
context->ref = 1;
|
context->ref = 1;
|
||||||
context->linked = NULL;
|
context->linked = NULL;
|
||||||
context->properties = ContextPropertyList_Create();
|
context->properties = ContextPropertyList_Create();
|
||||||
@ -62,6 +63,7 @@ void *Context_CreateLinkContext(unsigned int contextSize, void *linked, unsigned
|
|||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
memcpy(CONTEXT_FROM_BASE_CONTEXT(context), linked, contextSize);
|
memcpy(CONTEXT_FROM_BASE_CONTEXT(context), linked, contextSize);
|
||||||
|
context->vtbl = BASE_CONTEXT_FROM_CONTEXT(linked)->vtbl;
|
||||||
context->ref = 1;
|
context->ref = 1;
|
||||||
context->linked = BASE_CONTEXT_FROM_CONTEXT(linked);
|
context->linked = BASE_CONTEXT_FROM_CONTEXT(linked);
|
||||||
if (addRef)
|
if (addRef)
|
||||||
@ -103,7 +105,7 @@ CONTEXT_PROPERTY_LIST *Context_GetProperties(const void *context)
|
|||||||
return ptr->properties;
|
return ptr->properties;
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOL Context_Release(context_t *context, ContextFreeFunc dataContextFree)
|
BOOL Context_Release(context_t *context)
|
||||||
{
|
{
|
||||||
BOOL ret = TRUE;
|
BOOL ret = TRUE;
|
||||||
|
|
||||||
@ -118,9 +120,9 @@ BOOL Context_Release(context_t *context, ContextFreeFunc dataContextFree)
|
|||||||
if (!context->linked)
|
if (!context->linked)
|
||||||
{
|
{
|
||||||
ContextPropertyList_Free(context->properties);
|
ContextPropertyList_Free(context->properties);
|
||||||
dataContextFree(CONTEXT_FROM_BASE_CONTEXT(context));
|
context->vtbl->free(context);
|
||||||
} else {
|
} else {
|
||||||
Context_Release(context->linked, dataContextFree);
|
Context_Release(context->linked);
|
||||||
}
|
}
|
||||||
CryptMemFree(context);
|
CryptMemFree(context);
|
||||||
}
|
}
|
||||||
|
@ -29,6 +29,18 @@
|
|||||||
|
|
||||||
WINE_DEFAULT_DEBUG_CHANNEL(crypt);
|
WINE_DEFAULT_DEBUG_CHANNEL(crypt);
|
||||||
|
|
||||||
|
static void CRL_free(context_t *context)
|
||||||
|
{
|
||||||
|
crl_t *crl = (crl_t*)context;
|
||||||
|
|
||||||
|
CryptMemFree(crl->ctx.pbCrlEncoded);
|
||||||
|
LocalFree(crl->ctx.pCrlInfo);
|
||||||
|
}
|
||||||
|
|
||||||
|
static const context_vtbl_t crl_vtbl = {
|
||||||
|
CRL_free
|
||||||
|
};
|
||||||
|
|
||||||
PCCRL_CONTEXT WINAPI CertCreateCRLContext(DWORD dwCertEncodingType,
|
PCCRL_CONTEXT WINAPI CertCreateCRLContext(DWORD dwCertEncodingType,
|
||||||
const BYTE* pbCrlEncoded, DWORD cbCrlEncoded)
|
const BYTE* pbCrlEncoded, DWORD cbCrlEncoded)
|
||||||
{
|
{
|
||||||
@ -52,7 +64,7 @@ PCCRL_CONTEXT WINAPI CertCreateCRLContext(DWORD dwCertEncodingType,
|
|||||||
{
|
{
|
||||||
BYTE *data = NULL;
|
BYTE *data = NULL;
|
||||||
|
|
||||||
crl = Context_CreateDataContext(sizeof(CRL_CONTEXT));
|
crl = Context_CreateDataContext(sizeof(CRL_CONTEXT), &crl_vtbl);
|
||||||
if (!crl)
|
if (!crl)
|
||||||
goto end;
|
goto end;
|
||||||
data = CryptMemAlloc(cbCrlEncoded);
|
data = CryptMemAlloc(cbCrlEncoded);
|
||||||
@ -331,14 +343,6 @@ PCCRL_CONTEXT WINAPI CertDuplicateCRLContext(PCCRL_CONTEXT pCrlContext)
|
|||||||
return pCrlContext;
|
return pCrlContext;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void CrlDataContext_Free(void *context)
|
|
||||||
{
|
|
||||||
PCRL_CONTEXT crlContext = context;
|
|
||||||
|
|
||||||
CryptMemFree(crlContext->pbCrlEncoded);
|
|
||||||
LocalFree(crlContext->pCrlInfo);
|
|
||||||
}
|
|
||||||
|
|
||||||
BOOL WINAPI CertFreeCRLContext( PCCRL_CONTEXT pCrlContext)
|
BOOL WINAPI CertFreeCRLContext( PCCRL_CONTEXT pCrlContext)
|
||||||
{
|
{
|
||||||
BOOL ret = TRUE;
|
BOOL ret = TRUE;
|
||||||
@ -346,7 +350,7 @@ BOOL WINAPI CertFreeCRLContext( PCCRL_CONTEXT pCrlContext)
|
|||||||
TRACE("(%p)\n", pCrlContext);
|
TRACE("(%p)\n", pCrlContext);
|
||||||
|
|
||||||
if (pCrlContext)
|
if (pCrlContext)
|
||||||
ret = Context_Release(&crl_from_ptr(pCrlContext)->base, CrlDataContext_Free);
|
ret = Context_Release(&crl_from_ptr(pCrlContext)->base);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -159,11 +159,18 @@ void default_chain_engine_free(void) DECLSPEC_HIDDEN;
|
|||||||
|
|
||||||
typedef struct _CONTEXT_PROPERTY_LIST CONTEXT_PROPERTY_LIST;
|
typedef struct _CONTEXT_PROPERTY_LIST CONTEXT_PROPERTY_LIST;
|
||||||
|
|
||||||
|
typedef struct _context_t context_t;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
void (*free)(context_t*);
|
||||||
|
} context_vtbl_t;
|
||||||
|
|
||||||
typedef struct _context_t {
|
typedef struct _context_t {
|
||||||
|
const context_vtbl_t *vtbl;
|
||||||
LONG ref;
|
LONG ref;
|
||||||
struct _context_t *linked;
|
struct _context_t *linked;
|
||||||
CONTEXT_PROPERTY_LIST *properties;
|
CONTEXT_PROPERTY_LIST *properties;
|
||||||
} BASE_CONTEXT, context_t;
|
} BASE_CONTEXT;
|
||||||
|
|
||||||
static inline context_t *context_from_ptr(const void *ptr)
|
static inline context_t *context_from_ptr(const void *ptr)
|
||||||
{
|
{
|
||||||
@ -380,7 +387,7 @@ DWORD cert_name_to_str_with_indent(DWORD dwCertEncodingType, DWORD indent,
|
|||||||
* which should be one of CERT_CONTEXT, CRL_CONTEXT, or CTL_CONTEXT.
|
* which should be one of CERT_CONTEXT, CRL_CONTEXT, or CTL_CONTEXT.
|
||||||
* Free with Context_Release.
|
* Free with Context_Release.
|
||||||
*/
|
*/
|
||||||
void *Context_CreateDataContext(size_t contextSize) DECLSPEC_HIDDEN;
|
void *Context_CreateDataContext(size_t contextSize, const context_vtbl_t *vtbl) DECLSPEC_HIDDEN;
|
||||||
|
|
||||||
/* Creates a new link context with extra bytes. The context refers to linked
|
/* Creates a new link context with extra bytes. The context refers to linked
|
||||||
* rather than owning its own properties. If addRef is TRUE (which ordinarily
|
* rather than owning its own properties. If addRef is TRUE (which ordinarily
|
||||||
@ -396,7 +403,7 @@ void *Context_CreateLinkContext(unsigned int contextSize, void *linked, unsigned
|
|||||||
void *Context_GetExtra(const void *context, size_t contextSize) DECLSPEC_HIDDEN;
|
void *Context_GetExtra(const void *context, size_t contextSize) DECLSPEC_HIDDEN;
|
||||||
|
|
||||||
/* Gets the context linked to by context, which must be a link context. */
|
/* Gets the context linked to by context, which must be a link context. */
|
||||||
void *Context_GetLinkedContext(void *context) DECLSPEC_HIDDEN;
|
void *Context_GetLinkedContext(void*) DECLSPEC_HIDDEN;
|
||||||
|
|
||||||
/* Copies properties from fromContext to toContext. */
|
/* Copies properties from fromContext to toContext. */
|
||||||
void Context_CopyProperties(const void *to, const void *from) DECLSPEC_HIDDEN;
|
void Context_CopyProperties(const void *to, const void *from) DECLSPEC_HIDDEN;
|
||||||
@ -408,14 +415,12 @@ CONTEXT_PROPERTY_LIST *Context_GetProperties(const void *context) DECLSPEC_HIDDE
|
|||||||
|
|
||||||
void Context_AddRef(context_t*) DECLSPEC_HIDDEN;
|
void Context_AddRef(context_t*) DECLSPEC_HIDDEN;
|
||||||
|
|
||||||
typedef void (*ContextFreeFunc)(void *context);
|
|
||||||
|
|
||||||
/* Decrements context's ref count. If context is a link context, releases its
|
/* Decrements context's ref count. If context is a link context, releases its
|
||||||
* linked context as well.
|
* linked context as well.
|
||||||
* If a data context has its ref count reach 0, calls dataContextFree on it.
|
* If a data context has its ref count reach 0, calls dataContextFree on it.
|
||||||
* Returns FALSE if the reference count is <= 0 when called.
|
* Returns FALSE if the reference count is <= 0 when called.
|
||||||
*/
|
*/
|
||||||
BOOL Context_Release(context_t *context, ContextFreeFunc dataContextFree) DECLSPEC_HIDDEN;
|
BOOL Context_Release(context_t *context) DECLSPEC_HIDDEN;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Context property list functions
|
* Context property list functions
|
||||||
|
@ -29,6 +29,20 @@
|
|||||||
|
|
||||||
WINE_DEFAULT_DEBUG_CHANNEL(crypt);
|
WINE_DEFAULT_DEBUG_CHANNEL(crypt);
|
||||||
|
|
||||||
|
static void CTL_free(context_t *context)
|
||||||
|
{
|
||||||
|
ctl_t *ctl = (ctl_t*)context;
|
||||||
|
|
||||||
|
CryptMsgClose(ctl->ctx.hCryptMsg);
|
||||||
|
CryptMemFree(ctl->ctx.pbCtlEncoded);
|
||||||
|
CryptMemFree(ctl->ctx.pbCtlContext);
|
||||||
|
LocalFree(ctl->ctx.pCtlInfo);
|
||||||
|
}
|
||||||
|
|
||||||
|
static const context_vtbl_t ctl_vtbl = {
|
||||||
|
CTL_free
|
||||||
|
};
|
||||||
|
|
||||||
BOOL WINAPI CertAddCTLContextToStore(HCERTSTORE hCertStore,
|
BOOL WINAPI CertAddCTLContextToStore(HCERTSTORE hCertStore,
|
||||||
PCCTL_CONTEXT pCtlContext, DWORD dwAddDisposition,
|
PCCTL_CONTEXT pCtlContext, DWORD dwAddDisposition,
|
||||||
PCCTL_CONTEXT* ppStoreContext)
|
PCCTL_CONTEXT* ppStoreContext)
|
||||||
@ -403,7 +417,7 @@ PCCTL_CONTEXT WINAPI CertCreateCTLContext(DWORD dwMsgAndCertEncodingType,
|
|||||||
&ctlInfo, &size);
|
&ctlInfo, &size);
|
||||||
if (ret)
|
if (ret)
|
||||||
{
|
{
|
||||||
ctl = Context_CreateDataContext(sizeof(CTL_CONTEXT));
|
ctl = Context_CreateDataContext(sizeof(CTL_CONTEXT), &ctl_vtbl);
|
||||||
if (ctl)
|
if (ctl)
|
||||||
{
|
{
|
||||||
BYTE *data = CryptMemAlloc(cbCtlEncoded);
|
BYTE *data = CryptMemAlloc(cbCtlEncoded);
|
||||||
@ -461,16 +475,6 @@ PCCTL_CONTEXT WINAPI CertDuplicateCTLContext(PCCTL_CONTEXT pCtlContext)
|
|||||||
return pCtlContext;
|
return pCtlContext;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void CTLDataContext_Free(void *context)
|
|
||||||
{
|
|
||||||
PCTL_CONTEXT ctlContext = context;
|
|
||||||
|
|
||||||
CryptMsgClose(ctlContext->hCryptMsg);
|
|
||||||
CryptMemFree(ctlContext->pbCtlEncoded);
|
|
||||||
CryptMemFree(ctlContext->pbCtlContext);
|
|
||||||
LocalFree(ctlContext->pCtlInfo);
|
|
||||||
}
|
|
||||||
|
|
||||||
BOOL WINAPI CertFreeCTLContext(PCCTL_CONTEXT pCTLContext)
|
BOOL WINAPI CertFreeCTLContext(PCCTL_CONTEXT pCTLContext)
|
||||||
{
|
{
|
||||||
BOOL ret = TRUE;
|
BOOL ret = TRUE;
|
||||||
@ -478,7 +482,7 @@ BOOL WINAPI CertFreeCTLContext(PCCTL_CONTEXT pCTLContext)
|
|||||||
TRACE("(%p)\n", pCTLContext);
|
TRACE("(%p)\n", pCTLContext);
|
||||||
|
|
||||||
if (pCTLContext)
|
if (pCTLContext)
|
||||||
ret = Context_Release(&ctl_from_ptr(pCTLContext)->base, CTLDataContext_Free);
|
ret = Context_Release(&ctl_from_ptr(pCTLContext)->base);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user