Mercurial > prosody-modules
comparison mod_firewall/definitions.lib.lua @ 3240:c30f2cfe9f15
mod_firewall: Assume empty list if file could not be loaded
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Sun, 19 Aug 2018 17:53:05 +0100 |
parents | 9fd61234b6f0 |
children | b872f111b7af |
comparison
equal
deleted
inserted
replaced
3239:796c98e8e666 | 3240:c30f2cfe9f15 |
---|---|
145 }; | 145 }; |
146 | 146 |
147 -- %LIST: file:/path/to/file | 147 -- %LIST: file:/path/to/file |
148 file = { | 148 file = { |
149 init = function (self, file_spec, opts) | 149 init = function (self, file_spec, opts) |
150 local items = {}; | |
151 local n = 0; | |
150 local filename = file_spec:gsub("^file:", ""); | 152 local filename = file_spec:gsub("^file:", ""); |
151 local file, err = io.open(filename); | 153 local file, err = io.open(filename); |
152 if not file then | 154 if not file then |
153 module:log("warn", "Failed to open list from %s: %s", filename, err); | 155 module:log("warn", "Failed to open list from %s: %s", filename, err); |
154 return; | 156 return; |
155 end | 157 else |
156 local items = {}; | 158 for line in file:lines() do |
157 local n = 0; | 159 if not items[line] then |
158 for line in file:lines() do | 160 n = n + 1; |
159 if not items[line] then | 161 items[line] = true; |
160 n = n + 1; | 162 end |
161 items[line] = true; | |
162 end | 163 end |
163 end | 164 end |
164 self.items = items; | 165 self.items = items; |
165 module:log("debug", "Loaded %d items from %s", n, filename); | 166 module:log("debug", "Loaded %d items from %s", n, filename); |
166 end; | 167 end; |