|
|
@@ -4,10 +4,10 @@ |
|
|
* Copyright (c) 2004, 2005 Metaparadigm Pte. Ltd. |
|
|
* Copyright (c) 2004, 2005 Metaparadigm Pte. Ltd. |
|
|
* Michael Clark <michael@metaparadigm.com> |
|
|
* Michael Clark <michael@metaparadigm.com> |
|
|
* Copyright (c) 2009 Hewlett-Packard Development Company, L.P. |
|
|
* Copyright (c) 2009 Hewlett-Packard Development Company, L.P. |
|
|
|
|
|
* Copyright (C) 2016 Nicola Spanti (RyDroid) <dev@nicola-spanti.info> |
|
|
* |
|
|
* |
|
|
* This library is free software; you can redistribute it and/or modify |
|
|
* This library is free software; you can redistribute it and/or modify |
|
|
* it under the terms of the MIT license. See COPYING for details. |
|
|
* it under the terms of the MIT license. See COPYING for details. |
|
|
* |
|
|
|
|
|
*/ |
|
|
*/ |
|
|
|
|
|
|
|
|
#include "config.h" |
|
|
#include "config.h" |
|
|
@@ -196,20 +196,23 @@ int json_object_put(struct json_object *jso) |
|
|
|
|
|
|
|
|
static void json_object_generic_delete(struct json_object* jso) |
|
|
static void json_object_generic_delete(struct json_object* jso) |
|
|
{ |
|
|
{ |
|
|
|
|
|
if(jso != NULL) |
|
|
|
|
|
{ |
|
|
#ifdef REFCOUNT_DEBUG |
|
|
#ifdef REFCOUNT_DEBUG |
|
|
MC_DEBUG("json_object_delete_%s: %p\n", |
|
|
|
|
|
json_type_to_name(jso->o_type), jso); |
|
|
|
|
|
lh_table_delete(json_object_table, jso); |
|
|
|
|
|
|
|
|
MC_DEBUG("json_object_delete_%s: %p\n", |
|
|
|
|
|
json_type_to_name(jso->o_type), jso); |
|
|
|
|
|
lh_table_delete(json_object_table, jso); |
|
|
#endif /* REFCOUNT_DEBUG */ |
|
|
#endif /* REFCOUNT_DEBUG */ |
|
|
printbuf_free(jso->_pb); |
|
|
|
|
|
free(jso); |
|
|
|
|
|
|
|
|
printbuf_free(jso->_pb); |
|
|
|
|
|
free(jso); |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
static struct json_object* json_object_new(enum json_type o_type) |
|
|
static struct json_object* json_object_new(enum json_type o_type) |
|
|
{ |
|
|
{ |
|
|
struct json_object *jso; |
|
|
struct json_object *jso; |
|
|
|
|
|
|
|
|
jso = (struct json_object*)calloc(sizeof(struct json_object), 1); |
|
|
|
|
|
|
|
|
jso = (struct json_object*) calloc(sizeof(struct json_object), 1); |
|
|
if (!jso) |
|
|
if (!jso) |
|
|
return NULL; |
|
|
return NULL; |
|
|
jso->o_type = o_type; |
|
|
jso->o_type = o_type; |
|
|
@@ -240,12 +243,15 @@ enum json_type json_object_get_type(const struct json_object *jso) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
void* json_object_get_userdata(json_object *jso) { |
|
|
void* json_object_get_userdata(json_object *jso) { |
|
|
return jso->_userdata; |
|
|
|
|
|
|
|
|
return jso == NULL ? NULL : jso->_userdata; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
void json_object_set_userdata(json_object *jso, void *userdata, |
|
|
void json_object_set_userdata(json_object *jso, void *userdata, |
|
|
json_object_delete_fn *user_delete) |
|
|
json_object_delete_fn *user_delete) |
|
|
{ |
|
|
{ |
|
|
|
|
|
if (!jso) |
|
|
|
|
|
return; |
|
|
|
|
|
|
|
|
// First, clean up any previously existing user info |
|
|
// First, clean up any previously existing user info |
|
|
if (jso->_user_delete) |
|
|
if (jso->_user_delete) |
|
|
jso->_user_delete(jso, jso->_userdata); |
|
|
jso->_user_delete(jso, jso->_userdata); |
|
|
@@ -396,8 +402,7 @@ static int json_object_object_to_json_string(struct json_object* jso, |
|
|
} |
|
|
} |
|
|
if (flags & JSON_C_TO_STRING_SPACED) |
|
|
if (flags & JSON_C_TO_STRING_SPACED) |
|
|
return sprintbuf(pb, /*{*/ " }"); |
|
|
return sprintbuf(pb, /*{*/ " }"); |
|
|
else |
|
|
|
|
|
return sprintbuf(pb, /*{*/ "}"); |
|
|
|
|
|
|
|
|
return sprintbuf(pb, /*{*/ "}"); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@@ -410,8 +415,11 @@ static void json_object_lh_entry_free(struct lh_entry *ent) |
|
|
|
|
|
|
|
|
static void json_object_object_delete(struct json_object* jso) |
|
|
static void json_object_object_delete(struct json_object* jso) |
|
|
{ |
|
|
{ |
|
|
lh_table_free(jso->o.c_object); |
|
|
|
|
|
json_object_generic_delete(jso); |
|
|
|
|
|
|
|
|
if(jso) |
|
|
|
|
|
{ |
|
|
|
|
|
lh_table_free(jso->o.c_object); |
|
|
|
|
|
json_object_generic_delete(jso); |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
struct json_object* json_object_new_object(void) |
|
|
struct json_object* json_object_new_object(void) |
|
|
@@ -534,7 +542,8 @@ json_bool json_object_object_get_ex(const struct json_object* jso, const char *k |
|
|
|
|
|
|
|
|
void json_object_object_del(struct json_object* jso, const char *key) |
|
|
void json_object_object_del(struct json_object* jso, const char *key) |
|
|
{ |
|
|
{ |
|
|
lh_table_delete(jso->o.c_object, key); |
|
|
|
|
|
|
|
|
if(jso) |
|
|
|
|
|
lh_table_delete(jso->o.c_object, key); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@@ -545,7 +554,7 @@ static int json_object_boolean_to_json_string(struct json_object* jso, |
|
|
int level, |
|
|
int level, |
|
|
int flags) |
|
|
int flags) |
|
|
{ |
|
|
{ |
|
|
if (jso->o.c_boolean) |
|
|
|
|
|
|
|
|
if (jso && jso->o.c_boolean) |
|
|
return sprintbuf(pb, "true"); |
|
|
return sprintbuf(pb, "true"); |
|
|
return sprintbuf(pb, "false"); |
|
|
return sprintbuf(pb, "false"); |
|
|
} |
|
|
} |
|
|
@@ -587,6 +596,8 @@ static int json_object_int_to_json_string(struct json_object* jso, |
|
|
int level, |
|
|
int level, |
|
|
int flags) |
|
|
int flags) |
|
|
{ |
|
|
{ |
|
|
|
|
|
if(!jso) |
|
|
|
|
|
return -1; |
|
|
return sprintbuf(pb, "%" PRId64, jso->o.c_int64); |
|
|
return sprintbuf(pb, "%" PRId64, jso->o.c_int64); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@@ -772,7 +783,7 @@ int json_object_userdata_to_json_string(struct json_object *jso, |
|
|
|
|
|
|
|
|
void json_object_free_userdata(struct json_object *jso, void *userdata) |
|
|
void json_object_free_userdata(struct json_object *jso, void *userdata) |
|
|
{ |
|
|
{ |
|
|
free(userdata); |
|
|
|
|
|
|
|
|
if(userdata) free(userdata); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
double json_object_get_double(const struct json_object *jso) |
|
|
double json_object_get_double(const struct json_object *jso) |
|
|
|