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
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
)
32 context
= CryptMemAlloc(sizeof(context_t
) + contextSize
);
38 context
->linked
= NULL
;
39 context
->properties
= ContextPropertyList_Create();
40 if (!context
->properties
)
42 CryptMemFree(context
);
46 TRACE("returning %p\n", context
);
47 return context_ptr(context
);
50 context_t
*Context_CreateLinkContext(unsigned int contextSize
, context_t
*linked
)
54 TRACE("(%d, %p)\n", contextSize
, linked
);
56 context
= CryptMemAlloc(sizeof(context_t
) + contextSize
);
60 memcpy(context_ptr(context
), context_ptr(linked
), contextSize
);
61 context
->vtbl
= linked
->vtbl
;
63 context
->linked
= linked
;
64 context
->properties
= linked
->properties
;
65 Context_AddRef(linked
);
67 TRACE("returning %p\n", context
);
71 void Context_AddRef(context_t
*context
)
73 InterlockedIncrement(&context
->ref
);
74 TRACE("(%p) ref=%d\n", context
, context
->ref
);
77 void Context_Release(context_t
*context
)
79 if (context
->ref
<= 0)
81 ERR("%p's ref count is %d\n", context
, context
->ref
);
83 if (InterlockedDecrement(&context
->ref
) == 0)
85 TRACE("freeing %p\n", context
);
88 ContextPropertyList_Free(context
->properties
);
89 context
->vtbl
->free(context
);
91 Context_Release(context
->linked
);
93 CryptMemFree(context
);
96 TRACE("%p's ref count is %d\n", context
, context
->ref
);
99 void Context_CopyProperties(const void *to
, const void *from
)
101 CONTEXT_PROPERTY_LIST
*toProperties
, *fromProperties
;
103 toProperties
= context_from_ptr(to
)->properties
;
104 fromProperties
= context_from_ptr(from
)->properties
;
105 assert(toProperties
&& fromProperties
);
106 ContextPropertyList_Copy(toProperties
, fromProperties
);