From 5e82a8ce690587139794cfa80fbdaa460eb49d22 Mon Sep 17 00:00:00 2001 From: Olivia Ryan Date: Tue, 20 Jan 2026 13:24:43 +0000 Subject: [PATCH 01/13] xgameruntime: XUser stubs --- dlls/xgameruntime/GDKComponent/System/XUser.c | 317 ++++++++++++++++++ dlls/xgameruntime/GDKComponent/System/XUser.h | 35 ++ dlls/xgameruntime/Makefile.in | 3 +- dlls/xgameruntime/main.c | 4 + dlls/xgameruntime/private.h | 1 + dlls/xgameruntime/provider.idl | 178 ++++++++++ 6 files changed, 537 insertions(+), 1 deletion(-) create mode 100644 dlls/xgameruntime/GDKComponent/System/XUser.c create mode 100644 dlls/xgameruntime/GDKComponent/System/XUser.h diff --git a/dlls/xgameruntime/GDKComponent/System/XUser.c b/dlls/xgameruntime/GDKComponent/System/XUser.c new file mode 100644 index 00000000000..80fd3fa0819 --- /dev/null +++ b/dlls/xgameruntime/GDKComponent/System/XUser.c @@ -0,0 +1,317 @@ +/* + * 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" + +WINE_DEFAULT_DEBUG_CHANNEL(gdkc); + +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 (IsEqualGUID(iid, &IID_IUnknown) + || IsEqualGUID(iid, &CLSID_XUserImpl) + || IsEqualGUID(iid, &IID_IXUserImpl)) + { + *out = &impl->IXUserImpl_iface; + impl->IXUserImpl_iface.lpVtbl->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); + return ref; +} + +static HRESULT WINAPI x_user_XUserDuplicateHandle(IXUserImpl* iface, XUserHandle user, XUserHandle* duplicated) +{ + FIXME("iface %p, user %p, duplicated %p stub!\n", iface, user, duplicated); + return E_NOTIMPL; +} + +static void WINAPI x_user_XUserCloseHandle(IXUserImpl* iface, XUserHandle user) +{ + FIXME("iface %p, user %p stub!\n", iface, user); +} + +static INT32 WINAPI x_user_XUserCompare(IXUserImpl* iface, XUserHandle user1, XUserHandle user2) +{ + FIXME("iface %p, user1 %p, user2 %p stub!\n", iface, user1, user2); + return E_NOTIMPL; +} + +static HRESULT WINAPI x_user_XUserGetMaxUsers(IXUserImpl* iface, UINT32* maxUsers) +{ + FIXME("iface %p, maxUsers %p stub!\n", iface, maxUsers); + return E_NOTIMPL; +} + +static HRESULT WINAPI x_user_XUserAddAsync(IXUserImpl* iface, XUserAddOptions options, XAsyncBlock* asyncBlock) +{ + FIXME("iface %p, options %d, asyncBlock %p stub!\n", iface, options, asyncBlock); + return E_NOTIMPL; +} + +static HRESULT WINAPI x_user_XUserAddResult(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_XUserGetLocalId(IXUserImpl* iface, XUserHandle user, XUserLocalId* localId) +{ + FIXME("iface %p, user %p, localId %p stub!\n", iface, user, localId); + return E_NOTIMPL; +} + +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) +{ + FIXME("iface %p, user %p, userId %p stub!\n", iface, user, userId); + return E_NOTIMPL; +} + +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); + return E_NOTIMPL; +} + +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, void* 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) +{ + FIXME("user %p, group %p stub!\n", user, group); + return E_NOTIMPL; +} + +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; +} + +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) +{ + FIXME("iface %p, user %p, options %d, method %s, url %s, count %llu, headers %p, size %llu, buffer %p, asyncBlock %p stub!\n", iface, user, options, method, url, count, headers, size, buffer, asyncBlock); + return E_NOTIMPL; +} +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, void* 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) +{ + FIXME("iface %p, user %p, options %d, method %hs, url %hs, count %llu, headers %p, size %llu, buffer %p, asyncBlock %p stub!\n", iface, user, options, method, url, count, headers, size, buffer, asyncBlock); + return E_NOTIMPL; +} + +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, void* 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, void* 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 const struct IXUserImplVtbl x_user_vtbl = +{ + x_user_QueryInterface, + x_user_AddRef, + x_user_Release, + /* IXUserImpl 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 +}; + +static struct x_user x_user = { + {&x_user_vtbl}, + 0, +}; + +IXUserImpl *x_user_impl = &x_user.IXUserImpl_iface; \ No newline at end of file diff --git a/dlls/xgameruntime/GDKComponent/System/XUser.h b/dlls/xgameruntime/GDKComponent/System/XUser.h new file mode 100644 index 00000000000..e5fc9798cf6 --- /dev/null +++ b/dlls/xgameruntime/GDKComponent/System/XUser.h @@ -0,0 +1,35 @@ +/* + * 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" + +struct x_user +{ + IXUserImpl IXUserImpl_iface; + LONG ref; +}; + +#endif \ No newline at end of file diff --git a/dlls/xgameruntime/Makefile.in b/dlls/xgameruntime/Makefile.in index b00c401eec2..e41ef160db4 100644 --- a/dlls/xgameruntime/Makefile.in +++ b/dlls/xgameruntime/Makefile.in @@ -17,5 +17,6 @@ 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/XUser.c diff --git a/dlls/xgameruntime/main.c b/dlls/xgameruntime/main.c index f92911ec8c3..4378cfd4d7c 100644 --- a/dlls/xgameruntime/main.c +++ b/dlls/xgameruntime/main.c @@ -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..2120afcb68a 100644 --- a/dlls/xgameruntime/private.h +++ b/dlls/xgameruntime/private.h @@ -53,6 +53,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..c84f30ebe9c 100644 --- a/dlls/xgameruntime/provider.idl +++ b/dlls/xgameruntime/provider.idl @@ -22,15 +22,38 @@ import "propidl.idl"; +cpp_quote("#include ") + // --- xgameruntime --- // typedef void* XSystemHandle; +typedef void* XUserChangeEventCallback; +typedef void* XUserHandle; +typedef void* XUserSignOutDeferralHandle; typedef enum XSystemHandleType XSystemHandleType; typedef enum XSystemHandleCallbackReason XSystemHandleCallbackReason; typedef enum XGameRuntimeFeature XGameRuntimeFeature; +typedef enum XUserAddOptions XUserAddOptions; +typedef enum XUserAgeGroup XUserAgeGroup; +typedef enum XUserGamerPictureSize XUserGamerPictureSize; +typedef enum XUserGetTokenAndSignatureOptions XUserGetTokenAndSignatureOptions; +typedef enum XUserPrivilege XUserPrivilege; +typedef enum XUserPrivilegeDenyReason XUserPrivilegeDenyReason; +typedef enum XUserPrivilegeOptions XUserPrivilegeOptions; +typedef enum XUserState XUserState; typedef struct XVersion XVersion; typedef struct XSystemAnalyticsInfo XSystemAnalyticsInfo; +typedef struct XAsyncBlock XAsyncBlock; +typedef struct XTaskQueueObject* XTaskQueueHandle; +typedef struct XTaskQueueRegistrationToken XTaskQueueRegistrationToken; +typedef struct XUserGetTokenAndSignatureData XUserGetTokenAndSignatureData; +typedef struct XUserGetTokenAndSignatureUtf16Data XUserGetTokenAndSignatureUtf16Data; +typedef struct XUserGetTokenAndSignatureHttpHeader XUserGetTokenAndSignatureHttpHeader; +typedef struct XUserGetTokenAndSignatureUtf16HttpHeader XUserGetTokenAndSignatureUtf16HttpHeader; +typedef struct XUserLocalId XUserLocalId; + +typedef void XAsyncCompletionRoutine(struct XAsyncBlock* asyncBlock); interface IWineAsyncWorkImpl; interface IXSystemImpl; @@ -93,6 +116,78 @@ enum XSystemHandleCallbackReason Destroyed = 0x01 }; +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 XUserGamerPictureSize +{ + XUserGamerPictureSize_Small = 0, + XUserGamerPictureSize_Medium = 1, + XUserGamerPictureSize_Large = 2, + XUserGamerPictureSize_ExtraLarge = 3 +}; + +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 +}; + struct XVersion { union { @@ -115,6 +210,39 @@ struct XSystemAnalyticsInfo CHAR form[64]; }; +struct XUserGetTokenAndSignatureData +{ + SIZE_T tokenSize; + SIZE_T signatureSize; + LPCSTR token; + LPCSTR signature; +}; + +struct XUserGetTokenAndSignatureUtf16Data +{ + SIZE_T tokenSize; + SIZE_T signatureSize; + LPCWSTR token; + LPCWSTR signature; +}; + +struct XUserGetTokenAndSignatureHttpHeader +{ + LPCSTR name; + LPCSTR value; +}; + +struct XUserGetTokenAndSignatureUtf16HttpHeader +{ + LPCWSTR name; + LPCWSTR value; +}; + +struct XUserLocalId +{ + UINT64 value; +}; + [ object, uuid(7664288b-54e9-45f9-af0b-b4ad047fa194) @@ -162,6 +290,49 @@ interface IXGameRuntimeFeatureImpl : IUnknown BOOLEAN XGameRuntimeIsFeatureAvailable( [in] XGameRuntimeFeature feature ); } +[ + local, + object, + uuid(079415e3-6727-437f-8e9d-8f8f9b2439f7) +] +interface IXUserImpl : 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 ); +} + [ uuid(e349bd1a-fc20-4e40-b99c-4178cc6b409f) ] @@ -186,3 +357,10 @@ coclass XGameRuntimeFeatureImpl [default] interface IXGameRuntimeFeatureImpl; } +[ + uuid(01acd177-91f9-4763-a38e-ccbb55ce32e0) +] +coclass XUserImpl +{ + [default] interface IXUserImpl; +} \ No newline at end of file From 9804a460b39a3f3d31c1475195f3d2dafa984c94 Mon Sep 17 00:00:00 2001 From: Olivia Ryan Date: Mon, 2 Feb 2026 22:22:57 +0000 Subject: [PATCH 02/13] xgameruntime: XUserAdd async provider --- dlls/xgameruntime/GDKComponent/System/XUser.c | 128 ++++++++++++------ dlls/xgameruntime/main.c | 2 +- 2 files changed, 91 insertions(+), 39 deletions(-) diff --git a/dlls/xgameruntime/GDKComponent/System/XUser.c b/dlls/xgameruntime/GDKComponent/System/XUser.c index 80fd3fa0819..7085eae9a9a 100644 --- a/dlls/xgameruntime/GDKComponent/System/XUser.c +++ b/dlls/xgameruntime/GDKComponent/System/XUser.c @@ -89,16 +89,68 @@ static HRESULT WINAPI x_user_XUserGetMaxUsers(IXUserImpl* iface, UINT32* maxUser return E_NOTIMPL; } +struct XUserAddContext { + XUserAddOptions options; + XUserHandle user; +}; + +HRESULT XUserAddProvider(XAsyncOp operation, const XAsyncProviderData* providerData) +{ + struct XUserAddContext* context; + IXThreadingImpl* impl; + + TRACE("operation %d, providerData %p\n", operation, providerData); + + 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: + // TODO + impl->lpVtbl->XAsyncComplete(impl, providerData->async, S_OK, 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) { - FIXME("iface %p, options %d, asyncBlock %p stub!\n", iface, options, asyncBlock); - return E_NOTIMPL; + struct XUserAddContext* context; + IXThreadingImpl* impl; + + TRACE("iface %p, options %d, asyncBlock %p\n", iface, options, asyncBlock); + + if (FAILED(QueryApiImpl(&CLSID_XThreadingImpl, &IID_IXThreadingImpl, (void**)&impl))) return E_NOTIMPL; + if (!(context = calloc(1, sizeof(struct XUserAddContext)))) return E_OUTOFMEMORY; + context->options = options; + + return impl->lpVtbl->XAsyncBegin(impl, asyncBlock, context, x_user_XUserAddAsync, "XUserAddAsync", XUserAddProvider); } static HRESULT WINAPI x_user_XUserAddResult(IXUserImpl* iface, XAsyncBlock* asyncBlock, XUserHandle* user) { - FIXME("iface %p, asyncBlock %p, user %p stub!\n", iface, asyncBlock, *user); - return E_NOTIMPL; + IXThreadingImpl* impl; + + TRACE("iface %p, asyncBlock %p, user %p\n", iface, asyncBlock, *user); + + 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) @@ -273,40 +325,40 @@ static const struct IXUserImplVtbl x_user_vtbl = x_user_AddRef, x_user_Release, /* IXUserImpl 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 + 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 }; static struct x_user x_user = { diff --git a/dlls/xgameruntime/main.c b/dlls/xgameruntime/main.c index 4378cfd4d7c..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 ) { From 9fdfe8c3e3b5af170b52b0ec6eeb58bd3461c679 Mon Sep 17 00:00:00 2001 From: Olivia Ryan Date: Tue, 3 Feb 2026 19:36:34 +0000 Subject: [PATCH 03/13] xgameruntime: add getting device code --- dlls/xgameruntime/GDKComponent/System/XUser.c | 135 ++++++++++++++++++ 1 file changed, 135 insertions(+) diff --git a/dlls/xgameruntime/GDKComponent/System/XUser.c b/dlls/xgameruntime/GDKComponent/System/XUser.c index 7085eae9a9a..daa66c3dc74 100644 --- a/dlls/xgameruntime/GDKComponent/System/XUser.c +++ b/dlls/xgameruntime/GDKComponent/System/XUser.c @@ -22,9 +22,144 @@ */ #include "XUser.h" +#include "winhttp.h" WINE_DEFAULT_DEBUG_CHANNEL(gdkc); +static BOOLEAN HttpRequest(LPCWSTR method, LPCWSTR domain, LPCWSTR object, LPSTR data, LPCWSTR headers, LPCWSTR* accept, LPSTR* buffer, SIZE_T* bufferSize) +{ + HINTERNET session = NULL; + HINTERNET connection = NULL; + HINTERNET request = NULL; + BOOLEAN response = FALSE; + LPSTR chunkBuffer; + DWORD size; + BOOLEAN result = TRUE; + SIZE_T allocated; + + session = WinHttpOpen( + L"WineGDK/1.0", + WINHTTP_ACCESS_TYPE_AUTOMATIC_PROXY, + WINHTTP_NO_PROXY_NAME, + WINHTTP_NO_PROXY_BYPASS, + 0 + ); + + if (session) + connection = WinHttpConnect( + session, + domain, + INTERNET_DEFAULT_HTTPS_PORT, + 0 + ); + + if (connection) + request = WinHttpOpenRequest( + connection, + method, + object, + NULL, + WINHTTP_NO_REFERER, + accept, + WINHTTP_FLAG_SECURE + ); + + if (request) + response = WinHttpSendRequest( + request, + headers, + -1, + data, + strlen(data), + strlen(data), + 0 + ); + + if (response) + response = WinHttpReceiveResponse(request, NULL); + + /* buffer response data */ + if (response) + { + allocated = 0x1000; + *buffer = calloc(1, allocated); + *bufferSize = 0; + do + { + size = 0; + chunkBuffer = *buffer + *bufferSize; + if (!WinHttpQueryDataAvailable(request, &size)) + { + free(*buffer); + result = FALSE; + break; + } + + if (*bufferSize + size >= allocated) + { + allocated = (*bufferSize + size + 0xFFF) & ~0xFFF; + *buffer = realloc(*buffer, allocated); + if (!*buffer) + { + result = FALSE; + break; + } + } + + *bufferSize += size; + if (!WinHttpReadData(request, chunkBuffer, size, NULL)) + { + free(*buffer); + result = FALSE; + break; + } + } + while (size > 0); + } + else result = FALSE; + + if (request) WinHttpCloseHandle(request); + if (connection) WinHttpCloseHandle(connection); + if (session) WinHttpCloseHandle(session); + + return result; +} + +static BOOLEAN RequestOAuthToken(LPCSTR clientId) +{ + LPCSTR template = "scope=service%3a%3auser.auth.xboxlive.com%3a%3aMBI_SSL&response_type=device_code&client_id="; + LPCWSTR accept[] = {L"application/json", NULL}; + BOOLEAN result; + LPSTR data; + LPSTR buffer; + SIZE_T size; + + /* request a device code */ + + data = calloc(strlen(template) + strlen(clientId) + 1, sizeof(CHAR)); + strcpy(data, template); + strcat(data, clientId); + result = HttpRequest( + L"POST", + L"login.live.com", + L"/oauth20_connect.srf", + data, + L"content-type: application/x-www-form-urlencoded", + accept, + &buffer, + &size + ); + free(data); + + if (!result) + return result; + + TRACE("%s\n", buffer); + + free(buffer); + return result; +} + static inline struct x_user *impl_from_IXUserImpl(IXUserImpl *iface) { return CONTAINING_RECORD(iface, struct x_user, IXUserImpl_iface); From c7e9beb8706e366e56430af3ad0f5d101f74dff7 Mon Sep 17 00:00:00 2001 From: Olivia Ryan Date: Fri, 6 Mar 2026 13:55:18 +0000 Subject: [PATCH 04/13] windows.web: Support JSON array and object parsing --- dlls/windows.web/Makefile.in | 1 + dlls/windows.web/classes.idl | 1 + dlls/windows.web/json_array.c | 319 ++++++++++++++++++++++++++++ dlls/windows.web/json_object.c | 127 +++++++++-- dlls/windows.web/json_value.c | 374 ++++++++++++++++++++++++++++----- dlls/windows.web/main.c | 2 + dlls/windows.web/private.h | 5 + dlls/windows.web/tests/web.c | 50 ++++- 8 files changed, 802 insertions(+), 77 deletions(-) create mode 100644 dlls/windows.web/json_array.c 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(); From ba50827edd8535f0d8442c0aacd15ab3a943bae4 Mon Sep 17 00:00:00 2001 From: Olivia Ryan Date: Sun, 8 Feb 2026 11:48:14 +0000 Subject: [PATCH 05/13] xgameruntime: Get user's tokens --- .../GDKComponent/System/User/Token.c | 371 ++++++++++++++++++ .../GDKComponent/System/User/Token.h | 37 ++ .../GDKComponent/System/{ => User}/XUser.c | 259 ++++++------ .../GDKComponent/System/{ => User}/XUser.h | 11 +- dlls/xgameruntime/Makefile.in | 3 +- dlls/xgameruntime/private.h | 2 + 6 files changed, 557 insertions(+), 126 deletions(-) create mode 100644 dlls/xgameruntime/GDKComponent/System/User/Token.c create mode 100644 dlls/xgameruntime/GDKComponent/System/User/Token.h rename dlls/xgameruntime/GDKComponent/System/{ => User}/XUser.c (75%) rename dlls/xgameruntime/GDKComponent/System/{ => User}/XUser.h (82%) diff --git a/dlls/xgameruntime/GDKComponent/System/User/Token.c b/dlls/xgameruntime/GDKComponent/System/User/Token.c new file mode 100644 index 00000000000..1fc99e5353a --- /dev/null +++ b/dlls/xgameruntime/GDKComponent/System/User/Token.c @@ -0,0 +1,371 @@ +/* + * 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" + +WINE_DEFAULT_DEBUG_CHANNEL(gdkc); + +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 GetJsonStringValue(IJsonObject *object, LPCWSTR key, HSTRING *content) +{ + 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_GetNamedString(object, key_hstr, content))) + return hr; + + return S_OK; +} + +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 class_str = RuntimeClass_Windows_Data_Json_JsonValue; + LPCWSTR accept[] = {L"application/json", NULL}; + IJsonValueStatics *statics; + HSTRING_HEADER content_hdr; + HSTRING_HEADER expires_hdr; + HSTRING_HEADER class_hdr; + IJsonObject *object; + IJsonValue *value; + HSTRING content; + HSTRING expires; + LPWSTR w_buffer; + UINT32 w_size; + time_t expiry; + HSTRING class; + LPSTR buffer; + DOUBLE delta; + SIZE_T size; + HRESULT hr; + LPSTR data; + + if (!(data = calloc(1, strlen(template) + strlen(client_id) + + strlen("&refresh_token=") + strlen(refresh_token) + 1))) 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)) { + TRACE("web request failed\n"); + return hr; + } + + if (!(w_size = MultiByteToWideChar(CP_UTF8, 0, buffer, size, NULL, 0))) + { + free(buffer); + return HRESULT_FROM_WIN32(GetLastError()); + } + + if (!(w_buffer = calloc(w_size, sizeof(WCHAR)))) + { + free(buffer); + return E_OUTOFMEMORY; + } + + w_size = MultiByteToWideChar(CP_UTF8, 0, buffer, size, w_buffer, w_size); + free(buffer); + if (!w_size) + { + free(w_buffer); + return HRESULT_FROM_WIN32(GetLastError()); + } + + if (FAILED(hr = WindowsCreateStringReference(w_buffer, w_size, &content_hdr, &content))) + { + free(w_buffer); + return hr; + } + + if (FAILED(hr = WindowsCreateStringReference(class_str, wcslen(class_str), &class_hdr, &class))) + { + free(w_buffer); + return hr; + } + + if (FAILED(hr = RoGetActivationFactory(class, &IID_IJsonValueStatics, (void**)&statics))) + { + free(w_buffer); + return hr; + } + + hr = IJsonValueStatics_Parse(statics, content, &value); + free(w_buffer); + IJsonValueStatics_Release(statics); + if (FAILED(hr)) + { + IJsonValue_Release(value); + return hr; + } + + hr = IJsonValue_GetObject(value, &object); + IJsonValue_Release(value); + if (FAILED(hr)) + { + IJsonObject_Release(object); + return hr; + } + + if (FAILED(hr = GetJsonStringValue(object, L"access_token", new_oauth_token))) + { + TRACE("failed to get access_token\n"); + IJsonObject_Release(object); + return hr; + } + + if (FAILED(hr = GetJsonStringValue(object, L"refresh_token", new_refresh_token))) + { + TRACE("failed to get refresh_token\n"); + IJsonObject_Release(object); + return hr; + } + + if (FAILED(hr = WindowsCreateStringReference( + L"expires_in", wcslen(L"expires_in"), &expires_hdr, &expires))) + { + IJsonObject_Release(object); + return hr; + } + + hr = IJsonObject_GetNamedNumber(object, expires, &delta); + IJsonObject_Release(object); + if (FAILED(hr)) + { + TRACE("failed to get expires_in\n"); + return hr; + } + + if ((expiry = time(NULL)) == -1) return E_FAIL; + *new_expiry = expiry + delta; + + return S_OK; +} + +HRESULT RequestXToken(LPCWSTR domain, LPCWSTR path, LPSTR data, HSTRING *token) +{ + LPCWSTR class_str = RuntimeClass_Windows_Data_Json_JsonValue; + LPCWSTR accept[] = {L"application/json", NULL}; + HSTRING_HEADER token_key_hdr; + IJsonValueStatics *statics; + HSTRING_HEADER content_hdr; + HSTRING_HEADER class_hdr; + IJsonObject *object; + IJsonValue *value; + HSTRING token_key; + LPWSTR w_buffer; + HSTRING content; + HSTRING class; + LPSTR buffer; + SIZE_T size; + HRESULT hr; + INT w_size; + + hr = HttpRequest( + L"POST", + domain, + path, + data, + L"content-type: application/json", + accept, + &buffer, + &size + ); + + if (FAILED(hr)) return FALSE; + + if (!(w_size = MultiByteToWideChar(CP_UTF8, 0, buffer, size, NULL, 0))) + { + free(buffer); + return HRESULT_FROM_WIN32(GetLastError()); + } + + if (!(w_buffer = calloc(w_size, sizeof(WCHAR)))) + { + free(buffer); + return E_OUTOFMEMORY; + } + + w_size = MultiByteToWideChar(CP_UTF8, 0, buffer, size, w_buffer, w_size); + free(buffer); + if (!w_size) + { + free(w_buffer); + return HRESULT_FROM_WIN32(GetLastError()); + } + + if (FAILED(hr = WindowsCreateStringReference(w_buffer, w_size, &content_hdr, &content))) + { + free(w_buffer); + return hr; + } + + if (FAILED(hr = WindowsCreateStringReference( + L"Token", wcslen(L"Token"), &token_key_hdr, &token_key))) + { + free(w_buffer); + return hr; + } + + if (FAILED(hr = WindowsCreateStringReference(class_str, wcslen(class_str), &class_hdr, &class))) + { + free(w_buffer); + return hr; + } + + if (FAILED(hr = RoGetActivationFactory(class, &IID_IJsonValueStatics, (void**)&statics))) + { + free(w_buffer); + return hr; + } + + hr = IJsonValueStatics_Parse(statics, content, &value); + IJsonValueStatics_Release(statics); + free(w_buffer); + if (FAILED(hr)) + { + IJsonValue_Release(value); + return hr; + } + + hr = IJsonValue_GetObject(value, &object); + IJsonValue_Release(value); + if (FAILED(hr)) + { + IJsonObject_Release(object); + return hr; + } + + if (FAILED(hr = IJsonObject_GetNamedString(object, token_key, token))) + IJsonObject_Release(object); + + 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..6a44e1bf9c0 --- /dev/null +++ b/dlls/xgameruntime/GDKComponent/System/User/Token.h @@ -0,0 +1,37 @@ +/* + * 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 "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 RequestXToken(LPCWSTR domain, LPCWSTR path, LPSTR data, HSTRING *token); + +#endif \ No newline at end of file diff --git a/dlls/xgameruntime/GDKComponent/System/XUser.c b/dlls/xgameruntime/GDKComponent/System/User/XUser.c similarity index 75% rename from dlls/xgameruntime/GDKComponent/System/XUser.c rename to dlls/xgameruntime/GDKComponent/System/User/XUser.c index daa66c3dc74..f2587d48bd9 100644 --- a/dlls/xgameruntime/GDKComponent/System/XUser.c +++ b/dlls/xgameruntime/GDKComponent/System/User/XUser.c @@ -26,138 +26,133 @@ WINE_DEFAULT_DEBUG_CHANNEL(gdkc); -static BOOLEAN HttpRequest(LPCWSTR method, LPCWSTR domain, LPCWSTR object, LPSTR data, LPCWSTR headers, LPCWSTR* accept, LPSTR* buffer, SIZE_T* bufferSize) +static const struct IXUserImplVtbl x_user_vtbl; + +static HRESULT HSTRINGToMultiByte(HSTRING hstr, LPSTR *str, UINT32 *str_len) { - HINTERNET session = NULL; - HINTERNET connection = NULL; - HINTERNET request = NULL; - BOOLEAN response = FALSE; - LPSTR chunkBuffer; - DWORD size; - BOOLEAN result = TRUE; - SIZE_T allocated; - - session = WinHttpOpen( - L"WineGDK/1.0", - WINHTTP_ACCESS_TYPE_AUTOMATIC_PROXY, - WINHTTP_NO_PROXY_NAME, - WINHTTP_NO_PROXY_BYPASS, - 0 - ); - - if (session) - connection = WinHttpConnect( - session, - domain, - INTERNET_DEFAULT_HTTPS_PORT, - 0 - ); - - if (connection) - request = WinHttpOpenRequest( - connection, - method, - object, - NULL, - WINHTTP_NO_REFERER, - accept, - WINHTTP_FLAG_SECURE - ); - - if (request) - response = WinHttpSendRequest( - request, - headers, - -1, - data, - strlen(data), - strlen(data), - 0 - ); - - if (response) - response = WinHttpReceiveResponse(request, NULL); - - /* buffer response data */ - if (response) + 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))) { - allocated = 0x1000; - *buffer = calloc(1, allocated); - *bufferSize = 0; - do - { - size = 0; - chunkBuffer = *buffer + *bufferSize; - if (!WinHttpQueryDataAvailable(request, &size)) - { - free(*buffer); - result = FALSE; - break; - } - - if (*bufferSize + size >= allocated) - { - allocated = (*bufferSize + size + 0xFFF) & ~0xFFF; - *buffer = realloc(*buffer, allocated); - if (!*buffer) - { - result = FALSE; - break; - } - } - - *bufferSize += size; - if (!WinHttpReadData(request, chunkBuffer, size, NULL)) - { - free(*buffer); - result = FALSE; - break; - } - } - while (size > 0); + free(*str); + return HRESULT_FROM_WIN32(GetLastError()); } - else result = FALSE; - - if (request) WinHttpCloseHandle(request); - if (connection) WinHttpCloseHandle(connection); - if (session) WinHttpCloseHandle(session); - return result; + return S_OK; } -static BOOLEAN RequestOAuthToken(LPCSTR clientId) +static HRESULT LoadDefaultUser(XUserHandle *user, LPCSTR client_id) { - LPCSTR template = "scope=service%3a%3auser.auth.xboxlive.com%3a%3aMBI_SSL&response_type=device_code&client_id="; - LPCWSTR accept[] = {L"application/json", NULL}; - BOOLEAN result; - LPSTR data; + LPCSTR user_template = "{\"RelyingParty\":\"http://auth.xboxlive.com\",\"TokenType\":\"JWT\",\"Properties\":{\"AuthMethod\":\"RPS\",\"SiteName\":\"user.auth.xboxlive.com\",\"RpsTicket\":\""; + LPCSTR xsts_template = "{\"RelyingParty\":\"http://xboxlive.com\",\"TokenType\":\"JWT\",\"Properties\":{\"SandboxId\":\"RETAIL\",\"UserTokens\":[\""; + UINT32 token_str_len; + struct x_user *impl; + LPSTR token_str; + LSTATUS status; LPSTR buffer; - SIZE_T size; - - /* request a device code */ - - data = calloc(strlen(template) + strlen(clientId) + 1, sizeof(CHAR)); - strcpy(data, template); - strcat(data, clientId); - result = HttpRequest( - L"POST", - L"login.live.com", - L"/oauth20_connect.srf", - data, - L"content-type: application/x-www-form-urlencoded", - accept, - &buffer, + HRESULT hr; + LPSTR data; + DWORD size; + + if (ERROR_SUCCESS != (status = RegGetValueA( + HKEY_LOCAL_MACHINE, + "Software\\Wine\\WineGDK", + "RefreshToken", + RRF_RT_REG_SZ, + NULL, + NULL, &size - ); - free(data); + ))) 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 (!result) - return result; + if (!(impl = calloc(1, sizeof(*impl)))) return E_OUTOFMEMORY; + impl->IXUserImpl_iface.lpVtbl = &x_user_vtbl; + impl->ref = 1; - TRACE("%s\n", buffer); + hr = RefreshOAuth( + client_id, buffer, &impl->oauth_token_expiry, &impl->refresh_token, &impl->oauth_token); free(buffer); - return result; + if (FAILED(hr)) + { + TRACE("failed to get oauth token\n"); + IXUserImpl_Release(&impl->IXUserImpl_iface); + return hr; + } + + if (FAILED(hr = HSTRINGToMultiByte(impl->oauth_token, &token_str, &token_str_len))) + { + IXUserImpl_Release(&impl->IXUserImpl_iface); + return hr; + } + + if (!(data = calloc(1, strlen(user_template) + strlen(token_str) + strlen("\"}}")))) + { + free(token_str); + IXUserImpl_Release(&impl->IXUserImpl_iface); + return E_OUTOFMEMORY; + } + + strcpy(data, user_template); + strncat(data, token_str, token_str_len); + free(token_str); + strcat(data, "\"}}"); + hr = RequestXToken(L"user.auth.xboxlive.com", L"/user/authenticate", data, &impl->user_token); + free(data); + if (FAILED(hr)) + { + TRACE("failed to get user token\n"); + IXUserImpl_Release(&impl->IXUserImpl_iface); + return hr; + } + + if (FAILED(hr = HSTRINGToMultiByte(impl->user_token, &token_str, &token_str_len))) + { + IXUserImpl_Release(&impl->IXUserImpl_iface); + return hr; + } + + if (!(data = calloc(1, strlen(xsts_template) + strlen(token_str) + strlen("\"]}}")))) + { + IXUserImpl_Release(&impl->IXUserImpl_iface); + free(token_str); + return E_OUTOFMEMORY; + } + + strcpy(data, xsts_template); + strncat(data, token_str, token_str_len); + free(token_str); + strcat(data, "\"]}}"); + hr = RequestXToken(L"xsts.auth.xboxlive.com", L"/xsts/authorize", data, &impl->xsts_token); + free(data); + if (SUCCEEDED(hr)) *user = (XUserHandle)impl; + else { + TRACE("failed to get xsts token\n"); + IXUserImpl_Release(&impl->IXUserImpl_iface); + } + + return hr; } static inline struct x_user *impl_from_IXUserImpl(IXUserImpl *iface) @@ -198,18 +193,27 @@ 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); + free(impl); + } return ref; } static HRESULT WINAPI x_user_XUserDuplicateHandle(IXUserImpl* iface, XUserHandle user, XUserHandle* duplicated) { - FIXME("iface %p, user %p, duplicated %p stub!\n", iface, user, duplicated); - return E_NOTIMPL; + TRACE("iface %p, user %p, duplicated %p\n", iface, user, duplicated); + IXUserImpl_AddRef(&((struct x_user*)user)->IXUserImpl_iface); + *duplicated = user; + return S_OK; } static void WINAPI x_user_XUserCloseHandle(IXUserImpl* iface, XUserHandle user) { - FIXME("iface %p, user %p stub!\n", iface, user); + TRACE("iface %p, user %p\n", iface, user); + IXUserImpl_Release(&((struct x_user*)user)->IXUserImpl_iface); } static INT32 WINAPI x_user_XUserCompare(IXUserImpl* iface, XUserHandle user1, XUserHandle user2) @@ -227,12 +231,14 @@ static HRESULT WINAPI x_user_XUserGetMaxUsers(IXUserImpl* iface, UINT32* maxUser struct XUserAddContext { XUserAddOptions options; XUserHandle user; + LPCSTR client_id; }; HRESULT XUserAddProvider(XAsyncOp operation, const XAsyncProviderData* providerData) { struct XUserAddContext* context; IXThreadingImpl* impl; + HRESULT hr; TRACE("operation %d, providerData %p\n", operation, providerData); @@ -249,8 +255,13 @@ HRESULT XUserAddProvider(XAsyncOp operation, const XAsyncProviderData* providerD break; case DoWork: - // TODO - impl->lpVtbl->XAsyncComplete(impl, providerData->async, S_OK, sizeof(XUserHandle)); + 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: diff --git a/dlls/xgameruntime/GDKComponent/System/XUser.h b/dlls/xgameruntime/GDKComponent/System/User/XUser.h similarity index 82% rename from dlls/xgameruntime/GDKComponent/System/XUser.h rename to dlls/xgameruntime/GDKComponent/System/User/XUser.h index e5fc9798cf6..771d3bd81da 100644 --- a/dlls/xgameruntime/GDKComponent/System/XUser.h +++ b/dlls/xgameruntime/GDKComponent/System/User/XUser.h @@ -24,12 +24,21 @@ #ifndef XUSER_H #define XUSER_H -#include "../../private.h" +#include "../../../private.h" +#include "Token.h" struct x_user { IXUserImpl IXUserImpl_iface; LONG ref; + + XUserLocalId localId; + + 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 e41ef160db4..6c9f558d7e8 100644 --- a/dlls/xgameruntime/Makefile.in +++ b/dlls/xgameruntime/Makefile.in @@ -18,5 +18,6 @@ SOURCES = \ GDKComponent/System/XGameRuntimeFeature.c \ GDKComponent/System/Networking/HTTPClient.c \ GDKComponent/System/Networking/XNetworking.c \ - GDKComponent/System/XUser.c + GDKComponent/System/User/Token.c \ + GDKComponent/System/User/XUser.c diff --git a/dlls/xgameruntime/private.h b/dlls/xgameruntime/private.h index 2120afcb68a..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 From d62086007b846a62c04ef6cecbd8e04b1f549936 Mon Sep 17 00:00:00 2001 From: Olivia Ryan Date: Mon, 9 Feb 2026 18:57:27 +0000 Subject: [PATCH 06/13] xgameruntime: add xuser header --- include/xuser.h | 170 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 170 insertions(+) create mode 100644 include/xuser.h diff --git a/include/xuser.h b/include/xuser.h new file mode 100644 index 00000000000..6691cc9c059 --- /dev/null +++ b/include/xuser.h @@ -0,0 +1,170 @@ +/* + * Copyright (C) the Wine project + * + * 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 __WINE_XUSER_H +#define __WINE_XUSER_H + +#include +#include + +typedef enum XUserAddOptions +{ + AddOptionsNone = 0, + AddOptionsAddDefaultUserSilently = 1, + AddOptionsAllowGuests = 2, + AddDefaultUserAllowingUI = 4 +} XUserAddOptions; + +typedef enum XUserAgeGroup +{ + AgeGroupUnknown = 0, + AgeGroupChild = 1, + AgeGroupTeen = 2, + AgeGroupAdult = 3 +} XUserAgeGroup; + +typedef enum XUserChangeEvent +{ + ChangeEventSignedInAgain = 0, + ChangeEventSigningOut = 1, + ChangeEventSignedOut = 2, + ChangeEventGamertag = 3, + ChangeEventGamerPicture = 4, + ChangeEventPrivileges = 5 +} XUserChangeEvent; + +typedef enum XUserDefaultAudioEndpointKind +{ + DefaultAudioEndpointKindCommunicationRender = 0, + DefaultAudioEndpointKindCommunicationCapture = 1 +} XUserDefaultAudioEndpointKind; + +typedef enum XUserGamerPictureSize +{ + GamerPictureSizeSmall = 0, + GamerPictureSizeMedium = 1, + GamerPictureSizeLarge = 2, + GamerPictureSizeExtraLarge = 3 +} XUserGamerPictureSize; + +typedef enum XUserGamertagComponent +{ + GamertagComponentClassic = 0, + GamertagComponentModern = 1, + GamertagComponentModernSuffix = 2, + GamertagComponentUniqueModern = 3, +} XUserGamertagComponent; + +typedef enum XUserGetMsaTokenSilentlyOptions +{ + GetMsaTokenSilentlyOptionsNone = 0 +} XUserGetMsaTokenSilentlyOptions; + +typedef enum XUserGetTokenAndSignatureOptions +{ + GetTokenAndSignatureOptionsNone = 0, + GetTokenAndSignatureOptionsForceRefresh = 1, + GetTokenAndSignatureOptionsAllUsers = 2 +} XUserGetTokenAndSignatureOptions; + +typedef enum XUserPrivilege +{ + PrivilegeCrossPlay = 185, + PrivilegeClubs = 188, + PrivilegeSessions = 189, + PrivilegeBroadcast = 190, + PrivilegeManageProfilePrivacy = 196, + PrivilegeGameDvr = 198, + PrivilegeMultiplayerParties = 203, + PrivilegeCloudManageSession = 207, + PrivilegeCloudJoinSession = 208, + PrivilegeCloudSavedGames = 209, + PrivilegeSocialNetworkSharing = 220, + PrivilegeUserGeneratedContent = 247, + PrivilegeCommunications = 252, + PrivilegeMultiplayer = 254, + PrivilegeAddFriends = 255 +} XUserPrivilege; + +typedef enum XUserPrivilegeDenyReason +{ + PrivilegeDenyReasonNone = 0, + PrivilegeDenyReasonPurchaseRequired = 1, + PrivilegeRestricted = 2, + PrivilegeBanned = 3, + PrivilegeUnknown = -1 +} XUserPrivilegeDenyReason; + +typedef enum XUserPrivilegeOptions +{ + PrivilegeOptionsNone = 0, + PrivilegeOptionsAllUsers = 1 +} XUserPrivilegeOptions; + +typedef enum XUserState +{ + StateSignedIn = 0, + StateSigningOut = 1, + StateSignedOut = 2 +} XUserState; + +typedef struct XUserDeviceAssociationChange +{ + APP_LOCAL_DEVICE_ID deviceId; + XUserLocalId oldUser; + XUserLocalId newUser; +} XUserDeviceAssociationChange; + +typedef struct XUserGetTokenAndSignatureData +{ + SIZE_T tokenSize; + SIZE_T signatureSize; + LPCSTR token; + LPCSTR signature; +} XUserGetTokenAndSignatureData; + +typedef struct XUserGetTokenAndSignatureUtf16Data +{ + SIZE_T tokenSize; + SIZE_T signatureCount; + LPCWSTR token; + LPCWSTR signature; +} XUserGetTokenAndSignatureUtf16Data; + +typedef struct XUserGetTokenAndSignatureHttpHeader +{ + LPCSTR name; + LPCSTR value; +} XUserGetTokenAndSignatureHttpHeader; + +typedef struct XUserGetTokenAndSignatureUtf16HttpHeader +{ + LPCWSTR name; + LPCWSTR value; +} XUserGetTokenAndSignatureUtf16HttpHeader; + +typedef struct XUserLocalId +{ + UINT64 value; +} XUserLocalId; + +typedef void CALLBACK XUserChangeEventCallback(_In_opt_ PVOID context, _In_ XUserLocalId userLocalId, _In_ XUserChangeEvent event); +typedef void CALLBACK XUserDefaultAudioEndpointUtf16ChangedCallback(_In_opt_ PVOID context, _In_ XUserLocalId user, _In_ XUserDefaultAudioEndpointKind defaultAudioEndpointKind, _In_opt_z_ LPCWSTR endpointIdUtf16); +typedef void CALLBACK XUserDeviceAssociationChangedCallback(_In_opt_ PVOID context, _In_ const XUserDeviceAssociationChange *change); + +#endif /* __WINE_XUSER_H */ \ No newline at end of file From 9ceb883fd5c4b4b1f5dafea5aeb722dc9e15a5ad Mon Sep 17 00:00:00 2001 From: Olivia Ryan Date: Tue, 10 Feb 2026 00:31:19 +0000 Subject: [PATCH 07/13] xgameruntime: Move json response parsing to separate function --- .../GDKComponent/System/User/Token.c | 212 ++++++------------ .../GDKComponent/System/User/XUser.c | 6 +- 2 files changed, 67 insertions(+), 151 deletions(-) diff --git a/dlls/xgameruntime/GDKComponent/System/User/Token.c b/dlls/xgameruntime/GDKComponent/System/User/Token.c index 1fc99e5353a..149c362dd2d 100644 --- a/dlls/xgameruntime/GDKComponent/System/User/Token.c +++ b/dlls/xgameruntime/GDKComponent/System/User/Token.c @@ -18,8 +18,6 @@ #include "Token.h" -WINE_DEFAULT_DEBUG_CHANNEL(gdkc); - static HRESULT HttpRequest(LPCWSTR method, LPCWSTR domain, LPCWSTR object, LPSTR data, LPCWSTR headers, LPCWSTR* accept, LPSTR* buffer, SIZE_T* bufferSize) { HINTERNET connection = NULL; @@ -132,119 +130,109 @@ static HRESULT GetJsonStringValue(IJsonObject *object, LPCWSTR key, HSTRING *con return S_OK; } -HRESULT RefreshOAuth(LPCSTR client_id, LPCSTR refresh_token, time_t *new_expiry, HSTRING *new_refresh_token, HSTRING *new_oauth_token) +static HRESULT ParseJsonObject(LPCSTR str, UINT32 str_size, IJsonObject **object) { - LPCSTR template = "grant_type=refresh_token&scope=service::user.auth.xboxlive.com::MBI_SSL&client_id="; LPCWSTR class_str = RuntimeClass_Windows_Data_Json_JsonValue; - LPCWSTR accept[] = {L"application/json", NULL}; IJsonValueStatics *statics; HSTRING_HEADER content_hdr; - HSTRING_HEADER expires_hdr; HSTRING_HEADER class_hdr; - IJsonObject *object; IJsonValue *value; + UINT32 wstr_size; HSTRING content; - HSTRING expires; - LPWSTR w_buffer; - UINT32 w_size; - time_t expiry; HSTRING class; - LPSTR buffer; - DOUBLE delta; - SIZE_T size; + LPWSTR wstr; HRESULT hr; - LPSTR data; - if (!(data = calloc(1, strlen(template) + strlen(client_id) + - strlen("&refresh_token=") + strlen(refresh_token) + 1))) 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)) { - TRACE("web request failed\n"); - return hr; - } - - if (!(w_size = MultiByteToWideChar(CP_UTF8, 0, buffer, size, NULL, 0))) - { - free(buffer); + if (!(wstr_size = MultiByteToWideChar(CP_UTF8, 0, str, str_size, NULL, 0))) return HRESULT_FROM_WIN32(GetLastError()); - } - if (!(w_buffer = calloc(w_size, sizeof(WCHAR)))) - { - free(buffer); + if (!(wstr = calloc(wstr_size, sizeof(WCHAR)))) return E_OUTOFMEMORY; - } - w_size = MultiByteToWideChar(CP_UTF8, 0, buffer, size, w_buffer, w_size); - free(buffer); - if (!w_size) + if (!(wstr_size = MultiByteToWideChar(CP_UTF8, 0, str, str_size, wstr, wstr_size))) { - free(w_buffer); + free(wstr); return HRESULT_FROM_WIN32(GetLastError()); } - if (FAILED(hr = WindowsCreateStringReference(w_buffer, w_size, &content_hdr, &content))) + if (FAILED(hr = WindowsCreateStringReference(wstr, wstr_size, &content_hdr, &content))) { - free(w_buffer); + free(wstr); return hr; } if (FAILED(hr = WindowsCreateStringReference(class_str, wcslen(class_str), &class_hdr, &class))) { - free(w_buffer); + free(wstr); return hr; } if (FAILED(hr = RoGetActivationFactory(class, &IID_IJsonValueStatics, (void**)&statics))) { - free(w_buffer); + free(wstr); return hr; } hr = IJsonValueStatics_Parse(statics, content, &value); - free(w_buffer); IJsonValueStatics_Release(statics); - if (FAILED(hr)) - { - IJsonValue_Release(value); - return hr; - } + free(wstr); + if (FAILED(hr)) return hr; - hr = IJsonValue_GetObject(value, &object); + hr = IJsonValue_GetObject(value, object); IJsonValue_Release(value); - if (FAILED(hr)) - { - IJsonObject_Release(object); - return hr; - } + 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}; + HSTRING_HEADER expires_hdr; + IJsonObject *object; + HSTRING expires; + 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))) { - TRACE("failed to get access_token\n"); IJsonObject_Release(object); return hr; } if (FAILED(hr = GetJsonStringValue(object, L"refresh_token", new_refresh_token))) { - TRACE("failed to get refresh_token\n"); IJsonObject_Release(object); return hr; } @@ -258,11 +246,7 @@ HRESULT RefreshOAuth(LPCSTR client_id, LPCSTR refresh_token, time_t *new_expiry, hr = IJsonObject_GetNamedNumber(object, expires, &delta); IJsonObject_Release(object); - if (FAILED(hr)) - { - TRACE("failed to get expires_in\n"); - return hr; - } + if (FAILED(hr)) return hr; if ((expiry = time(NULL)) == -1) return E_FAIL; *new_expiry = expiry + delta; @@ -272,22 +256,11 @@ HRESULT RefreshOAuth(LPCSTR client_id, LPCSTR refresh_token, time_t *new_expiry, HRESULT RequestXToken(LPCWSTR domain, LPCWSTR path, LPSTR data, HSTRING *token) { - LPCWSTR class_str = RuntimeClass_Windows_Data_Json_JsonValue; LPCWSTR accept[] = {L"application/json", NULL}; - HSTRING_HEADER token_key_hdr; - IJsonValueStatics *statics; - HSTRING_HEADER content_hdr; - HSTRING_HEADER class_hdr; IJsonObject *object; - IJsonValue *value; - HSTRING token_key; - LPWSTR w_buffer; - HSTRING content; - HSTRING class; LPSTR buffer; SIZE_T size; HRESULT hr; - INT w_size; hr = HttpRequest( L"POST", @@ -300,72 +273,13 @@ HRESULT RequestXToken(LPCWSTR domain, LPCWSTR path, LPSTR data, HSTRING *token) &size ); - if (FAILED(hr)) return FALSE; - - if (!(w_size = MultiByteToWideChar(CP_UTF8, 0, buffer, size, NULL, 0))) - { - free(buffer); - return HRESULT_FROM_WIN32(GetLastError()); - } - - if (!(w_buffer = calloc(w_size, sizeof(WCHAR)))) - { - free(buffer); - return E_OUTOFMEMORY; - } - - w_size = MultiByteToWideChar(CP_UTF8, 0, buffer, size, w_buffer, w_size); + if (FAILED(hr)) return hr; + hr = ParseJsonObject(buffer, size, &object); free(buffer); - if (!w_size) - { - free(w_buffer); - return HRESULT_FROM_WIN32(GetLastError()); - } - - if (FAILED(hr = WindowsCreateStringReference(w_buffer, w_size, &content_hdr, &content))) - { - free(w_buffer); - return hr; - } - - if (FAILED(hr = WindowsCreateStringReference( - L"Token", wcslen(L"Token"), &token_key_hdr, &token_key))) - { - free(w_buffer); - return hr; - } - - if (FAILED(hr = WindowsCreateStringReference(class_str, wcslen(class_str), &class_hdr, &class))) - { - free(w_buffer); - return hr; - } - - if (FAILED(hr = RoGetActivationFactory(class, &IID_IJsonValueStatics, (void**)&statics))) - { - free(w_buffer); - return hr; - } - - hr = IJsonValueStatics_Parse(statics, content, &value); - IJsonValueStatics_Release(statics); - free(w_buffer); - if (FAILED(hr)) - { - IJsonValue_Release(value); - return hr; - } + if (FAILED(hr)) return hr; - hr = IJsonValue_GetObject(value, &object); - IJsonValue_Release(value); - if (FAILED(hr)) - { - IJsonObject_Release(object); - return hr; - } - - if (FAILED(hr = IJsonObject_GetNamedString(object, token_key, token))) - IJsonObject_Release(object); + hr = GetJsonStringValue(object, L"Token", token); + IJsonObject_Release(object); return hr; } \ No newline at end of file diff --git a/dlls/xgameruntime/GDKComponent/System/User/XUser.c b/dlls/xgameruntime/GDKComponent/System/User/XUser.c index f2587d48bd9..98915454e67 100644 --- a/dlls/xgameruntime/GDKComponent/System/User/XUser.c +++ b/dlls/xgameruntime/GDKComponent/System/User/XUser.c @@ -107,7 +107,7 @@ static HRESULT LoadDefaultUser(XUserHandle *user, LPCSTR client_id) return hr; } - if (!(data = calloc(1, strlen(user_template) + strlen(token_str) + strlen("\"}}")))) + if (!(data = calloc(strlen(user_template) + strlen(token_str) + strlen("\"}}") + 1, sizeof(CHAR)))) { free(token_str); IXUserImpl_Release(&impl->IXUserImpl_iface); @@ -133,7 +133,7 @@ static HRESULT LoadDefaultUser(XUserHandle *user, LPCSTR client_id) return hr; } - if (!(data = calloc(1, strlen(xsts_template) + strlen(token_str) + strlen("\"]}}")))) + if (!(data = calloc(strlen(xsts_template) + strlen(token_str) + strlen("\"]}}") + 1, sizeof(CHAR)))) { IXUserImpl_Release(&impl->IXUserImpl_iface); free(token_str); @@ -197,6 +197,8 @@ static ULONG WINAPI x_user_Release(IXUserImpl *iface) { WindowsDeleteString(impl->refresh_token); WindowsDeleteString(impl->oauth_token); + WindowsDeleteString(impl->user_token); + WindowsDeleteString(impl->xsts_token); free(impl); } return ref; From b932d1867396843d9c32200864c5d013b7db2440 Mon Sep 17 00:00:00 2001 From: Olivia Ryan Date: Tue, 10 Feb 2026 04:20:35 +0000 Subject: [PATCH 08/13] xgameruntime: extract user hash from user auth response --- .../GDKComponent/System/User/Token.c | 173 +++++++++++++++--- .../GDKComponent/System/User/Token.h | 3 + .../GDKComponent/System/User/XUser.c | 41 +---- .../GDKComponent/System/User/XUser.h | 2 +- 4 files changed, 153 insertions(+), 66 deletions(-) diff --git a/dlls/xgameruntime/GDKComponent/System/User/Token.c b/dlls/xgameruntime/GDKComponent/System/User/Token.c index 149c362dd2d..92ead2d8a96 100644 --- a/dlls/xgameruntime/GDKComponent/System/User/Token.c +++ b/dlls/xgameruntime/GDKComponent/System/User/Token.c @@ -18,6 +18,47 @@ #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; @@ -115,21 +156,6 @@ static HRESULT HttpRequest(LPCWSTR method, LPCWSTR domain, LPCWSTR object, LPSTR return hr; } -static HRESULT GetJsonStringValue(IJsonObject *object, LPCWSTR key, HSTRING *content) -{ - 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_GetNamedString(object, key_hstr, content))) - return hr; - - return S_OK; -} - static HRESULT ParseJsonObject(LPCSTR str, UINT32 str_size, IJsonObject **object) { LPCWSTR class_str = RuntimeClass_Windows_Data_Json_JsonValue; @@ -190,9 +216,7 @@ HRESULT RefreshOAuth(LPCSTR client_id, LPCSTR refresh_token, time_t *new_expiry, { LPCSTR template = "grant_type=refresh_token&scope=service::user.auth.xboxlive.com::MBI_SSL&client_id="; LPCWSTR accept[] = {L"application/json", NULL}; - HSTRING_HEADER expires_hdr; IJsonObject *object; - HSTRING expires; time_t expiry; LPSTR buffer; DOUBLE delta; @@ -232,19 +256,12 @@ HRESULT RefreshOAuth(LPCSTR client_id, LPCSTR refresh_token, time_t *new_expiry, } if (FAILED(hr = GetJsonStringValue(object, L"refresh_token", new_refresh_token))) - { - IJsonObject_Release(object); - return hr; - } - - if (FAILED(hr = WindowsCreateStringReference( - L"expires_in", wcslen(L"expires_in"), &expires_hdr, &expires))) { IJsonObject_Release(object); return hr; } - hr = IJsonObject_GetNamedNumber(object, expires, &delta); + if (FAILED(hr = GetJsonNumberValue(object, L"expires_in", &delta))) IJsonObject_Release(object); if (FAILED(hr)) return hr; @@ -281,5 +298,111 @@ HRESULT RequestXToken(LPCWSTR domain, LPCWSTR path, LPSTR data, HSTRING *token) hr = GetJsonStringValue(object, L"Token", token); IJsonObject_Release(object); + return hr; +} + +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; } \ No newline at end of file diff --git a/dlls/xgameruntime/GDKComponent/System/User/Token.h b/dlls/xgameruntime/GDKComponent/System/User/Token.h index 6a44e1bf9c0..904357a6086 100644 --- a/dlls/xgameruntime/GDKComponent/System/User/Token.h +++ b/dlls/xgameruntime/GDKComponent/System/User/Token.h @@ -21,6 +21,7 @@ #include "../../../private.h" +#include #include #include "time.h" @@ -32,6 +33,8 @@ struct token }; 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 RequestXToken(LPCWSTR domain, LPCWSTR path, LPSTR data, HSTRING *token); +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 index 98915454e67..a8cc918e1c7 100644 --- a/dlls/xgameruntime/GDKComponent/System/User/XUser.c +++ b/dlls/xgameruntime/GDKComponent/System/User/XUser.c @@ -28,28 +28,8 @@ WINE_DEFAULT_DEBUG_CHANNEL(gdkc); static const struct IXUserImplVtbl x_user_vtbl; -static 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); - return HRESULT_FROM_WIN32(GetLastError()); - } - - return S_OK; -} - static HRESULT LoadDefaultUser(XUserHandle *user, LPCSTR client_id) { - LPCSTR user_template = "{\"RelyingParty\":\"http://auth.xboxlive.com\",\"TokenType\":\"JWT\",\"Properties\":{\"AuthMethod\":\"RPS\",\"SiteName\":\"user.auth.xboxlive.com\",\"RpsTicket\":\""; LPCSTR xsts_template = "{\"RelyingParty\":\"http://xboxlive.com\",\"TokenType\":\"JWT\",\"Properties\":{\"SandboxId\":\"RETAIL\",\"UserTokens\":[\""; UINT32 token_str_len; struct x_user *impl; @@ -101,26 +81,7 @@ static HRESULT LoadDefaultUser(XUserHandle *user, LPCSTR client_id) return hr; } - if (FAILED(hr = HSTRINGToMultiByte(impl->oauth_token, &token_str, &token_str_len))) - { - IXUserImpl_Release(&impl->IXUserImpl_iface); - return hr; - } - - if (!(data = calloc(strlen(user_template) + strlen(token_str) + strlen("\"}}") + 1, sizeof(CHAR)))) - { - free(token_str); - IXUserImpl_Release(&impl->IXUserImpl_iface); - return E_OUTOFMEMORY; - } - - strcpy(data, user_template); - strncat(data, token_str, token_str_len); - free(token_str); - strcat(data, "\"}}"); - hr = RequestXToken(L"user.auth.xboxlive.com", L"/user/authenticate", data, &impl->user_token); - free(data); - if (FAILED(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); diff --git a/dlls/xgameruntime/GDKComponent/System/User/XUser.h b/dlls/xgameruntime/GDKComponent/System/User/XUser.h index 771d3bd81da..2fecca9a105 100644 --- a/dlls/xgameruntime/GDKComponent/System/User/XUser.h +++ b/dlls/xgameruntime/GDKComponent/System/User/XUser.h @@ -32,7 +32,7 @@ struct x_user IXUserImpl IXUserImpl_iface; LONG ref; - XUserLocalId localId; + XUserLocalId local_id; time_t oauth_token_expiry; HSTRING refresh_token; From f9ab9965bc53df82d2bb1d802716f4f000687832 Mon Sep 17 00:00:00 2001 From: Olivia Ryan Date: Tue, 10 Feb 2026 07:24:40 +0000 Subject: [PATCH 09/13] xgameruntime: basic auth done --- .../GDKComponent/System/User/Token.c | 116 +++++++++++++++--- .../GDKComponent/System/User/Token.h | 2 +- .../GDKComponent/System/User/XUser.c | 47 +++---- .../GDKComponent/System/User/XUser.h | 1 + 4 files changed, 116 insertions(+), 50 deletions(-) diff --git a/dlls/xgameruntime/GDKComponent/System/User/Token.c b/dlls/xgameruntime/GDKComponent/System/User/Token.c index 92ead2d8a96..4bb57829088 100644 --- a/dlls/xgameruntime/GDKComponent/System/User/Token.c +++ b/dlls/xgameruntime/GDKComponent/System/User/Token.c @@ -271,18 +271,41 @@ HRESULT RefreshOAuth(LPCSTR client_id, LPCSTR refresh_token, time_t *new_expiry, return S_OK; } -HRESULT RequestXToken(LPCWSTR domain, LPCWSTR path, LPSTR data, HSTRING *token) +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", - domain, - path, + L"user.auth.xboxlive.com", + L"/user/authenticate", data, L"content-type: application/json", accept, @@ -290,38 +313,91 @@ HRESULT RequestXToken(LPCWSTR domain, LPCWSTR path, LPSTR data, HSTRING *token) &size ); + free(data); if (FAILED(hr)) return hr; hr = ParseJsonObject(buffer, size, &object); free(buffer); if (FAILED(hr)) return hr; - hr = GetJsonStringValue(object, L"Token", token); + 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 RequestUserToken(HSTRING oauth_token, HSTRING *token, XUserLocalId *local_id) +HRESULT RequestXstsToken(HSTRING user_token, HSTRING *token, UINT64 *xuid) { - LPCSTR template = "{\"RelyingParty\":\"http://auth.xboxlive.com\",\"TokenType\":\"JWT\",\"Properties\":{\"AuthMethod\":\"RPS\",\"SiteName\":\"user.auth.xboxlive.com\",\"RpsTicket\":\""; + 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 uhs_str_len; + UINT32 xid_str_len; LPSTR token_str; IJsonArray *xui; - LPSTR uhs_str; + LPSTR xid_str; LPSTR buffer; SIZE_T size; - HSTRING uhs; - LPSTR data; + HSTRING xid; HRESULT hr; + LPSTR data; - if (FAILED(hr = HSTRINGToMultiByte(oauth_token, &token_str, &token_str_len))) + 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)))) + if (!(data = calloc(strlen(template) + token_str_len + strlen("\"]}}") + 1, sizeof(CHAR)))) { free(token_str); return E_OUTOFMEMORY; @@ -330,12 +406,12 @@ HRESULT RequestUserToken(HSTRING oauth_token, HSTRING *token, XUserLocalId *loca strcpy(data, template); strncat(data, token_str, token_str_len); free(token_str); - strcat(data, "\"}}"); + strcat(data, "\"]}}"); hr = HttpRequest( L"POST", - L"user.auth.xboxlive.com", - L"/user/authenticate", + L"xsts.auth.xboxlive.com", + L"/xsts/authorize", data, L"content-type: application/json", accept, @@ -379,7 +455,7 @@ HRESULT RequestUserToken(HSTRING oauth_token, HSTRING *token, XUserLocalId *loca return hr; } - hr = GetJsonStringValue(object, L"uhs", &uhs); + hr = GetJsonStringValue(object, L"xid", &xid); IJsonObject_Release(object); if (FAILED(hr)) { @@ -387,16 +463,16 @@ HRESULT RequestUserToken(HSTRING oauth_token, HSTRING *token, XUserLocalId *loca return hr; } - hr = HSTRINGToMultiByte(uhs, &uhs_str, &uhs_str_len); - WindowsDeleteString(uhs); + hr = HSTRINGToMultiByte(xid, &xid_str, &xid_str_len); + WindowsDeleteString(xid); if (FAILED(hr)) { WindowsDeleteString(*token); return hr; } - local_id->value = strtoull(uhs_str, NULL, 10); - free(uhs_str); + *xuid = strtoull(xid_str, NULL, 10); + free(xid_str); if (errno == ERANGE) { WindowsDeleteString(*token); diff --git a/dlls/xgameruntime/GDKComponent/System/User/Token.h b/dlls/xgameruntime/GDKComponent/System/User/Token.h index 904357a6086..cfdebee27fc 100644 --- a/dlls/xgameruntime/GDKComponent/System/User/Token.h +++ b/dlls/xgameruntime/GDKComponent/System/User/Token.h @@ -34,7 +34,7 @@ struct token 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 RequestXToken(LPCWSTR domain, LPCWSTR path, LPSTR data, HSTRING *token); +HRESULT RequestXstsToken(HSTRING user_token, HSTRING *token, UINT64 *xuid); 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 index a8cc918e1c7..6cb360b85b8 100644 --- a/dlls/xgameruntime/GDKComponent/System/User/XUser.c +++ b/dlls/xgameruntime/GDKComponent/System/User/XUser.c @@ -30,14 +30,10 @@ static const struct IXUserImplVtbl x_user_vtbl; static HRESULT LoadDefaultUser(XUserHandle *user, LPCSTR client_id) { - LPCSTR xsts_template = "{\"RelyingParty\":\"http://xboxlive.com\",\"TokenType\":\"JWT\",\"Properties\":{\"SandboxId\":\"RETAIL\",\"UserTokens\":[\""; - UINT32 token_str_len; struct x_user *impl; - LPSTR token_str; LSTATUS status; LPSTR buffer; HRESULT hr; - LPSTR data; DWORD size; if (ERROR_SUCCESS != (status = RegGetValueA( @@ -66,7 +62,12 @@ static HRESULT LoadDefaultUser(XUserHandle *user, LPCSTR client_id) return HRESULT_FROM_WIN32(status); } - if (!(impl = calloc(1, sizeof(*impl)))) return E_OUTOFMEMORY; + if (!(impl = calloc(1, sizeof(*impl)))) + { + free(buffer); + return E_OUTOFMEMORY; + } + impl->IXUserImpl_iface.lpVtbl = &x_user_vtbl; impl->ref = 1; @@ -88,30 +89,14 @@ static HRESULT LoadDefaultUser(XUserHandle *user, LPCSTR client_id) return hr; } - if (FAILED(hr = HSTRINGToMultiByte(impl->user_token, &token_str, &token_str_len))) + if (FAILED(hr = RequestXstsToken(impl->user_token, &impl->xsts_token, &impl->xuid))) { + TRACE("failed to get xsts token\n"); IXUserImpl_Release(&impl->IXUserImpl_iface); return hr; } - if (!(data = calloc(strlen(xsts_template) + strlen(token_str) + strlen("\"]}}") + 1, sizeof(CHAR)))) - { - IXUserImpl_Release(&impl->IXUserImpl_iface); - free(token_str); - return E_OUTOFMEMORY; - } - - strcpy(data, xsts_template); - strncat(data, token_str, token_str_len); - free(token_str); - strcat(data, "\"]}}"); - hr = RequestXToken(L"xsts.auth.xboxlive.com", L"/xsts/authorize", data, &impl->xsts_token); - free(data); - if (SUCCEEDED(hr)) *user = (XUserHandle)impl; - else { - TRACE("failed to get xsts token\n"); - IXUserImpl_Release(&impl->IXUserImpl_iface); - } + *user = (XUserHandle)impl; return hr; } @@ -132,7 +117,7 @@ static HRESULT WINAPI x_user_QueryInterface(IXUserImpl *iface, REFIID iid, void || IsEqualGUID(iid, &IID_IXUserImpl)) { *out = &impl->IXUserImpl_iface; - impl->IXUserImpl_iface.lpVtbl->AddRef(*out); + IXUserImpl_AddRef(*out); return S_OK; } @@ -264,8 +249,10 @@ static HRESULT WINAPI x_user_XUserAddResult(IXUserImpl* iface, XAsyncBlock* asyn static HRESULT WINAPI x_user_XUserGetLocalId(IXUserImpl* iface, XUserHandle user, XUserLocalId* localId) { - FIXME("iface %p, user %p, localId %p stub!\n", iface, user, localId); - return E_NOTIMPL; + TRACE("iface %p, user %p, localId %p\n", iface, user, localId); + if (!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) @@ -276,8 +263,10 @@ static HRESULT WINAPI x_user_XUserFindUserByLocalId(IXUserImpl* iface, XUserLoca static HRESULT WINAPI x_user_XUserGetId(IXUserImpl* iface, XUserHandle user, UINT64* userId) { - FIXME("iface %p, user %p, userId %p stub!\n", iface, user, userId); - return E_NOTIMPL; + TRACE("iface %p, user %p, userId %p\n", iface, user, userId); + if (!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) diff --git a/dlls/xgameruntime/GDKComponent/System/User/XUser.h b/dlls/xgameruntime/GDKComponent/System/User/XUser.h index 2fecca9a105..8b8b3593a89 100644 --- a/dlls/xgameruntime/GDKComponent/System/User/XUser.h +++ b/dlls/xgameruntime/GDKComponent/System/User/XUser.h @@ -32,6 +32,7 @@ struct x_user IXUserImpl IXUserImpl_iface; LONG ref; + UINT64 xuid; XUserLocalId local_id; time_t oauth_token_expiry; From 2c0a5777c5aa18b47eac3ded2131b8c88a51c826 Mon Sep 17 00:00:00 2001 From: Olivia Ryan Date: Tue, 10 Feb 2026 13:43:50 +0000 Subject: [PATCH 10/13] xgameruntime: XUserGetTokenAndSignature async provider stub --- .../GDKComponent/System/User/XUser.c | 122 ++++++++++++++++-- 1 file changed, 112 insertions(+), 10 deletions(-) diff --git a/dlls/xgameruntime/GDKComponent/System/User/XUser.c b/dlls/xgameruntime/GDKComponent/System/User/XUser.c index 6cb360b85b8..bb854f34b4e 100644 --- a/dlls/xgameruntime/GDKComponent/System/User/XUser.c +++ b/dlls/xgameruntime/GDKComponent/System/User/XUser.c @@ -176,13 +176,14 @@ static HRESULT WINAPI x_user_XUserGetMaxUsers(IXUserImpl* iface, UINT32* maxUser return E_NOTIMPL; } -struct XUserAddContext { +struct XUserAddContext +{ XUserAddOptions options; XUserHandle user; LPCSTR client_id; }; -HRESULT XUserAddProvider(XAsyncOp operation, const XAsyncProviderData* providerData) +static HRESULT XUserAddProvider(XAsyncOp operation, const XAsyncProviderData* providerData) { struct XUserAddContext* context; IXThreadingImpl* impl; @@ -305,7 +306,7 @@ static HRESULT WINAPI x_user_XUserGetGamerPictureResultSize(IXUserImpl* iface, X return E_NOTIMPL; } -static HRESULT WINAPI x_user_XUserGetGamerPictureResult(IXUserImpl* iface, XAsyncBlock* asyncBlock, SIZE_T size, void* buffer, SIZE_T* used) +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; @@ -335,18 +336,96 @@ static HRESULT WINAPI x_user_XUserResolvePrivilegeWithUiResult(IXUserImpl* iface 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 (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) { - FIXME("iface %p, user %p, options %d, method %s, url %s, count %llu, headers %p, size %llu, buffer %p, asyncBlock %p stub!\n", iface, user, options, method, url, count, headers, size, buffer, asyncBlock); - return E_NOTIMPL; + struct XUserGetTokenAndSignatureContext* context; + IXThreadingImpl* impl; + + 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 (FAILED(QueryApiImpl(&CLSID_XThreadingImpl, &IID_IXThreadingImpl, (void**)&impl))) return E_NOTIMPL; + if (!(context = calloc(1, sizeof(*context)))) 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); + return E_OUTOFMEMORY; + } + + for (SIZE_T i = 0; i < count; i++) + context->headers[i] = headers[i]; + + return impl->lpVtbl->XAsyncBegin(impl, asyncBlock, context, x_user_XUserGetTokenAndSignatureAsync, "XUserGetTokenAndSignatureAsync", XUserGetTokenAndSignatureProvider); } + 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, void* buffer, XUserGetTokenAndSignatureData** ptr, SIZE_T* used) +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; @@ -354,8 +433,31 @@ static HRESULT WINAPI x_user_XUserGetTokenAndSignatureResult(IXUserImpl* iface, 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) { - FIXME("iface %p, user %p, options %d, method %hs, url %hs, count %llu, headers %p, size %llu, buffer %p, asyncBlock %p stub!\n", iface, user, options, method, url, count, headers, size, buffer, asyncBlock); - return E_NOTIMPL; + struct XUserGetTokenAndSignatureContext* context; + IXThreadingImpl* impl; + + 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 (FAILED(QueryApiImpl(&CLSID_XThreadingImpl, &IID_IXThreadingImpl, (void**)&impl))) return E_NOTIMPL; + if (!(context = calloc(1, sizeof(*context)))) 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); + return E_OUTOFMEMORY; + } + + for (SIZE_T i = 0; i < count; i++) + context->headers_utf16[i] = headers[i]; + + return impl->lpVtbl->XAsyncBegin(impl, asyncBlock, context, x_user_XUserGetTokenAndSignatureUtf16Async, "XUserGetTokenAndSignatureUtf16Async", XUserGetTokenAndSignatureProvider); } static HRESULT WINAPI x_user_XUserGetTokenAndSignatureUtf16ResultSize(IXUserImpl* iface, XAsyncBlock* asyncBlock, SIZE_T* size) @@ -364,7 +466,7 @@ static HRESULT WINAPI x_user_XUserGetTokenAndSignatureUtf16ResultSize(IXUserImpl return E_NOTIMPL; } -static HRESULT WINAPI x_user_XUserGetTokenAndSignatureUtf16Result(IXUserImpl* iface, XAsyncBlock* asyncBlock, SIZE_T size, void* buffer, XUserGetTokenAndSignatureUtf16Data** ptr, SIZE_T* used) +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; @@ -394,7 +496,7 @@ static HRESULT WINAPI x_user_XUserResolveIssueWithUiUtf16Result(IXUserImpl* ifac return E_NOTIMPL; } -static HRESULT WINAPI x_user_XUserRegisterForChangeEvent(IXUserImpl* iface, XTaskQueueHandle queue, void* context, XUserChangeEventCallback* callback, XTaskQueueRegistrationToken* token) +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; From b14d2ccbd1776f12bb11b065ff8178dcf642b179 Mon Sep 17 00:00:00 2001 From: Olivia Ryan Date: Fri, 13 Feb 2026 02:38:17 +0000 Subject: [PATCH 11/13] xgameruntime: Stub XUser extension interfaces --- .../GDKComponent/System/User/XUser.c | 483 ++++++++++++------ .../GDKComponent/System/User/XUser.h | 1 + dlls/xgameruntime/provider.idl | 266 +++++----- include/Makefile.in | 1 + include/xuser.h | 170 ------ include/xuser.idl | 217 ++++++++ 6 files changed, 669 insertions(+), 469 deletions(-) delete mode 100644 include/xuser.h create mode 100644 include/xuser.idl diff --git a/dlls/xgameruntime/GDKComponent/System/User/XUser.c b/dlls/xgameruntime/GDKComponent/System/User/XUser.c index bb854f34b4e..faac649d122 100644 --- a/dlls/xgameruntime/GDKComponent/System/User/XUser.c +++ b/dlls/xgameruntime/GDKComponent/System/User/XUser.c @@ -27,8 +27,9 @@ 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) +static HRESULT LoadDefaultUser( XUserHandle *user, LPCSTR client_id ) { struct x_user *impl; LSTATUS status; @@ -44,9 +45,9 @@ static HRESULT LoadDefaultUser(XUserHandle *user, LPCSTR client_id) NULL, NULL, &size - ))) return HRESULT_FROM_WIN32(status); + ))) return HRESULT_FROM_WIN32( status ); - if (!(buffer = calloc(1, size))) return E_OUTOFMEMORY; + if (!(buffer = calloc( 1, size ))) return E_OUTOFMEMORY; if (ERROR_SUCCESS != (status = RegGetValueA( HKEY_LOCAL_MACHINE, @@ -58,41 +59,40 @@ static HRESULT LoadDefaultUser(XUserHandle *user, LPCSTR client_id) &size ))) { - free(buffer); - return HRESULT_FROM_WIN32(status); + free( buffer ); + return HRESULT_FROM_WIN32( status ); } - if (!(impl = calloc(1, sizeof(*impl)))) + if (!(impl = calloc( 1, sizeof( *impl ) ))) { - free(buffer); + 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)) + 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); + 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))) + 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); + 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))) + if (FAILED( hr = RequestXstsToken( impl->user_token, &impl->xsts_token, &impl->xuid ) )) { - TRACE("failed to get xsts token\n"); - IXUserImpl_Release(&impl->IXUserImpl_iface); + TRACE( "failed to get xsts token\n" ); + IXUserImpl_Release( &impl->IXUserImpl_iface ); return hr; } @@ -101,78 +101,91 @@ static HRESULT LoadDefaultUser(XUserHandle *user, LPCSTR client_id) return hr; } -static inline struct x_user *impl_from_IXUserImpl(IXUserImpl *iface) +static inline struct x_user *impl_from_IXUserImpl( IXUserImpl *iface ) { - return CONTAINING_RECORD(iface, struct x_user, IXUserImpl_iface); + return CONTAINING_RECORD( iface, struct x_user, IXUserImpl_iface ); } -static HRESULT WINAPI x_user_QueryInterface(IXUserImpl *iface, REFIID iid, void **out) +static HRESULT WINAPI x_user_QueryInterface( IXUserImpl *iface, REFIID iid, void **out ) { - struct x_user *impl = impl_from_IXUserImpl(iface); + struct x_user *impl = impl_from_IXUserImpl( iface ); + + TRACE( "iface %p, iid %s, out %p\n", iface, debugstr_guid( iid ), out ); - 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, &CLSID_XUserImpl) - || IsEqualGUID(iid, &IID_IXUserImpl)) + 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); + 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)); + FIXME( "%s not implemented, returning E_NOINTERFACE\n", debugstr_guid( iid ) ); *out = NULL; return E_NOINTERFACE; } -static ULONG WINAPI x_user_AddRef(IXUserImpl *iface) +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); + 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) +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); + 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); + 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) +static HRESULT WINAPI x_user_XUserDuplicateHandle( IXUserImpl *iface, XUserHandle user, XUserHandle* duplicated ) { - TRACE("iface %p, user %p, duplicated %p\n", iface, user, duplicated); - IXUserImpl_AddRef(&((struct x_user*)user)->IXUserImpl_iface); + TRACE( "iface %p, user %p, duplicated %p\n", iface, user, duplicated ); + IXUserImpl_AddRef( &((struct x_user*)user)->IXUserImpl_iface ); *duplicated = user; return S_OK; } -static void WINAPI x_user_XUserCloseHandle(IXUserImpl* iface, XUserHandle user) +static void WINAPI x_user_XUserCloseHandle( IXUserImpl *iface, XUserHandle user ) { - TRACE("iface %p, user %p\n", iface, user); - IXUserImpl_Release(&((struct x_user*)user)->IXUserImpl_iface); + TRACE( "iface %p, user %p\n", iface, user ); + IXUserImpl_Release( &((struct x_user*)user)->IXUserImpl_iface ); } -static INT32 WINAPI x_user_XUserCompare(IXUserImpl* iface, XUserHandle user1, XUserHandle user2) +static INT32 WINAPI x_user_XUserCompare( IXUserImpl *iface, XUserHandle user1, XUserHandle user2 ) { - FIXME("iface %p, user1 %p, user2 %p stub!\n", iface, user1, user2); + FIXME( "iface %p, user1 %p, user2 %p stub!\n", iface, user1, user2 ); return E_NOTIMPL; } -static HRESULT WINAPI x_user_XUserGetMaxUsers(IXUserImpl* iface, UINT32* maxUsers) +static HRESULT WINAPI x_user_XUserGetMaxUsers( IXUserImpl *iface, UINT32* maxUsers ) { - FIXME("iface %p, maxUsers %p stub!\n", iface, maxUsers); + FIXME( "iface %p, maxUsers %p stub!\n", iface, maxUsers ); return E_NOTIMPL; } @@ -183,38 +196,38 @@ struct XUserAddContext LPCSTR client_id; }; -static HRESULT XUserAddProvider(XAsyncOp operation, const XAsyncProviderData* providerData) +static HRESULT XUserAddProvider( XAsyncOp operation, const XAsyncProviderData* providerData ) { struct XUserAddContext* context; IXThreadingImpl* impl; HRESULT hr; - TRACE("operation %d, providerData %p\n", operation, providerData); + TRACE( "operation %d, providerData %p\n", operation, providerData ); - if (FAILED(QueryApiImpl(&CLSID_XThreadingImpl, &IID_IXThreadingImpl, (void**)&impl))) return E_FAIL; + 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); + return impl->lpVtbl->XAsyncSchedule( impl, providerData->async, 0 ); case GetResult: - memcpy(providerData->buffer, &context->user, sizeof(XUserHandle)); + memcpy( providerData->buffer, &context->user, sizeof( XUserHandle ) ); break; case DoWork: if (context->options & XUserAddOptions_AddDefaultUserAllowingUI) - hr = LoadDefaultUser(&context->user, context->client_id); + hr = LoadDefaultUser( &context->user, context->client_id ); else if (context->options & XUserAddOptions_AddDefaultUserSilently) - hr = LoadDefaultUser(&context->user, context->client_id); + hr = LoadDefaultUser( &context->user, context->client_id ); else hr = E_ABORT; - impl->lpVtbl->XAsyncComplete(impl, providerData->async, hr, sizeof(XUserHandle)); + impl->lpVtbl->XAsyncComplete( impl, providerData->async, hr, sizeof( XUserHandle ) ); break; case Cleanup: - free(context); + free( context ); break; case Cancel: @@ -224,115 +237,115 @@ static HRESULT XUserAddProvider(XAsyncOp operation, const XAsyncProviderData* pr return S_OK; } -static HRESULT WINAPI x_user_XUserAddAsync(IXUserImpl* iface, XUserAddOptions options, XAsyncBlock* asyncBlock) +static HRESULT WINAPI x_user_XUserAddAsync( IXUserImpl *iface, XUserAddOptions options, XAsyncBlock* asyncBlock ) { struct XUserAddContext* context; IXThreadingImpl* impl; - TRACE("iface %p, options %d, asyncBlock %p\n", iface, options, asyncBlock); + TRACE( "iface %p, options %d, asyncBlock %p\n", iface, options, asyncBlock ); - if (FAILED(QueryApiImpl(&CLSID_XThreadingImpl, &IID_IXThreadingImpl, (void**)&impl))) return E_NOTIMPL; - if (!(context = calloc(1, sizeof(struct XUserAddContext)))) return E_OUTOFMEMORY; + if (FAILED( QueryApiImpl( &CLSID_XThreadingImpl, &IID_IXThreadingImpl, (void**)&impl ) )) return E_NOTIMPL; + if (!(context = calloc( 1, sizeof( struct XUserAddContext ) ))) return E_OUTOFMEMORY; context->options = options; - return impl->lpVtbl->XAsyncBegin(impl, asyncBlock, context, x_user_XUserAddAsync, "XUserAddAsync", XUserAddProvider); + return impl->lpVtbl->XAsyncBegin( impl, asyncBlock, context, x_user_XUserAddAsync, "XUserAddAsync", XUserAddProvider ); } -static HRESULT WINAPI x_user_XUserAddResult(IXUserImpl* iface, XAsyncBlock* asyncBlock, XUserHandle* user) +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); + TRACE( "iface %p, asyncBlock %p, user %p\n", iface, asyncBlock, *user ); - 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); + 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) +static HRESULT WINAPI x_user_XUserGetLocalId( IXUserImpl *iface, XUserHandle user, XUserLocalId* localId ) { - TRACE("iface %p, user %p, localId %p\n", iface, user, localId); + TRACE( "iface %p, user %p, localId %p\n", iface, user, localId ); if (!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) +static HRESULT WINAPI x_user_XUserFindUserByLocalId( IXUserImpl *iface, XUserLocalId localId, XUserHandle* user ) { - FIXME("iface %p, localId %p, user %p stub!\n", iface, &localId, 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) +static HRESULT WINAPI x_user_XUserGetId( IXUserImpl *iface, XUserHandle user, UINT64* userId ) { - TRACE("iface %p, user %p, userId %p\n", iface, user, userId); + TRACE( "iface %p, user %p, userId %p\n", iface, user, userId ); if (!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) +static HRESULT WINAPI x_user_XUserFindUserById( IXUserImpl *iface, UINT64 userId, XUserHandle* user ) { - FIXME("iface %p, userId %llu, user %p stub!\n", iface, userId, 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) +static HRESULT WINAPI x_user_XUserGetIsGuest( IXUserImpl *iface, XUserHandle user, BOOLEAN* isGuest ) { - FIXME("iface %p, user %p, isGuest %p stub!\n", iface, user, isGuest); + FIXME( "iface %p, user %p, isGuest %p stub!\n", iface, user, isGuest ); return E_NOTIMPL; } -static HRESULT WINAPI x_user_XUserGetState(IXUserImpl* iface, XUserHandle user, XUserState* state) +static HRESULT WINAPI x_user_XUserGetState( IXUserImpl *iface, XUserHandle user, XUserState* state ) { - FIXME("iface %p, user %p, state %p stub!\n", iface, user, state); + FIXME( "iface %p, user %p, state %p stub!\n", iface, user, state ); return E_NOTIMPL; } -static HRESULT WINAPI __PADDING__(IXUserImpl* iface) +static HRESULT WINAPI __PADDING__( IXUserImpl *iface ) { - WARN("iface %p padding function called! It's unknown what this function does\n", 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) +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); + 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) +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); + 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) +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); + 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) +static HRESULT WINAPI x_user_XUserGetAgeGroup( IXUserImpl *iface, XUserHandle user, XUserAgeGroup* group ) { - FIXME("user %p, group %p stub!\n", user, group); + FIXME( "user %p, group %p stub!\n", user, group ); return E_NOTIMPL; } -static HRESULT WINAPI x_user_XUserCheckPrivilege(IXUserImpl* iface, XUserHandle user, XUserPrivilegeOptions options, XUserPrivilege privilege, BOOLEAN* hasPrivilege, XUserPrivilegeDenyReason* reason) +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); + 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) +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); + 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) +static HRESULT WINAPI x_user_XUserResolvePrivilegeWithUiResult( IXUserImpl *iface, XAsyncBlock* asyncBlock ) { - FIXME("iface %p, asyncBlock %p stub!\n", iface, asyncBlock); + FIXME( "iface %p, asyncBlock %p stub!\n", iface, asyncBlock ); return E_NOTIMPL; } @@ -352,35 +365,35 @@ struct XUserGetTokenAndSignatureContext const void *buffer; }; -static HRESULT XUserGetTokenAndSignatureProvider(XAsyncOp operation, const XAsyncProviderData* providerData) +static HRESULT XUserGetTokenAndSignatureProvider( XAsyncOp operation, const XAsyncProviderData* providerData ) { struct XUserGetTokenAndSignatureContext* context; IXThreadingImpl* impl; - TRACE("operation %d, providerData %p\n", operation, providerData); + TRACE( "operation %d, providerData %p\n", operation, providerData ); - if (FAILED(QueryApiImpl(&CLSID_XThreadingImpl, &IID_IXThreadingImpl, (void**)&impl))) return E_FAIL; + 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); + return impl->lpVtbl->XAsyncSchedule( impl, providerData->async, 0 ); case GetResult: break; case DoWork: - impl->lpVtbl->XAsyncComplete(impl, providerData->async, E_FAIL, sizeof(XUserHandle)); + 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); + if (context->utf16) free( context->headers_utf16 ); + else free( context->headers ); } - free(context); + free( context ); break; case Cancel: @@ -390,15 +403,15 @@ static HRESULT XUserGetTokenAndSignatureProvider(XAsyncOp operation, const XAsyn 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) +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; - 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); + 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 (FAILED(QueryApiImpl(&CLSID_XThreadingImpl, &IID_IXThreadingImpl, (void**)&impl))) return E_NOTIMPL; - if (!(context = calloc(1, sizeof(*context)))) return E_OUTOFMEMORY; + if (FAILED( QueryApiImpl( &CLSID_XThreadingImpl, &IID_IXThreadingImpl, (void**)&impl ) )) return E_NOTIMPL; + if (!(context = calloc( 1, sizeof( *context ) ))) return E_OUTOFMEMORY; context->options = options; context->buffer = buffer; context->method = method; @@ -407,39 +420,39 @@ static HRESULT WINAPI x_user_XUserGetTokenAndSignatureAsync(IXUserImpl* iface, X context->size = size; context->user = user; context->url = url; - if (count && !(context->headers = calloc(count, sizeof(*headers)))) + if (count && !(context->headers = calloc( count, sizeof( *headers ) ))) { - free(context); + free( context ); return E_OUTOFMEMORY; } for (SIZE_T i = 0; i < count; i++) context->headers[i] = headers[i]; - return impl->lpVtbl->XAsyncBegin(impl, asyncBlock, context, x_user_XUserGetTokenAndSignatureAsync, "XUserGetTokenAndSignatureAsync", XUserGetTokenAndSignatureProvider); + return impl->lpVtbl->XAsyncBegin( impl, asyncBlock, context, x_user_XUserGetTokenAndSignatureAsync, "XUserGetTokenAndSignatureAsync", XUserGetTokenAndSignatureProvider ); } -static HRESULT WINAPI x_user_XUserGetTokenAndSignatureResultSize(IXUserImpl* iface, XAsyncBlock* asyncBlock, SIZE_T* size) +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); + 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) +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); + 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) +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; - 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); + 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 (FAILED(QueryApiImpl(&CLSID_XThreadingImpl, &IID_IXThreadingImpl, (void**)&impl))) return E_NOTIMPL; - if (!(context = calloc(1, sizeof(*context)))) return E_OUTOFMEMORY; + if (FAILED( QueryApiImpl( &CLSID_XThreadingImpl, &IID_IXThreadingImpl, (void**)&impl ) )) return E_NOTIMPL; + if (!(context = calloc( 1, sizeof( *context ) ))) return E_OUTOFMEMORY; context->method_utf16 = method; context->options = options; context->buffer = buffer; @@ -448,83 +461,162 @@ static HRESULT WINAPI x_user_XUserGetTokenAndSignatureUtf16Async(IXUserImpl* ifa context->utf16 = TRUE; context->size = size; context->user = user; - if (count && !(context->headers_utf16 = calloc(count, sizeof(*headers)))) + if (count && !(context->headers_utf16 = calloc( count, sizeof( *headers ) ))) { - free(context); + free( context ); return E_OUTOFMEMORY; } for (SIZE_T i = 0; i < count; i++) context->headers_utf16[i] = headers[i]; - return impl->lpVtbl->XAsyncBegin(impl, asyncBlock, context, x_user_XUserGetTokenAndSignatureUtf16Async, "XUserGetTokenAndSignatureUtf16Async", XUserGetTokenAndSignatureProvider); + return impl->lpVtbl->XAsyncBegin( impl, asyncBlock, context, x_user_XUserGetTokenAndSignatureUtf16Async, "XUserGetTokenAndSignatureUtf16Async", XUserGetTokenAndSignatureProvider ); } -static HRESULT WINAPI x_user_XUserGetTokenAndSignatureUtf16ResultSize(IXUserImpl* iface, XAsyncBlock* asyncBlock, SIZE_T* size) +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); + 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) +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); + 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) +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); + 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) +static HRESULT WINAPI x_user_XUserResolveIssueWithUiResult( IXUserImpl *iface, XAsyncBlock* asyncBlock ) { - FIXME("iface %p, asyncBlock %p stub!\n", iface, 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) +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); + 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) +static HRESULT WINAPI x_user_XUserResolveIssueWithUiUtf16Result( IXUserImpl *iface, XAsyncBlock* asyncBlock ) { - FIXME("iface %p, asyncBlock %p stub!\n", iface, 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) +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); + 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) +static BOOLEAN WINAPI x_user_XUserUnregisterForChangeEvent( IXUserImpl *iface, XTaskQueueRegistrationToken token, BOOLEAN wait ) { - FIXME("iface %p, token %p, wait %d stub!\n", iface, &token, 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) +static HRESULT WINAPI x_user_XUserGetSignOutDeferral( IXUserImpl *iface, XUserSignOutDeferralHandle* deferral ) { - FIXME("iface %p, deferral %p stub!\n", iface, 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) +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, deferral %p stub!\n", iface, deferral); + 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, - /* IXUserImpl methods */ + /* IXUserBase methods */ x_user_XUserDuplicateHandle, x_user_XUserCloseHandle, x_user_XUserCompare, @@ -558,11 +650,108 @@ static const struct IXUserImplVtbl x_user_vtbl = x_user_XUserRegisterForChangeEvent, x_user_XUserUnregisterForChangeEvent, x_user_XUserGetSignOutDeferral, - x_user_XUserCloseSignOutDeferralHandle + 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, }; diff --git a/dlls/xgameruntime/GDKComponent/System/User/XUser.h b/dlls/xgameruntime/GDKComponent/System/User/XUser.h index 8b8b3593a89..e88e2f6d30c 100644 --- a/dlls/xgameruntime/GDKComponent/System/User/XUser.h +++ b/dlls/xgameruntime/GDKComponent/System/User/XUser.h @@ -30,6 +30,7 @@ struct x_user { IXUserImpl IXUserImpl_iface; + IXUserGamertag IXUserGamertag_iface; LONG ref; UINT64 xuid; diff --git a/dlls/xgameruntime/provider.idl b/dlls/xgameruntime/provider.idl index c84f30ebe9c..fe623a61eac 100644 --- a/dlls/xgameruntime/provider.idl +++ b/dlls/xgameruntime/provider.idl @@ -21,37 +21,22 @@ #pragma makedep header import "propidl.idl"; +import "xuser.idl"; cpp_quote("#include ") // --- xgameruntime --- // typedef void* XSystemHandle; -typedef void* XUserChangeEventCallback; -typedef void* XUserHandle; -typedef void* XUserSignOutDeferralHandle; typedef enum XSystemHandleType XSystemHandleType; typedef enum XSystemHandleCallbackReason XSystemHandleCallbackReason; typedef enum XGameRuntimeFeature XGameRuntimeFeature; -typedef enum XUserAddOptions XUserAddOptions; -typedef enum XUserAgeGroup XUserAgeGroup; -typedef enum XUserGamerPictureSize XUserGamerPictureSize; -typedef enum XUserGetTokenAndSignatureOptions XUserGetTokenAndSignatureOptions; -typedef enum XUserPrivilege XUserPrivilege; -typedef enum XUserPrivilegeDenyReason XUserPrivilegeDenyReason; -typedef enum XUserPrivilegeOptions XUserPrivilegeOptions; -typedef enum XUserState XUserState; typedef struct XVersion XVersion; typedef struct XSystemAnalyticsInfo XSystemAnalyticsInfo; typedef struct XAsyncBlock XAsyncBlock; typedef struct XTaskQueueObject* XTaskQueueHandle; typedef struct XTaskQueueRegistrationToken XTaskQueueRegistrationToken; -typedef struct XUserGetTokenAndSignatureData XUserGetTokenAndSignatureData; -typedef struct XUserGetTokenAndSignatureUtf16Data XUserGetTokenAndSignatureUtf16Data; -typedef struct XUserGetTokenAndSignatureHttpHeader XUserGetTokenAndSignatureHttpHeader; -typedef struct XUserGetTokenAndSignatureUtf16HttpHeader XUserGetTokenAndSignatureUtf16HttpHeader; -typedef struct XUserLocalId XUserLocalId; typedef void XAsyncCompletionRoutine(struct XAsyncBlock* asyncBlock); @@ -59,6 +44,13 @@ 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; @@ -116,78 +108,6 @@ enum XSystemHandleCallbackReason Destroyed = 0x01 }; -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 XUserGamerPictureSize -{ - XUserGamerPictureSize_Small = 0, - XUserGamerPictureSize_Medium = 1, - XUserGamerPictureSize_Large = 2, - XUserGamerPictureSize_ExtraLarge = 3 -}; - -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 -}; - struct XVersion { union { @@ -210,39 +130,6 @@ struct XSystemAnalyticsInfo CHAR form[64]; }; -struct XUserGetTokenAndSignatureData -{ - SIZE_T tokenSize; - SIZE_T signatureSize; - LPCSTR token; - LPCSTR signature; -}; - -struct XUserGetTokenAndSignatureUtf16Data -{ - SIZE_T tokenSize; - SIZE_T signatureSize; - LPCWSTR token; - LPCWSTR signature; -}; - -struct XUserGetTokenAndSignatureHttpHeader -{ - LPCSTR name; - LPCSTR value; -}; - -struct XUserGetTokenAndSignatureUtf16HttpHeader -{ - LPCWSTR name; - LPCWSTR value; -}; - -struct XUserLocalId -{ - UINT64 value; -}; - [ object, uuid(7664288b-54e9-45f9-af0b-b4ad047fa194) @@ -293,46 +180,120 @@ interface IXGameRuntimeFeatureImpl : IUnknown [ local, object, - uuid(079415e3-6727-437f-8e9d-8f8f9b2439f7) + uuid(01acd177-91f9-4763-a38e-ccbb55ce32e0) ] -interface IXUserImpl : IUnknown +interface IXUserBase : IUnknown { - HRESULT XUserDuplicateHandle( [in] XUserHandle user, [out] XUserHandle* duplicated); + 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 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 ); + 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 ); + 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) ] @@ -363,4 +324,5 @@ coclass XGameRuntimeFeatureImpl 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.h b/include/xuser.h deleted file mode 100644 index 6691cc9c059..00000000000 --- a/include/xuser.h +++ /dev/null @@ -1,170 +0,0 @@ -/* - * Copyright (C) the Wine project - * - * 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 __WINE_XUSER_H -#define __WINE_XUSER_H - -#include -#include - -typedef enum XUserAddOptions -{ - AddOptionsNone = 0, - AddOptionsAddDefaultUserSilently = 1, - AddOptionsAllowGuests = 2, - AddDefaultUserAllowingUI = 4 -} XUserAddOptions; - -typedef enum XUserAgeGroup -{ - AgeGroupUnknown = 0, - AgeGroupChild = 1, - AgeGroupTeen = 2, - AgeGroupAdult = 3 -} XUserAgeGroup; - -typedef enum XUserChangeEvent -{ - ChangeEventSignedInAgain = 0, - ChangeEventSigningOut = 1, - ChangeEventSignedOut = 2, - ChangeEventGamertag = 3, - ChangeEventGamerPicture = 4, - ChangeEventPrivileges = 5 -} XUserChangeEvent; - -typedef enum XUserDefaultAudioEndpointKind -{ - DefaultAudioEndpointKindCommunicationRender = 0, - DefaultAudioEndpointKindCommunicationCapture = 1 -} XUserDefaultAudioEndpointKind; - -typedef enum XUserGamerPictureSize -{ - GamerPictureSizeSmall = 0, - GamerPictureSizeMedium = 1, - GamerPictureSizeLarge = 2, - GamerPictureSizeExtraLarge = 3 -} XUserGamerPictureSize; - -typedef enum XUserGamertagComponent -{ - GamertagComponentClassic = 0, - GamertagComponentModern = 1, - GamertagComponentModernSuffix = 2, - GamertagComponentUniqueModern = 3, -} XUserGamertagComponent; - -typedef enum XUserGetMsaTokenSilentlyOptions -{ - GetMsaTokenSilentlyOptionsNone = 0 -} XUserGetMsaTokenSilentlyOptions; - -typedef enum XUserGetTokenAndSignatureOptions -{ - GetTokenAndSignatureOptionsNone = 0, - GetTokenAndSignatureOptionsForceRefresh = 1, - GetTokenAndSignatureOptionsAllUsers = 2 -} XUserGetTokenAndSignatureOptions; - -typedef enum XUserPrivilege -{ - PrivilegeCrossPlay = 185, - PrivilegeClubs = 188, - PrivilegeSessions = 189, - PrivilegeBroadcast = 190, - PrivilegeManageProfilePrivacy = 196, - PrivilegeGameDvr = 198, - PrivilegeMultiplayerParties = 203, - PrivilegeCloudManageSession = 207, - PrivilegeCloudJoinSession = 208, - PrivilegeCloudSavedGames = 209, - PrivilegeSocialNetworkSharing = 220, - PrivilegeUserGeneratedContent = 247, - PrivilegeCommunications = 252, - PrivilegeMultiplayer = 254, - PrivilegeAddFriends = 255 -} XUserPrivilege; - -typedef enum XUserPrivilegeDenyReason -{ - PrivilegeDenyReasonNone = 0, - PrivilegeDenyReasonPurchaseRequired = 1, - PrivilegeRestricted = 2, - PrivilegeBanned = 3, - PrivilegeUnknown = -1 -} XUserPrivilegeDenyReason; - -typedef enum XUserPrivilegeOptions -{ - PrivilegeOptionsNone = 0, - PrivilegeOptionsAllUsers = 1 -} XUserPrivilegeOptions; - -typedef enum XUserState -{ - StateSignedIn = 0, - StateSigningOut = 1, - StateSignedOut = 2 -} XUserState; - -typedef struct XUserDeviceAssociationChange -{ - APP_LOCAL_DEVICE_ID deviceId; - XUserLocalId oldUser; - XUserLocalId newUser; -} XUserDeviceAssociationChange; - -typedef struct XUserGetTokenAndSignatureData -{ - SIZE_T tokenSize; - SIZE_T signatureSize; - LPCSTR token; - LPCSTR signature; -} XUserGetTokenAndSignatureData; - -typedef struct XUserGetTokenAndSignatureUtf16Data -{ - SIZE_T tokenSize; - SIZE_T signatureCount; - LPCWSTR token; - LPCWSTR signature; -} XUserGetTokenAndSignatureUtf16Data; - -typedef struct XUserGetTokenAndSignatureHttpHeader -{ - LPCSTR name; - LPCSTR value; -} XUserGetTokenAndSignatureHttpHeader; - -typedef struct XUserGetTokenAndSignatureUtf16HttpHeader -{ - LPCWSTR name; - LPCWSTR value; -} XUserGetTokenAndSignatureUtf16HttpHeader; - -typedef struct XUserLocalId -{ - UINT64 value; -} XUserLocalId; - -typedef void CALLBACK XUserChangeEventCallback(_In_opt_ PVOID context, _In_ XUserLocalId userLocalId, _In_ XUserChangeEvent event); -typedef void CALLBACK XUserDefaultAudioEndpointUtf16ChangedCallback(_In_opt_ PVOID context, _In_ XUserLocalId user, _In_ XUserDefaultAudioEndpointKind defaultAudioEndpointKind, _In_opt_z_ LPCWSTR endpointIdUtf16); -typedef void CALLBACK XUserDeviceAssociationChangedCallback(_In_opt_ PVOID context, _In_ const XUserDeviceAssociationChange *change); - -#endif /* __WINE_XUSER_H */ \ No newline at end of file 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 From ee8c310c427df602e59dfc61a60d94dd0d605ace Mon Sep 17 00:00:00 2001 From: Olivia Ryan Date: Fri, 13 Feb 2026 15:37:35 +0000 Subject: [PATCH 12/13] xgameruntime: Check for nullptrs, XUserCompare & XUserGetAgeGroup --- .../GDKComponent/System/User/Token.c | 327 +++++++++--------- .../GDKComponent/System/User/Token.h | 8 +- .../GDKComponent/System/User/XUser.c | 119 ++++--- .../GDKComponent/System/User/XUser.h | 1 + 4 files changed, 243 insertions(+), 212 deletions(-) diff --git a/dlls/xgameruntime/GDKComponent/System/User/Token.c b/dlls/xgameruntime/GDKComponent/System/User/Token.c index 4bb57829088..c0e5e6e4edd 100644 --- a/dlls/xgameruntime/GDKComponent/System/User/Token.c +++ b/dlls/xgameruntime/GDKComponent/System/User/Token.c @@ -18,51 +18,51 @@ #include "Token.h" -#define GetJsonValue(obj_type, ret_type) \ -static inline HRESULT GetJson##obj_type##Value(IJsonObject *object, LPCWSTR key, ret_type value) \ +#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))) \ + if (FAILED( hr = WindowsCreateStringReference( key, wcslen( key ), &key_hdr, &key_hstr ) )) \ return hr; \ \ - if (FAILED(hr = IJsonObject_GetNamed##obj_type(object, key_hstr, value))) \ + 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*); +GetJsonValue( Array, IJsonArray** ); +GetJsonValue( Number, DOUBLE* ); +GetJsonValue( Object, IJsonObject** ); +GetJsonValue( String, HSTRING* ); -HRESULT HSTRINGToMultiByte(HSTRING hstr, LPSTR *str, UINT32 *str_len) +HRESULT HSTRINGToMultiByte( HSTRING hstr, LPSTR *str, UINT32 *str_len ) { UINT32 wstr_len; - LPCWSTR wstr = WindowsGetStringRawBuffer(hstr, &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_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 = calloc( 1, *str_len ))) return E_OUTOFMEMORY; - if (!(*str_len = WideCharToMultiByte(CP_UTF8, 0, wstr, wstr_len, *str, *str_len, NULL, NULL))) + if (!(*str_len = WideCharToMultiByte( CP_UTF8, 0, wstr, wstr_len, *str, *str_len, NULL, NULL ))) { - free(*str); + free( *str ); *str = NULL; - return HRESULT_FROM_WIN32(GetLastError()); + 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) +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); + DWORD size = sizeof( DWORD ); HINTERNET session = NULL; HINTERNET request = NULL; HRESULT hr = S_OK; @@ -74,16 +74,16 @@ static HRESULT HttpRequest(LPCWSTR method, LPCWSTR domain, LPCWSTR object, LPSTR WINHTTP_NO_PROXY_NAME, WINHTTP_NO_PROXY_BYPASS, 0 - ))) return HRESULT_FROM_WIN32(GetLastError()); + ))) return HRESULT_FROM_WIN32( GetLastError() ); if (!(connection = WinHttpConnect( session, domain, INTERNET_DEFAULT_HTTPS_PORT, 0 - ))) hr = HRESULT_FROM_WIN32(GetLastError()); + ))) hr = HRESULT_FROM_WIN32( GetLastError() ); - if (SUCCEEDED(hr) && !(request = WinHttpOpenRequest( + if (SUCCEEDED( hr ) && !(request = WinHttpOpenRequest( connection, method, object, @@ -91,55 +91,55 @@ static HRESULT HttpRequest(LPCWSTR method, LPCWSTR domain, LPCWSTR object, LPSTR WINHTTP_NO_REFERER, accept, WINHTTP_FLAG_SECURE - ))) hr = HRESULT_FROM_WIN32(GetLastError()); + ))) hr = HRESULT_FROM_WIN32( GetLastError() ); - if (SUCCEEDED(hr) && !WinHttpSendRequest( + if (SUCCEEDED( hr ) && !WinHttpSendRequest( request, headers, -1, data, - strlen(data), - strlen(data), + strlen( data ), + strlen( data ), 0 - )) hr = HRESULT_FROM_WIN32(GetLastError()); + )) hr = HRESULT_FROM_WIN32( GetLastError() ); - if (SUCCEEDED(hr) && !WinHttpReceiveResponse(request, NULL)) - hr = HRESULT_FROM_WIN32(GetLastError()); + if (SUCCEEDED( hr ) && !WinHttpReceiveResponse( request, NULL )) + hr = HRESULT_FROM_WIN32( GetLastError() ); - if (SUCCEEDED(hr) && !WinHttpQueryHeaders( + 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()); + )) hr = HRESULT_FROM_WIN32( GetLastError() ); - if (SUCCEEDED(hr) && status / 100 != 2) hr = E_FAIL; + if (SUCCEEDED( hr ) && status / 100 != 2) hr = E_FAIL; /* buffer response data */ *buffer = NULL; *bufferSize = 0; - if (SUCCEEDED(hr)) + if (SUCCEEDED( hr )) { do { - if (!(WinHttpQueryDataAvailable(request, &size))) + if (!(WinHttpQueryDataAvailable( request, &size ))) { - hr = HRESULT_FROM_WIN32(GetLastError()); + hr = HRESULT_FROM_WIN32( GetLastError() ); break; } if (!size) break; - if (!(*buffer = realloc(*buffer, *bufferSize + size))) + if (!(*buffer = realloc( *buffer, *bufferSize + size ))) { hr = E_OUTOFMEMORY; break; } - if (!(WinHttpReadData(request, *buffer + *bufferSize, size, &size))) + if (!(WinHttpReadData( request, *buffer + *bufferSize, size, &size ))) { - hr = HRESULT_FROM_WIN32(GetLastError()); + hr = HRESULT_FROM_WIN32( GetLastError() ); break; } @@ -148,15 +148,15 @@ static HRESULT HttpRequest(LPCWSTR method, LPCWSTR domain, LPCWSTR object, LPSTR while (size); } - if (connection) WinHttpCloseHandle(connection); - if (request) WinHttpCloseHandle(request); - if (session) WinHttpCloseHandle(session); - if (FAILED(hr) && *buffer) free(*buffer); + 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) +static HRESULT ParseJsonObject( LPCSTR str, UINT32 str_size, IJsonObject **object ) { LPCWSTR class_str = RuntimeClass_Windows_Data_Json_JsonValue; IJsonValueStatics *statics; @@ -169,50 +169,49 @@ static HRESULT ParseJsonObject(LPCSTR str, UINT32 str_size, IJsonObject **object LPWSTR wstr; HRESULT hr; + if (!(wstr_size = MultiByteToWideChar( CP_UTF8, 0, str, str_size, NULL, 0 ))) + return HRESULT_FROM_WIN32( GetLastError() ); - if (!(wstr_size = MultiByteToWideChar(CP_UTF8, 0, str, str_size, NULL, 0))) - return HRESULT_FROM_WIN32(GetLastError()); - - if (!(wstr = calloc(wstr_size, sizeof(WCHAR)))) + if (!(wstr = calloc( wstr_size, sizeof( WCHAR ) ))) return E_OUTOFMEMORY; - if (!(wstr_size = MultiByteToWideChar(CP_UTF8, 0, str, str_size, wstr, wstr_size))) + if (!(wstr_size = MultiByteToWideChar( CP_UTF8, 0, str, str_size, wstr, wstr_size ))) { - free(wstr); - return HRESULT_FROM_WIN32(GetLastError()); + free( wstr ); + return HRESULT_FROM_WIN32( GetLastError() ); } - if (FAILED(hr = WindowsCreateStringReference(wstr, wstr_size, &content_hdr, &content))) + if (FAILED( hr = WindowsCreateStringReference( wstr, wstr_size, &content_hdr, &content ) )) { - free(wstr); + free( wstr ); return hr; } - if (FAILED(hr = WindowsCreateStringReference(class_str, wcslen(class_str), &class_hdr, &class))) + if (FAILED( hr = WindowsCreateStringReference( class_str, wcslen( class_str ), &class_hdr, &class ) )) { - free(wstr); + free( wstr ); return hr; } - if (FAILED(hr = RoGetActivationFactory(class, &IID_IJsonValueStatics, (void**)&statics))) + if (FAILED( hr = RoGetActivationFactory( class, &IID_IJsonValueStatics, (void**)&statics ) )) { - free(wstr); + free( wstr ); return hr; } - hr = IJsonValueStatics_Parse(statics, content, &value); - IJsonValueStatics_Release(statics); - free(wstr); - if (FAILED(hr)) 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); + 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) +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}; @@ -224,13 +223,13 @@ HRESULT RefreshOAuth(LPCSTR client_id, LPCSTR refresh_token, time_t *new_expiry, HRESULT hr; LPSTR data; - if (!(data = calloc(strlen(template) + strlen(client_id) + strlen("&refresh_token=") + strlen(refresh_token) + 1, sizeof(CHAR)))) + 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); + strcpy( data, template ); + strcat( data, client_id ); + strcat( data, "&refresh_token=" ); + strcat( data, refresh_token ); hr = HttpRequest( L"POST", @@ -243,35 +242,35 @@ HRESULT RefreshOAuth(LPCSTR client_id, LPCSTR refresh_token, time_t *new_expiry, &size ); - free(data); - if (FAILED(hr)) return hr; - hr = ParseJsonObject(buffer, size, &object); - free(buffer); - if (FAILED(hr)) return hr; + 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))) + if (FAILED( hr = GetJsonStringValue( object, L"access_token", new_oauth_token ) )) { - IJsonObject_Release(object); + IJsonObject_Release( object ); return hr; } - if (FAILED(hr = GetJsonStringValue(object, L"refresh_token", new_refresh_token))) + if (FAILED( hr = GetJsonStringValue( object, L"refresh_token", new_refresh_token ) )) { - IJsonObject_Release(object); + IJsonObject_Release( object ); return hr; } - if (FAILED(hr = GetJsonNumberValue(object, L"expires_in", &delta))) - IJsonObject_Release(object); - if (FAILED(hr)) 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; + 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) +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}; @@ -288,19 +287,19 @@ HRESULT RequestUserToken(HSTRING oauth_token, HSTRING *token, XUserLocalId *loca LPSTR data; HRESULT hr; - if (FAILED(hr = HSTRINGToMultiByte(oauth_token, &token_str, &token_str_len))) + 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)))) + if (!(data = calloc( strlen( template ) + token_str_len + strlen( "\"}}" ) + 1, sizeof( CHAR ) ))) { - free(token_str); + free( token_str ); return E_OUTOFMEMORY; } - strcpy(data, template); - strncat(data, token_str, token_str_len); - free(token_str); - strcat(data, "\"}}"); + strcpy( data, template ); + strncat( data, token_str, token_str_len ); + free( token_str ); + strcat( data, "\"}}" ); hr = HttpRequest( L"POST", @@ -313,63 +312,63 @@ HRESULT RequestUserToken(HSTRING oauth_token, HSTRING *token, XUserLocalId *loca &size ); - free(data); - if (FAILED(hr)) return hr; - hr = ParseJsonObject(buffer, size, &object); - free(buffer); - if (FAILED(hr)) return hr; + 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))) + if (FAILED( hr = GetJsonStringValue( object, L"Token", token ) )) { - IJsonObject_Release(object); + IJsonObject_Release( object ); return hr; } - hr = GetJsonObjectValue(object, L"DisplayClaims", &display_claims); - IJsonObject_Release(object); - if (FAILED(hr)) + hr = GetJsonObjectValue( object, L"DisplayClaims", &display_claims ); + IJsonObject_Release( object ); + if (FAILED( hr )) { - WindowsDeleteString(*token); + WindowsDeleteString( *token ); return hr; } - hr = GetJsonArrayValue(display_claims, L"xui", &xui); - IJsonObject_Release(display_claims); - if (FAILED(hr)) + hr = GetJsonArrayValue( display_claims, L"xui", &xui ); + IJsonObject_Release( display_claims ); + if (FAILED( hr )) { - WindowsDeleteString(*token); + WindowsDeleteString( *token ); return hr; } - hr = IJsonArray_GetObjectAt(xui, 0, &object); - IJsonArray_Release(xui); - if (FAILED(hr)) + hr = IJsonArray_GetObjectAt( xui, 0, &object ); + IJsonArray_Release( xui ); + if (FAILED( hr )) { - WindowsDeleteString(*token); + WindowsDeleteString( *token ); return hr; } - hr = GetJsonStringValue(object, L"uhs", &uhs); - IJsonObject_Release(object); - if (FAILED(hr)) + hr = GetJsonStringValue( object, L"uhs", &uhs ); + IJsonObject_Release( object ); + if (FAILED( hr )) { - WindowsDeleteString(*token); + WindowsDeleteString( *token ); return hr; } - hr = HSTRINGToMultiByte(uhs, &uhs_str, &uhs_str_len); - WindowsDeleteString(uhs); - if (FAILED(hr)) + hr = HSTRINGToMultiByte( uhs, &uhs_str, &uhs_str_len ); + WindowsDeleteString( uhs ); + if (FAILED( hr )) { - WindowsDeleteString(*token); + WindowsDeleteString( *token ); return hr; } - local_id->value = strtoull(uhs_str, NULL, 10); - free(uhs_str); + local_id->value = strtoull( uhs_str, NULL, 10 ); + free( uhs_str ); if (errno == ERANGE) { - WindowsDeleteString(*token); + WindowsDeleteString( *token ); errno = 0; return E_FAIL; } @@ -377,7 +376,7 @@ HRESULT RequestUserToken(HSTRING oauth_token, HSTRING *token, XUserLocalId *loca return hr; } -HRESULT RequestXstsToken(HSTRING user_token, HSTRING *token, UINT64 *xuid) +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}; @@ -385,28 +384,31 @@ HRESULT RequestXstsToken(HSTRING user_token, HSTRING *token, UINT64 *xuid) 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))) + 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)))) + if (!(data = calloc( strlen( template ) + token_str_len + strlen( "\"]}}" ) + 1, sizeof( CHAR ) ))) { - free(token_str); + free( token_str ); return E_OUTOFMEMORY; } - strcpy(data, template); + strcpy( data, template ); strncat(data, token_str, token_str_len); - free(token_str); - strcat(data, "\"]}}"); + free( token_str ); + strcat( data, "\"]}}" ); hr = HttpRequest( L"POST", @@ -419,63 +421,76 @@ HRESULT RequestXstsToken(HSTRING user_token, HSTRING *token, UINT64 *xuid) &size ); - free(data); - if (FAILED(hr)) return hr; - hr = ParseJsonObject(buffer, size, &object); - free(buffer); - if (FAILED(hr)) return hr; + 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))) + if (FAILED( hr = GetJsonStringValue( object, L"Token", token ) )) { - IJsonObject_Release(object); + IJsonObject_Release( object ); return hr; } - hr = GetJsonObjectValue(object, L"DisplayClaims", &display_claims); - IJsonObject_Release(object); - if (FAILED(hr)) + hr = GetJsonObjectValue( object, L"DisplayClaims", &display_claims ); + IJsonObject_Release( object ); + if (FAILED( hr )) { - WindowsDeleteString(*token); + WindowsDeleteString( *token ); return hr; } - hr = GetJsonArrayValue(display_claims, L"xui", &xui); - IJsonObject_Release(display_claims); - if (FAILED(hr)) + hr = GetJsonArrayValue( display_claims, L"xui", &xui ); + IJsonObject_Release( display_claims ); + if (FAILED( hr )) { - WindowsDeleteString(*token); + WindowsDeleteString( *token ); return hr; } - hr = IJsonArray_GetObjectAt(xui, 0, &object); - IJsonArray_Release(xui); - if (FAILED(hr)) + hr = IJsonArray_GetObjectAt( xui, 0, &object ); + IJsonArray_Release( xui ); + if (FAILED( hr )) { - WindowsDeleteString(*token); + WindowsDeleteString( *token ); return hr; } - hr = GetJsonStringValue(object, L"xid", &xid); - IJsonObject_Release(object); - if (FAILED(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); + WindowsDeleteString( *token ); return hr; } - hr = HSTRINGToMultiByte(xid, &xid_str, &xid_str_len); - WindowsDeleteString(xid); - if (FAILED(hr)) + hr = HSTRINGToMultiByte( xid, &xid_str, &xid_str_len ); + WindowsDeleteString( xid ); + if (FAILED( hr )) { - WindowsDeleteString(*token); + WindowsDeleteString( *token ); return hr; } - *xuid = strtoull(xid_str, NULL, 10); - free(xid_str); + *xuid = strtoull( xid_str, NULL, 10 ); + free( xid_str ); if (errno == ERANGE) { - WindowsDeleteString(*token); + WindowsDeleteString( *token ); errno = 0; return E_FAIL; } diff --git a/dlls/xgameruntime/GDKComponent/System/User/Token.h b/dlls/xgameruntime/GDKComponent/System/User/Token.h index cfdebee27fc..dc6927e0cd6 100644 --- a/dlls/xgameruntime/GDKComponent/System/User/Token.h +++ b/dlls/xgameruntime/GDKComponent/System/User/Token.h @@ -32,9 +32,9 @@ struct token 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); -HRESULT HSTRINGToMultiByte(HSTRING hstr, LPSTR *str, UINT32 *str_len); +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 index faac649d122..a7ef29570c1 100644 --- a/dlls/xgameruntime/GDKComponent/System/User/XUser.c +++ b/dlls/xgameruntime/GDKComponent/System/User/XUser.c @@ -37,6 +37,8 @@ static HRESULT LoadDefaultUser( XUserHandle *user, LPCSTR client_id ) HRESULT hr; DWORD size; + if (!user || !client_id) return E_POINTER; + if (ERROR_SUCCESS != (status = RegGetValueA( HKEY_LOCAL_MACHINE, "Software\\Wine\\WineGDK", @@ -89,7 +91,7 @@ static HRESULT LoadDefaultUser( XUserHandle *user, LPCSTR client_id ) return hr; } - if (FAILED( hr = RequestXstsToken( impl->user_token, &impl->xsts_token, &impl->xuid ) )) + 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 ); @@ -163,9 +165,10 @@ static ULONG WINAPI x_user_Release( IXUserImpl *iface ) return ref; } -static HRESULT WINAPI x_user_XUserDuplicateHandle( IXUserImpl *iface, XUserHandle user, XUserHandle* duplicated ) +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; @@ -174,16 +177,17 @@ static HRESULT WINAPI x_user_XUserDuplicateHandle( IXUserImpl *iface, XUserHandl static void WINAPI x_user_XUserCloseHandle( IXUserImpl *iface, XUserHandle user ) { TRACE( "iface %p, user %p\n", iface, user ); - IXUserImpl_Release( &((struct x_user*)user)->IXUserImpl_iface ); + if (user) IXUserImpl_Release( &((struct x_user*)user)->IXUserImpl_iface ); } static INT32 WINAPI x_user_XUserCompare( IXUserImpl *iface, XUserHandle user1, XUserHandle user2 ) { - FIXME( "iface %p, user1 %p, user2 %p stub!\n", iface, user1, user2 ); - return E_NOTIMPL; + 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 ) +static HRESULT WINAPI x_user_XUserGetMaxUsers( IXUserImpl *iface, UINT32 *maxUsers ) { FIXME( "iface %p, maxUsers %p stub!\n", iface, maxUsers ); return E_NOTIMPL; @@ -196,14 +200,15 @@ struct XUserAddContext LPCSTR client_id; }; -static HRESULT XUserAddProvider( XAsyncOp operation, const XAsyncProviderData* providerData ) +static HRESULT XUserAddProvider( XAsyncOp operation, const XAsyncProviderData *providerData ) { - struct XUserAddContext* context; - IXThreadingImpl* impl; + 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; @@ -237,13 +242,14 @@ static HRESULT XUserAddProvider( XAsyncOp operation, const XAsyncProviderData* p return S_OK; } -static HRESULT WINAPI x_user_XUserAddAsync( IXUserImpl *iface, XUserAddOptions options, XAsyncBlock* asyncBlock ) +static HRESULT WINAPI x_user_XUserAddAsync( IXUserImpl *iface, XUserAddOptions options, XAsyncBlock *asyncBlock ) { - struct XUserAddContext* context; - IXThreadingImpl* impl; + struct XUserAddContext *context; + IXThreadingImpl *impl; TRACE( "iface %p, options %d, asyncBlock %p\n", iface, options, asyncBlock ); + if (!asyncBlock) return E_POINTER; if (FAILED( QueryApiImpl( &CLSID_XThreadingImpl, &IID_IXThreadingImpl, (void**)&impl ) )) return E_NOTIMPL; if (!(context = calloc( 1, sizeof( struct XUserAddContext ) ))) return E_OUTOFMEMORY; context->options = options; @@ -251,51 +257,54 @@ static HRESULT WINAPI x_user_XUserAddAsync( IXUserImpl *iface, XUserAddOptions o return impl->lpVtbl->XAsyncBegin( impl, asyncBlock, context, x_user_XUserAddAsync, "XUserAddAsync", XUserAddProvider ); } -static HRESULT WINAPI x_user_XUserAddResult( IXUserImpl *iface, XAsyncBlock* asyncBlock, XUserHandle* user ) +static HRESULT WINAPI x_user_XUserAddResult( IXUserImpl *iface, XAsyncBlock *asyncBlock, XUserHandle *user ) { - IXThreadingImpl* impl; + IXThreadingImpl *impl; - TRACE( "iface %p, asyncBlock %p, user %p\n", iface, asyncBlock, *user ); + 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 ) +static HRESULT WINAPI x_user_XUserGetLocalId( IXUserImpl *iface, XUserHandle user, XUserLocalId *localId ) { TRACE( "iface %p, user %p, localId %p\n", iface, user, localId ); - if (!localId) return E_POINTER; + 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 ) +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 ) +static HRESULT WINAPI x_user_XUserGetId( IXUserImpl *iface, XUserHandle user, UINT64 *userId ) { TRACE( "iface %p, user %p, userId %p\n", iface, user, userId ); - if (!userId) return E_POINTER; + 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 ) +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 ) +static HRESULT WINAPI x_user_XUserGetIsGuest( IXUserImpl *iface, XUserHandle user, BOOLEAN *isGuest ) { FIXME( "iface %p, user %p, isGuest %p stub!\n", iface, user, isGuest ); - return E_NOTIMPL; + if (!user || !isGuest) return E_POINTER; + *isGuest = FALSE; + return S_OK; } -static HRESULT WINAPI x_user_XUserGetState( IXUserImpl *iface, XUserHandle user, XUserState* state ) +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; @@ -307,43 +316,46 @@ static HRESULT WINAPI __PADDING__( IXUserImpl *iface ) return E_NOTIMPL; } -static HRESULT WINAPI x_user_XUserGetGamerPictureAsync( IXUserImpl *iface, XUserHandle user, XUserGamerPictureSize size, XAsyncBlock* asyncBlock ) +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 ) +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 ) +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 ) +static HRESULT WINAPI x_user_XUserGetAgeGroup( IXUserImpl *iface, XUserHandle user, XUserAgeGroup *group ) { - FIXME( "user %p, group %p stub!\n", user, group ); - return E_NOTIMPL; + 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 ) +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 ) +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 ) +static HRESULT WINAPI x_user_XUserResolvePrivilegeWithUiResult( IXUserImpl *iface, XAsyncBlock *asyncBlock ) { FIXME( "iface %p, asyncBlock %p stub!\n", iface, asyncBlock ); return E_NOTIMPL; @@ -365,13 +377,14 @@ struct XUserGetTokenAndSignatureContext const void *buffer; }; -static HRESULT XUserGetTokenAndSignatureProvider( XAsyncOp operation, const XAsyncProviderData* providerData ) +static HRESULT XUserGetTokenAndSignatureProvider( XAsyncOp operation, const XAsyncProviderData *providerData ) { - struct XUserGetTokenAndSignatureContext* context; - IXThreadingImpl* impl; + 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; @@ -403,13 +416,14 @@ static HRESULT XUserGetTokenAndSignatureProvider( XAsyncOp operation, const XAsy 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 ) +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; + struct XUserGetTokenAndSignatureContext *context; + IXThreadingImpl *impl; 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( QueryApiImpl( &CLSID_XThreadingImpl, &IID_IXThreadingImpl, (void**)&impl ) )) return E_NOTIMPL; if (!(context = calloc( 1, sizeof( *context ) ))) return E_OUTOFMEMORY; context->options = options; @@ -432,25 +446,26 @@ static HRESULT WINAPI x_user_XUserGetTokenAndSignatureAsync( IXUserImpl *iface, return impl->lpVtbl->XAsyncBegin( impl, asyncBlock, context, x_user_XUserGetTokenAndSignatureAsync, "XUserGetTokenAndSignatureAsync", XUserGetTokenAndSignatureProvider ); } -static HRESULT WINAPI x_user_XUserGetTokenAndSignatureResultSize( IXUserImpl *iface, XAsyncBlock* asyncBlock, SIZE_T* size ) +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 ) +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 ) +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; + struct XUserGetTokenAndSignatureContext *context; + IXThreadingImpl *impl; 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( QueryApiImpl( &CLSID_XThreadingImpl, &IID_IXThreadingImpl, (void**)&impl ) )) return E_NOTIMPL; if (!(context = calloc( 1, sizeof( *context ) ))) return E_OUTOFMEMORY; context->method_utf16 = method; @@ -473,43 +488,43 @@ static HRESULT WINAPI x_user_XUserGetTokenAndSignatureUtf16Async( IXUserImpl *if return impl->lpVtbl->XAsyncBegin( impl, asyncBlock, context, x_user_XUserGetTokenAndSignatureUtf16Async, "XUserGetTokenAndSignatureUtf16Async", XUserGetTokenAndSignatureProvider ); } -static HRESULT WINAPI x_user_XUserGetTokenAndSignatureUtf16ResultSize( IXUserImpl *iface, XAsyncBlock* asyncBlock, SIZE_T* size ) +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 ) +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 ) +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 ) +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 ) +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 ) +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 ) +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; @@ -521,7 +536,7 @@ static BOOLEAN WINAPI x_user_XUserUnregisterForChangeEvent( IXUserImpl *iface, X return FALSE; } -static HRESULT WINAPI x_user_XUserGetSignOutDeferral( IXUserImpl *iface, XUserSignOutDeferralHandle* deferral ) +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; diff --git a/dlls/xgameruntime/GDKComponent/System/User/XUser.h b/dlls/xgameruntime/GDKComponent/System/User/XUser.h index e88e2f6d30c..badfc37f9c4 100644 --- a/dlls/xgameruntime/GDKComponent/System/User/XUser.h +++ b/dlls/xgameruntime/GDKComponent/System/User/XUser.h @@ -35,6 +35,7 @@ struct x_user UINT64 xuid; XUserLocalId local_id; + XUserAgeGroup age_group; time_t oauth_token_expiry; HSTRING refresh_token; From 65c4dc0d4d0a3da19939cf683529894b67a5b165 Mon Sep 17 00:00:00 2001 From: Olivia Ryan Date: Tue, 17 Feb 2026 14:35:16 +0000 Subject: [PATCH 13/13] xgameruntime: Release IXThreading references --- .../GDKComponent/System/User/XUser.c | 45 ++++++++++++++----- 1 file changed, 35 insertions(+), 10 deletions(-) diff --git a/dlls/xgameruntime/GDKComponent/System/User/XUser.c b/dlls/xgameruntime/GDKComponent/System/User/XUser.c index a7ef29570c1..47082a8dc5f 100644 --- a/dlls/xgameruntime/GDKComponent/System/User/XUser.c +++ b/dlls/xgameruntime/GDKComponent/System/User/XUser.c @@ -246,15 +246,22 @@ static HRESULT WINAPI x_user_XUserAddAsync( IXUserImpl *iface, XUserAddOptions o { 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( QueryApiImpl( &CLSID_XThreadingImpl, &IID_IXThreadingImpl, (void**)&impl ) )) return E_NOTIMPL; - if (!(context = calloc( 1, sizeof( struct XUserAddContext ) ))) return E_OUTOFMEMORY; - context->options = options; + 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; + } - return impl->lpVtbl->XAsyncBegin( impl, asyncBlock, context, x_user_XUserAddAsync, "XUserAddAsync", XUserAddProvider ); + 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 ) @@ -420,12 +427,18 @@ static HRESULT WINAPI x_user_XUserGetTokenAndSignatureAsync( IXUserImpl *iface, { 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( QueryApiImpl( &CLSID_XThreadingImpl, &IID_IXThreadingImpl, (void**)&impl ) )) return E_NOTIMPL; - if (!(context = calloc( 1, sizeof( *context ) ))) return E_OUTOFMEMORY; + 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; @@ -437,13 +450,16 @@ static HRESULT WINAPI x_user_XUserGetTokenAndSignatureAsync( IXUserImpl *iface, 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]; - return impl->lpVtbl->XAsyncBegin( impl, asyncBlock, context, x_user_XUserGetTokenAndSignatureAsync, "XUserGetTokenAndSignatureAsync", XUserGetTokenAndSignatureProvider ); + 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 ) @@ -462,12 +478,18 @@ static HRESULT WINAPI x_user_XUserGetTokenAndSignatureUtf16Async( IXUserImpl *if { 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( QueryApiImpl( &CLSID_XThreadingImpl, &IID_IXThreadingImpl, (void**)&impl ) )) return E_NOTIMPL; - if (!(context = calloc( 1, sizeof( *context ) ))) return E_OUTOFMEMORY; + 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; @@ -479,13 +501,16 @@ static HRESULT WINAPI x_user_XUserGetTokenAndSignatureUtf16Async( IXUserImpl *if 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]; - return impl->lpVtbl->XAsyncBegin( impl, asyncBlock, context, x_user_XUserGetTokenAndSignatureUtf16Async, "XUserGetTokenAndSignatureUtf16Async", XUserGetTokenAndSignatureProvider ); + 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 )