[settings] add unused values and sign correct keys

* add -1 as unused enum entry
* change key parameter type from size_t to SSIZE_T
This commit is contained in:
Armin Novak 2023-10-16 20:44:25 +02:00 committed by akallabeth
parent 6e6559c41a
commit 704ee8bc4b
5 changed files with 28 additions and 45 deletions

View File

@ -4035,7 +4035,7 @@ static int freerdp_client_settings_parse_command_line_arguments_int(
if (count == 0)
return COMMAND_LINE_ERROR_UNEXPECTED_VALUE;
FreeRDP_Settings_Keys_Bool singleOptionWithoutOnOff = 0;
FreeRDP_Settings_Keys_Bool singleOptionWithoutOnOff = FreeRDP_BOOL_UNUSED;
for (x = 0; x < count; x++)
{
const char* cur = ptr[x];
@ -4075,7 +4075,7 @@ static int freerdp_client_settings_parse_command_line_arguments_int(
return COMMAND_LINE_ERROR_UNEXPECTED_VALUE;
}
if (singleOptionWithoutOnOff != 0)
if (singleOptionWithoutOnOff != FreeRDP_BOOL_UNUSED)
{
const FreeRDP_Settings_Keys_Bool options[] = {
FreeRDP_AadSecurity, FreeRDP_UseRdpSecurityLayer, FreeRDP_RdpSecurity,
@ -5191,7 +5191,7 @@ BOOL freerdp_client_load_addins(rdpChannels* channels, rdpSettings* settings)
{
ChannelToLoad dynChannels[] = {
#if defined(CHANNEL_AINPUT_CLIENT)
{ 0, AINPUT_CHANNEL_NAME, NULL }, /* always loaded */
{ FreeRDP_BOOL_UNUSED, AINPUT_CHANNEL_NAME, NULL }, /* always loaded */
#endif
{ FreeRDP_AudioCapture, AUDIN_CHANNEL_NAME, NULL },
{ FreeRDP_AudioPlayback, RDPSND_CHANNEL_NAME, NULL },
@ -5221,7 +5221,7 @@ BOOL freerdp_client_load_addins(rdpChannels* channels, rdpSettings* settings)
*/
for (size_t i = 0; i < ARRAYSIZE(dynChannels); i++)
{
if ((dynChannels[i].settingId == 0) ||
if ((dynChannels[i].settingId == FreeRDP_BOOL_UNUSED) ||
freerdp_settings_get_bool(settings, dynChannels[i].settingId))
{
const char* p[] = { dynChannels[i].channelName };

View File

@ -88,33 +88,16 @@ foreach(KEY ${SETTINGS_KEYS})
endif()
endforeach()
if (NOT SETTINGS_KEYS_BOOL)
set(SETTINGS_KEYS_BOOL "FreeRDP_BOOL_UNUSED = -1")
endif()
if (NOT SETTINGS_KEYS_INT16)
set(SETTINGS_KEYS_INT16 "FreeRDP_INT16_UNUSED = -1")
endif()
if (NOT SETTINGS_KEYS_UINT16)
set(SETTINGS_KEYS_UINT16 "FreeRDP_UINT16_UNUSED = -1")
endif()
if (NOT SETTINGS_KEYS_INT32)
set(SETTINGS_KEYS_INT32 "FreeRDP_INT32_UNUSED = -1")
endif()
if (NOT SETTINGS_KEYS_UINT32)
set(SETTINGS_KEYS_UINT32 "FreeRDP_UINT32_UNUSED = -1")
endif()
if (NOT SETTINGS_KEYS_INT64)
set(SETTINGS_KEYS_INT64 "FreeRDP_INT64_UNUSED = -1")
endif()
if (NOT SETTINGS_KEYS_UINT64)
set(SETTINGS_KEYS_UINT64 "FreeRDP_UINT64_UNUSED = -1")
endif()
if (NOT SETTINGS_KEYS_STRING)
set(SETTINGS_KEYS_STRING "FreeRDP_STRING_UNUSED = -1")
endif()
if (NOT SETTINGS_KEYS_POINTER)
set(SETTINGS_KEYS_POINTER "FreeRDP_POINTER_UNUSED = -1")
endif()
list(APPEND SETTINGS_KEYS_BOOL "FreeRDP_BOOL_UNUSED = -1")
list(APPEND SETTINGS_KEYS_INT16 "FreeRDP_INT16_UNUSED = -1")
list(APPEND SETTINGS_KEYS_UINT16 "FreeRDP_UINT16_UNUSED = -1")
list(APPEND SETTINGS_KEYS_INT32 "FreeRDP_INT32_UNUSED = -1")
list(APPEND SETTINGS_KEYS_UINT32 "FreeRDP_UINT32_UNUSED = -1")
list(APPEND SETTINGS_KEYS_INT64 "FreeRDP_INT64_UNUSED = -1")
list(APPEND SETTINGS_KEYS_UINT64 "FreeRDP_UINT64_UNUSED = -1")
list(APPEND SETTINGS_KEYS_STRING "FreeRDP_STRING_UNUSED = -1")
list(APPEND SETTINGS_KEYS_POINTER "FreeRDP_POINTER_UNUSED = -1")
string(REPLACE ";" ",\n\t" SETTINGS_KEYS_BOOL "${SETTINGS_KEYS_BOOL}")
string(REPLACE ";" ",\n\t" SETTINGS_KEYS_INT16 "${SETTINGS_KEYS_INT16}")
string(REPLACE ";" ",\n\t" SETTINGS_KEYS_UINT16 "${SETTINGS_KEYS_UINT16}")

View File

@ -118,7 +118,7 @@ typedef struct rdp_settings rdpSettings;
*/
FREERDP_API BOOL freerdp_settings_copy_item(rdpSettings* dst, const rdpSettings* src,
size_t id);
SSIZE_T id);
/** \brief Free a settings struct with all data in it
*
@ -564,11 +564,11 @@ typedef struct rdp_settings rdpSettings;
* \return The key type (e.g. FREERDP_SETTINGS_TYPE_BOOL) or -1 in case of an error (e.g. name
* does not exist)
*/
FREERDP_API SSIZE_T freerdp_settings_get_type_for_key(size_t key);
FREERDP_API const char* freerdp_settings_get_type_name_for_key(size_t key);
FREERDP_API SSIZE_T freerdp_settings_get_type_for_key(SSIZE_T key);
FREERDP_API const char* freerdp_settings_get_type_name_for_key(SSIZE_T key);
FREERDP_API const char* freerdp_settings_get_type_name_for_type(SSIZE_T type);
FREERDP_API const char* freerdp_settings_get_name_for_key(size_t key);
FREERDP_API const char* freerdp_settings_get_name_for_key(SSIZE_T key);
FREERDP_API UINT32 freerdp_settings_get_codecs_flags(const rdpSettings* settings);
/** \brief Parse capability data and apply to settings

View File

@ -1169,19 +1169,19 @@ BOOL freerdp_settings_set_value_for_name(rdpSettings* settings, const char* name
{
ULONGLONG uval;
LONGLONG ival;
SSIZE_T i, type;
size_t index;
SSIZE_T type;
if (!settings || !name)
return FALSE;
i = freerdp_settings_get_key_for_name(name);
const SSIZE_T i = freerdp_settings_get_key_for_name(name);
if (i < 0)
{
WLog_ERR(TAG, "Invalid settings key [%s]", name);
return FALSE;
}
index = (size_t)i;
const SSIZE_T index = i;
type = freerdp_settings_get_type_for_key(index);
switch (type)

View File

@ -363,7 +363,7 @@ SSIZE_T freerdp_settings_get_type_for_name(const char* value)
return -1;
}
const char* freerdp_settings_get_type_name_for_key(size_t key)
const char* freerdp_settings_get_type_name_for_key(SSIZE_T key)
{
const SSIZE_T type = freerdp_settings_get_type_for_key(key);
return freerdp_settings_get_type_name_for_type(type);
@ -396,29 +396,29 @@ const char* freerdp_settings_get_type_name_for_type(SSIZE_T type)
}
}
SSIZE_T freerdp_settings_get_type_for_key(size_t key)
SSIZE_T freerdp_settings_get_type_for_key(SSIZE_T key)
{
for (size_t x = 0; x < ARRAYSIZE(settings_map); x++)
{
const struct settings_str_entry* cur = &settings_map[x];
if (cur->id == (SSIZE_T)key)
if (cur->id == key)
return cur->type;
}
return -1;
}
const char* freerdp_settings_get_name_for_key(size_t key)
const char* freerdp_settings_get_name_for_key(SSIZE_T key)
{
for (size_t x = 0; x < ARRAYSIZE(settings_map); x++)
{
const struct settings_str_entry* cur = &settings_map[x];
if (cur->id == (SSIZE_T)key)
if (cur->id == key)
return cur->str;
}
return NULL;
}
BOOL freerdp_settings_copy_item(rdpSettings* dst, const rdpSettings* src, size_t id)
BOOL freerdp_settings_copy_item(rdpSettings* dst, const rdpSettings* src, SSIZE_T id)
{
WINPR_ASSERT(dst);
WINPR_ASSERT(src);