From 40e0931e70bfe198690a7dac43b32fad06f46ef9 Mon Sep 17 00:00:00 2001 From: Felix Fietkau Date: Thu, 26 Jul 2018 15:17:36 +0200 Subject: [PATCH] libubus: pass an empty UBUS_ATTR_DATA block if msg is NULL on invoke Signed-off-by: Felix Fietkau --- libubus-req.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/libubus-req.c b/libubus-req.c index 4eda383..74446f3 100644 --- a/libubus-req.c +++ b/libubus-req.c @@ -196,6 +196,14 @@ void ubus_complete_deferred_request(struct ubus_context *ctx, struct ubus_reques ubus_send_msg(ctx, req->seq, b.head, UBUS_MSG_STATUS, req->peer, req->fd); } +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); +} + int ubus_send_reply(struct ubus_context *ctx, struct ubus_request_data *req, struct blob_attr *msg) { @@ -203,7 +211,7 @@ int ubus_send_reply(struct ubus_context *ctx, struct ubus_request_data *req, blob_buf_init(&b, 0); blob_put_int32(&b, UBUS_ATTR_OBJID, req->object); - blob_put(&b, UBUS_ATTR_DATA, blob_data(msg), blob_len(msg)); + ubus_put_data(&b, msg); ret = ubus_send_msg(ctx, req->seq, b.head, UBUS_MSG_DATA, req->peer, -1); if (ret < 0) return UBUS_STATUS_NO_DATA; @@ -218,8 +226,7 @@ int ubus_invoke_async_fd(struct ubus_context *ctx, uint32_t obj, blob_buf_init(&b, 0); blob_put_int32(&b, UBUS_ATTR_OBJID, obj); blob_put_string(&b, UBUS_ATTR_METHOD, method); - if (msg) - blob_put(&b, UBUS_ATTR_DATA, blob_data(msg), blob_len(msg)); + ubus_put_data(&b, msg); memset(req, 0, sizeof(*req)); req->fd = fd; @@ -278,13 +285,11 @@ __ubus_notify_async(struct ubus_context *ctx, struct ubus_object *obj, blob_buf_init(&b, 0); blob_put_int32(&b, UBUS_ATTR_OBJID, obj->id); blob_put_string(&b, UBUS_ATTR_METHOD, type); + ubus_put_data(&b, msg); if (!reply) blob_put_int8(&b, UBUS_ATTR_NO_REPLY, true); - if (msg) - blob_put(&b, UBUS_ATTR_DATA, blob_data(msg), blob_len(msg)); - if (ubus_start_request(ctx, &req->req, b.head, UBUS_MSG_NOTIFY, obj->id) < 0) return UBUS_STATUS_INVALID_ARGUMENT; -- 2.30.2