Software /
code /
prosody-modules
Comparison
mod_firewall/definitions.lib.lua @ 2532:2ddb74805f91
mod_firewall: Add 'file' backend for lists (read-only atm)
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Mon, 20 Feb 2017 10:59:29 +0000 |
parent | 2530:84e103fd8039 |
child | 2535:b85d88737a32 |
comparison
equal
deleted
inserted
replaced
2531:9d2bfff515b8 | 2532:2ddb74805f91 |
---|---|
137 item = self.hash_function(item); | 137 item = self.hash_function(item); |
138 end | 138 end |
139 return self.items and self.items[item] == true; | 139 return self.items and self.items[item] == true; |
140 end; | 140 end; |
141 }; | 141 }; |
142 file = { | |
143 init = function (list_backend, file_spec, opts) | |
144 local filename = file_spec:gsub("^file:"); | |
145 local file, err = io.open(filename); | |
146 if not file then | |
147 module:log("warn", "Failed to open list from %s: %s", filename, err); | |
148 return; | |
149 end | |
150 local items = {}; | |
151 for line in file:lines() do | |
152 items[line] = true; | |
153 end | |
154 self.items = items; | |
155 end; | |
156 add = function (self, item) | |
157 self.items[item] = true; | |
158 end; | |
159 remove = function (self, item) | |
160 self.items[item] = nil; | |
161 end; | |
162 contains = function (self, item) | |
163 return self.items and self.items[item] == true; | |
164 end; | |
165 }; | |
142 }; | 166 }; |
143 list_backends.https = list_backends.http; | 167 list_backends.https = list_backends.http; |
144 | 168 |
145 local function create_list(list_backend, list_def, opts) | 169 local function create_list(list_backend, list_def, opts) |
146 if not list_backends[list_backend] then | 170 if not list_backends[list_backend] then |