libs/core: use imatch() in firewall and network model

This commit is contained in:
Jo-Philipp Wich 2010-10-30 17:56:06 +00:00
parent ddd1ba088e
commit 95886d4585
2 changed files with 6 additions and 26 deletions

View file

@ -29,16 +29,6 @@ module "luci.model.firewall"
local uci_r, uci_s local uci_r, uci_s
function _strlist(x)
if x == nil then
x = ""
elseif type(x) == "table" then
x = table.concat(x, " ")
end
return x:gmatch("%S+")
end
function _valid_id(x) function _valid_id(x)
return (x and #x > 0 and x:match("^[a-zA-Z0-9_]+$")) return (x and #x > 0 and x:match("^[a-zA-Z0-9_]+$"))
end end
@ -130,7 +120,7 @@ function get_zone_by_network(self, net)
function(s) function(s)
if s.name and net then if s.name and net then
local n local n
for n in _strlist(s.network or s.name) do for n in utl.imatch(s.network or s.name) do
if n == net then if n == net then
z = s['.name'] z = s['.name']
return false return false
@ -338,7 +328,7 @@ function zone.add_network(self, net)
local nets = { } local nets = { }
local n local n
for n in _strlist(self:get("network") or self:get("name")) do for n in utl.imatch(self:get("network") or self:get("name")) do
if n ~= net then if n ~= net then
nets[#nets+1] = n nets[#nets+1] = n
end end
@ -358,7 +348,7 @@ function zone.del_network(self, net)
local nets = { } local nets = { }
local n local n
for n in _strlist(self:get("network") or self:get("name")) do for n in utl.imatch(self:get("network") or self:get("name")) do
if n ~= net then if n ~= net then
nets[#nets+1] = n nets[#nets+1] = n
end end
@ -375,7 +365,7 @@ function zone.get_networks(self)
local nets = { } local nets = { }
local n local n
for n in _strlist(self:get("network") or self:get("name")) do for n in utl.imatch(self:get("network") or self:get("name")) do
nets[#nets+1] = n nets[#nets+1] = n
end end

View file

@ -93,16 +93,6 @@ function _stror(s1, s2)
end end
end end
function _strlist(x)
if x == nil then
x = ""
elseif type(x) == "table" then
x = table.concat(x, " ")
end
return x:gmatch("%S+")
end
function _get(c, s, o) function _get(c, s, o)
return uci_r:get(c, s, o) return uci_r:get(c, s, o)
end end
@ -619,7 +609,7 @@ function network.get_interfaces(self)
ifaces = { interface(ifn) } ifaces = { interface(ifn) }
else else
local nfs = { } local nfs = { }
for ifn in _strlist(self:get("ifname")) do for ifn in utl.imatch(self:get("ifname")) do
ifn = ifn:match("[^:]+") ifn = ifn:match("[^:]+")
nfs[ifn] = interface(ifn) nfs[ifn] = interface(ifn)
end end
@ -661,7 +651,7 @@ function network.contains_interface(self, ifname)
ifn = self:proto() .. "-" .. self.sid ifn = self:proto() .. "-" .. self.sid
return ifname == ifn return ifname == ifn
else else
for ifn in _strlist(self:get("ifname")) do for ifn in utl.imatch(self:get("ifname")) do
ifn = ifn:match("[^:]+") ifn = ifn:match("[^:]+")
if ifn == ifname then if ifn == ifname then
return true return true