[core,utils] unify channel reloading

Add the wrapper function utils_reload_channels that unifies the channel
cleanup and channel initialization sequence required on connect,
redirect and gateway policy apply
This commit is contained in:
akallabeth
2024-03-07 14:26:58 +01:00
committed by Martin Fleisz
parent 93eb4df524
commit ef8c9e48e8
4 changed files with 27 additions and 32 deletions

View File

@@ -622,11 +622,10 @@ BOOL rdp_client_redirect(rdpRdp* rdp)
if (!rdp_client_disconnect_and_clear(rdp))
return FALSE;
/* Only disconnect & close the channels here.
* they will be discarded and recreated after the new settings have been applied. */
freerdp_channels_disconnect(rdp->context->channels, rdp->context->instance);
freerdp_channels_close(rdp->context->channels, rdp->context->instance);
freerdp_channels_free(rdp->context->channels);
rdp->context->channels = freerdp_channels_new(rdp->context->instance);
WINPR_ASSERT(rdp->context->channels);
if (rdp_redirection_apply_settings(rdp) != 0)
return FALSE;
@@ -684,14 +683,10 @@ BOOL rdp_client_redirect(rdpRdp* rdp)
if (!IFCALLRESULT(TRUE, rdp->context->instance->Redirect, rdp->context->instance))
return FALSE;
BOOL ok = IFCALLRESULT(TRUE, rdp->context->instance->LoadChannels, rdp->context->instance);
BOOL ok = utils_reload_channels(rdp->context);
if (!ok)
return FALSE;
if (CHANNEL_RC_OK !=
freerdp_channels_pre_connect(rdp->context->channels, rdp->context->instance))
return FALSE;
status = rdp_client_connect(rdp);
if (status)

View File

@@ -84,7 +84,6 @@ static void sig_abort_connect(int signum, const char* signame, void* ctx)
static int freerdp_connect_begin(freerdp* instance)
{
BOOL rc = 0;
UINT status2 = CHANNEL_RC_OK;
rdpRdp* rdp = NULL;
BOOL status = TRUE;
rdpSettings* settings = NULL;
@@ -121,16 +120,9 @@ static int freerdp_connect_begin(freerdp* instance)
freerdp_settings_print_warnings(settings);
if (status)
{
if (!rdp_set_backup_settings(rdp))
return 0;
WINPR_ASSERT(instance->LoadChannels);
if (!instance->LoadChannels(instance))
return 0;
status2 = freerdp_channels_pre_connect(instance->context->channels, instance);
}
status = rdp_set_backup_settings(rdp);
if (status)
status = utils_reload_channels(instance->context);
KeyboardLayout = freerdp_settings_get_uint32(settings, FreeRDP_KeyboardLayout);
switch (KeyboardLayout)
@@ -151,7 +143,7 @@ static int freerdp_connect_begin(freerdp* instance)
break;
}
if (!status || (status2 != CHANNEL_RC_OK))
if (!status)
{
rdpContext* context = instance->context;
WINPR_ASSERT(context);

View File

@@ -360,18 +360,7 @@ static BOOL disable_pnp(rdpSettings* settings)
static BOOL apply_gw_policy(rdpContext* context)
{
WINPR_ASSERT(context);
freerdp_channels_disconnect(context->channels, context->instance);
freerdp_channels_close(context->channels, context->instance);
freerdp_channels_free(context->channels);
context->channels = freerdp_channels_new(context->instance);
WINPR_ASSERT(context->channels);
BOOL rc = TRUE;
IFCALLRET(context->instance->LoadChannels, rc, context->instance);
if (rc)
return freerdp_channels_pre_connect(context->channels, context->instance) == CHANNEL_RC_OK;
return rc;
return utils_reload_channels(context);
}
BOOL utils_apply_gateway_policy(wLog* log, rdpContext* context, UINT32 flags, const char* module)
@@ -474,3 +463,20 @@ char* utils_redir_flags_to_string(UINT32 flags, char* buffer, size_t size)
winpr_str_append("{", buffer, size, "}");
return buffer;
}
BOOL utils_reload_channels(rdpContext* context)
{
WINPR_ASSERT(context);
freerdp_channels_disconnect(context->channels, context->instance);
freerdp_channels_close(context->channels, context->instance);
freerdp_channels_free(context->channels);
context->channels = freerdp_channels_new(context->instance);
WINPR_ASSERT(context->channels);
BOOL rc = TRUE;
IFCALLRET(context->instance->LoadChannels, rc, context->instance);
if (rc)
return freerdp_channels_pre_connect(context->channels, context->instance) == CHANNEL_RC_OK;
return rc;
}

View File

@@ -59,4 +59,6 @@ const char* utils_is_vsock(const char* hostname);
BOOL utils_apply_gateway_policy(wLog* log, rdpContext* context, UINT32 flags, const char* module);
char* utils_redir_flags_to_string(UINT32 flags, char* buffer, size_t size);
BOOL utils_reload_channels(rdpContext* context);
#endif /* FREERDP_LIB_CORE_UTILS_H */