comparison mod_block_outgoing/mod_block_outgoing.lua @ 2007:dc1299ca0185

mod_block_outgoing: Make blocked stanza types configurable, and default to blocking messages only
author Matthew Wild <mwild1@gmail.com>
date Wed, 13 Jan 2016 23:04:55 +0000
parents cb810a2bca47
children
comparison
equal deleted inserted replaced
2006:cb810a2bca47 2007:dc1299ca0185
1 -- Module to block all outgoing stanzas from a list of users 1 -- Module to block all outgoing stanzas from a list of users
2 2
3 local jid_bare = require "util.jid".bare; 3 local jid_bare = require "util.jid".bare;
4 local is_admin = require "core.usermanager".is_admin; 4 local is_admin = require "core.usermanager".is_admin;
5 local set = require "util.set";
5 6
6 local block_users = module:get_option_set("block_outgoing_users", {}); 7 local block_users = module:get_option_set("block_outgoing_users", {});
7 local block_all = block_users:empty(); 8 local block_all = block_users:empty();
8 9
9 local stanza_types = { "iq", "presence", "message" }; 10 local stanza_types = module:get_option_set("block_outgoing_stanzas", { "message" });
10 local jid_types = { "host", "bare", "full" }; 11 local jid_types = set.new{ "host", "bare", "full" };
11 12
12 local function block_stanza(event) 13 local function block_stanza(event)
13 local stanza = event.stanza; 14 local stanza = event.stanza;
14 local from_jid = jid_bare(stanza.attr.from); 15 local from_jid = jid_bare(stanza.attr.from);
15 if stanza.attr.to == nil or stanza.attr.to == module.host or is_admin(from_jid, module.host) then 16 if stanza.attr.to == nil or stanza.attr.to == module.host or is_admin(from_jid, module.host) then
20 return true; 21 return true;
21 end 22 end
22 end 23 end
23 24
24 function module.load() 25 function module.load()
25 for _, stanza_type in ipairs(stanza_types) do 26 for stanza_type in stanza_types do
26 for _, jid_type in ipairs(jid_types) do 27 for jid_type in jid_types do
27 module:hook("pre-"..stanza_type.."/"..jid_type, block_stanza, 10000); 28 module:hook("pre-"..stanza_type.."/"..jid_type, block_stanza, 10000);
28 end 29 end
29 end 30 end
30 end 31 end