258 lines
9.1 KiB
C
258 lines
9.1 KiB
C
|
|
|
|
#ifndef cJSON__h
|
|
#define cJSON__h
|
|
|
|
#ifdef __cplusplus
|
|
extern "C"
|
|
{
|
|
#endif
|
|
|
|
#if !defined(__WINDOWS__) && (defined(WIN32) || defined(WIN64) || defined(_MSC_VER) || defined(_WIN32))
|
|
#define __WINDOWS__
|
|
#endif
|
|
|
|
#ifdef __WINDOWS__
|
|
|
|
|
|
|
|
#define CJSON_CDECL __cdecl
|
|
#define CJSON_STDCALL __stdcall
|
|
|
|
|
|
#if !defined(CJSON_HIDE_SYMBOLS) && !defined(CJSON_IMPORT_SYMBOLS) && !defined(CJSON_EXPORT_SYMBOLS)
|
|
#define CJSON_EXPORT_SYMBOLS
|
|
#endif
|
|
|
|
#if defined(CJSON_HIDE_SYMBOLS)
|
|
#define CJSON_PUBLIC(type) type CJSON_STDCALL
|
|
#elif defined(CJSON_EXPORT_SYMBOLS)
|
|
#define CJSON_PUBLIC(type) __declspec(dllexport) type CJSON_STDCALL
|
|
#elif defined(CJSON_IMPORT_SYMBOLS)
|
|
#define CJSON_PUBLIC(type) __declspec(dllimport) type CJSON_STDCALL
|
|
#endif
|
|
#else
|
|
#define CJSON_CDECL
|
|
#define CJSON_STDCALL
|
|
|
|
#if (defined(__GNUC__) || defined(__SUNPRO_CC) || defined (__SUNPRO_C)) && defined(CJSON_API_VISIBILITY)
|
|
#define CJSON_PUBLIC(type) __attribute__((visibility("default"))) type
|
|
#else
|
|
#define CJSON_PUBLIC(type) type
|
|
#endif
|
|
#endif
|
|
|
|
|
|
#define CJSON_VERSION_MAJOR 1
|
|
#define CJSON_VERSION_MINOR 7
|
|
#define CJSON_VERSION_PATCH 16
|
|
|
|
#include <stddef.h>
|
|
|
|
#define cJSON_Invalid (0)
|
|
#define cJSON_False (1 << 0)
|
|
#define cJSON_True (1 << 1)
|
|
#define cJSON_NULL (1 << 2)
|
|
#define cJSON_Number (1 << 3)
|
|
#define cJSON_String (1 << 4)
|
|
#define cJSON_Array (1 << 5)
|
|
#define cJSON_Object (1 << 6)
|
|
#define cJSON_Raw (1 << 7)
|
|
|
|
#define cJSON_IsReference 256
|
|
#define cJSON_StringIsConst 512
|
|
|
|
typedef struct cJSON
|
|
{
|
|
|
|
struct cJSON* next;
|
|
struct cJSON* prev;
|
|
|
|
struct cJSON* child;
|
|
|
|
|
|
int type;
|
|
|
|
|
|
char* valuestring;
|
|
|
|
int valueint;
|
|
|
|
double valuedouble;
|
|
|
|
|
|
char* string;
|
|
} cJSON;
|
|
|
|
typedef struct cJSON_Hooks
|
|
{
|
|
|
|
void* (CJSON_CDECL* malloc_fn)(size_t sz);
|
|
void (CJSON_CDECL* free_fn)(void* ptr);
|
|
} cJSON_Hooks;
|
|
|
|
typedef int cJSON_bool;
|
|
|
|
|
|
|
|
#ifndef CJSON_NESTING_LIMIT
|
|
#define CJSON_NESTING_LIMIT 1000
|
|
#endif
|
|
|
|
|
|
CJSON_PUBLIC(const char*) cJSON_Version(void);
|
|
|
|
|
|
CJSON_PUBLIC(void) cJSON_InitHooks(cJSON_Hooks* hooks);
|
|
|
|
|
|
|
|
CJSON_PUBLIC(cJSON*) cJSON_Parse(const char* value);
|
|
CJSON_PUBLIC(cJSON*) cJSON_ParseWithLength(const char* value, size_t buffer_length);
|
|
|
|
|
|
CJSON_PUBLIC(cJSON*) cJSON_ParseWithOpts(const char* value, const char** return_parse_end, cJSON_bool require_null_terminated);
|
|
CJSON_PUBLIC(cJSON*) cJSON_ParseWithLengthOpts(const char* value, size_t buffer_length, const char** return_parse_end, cJSON_bool require_null_terminated);
|
|
|
|
|
|
CJSON_PUBLIC(char*) cJSON_Print(const cJSON* item);
|
|
|
|
CJSON_PUBLIC(char*) cJSON_PrintUnformatted(const cJSON* item);
|
|
|
|
CJSON_PUBLIC(char*) cJSON_PrintBuffered(const cJSON* item, int prebuffer, cJSON_bool fmt);
|
|
|
|
|
|
CJSON_PUBLIC(cJSON_bool) cJSON_PrintPreallocated(cJSON* item, char* buffer, const int length, const cJSON_bool format);
|
|
|
|
CJSON_PUBLIC(void) cJSON_Delete(cJSON* item);
|
|
|
|
|
|
CJSON_PUBLIC(int) cJSON_GetArraySize(const cJSON* array);
|
|
|
|
CJSON_PUBLIC(cJSON*) cJSON_GetArrayItem(const cJSON* array, int index);
|
|
|
|
CJSON_PUBLIC(cJSON*) cJSON_GetObjectItem(const cJSON* const object, const char* const string);
|
|
CJSON_PUBLIC(cJSON*) cJSON_GetObjectItemCaseSensitive(const cJSON* const object, const char* const string);
|
|
CJSON_PUBLIC(cJSON_bool) cJSON_HasObjectItem(const cJSON* object, const char* string);
|
|
|
|
CJSON_PUBLIC(const char*) cJSON_GetErrorPtr(void);
|
|
|
|
|
|
CJSON_PUBLIC(char*) cJSON_GetStringValue(const cJSON* const item);
|
|
CJSON_PUBLIC(double) cJSON_GetNumberValue(const cJSON* const item);
|
|
|
|
|
|
CJSON_PUBLIC(cJSON_bool) cJSON_IsInvalid(const cJSON* const item);
|
|
CJSON_PUBLIC(cJSON_bool) cJSON_IsFalse(const cJSON* const item);
|
|
CJSON_PUBLIC(cJSON_bool) cJSON_IsTrue(const cJSON* const item);
|
|
CJSON_PUBLIC(cJSON_bool) cJSON_IsBool(const cJSON* const item);
|
|
CJSON_PUBLIC(cJSON_bool) cJSON_IsNull(const cJSON* const item);
|
|
CJSON_PUBLIC(cJSON_bool) cJSON_IsNumber(const cJSON* const item);
|
|
CJSON_PUBLIC(cJSON_bool) cJSON_IsString(const cJSON* const item);
|
|
CJSON_PUBLIC(cJSON_bool) cJSON_IsArray(const cJSON* const item);
|
|
CJSON_PUBLIC(cJSON_bool) cJSON_IsObject(const cJSON* const item);
|
|
CJSON_PUBLIC(cJSON_bool) cJSON_IsRaw(const cJSON* const item);
|
|
|
|
|
|
CJSON_PUBLIC(cJSON*) cJSON_CreateNull(void);
|
|
CJSON_PUBLIC(cJSON*) cJSON_CreateTrue(void);
|
|
CJSON_PUBLIC(cJSON*) cJSON_CreateFalse(void);
|
|
CJSON_PUBLIC(cJSON*) cJSON_CreateBool(cJSON_bool boolean);
|
|
CJSON_PUBLIC(cJSON*) cJSON_CreateNumber(double num);
|
|
CJSON_PUBLIC(cJSON*) cJSON_CreateString(const char* string);
|
|
|
|
CJSON_PUBLIC(cJSON*) cJSON_CreateRaw(const char* raw);
|
|
CJSON_PUBLIC(cJSON*) cJSON_CreateArray(void);
|
|
CJSON_PUBLIC(cJSON*) cJSON_CreateObject(void);
|
|
|
|
|
|
|
|
CJSON_PUBLIC(cJSON*) cJSON_CreateStringReference(const char* string);
|
|
|
|
|
|
CJSON_PUBLIC(cJSON*) cJSON_CreateObjectReference(const cJSON* child);
|
|
CJSON_PUBLIC(cJSON*) cJSON_CreateArrayReference(const cJSON* child);
|
|
|
|
|
|
|
|
CJSON_PUBLIC(cJSON*) cJSON_CreateIntArray(const int* numbers, int count);
|
|
CJSON_PUBLIC(cJSON*) cJSON_CreateFloatArray(const float* numbers, int count);
|
|
CJSON_PUBLIC(cJSON*) cJSON_CreateDoubleArray(const double* numbers, int count);
|
|
CJSON_PUBLIC(cJSON*) cJSON_CreateStringArray(const char* const* strings, int count);
|
|
|
|
|
|
CJSON_PUBLIC(cJSON_bool) cJSON_AddItemToArray(cJSON* array, cJSON* item);
|
|
CJSON_PUBLIC(cJSON_bool) cJSON_AddItemToObject(cJSON* object, const char* string, cJSON* item);
|
|
|
|
|
|
CJSON_PUBLIC(cJSON_bool) cJSON_AddItemToObjectCS(cJSON* object, const char* string, cJSON* item);
|
|
|
|
CJSON_PUBLIC(cJSON_bool) cJSON_AddItemReferenceToArray(cJSON* array, cJSON* item);
|
|
CJSON_PUBLIC(cJSON_bool) cJSON_AddItemReferenceToObject(cJSON* object, const char* string, cJSON* item);
|
|
|
|
|
|
CJSON_PUBLIC(cJSON*) cJSON_DetachItemViaPointer(cJSON* parent, cJSON* const item);
|
|
CJSON_PUBLIC(cJSON*) cJSON_DetachItemFromArray(cJSON* array, int which);
|
|
CJSON_PUBLIC(void) cJSON_DeleteItemFromArray(cJSON* array, int which);
|
|
CJSON_PUBLIC(cJSON*) cJSON_DetachItemFromObject(cJSON* object, const char* string);
|
|
CJSON_PUBLIC(cJSON*) cJSON_DetachItemFromObjectCaseSensitive(cJSON* object, const char* string);
|
|
CJSON_PUBLIC(void) cJSON_DeleteItemFromObject(cJSON* object, const char* string);
|
|
CJSON_PUBLIC(void) cJSON_DeleteItemFromObjectCaseSensitive(cJSON* object, const char* string);
|
|
|
|
|
|
CJSON_PUBLIC(cJSON_bool) cJSON_InsertItemInArray(cJSON* array, int which, cJSON* newitem);
|
|
CJSON_PUBLIC(cJSON_bool) cJSON_ReplaceItemViaPointer(cJSON* const parent, cJSON* const item, cJSON* replacement);
|
|
CJSON_PUBLIC(cJSON_bool) cJSON_ReplaceItemInArray(cJSON* array, int which, cJSON* newitem);
|
|
CJSON_PUBLIC(cJSON_bool) cJSON_ReplaceItemInObject(cJSON* object, const char* string, cJSON* newitem);
|
|
CJSON_PUBLIC(cJSON_bool) cJSON_ReplaceItemInObjectCaseSensitive(cJSON* object, const char* string, cJSON* newitem);
|
|
|
|
|
|
CJSON_PUBLIC(cJSON*) cJSON_Duplicate(const cJSON* item, cJSON_bool recurse);
|
|
|
|
|
|
|
|
|
|
CJSON_PUBLIC(cJSON_bool) cJSON_Compare(const cJSON* const a, const cJSON* const b, const cJSON_bool case_sensitive);
|
|
|
|
|
|
|
|
CJSON_PUBLIC(void) cJSON_Minify(char* json);
|
|
|
|
|
|
|
|
CJSON_PUBLIC(cJSON*) cJSON_AddNullToObject(cJSON* const object, const char* const name);
|
|
CJSON_PUBLIC(cJSON*) cJSON_AddTrueToObject(cJSON* const object, const char* const name);
|
|
CJSON_PUBLIC(cJSON*) cJSON_AddFalseToObject(cJSON* const object, const char* const name);
|
|
CJSON_PUBLIC(cJSON*) cJSON_AddBoolToObject(cJSON* const object, const char* const name, const cJSON_bool boolean);
|
|
CJSON_PUBLIC(cJSON*) cJSON_AddNumberToObject(cJSON* const object, const char* const name, const double number);
|
|
CJSON_PUBLIC(cJSON*) cJSON_AddStringToObject(cJSON* const object, const char* const name, const char* const string);
|
|
CJSON_PUBLIC(cJSON*) cJSON_AddRawToObject(cJSON* const object, const char* const name, const char* const raw);
|
|
CJSON_PUBLIC(cJSON*) cJSON_AddObjectToObject(cJSON* const object, const char* const name);
|
|
CJSON_PUBLIC(cJSON*) cJSON_AddArrayToObject(cJSON* const object, const char* const name);
|
|
|
|
|
|
#define cJSON_SetIntValue(object, number) ((object) ? (object)->valueint = (object)->valuedouble = (number) : (number))
|
|
|
|
CJSON_PUBLIC(double) cJSON_SetNumberHelper(cJSON* object, double number);
|
|
#define cJSON_SetNumberValue(object, number) ((object != NULL) ? cJSON_SetNumberHelper(object, (double)number) : (number))
|
|
|
|
CJSON_PUBLIC(char*) cJSON_SetValuestring(cJSON* object, const char* valuestring);
|
|
|
|
|
|
#define cJSON_SetBoolValue(object, boolValue) ( \
|
|
(object != NULL && ((object)->type & (cJSON_False|cJSON_True))) ? \
|
|
(object)->type=((object)->type &(~(cJSON_False|cJSON_True)))|((boolValue)?cJSON_True:cJSON_False) : \
|
|
cJSON_Invalid\
|
|
)
|
|
|
|
#define cJSON_ArrayForEach(element, array) for(element = (array != NULL) ? (array)->child : NULL; element != NULL; element = element->next)
|
|
|
|
CJSON_PUBLIC(void*) cJSON_malloc(size_t size);
|
|
CJSON_PUBLIC(void) cJSON_free(void* object);
|
|
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif
|
|
|
|
#endif
|