12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034 |
- #ifndef _json_object_h_
- #define _json_object_h_
- #ifdef __GNUC__
- #define THIS_FUNCTION_IS_DEPRECATED(func) func __attribute__ ((deprecated))
- #elif defined(_MSC_VER)
- #define THIS_FUNCTION_IS_DEPRECATED(func) __declspec(deprecated) func
- #elif defined(__clang__)
- #define THIS_FUNCTION_IS_DEPRECATED(func) func __deprecated
- #else
- #define THIS_FUNCTION_IS_DEPRECATED(func) func
- #endif
- #ifdef __GNUC__
- #define JSON_C_CONST_FUNCTION(func) func __attribute__((const))
- #else
- #define JSON_C_CONST_FUNCTION(func) func
- #endif
- #if defined(_MSC_VER)
- #define JSON_EXPORT __declspec(dllexport)
- #else
- #define JSON_EXPORT extern
- #endif
- #include <stddef.h>
- #include "json_inttypes.h"
- #include "printbuf.h"
- #ifdef __cplusplus
- extern "C" {
- #endif
- #define JSON_OBJECT_DEF_HASH_ENTRIES 16
- #define JSON_C_TO_STRING_PLAIN 0
- #define JSON_C_TO_STRING_SPACED (1<<0)
- #define JSON_C_TO_STRING_PRETTY (1<<1)
- #define JSON_C_TO_STRING_PRETTY_TAB (1<<3)
- #define JSON_C_TO_STRING_NOZERO (1<<2)
- #define JSON_C_TO_STRING_NOSLASHESCAPE (1<<4)
- #define JSON_C_OBJECT_ADD_KEY_IS_NEW (1<<1)
- #define JSON_C_OBJECT_KEY_IS_CONSTANT (1<<2)
- #undef FALSE
- #define FALSE ((json_bool)0)
- #undef TRUE
- #define TRUE ((json_bool)1)
- #define JSON_C_OPTION_GLOBAL (0)
- #define JSON_C_OPTION_THREAD (1)
- struct json_object_iter
- {
- char *key;
- struct json_object *val;
- struct lh_entry *entry;
- };
- typedef struct json_object_iter json_object_iter;
- typedef int json_bool;
- typedef struct json_object json_object;
- typedef void (json_object_delete_fn)(struct json_object *jso, void *userdata);
- typedef int (json_object_to_json_string_fn)(struct json_object *jso,
- struct printbuf *pb,
- int level,
- int flags);
- typedef enum json_type {
-
- json_type_null,
- json_type_boolean,
- json_type_double,
- json_type_int,
- json_type_object,
- json_type_array,
- json_type_string
- } json_type;
- JSON_EXPORT struct json_object* json_object_get(struct json_object *obj);
- JSON_EXPORT int json_object_put(struct json_object *obj);
- JSON_EXPORT int json_object_is_type(const struct json_object *obj, enum json_type type);
- JSON_EXPORT enum json_type json_object_get_type(const struct json_object *obj);
- JSON_EXPORT const char* json_object_to_json_string(struct json_object *obj);
- JSON_EXPORT const char* json_object_to_json_string_ext(struct json_object *obj, int
- flags);
- JSON_EXPORT const char* json_object_to_json_string_length(struct json_object *obj, int
- flags, size_t *length);
- JSON_EXPORT void* json_object_get_userdata(json_object *jso);
- JSON_EXPORT void json_object_set_userdata(json_object *jso, void *userdata,
- json_object_delete_fn *user_delete);
- JSON_EXPORT void json_object_set_serializer(json_object *jso,
- json_object_to_json_string_fn *to_string_func,
- void *userdata,
- json_object_delete_fn *user_delete);
- #ifdef __clang__
- #pragma clang diagnostic push
- #pragma clang diagnostic ignored "-Wdocumentation"
- #endif
- json_object_delete_fn json_object_free_userdata;
- json_object_to_json_string_fn json_object_userdata_to_json_string;
- #ifdef __clang__
- #pragma clang diagnostic pop
- #endif
- JSON_EXPORT struct json_object* json_object_new_object(void);
- JSON_EXPORT struct lh_table* json_object_get_object(const struct json_object *obj);
- JSON_EXPORT int json_object_object_length(const struct json_object* obj);
- JSON_C_CONST_FUNCTION(JSON_EXPORT size_t json_c_object_sizeof(void));
- JSON_EXPORT int json_object_object_add(struct json_object* obj, const char *key,
- struct json_object *val);
- JSON_EXPORT int json_object_object_add_ex(struct json_object* obj,
- const char *const key,
- struct json_object *const val,
- const unsigned opts);
- JSON_EXPORT struct json_object* json_object_object_get(const struct json_object* obj,
- const char *key);
- JSON_EXPORT json_bool json_object_object_get_ex(const struct json_object* obj,
- const char *key,
- struct json_object **value);
- JSON_EXPORT void json_object_object_del(struct json_object* obj, const char *key);
- #if defined(__GNUC__) && !defined(__STRICT_ANSI__) && __STDC_VERSION__ >= 199901L
- # define json_object_object_foreach(obj,key,val) \
- char *key = NULL; \
- struct json_object *val __attribute__((__unused__)) = NULL; \
- for(struct lh_entry *entry ## key = json_object_get_object(obj)->head, *entry_next ## key = NULL; \
- ({ if(entry ## key) { \
- key = (char*)lh_entry_k(entry ## key); \
- val = (struct json_object*)lh_entry_v(entry ## key); \
- entry_next ## key = entry ## key->next; \
- } ; entry ## key; }); \
- entry ## key = entry_next ## key )
- #else
- # define json_object_object_foreach(obj,key,val) \
- char *key = NULL;\
- struct json_object *val = NULL; \
- struct lh_entry *entry ## key; \
- struct lh_entry *entry_next ## key = NULL; \
- for(entry ## key = json_object_get_object(obj)->head; \
- (entry ## key ? ( \
- key = (char*)lh_entry_k(entry ## key), \
- val = (struct json_object*)lh_entry_v(entry ## key), \
- entry_next ## key = entry ## key->next, \
- entry ## key) : 0); \
- entry ## key = entry_next ## key)
- #endif
- #define json_object_object_foreachC(obj,iter) \
- for(iter.entry = json_object_get_object(obj)->head; \
- (iter.entry ? (iter.key = (char*)lh_entry_k(iter.entry), iter.val = (struct json_object*)lh_entry_v(iter.entry), iter.entry) : 0); \
- iter.entry = iter.entry->next)
- JSON_EXPORT struct json_object* json_object_new_array(void);
- JSON_EXPORT struct array_list* json_object_get_array(const struct json_object *obj);
- JSON_EXPORT size_t json_object_array_length(const struct json_object *obj);
- JSON_EXPORT void json_object_array_sort(struct json_object *jso, int(*sort_fn)(const void *, const void *));
- JSON_EXPORT struct json_object* json_object_array_bsearch(
- const struct json_object *key,
- const struct json_object *jso,
- int (*sort_fn)(const void *, const void *));
- JSON_EXPORT int json_object_array_add(struct json_object *obj,
- struct json_object *val);
- JSON_EXPORT int json_object_array_put_idx(struct json_object *obj, size_t idx,
- struct json_object *val);
- JSON_EXPORT struct json_object* json_object_array_get_idx(const struct json_object *obj,
- size_t idx);
- JSON_EXPORT int json_object_array_del_idx(struct json_object *obj, size_t idx, size_t count);
- JSON_EXPORT struct json_object* json_object_new_boolean(json_bool b);
- JSON_EXPORT json_bool json_object_get_boolean(const struct json_object *obj);
- JSON_EXPORT int json_object_set_boolean(struct json_object *obj,json_bool new_value);
- JSON_EXPORT struct json_object* json_object_new_int(int32_t i);
- JSON_EXPORT struct json_object* json_object_new_int64(int64_t i);
- JSON_EXPORT int32_t json_object_get_int(const struct json_object *obj);
- JSON_EXPORT int json_object_set_int(struct json_object *obj,int new_value);
- JSON_EXPORT int json_object_int_inc(struct json_object *obj, int64_t val);
- JSON_EXPORT int64_t json_object_get_int64(const struct json_object *obj);
- JSON_EXPORT int json_object_set_int64(struct json_object *obj,int64_t new_value);
- JSON_EXPORT struct json_object* json_object_new_double(double d);
- JSON_EXPORT struct json_object* json_object_new_double_s(double d, const char *ds);
- int json_c_set_serialization_double_format(const char *double_format, int global_or_thread);
- JSON_EXPORT int json_object_double_to_json_string(struct json_object* jso,
- struct printbuf *pb,
- int level,
- int flags);
- JSON_EXPORT double json_object_get_double(const struct json_object *obj);
- JSON_EXPORT int json_object_set_double(struct json_object *obj,double new_value);
- JSON_EXPORT struct json_object* json_object_new_string(const char *s);
- JSON_EXPORT struct json_object* json_object_new_string_len(const char *s, int len);
- JSON_EXPORT const char* json_object_get_string(struct json_object *obj);
- JSON_EXPORT int json_object_get_string_len(const struct json_object *obj);
- JSON_EXPORT int json_object_set_string(json_object* obj, const char* new_value);
- JSON_EXPORT int json_object_set_string_len(json_object* obj, const char* new_value, int len);
- JSON_EXPORT int json_object_equal(struct json_object *obj1,
- struct json_object *obj2);
- typedef int (json_c_shallow_copy_fn)(json_object *src, json_object *parent, const char *key, size_t index, json_object **dst);
- json_c_shallow_copy_fn json_c_shallow_copy_default;
- JSON_EXPORT int json_object_deep_copy(struct json_object *src, struct json_object **dst, json_c_shallow_copy_fn *shallow_copy);
- #ifdef __cplusplus
- }
- #endif
- #endif
|