diff --git a/dlls/windows.web/Makefile.in b/dlls/windows.web/Makefile.in index ebcf7bbc2f3..aaaacd6b298 100644 --- a/dlls/windows.web/Makefile.in +++ b/dlls/windows.web/Makefile.in @@ -3,6 +3,7 @@ IMPORTS = combase SOURCES = \ classes.idl \ + json_array.c \ json_object.c \ json_value.c \ main.c diff --git a/dlls/windows.web/classes.idl b/dlls/windows.web/classes.idl index 37537cfeb26..266f560af01 100644 --- a/dlls/windows.web/classes.idl +++ b/dlls/windows.web/classes.idl @@ -24,6 +24,7 @@ import "windows.data.json.idl"; namespace Windows.Data.Json { + runtimeclass JsonArray; runtimeclass JsonObject; runtimeclass JsonValue; } diff --git a/dlls/windows.web/json_array.c b/dlls/windows.web/json_array.c new file mode 100644 index 00000000000..943c0166d61 --- /dev/null +++ b/dlls/windows.web/json_array.c @@ -0,0 +1,319 @@ +/* WinRT Windows.Data.Json.JsonArray Implementation + * + * Copyright (C) 2026 Olivia Ryan + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA + */ + +#include "private.h" +#include "wine/debug.h" + +WINE_DEFAULT_DEBUG_CHANNEL(web); + +struct json_array +{ + IJsonArray IJsonArray_iface; + LONG ref; + IJsonValue **elements; + ULONG length; + ULONG size; +}; + +static inline struct json_array *impl_from_IJsonArray( IJsonArray *iface ) +{ + return CONTAINING_RECORD( iface, struct json_array, IJsonArray_iface ); +} + +HRESULT json_array_push( IJsonArray *iface, IJsonValue *value ) +{ + struct json_array *impl = impl_from_IJsonArray( iface ); + IJsonValue **new = impl->elements; + + TRACE( "iface %p, value %p.\n", iface, value ); + + if (impl->length == impl->size) + new = realloc(new, ++impl->size * sizeof(*new)); + + if (!new) + { + impl->size--; + return E_OUTOFMEMORY; + } + + impl->elements = new; + impl->elements[impl->length++] = value; + return S_OK; +} + +HRESULT json_array_pop( IJsonArray *iface, IJsonValue **value ) +{ + struct json_array *impl = impl_from_IJsonArray( iface ); + + TRACE( "iface %p, value %p.\n", iface, value ); + + if (impl->length == 0) return E_FAIL; + + if (value) *value = impl->elements[--impl->length]; + else IJsonValue_Release( impl->elements[--impl->length] ); + return S_OK; +} + +static HRESULT WINAPI json_array_statics_QueryInterface( IJsonArray *iface, REFIID iid, void **out ) +{ + struct json_array *impl = impl_from_IJsonArray( iface ); + + TRACE( "iface %p, iid %s, out %p.\n", iface, debugstr_guid( iid ), out ); + + if (IsEqualGUID( iid, &IID_IUnknown ) || + IsEqualGUID( iid, &IID_IInspectable ) || + IsEqualGUID( iid, &IID_IAgileObject ) || + IsEqualGUID( iid, &IID_IJsonArray )) + { + *out = &impl->IJsonArray_iface; + IInspectable_AddRef( *out ); + return S_OK; + } + + FIXME( "%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid( iid ) ); + *out = NULL; + return E_NOINTERFACE; +} + +static ULONG WINAPI json_array_statics_AddRef( IJsonArray *iface ) +{ + struct json_array *impl = impl_from_IJsonArray( iface ); + ULONG ref = InterlockedIncrement( &impl->ref ); + TRACE( "iface %p, ref %lu.\n", iface, ref ); + return ref; +} + +static ULONG WINAPI json_array_statics_Release( IJsonArray *iface ) +{ + struct json_array *impl = impl_from_IJsonArray( iface ); + ULONG ref = InterlockedDecrement( &impl->ref ); + + TRACE( "iface %p, ref %lu.\n", iface, ref ); + + if (!ref) + { + for (UINT32 i = 0; i < impl->length; i++) + IJsonValue_Release( impl->elements[i] ); + + if (impl->elements) free( impl->elements ); + free( impl ); + } + return ref; +} + +static HRESULT WINAPI json_array_statics_GetIids( IJsonArray *iface, ULONG *iid_count, IID **iids ) +{ + FIXME( "iface %p, iid_count %p, iids %p stub!\n", iface, iid_count, iids ); + return E_NOTIMPL; +} + +static HRESULT WINAPI json_array_statics_GetRuntimeClassName( IJsonArray *iface, HSTRING *class_name ) +{ + FIXME( "iface %p, class_name %p stub!\n", iface, class_name ); + return E_NOTIMPL; +} + +static HRESULT WINAPI json_array_statics_GetTrustLevel( IJsonArray *iface, TrustLevel *trust_level ) +{ + FIXME( "iface %p, trust_level %p stub!\n", iface, trust_level ); + return E_NOTIMPL; +} + +static HRESULT WINAPI json_array_statics_GetObjectAt( IJsonArray *iface, UINT32 index, IJsonObject **value ) +{ + struct json_array *impl = impl_from_IJsonArray( iface ); + + TRACE( "iface %p, index %u, value %p\n", iface, index, value ); + + if (!value) return E_POINTER; + if (index >= impl->length) return WEB_E_JSON_VALUE_NOT_FOUND; + + return IJsonValue_GetObject( impl->elements[index], value ); +} + +static HRESULT WINAPI json_array_statics_GetArrayAt( IJsonArray *iface, UINT32 index, IJsonArray **value ) +{ + struct json_array *impl = impl_from_IJsonArray( iface ); + + TRACE( "iface %p, index %u, value %p\n", iface, index, value ); + + if (!value) return E_POINTER; + if (index >= impl->length) return WEB_E_JSON_VALUE_NOT_FOUND; + + return IJsonValue_GetArray( impl->elements[index], value ); +} + +static HRESULT WINAPI json_array_statics_GetStringAt( IJsonArray *iface, UINT32 index, HSTRING *value ) +{ + struct json_array *impl = impl_from_IJsonArray( iface ); + + TRACE( "iface %p, index %u, value %p\n", iface, index, value ); + + if (!value) return E_POINTER; + if (index >= impl->length) return WEB_E_JSON_VALUE_NOT_FOUND; + + return IJsonValue_GetString( impl->elements[index], value ); +} + +static HRESULT WINAPI json_array_statics_GetNumberAt( IJsonArray *iface, UINT32 index, double *value ) +{ + struct json_array *impl = impl_from_IJsonArray( iface ); + + TRACE( "iface %p, index %u, value %p\n", iface, index, value ); + + if (!value) return E_POINTER; + if (index >= impl->length) return WEB_E_JSON_VALUE_NOT_FOUND; + + return IJsonValue_GetNumber( impl->elements[index], value ); +} + +static HRESULT WINAPI json_array_statics_GetBooleanAt( IJsonArray *iface, UINT32 index, boolean *value ) +{ + struct json_array *impl = impl_from_IJsonArray( iface ); + + TRACE( "iface %p, index %u, value %p\n", iface, index, value ); + + if (!value) return E_POINTER; + if (index >= impl->length) return WEB_E_JSON_VALUE_NOT_FOUND; + + return IJsonValue_GetBoolean( impl->elements[index], value ); +} + +static const struct IJsonArrayVtbl json_array_statics_vtbl = +{ + json_array_statics_QueryInterface, + json_array_statics_AddRef, + json_array_statics_Release, + /* IInspectable methods */ + json_array_statics_GetIids, + json_array_statics_GetRuntimeClassName, + json_array_statics_GetTrustLevel, + /* IJsonArray methods */ + json_array_statics_GetObjectAt, + json_array_statics_GetArrayAt, + json_array_statics_GetStringAt, + json_array_statics_GetNumberAt, + json_array_statics_GetBooleanAt, +}; + +struct json_array_statics +{ + IActivationFactory IActivationFactory_iface; + LONG ref; +}; + +static inline struct json_array_statics *impl_from_IActivationFactory( IActivationFactory *iface ) +{ + return CONTAINING_RECORD( iface, struct json_array_statics, IActivationFactory_iface ); +} + +static HRESULT WINAPI factory_QueryInterface( IActivationFactory *iface, REFIID iid, void **out ) +{ + struct json_array_statics *impl = impl_from_IActivationFactory( iface ); + + TRACE( "iface %p, iid %s, out %p.\n", iface, debugstr_guid(iid), out); + + if (IsEqualGUID( iid, &IID_IUnknown ) || + IsEqualGUID( iid, &IID_IInspectable ) || + IsEqualGUID( iid, &IID_IAgileObject ) || + IsEqualGUID( iid, &IID_IActivationFactory )) + { + *out = &impl->IActivationFactory_iface; + IInspectable_AddRef( *out ); + return S_OK; + } + + FIXME( "%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid( iid ) ); + *out = NULL; + return E_NOINTERFACE; +} + +static ULONG WINAPI factory_AddRef( IActivationFactory *iface ) +{ + struct json_array_statics *impl = impl_from_IActivationFactory( iface ); + ULONG ref = InterlockedIncrement( &impl->ref ); + TRACE( "iface %p, ref %lu.\n", iface, ref ); + return ref; +} + +static ULONG WINAPI factory_Release( IActivationFactory *iface ) +{ + struct json_array_statics *impl = impl_from_IActivationFactory( iface ); + ULONG ref = InterlockedDecrement( &impl->ref ); + TRACE( "iface %p, ref %lu.\n", iface, ref ); + return ref; +} + +static HRESULT WINAPI factory_GetIids( IActivationFactory *iface, ULONG *iid_count, IID **iids ) +{ + FIXME( "iface %p, iid_count %p, iids %p stub!\n", iface, iid_count, iids ); + return E_NOTIMPL; +} + +static HRESULT WINAPI factory_GetRuntimeClassName( IActivationFactory *iface, HSTRING *class_name ) +{ + FIXME( "iface %p, class_name %p stub!\n", iface, class_name ); + return E_NOTIMPL; +} + +static HRESULT WINAPI factory_GetTrustLevel( IActivationFactory *iface, TrustLevel *trust_level ) +{ + FIXME( "iface %p, trust_level %p stub!\n", iface, trust_level ); + return E_NOTIMPL; +} + +static HRESULT WINAPI factory_ActivateInstance( IActivationFactory *iface, IInspectable **instance ) +{ + struct json_array *impl; + + TRACE( "iface %p, instance %p.\n", iface, instance ); + + *instance = NULL; + if (!(impl = calloc( 1, sizeof(*impl) ))) return E_OUTOFMEMORY; + + impl->IJsonArray_iface.lpVtbl = &json_array_statics_vtbl; + impl->ref = 1; + impl->elements = NULL; + impl->length = 0; + impl->size = 0; + + *instance = (IInspectable*)&impl->IJsonArray_iface; + return S_OK; +} + +static const struct IActivationFactoryVtbl factory_vtbl = +{ + factory_QueryInterface, + factory_AddRef, + factory_Release, + /* IInspectable methods */ + factory_GetIids, + factory_GetRuntimeClassName, + factory_GetTrustLevel, + /* IActivationFactory methods */ + factory_ActivateInstance, +}; + +static struct json_array_statics json_array_statics = +{ + {&factory_vtbl}, + 1, +}; + +IActivationFactory *json_array_factory = &json_array_statics.IActivationFactory_iface; diff --git a/dlls/windows.web/json_object.c b/dlls/windows.web/json_object.c index 38c899288b7..43b46e45c3f 100644 --- a/dlls/windows.web/json_object.c +++ b/dlls/windows.web/json_object.c @@ -1,6 +1,7 @@ /* WinRT Windows.Data.Json.JsonObject Implementation * * Copyright (C) 2024 Mohamad Al-Jaf + * Copyright (C) 2026 Olivia Ryan * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -26,6 +27,7 @@ struct json_object { IJsonObject IJsonObject_iface; LONG ref; + IMap_HSTRING_IInspectable *members; }; static inline struct json_object *impl_from_IJsonObject( IJsonObject *iface ) @@ -69,7 +71,10 @@ static ULONG WINAPI json_object_statics_Release( IJsonObject *iface ) TRACE( "iface %p, ref %lu.\n", iface, ref ); - if (!ref) free( impl ); + if (!ref) { + IMap_HSTRING_IInspectable_Release( impl->members ); + free( impl ); + } return ref; } @@ -93,44 +98,115 @@ static HRESULT WINAPI json_object_statics_GetTrustLevel( IJsonObject *iface, Tru static HRESULT WINAPI json_object_statics_GetNamedValue( IJsonObject *iface, HSTRING name, IJsonValue **value ) { - FIXME( "iface %p, name %s, value %p stub!\n", iface, debugstr_hstring( name ), value ); - return E_NOTIMPL; + struct json_object *impl = impl_from_IJsonObject( iface ); + boolean exists; + HRESULT hr; + + TRACE( "iface %p, name %s, value %p.\n", iface, debugstr_hstring( name ), value ); + + if (!value) return E_POINTER; + + hr = IMap_HSTRING_IInspectable_HasKey( impl->members, name, &exists ); + if ( FAILED(hr) || !exists ) return WEB_E_JSON_VALUE_NOT_FOUND; + return IMap_HSTRING_IInspectable_Lookup( impl->members, name, (IInspectable**)value ); } static HRESULT WINAPI json_object_statics_SetNamedValue( IJsonObject *iface, HSTRING name, IJsonValue *value ) { - FIXME( "iface %p, name %s, value %p stub!\n", iface, debugstr_hstring( name ), value ); - return E_NOTIMPL; + boolean dummy; + struct json_object *impl = impl_from_IJsonObject( iface ); + TRACE( "iface %p, name %s, value %p.\n", iface, debugstr_hstring( name ), value ); + return IMap_HSTRING_IInspectable_Insert( impl->members, name, (IInspectable*)value, &dummy ); } static HRESULT WINAPI json_object_statics_GetNamedObject( IJsonObject *iface, HSTRING name, IJsonObject **value ) { - FIXME( "iface %p, name %s, value %p stub!\n", iface, debugstr_hstring( name ), value ); - return E_NOTIMPL; + IJsonValue *internal_value; + JsonValueType value_type; + HRESULT hr; + + TRACE( "iface %p, name %s, value %p.\n", iface, debugstr_hstring( name ), value ); + + if (FAILED(hr = IJsonObject_GetNamedValue( iface, name, &internal_value ))) + return hr; + + IJsonValue_Release( internal_value ); + IJsonValue_get_ValueType( internal_value, &value_type ); + if (value_type != JsonValueType_Object) return E_ILLEGAL_METHOD_CALL; + + return IJsonValue_GetObject( internal_value, value ); } static HRESULT WINAPI json_object_statics_GetNamedArray( IJsonObject *iface, HSTRING name, IJsonArray **value ) { - FIXME( "iface %p, name %s, value %p stub!\n", iface, debugstr_hstring( name ), value ); - return E_NOTIMPL; + IJsonValue *internal_value; + JsonValueType value_type; + HRESULT hr; + + TRACE( "iface %p, name %s, value %p.\n", iface, debugstr_hstring( name ), value ); + + if (FAILED(hr = IJsonObject_GetNamedValue( iface, name, &internal_value ))) + return hr; + + IJsonValue_Release( internal_value ); + IJsonValue_get_ValueType( internal_value, &value_type ); + if (value_type != JsonValueType_Array) return E_ILLEGAL_METHOD_CALL; + + return IJsonValue_GetArray( internal_value, value ); } static HRESULT WINAPI json_object_statics_GetNamedString( IJsonObject *iface, HSTRING name, HSTRING *value ) { - FIXME( "iface %p, name %s, value %p stub!\n", iface, debugstr_hstring( name ), value ); - return E_NOTIMPL; + IJsonValue *internal_value; + JsonValueType value_type; + HRESULT hr; + + TRACE( "iface %p, name %s, value %p.\n", iface, debugstr_hstring( name ), value ); + + if (FAILED(hr = IJsonObject_GetNamedValue( iface, name, &internal_value ))) + return hr; + + IJsonValue_Release( internal_value ); + IJsonValue_get_ValueType( internal_value, &value_type ); + if (value_type != JsonValueType_String) return E_ILLEGAL_METHOD_CALL; + + return IJsonValue_GetString( internal_value, value ); } static HRESULT WINAPI json_object_statics_GetNamedNumber( IJsonObject *iface, HSTRING name, DOUBLE *value ) { - FIXME( "iface %p, name %s, value %p stub!\n", iface, debugstr_hstring( name ), value ); - return E_NOTIMPL; + IJsonValue *internal_value; + JsonValueType value_type; + HRESULT hr; + + TRACE( "iface %p, name %s, value %p.\n", iface, debugstr_hstring( name ), value ); + + if (FAILED(hr = IJsonObject_GetNamedValue( iface, name, &internal_value ))) + return hr; + + IJsonValue_Release( internal_value ); + IJsonValue_get_ValueType( internal_value, &value_type ); + if (value_type != JsonValueType_Number) return E_ILLEGAL_METHOD_CALL; + + return IJsonValue_GetNumber( internal_value, value ); } static HRESULT WINAPI json_object_statics_GetNamedBoolean( IJsonObject *iface, HSTRING name, boolean *value ) { - FIXME( "iface %p, name %s, value %p stub!\n", iface, debugstr_hstring( name ), value ); - return E_NOTIMPL; + IJsonValue *internal_value; + JsonValueType value_type; + HRESULT hr; + + TRACE( "iface %p, name %s, value %p.\n", iface, debugstr_hstring( name ), value ); + + if (FAILED(hr = IJsonObject_GetNamedValue( iface, name, &internal_value ))) + return hr; + + IJsonValue_Release( internal_value ); + IJsonValue_get_ValueType( internal_value, &value_type ); + if (value_type != JsonValueType_Boolean) return E_ILLEGAL_METHOD_CALL; + + return IJsonValue_GetBoolean( internal_value, value ); } static const struct IJsonObjectVtbl json_object_statics_vtbl = @@ -220,7 +296,12 @@ static HRESULT WINAPI factory_GetTrustLevel( IActivationFactory *iface, TrustLev static HRESULT WINAPI factory_ActivateInstance( IActivationFactory *iface, IInspectable **instance ) { + const WCHAR *property_set_str = RuntimeClass_Windows_Foundation_Collections_PropertySet; + IPropertySet *property_set; + HSTRING property_set_class; struct json_object *impl; + HSTRING_HEADER header; + HRESULT hr; TRACE( "iface %p, instance %p.\n", iface, instance ); @@ -230,6 +311,22 @@ static HRESULT WINAPI factory_ActivateInstance( IActivationFactory *iface, IInsp impl->IJsonObject_iface.lpVtbl = &json_object_statics_vtbl; impl->ref = 1; + WindowsCreateStringReference( property_set_str, + wcslen( property_set_str ), &header, &property_set_class ); + if (FAILED(hr = RoActivateInstance( property_set_class, (IInspectable**)&property_set ))) + { + free( impl ); + return hr; + } + hr = IPropertySet_QueryInterface( property_set, + &IID_IMap_HSTRING_IInspectable, (void**)&impl->members ); + IPropertySet_Release( property_set ); + if (FAILED(hr)) + { + free( impl ); + return hr; + } + *instance = (IInspectable *)&impl->IJsonObject_iface; return S_OK; } diff --git a/dlls/windows.web/json_value.c b/dlls/windows.web/json_value.c index f1930beaad3..379dc411718 100644 --- a/dlls/windows.web/json_value.c +++ b/dlls/windows.web/json_value.c @@ -1,6 +1,7 @@ /* WinRT Windows.Data.Json.JsonValue Implementation * * Copyright (C) 2024 Mohamad Al-Jaf + * Copyright (C) 2026 Olivia Ryan * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -124,7 +125,8 @@ struct json_value HSTRING parsed_string; double parsed_number; boolean parsed_boolean; - HSTRING string_value; + IJsonArray *parsed_array; + IJsonObject *parsed_object; }; static inline struct json_value *impl_from_IJsonValue( IJsonValue *iface ) @@ -171,7 +173,8 @@ static ULONG WINAPI json_value_Release( IJsonValue *iface ) if (!ref) { WindowsDeleteString( impl->parsed_string ); - WindowsDeleteString( impl->string_value ); + if ( impl->parsed_array ) IJsonArray_Release( impl->parsed_array ); + if ( impl->parsed_object ) IJsonObject_Release( impl->parsed_object ); free( impl ); } return ref; @@ -255,24 +258,28 @@ static HRESULT WINAPI json_value_GetArray( IJsonValue *iface, IJsonArray **value { struct json_value *impl = impl_from_IJsonValue( iface ); - FIXME( "iface %p, value %p stub!\n", iface, value ); + TRACE( "iface %p, value %p\n", iface, value ); if (!value) return E_POINTER; if (impl->json_value_type != JsonValueType_Array) return E_ILLEGAL_METHOD_CALL; - return E_NOTIMPL; + IJsonArray_AddRef( impl->parsed_array ); + *value = impl->parsed_array; + return S_OK; } static HRESULT WINAPI json_value_GetObject( IJsonValue *iface, IJsonObject **value ) { struct json_value *impl = impl_from_IJsonValue( iface ); - FIXME( "iface %p, value %p stub!\n", iface, value ); + TRACE( "iface %p, value %p\n", iface, value ); if (!value) return E_POINTER; if (impl->json_value_type != JsonValueType_Object) return E_ILLEGAL_METHOD_CALL; - return E_NOTIMPL; + IJsonObject_AddRef( impl->parsed_object ); + *value = impl->parsed_object; + return S_OK; } static const struct IJsonValueVtbl json_value_vtbl = @@ -296,72 +303,293 @@ static const struct IJsonValueVtbl json_value_vtbl = DEFINE_IINSPECTABLE( json_value_statics, IJsonValueStatics, struct json_value_statics, IActivationFactory_iface ) -static HRESULT unescape_string( const WCHAR *src, HSTRING *output ) +static void trim_string( const WCHAR **input, UINT32 *len ) { - UINT32 len = wcslen( src ) - 1, n; - const WCHAR *end = src + len; - HSTRING_BUFFER buf; + static const WCHAR valid_whitespace[] = L" \t\n\r"; + UINT32 end = *len, start = 0; + + while (start < end && wcschr( valid_whitespace, (*input)[start] )) start++; + while (end > start && wcschr( valid_whitespace, (*input)[end - 1] )) end--; + + *len = end - start; + *input += start; +} + +static HRESULT parse_json_value( const WCHAR **json, UINT32 *len, struct json_value *impl ); + +static HRESULT parse_json_array( const WCHAR **json, UINT32 *len, struct json_value *impl ) +{ + struct json_value *child; + IJsonArray *array; HRESULT hr; + + TRACE( "json %s, impl %p", debugstr_wn( *json, *len ), impl ); + + if (FAILED(hr = IActivationFactory_ActivateInstance( + json_array_factory, (IInspectable**)&array ))) return hr; + + (*json)++; + (*len)--; + + trim_string( json, len ); + while (len && **json != ']') + { + if (!(child = calloc( 1, sizeof( *child ) ))) + { + IJsonArray_Release( array ); + return E_OUTOFMEMORY; + } + + child->IJsonValue_iface.lpVtbl = &json_value_vtbl; + child->ref = 1; + + if (FAILED(hr = parse_json_value( json, len, child ))) + { + IJsonValue_Release( &child->IJsonValue_iface ); + IJsonArray_Release( array ); + return hr; + } + + if (FAILED(hr = json_array_push( array, &child->IJsonValue_iface ))) + { + IJsonValue_Release( &child->IJsonValue_iface ); + IJsonArray_Release( array ); + return hr; + } + + trim_string( json, len ); + + if (**json == ',') + { + (*json)++; + (*len)--; + } + else if (**json != ']') + { + IJsonArray_Release( array ); + return WEB_E_INVALID_JSON_STRING; + } + + trim_string( json, len ); + } + + (*json)++; + (*len)--; + + impl->parsed_array = array; + impl->json_value_type = JsonValueType_Array; + return S_OK; +} + +static HRESULT parse_json_string( const WCHAR **json, UINT32 *len, HSTRING *output ) +{ + const WCHAR valid_hex_chars[] = L"abcdefABCDEF0123456789"; + const WCHAR valid_escape_chars[] = L"\"\\/bfnrtu"; + UINT32 string_len = 0; + HSTRING_BUFFER buf; + UINT32 offset = 0; + HRESULT hr = S_OK; WCHAR *dst; - for (len = n = 0; len + n < end - src; len++) { if (src[len + n] == '\\') n++; } - if (FAILED(hr = WindowsPreallocateStringBuffer( len, &dst, &buf ))) return hr; - while (src != end) { if (*src == '\\' && ++src == end) break; *dst++ = *src++; } + TRACE( "json %s, output %p", debugstr_wn( *json, *len ), output ); + + (*json)++; + (*len)--; + + /* validate string */ + + while (offset < *len) + { + if ((*json)[offset] < 32) return WEB_E_INVALID_JSON_STRING; + + if ((*json)[offset] == '\\') + { + if (*len - offset < 3 || + !wcschr( valid_escape_chars, (*json)[offset + 1]) || + ( (*json)[offset + 1] == 'u' && ( + !wcschr( valid_hex_chars, (*json)[offset + 2]) || + !wcschr( valid_hex_chars, (*json)[offset + 3]) || + !wcschr( valid_hex_chars, (*json)[offset + 4]) || + !wcschr( valid_hex_chars, (*json)[offset + 5]) ) )) + return WEB_E_INVALID_JSON_STRING; + + string_len++; + if ((*json)[offset + 1] == 'u') offset += 6; + else offset += 2; + } + else if ((*json)[offset] == '"') break; + else + { + string_len++; + offset++; + } + } + + if (offset == *len) return WEB_E_INVALID_JSON_STRING; + + /* create & escape string */ + + if (FAILED(hr = WindowsPreallocateStringBuffer( string_len, &dst, &buf ))) return hr; + + for (UINT32 i = 0; i < string_len; i++) + { + if (**json == '\\') + { + (*json)++; + *len -= 2; + if (**json == '"') { *dst++ = '"'; (*json)++; } + else if (**json == '\\') { *dst++ = '\\'; (*json)++; } + else if (**json == '/') { *dst++ = '/'; (*json)++; } + else if (**json == 'b') { *dst++ = '\b'; (*json)++; } + else if (**json == 'f') { *dst++ = '\f'; (*json)++; } + else if (**json == 'n') { *dst++ = '\n'; (*json)++; } + else if (**json == 'r') { *dst++ = '\r'; (*json)++; } + else if (**json == 't') { *dst++ = '\t'; (*json)++; } + else + { + (*json)++; + *len -= 4; + if (**json >= 65) *dst = ((*(*json)++ & 0x7) + 10) << 12; + else *dst = (*(*json)++ & 0xf) << 12; + + if (**json >= 65) *dst |= ((*(*json)++ & 0x7) + 10) << 8; + else *dst |= (*(*json)++ & 0xf) << 8; + + if (**json >= 65) *dst |= ((*(*json++) & 0x7) + 10) << 4; + else *dst |= (*(*json)++ & 0xf) << 4; + + if (**json >= 65) *dst++ |= (*(*json)++ & 0x7) + 10; + else *dst++ |= *(*json)++ & 0xf; + } + } + else + { + *dst++ = *(*json)++; + (*len)--; + } + } + + (*json)++; + (*len)--; return WindowsPromoteStringBuffer( buf, output ); } -static HRESULT trim_string( HSTRING input, HSTRING *output ) +static HRESULT parse_json_object( const WCHAR **json, UINT32 *len, struct json_value *impl ) { - static const WCHAR valid_whitespace[] = L" \t\n\r"; - UINT32 len, start = 0, end; - const WCHAR *json = WindowsGetStringRawBuffer( input, &len ); + struct json_value *child; + HSTRING name; + HRESULT hr; + + TRACE( "json %s, impl %p", debugstr_wn( *json, *len ), impl ); + + if (FAILED(hr = IActivationFactory_ActivateInstance( + json_object_factory, (IInspectable**)&impl->parsed_object ))) return hr; - end = len; - while (start < end && wcschr( valid_whitespace, json[start] )) start++; - while (end > start && wcschr( valid_whitespace, json[end - 1] )) end--; + (*json)++; + (*len)--; - return WindowsCreateString( json + start, end - start, output ); + trim_string( json, len ); + while (*len && **json != '}') + { + if (FAILED(hr = parse_json_string( json, len, &name ))) + { + IJsonObject_Release( impl->parsed_object ); + return hr; + } + + trim_string( json, len ); + if (!*len || **json != ':') + { + IJsonObject_Release( impl->parsed_object ); + WindowsDeleteString( name ); + return WEB_E_INVALID_JSON_STRING; + } + (*json)++; + (*len)--; + trim_string( json, len ); + + if (!(child = calloc( 1, sizeof( *child ) ))) + { + IJsonObject_Release( impl->parsed_object ); + WindowsDeleteString( name ); + return E_OUTOFMEMORY; + } + + child->IJsonValue_iface.lpVtbl = &json_value_vtbl; + child->ref = 1; + + if (FAILED(hr = parse_json_value( json, len, child ))) + { + IJsonValue_Release( &child->IJsonValue_iface ); + IJsonObject_Release( impl->parsed_object ); + WindowsDeleteString( name ); + return hr; + } + + hr = IJsonObject_SetNamedValue( impl->parsed_object, name, &child->IJsonValue_iface ); + IJsonValue_Release( &child->IJsonValue_iface ); + if (FAILED(hr)) + { + IJsonObject_Release( impl->parsed_object ); + WindowsDeleteString( name ); + return hr; + } + + trim_string( json, len ); + if (**json == ',') (*json)++; + else if (**json != '}') return WEB_E_INVALID_JSON_STRING; + trim_string( json, len ); + } + + if (!*len) return WEB_E_INVALID_JSON_STRING; + (*json)++; + (*len)--; + + impl->json_value_type = JsonValueType_Object; + return S_OK; } -static HRESULT parse_json_value( HSTRING input, struct json_value *impl ) +static HRESULT parse_json_value( const WCHAR **json, UINT32 *len, struct json_value *impl ) { - UINT32 len; - const WCHAR *json = WindowsGetStringRawBuffer( input, &len ); HRESULT hr = S_OK; - /* FIXME: Handle all JSON edge cases */ + TRACE( "json %s, impl %p\n", debugstr_wn( *json, *len ), impl ); - if (!len) return WEB_E_INVALID_JSON_STRING; + if (!*len) return WEB_E_INVALID_JSON_STRING; - if (len == 4 && !wcsncmp( L"null", json, 4 )) + if (*len >= 4 && !wcsncmp( L"null", *json, 4 )) { + *json += 4; + *len -= 4; impl->json_value_type = JsonValueType_Null; } - else if ((len == 4 && !wcsncmp( L"true", json, 4 )) || (len == 5 && !wcsncmp( L"false", json, 5 ))) + else if (*len >= 4 && !wcsncmp( L"true", *json, 4)) { - impl->parsed_boolean = len == 4; + *json += 4; + *len -= 4; + impl->parsed_boolean = TRUE; impl->json_value_type = JsonValueType_Boolean; } - else if (json[0] == '\"' && json[len - 1] == '\"') + else if (*len >= 5 && !wcsncmp( L"false", *json, 5 )) { - json++; - len -= 2; - - if (len <= 2) return WEB_E_INVALID_JSON_STRING; - if (FAILED(hr = unescape_string( json, &impl->parsed_string ))) return hr; - + *json += 5; + *len -= 5; + impl->parsed_boolean = FALSE; + impl->json_value_type = JsonValueType_Boolean; + } + else if (**json == '\"') + { + if (FAILED(hr = parse_json_string( json, len, &impl->parsed_string ))) return hr; impl->json_value_type = JsonValueType_String; } - else if (json[0] == '[' && json[len - 1] == ']') + else if (**json == '[') { - FIXME( "Array parsing not implemented!\n" ); - impl->json_value_type = JsonValueType_Array; + if (FAILED(hr = parse_json_array( json, len, impl ))) return hr; } - else if (json[0] == '{' && json[len - 1] == '}') + else if (**json == '{') { - FIXME( "Object parsing not implemented!\n" ); - impl->json_value_type = JsonValueType_Object; + if (FAILED(hr = parse_json_object( json, len, impl ))) return hr; } else { @@ -369,9 +597,12 @@ static HRESULT parse_json_value( HSTRING input, struct json_value *impl ) WCHAR *end; errno = 0; - result = wcstold( json, &end ); + result = wcstold( *json, &end ); - if (errno || errno == ERANGE || end != json + len) return WEB_E_INVALID_JSON_NUMBER; + *len -= end - *json; + *json = end; + + if (errno || errno == ERANGE) return WEB_E_INVALID_JSON_NUMBER; impl->parsed_number = result; impl->json_value_type = JsonValueType_Number; @@ -380,16 +611,17 @@ static HRESULT parse_json_value( HSTRING input, struct json_value *impl ) return hr; } -static HRESULT parse_json( HSTRING json, struct json_value *impl ) +static HRESULT parse_json( HSTRING string, struct json_value *impl ) { - HSTRING trimmed_json = NULL; - HRESULT hr = trim_string( json, &trimmed_json ); - - if (SUCCEEDED(hr) && WindowsIsStringEmpty( trimmed_json )) hr = WEB_E_INVALID_JSON_STRING; - if (SUCCEEDED(hr)) hr = parse_json_value( trimmed_json, impl ); + HRESULT hr; + UINT32 len; + const WCHAR *json = WindowsGetStringRawBuffer( string, &len ); - WindowsDeleteString( trimmed_json ); - return hr; + trim_string( &json, &len ); + if (!len) return WEB_E_INVALID_JSON_STRING; + if (FAILED(hr = parse_json_value( &json, &len, impl ))) return hr; + if (len) return WEB_E_INVALID_JSON_STRING; + return S_OK; } static HRESULT WINAPI json_value_statics_Parse( IJsonValueStatics *iface, HSTRING input, IJsonValue **value ) @@ -397,7 +629,7 @@ static HRESULT WINAPI json_value_statics_Parse( IJsonValueStatics *iface, HSTRIN struct json_value *impl; HRESULT hr; - FIXME( "iface %p, input %s, value %p semi-stub\n", iface, debugstr_hstring( input ), value ); + TRACE( "iface %p, input %s, value %p\n", iface, debugstr_hstring( input ), value ); if (!value) return E_POINTER; if (!input) return WEB_E_INVALID_JSON_STRING; @@ -424,14 +656,40 @@ static HRESULT WINAPI json_value_statics_TryParse( IJsonValueStatics *iface, HST static HRESULT WINAPI json_value_statics_CreateBooleanValue( IJsonValueStatics *iface, boolean input, IJsonValue **value ) { - FIXME( "iface %p, input %d, value %p stub!\n", iface, input, value ); - return E_NOTIMPL; + struct json_value *impl; + + TRACE( "iface %p, input %d, value %p\n", iface, input, value ); + + if (!value) return E_POINTER; + if (!(impl = calloc( 1, sizeof(*impl) ))) return E_OUTOFMEMORY; + + impl->IJsonValue_iface.lpVtbl = &json_value_vtbl; + impl->ref = 1; + impl->json_value_type = JsonValueType_Boolean; + impl->parsed_boolean = input != FALSE; + + *value = &impl->IJsonValue_iface; + TRACE( "created IJsonValue %p.\n", *value ); + return S_OK; } static HRESULT WINAPI json_value_statics_CreateNumberValue( IJsonValueStatics *iface, DOUBLE input, IJsonValue **value ) { - FIXME( "iface %p, input %f, value %p stub!\n", iface, input, value ); - return E_NOTIMPL; + struct json_value *impl; + + TRACE( "iface %p, input %f, value %p\n", iface, input, value ); + + if (!value) return E_POINTER; + if (!(impl = calloc( 1, sizeof(*impl) ))) return E_OUTOFMEMORY; + + impl->IJsonValue_iface.lpVtbl = &json_value_vtbl; + impl->ref = 1; + impl->json_value_type = JsonValueType_Number; + impl->parsed_number = input; + + *value = &impl->IJsonValue_iface; + TRACE( "created IJsonValue %p.\n", *value ); + return S_OK; } static HRESULT WINAPI json_value_statics_CreateStringValue( IJsonValueStatics *iface, HSTRING input, IJsonValue **value ) @@ -447,7 +705,7 @@ static HRESULT WINAPI json_value_statics_CreateStringValue( IJsonValueStatics *i impl->IJsonValue_iface.lpVtbl = &json_value_vtbl; impl->ref = 1; impl->json_value_type = JsonValueType_String; - if (FAILED(hr = WindowsDuplicateString( input, &impl->string_value ))) + if (FAILED(hr = WindowsDuplicateString( input, &impl->parsed_string ))) { free( impl ); return hr; diff --git a/dlls/windows.web/main.c b/dlls/windows.web/main.c index 60e95fdba0c..bec92a81775 100644 --- a/dlls/windows.web/main.c +++ b/dlls/windows.web/main.c @@ -38,6 +38,8 @@ HRESULT WINAPI DllGetActivationFactory( HSTRING classid, IActivationFactory **fa *factory = NULL; + if (!wcscmp( buffer, RuntimeClass_Windows_Data_Json_JsonArray )) + IActivationFactory_QueryInterface( json_array_factory, &IID_IActivationFactory, (void **)factory ); if (!wcscmp( buffer, RuntimeClass_Windows_Data_Json_JsonObject )) IActivationFactory_QueryInterface( json_object_factory, &IID_IActivationFactory, (void **)factory ); if (!wcscmp( buffer, RuntimeClass_Windows_Data_Json_JsonValue )) diff --git a/dlls/windows.web/private.h b/dlls/windows.web/private.h index d5f0e76d641..0cc2a351199 100644 --- a/dlls/windows.web/private.h +++ b/dlls/windows.web/private.h @@ -29,6 +29,7 @@ #include "winstring.h" #include "activation.h" +#include "roapi.h" #define WIDL_using_Windows_Foundation #define WIDL_using_Windows_Foundation_Collections @@ -36,9 +37,13 @@ #define WIDL_using_Windows_Data_Json #include "windows.data.json.h" +extern IActivationFactory *json_array_factory; extern IActivationFactory *json_object_factory; extern IActivationFactory *json_value_factory; +HRESULT json_array_push( IJsonArray *iface, IJsonValue *value ); +HRESULT json_array_pop( IJsonArray *iface, IJsonValue **value ); + #define DEFINE_IINSPECTABLE_( pfx, iface_type, impl_type, impl_from, iface_mem, expr ) \ static inline impl_type *impl_from( iface_type *iface ) \ { \ diff --git a/dlls/windows.web/tests/web.c b/dlls/windows.web/tests/web.c index b0f38edfb3b..0c1d822ed3c 100644 --- a/dlls/windows.web/tests/web.c +++ b/dlls/windows.web/tests/web.c @@ -45,6 +45,51 @@ static void check_interface_( unsigned int line, void *obj, const IID *iid ) IUnknown_Release( unk ); } +static void test_JsonArrayStatics(void) +{ + static const WCHAR *json_array_name = L"Windows.Data.Json.JsonArray"; + IActivationFactory *factory = (void *)0xdeadbeef; + IInspectable *inspectable = (void *)0xdeadbeef; + IJsonArray *json_array = (void *)0xdeadbeef; + HSTRING str = NULL; + HRESULT hr; + LONG ref; + + hr = WindowsCreateString( json_array_name, wcslen( json_array_name ), &str ); + ok( hr == S_OK, "got hr %#lx.\n", hr ); + hr = RoGetActivationFactory( str, &IID_IActivationFactory, (void **)&factory ); + WindowsDeleteString( str ); + ok( hr == S_OK || broken( hr == REGDB_E_CLASSNOTREG ), "got hr %#lx.\n", hr ); + if (hr == REGDB_E_CLASSNOTREG) + { + win_skip( "%s runtimeclass not registered, skipping tests.\n", wine_dbgstr_w( json_array_name ) ); + return; + } + + check_interface( factory, &IID_IUnknown ); + check_interface( factory, &IID_IInspectable ); + check_interface( factory, &IID_IAgileObject ); + + hr = IActivationFactory_QueryInterface( factory, &IID_IJsonArray, (void **)&json_array ); + ok( hr == E_NOINTERFACE, "got hr %#lx.\n", hr ); + + hr = WindowsCreateString( json_array_name, wcslen( json_array_name ), &str ); + ok( hr == S_OK, "got hr %#lx.\n", hr ); + hr = RoActivateInstance( str, &inspectable ); + ok( hr == S_OK, "got hr %#lx.\n", hr ); + WindowsDeleteString( str ); + + hr = IInspectable_QueryInterface( inspectable, &IID_IJsonArray, (void **)&json_array ); + ok( hr == S_OK, "got hr %#lx.\n", hr ); + + check_interface( inspectable, &IID_IAgileObject ); + + IJsonArray_Release( json_array ); + IInspectable_Release( inspectable ); + ref = IActivationFactory_Release( factory ); + ok( ref == 1, "got ref %ld.\n", ref ); +} + static void test_JsonObjectStatics(void) { static const WCHAR *json_object_name = L"Windows.Data.Json.JsonObject"; @@ -112,7 +157,6 @@ static void check_json_( unsigned int line, IJsonValueStatics *json_value_static if (expected_json_value_type == JsonValueType_Number) ok_(__FILE__, line)( hr == WEB_E_INVALID_JSON_NUMBER, "got hr %#lx.\n", hr ); else - todo_wine ok_(__FILE__, line)( hr == WEB_E_INVALID_JSON_STRING, "got hr %#lx.\n", hr ); WindowsDeleteString( str ); @@ -187,13 +231,11 @@ static void check_json_( unsigned int line, IJsonValueStatics *json_value_static break; case JsonValueType_Array: hr = IJsonValue_GetArray( json_value, &json_array ); - todo_wine ok_(__FILE__, line)( hr == S_OK, "got hr %#lx.\n", hr ); if (hr == S_OK) IJsonArray_Release( json_array ); break; case JsonValueType_Object: hr = IJsonValue_GetObject( json_value, &json_object ); - todo_wine ok_(__FILE__, line)( hr == S_OK, "got hr %#lx.\n", hr ); if (hr == S_OK) IJsonObject_Release( json_object ); break; @@ -289,7 +331,6 @@ static void test_JsonValueStatics(void) hr = IJsonValueStatics_Parse( json_value_statics, str, NULL ); ok( hr == E_POINTER, "got hr %#lx.\n", hr ); hr = IJsonValueStatics_Parse( json_value_statics, str, &json_value ); - todo_wine ok( hr == WEB_E_INVALID_JSON_STRING, "got hr %#lx.\n", hr ); WindowsDeleteString( str ); @@ -404,6 +445,7 @@ START_TEST(web) hr = RoInitialize( RO_INIT_MULTITHREADED ); ok( hr == S_OK, "RoInitialize failed, hr %#lx\n", hr ); + test_JsonArrayStatics(); test_JsonObjectStatics(); test_JsonValueStatics(); diff --git a/dlls/xgameruntime/GDKComponent/System/User/Token.c b/dlls/xgameruntime/GDKComponent/System/User/Token.c new file mode 100644 index 00000000000..c0e5e6e4edd --- /dev/null +++ b/dlls/xgameruntime/GDKComponent/System/User/Token.c @@ -0,0 +1,499 @@ +/* + * Copyright 2026 Olivia Ryan + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA + */ + +#include "Token.h" + +#define GetJsonValue( obj_type, ret_type ) \ +static inline HRESULT GetJson##obj_type##Value( IJsonObject *object, LPCWSTR key, ret_type value ) \ +{ \ + HSTRING_HEADER key_hdr; \ + HSTRING key_hstr; \ + HRESULT hr; \ + \ + if (FAILED( hr = WindowsCreateStringReference( key, wcslen( key ), &key_hdr, &key_hstr ) )) \ + return hr; \ + \ + if (FAILED( hr = IJsonObject_GetNamed##obj_type( object, key_hstr, value ) )) \ + return hr; \ + \ + return S_OK; \ +} + +GetJsonValue( Array, IJsonArray** ); +GetJsonValue( Number, DOUBLE* ); +GetJsonValue( Object, IJsonObject** ); +GetJsonValue( String, HSTRING* ); + +HRESULT HSTRINGToMultiByte( HSTRING hstr, LPSTR *str, UINT32 *str_len ) +{ + UINT32 wstr_len; + LPCWSTR wstr = WindowsGetStringRawBuffer( hstr, &wstr_len ); + + if (!(*str_len = WideCharToMultiByte( CP_UTF8, 0, wstr, wstr_len, NULL, 0, NULL, NULL ))) + return HRESULT_FROM_WIN32( GetLastError() ); + + if (!(*str = calloc( 1, *str_len ))) return E_OUTOFMEMORY; + + if (!(*str_len = WideCharToMultiByte( CP_UTF8, 0, wstr, wstr_len, *str, *str_len, NULL, NULL ))) + { + free( *str ); + *str = NULL; + return HRESULT_FROM_WIN32( GetLastError() ); + } + + return S_OK; +} + +static HRESULT HttpRequest( LPCWSTR method, LPCWSTR domain, LPCWSTR object, LPSTR data, LPCWSTR headers, LPCWSTR *accept, LPSTR *buffer, SIZE_T *bufferSize ) +{ + HINTERNET connection = NULL; + DWORD size = sizeof( DWORD ); + HINTERNET session = NULL; + HINTERNET request = NULL; + HRESULT hr = S_OK; + DWORD status; + + if (!(session = WinHttpOpen( + L"WineGDK/1.0", + WINHTTP_ACCESS_TYPE_AUTOMATIC_PROXY, + WINHTTP_NO_PROXY_NAME, + WINHTTP_NO_PROXY_BYPASS, + 0 + ))) return HRESULT_FROM_WIN32( GetLastError() ); + + if (!(connection = WinHttpConnect( + session, + domain, + INTERNET_DEFAULT_HTTPS_PORT, + 0 + ))) hr = HRESULT_FROM_WIN32( GetLastError() ); + + if (SUCCEEDED( hr ) && !(request = WinHttpOpenRequest( + connection, + method, + object, + NULL, + WINHTTP_NO_REFERER, + accept, + WINHTTP_FLAG_SECURE + ))) hr = HRESULT_FROM_WIN32( GetLastError() ); + + if (SUCCEEDED( hr ) && !WinHttpSendRequest( + request, + headers, + -1, + data, + strlen( data ), + strlen( data ), + 0 + )) hr = HRESULT_FROM_WIN32( GetLastError() ); + + if (SUCCEEDED( hr ) && !WinHttpReceiveResponse( request, NULL )) + hr = HRESULT_FROM_WIN32( GetLastError() ); + + if (SUCCEEDED( hr ) && !WinHttpQueryHeaders( + request, + WINHTTP_QUERY_STATUS_CODE | WINHTTP_QUERY_FLAG_NUMBER, + WINHTTP_HEADER_NAME_BY_INDEX, + &status, + &size, + WINHTTP_NO_HEADER_INDEX + )) hr = HRESULT_FROM_WIN32( GetLastError() ); + + if (SUCCEEDED( hr ) && status / 100 != 2) hr = E_FAIL; + + /* buffer response data */ + *buffer = NULL; + *bufferSize = 0; + if (SUCCEEDED( hr )) + { + do + { + if (!(WinHttpQueryDataAvailable( request, &size ))) + { + hr = HRESULT_FROM_WIN32( GetLastError() ); + break; + } + + if (!size) break; + if (!(*buffer = realloc( *buffer, *bufferSize + size ))) + { + hr = E_OUTOFMEMORY; + break; + } + + if (!(WinHttpReadData( request, *buffer + *bufferSize, size, &size ))) + { + hr = HRESULT_FROM_WIN32( GetLastError() ); + break; + } + + *bufferSize += size; + } + while (size); + } + + if (connection) WinHttpCloseHandle( connection ); + if (request) WinHttpCloseHandle( request ); + if (session) WinHttpCloseHandle( session ); + if (FAILED( hr ) && *buffer) free( *buffer ); + + return hr; +} + +static HRESULT ParseJsonObject( LPCSTR str, UINT32 str_size, IJsonObject **object ) +{ + LPCWSTR class_str = RuntimeClass_Windows_Data_Json_JsonValue; + IJsonValueStatics *statics; + HSTRING_HEADER content_hdr; + HSTRING_HEADER class_hdr; + IJsonValue *value; + UINT32 wstr_size; + HSTRING content; + HSTRING class; + LPWSTR wstr; + HRESULT hr; + + if (!(wstr_size = MultiByteToWideChar( CP_UTF8, 0, str, str_size, NULL, 0 ))) + return HRESULT_FROM_WIN32( GetLastError() ); + + if (!(wstr = calloc( wstr_size, sizeof( WCHAR ) ))) + return E_OUTOFMEMORY; + + if (!(wstr_size = MultiByteToWideChar( CP_UTF8, 0, str, str_size, wstr, wstr_size ))) + { + free( wstr ); + return HRESULT_FROM_WIN32( GetLastError() ); + } + + if (FAILED( hr = WindowsCreateStringReference( wstr, wstr_size, &content_hdr, &content ) )) + { + free( wstr ); + return hr; + } + + if (FAILED( hr = WindowsCreateStringReference( class_str, wcslen( class_str ), &class_hdr, &class ) )) + { + free( wstr ); + return hr; + } + + if (FAILED( hr = RoGetActivationFactory( class, &IID_IJsonValueStatics, (void**)&statics ) )) + { + free( wstr ); + return hr; + } + + hr = IJsonValueStatics_Parse( statics, content, &value ); + IJsonValueStatics_Release( statics ); + free( wstr ); + if (FAILED( hr )) return hr; + + hr = IJsonValue_GetObject( value, object ); + IJsonValue_Release( value ); + if (FAILED( hr )) IJsonObject_Release( *object ); + + return hr; +} + +HRESULT RefreshOAuth( LPCSTR client_id, LPCSTR refresh_token, time_t *new_expiry, HSTRING *new_refresh_token, HSTRING *new_oauth_token ) +{ + LPCSTR template = "grant_type=refresh_token&scope=service::user.auth.xboxlive.com::MBI_SSL&client_id="; + LPCWSTR accept[] = {L"application/json", NULL}; + IJsonObject *object; + time_t expiry; + LPSTR buffer; + DOUBLE delta; + SIZE_T size; + HRESULT hr; + LPSTR data; + + if (!(data = calloc( strlen( template ) + strlen( client_id ) + strlen( "&refresh_token=" ) + strlen( refresh_token ) + 1, sizeof( CHAR ) ))) + return E_OUTOFMEMORY; + + strcpy( data, template ); + strcat( data, client_id ); + strcat( data, "&refresh_token=" ); + strcat( data, refresh_token ); + + hr = HttpRequest( + L"POST", + L"login.live.com", + L"/oauth20_token.srf", + data, + L"content-type: application/x-www-form-urlencoded", + accept, + &buffer, + &size + ); + + free( data ); + if (FAILED( hr )) return hr; + hr = ParseJsonObject( buffer, size, &object ); + free( buffer ); + if (FAILED( hr )) return hr; + + if (FAILED( hr = GetJsonStringValue( object, L"access_token", new_oauth_token ) )) + { + IJsonObject_Release( object ); + return hr; + } + + if (FAILED( hr = GetJsonStringValue( object, L"refresh_token", new_refresh_token ) )) + { + IJsonObject_Release( object ); + return hr; + } + + if (FAILED( hr = GetJsonNumberValue( object, L"expires_in", &delta ) )) + IJsonObject_Release( object ); + if (FAILED( hr )) return hr; + + if ((expiry = time( NULL )) == -1) return E_FAIL; + *new_expiry = expiry + delta; + + return S_OK; +} + +HRESULT RequestUserToken( HSTRING oauth_token, HSTRING *token, XUserLocalId *local_id ) +{ + LPCSTR template = "{\"RelyingParty\":\"http://auth.xboxlive.com\",\"TokenType\":\"JWT\",\"Properties\":{\"AuthMethod\":\"RPS\",\"SiteName\":\"user.auth.xboxlive.com\",\"RpsTicket\":\""; + LPCWSTR accept[] = {L"application/json", NULL}; + IJsonObject *display_claims; + UINT32 token_str_len; + IJsonObject *object; + UINT32 uhs_str_len; + LPSTR token_str; + IJsonArray *xui; + LPSTR uhs_str; + LPSTR buffer; + SIZE_T size; + HSTRING uhs; + LPSTR data; + HRESULT hr; + + if (FAILED( hr = HSTRINGToMultiByte( oauth_token, &token_str, &token_str_len ) )) + return hr; + + if (!(data = calloc( strlen( template ) + token_str_len + strlen( "\"}}" ) + 1, sizeof( CHAR ) ))) + { + free( token_str ); + return E_OUTOFMEMORY; + } + + strcpy( data, template ); + strncat( data, token_str, token_str_len ); + free( token_str ); + strcat( data, "\"}}" ); + + hr = HttpRequest( + L"POST", + L"user.auth.xboxlive.com", + L"/user/authenticate", + data, + L"content-type: application/json", + accept, + &buffer, + &size + ); + + free( data ); + if (FAILED( hr )) return hr; + hr = ParseJsonObject( buffer, size, &object ); + free( buffer ); + if (FAILED( hr )) return hr; + + if (FAILED( hr = GetJsonStringValue( object, L"Token", token ) )) + { + IJsonObject_Release( object ); + return hr; + } + + hr = GetJsonObjectValue( object, L"DisplayClaims", &display_claims ); + IJsonObject_Release( object ); + if (FAILED( hr )) + { + WindowsDeleteString( *token ); + return hr; + } + + hr = GetJsonArrayValue( display_claims, L"xui", &xui ); + IJsonObject_Release( display_claims ); + if (FAILED( hr )) + { + WindowsDeleteString( *token ); + return hr; + } + + hr = IJsonArray_GetObjectAt( xui, 0, &object ); + IJsonArray_Release( xui ); + if (FAILED( hr )) + { + WindowsDeleteString( *token ); + return hr; + } + + hr = GetJsonStringValue( object, L"uhs", &uhs ); + IJsonObject_Release( object ); + if (FAILED( hr )) + { + WindowsDeleteString( *token ); + return hr; + } + + hr = HSTRINGToMultiByte( uhs, &uhs_str, &uhs_str_len ); + WindowsDeleteString( uhs ); + if (FAILED( hr )) + { + WindowsDeleteString( *token ); + return hr; + } + + local_id->value = strtoull( uhs_str, NULL, 10 ); + free( uhs_str ); + if (errno == ERANGE) + { + WindowsDeleteString( *token ); + errno = 0; + return E_FAIL; + } + + return hr; +} + +HRESULT RequestXstsToken( HSTRING user_token, HSTRING *token, UINT64 *xuid, XUserAgeGroup *age_group ) +{ + LPCSTR template = "{\"RelyingParty\":\"http://xboxlive.com\",\"TokenType\":\"JWT\",\"Properties\":{\"SandboxId\":\"RETAIL\",\"UserTokens\":[\""; + LPCWSTR accept[] = {L"application/json", NULL}; + IJsonObject *display_claims; + UINT32 token_str_len; + IJsonObject *object; + UINT32 xid_str_len; + LPCWSTR agg_str; + LPSTR token_str; + IJsonArray *xui; + UINT32 agg_len; + LPSTR xid_str; + LPSTR buffer; + HSTRING agg; + SIZE_T size; + HSTRING xid; + HRESULT hr; + LPSTR data; + + if (FAILED( hr = HSTRINGToMultiByte( user_token, &token_str, &token_str_len ) )) + return hr; + + if (!(data = calloc( strlen( template ) + token_str_len + strlen( "\"]}}" ) + 1, sizeof( CHAR ) ))) + { + free( token_str ); + return E_OUTOFMEMORY; + } + + strcpy( data, template ); + strncat(data, token_str, token_str_len); + free( token_str ); + strcat( data, "\"]}}" ); + + hr = HttpRequest( + L"POST", + L"xsts.auth.xboxlive.com", + L"/xsts/authorize", + data, + L"content-type: application/json", + accept, + &buffer, + &size + ); + + free( data ); + if (FAILED( hr )) return hr; + hr = ParseJsonObject( buffer, size, &object ); + free( buffer ); + if (FAILED( hr )) return hr; + + if (FAILED( hr = GetJsonStringValue( object, L"Token", token ) )) + { + IJsonObject_Release( object ); + return hr; + } + + hr = GetJsonObjectValue( object, L"DisplayClaims", &display_claims ); + IJsonObject_Release( object ); + if (FAILED( hr )) + { + WindowsDeleteString( *token ); + return hr; + } + + hr = GetJsonArrayValue( display_claims, L"xui", &xui ); + IJsonObject_Release( display_claims ); + if (FAILED( hr )) + { + WindowsDeleteString( *token ); + return hr; + } + + hr = IJsonArray_GetObjectAt( xui, 0, &object ); + IJsonArray_Release( xui ); + if (FAILED( hr )) + { + WindowsDeleteString( *token ); + return hr; + } + + if (FAILED( hr = GetJsonStringValue( object, L"agg", &agg ))) + { + IJsonObject_Release( object ); + WindowsDeleteString( *token ); + return hr; + } + + agg_str = WindowsGetStringRawBuffer( agg, &agg_len ); + if (agg_len >= 5 && wcsncmp( agg_str, L"Child", 5 )) *age_group = XUserAgeGroup_Child; + else if (agg_len >= 4 && wcsncmp( agg_str, L"Teen", 4 )) *age_group = XUserAgeGroup_Teen; + else if (agg_len >= 5 && wcsncmp( agg_str, L"Adult", 5 )) *age_group = XUserAgeGroup_Adult; + else *age_group = XUserAgeGroup_Unknown; + + hr = GetJsonStringValue( object, L"xid", &xid ); + IJsonObject_Release( object ); + if (FAILED( hr )) + { + WindowsDeleteString( *token ); + return hr; + } + + hr = HSTRINGToMultiByte( xid, &xid_str, &xid_str_len ); + WindowsDeleteString( xid ); + if (FAILED( hr )) + { + WindowsDeleteString( *token ); + return hr; + } + + *xuid = strtoull( xid_str, NULL, 10 ); + free( xid_str ); + if (errno == ERANGE) + { + WindowsDeleteString( *token ); + errno = 0; + return E_FAIL; + } + + return hr; +} \ No newline at end of file diff --git a/dlls/xgameruntime/GDKComponent/System/User/Token.h b/dlls/xgameruntime/GDKComponent/System/User/Token.h new file mode 100644 index 00000000000..dc6927e0cd6 --- /dev/null +++ b/dlls/xgameruntime/GDKComponent/System/User/Token.h @@ -0,0 +1,40 @@ +/* + * Copyright 2026 Olivia Ryan + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA + */ + +#ifndef TOKEN_H +#define TOKEN_H + +#include "../../../private.h" + +#include +#include +#include "time.h" + +struct token +{ + time_t expiry; + LPCSTR content; + UINT32 size; +}; + +HRESULT RefreshOAuth( LPCSTR client_id, LPCSTR refresh_token, time_t *new_expiry, HSTRING *new_refresh_token, HSTRING *new_oauth_token ); +HRESULT RequestUserToken( HSTRING oauth_token, HSTRING *token, XUserLocalId *localId ); +HRESULT RequestXstsToken( HSTRING user_token, HSTRING *token, UINT64 *xuid, XUserAgeGroup *age_group ); +HRESULT HSTRINGToMultiByte( HSTRING hstr, LPSTR *str, UINT32 *str_len ); + +#endif \ No newline at end of file diff --git a/dlls/xgameruntime/GDKComponent/System/User/XUser.c b/dlls/xgameruntime/GDKComponent/System/User/XUser.c new file mode 100644 index 00000000000..47082a8dc5f --- /dev/null +++ b/dlls/xgameruntime/GDKComponent/System/User/XUser.c @@ -0,0 +1,798 @@ +/* + * Copyright 2026 Olivia Ryan + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA + */ + +/* + * Xbox Game runtime Library + * GDK Component: System API -> XUser + */ + +#include "XUser.h" +#include "winhttp.h" + +WINE_DEFAULT_DEBUG_CHANNEL(gdkc); + +static const struct IXUserImplVtbl x_user_vtbl; +static const struct IXUserGamertagVtbl x_user_gt_vtbl; + +static HRESULT LoadDefaultUser( XUserHandle *user, LPCSTR client_id ) +{ + struct x_user *impl; + LSTATUS status; + LPSTR buffer; + HRESULT hr; + DWORD size; + + if (!user || !client_id) return E_POINTER; + + if (ERROR_SUCCESS != (status = RegGetValueA( + HKEY_LOCAL_MACHINE, + "Software\\Wine\\WineGDK", + "RefreshToken", + RRF_RT_REG_SZ, + NULL, + NULL, + &size + ))) return HRESULT_FROM_WIN32( status ); + + if (!(buffer = calloc( 1, size ))) return E_OUTOFMEMORY; + + if (ERROR_SUCCESS != (status = RegGetValueA( + HKEY_LOCAL_MACHINE, + "Software\\Wine\\WineGDK", + "RefreshToken", + RRF_RT_REG_SZ, + NULL, + buffer, + &size + ))) + { + free( buffer ); + return HRESULT_FROM_WIN32( status ); + } + + if (!(impl = calloc( 1, sizeof( *impl ) ))) + { + free( buffer ); + return E_OUTOFMEMORY; + } + + impl->IXUserImpl_iface.lpVtbl = &x_user_vtbl; + impl->IXUserGamertag_iface.lpVtbl = &x_user_gt_vtbl; + impl->ref = 1; + + hr = RefreshOAuth( client_id, buffer, &impl->oauth_token_expiry, &impl->refresh_token, &impl->oauth_token ); + free( buffer ); + if (FAILED( hr )) + { + TRACE( "failed to get oauth token\n" ); + IXUserImpl_Release( &impl->IXUserImpl_iface ); + return hr; + } + + if (FAILED( hr = RequestUserToken( impl->oauth_token, &impl->user_token, &impl->local_id ) )) + { + TRACE( "failed to get user token\n" ); + IXUserImpl_Release( &impl->IXUserImpl_iface ); + return hr; + } + + if (FAILED( hr = RequestXstsToken( impl->user_token, &impl->xsts_token, &impl->xuid, &impl->age_group ) )) + { + TRACE( "failed to get xsts token\n" ); + IXUserImpl_Release( &impl->IXUserImpl_iface ); + return hr; + } + + *user = (XUserHandle)impl; + + return hr; +} + +static inline struct x_user *impl_from_IXUserImpl( IXUserImpl *iface ) +{ + return CONTAINING_RECORD( iface, struct x_user, IXUserImpl_iface ); +} + +static HRESULT WINAPI x_user_QueryInterface( IXUserImpl *iface, REFIID iid, void **out ) +{ + struct x_user *impl = impl_from_IXUserImpl( iface ); + + TRACE( "iface %p, iid %s, out %p\n", iface, debugstr_guid( iid ), out ); + + if (!out) return E_POINTER; + + if (IsEqualGUID( iid, &IID_IUnknown ) || + IsEqualGUID( iid, &IID_IXUserBase ) || + IsEqualGUID( iid, &IID_IXUserAddWithUi ) || + IsEqualGUID( iid, &IID_IXUserMsa ) || + IsEqualGUID( iid, &IID_IXUserStore ) || + IsEqualGUID( iid, &IID_IXUserPlatform ) || + IsEqualGUID( iid, &IID_IXUserSignOut )) + { + *out = &impl->IXUserImpl_iface; + IXUserImpl_AddRef( *out ); + return S_OK; + } + + if (IsEqualGUID( iid, &IID_IXUserGamertag )) + { + *out = &impl->IXUserGamertag_iface; + IXUserGamertag_AddRef( *out ); + return S_OK; + } + + FIXME( "%s not implemented, returning E_NOINTERFACE\n", debugstr_guid( iid ) ); + *out = NULL; + return E_NOINTERFACE; +} + +static ULONG WINAPI x_user_AddRef( IXUserImpl *iface ) +{ + struct x_user *impl = impl_from_IXUserImpl( iface ); + ULONG ref = InterlockedIncrement( &impl->ref ); + TRACE( "iface %p increasing refcount to %lu\n", iface, ref ); + return ref; +} + +static ULONG WINAPI x_user_Release( IXUserImpl *iface ) +{ + struct x_user *impl = impl_from_IXUserImpl( iface ); + ULONG ref = InterlockedDecrement( &impl->ref ); + TRACE( "iface %p decreasing refcount to %lu\n", iface, ref ); + if (!ref) + { + WindowsDeleteString( impl->refresh_token ); + WindowsDeleteString( impl->oauth_token ); + WindowsDeleteString( impl->user_token ); + WindowsDeleteString( impl->xsts_token ); + free( impl ); + } + return ref; +} + +static HRESULT WINAPI x_user_XUserDuplicateHandle( IXUserImpl *iface, XUserHandle user, XUserHandle *duplicated ) +{ + TRACE( "iface %p, user %p, duplicated %p\n", iface, user, duplicated ); + if (!user || !duplicated) return E_POINTER; + IXUserImpl_AddRef( &((struct x_user*)user)->IXUserImpl_iface ); + *duplicated = user; + return S_OK; +} + +static void WINAPI x_user_XUserCloseHandle( IXUserImpl *iface, XUserHandle user ) +{ + TRACE( "iface %p, user %p\n", iface, user ); + if (user) IXUserImpl_Release( &((struct x_user*)user)->IXUserImpl_iface ); +} + +static INT32 WINAPI x_user_XUserCompare( IXUserImpl *iface, XUserHandle user1, XUserHandle user2 ) +{ + TRACE( "iface %p, user1 %p, user2 %p\n", iface, user1, user2 ); + if (!user1 || !user2) return 1; + return ((struct x_user*)user1)->xuid != ((struct x_user*)user2)->xuid; +} + +static HRESULT WINAPI x_user_XUserGetMaxUsers( IXUserImpl *iface, UINT32 *maxUsers ) +{ + FIXME( "iface %p, maxUsers %p stub!\n", iface, maxUsers ); + return E_NOTIMPL; +} + +struct XUserAddContext +{ + XUserAddOptions options; + XUserHandle user; + LPCSTR client_id; +}; + +static HRESULT XUserAddProvider( XAsyncOp operation, const XAsyncProviderData *providerData ) +{ + struct XUserAddContext *context; + IXThreadingImpl *impl; + HRESULT hr; + + TRACE( "operation %d, providerData %p\n", operation, providerData ); + + if (!providerData) return E_POINTER; + if (FAILED( QueryApiImpl( &CLSID_XThreadingImpl, &IID_IXThreadingImpl, (void**)&impl ) )) return E_FAIL; + context = providerData->context; + + switch (operation) + { + case Begin: + return impl->lpVtbl->XAsyncSchedule( impl, providerData->async, 0 ); + + case GetResult: + memcpy( providerData->buffer, &context->user, sizeof( XUserHandle ) ); + break; + + case DoWork: + if (context->options & XUserAddOptions_AddDefaultUserAllowingUI) + hr = LoadDefaultUser( &context->user, context->client_id ); + else if (context->options & XUserAddOptions_AddDefaultUserSilently) + hr = LoadDefaultUser( &context->user, context->client_id ); + else hr = E_ABORT; + + impl->lpVtbl->XAsyncComplete( impl, providerData->async, hr, sizeof( XUserHandle ) ); + break; + + case Cleanup: + free( context ); + break; + + case Cancel: + break; + } + + return S_OK; +} + +static HRESULT WINAPI x_user_XUserAddAsync( IXUserImpl *iface, XUserAddOptions options, XAsyncBlock *asyncBlock ) +{ + struct XUserAddContext *context; + IXThreadingImpl *impl; + HRESULT hr; + + TRACE( "iface %p, options %d, asyncBlock %p\n", iface, options, asyncBlock ); + + if (!asyncBlock) return E_POINTER; + if (FAILED( hr = QueryApiImpl( &CLSID_XThreadingImpl, &IID_IXThreadingImpl, (void**)&impl ) )) return hr; + if (!(context = calloc( 1, sizeof( struct XUserAddContext ) ))) + { + impl->lpVtbl->Release( impl ); + return E_OUTOFMEMORY; + } + + context->options = options; + hr = impl->lpVtbl->XAsyncBegin( impl, asyncBlock, context, x_user_XUserAddAsync, "XUserAddAsync", XUserAddProvider ); + impl->lpVtbl->Release( impl ); + return hr; +} + +static HRESULT WINAPI x_user_XUserAddResult( IXUserImpl *iface, XAsyncBlock *asyncBlock, XUserHandle *user ) +{ + IXThreadingImpl *impl; + + TRACE( "iface %p, asyncBlock %p, user %p\n", iface, asyncBlock, user ); + + if (!asyncBlock || !user) return E_POINTER; + if (FAILED( QueryApiImpl( &CLSID_XThreadingImpl, &IID_IXThreadingImpl, (void**)&impl ) )) return E_NOTIMPL; + return impl->lpVtbl->XAsyncGetResult( impl, asyncBlock, x_user_XUserAddAsync, sizeof( XUserHandle ), user, NULL ); +} + +static HRESULT WINAPI x_user_XUserGetLocalId( IXUserImpl *iface, XUserHandle user, XUserLocalId *localId ) +{ + TRACE( "iface %p, user %p, localId %p\n", iface, user, localId ); + if (!user || !localId) return E_POINTER; + *localId = ((struct x_user*)user)->local_id; + return S_OK; +} + +static HRESULT WINAPI x_user_XUserFindUserByLocalId( IXUserImpl *iface, XUserLocalId localId, XUserHandle *user ) +{ + FIXME( "iface %p, localId %p, user %p stub!\n", iface, &localId, user ); + return E_NOTIMPL; +} + +static HRESULT WINAPI x_user_XUserGetId( IXUserImpl *iface, XUserHandle user, UINT64 *userId ) +{ + TRACE( "iface %p, user %p, userId %p\n", iface, user, userId ); + if (!user || !userId) return E_POINTER; + *userId = ((struct x_user*)user)->xuid; + return S_OK; +} + +static HRESULT WINAPI x_user_XUserFindUserById( IXUserImpl *iface, UINT64 userId, XUserHandle *user ) +{ + FIXME( "iface %p, userId %llu, user %p stub!\n", iface, userId, user ); + return E_NOTIMPL; +} + +static HRESULT WINAPI x_user_XUserGetIsGuest( IXUserImpl *iface, XUserHandle user, BOOLEAN *isGuest ) +{ + FIXME( "iface %p, user %p, isGuest %p stub!\n", iface, user, isGuest ); + if (!user || !isGuest) return E_POINTER; + *isGuest = FALSE; + return S_OK; +} + +static HRESULT WINAPI x_user_XUserGetState( IXUserImpl *iface, XUserHandle user, XUserState *state ) +{ + FIXME( "iface %p, user %p, state %p stub!\n", iface, user, state ); + return E_NOTIMPL; +} + +static HRESULT WINAPI __PADDING__( IXUserImpl *iface ) +{ + WARN( "iface %p padding function called! It's unknown what this function does\n", iface ); + return E_NOTIMPL; +} + +static HRESULT WINAPI x_user_XUserGetGamerPictureAsync( IXUserImpl *iface, XUserHandle user, XUserGamerPictureSize size, XAsyncBlock *asyncBlock ) +{ + FIXME( "iface %p, user %p, size %p, asyncBlock %p stub!\n", iface, user, &size, asyncBlock ); + return E_NOTIMPL; +} + +static HRESULT WINAPI x_user_XUserGetGamerPictureResultSize( IXUserImpl *iface, XAsyncBlock *asyncBlock, SIZE_T *size ) +{ + FIXME( "iface %p, asyncBlock %p, size %p stub!\n", iface, asyncBlock, size ); + return E_NOTIMPL; +} + +static HRESULT WINAPI x_user_XUserGetGamerPictureResult( IXUserImpl *iface, XAsyncBlock *asyncBlock, SIZE_T size, PVOID buffer, SIZE_T *used ) +{ + FIXME( "iface %p, asyncBlock %p, size %llu, buffer %p, used %p stub!\n", iface, asyncBlock, size, buffer, used ); + return E_NOTIMPL; +} + +static HRESULT WINAPI x_user_XUserGetAgeGroup( IXUserImpl *iface, XUserHandle user, XUserAgeGroup *group ) +{ + TRACE( "iface %p, user %p, group %p\n", iface, user, group ); + + if (!user || !group) return E_POINTER; + *group = ((struct x_user*)user)->age_group; + return S_OK; +} + +static HRESULT WINAPI x_user_XUserCheckPrivilege( IXUserImpl *iface, XUserHandle user, XUserPrivilegeOptions options, XUserPrivilege privilege, BOOLEAN *hasPrivilege, XUserPrivilegeDenyReason *reason ) +{ + FIXME( "iface %p, user %p, options %d, privilege %d, hasPrivilege %p, reason %p stub!\n", iface, user, options, privilege, hasPrivilege, reason ); + return E_NOTIMPL; +} + +static HRESULT WINAPI x_user_XUserResolvePrivilegeWithUiAsync( IXUserImpl *iface, XUserHandle user, XUserPrivilegeOptions options, XUserPrivilege privilege, XAsyncBlock *asyncBlock ) +{ + FIXME( "iface %p, user %p, options %d, privilege %d, asyncBlock %p stub!\n", iface, user, options, privilege, asyncBlock ); + return E_NOTIMPL; +} + +static HRESULT WINAPI x_user_XUserResolvePrivilegeWithUiResult( IXUserImpl *iface, XAsyncBlock *asyncBlock ) +{ + FIXME( "iface %p, asyncBlock %p stub!\n", iface, asyncBlock ); + return E_NOTIMPL; +} + +struct XUserGetTokenAndSignatureContext +{ + BOOLEAN utf16; + XUserHandle user; + XUserGetTokenAndSignatureOptions options; + LPCSTR method; + LPCWSTR method_utf16; + LPCSTR url; + LPCWSTR url_utf16; + SIZE_T count; + XUserGetTokenAndSignatureHttpHeader *headers; + XUserGetTokenAndSignatureUtf16HttpHeader *headers_utf16; + SIZE_T size; + const void *buffer; +}; + +static HRESULT XUserGetTokenAndSignatureProvider( XAsyncOp operation, const XAsyncProviderData *providerData ) +{ + struct XUserGetTokenAndSignatureContext *context; + IXThreadingImpl *impl; + + TRACE( "operation %d, providerData %p\n", operation, providerData ); + + if (!providerData) return E_POINTER; + if (FAILED( QueryApiImpl( &CLSID_XThreadingImpl, &IID_IXThreadingImpl, (void**)&impl ) )) return E_FAIL; + context = providerData->context; + + switch (operation) + { + case Begin: + return impl->lpVtbl->XAsyncSchedule( impl, providerData->async, 0 ); + + case GetResult: + break; + + case DoWork: + impl->lpVtbl->XAsyncComplete( impl, providerData->async, E_FAIL, sizeof( XUserHandle ) ); + break; + + case Cleanup: + if (context->count) + { + if (context->utf16) free( context->headers_utf16 ); + else free( context->headers ); + } + free( context ); + break; + + case Cancel: + break; + } + + return S_OK; +} + +static HRESULT WINAPI x_user_XUserGetTokenAndSignatureAsync( IXUserImpl *iface, XUserHandle user, XUserGetTokenAndSignatureOptions options, LPCSTR method, LPCSTR url, SIZE_T count, const XUserGetTokenAndSignatureHttpHeader *headers, SIZE_T size, const void *buffer, XAsyncBlock *asyncBlock ) +{ + struct XUserGetTokenAndSignatureContext *context; + IXThreadingImpl *impl; + HRESULT hr; + + TRACE( "iface %p, user %p, options %d, method %s, url %s, count %llu, headers %p, size %llu, buffer %p, asyncBlock %p\n", iface, user, options, method, url, count, headers, size, buffer, asyncBlock ); + + if (!user || !method || !url || !headers || !buffer || !asyncBlock) return E_POINTER; + if (FAILED( hr = QueryApiImpl( &CLSID_XThreadingImpl, &IID_IXThreadingImpl, (void**)&impl ) )) return hr; + if (!(context = calloc( 1, sizeof( *context ) ))) + { + impl->lpVtbl->Release( impl ); + return E_OUTOFMEMORY; + } + + context->options = options; + context->buffer = buffer; + context->method = method; + context->count = count; + context->utf16 = FALSE; + context->size = size; + context->user = user; + context->url = url; + if (count && !(context->headers = calloc( count, sizeof( *headers ) ))) + { + free( context ); + impl->lpVtbl->Release( impl ); + return E_OUTOFMEMORY; + } + + for (SIZE_T i = 0; i < count; i++) + context->headers[i] = headers[i]; + + hr = impl->lpVtbl->XAsyncBegin( impl, asyncBlock, context, x_user_XUserGetTokenAndSignatureAsync, "XUserGetTokenAndSignatureAsync", XUserGetTokenAndSignatureProvider ); + impl->lpVtbl->Release( impl ); + return hr; +} + +static HRESULT WINAPI x_user_XUserGetTokenAndSignatureResultSize( IXUserImpl *iface, XAsyncBlock *asyncBlock, SIZE_T *size ) +{ + FIXME( "iface %p, asyncBlock %p, size %p stub!\n", iface, asyncBlock, size ); + return E_NOTIMPL; +} + +static HRESULT WINAPI x_user_XUserGetTokenAndSignatureResult( IXUserImpl *iface, XAsyncBlock *asyncBlock, SIZE_T size, PVOID buffer, XUserGetTokenAndSignatureData **ptr, SIZE_T *used ) +{ + FIXME( "iface %p, asyncBlock %p, size %llu, buffer %p, ptr %p, used %p stub!\n", iface, asyncBlock, size, buffer, ptr, used ); + return E_NOTIMPL; +} + +static HRESULT WINAPI x_user_XUserGetTokenAndSignatureUtf16Async( IXUserImpl *iface, XUserHandle user, XUserGetTokenAndSignatureOptions options, LPCWSTR method, LPCWSTR url, SIZE_T count, const XUserGetTokenAndSignatureUtf16HttpHeader *headers, SIZE_T size, const void *buffer, XAsyncBlock *asyncBlock ) +{ + struct XUserGetTokenAndSignatureContext *context; + IXThreadingImpl *impl; + HRESULT hr; + + TRACE( "iface %p, user %p, options %d, method %hs, url %hs, count %llu, headers %p, size %llu, buffer %p, asyncBlock %p\n", iface, user, options, method, url, count, headers, size, buffer, asyncBlock ); + + if (!user || !method || !url || !headers || !buffer || !asyncBlock) return E_POINTER; + if (FAILED( hr = QueryApiImpl( &CLSID_XThreadingImpl, &IID_IXThreadingImpl, (void**)&impl ) )) return hr; + if (!(context = calloc( 1, sizeof( *context ) ))) + { + impl->lpVtbl->Release( impl ); + return E_OUTOFMEMORY; + } + + context->method_utf16 = method; + context->options = options; + context->buffer = buffer; + context->url_utf16 = url; + context->count = count; + context->utf16 = TRUE; + context->size = size; + context->user = user; + if (count && !(context->headers_utf16 = calloc( count, sizeof( *headers ) ))) + { + free( context ); + impl->lpVtbl->Release( impl ); + return E_OUTOFMEMORY; + } + + for (SIZE_T i = 0; i < count; i++) + context->headers_utf16[i] = headers[i]; + + hr = impl->lpVtbl->XAsyncBegin( impl, asyncBlock, context, x_user_XUserGetTokenAndSignatureUtf16Async, "XUserGetTokenAndSignatureUtf16Async", XUserGetTokenAndSignatureProvider ); + impl->lpVtbl->Release( impl ); + return hr; +} + +static HRESULT WINAPI x_user_XUserGetTokenAndSignatureUtf16ResultSize( IXUserImpl *iface, XAsyncBlock *asyncBlock, SIZE_T *size ) +{ + FIXME( "iface %p, asyncBlock %p, size %p stub!\n", iface, asyncBlock, size ); + return E_NOTIMPL; +} + +static HRESULT WINAPI x_user_XUserGetTokenAndSignatureUtf16Result( IXUserImpl *iface, XAsyncBlock *asyncBlock, SIZE_T size, PVOID buffer, XUserGetTokenAndSignatureUtf16Data **ptr, SIZE_T *used ) +{ + FIXME( "iface %p, asyncBlock %p, size %llu, buffer %p, ptr %p, used %p stub!\n", iface, asyncBlock, size, buffer, ptr, used ); + return E_NOTIMPL; +} + +static HRESULT WINAPI x_user_XUserResolveIssueWithUiAsync( IXUserImpl *iface, XUserHandle user, LPCSTR url, XAsyncBlock *asyncBlock ) +{ + FIXME( "iface %p, user %p, url %s, asyncBlock %p stub!\n", iface, user, url, asyncBlock ); + return E_NOTIMPL; +} + +static HRESULT WINAPI x_user_XUserResolveIssueWithUiResult( IXUserImpl *iface, XAsyncBlock *asyncBlock ) +{ + FIXME( "iface %p, asyncBlock %p stub!\n", iface, asyncBlock ); + return E_NOTIMPL; +} + +static HRESULT WINAPI x_user_XUserResolveIssueWithUiUtf16Async( IXUserImpl *iface, XUserHandle user, LPCWSTR url, XAsyncBlock *asyncBlock ) +{ + FIXME( "iface %p, user %p, url %hs, asyncBlock %p stub!\n", iface, user, url, asyncBlock ); + return E_NOTIMPL; +} + +static HRESULT WINAPI x_user_XUserResolveIssueWithUiUtf16Result( IXUserImpl *iface, XAsyncBlock *asyncBlock ) +{ + FIXME( "iface %p, asyncBlock %p stub!\n", iface, asyncBlock ); + return E_NOTIMPL; +} + +static HRESULT WINAPI x_user_XUserRegisterForChangeEvent( IXUserImpl *iface, XTaskQueueHandle queue, PVOID context, XUserChangeEventCallback *callback, XTaskQueueRegistrationToken *token ) +{ + FIXME( "iface %p, context %p, callback %p, token %p stub!\n", iface, context, callback, token ); + return E_NOTIMPL; +} + +static BOOLEAN WINAPI x_user_XUserUnregisterForChangeEvent( IXUserImpl *iface, XTaskQueueRegistrationToken token, BOOLEAN wait ) +{ + FIXME( "iface %p, token %p, wait %d stub!\n", iface, &token, wait ); + return FALSE; +} + +static HRESULT WINAPI x_user_XUserGetSignOutDeferral( IXUserImpl *iface, XUserSignOutDeferralHandle *deferral ) +{ + FIXME( "iface %p, deferral %p stub!\n", iface, deferral ); + return E_GAMEUSER_DEFERRAL_NOT_AVAILABLE; +} + +static void WINAPI x_user_XUserCloseSignOutDeferralHandle( IXUserImpl *iface, XUserSignOutDeferralHandle deferral ) +{ + FIXME( "iface %p, deferral %p stub!\n", iface, deferral ); +} + +static HRESULT WINAPI x_user_XUserAddByIdWithUiAsync( IXUserImpl *iface, UINT64 userId, XAsyncBlock *asyncBlock ) +{ + FIXME( "iface %p, userId %llu, asyncBlock %p stub!\n", iface, userId, asyncBlock ); + return E_NOTIMPL; +} + +static HRESULT WINAPI x_user_XUserAddByIdWithUiResult( IXUserImpl *iface, XAsyncBlock *asyncBlock, XUserHandle *user ) +{ + FIXME( "iface %p, asyncBlock %p, user %p stub!\n", iface, asyncBlock, user ); + return E_NOTIMPL; +} + +static HRESULT WINAPI x_user_XUserGetMsaTokenSilentlyAsync( IXUserImpl *iface, XUserHandle user, XUserGetMsaTokenSilentlyOptions options, LPCSTR scope, XAsyncBlock *asyncBlock ) +{ + FIXME( "iface %p, options %u, scope %s, asyncBlock %p stub!\n", iface, options, scope, asyncBlock ); + return E_NOTIMPL; +} + +static HRESULT WINAPI x_user_XUserGetMsaTokenSilentlyResult( IXUserImpl *iface, XAsyncBlock *asyncBlock, SIZE_T size, LPSTR token, SIZE_T *used ) +{ + FIXME( "iface %p, size %llu, token %p, used %p stub!\n", iface, size, token, used ); + return E_NOTIMPL; +} + +static HRESULT WINAPI x_user_XUserGetMsaTokenSilentlyResultSize( IXUserImpl *iface, XAsyncBlock *asyncBlock, SIZE_T *size ) +{ + FIXME( "iface %p, asyncBlock %p stub!\n", iface, asyncBlock ); + return E_NOTIMPL; +} + +static BOOLEAN WINAPI x_user_XUserIsStoreUser( IXUserImpl *iface, XUserHandle user ) +{ + FIXME( "iface %p, user %p stub!\n", iface, user ); + return FALSE; +} + +static HRESULT WINAPI x_user_XUserPlatformRemoteConnectSetEventHandlers( IXUserImpl *iface, XTaskQueueHandle queue, XUserPlatformRemoteConnectEventHandlers *handlers ) +{ + FIXME( "iface %p, queue %p, handlers %p stub!\n", iface, queue, handlers ); + return E_NOTIMPL; +} + +static HRESULT WINAPI x_user_XUserPlatformRemoteConnectCancelPrompt( IXUserImpl *iface, XUserPlatformOperation operation ) +{ + FIXME( "iface %p, operation %p stub!\n", iface, operation ); + return E_NOTIMPL; +} + +static HRESULT WINAPI x_user_XUserPlatformSpopPromptSetEventHandlers( IXUserImpl *iface, XTaskQueueHandle queue, XUserPlatformSpopPromptEventHandler *handler, void *context ) +{ + FIXME( "iface %p, queue %p, handler %p, context %p stub!\n", iface, queue, handler, context ); + return E_NOTIMPL; +} + +static HRESULT WINAPI x_user_XUserPlatformSpopPromptComplete( IXUserImpl *iface, XUserPlatformOperation operation, XUserPlatformOperationResult result ) +{ + FIXME( "iface %p iface, operation %p, result %d stub!\n", iface, operation, result ); + return E_NOTIMPL; +} + +static BOOLEAN WINAPI x_user_XUserIsSignOutPresent( IXUserImpl *iface ) +{ + FIXME( "iface %p stub!\n", iface ); + return FALSE; +} + +static HRESULT WINAPI x_user_XUserSignOutAsync( IXUserImpl *iface, XUserHandle user, XAsyncBlock *asyncBlock ) +{ + FIXME( "iface %p, user %p, asyncBlock %p stub!\n", iface, user, asyncBlock ); + return E_NOTIMPL; +} + +static HRESULT WINAPI x_user_XUserSignOutResult( IXUserImpl *iface, XAsyncBlock *asyncBlock ) +{ + FIXME( "iface %p, asyncBlock %p stub!\n", iface, asyncBlock ); + return E_NOTIMPL; +} + +static const struct IXUserImplVtbl x_user_vtbl = +{ + /* IUnknown methods */ + x_user_QueryInterface, + x_user_AddRef, + x_user_Release, + /* IXUserBase methods */ + x_user_XUserDuplicateHandle, + x_user_XUserCloseHandle, + x_user_XUserCompare, + x_user_XUserGetMaxUsers, + x_user_XUserAddAsync, + x_user_XUserAddResult, + x_user_XUserGetLocalId, + x_user_XUserFindUserByLocalId, + x_user_XUserGetId, + x_user_XUserFindUserById, + x_user_XUserGetIsGuest, + x_user_XUserGetState, + __PADDING__, + x_user_XUserGetGamerPictureAsync, + x_user_XUserGetGamerPictureResultSize, + x_user_XUserGetGamerPictureResult, + x_user_XUserGetAgeGroup, + x_user_XUserCheckPrivilege, + x_user_XUserResolvePrivilegeWithUiAsync, + x_user_XUserResolvePrivilegeWithUiResult, + x_user_XUserGetTokenAndSignatureAsync, + x_user_XUserGetTokenAndSignatureResultSize, + x_user_XUserGetTokenAndSignatureResult, + x_user_XUserGetTokenAndSignatureUtf16Async, + x_user_XUserGetTokenAndSignatureUtf16ResultSize, + x_user_XUserGetTokenAndSignatureUtf16Result, + x_user_XUserResolveIssueWithUiAsync, + x_user_XUserResolveIssueWithUiResult, + x_user_XUserResolveIssueWithUiUtf16Async, + x_user_XUserResolveIssueWithUiUtf16Result, + x_user_XUserRegisterForChangeEvent, + x_user_XUserUnregisterForChangeEvent, + x_user_XUserGetSignOutDeferral, + x_user_XUserCloseSignOutDeferralHandle, + /* IXUserAddWithUi methods */ + x_user_XUserAddByIdWithUiAsync, + x_user_XUserAddByIdWithUiResult, + /* IXUserMsa methods */ + x_user_XUserGetMsaTokenSilentlyAsync, + x_user_XUserGetMsaTokenSilentlyResult, + x_user_XUserGetMsaTokenSilentlyResultSize, + /* IXUserStore methods */ + x_user_XUserIsStoreUser, + /* IXUserPlatform methods */ + x_user_XUserPlatformRemoteConnectSetEventHandlers, + x_user_XUserPlatformRemoteConnectCancelPrompt, + x_user_XUserPlatformSpopPromptSetEventHandlers, + x_user_XUserPlatformSpopPromptComplete, + /* IXUserSignOut methods */ + x_user_XUserIsSignOutPresent, + x_user_XUserSignOutAsync, + x_user_XUserSignOutResult +}; + +static inline struct x_user *impl_from_IXUserGamertag( IXUserGamertag *iface ) +{ + return CONTAINING_RECORD( iface, struct x_user, IXUserGamertag_iface ); +} + +static HRESULT WINAPI x_user_gt_QueryInterface( IXUserGamertag *iface, REFIID iid, void **out ) +{ + struct x_user *impl = impl_from_IXUserGamertag( iface ); + + TRACE( "iface %p, iid %s, out %p\n", iface, debugstr_guid( iid ), out ); + + if (!out) return E_POINTER; + + if (IsEqualGUID( iid, &IID_IUnknown ) || + IsEqualGUID( iid, &IID_IXUserBase ) || + IsEqualGUID( iid, &IID_IXUserAddWithUi ) || + IsEqualGUID( iid, &IID_IXUserMsa ) || + IsEqualGUID( iid, &IID_IXUserStore ) || + IsEqualGUID( iid, &IID_IXUserPlatform ) || + IsEqualGUID( iid, &IID_IXUserSignOut )) + { + *out = &impl->IXUserImpl_iface; + IXUserImpl_AddRef( *out ); + return S_OK; + } + + if (IsEqualGUID( iid, &IID_IXUserGamertag )) + { + *out = &impl->IXUserGamertag_iface; + IXUserGamertag_AddRef( *out ); + return S_OK; + } + + FIXME( "%s not implemented, returning E_NOINTERFACE\n", debugstr_guid( iid ) ); + *out = NULL; + return E_NOINTERFACE; +} + +static ULONG WINAPI x_user_gt_AddRef( IXUserGamertag *iface ) +{ + struct x_user *impl = impl_from_IXUserGamertag( iface ); + ULONG ref = InterlockedIncrement( &impl->ref ); + TRACE( "iface %p increasing refcount to %lu\n", iface, ref ); + return ref; +} + +static ULONG WINAPI x_user_gt_Release( IXUserGamertag *iface ) +{ + struct x_user *impl = impl_from_IXUserGamertag( iface ); + ULONG ref = InterlockedDecrement( &impl->ref ); + TRACE( "iface %p decreasing refcount to %lu\n", iface, ref ); + if (!ref) + { + WindowsDeleteString( impl->refresh_token ); + WindowsDeleteString( impl->oauth_token ); + WindowsDeleteString( impl->user_token ); + WindowsDeleteString( impl->xsts_token ); + free( impl ); + } + return ref; +} + +static HRESULT x_user_gt_XUserGetGamertag( IXUserGamertag *iface, XUserHandle user, XUserGamertagComponent component, SIZE_T size, LPSTR gamertag, SIZE_T *used ) +{ + FIXME( "iface %p, user %p, component %d, size %llu, gamertag %p, used %p stub!\n", iface, user, component, size, gamertag, used ); + return E_NOTIMPL; +} + +static const struct IXUserGamertagVtbl x_user_gt_vtbl = +{ + /* IUnknown methods */ + x_user_gt_QueryInterface, + x_user_gt_AddRef, + x_user_gt_Release, + /* IXUserGamertag methods */ + x_user_gt_XUserGetGamertag +}; + +static struct x_user x_user = { + {&x_user_vtbl}, + {&x_user_gt_vtbl}, + 0, +}; + +IXUserImpl *x_user_impl = &x_user.IXUserImpl_iface; \ No newline at end of file diff --git a/dlls/xgameruntime/GDKComponent/System/User/XUser.h b/dlls/xgameruntime/GDKComponent/System/User/XUser.h new file mode 100644 index 00000000000..badfc37f9c4 --- /dev/null +++ b/dlls/xgameruntime/GDKComponent/System/User/XUser.h @@ -0,0 +1,47 @@ +/* + * Copyright 2026 Olivia Ryan + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA + */ + +/* + * Xbox Game runtime Library + * GDK Component: System API -> XUser + */ + +#ifndef XUSER_H +#define XUSER_H + +#include "../../../private.h" +#include "Token.h" + +struct x_user +{ + IXUserImpl IXUserImpl_iface; + IXUserGamertag IXUserGamertag_iface; + LONG ref; + + UINT64 xuid; + XUserLocalId local_id; + XUserAgeGroup age_group; + + time_t oauth_token_expiry; + HSTRING refresh_token; + HSTRING oauth_token; + HSTRING user_token; + HSTRING xsts_token; +}; + +#endif \ No newline at end of file diff --git a/dlls/xgameruntime/Makefile.in b/dlls/xgameruntime/Makefile.in index b00c401eec2..6c9f558d7e8 100644 --- a/dlls/xgameruntime/Makefile.in +++ b/dlls/xgameruntime/Makefile.in @@ -17,5 +17,7 @@ SOURCES = \ GDKComponent/System/XSystemAnalytics.c \ GDKComponent/System/XGameRuntimeFeature.c \ GDKComponent/System/Networking/HTTPClient.c \ - GDKComponent/System/Networking/XNetworking.c + GDKComponent/System/Networking/XNetworking.c \ + GDKComponent/System/User/Token.c \ + GDKComponent/System/User/XUser.c diff --git a/dlls/xgameruntime/main.c b/dlls/xgameruntime/main.c index f92911ec8c3..067bf4298f9 100644 --- a/dlls/xgameruntime/main.c +++ b/dlls/xgameruntime/main.c @@ -146,7 +146,7 @@ HRESULT WINAPI InitializeApiImpl( ULONG gdkVer, ULONG gsVer ) return InitializeApiImplEx2( gdkVer, gsVer, 0, NULL ); } -typedef HRESULT (WINAPI *QueryApiImpl_ext)( GUID *runtimeClassId, REFIID interfaceId, void **out ); +typedef HRESULT (WINAPI *QueryApiImpl_ext)( const GUID *runtimeClassId, REFIID interfaceId, void **out ); HRESULT WINAPI QueryApiImpl( const GUID *runtimeClassId, REFIID interfaceId, void **out ) { @@ -210,6 +210,10 @@ HRESULT WINAPI QueryApiImpl( const GUID *runtimeClassId, REFIID interfaceId, voi { return IXNetworkingImpl_QueryInterface( x_networking_impl, interfaceId, out ); } + else if ( IsEqualGUID( runtimeClassId, &CLSID_XUserImpl ) ) + { + return IXUserImpl_QueryInterface( x_user_impl, interfaceId, out ); + } FIXME( "%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid( runtimeClassId ) ); return E_NOTIMPL; diff --git a/dlls/xgameruntime/private.h b/dlls/xgameruntime/private.h index 2ff793affb3..b19a8c75e33 100644 --- a/dlls/xgameruntime/private.h +++ b/dlls/xgameruntime/private.h @@ -39,6 +39,8 @@ #define WIDL_using_Windows_Foundation #define WIDL_using_Windows_Foundation_Collections #include "windows.foundation.h" +#define WIDL_using_Windows_Data_Json +#include "windows.data.json.h" #define WIDL_using_Windows_Globalization #include "windows.globalization.h" #define WIDL_using_Windows_System_Profile @@ -53,6 +55,7 @@ extern IXSystemAnalyticsImpl *x_system_analytics_impl; extern IXThreadingImpl *x_threading_impl; extern IXGameRuntimeFeatureImpl *x_game_runtime_feature_impl; extern IXNetworkingImpl *x_networking_impl; +extern IXUserImpl *x_user_impl; typedef struct _INITIALIZE_OPTIONS { diff --git a/dlls/xgameruntime/provider.idl b/dlls/xgameruntime/provider.idl index 52a837fcb89..fe623a61eac 100644 --- a/dlls/xgameruntime/provider.idl +++ b/dlls/xgameruntime/provider.idl @@ -21,6 +21,9 @@ #pragma makedep header import "propidl.idl"; +import "xuser.idl"; + +cpp_quote("#include ") // --- xgameruntime --- // typedef void* XSystemHandle; @@ -31,11 +34,23 @@ typedef enum XGameRuntimeFeature XGameRuntimeFeature; typedef struct XVersion XVersion; typedef struct XSystemAnalyticsInfo XSystemAnalyticsInfo; +typedef struct XAsyncBlock XAsyncBlock; +typedef struct XTaskQueueObject* XTaskQueueHandle; +typedef struct XTaskQueueRegistrationToken XTaskQueueRegistrationToken; + +typedef void XAsyncCompletionRoutine(struct XAsyncBlock* asyncBlock); interface IWineAsyncWorkImpl; interface IXSystemImpl; interface IXSystemAnalyticsImpl; interface IXGameRuntimeFeatureImpl; +interface IXUserBase; +interface IXUserAddWithUi; +interface IXUserMsa; +interface IXUserStore; +interface IXUserPlatform; +interface IXUserSignOut; +interface IXUserImpl; coclass XSystemImpl; coclass XSystemAnalyticsImpl; @@ -162,6 +177,123 @@ interface IXGameRuntimeFeatureImpl : IUnknown BOOLEAN XGameRuntimeIsFeatureAvailable( [in] XGameRuntimeFeature feature ); } +[ + local, + object, + uuid(01acd177-91f9-4763-a38e-ccbb55ce32e0) +] +interface IXUserBase : IUnknown +{ + HRESULT XUserDuplicateHandle( [in] XUserHandle user, [out] XUserHandle *duplicated); + void XUserCloseHandle( [in] XUserHandle user ); + INT32 XUserCompare( [in] XUserHandle user1, [in] XUserHandle user2 ); + HRESULT XUserGetMaxUsers( [out] UINT32 *maxUsers ); + HRESULT XUserAddAsync( [in] XUserAddOptions options, [in,out] XAsyncBlock *asyncBlock ); + HRESULT XUserAddResult( [in,out] XAsyncBlock *asyncBlock, [out] XUserHandle *user ); + HRESULT XUserGetLocalId( [in] XUserHandle user, [out] XUserLocalId *localId ); + HRESULT XUserFindUserByLocalId( [in] XUserLocalId localId, [out] XUserHandle *user ); + HRESULT XUserGetId( [in] XUserHandle user, [out] UINT64 *userId ); + HRESULT XUserFindUserById( [in] UINT64 userId, [out] XUserHandle *user ); + HRESULT XUserGetIsGuest( [in] XUserHandle user, [out] BOOLEAN *isGuest ); + HRESULT XUserGetState( [in] XUserHandle user, [out] XUserState *state ); + HRESULT __PADDING__(); + HRESULT XUserGetGamerPictureAsync( [in] XUserHandle user, [in] XUserGamerPictureSize size, [in,out] XAsyncBlock *asyncBlock ); + HRESULT XUserGetGamerPictureResultSize( [in,out] XAsyncBlock *asyncBlock, [out] SIZE_T *size ); + HRESULT XUserGetGamerPictureResult( [in,out] XAsyncBlock *asyncBlock, [in] SIZE_T size, [out] void *buffer, [out] SIZE_T *used ); + HRESULT XUserGetAgeGroup( [in] XUserHandle user, [out] XUserAgeGroup *group ); + HRESULT XUserCheckPrivilege( [in] XUserHandle user, [in] XUserPrivilegeOptions options, [in] XUserPrivilege privilege, [out] BOOLEAN *hasPrivilege, [out] XUserPrivilegeDenyReason *reason ); + HRESULT XUserResolvePrivilegeWithUiAsync( [in] XUserHandle user, [in] XUserPrivilegeOptions options, [in] XUserPrivilege privilege, [in,out] XAsyncBlock *asyncBlock ); + HRESULT XUserResolvePrivilegeWithUiResult( [in,out] XAsyncBlock *asyncBlock ); + HRESULT XUserGetTokenAndSignatureAsync( [in] XUserHandle user, [in] XUserGetTokenAndSignatureOptions options, [in] LPCSTR method, [in] LPCSTR url, [in] SIZE_T count, [in] const XUserGetTokenAndSignatureHttpHeader *headers, [in] SIZE_T size, [in] const void *buffer, [in,out] XAsyncBlock *asyncBlock ); + HRESULT XUserGetTokenAndSignatureResultSize( [in,out] XAsyncBlock *asyncBlock, [out] SIZE_T *size ); + HRESULT XUserGetTokenAndSignatureResult( [in,out] XAsyncBlock *asyncBlock, [in] SIZE_T size, [out] void *buffer, [out] XUserGetTokenAndSignatureData **ptr, [out] SIZE_T *used ); + HRESULT XUserGetTokenAndSignatureUtf16Async( [in] XUserHandle user, [in] XUserGetTokenAndSignatureOptions options, [in] LPCWSTR method, [in] LPCWSTR url, [in] SIZE_T count, [in] const XUserGetTokenAndSignatureUtf16HttpHeader *headers, [in] SIZE_T size, [in] const void *buffer, [in,out] XAsyncBlock *asyncBlock ); + HRESULT XUserGetTokenAndSignatureUtf16ResultSize( [in,out] XAsyncBlock *asyncBlock, [out] SIZE_T *size ); + HRESULT XUserGetTokenAndSignatureUtf16Result( [in,out] XAsyncBlock *asyncBlock, [in] SIZE_T size, [out] void *buffer, [out] XUserGetTokenAndSignatureUtf16Data **ptr, [out] SIZE_T *used ); + HRESULT XUserResolveIssueWithUiAsync( [in] XUserHandle user, [in] LPCSTR url, [in,out] XAsyncBlock *asyncBlock ); + HRESULT XUserResolveIssueWithUiResult( [in,out] XAsyncBlock *asyncBlock ); + HRESULT XUserResolveIssueWithUiUtf16Async( [in] XUserHandle user, [in] LPCWSTR url, [in,out] XAsyncBlock *asyncBlock ); + HRESULT XUserResolveIssueWithUiUtf16Result( [in,out] XAsyncBlock *asyncBlock ); + HRESULT XUserRegisterForChangeEvent( [in] XTaskQueueHandle queue, [in] void *context, [in] XUserChangeEventCallback *callback, [in] XTaskQueueRegistrationToken *token ); + BOOLEAN XUserUnregisterForChangeEvent( [in] XTaskQueueRegistrationToken token, [in] BOOLEAN wait ); + HRESULT XUserGetSignOutDeferral( [out] XUserSignOutDeferralHandle *deferral ); + void XUserCloseSignOutDeferralHandle( [in] XUserSignOutDeferralHandle deferral ); +} + +[ + local, + object, + uuid(eb9bf948-18dc-4d82-bbcc-40e0a809c4c0) +] +interface IXUserAddWithUi : IXUserBase +{ + HRESULT XUserAddByIdWithUiAsync( [in] UINT64 userId, [in,out] XAsyncBlock *asyncBlock ); + HRESULT XUserAddByIdWithUiResult( [in,out] XAsyncBlock *asyncBlock, [out] XUserHandle *user ); +} + +[ + local, + object, + uuid(1bf2f8c5-d507-4e52-bb05-f726d0e71161) +] +interface IXUserMsa : IXUserAddWithUi +{ + HRESULT XUserGetMsaTokenSilentlyAsync( [in] XUserHandle user, [in] XUserGetMsaTokenSilentlyOptions options, [in] LPCSTR scope, [in,out] XAsyncBlock *asyncBlock ); + HRESULT XUserGetMsaTokenSilentlyResult( [in,out] XAsyncBlock *asyncBlock, [in] SIZE_T size, [out] LPSTR token, [out] SIZE_T *used ); + HRESULT XUserGetMsaTokenSilentlyResultSize( [in,out] XAsyncBlock *asyncBlock, [out] SIZE_T *size ); +} + +[ + local, + object, + uuid(079415e3-6727-437f-8e9d-8f8f9b2439f7) +] +interface IXUserStore : IXUserMsa +{ + BOOLEAN XUserIsStoreUser( [in] XUserHandle user ); +} + +[ + local, + object, + uuid(26f3c674-a2fe-44fa-b6c4-a323bc94ff53) +] +interface IXUserPlatform : IXUserStore +{ + HRESULT XUserPlatformRemoteConnectSetEventHandlers( [in] XTaskQueueHandle queue, [in] XUserPlatformRemoteConnectEventHandlers *handlers ); + HRESULT XUserPlatformRemoteConnectCancelPrompt( [in] XUserPlatformOperation operation ); + HRESULT XUserPlatformSpopPromptSetEventHandlers( [in] XTaskQueueHandle queue, [in] XUserPlatformSpopPromptEventHandler *handler, [in] void *context ); + HRESULT XUserPlatformSpopPromptComplete( [in] XUserPlatformOperation operation, [in] XUserPlatformOperationResult result ); +} + +[ + local, + object, + uuid(5131d685-4394-4ee6-8c18-bfb5d4aef1ff) +] +interface IXUserSignOut : IXUserPlatform +{ + BOOLEAN XUserIsSignOutPresent(); + HRESULT XUserSignOutAsync( [in] XUserHandle user, [in,out] XAsyncBlock *asyncBlock ); + HRESULT XUserSignOutResult( [in,out] XAsyncBlock *asyncBlock ); +} + +[ + object +] +interface IXUserImpl : IXUserSignOut +{} + +[ + local, + object, + uuid(cef4fac0-7676-4a94-a119-4c43f9eb5b74) +] +interface IXUserGamertag : IUnknown +{ + HRESULT XUserGetGamertag( [in] XUserHandle user, [in] XUserGamertagComponent component, [in] SIZE_T size, [out] LPSTR gamertag, [out] SIZE_T *used ); +} + [ uuid(e349bd1a-fc20-4e40-b99c-4178cc6b409f) ] @@ -186,3 +318,11 @@ coclass XGameRuntimeFeatureImpl [default] interface IXGameRuntimeFeatureImpl; } +[ + uuid(01acd177-91f9-4763-a38e-ccbb55ce32e0) +] +coclass XUserImpl +{ + [default] interface IXUserImpl; + interface IXUserGamertag; +} \ No newline at end of file diff --git a/include/Makefile.in b/include/Makefile.in index b8420ebb60d..424951c489e 100644 --- a/include/Makefile.in +++ b/include/Makefile.in @@ -1104,6 +1104,7 @@ SOURCES = \ xmllite.idl \ xpsobjectmodel.idl \ xpsobjectmodel_1.idl \ + xuser.idl \ zmouse.h INSTALL_LIB = \ diff --git a/include/xuser.idl b/include/xuser.idl new file mode 100644 index 00000000000..2f7292b7edb --- /dev/null +++ b/include/xuser.idl @@ -0,0 +1,217 @@ +/* + * Copyright 2026 Olivia Ryan + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA + */ + +import "propidl.idl"; + +typedef PVOID XUserPlatformOperation; +typedef PVOID XUserHandle; +typedef PVOID XUserSignOutDeferralHandle; + +typedef enum XUserAddOptions XUserAddOptions; +typedef enum XUserAgeGroup XUserAgeGroup; +typedef enum XUserChangeEvent XUserChangeEvent; +typedef enum XUserDefaultAudioEndpointKind XUserDefaultAudioEndpointKind; +typedef enum XUserGamerPictureSize XUserGamerPictureSize; +typedef enum XUserGamertagComponent XUserGamertagComponent; +typedef enum XUserGetMsaTokenSilentlyOptions XUserGetMsaTokenSilentlyOptions; +typedef enum XUserGetTokenAndSignatureOptions XUserGetTokenAndSignatureOptions; +typedef enum XUserPrivilege XUserPrivilege; +typedef enum XUserPrivilegeDenyReason XUserPrivilegeDenyReason; +typedef enum XUserPrivilegeOptions XUserPrivilegeOptions; +typedef enum XUserState XUserState; +typedef enum XUserPlatformOperationResult XUserPlatformOperationResult; +typedef enum XUserPlatformSpopOperationResult XUserPlatformSpopOperationResult; + +typedef struct APP_LOCAL_DEVICE_ID APP_LOCAL_DEVICE_ID; +typedef struct XUserDeviceAssociationChange XUserDeviceAssociationChange; +typedef struct XUserGetTokenAndSignatureData XUserGetTokenAndSignatureData; +typedef struct XUserGetTokenAndSignatureHttpHeader XUserGetTokenAndSignatureHttpHeader; +typedef struct XUserGetTokenAndSignatureUtf16Data XUserGetTokenAndSignatureUtf16Data; +typedef struct XUserGetTokenAndSignatureUtf16HttpHeader XUserGetTokenAndSignatureUtf16HttpHeader; +typedef struct XUserLocalId XUserLocalId; +typedef struct XUserPlatformRemoteConnectEventHandlers XUserPlatformRemoteConnectEventHandlers; + +typedef void (__stdcall *XUserChangeEventCallback)( PVOID context, XUserLocalId userLocalId, XUserChangeEvent event ); +typedef void (__stdcall *XUserDefaultAudioEndpointUtf16ChangedCallback)( PVOID context, XUserLocalId userLocalId, XUserDefaultAudioEndpointKind defaultAudioEndpointKind, LPCWSTR endpointIdUtf16 ); +typedef void (__stdcall *XUserDeviceAssociationChangedCallback)( PVOID context, const XUserDeviceAssociationChange *change ); +typedef void (__stdcall *XUserPlatformRemoteConnectShowPromptEventHandler)( PVOID context, UINT32 userIdentifier, XUserPlatformOperation operation, LPCSTR url, LPCSTR code, SIZE_T qrCodeSize, const PVOID qrCode ); +typedef void (__stdcall *XUserPlatformRemoteConnectClosePromptEventHandler)( PVOID context, UINT32 userIdentifier, XUserPlatformOperation operation ); +typedef void (__stdcall *XUserPlatformSpopPromptEventHandler)( PVOID context, UINT32 userIdentifier, XUserPlatformOperation operation, LPCSTR modernGamertag, LPCSTR modernGamertagSuffix ); + + +enum XUserAddOptions +{ + XUserAddOptions_None = 0, + XUserAddOptions_AddDefaultUserSilently = 1, + XUserAddOptions_AllowGuests = 2, + XUserAddOptions_AddDefaultUserAllowingUI = 4 +}; + +enum XUserAgeGroup +{ + XUserAgeGroup_Unknown = 0, + XUserAgeGroup_Child = 1, + XUserAgeGroup_Teen = 2, + XUserAgeGroup_Adult = 3 +}; + +enum XUserChangeEvent +{ + XUserChangeEvent_SignedInAgain = 0, + XUserChangeEvent_SigningOut = 1, + XUserChangeEvent_SignedOut = 2, + XUserChangeEvent_Gamertag = 3, + XUserChangeEvent_GamerPicture = 4, + XUserChangeEvent_Privileges = 5 +}; + +enum XUserDefaultAudioEndpointKind +{ + XUserDefaultAudioEndpointKind_CommunicationRender = 0, + XUserDefaultAudioEndpointKind_CommunicationCapture = 1 +}; + +enum XUserGamerPictureSize +{ + XUserGamerPictureSize_Small = 0, + XUserGamerPictureSize_Medium = 1, + XUserGamerPictureSize_Large = 2, + XUserGamerPictureSize_ExtraLarge = 3 +}; + +enum XUserGamertagComponent +{ + XUserGamertagComponent_Classic = 0, + XUserGamertagComponent_Modern = 1, + XUserGamertagComponent_ModerSuffix = 2, + XUserGamertagComponent_UniqueModern = 3 +}; + +enum XUserGetMsaTokenSilentlyOptions +{ + XUserGetMsaTokenSilentlyOptions_None = 0 +}; + +enum XUserGetTokenAndSignatureOptions +{ + XUserGetTokenAndSignatureOptions_None = 0, + XUserGetTokenAndSignatureOptions_ForceRefresh = 1, + XUserGetTokenAndSignatureOptions_AllUsers = 2 +}; + +enum XUserPrivilege +{ + XUserPrivilege_CrossPlay = 185, + XUserPrivilege_Clubs = 188, + XUserPrivilege_Sessions = 189, + XUserPrivilege_Broadcast = 190, + XUserPrivilege_ManageProfilePrivacy = 196, + XUserPrivilege_GameDvr = 198, + XUserPrivilege_MultiplayerParties = 203, + XUserPrivilege_CloudManageSession = 207, + XUserPrivilege_CloudJoinSession = 208, + XUserPrivilege_CloudSavedGames = 209, + XUserPrivilege_SocialNetworkSharing = 220, + XUserPrivilege_UserGeneratedContent = 247, + XUserPrivilege_Communications = 252, + XUserPrivilege_Multiplayer = 254, + XUserPrivilege_AddFriends = 255 +}; + +enum XUserPrivilegeDenyReason +{ + XUserPrivilegeDenyReason_None = 0, + XUserPrivilegeDenyReason_PurchaseRequired = 1, + XUserPrivilegeDenyReason_Restricted = 2, + XUserPrivilegeDenyReason_Banned = 3, + XUserPrivilegeDenyReason_Unknown = -1 +}; + +enum XUserPrivilegeOptions +{ + XUserPrivilegeOptions_None = 0, + XUserPrivilegeOptions_AllUsers = 1 +}; + +enum XUserState +{ + XUserState_SignedIn = 0, + XUserState_SigningOut = 1, + XUserState_SignedOut = 2 +}; + +enum XUserPlatformOperationResult +{ + XUserPlatformOperationResult_Success = 0, + XUserPlatformOperationResult_Failure = 1, + XUserPlatformOperationResult_Canceled = 2 +}; + +enum XUserPlatformSpopOperationResult +{ + XUserPlatformSpopOperationResult_SignInHere = 0, + XUserPlatformSpopOperationResult_SwitchAccount = 1, + XUserPlatformSpopOperationResult_Failure = 2, + XUserPlatformSpopOperationResult_Canceled = 3 +}; + +struct APP_LOCAL_DEVICE_ID +{ + BYTE value[32]; +}; + +struct XUserLocalId { + UINT64 value; +}; + +struct XUserDeviceAssociationChange +{ + APP_LOCAL_DEVICE_ID deviceId; + XUserLocalId oldUser; + XUserLocalId newUser; +}; + +struct XUserGetTokenAndSignatureData { + SIZE_T tokenSize; + SIZE_T signatureSize; + LPCSTR token; + LPCSTR signature; +}; + +struct XUserGetTokenAndSignatureHttpHeader { + LPCSTR name; + LPCSTR value; +}; + +struct XUserGetTokenAndSignatureUtf16Data { + SIZE_T tokenCount; + SIZE_T signatureCount; + LPCWSTR token; + LPCWSTR signature; +}; + +struct XUserGetTokenAndSignatureUtf16HttpHeader { + LPCWSTR name; + LPCWSTR value; +}; + +struct XUserPlatformRemoteConnectEventHandlers { + XUserPlatformRemoteConnectShowPromptEventHandler* show; + XUserPlatformRemoteConnectClosePromptEventHandler* close; + PVOID context; +}; \ No newline at end of file