diff options
author | Kaarle Ritvanen <kaarle.ritvanen@datakunkku.fi> | 2014-09-18 10:33:28 +0300 |
---|---|---|
committer | Kaarle Ritvanen <kaarle.ritvanen@datakunkku.fi> | 2014-09-18 10:33:28 +0300 |
commit | 0bfb89f3dd963afa7995a63f756edff42ddeacd4 (patch) | |
tree | 7e995f1680bda86b162657f60ef231e3df125f2b | |
parent | be8890f615cbe4da185321dd138090dd28ca554d (diff) | |
download | awall-0bfb89f3dd963afa7995a63f756edff42ddeacd4.tar.bz2 awall-0bfb89f3dd963afa7995a63f756edff42ddeacd4.tar.xz |
move 'uniqueid' method to ConfigObject
-rw-r--r-- | awall/model.lua | 35 |
1 files changed, 17 insertions, 18 deletions
diff --git a/awall/model.lua b/awall/model.lua index 41e68ec..826971a 100644 --- a/awall/model.lua +++ b/awall/model.lua @@ -37,6 +37,7 @@ function M.ConfigObject:init(context, location) self.root = context.objects end self.location = location + self.uniqueids = {} end function M.ConfigObject:create(cls, params) @@ -55,6 +56,22 @@ function M.ConfigObject:create(cls, params) return cls.morph(params, self.context, self.location) end +function M.ConfigObject:uniqueid(key) + if self.uniqueids[key] then return self.uniqueids[key] end + + if not self.context.lastid then self.context.lastid = {} end + local lastid = self.context.lastid + + local res = key + if self.label then res = res..'-'..self.label end + if not lastid[res] then lastid[res] = -1 end + lastid[res] = lastid[res] + 1 + res = res..'-'..lastid[res] + + self.uniqueids[key] = res + return res +end + function M.ConfigObject:error(msg) raise(self.location..': '..msg) end function M.ConfigObject:warning(msg) @@ -136,8 +153,6 @@ M.Rule = M.class(M.ConfigObject) function M.Rule:init(...) M.Rule.super(self):init(...) - self.uniqueids = {} - for i, prop in ipairs({'in', 'out'}) do self[prop] = self[prop] and maplist( self[prop], @@ -538,22 +553,6 @@ end function M.Rule:extraoptfrags() return {} end -function M.Rule:uniqueid(key) - if self.uniqueids[key] then return self.uniqueids[key] end - - if not self.context.lastid then self.context.lastid = {} end - local lastid = self.context.lastid - - local res = key - if self.label then res = res..'-'..self.label end - if not lastid[res] then lastid[res] = -1 end - lastid[res] = lastid[res] + 1 - res = res..'-'..lastid[res] - - self.uniqueids[key] = res - return res -end - M.export = {zone={class=M.Zone}, ipset={class=IPSet, before='%modules'}} |