Commit 2553b460 authored by Jacek Caban's avatar Jacek Caban Committed by Alexandre Julliard

crypt32: Use context_t in Context_CreateLinkContext.

parent c72570ce
...@@ -73,17 +73,15 @@ static DWORD Collection_release(WINECRYPT_CERTSTORE *store, DWORD flags) ...@@ -73,17 +73,15 @@ static DWORD Collection_release(WINECRYPT_CERTSTORE *store, DWORD flags)
} }
static void *CRYPT_CollectionCreateContextFromChild(WINE_COLLECTIONSTORE *store, static void *CRYPT_CollectionCreateContextFromChild(WINE_COLLECTIONSTORE *store,
WINE_STORE_LIST_ENTRY *storeEntry, void *child, size_t contextSize, WINE_STORE_LIST_ENTRY *storeEntry, void *child, size_t contextSize)
BOOL addRef)
{ {
void *ret = Context_CreateLinkContext(contextSize, child, context_t *ret = Context_CreateLinkContext(contextSize, context_from_ptr(child),
sizeof(WINE_STORE_LIST_ENTRY*), addRef); sizeof(WINE_STORE_LIST_ENTRY*));
if (ret) if (ret)
*(WINE_STORE_LIST_ENTRY **)Context_GetExtra(ret, contextSize) *(WINE_STORE_LIST_ENTRY **)Context_GetExtra(context_ptr(ret), contextSize) = storeEntry;
= storeEntry;
return ret; return context_ptr(ret);
} }
static BOOL CRYPT_CollectionAddContext(WINE_COLLECTIONSTORE *store, static BOOL CRYPT_CollectionAddContext(WINE_COLLECTIONSTORE *store,
...@@ -168,9 +166,10 @@ static void *CRYPT_CollectionAdvanceEnum(WINE_COLLECTIONSTORE *store, ...@@ -168,9 +166,10 @@ static void *CRYPT_CollectionAdvanceEnum(WINE_COLLECTIONSTORE *store,
} }
else else
child = contextFuncs->enumContext(storeEntry->store, NULL); child = contextFuncs->enumContext(storeEntry->store, NULL);
if (child) if (child) {
ret = CRYPT_CollectionCreateContextFromChild(store, storeEntry, child, ret = CRYPT_CollectionCreateContextFromChild(store, storeEntry, child, contextSize);
contextSize, FALSE); Context_Release(context_from_ptr(child));
}
else else
{ {
if (storeNext) if (storeNext)
...@@ -211,8 +210,7 @@ static BOOL Collection_addCert(WINECRYPT_CERTSTORE *store, void *cert, ...@@ -211,8 +210,7 @@ static BOOL Collection_addCert(WINECRYPT_CERTSTORE *store, void *cert,
WINE_STORE_LIST_ENTRY *storeEntry = *(WINE_STORE_LIST_ENTRY **) WINE_STORE_LIST_ENTRY *storeEntry = *(WINE_STORE_LIST_ENTRY **)
Context_GetExtra(childContext, sizeof(CERT_CONTEXT)); Context_GetExtra(childContext, sizeof(CERT_CONTEXT));
PCERT_CONTEXT context = PCERT_CONTEXT context =
CRYPT_CollectionCreateContextFromChild(cs, storeEntry, childContext, CRYPT_CollectionCreateContextFromChild(cs, storeEntry, childContext, sizeof(CERT_CONTEXT));
sizeof(CERT_CONTEXT), TRUE);
if (context) if (context)
context->hCertStore = store; context->hCertStore = store;
...@@ -291,8 +289,7 @@ static BOOL Collection_addCRL(WINECRYPT_CERTSTORE *store, void *crl, ...@@ -291,8 +289,7 @@ static BOOL Collection_addCRL(WINECRYPT_CERTSTORE *store, void *crl,
WINE_STORE_LIST_ENTRY *storeEntry = *(WINE_STORE_LIST_ENTRY **) WINE_STORE_LIST_ENTRY *storeEntry = *(WINE_STORE_LIST_ENTRY **)
Context_GetExtra(childContext, sizeof(CRL_CONTEXT)); Context_GetExtra(childContext, sizeof(CRL_CONTEXT));
PCRL_CONTEXT context = PCRL_CONTEXT context =
CRYPT_CollectionCreateContextFromChild(cs, storeEntry, childContext, CRYPT_CollectionCreateContextFromChild(cs, storeEntry, childContext, sizeof(CRL_CONTEXT));
sizeof(CRL_CONTEXT), TRUE);
if (context) if (context)
context->hCertStore = store; context->hCertStore = store;
...@@ -370,8 +367,7 @@ static BOOL Collection_addCTL(WINECRYPT_CERTSTORE *store, void *ctl, ...@@ -370,8 +367,7 @@ static BOOL Collection_addCTL(WINECRYPT_CERTSTORE *store, void *ctl,
WINE_STORE_LIST_ENTRY *storeEntry = *(WINE_STORE_LIST_ENTRY **) WINE_STORE_LIST_ENTRY *storeEntry = *(WINE_STORE_LIST_ENTRY **)
Context_GetExtra(childContext, sizeof(CTL_CONTEXT)); Context_GetExtra(childContext, sizeof(CTL_CONTEXT));
PCTL_CONTEXT context = PCTL_CONTEXT context =
CRYPT_CollectionCreateContextFromChild(cs, storeEntry, childContext, CRYPT_CollectionCreateContextFromChild(cs, storeEntry, childContext, sizeof(CTL_CONTEXT));
sizeof(CTL_CONTEXT), TRUE);
if (context) if (context)
context->hCertStore = store; context->hCertStore = store;
......
...@@ -51,10 +51,9 @@ void *Context_CreateDataContext(size_t contextSize, const context_vtbl_t *vtbl) ...@@ -51,10 +51,9 @@ void *Context_CreateDataContext(size_t contextSize, const context_vtbl_t *vtbl)
return CONTEXT_FROM_BASE_CONTEXT(context); return CONTEXT_FROM_BASE_CONTEXT(context);
} }
void *Context_CreateLinkContext(unsigned int contextSize, void *linked, unsigned int extra, context_t *Context_CreateLinkContext(unsigned int contextSize, context_t *linked, unsigned int extra)
BOOL addRef)
{ {
BASE_CONTEXT *context; context_t *context;
TRACE("(%d, %p, %d)\n", contextSize, linked, extra); TRACE("(%d, %p, %d)\n", contextSize, linked, extra);
...@@ -62,15 +61,14 @@ void *Context_CreateLinkContext(unsigned int contextSize, void *linked, unsigned ...@@ -62,15 +61,14 @@ void *Context_CreateLinkContext(unsigned int contextSize, void *linked, unsigned
if (!context) if (!context)
return NULL; return NULL;
memcpy(CONTEXT_FROM_BASE_CONTEXT(context), linked, contextSize); memcpy(context_ptr(context), context_ptr(linked), contextSize);
context->vtbl = BASE_CONTEXT_FROM_CONTEXT(linked)->vtbl; context->vtbl = linked->vtbl;
context->ref = 1; context->ref = 1;
context->linked = BASE_CONTEXT_FROM_CONTEXT(linked); context->linked = linked;
if (addRef) Context_AddRef(linked);
Context_AddRef(BASE_CONTEXT_FROM_CONTEXT(linked));
TRACE("returning %p\n", context); TRACE("returning %p\n", context);
return CONTEXT_FROM_BASE_CONTEXT(context); return context;
} }
void Context_AddRef(context_t *context) void Context_AddRef(context_t *context)
...@@ -185,15 +183,14 @@ static inline void *ContextList_EntryToContext(const struct ContextList *list, ...@@ -185,15 +183,14 @@ static inline void *ContextList_EntryToContext(const struct ContextList *list,
void *ContextList_Add(struct ContextList *list, void *toLink, void *toReplace) void *ContextList_Add(struct ContextList *list, void *toLink, void *toReplace)
{ {
void *context; context_t *context;
TRACE("(%p, %p, %p)\n", list, toLink, toReplace); TRACE("(%p, %p, %p)\n", list, toLink, toReplace);
context = Context_CreateLinkContext(list->contextSize, toLink, context = Context_CreateLinkContext(list->contextSize, context_from_ptr(toLink), sizeof(struct list));
sizeof(struct list), TRUE);
if (context) 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); TRACE("adding %p\n", context);
EnterCriticalSection(&list->cs); EnterCriticalSection(&list->cs);
...@@ -212,7 +209,7 @@ void *ContextList_Add(struct ContextList *list, void *toLink, void *toReplace) ...@@ -212,7 +209,7 @@ void *ContextList_Add(struct ContextList *list, void *toLink, void *toReplace)
list_add_head(&list->contexts, entry); list_add_head(&list->contexts, entry);
LeaveCriticalSection(&list->cs); LeaveCriticalSection(&list->cs);
} }
return context; return CONTEXT_FROM_BASE_CONTEXT(context);
} }
void *ContextList_Enum(struct ContextList *list, void *pPrev) void *ContextList_Enum(struct ContextList *list, void *pPrev)
......
...@@ -177,6 +177,11 @@ static inline context_t *context_from_ptr(const void *ptr) ...@@ -177,6 +177,11 @@ static inline context_t *context_from_ptr(const void *ptr)
return (context_t*)ptr-1; return (context_t*)ptr-1;
} }
static inline void *context_ptr(context_t *context)
{
return context+1;
}
typedef struct { typedef struct {
context_t base; context_t base;
CERT_CONTEXT ctx; CERT_CONTEXT ctx;
...@@ -390,8 +395,7 @@ void *Context_CreateDataContext(size_t contextSize, const context_vtbl_t *vtbl) ...@@ -390,8 +395,7 @@ void *Context_CreateDataContext(size_t contextSize, const context_vtbl_t *vtbl)
* it should be) linked is addref'd. * it should be) linked is addref'd.
* Free with Context_Release. * Free with Context_Release.
*/ */
void *Context_CreateLinkContext(unsigned int contextSize, void *linked, unsigned int extra, context_t *Context_CreateLinkContext(unsigned contextSize, context_t *linked, unsigned extra) DECLSPEC_HIDDEN;
BOOL addRef) DECLSPEC_HIDDEN;
/* Returns a pointer to the extra bytes allocated with context, which must be /* Returns a pointer to the extra bytes allocated with context, which must be
* a link context. * a link context.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment