123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038 |
- #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)
- #ifdef FALSE
- #undef FALSE
- #define FALSE ((json_bool)0)
- #endif
- #ifdef TRUE
- #undef TRUE
- #define TRUE ((json_bool)1)
- #endif
- #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
|