summaryrefslogtreecommitdiff
path: root/ubus.c
diff options
context:
space:
mode:
authorJo-Philipp Wich <jo@mein.io>2020-10-01 19:58:27 +0200
committerJo-Philipp Wich <jo@mein.io>2020-10-04 22:59:11 +0200
commit14a3cb42047bd0c0f8d5713332b9b4516a505607 (patch)
treec74ba35f7e9b87839a3587422ec446a3a507ee84 /ubus.c
parent0f38b0370718518e66dabeaa5522f546cb459393 (diff)
ubus: fix legacy empty reply format
The legacy ubus protocol must not include an empty object in the result array if the invoked ubus procedure yielded no response. This fixes compatibility with existing legacy ubus api clients that expect this behaviour, LuCI's fs.js in particular. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
Diffstat (limited to 'ubus.c')
-rw-r--r--ubus.c12
1 files changed, 8 insertions, 4 deletions
diff --git a/ubus.c b/ubus.c
index 39b38b2..cc7447e 100644
--- a/ubus.c
+++ b/ubus.c
@@ -465,10 +465,14 @@ uh_ubus_request_cb(struct ubus_request *req, int ret)
uh_ubus_init_json_rpc_response(cl, &buf);
r = blobmsg_open_array(&buf, "result");
blobmsg_add_u32(&buf, "", ret);
- c = blobmsg_open_table(&buf, NULL);
- blob_for_each_attr(cur, du->buf.head, rem)
- blobmsg_add_blob(&buf, cur);
- blobmsg_close_table(&buf, c);
+
+ if (blob_len(du->buf.head)) {
+ c = blobmsg_open_table(&buf, NULL);
+ blob_for_each_attr(cur, du->buf.head, rem)
+ blobmsg_add_blob(&buf, cur);
+ blobmsg_close_table(&buf, c);
+ }
+
blobmsg_close_array(&buf, r);
uh_ubus_send_response(cl, &buf);
return;