-static bool ubus_get_status(struct ubus_msghdr *hdr, int *ret)
-{
- struct blob_attr **attrbuf = ubus_parse_msg(hdr->data);
-
- if (!attrbuf[UBUS_ATTR_STATUS])
- return false;
-
- *ret = blob_get_u32(attrbuf[UBUS_ATTR_STATUS]);
- return true;
-}
-
-static void req_data_cb(struct ubus_request *req, int type, struct blob_attr *data)
-{
- struct blob_attr **attr;
-
- if (req->raw_data_cb)
- req->raw_data_cb(req, type, data);
-
- if (!req->data_cb)
- return;
-
- attr = ubus_parse_msg(data);
- req->data_cb(req, type, attr[UBUS_ATTR_DATA]);
-}
-
-static void ubus_process_req_data(struct ubus_request *req)
-{
- struct ubus_pending_data *data;
-
- while (!list_empty(&req->pending)) {
- data = list_first_entry(&req->pending,
- struct ubus_pending_data, list);
- list_del(&data->list);
- if (!req->cancelled)
- req_data_cb(req, data->type, data->data);
- free(data);
- }
-}
-
-static void ubus_req_complete_cb(struct ubus_request *req)
-{
- ubus_complete_handler_t cb = req->complete_cb;
-
- if (!cb)
- return;
-
- req->complete_cb = NULL;
- cb(req, req->status_code);
-}
-
-static int ubus_process_req_status(struct ubus_request *req, struct ubus_msghdr *hdr)
-{
- int ret = UBUS_STATUS_INVALID_ARGUMENT;
-
- if (!list_empty(&req->list))
- list_del_init(&req->list);
-
- ubus_get_status(hdr, &ret);
- req->peer = hdr->peer;
- req->status_msg = true;
- req->status_code = ret;
- if (!req->blocked)
- ubus_req_complete_cb(req);
-
- return ret;
-}
-
-static void ubus_req_data(struct ubus_request *req, struct ubus_msghdr *hdr)
-{
- struct ubus_pending_data *data;
- int len;
-
- if (!req->blocked) {
- req->blocked = true;
- req_data_cb(req, hdr->type, hdr->data);
- ubus_process_req_data(req);
- req->blocked = false;
-
- if (req->status_msg)
- ubus_req_complete_cb(req);
-
- return;
- }
-
- len = blob_raw_len(hdr->data);
- data = calloc(1, sizeof(*data) + len);
- if (!data)
- return;
-
- data->type = hdr->type;
- memcpy(data->data, hdr->data, len);
- list_add(&data->list, &req->pending);
-}
-
-static struct ubus_request *ubus_find_request(struct ubus_context *ctx, uint32_t seq, uint32_t peer)