mirror of
https://github.com/vale981/libblobpack
synced 2025-03-05 18:01:41 -05:00
blobmsg: allow BLOBMSG_TYPE_UNSPEC attributes, treat them as null for JSON conversion
Signed-off-by: Felix Fietkau <nbd@openwrt.org>
This commit is contained in:
parent
c395304fe5
commit
a0562bff3c
2 changed files with 5 additions and 1 deletions
|
@ -21,6 +21,7 @@ static const int blob_type[__BLOBMSG_TYPE_LAST] = {
|
||||||
[BLOBMSG_TYPE_INT32] = BLOB_ATTR_INT32,
|
[BLOBMSG_TYPE_INT32] = BLOB_ATTR_INT32,
|
||||||
[BLOBMSG_TYPE_INT64] = BLOB_ATTR_INT64,
|
[BLOBMSG_TYPE_INT64] = BLOB_ATTR_INT64,
|
||||||
[BLOBMSG_TYPE_STRING] = BLOB_ATTR_STRING,
|
[BLOBMSG_TYPE_STRING] = BLOB_ATTR_STRING,
|
||||||
|
[BLOBMSG_TYPE_UNSPEC] = BLOB_ATTR_BINARY,
|
||||||
};
|
};
|
||||||
|
|
||||||
static uint16_t
|
static uint16_t
|
||||||
|
@ -52,7 +53,7 @@ bool blobmsg_check_attr(const struct blob_attr *attr, bool name)
|
||||||
len = blobmsg_data_len(attr);
|
len = blobmsg_data_len(attr);
|
||||||
data = blobmsg_data(attr);
|
data = blobmsg_data(attr);
|
||||||
|
|
||||||
if (!id || id > BLOBMSG_TYPE_LAST)
|
if (id > BLOBMSG_TYPE_LAST)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (!blob_type[id])
|
if (!blob_type[id])
|
||||||
|
|
|
@ -228,6 +228,9 @@ static void blobmsg_format_element(struct strbuf *s, struct blob_attr *attr, boo
|
||||||
|
|
||||||
data_str = buf;
|
data_str = buf;
|
||||||
switch(blob_id(attr)) {
|
switch(blob_id(attr)) {
|
||||||
|
case BLOBMSG_TYPE_UNSPEC:
|
||||||
|
sprintf(buf, "null");
|
||||||
|
break;
|
||||||
case BLOBMSG_TYPE_BOOL:
|
case BLOBMSG_TYPE_BOOL:
|
||||||
sprintf(buf, "%s", *(uint8_t *)data ? "true" : "false");
|
sprintf(buf, "%s", *(uint8_t *)data ? "true" : "false");
|
||||||
break;
|
break;
|
||||||
|
|
Loading…
Add table
Reference in a new issue