3 (c) 2009 Steven Barth <steven@midlink.org>
5 Licensed under the Apache License, Version 2.0 (the "License");
6 you may not use this file except in compliance with the License.
7 You may obtain a copy of the License at
9 http://www.apache.org/licenses/LICENSE-2.0
13 local uci = require "luci.model.uci"
14 local tostring, getmetatable, pairs = tostring, getmetatable, pairs
15 local error, type = error, type
16 local nixio = require "nixio"
17 local srv = require "luci.lucid.rpc.server"
19 module "luci.lucid.rpc.ruci"
22 local m = srv.Module("Remote UCI API")
24 for k, v in pairs(_M) do
25 if type(v) == "function" and v ~= _factory then
26 m:add(k, srv.Method.extended(v))
33 local function getinst(session, name)
34 return session.ruci and session.ruci[name]
37 local function setinst(session, obj)
38 session.ruci = session.ruci or {}
39 local name = tostring(obj):match("0x([a-z0-9]+)")
40 session.ruci[name] = obj
44 local Cursor = getmetatable(uci.cursor())
46 for name, func in pairs(Cursor) do
47 _M[name] = function(session, inst, ...)
48 inst = getinst(session, inst)
49 return inst[name](inst, ...)
53 function cursor(session, ...)
54 return setinst(session, uci.cursor(...))
57 function cursor_state(session, ...)
58 return setinst(session, uci.cursor_state(...))
61 function foreach(session, inst, config, sectiontype)
62 local inst = getinst(session, inst)
64 inst:foreach(config, sectiontype, function(s) secs[#secs+1] = s end)