[core,settings] update getter/setter generation

fix issues with const and non const string pointer update
This commit is contained in:
akallabeth 2023-01-30 14:18:24 +01:00 committed by Martin Fleisz
parent 3f80e6a5ba
commit da42a2141e
5 changed files with 491 additions and 151 deletions

View File

@ -1570,7 +1570,7 @@ void* freerdp_settings_get_pointer_array_writable(const rdpSettings* settings, s
max = freerdp_settings_get_uint32(settings, FreeRDP_TargetNetAddressCount); max = freerdp_settings_get_uint32(settings, FreeRDP_TargetNetAddressCount);
if (offset >= max) if (offset >= max)
goto fail; goto fail;
return settings->TargetNetPorts[offset]; return (void*)(uintptr_t)settings->TargetNetPorts[offset];
case FreeRDP_ClientTimeZone: case FreeRDP_ClientTimeZone:
max = 1; max = 1;
if (offset >= max) if (offset >= max)
@ -2023,7 +2023,7 @@ BOOL freerdp_settings_set_string_from_utf16(rdpSettings* settings, size_t id, co
WINPR_ASSERT(settings); WINPR_ASSERT(settings);
if (!param) if (!param)
return freerdp_settings_set_string_(settings, id, NULL, 0, TRUE, TRUE); return freerdp_settings_set_string_copy_(settings, id, NULL, 0, TRUE);
size_t len = 0; size_t len = 0;
@ -2031,7 +2031,7 @@ BOOL freerdp_settings_set_string_from_utf16(rdpSettings* settings, size_t id, co
if (!str && (len != 0)) if (!str && (len != 0))
return FALSE; return FALSE;
return freerdp_settings_set_string_(settings, id, str, len, FALSE, TRUE); return freerdp_settings_set_string_(settings, id, str, len);
} }
BOOL freerdp_settings_set_string_from_utf16N(rdpSettings* settings, size_t id, const WCHAR* param, BOOL freerdp_settings_set_string_from_utf16N(rdpSettings* settings, size_t id, const WCHAR* param,
@ -2042,7 +2042,7 @@ BOOL freerdp_settings_set_string_from_utf16N(rdpSettings* settings, size_t id, c
WINPR_ASSERT(settings); WINPR_ASSERT(settings);
if (!param) if (!param)
return freerdp_settings_set_string_(settings, id, NULL, length, TRUE, TRUE); return freerdp_settings_set_string_copy_(settings, id, NULL, length, TRUE);
char* str = ConvertWCharNToUtf8Alloc(param, length, &len); char* str = ConvertWCharNToUtf8Alloc(param, length, &len);
if (!str && (length != 0)) if (!str && (length != 0))
@ -2054,7 +2054,7 @@ BOOL freerdp_settings_set_string_from_utf16N(rdpSettings* settings, size_t id, c
return FALSE; return FALSE;
} }
return freerdp_settings_set_string_(settings, id, str, len, FALSE, TRUE); return freerdp_settings_set_string_(settings, id, str, len);
} }
WCHAR* freerdp_settings_get_string_as_utf16(const rdpSettings* settings, size_t id, WCHAR* freerdp_settings_get_string_as_utf16(const rdpSettings* settings, size_t id,

View File

@ -8,25 +8,45 @@
#define TAG FREERDP_TAG("common.settings") #define TAG FREERDP_TAG("common.settings")
static BOOL update_string(char** current, const char* next, size_t next_len, BOOL copy, static void free_string(char** current, BOOL cleanup)
BOOL cleanup)
{ {
if (cleanup) if (cleanup)
{ {
if (*current) if (*current)
memset(*current, 0, strlen(*current)); memset(*current, 0, strlen(*current));
free(*current); free(*current);
(*current) = NULL;
}
} }
static BOOL alloc_empty_string(char** current, const char* next, size_t next_len)
{
if (!next && (next_len > 0)) if (!next && (next_len > 0))
{ {
*current = calloc(next_len, 1); *current = calloc(next_len, 1);
return (*current != NULL); return (*current != NULL);
} }
return FALSE;
}
static BOOL update_string_copy_(char** current, const char* next, size_t next_len, BOOL cleanup)
{
free_string(current, cleanup);
if (alloc_empty_string(current, next, next_len))
return TRUE;
if (copy)
*current = (next ? strndup(next, next_len) : NULL); *current = (next ? strndup(next, next_len) : NULL);
else return !next || (*current != NULL);
}
static BOOL update_string_(char** current, char* next, size_t next_len)
{
free_string(current, TRUE);
if (alloc_empty_string(current, next, next_len))
return TRUE;
*current = next; *current = next;
return !next || (*current != NULL); return !next || (*current != NULL);
} }
@ -3064,8 +3084,7 @@ char* freerdp_settings_get_string_writable(rdpSettings* settings, size_t id)
} }
} }
BOOL freerdp_settings_set_string_(rdpSettings* settings, size_t id, const char* val, size_t len, BOOL freerdp_settings_set_string_(rdpSettings* settings, size_t id, char* val, size_t len)
BOOL copy, BOOL cleanup)
{ {
union union
{ {
@ -3081,274 +3100,271 @@ BOOL freerdp_settings_set_string_(rdpSettings* settings, size_t id, const char*
switch (id) switch (id)
{ {
case FreeRDP_AcceptedCert: case FreeRDP_AcceptedCert:
return update_string(&settings->AcceptedCert, cnv.cc, len, copy, cleanup); return update_string_(&settings->AcceptedCert, cnv.c, len);
case FreeRDP_ActionScript: case FreeRDP_ActionScript:
return update_string(&settings->ActionScript, cnv.cc, len, copy, cleanup); return update_string_(&settings->ActionScript, cnv.c, len);
case FreeRDP_AllowedTlsCiphers: case FreeRDP_AllowedTlsCiphers:
return update_string(&settings->AllowedTlsCiphers, cnv.cc, len, copy, cleanup); return update_string_(&settings->AllowedTlsCiphers, cnv.c, len);
case FreeRDP_AlternateShell: case FreeRDP_AlternateShell:
return update_string(&settings->AlternateShell, cnv.cc, len, copy, cleanup); return update_string_(&settings->AlternateShell, cnv.c, len);
case FreeRDP_AssistanceFile: case FreeRDP_AssistanceFile:
return update_string(&settings->AssistanceFile, cnv.cc, len, copy, cleanup); return update_string_(&settings->AssistanceFile, cnv.c, len);
case FreeRDP_AuthenticationPackageList: case FreeRDP_AuthenticationPackageList:
return update_string(&settings->AuthenticationPackageList, cnv.cc, len, copy, cleanup); return update_string_(&settings->AuthenticationPackageList, cnv.c, len);
case FreeRDP_AuthenticationServiceClass: case FreeRDP_AuthenticationServiceClass:
return update_string(&settings->AuthenticationServiceClass, cnv.cc, len, copy, cleanup); return update_string_(&settings->AuthenticationServiceClass, cnv.c, len);
case FreeRDP_BitmapCachePersistFile: case FreeRDP_BitmapCachePersistFile:
return update_string(&settings->BitmapCachePersistFile, cnv.cc, len, copy, cleanup); return update_string_(&settings->BitmapCachePersistFile, cnv.c, len);
case FreeRDP_CardName: case FreeRDP_CardName:
return update_string(&settings->CardName, cnv.cc, len, copy, cleanup); return update_string_(&settings->CardName, cnv.c, len);
case FreeRDP_CertificateAcceptedFingerprints: case FreeRDP_CertificateAcceptedFingerprints:
return update_string(&settings->CertificateAcceptedFingerprints, cnv.cc, len, copy, return update_string_(&settings->CertificateAcceptedFingerprints, cnv.c, len);
cleanup);
case FreeRDP_CertificateContent: case FreeRDP_CertificateContent:
return update_string(&settings->CertificateContent, cnv.cc, len, copy, cleanup); return update_string_(&settings->CertificateContent, cnv.c, len);
case FreeRDP_CertificateFile: case FreeRDP_CertificateFile:
return update_string(&settings->CertificateFile, cnv.cc, len, copy, cleanup); return update_string_(&settings->CertificateFile, cnv.c, len);
case FreeRDP_CertificateName: case FreeRDP_CertificateName:
return update_string(&settings->CertificateName, cnv.cc, len, copy, cleanup); return update_string_(&settings->CertificateName, cnv.c, len);
case FreeRDP_ClientAddress: case FreeRDP_ClientAddress:
return update_string(&settings->ClientAddress, cnv.cc, len, copy, cleanup); return update_string_(&settings->ClientAddress, cnv.c, len);
case FreeRDP_ClientDir: case FreeRDP_ClientDir:
return update_string(&settings->ClientDir, cnv.cc, len, copy, cleanup); return update_string_(&settings->ClientDir, cnv.c, len);
case FreeRDP_ClientHostname: case FreeRDP_ClientHostname:
return update_string(&settings->ClientHostname, cnv.cc, len, copy, cleanup); return update_string_(&settings->ClientHostname, cnv.c, len);
case FreeRDP_ClientProductId: case FreeRDP_ClientProductId:
return update_string(&settings->ClientProductId, cnv.cc, len, copy, cleanup); return update_string_(&settings->ClientProductId, cnv.c, len);
case FreeRDP_ComputerName: case FreeRDP_ComputerName:
return update_string(&settings->ComputerName, cnv.cc, len, copy, cleanup); return update_string_(&settings->ComputerName, cnv.c, len);
case FreeRDP_ConfigPath: case FreeRDP_ConfigPath:
return update_string(&settings->ConfigPath, cnv.cc, len, copy, cleanup); return update_string_(&settings->ConfigPath, cnv.c, len);
case FreeRDP_ConnectionFile: case FreeRDP_ConnectionFile:
return update_string(&settings->ConnectionFile, cnv.cc, len, copy, cleanup); return update_string_(&settings->ConnectionFile, cnv.c, len);
case FreeRDP_ContainerName: case FreeRDP_ContainerName:
return update_string(&settings->ContainerName, cnv.cc, len, copy, cleanup); return update_string_(&settings->ContainerName, cnv.c, len);
case FreeRDP_CspName: case FreeRDP_CspName:
return update_string(&settings->CspName, cnv.cc, len, copy, cleanup); return update_string_(&settings->CspName, cnv.c, len);
case FreeRDP_CurrentPath: case FreeRDP_CurrentPath:
return update_string(&settings->CurrentPath, cnv.cc, len, copy, cleanup); return update_string_(&settings->CurrentPath, cnv.c, len);
case FreeRDP_Domain: case FreeRDP_Domain:
return update_string(&settings->Domain, cnv.cc, len, copy, cleanup); return update_string_(&settings->Domain, cnv.c, len);
case FreeRDP_DrivesToRedirect: case FreeRDP_DrivesToRedirect:
return update_string(&settings->DrivesToRedirect, cnv.cc, len, copy, cleanup); return update_string_(&settings->DrivesToRedirect, cnv.c, len);
case FreeRDP_DumpRemoteFxFile: case FreeRDP_DumpRemoteFxFile:
return update_string(&settings->DumpRemoteFxFile, cnv.cc, len, copy, cleanup); return update_string_(&settings->DumpRemoteFxFile, cnv.c, len);
case FreeRDP_DynamicDSTTimeZoneKeyName: case FreeRDP_DynamicDSTTimeZoneKeyName:
return update_string(&settings->DynamicDSTTimeZoneKeyName, cnv.cc, len, copy, cleanup); return update_string_(&settings->DynamicDSTTimeZoneKeyName, cnv.c, len);
case FreeRDP_GatewayAcceptedCert: case FreeRDP_GatewayAcceptedCert:
return update_string(&settings->GatewayAcceptedCert, cnv.cc, len, copy, cleanup); return update_string_(&settings->GatewayAcceptedCert, cnv.c, len);
case FreeRDP_GatewayAccessToken: case FreeRDP_GatewayAccessToken:
return update_string(&settings->GatewayAccessToken, cnv.cc, len, copy, cleanup); return update_string_(&settings->GatewayAccessToken, cnv.c, len);
case FreeRDP_GatewayDomain: case FreeRDP_GatewayDomain:
return update_string(&settings->GatewayDomain, cnv.cc, len, copy, cleanup); return update_string_(&settings->GatewayDomain, cnv.c, len);
case FreeRDP_GatewayHostname: case FreeRDP_GatewayHostname:
return update_string(&settings->GatewayHostname, cnv.cc, len, copy, cleanup); return update_string_(&settings->GatewayHostname, cnv.c, len);
case FreeRDP_GatewayPassword: case FreeRDP_GatewayPassword:
return update_string(&settings->GatewayPassword, cnv.cc, len, copy, cleanup); return update_string_(&settings->GatewayPassword, cnv.c, len);
case FreeRDP_GatewayUsername: case FreeRDP_GatewayUsername:
return update_string(&settings->GatewayUsername, cnv.cc, len, copy, cleanup); return update_string_(&settings->GatewayUsername, cnv.c, len);
case FreeRDP_HomePath: case FreeRDP_HomePath:
return update_string(&settings->HomePath, cnv.cc, len, copy, cleanup); return update_string_(&settings->HomePath, cnv.c, len);
case FreeRDP_ImeFileName: case FreeRDP_ImeFileName:
return update_string(&settings->ImeFileName, cnv.cc, len, copy, cleanup); return update_string_(&settings->ImeFileName, cnv.c, len);
case FreeRDP_KerberosArmor: case FreeRDP_KerberosArmor:
return update_string(&settings->KerberosArmor, cnv.cc, len, copy, cleanup); return update_string_(&settings->KerberosArmor, cnv.c, len);
case FreeRDP_KerberosCache: case FreeRDP_KerberosCache:
return update_string(&settings->KerberosCache, cnv.cc, len, copy, cleanup); return update_string_(&settings->KerberosCache, cnv.c, len);
case FreeRDP_KerberosKdcUrl: case FreeRDP_KerberosKdcUrl:
return update_string(&settings->KerberosKdcUrl, cnv.cc, len, copy, cleanup); return update_string_(&settings->KerberosKdcUrl, cnv.c, len);
case FreeRDP_KerberosKeytab: case FreeRDP_KerberosKeytab:
return update_string(&settings->KerberosKeytab, cnv.cc, len, copy, cleanup); return update_string_(&settings->KerberosKeytab, cnv.c, len);
case FreeRDP_KerberosLifeTime: case FreeRDP_KerberosLifeTime:
return update_string(&settings->KerberosLifeTime, cnv.cc, len, copy, cleanup); return update_string_(&settings->KerberosLifeTime, cnv.c, len);
case FreeRDP_KerberosRealm: case FreeRDP_KerberosRealm:
return update_string(&settings->KerberosRealm, cnv.cc, len, copy, cleanup); return update_string_(&settings->KerberosRealm, cnv.c, len);
case FreeRDP_KerberosRenewableLifeTime: case FreeRDP_KerberosRenewableLifeTime:
return update_string(&settings->KerberosRenewableLifeTime, cnv.cc, len, copy, cleanup); return update_string_(&settings->KerberosRenewableLifeTime, cnv.c, len);
case FreeRDP_KerberosStartTime: case FreeRDP_KerberosStartTime:
return update_string(&settings->KerberosStartTime, cnv.cc, len, copy, cleanup); return update_string_(&settings->KerberosStartTime, cnv.c, len);
case FreeRDP_KeyboardRemappingList: case FreeRDP_KeyboardRemappingList:
return update_string(&settings->KeyboardRemappingList, cnv.cc, len, copy, cleanup); return update_string_(&settings->KeyboardRemappingList, cnv.c, len);
case FreeRDP_NtlmSamFile: case FreeRDP_NtlmSamFile:
return update_string(&settings->NtlmSamFile, cnv.cc, len, copy, cleanup); return update_string_(&settings->NtlmSamFile, cnv.c, len);
case FreeRDP_Password: case FreeRDP_Password:
return update_string(&settings->Password, cnv.cc, len, copy, cleanup); return update_string_(&settings->Password, cnv.c, len);
case FreeRDP_PasswordHash: case FreeRDP_PasswordHash:
return update_string(&settings->PasswordHash, cnv.cc, len, copy, cleanup); return update_string_(&settings->PasswordHash, cnv.c, len);
case FreeRDP_Pkcs11Module: case FreeRDP_Pkcs11Module:
return update_string(&settings->Pkcs11Module, cnv.cc, len, copy, cleanup); return update_string_(&settings->Pkcs11Module, cnv.c, len);
case FreeRDP_PkinitAnchors: case FreeRDP_PkinitAnchors:
return update_string(&settings->PkinitAnchors, cnv.cc, len, copy, cleanup); return update_string_(&settings->PkinitAnchors, cnv.c, len);
case FreeRDP_PlayRemoteFxFile: case FreeRDP_PlayRemoteFxFile:
return update_string(&settings->PlayRemoteFxFile, cnv.cc, len, copy, cleanup); return update_string_(&settings->PlayRemoteFxFile, cnv.c, len);
case FreeRDP_PreconnectionBlob: case FreeRDP_PreconnectionBlob:
return update_string(&settings->PreconnectionBlob, cnv.cc, len, copy, cleanup); return update_string_(&settings->PreconnectionBlob, cnv.c, len);
case FreeRDP_PrivateKeyContent: case FreeRDP_PrivateKeyContent:
return update_string(&settings->PrivateKeyContent, cnv.cc, len, copy, cleanup); return update_string_(&settings->PrivateKeyContent, cnv.c, len);
case FreeRDP_PrivateKeyFile: case FreeRDP_PrivateKeyFile:
return update_string(&settings->PrivateKeyFile, cnv.cc, len, copy, cleanup); return update_string_(&settings->PrivateKeyFile, cnv.c, len);
case FreeRDP_ProxyHostname: case FreeRDP_ProxyHostname:
return update_string(&settings->ProxyHostname, cnv.cc, len, copy, cleanup); return update_string_(&settings->ProxyHostname, cnv.c, len);
case FreeRDP_ProxyPassword: case FreeRDP_ProxyPassword:
return update_string(&settings->ProxyPassword, cnv.cc, len, copy, cleanup); return update_string_(&settings->ProxyPassword, cnv.c, len);
case FreeRDP_ProxyUsername: case FreeRDP_ProxyUsername:
return update_string(&settings->ProxyUsername, cnv.cc, len, copy, cleanup); return update_string_(&settings->ProxyUsername, cnv.c, len);
case FreeRDP_RDP2TCPArgs: case FreeRDP_RDP2TCPArgs:
return update_string(&settings->RDP2TCPArgs, cnv.cc, len, copy, cleanup); return update_string_(&settings->RDP2TCPArgs, cnv.c, len);
case FreeRDP_ReaderName: case FreeRDP_ReaderName:
return update_string(&settings->ReaderName, cnv.cc, len, copy, cleanup); return update_string_(&settings->ReaderName, cnv.c, len);
case FreeRDP_RedirectionAcceptedCert: case FreeRDP_RedirectionAcceptedCert:
return update_string(&settings->RedirectionAcceptedCert, cnv.cc, len, copy, cleanup); return update_string_(&settings->RedirectionAcceptedCert, cnv.c, len);
case FreeRDP_RedirectionDomain: case FreeRDP_RedirectionDomain:
return update_string(&settings->RedirectionDomain, cnv.cc, len, copy, cleanup); return update_string_(&settings->RedirectionDomain, cnv.c, len);
case FreeRDP_RedirectionTargetFQDN: case FreeRDP_RedirectionTargetFQDN:
return update_string(&settings->RedirectionTargetFQDN, cnv.cc, len, copy, cleanup); return update_string_(&settings->RedirectionTargetFQDN, cnv.c, len);
case FreeRDP_RedirectionTargetNetBiosName: case FreeRDP_RedirectionTargetNetBiosName:
return update_string(&settings->RedirectionTargetNetBiosName, cnv.cc, len, copy, return update_string_(&settings->RedirectionTargetNetBiosName, cnv.c, len);
cleanup);
case FreeRDP_RedirectionUsername: case FreeRDP_RedirectionUsername:
return update_string(&settings->RedirectionUsername, cnv.cc, len, copy, cleanup); return update_string_(&settings->RedirectionUsername, cnv.c, len);
case FreeRDP_RemoteApplicationCmdLine: case FreeRDP_RemoteApplicationCmdLine:
return update_string(&settings->RemoteApplicationCmdLine, cnv.cc, len, copy, cleanup); return update_string_(&settings->RemoteApplicationCmdLine, cnv.c, len);
case FreeRDP_RemoteApplicationFile: case FreeRDP_RemoteApplicationFile:
return update_string(&settings->RemoteApplicationFile, cnv.cc, len, copy, cleanup); return update_string_(&settings->RemoteApplicationFile, cnv.c, len);
case FreeRDP_RemoteApplicationGuid: case FreeRDP_RemoteApplicationGuid:
return update_string(&settings->RemoteApplicationGuid, cnv.cc, len, copy, cleanup); return update_string_(&settings->RemoteApplicationGuid, cnv.c, len);
case FreeRDP_RemoteApplicationIcon: case FreeRDP_RemoteApplicationIcon:
return update_string(&settings->RemoteApplicationIcon, cnv.cc, len, copy, cleanup); return update_string_(&settings->RemoteApplicationIcon, cnv.c, len);
case FreeRDP_RemoteApplicationName: case FreeRDP_RemoteApplicationName:
return update_string(&settings->RemoteApplicationName, cnv.cc, len, copy, cleanup); return update_string_(&settings->RemoteApplicationName, cnv.c, len);
case FreeRDP_RemoteApplicationProgram: case FreeRDP_RemoteApplicationProgram:
return update_string(&settings->RemoteApplicationProgram, cnv.cc, len, copy, cleanup); return update_string_(&settings->RemoteApplicationProgram, cnv.c, len);
case FreeRDP_RemoteApplicationWorkingDir: case FreeRDP_RemoteApplicationWorkingDir:
return update_string(&settings->RemoteApplicationWorkingDir, cnv.cc, len, copy, return update_string_(&settings->RemoteApplicationWorkingDir, cnv.c, len);
cleanup);
case FreeRDP_RemoteAssistancePassStub: case FreeRDP_RemoteAssistancePassStub:
return update_string(&settings->RemoteAssistancePassStub, cnv.cc, len, copy, cleanup); return update_string_(&settings->RemoteAssistancePassStub, cnv.c, len);
case FreeRDP_RemoteAssistancePassword: case FreeRDP_RemoteAssistancePassword:
return update_string(&settings->RemoteAssistancePassword, cnv.cc, len, copy, cleanup); return update_string_(&settings->RemoteAssistancePassword, cnv.c, len);
case FreeRDP_RemoteAssistanceRCTicket: case FreeRDP_RemoteAssistanceRCTicket:
return update_string(&settings->RemoteAssistanceRCTicket, cnv.cc, len, copy, cleanup); return update_string_(&settings->RemoteAssistanceRCTicket, cnv.c, len);
case FreeRDP_RemoteAssistanceSessionId: case FreeRDP_RemoteAssistanceSessionId:
return update_string(&settings->RemoteAssistanceSessionId, cnv.cc, len, copy, cleanup); return update_string_(&settings->RemoteAssistanceSessionId, cnv.c, len);
case FreeRDP_ServerHostname: case FreeRDP_ServerHostname:
return update_string(&settings->ServerHostname, cnv.cc, len, copy, cleanup); return update_string_(&settings->ServerHostname, cnv.c, len);
case FreeRDP_ServerLicenseCompanyName: case FreeRDP_ServerLicenseCompanyName:
return update_string(&settings->ServerLicenseCompanyName, cnv.cc, len, copy, cleanup); return update_string_(&settings->ServerLicenseCompanyName, cnv.c, len);
case FreeRDP_ServerLicenseProductName: case FreeRDP_ServerLicenseProductName:
return update_string(&settings->ServerLicenseProductName, cnv.cc, len, copy, cleanup); return update_string_(&settings->ServerLicenseProductName, cnv.c, len);
case FreeRDP_ShellWorkingDirectory: case FreeRDP_ShellWorkingDirectory:
return update_string(&settings->ShellWorkingDirectory, cnv.cc, len, copy, cleanup); return update_string_(&settings->ShellWorkingDirectory, cnv.c, len);
case FreeRDP_SmartcardCertificate: case FreeRDP_SmartcardCertificate:
return update_string(&settings->SmartcardCertificate, cnv.cc, len, copy, cleanup); return update_string_(&settings->SmartcardCertificate, cnv.c, len);
case FreeRDP_SmartcardPrivateKey: case FreeRDP_SmartcardPrivateKey:
return update_string(&settings->SmartcardPrivateKey, cnv.cc, len, copy, cleanup); return update_string_(&settings->SmartcardPrivateKey, cnv.c, len);
case FreeRDP_SspiModule: case FreeRDP_SspiModule:
return update_string(&settings->SspiModule, cnv.cc, len, copy, cleanup); return update_string_(&settings->SspiModule, cnv.c, len);
case FreeRDP_TargetNetAddress: case FreeRDP_TargetNetAddress:
return update_string(&settings->TargetNetAddress, cnv.cc, len, copy, cleanup); return update_string_(&settings->TargetNetAddress, cnv.c, len);
case FreeRDP_TerminalDescriptor: case FreeRDP_TerminalDescriptor:
return update_string(&settings->TerminalDescriptor, cnv.cc, len, copy, cleanup); return update_string_(&settings->TerminalDescriptor, cnv.c, len);
case FreeRDP_TlsSecretsFile: case FreeRDP_TlsSecretsFile:
return update_string(&settings->TlsSecretsFile, cnv.cc, len, copy, cleanup); return update_string_(&settings->TlsSecretsFile, cnv.c, len);
case FreeRDP_TransportDumpFile: case FreeRDP_TransportDumpFile:
return update_string(&settings->TransportDumpFile, cnv.cc, len, copy, cleanup); return update_string_(&settings->TransportDumpFile, cnv.c, len);
case FreeRDP_UserSpecifiedServerName: case FreeRDP_UserSpecifiedServerName:
return update_string(&settings->UserSpecifiedServerName, cnv.cc, len, copy, cleanup); return update_string_(&settings->UserSpecifiedServerName, cnv.c, len);
case FreeRDP_Username: case FreeRDP_Username:
return update_string(&settings->Username, cnv.cc, len, copy, cleanup); return update_string_(&settings->Username, cnv.c, len);
case FreeRDP_WindowTitle: case FreeRDP_WindowTitle:
return update_string(&settings->WindowTitle, cnv.cc, len, copy, cleanup); return update_string_(&settings->WindowTitle, cnv.c, len);
case FreeRDP_WmClass: case FreeRDP_WmClass:
return update_string(&settings->WmClass, cnv.cc, len, copy, cleanup); return update_string_(&settings->WmClass, cnv.c, len);
default: default:
WLog_ERR(TAG, "Invalid key index %" PRIuz " [%s|%s]", id, WLog_ERR(TAG, "Invalid key index %" PRIuz " [%s|%s]", id,
@ -3361,7 +3377,7 @@ BOOL freerdp_settings_set_string_(rdpSettings* settings, size_t id, const char*
BOOL freerdp_settings_set_string_len(rdpSettings* settings, size_t id, const char* val, size_t len) BOOL freerdp_settings_set_string_len(rdpSettings* settings, size_t id, const char* val, size_t len)
{ {
return freerdp_settings_set_string_(settings, id, val, len, TRUE, TRUE); return freerdp_settings_set_string_copy_(settings, id, val, len, TRUE);
} }
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)
@ -3369,7 +3385,302 @@ BOOL freerdp_settings_set_string(rdpSettings* settings, size_t id, const char* v
size_t len = 0; size_t len = 0;
if (val) if (val)
len = strlen(val); len = strlen(val);
return freerdp_settings_set_string_(settings, id, val, len, TRUE, TRUE); return freerdp_settings_set_string_copy_(settings, id, val, len, TRUE);
}
BOOL freerdp_settings_set_string_copy_(rdpSettings* settings, size_t id, const char* val,
size_t len, BOOL cleanup)
{
union
{
void* v;
const void* cv;
char* c;
const char* cc;
} cnv;
WINPR_ASSERT(settings);
cnv.cc = val;
switch (id)
{
case FreeRDP_AcceptedCert:
return update_string_copy_(&settings->AcceptedCert, cnv.cc, len, cleanup);
case FreeRDP_ActionScript:
return update_string_copy_(&settings->ActionScript, cnv.cc, len, cleanup);
case FreeRDP_AllowedTlsCiphers:
return update_string_copy_(&settings->AllowedTlsCiphers, cnv.cc, len, cleanup);
case FreeRDP_AlternateShell:
return update_string_copy_(&settings->AlternateShell, cnv.cc, len, cleanup);
case FreeRDP_AssistanceFile:
return update_string_copy_(&settings->AssistanceFile, cnv.cc, len, cleanup);
case FreeRDP_AuthenticationPackageList:
return update_string_copy_(&settings->AuthenticationPackageList, cnv.cc, len, cleanup);
case FreeRDP_AuthenticationServiceClass:
return update_string_copy_(&settings->AuthenticationServiceClass, cnv.cc, len, cleanup);
case FreeRDP_BitmapCachePersistFile:
return update_string_copy_(&settings->BitmapCachePersistFile, cnv.cc, len, cleanup);
case FreeRDP_CardName:
return update_string_copy_(&settings->CardName, cnv.cc, len, cleanup);
case FreeRDP_CertificateAcceptedFingerprints:
return update_string_copy_(&settings->CertificateAcceptedFingerprints, cnv.cc, len,
cleanup);
case FreeRDP_CertificateContent:
return update_string_copy_(&settings->CertificateContent, cnv.cc, len, cleanup);
case FreeRDP_CertificateFile:
return update_string_copy_(&settings->CertificateFile, cnv.cc, len, cleanup);
case FreeRDP_CertificateName:
return update_string_copy_(&settings->CertificateName, cnv.cc, len, cleanup);
case FreeRDP_ClientAddress:
return update_string_copy_(&settings->ClientAddress, cnv.cc, len, cleanup);
case FreeRDP_ClientDir:
return update_string_copy_(&settings->ClientDir, cnv.cc, len, cleanup);
case FreeRDP_ClientHostname:
return update_string_copy_(&settings->ClientHostname, cnv.cc, len, cleanup);
case FreeRDP_ClientProductId:
return update_string_copy_(&settings->ClientProductId, cnv.cc, len, cleanup);
case FreeRDP_ComputerName:
return update_string_copy_(&settings->ComputerName, cnv.cc, len, cleanup);
case FreeRDP_ConfigPath:
return update_string_copy_(&settings->ConfigPath, cnv.cc, len, cleanup);
case FreeRDP_ConnectionFile:
return update_string_copy_(&settings->ConnectionFile, cnv.cc, len, cleanup);
case FreeRDP_ContainerName:
return update_string_copy_(&settings->ContainerName, cnv.cc, len, cleanup);
case FreeRDP_CspName:
return update_string_copy_(&settings->CspName, cnv.cc, len, cleanup);
case FreeRDP_CurrentPath:
return update_string_copy_(&settings->CurrentPath, cnv.cc, len, cleanup);
case FreeRDP_Domain:
return update_string_copy_(&settings->Domain, cnv.cc, len, cleanup);
case FreeRDP_DrivesToRedirect:
return update_string_copy_(&settings->DrivesToRedirect, cnv.cc, len, cleanup);
case FreeRDP_DumpRemoteFxFile:
return update_string_copy_(&settings->DumpRemoteFxFile, cnv.cc, len, cleanup);
case FreeRDP_DynamicDSTTimeZoneKeyName:
return update_string_copy_(&settings->DynamicDSTTimeZoneKeyName, cnv.cc, len, cleanup);
case FreeRDP_GatewayAcceptedCert:
return update_string_copy_(&settings->GatewayAcceptedCert, cnv.cc, len, cleanup);
case FreeRDP_GatewayAccessToken:
return update_string_copy_(&settings->GatewayAccessToken, cnv.cc, len, cleanup);
case FreeRDP_GatewayDomain:
return update_string_copy_(&settings->GatewayDomain, cnv.cc, len, cleanup);
case FreeRDP_GatewayHostname:
return update_string_copy_(&settings->GatewayHostname, cnv.cc, len, cleanup);
case FreeRDP_GatewayPassword:
return update_string_copy_(&settings->GatewayPassword, cnv.cc, len, cleanup);
case FreeRDP_GatewayUsername:
return update_string_copy_(&settings->GatewayUsername, cnv.cc, len, cleanup);
case FreeRDP_HomePath:
return update_string_copy_(&settings->HomePath, cnv.cc, len, cleanup);
case FreeRDP_ImeFileName:
return update_string_copy_(&settings->ImeFileName, cnv.cc, len, cleanup);
case FreeRDP_KerberosArmor:
return update_string_copy_(&settings->KerberosArmor, cnv.cc, len, cleanup);
case FreeRDP_KerberosCache:
return update_string_copy_(&settings->KerberosCache, cnv.cc, len, cleanup);
case FreeRDP_KerberosKdcUrl:
return update_string_copy_(&settings->KerberosKdcUrl, cnv.cc, len, cleanup);
case FreeRDP_KerberosKeytab:
return update_string_copy_(&settings->KerberosKeytab, cnv.cc, len, cleanup);
case FreeRDP_KerberosLifeTime:
return update_string_copy_(&settings->KerberosLifeTime, cnv.cc, len, cleanup);
case FreeRDP_KerberosRealm:
return update_string_copy_(&settings->KerberosRealm, cnv.cc, len, cleanup);
case FreeRDP_KerberosRenewableLifeTime:
return update_string_copy_(&settings->KerberosRenewableLifeTime, cnv.cc, len, cleanup);
case FreeRDP_KerberosStartTime:
return update_string_copy_(&settings->KerberosStartTime, cnv.cc, len, cleanup);
case FreeRDP_KeyboardRemappingList:
return update_string_copy_(&settings->KeyboardRemappingList, cnv.cc, len, cleanup);
case FreeRDP_NtlmSamFile:
return update_string_copy_(&settings->NtlmSamFile, cnv.cc, len, cleanup);
case FreeRDP_Password:
return update_string_copy_(&settings->Password, cnv.cc, len, cleanup);
case FreeRDP_PasswordHash:
return update_string_copy_(&settings->PasswordHash, cnv.cc, len, cleanup);
case FreeRDP_Pkcs11Module:
return update_string_copy_(&settings->Pkcs11Module, cnv.cc, len, cleanup);
case FreeRDP_PkinitAnchors:
return update_string_copy_(&settings->PkinitAnchors, cnv.cc, len, cleanup);
case FreeRDP_PlayRemoteFxFile:
return update_string_copy_(&settings->PlayRemoteFxFile, cnv.cc, len, cleanup);
case FreeRDP_PreconnectionBlob:
return update_string_copy_(&settings->PreconnectionBlob, cnv.cc, len, cleanup);
case FreeRDP_PrivateKeyContent:
return update_string_copy_(&settings->PrivateKeyContent, cnv.cc, len, cleanup);
case FreeRDP_PrivateKeyFile:
return update_string_copy_(&settings->PrivateKeyFile, cnv.cc, len, cleanup);
case FreeRDP_ProxyHostname:
return update_string_copy_(&settings->ProxyHostname, cnv.cc, len, cleanup);
case FreeRDP_ProxyPassword:
return update_string_copy_(&settings->ProxyPassword, cnv.cc, len, cleanup);
case FreeRDP_ProxyUsername:
return update_string_copy_(&settings->ProxyUsername, cnv.cc, len, cleanup);
case FreeRDP_RDP2TCPArgs:
return update_string_copy_(&settings->RDP2TCPArgs, cnv.cc, len, cleanup);
case FreeRDP_ReaderName:
return update_string_copy_(&settings->ReaderName, cnv.cc, len, cleanup);
case FreeRDP_RedirectionAcceptedCert:
return update_string_copy_(&settings->RedirectionAcceptedCert, cnv.cc, len, cleanup);
case FreeRDP_RedirectionDomain:
return update_string_copy_(&settings->RedirectionDomain, cnv.cc, len, cleanup);
case FreeRDP_RedirectionTargetFQDN:
return update_string_copy_(&settings->RedirectionTargetFQDN, cnv.cc, len, cleanup);
case FreeRDP_RedirectionTargetNetBiosName:
return update_string_copy_(&settings->RedirectionTargetNetBiosName, cnv.cc, len,
cleanup);
case FreeRDP_RedirectionUsername:
return update_string_copy_(&settings->RedirectionUsername, cnv.cc, len, cleanup);
case FreeRDP_RemoteApplicationCmdLine:
return update_string_copy_(&settings->RemoteApplicationCmdLine, cnv.cc, len, cleanup);
case FreeRDP_RemoteApplicationFile:
return update_string_copy_(&settings->RemoteApplicationFile, cnv.cc, len, cleanup);
case FreeRDP_RemoteApplicationGuid:
return update_string_copy_(&settings->RemoteApplicationGuid, cnv.cc, len, cleanup);
case FreeRDP_RemoteApplicationIcon:
return update_string_copy_(&settings->RemoteApplicationIcon, cnv.cc, len, cleanup);
case FreeRDP_RemoteApplicationName:
return update_string_copy_(&settings->RemoteApplicationName, cnv.cc, len, cleanup);
case FreeRDP_RemoteApplicationProgram:
return update_string_copy_(&settings->RemoteApplicationProgram, cnv.cc, len, cleanup);
case FreeRDP_RemoteApplicationWorkingDir:
return update_string_copy_(&settings->RemoteApplicationWorkingDir, cnv.cc, len,
cleanup);
case FreeRDP_RemoteAssistancePassStub:
return update_string_copy_(&settings->RemoteAssistancePassStub, cnv.cc, len, cleanup);
case FreeRDP_RemoteAssistancePassword:
return update_string_copy_(&settings->RemoteAssistancePassword, cnv.cc, len, cleanup);
case FreeRDP_RemoteAssistanceRCTicket:
return update_string_copy_(&settings->RemoteAssistanceRCTicket, cnv.cc, len, cleanup);
case FreeRDP_RemoteAssistanceSessionId:
return update_string_copy_(&settings->RemoteAssistanceSessionId, cnv.cc, len, cleanup);
case FreeRDP_ServerHostname:
return update_string_copy_(&settings->ServerHostname, cnv.cc, len, cleanup);
case FreeRDP_ServerLicenseCompanyName:
return update_string_copy_(&settings->ServerLicenseCompanyName, cnv.cc, len, cleanup);
case FreeRDP_ServerLicenseProductName:
return update_string_copy_(&settings->ServerLicenseProductName, cnv.cc, len, cleanup);
case FreeRDP_ShellWorkingDirectory:
return update_string_copy_(&settings->ShellWorkingDirectory, cnv.cc, len, cleanup);
case FreeRDP_SmartcardCertificate:
return update_string_copy_(&settings->SmartcardCertificate, cnv.cc, len, cleanup);
case FreeRDP_SmartcardPrivateKey:
return update_string_copy_(&settings->SmartcardPrivateKey, cnv.cc, len, cleanup);
case FreeRDP_SspiModule:
return update_string_copy_(&settings->SspiModule, cnv.cc, len, cleanup);
case FreeRDP_TargetNetAddress:
return update_string_copy_(&settings->TargetNetAddress, cnv.cc, len, cleanup);
case FreeRDP_TerminalDescriptor:
return update_string_copy_(&settings->TerminalDescriptor, cnv.cc, len, cleanup);
case FreeRDP_TlsSecretsFile:
return update_string_copy_(&settings->TlsSecretsFile, cnv.cc, len, cleanup);
case FreeRDP_TransportDumpFile:
return update_string_copy_(&settings->TransportDumpFile, cnv.cc, len, cleanup);
case FreeRDP_UserSpecifiedServerName:
return update_string_copy_(&settings->UserSpecifiedServerName, cnv.cc, len, cleanup);
case FreeRDP_Username:
return update_string_copy_(&settings->Username, cnv.cc, len, cleanup);
case FreeRDP_WindowTitle:
return update_string_copy_(&settings->WindowTitle, cnv.cc, len, cleanup);
case FreeRDP_WmClass:
return update_string_copy_(&settings->WmClass, cnv.cc, len, cleanup);
default:
WLog_ERR(TAG, "Invalid key index %" PRIuz " [%s|%s]", id,
freerdp_settings_get_name_for_key(id),
freerdp_settings_get_type_name_for_key(id));
return FALSE;
}
return TRUE;
} }
void* freerdp_settings_get_pointer_writable(rdpSettings* settings, size_t id) void* freerdp_settings_get_pointer_writable(rdpSettings* settings, size_t id)

View File

@ -644,7 +644,7 @@ BOOL freerdp_settings_clone_keys(rdpSettings* dst, const rdpSettings* src)
size_t len = 0; size_t len = 0;
if (sval) if (sval)
len = strlen(sval); len = strlen(sval);
if (!freerdp_settings_set_string_(dst, cur->id, sval, len, TRUE, FALSE)) if (!freerdp_settings_set_string_copy_(dst, cur->id, sval, len, FALSE))
return FALSE; return FALSE;
} }
break; break;
@ -874,7 +874,7 @@ void freerdp_settings_free_keys(rdpSettings* dst, BOOL cleanup)
switch (cur->type) switch (cur->type)
{ {
case 7: /* strings */ case 7: /* strings */
freerdp_settings_set_string_(dst, cur->id, NULL, 0, TRUE, cleanup); freerdp_settings_set_string_copy_(dst, cur->id, NULL, 0, cleanup);
break; break;
case 8: /* pointer */ case 8: /* pointer */
freerdp_settings_set_pointer_len(dst, cur->id, NULL, 0); freerdp_settings_set_pointer_len(dst, cur->id, NULL, 0);

View File

@ -34,8 +34,10 @@
FREERDP_LOCAL BOOL freerdp_settings_set_default_order_support(rdpSettings* settings); FREERDP_LOCAL BOOL freerdp_settings_set_default_order_support(rdpSettings* settings);
FREERDP_LOCAL BOOL freerdp_settings_clone_keys(rdpSettings* dst, const rdpSettings* src); 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 void freerdp_settings_free_keys(rdpSettings* dst, BOOL cleanup);
FREERDP_LOCAL BOOL freerdp_settings_set_string_(rdpSettings* settings, size_t id, const char* val, FREERDP_LOCAL BOOL freerdp_settings_set_string_(rdpSettings* settings, size_t id, char* val,
size_t len, BOOL copy, BOOL cleanup); size_t len);
FREERDP_LOCAL BOOL freerdp_settings_set_string_copy_(rdpSettings* settings, size_t id,
const char* val, size_t len, BOOL cleanup);
FREERDP_LOCAL BOOL freerdp_capability_buffer_allocate(rdpSettings* settings, UINT32 count); FREERDP_LOCAL BOOL freerdp_capability_buffer_allocate(rdpSettings* settings, UINT32 count);
#endif /* FREERDP_LIB_CORE_SETTINGS_H */ #endif /* FREERDP_LIB_CORE_SETTINGS_H */

View File

@ -129,7 +129,7 @@ def write_str(f, entry_dict):
f.write('\t\t\t\tconst char* sval = freerdp_settings_get_string(src, cur->id);\n') f.write('\t\t\t\tconst char* sval = freerdp_settings_get_string(src, cur->id);\n')
f.write('\t\t\t\t\tsize_t len = 0;\n') f.write('\t\t\t\t\tsize_t len = 0;\n')
f.write('\t\t\t\t\tif (sval) len = strlen(sval);\n') f.write('\t\t\t\t\tif (sval) len = strlen(sval);\n')
f.write('\t\t\t\tif (!freerdp_settings_set_string_(dst, cur->id, sval, len, TRUE, FALSE))\n') f.write('\t\t\t\tif (!freerdp_settings_set_string_copy_(dst, cur->id, sval, len, FALSE))\n')
f.write('\t\t\t\t\treturn FALSE;\n') f.write('\t\t\t\t\treturn FALSE;\n')
f.write('\t\t\t}\n') f.write('\t\t\t}\n')
f.write('\t\t\tbreak;\n') f.write('\t\t\tbreak;\n')
@ -355,7 +355,7 @@ def write_str(f, entry_dict):
f.write('\t\tswitch(cur->type)\n') f.write('\t\tswitch(cur->type)\n')
f.write('\t\t{\n') f.write('\t\t{\n')
f.write('\t\t\tcase 7: /* strings */\n') f.write('\t\t\tcase 7: /* strings */\n')
f.write('\t\t\t\tfreerdp_settings_set_string_(dst, cur->id, NULL, 0, TRUE, cleanup);\n') f.write('\t\t\t\tfreerdp_settings_set_string_copy_(dst, cur->id, NULL, 0, cleanup);\n')
f.write('\t\t\tbreak;\n') f.write('\t\t\tbreak;\n')
f.write('\t\t\tcase 8: /* pointer */\n') f.write('\t\t\tcase 8: /* pointer */\n')
f.write('\t\t\t\tfreerdp_settings_set_pointer_len(dst, cur->id, NULL, 0);\n') f.write('\t\t\t\tfreerdp_settings_set_pointer_len(dst, cur->id, NULL, 0);\n')
@ -474,7 +474,7 @@ def write_getter_body(f, values, ret):
f.write('\t}\n') f.write('\t}\n')
f.write('}\n\n') f.write('}\n\n')
def write_getter(f, entry_dict, entry_type, entry_name): def write_getter(f, entry_dict, entry_type, entry_name, postfix):
isString = 'string' in entry_name isString = 'string' in entry_name
isPointer = 'pointer' in entry_name isPointer = 'pointer' in entry_name
values = get_values(entry_dict, entry_type) values = get_values(entry_dict, entry_type)
@ -503,34 +503,37 @@ def write_getter(f, entry_dict, entry_type, entry_name):
f.write('char* freerdp_settings_get_' + entry_name.lower() + '_writable(rdpSettings* settings, size_t id)\n') f.write('char* freerdp_settings_get_' + entry_name.lower() + '_writable(rdpSettings* settings, size_t id)\n')
write_getter_body(f, values, ret) write_getter_body(f, values, ret)
def write_setter_case(f, val, isString, isPointer): def write_setter_case(f, val, postfix, isPointer):
f.write('\t\tcase FreeRDP_' + val + ':\n') f.write('\t\tcase FreeRDP_' + val + ':\n')
if isPointer: if isPointer:
f.write('\t\t\tsettings->' + val + ' = cnv.v;\n') f.write('\t\t\tsettings->' + val + ' = cnv.v;\n')
f.write('\t\t\tbreak;\n\n') f.write('\t\t\tbreak;\n\n')
elif not isString: elif not postfix:
f.write('\t\t\tsettings->' + val + ' = cnv.c;\n') f.write('\t\t\tsettings->' + val + ' = cnv.c;\n')
f.write('\t\t\tbreak;\n\n') f.write('\t\t\tbreak;\n\n')
elif len(postfix) <= 1:
f.write('\t\t\treturn update_string' + postfix + '(&settings->' + val + ', cnv.c, len);\n\n')
else: else:
f.write('\t\t\treturn update_string(&settings->' + val + ', cnv.cc, len, copy, cleanup);\n\n') f.write('\t\t\treturn update_string' + postfix + '(&settings->' + val + ', cnv.cc, len, cleanup);\n\n')
def write_setter(f, entry_dict, entry_type, entry_name): def write_setter(f, entry_dict, entry_type, entry_name, postfix):
isString = 'string' in entry_name isString = 'string' in entry_name
isPointer = 'pointer' in entry_name isPointer = 'pointer' in entry_name
values = get_values(entry_dict, entry_type) values = get_values(entry_dict, entry_type)
f.write('BOOL freerdp_settings_set_' + entry_name.lower()) f.write('BOOL freerdp_settings_set_' + entry_name.lower())
if isString: f.write(postfix)
f.write('_')
f.write('(rdpSettings* settings, size_t id, ') f.write('(rdpSettings* settings, size_t id, ')
if isString or isPointer: if isString and len(postfix) > 1 or isPointer:
f.write('const ') f.write('const ')
if not isPointer: if not isPointer:
f.write(entry_type + ' val') f.write(entry_type + ' val')
else: else:
f.write('void* val') f.write('void* val')
if isString: if isString and len(postfix) <= 1:
f.write(', size_t len, BOOL copy, BOOL cleanup)\n') f.write(', size_t len)\n')
elif isString:
f.write(', size_t len, BOOL cleanup)\n')
else: else:
f.write(')\n') f.write(')\n')
f.write('{\n') f.write('{\n')
@ -554,7 +557,7 @@ def write_setter(f, entry_dict, entry_type, entry_name):
f.write('\t{\n') f.write('\t{\n')
if values: if values:
for val in values: for val in values:
write_setter_case(f, val, isString, isPointer) write_setter_case(f, val, postfix, isPointer)
f.write('\t\tdefault:\n') f.write('\t\tdefault:\n')
f.write('\t\t\tWLog_ERR(TAG, "Invalid key index %" PRIuz " [%s|%s]", id, freerdp_settings_get_name_for_key(id), freerdp_settings_get_type_name_for_key(id));\n') f.write('\t\t\tWLog_ERR(TAG, "Invalid key index %" PRIuz " [%s|%s]", id, freerdp_settings_get_name_for_key(id), freerdp_settings_get_type_name_for_key(id));\n')
f.write('\t\t\treturn FALSE;\n') f.write('\t\t\treturn FALSE;\n')
@ -562,10 +565,10 @@ def write_setter(f, entry_dict, entry_type, entry_name):
f.write('\treturn TRUE;\n') f.write('\treturn TRUE;\n')
f.write('}\n\n') f.write('}\n\n')
f.write('\n') f.write('\n')
if isString: if isString and len(postfix) <= 1:
f.write('BOOL freerdp_settings_set_string_len(rdpSettings* settings, size_t id, const char* val, size_t len)\n') f.write('BOOL freerdp_settings_set_string_len(rdpSettings* settings, size_t id, const char* val, size_t len)\n')
f.write('{\n') f.write('{\n')
f.write('\treturn freerdp_settings_set_string_(settings, id, val, len, TRUE, TRUE);\n') f.write('\treturn freerdp_settings_set_string_copy_(settings, id, val, len, TRUE);\n')
f.write('}\n') f.write('}\n')
f.write('\n') f.write('\n')
@ -573,7 +576,7 @@ def write_setter(f, entry_dict, entry_type, entry_name):
f.write('{\n') f.write('{\n')
f.write('\tsize_t len = 0;\n') f.write('\tsize_t len = 0;\n')
f.write('\tif (val) len = strlen(val);\n') f.write('\tif (val) len = strlen(val);\n')
f.write('\treturn freerdp_settings_set_string_(settings, id, val, len, TRUE, TRUE);\n') f.write('\treturn freerdp_settings_set_string_copy_(settings, id, val, len, TRUE);\n')
f.write('}\n') f.write('}\n')
f.write('\n') f.write('\n')
@ -625,48 +628,72 @@ try:
f.write('#include "../core/settings.h"\n\n') f.write('#include "../core/settings.h"\n\n')
f.write('#define TAG FREERDP_TAG("common.settings")\n\n') f.write('#define TAG FREERDP_TAG("common.settings")\n\n')
f.write('static BOOL update_string(char** current, const char* next, size_t next_len, BOOL copy, BOOL cleanup)\n') f.write('static void free_string(char** current, BOOL cleanup)\n')
f.write('{\n') f.write('{\n')
f.write('\tif (cleanup)\n') f.write('\tif (cleanup)\n')
f.write('\t{\n') f.write('\t{\n')
f.write('\t\tif (*current)\n') f.write('\t\tif (*current)\n')
f.write('\t\t\tmemset(*current, 0, strlen(*current));\n') f.write('\t\t\tmemset(*current, 0, strlen(*current));\n')
f.write('\t\tfree(*current);\n') f.write('\t\tfree(*current);\n')
f.write('\t\t(*current) = NULL;\n')
f.write('\t}\n') f.write('\t}\n')
f.write('\n') f.write('}\n\n')
f.write('static BOOL alloc_empty_string(char** current, const char* next, size_t next_len)\n')
f.write('{\n')
f.write('\tif (!next && (next_len > 0))\n') f.write('\tif (!next && (next_len > 0))\n')
f.write('\t{\n') f.write('\t{\n')
f.write('\t\t*current = calloc(next_len, 1);\n') f.write('\t\t*current = calloc(next_len, 1);\n')
f.write('\t\treturn (*current != NULL);\n') f.write('\t\treturn (*current != NULL);\n')
f.write('\t}\n') f.write('\t}\n')
f.write('\treturn FALSE;\n')
f.write('}\n\n')
f.write('static BOOL update_string_copy_(char** current, const char* next, size_t next_len, BOOL cleanup)\n')
f.write('{\n')
f.write('\tfree_string(current, cleanup);\n')
f.write('\n') f.write('\n')
f.write('\tif(copy)') f.write('\tif (alloc_empty_string(current, next, next_len))\n')
f.write('\t\t*current = (next ? strndup(next, next_len) : NULL);\n') f.write('\t\treturn TRUE;\n')
f.write('\telse') f.write('\n')
f.write('\t\t*current = next;\n') f.write('\t*current = (next ? strndup(next, next_len) : NULL);\n')
f.write('\treturn !next || (*current != NULL);\n')
f.write('}\n\n')
f.write('static BOOL update_string_(char** current, char* next, size_t next_len)\n')
f.write('{\n')
f.write('\tfree_string(current, TRUE);\n')
f.write('\n')
f.write('\tif (alloc_empty_string(current, next, next_len))\n')
f.write('\t\treturn TRUE;\n')
f.write('\n')
f.write('\t*current = next;\n')
f.write('\treturn !next || (*current != NULL);\n') f.write('\treturn !next || (*current != NULL);\n')
f.write('}\n\n') f.write('}\n\n')
getter_list = dict(type_list) getter_list = dict(type_list)
setter_list = dict(type_list) setter_list = dict(type_list)
write_getter(f, getter_list, 'BOOL', 'bool') setter_list2 = dict(type_list)
write_setter(f, setter_list, 'BOOL', 'bool') write_getter(f, getter_list, 'BOOL', 'bool', '')
write_getter(f, getter_list, 'UINT16', 'uint16') write_setter(f, setter_list, 'BOOL', 'bool', '')
write_setter(f, setter_list, 'UINT16', 'uint16') write_getter(f, getter_list, 'UINT16', 'uint16', '')
write_getter(f, getter_list, 'INT16', 'int16') write_setter(f, setter_list, 'UINT16', 'uint16', '')
write_setter(f, setter_list, 'INT16', 'int16') write_getter(f, getter_list, 'INT16', 'int16', '')
write_getter(f, getter_list, 'UINT32', 'uint32') write_setter(f, setter_list, 'INT16', 'int16', '')
write_setter(f, setter_list, 'UINT32', 'uint32') write_getter(f, getter_list, 'UINT32', 'uint32', '')
write_getter(f, getter_list, 'INT32', 'int32') write_setter(f, setter_list, 'UINT32', 'uint32', '')
write_setter(f, setter_list, 'INT32', 'int32') write_getter(f, getter_list, 'INT32', 'int32', '')
write_getter(f, getter_list, 'UINT64', 'uint64') write_setter(f, setter_list, 'INT32', 'int32', '')
write_setter(f, setter_list, 'UINT64', 'uint64') write_getter(f, getter_list, 'UINT64', 'uint64', '')
write_getter(f, getter_list, 'INT64', 'int64') write_setter(f, setter_list, 'UINT64', 'uint64', '')
write_setter(f, setter_list, 'INT64', 'int64') write_getter(f, getter_list, 'INT64', 'int64', '')
write_getter(f, getter_list, 'char*', 'string') write_setter(f, setter_list, 'INT64', 'int64', '')
write_setter(f, setter_list, 'char*', 'string') write_getter(f, getter_list, 'char*', 'string', '_')
write_getter(f, getter_list, '*', 'pointer') write_setter(f, setter_list, 'char*', 'string', '_')
write_setter(f, setter_list, '*', 'pointer') write_setter(f, setter_list2, 'char*', 'string', '_copy_')
write_getter(f, getter_list, '*', 'pointer', '')
write_setter(f, setter_list, '*', 'pointer', '')
f.write('\n') f.write('\n')