Mercurial > prosody-modules
comparison mod_firewall/conditions.lib.lua @ 2519:d4bc434a60a4
mod_firewall: Update functions that use meta() to allow functions with deps inside expressions
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Sun, 19 Feb 2017 21:08:30 +0000 |
parents | bd69ffe071e6 |
children | c6fd8975704b |
comparison
equal
deleted
inserted
replaced
2518:0e1054c19f9d | 2519:d4bc434a60a4 |
---|---|
122 if path:find("=") then | 122 if path:find("=") then |
123 local query, match_type, value = path:match("(.-)([~/$]*)=(.*)"); | 123 local query, match_type, value = path:match("(.-)([~/$]*)=(.*)"); |
124 if not(query:match("#$") or query:match("@[^/]+")) then | 124 if not(query:match("#$") or query:match("@[^/]+")) then |
125 error("Stanza path does not return a string (append # for text content or @name for value of named attribute)", 0); | 125 error("Stanza path does not return a string (append # for text content or @name for value of named attribute)", 0); |
126 end | 126 end |
127 local meta_deps = {}; | |
127 local quoted_value = ("%q"):format(value); | 128 local quoted_value = ("%q"):format(value); |
128 if match_type:find("$", 1, true) then | 129 if match_type:find("$", 1, true) then |
129 match_type = match_type:gsub("%$", ""); | 130 match_type = match_type:gsub("%$", ""); |
130 quoted_value = meta(quoted_value); | 131 quoted_value = meta(quoted_value, meta_deps); |
131 end | 132 end |
132 if match_type == "~" then -- Lua pattern match | 133 if match_type == "~" then -- Lua pattern match |
133 return ("(stanza:find(%q) or ''):match(%s)"):format(query, quoted_value); | 134 return ("(stanza:find(%q) or ''):match(%s)"):format(query, quoted_value), meta_deps; |
134 elseif match_type == "/" then -- find literal substring | 135 elseif match_type == "/" then -- find literal substring |
135 return ("(stanza:find(%q) or ''):find(%s, 1, true)"):format(query, quoted_value); | 136 return ("(stanza:find(%q) or ''):find(%s, 1, true)"):format(query, quoted_value), meta_deps; |
136 elseif match_type == "" then -- exact match | 137 elseif match_type == "" then -- exact match |
137 return ("stanza:find(%q) == %s"):format(query, quoted_value); | 138 return ("stanza:find(%q) == %s"):format(query, quoted_value), meta_deps; |
138 else | 139 else |
139 error("Unrecognised comparison '"..match_type.."='", 0); | 140 error("Unrecognised comparison '"..match_type.."='", 0); |
140 end | 141 end |
141 end | 142 end |
142 return ("stanza:find(%q)"):format(path); | 143 return ("stanza:find(%q)"):format(path); |
218 return table.concat(conditions, " or "), { "time:hour,min" }; | 219 return table.concat(conditions, " or "), { "time:hour,min" }; |
219 end | 220 end |
220 | 221 |
221 function condition_handlers.LIMIT(spec) | 222 function condition_handlers.LIMIT(spec) |
222 local name, param = spec:match("^(%w+) on (.+)$"); | 223 local name, param = spec:match("^(%w+) on (.+)$"); |
224 local meta_deps = {}; | |
223 | 225 |
224 if not name then | 226 if not name then |
225 name = spec:match("^%w+$"); | 227 name = spec:match("^%w+$"); |
226 if not name then | 228 if not name then |
227 error("Unable to parse LIMIT specification"); | 229 error("Unable to parse LIMIT specification"); |
228 end | 230 end |
229 else | 231 else |
230 param = meta(("%q"):format(param)); | 232 param = meta(("%q"):format(param), meta_deps); |
231 end | 233 end |
232 | 234 |
233 if not param then | 235 if not param then |
234 return ("not global_throttle_%s:poll(1)"):format(name), { "globalthrottle:"..name }; | 236 return ("not global_throttle_%s:poll(1)"):format(name), { "globalthrottle:"..name, unpack(meta_deps) }; |
235 end | 237 end |
236 return ("not multi_throttle_%s:poll_on(%s, 1)"):format(name, param), { "multithrottle:"..name }; | 238 return ("not multi_throttle_%s:poll_on(%s, 1)"):format(name, param), { "multithrottle:"..name, unpack(meta_deps) }; |
237 end | 239 end |
238 | 240 |
239 function condition_handlers.ORIGIN_MARKED(name_and_time) | 241 function condition_handlers.ORIGIN_MARKED(name_and_time) |
240 local name, time = name_and_time:match("^%s*([%w_]+)%s+%(([^)]+)s%)%s*$"); | 242 local name, time = name_and_time:match("^%s*([%w_]+)%s+%(([^)]+)s%)%s*$"); |
241 if not name then | 243 if not name then |