# HG changeset patch # User Marco Cirillo # Date 1340712324 0 # Node ID 8ad2e24f5efd6bd7198a38ec494804f3204d650b # Parent 99f5846bcd8596cd0bf0d5e9ba3a0246d1de8327 mod_host_guard: reduced code duplication and added better logging. diff -r 99f5846bcd85 -r 8ad2e24f5efd mod_host_guard/mod_host_guard.lua --- a/mod_host_guard/mod_host_guard.lua Tue Jun 26 10:57:24 2012 +0000 +++ b/mod_host_guard/mod_host_guard.lua Tue Jun 26 12:05:24 2012 +0000 @@ -40,37 +40,37 @@ return nil end -local function handle_activation (host) +local function handle_activation (host, u) if guard_blockall:contains(host) or guard_protect:contains(host) then if hosts[host] and hosts[host].events then hosts[host].events.add_handler("s2sin-established", s2s_hook, 500) hosts[host].events.add_handler("route/remote", rr_hook, 500) hosts[host].events.add_handler("stanza/jabber:server:dialback:result", s2s_hook, 500) - module:log ("debug", "adding host protection for: "..host) + if not u then + module:log ("debug", "adding host protection for: "..host) + else + module:log ("debug", "updating host protection for: "..host) + end end end end -local function handle_deactivation (host) +local function handle_deactivation (host, u, i) if guard_blockall:contains(host) or guard_protect:contains(host) then if hosts[host] and hosts[host].events then hosts[host].events.remove_handler("s2sin-established", s2s_hook) hosts[host].events.remove_handler("route/remote", rr_hook) hosts[host].events.remove_handler("stanza/jabber:server:dialback:result", s2s_hook) - module:log ("debug", "removing host protection for: "..host) + if not u and not i then module:log ("debug", "removing host protection for: "..host) end end end end -local function init_hosts() +local function init_hosts(u, i) for n in pairs(hosts) do if guard_blockall:contains(n) or guard_protect:contains(n) then - -- required as during config:reload() handlers should be reinitialized as well. - hosts[n].events.remove_handler("s2sin-established", s2s_hook) - hosts[n].events.remove_handler("route/remote", rr_hook) - hosts[n].events.remove_handler("stanza/jabber:server:dialback:result", s2s_hook) - - handle_activation(n) + handle_deactivation(n, u, i) + handle_activation(n, u) end end end @@ -82,7 +82,7 @@ guard_protect = module:get_option_set("host_guard_selective", {}) guard_block_bl = module:get_option_set("host_guard_blacklist", {}) - init_hosts() + init_hosts(true) end local function setup() @@ -91,7 +91,7 @@ module:hook ("host-deactivated", handle_deactivation) module:hook ("config-reloaded", reload) - init_hosts() + init_hosts(false, true) end function module.unload()