make the blobmsg format endian agnostic (stick to big-endian)
This commit is contained in:
parent
309d7d456f
commit
08aada9a93
2 changed files with 11 additions and 5 deletions
14
blobmsg.c
14
blobmsg.c
|
@ -23,6 +23,12 @@ static const int blob_type[__BLOBMSG_TYPE_LAST] = {
|
||||||
[BLOBMSG_TYPE_STRING] = BLOB_ATTR_STRING,
|
[BLOBMSG_TYPE_STRING] = BLOB_ATTR_STRING,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static uint16_t
|
||||||
|
blobmsg_namelen(const struct blobmsg_hdr *hdr)
|
||||||
|
{
|
||||||
|
return be16_to_cpu(hdr->namelen);
|
||||||
|
}
|
||||||
|
|
||||||
bool blobmsg_check_attr(const struct blob_attr *attr, bool name)
|
bool blobmsg_check_attr(const struct blob_attr *attr, bool name)
|
||||||
{
|
{
|
||||||
const struct blobmsg_hdr *hdr;
|
const struct blobmsg_hdr *hdr;
|
||||||
|
@ -36,10 +42,10 @@ bool blobmsg_check_attr(const struct blob_attr *attr, bool name)
|
||||||
if (!hdr->namelen && name)
|
if (!hdr->namelen && name)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (hdr->namelen > blob_len(attr) - sizeof(struct blobmsg_hdr))
|
if (blobmsg_namelen(hdr) > blob_len(attr) - sizeof(struct blobmsg_hdr))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (hdr->name[hdr->namelen] != 0)
|
if (hdr->name[blobmsg_namelen(hdr)] != 0)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
id = blob_id(attr);
|
id = blob_id(attr);
|
||||||
|
@ -82,7 +88,7 @@ int blobmsg_parse(const struct blobmsg_policy *policy, int policy_len,
|
||||||
blob_id(attr) != policy[i].type)
|
blob_id(attr) != policy[i].type)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (hdr->namelen != pslen[i])
|
if (blobmsg_namelen(hdr) != pslen[i])
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (!blobmsg_check_attr(attr, true))
|
if (!blobmsg_check_attr(attr, true))
|
||||||
|
@ -119,7 +125,7 @@ blobmsg_new(struct blob_buf *buf, int type, const char *name, int payload_len, v
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
hdr = blob_data(attr);
|
hdr = blob_data(attr);
|
||||||
hdr->namelen = namelen;
|
hdr->namelen = cpu_to_be16(namelen);
|
||||||
strcpy((char *) hdr->name, (const char *)name);
|
strcpy((char *) hdr->name, (const char *)name);
|
||||||
*data = blobmsg_data(attr);
|
*data = blobmsg_data(attr);
|
||||||
|
|
||||||
|
|
|
@ -64,7 +64,7 @@ static inline int blobmsg_type(const struct blob_attr *attr)
|
||||||
static inline void *blobmsg_data(const struct blob_attr *attr)
|
static inline void *blobmsg_data(const struct blob_attr *attr)
|
||||||
{
|
{
|
||||||
struct blobmsg_hdr *hdr = blob_data(attr);
|
struct blobmsg_hdr *hdr = blob_data(attr);
|
||||||
return (char *) hdr + blobmsg_hdrlen(hdr->namelen);
|
return (char *) hdr + blobmsg_hdrlen(be16_to_cpu(hdr->namelen));
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline int blobmsg_data_len(const struct blob_attr *attr)
|
static inline int blobmsg_data_len(const struct blob_attr *attr)
|
||||||
|
|
Loading…
Reference in a new issue