2012-12-14 14:13:27 +01:00
|
|
|
/*
|
2014-02-18 15:02:48 +01:00
|
|
|
* Copyright (C) 2011-2014 Felix Fietkau <nbd@openwrt.org>
|
2012-12-14 14:13:27 +01:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Lesser General Public License version 2.1
|
|
|
|
* as published by the Free Software Foundation
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*/
|
|
|
|
|
2014-02-18 15:02:48 +01:00
|
|
|
#include <unistd.h>
|
2012-12-14 14:13:27 +01:00
|
|
|
#include "libubus.h"
|
|
|
|
#include "libubus-internal.h"
|
|
|
|
|
|
|
|
struct ubus_pending_data {
|
|
|
|
struct list_head list;
|
|
|
|
int type;
|
|
|
|
struct blob_attr data[];
|
|
|
|
};
|
|
|
|
|
|
|
|
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);
|
2018-07-25 10:37:30 +02:00
|
|
|
if (!attr[UBUS_ATTR_DATA])
|
|
|
|
return;
|
|
|
|
|
2012-12-14 14:13:27 +01:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-19 10:30:36 +01:00
|
|
|
int __hidden __ubus_start_request(struct ubus_context *ctx, struct ubus_request *req,
|
2012-12-14 19:48:26 +01:00
|
|
|
struct blob_attr *msg, int cmd, uint32_t peer)
|
|
|
|
{
|
|
|
|
|
|
|
|
if (msg && blob_pad_len(msg) > UBUS_MAX_MSGLEN)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
INIT_LIST_HEAD(&req->list);
|
|
|
|
INIT_LIST_HEAD(&req->pending);
|
|
|
|
req->ctx = ctx;
|
|
|
|
req->peer = peer;
|
|
|
|
req->seq = ++ctx->request_seq;
|
2016-12-19 10:30:36 +01:00
|
|
|
|
|
|
|
return ubus_send_msg(ctx, req->seq, msg, cmd, peer, req->fd);
|
2012-12-14 19:48:26 +01:00
|
|
|
}
|
|
|
|
|
2016-12-19 10:30:36 +01:00
|
|
|
int __hidden ubus_start_request(struct ubus_context *ctx, struct ubus_request *req,
|
|
|
|
struct blob_attr *msg, int cmd, uint32_t peer)
|
|
|
|
{
|
|
|
|
memset(req, 0, sizeof(*req));
|
|
|
|
|
|
|
|
req->fd = -1;
|
|
|
|
|
|
|
|
return __ubus_start_request(ctx, req, msg, cmd, peer);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-12-14 14:13:27 +01:00
|
|
|
void ubus_abort_request(struct ubus_context *ctx, struct ubus_request *req)
|
|
|
|
{
|
2013-05-30 12:39:51 +02:00
|
|
|
if (list_empty(&req->list))
|
2012-12-14 14:13:27 +01:00
|
|
|
return;
|
|
|
|
|
|
|
|
req->cancelled = true;
|
|
|
|
__ubus_process_req_data(req);
|
|
|
|
list_del_init(&req->list);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ubus_complete_request_async(struct ubus_context *ctx, struct ubus_request *req)
|
|
|
|
{
|
|
|
|
if (!list_empty(&req->list))
|
|
|
|
return;
|
|
|
|
|
|
|
|
list_add(&req->list, &ctx->requests);
|
|
|
|
}
|
|
|
|
|
2012-12-15 00:35:12 +01:00
|
|
|
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 void
|
|
|
|
ubus_set_req_status(struct ubus_request *req, int ret)
|
|
|
|
{
|
|
|
|
if (!list_empty(&req->list))
|
|
|
|
list_del_init(&req->list);
|
|
|
|
|
|
|
|
req->status_msg = true;
|
|
|
|
req->status_code = ret;
|
|
|
|
if (!req->blocked)
|
|
|
|
ubus_req_complete_cb(req);
|
|
|
|
}
|
|
|
|
|
2012-12-14 14:13:27 +01:00
|
|
|
static void ubus_sync_req_cb(struct ubus_request *req, int ret)
|
|
|
|
{
|
|
|
|
req->status_msg = true;
|
|
|
|
req->status_code = ret;
|
2017-02-03 18:39:11 +01:00
|
|
|
req->ctx->cancel_poll = true;
|
2012-12-14 14:13:27 +01:00
|
|
|
}
|
|
|
|
|
2014-03-18 22:36:36 +01:00
|
|
|
static int64_t get_time_msec(void)
|
2012-12-14 14:13:27 +01:00
|
|
|
{
|
2014-03-18 22:36:36 +01:00
|
|
|
struct timespec ts;
|
|
|
|
int64_t val;
|
2012-12-14 14:13:27 +01:00
|
|
|
|
2014-03-18 22:36:36 +01:00
|
|
|
clock_gettime(CLOCK_MONOTONIC, &ts);
|
|
|
|
val = (int64_t) ts.tv_sec * 1000LL;
|
|
|
|
val += ts.tv_nsec / 1000000LL;
|
|
|
|
return val;
|
2012-12-14 14:13:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
int ubus_complete_request(struct ubus_context *ctx, struct ubus_request *req,
|
2014-03-18 22:36:36 +01:00
|
|
|
int req_timeout)
|
2012-12-14 14:13:27 +01:00
|
|
|
{
|
|
|
|
ubus_complete_handler_t complete_cb = req->complete_cb;
|
|
|
|
int status = UBUS_STATUS_NO_DATA;
|
2014-03-18 22:36:36 +01:00
|
|
|
int64_t timeout = 0, time_end = 0;
|
2012-12-14 14:13:27 +01:00
|
|
|
|
2014-03-18 22:36:36 +01:00
|
|
|
if (req_timeout)
|
|
|
|
time_end = get_time_msec() + req_timeout;
|
2012-12-14 14:13:27 +01:00
|
|
|
|
|
|
|
ubus_complete_request_async(ctx, req);
|
|
|
|
req->complete_cb = ubus_sync_req_cb;
|
|
|
|
|
|
|
|
ctx->stack_depth++;
|
|
|
|
while (!req->status_msg) {
|
2014-03-18 22:36:36 +01:00
|
|
|
if (req_timeout) {
|
|
|
|
timeout = time_end - get_time_msec();
|
|
|
|
if (timeout <= 0) {
|
|
|
|
ubus_set_req_status(req, UBUS_STATUS_TIMEOUT);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2017-02-03 18:39:11 +01:00
|
|
|
|
2014-03-18 22:36:36 +01:00
|
|
|
ubus_poll_data(ctx, (unsigned int) timeout);
|
|
|
|
|
2015-12-09 18:35:07 +01:00
|
|
|
if (ctx->sock.eof) {
|
|
|
|
ubus_set_req_status(req, UBUS_STATUS_CONNECTION_FAILED);
|
2017-02-03 18:39:11 +01:00
|
|
|
ctx->cancel_poll = true;
|
2015-12-09 18:35:07 +01:00
|
|
|
break;
|
|
|
|
}
|
2012-12-14 14:13:27 +01:00
|
|
|
}
|
2017-02-03 18:39:11 +01:00
|
|
|
|
2012-12-14 14:13:27 +01:00
|
|
|
ctx->stack_depth--;
|
2013-05-11 20:39:54 +02:00
|
|
|
if (ctx->stack_depth)
|
2017-02-03 18:39:11 +01:00
|
|
|
ctx->cancel_poll = true;
|
2012-12-14 14:13:27 +01:00
|
|
|
|
|
|
|
if (req->status_msg)
|
|
|
|
status = req->status_code;
|
|
|
|
|
|
|
|
req->complete_cb = complete_cb;
|
|
|
|
if (req->complete_cb)
|
|
|
|
req->complete_cb(req, status);
|
|
|
|
|
2017-01-22 14:33:37 +01:00
|
|
|
if (!ctx->stack_depth && !ctx->sock.registered)
|
|
|
|
ctx->pending_timer.cb(&ctx->pending_timer);
|
2014-06-24 22:42:14 +02:00
|
|
|
|
2012-12-14 14:13:27 +01:00
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ubus_complete_deferred_request(struct ubus_context *ctx, struct ubus_request_data *req, int ret)
|
|
|
|
{
|
|
|
|
blob_buf_init(&b, 0);
|
|
|
|
blob_put_int32(&b, UBUS_ATTR_STATUS, ret);
|
|
|
|
blob_put_int32(&b, UBUS_ATTR_OBJID, req->object);
|
2014-02-18 15:02:48 +01:00
|
|
|
ubus_send_msg(ctx, req->seq, b.head, UBUS_MSG_STATUS, req->peer, req->fd);
|
2012-12-14 14:13:27 +01:00
|
|
|
}
|
|
|
|
|
2018-07-26 15:17:36 +02:00
|
|
|
static void ubus_put_data(struct blob_buf *buf, struct blob_attr *msg)
|
|
|
|
{
|
|
|
|
if (msg)
|
|
|
|
blob_put(buf, UBUS_ATTR_DATA, blob_data(msg), blob_len(msg));
|
|
|
|
else
|
|
|
|
blob_put(buf, UBUS_ATTR_DATA, NULL, 0);
|
|
|
|
}
|
|
|
|
|
2012-12-14 14:13:27 +01:00
|
|
|
int ubus_send_reply(struct ubus_context *ctx, struct ubus_request_data *req,
|
|
|
|
struct blob_attr *msg)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
blob_buf_init(&b, 0);
|
|
|
|
blob_put_int32(&b, UBUS_ATTR_OBJID, req->object);
|
2018-07-26 15:17:36 +02:00
|
|
|
ubus_put_data(&b, msg);
|
2014-02-18 15:02:48 +01:00
|
|
|
ret = ubus_send_msg(ctx, req->seq, b.head, UBUS_MSG_DATA, req->peer, -1);
|
2012-12-14 14:13:27 +01:00
|
|
|
if (ret < 0)
|
|
|
|
return UBUS_STATUS_NO_DATA;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-12-24 14:35:58 +01:00
|
|
|
int ubus_invoke_async_fd(struct ubus_context *ctx, uint32_t obj,
|
|
|
|
const char *method, struct blob_attr *msg,
|
|
|
|
struct ubus_request *req, int fd)
|
2016-12-19 10:30:36 +01:00
|
|
|
{
|
|
|
|
blob_buf_init(&b, 0);
|
|
|
|
blob_put_int32(&b, UBUS_ATTR_OBJID, obj);
|
|
|
|
blob_put_string(&b, UBUS_ATTR_METHOD, method);
|
2018-07-26 15:17:36 +02:00
|
|
|
ubus_put_data(&b, msg);
|
2016-12-19 10:30:36 +01:00
|
|
|
|
|
|
|
memset(req, 0, sizeof(*req));
|
|
|
|
req->fd = fd;
|
|
|
|
if (__ubus_start_request(ctx, req, b.head, UBUS_MSG_INVOKE, obj) < 0)
|
|
|
|
return UBUS_STATUS_INVALID_ARGUMENT;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int ubus_invoke_fd(struct ubus_context *ctx, uint32_t obj, const char *method,
|
2016-12-24 14:35:58 +01:00
|
|
|
struct blob_attr *msg, ubus_data_handler_t cb, void *priv,
|
|
|
|
int timeout, int fd)
|
2016-12-19 10:30:36 +01:00
|
|
|
{
|
|
|
|
struct ubus_request req;
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
rc = ubus_invoke_async_fd(ctx, obj, method, msg, &req, fd);
|
|
|
|
if (rc)
|
|
|
|
return rc;
|
|
|
|
|
|
|
|
req.data_cb = cb;
|
|
|
|
req.priv = priv;
|
|
|
|
return ubus_complete_request(ctx, &req, timeout);
|
|
|
|
}
|
|
|
|
|
2012-12-15 00:37:09 +01:00
|
|
|
static void
|
|
|
|
ubus_notify_complete_cb(struct ubus_request *req, int ret)
|
|
|
|
{
|
|
|
|
struct ubus_notify_request *nreq;
|
|
|
|
|
|
|
|
nreq = container_of(req, struct ubus_notify_request, req);
|
|
|
|
if (!nreq->complete_cb)
|
|
|
|
return;
|
|
|
|
|
|
|
|
nreq->complete_cb(nreq, 0, 0);
|
|
|
|
}
|
|
|
|
|
2017-11-01 22:14:42 +01:00
|
|
|
static void
|
|
|
|
ubus_notify_data_cb(struct ubus_request *req, int type, struct blob_attr *msg)
|
|
|
|
{
|
|
|
|
struct ubus_notify_request *nreq;
|
|
|
|
|
|
|
|
nreq = container_of(req, struct ubus_notify_request, req);
|
|
|
|
if (!nreq->data_cb)
|
|
|
|
return;
|
|
|
|
|
|
|
|
nreq->data_cb(nreq, type, msg);
|
|
|
|
}
|
|
|
|
|
2012-12-15 00:37:09 +01:00
|
|
|
static int
|
|
|
|
__ubus_notify_async(struct ubus_context *ctx, struct ubus_object *obj,
|
|
|
|
const char *type, struct blob_attr *msg,
|
|
|
|
struct ubus_notify_request *req, bool reply)
|
|
|
|
{
|
|
|
|
memset(req, 0, sizeof(*req));
|
|
|
|
|
|
|
|
blob_buf_init(&b, 0);
|
|
|
|
blob_put_int32(&b, UBUS_ATTR_OBJID, obj->id);
|
|
|
|
blob_put_string(&b, UBUS_ATTR_METHOD, type);
|
2018-07-26 15:17:36 +02:00
|
|
|
ubus_put_data(&b, msg);
|
2012-12-15 00:37:09 +01:00
|
|
|
|
|
|
|
if (!reply)
|
|
|
|
blob_put_int8(&b, UBUS_ATTR_NO_REPLY, true);
|
|
|
|
|
|
|
|
if (ubus_start_request(ctx, &req->req, b.head, UBUS_MSG_NOTIFY, obj->id) < 0)
|
|
|
|
return UBUS_STATUS_INVALID_ARGUMENT;
|
|
|
|
|
|
|
|
/* wait for status message from ubusd first */
|
|
|
|
req->req.notify = true;
|
|
|
|
req->pending = 1;
|
|
|
|
req->id[0] = obj->id;
|
|
|
|
req->req.complete_cb = ubus_notify_complete_cb;
|
2017-11-01 22:14:42 +01:00
|
|
|
req->req.data_cb = ubus_notify_data_cb;
|
2012-12-15 00:37:09 +01:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int ubus_notify_async(struct ubus_context *ctx, struct ubus_object *obj,
|
|
|
|
const char *type, struct blob_attr *msg,
|
|
|
|
struct ubus_notify_request *req)
|
|
|
|
{
|
|
|
|
return __ubus_notify_async(ctx, obj, type, msg, req, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
int ubus_notify(struct ubus_context *ctx, struct ubus_object *obj,
|
|
|
|
const char *type, struct blob_attr *msg, int timeout)
|
|
|
|
{
|
|
|
|
struct ubus_notify_request req;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = __ubus_notify_async(ctx, obj, type, msg, &req, timeout >= 0);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
|
2013-03-17 17:55:11 +01:00
|
|
|
if (timeout < 0) {
|
|
|
|
ubus_abort_request(ctx, &req.req);
|
2012-12-15 00:37:09 +01:00
|
|
|
return 0;
|
2013-03-17 17:55:11 +01:00
|
|
|
}
|
2012-12-15 00:37:09 +01:00
|
|
|
|
|
|
|
return ubus_complete_request(ctx, &req.req, timeout);
|
|
|
|
}
|
|
|
|
|
2014-09-15 15:29:29 +02:00
|
|
|
static bool ubus_get_status(struct ubus_msghdr_buf *buf, int *ret)
|
2012-12-14 14:13:27 +01:00
|
|
|
{
|
2014-09-15 15:29:29 +02:00
|
|
|
struct blob_attr **attrbuf = ubus_parse_msg(buf->data);
|
2012-12-14 14:13:27 +01:00
|
|
|
|
|
|
|
if (!attrbuf[UBUS_ATTR_STATUS])
|
|
|
|
return false;
|
|
|
|
|
|
|
|
*ret = blob_get_u32(attrbuf[UBUS_ATTR_STATUS]);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2014-09-15 15:29:29 +02:00
|
|
|
ubus_process_req_status(struct ubus_request *req, struct ubus_msghdr_buf *buf)
|
2012-12-14 14:13:27 +01:00
|
|
|
{
|
|
|
|
int ret = UBUS_STATUS_INVALID_ARGUMENT;
|
|
|
|
|
2014-09-15 15:29:29 +02:00
|
|
|
ubus_get_status(buf, &ret);
|
|
|
|
req->peer = buf->hdr.peer;
|
2012-12-15 00:35:12 +01:00
|
|
|
ubus_set_req_status(req, ret);
|
2012-12-14 14:13:27 +01:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2014-09-15 15:29:29 +02:00
|
|
|
ubus_process_req_data(struct ubus_request *req, struct ubus_msghdr_buf *buf)
|
2012-12-14 14:13:27 +01:00
|
|
|
{
|
|
|
|
struct ubus_pending_data *data;
|
|
|
|
int len;
|
|
|
|
|
|
|
|
if (!req->blocked) {
|
|
|
|
req->blocked = true;
|
2014-09-15 15:29:29 +02:00
|
|
|
req_data_cb(req, buf->hdr.type, buf->data);
|
2012-12-14 14:13:27 +01:00
|
|
|
__ubus_process_req_data(req);
|
|
|
|
req->blocked = false;
|
|
|
|
|
|
|
|
if (req->status_msg)
|
|
|
|
ubus_req_complete_cb(req);
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-09-15 15:29:29 +02:00
|
|
|
len = blob_raw_len(buf->data);
|
2012-12-14 14:13:27 +01:00
|
|
|
data = calloc(1, sizeof(*data) + len);
|
|
|
|
if (!data)
|
|
|
|
return;
|
|
|
|
|
2014-09-15 15:29:29 +02:00
|
|
|
data->type = buf->hdr.type;
|
|
|
|
memcpy(data->data, buf->data, len);
|
2012-12-14 14:13:27 +01:00
|
|
|
list_add(&data->list, &req->pending);
|
|
|
|
}
|
|
|
|
|
2012-12-15 00:37:09 +01:00
|
|
|
static int
|
|
|
|
ubus_find_notify_id(struct ubus_notify_request *n, uint32_t objid)
|
|
|
|
{
|
|
|
|
uint32_t pending = n->pending;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; pending; i++, pending >>= 1) {
|
|
|
|
if (!(pending & 1))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (n->id[i] == objid)
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2012-12-14 14:13:27 +01:00
|
|
|
static struct ubus_request *
|
2012-12-15 00:37:09 +01:00
|
|
|
ubus_find_request(struct ubus_context *ctx, uint32_t seq, uint32_t peer, int *id)
|
2012-12-14 14:13:27 +01:00
|
|
|
{
|
|
|
|
struct ubus_request *req;
|
|
|
|
|
|
|
|
list_for_each_entry(req, &ctx->requests, list) {
|
2012-12-15 00:37:09 +01:00
|
|
|
struct ubus_notify_request *nreq;
|
|
|
|
nreq = container_of(req, struct ubus_notify_request, req);
|
|
|
|
|
|
|
|
if (seq != req->seq)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (req->notify) {
|
|
|
|
if (!nreq->pending)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
*id = ubus_find_notify_id(nreq, peer);
|
|
|
|
if (*id < 0)
|
|
|
|
continue;
|
|
|
|
} else if (peer != req->peer)
|
2012-12-14 14:13:27 +01:00
|
|
|
continue;
|
|
|
|
|
|
|
|
return req;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2014-09-15 15:29:29 +02:00
|
|
|
static void ubus_process_notify_status(struct ubus_request *req, int id, struct ubus_msghdr_buf *buf)
|
2012-12-15 00:37:09 +01:00
|
|
|
{
|
|
|
|
struct ubus_notify_request *nreq;
|
|
|
|
struct blob_attr **tb;
|
|
|
|
struct blob_attr *cur;
|
iron out all extra compiler warnings
clang-9 on x86/64 has reported following warnings/errors:
libubus-acl.c:123:2: error: comparison of integers of different signs: 'size_t' (aka 'unsigned long') and 'int' [-Werror,-Wsign-compare]
libubus-io.c:108:18: error: comparison of integers of different signs: 'int' and 'size_t' (aka 'unsigned long') [-Werror,-Wsign-compare]
libubus-io.c:395:56: error: comparison of integers of different signs: 'ssize_t' (aka 'long') and 'size_t' (aka 'unsigned long') [-Werror,-Wsign-compare]
libubus-req.c:441:4: error: comparison of integers of different signs: 'size_t' (aka 'unsigned long') and 'int' [-Werror,-Wsign-compare]
ubusd_acl.c:119:18: error: comparison of integers of different signs: 'int' and 'unsigned long' [-Werror,-Wsign-compare]
ubusd_acl.c:152:5: error: comparison of integers of different signs: 'size_t' (aka 'unsigned long') and 'int' [-Werror,-Wsign-compare]
ubusd_acl.c:348:3: error: comparison of integers of different signs: 'size_t' (aka 'unsigned long') and 'int' [-Werror,-Wsign-compare]
ubusd_acl.c:352:3: error: comparison of integers of different signs: 'size_t' (aka 'unsigned long') and 'int' [-Werror,-Wsign-compare]
ubusd_acl.c:357:3: error: comparison of integers of different signs: 'size_t' (aka 'unsigned long') and 'int' [-Werror,-Wsign-compare]
ubusd_acl.c:362:3: error: comparison of integers of different signs: 'size_t' (aka 'unsigned long') and 'int' [-Werror,-Wsign-compare]
ubusd_acl.c:367:3: error: comparison of integers of different signs: 'size_t' (aka 'unsigned long') and 'int' [-Werror,-Wsign-compare]
ubusd_acl.c:447:16: error: comparison of integers of different signs: 'int' and '__size_t' (aka 'unsigned long') [-Werror,-Wsign-compare]
ubusd_acl.c:502:18: error: comparison of integers of different signs: 'int' and 'unsigned long' [-Werror,-Wsign-compare]
ubusd.c:123:13: error: comparison of integers of different signs: 'int' and 'unsigned long' [-Werror,-Wsign-compare]
ubusd.c:170:15: error: comparison of integers of different signs: 'int' and 'unsigned long' [-Werror,-Wsign-compare]
ubusd.c:262:43: error: comparison of integers of different signs: 'int' and 'unsigned long' [-Werror,-Wsign-compare]
ubusd.c:287:30: error: comparison of integers of different signs: 'int' and 'unsigned long' [-Werror,-Wsign-compare]
ubusd_event.c:170:18: error: comparison of integers of different signs: 'int' and 'unsigned long' [-Werror,-Wsign-compare]
ubusd_obj.c:71:2: error: comparison of integers of different signs: 'size_t' (aka 'unsigned long') and 'int' [-Werror,-Wsign-compare]
Signed-off-by: Petr Štetiar <ynezz@true.cz>
2019-12-11 10:36:36 +01:00
|
|
|
size_t rem;
|
|
|
|
int idx = 1;
|
2012-12-15 14:11:15 +01:00
|
|
|
int ret = 0;
|
2012-12-15 00:37:09 +01:00
|
|
|
|
|
|
|
nreq = container_of(req, struct ubus_notify_request, req);
|
|
|
|
nreq->pending &= ~(1 << id);
|
|
|
|
|
|
|
|
if (!id) {
|
|
|
|
/* first id: ubusd's status message with a list of ids */
|
2014-09-15 15:29:29 +02:00
|
|
|
tb = ubus_parse_msg(buf->data);
|
2012-12-15 00:37:09 +01:00
|
|
|
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))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
nreq->pending |= (1 << idx);
|
|
|
|
nreq->id[idx] = blob_get_int32(cur);
|
|
|
|
idx++;
|
|
|
|
|
|
|
|
if (idx == UBUS_MAX_NOTIFY_PEERS + 1)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
2014-09-15 15:29:29 +02:00
|
|
|
ubus_get_status(buf, &ret);
|
2012-12-15 00:37:09 +01:00
|
|
|
if (nreq->status_cb)
|
|
|
|
nreq->status_cb(nreq, id, ret);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!nreq->pending)
|
|
|
|
ubus_set_req_status(req, 0);
|
|
|
|
}
|
|
|
|
|
2014-09-15 15:29:29 +02:00
|
|
|
void __hidden ubus_process_req_msg(struct ubus_context *ctx, struct ubus_msghdr_buf *buf, int fd)
|
2012-12-14 14:13:27 +01:00
|
|
|
{
|
2014-09-15 15:29:29 +02:00
|
|
|
struct ubus_msghdr *hdr = &buf->hdr;
|
2012-12-14 14:13:27 +01:00
|
|
|
struct ubus_request *req;
|
2012-12-15 00:37:09 +01:00
|
|
|
int id = -1;
|
2012-12-14 14:13:27 +01:00
|
|
|
|
|
|
|
switch(hdr->type) {
|
|
|
|
case UBUS_MSG_STATUS:
|
2012-12-15 00:37:09 +01:00
|
|
|
req = ubus_find_request(ctx, hdr->seq, hdr->peer, &id);
|
2012-12-14 14:13:27 +01:00
|
|
|
if (!req)
|
|
|
|
break;
|
|
|
|
|
2014-02-18 15:02:48 +01:00
|
|
|
if (fd >= 0) {
|
|
|
|
if (req->fd_cb)
|
|
|
|
req->fd_cb(req, fd);
|
|
|
|
else
|
|
|
|
close(fd);
|
|
|
|
}
|
|
|
|
|
2012-12-15 00:37:09 +01:00
|
|
|
if (id >= 0)
|
2014-09-15 15:29:29 +02:00
|
|
|
ubus_process_notify_status(req, id, buf);
|
2012-12-15 00:37:09 +01:00
|
|
|
else
|
2014-09-15 15:29:29 +02:00
|
|
|
ubus_process_req_status(req, buf);
|
2012-12-14 14:13:27 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case UBUS_MSG_DATA:
|
2012-12-15 00:37:09 +01:00
|
|
|
req = ubus_find_request(ctx, hdr->seq, hdr->peer, &id);
|
2012-12-14 14:13:27 +01:00
|
|
|
if (req && (req->data_cb || req->raw_data_cb))
|
2014-09-15 15:29:29 +02:00
|
|
|
ubus_process_req_data(req, buf);
|
2012-12-14 14:13:27 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2015-11-19 22:32:25 +01:00
|
|
|
|
|
|
|
int __ubus_monitor(struct ubus_context *ctx, const char *type)
|
|
|
|
{
|
|
|
|
blob_buf_init(&b, 0);
|
|
|
|
return ubus_invoke(ctx, UBUS_SYSTEM_OBJECT_MONITOR, type, b.head, NULL, NULL, 1000);
|
|
|
|
}
|