[winpr,utils] add WINPR_JSON_AddItemToArray

This commit is contained in:
akallabeth 2024-07-19 15:38:49 +02:00
parent 467cf6e346
commit e34b8b5205
No known key found for this signature in database
GPG Key ID: A49454A3FC909FD5
2 changed files with 18 additions and 0 deletions

View File

@ -83,6 +83,8 @@ extern "C"
WINPR_API WINPR_JSON* WINPR_JSON_AddObjectToObject(WINPR_JSON* object, const char* name);
WINPR_API WINPR_JSON* WINPR_JSON_AddArrayToObject(WINPR_JSON* object, const char* name);
WINPR_API BOOL WINPR_JSON_AddItemToArray(WINPR_JSON* array, WINPR_JSON* item);
WINPR_API char* WINPR_JSON_Print(WINPR_JSON* item);
WINPR_API char* WINPR_JSON_PrintUnformatted(WINPR_JSON* item);

View File

@ -613,6 +613,22 @@ WINPR_JSON* WINPR_JSON_AddObjectToObject(WINPR_JSON* const object, const char* c
#endif
}
BOOL WINPR_JSON_AddItemToArray(WINPR_JSON* array, WINPR_JSON* item)
{
#if defined(WITH_JSONC)
const int rc = json_object_array_add((json_object*)array, (json_object*)item);
if (rc != 0)
return FALSE;
return TRUE;
#elif defined(WITH_CJSON)
return cJSON_AddItemToArray((cJSON*)array, (cJSON*)item);
#else
WINPR_UNUSED(object);
WINPR_UNUSED(name);
return FALSE;
#endif
}
WINPR_JSON* WINPR_JSON_AddArrayToObject(WINPR_JSON* const object, const char* const name)
{
#if defined(WITH_JSONC)