diff options
author | Felix Fietkau <nbd@openwrt.org> | 2013-01-13 12:02:47 +0400 |
---|---|---|
committer | Felix Fietkau <nbd@openwrt.org> | 2013-01-13 12:02:51 +0400 |
commit | 4b5f278195c4bda222759682a2f9167646d05c77 (patch) | |
tree | 575a04d480b7097d14f3690edb6ad068aee19123 | |
parent | 2f74dbad14b42c3a6687b093210b8604d0b235cd (diff) |
blobmsg: allow BLOBMSG_TYPE_UNSPEC attributes, treat them as null for JSON conversion
Signed-off-by: Felix Fietkau <nbd@openwrt.org>
-rw-r--r-- | blobmsg.c | 3 | ||||
-rw-r--r-- | blobmsg_json.c | 3 |
2 files changed, 5 insertions, 1 deletions
@@ -21,6 +21,7 @@ static const int blob_type[__BLOBMSG_TYPE_LAST] = { [BLOBMSG_TYPE_INT32] = BLOB_ATTR_INT32, [BLOBMSG_TYPE_INT64] = BLOB_ATTR_INT64, [BLOBMSG_TYPE_STRING] = BLOB_ATTR_STRING, + [BLOBMSG_TYPE_UNSPEC] = BLOB_ATTR_BINARY, }; static uint16_t @@ -52,7 +53,7 @@ bool blobmsg_check_attr(const struct blob_attr *attr, bool name) len = blobmsg_data_len(attr); data = blobmsg_data(attr); - if (!id || id > BLOBMSG_TYPE_LAST) + if (id > BLOBMSG_TYPE_LAST) return false; if (!blob_type[id]) diff --git a/blobmsg_json.c b/blobmsg_json.c index f629d76..d4f6846 100644 --- a/blobmsg_json.c +++ b/blobmsg_json.c @@ -228,6 +228,9 @@ static void blobmsg_format_element(struct strbuf *s, struct blob_attr *attr, boo data_str = buf; switch(blob_id(attr)) { + case BLOBMSG_TYPE_UNSPEC: + sprintf(buf, "null"); + break; case BLOBMSG_TYPE_BOOL: sprintf(buf, "%s", *(uint8_t *)data ? "true" : "false"); break; |