X-Git-Url: http://git.archive.openwrt.org/?p=project%2Flibubox.git;a=blobdiff_plain;f=blobmsg.h;h=e58f95deb6be700c501fdfb2b8b604df459db47b;hp=d8f1045ebd8e23061edc1380fa7cc46cd62e7d30;hb=6a75b3b6437d3c98d852c1bca131c8f81646f2f5;hpb=4436338588cb317b5799d3aa3107d2cb0b6192cc diff --git a/blobmsg.h b/blobmsg.h index d8f1045..e58f95d 100644 --- a/blobmsg.h +++ b/blobmsg.h @@ -51,6 +51,12 @@ static inline int blobmsg_hdrlen(unsigned int namelen) return BLOBMSG_PADDING(sizeof(struct blobmsg_hdr) + namelen + 1); } +static inline void blobmsg_clear_name(struct blob_attr *attr) +{ + struct blobmsg_hdr *hdr = (struct blobmsg_hdr *) blob_data(attr); + hdr->name[0] = 0; +} + static inline const char *blobmsg_name(const struct blob_attr *attr) { struct blobmsg_hdr *hdr = (struct blobmsg_hdr *) blob_data(attr); @@ -90,6 +96,15 @@ static inline int blobmsg_len(const struct blob_attr *attr) bool blobmsg_check_attr(const struct blob_attr *attr, bool name); bool blobmsg_check_attr_list(const struct blob_attr *attr, int type); + +/* + * blobmsg_check_array: validate array/table and return size + * + * Checks if all elements of an array or table are valid and have + * the specified type. Returns the number of elements in the array + */ +int blobmsg_check_array(const struct blob_attr *attr, int type); + int blobmsg_parse(const struct blobmsg_policy *policy, int policy_len, struct blob_attr **tb, void *data, unsigned int len); int blobmsg_parse_array(const struct blobmsg_policy *policy, int policy_len, @@ -199,6 +214,9 @@ static inline uint64_t blobmsg_get_u64(struct blob_attr *attr) static inline char *blobmsg_get_string(struct blob_attr *attr) { + if (!attr) + return NULL; + return (char *) blobmsg_data(attr); }