]>
Commit | Line | Data |
---|---|---|
d430a5e8 SS |
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 komodo_cJSON__h | |
24 | #define komodo_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 | ||
34 | #include "cJSON.h" | |
35 | ||
36 | //#include "../crypto777/OS_portable.h" | |
37 | ||
38 | #define MAX_JSON_FIELD 4096 // on the big side | |
39 | ||
40 | #ifdef __cplusplus | |
41 | extern "C" | |
42 | { | |
43 | #endif | |
44 | ||
45 | /* Macros for creating things quickly. */ | |
46 | #define cJSON_AddNullToObject(object,name) cJSON_AddItemToObject(object, name, cJSON_CreateNull()) | |
47 | #define cJSON_AddTrueToObject(object,name) cJSON_AddItemToObject(object, name, cJSON_CreateTrue()) | |
48 | #define cJSON_AddFalseToObject(object,name) cJSON_AddItemToObject(object, name, cJSON_CreateFalse()) | |
49 | #define cJSON_AddBoolToObject(object,name,b) cJSON_AddItemToObject(object, name, cJSON_CreateBool(b)) | |
50 | #define cJSON_AddNumberToObject(object,name,n) cJSON_AddItemToObject(object, name, cJSON_CreateNumber(n)) | |
51 | #define cJSON_AddStringToObject(object,name,s) cJSON_AddItemToObject(object, name, cJSON_CreateString(s)) | |
52 | ||
53 | struct destbuf { char buf[MAX_JSON_FIELD]; }; | |
54 | ||
55 | #define jfieldstr get_cJSON_fieldname | |
56 | ||
57 | char *cJSON_str(cJSON *json); | |
58 | char *jstr(cJSON *json,char *field); | |
59 | char *jprint(cJSON *json,int32_t freeflag); | |
60 | int32_t jint(cJSON *json,char *field); | |
61 | uint32_t juint(cJSON *json,char *field); | |
62 | char *jstri(cJSON *json,int32_t i); | |
63 | int32_t jinti(cJSON *json,int32_t i); | |
64 | uint32_t juinti(cJSON *json,int32_t i); | |
65 | uint64_t j64bitsi(cJSON *json,int32_t i); | |
66 | double jdoublei(cJSON *json,int32_t i); | |
67 | double jdouble(cJSON *json,char *field); | |
68 | cJSON *jobj(cJSON *json,char *field); | |
69 | cJSON *jarray(int32_t *nump,cJSON *json,char *field); | |
70 | cJSON *jitem(cJSON *array,int32_t i); | |
71 | uint64_t j64bits(cJSON *json,char *field); | |
72 | void jadd(cJSON *json,char *field,cJSON *item); | |
73 | void jaddstr(cJSON *json,char *field,char *str); | |
74 | void jaddnum(cJSON *json,char *field,double num); | |
75 | void jadd64bits(cJSON *json,char *field,uint64_t nxt64bits); | |
76 | void jaddi(cJSON *json,cJSON *item); | |
77 | void jaddistr(cJSON *json,char *str); | |
78 | void jaddinum(cJSON *json,double num); | |
79 | void jaddi64bits(cJSON *json,uint64_t nxt64bits); | |
80 | void jdelete(cJSON *object,char *string); | |
81 | cJSON *jduplicate(cJSON *json); | |
82 | int32_t jnum(cJSON *obj,char *field); | |
83 | ||
84 | bits256 jbits256(cJSON *json,char *field); | |
85 | bits256 jbits256i(cJSON *json,int32_t i); | |
86 | void jaddbits256(cJSON *json,char *field,bits256 hash); | |
87 | void jaddibits256(cJSON *json,bits256 hash); | |
88 | void copy_cJSON(struct destbuf *dest,cJSON *obj); | |
89 | void copy_cJSON2(char *dest,int32_t maxlen,cJSON *obj); | |
90 | cJSON *gen_list_json(char **list); | |
91 | int32_t extract_cJSON_str(char *dest,int32_t max,cJSON *json,char *field); | |
92 | ||
93 | void free_json(cJSON *json); | |
94 | int64_t _conv_cJSON_float(cJSON *json); | |
95 | int64_t conv_cJSON_float(cJSON *json,char *field); | |
96 | int64_t get_cJSON_int(cJSON *json,char *field); | |
97 | void add_satoshis_json(cJSON *json,char *field,uint64_t satoshis); | |
98 | uint64_t get_satoshi_obj(cJSON *json,char *field); | |
99 | ||
100 | int32_t get_API_int(cJSON *obj,int32_t val); | |
101 | uint32_t get_API_uint(cJSON *obj,uint32_t val); | |
102 | uint64_t get_API_nxt64bits(cJSON *obj); | |
103 | double get_API_float(cJSON *obj); | |
104 | char *get_cJSON_fieldname(cJSON *obj); | |
105 | void ensure_jsonitem(cJSON *json,char *field,char *value); | |
106 | int32_t in_jsonarray(cJSON *array,char *value); | |
107 | char *bitcoind_RPC(char **retstrp,char *debugstr,char *url,char *userpass,char *command,char *params); | |
108 | uint64_t calc_nxt64bits(const char *str); | |
109 | int32_t expand_nxt64bits(char *str,uint64_t nxt64bits); | |
110 | char *nxt64str(uint64_t nxt64bits); | |
111 | char *nxt64str2(uint64_t nxt64bits); | |
112 | cJSON *addrs_jsonarray(uint64_t *addrs,int32_t num); | |
113 | int32_t myatoi(char *str,int32_t range); | |
114 | ||
115 | char *stringifyM(char *str); | |
116 | #define replace_backslashquotes unstringify | |
117 | char *unstringify(char *str); | |
118 | #define jtrue cJSON_CreateTrue | |
119 | #define jfalse cJSON_CreateFalse | |
120 | ||
121 | #define jfieldname get_cJSON_fieldname | |
122 | ||
123 | #ifdef __cplusplus | |
124 | } | |
125 | #endif | |
126 | ||
127 | #endif |