summaryrefslogtreecommitdiffhomepage
path: root/modules/luci-base
diff options
context:
space:
mode:
authorJo-Philipp Wich <jo@mein.io>2019-09-12 14:00:47 +0200
committerJo-Philipp Wich <jo@mein.io>2019-09-12 14:00:47 +0200
commitcc81d5a0d4b73fc62e67c4659e08f653cbcdfaef (patch)
treef0eb76f98315f4d2bc4546e46d5de05880457198 /modules/luci-base
parente712a8a4ac896189c333400134e00977912a918a (diff)
luci-base: fix list method handling in ubus-rpc protocol proxy
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
Diffstat (limited to 'modules/luci-base')
-rw-r--r--modules/luci-base/luasrc/controller/admin/index.lua35
1 files changed, 22 insertions, 13 deletions
diff --git a/modules/luci-base/luasrc/controller/admin/index.lua b/modules/luci-base/luasrc/controller/admin/index.lua
index b0427d6c05..928faa14b4 100644
--- a/modules/luci-base/luasrc/controller/admin/index.lua
+++ b/modules/luci-base/luasrc/controller/admin/index.lua
@@ -147,6 +147,8 @@ local function ubus_reply(id, data, code, errmsg)
code = code,
message = errmsg
}
+ elseif type(code) == "table" then
+ reply.result = code
else
reply.result = { code, data }
end
@@ -178,11 +180,14 @@ local function ubus_access(sid, obj, fun)
end
local function ubus_request(req)
- if type(req) ~= "table" or type(req.method) ~= "string" or type(req.params) ~= "table" or
- #req.params < 2 or req.jsonrpc ~= "2.0" or req.id == nil then
+ if type(req) ~= "table" or type(req.method) ~= "string" or req.jsonrpc ~= "2.0" or req.id == nil then
return ubus_reply(nil, nil, -32600, "Invalid request")
elseif req.method == "call" then
+ if type(req.params) ~= "table" or #req.params < 3 then
+ return ubus_reply(nil, nil, -32600, "Invalid parameters")
+ end
+
local sid, obj, fun, arg =
req.params[1], req.params[2], req.params[3], req.params[4] or {}
if type(arg) ~= "table" or arg.ubus_rpc_session ~= nil then
@@ -203,34 +208,38 @@ local function ubus_request(req)
return ubus_reply(req.id, res, code or 0)
elseif req.method == "list" then
- if type(params) ~= "table" or #params == 0 then
- local objs = { luci.util.ubus() }
- return ubus_reply(req.id, objs, 0)
- else
+ if req.params == nil or (type(req.params) == "table" and #req.params == 0) then
+ local objs = luci.util.ubus()
+ return ubus_reply(req.id, nil, objs)
+
+ elseif type(req.params) == "table" then
local n, rv = nil, {}
- for n = 1, #params do
- if type(params[n]) ~= "string" then
+ for n = 1, #req.params do
+ if type(req.params[n]) ~= "string" then
return ubus_reply(req.id, nil, -32602, "Invalid parameters")
end
- local sig = luci.util.ubus(params[n])
+ local sig = luci.util.ubus(req.params[n])
if sig and type(sig) == "table" then
- rv[params[n]] = {}
+ rv[req.params[n]] = {}
local m, p
for m, p in pairs(sig) do
if type(p) == "table" then
- rv[params[n]][m] = {}
+ rv[req.params[n]][m] = {}
local pn, pt
for pn, pt in pairs(p) do
- rv[params[n]][m][pn] = ubus_types[pt] or "unknown"
+ rv[req.params[n]][m][pn] = ubus_types[pt] or "unknown"
end
end
end
end
end
- return ubus_reply(req.id, rv, 0)
+ return ubus_reply(req.id, nil, rv)
+
+ else
+ return ubus_reply(req.id, nil, -32602, "Invalid parameters")
end
end