1a497129bSjef /* 2cab5dba8SBruce A. Mah Copyright (c) 2009-2017 Dave Gamble and cJSON contributors 3a497129bSjef 4a497129bSjef Permission is hereby granted, free of charge, to any person obtaining a copy 5a497129bSjef of this software and associated documentation files (the "Software"), to deal 6a497129bSjef in the Software without restriction, including without limitation the rights 7a497129bSjef to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8a497129bSjef copies of the Software, and to permit persons to whom the Software is 9a497129bSjef furnished to do so, subject to the following conditions: 10a497129bSjef 11a497129bSjef The above copyright notice and this permission notice shall be included in 12a497129bSjef all copies or substantial portions of the Software. 13a497129bSjef 14a497129bSjef THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15a497129bSjef IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16a497129bSjef FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17a497129bSjef AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18a497129bSjef LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19a497129bSjef OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20a497129bSjef THE SOFTWARE. 21a497129bSjef */ 22a8ee9c65Sf1rebird #include "iperf_config.h" 23a497129bSjef 24a497129bSjef #ifndef cJSON__h 25a497129bSjef #define cJSON__h 26a497129bSjef 27a8ee9c65Sf1rebird #ifdef HAVE_STDINT_H 28a8ee9c65Sf1rebird #include <stdint.h> 29a8ee9c65Sf1rebird #endif 30a8ee9c65Sf1rebird 31a497129bSjef #ifdef __cplusplus 32a497129bSjef extern "C" 33a497129bSjef { 34a497129bSjef #endif 35a497129bSjef 36*6c10d8a0SBruce A. Mah #if !defined(__WINDOWS__) && (defined(WIN32) || defined(WIN64) || defined(_MSC_VER) || defined(_WIN32)) 37*6c10d8a0SBruce A. Mah #define __WINDOWS__ 38*6c10d8a0SBruce A. Mah #endif 39*6c10d8a0SBruce A. Mah 40*6c10d8a0SBruce A. Mah #ifdef __WINDOWS__ 41*6c10d8a0SBruce A. Mah 42*6c10d8a0SBruce A. Mah /* When compiling for windows, we specify a specific calling convention to avoid issues where we are being called from a project with a different default calling convention. For windows you have 3 define options: 43*6c10d8a0SBruce A. Mah 44*6c10d8a0SBruce A. Mah CJSON_HIDE_SYMBOLS - Define this in the case where you don't want to ever dllexport symbols 45*6c10d8a0SBruce A. Mah CJSON_EXPORT_SYMBOLS - Define this on library build when you want to dllexport symbols (default) 46*6c10d8a0SBruce A. Mah CJSON_IMPORT_SYMBOLS - Define this if you want to dllimport symbol 47*6c10d8a0SBruce A. Mah 48*6c10d8a0SBruce A. Mah For *nix builds that support visibility attribute, you can define similar behavior by 49*6c10d8a0SBruce A. Mah 50*6c10d8a0SBruce A. Mah setting default visibility to hidden by adding 51*6c10d8a0SBruce A. Mah -fvisibility=hidden (for gcc) 52*6c10d8a0SBruce A. Mah or 53*6c10d8a0SBruce A. Mah -xldscope=hidden (for sun cc) 54*6c10d8a0SBruce A. Mah to CFLAGS 55*6c10d8a0SBruce A. Mah 56*6c10d8a0SBruce A. Mah then using the CJSON_API_VISIBILITY flag to "export" the same symbols the way CJSON_EXPORT_SYMBOLS does 57*6c10d8a0SBruce A. Mah 58*6c10d8a0SBruce A. Mah */ 59*6c10d8a0SBruce A. Mah 60*6c10d8a0SBruce A. Mah #define CJSON_CDECL __cdecl 61*6c10d8a0SBruce A. Mah #define CJSON_STDCALL __stdcall 62*6c10d8a0SBruce A. Mah 63*6c10d8a0SBruce A. Mah /* export symbols by default, this is necessary for copy pasting the C and header file */ 64*6c10d8a0SBruce A. Mah #if !defined(CJSON_HIDE_SYMBOLS) && !defined(CJSON_IMPORT_SYMBOLS) && !defined(CJSON_EXPORT_SYMBOLS) 65*6c10d8a0SBruce A. Mah #define CJSON_EXPORT_SYMBOLS 66*6c10d8a0SBruce A. Mah #endif 67*6c10d8a0SBruce A. Mah 68*6c10d8a0SBruce A. Mah #if defined(CJSON_HIDE_SYMBOLS) 69*6c10d8a0SBruce A. Mah #define CJSON_PUBLIC(type) type CJSON_STDCALL 70*6c10d8a0SBruce A. Mah #elif defined(CJSON_EXPORT_SYMBOLS) 71*6c10d8a0SBruce A. Mah #define CJSON_PUBLIC(type) __declspec(dllexport) type CJSON_STDCALL 72*6c10d8a0SBruce A. Mah #elif defined(CJSON_IMPORT_SYMBOLS) 73*6c10d8a0SBruce A. Mah #define CJSON_PUBLIC(type) __declspec(dllimport) type CJSON_STDCALL 74*6c10d8a0SBruce A. Mah #endif 75*6c10d8a0SBruce A. Mah #else /* !__WINDOWS__ */ 76*6c10d8a0SBruce A. Mah #define CJSON_CDECL 77*6c10d8a0SBruce A. Mah #define CJSON_STDCALL 78*6c10d8a0SBruce A. Mah 79*6c10d8a0SBruce A. Mah #if (defined(__GNUC__) || defined(__SUNPRO_CC) || defined (__SUNPRO_C)) && defined(CJSON_API_VISIBILITY) 80*6c10d8a0SBruce A. Mah #define CJSON_PUBLIC(type) __attribute__((visibility("default"))) type 81*6c10d8a0SBruce A. Mah #else 82*6c10d8a0SBruce A. Mah #define CJSON_PUBLIC(type) type 83*6c10d8a0SBruce A. Mah #endif 84*6c10d8a0SBruce A. Mah #endif 85*6c10d8a0SBruce A. Mah 86cab5dba8SBruce A. Mah /* project version */ 87cab5dba8SBruce A. Mah #define CJSON_VERSION_MAJOR 1 88*6c10d8a0SBruce A. Mah #define CJSON_VERSION_MINOR 7 89*6c10d8a0SBruce A. Mah #define CJSON_VERSION_PATCH 13 90cab5dba8SBruce A. Mah 91cab5dba8SBruce A. Mah #include <stddef.h> 92cab5dba8SBruce A. Mah 93a497129bSjef /* cJSON Types: */ 94cab5dba8SBruce A. Mah #define cJSON_Invalid (0) 95ed94082bSBruce A. Mah #define cJSON_False (1 << 0) 96ed94082bSBruce A. Mah #define cJSON_True (1 << 1) 97ed94082bSBruce A. Mah #define cJSON_NULL (1 << 2) 98ed94082bSBruce A. Mah #define cJSON_Number (1 << 3) 99ed94082bSBruce A. Mah #define cJSON_String (1 << 4) 100ed94082bSBruce A. Mah #define cJSON_Array (1 << 5) 101ed94082bSBruce A. Mah #define cJSON_Object (1 << 6) 102cab5dba8SBruce A. Mah #define cJSON_Raw (1 << 7) /* raw json */ 103a497129bSjef 104a497129bSjef #define cJSON_IsReference 256 105ed94082bSBruce A. Mah #define cJSON_StringIsConst 512 106a497129bSjef 107a497129bSjef /* The cJSON structure: */ 108cab5dba8SBruce A. Mah typedef struct cJSON 109cab5dba8SBruce A. Mah { 110cab5dba8SBruce A. Mah /* next/prev allow you to walk array/object chains. Alternatively, use GetArraySize/GetArrayItem/GetObjectItem */ 111cab5dba8SBruce A. Mah struct cJSON *next; 112cab5dba8SBruce A. Mah struct cJSON *prev; 113cab5dba8SBruce A. Mah /* An array or object item will have a child pointer pointing to a chain of the items in the array/object. */ 114cab5dba8SBruce A. Mah struct cJSON *child; 115a497129bSjef 116cab5dba8SBruce A. Mah /* The type of the item, as above. */ 117cab5dba8SBruce A. Mah int type; 118a497129bSjef 119cab5dba8SBruce A. Mah /* The item's string, if type==cJSON_String and type == cJSON_Raw */ 120cab5dba8SBruce A. Mah char *valuestring; 121cab5dba8SBruce A. Mah /* writing to valueint is DEPRECATED, use cJSON_SetNumberValue instead */ 122cab5dba8SBruce A. Mah int64_t valueint; 123cab5dba8SBruce A. Mah /* The item's number, if type==cJSON_Number */ 124cab5dba8SBruce A. Mah double valuedouble; 125a497129bSjef 126cab5dba8SBruce A. Mah /* The item's name string, if this item is the child of, or is in the list of subitems of an object. */ 127cab5dba8SBruce A. Mah char *string; 128a497129bSjef } cJSON; 129a497129bSjef 130cab5dba8SBruce A. Mah typedef struct cJSON_Hooks 131cab5dba8SBruce A. Mah { 132*6c10d8a0SBruce A. Mah /* malloc/free are CDECL on Windows regardless of the default calling convention of the compiler, so ensure the hooks allow passing those functions directly. */ 133*6c10d8a0SBruce A. Mah void *(CJSON_CDECL *malloc_fn)(size_t sz); 134*6c10d8a0SBruce A. Mah void (CJSON_CDECL *free_fn)(void *ptr); 135a497129bSjef } cJSON_Hooks; 136a497129bSjef 137cab5dba8SBruce A. Mah typedef int cJSON_bool; 138cab5dba8SBruce A. Mah 139cab5dba8SBruce A. Mah /* Limits how deeply nested arrays/objects can be before cJSON rejects to parse them. 140cab5dba8SBruce A. Mah * This is to prevent stack overflows. */ 141cab5dba8SBruce A. Mah #ifndef CJSON_NESTING_LIMIT 142cab5dba8SBruce A. Mah #define CJSON_NESTING_LIMIT 1000 143cab5dba8SBruce A. Mah #endif 144cab5dba8SBruce A. Mah 145cab5dba8SBruce A. Mah /* returns the version of cJSON as a string */ 146cab5dba8SBruce A. Mah CJSON_PUBLIC(const char*) cJSON_Version(void); 147cab5dba8SBruce A. Mah 148a497129bSjef /* Supply malloc, realloc and free functions to cJSON */ 149cab5dba8SBruce A. Mah CJSON_PUBLIC(void) cJSON_InitHooks(cJSON_Hooks* hooks); 150a497129bSjef 151cab5dba8SBruce A. Mah /* Memory Management: the caller is always responsible to free the results from all variants of cJSON_Parse (with cJSON_Delete) and cJSON_Print (with stdlib free, cJSON_Hooks.free_fn, or cJSON_free as appropriate). The exception is cJSON_PrintPreallocated, where the caller has full responsibility of the buffer. */ 152cab5dba8SBruce A. Mah /* Supply a block of JSON, and this returns a cJSON object you can interrogate. */ 153cab5dba8SBruce A. Mah CJSON_PUBLIC(cJSON *) cJSON_Parse(const char *value); 154*6c10d8a0SBruce A. Mah CJSON_PUBLIC(cJSON *) cJSON_ParseWithLength(const char *value, size_t buffer_length); 155*6c10d8a0SBruce A. Mah /* ParseWithOpts allows you to require (and check) that the JSON is null terminated, and to retrieve the pointer to the final byte parsed. */ 156*6c10d8a0SBruce A. Mah /* If you supply a ptr in return_parse_end and parsing fails, then return_parse_end will contain a pointer to the error so will match cJSON_GetErrorPtr(). */ 157*6c10d8a0SBruce A. Mah CJSON_PUBLIC(cJSON *) cJSON_ParseWithOpts(const char *value, const char **return_parse_end, cJSON_bool require_null_terminated); 158*6c10d8a0SBruce A. Mah CJSON_PUBLIC(cJSON *) cJSON_ParseWithLengthOpts(const char *value, size_t buffer_length, const char **return_parse_end, cJSON_bool require_null_terminated); 159*6c10d8a0SBruce A. Mah 160cab5dba8SBruce A. Mah /* Render a cJSON entity to text for transfer/storage. */ 161cab5dba8SBruce A. Mah CJSON_PUBLIC(char *) cJSON_Print(const cJSON *item); 162cab5dba8SBruce A. Mah /* Render a cJSON entity to text for transfer/storage without any formatting. */ 163cab5dba8SBruce A. Mah CJSON_PUBLIC(char *) cJSON_PrintUnformatted(const cJSON *item); 164ed94082bSBruce A. Mah /* Render a cJSON entity to text using a buffered strategy. prebuffer is a guess at the final size. guessing well reduces reallocation. fmt=0 gives unformatted, =1 gives formatted */ 165cab5dba8SBruce A. Mah CJSON_PUBLIC(char *) cJSON_PrintBuffered(const cJSON *item, int prebuffer, cJSON_bool fmt); 166cab5dba8SBruce A. Mah /* Render a cJSON entity to text using a buffer already allocated in memory with given length. Returns 1 on success and 0 on failure. */ 167cab5dba8SBruce A. Mah /* NOTE: cJSON is not always 100% accurate in estimating how much memory it will use, so to be safe allocate 5 bytes more than you actually need */ 168cab5dba8SBruce A. Mah CJSON_PUBLIC(cJSON_bool) cJSON_PrintPreallocated(cJSON *item, char *buffer, const int length, const cJSON_bool format); 169a497129bSjef /* Delete a cJSON entity and all subentities. */ 170*6c10d8a0SBruce A. Mah CJSON_PUBLIC(void) cJSON_Delete(cJSON *item); 171a497129bSjef 172a497129bSjef /* Returns the number of items in an array (or object). */ 173cab5dba8SBruce A. Mah CJSON_PUBLIC(int) cJSON_GetArraySize(const cJSON *array); 174*6c10d8a0SBruce A. Mah /* Retrieve item number "index" from array "array". Returns NULL if unsuccessful. */ 175cab5dba8SBruce A. Mah CJSON_PUBLIC(cJSON *) cJSON_GetArrayItem(const cJSON *array, int index); 176a497129bSjef /* Get item "string" from object. Case insensitive. */ 177cab5dba8SBruce A. Mah CJSON_PUBLIC(cJSON *) cJSON_GetObjectItem(const cJSON * const object, const char * const string); 178cab5dba8SBruce A. Mah CJSON_PUBLIC(cJSON *) cJSON_GetObjectItemCaseSensitive(const cJSON * const object, const char * const string); 179cab5dba8SBruce A. Mah CJSON_PUBLIC(cJSON_bool) cJSON_HasObjectItem(const cJSON *object, const char *string); 180a497129bSjef /* For analysing failed parses. This returns a pointer to the parse error. You'll probably need to look a few chars back to make sense of it. Defined when cJSON_Parse() returns 0. 0 when cJSON_Parse() succeeds. */ 181cab5dba8SBruce A. Mah CJSON_PUBLIC(const char *) cJSON_GetErrorPtr(void); 182cab5dba8SBruce A. Mah 183*6c10d8a0SBruce A. Mah /* Check item type and return its value */ 184*6c10d8a0SBruce A. Mah CJSON_PUBLIC(char *) cJSON_GetStringValue(cJSON *item); 185*6c10d8a0SBruce A. Mah CJSON_PUBLIC(double) cJSON_GetNumberValue(cJSON *item); 186*6c10d8a0SBruce A. Mah 187cab5dba8SBruce A. Mah /* These functions check the type of an item */ 188cab5dba8SBruce A. Mah CJSON_PUBLIC(cJSON_bool) cJSON_IsInvalid(const cJSON * const item); 189cab5dba8SBruce A. Mah CJSON_PUBLIC(cJSON_bool) cJSON_IsFalse(const cJSON * const item); 190cab5dba8SBruce A. Mah CJSON_PUBLIC(cJSON_bool) cJSON_IsTrue(const cJSON * const item); 191cab5dba8SBruce A. Mah CJSON_PUBLIC(cJSON_bool) cJSON_IsBool(const cJSON * const item); 192cab5dba8SBruce A. Mah CJSON_PUBLIC(cJSON_bool) cJSON_IsNull(const cJSON * const item); 193cab5dba8SBruce A. Mah CJSON_PUBLIC(cJSON_bool) cJSON_IsNumber(const cJSON * const item); 194cab5dba8SBruce A. Mah CJSON_PUBLIC(cJSON_bool) cJSON_IsString(const cJSON * const item); 195cab5dba8SBruce A. Mah CJSON_PUBLIC(cJSON_bool) cJSON_IsArray(const cJSON * const item); 196cab5dba8SBruce A. Mah CJSON_PUBLIC(cJSON_bool) cJSON_IsObject(const cJSON * const item); 197cab5dba8SBruce A. Mah CJSON_PUBLIC(cJSON_bool) cJSON_IsRaw(const cJSON * const item); 198a497129bSjef 199a497129bSjef /* These calls create a cJSON item of the appropriate type. */ 200cab5dba8SBruce A. Mah CJSON_PUBLIC(cJSON *) cJSON_CreateNull(void); 201cab5dba8SBruce A. Mah CJSON_PUBLIC(cJSON *) cJSON_CreateTrue(void); 202cab5dba8SBruce A. Mah CJSON_PUBLIC(cJSON *) cJSON_CreateFalse(void); 203cab5dba8SBruce A. Mah CJSON_PUBLIC(cJSON *) cJSON_CreateBool(cJSON_bool boolean); 204cab5dba8SBruce A. Mah CJSON_PUBLIC(cJSON *) cJSON_CreateNumber(double num); 205cab5dba8SBruce A. Mah CJSON_PUBLIC(cJSON *) cJSON_CreateString(const char *string); 206cab5dba8SBruce A. Mah /* raw json */ 207cab5dba8SBruce A. Mah CJSON_PUBLIC(cJSON *) cJSON_CreateRaw(const char *raw); 208cab5dba8SBruce A. Mah CJSON_PUBLIC(cJSON *) cJSON_CreateArray(void); 209cab5dba8SBruce A. Mah CJSON_PUBLIC(cJSON *) cJSON_CreateObject(void); 210a497129bSjef 211*6c10d8a0SBruce A. Mah /* Create a string where valuestring references a string so 212*6c10d8a0SBruce A. Mah * it will not be freed by cJSON_Delete */ 213*6c10d8a0SBruce A. Mah CJSON_PUBLIC(cJSON *) cJSON_CreateStringReference(const char *string); 214*6c10d8a0SBruce A. Mah /* Create an object/array that only references it's elements so 215*6c10d8a0SBruce A. Mah * they will not be freed by cJSON_Delete */ 216*6c10d8a0SBruce A. Mah CJSON_PUBLIC(cJSON *) cJSON_CreateObjectReference(const cJSON *child); 217*6c10d8a0SBruce A. Mah CJSON_PUBLIC(cJSON *) cJSON_CreateArrayReference(const cJSON *child); 218*6c10d8a0SBruce A. Mah 219*6c10d8a0SBruce A. Mah /* These utilities create an Array of count items. 220*6c10d8a0SBruce A. Mah * The parameter count cannot be greater than the number of elements in the number array, otherwise array access will be out of bounds.*/ 221cab5dba8SBruce A. Mah CJSON_PUBLIC(cJSON *) cJSON_CreateIntArray(const int *numbers, int count); 222cab5dba8SBruce A. Mah CJSON_PUBLIC(cJSON *) cJSON_CreateFloatArray(const float *numbers, int count); 223cab5dba8SBruce A. Mah CJSON_PUBLIC(cJSON *) cJSON_CreateDoubleArray(const double *numbers, int count); 224*6c10d8a0SBruce A. Mah CJSON_PUBLIC(cJSON *) cJSON_CreateStringArray(const char *const *strings, int count); 225a497129bSjef 226a497129bSjef /* Append item to the specified array/object. */ 227*6c10d8a0SBruce A. Mah CJSON_PUBLIC(cJSON_bool) cJSON_AddItemToArray(cJSON *array, cJSON *item); 228*6c10d8a0SBruce A. Mah CJSON_PUBLIC(cJSON_bool) cJSON_AddItemToObject(cJSON *object, const char *string, cJSON *item); 229cab5dba8SBruce A. Mah /* Use this when string is definitely const (i.e. a literal, or as good as), and will definitely survive the cJSON object. 230cab5dba8SBruce A. Mah * WARNING: When this function was used, make sure to always check that (item->type & cJSON_StringIsConst) is zero before 231cab5dba8SBruce A. Mah * writing to `item->string` */ 232*6c10d8a0SBruce A. Mah CJSON_PUBLIC(cJSON_bool) cJSON_AddItemToObjectCS(cJSON *object, const char *string, cJSON *item); 233a497129bSjef /* Append reference to item to the specified array/object. Use this when you want to add an existing cJSON to a new cJSON, but don't want to corrupt your existing cJSON. */ 234*6c10d8a0SBruce A. Mah CJSON_PUBLIC(cJSON_bool) cJSON_AddItemReferenceToArray(cJSON *array, cJSON *item); 235*6c10d8a0SBruce A. Mah CJSON_PUBLIC(cJSON_bool) cJSON_AddItemReferenceToObject(cJSON *object, const char *string, cJSON *item); 236a497129bSjef 237*6c10d8a0SBruce A. Mah /* Remove/Detach items from Arrays/Objects. */ 238cab5dba8SBruce A. Mah CJSON_PUBLIC(cJSON *) cJSON_DetachItemViaPointer(cJSON *parent, cJSON * const item); 239cab5dba8SBruce A. Mah CJSON_PUBLIC(cJSON *) cJSON_DetachItemFromArray(cJSON *array, int which); 240cab5dba8SBruce A. Mah CJSON_PUBLIC(void) cJSON_DeleteItemFromArray(cJSON *array, int which); 241cab5dba8SBruce A. Mah CJSON_PUBLIC(cJSON *) cJSON_DetachItemFromObject(cJSON *object, const char *string); 242cab5dba8SBruce A. Mah CJSON_PUBLIC(cJSON *) cJSON_DetachItemFromObjectCaseSensitive(cJSON *object, const char *string); 243cab5dba8SBruce A. Mah CJSON_PUBLIC(void) cJSON_DeleteItemFromObject(cJSON *object, const char *string); 244cab5dba8SBruce A. Mah CJSON_PUBLIC(void) cJSON_DeleteItemFromObjectCaseSensitive(cJSON *object, const char *string); 245a497129bSjef 246a497129bSjef /* Update array items. */ 247*6c10d8a0SBruce A. Mah CJSON_PUBLIC(cJSON_bool) cJSON_InsertItemInArray(cJSON *array, int which, cJSON *newitem); /* Shifts pre-existing items to the right. */ 248cab5dba8SBruce A. Mah CJSON_PUBLIC(cJSON_bool) cJSON_ReplaceItemViaPointer(cJSON * const parent, cJSON * const item, cJSON * replacement); 249*6c10d8a0SBruce A. Mah CJSON_PUBLIC(cJSON_bool) cJSON_ReplaceItemInArray(cJSON *array, int which, cJSON *newitem); 250*6c10d8a0SBruce A. Mah CJSON_PUBLIC(cJSON_bool) cJSON_ReplaceItemInObject(cJSON *object,const char *string,cJSON *newitem); 251*6c10d8a0SBruce A. Mah CJSON_PUBLIC(cJSON_bool) cJSON_ReplaceItemInObjectCaseSensitive(cJSON *object,const char *string,cJSON *newitem); 252a497129bSjef 253ed94082bSBruce A. Mah /* Duplicate a cJSON item */ 254cab5dba8SBruce A. Mah CJSON_PUBLIC(cJSON *) cJSON_Duplicate(const cJSON *item, cJSON_bool recurse); 255ed94082bSBruce A. Mah /* Duplicate will create a new, identical cJSON item to the one you pass, in new memory that will 256*6c10d8a0SBruce A. Mah * need to be released. With recurse!=0, it will duplicate any children connected to the item. 257*6c10d8a0SBruce A. Mah * The item->next and ->prev pointers are always zero on return from Duplicate. */ 258cab5dba8SBruce A. Mah /* Recursively compare two cJSON items for equality. If either a or b is NULL or invalid, they will be considered unequal. 259cab5dba8SBruce A. Mah * case_sensitive determines if object keys are treated case sensitive (1) or case insensitive (0) */ 260cab5dba8SBruce A. Mah CJSON_PUBLIC(cJSON_bool) cJSON_Compare(const cJSON * const a, const cJSON * const b, const cJSON_bool case_sensitive); 261cab5dba8SBruce A. Mah 262*6c10d8a0SBruce A. Mah /* Minify a strings, remove blank characters(such as ' ', '\t', '\r', '\n') from strings. 263*6c10d8a0SBruce A. Mah * The input pointer json cannot point to a read-only address area, such as a string constant, 264*6c10d8a0SBruce A. Mah * but should point to a readable and writable adress area. */ 265cab5dba8SBruce A. Mah CJSON_PUBLIC(void) cJSON_Minify(char *json); 266ed94082bSBruce A. Mah 267*6c10d8a0SBruce A. Mah /* Helper functions for creating and adding items to an object at the same time. 268*6c10d8a0SBruce A. Mah * They return the added item or NULL on failure. */ 269*6c10d8a0SBruce A. Mah CJSON_PUBLIC(cJSON*) cJSON_AddNullToObject(cJSON * const object, const char * const name); 270*6c10d8a0SBruce A. Mah CJSON_PUBLIC(cJSON*) cJSON_AddTrueToObject(cJSON * const object, const char * const name); 271*6c10d8a0SBruce A. Mah CJSON_PUBLIC(cJSON*) cJSON_AddFalseToObject(cJSON * const object, const char * const name); 272*6c10d8a0SBruce A. Mah CJSON_PUBLIC(cJSON*) cJSON_AddBoolToObject(cJSON * const object, const char * const name, const cJSON_bool boolean); 273*6c10d8a0SBruce A. Mah CJSON_PUBLIC(cJSON*) cJSON_AddNumberToObject(cJSON * const object, const char * const name, const double number); 274*6c10d8a0SBruce A. Mah CJSON_PUBLIC(cJSON*) cJSON_AddStringToObject(cJSON * const object, const char * const name, const char * const string); 275*6c10d8a0SBruce A. Mah CJSON_PUBLIC(cJSON*) cJSON_AddRawToObject(cJSON * const object, const char * const name, const char * const raw); 276*6c10d8a0SBruce A. Mah CJSON_PUBLIC(cJSON*) cJSON_AddObjectToObject(cJSON * const object, const char * const name); 277*6c10d8a0SBruce A. Mah CJSON_PUBLIC(cJSON*) cJSON_AddArrayToObject(cJSON * const object, const char * const name); 278a497129bSjef 279ed94082bSBruce A. Mah /* When assigning an integer value, it needs to be propagated to valuedouble too. */ 280cab5dba8SBruce A. Mah #define cJSON_SetIntValue(object, number) ((object) ? (object)->valueint = (object)->valuedouble = (number) : (number)) 281cab5dba8SBruce A. Mah /* helper for the cJSON_SetNumberValue macro */ 282cab5dba8SBruce A. Mah CJSON_PUBLIC(double) cJSON_SetNumberHelper(cJSON *object, double number); 283cab5dba8SBruce A. Mah #define cJSON_SetNumberValue(object, number) ((object != NULL) ? cJSON_SetNumberHelper(object, (double)number) : (number)) 284*6c10d8a0SBruce A. Mah /* Change the valuestring of a cJSON_String object, only takes effect when type of object is cJSON_String */ 285*6c10d8a0SBruce A. Mah CJSON_PUBLIC(char*) cJSON_SetValuestring(cJSON *object, const char *valuestring); 286ed94082bSBruce A. Mah 287*6c10d8a0SBruce A. Mah /* Macro for iterating over an array or object */ 288cab5dba8SBruce A. Mah #define cJSON_ArrayForEach(element, array) for(element = (array != NULL) ? (array)->child : NULL; element != NULL; element = element->next) 289cab5dba8SBruce A. Mah 290cab5dba8SBruce A. Mah /* malloc/free objects using the malloc/free functions that have been set with cJSON_InitHooks */ 291cab5dba8SBruce A. Mah CJSON_PUBLIC(void *) cJSON_malloc(size_t size); 292cab5dba8SBruce A. Mah CJSON_PUBLIC(void) cJSON_free(void *object); 293ed94082bSBruce A. Mah 294a497129bSjef #ifdef __cplusplus 295a497129bSjef } 296a497129bSjef #endif 297a497129bSjef 298a497129bSjef #endif 299