From: Shaun Ren sren@codeweavers.com
--- dlls/sapi/token.c | 88 ++++++++++++++++++++++++++++------------------- 1 file changed, 53 insertions(+), 35 deletions(-)
diff --git a/dlls/sapi/token.c b/dlls/sapi/token.c index 0380e36dd0a..b6c6a4a2189 100644 --- a/dlls/sapi/token.c +++ b/dlls/sapi/token.c @@ -53,7 +53,7 @@ struct object_token ISpObjectToken ISpObjectToken_iface; LONG ref;
- HKEY token_key; + ISpRegDataKey *data_key; WCHAR *token_id; };
@@ -750,6 +750,7 @@ static HRESULT WINAPI token_enum_Next( ISpObjectTokenEnumBuilder *iface, WCHAR *subkey_name; HKEY sub_key; DWORD size; + ISpRegDataKey *data_key;
TRACE( "(%p)->(%lu %p %p)\n", This, num, tokens, fetched );
@@ -779,6 +780,22 @@ static HRESULT WINAPI token_enum_Next( ISpObjectTokenEnumBuilder *iface, return E_FAIL; }
+ hr = CoCreateInstance( &CLSID_SpDataKey, NULL, CLSCTX_ALL, + &IID_ISpRegDataKey, (void **)&data_key ); + if (FAILED(hr)) + { + free( subkey_name ); + return hr; + } + + hr = ISpRegDataKey_SetKey( data_key, sub_key, FALSE ); + if (FAILED(hr)) + { + free( subkey_name ); + ISpRegDataKey_Release( data_key ); + return hr; + } + hr = token_create( NULL, &IID_ISpObjectToken, (void**)tokens ); if (FAILED(hr)) { @@ -787,7 +804,7 @@ static HRESULT WINAPI token_enum_Next( ISpObjectTokenEnumBuilder *iface, }
object = impl_from_ISpObjectToken( *tokens ); - object->token_key = sub_key; + object->data_key = data_key; object->token_id = subkey_name;
if (fetched) *fetched = 1; @@ -825,6 +842,7 @@ static HRESULT WINAPI token_enum_Item( ISpObjectTokenEnumBuilder *iface, DWORD size; LONG ret; HKEY key; + ISpRegDataKey *data_key;
TRACE( "%p, %lu, %p\n", This, index, token );
@@ -851,6 +869,22 @@ static HRESULT WINAPI token_enum_Item( ISpObjectTokenEnumBuilder *iface, return HRESULT_FROM_WIN32(ret); }
+ hr = CoCreateInstance( &CLSID_SpDataKey, NULL, CLSCTX_ALL, + &IID_ISpRegDataKey, (void **)&data_key ); + if (FAILED(hr)) + { + free( subkey ); + return hr; + } + + hr = ISpRegDataKey_SetKey( data_key, key, FALSE ); + if (FAILED(hr)) + { + free( subkey ); + ISpRegDataKey_Release( data_key ); + return hr; + } + hr = token_create( NULL, &IID_ISpObjectToken, (void**)&subtoken ); if (FAILED(hr)) { @@ -859,7 +893,7 @@ static HRESULT WINAPI token_enum_Item( ISpObjectTokenEnumBuilder *iface, }
object = impl_from_ISpObjectToken( subtoken ); - object->token_key = key; + object->data_key = data_key; object->token_id = subkey;
*token = subtoken; @@ -1016,7 +1050,7 @@ static ULONG WINAPI token_Release( ISpObjectToken *iface )
if (!ref) { - if (This->token_key) RegCloseKey( This->token_key ); + if (This->data_key) ISpRegDataKey_Release( This->data_key ); free( This->token_id ); free( This ); } @@ -1072,36 +1106,10 @@ static HRESULT WINAPI token_OpenKey( ISpObjectToken *iface, LPCWSTR name, ISpDataKey **sub_key ) { struct object_token *This = impl_from_ISpObjectToken( iface ); - ISpRegDataKey *spregkey; - HRESULT hr; - HKEY key; - LONG ret;
TRACE( "%p, %s, %p\n", This, debugstr_w(name), sub_key );
- ret = RegOpenKeyExW (This->token_key, name, 0, KEY_ALL_ACCESS, &key); - if (ret != ERROR_SUCCESS) - return SPERR_NOT_FOUND; - - hr = data_key_create(NULL, &IID_ISpRegDataKey, (void**)&spregkey); - if (FAILED(hr)) - { - RegCloseKey(key); - return hr; - } - - hr = ISpRegDataKey_SetKey(spregkey, key, FALSE); - if (FAILED(hr)) - { - RegCloseKey(key); - ISpRegDataKey_Release(spregkey); - return hr; - } - - hr = ISpRegDataKey_QueryInterface(spregkey, &IID_ISpDataKey, (void**)sub_key); - ISpRegDataKey_Release(spregkey); - - return hr; + return ISpRegDataKey_OpenKey( This->data_key, name, sub_key ); }
static HRESULT WINAPI token_CreateKey( ISpObjectToken *iface, @@ -1152,7 +1160,7 @@ static HRESULT WINAPI token_SetId( ISpObjectToken *iface, FIXME( "(%p)->(%s %s %d): semi-stub\n", This, debugstr_w( category_id ), debugstr_w(token_id), create );
- if (This->token_key) return SPERR_ALREADY_INITIALIZED; + if (This->data_key) return SPERR_ALREADY_INITIALIZED;
if (!token_id) return E_POINTER;
@@ -1165,10 +1173,20 @@ static HRESULT WINAPI token_SetId( ISpObjectToken *iface, res = RegOpenKeyExW( root, subkey, 0, KEY_ALL_ACCESS, &key ); if (res) return SPERR_NOT_FOUND;
- This->token_key = key; + hr = CoCreateInstance( &CLSID_SpDataKey, NULL, CLSCTX_ALL, + &IID_ISpRegDataKey, (void **)&This->data_key ); + if (FAILED(hr)) goto fail; + + hr = ISpRegDataKey_SetKey( This->data_key, key, FALSE ); + if (FAILED(hr)) goto fail; + This->token_id = wcsdup(token_id);
return S_OK; + +fail: + RegCloseKey( key ); + return hr; }
static HRESULT WINAPI token_GetId( ISpObjectToken *iface, @@ -1178,7 +1196,7 @@ static HRESULT WINAPI token_GetId( ISpObjectToken *iface,
TRACE( "%p, %p\n", This, token_id);
- if (!This->token_key) + if (!This->data_key) return SPERR_UNINITIALIZED;
if (!token_id) @@ -1311,7 +1329,7 @@ HRESULT token_create( IUnknown *outer, REFIID iid, void **obj ) This->ISpObjectToken_iface.lpVtbl = &token_vtbl; This->ref = 1;
- This->token_key = NULL; + This->data_key = NULL; This->token_id = NULL;
hr = ISpObjectToken_QueryInterface( &This->ISpObjectToken_iface, iid, obj );