diff --git a/include/freerdp/utils/helpers.h b/include/freerdp/utils/helpers.h index 5f5b8d2f7..68d9898fd 100644 --- a/include/freerdp/utils/helpers.h +++ b/include/freerdp/utils/helpers.h @@ -21,6 +21,8 @@ #pragma once #include +#include + #include /** @brief Return the absolute path of a configuration file (the path of the configuration @@ -38,3 +40,15 @@ */ WINPR_ATTR_MALLOC(free, 1) FREERDP_API char* freerdp_GetConfigFilePath(BOOL system, const char* filename); + +/** @brief return a parsed JSON for a given config file name. + * + * @param system a boolean indicating the configuration base, \b TRUE for system configuration, + * \b FALSE for user configuration + * @param filename an optional configuration file name to append. + * + * @return A parsed \b WINPR_JSON object or \b NULL in case of any failure. + * @since version 3.16.0 + */ +WINPR_ATTR_MALLOC(WINPR_JSON_Delete, 1) +FREERDP_API WINPR_JSON* freerdp_GetJSONConfigFile(BOOL system, const char* filename); diff --git a/libfreerdp/utils/helpers.c b/libfreerdp/utils/helpers.c index 6efefaf5c..c92254754 100644 --- a/libfreerdp/utils/helpers.c +++ b/libfreerdp/utils/helpers.c @@ -59,3 +59,14 @@ char* freerdp_GetConfigFilePath(BOOL system, const char* filename) free(base); return path; } + +WINPR_JSON* freerdp_GetJSONConfigFile(BOOL system, const char* filename) +{ + char* path = freerdp_GetConfigFilePath(system, filename); + if (!path) + return NULL; + + WINPR_JSON* json = WINPR_JSON_ParseFromFile(path); + free(path); + return json; +}