Changes in crossover-wine-src-6.1.0 except for configure
[wine/hacks.git] / dlls / pstorec / pstorec.c
blob1ae39bb31428ea98c9205768b5141aec09c3e2e6
1 /*
2 * Protected Storage (pstores)
4 * Copyright 2004 Mike McCormack for CodeWeavers
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #include <stdarg.h>
22 #include <stdio.h>
24 #define COBJMACROS
25 #include "windef.h"
26 #include "winbase.h"
27 #include "winreg.h"
28 #include "winerror.h"
29 #include "winuser.h"
30 #include "winnls.h"
31 #include "ole2.h"
32 #include "shlwapi.h"
34 #include "pstore.h"
36 #include "wine/unicode.h"
37 #include "wine/debug.h"
39 WINE_DEFAULT_DEBUG_CHANNEL(pstores);
41 typedef struct
43 const IPStoreVtbl *lpVtbl;
44 LONG ref;
45 } PStore_impl;
48 static const WCHAR szPStoresKey[] = {
49 'S','o','f','t','w','a','r','e','\\',
50 'W','i','n','e','\\','W','i','n','e','\\',
51 'p','s','t','o','r','e','s',0
54 /* convert a guid to a wide character string */
55 static void IPStore_guid2wstr( const GUID *guid, LPWSTR wstr )
57 char str[40];
59 sprintf(str, "{%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X}",
60 guid->Data1, guid->Data2, guid->Data3,
61 guid->Data4[0], guid->Data4[1], guid->Data4[2], guid->Data4[3],
62 guid->Data4[4], guid->Data4[5], guid->Data4[6], guid->Data4[7] );
63 MultiByteToWideChar( CP_ACP, 0, str, -1, wstr, 40 );
66 static LONG IPStore_OpenRoot( PST_KEY Key, HKEY *hkey )
68 switch( Key )
70 case PST_KEY_CURRENT_USER:
71 return RegCreateKeyW( HKEY_CURRENT_USER, szPStoresKey, hkey );
72 case PST_KEY_LOCAL_MACHINE:
73 return RegCreateKeyW( HKEY_LOCAL_MACHINE, szPStoresKey, hkey );
75 return ERROR_INVALID_PARAMETER;
78 /**************************************************************************
79 * IPStore->QueryInterface
81 static HRESULT WINAPI PStore_fnQueryInterface(
82 IPStore* iface,
83 REFIID riid,
84 LPVOID *ppvObj)
86 PStore_impl *This = (PStore_impl *)iface;
88 TRACE("(%p)->(\n\tIID:\t%s)\n",This,debugstr_guid(riid));
90 *ppvObj = NULL;
92 if (IsEqualIID(riid, &IID_IUnknown))
94 *ppvObj = This;
97 if (*ppvObj)
99 IUnknown_AddRef((IUnknown*)(*ppvObj));
100 return S_OK;
102 TRACE("-- Interface: E_NOINTERFACE\n");
103 return E_NOINTERFACE;
106 /******************************************************************************
107 * IPStore->AddRef
109 static ULONG WINAPI PStore_fnAddRef(IPStore* iface)
111 PStore_impl *This = (PStore_impl *)iface;
113 TRACE("%p %u\n", This, This->ref);
115 return InterlockedIncrement( &This->ref );
118 /******************************************************************************
119 * IPStore->Release
121 static ULONG WINAPI PStore_fnRelease(IPStore* iface)
123 PStore_impl *This = (PStore_impl *)iface;
124 LONG ref;
126 TRACE("%p %u\n", This, This->ref);
128 ref = InterlockedDecrement( &This->ref );
129 if( !ref )
130 HeapFree( GetProcessHeap(), 0, This );
132 return ref;
135 /******************************************************************************
136 * IPStore->GetInfo
138 static HRESULT WINAPI PStore_fnGetInfo( IPStore* iface, PPST_PROVIDERINFO* ppProperties)
140 FIXME("\n");
141 return E_FAIL;
144 /******************************************************************************
145 * IPStore->GetProvParam
147 static HRESULT WINAPI PStore_fnGetProvParam( IPStore* iface,
148 DWORD dwParam, DWORD* pcbData, BYTE** ppbData, DWORD dwFlags)
150 FIXME("\n");
151 return E_FAIL;
154 /******************************************************************************
155 * IPStore->SetProvParam
157 static HRESULT WINAPI PStore_fnSetProvParam( IPStore* This,
158 DWORD dwParam, DWORD cbData, BYTE* pbData, DWORD* dwFlags)
160 FIXME("\n");
161 return E_FAIL;
164 /******************************************************************************
165 * IPStore->CreateType
167 static HRESULT WINAPI PStore_fnCreateType( IPStore* This,
168 PST_KEY Key, const GUID* pType, PPST_TYPEINFO pInfo, DWORD dwFlags)
170 LONG r;
171 HKEY hkey, hkeytype;
172 WCHAR szGuid[40];
173 HRESULT hres = E_FAIL;
174 DWORD dwCreated = 0;
176 TRACE("%p %08x %s %p(%d,%s) %08x\n", This, Key, debugstr_guid(pType),
177 pInfo, pInfo->cbSize, debugstr_w(pInfo->szDisplayName), dwFlags);
179 r = IPStore_OpenRoot( Key, &hkey );
180 if( r )
181 return hres;
183 IPStore_guid2wstr( pType, szGuid );
184 r = RegCreateKeyExW( hkey, szGuid, 0, NULL, REG_OPTION_NON_VOLATILE,
185 KEY_ALL_ACCESS, NULL, &hkeytype, &dwCreated );
186 if( r == ERROR_SUCCESS )
188 if( dwCreated == REG_CREATED_NEW_KEY )
190 r = RegSetValueW( hkeytype, NULL, REG_SZ,
191 pInfo->szDisplayName, strlenW( pInfo->szDisplayName ) );
192 if( r == ERROR_SUCCESS )
193 hres = PST_E_OK;
194 RegCloseKey( hkeytype );
196 else
197 hres = PST_E_TYPE_EXISTS;
199 RegCloseKey( hkey );
201 return hres;
204 /******************************************************************************
205 * IPStore->GetTypeInfo
207 static HRESULT WINAPI PStore_fnGetTypeInfo( IPStore* This,
208 PST_KEY Key, const GUID* pType, PPST_TYPEINFO** ppInfo, DWORD dwFlags)
210 FIXME("\n");
211 return E_FAIL;
214 /******************************************************************************
215 * IPStore->DeleteType
217 static HRESULT WINAPI PStore_fnDeleteType( IPStore* This,
218 PST_KEY Key, const GUID* pType, DWORD dwFlags)
220 LONG r;
221 HKEY hkey;
222 WCHAR szGuid[40];
223 HRESULT hres = E_FAIL;
225 TRACE("%p %d %s %08x\n", This, Key, debugstr_guid(pType), dwFlags);
227 r = IPStore_OpenRoot( Key, &hkey );
228 if( r )
229 return hres;
231 IPStore_guid2wstr( pType, szGuid );
232 r = SHDeleteKeyW( hkey, szGuid );
233 if( r == ERROR_SUCCESS )
234 hres = PST_E_OK;
235 RegCloseKey( hkey );
237 return hres;
240 /******************************************************************************
241 * IPStore->CreateSubtype
243 static HRESULT WINAPI PStore_fnCreateSubtype( IPStore* This,
244 PST_KEY Key, const GUID* pType, const GUID* pSubtype,
245 PPST_TYPEINFO pInfo, PPST_ACCESSRULESET pRules, DWORD dwFlags)
247 LONG r;
248 HKEY hkey, hkeysubtype;
249 WCHAR szGuid[80];
250 HRESULT hres = E_FAIL;
251 DWORD dwCreated = 0;
253 TRACE("%p %08x %s %s %p %p %08x\n", This, Key, debugstr_guid(pType),
254 debugstr_guid(pSubtype), pInfo, pRules, dwFlags);
256 r = IPStore_OpenRoot( Key, &hkey );
257 if( r )
258 return E_FAIL;
260 IPStore_guid2wstr( pType, szGuid );
261 szGuid[38] = '\\';
262 IPStore_guid2wstr( pSubtype, &szGuid[39] );
263 r = RegCreateKeyExW( hkey, szGuid, 0, NULL, REG_OPTION_NON_VOLATILE,
264 KEY_ALL_ACCESS, NULL, &hkeysubtype, &dwCreated );
265 if( r == ERROR_SUCCESS )
267 if( dwCreated == REG_CREATED_NEW_KEY )
269 r = RegSetValueW( hkeysubtype, NULL, REG_SZ,
270 pInfo->szDisplayName, strlenW( pInfo->szDisplayName ) );
271 if( r == ERROR_SUCCESS )
272 hres = S_OK;
273 RegCloseKey( hkeysubtype );
275 else
276 hres = PST_E_TYPE_EXISTS;
278 RegCloseKey( hkey );
280 return hres;
283 /******************************************************************************
284 * IPStore->GetSubtypeInfo
286 static HRESULT WINAPI PStore_fnGetSubtypeInfo( IPStore* This,
287 PST_KEY Key, const GUID* pType, const GUID* pSubtype,
288 PPST_TYPEINFO** ppInfo, DWORD dwFlags)
290 FIXME("\n");
291 return E_FAIL;
294 /******************************************************************************
295 * IPStore->DeleteSubtype
297 static HRESULT WINAPI PStore_fnDeleteSubtype( IPStore* This,
298 PST_KEY Key, const GUID* pType, const GUID* pSubtype, DWORD dwFlags)
300 LONG r;
301 HKEY hkey, hkeytype;
302 WCHAR szGuid[40];
303 HRESULT hres = E_FAIL;
305 TRACE("%p %u %s %s %08x\n", This, Key,
306 debugstr_guid(pType), debugstr_guid(pSubtype), dwFlags);
308 r = IPStore_OpenRoot( Key, &hkey );
309 if( r )
310 return hres;
312 IPStore_guid2wstr( pType, szGuid );
313 r = RegOpenKeyW( hkey, szGuid, &hkeytype );
314 if( r == ERROR_SUCCESS )
316 IPStore_guid2wstr( pSubtype, szGuid );
317 r = SHDeleteKeyW( hkeytype, szGuid );
318 if( r == ERROR_SUCCESS )
319 hres = PST_E_OK;
320 RegCloseKey( hkeytype );
322 RegCloseKey( hkey );
324 return hres;
327 /******************************************************************************
328 * IPStore->ReadAccessRuleset
330 static HRESULT WINAPI PStore_fnReadAccessRuleset( IPStore* This,
331 PST_KEY Key, const GUID* pType, const GUID* pSubtype, PPST_TYPEINFO pInfo,
332 PPST_ACCESSRULESET** ppRules, DWORD dwFlags)
334 FIXME("\n");
335 return E_FAIL;
338 /******************************************************************************
339 * IPStore->WriteAccessRuleSet
341 static HRESULT WINAPI PStore_fnWriteAccessRuleset( IPStore* This,
342 PST_KEY Key, const GUID* pType, const GUID* pSubtype,
343 PPST_TYPEINFO pInfo, PPST_ACCESSRULESET pRules, DWORD dwFlags)
345 FIXME("\n");
346 return E_FAIL;
349 /******************************************************************************
350 * IPStore->EnumTypes
352 static HRESULT WINAPI PStore_fnEnumTypes( IPStore* This, PST_KEY Key,
353 DWORD dwFlags, IEnumPStoreTypes** ppenum)
355 FIXME("\n");
356 return E_FAIL;
359 /******************************************************************************
360 * IPStore->EnumSubtypes
362 static HRESULT WINAPI PStore_fnEnumSubtypes( IPStore* This, PST_KEY Key,
363 const GUID* pType, DWORD dwFlags, IEnumPStoreTypes** ppenum)
365 FIXME("\n");
366 return E_FAIL;
369 /******************************************************************************
370 * IPStore->DeleteItem
372 static HRESULT WINAPI PStore_fnDeleteItem( IPStore* This, PST_KEY Key,
373 const GUID* pItemType, const GUID* pItemSubType, LPCWSTR szItemName,
374 PPST_PROMPTINFO pPromptInfo, DWORD dwFlags)
376 FIXME("\n");
377 return E_FAIL;
380 /******************************************************************************
381 * IPStore->ReadItem
383 static HRESULT WINAPI PStore_fnReadItem( IPStore* This, PST_KEY Key,
384 const GUID* pItemType, const GUID* pItemSubtype, LPCWSTR szItemName,
385 DWORD *cbData, BYTE** pbData, PPST_PROMPTIFO pPromptInfo, DWORD dwFlags)
387 LONG r;
388 HKEY hkey, hkeysubtype;
389 WCHAR szGuid[80];
390 DWORD type, sz = 0;
392 TRACE("%p %08x %s %s %s %p %p %p %08x\n", This, Key,
393 debugstr_guid(pItemType), debugstr_guid(pItemSubtype),
394 debugstr_w(szItemName), cbData, pbData, pPromptInfo, dwFlags);
396 *pbData = NULL;
397 *cbData = 0;
399 r = IPStore_OpenRoot( Key, &hkey );
400 if( r )
401 return E_FAIL;
403 IPStore_guid2wstr( pItemType, szGuid );
404 szGuid[38] = '\\';
405 IPStore_guid2wstr( pItemSubtype, &szGuid[39] );
406 r = RegOpenKeyW( hkey, szGuid, &hkeysubtype );
407 if( r == ERROR_SUCCESS )
409 type = 0;
410 sz = 0;
411 r = RegQueryValueExW( hkeysubtype, szItemName, NULL, &type,
412 NULL, cbData );
413 if( ( r == ERROR_SUCCESS ) && ( type == REG_BINARY ) )
415 *pbData = CoTaskMemAlloc( *cbData );
416 r = RegQueryValueExW( hkeysubtype, szItemName, NULL, &type,
417 *pbData, cbData );
419 RegCloseKey( hkeysubtype );
422 RegCloseKey( hkey );
424 return ( r == ERROR_SUCCESS ) ? S_OK : E_FAIL;
427 /******************************************************************************
428 * IPStore->WriteItem
430 static HRESULT WINAPI PStore_fnWriteItem( IPStore* This, PST_KEY Key,
431 const GUID* pItemType, const GUID* pItemSubtype, LPCWSTR szItemName,
432 DWORD cbData, BYTE* ppbData, PPST_PROMPTIFO pPromptInfo,
433 DWORD dwDefaultConfirmationStyle, DWORD dwFlags)
435 LONG r;
436 HKEY hkey, hkeysubtype;
437 WCHAR szGuid[80];
439 TRACE("%p %08x %s %s %s %d %p %p %08x\n", This, Key,
440 debugstr_guid(pItemType), debugstr_guid(pItemSubtype),
441 debugstr_w(szItemName), cbData, ppbData, pPromptInfo, dwFlags);
443 r = IPStore_OpenRoot( Key, &hkey );
444 if( r )
445 return E_FAIL;
447 IPStore_guid2wstr( pItemType, szGuid );
448 szGuid[38] = '\\';
449 IPStore_guid2wstr( pItemSubtype, &szGuid[39] );
450 r = RegOpenKeyW( hkey, szGuid, &hkeysubtype );
451 if( r == ERROR_SUCCESS )
453 r = RegSetValueExW( hkeysubtype, szItemName, 0, REG_BINARY,
454 ppbData, cbData );
455 RegCloseKey( hkeysubtype );
458 RegCloseKey( hkey );
460 return ( r == ERROR_SUCCESS ) ? S_OK : E_FAIL;
463 /******************************************************************************
464 * IPStore->OpenItem
466 static HRESULT WINAPI PStore_fnOpenItem( IPStore* This, PST_KEY Key,
467 const GUID* pItemType, const GUID* pItemSubtype, LPCWSTR szItemName,
468 PST_ACCESSMODE ModeFlags, PPST_PROMPTIFO pProomptInfo, DWORD dwFlags )
470 LONG r;
471 HKEY hkey, hkeysubtype;
472 WCHAR szGuid[80];
474 TRACE("%p %08x %s %s %p %08x %p %08x\n", This, Key,
475 debugstr_guid(pItemType), debugstr_guid(pItemSubtype),
476 debugstr_w(szItemName), ModeFlags, pProomptInfo, dwFlags);
478 r = IPStore_OpenRoot( Key, &hkey );
479 if( r )
480 return E_FAIL;
482 IPStore_guid2wstr( pItemType, szGuid );
483 szGuid[38] = '\\';
484 IPStore_guid2wstr( pItemSubtype, &szGuid[39] );
485 r = RegOpenKeyW( hkey, szGuid, &hkeysubtype );
486 if( r == ERROR_SUCCESS )
488 DWORD type;
490 r = RegQueryValueExW( hkeysubtype, szItemName, NULL, &type,
491 NULL, NULL );
492 if( ( r == ERROR_SUCCESS ) && ( type != REG_BINARY ) )
493 r = ERROR_INVALID_DATA;
495 RegCloseKey( hkeysubtype );
498 RegCloseKey( hkey );
500 return ( r == ERROR_SUCCESS ) ? S_OK : E_FAIL;
503 /******************************************************************************
504 * IPStore->CloseItem
506 static HRESULT WINAPI PStore_fnCloseItem( IPStore* This, PST_KEY Key,
507 const GUID* pItemType, const GUID* pItemSubtype, LPCWSTR* szItemName,
508 DWORD dwFlags)
510 TRACE("\n");
511 return S_OK;
514 /******************************************************************************
515 * IPStore->EnumItems
517 static HRESULT WINAPI PStore_fnEnumItems( IPStore* This, PST_KEY Key,
518 const GUID* pItemType, const GUID* pItemSubtype, DWORD dwFlags,
519 IEnumPStoreItems** ppenum)
521 FIXME("\n");
522 return E_FAIL;
526 static const IPStoreVtbl pstores_vtbl =
528 PStore_fnQueryInterface,
529 PStore_fnAddRef,
530 PStore_fnRelease,
531 PStore_fnGetInfo,
532 PStore_fnGetProvParam,
533 PStore_fnSetProvParam,
534 PStore_fnCreateType,
535 PStore_fnGetTypeInfo,
536 PStore_fnDeleteType,
537 PStore_fnCreateSubtype,
538 PStore_fnGetSubtypeInfo,
539 PStore_fnDeleteSubtype,
540 PStore_fnReadAccessRuleset,
541 PStore_fnWriteAccessRuleset,
542 PStore_fnEnumTypes,
543 PStore_fnEnumSubtypes,
544 PStore_fnDeleteItem,
545 PStore_fnReadItem,
546 PStore_fnWriteItem,
547 PStore_fnOpenItem,
548 PStore_fnCloseItem,
549 PStore_fnEnumItems
552 HRESULT WINAPI PStoreCreateInstance( IPStore** ppProvider,
553 PST_PROVIDERID* pProviderID, void* pReserved, DWORD dwFlags)
555 PStore_impl *ips;
557 TRACE("%p %s %p %08x\n", ppProvider, debugstr_guid(pProviderID), pReserved, dwFlags);
559 ips = HeapAlloc( GetProcessHeap(), 0, sizeof (PStore_impl) );
560 if( !ips )
561 return E_OUTOFMEMORY;
563 ips->lpVtbl = &pstores_vtbl;
564 ips->ref = 1;
566 *ppProvider = (IPStore*) ips;
568 return S_OK;
571 HRESULT WINAPI DllRegisterServer(void)
573 FIXME("stub\n");
574 return S_OK;
577 HRESULT WINAPI DllUnregisterServer(void)
579 FIXME("stub\n");
580 return S_OK;
583 /***********************************************************************
584 * DllGetClassObject (PSTOREC.@)
586 HRESULT WINAPI DllGetClassObject(REFCLSID rclsid, REFIID iid, LPVOID *ppv)
588 FIXME("(%s,%s,%p) stub\n", debugstr_guid(rclsid), debugstr_guid(iid), ppv);
589 return CLASS_E_CLASSNOTAVAILABLE;
592 HRESULT WINAPI DllCanUnloadNow(void)
594 return S_FALSE;