summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorSteven Barth <steven@midlink.org>2008-08-17 10:20:36 +0000
committerSteven Barth <steven@midlink.org>2008-08-17 10:20:36 +0000
commit75d4cca7ae10a39d9787afd5f1c2f14800491acd (patch)
treed78aa1fec1690510ed723f6c8433f71fda709e28
parent746fa9df8f3d3443d82cd26d6717e7b5cf3dc8c1 (diff)
Fixed a design flaw in luci.model.uci
-rwxr-xr-xapplications/luci-splash/root/usr/bin/luci-splashd2
-rwxr-xr-xapplications/luci-splash/root/usr/sbin/luci-splash10
-rw-r--r--libs/cbi/luasrc/cbi.lua24
-rw-r--r--libs/uci/luasrc/model/uci.lua49
-rw-r--r--libs/uvl/luasrc/uvl.lua9
-rw-r--r--modules/admin-core/luasrc/tools/webadmin.lua12
-rw-r--r--modules/admin-full/luasrc/controller/admin/uci.lua4
-rw-r--r--modules/admin-full/luasrc/model/cbi/admin_network/network.lua9
-rw-r--r--modules/admin-mini/luasrc/controller/mini/uci.lua4
-rw-r--r--modules/admin-mini/luasrc/model/cbi/mini/index.lua14
-rw-r--r--themes/fledermaus/luasrc/view/themes/fledermaus/header.htm4
-rw-r--r--themes/openwrt-light/luasrc/view/themes/openwrt-light/header.htm4
-rw-r--r--themes/openwrt.org/luasrc/view/themes/openwrt.org/header.htm4
13 files changed, 93 insertions, 56 deletions
diff --git a/applications/luci-splash/root/usr/bin/luci-splashd b/applications/luci-splash/root/usr/bin/luci-splashd
index e8c275209..3e0c938eb 100755
--- a/applications/luci-splash/root/usr/bin/luci-splashd
+++ b/applications/luci-splash/root/usr/bin/luci-splashd
@@ -4,7 +4,7 @@ require("socket")
require("luci.ip")
require("luci.model.uci")
-luci.model.uci.set_savedir(luci.model.uci.savedir_state)
+luci.model.uci.load_state("network")
local server = socket.bind("0.0.0.0", arg[1] or 8082)
server:settimeout(0, "t")
diff --git a/applications/luci-splash/root/usr/sbin/luci-splash b/applications/luci-splash/root/usr/sbin/luci-splash
index 0b645fab7..520f87702 100755
--- a/applications/luci-splash/root/usr/sbin/luci-splash
+++ b/applications/luci-splash/root/usr/sbin/luci-splash
@@ -5,7 +5,7 @@ require("luci.util")
require("luci.model.uci")
-- Init state session
-luci.model.uci.set_savedir(luci.model.uci.savedir_state)
+luci.model.uci.load_state("luci_splash")
local uci = luci.model.uci
@@ -66,7 +66,7 @@ function add_lease(mac)
})
add_rule(mac)
- uci.save()
+ uci.save_state("luci_splash")
end
@@ -87,7 +87,7 @@ function remove_lease(mac)
uci.delete("luci_splash", j)
end
- uci.save()
+ uci.save_state("luci_splash")
end
@@ -156,7 +156,7 @@ function sync()
local leasetime = tonumber(uci.get("luci_splash", "general", "leasetime")) * 3600
-- Clean state file
- uci.load("luci_splash")
+ uci.load_state("luci_splash")
uci.revert("luci_splash")
@@ -185,7 +185,7 @@ function sync()
end
end
- uci.save("luci_splash")
+ uci.save_state("luci_splash")
end
main(arg) \ No newline at end of file
diff --git a/libs/cbi/luasrc/cbi.lua b/libs/cbi/luasrc/cbi.lua
index bf4bfb80c..fed53f6ee 100644
--- a/libs/cbi/luasrc/cbi.lua
+++ b/libs/cbi/luasrc/cbi.lua
@@ -157,7 +157,7 @@ function Map.__init__(self, config, ...)
self.config = config
self.parsechain = {self.config}
self.template = "cbi/map"
- if not uci.load(self.config) then
+ if not uci.load_config(self.config) then
error("Unable to read UCI data: " .. self.config)
end
end
@@ -170,9 +170,16 @@ end
-- Use optimized UCI writing
function Map.parse(self, ...)
+ if self.stateful then
+ uci.load_state(self.config)
+ else
+ uci.load_config(self.config)
+ end
+
Node.parse(self, ...)
+
for i, config in ipairs(self.parsechain) do
- uci.save(config)
+ uci.save_config(config)
end
if luci.http.formvalue("cbi.apply") then
for i, config in ipairs(self.parsechain) do
@@ -182,8 +189,7 @@ function Map.parse(self, ...)
end
-- Refresh data because commit changes section names
- uci.unload(config)
- uci.load(config)
+ uci.load_config(config)
end
-- Reparse sections
@@ -240,11 +246,6 @@ function Map.get(self, section, option)
end
end
--- UCI stateget
-function Map.stateget(self, section, option)
- return uci.get_statevalue(self.config, section, option)
-end
-
--[[
Page - A simple node
@@ -705,7 +706,6 @@ function AbstractValue.__init__(self, map, option, ...)
self.default = nil
self.size = nil
self.optional = false
- self.stateful = false
end
-- Add a dependencie to another section field
@@ -789,9 +789,7 @@ end
-- Return the UCI value of this object
function AbstractValue.cfgvalue(self, section)
- return self.stateful
- and self.map:stateget(section, self.option)
- or self.map:get(section, self.option)
+ return self.map:get(section, self.option)
end
-- Validate the form value
diff --git a/libs/uci/luasrc/model/uci.lua b/libs/uci/luasrc/model/uci.lua
index 665866e68..dd7a48ab6 100644
--- a/libs/uci/luasrc/model/uci.lua
+++ b/libs/uci/luasrc/model/uci.lua
@@ -79,15 +79,46 @@ function section(config, type, name, values)
return stat and name
end
---- Get a certain state value.
--- @param ... Parameters passed to function get
--- @return UCI value
--- @see get
-function get_statevalue(...)
+--- Savely load the configuration.
+-- @param config Configuration to load
+-- @return Sucess status
+-- @see load_state
+-- @see load
+function load_config(...)
+ set_confdir(confdir_default)
+ set_savedir(savedir_default)
+ return load(...)
+end
+
+--- Savely load state values.
+-- @param config Configuration to load
+-- @return Sucess status
+-- @see load_config
+-- @see load
+function load_state(config)
+ set_confdir(confdir_default)
set_savedir(savedir_state)
- local result = get(...)
+ return load(config)
+end
+
+--- Save changes to config values.
+-- @param config Configuration to save
+-- @return Sucess status
+-- @see save_state
+-- @see save
+function save_config(config)
set_savedir(savedir_default)
- return result
+ return save(config)
+end
+
+--- Save changes to state values.
+-- @param config Configuration to save
+-- @return Sucess status
+-- @see save_config
+-- @see save
+function save_state(config)
+ set_savedir(savedir_state)
+ return save(config)
end
--- Updated the data of a section using data from a table.
@@ -157,10 +188,13 @@ end
-- @return Table of UCI sections or table of UCI values
--- Manually load a config.
+-- Warning: This function is unsave! You should use load_config or load_state if possible.
-- @class function
-- @name load
-- @param config UCI config
-- @return Boolean whether operation succeeded
+-- @see load_config
+-- @see load_state
-- @see save
-- @see unload
@@ -180,6 +214,7 @@ end
-- @see unload
--- Set a value or create a named section.
+-- Warning: This function is unsave! You should use save_config or save_state if possible.
-- @class function
-- @name set
-- @param config UCI config
diff --git a/libs/uvl/luasrc/uvl.lua b/libs/uvl/luasrc/uvl.lua
index 0e32dc1e2..33ee79b79 100644
--- a/libs/uvl/luasrc/uvl.lua
+++ b/libs/uvl/luasrc/uvl.lua
@@ -69,8 +69,7 @@ end
-- @return String containing the reason for errors (if any)
function UVL.validate( self, config )
- self.uci.set_confdir( self.uci.confdir_default )
- self.uci.load( config )
+ self.uci.load_config( config )
self.beenthere = { }
local co = self.uci.get_all( config )
@@ -109,8 +108,7 @@ function UVL.validate( self, config )
end
function UVL.validate_section( self, config, section )
- self.uci.set_confdir( self.uci.confdir_default )
- self.uci.load( config )
+ self.uci.load_config( config )
self.beenthere = { }
local co = self.uci.get_all( config )
@@ -125,8 +123,7 @@ function UVL.validate_section( self, config, section )
end
function UVL.validate_option( self, config, section, option )
- self.uci.set_confdir( self.uci.confdir_default )
- self.uci.load( config )
+ self.uci.load_config( config )
self.beenthere = { }
local co = self.uci.get_all( config )
diff --git a/modules/admin-core/luasrc/tools/webadmin.lua b/modules/admin-core/luasrc/tools/webadmin.lua
index 0f7612ff7..fe725d42d 100644
--- a/modules/admin-core/luasrc/tools/webadmin.lua
+++ b/modules/admin-core/luasrc/tools/webadmin.lua
@@ -57,10 +57,11 @@ function date_format(secs)
end
function network_get_addresses(net)
+ luci.model.uci.load_state("network")
local addr = {}
- local ipv4 = luci.model.uci.get_statevalue("network", net, "ipaddr")
- local mav4 = luci.model.uci.get_statevalue("network", net, "netmask")
- local ipv6 = luci.model.uci.get_statevalue("network", net, "ip6addr")
+ local ipv4 = luci.model.uci.get("network", net, "ipaddr")
+ local mav4 = luci.model.uci.get("network", net, "netmask")
+ local ipv6 = luci.model.uci.get("network", net, "ip6addr")
if ipv4 and mav4 then
ipv4 = luci.ip.IPv4(ipv4, mav4)
@@ -113,7 +114,7 @@ function cbi_add_knownips(field)
end
function network_get_zones(net)
- if not luci.model.uci.load("firewall") then
+ if not luci.model.uci.load_state("firewall") then
return nil
end
@@ -146,11 +147,12 @@ function firewall_find_zone(name)
end
function iface_get_network(iface)
+ luci.model.uci.load_state("network")
local net
luci.model.uci.foreach("network", "interface",
function (section)
- local ifname = luci.model.uci.get_statevalue(
+ local ifname = luci.model.uci.get(
"network", section[".name"], "ifname"
)
diff --git a/modules/admin-full/luasrc/controller/admin/uci.lua b/modules/admin-full/luasrc/controller/admin/uci.lua
index c06683d71..5dd0aaf6e 100644
--- a/modules/admin-full/luasrc/controller/admin/uci.lua
+++ b/modules/admin-full/luasrc/controller/admin/uci.lua
@@ -65,7 +65,7 @@ function action_apply()
for r, tbl in pairs(changes) do
if r then
if path[#path] ~= "apply" then
- luci.model.uci.load(r)
+ luci.model.uci.load_config(r)
luci.model.uci.commit(r)
luci.model.uci.unload(r)
end
@@ -93,7 +93,7 @@ function action_revert()
-- Collect files to be reverted
for r, tbl in pairs(changes) do
- luci.model.uci.load(r)
+ luci.model.uci.load_config(r)
luci.model.uci.revert(r)
luci.model.uci.unload(r)
end
diff --git a/modules/admin-full/luasrc/model/cbi/admin_network/network.lua b/modules/admin-full/luasrc/model/cbi/admin_network/network.lua
index d2ccb9b95..d4f95b8f6 100644
--- a/modules/admin-full/luasrc/model/cbi/admin_network/network.lua
+++ b/modules/admin-full/luasrc/model/cbi/admin_network/network.lua
@@ -17,6 +17,7 @@ require("luci.tools.webadmin")
m = Map("network", translate("interfaces"))
+m.stateful = true
local created
local netstat = luci.sys.net.deviceinfo()
@@ -44,14 +45,12 @@ function s.parse(self, ...)
end
up = s:option(Flag, "up")
-up.stateful = true
function up.write(self, section, value)
local call = value == "1" and "ifdown" or "ifup"
os.execute(call .. " " .. section)
end
ifname = s:option(DummyValue, "ifname", translate("device"))
-ifname.stateful = true
ifname.titleref = luci.dispatcher.build_url("admin", "network", "vlan")
if luci.model.uci.load("firewall") then
@@ -66,7 +65,7 @@ end
hwaddr = s:option(DummyValue, "_hwaddr")
function hwaddr.cfgvalue(self, section)
- local ix = self.map:stateget(section, "ifname") or ""
+ local ix = self.map:get(section, "ifname") or ""
return luci.fs.readfile("/sys/class/net/" .. ix .. "/address") or "n/a"
end
@@ -81,7 +80,7 @@ end
txrx = s:option(DummyValue, "_txrx")
function txrx.cfgvalue(self, section)
- local ix = self.map:stateget(section, "ifname")
+ local ix = self.map:get(section, "ifname")
local rx = netstat and netstat[ix] and netstat[ix][1]
rx = rx and luci.tools.webadmin.byte_format(tonumber(rx)) or "-"
@@ -95,7 +94,7 @@ end
errors = s:option(DummyValue, "_err")
function errors.cfgvalue(self, section)
- local ix = self.map:stateget(section, "ifname")
+ local ix = self.map:get(section, "ifname")
local rx = netstat and netstat[ix] and netstat[ix][3]
local tx = netstat and netstat[ix] and netstat[ix][11]
diff --git a/modules/admin-mini/luasrc/controller/mini/uci.lua b/modules/admin-mini/luasrc/controller/mini/uci.lua
index 5ba4f2949..9b57fe31a 100644
--- a/modules/admin-mini/luasrc/controller/mini/uci.lua
+++ b/modules/admin-mini/luasrc/controller/mini/uci.lua
@@ -63,7 +63,7 @@ function action_apply()
-- Collect files to be applied and commit changes
for r, tbl in pairs(changes) do
if r then
- luci.model.uci.load(r)
+ luci.model.uci.load_config(r)
luci.model.uci.commit(r)
luci.model.uci.unload(r)
if luci.config.uci_oncommit and luci.config.uci_oncommit[r] then
@@ -90,7 +90,7 @@ function action_revert()
-- Collect files to be reverted
for r, tbl in pairs(changes) do
- luci.model.uci.load(r)
+ luci.model.uci.load_config(r)
luci.model.uci.revert(r)
luci.model.uci.unload(r)
end
diff --git a/modules/admin-mini/luasrc/model/cbi/mini/index.lua b/modules/admin-mini/luasrc/model/cbi/mini/index.lua
index eb7d77eb1..5ce9dfcd9 100644
--- a/modules/admin-mini/luasrc/model/cbi/mini/index.lua
+++ b/modules/admin-mini/luasrc/model/cbi/mini/index.lua
@@ -47,6 +47,7 @@ f:field(DummyValue, "_uptime", translate("m_i_uptime")).value =
m = Map("network", translate("interfaces"))
+m.stateful = true
local netstat = luci.sys.net.deviceinfo()
m.parse = function() end
@@ -60,21 +61,20 @@ end
hwaddr = s:option(DummyValue, "_hwaddr")
function hwaddr.cfgvalue(self, section)
- local ix = self.map:stateget(section, "ifname") or ""
+ local ix = self.map:get(section, "ifname") or ""
return luci.fs.readfile("/sys/class/net/" .. ix .. "/address") or "n/a"
end
-ipaddr = s:option(DummyValue, "ipaddr", translate("ipaddress"))
-ipaddr.stateful = true
+s:option(DummyValue, "ipaddr", translate("ipaddress"))
+
+s:option(DummyValue, "netmask", translate("netmask"))
-ipaddr = s:option(DummyValue, "netmask", translate("netmask"))
-ipaddr.stateful = true
txrx = s:option(DummyValue, "_txrx")
function txrx.cfgvalue(self, section)
- local ix = self.map:stateget(section, "ifname")
+ local ix = self.map:get(section, "ifname")
local rx = netstat and netstat[ix] and netstat[ix][1]
rx = rx and luci.tools.webadmin.byte_format(tonumber(rx)) or "-"
@@ -88,7 +88,7 @@ end
errors = s:option(DummyValue, "_err")
function errors.cfgvalue(self, section)
- local ix = self.map:stateget(section, "ifname")
+ local ix = self.map:get(section, "ifname")
local rx = netstat and netstat[ix] and netstat[ix][3]
local tx = netstat and netstat[ix] and netstat[ix][11]
diff --git a/themes/fledermaus/luasrc/view/themes/fledermaus/header.htm b/themes/fledermaus/luasrc/view/themes/fledermaus/header.htm
index ca6438111..db29affb9 100644
--- a/themes/fledermaus/luasrc/view/themes/fledermaus/header.htm
+++ b/themes/fledermaus/luasrc/view/themes/fledermaus/header.htm
@@ -154,7 +154,9 @@ end
<%
if tree.nodes[category] and tree.nodes[category].ucidata then
local ucic = 0
- for i, j in pairs(require("luci.model.uci").changes()) do
+ require("luci.model.uci")
+ luci.model.uci.set_savedir(luci.model.uci.savedir_default)
+ for i, j in pairs(luci.model.uci.changes()) do
for k, l in pairs(j) do
for m, n in pairs(l) do
ucic = ucic + 1;
diff --git a/themes/openwrt-light/luasrc/view/themes/openwrt-light/header.htm b/themes/openwrt-light/luasrc/view/themes/openwrt-light/header.htm
index e9e1a135a..fe0fa0b33 100644
--- a/themes/openwrt-light/luasrc/view/themes/openwrt-light/header.htm
+++ b/themes/openwrt-light/luasrc/view/themes/openwrt-light/header.htm
@@ -161,7 +161,9 @@ end
<%
if tree.nodes[category] and tree.nodes[category].ucidata then
local ucic = 0
- for i, j in pairs(require("luci.model.uci").changes()) do
+ require("luci.model.uci")
+ luci.model.uci.set_savedir(luci.model.uci.savedir_default)
+ for i, j in pairs(luci.model.uci.changes()) do
for k, l in pairs(j) do
for m, n in pairs(l) do
ucic = ucic + 1;
diff --git a/themes/openwrt.org/luasrc/view/themes/openwrt.org/header.htm b/themes/openwrt.org/luasrc/view/themes/openwrt.org/header.htm
index 6b8311431..b3a53c589 100644
--- a/themes/openwrt.org/luasrc/view/themes/openwrt.org/header.htm
+++ b/themes/openwrt.org/luasrc/view/themes/openwrt.org/header.htm
@@ -162,7 +162,9 @@ end
<%
if tree.nodes[category] and tree.nodes[category].ucidata then
local ucic = 0
- for i, j in pairs(require("luci.model.uci").changes()) do
+ require("luci.model.uci")
+ luci.model.uci.set_savedir(luci.model.uci.savedir_default)
+ for i, j in pairs(luci.model.uci.changes()) do
for k, l in pairs(j) do
for m, n in pairs(l) do
ucic = ucic + 1;