crypt32: Use context_t in Context_CreateLinkContext.

This commit is contained in:
Jacek Caban 2013-10-14 14:48:06 +02:00 committed by Alexandre Julliard
parent c72570ce52
commit 2553b4602b
3 changed files with 29 additions and 32 deletions

View File

@ -73,17 +73,15 @@ static DWORD Collection_release(WINECRYPT_CERTSTORE *store, DWORD flags)
}
static void *CRYPT_CollectionCreateContextFromChild(WINE_COLLECTIONSTORE *store,
WINE_STORE_LIST_ENTRY *storeEntry, void *child, size_t contextSize,
BOOL addRef)
WINE_STORE_LIST_ENTRY *storeEntry, void *child, size_t contextSize)
{
void *ret = Context_CreateLinkContext(contextSize, child,
sizeof(WINE_STORE_LIST_ENTRY*), addRef);
context_t *ret = Context_CreateLinkContext(contextSize, context_from_ptr(child),
sizeof(WINE_STORE_LIST_ENTRY*));
if (ret)
*(WINE_STORE_LIST_ENTRY **)Context_GetExtra(ret, contextSize)
= storeEntry;
*(WINE_STORE_LIST_ENTRY **)Context_GetExtra(context_ptr(ret), contextSize) = storeEntry;
return ret;
return context_ptr(ret);
}
static BOOL CRYPT_CollectionAddContext(WINE_COLLECTIONSTORE *store,
@ -168,9 +166,10 @@ static void *CRYPT_CollectionAdvanceEnum(WINE_COLLECTIONSTORE *store,
}
else
child = contextFuncs->enumContext(storeEntry->store, NULL);
if (child)
ret = CRYPT_CollectionCreateContextFromChild(store, storeEntry, child,
contextSize, FALSE);
if (child) {
ret = CRYPT_CollectionCreateContextFromChild(store, storeEntry, child, contextSize);
Context_Release(context_from_ptr(child));
}
else
{
if (storeNext)
@ -211,8 +210,7 @@ static BOOL Collection_addCert(WINECRYPT_CERTSTORE *store, void *cert,
WINE_STORE_LIST_ENTRY *storeEntry = *(WINE_STORE_LIST_ENTRY **)
Context_GetExtra(childContext, sizeof(CERT_CONTEXT));
PCERT_CONTEXT context =
CRYPT_CollectionCreateContextFromChild(cs, storeEntry, childContext,
sizeof(CERT_CONTEXT), TRUE);
CRYPT_CollectionCreateContextFromChild(cs, storeEntry, childContext, sizeof(CERT_CONTEXT));
if (context)
context->hCertStore = store;
@ -291,8 +289,7 @@ static BOOL Collection_addCRL(WINECRYPT_CERTSTORE *store, void *crl,
WINE_STORE_LIST_ENTRY *storeEntry = *(WINE_STORE_LIST_ENTRY **)
Context_GetExtra(childContext, sizeof(CRL_CONTEXT));
PCRL_CONTEXT context =
CRYPT_CollectionCreateContextFromChild(cs, storeEntry, childContext,
sizeof(CRL_CONTEXT), TRUE);
CRYPT_CollectionCreateContextFromChild(cs, storeEntry, childContext, sizeof(CRL_CONTEXT));
if (context)
context->hCertStore = store;
@ -370,8 +367,7 @@ static BOOL Collection_addCTL(WINECRYPT_CERTSTORE *store, void *ctl,
WINE_STORE_LIST_ENTRY *storeEntry = *(WINE_STORE_LIST_ENTRY **)
Context_GetExtra(childContext, sizeof(CTL_CONTEXT));
PCTL_CONTEXT context =
CRYPT_CollectionCreateContextFromChild(cs, storeEntry, childContext,
sizeof(CTL_CONTEXT), TRUE);
CRYPT_CollectionCreateContextFromChild(cs, storeEntry, childContext, sizeof(CTL_CONTEXT));
if (context)
context->hCertStore = store;

View File

@ -51,10 +51,9 @@ void *Context_CreateDataContext(size_t contextSize, const context_vtbl_t *vtbl)
return CONTEXT_FROM_BASE_CONTEXT(context);
}
void *Context_CreateLinkContext(unsigned int contextSize, void *linked, unsigned int extra,
BOOL addRef)
context_t *Context_CreateLinkContext(unsigned int contextSize, context_t *linked, unsigned int extra)
{
BASE_CONTEXT *context;
context_t *context;
TRACE("(%d, %p, %d)\n", contextSize, linked, extra);
@ -62,15 +61,14 @@ void *Context_CreateLinkContext(unsigned int contextSize, void *linked, unsigned
if (!context)
return NULL;
memcpy(CONTEXT_FROM_BASE_CONTEXT(context), linked, contextSize);
context->vtbl = BASE_CONTEXT_FROM_CONTEXT(linked)->vtbl;
memcpy(context_ptr(context), context_ptr(linked), contextSize);
context->vtbl = linked->vtbl;
context->ref = 1;
context->linked = BASE_CONTEXT_FROM_CONTEXT(linked);
if (addRef)
Context_AddRef(BASE_CONTEXT_FROM_CONTEXT(linked));
context->linked = linked;
Context_AddRef(linked);
TRACE("returning %p\n", context);
return CONTEXT_FROM_BASE_CONTEXT(context);
return context;
}
void Context_AddRef(context_t *context)
@ -185,15 +183,14 @@ static inline void *ContextList_EntryToContext(const struct ContextList *list,
void *ContextList_Add(struct ContextList *list, void *toLink, void *toReplace)
{
void *context;
context_t *context;
TRACE("(%p, %p, %p)\n", list, toLink, toReplace);
context = Context_CreateLinkContext(list->contextSize, toLink,
sizeof(struct list), TRUE);
context = Context_CreateLinkContext(list->contextSize, context_from_ptr(toLink), sizeof(struct list));
if (context)
{
struct list *entry = ContextList_ContextToEntry(list, context);
struct list *entry = ContextList_ContextToEntry(list, CONTEXT_FROM_BASE_CONTEXT(context));
TRACE("adding %p\n", context);
EnterCriticalSection(&list->cs);
@ -212,7 +209,7 @@ void *ContextList_Add(struct ContextList *list, void *toLink, void *toReplace)
list_add_head(&list->contexts, entry);
LeaveCriticalSection(&list->cs);
}
return context;
return CONTEXT_FROM_BASE_CONTEXT(context);
}
void *ContextList_Enum(struct ContextList *list, void *pPrev)

View File

@ -177,6 +177,11 @@ static inline context_t *context_from_ptr(const void *ptr)
return (context_t*)ptr-1;
}
static inline void *context_ptr(context_t *context)
{
return context+1;
}
typedef struct {
context_t base;
CERT_CONTEXT ctx;
@ -390,8 +395,7 @@ void *Context_CreateDataContext(size_t contextSize, const context_vtbl_t *vtbl)
* it should be) linked is addref'd.
* Free with Context_Release.
*/
void *Context_CreateLinkContext(unsigned int contextSize, void *linked, unsigned int extra,
BOOL addRef) DECLSPEC_HIDDEN;
context_t *Context_CreateLinkContext(unsigned contextSize, context_t *linked, unsigned extra) DECLSPEC_HIDDEN;
/* Returns a pointer to the extra bytes allocated with context, which must be
* a link context.