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