Software /
code /
prosody-modules
File
mod_anti_spam/trie.lib.lua @ 6112:4c0e3fe57e92
mod_compliance_latest: Gracefull error logging on missing dependency.
diff --git a/mod_compliance_latest/README.md b/mod_compliance_latest/README.md
--- a/mod_compliance_latest/README.md
+++ b/mod_compliance_latest/README.md
@@ -9,13 +9,15 @@ rockspec:
# Introduction
-This module will always require and load to the lastest compliance tester we have in the community modules.
-Currently this is [mod_compliance_2023].
+This meta-module will always `require` (and therefore auto-load) the lastest compliance tester we have in the community modules.
+Currently this is [mod_compliance_2023]. See the linked module for further details.
+
+If you do not use the *Prosody plugin installer* this module will likely have limited value to you.
+You can also just install the current compliance tester manually.
# Configuration
-Just load this module as any other module and it will automatically install [mod_compliance_2023] if you use the Prosody plugin installer.
-See the linked module for further details.
+Just load this module as any other module and it will automatically install and load [mod_compliance_2023] if you use the *Prosody plugin installer*.
# Compatibility
diff --git a/mod_compliance_latest/mod_compliance_latest.lua b/mod_compliance_latest/mod_compliance_latest.lua
--- a/mod_compliance_latest/mod_compliance_latest.lua
+++ b/mod_compliance_latest/mod_compliance_latest.lua
@@ -1,1 +1,6 @@
-module:depends("compliance_2023");
+local success, err = pcall(function() module:depends("compliance_2023") end)
+
+if not success then
+ module:log("error", "Error, can't load module: mod_compliance_2023. Is this module downloaded in a folder readable by prosody?")
+ return 1, "Error: Couldn't load dependency mod_compliance_2023."
+end
author | Menel <menel@snikket.de> |
---|---|
date | Mon, 23 Dec 2024 12:58:03 +0100 |
parent | 5883:259ffdbf8906 |
child | 6118:8338f42d2bc5 |
child | 6208:e20901443eae |
line wrap: on
line source
local bit = require "prosody.util.bitcompat"; local trie_methods = {}; local trie_mt = { __index = trie_methods }; local function new_node() return {}; end function trie_methods:set(item, value) local node = self.root; for i = 1, #item do local c = item:byte(i); if not node[c] then node[c] = new_node(); end node = node[c]; end node.terminal = true; node.value = value; end local function _remove(node, item, i) if i > #item then if node.terminal then node.terminal = nil; node.value = nil; end if next(node) ~= nil then return node; end return nil; end local c = item:byte(i); local child = node[c]; local ret; if child then ret = _remove(child, item, i+1); node[c] = ret; end if ret == nil and next(node) == nil then return nil; end return node; end function trie_methods:remove(item) return _remove(self.root, item, 1); end function trie_methods:get(item, partial) local value; local node = self.root; local len = #item; for i = 1, len do if partial and node.terminal then value = node.value; end local c = item:byte(i); node = node[c]; if not node then return value, i - 1; end end return node.value, len; end function trie_methods:add(item) return self:set(item, true); end function trie_methods:contains(item, partial) return self:get(item, partial) ~= nil; end function trie_methods:longest_prefix(item) return select(2, self:get(item)); end function trie_methods:add_subnet(item, bits) item = item.packed:sub(1, math.ceil(bits/8)); local existing = self:get(item); if not existing then existing = { bits }; return self:set(item, existing); end -- Simple insertion sort for i = 1, #existing do local v = existing[i]; if v == bits then return; -- Already in there elseif v > bits then table.insert(existing, v, i); return; end end end function trie_methods:remove_subnet(item, bits) item = item.packed:sub(1, math.ceil(bits/8)); local existing = self:get(item); if not existing then return; end -- Simple insertion sort for i = 1, #existing do local v = existing[i]; if v == bits then table.remove(existing, i); break; elseif v > bits then return; -- Stop search end end if #existing == 0 then self:remove(item); end end function trie_methods:has_ip(item) item = item.packed; local node = self.root; local len = #item; for i = 1, len do if node.terminal then return true; end local c = item:byte(i); local child = node[c]; if not child then for child_byte, child_node in pairs(node) do if type(child_byte) == "number" and child_node.terminal then local bits = child_node.value; for j = #bits, 1, -1 do local b = bits[j]-((i-1)*8); if b ~= 8 then local mask = bit.bnot(2^b-1); if bit.band(bit.bxor(c, child_byte), mask) == 0 then return true; end end end end end return false; end node = child; end end local function new() return setmetatable({ root = new_node(); }, trie_mt); end local function is_trie(o) return getmetatable(o) == trie_mt; end return { new = new; is_trie = is_trie; };