Skip to content
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
[common,settings] add freerdp_settings_apply_from_json
  • Loading branch information
akallabeth committed Oct 1, 2026
commit 693c5cc53b8c80d1ef98d7b51cda00c37e998708
39 changes: 28 additions & 11 deletions libfreerdp/common/settings.c
Original file line number Diff line number Diff line change
Expand Up @@ -4537,6 +4537,32 @@ rdpSettings* freerdp_settings_deserialize(const char* jstr, size_t length)
return nullptr;
}

rdpSettings* settings = freerdp_settings_new(0);
if (!settings)
{
WLog_Print(log, WLOG_ERROR, "freerdp_settings_new failed");
goto fail;
}

if (!freerdp_settings_apply_from_json(settings, json))
goto fail;

WINPR_JSON_Delete(json);
return settings;

fail:
freerdp_settings_free(settings);
WINPR_JSON_Delete(json);
return nullptr;
}

BOOL freerdp_settings_apply_from_json(rdpSettings* settings, WINPR_JSON* json)
{
wLog* log = WLog_Get(TAG);

WINPR_ASSERT(settings);
WINPR_ASSERT(json);

WINPR_JSON* jbool = WINPR_JSON_GetObjectItemCaseSensitive(
json, freerdp_settings_get_type_name_for_type(RDP_SETTINGS_TYPE_BOOL));
WINPR_JSON* juint16 = WINPR_JSON_GetObjectItemCaseSensitive(
Expand All @@ -4556,12 +4582,6 @@ rdpSettings* freerdp_settings_deserialize(const char* jstr, size_t length)
WINPR_JSON* jpointer = WINPR_JSON_GetObjectItemCaseSensitive(
json, freerdp_settings_get_type_name_for_type(RDP_SETTINGS_TYPE_POINTER));

rdpSettings* settings = freerdp_settings_new(0);
if (!settings)
{
WLog_Print(log, WLOG_ERROR, "freerdp_settings_new failed");
goto fail;
}
if (!jbool || !juint16 || !jint16 || !juint32 || !jint32 || !juint64 || !jint64 || !jstring ||
!jpointer)
goto fail;
Expand Down Expand Up @@ -4656,13 +4676,10 @@ rdpSettings* freerdp_settings_deserialize(const char* jstr, size_t length)
}
}

WINPR_JSON_Delete(json);
return settings;
return TRUE;

fail:
freerdp_settings_free(settings);
WINPR_JSON_Delete(json);
return nullptr;
return FALSE;
}

const ADDIN_ARGV* freerdp_device_get_args(const RDPDR_DEVICE* device)
Expand Down
12 changes: 12 additions & 0 deletions libfreerdp/core/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

#include <winpr/string.h>
#include <winpr/sspi.h>
#include <winpr/json.h>

#include <freerdp/config.h>

Expand Down Expand Up @@ -120,4 +121,15 @@ FREERDP_LOCAL BOOL freerdp_target_net_adresses_reset(rdpSettings* settings, size
WINPR_ATTR_NODISCARD
FREERDP_LOCAL BOOL freerdp_target_net_addresses_resize(rdpSettings* settings, size_t count);

/** @brief A function that reads \b rdpSettings values from a JSON file
*
* @param settings The settings to store the updated values in
* @param json The JSON to read the data from
*
* @return TRUE for success, FALSE on failure
* @since version 3.33.0
*/
WINPR_ATTR_NODISCARD
FREERDP_LOCAL BOOL freerdp_settings_apply_from_json(rdpSettings* settings, WINPR_JSON* json);

#endif /* FREERDP_LIB_CORE_SETTINGS_H */