extern struct blob_buf b;
extern const struct ubus_method watch_method;
-static inline struct blob_attr *
-ubus_msghdr_data(struct ubus_msghdr *hdr)
-{
- struct ubus_msghdr_buf *hdrbuf = container_of(hdr, struct ubus_msghdr_buf, hdr);
- return hdrbuf->data;
-}
-
struct blob_attr **ubus_parse_msg(struct blob_attr *msg);
void ubus_handle_data(struct uloop_fd *u, unsigned int events);
int ubus_send_msg(struct ubus_context *ctx, uint32_t seq,
struct blob_attr *msg, int cmd, uint32_t peer, int fd);
-void ubus_process_msg(struct ubus_context *ctx, struct ubus_msghdr *hdr, int fd);
+void ubus_process_msg(struct ubus_context *ctx, struct ubus_msghdr_buf *buf, int fd);
int __hidden ubus_start_request(struct ubus_context *ctx, struct ubus_request *req,
struct blob_attr *msg, int cmd, uint32_t peer);
-void ubus_process_obj_msg(struct ubus_context*ctx, struct ubus_msghdr *hdr);
-void ubus_process_req_msg(struct ubus_context *ctx, struct ubus_msghdr *hdr, int fd);
+void ubus_process_obj_msg(struct ubus_context *ctx, struct ubus_msghdr_buf *buf);
+void ubus_process_req_msg(struct ubus_context *ctx, struct ubus_msghdr_buf *buf, int fd);
void __hidden ubus_poll_data(struct ubus_context *ctx, int timeout);
void __hidden ubus_handle_data(struct uloop_fd *u, unsigned int events)
{
struct ubus_context *ctx = container_of(u, struct ubus_context, sock);
- struct ubus_msghdr *hdr = &ctx->msgbuf.hdr;
int recv_fd = -1;
while (get_next_msg(ctx, &recv_fd)) {
- ubus_process_msg(ctx, hdr, recv_fd);
+ ubus_process_msg(ctx, &ctx->msgbuf, recv_fd);
if (uloop_cancelled)
break;
}
ubus_complete_deferred_request(ctx, &req, ret);
}
-void __hidden ubus_process_obj_msg(struct ubus_context *ctx, struct ubus_msghdr *hdr)
+void __hidden ubus_process_obj_msg(struct ubus_context *ctx, struct ubus_msghdr_buf *buf)
{
void (*cb)(struct ubus_context *, struct ubus_msghdr *,
struct ubus_object *, struct blob_attr **);
+ struct ubus_msghdr *hdr = &buf->hdr;
struct blob_attr **attrbuf;
struct ubus_object *obj;
uint32_t objid;
- attrbuf = ubus_parse_msg(ubus_msghdr_data(hdr));
+ attrbuf = ubus_parse_msg(buf->data);
if (!attrbuf[UBUS_ATTR_OBJID])
return;
return ubus_complete_request(ctx, &req.req, timeout);
}
-static bool ubus_get_status(struct ubus_msghdr *hdr, int *ret)
+static bool ubus_get_status(struct ubus_msghdr_buf *buf, int *ret)
{
- struct blob_attr **attrbuf = ubus_parse_msg(ubus_msghdr_data(hdr));
+ struct blob_attr **attrbuf = ubus_parse_msg(buf->data);
if (!attrbuf[UBUS_ATTR_STATUS])
return false;
}
static int
-ubus_process_req_status(struct ubus_request *req, struct ubus_msghdr *hdr)
+ubus_process_req_status(struct ubus_request *req, struct ubus_msghdr_buf *buf)
{
int ret = UBUS_STATUS_INVALID_ARGUMENT;
- ubus_get_status(hdr, &ret);
- req->peer = hdr->peer;
+ ubus_get_status(buf, &ret);
+ req->peer = buf->hdr.peer;
ubus_set_req_status(req, ret);
return ret;
}
static void
-ubus_process_req_data(struct ubus_request *req, struct ubus_msghdr *hdr)
+ubus_process_req_data(struct ubus_request *req, struct ubus_msghdr_buf *buf)
{
- 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, msg_data);
+ req_data_cb(req, buf->hdr.type, buf->data);
__ubus_process_req_data(req);
req->blocked = false;
return;
}
- len = blob_raw_len(msg_data);
+ len = blob_raw_len(buf->data);
data = calloc(1, sizeof(*data) + len);
if (!data)
return;
- data->type = hdr->type;
- memcpy(data->data, msg_data, len);
+ data->type = buf->hdr.type;
+ memcpy(data->data, buf->data, len);
list_add(&data->list, &req->pending);
}
return NULL;
}
-static void ubus_process_notify_status(struct ubus_request *req, int id, struct ubus_msghdr *hdr)
+static void ubus_process_notify_status(struct ubus_request *req, int id, struct ubus_msghdr_buf *buf)
{
struct ubus_notify_request *nreq;
struct blob_attr **tb;
if (!id) {
/* first id: ubusd's status message with a list of ids */
- tb = ubus_parse_msg(ubus_msghdr_data(hdr));
+ tb = ubus_parse_msg(buf->data);
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))
}
}
} else {
- ubus_get_status(hdr, &ret);
+ ubus_get_status(buf, &ret);
if (nreq->status_cb)
nreq->status_cb(nreq, id, ret);
}
ubus_set_req_status(req, 0);
}
-void __hidden ubus_process_req_msg(struct ubus_context *ctx, struct ubus_msghdr *hdr, int fd)
+void __hidden ubus_process_req_msg(struct ubus_context *ctx, struct ubus_msghdr_buf *buf, int fd)
{
+ struct ubus_msghdr *hdr = &buf->hdr;
struct ubus_request *req;
int id = -1;
}
if (id >= 0)
- ubus_process_notify_status(req, id, hdr);
+ ubus_process_notify_status(req, id, buf);
else
- ubus_process_req_status(req, hdr);
+ ubus_process_req_status(req, buf);
break;
case UBUS_MSG_DATA:
req = ubus_find_request(ctx, hdr->seq, hdr->peer, &id);
if (req && (req->data_cb || req->raw_data_cb))
- ubus_process_req_data(req, hdr);
+ ubus_process_req_data(req, buf);
break;
}
}
}
static void
-ubus_queue_msg(struct ubus_context *ctx, struct ubus_msghdr *hdr)
+ubus_queue_msg(struct ubus_context *ctx, struct ubus_msghdr_buf *buf)
{
struct ubus_pending_msg *pending;
void *data;
- pending = calloc_a(sizeof(*pending),
- &data, blob_raw_len(ubus_msghdr_data(hdr)));
+ pending = calloc_a(sizeof(*pending), &data, blob_raw_len(buf->data));
pending->hdr.data = data;
- memcpy(&pending->hdr.hdr, hdr, sizeof(*hdr));
- memcpy(data, ubus_msghdr_data(hdr), blob_raw_len(ubus_msghdr_data(hdr)));
+ memcpy(&pending->hdr.hdr, &buf->hdr, sizeof(buf->hdr));
+ memcpy(data, buf->data, blob_raw_len(buf->data));
list_add(&pending->list, &ctx->pending);
if (ctx->sock.registered)
uloop_timeout_set(&ctx->pending_timer, 1);
}
void __hidden
-ubus_process_msg(struct ubus_context *ctx, struct ubus_msghdr *hdr, int fd)
+ubus_process_msg(struct ubus_context *ctx, struct ubus_msghdr_buf *buf, int fd)
{
-
- switch(hdr->type) {
+ switch(buf->hdr.type) {
case UBUS_MSG_STATUS:
case UBUS_MSG_DATA:
- ubus_process_req_msg(ctx, hdr, fd);
+ ubus_process_req_msg(ctx, buf, fd);
break;
case UBUS_MSG_INVOKE:
case UBUS_MSG_UNSUBSCRIBE:
case UBUS_MSG_NOTIFY:
if (ctx->stack_depth) {
- ubus_queue_msg(ctx, hdr);
+ ubus_queue_msg(ctx, buf);
break;
}
- ubus_process_obj_msg(ctx, hdr);
+ ubus_process_obj_msg(ctx, buf);
break;
}
}
while (!ctx->stack_depth && !list_empty(&ctx->pending)) {
pending = list_first_entry(&ctx->pending, struct ubus_pending_msg, list);
list_del(&pending->list);
- ubus_process_msg(ctx, &pending->hdr.hdr, -1);
+ ubus_process_msg(ctx, &pending->hdr, -1);
free(pending);
}
}