4 * Copyright 1997, 2002 Alexandre Julliard
5 * Copyright 2008 James Hawkins
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
31 #include "wine/debug.h"
33 #include "propsys_private.h"
35 WINE_DEFAULT_DEBUG_CHANNEL(propsys
);
37 static HRESULT WINAPI
ClassFactory_QueryInterface(IClassFactory
*iface
, REFIID riid
, void **ppv
)
41 if(IsEqualGUID(&IID_IUnknown
, riid
)) {
42 TRACE("(%p)->(IID_IUnknown %p)\n", iface
, ppv
);
44 }else if(IsEqualGUID(&IID_IClassFactory
, riid
)) {
45 TRACE("(%p)->(IID_IClassFactory %p)\n", iface
, ppv
);
50 IUnknown_AddRef((IUnknown
*)*ppv
);
54 FIXME("(%p)->(%s %p)\n", iface
, debugstr_guid(riid
), ppv
);
58 static ULONG WINAPI
ClassFactory_AddRef(IClassFactory
*iface
)
60 TRACE("(%p)\n", iface
);
64 static ULONG WINAPI
ClassFactory_Release(IClassFactory
*iface
)
66 TRACE("(%p)\n", iface
);
70 static HRESULT WINAPI
ClassFactory_LockServer(IClassFactory
*iface
, BOOL fLock
)
72 TRACE("(%p)->(%x)\n", iface
, fLock
);
77 static HRESULT WINAPI
InMemoryPropertyStoreFactory_CreateInstance(IClassFactory
*iface
, IUnknown
*outer
,
78 REFIID riid
, void **ppv
)
80 TRACE("(%p %s %p)\n", outer
, debugstr_guid(riid
), ppv
);
82 return PropertyStore_CreateInstance(outer
, riid
, ppv
);
85 static const IClassFactoryVtbl InMemoryPropertyStoreFactoryVtbl
= {
86 ClassFactory_QueryInterface
,
89 InMemoryPropertyStoreFactory_CreateInstance
,
90 ClassFactory_LockServer
93 static IClassFactory InMemoryPropertyStoreFactory
= { &InMemoryPropertyStoreFactoryVtbl
};
95 HRESULT WINAPI
DllGetClassObject(REFCLSID rclsid
, REFIID riid
, LPVOID
*ppv
)
97 if(IsEqualGUID(&CLSID_InMemoryPropertyStore
, rclsid
)) {
98 TRACE("(CLSID_InMemoryPropertyStore %s %p)\n", debugstr_guid(riid
), ppv
);
99 return IClassFactory_QueryInterface(&InMemoryPropertyStoreFactory
, riid
, ppv
);
102 FIXME("%s %s %p\n", debugstr_guid(rclsid
), debugstr_guid(riid
), ppv
);
103 return CLASS_E_CLASSNOTAVAILABLE
;
106 static HRESULT WINAPI
propsys_QueryInterface(IPropertySystem
*iface
, REFIID riid
, void **obj
)
110 if (IsEqualIID(riid
, &IID_IPropertySystem
) || IsEqualIID(riid
, &IID_IUnknown
)) {
112 IPropertySystem_AddRef(iface
);
116 FIXME("%s\n", debugstr_guid(riid
));
117 return E_NOINTERFACE
;
120 static ULONG WINAPI
propsys_AddRef(IPropertySystem
*iface
)
125 static ULONG WINAPI
propsys_Release(IPropertySystem
*iface
)
130 static HRESULT WINAPI
propsys_GetPropertyDescription(IPropertySystem
*iface
,
131 REFPROPERTYKEY propkey
, REFIID riid
, void **ppv
)
133 return PSGetPropertyDescription(propkey
, riid
, ppv
);
136 static HRESULT WINAPI
propsys_GetPropertyDescriptionByName(IPropertySystem
*iface
,
137 LPCWSTR canonical_name
, REFIID riid
, void **ppv
)
139 FIXME("%s %s %p: stub\n", debugstr_w(canonical_name
), debugstr_guid(riid
), ppv
);
143 static HRESULT WINAPI
propsys_GetPropertyDescriptionListFromString(IPropertySystem
*iface
,
144 LPCWSTR proplist
, REFIID riid
, void **ppv
)
146 return PSGetPropertyDescriptionListFromString(proplist
, riid
, ppv
);
149 static HRESULT WINAPI
propsys_EnumeratePropertyDescriptions(IPropertySystem
*iface
,
150 PROPDESC_ENUMFILTER filter
, REFIID riid
, void **ppv
)
152 FIXME("%d %s %p: stub\n", filter
, debugstr_guid(riid
), ppv
);
156 static HRESULT WINAPI
propsys_FormatForDisplay(IPropertySystem
*iface
,
157 REFPROPERTYKEY key
, REFPROPVARIANT propvar
, PROPDESC_FORMAT_FLAGS flags
,
158 LPWSTR dest
, DWORD destlen
)
160 FIXME("%p %p %x %p %d: stub\n", key
, propvar
, flags
, dest
, destlen
);
164 static HRESULT WINAPI
propsys_FormatForDisplayAlloc(IPropertySystem
*iface
,
165 REFPROPERTYKEY key
, REFPROPVARIANT propvar
, PROPDESC_FORMAT_FLAGS flags
,
168 FIXME("%p %p %x %p: stub\n", key
, propvar
, flags
, text
);
172 static HRESULT WINAPI
propsys_RegisterPropertySchema(IPropertySystem
*iface
, LPCWSTR path
)
174 return PSRegisterPropertySchema(path
);
177 static HRESULT WINAPI
propsys_UnregisterPropertySchema(IPropertySystem
*iface
, LPCWSTR path
)
179 return PSUnregisterPropertySchema(path
);
182 static HRESULT WINAPI
propsys_RefreshPropertySchema(IPropertySystem
*iface
)
184 return PSRefreshPropertySchema();
187 static const IPropertySystemVtbl propsysvtbl
= {
188 propsys_QueryInterface
,
191 propsys_GetPropertyDescription
,
192 propsys_GetPropertyDescriptionByName
,
193 propsys_GetPropertyDescriptionListFromString
,
194 propsys_EnumeratePropertyDescriptions
,
195 propsys_FormatForDisplay
,
196 propsys_FormatForDisplayAlloc
,
197 propsys_RegisterPropertySchema
,
198 propsys_UnregisterPropertySchema
,
199 propsys_RefreshPropertySchema
202 static IPropertySystem propsys
= { &propsysvtbl
};
204 HRESULT WINAPI
PSGetPropertySystem(REFIID riid
, void **obj
)
206 return IPropertySystem_QueryInterface(&propsys
, riid
, obj
);
209 HRESULT WINAPI
PSRegisterPropertySchema(PCWSTR path
)
211 FIXME("%s stub\n", debugstr_w(path
));
216 HRESULT WINAPI
PSUnregisterPropertySchema(PCWSTR path
)
218 FIXME("%s stub\n", debugstr_w(path
));
223 HRESULT WINAPI
PSGetPropertyDescription(REFPROPERTYKEY propkey
, REFIID riid
, void **ppv
)
225 FIXME("%p, %p, %p\n", propkey
, riid
, ppv
);
229 HRESULT WINAPI
PSGetPropertyDescriptionListFromString(LPCWSTR proplist
, REFIID riid
, void **ppv
)
231 FIXME("%s, %p, %p\n", debugstr_w(proplist
), riid
, ppv
);
235 HRESULT WINAPI
PSGetPropertyKeyFromName(PCWSTR name
, PROPERTYKEY
*key
)
237 FIXME("%s, %p\n", debugstr_w(name
), key
);
241 HRESULT WINAPI
PSRefreshPropertySchema(void)
247 HRESULT WINAPI
PSStringFromPropertyKey(REFPROPERTYKEY pkey
, LPWSTR psz
, UINT cch
)
249 WCHAR pidW
[PKEY_PIDSTR_MAX
+ 1];
253 TRACE("(%p, %p, %u)\n", pkey
, psz
, cch
);
258 /* GUIDSTRING_MAX accounts for null terminator, +1 for space character. */
259 if (cch
<= GUIDSTRING_MAX
+ 1)
260 return E_NOT_SUFFICIENT_BUFFER
;
265 return E_NOT_SUFFICIENT_BUFFER
;
268 swprintf(psz
, cch
, L
"{%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X}", pkey
->fmtid
.Data1
,
269 pkey
->fmtid
.Data2
, pkey
->fmtid
.Data3
, pkey
->fmtid
.Data4
[0], pkey
->fmtid
.Data4
[1],
270 pkey
->fmtid
.Data4
[2], pkey
->fmtid
.Data4
[3], pkey
->fmtid
.Data4
[4],
271 pkey
->fmtid
.Data4
[5], pkey
->fmtid
.Data4
[6], pkey
->fmtid
.Data4
[7]);
273 /* Overwrite the null terminator with the space character. */
274 p
+= GUIDSTRING_MAX
- 1;
276 cch
-= GUIDSTRING_MAX
- 1 + 1;
278 len
= swprintf(pidW
, ARRAY_SIZE(pidW
), L
"%u", pkey
->pid
);
287 WCHAR
*ptr
= pidW
+ len
- 1;
293 /* Replicate a quirk of the native implementation where the contents
294 * of the property ID string are written backwards to the output
295 * buffer, skipping the rightmost digit. */
303 return E_NOT_SUFFICIENT_BUFFER
;
307 static const BYTE hex2bin
[] =
309 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x00 */
310 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x10 */
311 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x20 */
312 0,1,2,3,4,5,6,7,8,9,0,0,0,0,0,0, /* 0x30 */
313 0,10,11,12,13,14,15,0,0,0,0,0,0,0,0,0, /* 0x40 */
314 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x50 */
315 0,10,11,12,13,14,15 /* 0x60 */
318 static BOOL
validate_indices(LPCWSTR s
, int min
, int max
)
322 for (i
= min
; i
<= max
; i
++)
332 else if (i
== 9 || i
== 14 || i
== 19 || i
== 24)
344 if (s
[i
] > 'f' || (!hex2bin
[s
[i
]] && s
[i
] != '0'))
352 /* Adapted from CLSIDFromString helper in dlls/ole32/compobj.c and
353 * UuidFromString in dlls/rpcrt4/rpcrt4_main.c. */
354 static BOOL
string_to_guid(LPCWSTR s
, LPGUID id
)
356 /* in form {XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX} */
358 if (!validate_indices(s
, 0, 8)) return FALSE
;
359 id
->Data1
= (hex2bin
[s
[1]] << 28 | hex2bin
[s
[2]] << 24 | hex2bin
[s
[3]] << 20 | hex2bin
[s
[4]] << 16 |
360 hex2bin
[s
[5]] << 12 | hex2bin
[s
[6]] << 8 | hex2bin
[s
[7]] << 4 | hex2bin
[s
[8]]);
361 if (!validate_indices(s
, 9, 14)) return FALSE
;
362 id
->Data2
= hex2bin
[s
[10]] << 12 | hex2bin
[s
[11]] << 8 | hex2bin
[s
[12]] << 4 | hex2bin
[s
[13]];
363 if (!validate_indices(s
, 15, 19)) return FALSE
;
364 id
->Data3
= hex2bin
[s
[15]] << 12 | hex2bin
[s
[16]] << 8 | hex2bin
[s
[17]] << 4 | hex2bin
[s
[18]];
366 /* these are just sequential bytes */
368 if (!validate_indices(s
, 20, 21)) return FALSE
;
369 id
->Data4
[0] = hex2bin
[s
[20]] << 4 | hex2bin
[s
[21]];
370 if (!validate_indices(s
, 22, 24)) return FALSE
;
371 id
->Data4
[1] = hex2bin
[s
[22]] << 4 | hex2bin
[s
[23]];
373 if (!validate_indices(s
, 25, 26)) return FALSE
;
374 id
->Data4
[2] = hex2bin
[s
[25]] << 4 | hex2bin
[s
[26]];
375 if (!validate_indices(s
, 27, 28)) return FALSE
;
376 id
->Data4
[3] = hex2bin
[s
[27]] << 4 | hex2bin
[s
[28]];
377 if (!validate_indices(s
, 29, 30)) return FALSE
;
378 id
->Data4
[4] = hex2bin
[s
[29]] << 4 | hex2bin
[s
[30]];
379 if (!validate_indices(s
, 31, 32)) return FALSE
;
380 id
->Data4
[5] = hex2bin
[s
[31]] << 4 | hex2bin
[s
[32]];
381 if (!validate_indices(s
, 33, 34)) return FALSE
;
382 id
->Data4
[6] = hex2bin
[s
[33]] << 4 | hex2bin
[s
[34]];
383 if (!validate_indices(s
, 35, 37)) return FALSE
;
384 id
->Data4
[7] = hex2bin
[s
[35]] << 4 | hex2bin
[s
[36]];
389 HRESULT WINAPI
PSPropertyKeyFromString(LPCWSTR pszString
, PROPERTYKEY
*pkey
)
391 BOOL has_minus
= FALSE
, has_comma
= FALSE
;
393 TRACE("(%s, %p)\n", debugstr_w(pszString
), pkey
);
395 if (!pszString
|| !pkey
)
398 memset(pkey
, 0, sizeof(PROPERTYKEY
));
400 if (!string_to_guid(pszString
, &pkey
->fmtid
))
403 pszString
+= GUIDSTRING_MAX
- 1;
408 /* Only the space seems to be recognized as whitespace. The comma is only
409 * recognized once and processing terminates if another comma is found. */
410 while (*pszString
== ' ' || *pszString
== ',')
412 if (*pszString
== ',')
425 /* Only two minus signs are recognized if no comma is detected. The first
426 * sign is ignored, and the second is interpreted. If a comma is detected
427 * before the minus sign, then only one minus sign counts, and property ID
428 * interpretation begins with the next character. */
431 if (*pszString
== '-')
439 if (*pszString
== '-')
442 /* Skip any intermediate spaces after the first minus sign. */
443 while (*pszString
== ' ')
446 if (*pszString
== '-')
452 /* Skip any remaining spaces after minus sign. */
453 while (*pszString
== ' ')
457 /* Overflow is not checked. */
458 while ('0' <= *pszString
&& *pszString
<= '9')
461 pkey
->pid
+= (*pszString
- '0');
466 pkey
->pid
= ~pkey
->pid
+ 1;
471 HRESULT WINAPI
PSCreateMemoryPropertyStore(REFIID riid
, void **ppv
)
473 TRACE("(%s, %p)\n", debugstr_guid(riid
), ppv
);
475 return PropertyStore_CreateInstance(NULL
, riid
, ppv
);