crypt32: Moved ContextList freeing to store.c and get rid of ContextList.
[wine.git] / dlls / crypt32 / context.c
blob4809eeaa57fba606d03d87c867f5247f1eae3dae
1 /*
2 * Copyright 2006 Juan Lang
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
18 #include <assert.h>
19 #include <stdarg.h>
20 #include "windef.h"
21 #include "winbase.h"
22 #include "wincrypt.h"
23 #include "wine/debug.h"
24 #include "crypt32_private.h"
26 WINE_DEFAULT_DEBUG_CHANNEL(context);
28 void *Context_CreateDataContext(size_t contextSize, const context_vtbl_t *vtbl)
30 context_t *context;
32 context = CryptMemAlloc(sizeof(context_t) + contextSize);
33 if (!context)
34 return NULL;
36 context->vtbl = vtbl;
37 context->ref = 1;
38 context->linked = NULL;
39 context->properties = ContextPropertyList_Create();
40 if (!context->properties)
42 CryptMemFree(context);
43 return NULL;
46 TRACE("returning %p\n", context);
47 return context_ptr(context);
50 context_t *Context_CreateLinkContext(unsigned int contextSize, context_t *linked)
52 context_t *context;
54 TRACE("(%d, %p)\n", contextSize, linked);
56 context = CryptMemAlloc(sizeof(context_t) + contextSize);
57 if (!context)
58 return NULL;
60 memcpy(context_ptr(context), context_ptr(linked), contextSize);
61 context->vtbl = linked->vtbl;
62 context->ref = 1;
63 context->linked = linked;
64 context->properties = linked->properties;
65 Context_AddRef(linked);
67 TRACE("returning %p\n", context);
68 return context;
71 void Context_AddRef(context_t *context)
73 InterlockedIncrement(&context->ref);
74 TRACE("(%p) ref=%d\n", context, context->ref);
77 BOOL Context_Release(context_t *context)
79 BOOL ret = TRUE;
81 if (context->ref <= 0)
83 ERR("%p's ref count is %d\n", context, context->ref);
84 return FALSE;
86 if (InterlockedDecrement(&context->ref) == 0)
88 TRACE("freeing %p\n", context);
89 if (!context->linked)
91 ContextPropertyList_Free(context->properties);
92 context->vtbl->free(context);
93 } else {
94 Context_Release(context->linked);
96 CryptMemFree(context);
98 else
99 TRACE("%p's ref count is %d\n", context, context->ref);
100 return ret;
103 void Context_CopyProperties(const void *to, const void *from)
105 CONTEXT_PROPERTY_LIST *toProperties, *fromProperties;
107 toProperties = context_from_ptr(to)->properties;
108 fromProperties = context_from_ptr(from)->properties;
109 assert(toProperties && fromProperties);
110 ContextPropertyList_Copy(toProperties, fromProperties);