mf/topoloader: Move node connection responsibility to connection function.
[wine/zf.git] / dlls / sapi / token.c
blob04fa3a25d6a4050201dc05984c471cfb0270a0ca
1 /*
2 * Speech API (SAPI) token implementation.
4 * Copyright (C) 2017 Huw Davies
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>
23 #define COBJMACROS
25 #include "windef.h"
26 #include "winbase.h"
27 #include "objbase.h"
28 #include "sapiddk.h"
29 #include "sperror.h"
31 #include "wine/debug.h"
33 #include "sapi_private.h"
35 WINE_DEFAULT_DEBUG_CHANNEL(sapi);
37 struct data_key
39 ISpRegDataKey ISpRegDataKey_iface;
40 LONG ref;
42 HKEY key;
43 BOOL read_only;
46 static struct data_key *impl_from_ISpRegDataKey( ISpRegDataKey *iface )
48 return CONTAINING_RECORD( iface, struct data_key, ISpRegDataKey_iface );
51 static HRESULT WINAPI data_key_QueryInterface( ISpRegDataKey *iface, REFIID iid, void **obj )
53 struct data_key *This = impl_from_ISpRegDataKey( iface );
55 TRACE( "(%p)->(%s %p)\n", This, debugstr_guid( iid ), obj );
57 if (IsEqualIID( iid, &IID_IUnknown ) ||
58 IsEqualIID( iid, &IID_ISpDataKey ) ||
59 IsEqualIID( iid, &IID_ISpRegDataKey ))
61 ISpRegDataKey_AddRef( iface );
62 *obj = iface;
63 return S_OK;
66 FIXME( "interface %s not implemented\n", debugstr_guid( iid ) );
67 *obj = NULL;
68 return E_NOINTERFACE;
71 static ULONG WINAPI data_key_AddRef( ISpRegDataKey *iface )
73 struct data_key *This = impl_from_ISpRegDataKey( iface );
74 ULONG ref = InterlockedIncrement( &This->ref );
76 TRACE( "(%p) ref = %u\n", This, ref );
77 return ref;
80 static ULONG WINAPI data_key_Release( ISpRegDataKey *iface )
82 struct data_key *This = impl_from_ISpRegDataKey( iface );
83 ULONG ref = InterlockedDecrement(&This->ref);
85 TRACE( "(%p) ref = %u\n", This, ref );
87 if (!ref)
89 if (This->key) RegCloseKey( This->key );
90 heap_free( This );
93 return ref;
96 static HRESULT WINAPI data_key_SetData( ISpRegDataKey *iface, LPCWSTR name,
97 ULONG size, const BYTE *data )
99 FIXME( "stub\n" );
100 return E_NOTIMPL;
103 static HRESULT WINAPI data_key_GetData( ISpRegDataKey *iface, LPCWSTR name,
104 ULONG *size, BYTE *data )
106 FIXME( "stub\n" );
107 return E_NOTIMPL;
110 static HRESULT WINAPI data_key_SetStringValue( ISpRegDataKey *iface,
111 LPCWSTR name, LPCWSTR value )
113 FIXME( "stub\n" );
114 return E_NOTIMPL;
117 static HRESULT WINAPI data_key_GetStringValue( ISpRegDataKey *iface,
118 LPCWSTR name, LPWSTR *value )
120 FIXME( "stub\n" );
121 return E_NOTIMPL;
124 static HRESULT WINAPI data_key_SetDWORD( ISpRegDataKey *iface,
125 LPCWSTR name, DWORD value )
127 FIXME( "stub\n" );
128 return E_NOTIMPL;
131 static HRESULT WINAPI data_key_GetDWORD( ISpRegDataKey *iface,
132 LPCWSTR name, DWORD *pdwValue )
134 FIXME( "stub\n" );
135 return E_NOTIMPL;
138 static HRESULT WINAPI data_key_OpenKey( ISpRegDataKey *iface,
139 LPCWSTR name, ISpDataKey **sub_key )
141 FIXME( "stub\n" );
142 return E_NOTIMPL;
145 static HRESULT WINAPI data_key_CreateKey( ISpRegDataKey *iface,
146 LPCWSTR name, ISpDataKey **sub_key )
148 FIXME( "stub\n" );
149 return E_NOTIMPL;
152 static HRESULT WINAPI data_key_DeleteKey( ISpRegDataKey *iface, LPCWSTR name )
154 FIXME( "stub\n" );
155 return E_NOTIMPL;
158 static HRESULT WINAPI data_key_DeleteValue( ISpRegDataKey *iface, LPCWSTR name )
160 FIXME( "stub\n" );
161 return E_NOTIMPL;
164 static HRESULT WINAPI data_key_EnumKeys( ISpRegDataKey *iface,
165 ULONG index, LPWSTR *sub_key )
167 FIXME( "stub\n" );
168 return E_NOTIMPL;
171 static HRESULT WINAPI data_key_EnumValues( ISpRegDataKey *iface,
172 ULONG index, LPWSTR *value )
174 FIXME( "stub\n" );
175 return E_NOTIMPL;
178 static HRESULT WINAPI data_key_SetKey( ISpRegDataKey *iface,
179 HKEY key, BOOL read_only )
181 struct data_key *This = impl_from_ISpRegDataKey( iface );
183 TRACE( "(%p)->(%p %d)\n", This, key, read_only );
185 if (This->key) return SPERR_ALREADY_INITIALIZED;
187 This->key = key;
188 This->read_only = read_only;
189 return S_OK;
192 const struct ISpRegDataKeyVtbl data_key_vtbl =
194 data_key_QueryInterface,
195 data_key_AddRef,
196 data_key_Release,
197 data_key_SetData,
198 data_key_GetData,
199 data_key_SetStringValue,
200 data_key_GetStringValue,
201 data_key_SetDWORD,
202 data_key_GetDWORD,
203 data_key_OpenKey,
204 data_key_CreateKey,
205 data_key_DeleteKey,
206 data_key_DeleteValue,
207 data_key_EnumKeys,
208 data_key_EnumValues,
209 data_key_SetKey
212 HRESULT data_key_create( IUnknown *outer, REFIID iid, void **obj )
214 struct data_key *This = heap_alloc( sizeof(*This) );
215 HRESULT hr;
217 if (!This) return E_OUTOFMEMORY;
218 This->ISpRegDataKey_iface.lpVtbl = &data_key_vtbl;
219 This->ref = 1;
220 This->key = NULL;
221 This->read_only = FALSE;
223 hr = ISpRegDataKey_QueryInterface( &This->ISpRegDataKey_iface, iid, obj );
225 ISpRegDataKey_Release( &This->ISpRegDataKey_iface );
226 return hr;
229 struct token_category
231 ISpObjectTokenCategory ISpObjectTokenCategory_iface;
232 LONG ref;
234 ISpRegDataKey *data_key;
237 static struct token_category *impl_from_ISpObjectTokenCategory( ISpObjectTokenCategory *iface )
239 return CONTAINING_RECORD( iface, struct token_category, ISpObjectTokenCategory_iface );
242 static HRESULT WINAPI token_category_QueryInterface( ISpObjectTokenCategory *iface,
243 REFIID iid, void **obj )
245 struct token_category *This = impl_from_ISpObjectTokenCategory( iface );
247 TRACE( "(%p)->(%s %p)\n", This, debugstr_guid( iid ), obj );
249 if (IsEqualIID( iid, &IID_IUnknown ) ||
250 IsEqualIID( iid, &IID_ISpDataKey ) ||
251 IsEqualIID( iid, &IID_ISpObjectTokenCategory ))
253 ISpObjectTokenCategory_AddRef( iface );
254 *obj = iface;
255 return S_OK;
258 FIXME( "interface %s not implemented\n", debugstr_guid( iid ) );
259 *obj = NULL;
260 return E_NOINTERFACE;
263 static ULONG WINAPI token_category_AddRef( ISpObjectTokenCategory *iface )
265 struct token_category *This = impl_from_ISpObjectTokenCategory( iface );
266 ULONG ref = InterlockedIncrement( &This->ref );
268 TRACE( "(%p) ref = %u\n", This, ref );
269 return ref;
272 static ULONG WINAPI token_category_Release( ISpObjectTokenCategory *iface )
274 struct token_category *This = impl_from_ISpObjectTokenCategory( iface );
275 ULONG ref = InterlockedDecrement(&This->ref);
277 TRACE( "(%p) ref = %u\n", This, ref );
279 if (!ref)
281 if (This->data_key) ISpRegDataKey_Release( This->data_key );
282 heap_free( This );
284 return ref;
287 static HRESULT WINAPI token_category_SetData( ISpObjectTokenCategory *iface,
288 LPCWSTR name, ULONG size,
289 const BYTE *data )
291 FIXME( "stub\n" );
292 return E_NOTIMPL;
295 static HRESULT WINAPI token_category_GetData( ISpObjectTokenCategory *iface,
296 LPCWSTR name, ULONG *size,
297 BYTE *data )
299 FIXME( "stub\n" );
300 return E_NOTIMPL;
303 static HRESULT WINAPI token_category_SetStringValue( ISpObjectTokenCategory *iface,
304 LPCWSTR name, LPCWSTR value )
306 FIXME( "stub\n" );
307 return E_NOTIMPL;
310 static HRESULT WINAPI token_category_GetStringValue( ISpObjectTokenCategory *iface,
311 LPCWSTR name, LPWSTR *value )
313 FIXME( "stub\n" );
314 return E_NOTIMPL;
317 static HRESULT WINAPI token_category_SetDWORD( ISpObjectTokenCategory *iface,
318 LPCWSTR name, DWORD value )
320 FIXME( "stub\n" );
321 return E_NOTIMPL;
324 static HRESULT WINAPI token_category_GetDWORD( ISpObjectTokenCategory *iface,
325 LPCWSTR name, DWORD *pdwValue )
327 FIXME( "stub\n" );
328 return E_NOTIMPL;
331 static HRESULT WINAPI token_category_OpenKey( ISpObjectTokenCategory *iface,
332 LPCWSTR name, ISpDataKey **sub_key )
334 FIXME( "stub\n" );
335 return E_NOTIMPL;
338 static HRESULT WINAPI token_category_CreateKey( ISpObjectTokenCategory *iface,
339 LPCWSTR name, ISpDataKey **sub_key )
341 FIXME( "stub\n" );
342 return E_NOTIMPL;
345 static HRESULT WINAPI token_category_DeleteKey( ISpObjectTokenCategory *iface,
346 LPCWSTR name )
348 FIXME( "stub\n" );
349 return E_NOTIMPL;
352 static HRESULT WINAPI token_category_DeleteValue( ISpObjectTokenCategory *iface,
353 LPCWSTR name )
355 FIXME( "stub\n" );
356 return E_NOTIMPL;
359 static HRESULT WINAPI token_category_EnumKeys( ISpObjectTokenCategory *iface,
360 ULONG index, LPWSTR *sub_key )
362 FIXME( "stub\n" );
363 return E_NOTIMPL;
366 static HRESULT WINAPI token_category_EnumValues( ISpObjectTokenCategory *iface,
367 ULONG index, LPWSTR *value )
369 FIXME( "stub\n" );
370 return E_NOTIMPL;
373 static HRESULT parse_cat_id( const WCHAR *str, HKEY *root, const WCHAR **sub_key )
375 struct table
377 const WCHAR *name;
378 unsigned int len;
379 HKEY key;
380 } table[] =
382 #define X(s) s, ARRAY_SIZE(s) - 1
383 { X(L"HKEY_LOCAL_MACHINE\\"), HKEY_LOCAL_MACHINE },
384 { X(L"HKEY_CURRENT_USER\\"), HKEY_CURRENT_USER },
385 { NULL }
386 #undef X
388 struct table *ptr;
389 int len = lstrlenW( str );
391 for (ptr = table; ptr->name; ptr++)
393 if (len >= ptr->len && !wcsncmp( str, ptr->name, ptr->len ))
395 *root = ptr->key;
396 *sub_key = str + ptr->len;
397 return S_OK;
400 return S_FALSE;
403 static HRESULT WINAPI token_category_SetId( ISpObjectTokenCategory *iface,
404 LPCWSTR id, BOOL create )
406 struct token_category *This = impl_from_ISpObjectTokenCategory( iface );
407 HKEY root, key;
408 const WCHAR *subkey;
409 LONG res;
410 HRESULT hr;
412 TRACE( "(%p)->(%s %d)\n", This, debugstr_w( id ), create );
414 if (This->data_key) return SPERR_ALREADY_INITIALIZED;
416 hr = parse_cat_id( id, &root, &subkey );
417 if (hr != S_OK) return SPERR_INVALID_REGISTRY_KEY;
419 if (create) FIXME( "Ignoring create\n" );
421 res = RegOpenKeyExW( root, subkey, 0, KEY_ALL_ACCESS, &key );
422 if (res) return SPERR_INVALID_REGISTRY_KEY;
424 hr = CoCreateInstance( &CLSID_SpDataKey, NULL, CLSCTX_ALL,
425 &IID_ISpRegDataKey, (void **)&This->data_key );
426 if (FAILED(hr)) goto fail;
428 hr = ISpRegDataKey_SetKey( This->data_key, key, FALSE );
429 if (FAILED(hr)) goto fail;
431 return hr;
433 fail:
434 RegCloseKey( key );
435 return hr;
438 static HRESULT WINAPI token_category_GetId( ISpObjectTokenCategory *iface,
439 LPWSTR *id )
441 FIXME( "stub\n" );
442 return E_NOTIMPL;
445 static HRESULT WINAPI token_category_GetDataKey( ISpObjectTokenCategory *iface,
446 SPDATAKEYLOCATION location,
447 ISpDataKey **data_key )
449 FIXME( "stub\n" );
450 return E_NOTIMPL;
453 static HRESULT WINAPI token_category_EnumTokens( ISpObjectTokenCategory *iface,
454 LPCWSTR req, LPCWSTR opt,
455 IEnumSpObjectTokens **enum_tokens )
457 struct token_category *This = impl_from_ISpObjectTokenCategory( iface );
458 ISpObjectTokenEnumBuilder *builder;
459 HRESULT hr;
461 FIXME( "(%p)->(%s %s %p): semi-stub\n", This, debugstr_w( req ), debugstr_w( opt ), enum_tokens );
463 if (!This->data_key) return SPERR_UNINITIALIZED;
465 hr = CoCreateInstance( &CLSID_SpObjectTokenEnum, NULL, CLSCTX_ALL,
466 &IID_ISpObjectTokenEnumBuilder, (void **)&builder );
467 if (FAILED(hr)) return hr;
469 hr = ISpObjectTokenEnumBuilder_SetAttribs( builder, req, opt );
470 if (FAILED(hr)) goto fail;
472 /* FIXME: Build the enumerator */
474 hr = ISpObjectTokenEnumBuilder_QueryInterface( builder, &IID_IEnumSpObjectTokens,
475 (void **)enum_tokens );
477 fail:
478 ISpObjectTokenEnumBuilder_Release( builder );
479 return hr;
482 static HRESULT WINAPI token_category_SetDefaultTokenId( ISpObjectTokenCategory *iface,
483 LPCWSTR id )
485 FIXME( "stub\n" );
486 return E_NOTIMPL;
489 static HRESULT WINAPI token_category_GetDefaultTokenId( ISpObjectTokenCategory *iface,
490 LPWSTR *id )
492 struct token_category *This = impl_from_ISpObjectTokenCategory( iface );
493 struct data_key *this_data_key;
494 LONG res;
495 WCHAR regvalue[512];
496 DWORD regvalue_size = sizeof( regvalue );
498 FIXME( "(%p)->(%p): semi-stub\n", iface, id );
500 if (!This->data_key)
501 return SPERR_UNINITIALIZED;
503 if (!id)
504 return E_POINTER;
506 /* todo: check HKCU's DefaultTokenId before */
508 this_data_key = impl_from_ISpRegDataKey( This->data_key );
510 res = RegGetValueW( this_data_key->key, NULL, L"DefaultDefaultTokenId", RRF_RT_REG_SZ,
511 NULL, &regvalue, &regvalue_size);
512 if (res == ERROR_FILE_NOT_FOUND) {
513 return SPERR_NOT_FOUND;
514 } else if (res != ERROR_SUCCESS) {
515 /* probably not the correct return value */
516 FIXME( "returning %08x\n", res );
517 return res;
520 *id = CoTaskMemAlloc( regvalue_size );
521 wcscpy( *id, regvalue );
523 return S_OK;
526 const struct ISpObjectTokenCategoryVtbl token_category_vtbl =
528 token_category_QueryInterface,
529 token_category_AddRef,
530 token_category_Release,
531 token_category_SetData,
532 token_category_GetData,
533 token_category_SetStringValue,
534 token_category_GetStringValue,
535 token_category_SetDWORD,
536 token_category_GetDWORD,
537 token_category_OpenKey,
538 token_category_CreateKey,
539 token_category_DeleteKey,
540 token_category_DeleteValue,
541 token_category_EnumKeys,
542 token_category_EnumValues,
543 token_category_SetId,
544 token_category_GetId,
545 token_category_GetDataKey,
546 token_category_EnumTokens,
547 token_category_SetDefaultTokenId,
548 token_category_GetDefaultTokenId,
551 HRESULT token_category_create( IUnknown *outer, REFIID iid, void **obj )
553 struct token_category *This = heap_alloc( sizeof(*This) );
554 HRESULT hr;
556 if (!This) return E_OUTOFMEMORY;
557 This->ISpObjectTokenCategory_iface.lpVtbl = &token_category_vtbl;
558 This->ref = 1;
559 This->data_key = NULL;
561 hr = ISpObjectTokenCategory_QueryInterface( &This->ISpObjectTokenCategory_iface, iid, obj );
563 ISpObjectTokenCategory_Release( &This->ISpObjectTokenCategory_iface );
564 return hr;
567 struct token_enum
569 ISpObjectTokenEnumBuilder ISpObjectTokenEnumBuilder_iface;
570 LONG ref;
572 BOOL init;
573 WCHAR *req, *opt;
574 ULONG count;
577 static struct token_enum *impl_from_ISpObjectTokenEnumBuilder( ISpObjectTokenEnumBuilder *iface )
579 return CONTAINING_RECORD( iface, struct token_enum, ISpObjectTokenEnumBuilder_iface );
582 static HRESULT WINAPI token_enum_QueryInterface( ISpObjectTokenEnumBuilder *iface,
583 REFIID iid, void **obj )
585 struct token_enum *This = impl_from_ISpObjectTokenEnumBuilder( iface );
587 TRACE( "(%p)->(%s %p)\n", This, debugstr_guid( iid ), obj );
589 if (IsEqualIID( iid, &IID_IUnknown ) ||
590 IsEqualIID( iid, &IID_IEnumSpObjectTokens ) ||
591 IsEqualIID( iid, &IID_ISpObjectTokenEnumBuilder ))
593 ISpObjectTokenEnumBuilder_AddRef( iface );
594 *obj = iface;
595 return S_OK;
598 FIXME( "interface %s not implemented\n", debugstr_guid( iid ) );
599 *obj = NULL;
600 return E_NOINTERFACE;
603 static ULONG WINAPI token_enum_AddRef( ISpObjectTokenEnumBuilder *iface )
605 struct token_enum *This = impl_from_ISpObjectTokenEnumBuilder( iface );
606 ULONG ref = InterlockedIncrement( &This->ref );
608 TRACE( "(%p) ref = %u\n", This, ref );
609 return ref;
612 static ULONG WINAPI token_enum_Release( ISpObjectTokenEnumBuilder *iface )
614 struct token_enum *This = impl_from_ISpObjectTokenEnumBuilder( iface );
615 ULONG ref = InterlockedDecrement(&This->ref);
617 TRACE( "(%p) ref = %u\n", This, ref );
619 if (!ref)
621 heap_free( This->req );
622 heap_free( This->opt );
623 heap_free( This );
626 return ref;
629 static HRESULT WINAPI token_enum_Next( ISpObjectTokenEnumBuilder *iface,
630 ULONG num, ISpObjectToken **tokens,
631 ULONG *fetched )
633 struct token_enum *This = impl_from_ISpObjectTokenEnumBuilder( iface );
635 TRACE( "(%p)->(%u %p %p)\n", This, num, tokens, fetched );
637 if (!This->init) return SPERR_UNINITIALIZED;
639 FIXME( "semi-stub: Returning an empty enumerator\n" );
641 if (fetched) *fetched = 0;
642 return S_FALSE;
645 static HRESULT WINAPI token_enum_Skip( ISpObjectTokenEnumBuilder *iface,
646 ULONG num )
648 FIXME( "stub\n" );
649 return E_NOTIMPL;
652 static HRESULT WINAPI token_enum_Reset( ISpObjectTokenEnumBuilder *iface)
654 FIXME( "stub\n" );
655 return E_NOTIMPL;
658 static HRESULT WINAPI token_enum_Clone( ISpObjectTokenEnumBuilder *iface,
659 IEnumSpObjectTokens **clone )
661 FIXME( "stub\n" );
662 return E_NOTIMPL;
665 static HRESULT WINAPI token_enum_Item( ISpObjectTokenEnumBuilder *iface,
666 ULONG index, ISpObjectToken **token )
668 FIXME( "stub\n" );
669 return E_NOTIMPL;
672 static HRESULT WINAPI token_enum_GetCount( ISpObjectTokenEnumBuilder *iface,
673 ULONG *count )
675 struct token_enum *This = impl_from_ISpObjectTokenEnumBuilder( iface );
677 TRACE( "(%p)->(%p)\n", This, count );
679 if (!This->init) return SPERR_UNINITIALIZED;
681 *count = This->count;
682 return S_OK;
685 static HRESULT WINAPI token_enum_SetAttribs( ISpObjectTokenEnumBuilder *iface,
686 LPCWSTR req, LPCWSTR opt)
688 struct token_enum *This = impl_from_ISpObjectTokenEnumBuilder( iface );
690 TRACE( "(%p)->(%s %s)\n", This, debugstr_w( req ), debugstr_w( opt ) );
692 if (This->init) return SPERR_ALREADY_INITIALIZED;
694 if (req)
696 This->req = heap_strdupW( req );
697 if (!This->req) goto out_of_mem;
700 if (opt)
702 This->opt = heap_strdupW( opt );
703 if (!This->opt) goto out_of_mem;
706 This->init = TRUE;
707 return S_OK;
709 out_of_mem:
710 heap_free( This->req );
711 return E_OUTOFMEMORY;
714 static HRESULT WINAPI token_enum_AddTokens( ISpObjectTokenEnumBuilder *iface,
715 ULONG num, ISpObjectToken **tokens )
717 FIXME( "stub\n" );
718 return E_NOTIMPL;
721 static HRESULT WINAPI token_enum_AddTokensFromDataKey( ISpObjectTokenEnumBuilder *iface,
722 ISpDataKey *data_key,
723 LPCWSTR sub_key, LPCWSTR cat_id )
725 FIXME( "stub\n" );
726 return E_NOTIMPL;
729 static HRESULT WINAPI token_enum_AddTokensFromTokenEnum( ISpObjectTokenEnumBuilder *iface,
730 IEnumSpObjectTokens *token_enum )
732 FIXME( "stub\n" );
733 return E_NOTIMPL;
736 static HRESULT WINAPI token_enum_Sort( ISpObjectTokenEnumBuilder *iface,
737 LPCWSTR first )
739 FIXME( "stub\n" );
740 return E_NOTIMPL;
743 const struct ISpObjectTokenEnumBuilderVtbl token_enum_vtbl =
745 token_enum_QueryInterface,
746 token_enum_AddRef,
747 token_enum_Release,
748 token_enum_Next,
749 token_enum_Skip,
750 token_enum_Reset,
751 token_enum_Clone,
752 token_enum_Item,
753 token_enum_GetCount,
754 token_enum_SetAttribs,
755 token_enum_AddTokens,
756 token_enum_AddTokensFromDataKey,
757 token_enum_AddTokensFromTokenEnum,
758 token_enum_Sort
761 HRESULT token_enum_create( IUnknown *outer, REFIID iid, void **obj )
763 struct token_enum *This = heap_alloc( sizeof(*This) );
764 HRESULT hr;
766 if (!This) return E_OUTOFMEMORY;
767 This->ISpObjectTokenEnumBuilder_iface.lpVtbl = &token_enum_vtbl;
768 This->ref = 1;
769 This->req = NULL;
770 This->opt = NULL;
771 This->init = FALSE;
772 This->count = 0;
774 hr = ISpObjectTokenEnumBuilder_QueryInterface( &This->ISpObjectTokenEnumBuilder_iface, iid, obj );
776 ISpObjectTokenEnumBuilder_Release( &This->ISpObjectTokenEnumBuilder_iface );
777 return hr;
780 struct object_token
782 ISpObjectToken ISpObjectToken_iface;
783 LONG ref;
785 HKEY token_key;
788 static struct object_token *impl_from_ISpObjectToken( ISpObjectToken *iface )
790 return CONTAINING_RECORD( iface, struct object_token, ISpObjectToken_iface );
793 static HRESULT WINAPI token_QueryInterface( ISpObjectToken *iface,
794 REFIID iid, void **obj )
796 struct object_token *This = impl_from_ISpObjectToken( iface );
798 TRACE( "(%p)->(%s %p)\n", This, debugstr_guid( iid ), obj );
800 if (IsEqualIID( iid, &IID_IUnknown ) ||
801 IsEqualIID( iid, &IID_ISpDataKey ) ||
802 IsEqualIID( iid, &IID_ISpObjectToken ))
804 ISpObjectToken_AddRef( iface );
805 *obj = iface;
806 return S_OK;
809 FIXME( "interface %s not implemented\n", debugstr_guid( iid ) );
810 *obj = NULL;
811 return E_NOINTERFACE;
814 static ULONG WINAPI token_AddRef( ISpObjectToken *iface )
816 struct object_token *This = impl_from_ISpObjectToken( iface );
817 ULONG ref = InterlockedIncrement( &This->ref );
819 TRACE( "(%p) ref = %u\n", This, ref );
820 return ref;
823 static ULONG WINAPI token_Release( ISpObjectToken *iface )
825 struct object_token *This = impl_from_ISpObjectToken( iface );
826 ULONG ref = InterlockedDecrement(&This->ref);
828 TRACE( "(%p) ref = %u\n", This, ref );
830 if (!ref)
832 if (This->token_key) RegCloseKey( This->token_key );
833 heap_free( This );
836 return ref;
839 static HRESULT WINAPI token_SetData( ISpObjectToken *iface,
840 LPCWSTR name, ULONG size,
841 const BYTE *data )
843 FIXME( "stub\n" );
844 return E_NOTIMPL;
847 static HRESULT WINAPI token_GetData( ISpObjectToken *iface,
848 LPCWSTR name, ULONG *size,
849 BYTE *data )
851 FIXME( "stub\n" );
852 return E_NOTIMPL;
855 static HRESULT WINAPI token_SetStringValue( ISpObjectToken *iface,
856 LPCWSTR name, LPCWSTR value )
858 FIXME( "stub\n" );
859 return E_NOTIMPL;
862 static HRESULT WINAPI token_GetStringValue( ISpObjectToken *iface,
863 LPCWSTR name, LPWSTR *value )
865 FIXME( "stub\n" );
866 return E_NOTIMPL;
869 static HRESULT WINAPI token_SetDWORD( ISpObjectToken *iface,
870 LPCWSTR name, DWORD value )
872 FIXME( "stub\n" );
873 return E_NOTIMPL;
876 static HRESULT WINAPI token_GetDWORD( ISpObjectToken *iface,
877 LPCWSTR name, DWORD *pdwValue )
879 FIXME( "stub\n" );
880 return E_NOTIMPL;
883 static HRESULT WINAPI token_OpenKey( ISpObjectToken *iface,
884 LPCWSTR name, ISpDataKey **sub_key )
886 FIXME( "stub\n" );
887 return E_NOTIMPL;
890 static HRESULT WINAPI token_CreateKey( ISpObjectToken *iface,
891 LPCWSTR name, ISpDataKey **sub_key )
893 FIXME( "stub\n" );
894 return E_NOTIMPL;
897 static HRESULT WINAPI token_DeleteKey( ISpObjectToken *iface,
898 LPCWSTR name )
900 FIXME( "stub\n" );
901 return E_NOTIMPL;
904 static HRESULT WINAPI token_DeleteValue( ISpObjectToken *iface,
905 LPCWSTR name )
907 FIXME( "stub\n" );
908 return E_NOTIMPL;
911 static HRESULT WINAPI token_EnumKeys( ISpObjectToken *iface,
912 ULONG index, LPWSTR *sub_key )
914 FIXME( "stub\n" );
915 return E_NOTIMPL;
918 static HRESULT WINAPI token_EnumValues( ISpObjectToken *iface,
919 ULONG index, LPWSTR *value )
921 FIXME( "stub\n" );
922 return E_NOTIMPL;
925 static HRESULT WINAPI token_SetId( ISpObjectToken *iface,
926 LPCWSTR category_id, LPCWSTR token_id,
927 BOOL create )
929 struct object_token *This = impl_from_ISpObjectToken( iface );
930 BOOL res;
931 HRESULT hr;
932 HKEY root, key;
933 const WCHAR *subkey;
935 FIXME( "(%p)->(%s %s %d): semi-stub\n", This, debugstr_w( category_id ),
936 debugstr_w(token_id), create );
938 if (This->token_key) return SPERR_ALREADY_INITIALIZED;
940 if (!token_id) return E_POINTER;
942 hr = parse_cat_id( token_id, &root, &subkey );
943 if (hr != S_OK) return SPERR_NOT_FOUND;
945 res = RegOpenKeyExW( root, subkey, 0, KEY_ALL_ACCESS, &key );
946 if (res) return SPERR_NOT_FOUND;
948 This->token_key = key;
950 return S_OK;
953 static HRESULT WINAPI token_GetId( ISpObjectToken *iface,
954 LPWSTR *token_id )
956 FIXME( "stub\n" );
957 return E_NOTIMPL;
960 static HRESULT WINAPI token_GetCategory( ISpObjectToken *iface,
961 ISpObjectTokenCategory **category )
963 FIXME( "stub\n" );
964 return E_NOTIMPL;
967 static HRESULT WINAPI token_CreateInstance( ISpObjectToken *iface,
968 IUnknown *outer,
969 DWORD class_context,
970 REFIID riid,
971 void **object )
973 FIXME( "stub\n" );
974 return E_NOTIMPL;
977 static HRESULT WINAPI token_GetStorageFileName( ISpObjectToken *iface,
978 REFCLSID caller,
979 LPCWSTR key_name,
980 LPCWSTR filename,
981 ULONG folder,
982 LPWSTR *filepath )
984 FIXME( "stub\n" );
985 return E_NOTIMPL;
988 static HRESULT WINAPI token_RemoveStorageFileName( ISpObjectToken *iface,
989 REFCLSID caller,
990 LPCWSTR key_name,
991 BOOL delete_file )
993 FIXME( "stub\n" );
994 return E_NOTIMPL;
997 static HRESULT WINAPI token_Remove( ISpObjectToken *iface,
998 REFCLSID caller )
1000 FIXME( "stub\n" );
1001 return E_NOTIMPL;
1004 static HRESULT WINAPI token_IsUISupported( ISpObjectToken *iface,
1005 LPCWSTR ui_type,
1006 void *extra_data,
1007 ULONG extra_data_size,
1008 IUnknown *object,
1009 BOOL *supported )
1011 FIXME( "stub\n" );
1012 return E_NOTIMPL;
1015 static HRESULT WINAPI token_DisplayUI( ISpObjectToken *iface,
1016 HWND parent,
1017 LPCWSTR title,
1018 LPCWSTR ui_type,
1019 void *extra_data,
1020 ULONG extra_data_size,
1021 IUnknown *object )
1023 FIXME( "stub\n" );
1024 return E_NOTIMPL;
1027 static HRESULT WINAPI token_MatchesAttributes( ISpObjectToken *iface,
1028 LPCWSTR attributes,
1029 BOOL *matches )
1031 FIXME( "stub\n" );
1032 return E_NOTIMPL;
1035 const struct ISpObjectTokenVtbl token_vtbl =
1037 token_QueryInterface,
1038 token_AddRef,
1039 token_Release,
1040 token_SetData,
1041 token_GetData,
1042 token_SetStringValue,
1043 token_GetStringValue,
1044 token_SetDWORD,
1045 token_GetDWORD,
1046 token_OpenKey,
1047 token_CreateKey,
1048 token_DeleteKey,
1049 token_DeleteValue,
1050 token_EnumKeys,
1051 token_EnumValues,
1052 token_SetId,
1053 token_GetId,
1054 token_GetCategory,
1055 token_CreateInstance,
1056 token_GetStorageFileName,
1057 token_RemoveStorageFileName,
1058 token_Remove,
1059 token_IsUISupported,
1060 token_DisplayUI,
1061 token_MatchesAttributes
1064 HRESULT token_create( IUnknown *outer, REFIID iid, void **obj )
1066 struct object_token *This = heap_alloc( sizeof(*This) );
1067 HRESULT hr;
1069 if (!This) return E_OUTOFMEMORY;
1070 This->ISpObjectToken_iface.lpVtbl = &token_vtbl;
1071 This->ref = 1;
1073 This->token_key = NULL;
1075 hr = ISpObjectToken_QueryInterface( &This->ISpObjectToken_iface, iid, obj );
1077 ISpObjectToken_Release( &This->ISpObjectToken_iface );
1078 return hr;