projects
/
project
/
libubox.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
ff585b9
)
add support for json-formatting blobmsg elements
author
Felix Fietkau
<nbd@openwrt.org>
Sun, 30 Jan 2011 13:15:57 +0000
(14:15 +0100)
committer
Felix Fietkau
<nbd@openwrt.org>
Sun, 30 Jan 2011 13:15:57 +0000
(14:15 +0100)
blobmsg.c
patch
|
blob
|
history
blobmsg.h
patch
|
blob
|
history
diff --git
a/blobmsg.c
b/blobmsg.c
index
69a160b
..
742a93b
100644
(file)
--- a/
blobmsg.c
+++ b/
blobmsg.c
@@
-100,7
+100,7
@@
static void blobmsg_format_element(struct strbuf *s, struct blob_attr *attr, boo
void *data;
int len;
void *data;
int len;
- if (!array) {
+ if (!array
&& blobmsg_name(attr)[0]
) {
blobmsg_format_string(s, blobmsg_name(attr));
blobmsg_puts(s, ":", 1);
}
blobmsg_format_string(s, blobmsg_name(attr));
blobmsg_puts(s, ":", 1);
}
@@
-155,7
+155,7
@@
static void blobmsg_format_json_list(struct strbuf *s, struct blob_attr *attr, i
blobmsg_puts(s, (array ? " ]" : " }"), 2);
}
blobmsg_puts(s, (array ? " ]" : " }"), 2);
}
-char *blobmsg_format_json(struct blob_attr *attr, bool
named
)
+char *blobmsg_format_json(struct blob_attr *attr, bool
list
)
{
struct strbuf s;
{
struct strbuf s;
@@
-163,7
+163,10
@@
char *blobmsg_format_json(struct blob_attr *attr, bool named)
s.buf = malloc(s.len);
s.pos = 0;
s.buf = malloc(s.len);
s.pos = 0;
- blobmsg_format_json_list(&s, blob_data(attr), blob_len(attr), !named);
+ if (list)
+ blobmsg_format_json_list(&s, blob_data(attr), blob_len(attr), false);
+ else
+ blobmsg_format_element(&s, attr, false, false);
if (!s.len)
return NULL;
if (!s.len)
return NULL;
diff --git
a/blobmsg.h
b/blobmsg.h
index
554bed8
..
7c63dbf
100644
(file)
--- a/
blobmsg.h
+++ b/
blobmsg.h
@@
-49,10
+49,10
@@
static inline int blobmsg_hdrlen(int namelen)
return BLOBMSG_PADDING(sizeof(struct blobmsg_hdr) + namelen + 1);
}
return BLOBMSG_PADDING(sizeof(struct blobmsg_hdr) + namelen + 1);
}
-static inline
void
*blobmsg_name(struct blob_attr *attr)
+static inline
char
*blobmsg_name(struct blob_attr *attr)
{
struct blobmsg_hdr *hdr = blob_data(attr);
{
struct blobmsg_hdr *hdr = blob_data(attr);
- return
&
hdr->name;
+ return
(char *)
hdr->name;
}
static inline void *blobmsg_data(struct blob_attr *attr)
}
static inline void *blobmsg_data(struct blob_attr *attr)
@@
-139,7
+139,7
@@
static inline int blobmsg_buf_init(struct blob_buf *buf)
return blob_buf_init(buf, BLOBMSG_TYPE_TABLE);
}
return blob_buf_init(buf, BLOBMSG_TYPE_TABLE);
}
-char *blobmsg_format_json(struct blob_attr *attr, bool
named
);
+char *blobmsg_format_json(struct blob_attr *attr, bool
list
);
#define blobmsg_for_each_attr(pos, attr, rem) \
for (rem = blobmsg_data_len(attr), pos = blobmsg_data(attr); \
#define blobmsg_for_each_attr(pos, attr, rem) \
for (rem = blobmsg_data_len(attr), pos = blobmsg_data(attr); \