From c75af2b9e06b193e7cf5f5f75e47e78224a78028 Mon Sep 17 00:00:00 2001 From: Jacek Caban Date: Thu, 17 Oct 2013 11:07:55 +0200 Subject: [PATCH] crypt32: Use context_t in enumContext. --- dlls/crypt32/collectionstore.c | 79 ++++++++++++++++------------------ dlls/crypt32/context.c | 14 +++--- dlls/crypt32/crypt32_private.h | 7 +-- dlls/crypt32/ctl.c | 9 ++-- dlls/crypt32/provstore.c | 66 ++++++++++++++-------------- dlls/crypt32/store.c | 46 ++++++++++---------- 6 files changed, 106 insertions(+), 115 deletions(-) diff --git a/dlls/crypt32/collectionstore.c b/dlls/crypt32/collectionstore.c index 69e29b6008f..f247c5c71b7 100644 --- a/dlls/crypt32/collectionstore.c +++ b/dlls/crypt32/collectionstore.c @@ -71,7 +71,7 @@ static DWORD Collection_release(WINECRYPT_CERTSTORE *store, DWORD flags) return ERROR_SUCCESS; } -static void *CRYPT_CollectionCreateContextFromChild(WINE_COLLECTIONSTORE *store, +static context_t *CRYPT_CollectionCreateContextFromChild(WINE_COLLECTIONSTORE *store, WINE_STORE_LIST_ENTRY *storeEntry, context_t *child, size_t contextSize) { context_t *ret; @@ -81,7 +81,7 @@ static void *CRYPT_CollectionCreateContextFromChild(WINE_COLLECTIONSTORE *store, return NULL; ret->u.ptr = storeEntry; - return context_ptr(ret); + return ret; } static BOOL CRYPT_CollectionAddContext(WINE_COLLECTIONSTORE *store, @@ -143,32 +143,29 @@ static BOOL CRYPT_CollectionAddContext(WINE_COLLECTIONSTORE *store, * Returns NULL if the collection contains no more items or on error. * Assumes the collection store's lock is held. */ -static void *CRYPT_CollectionAdvanceEnum(WINE_COLLECTIONSTORE *store, +static context_t *CRYPT_CollectionAdvanceEnum(WINE_COLLECTIONSTORE *store, WINE_STORE_LIST_ENTRY *storeEntry, const CONTEXT_FUNCS *contextFuncs, - const WINE_CONTEXT_INTERFACE *contextInterface, void *pPrev, size_t contextSize) + const WINE_CONTEXT_INTERFACE *contextInterface, context_t *prev, size_t contextSize) { - context_t *child; - void *ret, *tmp; + context_t *child, *ret; struct list *storeNext = list_next(&store->stores, &storeEntry->entry); - TRACE("(%p, %p, %p)\n", store, storeEntry, pPrev); + TRACE("(%p, %p, %p)\n", store, storeEntry, prev); - if (pPrev) + if (prev) { /* Ref-counting funny business: "duplicate" (addref) the child, because * the free(pPrev) below can cause the ref count to become negative. */ - child = context_from_ptr(pPrev)->linked; + child = prev->linked; Context_AddRef(child); - tmp = contextFuncs->enumContext(storeEntry->store, context_ptr(child)); - child = tmp ? context_from_ptr(tmp) : NULL; - Context_Release(context_from_ptr(pPrev)); - pPrev = NULL; + child = contextFuncs->enumContext(storeEntry->store, child); + Context_Release(prev); + prev = NULL; } else { - tmp = contextFuncs->enumContext(storeEntry->store, NULL); - child = tmp ? context_from_ptr(tmp) : NULL; + child = contextFuncs->enumContext(storeEntry->store, NULL); } if (child) { ret = CRYPT_CollectionCreateContextFromChild(store, storeEntry, child, contextSize); @@ -212,29 +209,29 @@ static BOOL Collection_addCert(WINECRYPT_CERTSTORE *store, void *cert, if (ppStoreContext && childContext) { WINE_STORE_LIST_ENTRY *storeEntry = context_from_ptr(childContext)->u.ptr; - PCERT_CONTEXT context = - CRYPT_CollectionCreateContextFromChild(cs, storeEntry, context_from_ptr(childContext), sizeof(CERT_CONTEXT)); + cert_t *context = (cert_t*)CRYPT_CollectionCreateContextFromChild(cs, storeEntry, + context_from_ptr(childContext), sizeof(CERT_CONTEXT)); - *ppStoreContext = context; + *ppStoreContext = &context->ctx; } CertFreeCertificateContext(childContext); return ret; } -static void *Collection_enumCert(WINECRYPT_CERTSTORE *store, void *pPrev) +static context_t *Collection_enumCert(WINECRYPT_CERTSTORE *store, context_t *prev) { WINE_COLLECTIONSTORE *cs = (WINE_COLLECTIONSTORE*)store; - void *ret; + context_t *ret; - TRACE("(%p, %p)\n", store, pPrev); + TRACE("(%p, %p)\n", store, prev); EnterCriticalSection(&cs->cs); - if (pPrev) + if (prev) { - WINE_STORE_LIST_ENTRY *storeEntry = context_from_ptr(pPrev)->u.ptr; + WINE_STORE_LIST_ENTRY *storeEntry = prev->u.ptr; ret = CRYPT_CollectionAdvanceEnum(cs, storeEntry, - &storeEntry->store->vtbl->certs, pCertInterface, pPrev, + &storeEntry->store->vtbl->certs, pCertInterface, prev, sizeof(CERT_CONTEXT)); } else @@ -285,29 +282,29 @@ static BOOL Collection_addCRL(WINECRYPT_CERTSTORE *store, void *crl, if (ppStoreContext && childContext) { WINE_STORE_LIST_ENTRY *storeEntry = context_from_ptr(childContext)->u.ptr; - PCRL_CONTEXT context = - CRYPT_CollectionCreateContextFromChild(cs, storeEntry, context_from_ptr(childContext), sizeof(CRL_CONTEXT)); + crl_t *context = (crl_t*)CRYPT_CollectionCreateContextFromChild(cs, storeEntry, + context_from_ptr(childContext), sizeof(CRL_CONTEXT)); - *ppStoreContext = context; + *ppStoreContext = &context->ctx; } CertFreeCRLContext(childContext); return ret; } -static void *Collection_enumCRL(WINECRYPT_CERTSTORE *store, void *pPrev) +static context_t *Collection_enumCRL(WINECRYPT_CERTSTORE *store, context_t *prev) { WINE_COLLECTIONSTORE *cs = (WINE_COLLECTIONSTORE*)store; - void *ret; + context_t *ret; - TRACE("(%p, %p)\n", store, pPrev); + TRACE("(%p, %p)\n", store, prev); EnterCriticalSection(&cs->cs); - if (pPrev) + if (prev) { - WINE_STORE_LIST_ENTRY *storeEntry = context_from_ptr(pPrev)->u.ptr; + WINE_STORE_LIST_ENTRY *storeEntry = prev->u.ptr; ret = CRYPT_CollectionAdvanceEnum(cs, storeEntry, - &storeEntry->store->vtbl->crls, pCRLInterface, pPrev, sizeof(CRL_CONTEXT)); + &storeEntry->store->vtbl->crls, pCRLInterface, prev, sizeof(CRL_CONTEXT)); } else { @@ -356,29 +353,29 @@ static BOOL Collection_addCTL(WINECRYPT_CERTSTORE *store, void *ctl, if (ppStoreContext && childContext) { WINE_STORE_LIST_ENTRY *storeEntry = context_from_ptr(childContext)->u.ptr; - PCTL_CONTEXT context = - CRYPT_CollectionCreateContextFromChild(cs, storeEntry, context_from_ptr(childContext), sizeof(CTL_CONTEXT)); + ctl_t *context = (ctl_t*)CRYPT_CollectionCreateContextFromChild(cs, storeEntry, + context_from_ptr(childContext), sizeof(CTL_CONTEXT)); - *ppStoreContext = context; + *ppStoreContext = &context->ctx; } CertFreeCTLContext(childContext); return ret; } -static void *Collection_enumCTL(WINECRYPT_CERTSTORE *store, void *pPrev) +static context_t *Collection_enumCTL(WINECRYPT_CERTSTORE *store, context_t *prev) { WINE_COLLECTIONSTORE *cs = (WINE_COLLECTIONSTORE*)store; void *ret; - TRACE("(%p, %p)\n", store, pPrev); + TRACE("(%p, %p)\n", store, prev); EnterCriticalSection(&cs->cs); - if (pPrev) + if (prev) { - WINE_STORE_LIST_ENTRY *storeEntry = context_from_ptr(pPrev)->u.ptr; + WINE_STORE_LIST_ENTRY *storeEntry = prev->u.ptr; ret = CRYPT_CollectionAdvanceEnum(cs, storeEntry, - &storeEntry->store->vtbl->ctls, pCTLInterface, pPrev, sizeof(CTL_CONTEXT)); + &storeEntry->store->vtbl->ctls, pCTLInterface, prev, sizeof(CTL_CONTEXT)); } else { diff --git a/dlls/crypt32/context.c b/dlls/crypt32/context.c index 3b344630f78..9108ada5f66 100644 --- a/dlls/crypt32/context.c +++ b/dlls/crypt32/context.c @@ -164,16 +164,16 @@ context_t *ContextList_Add(struct ContextList *list, context_t *toLink, context_ return context; } -void *ContextList_Enum(struct ContextList *list, void *pPrev) +context_t *ContextList_Enum(struct ContextList *list, context_t *prev) { struct list *listNext; - void *ret; + context_t *ret; EnterCriticalSection(&list->cs); - if (pPrev) + if (prev) { - listNext = list_next(&list->contexts, &context_from_ptr(pPrev)->u.entry); - Context_Release(context_from_ptr(pPrev)); + listNext = list_next(&list->contexts, &prev->u.entry); + Context_Release(prev); } else listNext = list_next(&list->contexts, &list->contexts); @@ -181,8 +181,8 @@ void *ContextList_Enum(struct ContextList *list, void *pPrev) if (listNext) { - ret = CONTEXT_FROM_BASE_CONTEXT(LIST_ENTRY(listNext, context_t, u.entry)); - Context_AddRef(context_from_ptr(ret)); + ret = LIST_ENTRY(listNext, context_t, u.entry); + Context_AddRef(ret); } else ret = NULL; diff --git a/dlls/crypt32/crypt32_private.h b/dlls/crypt32/crypt32_private.h index 1d7b287a823..470d8d5e1d6 100644 --- a/dlls/crypt32/crypt32_private.h +++ b/dlls/crypt32/crypt32_private.h @@ -264,9 +264,6 @@ extern const WINE_CONTEXT_INTERFACE *pCTLInterface DECLSPEC_HIDDEN; typedef struct WINE_CRYPTCERTSTORE * (*StoreOpenFunc)(HCRYPTPROV hCryptProv, DWORD dwFlags, const void *pvPara); -/* Called to enumerate the next context in a store. */ -typedef void * (*EnumFunc)(struct WINE_CRYPTCERTSTORE *store, void *pPrev); - typedef struct _CONTEXT_FUNCS { /* Called to add a context to a store. If toReplace is not NULL, @@ -276,7 +273,7 @@ typedef struct _CONTEXT_FUNCS * context should be returned in *ppStoreContext. */ BOOL (*addContext)(struct WINE_CRYPTCERTSTORE*,void*,void*,const void**,BOOL); - EnumFunc enumContext; + context_t *(*enumContext)(struct WINE_CRYPTCERTSTORE *store, context_t *prev); BOOL (*delete)(struct WINE_CRYPTCERTSTORE*,context_t*); } CONTEXT_FUNCS; @@ -447,7 +444,7 @@ struct ContextList *ContextList_Create( context_t *ContextList_Add(struct ContextList *list, context_t *toLink, context_t *toReplace, struct WINE_CRYPTCERTSTORE *store, BOOL use_link) DECLSPEC_HIDDEN; -void *ContextList_Enum(struct ContextList *list, void *pPrev) DECLSPEC_HIDDEN; +context_t *ContextList_Enum(struct ContextList *list, context_t *prev) DECLSPEC_HIDDEN; /* Removes a context from the list. Returns TRUE if the context was removed, * or FALSE if not. (The context may have been duplicated, so subsequent diff --git a/dlls/crypt32/ctl.c b/dlls/crypt32/ctl.c index 2811260ee28..4839ef3d67d 100644 --- a/dlls/crypt32/ctl.c +++ b/dlls/crypt32/ctl.c @@ -193,11 +193,10 @@ BOOL WINAPI CertAddEncodedCTLToStore(HCERTSTORE hCertStore, return ret; } -PCCTL_CONTEXT WINAPI CertEnumCTLsInStore(HCERTSTORE hCertStore, - PCCTL_CONTEXT pPrev) +PCCTL_CONTEXT WINAPI CertEnumCTLsInStore(HCERTSTORE hCertStore, PCCTL_CONTEXT pPrev) { + ctl_t *prev = pPrev ? ctl_from_ptr(pPrev) : NULL, *ret; WINECRYPT_CERTSTORE *hcs = hCertStore; - PCCTL_CONTEXT ret; TRACE("(%p, %p)\n", hCertStore, pPrev); if (!hCertStore) @@ -205,8 +204,8 @@ PCCTL_CONTEXT WINAPI CertEnumCTLsInStore(HCERTSTORE hCertStore, else if (hcs->dwMagic != WINE_CRYPTCERTSTORE_MAGIC) ret = NULL; else - ret = (PCCTL_CONTEXT)hcs->vtbl->ctls.enumContext(hcs, (void *)pPrev); - return ret; + ret = (ctl_t*)hcs->vtbl->ctls.enumContext(hcs, prev ? &prev->base : NULL); + return ret ? &ret->ctx : NULL; } typedef BOOL (*CtlCompareFunc)(PCCTL_CONTEXT pCtlContext, DWORD dwType, diff --git a/dlls/crypt32/provstore.c b/dlls/crypt32/provstore.c index 2b8c7967571..1c3870e259c 100644 --- a/dlls/crypt32/provstore.c +++ b/dlls/crypt32/provstore.c @@ -97,20 +97,20 @@ static BOOL ProvStore_addCert(WINECRYPT_CERTSTORE *store, void *cert, return ret; } -static void *ProvStore_enumCert(WINECRYPT_CERTSTORE *store, void *pPrev) +static context_t *ProvStore_enumCert(WINECRYPT_CERTSTORE *store, context_t *prev) { WINE_PROVIDERSTORE *ps = (WINE_PROVIDERSTORE*)store; - void *ret; + cert_t *ret; - ret = ps->memStore->vtbl->certs.enumContext(ps->memStore, pPrev); - if (ret) - { - /* same dirty trick: replace the returned context's hCertStore with - * store. - */ - ((PCERT_CONTEXT)ret)->hCertStore = store; - } - return ret; + ret = (cert_t*)ps->memStore->vtbl->certs.enumContext(ps->memStore, prev); + if (!ret) + return NULL; + + /* same dirty trick: replace the returned context's hCertStore with + * store. + */ + ret->ctx.hCertStore = store; + return &ret->base; } static BOOL ProvStore_deleteCert(WINECRYPT_CERTSTORE *store, context_t *context) @@ -164,20 +164,20 @@ static BOOL ProvStore_addCRL(WINECRYPT_CERTSTORE *store, void *crl, return ret; } -static void *ProvStore_enumCRL(WINECRYPT_CERTSTORE *store, void *pPrev) +static context_t *ProvStore_enumCRL(WINECRYPT_CERTSTORE *store, context_t *prev) { WINE_PROVIDERSTORE *ps = (WINE_PROVIDERSTORE*)store; - void *ret; + crl_t *ret; - ret = ps->memStore->vtbl->crls.enumContext(ps->memStore, pPrev); - if (ret) - { - /* same dirty trick: replace the returned context's hCertStore with - * store. - */ - ((PCRL_CONTEXT)ret)->hCertStore = store; - } - return ret; + ret = (crl_t*)ps->memStore->vtbl->crls.enumContext(ps->memStore, prev); + if (!ret) + return NULL; + + /* same dirty trick: replace the returned context's hCertStore with + * store. + */ + ret->ctx.hCertStore = store; + return &ret->base; } static BOOL ProvStore_deleteCRL(WINECRYPT_CERTSTORE *store, context_t *crl) @@ -231,20 +231,20 @@ static BOOL ProvStore_addCTL(WINECRYPT_CERTSTORE *store, void *ctl, return ret; } -static void *ProvStore_enumCTL(WINECRYPT_CERTSTORE *store, void *pPrev) +static context_t *ProvStore_enumCTL(WINECRYPT_CERTSTORE *store, context_t *prev) { WINE_PROVIDERSTORE *ps = (WINE_PROVIDERSTORE*)store; - void *ret; + ctl_t *ret; - ret = ps->memStore->vtbl->ctls.enumContext(ps->memStore, pPrev); - if (ret) - { - /* same dirty trick: replace the returned context's hCertStore with - * store. - */ - ((PCTL_CONTEXT)ret)->hCertStore = store; - } - return ret; + ret = (ctl_t*)ps->memStore->vtbl->ctls.enumContext(ps->memStore, prev); + if (!ret) + return NULL; + + /* same dirty trick: replace the returned context's hCertStore with + * store. + */ + ret->ctx.hCertStore = store; + return &ret->base; } static BOOL ProvStore_deleteCTL(WINECRYPT_CERTSTORE *store, context_t *ctl) diff --git a/dlls/crypt32/store.c b/dlls/crypt32/store.c index 3381194ebd4..dcc350d34e2 100644 --- a/dlls/crypt32/store.c +++ b/dlls/crypt32/store.c @@ -161,14 +161,14 @@ static BOOL MemStore_addCert(WINECRYPT_CERTSTORE *store, void *cert, return TRUE; } -static void *MemStore_enumCert(WINECRYPT_CERTSTORE *store, void *pPrev) +static context_t *MemStore_enumCert(WINECRYPT_CERTSTORE *store, context_t *prev) { WINE_MEMSTORE *ms = (WINE_MEMSTORE *)store; - void *ret; + context_t *ret; - TRACE("(%p, %p)\n", store, pPrev); + TRACE("(%p, %p)\n", store, prev); - ret = ContextList_Enum(ms->certs, pPrev); + ret = ContextList_Enum(ms->certs, prev); if (!ret) SetLastError(CRYPT_E_NOT_FOUND); @@ -205,14 +205,14 @@ static BOOL MemStore_addCRL(WINECRYPT_CERTSTORE *store, void *crl, return TRUE; } -static void *MemStore_enumCRL(WINECRYPT_CERTSTORE *store, void *pPrev) +static context_t *MemStore_enumCRL(WINECRYPT_CERTSTORE *store, context_t *prev) { WINE_MEMSTORE *ms = (WINE_MEMSTORE *)store; - void *ret; + context_t *ret; - TRACE("(%p, %p)\n", store, pPrev); + TRACE("(%p, %p)\n", store, prev); - ret = ContextList_Enum(ms->crls, pPrev); + ret = ContextList_Enum(ms->crls, prev); if (!ret) SetLastError(CRYPT_E_NOT_FOUND); @@ -249,14 +249,14 @@ static BOOL MemStore_addCTL(WINECRYPT_CERTSTORE *store, void *ctl, return TRUE; } -static void *MemStore_enumCTL(WINECRYPT_CERTSTORE *store, void *pPrev) +static context_t *MemStore_enumCTL(WINECRYPT_CERTSTORE *store, context_t *prev) { WINE_MEMSTORE *ms = (WINE_MEMSTORE *)store; - void *ret; + context_t *ret; - TRACE("(%p, %p)\n", store, pPrev); + TRACE("(%p, %p)\n", store, prev); - ret = ContextList_Enum(ms->ctls, pPrev); + ret = ContextList_Enum(ms->ctls, prev); if (!ret) SetLastError(CRYPT_E_NOT_FOUND); @@ -887,11 +887,10 @@ HCERTSTORE WINAPI CertOpenSystemStoreW(HCRYPTPROV_LEGACY hProv, CERT_SYSTEM_STORE_CURRENT_USER, szSubSystemProtocol); } -PCCERT_CONTEXT WINAPI CertEnumCertificatesInStore(HCERTSTORE hCertStore, - PCCERT_CONTEXT pPrev) +PCCERT_CONTEXT WINAPI CertEnumCertificatesInStore(HCERTSTORE hCertStore, PCCERT_CONTEXT pPrev) { + cert_t *prev = pPrev ? cert_from_ptr(pPrev) : NULL, *ret; WINECRYPT_CERTSTORE *hcs = hCertStore; - PCCERT_CONTEXT ret; TRACE("(%p, %p)\n", hCertStore, pPrev); if (!hCertStore) @@ -899,8 +898,8 @@ PCCERT_CONTEXT WINAPI CertEnumCertificatesInStore(HCERTSTORE hCertStore, else if (hcs->dwMagic != WINE_CRYPTCERTSTORE_MAGIC) ret = NULL; else - ret = (PCCERT_CONTEXT)hcs->vtbl->certs.enumContext(hcs, (void *)pPrev); - return ret; + ret = (cert_t*)hcs->vtbl->certs.enumContext(hcs, prev ? &prev->base : NULL); + return ret ? &ret->ctx : NULL; } BOOL WINAPI CertDeleteCertificateFromStore(PCCERT_CONTEXT pCertContext) @@ -1063,11 +1062,10 @@ BOOL WINAPI CertDeleteCRLFromStore(PCCRL_CONTEXT pCrlContext) return ret; } -PCCRL_CONTEXT WINAPI CertEnumCRLsInStore(HCERTSTORE hCertStore, - PCCRL_CONTEXT pPrev) +PCCRL_CONTEXT WINAPI CertEnumCRLsInStore(HCERTSTORE hCertStore, PCCRL_CONTEXT pPrev) { + crl_t *ret, *prev = pPrev ? crl_from_ptr(pPrev) : NULL; WINECRYPT_CERTSTORE *hcs = hCertStore; - PCCRL_CONTEXT ret; TRACE("(%p, %p)\n", hCertStore, pPrev); if (!hCertStore) @@ -1075,8 +1073,8 @@ PCCRL_CONTEXT WINAPI CertEnumCRLsInStore(HCERTSTORE hCertStore, else if (hcs->dwMagic != WINE_CRYPTCERTSTORE_MAGIC) ret = NULL; else - ret = (PCCRL_CONTEXT)hcs->vtbl->crls.enumContext(hcs, (void *)pPrev); - return ret; + ret = (crl_t*)hcs->vtbl->crls.enumContext(hcs, prev ? &prev->base : NULL); + return ret ? &ret->ctx : NULL; } HCERTSTORE WINAPI CertDuplicateStore(HCERTSTORE hCertStore) @@ -1374,12 +1372,12 @@ static BOOL EmptyStore_add(WINECRYPT_CERTSTORE *store, void *context, return TRUE; } -static void *EmptyStore_enum(WINECRYPT_CERTSTORE *store, void *prev) +static context_t *EmptyStore_enum(WINECRYPT_CERTSTORE *store, context_t *prev) { TRACE("(%p, %p)\n", store, prev); SetLastError(CRYPT_E_NOT_FOUND); - return FALSE; + return NULL; } static BOOL EmptyStore_delete(WINECRYPT_CERTSTORE *store, context_t *context)