static bool ubus_validate_hdr(struct ubus_msghdr *hdr)
{
+ struct blob_attr *data = ubus_msghdr_data(hdr);
+
if (hdr->version != 0)
return false;
- if (blob_raw_len(hdr->data) < sizeof(*hdr->data))
+ if (blob_raw_len(data) < sizeof(*data))
return false;
- if (blob_pad_len(hdr->data) > UBUS_MAX_MSGLEN)
+ if (blob_pad_len(data) > UBUS_MAX_MSGLEN)
return false;
return true;
return false;
}
- iov.iov_len = blob_len(ctx->msgbuf.hdr.data);
+ iov.iov_len = blob_len(ubus_msghdr_data(&ctx->msgbuf.hdr));
if (iov.iov_len > 0 && !recv_retry(ctx->sock.fd, &iov, true))
return false;
static bool ubus_get_status(struct ubus_msghdr *hdr, int *ret)
{
- struct blob_attr **attrbuf = ubus_parse_msg(hdr->data);
+ struct blob_attr **attrbuf = ubus_parse_msg(ubus_msghdr_data(hdr));
if (!attrbuf[UBUS_ATTR_STATUS])
return false;
static void
ubus_process_req_data(struct ubus_request *req, struct ubus_msghdr *hdr)
{
+ struct blob_attr *msg_data = ubus_msghdr_data(hdr);
struct ubus_pending_data *data;
int len;
if (!req->blocked) {
req->blocked = true;
- req_data_cb(req, hdr->type, hdr->data);
+ req_data_cb(req, hdr->type, msg_data);
__ubus_process_req_data(req);
req->blocked = false;
return;
}
- len = blob_raw_len(hdr->data);
+ len = blob_raw_len(msg_data);
data = calloc(1, sizeof(*data) + len);
if (!data)
return;
data->type = hdr->type;
- memcpy(data->data, hdr->data, len);
+ memcpy(data->data, msg_data, len);
list_add(&data->list, &req->pending);
}
if (!id) {
/* first id: ubusd's status message with a list of ids */
- tb = ubus_parse_msg(hdr->data);
+ tb = ubus_parse_msg(ubus_msghdr_data(hdr));
if (tb[UBUS_ATTR_SUBSCRIBERS]) {
blob_for_each_attr(cur, tb[UBUS_ATTR_SUBSCRIBERS], rem) {
if (!blob_check_type(blob_data(cur), blob_len(cur), BLOB_ATTR_INT32))
{
struct ubus_pending_msg *pending;
- pending = calloc(1, sizeof(*pending) + blob_raw_len(hdr->data));
+ pending = calloc(1, sizeof(*pending) + blob_raw_len(ubus_msghdr_data(hdr)));
if (!pending)
return;
- memcpy(&pending->hdr, hdr, sizeof(*hdr) + blob_raw_len(hdr->data));
+ memcpy(&pending->hdr, hdr, sizeof(*hdr) + blob_raw_len(ubus_msghdr_data(hdr)));
list_add(&pending->list, &ctx->pending);
}
struct ubus_subscriber;
struct ubus_notify_request;
+static inline struct blob_attr *
+ubus_msghdr_data(struct ubus_msghdr *hdr)
+{
+ return (struct blob_attr *) (hdr + 1);
+}
+
typedef void (*ubus_lookup_handler_t)(struct ubus_context *ctx,
struct ubus_object_data *obj,
void *priv);