]> Git Repo - VerusCoin.git/blame - src/cJSON.h
test
[VerusCoin.git] / src / cJSON.h
CommitLineData
3a2b2b45 1/*
2 Copyright (c) 2009 Dave Gamble
3
4 Permission is hereby granted, free of charge, to any person obtaining a copy
5 of this software and associated documentation files (the "Software"), to deal
6 in the Software without restriction, including without limitation the rights
7 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 copies of the Software, and to permit persons to whom the Software is
9 furnished to do so, subject to the following conditions:
10
11 The above copyright notice and this permission notice shall be included in
12 all copies or substantial portions of the Software.
13
14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20 THE SOFTWARE.
21 */
22
23#ifndef cJSON__h
24#define cJSON__h
25
26#include <stdio.h>
27#include <stdlib.h>
28#include <stdint.h>
29#include <math.h>
30#include <ctype.h>
31#include <float.h>
32#include <memory.h>
33
c23b9ce3 34//#include "../crypto777/OS_portable.h"
3a2b2b45 35
3a2b2b45 36#define MAX_JSON_FIELD 4096 // on the big side
37
38#ifdef __cplusplus
39extern "C"
40{
41#endif
42
43 /* cJSON Types: */
44#define cJSON_False 0
45#define cJSON_True 1
46#define cJSON_NULL 2
47#define cJSON_Number 3
48#define cJSON_String 4
49#define cJSON_Array 5
50#define cJSON_Object 6
51
52#define is_cJSON_Null(json) ((json) != 0 && ((json)->type & 0xff) == cJSON_NULL)
53#define is_cJSON_Array(json) ((json) != 0 && ((json)->type & 0xff) == cJSON_Array)
54#define is_cJSON_String(json) ((json) != 0 && ((json)->type & 0xff) == cJSON_String)
55#define is_cJSON_Number(json) ((json) != 0 && ((json)->type & 0xff) == cJSON_Number)
56#define is_cJSON_Object(json) ((json) != 0 && ((json)->type & 0xff) == cJSON_Object)
57#define is_cJSON_True(json) ((json) != 0 && ((json)->type & 0xff) == cJSON_True)
58#define is_cJSON_False(json) ((json) != 0 && ((json)->type & 0xff) == cJSON_False)
59
60#define cJSON_IsReference 256
61
62 /* The cJSON structure: */
63 typedef struct cJSON {
64 struct cJSON *next,*prev; /* next/prev allow you to walk array/object chains. Alternatively, use GetArraySize/GetArrayItem/GetObjectItem */
65 struct cJSON *child; /* An array or object item will have a child pointer pointing to a chain of the items in the array/object. */
66
67 int32_t type; /* The type of the item, as above. */
68
69 char *valuestring; /* The item's string, if type==cJSON_String */
70 int64_t valueint; /* The item's number, if type==cJSON_Number */
71 double valuedouble; /* The item's number, if type==cJSON_Number */
72
73 char *string; /* The item's name string, if this item is the child of, or is in the list of subitems of an object. */
74 } cJSON;
75
76 typedef struct cJSON_Hooks {
77 void *(*malloc_fn)(size_t sz);
78 void (*free_fn)(void *ptr);
79 } cJSON_Hooks;
80
81 /* Supply malloc, realloc and free functions to cJSON */
82 extern void cJSON_InitHooks(cJSON_Hooks* hooks);
83
84
85 /* Supply a block of JSON, and this returns a cJSON object you can interrogate. Call cJSON_Delete when finished. */
86 extern cJSON *cJSON_Parse(const char *value);
87 /* Render a cJSON entity to text for transfer/storage. Free the char* when finished. */
88 extern char *cJSON_Print(cJSON *item);
89 /* Render a cJSON entity to text for transfer/storage without any formatting. Free the char* when finished. */
90 extern char *cJSON_PrintUnformatted(cJSON *item);
91 /* Delete a cJSON entity and all subentities. */
92 extern void cJSON_Delete(cJSON *c);
93
94 /* Returns the number of items in an array (or object). */
95 extern int cJSON_GetArraySize(cJSON *array);
96 /* Retrieve item number "item" from array "array". Returns NULL if unsuccessful. */
97 extern cJSON *cJSON_GetArrayItem(cJSON *array,int32_t item);
98 /* Get item "string" from object. Case insensitive. */
99 extern cJSON *cJSON_GetObjectItem(cJSON *object,const char *string);
100
101 /* 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. */
102 extern const char *cJSON_GetErrorPtr(void);
103
104 /* These calls create a cJSON item of the appropriate type. */
105 extern cJSON *cJSON_CreateNull(void);
106 extern cJSON *cJSON_CreateTrue(void);
107 extern cJSON *cJSON_CreateFalse(void);
108 extern cJSON *cJSON_CreateBool(int32_t b);
109 extern cJSON *cJSON_CreateNumber(double num);
110 extern cJSON *cJSON_CreateString(const char *string);
111 extern cJSON *cJSON_CreateArray(void);
112 extern cJSON *cJSON_CreateObject(void);
113
114 /* These utilities create an Array of count items. */
115 extern cJSON *cJSON_CreateIntArray(int64_t *numbers,int32_t count);
116 extern cJSON *cJSON_CreateFloatArray(float *numbers,int32_t count);
117 extern cJSON *cJSON_CreateDoubleArray(double *numbers,int32_t count);
118 extern cJSON *cJSON_CreateStringArray(char **strings,int32_t count);
119
120 /* Append item to the specified array/object. */
121 extern void cJSON_AddItemToArray(cJSON *array, cJSON *item);
122 extern void cJSON_AddItemToObject(cJSON *object,const char *string,cJSON *item);
123 /* 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. */
124 extern void cJSON_AddItemReferenceToArray(cJSON *array, cJSON *item);
125 extern void cJSON_AddItemReferenceToObject(cJSON *object,const char *string,cJSON *item);
126
127 /* Remove/Detatch items from Arrays/Objects. */
128 extern cJSON *cJSON_DetachItemFromArray(cJSON *array,int32_t which);
129 extern void cJSON_DeleteItemFromArray(cJSON *array,int32_t which);
130 extern cJSON *cJSON_DetachItemFromObject(cJSON *object,const char *string);
131 extern void cJSON_DeleteItemFromObject(cJSON *object,const char *string);
132
133 /* Update array items. */
134 extern void cJSON_ReplaceItemInArray(cJSON *array,int32_t which,cJSON *newitem);
135 extern void cJSON_ReplaceItemInObject(cJSON *object,const char *string,cJSON *newitem);
136
137 /* Duplicate a cJSON item */
138 extern cJSON *cJSON_Duplicate(cJSON *item,int32_t recurse);
139 /* Duplicate will create a new, identical cJSON item to the one you pass, in new memory that will
140 need to be released. With recurse!=0, it will duplicate any children connected to the item.
141 The item->next and ->prev pointers are always zero on return from Duplicate. */
142
143 /* ParseWithOpts allows you to require (and check) that the JSON is null terminated, and to retrieve the pointer to the final byte parsed. */
144 extern cJSON *cJSON_ParseWithOpts(const char *value,const char **return_parse_end,int32_t require_null_terminated);
145
146 extern void cJSON_Minify(char *json);
147
148 /* Macros for creating things quickly. */
149#define cJSON_AddNullToObject(object,name) cJSON_AddItemToObject(object, name, cJSON_CreateNull())
150#define cJSON_AddTrueToObject(object,name) cJSON_AddItemToObject(object, name, cJSON_CreateTrue())
151#define cJSON_AddFalseToObject(object,name) cJSON_AddItemToObject(object, name, cJSON_CreateFalse())
152#define cJSON_AddBoolToObject(object,name,b) cJSON_AddItemToObject(object, name, cJSON_CreateBool(b))
153#define cJSON_AddNumberToObject(object,name,n) cJSON_AddItemToObject(object, name, cJSON_CreateNumber(n))
154#define cJSON_AddStringToObject(object,name,s) cJSON_AddItemToObject(object, name, cJSON_CreateString(s))
155
156 struct destbuf { char buf[MAX_JSON_FIELD]; };
157
158 /* When assigning an integer value, it needs to be propagated to valuedouble too. */
159#define cJSON_SetIntValue(object,val) ((object)?(object)->valueint=(object)->valuedouble=(val):(val))
160#define jfieldstr get_cJSON_fieldname
161
162 char *cJSON_str(cJSON *json);
163 char *jstr(cJSON *json,char *field);
164 char *jprint(cJSON *json,int32_t freeflag);
165 int32_t jint(cJSON *json,char *field);
166 uint32_t juint(cJSON *json,char *field);
167 char *jstri(cJSON *json,int32_t i);
168 int32_t jinti(cJSON *json,int32_t i);
169 uint32_t juinti(cJSON *json,int32_t i);
170 uint64_t j64bitsi(cJSON *json,int32_t i);
171 double jdoublei(cJSON *json,int32_t i);
172 double jdouble(cJSON *json,char *field);
173 cJSON *jobj(cJSON *json,char *field);
174 cJSON *jarray(int32_t *nump,cJSON *json,char *field);
175 cJSON *jitem(cJSON *array,int32_t i);
176 uint64_t j64bits(cJSON *json,char *field);
177 void jadd(cJSON *json,char *field,cJSON *item);
178 void jaddstr(cJSON *json,char *field,char *str);
179 void jaddnum(cJSON *json,char *field,double num);
180 void jadd64bits(cJSON *json,char *field,uint64_t nxt64bits);
181 void jaddi(cJSON *json,cJSON *item);
182 void jaddistr(cJSON *json,char *str);
183 void jaddinum(cJSON *json,double num);
184 void jaddi64bits(cJSON *json,uint64_t nxt64bits);
185 void jdelete(cJSON *object,char *string);
186 cJSON *jduplicate(cJSON *json);
187 int32_t jnum(cJSON *obj,char *field);
188
189 bits256 jbits256(cJSON *json,char *field);
190 bits256 jbits256i(cJSON *json,int32_t i);
191 void jaddbits256(cJSON *json,char *field,bits256 hash);
192 void jaddibits256(cJSON *json,bits256 hash);
193 void copy_cJSON(struct destbuf *dest,cJSON *obj);
194 void copy_cJSON2(char *dest,int32_t maxlen,cJSON *obj);
195 cJSON *gen_list_json(char **list);
196 int32_t extract_cJSON_str(char *dest,int32_t max,cJSON *json,char *field);
197
198 void free_json(cJSON *json);
199 int64_t _conv_cJSON_float(cJSON *json);
200 int64_t conv_cJSON_float(cJSON *json,char *field);
201 int64_t get_cJSON_int(cJSON *json,char *field);
202 void add_satoshis_json(cJSON *json,char *field,uint64_t satoshis);
203 uint64_t get_satoshi_obj(cJSON *json,char *field);
204
205 int32_t get_API_int(cJSON *obj,int32_t val);
206 uint32_t get_API_uint(cJSON *obj,uint32_t val);
207 uint64_t get_API_nxt64bits(cJSON *obj);
208 double get_API_float(cJSON *obj);
209 char *get_cJSON_fieldname(cJSON *obj);
210 void ensure_jsonitem(cJSON *json,char *field,char *value);
211 int32_t in_jsonarray(cJSON *array,char *value);
212 char *bitcoind_RPC(char **retstrp,char *debugstr,char *url,char *userpass,char *command,char *params);
213 uint64_t calc_nxt64bits(const char *str);
214 int32_t expand_nxt64bits(char *str,uint64_t nxt64bits);
215 char *nxt64str(uint64_t nxt64bits);
216 char *nxt64str2(uint64_t nxt64bits);
217 cJSON *addrs_jsonarray(uint64_t *addrs,int32_t num);
218 int32_t myatoi(char *str,int32_t range);
219
220 char *stringifyM(char *str);
221#define replace_backslashquotes unstringify
222 char *unstringify(char *str);
223#define jtrue cJSON_CreateTrue
224#define jfalse cJSON_CreateFalse
225
226#define jfieldname get_cJSON_fieldname
227
228#ifdef __cplusplus
229}
230#endif
231
232#endif
This page took 0.053434 seconds and 4 git commands to generate.