ReactOS 0.4.16-dev-250-g3ecd236
proplist.c
Go to the documentation of this file.
1/*
2 * Copyright 2004-2006 Juan Lang
3 *
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.
8 *
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.
13 *
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
17 */
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 "wine/list.h"
25#include "crypt32_private.h"
26
28
30{
33};
34
35typedef struct _CONTEXT_PROPERTY
36{
40 struct list entry;
42
44{
46
47 if (list)
48 {
50 list->cs.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": PCONTEXT_PROPERTY_LIST->cs");
51 list_init(&list->properties);
52 }
53 return list;
54}
55
57{
58 CONTEXT_PROPERTY *prop, *next;
59
61 entry)
62 {
63 list_remove(&prop->entry);
64 CryptMemFree(prop->pbData);
65 CryptMemFree(prop);
66 }
67 list->cs.DebugInfo->Spare[0] = 0;
70}
71
74{
75 CONTEXT_PROPERTY *prop;
76 BOOL ret = FALSE;
77
78 TRACE("(%p, %d, %p)\n", list, id, blob);
79
82 {
83 if (prop->propID == id)
84 {
85 blob->cbData = prop->cbData;
86 blob->pbData = prop->pbData;
87 ret = TRUE;
88 break;
89 }
90 }
92 return ret;
93}
94
96 const BYTE *pbData, size_t cbData)
97{
99 BOOL ret = FALSE;
100
101 if (cbData)
102 {
103 data = CryptMemAlloc(cbData);
104 if (data)
105 memcpy(data, pbData, cbData);
106 }
107 else
108 data = NULL;
109 if (!cbData || data)
110 {
111 CONTEXT_PROPERTY *prop;
112 BOOL found = FALSE;
113
115 LIST_FOR_EACH_ENTRY(prop, &list->properties, CONTEXT_PROPERTY, entry)
116 {
117 if (prop->propID == id)
118 {
119 found = TRUE;
120 break;
121 }
122 }
123 if (found)
124 {
125 CryptMemFree(prop->pbData);
126 prop->cbData = cbData;
127 prop->pbData = data;
128 ret = TRUE;
129 }
130 else
131 {
132 prop = CryptMemAlloc(sizeof(CONTEXT_PROPERTY));
133 if (prop)
134 {
135 prop->propID = id;
136 prop->cbData = cbData;
137 prop->pbData = data;
138 list_add_tail(&list->properties, &prop->entry);
139 ret = TRUE;
140 }
141 else
143 }
145 }
146 return ret;
147}
148
150{
151 CONTEXT_PROPERTY *prop;
152
154 LIST_FOR_EACH_ENTRY(prop, &list->properties, CONTEXT_PROPERTY, entry)
155 {
156 if (prop->propID == id)
157 {
158 list_remove(&prop->entry);
159 CryptMemFree(prop->pbData);
160 CryptMemFree(prop);
161 break;
162 }
163 }
165}
166
167/* Since the properties are stored in a list, this is a tad inefficient
168 * (O(n^2)) since I have to find the previous position every time.
169 */
171{
172 DWORD ret;
173
175 if (id)
176 {
177 CONTEXT_PROPERTY *cursor = NULL, *prop;
178
179 LIST_FOR_EACH_ENTRY(prop, &list->properties, CONTEXT_PROPERTY, entry)
180 {
181 if (prop->propID == id)
182 {
183 cursor = prop;
184 break;
185 }
186 }
187 if (cursor)
188 {
189 if (cursor->entry.next != &list->properties)
190 ret = LIST_ENTRY(cursor->entry.next, CONTEXT_PROPERTY,
191 entry)->propID;
192 else
193 ret = 0;
194 }
195 else
196 ret = 0;
197 }
198 else if (!list_empty(&list->properties))
199 ret = LIST_ENTRY(list->properties.next, CONTEXT_PROPERTY,
200 entry)->propID;
201 else
202 ret = 0;
204 return ret;
205}
206
208{
209 CONTEXT_PROPERTY *prop;
210
212 LIST_FOR_EACH_ENTRY(prop, &from->properties, CONTEXT_PROPERTY, entry)
213 {
215 prop->cbData);
216 }
218}
#define WINE_DEFAULT_DEBUG_CHANNEL(t)
Definition: precomp.h:23
static void list_remove(struct list_entry *entry)
Definition: list.h:90
static int list_empty(struct list_entry *head)
Definition: list.h:58
static void list_add_tail(struct list_entry *head, struct list_entry *entry)
Definition: list.h:83
static void list_init(struct list_entry *head)
Definition: list.h:51
Definition: list.h:37
struct list * next
Definition: list.h:38
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
LPVOID WINAPI CryptMemAlloc(ULONG cbSize)
Definition: main.c:131
VOID WINAPI CryptMemFree(LPVOID pv)
Definition: main.c:141
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
GLuint id
Definition: glext.h:5910
const char cursor[]
Definition: icontest.c:13
uint32_t entry
Definition: isohybrid.c:63
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
void ContextPropertyList_Free(CONTEXT_PROPERTY_LIST *list)
Definition: proplist.c:56
DWORD ContextPropertyList_EnumPropIDs(CONTEXT_PROPERTY_LIST *list, DWORD id)
Definition: proplist.c:170
struct _CONTEXT_PROPERTY CONTEXT_PROPERTY
CONTEXT_PROPERTY_LIST * ContextPropertyList_Create(void)
Definition: proplist.c:43
BOOL ContextPropertyList_FindProperty(CONTEXT_PROPERTY_LIST *list, DWORD id, PCRYPT_DATA_BLOB blob)
Definition: proplist.c:72
void ContextPropertyList_RemoveProperty(CONTEXT_PROPERTY_LIST *list, DWORD id)
Definition: proplist.c:149
void ContextPropertyList_Copy(CONTEXT_PROPERTY_LIST *to, CONTEXT_PROPERTY_LIST *from)
Definition: proplist.c:207
BOOL ContextPropertyList_SetProperty(CONTEXT_PROPERTY_LIST *list, DWORD id, const BYTE *pbData, size_t cbData)
Definition: proplist.c:95
static unsigned __int64 next
Definition: rand_nt.c:6
#define list
Definition: rosglue.h:35
#define LIST_FOR_EACH_ENTRY(elem, list, type, field)
Definition: list.h:198
#define LIST_FOR_EACH_ENTRY_SAFE(cursor, cursor2, list, type, field)
Definition: list.h:204
#define TRACE(s)
Definition: solgame.cpp:4
CardRegion * from
Definition: spigame.cpp:19
struct list properties
Definition: proplist.c:32
CRITICAL_SECTION cs
Definition: proplist.c:31
struct list entry
Definition: proplist.c:40
Definition: image.c:134
VOID WINAPI InitializeCriticalSection(OUT LPCRITICAL_SECTION lpCriticalSection)
Definition: synch.c:751
#define LIST_ENTRY(type)
Definition: queue.h:175
#define DWORD_PTR
Definition: treelist.c:76
unsigned char * LPBYTE
Definition: typedefs.h:53
int ret
void WINAPI LeaveCriticalSection(LPCRITICAL_SECTION)
void WINAPI EnterCriticalSection(LPCRITICAL_SECTION)
void WINAPI DeleteCriticalSection(PCRITICAL_SECTION)
_In_ HCRYPTHASH _In_ BOOL _In_ DWORD _Inout_updates_bytes_to_ pdwDataLen BYTE * pbData
Definition: wincrypt.h:4201
unsigned char BYTE
Definition: xxhash.c:193