44 static const char* json_type_name[] = {
63 static struct lh_table *json_object_table;
65 static void json_object_init() __attribute__ ((constructor));
66 static void json_object_init() {
67 mc_debug(
"json_object_init: creating object table\n");
71 static void json_object_fini() __attribute__ ((destructor));
72 static void json_object_fini() {
75 mc_debug(
"json_object_fini: %d referenced objects at exit\n",
76 json_object_table->
count);
82 mc_debug(
"json_object_fini: freeing object table\n");
92 int pos = 0, start_offset = 0;
106 if(pos - start_offset > 0)
115 start_offset = ++pos;
119 if(pos - start_offset > 0)
124 start_offset = ++pos;
128 if(pos - start_offset > 0)
157 #ifdef REFCOUNT_DEBUG 158 mc_debug(
"json_object_delete_%s: %p\n",
159 json_type_name[this->
o_type],
this);
169 if(!
this)
return NULL;
173 #ifdef REFCOUNT_DEBUG 175 mc_debug(
"json_object_new_%s: %p\n", json_type_name[this->o_type],
this);
187 return (this->
o_type == type);
201 if(!
this)
return "null";
251 if(!
this)
return NULL;
261 if(!
this)
return NULL;
262 switch(this->o_type) {
264 return this->o.c_object;
300 if(!
this)
return NULL;
308 if(!
this)
return FALSE;
313 return (this->
o.
c_int != 0);
335 if(!
this)
return NULL;
354 if(sscanf(this->
o.
c_string,
"%d", &cint) == 1)
return cint;
371 #define AC_BETTER_PRECISION 372 #ifdef AC_BETTER_PRECISION 374 if( ((
int) this->
o.
c_double) != this->o.c_double)
389 if(!
this)
return NULL;
399 if(!
this)
return 0.0;
408 if(sscanf(this->
o.
c_string,
"%lf", &cdouble) == 1)
return cdouble;
435 if(!
this)
return NULL;
445 if(!
this)
return NULL;
454 if(!
this)
return NULL;
477 if(val == NULL) {
sprintbuf(pb,
"null"); }
498 if(!
this)
return NULL;
507 if(!
this)
return NULL;
508 switch(this->o_type) {
510 return this->o.c_array;
char * json_object_get_string(struct json_object *this)
int json_object_array_length(struct json_object *this)
void json_object_put(struct json_object *this)
double json_object_get_double(struct json_object *this)
static int json_object_object_to_json_string(struct json_object *this, struct printbuf *pb)
struct json_object * json_object_object_get(struct json_object *this, const char *key)
json_object_delete_fn * _delete
struct json_object * json_object_new_boolean(boolean b)
struct json_object * json_object_new_double(double d)
struct array_list * array_list_new(array_list_free_fn *free_fn)
int lh_table_delete(struct lh_table *t, void *k)
void mc_debug(const char *msg,...)
#define lh_foreach(table, entry)
enum json_type json_object_get_type(struct json_object *this)
int json_object_is_type(struct json_object *this, int type)
struct printbuf * printbuf_new()
int array_list_put_idx(struct array_list *this, int idx, void *data)
#define JSON_OBJECT_DEF_HASH_ENTIRES
struct json_object * json_object_new_string(const char *s)
static void json_object_object_delete(struct json_object *this)
int array_list_add(struct array_list *this, void *data)
int json_object_get_int(struct json_object *this)
struct lh_table * lh_kptr_table_new(int size, char *name, lh_entry_free_fn *free_fn)
static int json_object_string_to_json_string(struct json_object *this, struct printbuf *pb)
void array_list_free(struct array_list *this)
int lh_table_insert(struct lh_table *t, void *k, void *v)
int json_object_array_add(struct json_object *this, struct json_object *val)
struct array_list * json_object_get_array(struct json_object *this)
void * array_list_get_idx(struct array_list *this, int i)
union json_object::data o
struct lh_table * c_object
static void json_object_string_delete(struct json_object *this)
void lh_table_free(struct lh_table *t)
static int json_object_array_to_json_string(struct json_object *this, struct printbuf *pb)
static int json_object_double_to_json_string(struct json_object *this, struct printbuf *pb)
const char * json_object_to_json_string(struct json_object *this)
struct array_list * c_array
struct lh_table * lh_kchar_table_new(int size, char *name, lh_entry_free_fn *free_fn)
struct json_object * json_object_new_array()
struct json_object * json_object_get(struct json_object *this)
#define json_object_object_foreachC(obj, iter)
void * lh_table_lookup(struct lh_table *t, void *k)
struct json_object * json_object_new_object()
static void json_object_array_entry_free(void *data)
static int json_object_int_to_json_string(struct json_object *this, struct printbuf *pb)
struct json_object * json_object_new_int(int i)
int array_list_length(struct array_list *this)
static int json_object_boolean_to_json_string(struct json_object *this, struct printbuf *pb)
void json_object_object_add(struct json_object *this, const char *key, struct json_object *val)
void printbuf_free(struct printbuf *p)
const char * json_hex_chars
const char * float_format
const char * json_number_chars
struct lh_table * json_object_get_object(struct json_object *this)
static void json_object_lh_entry_free(struct lh_entry *ent)
char * json_c_strndup(const char *str, size_t n)
json_object_to_json_string_fn * _to_json_string
void json_set_float_format(const char *f)
static void json_object_array_delete(struct json_object *this)
void json_object_object_del(struct json_object *this, const char *key)
static void json_object_generic_delete(struct json_object *this)
int printbuf_memappend(struct printbuf *p, const char *buf, int size)
struct json_object * json_object_array_get_idx(struct json_object *this, int idx)
int json_object_array_put_idx(struct json_object *this, int idx, struct json_object *val)
int sprintbuf(struct printbuf *p, const char *msg,...)
void printbuf_reset(struct printbuf *p)
struct json_object * json_object_new_string_len(const char *s, int len)
static int json_escape_str(struct printbuf *pb, char *str)
static struct json_object * json_object_new(enum json_type o_type)
boolean json_object_get_boolean(struct json_object *this)