diff --git a/client/common/file.c b/client/common/file.c index e5bff1dd7..7ffeecc6d 100644 --- a/client/common/file.c +++ b/client/common/file.c @@ -1750,13 +1750,55 @@ fail: return NULL; } -BOOL freerdp_client_populate_settings_from_rdp_file(const rdpFile* file, rdpSettings* settings) +BOOL freerdp_client_populate_settings_from_rdp_file_unchecked(const rdpFile* file, + rdpSettings* settings) { - BOOL setDefaultConnectionType = TRUE; - if (!file || !settings) return FALSE; + /* Start with connection type. + * This setting initializes certain defaults which might be overridden by later options. + */ + if (~file->BandwidthAutoDetect) + { + if (file->BandwidthAutoDetect != 0) + { + if ((~file->NetworkAutoDetect) && (file->NetworkAutoDetect == 0)) + { + WLog_WARN(TAG, + "Got networkautodetect:i:%" PRIu32 " and bandwidthautodetect:i:%" PRIu32 + ". Correcting to networkautodetect:i:1", + file->NetworkAutoDetect, file->BandwidthAutoDetect); + WLog_WARN(TAG, + "Add networkautodetect:i:1 to your RDP file to eliminate this warning."); + } + } + if (!freerdp_settings_set_bool(settings, FreeRDP_NetworkAutoDetect, + (file->BandwidthAutoDetect != 0) || + (file->NetworkAutoDetect != 0))) + return FALSE; + } + + if (~file->NetworkAutoDetect) + { + if (file->NetworkAutoDetect != 0) + { + if ((~file->BandwidthAutoDetect) && (file->BandwidthAutoDetect == 0)) + { + WLog_WARN(TAG, + "Got networkautodetect:i:%" PRIu32 " and bandwidthautodetect:i:%" PRIu32 + ". Correcting to bandwidthautodetect:i:1", + file->NetworkAutoDetect, file->BandwidthAutoDetect); + WLog_WARN( + TAG, "Add bandwidthautodetect:i:1 to your RDP file to eliminate this warning."); + } + } + if (!freerdp_settings_set_bool(settings, FreeRDP_NetworkAutoDetect, + (file->BandwidthAutoDetect != 0) || + (file->NetworkAutoDetect != 0))) + return FALSE; + } + if (~((size_t)file->Domain)) { if (!freerdp_settings_set_string(settings, FreeRDP_Domain, file->Domain)) @@ -2013,9 +2055,8 @@ BOOL freerdp_client_populate_settings_from_rdp_file(const rdpFile* file, rdpSett if (~file->ConnectionType) { - if (!freerdp_set_connection_type(settings, file->ConnectionType)) + if (!freerdp_settings_set_uint32(settings, FreeRDP_ConnectionType, file->ConnectionType)) return FALSE; - setDefaultConnectionType = FALSE; } if (~file->AudioMode) @@ -2276,55 +2317,6 @@ BOOL freerdp_client_populate_settings_from_rdp_file(const rdpFile* file, rdpSett return FALSE; } - if (~file->BandwidthAutoDetect) - { - if (file->BandwidthAutoDetect != 0) - { - if ((~file->NetworkAutoDetect) && (file->NetworkAutoDetect == 0)) - { - WLog_WARN(TAG, - "Got networkautodetect:i:%" PRIu32 " and bandwidthautodetect:i:%" PRIu32 - ". Correcting to networkautodetect:i:1", - file->NetworkAutoDetect, file->BandwidthAutoDetect); - WLog_WARN(TAG, - "Add networkautodetect:i:1 to your RDP file to eliminate this warning."); - } - - if (!freerdp_set_connection_type(settings, CONNECTION_TYPE_AUTODETECT)) - return FALSE; - setDefaultConnectionType = FALSE; - } - if (!freerdp_settings_set_bool(settings, FreeRDP_NetworkAutoDetect, - (file->BandwidthAutoDetect != 0) || - (file->NetworkAutoDetect != 0))) - return FALSE; - } - - if (~file->NetworkAutoDetect) - { - if (file->NetworkAutoDetect != 0) - { - if ((~file->BandwidthAutoDetect) && (file->BandwidthAutoDetect == 0)) - { - WLog_WARN(TAG, - "Got networkautodetect:i:%" PRIu32 " and bandwidthautodetect:i:%" PRIu32 - ". Correcting to bandwidthautodetect:i:1", - file->NetworkAutoDetect, file->BandwidthAutoDetect); - WLog_WARN( - TAG, "Add bandwidthautodetect:i:1 to your RDP file to eliminate this warning."); - } - - if (!freerdp_set_connection_type(settings, CONNECTION_TYPE_AUTODETECT)) - return FALSE; - - setDefaultConnectionType = FALSE; - } - if (!freerdp_settings_set_bool(settings, FreeRDP_NetworkAutoDetect, - (file->BandwidthAutoDetect != 0) || - (file->NetworkAutoDetect != 0))) - return FALSE; - } - if (~file->AutoReconnectionEnabled) { if (!freerdp_settings_set_bool(settings, FreeRDP_AutoReconnectionEnabled, @@ -2628,15 +2620,23 @@ BOOL freerdp_client_populate_settings_from_rdp_file(const rdpFile* file, rdpSett return FALSE; } - if (setDefaultConnectionType) - { - if (!freerdp_set_connection_type(settings, CONNECTION_TYPE_AUTODETECT)) - return FALSE; - } - return TRUE; } +BOOL freerdp_client_populate_settings_from_rdp_file(const rdpFile* file, rdpSettings* settings) +{ + if (!freerdp_client_populate_settings_from_rdp_file_unchecked(file, settings)) + return FALSE; + + DWORD type = freerdp_settings_get_uint32(settings, FreeRDP_ConnectionType); + if ((~file->ConnectionType) == 0) + { + if (freerdp_settings_get_bool(settings, FreeRDP_NetworkAutoDetect)) + type = CONNECTION_TYPE_AUTODETECT; + } + return freerdp_set_connection_type(settings, type); +} + static rdpFileLine* freerdp_client_rdp_file_find_line_by_name(const rdpFile* file, const char* name) { BOOL bFound = FALSE; diff --git a/include/freerdp/client/file.h b/include/freerdp/client/file.h index 30c6543d7..3368682bf 100644 --- a/include/freerdp/client/file.h +++ b/include/freerdp/client/file.h @@ -47,6 +47,26 @@ extern "C" size_t size); FREERDP_API BOOL freerdp_client_parse_rdp_file_buffer_ex(rdpFile* file, const BYTE* buffer, size_t size, rdp_file_fkt_parse parse); + + /** @brief Populate \b settings from RDP \b file. Do only notify about inconsistencies and not + * correct them. + * + * @param file A pointer to the RDP file to use + * @param settings A pointer to the settings to update + * + * @return \b TRUE for success, \b FALSE otherwise + * @version since 3.17.0 + */ + FREERDP_API BOOL freerdp_client_populate_settings_from_rdp_file_unchecked( + const rdpFile* file, rdpSettings* settings); + + /** @brief Populate \b settings from RDP \b file. Do correct inconsistencies detected. + * + * @param file A pointer to the RDP file to use + * @param settings A pointer to the settings to update + * + * @return \b TRUE for success, \b FALSE otherwise + */ FREERDP_API BOOL freerdp_client_populate_settings_from_rdp_file(const rdpFile* file, rdpSettings* settings);