[core] unify settings copy set/reset

This commit is contained in:
Armin Novak 2023-01-17 12:39:29 +01:00 committed by Martin Fleisz
parent 9e331a6fcb
commit 78b8df86bc
5 changed files with 42 additions and 25 deletions

View File

@ -105,14 +105,7 @@ static int freerdp_connect_begin(freerdp* instance)
if (status)
{
freerdp_settings_free(rdp->originalSettings);
rdp->originalSettings = freerdp_settings_clone(settings);
if (!rdp->originalSettings)
return 0;
freerdp_settings_free(rdp->remoteSettings);
rdp->remoteSettings = freerdp_settings_new(0);
if (!rdp->remoteSettings)
if (!rdp_set_backup_settings(rdp))
return 0;
WINPR_ASSERT(instance->LoadChannels);

View File

@ -1240,7 +1240,7 @@ static BOOL freerdp_peer_send_server_redirection_pdu(freerdp_peer* peer,
if (!rdp_send_pdu(peer->context->rdp, s, PDU_TYPE_SERVER_REDIRECTION, 0))
goto fail;
return TRUE;
return rdp_reset_runtime_settings(peer->context->rdp);
fail:
Stream_Release(s);
return FALSE;

View File

@ -2072,16 +2072,9 @@ rdpRdp* rdp_new(rdpContext* context)
rdp->settings = context->settings;
/* Keep a backup copy of settings for later comparisons */
freerdp_settings_free(rdp->originalSettings);
rdp->originalSettings = freerdp_settings_clone(rdp->settings);
if (!rdp->originalSettings)
if (!rdp_set_backup_settings(rdp))
return FALSE;
freerdp_settings_free(rdp->remoteSettings);
rdp->remoteSettings = freerdp_settings_new(remoteFlags);
if (!rdp->remoteSettings)
return false;
rdp->settings->instance = context->instance;
context->settings = rdp->settings;
@ -2487,3 +2480,37 @@ const char* rdp_security_flag_string(UINT32 securityFlags, char* buffer, size_t
return buffer;
}
static BOOL rdp_reset_remote_settings(rdpRdp* rdp)
{
UINT32 flags = 0;
WINPR_ASSERT(rdp);
freerdp_settings_free(rdp->remoteSettings);
if (!freerdp_settings_get_bool(rdp->settings, FreeRDP_ServerMode))
flags |= FREERDP_SETTINGS_SERVER_MODE;
rdp->remoteSettings = freerdp_settings_new(flags);
return rdp->remoteSettings != NULL;
}
BOOL rdp_set_backup_settings(rdpRdp* rdp)
{
WINPR_ASSERT(rdp);
freerdp_settings_free(rdp->originalSettings);
rdp->originalSettings = freerdp_settings_clone(rdp->settings);
if (!rdp->originalSettings)
return FALSE;
return rdp_reset_remote_settings(rdp);
}
BOOL rdp_reset_runtime_settings(rdpRdp* rdp)
{
WINPR_ASSERT(rdp);
freerdp_settings_free(rdp->settings);
rdp->context->settings = rdp->settings = freerdp_settings_clone(rdp->originalSettings);
if (!rdp->settings)
return FALSE;
return rdp_reset_remote_settings(rdp);
}

View File

@ -286,4 +286,7 @@ BOOL rdp_reset_rc4_decrypt_keys(rdpRdp* rdp);
const char* rdp_security_flag_string(UINT32 securityFlags, char* buffer, size_t size);
BOOL rdp_set_backup_settings(rdpRdp* rdp);
BOOL rdp_reset_runtime_settings(rdpRdp* rdp);
#endif /* FREERDP_LIB_CORE_RDP_H */

View File

@ -208,18 +208,12 @@ int rdp_redirection_apply_settings(rdpRdp* rdp)
rdpSettings* settings;
rdpRedirection* redirection;
WINPR_ASSERT(rdp);
freerdp_settings_free(rdp->settings);
rdp->context->settings = rdp->settings = freerdp_settings_clone(rdp->originalSettings);
if (!rdp_reset_runtime_settings(rdp))
return -1;
settings = rdp->settings;
WINPR_ASSERT(settings);
freerdp_settings_free(rdp->remoteSettings);
rdp->remoteSettings = freerdp_settings_new(0);
WINPR_ASSERT(rdp->remoteSettings);
redirection = rdp->redirection;
WINPR_ASSERT(redirection);