diff --git a/winpr/include/winpr/json.h b/winpr/include/winpr/json.h index c06296ba6..d4b2f0eb6 100644 --- a/winpr/include/winpr/json.h +++ b/winpr/include/winpr/json.h @@ -346,6 +346,16 @@ extern "C" WINPR_API WINPR_JSON* WINPR_JSON_AddNumberToObject(WINPR_JSON* object, const char* name, double number); + /** + * @brief WINPR_JSON_AddIntegerToObject + * @param object The JSON object the new item is added to + * @param name The name of the object + * @return the new JSON item added + * @since version 3.6.0 + */ + WINPR_API WINPR_JSON* WINPR_JSON_AddIntegerToObject(WINPR_JSON* object, const char* name, + int64_t number); + /** * @brief WINPR_JSON_AddStringToObject * @param object The JSON object the new item is added to diff --git a/winpr/libwinpr/utils/json/c-json.c b/winpr/libwinpr/utils/json/c-json.c index bd95d77e7..7686b51d4 100644 --- a/winpr/libwinpr/utils/json/c-json.c +++ b/winpr/libwinpr/utils/json/c-json.c @@ -259,6 +259,13 @@ WINPR_JSON* WINPR_JSON_AddNumberToObject(WINPR_JSON* object, const char* name, d return cJSON_AddNumberToObject((cJSON*)object, name, number); } +WINPR_JSON* WINPR_JSON_AddIntegerToObject(WINPR_JSON* object, const char* name, int64_t number) +{ + char str[64] = { 0 }; + (void)_snprintf(str, sizeof(str), "%" PRId64, number); + return cJSON_AddRawToObject((cJSON*)object, name, str); +} + WINPR_JSON* WINPR_JSON_AddStringToObject(WINPR_JSON* object, const char* name, const char* string) { return cJSON_AddStringToObject((cJSON*)object, name, string); diff --git a/winpr/libwinpr/utils/json/jansson.c b/winpr/libwinpr/utils/json/jansson.c index a1f68cba8..ce3c23ce0 100644 --- a/winpr/libwinpr/utils/json/jansson.c +++ b/winpr/libwinpr/utils/json/jansson.c @@ -298,6 +298,12 @@ WINPR_JSON* WINPR_JSON_AddNumberToObject(WINPR_JSON* object, const char* name, d return add_to_object(object, name, obj); } +WINPR_JSON* WINPR_JSON_AddIntegerToObject(WINPR_JSON* object, const char* name, int64_t number) +{ + json_t* obj = json_integer(number); + return add_to_object(object, name, obj); +} + WINPR_JSON* WINPR_JSON_AddStringToObject(WINPR_JSON* object, const char* name, const char* string) { json_t* obj = json_string(string); diff --git a/winpr/libwinpr/utils/json/json-c.c b/winpr/libwinpr/utils/json/json-c.c index 1fde41331..df1d2a590 100644 --- a/winpr/libwinpr/utils/json/json-c.c +++ b/winpr/libwinpr/utils/json/json-c.c @@ -274,6 +274,17 @@ WINPR_JSON* WINPR_JSON_AddNumberToObject(WINPR_JSON* object, const char* name, d return obj; } +WINPR_JSON* WINPR_JSON_AddIntegerToObject(WINPR_JSON* object, const char* name, int64_t number) +{ + struct json_object* obj = json_object_new_int64(number); + if (json_object_object_add((json_object*)object, name, obj) != 0) + { + json_object_put(obj); + return NULL; + } + return obj; +} + WINPR_JSON* WINPR_JSON_AddStringToObject(WINPR_JSON* object, const char* name, const char* string) { struct json_object* obj = json_object_new_string(string);