- 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)
-{
- struct ubus_request *req;
-
- list_for_each_entry(req, &ctx->requests, list) {
- if (seq != req->seq || peer != req->peer)
- continue;
-
- return req;
- }
- return NULL;
-}
-
-static void ubus_process_invoke(struct ubus_context *ctx, struct ubus_msghdr *hdr)
-{
- struct ubus_request_data req;
- struct ubus_object *obj;
- uint32_t objid = 0;
- int method;
- int ret = 0;
-
- ubus_parse_msg(hdr->data);
-
- if (!attrbuf[UBUS_ATTR_OBJID])
- return;
-
- objid = blob_get_int32(attrbuf[UBUS_ATTR_OBJID]);
-
- if (!attrbuf[UBUS_ATTR_METHOD]) {
- ret = UBUS_STATUS_INVALID_ARGUMENT;
- goto send;
- }
-
- obj = avl_find_element(&ctx->objects, &objid, obj, avl);
- if (!obj) {
- ret = UBUS_STATUS_NOT_FOUND;
- goto send;
- }
-
- for (method = 0; method < obj->n_methods; method++)
- if (!strcmp(obj->methods[method].name,
- blob_data(attrbuf[UBUS_ATTR_METHOD])))
- goto found;
-
- /* not found */
- ret = UBUS_STATUS_METHOD_NOT_FOUND;
- goto send;
-
-found:
- req.object = objid;
- req.peer = hdr->peer;
- req.seq = hdr->seq;
- ret = obj->methods[method].handler(ctx, obj, &req,
- obj->methods[method].name,
- attrbuf[UBUS_ATTR_DATA]);
-
-send:
- blob_buf_init(&b, 0);
- blob_put_int32(&b, UBUS_ATTR_STATUS, ret);
- blob_put_int32(&b, UBUS_ATTR_OBJID, objid);
- ubus_send_msg(ctx, hdr->seq, b.head, UBUS_MSG_STATUS, hdr->peer);
+ pending->hdr.data = data;
+ memcpy(&pending->hdr.hdr, &buf->hdr, sizeof(buf->hdr));
+ memcpy(data, buf->data, blob_raw_len(buf->data));
+ list_add_tail(&pending->list, &ctx->pending);
+ if (ctx->sock.registered)
+ uloop_timeout_set(&ctx->pending_timer, 1);