[winpr,pubsub] check return of PubSub_Subscribe

This commit is contained in:
Armin Novak
2026-02-27 11:56:23 +01:00
parent 7b47aac9e6
commit 0445ed6734
11 changed files with 70 additions and 44 deletions

View File

@@ -462,8 +462,10 @@ sdlDispContext::sdlDispContext(SdlContext* sdl) : _sdl(sdl)
WINPR_ASSERTING_INT_CAST(int, freerdp_settings_get_uint32(settings, FreeRDP_DesktopWidth));
_lastSentHeight = _targetHeight =
WINPR_ASSERTING_INT_CAST(int, freerdp_settings_get_uint32(settings, FreeRDP_DesktopHeight));
PubSub_SubscribeActivated(pubSub, sdlDispContext::OnActivated);
PubSub_SubscribeGraphicsReset(pubSub, sdlDispContext::OnGraphicsReset);
if (PubSub_SubscribeActivated(pubSub, sdlDispContext::OnActivated) < 0)
throw std::exception();
if (PubSub_SubscribeGraphicsReset(pubSub, sdlDispContext::OnGraphicsReset) < 0)
throw std::exception();
addTimer();
}

View File

@@ -605,9 +605,12 @@ static BOOL sdl_pre_connect(freerdp* instance)
* callbacks or deactivate certain features. */
/* Register the channel listeners.
* They are required to set up / tear down channels if they are loaded. */
PubSub_SubscribeChannelConnected(instance->context->pubSub, sdl_OnChannelConnectedEventHandler);
PubSub_SubscribeChannelDisconnected(instance->context->pubSub,
sdl_OnChannelDisconnectedEventHandler);
if (PubSub_SubscribeChannelConnected(instance->context->pubSub,
sdl_OnChannelConnectedEventHandler) < 0)
return FALSE;
if (PubSub_SubscribeChannelDisconnected(instance->context->pubSub,
sdl_OnChannelDisconnectedEventHandler) < 0)
return FALSE;
if (!freerdp_settings_get_bool(settings, FreeRDP_AuthenticationOnly))
{

View File

@@ -155,9 +155,12 @@ BOOL SdlContext::preConnect(freerdp* instance)
* callbacks or deactivate certain features. */
/* Register the channel listeners.
* They are required to set up / tear down channels if they are loaded. */
PubSub_SubscribeChannelConnected(instance->context->pubSub, sdl_OnChannelConnectedEventHandler);
PubSub_SubscribeChannelDisconnected(instance->context->pubSub,
sdl_OnChannelDisconnectedEventHandler);
if (PubSub_SubscribeChannelConnected(instance->context->pubSub,
sdl_OnChannelConnectedEventHandler) < 0)
return FALSE;
if (PubSub_SubscribeChannelDisconnected(instance->context->pubSub,
sdl_OnChannelDisconnectedEventHandler) < 0)
return FALSE;
if (!freerdp_settings_get_bool(settings, FreeRDP_AuthenticationOnly))
{

View File

@@ -470,8 +470,10 @@ sdlDispContext::sdlDispContext(SdlContext* sdl) : _sdl(sdl)
auto pubSub = _sdl->context()->pubSub;
PubSub_SubscribeActivated(pubSub, sdlDispContext::OnActivated);
PubSub_SubscribeGraphicsReset(pubSub, sdlDispContext::OnGraphicsReset);
if (PubSub_SubscribeActivated(pubSub, sdlDispContext::OnActivated) < 0)
throw std::exception();
if (PubSub_SubscribeGraphicsReset(pubSub, sdlDispContext::OnGraphicsReset) < 0)
throw std::exception();
std::ignore = addTimer();
}

View File

@@ -167,9 +167,12 @@ static BOOL tf_pre_connect(freerdp* instance)
* callbacks or deactivate certain features. */
/* Register the channel listeners.
* They are required to set up / tear down channels if they are loaded. */
PubSub_SubscribeChannelConnected(instance->context->pubSub, tf_OnChannelConnectedEventHandler);
PubSub_SubscribeChannelDisconnected(instance->context->pubSub,
tf_OnChannelDisconnectedEventHandler);
if (PubSub_SubscribeChannelConnected(instance->context->pubSub,
tf_OnChannelConnectedEventHandler) < 0)
return FALSE;
if (PubSub_SubscribeChannelDisconnected(instance->context->pubSub,
tf_OnChannelDisconnectedEventHandler) < 0)
return FALSE;
/* TODO: Any code your client requires */
return TRUE;

View File

@@ -271,16 +271,18 @@ static void wlf_disp_OnGraphicsReset(void* context, const GraphicsResetEventArgs
wlfDispContext* wlf_disp_new(wlfContext* wlc)
{
wlfDispContext* ret = nullptr;
wPubSub* pubSub = nullptr;
rdpSettings* settings = nullptr;
if (!wlc || !wlc->common.context.settings || !wlc->common.context.pubSub)
return nullptr;
settings = wlc->common.context.settings;
pubSub = wlc->common.context.pubSub;
ret = calloc(1, sizeof(wlfDispContext));
rdpSettings* settings = wlc->common.context.settings;
wPubSub* pubSub = wlc->common.context.pubSub;
if (PubSub_SubscribeActivated(pubSub, wlf_disp_OnActivated) < 0)
return nullptr;
if (PubSub_SubscribeGraphicsReset(pubSub, wlf_disp_OnGraphicsReset) < 0)
return nullptr;
wlfDispContext* ret = calloc(1, sizeof(wlfDispContext));
if (!ret)
return nullptr;
@@ -290,8 +292,6 @@ wlfDispContext* wlf_disp_new(wlfContext* wlc)
WINPR_ASSERTING_INT_CAST(int, freerdp_settings_get_uint32(settings, FreeRDP_DesktopWidth));
ret->lastSentHeight = ret->targetHeight =
WINPR_ASSERTING_INT_CAST(int, freerdp_settings_get_uint32(settings, FreeRDP_DesktopHeight));
PubSub_SubscribeActivated(pubSub, wlf_disp_OnActivated);
PubSub_SubscribeGraphicsReset(pubSub, wlf_disp_OnGraphicsReset);
return ret;
}

View File

@@ -197,9 +197,12 @@ static BOOL wl_pre_connect(freerdp* instance)
return FALSE;
if (!freerdp_settings_set_uint32(settings, FreeRDP_OsMinorType, OSMINORTYPE_NATIVE_WAYLAND))
return FALSE;
PubSub_SubscribeChannelConnected(instance->context->pubSub, wlf_OnChannelConnectedEventHandler);
PubSub_SubscribeChannelDisconnected(instance->context->pubSub,
wlf_OnChannelDisconnectedEventHandler);
if (PubSub_SubscribeChannelConnected(instance->context->pubSub,
wlf_OnChannelConnectedEventHandler) < 0)
return FALSE;
if (PubSub_SubscribeChannelDisconnected(instance->context->pubSub,
wlf_OnChannelDisconnectedEventHandler) < 0)
return FALSE;
if (freerdp_settings_get_bool(settings, FreeRDP_Fullscreen))
{

View File

@@ -1178,8 +1178,11 @@ static BOOL xf_pre_connect(freerdp* instance)
return FALSE;
if (!freerdp_settings_set_uint32(settings, FreeRDP_OsMinorType, OSMINORTYPE_NATIVE_XSERVER))
return FALSE;
PubSub_SubscribeChannelConnected(context->pubSub, xf_OnChannelConnectedEventHandler);
PubSub_SubscribeChannelDisconnected(context->pubSub, xf_OnChannelDisconnectedEventHandler);
if (PubSub_SubscribeChannelConnected(context->pubSub, xf_OnChannelConnectedEventHandler) < 0)
return FALSE;
if (PubSub_SubscribeChannelDisconnected(context->pubSub, xf_OnChannelDisconnectedEventHandler) <
0)
return FALSE;
if (!freerdp_settings_get_string(settings, FreeRDP_Username) &&
!freerdp_settings_get_bool(settings, FreeRDP_CredentialsFromStdin) &&
@@ -2058,10 +2061,13 @@ static BOOL xfreerdp_client_new(freerdp* instance, rdpContext* context)
instance->PostFinalDisconnect = xf_post_final_disconnect;
instance->LogonErrorInfo = xf_logon_error_info;
instance->GetAccessToken = client_cli_get_access_token;
PubSub_SubscribeTerminate(context->pubSub, xf_TerminateEventHandler);
if (PubSub_SubscribeTerminate(context->pubSub, xf_TerminateEventHandler) < 0)
return FALSE;
#ifdef WITH_XRENDER
PubSub_SubscribeZoomingChange(context->pubSub, xf_ZoomingChangeEventHandler);
PubSub_SubscribePanningChange(context->pubSub, xf_PanningChangeEventHandler);
if (PubSub_SubscribeZoomingChange(context->pubSub, xf_ZoomingChangeEventHandler) < 0)
return FALSE;
if (PubSub_SubscribePanningChange(context->pubSub, xf_PanningChangeEventHandler) < 0)
return FALSE;
#endif
xfc->log = WLog_Get(TAG);

View File

@@ -333,19 +333,22 @@ static void xf_disp_OnWindowStateChange(void* context, const WindowStateChangeEv
xfDispContext* xf_disp_new(xfContext* xfc)
{
xfDispContext* ret = nullptr;
const rdpSettings* settings = nullptr;
wPubSub* pubSub = nullptr;
WINPR_ASSERT(xfc);
pubSub = xfc->common.context.pubSub;
wPubSub* pubSub = xfc->common.context.pubSub;
WINPR_ASSERT(pubSub);
settings = xfc->common.context.settings;
const rdpSettings* settings = xfc->common.context.settings;
WINPR_ASSERT(settings);
ret = calloc(1, sizeof(xfDispContext));
if (PubSub_SubscribeActivated(pubSub, xf_disp_OnActivated) < 0)
return nullptr;
if (PubSub_SubscribeGraphicsReset(pubSub, xf_disp_OnGraphicsReset) < 0)
return nullptr;
if (PubSub_SubscribeWindowStateChange(pubSub, xf_disp_OnWindowStateChange) < 0)
return nullptr;
xfDispContext* ret = calloc(1, sizeof(xfDispContext));
if (!ret)
return nullptr;
@@ -363,9 +366,6 @@ xfDispContext* xf_disp_new(xfContext* xfc)
freerdp_settings_get_uint32(settings, FreeRDP_DesktopWidth);
ret->lastSentHeight = ret->targetHeight =
freerdp_settings_get_uint32(settings, FreeRDP_DesktopHeight);
PubSub_SubscribeActivated(pubSub, xf_disp_OnActivated);
PubSub_SubscribeGraphicsReset(pubSub, xf_disp_OnGraphicsReset);
PubSub_SubscribeWindowStateChange(pubSub, xf_disp_OnWindowStateChange);
return ret;
}

View File

@@ -289,8 +289,10 @@ static BOOL pf_client_pre_connect(freerdp* instance)
if (!freerdp_settings_set_bool(settings, FreeRDP_AutoReconnectionEnabled, TRUE))
return FALSE;
PubSub_SubscribeErrorInfo(instance->context->pubSub, pf_client_on_error_info);
PubSub_SubscribeActivated(instance->context->pubSub, pf_client_on_activated);
if (PubSub_SubscribeErrorInfo(instance->context->pubSub, pf_client_on_error_info) < 0)
return FALSE;
if (PubSub_SubscribeActivated(instance->context->pubSub, pf_client_on_activated) < 0)
return FALSE;
if (!pf_client_use_peer_load_balance_info(pc))
return FALSE;

View File

@@ -43,8 +43,10 @@ int TestPubSub(int argc, char* argv[])
PubSub_AddEventTypes(node, Node_Events, NODE_EVENT_COUNT);
PubSub_SubscribeMouseMotion(node, MouseMotionEventHandler);
PubSub_SubscribeMouseButton(node, MouseButtonEventHandler);
if (PubSub_SubscribeMouseMotion(node, MouseMotionEventHandler) < 0)
return -1;
if (PubSub_SubscribeMouseButton(node, MouseButtonEventHandler) < 0)
return -1;
/* Call Event Handler */
{