Refactored settings clone/free, extended tests

(cherry picked from commit 773ad6e9791844ca3ccdc40d378a37fc0238ef0a)
This commit is contained in:
akallabeth 2020-05-15 12:22:37 +02:00
parent 6b8311a15a
commit c060089a2b
6 changed files with 621 additions and 247 deletions

View File

@ -2358,7 +2358,7 @@ const char* freerdp_settings_get_string(const rdpSettings* settings, size_t id)
}
}
BOOL freerdp_settings_set_string(rdpSettings* settings, size_t id, const char* val)
BOOL freerdp_settings_set_string_(rdpSettings* settings, size_t id, const char* val, BOOL cleanup)
{
if (!settings)
return FALSE;
@ -2366,332 +2366,398 @@ BOOL freerdp_settings_set_string(rdpSettings* settings, size_t id, const char* v
switch (id)
{
case FreeRDP_AcceptedCert:
free(settings->AcceptedCert);
if (cleanup)
free(settings->AcceptedCert);
settings->AcceptedCert = (val ? _strdup(val) : NULL);
return (!val || settings->AcceptedCert != NULL);
case FreeRDP_AllowedTlsCiphers:
free(settings->AllowedTlsCiphers);
if (cleanup)
free(settings->AllowedTlsCiphers);
settings->AllowedTlsCiphers = (val ? _strdup(val) : NULL);
return (!val || settings->AllowedTlsCiphers != NULL);
case FreeRDP_AlternateShell:
free(settings->AlternateShell);
if (cleanup)
free(settings->AlternateShell);
settings->AlternateShell = (val ? _strdup(val) : NULL);
return (!val || settings->AlternateShell != NULL);
case FreeRDP_AssistanceFile:
free(settings->AssistanceFile);
if (cleanup)
free(settings->AssistanceFile);
settings->AssistanceFile = (val ? _strdup(val) : NULL);
return (!val || settings->AssistanceFile != NULL);
case FreeRDP_AuthenticationServiceClass:
free(settings->AuthenticationServiceClass);
if (cleanup)
free(settings->AuthenticationServiceClass);
settings->AuthenticationServiceClass = (val ? _strdup(val) : NULL);
return (!val || settings->AuthenticationServiceClass != NULL);
case FreeRDP_CertificateAcceptedFingerprints:
free(settings->CertificateAcceptedFingerprints);
if (cleanup)
free(settings->CertificateAcceptedFingerprints);
settings->CertificateAcceptedFingerprints = (val ? _strdup(val) : NULL);
return (!val || settings->CertificateAcceptedFingerprints != NULL);
case FreeRDP_CertificateContent:
free(settings->CertificateContent);
if (cleanup)
free(settings->CertificateContent);
settings->CertificateContent = (val ? _strdup(val) : NULL);
return (!val || settings->CertificateContent != NULL);
case FreeRDP_CertificateFile:
free(settings->CertificateFile);
if (cleanup)
free(settings->CertificateFile);
settings->CertificateFile = (val ? _strdup(val) : NULL);
return (!val || settings->CertificateFile != NULL);
case FreeRDP_CertificateName:
free(settings->CertificateName);
if (cleanup)
free(settings->CertificateName);
settings->CertificateName = (val ? _strdup(val) : NULL);
return (!val || settings->CertificateName != NULL);
case FreeRDP_ClientAddress:
free(settings->ClientAddress);
if (cleanup)
free(settings->ClientAddress);
settings->ClientAddress = (val ? _strdup(val) : NULL);
return (!val || settings->ClientAddress != NULL);
case FreeRDP_ClientDir:
free(settings->ClientDir);
if (cleanup)
free(settings->ClientDir);
settings->ClientDir = (val ? _strdup(val) : NULL);
return (!val || settings->ClientDir != NULL);
case FreeRDP_ClientHostname:
free(settings->ClientHostname);
if (cleanup)
free(settings->ClientHostname);
settings->ClientHostname = (val ? _strdup(val) : NULL);
return (!val || settings->ClientHostname != NULL);
case FreeRDP_ClientProductId:
free(settings->ClientProductId);
if (cleanup)
free(settings->ClientProductId);
settings->ClientProductId = (val ? _strdup(val) : NULL);
return (!val || settings->ClientProductId != NULL);
case FreeRDP_ComputerName:
free(settings->ComputerName);
if (cleanup)
free(settings->ComputerName);
settings->ComputerName = (val ? _strdup(val) : NULL);
return (!val || settings->ComputerName != NULL);
case FreeRDP_ConfigPath:
free(settings->ConfigPath);
if (cleanup)
free(settings->ConfigPath);
settings->ConfigPath = (val ? _strdup(val) : NULL);
return (!val || settings->ConfigPath != NULL);
case FreeRDP_ConnectionFile:
free(settings->ConnectionFile);
if (cleanup)
free(settings->ConnectionFile);
settings->ConnectionFile = (val ? _strdup(val) : NULL);
return (!val || settings->ConnectionFile != NULL);
case FreeRDP_CurrentPath:
free(settings->CurrentPath);
if (cleanup)
free(settings->CurrentPath);
settings->CurrentPath = (val ? _strdup(val) : NULL);
return (!val || settings->CurrentPath != NULL);
case FreeRDP_Domain:
free(settings->Domain);
if (cleanup)
free(settings->Domain);
settings->Domain = (val ? _strdup(val) : NULL);
return (!val || settings->Domain != NULL);
case FreeRDP_DrivesToRedirect:
free(settings->DrivesToRedirect);
if (cleanup)
free(settings->DrivesToRedirect);
settings->DrivesToRedirect = (val ? _strdup(val) : NULL);
return (!val || settings->DrivesToRedirect != NULL);
case FreeRDP_DumpRemoteFxFile:
free(settings->DumpRemoteFxFile);
if (cleanup)
free(settings->DumpRemoteFxFile);
settings->DumpRemoteFxFile = (val ? _strdup(val) : NULL);
return (!val || settings->DumpRemoteFxFile != NULL);
case FreeRDP_DynamicDSTTimeZoneKeyName:
free(settings->DynamicDSTTimeZoneKeyName);
if (cleanup)
free(settings->DynamicDSTTimeZoneKeyName);
settings->DynamicDSTTimeZoneKeyName = (val ? _strdup(val) : NULL);
return (!val || settings->DynamicDSTTimeZoneKeyName != NULL);
case FreeRDP_GatewayAcceptedCert:
free(settings->GatewayAcceptedCert);
if (cleanup)
free(settings->GatewayAcceptedCert);
settings->GatewayAcceptedCert = (val ? _strdup(val) : NULL);
return (!val || settings->GatewayAcceptedCert != NULL);
case FreeRDP_GatewayAccessToken:
free(settings->GatewayAccessToken);
if (cleanup)
free(settings->GatewayAccessToken);
settings->GatewayAccessToken = (val ? _strdup(val) : NULL);
return (!val || settings->GatewayAccessToken != NULL);
case FreeRDP_GatewayDomain:
free(settings->GatewayDomain);
if (cleanup)
free(settings->GatewayDomain);
settings->GatewayDomain = (val ? _strdup(val) : NULL);
return (!val || settings->GatewayDomain != NULL);
case FreeRDP_GatewayHostname:
free(settings->GatewayHostname);
if (cleanup)
free(settings->GatewayHostname);
settings->GatewayHostname = (val ? _strdup(val) : NULL);
return (!val || settings->GatewayHostname != NULL);
case FreeRDP_GatewayPassword:
free(settings->GatewayPassword);
if (cleanup)
free(settings->GatewayPassword);
settings->GatewayPassword = (val ? _strdup(val) : NULL);
return (!val || settings->GatewayPassword != NULL);
case FreeRDP_GatewayUsername:
free(settings->GatewayUsername);
if (cleanup)
free(settings->GatewayUsername);
settings->GatewayUsername = (val ? _strdup(val) : NULL);
return (!val || settings->GatewayUsername != NULL);
case FreeRDP_HomePath:
free(settings->HomePath);
if (cleanup)
free(settings->HomePath);
settings->HomePath = (val ? _strdup(val) : NULL);
return (!val || settings->HomePath != NULL);
case FreeRDP_ImeFileName:
free(settings->ImeFileName);
if (cleanup)
free(settings->ImeFileName);
settings->ImeFileName = (val ? _strdup(val) : NULL);
return (!val || settings->ImeFileName != NULL);
case FreeRDP_KerberosKdc:
free(settings->KerberosKdc);
if (cleanup)
free(settings->KerberosKdc);
settings->KerberosKdc = (val ? _strdup(val) : NULL);
return (!val || settings->KerberosKdc != NULL);
case FreeRDP_KerberosRealm:
free(settings->KerberosRealm);
if (cleanup)
free(settings->KerberosRealm);
settings->KerberosRealm = (val ? _strdup(val) : NULL);
return (!val || settings->KerberosRealm != NULL);
case FreeRDP_NtlmSamFile:
free(settings->NtlmSamFile);
if (cleanup)
free(settings->NtlmSamFile);
settings->NtlmSamFile = (val ? _strdup(val) : NULL);
return (!val || settings->NtlmSamFile != NULL);
case FreeRDP_Password:
free(settings->Password);
if (cleanup)
free(settings->Password);
settings->Password = (val ? _strdup(val) : NULL);
return (!val || settings->Password != NULL);
case FreeRDP_PasswordHash:
free(settings->PasswordHash);
if (cleanup)
free(settings->PasswordHash);
settings->PasswordHash = (val ? _strdup(val) : NULL);
return (!val || settings->PasswordHash != NULL);
case FreeRDP_PlayRemoteFxFile:
free(settings->PlayRemoteFxFile);
if (cleanup)
free(settings->PlayRemoteFxFile);
settings->PlayRemoteFxFile = (val ? _strdup(val) : NULL);
return (!val || settings->PlayRemoteFxFile != NULL);
case FreeRDP_PreconnectionBlob:
free(settings->PreconnectionBlob);
if (cleanup)
free(settings->PreconnectionBlob);
settings->PreconnectionBlob = (val ? _strdup(val) : NULL);
return (!val || settings->PreconnectionBlob != NULL);
case FreeRDP_PrivateKeyContent:
free(settings->PrivateKeyContent);
if (cleanup)
free(settings->PrivateKeyContent);
settings->PrivateKeyContent = (val ? _strdup(val) : NULL);
return (!val || settings->PrivateKeyContent != NULL);
case FreeRDP_PrivateKeyFile:
free(settings->PrivateKeyFile);
if (cleanup)
free(settings->PrivateKeyFile);
settings->PrivateKeyFile = (val ? _strdup(val) : NULL);
return (!val || settings->PrivateKeyFile != NULL);
case FreeRDP_ProxyHostname:
free(settings->ProxyHostname);
if (cleanup)
free(settings->ProxyHostname);
settings->ProxyHostname = (val ? _strdup(val) : NULL);
return (!val || settings->ProxyHostname != NULL);
case FreeRDP_ProxyPassword:
free(settings->ProxyPassword);
if (cleanup)
free(settings->ProxyPassword);
settings->ProxyPassword = (val ? _strdup(val) : NULL);
return (!val || settings->ProxyPassword != NULL);
case FreeRDP_ProxyUsername:
free(settings->ProxyUsername);
if (cleanup)
free(settings->ProxyUsername);
settings->ProxyUsername = (val ? _strdup(val) : NULL);
return (!val || settings->ProxyUsername != NULL);
case FreeRDP_RDP2TCPArgs:
free(settings->RDP2TCPArgs);
if (cleanup)
free(settings->RDP2TCPArgs);
settings->RDP2TCPArgs = (val ? _strdup(val) : NULL);
return (!val || settings->RDP2TCPArgs != NULL);
case FreeRDP_RdpKeyContent:
free(settings->RdpKeyContent);
if (cleanup)
free(settings->RdpKeyContent);
settings->RdpKeyContent = (val ? _strdup(val) : NULL);
return (!val || settings->RdpKeyContent != NULL);
case FreeRDP_RdpKeyFile:
free(settings->RdpKeyFile);
if (cleanup)
free(settings->RdpKeyFile);
settings->RdpKeyFile = (val ? _strdup(val) : NULL);
return (!val || settings->RdpKeyFile != NULL);
case FreeRDP_RedirectionAcceptedCert:
free(settings->RedirectionAcceptedCert);
if (cleanup)
free(settings->RedirectionAcceptedCert);
settings->RedirectionAcceptedCert = (val ? _strdup(val) : NULL);
return (!val || settings->RedirectionAcceptedCert != NULL);
case FreeRDP_RedirectionDomain:
free(settings->RedirectionDomain);
if (cleanup)
free(settings->RedirectionDomain);
settings->RedirectionDomain = (val ? _strdup(val) : NULL);
return (!val || settings->RedirectionDomain != NULL);
case FreeRDP_RedirectionTargetFQDN:
free(settings->RedirectionTargetFQDN);
if (cleanup)
free(settings->RedirectionTargetFQDN);
settings->RedirectionTargetFQDN = (val ? _strdup(val) : NULL);
return (!val || settings->RedirectionTargetFQDN != NULL);
case FreeRDP_RedirectionTargetNetBiosName:
free(settings->RedirectionTargetNetBiosName);
if (cleanup)
free(settings->RedirectionTargetNetBiosName);
settings->RedirectionTargetNetBiosName = (val ? _strdup(val) : NULL);
return (!val || settings->RedirectionTargetNetBiosName != NULL);
case FreeRDP_RedirectionUsername:
free(settings->RedirectionUsername);
if (cleanup)
free(settings->RedirectionUsername);
settings->RedirectionUsername = (val ? _strdup(val) : NULL);
return (!val || settings->RedirectionUsername != NULL);
case FreeRDP_RemoteApplicationCmdLine:
free(settings->RemoteApplicationCmdLine);
if (cleanup)
free(settings->RemoteApplicationCmdLine);
settings->RemoteApplicationCmdLine = (val ? _strdup(val) : NULL);
return (!val || settings->RemoteApplicationCmdLine != NULL);
case FreeRDP_RemoteApplicationFile:
free(settings->RemoteApplicationFile);
if (cleanup)
free(settings->RemoteApplicationFile);
settings->RemoteApplicationFile = (val ? _strdup(val) : NULL);
return (!val || settings->RemoteApplicationFile != NULL);
case FreeRDP_RemoteApplicationGuid:
free(settings->RemoteApplicationGuid);
if (cleanup)
free(settings->RemoteApplicationGuid);
settings->RemoteApplicationGuid = (val ? _strdup(val) : NULL);
return (!val || settings->RemoteApplicationGuid != NULL);
case FreeRDP_RemoteApplicationIcon:
free(settings->RemoteApplicationIcon);
if (cleanup)
free(settings->RemoteApplicationIcon);
settings->RemoteApplicationIcon = (val ? _strdup(val) : NULL);
return (!val || settings->RemoteApplicationIcon != NULL);
case FreeRDP_RemoteApplicationName:
free(settings->RemoteApplicationName);
if (cleanup)
free(settings->RemoteApplicationName);
settings->RemoteApplicationName = (val ? _strdup(val) : NULL);
return (!val || settings->RemoteApplicationName != NULL);
case FreeRDP_RemoteApplicationProgram:
free(settings->RemoteApplicationProgram);
if (cleanup)
free(settings->RemoteApplicationProgram);
settings->RemoteApplicationProgram = (val ? _strdup(val) : NULL);
return (!val || settings->RemoteApplicationProgram != NULL);
case FreeRDP_RemoteApplicationWorkingDir:
free(settings->RemoteApplicationWorkingDir);
if (cleanup)
free(settings->RemoteApplicationWorkingDir);
settings->RemoteApplicationWorkingDir = (val ? _strdup(val) : NULL);
return (!val || settings->RemoteApplicationWorkingDir != NULL);
case FreeRDP_RemoteAssistancePassStub:
free(settings->RemoteAssistancePassStub);
if (cleanup)
free(settings->RemoteAssistancePassStub);
settings->RemoteAssistancePassStub = (val ? _strdup(val) : NULL);
return (!val || settings->RemoteAssistancePassStub != NULL);
case FreeRDP_RemoteAssistancePassword:
free(settings->RemoteAssistancePassword);
if (cleanup)
free(settings->RemoteAssistancePassword);
settings->RemoteAssistancePassword = (val ? _strdup(val) : NULL);
return (!val || settings->RemoteAssistancePassword != NULL);
case FreeRDP_RemoteAssistanceRCTicket:
free(settings->RemoteAssistanceRCTicket);
if (cleanup)
free(settings->RemoteAssistanceRCTicket);
settings->RemoteAssistanceRCTicket = (val ? _strdup(val) : NULL);
return (!val || settings->RemoteAssistanceRCTicket != NULL);
case FreeRDP_RemoteAssistanceSessionId:
free(settings->RemoteAssistanceSessionId);
if (cleanup)
free(settings->RemoteAssistanceSessionId);
settings->RemoteAssistanceSessionId = (val ? _strdup(val) : NULL);
return (!val || settings->RemoteAssistanceSessionId != NULL);
case FreeRDP_ServerHostname:
free(settings->ServerHostname);
if (cleanup)
free(settings->ServerHostname);
settings->ServerHostname = (val ? _strdup(val) : NULL);
return (!val || settings->ServerHostname != NULL);
case FreeRDP_ShellWorkingDirectory:
free(settings->ShellWorkingDirectory);
if (cleanup)
free(settings->ShellWorkingDirectory);
settings->ShellWorkingDirectory = (val ? _strdup(val) : NULL);
return (!val || settings->ShellWorkingDirectory != NULL);
case FreeRDP_TargetNetAddress:
free(settings->TargetNetAddress);
if (cleanup)
free(settings->TargetNetAddress);
settings->TargetNetAddress = (val ? _strdup(val) : NULL);
return (!val || settings->TargetNetAddress != NULL);
case FreeRDP_Username:
free(settings->Username);
if (cleanup)
free(settings->Username);
settings->Username = (val ? _strdup(val) : NULL);
return (!val || settings->Username != NULL);
case FreeRDP_WindowTitle:
free(settings->WindowTitle);
if (cleanup)
free(settings->WindowTitle);
settings->WindowTitle = (val ? _strdup(val) : NULL);
return (!val || settings->WindowTitle != NULL);
case FreeRDP_WmClass:
free(settings->WmClass);
if (cleanup)
free(settings->WmClass);
settings->WmClass = (val ? _strdup(val) : NULL);
return (!val || settings->WmClass != NULL);
@ -2702,6 +2768,11 @@ BOOL freerdp_settings_set_string(rdpSettings* settings, size_t id, const char* v
return TRUE;
}
BOOL freerdp_settings_set_string(rdpSettings* settings, size_t id, const char* val)
{
return freerdp_settings_set_string_(settings, id, val, TRUE);
}
const void* freerdp_settings_get_pointer(const rdpSettings* settings, size_t id)
{
if (!settings)
@ -2792,3 +2863,121 @@ const void* freerdp_settings_get_pointer(const rdpSettings* settings, size_t id)
return FALSE;
}
}
BOOL freerdp_settings_set_pointer(rdpSettings* settings, size_t id, const void* val)
{
if (!settings)
return FALSE;
switch (id)
{
case FreeRDP_BitmapCacheV2CellInfo:
settings->BitmapCacheV2CellInfo = (void*)val;
break;
case FreeRDP_ChannelDefArray:
settings->ChannelDefArray = (void*)val;
break;
case FreeRDP_ClientAutoReconnectCookie:
settings->ClientAutoReconnectCookie = (void*)val;
break;
case FreeRDP_ClientRandom:
settings->ClientRandom = (void*)val;
break;
case FreeRDP_ClientTimeZone:
settings->ClientTimeZone = (void*)val;
break;
case FreeRDP_DeviceArray:
settings->DeviceArray = (void*)val;
break;
case FreeRDP_DynamicChannelArray:
settings->DynamicChannelArray = (void*)val;
break;
case FreeRDP_FragCache:
settings->FragCache = (void*)val;
break;
case FreeRDP_GlyphCache:
settings->GlyphCache = (void*)val;
break;
case FreeRDP_LoadBalanceInfo:
settings->LoadBalanceInfo = (void*)val;
break;
case FreeRDP_MonitorDefArray:
settings->MonitorDefArray = (void*)val;
break;
case FreeRDP_MonitorIds:
settings->MonitorIds = (void*)val;
break;
case FreeRDP_OrderSupport:
settings->OrderSupport = (void*)val;
break;
case FreeRDP_Password51:
settings->Password51 = (void*)val;
break;
case FreeRDP_RdpServerCertificate:
settings->RdpServerCertificate = (void*)val;
break;
case FreeRDP_RdpServerRsaKey:
settings->RdpServerRsaKey = (void*)val;
break;
case FreeRDP_ReceivedCapabilities:
settings->ReceivedCapabilities = (void*)val;
break;
case FreeRDP_RedirectionPassword:
settings->RedirectionPassword = (void*)val;
break;
case FreeRDP_RedirectionTsvUrl:
settings->RedirectionTsvUrl = (void*)val;
break;
case FreeRDP_ServerAutoReconnectCookie:
settings->ServerAutoReconnectCookie = (void*)val;
break;
case FreeRDP_ServerCertificate:
settings->ServerCertificate = (void*)val;
break;
case FreeRDP_ServerRandom:
settings->ServerRandom = (void*)val;
break;
case FreeRDP_StaticChannelArray:
settings->StaticChannelArray = (void*)val;
break;
case FreeRDP_TargetNetAddresses:
settings->TargetNetAddresses = (void*)val;
break;
case FreeRDP_TargetNetPorts:
settings->TargetNetPorts = (void*)val;
break;
case FreeRDP_instance:
settings->instance = (void*)val;
break;
default:
WLog_ERR(TAG, "[%s] Invalid key index %" PRIuz, __FUNCTION__, id);
return FALSE;
}
return TRUE;
}

View File

@ -3,6 +3,8 @@
#include <freerdp/settings.h>
#include <freerdp/log.h>
#include "../core/settings.h"
#define TAG FREERDP_TAG("common.settings")
struct settings_str_entry
@ -385,6 +387,100 @@ static const struct settings_str_entry settings_map[] = {
{ FreeRDP_instance, 8, "FreeRDP_instance" },
};
BOOL freerdp_settings_clone_keys(rdpSettings* dst, const rdpSettings* src)
{
size_t x;
for (x = 0; x < ARRAYSIZE(settings_map); x++)
{
const struct settings_str_entry* cur = &settings_map[x];
switch (cur->type)
{
case 0: /* bool */
{
BOOL sval = freerdp_settings_get_bool(src, cur->id);
if (!freerdp_settings_set_bool(dst, cur->id, sval))
return FALSE;
}
break;
case 1: /* UINT16 */
{
UINT16 sval = freerdp_settings_get_uint16(src, cur->id);
if (!freerdp_settings_set_uint16(dst, cur->id, sval))
return FALSE;
}
break;
case 2: /* INT16 */
{
INT16 sval = freerdp_settings_get_int16(src, cur->id);
if (!freerdp_settings_set_int16(dst, cur->id, sval))
return FALSE;
}
break;
case 3: /* UINT32 */
{
UINT32 sval = freerdp_settings_get_uint32(src, cur->id);
if (!freerdp_settings_set_uint32(dst, cur->id, sval))
return FALSE;
}
break;
case 4: /* INT32 */
{
INT32 sval = freerdp_settings_get_int32(src, cur->id);
if (!freerdp_settings_set_int32(dst, cur->id, sval))
return FALSE;
}
break;
case 5: /* UINT64 */
{
UINT64 sval = freerdp_settings_get_uint64(src, cur->id);
if (!freerdp_settings_set_uint64(dst, cur->id, sval))
return FALSE;
}
break;
case 6: /* INT64 */
{
INT64 sval = freerdp_settings_get_int64(src, cur->id);
if (!freerdp_settings_set_int64(dst, cur->id, sval))
return FALSE;
}
break;
case 7: /* strings */
{
const char* sval = freerdp_settings_get_string(src, cur->id);
if (!freerdp_settings_set_string_(dst, cur->id, sval, FALSE))
return FALSE;
}
break;
case 8: /* pointer */
{
const void* sval = freerdp_settings_get_pointer(src, cur->id);
if (!freerdp_settings_set_pointer(dst, cur->id, sval))
return FALSE;
}
break;
}
}
return TRUE;
}
void freerdp_settings_free_keys(rdpSettings* dst, BOOL cleanup)
{
size_t x;
for (x = 0; x < ARRAYSIZE(settings_map); x++)
{
const struct settings_str_entry* cur = &settings_map[x];
switch (cur->type)
{
case 7: /* strings */
freerdp_settings_set_string_(dst, cur->id, NULL, cleanup);
break;
case 8: /* pointer */
freerdp_settings_set_pointer(dst, cur->id, NULL);
break;
}
}
}
SSIZE_T freerdp_settings_get_key_for_name(const char* value)
{
size_t x;

View File

@ -40,6 +40,8 @@
#include <freerdp/build-config.h>
#include <ctype.h>
#include "settings.h"
#ifdef _WIN32
#pragma warning(push)
#pragma warning(disable : 4244)
@ -626,39 +628,15 @@ out_fail:
static void freerdp_settings_free_internal(rdpSettings* settings)
{
free(settings->ServerHostname);
free(settings->Username);
free(settings->Password);
free(settings->Domain);
free(settings->PasswordHash);
free(settings->AcceptedCert);
free(settings->AlternateShell);
free(settings->ShellWorkingDirectory);
free(settings->ComputerName);
free(settings->ChannelDefArray);
free(settings->MonitorDefArray);
free(settings->MonitorIds);
free(settings->ClientAddress);
free(settings->ClientDir);
free(settings->AllowedTlsCiphers);
free(settings->NtlmSamFile);
free(settings->CertificateFile);
free(settings->PrivateKeyFile);
free(settings->ConnectionFile);
free(settings->AssistanceFile);
free(settings->ReceivedCapabilities);
free(settings->OrderSupport);
free(settings->ClientHostname);
free(settings->ClientProductId);
free(settings->ServerRandom);
free(settings->ClientRandom);
free(settings->ServerCertificate);
free(settings->RdpKeyFile);
certificate_free(settings->RdpServerCertificate);
free(settings->CertificateContent);
free(settings->PrivateKeyContent);
free(settings->RdpKeyContent);
free(settings->CertificateAcceptedFingerprints);
free(settings->ClientAutoReconnectCookie);
free(settings->ServerAutoReconnectCookie);
free(settings->ClientTimeZone);
@ -666,52 +644,21 @@ static void freerdp_settings_free_internal(rdpSettings* settings)
free(settings->GlyphCache);
free(settings->FragCache);
key_free(settings->RdpServerRsaKey);
free(settings->ConfigPath);
free(settings->CurrentPath);
free(settings->HomePath);
free(settings->LoadBalanceInfo);
free(settings->TargetNetAddress);
free(settings->RedirectionTargetFQDN);
free(settings->RedirectionTargetNetBiosName);
free(settings->RedirectionUsername);
free(settings->RedirectionDomain);
free(settings->RedirectionPassword);
free(settings->RedirectionTsvUrl);
free(settings->RedirectionAcceptedCert);
free(settings->RemoteAssistanceSessionId);
free(settings->RemoteAssistancePassword);
free(settings->RemoteAssistancePassStub);
free(settings->RemoteAssistanceRCTicket);
free(settings->AuthenticationServiceClass);
free(settings->GatewayHostname);
free(settings->GatewayUsername);
free(settings->GatewayPassword);
free(settings->GatewayDomain);
free(settings->GatewayAccessToken);
free(settings->GatewayAcceptedCert);
free(settings->CertificateName);
free(settings->DynamicDSTTimeZoneKeyName);
free(settings->PreconnectionBlob);
free(settings->KerberosKdc);
free(settings->KerberosRealm);
free(settings->DumpRemoteFxFile);
free(settings->PlayRemoteFxFile);
free(settings->RemoteApplicationName);
free(settings->RemoteApplicationIcon);
free(settings->RemoteApplicationProgram);
free(settings->RemoteApplicationFile);
free(settings->RemoteApplicationGuid);
free(settings->RemoteApplicationCmdLine);
free(settings->ImeFileName);
free(settings->DrivesToRedirect);
free(settings->WindowTitle);
free(settings->WmClass);
free(settings->ActionScript);
freerdp_target_net_addresses_free(settings);
freerdp_device_collection_free(settings);
freerdp_static_channel_collection_free(settings);
freerdp_dynamic_channel_collection_free(settings);
memset(settings, 0, sizeof(rdpSettings));
/* Extensions */
free(settings->ActionScript);
settings->ActionScript = NULL;
/* Free all strings, set other pointers NULL */
freerdp_settings_free_keys(settings, TRUE);
}
void freerdp_settings_free(rdpSettings* settings)
@ -723,79 +670,13 @@ void freerdp_settings_free(rdpSettings* settings)
free(settings);
}
BOOL freerdp_settings_copy(rdpSettings* _settings, const rdpSettings* settings)
static BOOL freerdp_settings_int_buffer_copy(rdpSettings* _settings, const rdpSettings* settings)
{
BOOL rc = FALSE;
UINT32 index;
if (!settings || !_settings)
if (!_settings || !settings)
return FALSE;
freerdp_settings_free_internal(_settings);
*_settings = *settings;
/* char* values */
#define CHECKED_STRDUP(name) \
if (settings->name && !(_settings->name = _strdup(settings->name))) \
goto out_fail
CHECKED_STRDUP(ServerHostname); /* 20 */
CHECKED_STRDUP(Username); /* 21 */
CHECKED_STRDUP(Password); /* 22 */
CHECKED_STRDUP(Domain); /* 23 */
CHECKED_STRDUP(PasswordHash); /* 24 */
CHECKED_STRDUP(AcceptedCert); /* 27 */
CHECKED_STRDUP(AlternateShell); /* 640 */
CHECKED_STRDUP(ShellWorkingDirectory); /* 641 */
CHECKED_STRDUP(ClientAddress); /* 769 */
CHECKED_STRDUP(ClientDir); /* 770 */
CHECKED_STRDUP(DynamicDSTTimeZoneKeyName); /* 897 */
CHECKED_STRDUP(RemoteAssistanceSessionId); /* 1025 */
CHECKED_STRDUP(RemoteAssistancePassStub); /* 1026 */
CHECKED_STRDUP(RemoteAssistancePassword); /* 1027 */
CHECKED_STRDUP(RemoteAssistanceRCTicket); /* 1028 */
CHECKED_STRDUP(AuthenticationServiceClass); /* 1098 */
CHECKED_STRDUP(AllowedTlsCiphers); /* 1101 */
CHECKED_STRDUP(NtlmSamFile); /* 1103 */
CHECKED_STRDUP(PreconnectionBlob); /* 1155 */
CHECKED_STRDUP(TargetNetAddress); /* 1217 */
CHECKED_STRDUP(RedirectionUsername); /* 1220 */
CHECKED_STRDUP(RedirectionDomain); /* 1221 */
CHECKED_STRDUP(RedirectionTargetFQDN); /* 1224 */
CHECKED_STRDUP(RedirectionTargetNetBiosName); /* 1225 */
CHECKED_STRDUP(RedirectionAcceptedCert); /* 1231 */
CHECKED_STRDUP(KerberosKdc); /* 1344 */
CHECKED_STRDUP(KerberosRealm); /* 1345 */
CHECKED_STRDUP(CertificateName); /* 1409 */
CHECKED_STRDUP(CertificateFile); /* 1410 */
CHECKED_STRDUP(PrivateKeyFile); /* 1411 */
CHECKED_STRDUP(RdpKeyFile); /* 1412 */
CHECKED_STRDUP(CertificateContent); /* 1416 */
CHECKED_STRDUP(PrivateKeyContent); /* 1417 */
CHECKED_STRDUP(RdpKeyContent); /* 1418 */
CHECKED_STRDUP(WindowTitle); /* 1542 */
CHECKED_STRDUP(WmClass); /* 1549 */
CHECKED_STRDUP(ComputerName); /* 1664 */
CHECKED_STRDUP(ConnectionFile); /* 1728 */
CHECKED_STRDUP(AssistanceFile); /* 1729 */
CHECKED_STRDUP(HomePath); /* 1792 */
CHECKED_STRDUP(ConfigPath); /* 1793 */
CHECKED_STRDUP(CurrentPath); /* 1794 */
CHECKED_STRDUP(DumpRemoteFxFile); /* 1858 */
CHECKED_STRDUP(PlayRemoteFxFile); /* 1859 */
CHECKED_STRDUP(GatewayHostname); /* 1986 */
CHECKED_STRDUP(GatewayUsername); /* 1987 */
CHECKED_STRDUP(GatewayPassword); /* 1988 */
CHECKED_STRDUP(GatewayDomain); /* 1989 */
CHECKED_STRDUP(GatewayAccessToken); /* 1997 */
CHECKED_STRDUP(GatewayAcceptedCert); /* 1998 */
CHECKED_STRDUP(ProxyHostname); /* 2016 */
CHECKED_STRDUP(RemoteApplicationName); /* 2113 */
CHECKED_STRDUP(RemoteApplicationIcon); /* 2114 */
CHECKED_STRDUP(RemoteApplicationProgram); /* 2115 */
CHECKED_STRDUP(RemoteApplicationFile); /* 2116 */
CHECKED_STRDUP(RemoteApplicationGuid); /* 2117 */
CHECKED_STRDUP(RemoteApplicationCmdLine); /* 2118 */
CHECKED_STRDUP(ImeFileName); /* 2628 */
CHECKED_STRDUP(DrivesToRedirect); /* 4290 */
CHECKED_STRDUP(ActionScript);
if (settings->LoadBalanceInfo && settings->LoadBalanceInfoLength)
{
@ -902,15 +783,6 @@ BOOL freerdp_settings_copy(rdpSettings* _settings, const rdpSettings* settings)
CopyMemory(_settings->ReceivedCapabilities, settings->ReceivedCapabilities, 32);
CopyMemory(_settings->OrderSupport, settings->OrderSupport, 32);
_settings->ClientHostname = _strdup(settings->ClientHostname);
if (!_settings->ClientHostname)
goto out_fail;
_settings->ClientProductId = _strdup(settings->ClientProductId);
if (!_settings->ClientProductId)
goto out_fail;
_settings->BitmapCacheV2CellInfo =
(BITMAP_CACHE_V2_CELL_INFO*)malloc(sizeof(BITMAP_CACHE_V2_CELL_INFO) * 6);
@ -933,16 +805,6 @@ BOOL freerdp_settings_copy(rdpSettings* _settings, const rdpSettings* settings)
CopyMemory(_settings->GlyphCache, settings->GlyphCache, sizeof(GLYPH_CACHE_DEFINITION) * 10);
CopyMemory(_settings->FragCache, settings->FragCache, sizeof(GLYPH_CACHE_DEFINITION));
if (settings->CertificateContent)
_settings->CertificateContent = _strdup(settings->CertificateContent);
if (settings->PrivateKeyContent)
_settings->PrivateKeyContent = _strdup(settings->PrivateKeyContent);
if (settings->RdpKeyContent)
_settings->RdpKeyContent = _strdup(settings->RdpKeyContent);
if (settings->CertificateAcceptedFingerprints)
_settings->CertificateAcceptedFingerprints =
_strdup(settings->CertificateAcceptedFingerprints);
_settings->ClientAutoReconnectCookie =
(ARC_CS_PRIVATE_PACKET*)malloc(sizeof(ARC_CS_PRIVATE_PACKET));
@ -1119,6 +981,55 @@ BOOL freerdp_settings_copy(rdpSettings* _settings, const rdpSettings* settings)
goto out_fail;
}
if (settings->ActionScript)
_settings->ActionScript = _strdup(settings->ActionScript);
rc = TRUE;
out_fail:
return rc;
}
BOOL freerdp_settings_copy(rdpSettings* _settings, const rdpSettings* settings)
{
BOOL rc;
if (!settings || !_settings)
return FALSE;
/* This is required to free all non string buffers */
freerdp_settings_free_internal(_settings);
/* This copies everything except allocated non string buffers. reset all allocated buffers to
* NULL to fix issues during cleanup */
rc = freerdp_settings_clone_keys(_settings, settings);
_settings->LoadBalanceInfo = NULL;
_settings->ServerRandom = NULL;
_settings->ClientRandom = NULL;
_settings->RdpServerCertificate = NULL;
_settings->RdpServerRsaKey = NULL;
_settings->ChannelDefArray = NULL;
_settings->MonitorDefArray = NULL;
_settings->MonitorIds = NULL;
_settings->ReceivedCapabilities = NULL;
_settings->OrderSupport = NULL;
_settings->BitmapCacheV2CellInfo = NULL;
_settings->GlyphCache = NULL;
_settings->FragCache = NULL;
_settings->ClientAutoReconnectCookie = NULL;
_settings->ServerAutoReconnectCookie = NULL;
_settings->ClientTimeZone = NULL;
_settings->RedirectionPassword = NULL;
_settings->RedirectionTsvUrl = NULL;
_settings->TargetNetAddresses = NULL;
_settings->DeviceArray = NULL;
_settings->StaticChannelArray = NULL;
_settings->DynamicChannelArray = NULL;
_settings->ActionScript = NULL;
if (!rc)
goto out_fail;
/* Begin copying */
if (!freerdp_settings_int_buffer_copy(_settings, settings))
goto out_fail;
return TRUE;
out_fail:
freerdp_settings_free_internal(_settings);
@ -1134,13 +1045,7 @@ rdpSettings* freerdp_settings_clone(const rdpSettings* settings)
return _settings;
out_fail:
/* In case any memory allocation failed during clone, some bytes might leak.
*
* freerdp_settings_free can't be reliable used at this point since it could
* free memory of pointers copied by CopyMemory and detecting and freeing
* each allocation separately is quite painful.
*/
free(_settings);
freerdp_settings_free(_settings);
return NULL;
}
#ifdef _WIN32

View File

@ -26,5 +26,10 @@
#include <freerdp/api.h>
FREERDP_LOCAL BOOL freerdp_settings_set_default_order_support(rdpSettings* settings);
FREERDP_LOCAL BOOL freerdp_settings_set_pointer(rdpSettings* dst, size_t index, const void* ptr);
FREERDP_LOCAL BOOL freerdp_settings_clone_keys(rdpSettings* dst, const rdpSettings* src);
FREERDP_LOCAL void freerdp_settings_free_keys(rdpSettings* dst, BOOL cleanup);
FREERDP_LOCAL BOOL freerdp_settings_set_string_(rdpSettings* settings, size_t id, const char* val,
BOOL cleanup);
#endif /* FREERDP_LIB_CORE_SETTINGS_H */

View File

@ -6,7 +6,8 @@ int TestSettings(int argc, char* argv[])
int rc = -1;
size_t x;
rdpSettings* settings = NULL;
rdpSettings* cloned;
rdpSettings* cloned = NULL;
rdpSettings* cloned2 = NULL;
WINPR_UNUSED(argc);
WINPR_UNUSED(argv);
settings = freerdp_settings_new(0);
@ -17,24 +18,29 @@ int TestSettings(int argc, char* argv[])
return -1;
}
settings->Username = _strdup("abcdefg");
settings->Password = _strdup("xyz");
if (!freerdp_settings_set_string(settings, FreeRDP_Username, "abcdefg"))
goto fail;
if (!freerdp_settings_set_string(settings, FreeRDP_Password, "xyz"))
goto fail;
cloned = freerdp_settings_clone(settings);
if (!cloned)
{
printf("Problem cloning settings\n");
freerdp_settings_free(settings);
return -1;
}
goto fail;
#if defined(have_bool_list_indices)
for (x = 0; x < ARRAYSIZE(bool_list_indices); x++)
{
const size_t key = bool_list_indices[x];
const char* name = freerdp_settings_get_name_for_key(key);
const BOOL val = freerdp_settings_get_bool(settings, key);
const BOOL cval = freerdp_settings_get_bool(cloned, key);
if (val != cval)
{
printf("mismatch for key %s: %u -> copy %u\n", name, val, cval);
goto fail;
}
if (!freerdp_settings_set_bool(settings, key, val))
goto fail;
}
@ -45,8 +51,14 @@ int TestSettings(int argc, char* argv[])
for (x = 0; x < ARRAYSIZE(int16_list_indices); x++)
{
const size_t key = int16_list_indices[x];
const char* name = freerdp_settings_get_name_for_key(key);
const INT16 val = freerdp_settings_get_int16(settings, key);
const INT16 cval = freerdp_settings_get_int16(cloned, key);
if (val != cval)
{
printf("mismatch for key %s: %" PRId16 " -> copy %" PRId16 "\n", name, val, cval);
goto fail;
}
if (!freerdp_settings_set_int16(settings, key, val))
goto fail;
}
@ -57,8 +69,14 @@ int TestSettings(int argc, char* argv[])
for (x = 0; x < ARRAYSIZE(uint16_list_indices); x++)
{
const size_t key = uint16_list_indices[x];
const char* name = freerdp_settings_get_name_for_key(key);
const UINT16 val = freerdp_settings_get_uint16(settings, key);
const UINT16 cval = freerdp_settings_get_uint16(cloned, key);
if (val != cval)
{
printf("mismatch for key %s: %" PRIu16 " -> copy %" PRIu16 "\n", name, val, cval);
goto fail;
}
if (!freerdp_settings_set_uint16(settings, key, val))
goto fail;
}
@ -69,8 +87,14 @@ int TestSettings(int argc, char* argv[])
for (x = 0; x < ARRAYSIZE(uint32_list_indices); x++)
{
const size_t key = uint32_list_indices[x];
const char* name = freerdp_settings_get_name_for_key(key);
const UINT32 val = freerdp_settings_get_uint32(settings, key);
const UINT32 cval = freerdp_settings_get_uint32(cloned, key);
if (val != cval)
{
printf("mismatch for key %s: %" PRIu32 " -> copy %" PRIu32 "\n", name, val, cval);
goto fail;
}
if (!freerdp_settings_set_uint32(settings, key, val))
goto fail;
}
@ -81,8 +105,14 @@ int TestSettings(int argc, char* argv[])
for (x = 0; x < ARRAYSIZE(int32_list_indices); x++)
{
const size_t key = int32_list_indices[x];
const char* name = freerdp_settings_get_name_for_key(key);
const INT32 val = freerdp_settings_get_int32(settings, key);
const INT32 cval = freerdp_settings_get_int32(cloned, key);
if (val != cval)
{
printf("mismatch for key %s: %" PRId32 " -> copy %" PRId32 "\n", name, val, cval);
goto fail;
}
if (!freerdp_settings_set_int32(settings, key, val))
goto fail;
}
@ -93,8 +123,14 @@ int TestSettings(int argc, char* argv[])
for (x = 0; x < ARRAYSIZE(uint64_list_indices); x++)
{
const size_t key = uint64_list_indices[x];
const char* name = freerdp_settings_get_name_for_key(key);
const UINT64 val = freerdp_settings_get_uint64(settings, key);
const UINT64 cval = freerdp_settings_get_uint64(cloned, key);
if (val != cval)
{
printf("mismatch for key %s: %" PRIu64 " -> copy %" PRIu64 "\n", name, val, cval);
goto fail;
}
if (!freerdp_settings_set_uint64(settings, key, val))
goto fail;
}
@ -105,8 +141,14 @@ int TestSettings(int argc, char* argv[])
for (x = 0; x < ARRAYSIZE(int64_list_indices); x++)
{
const size_t key = int64_list_indices[x];
const char* name = freerdp_settings_get_name_for_key(key);
const INT64 val = freerdp_settings_get_int64(settings, key);
const INT64 cval = freerdp_settings_get_int64(cloned, key);
if (val != cval)
{
printf("mismatch for key %s: %" PRId64 " -> copy %" PRId64 "\n", name, val, cval);
goto fail;
}
if (!freerdp_settings_set_int64(settings, key, val))
goto fail;
}
@ -119,7 +161,14 @@ int TestSettings(int argc, char* argv[])
const size_t key = string_list_indices[x];
const char val[] = "test-string";
const char* res;
const char* name = freerdp_settings_get_name_for_key(key);
const char* oval = freerdp_settings_get_string(settings, key);
const char* cval = freerdp_settings_get_string(cloned, key);
if ((oval != cval) && (strcmp(oval, cval) != 0))
{
printf("mismatch for key %s: %s -> copy %s\n", name, oval, cval);
goto fail;
}
if (!freerdp_settings_set_string(settings, key, val))
goto fail;
@ -139,9 +188,16 @@ int TestSettings(int argc, char* argv[])
}
#endif
cloned2 = freerdp_settings_clone(settings);
if (!cloned2)
goto fail;
if (!freerdp_settings_copy(cloned2, cloned))
goto fail;
rc = 0;
fail:
freerdp_settings_free(cloned);
freerdp_settings_free(cloned2);
freerdp_settings_free(settings);
return rc;
}

View File

@ -49,6 +49,103 @@ def write_str(f, entry_dict):
for val in values:
write_str_case(f, entry_types.index(entry_type), val)
f.write('};\n\n')
f.write('\n')
f.write('BOOL freerdp_settings_clone_keys(rdpSettings* dst, const rdpSettings* src)\n')
f.write('{\n')
f.write('\tsize_t x;\n')
f.write('\tfor(x=0; x<ARRAYSIZE(settings_map); x++)\n')
f.write('\t{\n')
f.write('\t\tconst struct settings_str_entry* cur = &settings_map[x];\n')
f.write('\t\tswitch(cur->type)\n')
f.write('\t\t{\n')
f.write('\t\t\tcase 0: /* bool */\n')
f.write('\t\t\t{\n')
f.write('\t\t\t\tBOOL sval = freerdp_settings_get_bool(src, cur->id);\n')
f.write('\t\t\t\tif (!freerdp_settings_set_bool(dst, cur->id, sval))\n')
f.write('\t\t\t\t\treturn FALSE;\n')
f.write('\t\t\t}\n')
f.write('\t\t\tbreak;\n')
f.write('\t\t\tcase 1: /* UINT16 */\n')
f.write('\t\t\t{\n')
f.write('\t\t\t\tUINT16 sval = freerdp_settings_get_uint16(src, cur->id);\n')
f.write('\t\t\t\tif (!freerdp_settings_set_uint16(dst, cur->id, sval))\n')
f.write('\t\t\t\t\treturn FALSE;\n')
f.write('\t\t\t}\n')
f.write('\t\t\tbreak;\n')
f.write('\t\t\tcase 2: /* INT16 */\n')
f.write('\t\t\t{\n')
f.write('\t\t\t\tINT16 sval = freerdp_settings_get_int16(src, cur->id);\n')
f.write('\t\t\t\tif (!freerdp_settings_set_int16(dst, cur->id, sval))\n')
f.write('\t\t\t\t\treturn FALSE;\n')
f.write('\t\t\t}\n')
f.write('\t\t\tbreak;\n')
f.write('\t\t\tcase 3: /* UINT32 */\n')
f.write('\t\t\t{\n')
f.write('\t\t\t\tUINT32 sval = freerdp_settings_get_uint32(src, cur->id);\n')
f.write('\t\t\t\tif (!freerdp_settings_set_uint32(dst, cur->id, sval))\n')
f.write('\t\t\t\t\treturn FALSE;\n')
f.write('\t\t\t}\n')
f.write('\t\t\tbreak;\n')
f.write('\t\t\tcase 4: /* INT32 */\n')
f.write('\t\t\t{\n')
f.write('\t\t\t\tINT32 sval = freerdp_settings_get_int32(src, cur->id);\n')
f.write('\t\t\t\tif (!freerdp_settings_set_int32(dst, cur->id, sval))\n')
f.write('\t\t\t\t\treturn FALSE;\n')
f.write('\t\t\t}\n')
f.write('\t\t\tbreak;\n')
f.write('\t\t\tcase 5: /* UINT64 */\n')
f.write('\t\t\t{\n')
f.write('\t\t\t\tUINT64 sval = freerdp_settings_get_uint64(src, cur->id);\n')
f.write('\t\t\t\tif (!freerdp_settings_set_uint64(dst, cur->id, sval))\n')
f.write('\t\t\t\t\treturn FALSE;\n')
f.write('\t\t\t}\n')
f.write('\t\t\tbreak;\n')
f.write('\t\t\tcase 6: /* INT64 */\n')
f.write('\t\t\t{\n')
f.write('\t\t\t\tINT64 sval = freerdp_settings_get_int64(src, cur->id);\n')
f.write('\t\t\t\tif (!freerdp_settings_set_int64(dst, cur->id, sval))\n')
f.write('\t\t\t\t\treturn FALSE;\n')
f.write('\t\t\t}\n')
f.write('\t\t\tbreak;\n')
f.write('\t\t\tcase 7: /* strings */\n')
f.write('\t\t\t{\n')
f.write('\t\t\t\tconst char* sval = freerdp_settings_get_string(src, cur->id);\n')
f.write('\t\t\t\tif (!freerdp_settings_set_string_(dst, cur->id, sval, FALSE))\n')
f.write('\t\t\t\t\treturn FALSE;\n')
f.write('\t\t\t}\n')
f.write('\t\t\tbreak;\n')
f.write('\t\t\tcase 8: /* pointer */\n')
f.write('\t\t\t{\n')
f.write('\t\t\t\tconst void* sval = freerdp_settings_get_pointer(src, cur->id);\n')
f.write('\t\t\t\tif (!freerdp_settings_set_pointer(dst, cur->id, sval))\n')
f.write('\t\t\t\t\treturn FALSE;\n')
f.write('\t\t\t}\n')
f.write('\t\t\tbreak;\n')
f.write('\t\t}\n')
f.write('\t}\n')
f.write('\treturn TRUE;\n')
f.write('}\n')
f.write('\n')
f.write('void freerdp_settings_free_keys(rdpSettings* dst, BOOL cleanup)\n')
f.write('{\n')
f.write('\tsize_t x;\n')
f.write('\tfor(x=0; x<ARRAYSIZE(settings_map); x++)\n')
f.write('\t{\n')
f.write('\t\tconst struct settings_str_entry* cur = &settings_map[x];\n')
f.write('\t\tswitch(cur->type)\n')
f.write('\t\t{\n')
f.write('\t\t\tcase 7: /* strings */\n')
f.write('\t\t\t\tfreerdp_settings_set_string_(dst, cur->id, NULL, cleanup);\n')
f.write('\t\t\tbreak;\n')
f.write('\t\t\tcase 8: /* pointer */\n')
f.write('\t\t\t\tfreerdp_settings_set_pointer(dst, cur->id, NULL);\n')
f.write('\t\t\tbreak;\n')
f.write('\t\t}\n')
f.write('\t}\n')
f.write('}\n')
f.write('\n')
f.write('SSIZE_T freerdp_settings_get_key_for_name(const char* value)\n')
f.write('{\n')
f.write('\tsize_t x;\n')
@ -130,11 +227,15 @@ def write_getter(f, entry_dict, entry_type, entry_name):
def write_setter_case(f, val, isString, isPointer):
f.write('\t\tcase FreeRDP_' + val + ':\n')
if not isString:
if isPointer:
f.write('\t\t\tsettings->' + val + ' = (void*)val;\n')
f.write('\t\t\tbreak;\n\n')
elif not isString:
f.write('\t\t\tsettings->' + val + ' = val;\n')
f.write('\t\t\tbreak;\n\n')
else:
f.write('\t\t\tfree(settings->' + val + ');\n')
f.write('\t\t\tif (cleanup)\n')
f.write('\t\t\t\tfree(settings->' + val + ');\n')
f.write('\t\t\tsettings->' + val + ' = (val ? _strdup(val) : NULL);\n')
f.write('\t\t\treturn (!val || settings->' + val + ' != NULL);\n\n')
@ -143,13 +244,20 @@ def write_setter(f, entry_dict, entry_type, entry_name):
isPointer = 'pointer' in entry_name
values = get_values(entry_dict, entry_type)
f.write('BOOL freerdp_settings_set_' + entry_name.lower() + '(rdpSettings* settings, size_t id, ')
f.write('BOOL freerdp_settings_set_' + entry_name.lower())
if isString:
f.write('_')
f.write('(rdpSettings* settings, size_t id, ')
if isString or isPointer:
f.write('const ')
if not isPointer:
f.write(entry_type + ' val)\n')
f.write(entry_type + ' val')
else:
f.write('void* val)\n')
f.write('void* val')
if isString:
f.write(', BOOL cleanup)\n')
else:
f.write(')\n')
f.write('{\n')
f.write('\tif (!settings)\n')
f.write('\t\treturn FALSE;\n\n')
@ -164,6 +272,20 @@ def write_setter(f, entry_dict, entry_type, entry_name):
f.write('\t}\n')
f.write('\treturn TRUE;\n')
f.write('}\n\n')
f.write('\n')
if isString:
f.write('BOOL freerdp_settings_set_' + entry_name.lower() + '(rdpSettings* settings, size_t id, ')
if isString or isPointer:
f.write('const ')
if not isPointer:
f.write(entry_type + ' val')
else:
f.write('void* val')
f.write(')\n')
f.write('{\n')
f.write('\treturn freerdp_settings_set_' + entry_name.lower() + '_(settings, id, val, TRUE);\n')
f.write('}\n')
f.write('\n')
name = os.path.dirname(os.path.realpath(__file__))
begin = "WARNING: this data structure is carefully padded for ABI stability!"
@ -230,7 +352,7 @@ try:
write_getter(f, getter_list, 'char*', 'string')
write_setter(f, setter_list, 'char*', 'string')
write_getter(f, getter_list, '*', 'pointer')
# write_setter(f, setter_list, '*', 'pointer')
write_setter(f, setter_list, '*', 'pointer')
f.write('\n')
@ -238,6 +360,7 @@ try:
f.write('/* Generated by ' + '' + ' */\n\n')
f.write('#include <freerdp/settings.h>\n')
f.write('#include <freerdp/log.h>\n\n')
f.write('#include "../core/settings.h"\n\n')
f.write('#define TAG FREERDP_TAG("common.settings")\n\n')
getter_list = dict(type_list)