winemaker: Use utf-8 for stdout.
[wine.git] / dlls / propsys / propsys_main.c
blobce9131b209df39cbc0102d1c5d495c14e399a0dc
1 /*
2 * propsys main
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
22 #define COBJMACROS
23 #include "config.h"
25 #include <stdarg.h>
27 #include "windef.h"
28 #include "winbase.h"
29 #include "objbase.h"
30 #include "rpcproxy.h"
31 #include "propsys.h"
32 #include "wine/debug.h"
33 #include "wine/unicode.h"
35 #include "propsys_private.h"
37 WINE_DEFAULT_DEBUG_CHANNEL(propsys);
39 static HINSTANCE propsys_hInstance;
41 BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
43 TRACE("(0x%p, %d, %p)\n", hinstDLL, fdwReason, lpvReserved);
45 switch (fdwReason)
47 case DLL_WINE_PREATTACH:
48 return FALSE; /* prefer native version */
49 case DLL_PROCESS_ATTACH:
50 propsys_hInstance = hinstDLL;
51 DisableThreadLibraryCalls(hinstDLL);
52 break;
55 return TRUE;
58 HRESULT WINAPI DllRegisterServer(void)
60 return __wine_register_resources( propsys_hInstance );
63 HRESULT WINAPI DllUnregisterServer(void)
65 return __wine_unregister_resources( propsys_hInstance );
68 static HRESULT WINAPI ClassFactory_QueryInterface(IClassFactory *iface, REFIID riid, void **ppv)
70 *ppv = NULL;
72 if(IsEqualGUID(&IID_IUnknown, riid)) {
73 TRACE("(%p)->(IID_IUnknown %p)\n", iface, ppv);
74 *ppv = iface;
75 }else if(IsEqualGUID(&IID_IClassFactory, riid)) {
76 TRACE("(%p)->(IID_IClassFactory %p)\n", iface, ppv);
77 *ppv = iface;
80 if(*ppv) {
81 IUnknown_AddRef((IUnknown*)*ppv);
82 return S_OK;
85 FIXME("(%p)->(%s %p)\n", iface, debugstr_guid(riid), ppv);
86 return E_NOINTERFACE;
89 static ULONG WINAPI ClassFactory_AddRef(IClassFactory *iface)
91 TRACE("(%p)\n", iface);
92 return 2;
95 static ULONG WINAPI ClassFactory_Release(IClassFactory *iface)
97 TRACE("(%p)\n", iface);
98 return 1;
101 static HRESULT WINAPI ClassFactory_LockServer(IClassFactory *iface, BOOL fLock)
103 TRACE("(%p)->(%x)\n", iface, fLock);
105 return S_OK;
108 static HRESULT WINAPI InMemoryPropertyStoreFactory_CreateInstance(IClassFactory *iface, IUnknown *outer,
109 REFIID riid, void **ppv)
111 TRACE("(%p %s %p)\n", outer, debugstr_guid(riid), ppv);
113 return PropertyStore_CreateInstance(outer, riid, ppv);
116 static const IClassFactoryVtbl InMemoryPropertyStoreFactoryVtbl = {
117 ClassFactory_QueryInterface,
118 ClassFactory_AddRef,
119 ClassFactory_Release,
120 InMemoryPropertyStoreFactory_CreateInstance,
121 ClassFactory_LockServer
124 static IClassFactory InMemoryPropertyStoreFactory = { &InMemoryPropertyStoreFactoryVtbl };
126 HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID *ppv)
128 if(IsEqualGUID(&CLSID_InMemoryPropertyStore, rclsid)) {
129 TRACE("(CLSID_InMemoryPropertyStore %s %p)\n", debugstr_guid(riid), ppv);
130 return IClassFactory_QueryInterface(&InMemoryPropertyStoreFactory, riid, ppv);
133 FIXME("%s %s %p\n", debugstr_guid(rclsid), debugstr_guid(riid), ppv);
134 return CLASS_E_CLASSNOTAVAILABLE;
137 HRESULT WINAPI DllCanUnloadNow(void)
139 return S_FALSE;
142 HRESULT WINAPI PSRegisterPropertySchema(PCWSTR path)
144 FIXME("%s stub\n", debugstr_w(path));
146 return S_OK;
149 HRESULT WINAPI PSUnregisterPropertySchema(PCWSTR path)
151 FIXME("%s stub\n", debugstr_w(path));
153 return E_NOTIMPL;
156 HRESULT WINAPI PSGetPropertyDescription(REFPROPERTYKEY propkey, REFIID riid, void **ppv)
158 FIXME("%p, %p, %p\n", propkey, riid, ppv);
159 return E_NOTIMPL;
162 HRESULT WINAPI PSRefreshPropertySchema(void)
164 FIXME("\n");
165 return S_OK;
168 HRESULT WINAPI PSStringFromPropertyKey(REFPROPERTYKEY pkey, LPWSTR psz, UINT cch)
170 static const WCHAR guid_fmtW[] = {'{','%','0','8','X','-','%','0','4','X','-',
171 '%','0','4','X','-','%','0','2','X','%','0','2','X','-',
172 '%','0','2','X','%','0','2','X','%','0','2','X',
173 '%','0','2','X','%','0','2','X','%','0','2','X','}',0};
174 static const WCHAR pid_fmtW[] = {'%','u',0};
176 WCHAR pidW[PKEY_PIDSTR_MAX + 1];
177 LPWSTR p = psz;
178 int len;
180 TRACE("(%p, %p, %u)\n", pkey, psz, cch);
182 if (!psz)
183 return E_POINTER;
185 /* GUIDSTRING_MAX accounts for null terminator, +1 for space character. */
186 if (cch <= GUIDSTRING_MAX + 1)
187 return HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER);
189 if (!pkey)
191 psz[0] = '\0';
192 return HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER);
195 sprintfW(psz, guid_fmtW, pkey->fmtid.Data1, pkey->fmtid.Data2,
196 pkey->fmtid.Data3, pkey->fmtid.Data4[0], pkey->fmtid.Data4[1],
197 pkey->fmtid.Data4[2], pkey->fmtid.Data4[3], pkey->fmtid.Data4[4],
198 pkey->fmtid.Data4[5], pkey->fmtid.Data4[6], pkey->fmtid.Data4[7]);
200 /* Overwrite the null terminator with the space character. */
201 p += GUIDSTRING_MAX - 1;
202 *p++ = ' ';
203 cch -= GUIDSTRING_MAX - 1 + 1;
205 len = sprintfW(pidW, pid_fmtW, pkey->pid);
207 if (cch >= len + 1)
209 strcpyW(p, pidW);
210 return S_OK;
212 else
214 WCHAR *ptr = pidW + len - 1;
216 psz[0] = '\0';
217 *p++ = '\0';
218 cch--;
220 /* Replicate a quirk of the native implementation where the contents
221 * of the property ID string are written backwards to the output
222 * buffer, skipping the rightmost digit. */
223 if (cch)
225 ptr--;
226 while (cch--)
227 *p++ = *ptr--;
230 return HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER);
234 static const BYTE hex2bin[] =
236 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x00 */
237 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x10 */
238 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x20 */
239 0,1,2,3,4,5,6,7,8,9,0,0,0,0,0,0, /* 0x30 */
240 0,10,11,12,13,14,15,0,0,0,0,0,0,0,0,0, /* 0x40 */
241 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 0x50 */
242 0,10,11,12,13,14,15 /* 0x60 */
245 static BOOL validate_indices(LPCWSTR s, int min, int max)
247 int i;
249 for (i = min; i <= max; i++)
251 if (!s[i])
252 return FALSE;
254 if (i == 0)
256 if (s[i] != '{')
257 return FALSE;
259 else if (i == 9 || i == 14 || i == 19 || i == 24)
261 if (s[i] != '-')
262 return FALSE;
264 else if (i == 37)
266 if (s[i] != '}')
267 return FALSE;
269 else
271 if (s[i] > 'f' || (!hex2bin[s[i]] && s[i] != '0'))
272 return FALSE;
276 return TRUE;
279 /* Adapted from CLSIDFromString helper in dlls/ole32/compobj.c and
280 * UuidFromString in dlls/rpcrt4/rpcrt4_main.c. */
281 static BOOL string_to_guid(LPCWSTR s, LPGUID id)
283 /* in form {XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX} */
285 if (!validate_indices(s, 0, 8)) return FALSE;
286 id->Data1 = (hex2bin[s[1]] << 28 | hex2bin[s[2]] << 24 | hex2bin[s[3]] << 20 | hex2bin[s[4]] << 16 |
287 hex2bin[s[5]] << 12 | hex2bin[s[6]] << 8 | hex2bin[s[7]] << 4 | hex2bin[s[8]]);
288 if (!validate_indices(s, 9, 14)) return FALSE;
289 id->Data2 = hex2bin[s[10]] << 12 | hex2bin[s[11]] << 8 | hex2bin[s[12]] << 4 | hex2bin[s[13]];
290 if (!validate_indices(s, 15, 19)) return FALSE;
291 id->Data3 = hex2bin[s[15]] << 12 | hex2bin[s[16]] << 8 | hex2bin[s[17]] << 4 | hex2bin[s[18]];
293 /* these are just sequential bytes */
295 if (!validate_indices(s, 20, 21)) return FALSE;
296 id->Data4[0] = hex2bin[s[20]] << 4 | hex2bin[s[21]];
297 if (!validate_indices(s, 22, 24)) return FALSE;
298 id->Data4[1] = hex2bin[s[22]] << 4 | hex2bin[s[23]];
300 if (!validate_indices(s, 25, 26)) return FALSE;
301 id->Data4[2] = hex2bin[s[25]] << 4 | hex2bin[s[26]];
302 if (!validate_indices(s, 27, 28)) return FALSE;
303 id->Data4[3] = hex2bin[s[27]] << 4 | hex2bin[s[28]];
304 if (!validate_indices(s, 29, 30)) return FALSE;
305 id->Data4[4] = hex2bin[s[29]] << 4 | hex2bin[s[30]];
306 if (!validate_indices(s, 31, 32)) return FALSE;
307 id->Data4[5] = hex2bin[s[31]] << 4 | hex2bin[s[32]];
308 if (!validate_indices(s, 33, 34)) return FALSE;
309 id->Data4[6] = hex2bin[s[33]] << 4 | hex2bin[s[34]];
310 if (!validate_indices(s, 35, 37)) return FALSE;
311 id->Data4[7] = hex2bin[s[35]] << 4 | hex2bin[s[36]];
313 return TRUE;
316 HRESULT WINAPI PSPropertyKeyFromString(LPCWSTR pszString, PROPERTYKEY *pkey)
318 int has_minus = 0, has_comma = 0;
320 TRACE("(%s, %p)\n", debugstr_w(pszString), pkey);
322 if (!pszString || !pkey)
323 return E_POINTER;
325 memset(pkey, 0, sizeof(PROPERTYKEY));
327 if (!string_to_guid(pszString, &pkey->fmtid))
328 return E_INVALIDARG;
330 pszString += GUIDSTRING_MAX - 1;
332 if (!*pszString)
333 return E_INVALIDARG;
335 /* Only the space seems to be recognized as whitespace. The comma is only
336 * recognized once and processing terminates if another comma is found. */
337 while (*pszString == ' ' || *pszString == ',')
339 if (*pszString == ',')
341 if (has_comma)
342 return S_OK;
343 else
344 has_comma = 1;
346 pszString++;
349 if (!*pszString)
350 return E_INVALIDARG;
352 /* Only two minus signs are recognized if no comma is detected. The first
353 * sign is ignored, and the second is interpreted. If a comma is detected
354 * before the minus sign, then only one minus sign counts, and property ID
355 * interpretation begins with the next character. */
356 if (has_comma)
358 if (*pszString == '-')
360 has_minus = 1;
361 pszString++;
364 else
366 if (*pszString == '-')
367 pszString++;
369 /* Skip any intermediate spaces after the first minus sign. */
370 while (*pszString == ' ')
371 pszString++;
373 if (*pszString == '-')
375 has_minus = 1;
376 pszString++;
379 /* Skip any remaining spaces after minus sign. */
380 while (*pszString == ' ')
381 pszString++;
384 /* Overflow is not checked. */
385 while (isdigitW(*pszString))
387 pkey->pid *= 10;
388 pkey->pid += (*pszString - '0');
389 pszString++;
392 if (has_minus)
393 pkey->pid = ~pkey->pid + 1;
395 return S_OK;