[winpr,json] fix json-c case insensitive object get

This commit is contained in:
Armin Novak
2025-09-23 12:29:32 +02:00
parent fda43ec692
commit 75787a62de
2 changed files with 14 additions and 3 deletions

View File

@@ -119,14 +119,14 @@ extern "C"
/**
* @brief Return a pointer to an JSON object item
* @param object the JSON object
* @param string the name of the object
* @param string the name of the object (case is ignored)
* @return A pointer to the object identified by @ref string or \b NULL
* @since version 3.6.0
*/
WINPR_API WINPR_JSON* WINPR_JSON_GetObjectItem(const WINPR_JSON* object, const char* string);
/**
* @brief Same as @ref WINPR_JSON_GetObjectItem but with case insensitive matching
* @brief Same as @ref WINPR_JSON_GetObjectItem but with case sensitive matching
*
* @param object the JSON instance to query
* @param string the name of the object

View File

@@ -184,7 +184,18 @@ size_t WINPR_JSON_GetArraySize(const WINPR_JSON* array)
WINPR_JSON* WINPR_JSON_GetObjectItem(const WINPR_JSON* object, const char* string)
{
#if defined(WITH_JSONC)
return json_object_object_get((const json_object*)object, string);
struct json_object_iterator it = json_object_iter_begin((const json_object*)object);
struct json_object_iterator itEnd = json_object_iter_end((const json_object*)object);
while (!json_object_iter_equal(&it, &itEnd))
{
const char* key = json_object_iter_peek_name(&it);
if (_stricmp(key, string) == 0)
{
return json_object_iter_peek_value(&it);
}
json_object_iter_next(&it);
}
return NULL;
#elif defined(WITH_CJSON)
return cJSON_GetObjectItem((const cJSON*)object, string);
#else