Software /
code /
prosody-modules
Comparison
mod_firewall/definitions.lib.lua @ 2898:9fd61234b6f0
mod_firewall/definitions: Comments on LIST backends
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Tue, 06 Mar 2018 18:24:34 +0100 |
parent | 2859:22e11645a895 |
child | 3240:c30f2cfe9f15 |
comparison
equal
deleted
inserted
replaced
2897:39485b9bbdd6 | 2898:9fd61234b6f0 |
---|---|
60 end; | 60 end; |
61 }; | 61 }; |
62 end | 62 end |
63 | 63 |
64 local list_backends = { | 64 local list_backends = { |
65 -- %LIST name: memory (limit: number) | |
65 memory = { | 66 memory = { |
66 init = function (self, type, opts) | 67 init = function (self, type, opts) |
67 if opts.limit then | 68 if opts.limit then |
68 local have_cache_lib, cache_lib = pcall(require, "util.cache"); | 69 local have_cache_lib, cache_lib = pcall(require, "util.cache"); |
69 if not have_cache_lib then | 70 if not have_cache_lib then |
86 end; | 87 end; |
87 contains = function (self, item) | 88 contains = function (self, item) |
88 return self.items[item] == true; | 89 return self.items[item] == true; |
89 end; | 90 end; |
90 }; | 91 }; |
92 | |
93 -- %LIST name: http://example.com/ (ttl: number, pattern: pat, hash: sha1) | |
91 http = { | 94 http = { |
92 init = function (self, url, opts) | 95 init = function (self, url, opts) |
93 local poll_interval = assert(tonumber(opts.ttl or "3600"), "invalid ttl for <"..url.."> (expected number of seconds)"); | 96 local poll_interval = assert(tonumber(opts.ttl or "3600"), "invalid ttl for <"..url.."> (expected number of seconds)"); |
94 local pattern = opts.pattern or "([^\r\n]+)\r?\n"; | 97 local pattern = opts.pattern or "([^\r\n]+)\r?\n"; |
95 assert(pcall(string.match, "", pattern), "invalid pattern for <"..url..">"); | 98 assert(pcall(string.match, "", pattern), "invalid pattern for <"..url..">"); |
138 item = self.hash_function(item); | 141 item = self.hash_function(item); |
139 end | 142 end |
140 return self.items and self.items[item] == true; | 143 return self.items and self.items[item] == true; |
141 end; | 144 end; |
142 }; | 145 }; |
146 | |
147 -- %LIST: file:/path/to/file | |
143 file = { | 148 file = { |
144 init = function (self, file_spec, opts) | 149 init = function (self, file_spec, opts) |
145 local filename = file_spec:gsub("^file:", ""); | 150 local filename = file_spec:gsub("^file:", ""); |
146 local file, err = io.open(filename); | 151 local file, err = io.open(filename); |
147 if not file then | 152 if not file then |