blobmsg: allow BLOBMSG_TYPE_UNSPEC attributes, treat them as null for JSON conversion
authorFelix Fietkau <nbd@openwrt.org>
Sun, 13 Jan 2013 08:02:47 +0000 (09:02 +0100)
committerFelix Fietkau <nbd@openwrt.org>
Sun, 13 Jan 2013 08:02:51 +0000 (09:02 +0100)
Signed-off-by: Felix Fietkau <nbd@openwrt.org>
blobmsg.c
blobmsg_json.c

index e04fa53ddf28f2331b665fe957edf966b0903d98..8e2d73a0b8157872d0876050852d7d6b3564217c 100644 (file)
--- a/blobmsg.c
+++ b/blobmsg.c
@@ -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])
index f629d76edae032177f843675d93d21652f761ad7..d4f68465512b2fccc92c0c415049b4458ed947ee 100644 (file)
@@ -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;