23 #include <json/json.h>
28 json_object_object_foreach(obj, key, val) {
39 for (i = 0, len = array_list_length(a); i < len; i++) {
52 switch (json_object_get_type(obj)) {
53 case json_type_object:
63 case json_type_string:
66 case json_type_boolean:
70 int64_t i64 = json_object_get_int64(obj);
71 if (i64 >= INT32_MIN && i64 <= INT32_MAX) {
78 case json_type_double:
97 if (json_object_get_type(obj) != json_type_object)
103 json_object_put(obj);
137 if (s->
pos + len >= s->
len) {
138 new_len = s->
len + 16 + len;
139 new_buf = realloc(s->
buf, new_len);
147 memcpy(s->
buf + s->
pos, c, len);
154 const char indent_chars[] =
"\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t";
161 if (len >
sizeof(indent_chars) - 1)
162 len =
sizeof(indent_chars) - 1;
170 const unsigned char *p, *last, *end;
171 char buf[8] =
"\\u00";
173 end = (
unsigned char *) str + strlen(str);
175 for (p = (
unsigned char *) str, last = p; *p; p++) {
211 snprintf(buf + 4,
sizeof(buf) - 4,
"%02x", (
unsigned char) *p);
227 const char *data_str;
252 snprintf(buf,
sizeof(buf),
"null");
255 snprintf(buf,
sizeof(buf),
"%s", *(uint8_t *)
data ?
"true" :
"false");
258 snprintf(buf,
sizeof(buf),
"%" PRId16, (int16_t)
be16_to_cpu(*(uint16_t *)
data));
261 snprintf(buf,
sizeof(buf),
"%" PRId32, (int32_t)
be32_to_cpu(*(uint32_t *)
data));
264 snprintf(buf,
sizeof(buf),
"%" PRId64, (int64_t)
be64_to_cpu(*(uint64_t *)
data));
345 ret = realloc(s.
buf, s.
pos + 1);
372 ret = realloc(s.
buf, s.
pos + 1);
static bool blob_is_extended(const struct blob_attr *attr)
#define __blob_for_each_attr(pos, attr, rem)
static size_t blob_len(const struct blob_attr *attr)
static unsigned int blob_id(const struct blob_attr *attr)
int blobmsg_add_field(struct blob_buf *buf, int type, const char *name, const void *data, unsigned int len)
bool blobmsg_check_attr(const struct blob_attr *attr, bool name)
static size_t blobmsg_data_len(const struct blob_attr *attr)
static void * blobmsg_open_table(struct blob_buf *buf, const char *name)
static void blobmsg_close_table(struct blob_buf *buf, void *cookie)
static int blobmsg_add_u8(struct blob_buf *buf, const char *name, uint8_t val)
static const char * blobmsg_name(const struct blob_attr *attr)
static int blobmsg_add_u64(struct blob_buf *buf, const char *name, uint64_t val)
static int blobmsg_add_string(struct blob_buf *buf, const char *name, const char *string)
static void blobmsg_close_array(struct blob_buf *buf, void *cookie)
static void * blobmsg_open_array(struct blob_buf *buf, const char *name)
static double blobmsg_get_double(struct blob_attr *attr)
static void * blobmsg_data(const struct blob_attr *attr)
static int blobmsg_add_double(struct blob_buf *buf, const char *name, double val)
static int blobmsg_add_u32(struct blob_buf *buf, const char *name, uint32_t val)
static bool __blobmsg_add_json(struct blob_buf *b, json_object *obj)
bool blobmsg_add_object(struct blob_buf *b, json_object *obj)
char * blobmsg_format_json_value_with_cb(struct blob_attr *attr, blobmsg_json_format_t cb, void *priv, int indent)
static void blobmsg_format_element(struct strbuf *s, struct blob_attr *attr, bool without_name, bool head)
static void blobmsg_format_json_list(struct strbuf *s, struct blob_attr *attr, int len, bool array)
static void setup_strbuf(struct strbuf *s, struct blob_attr *attr, blobmsg_json_format_t cb, void *priv, int indent)
bool blobmsg_add_json_from_file(struct blob_buf *b, const char *file)
static bool blobmsg_puts(struct strbuf *s, const char *c, int len)
static void blobmsg_format_string(struct strbuf *s, const char *str)
char * blobmsg_format_json_with_cb(struct blob_attr *attr, bool list, blobmsg_json_format_t cb, void *priv, int indent)
static bool blobmsg_add_array(struct blob_buf *b, struct array_list *a)
bool blobmsg_add_json_element(struct blob_buf *b, const char *name, json_object *obj)
bool blobmsg_add_json_from_string(struct blob_buf *b, const char *str)
static void add_separator(struct strbuf *s)
const char *(* blobmsg_json_format_t)(void *priv, struct blob_attr *attr)
blobmsg_json_format_t custom_format