libubus ubus_invoke() with an extended struct blob_attr *msg as input
Bjørn Mork
bjorn at mork.no
Mon Apr 8 04:14:31 PDT 2024
Not too sure about any of this, so I just wanted to ask if this would
make sense:
bjorn at miraculix:/usr/local/src/git/ubus$ git diff
diff --git a/libubus-req.c b/libubus-req.c
index ae9d1925ecdf..cf85303e6aed 100644
--- a/libubus-req.c
+++ b/libubus-req.c
@@ -197,7 +197,7 @@ void ubus_complete_deferred_request(struct ubus_context *ctx, struct ubus_reques
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));
+ blob_put(buf, UBUS_ATTR_DATA, blobmsg_data(msg), blobmsg_len(msg));
else
blob_put(buf, UBUS_ATTR_DATA, NULL, 0);
}
The reason is that I spent some time scratching my head trying to figure
out why the blob I passed to ubus_invoke() had no effect at all. It
turned out to be because I passed a msg parameter with a blobmsg header
(and name).
I know it sounds like a strange thing to do. But the input was passed to
my program as an element of a larger json struct. So I simply ran
blobmsg_add_json_from_string() and blobmsg_parse() on that, extracting
the attribute with the input for my ubus call. Which means that the
attribute ended up with a blobmsg_hdr.
I can fix the problem now that I know of it, although it doesn't seem
like there's any helpers doing just that? But I think it would be nice
if this just worked either way. And I believe the above diff will do
that.
AFAICS, it changes nothing unless the BLOB_ATTR_EXTENDED flag is set.
Bjørn
More information about the openwrt-devel
mailing list