plugins/mod_blocklist.lua
author Kim Alvefur <zash@zash.se>
Tue, 09 Dec 2014 19:36:34 +0100
changeset 6534 18f4973849b1
parent 6498 44df423f8290
child 6632 42aeb882b3e1
permissions -rw-r--r--
mod_blocklist: Fix import
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
6344
68b5c1ed18dd mod_blocklist: XEP-0191 implementation written for speed and independence from mod_privacy
Kim Alvefur <zash@zash.se>
parents:
diff changeset
     1
-- Prosody IM
68b5c1ed18dd mod_blocklist: XEP-0191 implementation written for speed and independence from mod_privacy
Kim Alvefur <zash@zash.se>
parents:
diff changeset
     2
-- Copyright (C) 2009-2010 Matthew Wild
68b5c1ed18dd mod_blocklist: XEP-0191 implementation written for speed and independence from mod_privacy
Kim Alvefur <zash@zash.se>
parents:
diff changeset
     3
-- Copyright (C) 2009-2010 Waqas Hussain
68b5c1ed18dd mod_blocklist: XEP-0191 implementation written for speed and independence from mod_privacy
Kim Alvefur <zash@zash.se>
parents:
diff changeset
     4
-- Copyright (C) 2014 Kim Alvefur
68b5c1ed18dd mod_blocklist: XEP-0191 implementation written for speed and independence from mod_privacy
Kim Alvefur <zash@zash.se>
parents:
diff changeset
     5
--
68b5c1ed18dd mod_blocklist: XEP-0191 implementation written for speed and independence from mod_privacy
Kim Alvefur <zash@zash.se>
parents:
diff changeset
     6
-- This project is MIT/X11 licensed. Please see the
68b5c1ed18dd mod_blocklist: XEP-0191 implementation written for speed and independence from mod_privacy
Kim Alvefur <zash@zash.se>
parents:
diff changeset
     7
-- COPYING file in the source package for more information.
68b5c1ed18dd mod_blocklist: XEP-0191 implementation written for speed and independence from mod_privacy
Kim Alvefur <zash@zash.se>
parents:
diff changeset
     8
--
68b5c1ed18dd mod_blocklist: XEP-0191 implementation written for speed and independence from mod_privacy
Kim Alvefur <zash@zash.se>
parents:
diff changeset
     9
-- This module implements XEP-0191: Blocking Command
68b5c1ed18dd mod_blocklist: XEP-0191 implementation written for speed and independence from mod_privacy
Kim Alvefur <zash@zash.se>
parents:
diff changeset
    10
--
68b5c1ed18dd mod_blocklist: XEP-0191 implementation written for speed and independence from mod_privacy
Kim Alvefur <zash@zash.se>
parents:
diff changeset
    11
68b5c1ed18dd mod_blocklist: XEP-0191 implementation written for speed and independence from mod_privacy
Kim Alvefur <zash@zash.se>
parents:
diff changeset
    12
local user_exists = require"core.usermanager".user_exists;
68b5c1ed18dd mod_blocklist: XEP-0191 implementation written for speed and independence from mod_privacy
Kim Alvefur <zash@zash.se>
parents:
diff changeset
    13
local is_contact_subscribed = require"core.rostermanager".is_contact_subscribed;
68b5c1ed18dd mod_blocklist: XEP-0191 implementation written for speed and independence from mod_privacy
Kim Alvefur <zash@zash.se>
parents:
diff changeset
    14
local st = require"util.stanza";
68b5c1ed18dd mod_blocklist: XEP-0191 implementation written for speed and independence from mod_privacy
Kim Alvefur <zash@zash.se>
parents:
diff changeset
    15
local st_error_reply = st.error_reply;
6534
18f4973849b1 mod_blocklist: Fix import
Kim Alvefur <zash@zash.se>
parents: 6498
diff changeset
    16
local jid_prep, jid_split = import("util.jid", "prep", "split");
6344
68b5c1ed18dd mod_blocklist: XEP-0191 implementation written for speed and independence from mod_privacy
Kim Alvefur <zash@zash.se>
parents:
diff changeset
    17
68b5c1ed18dd mod_blocklist: XEP-0191 implementation written for speed and independence from mod_privacy
Kim Alvefur <zash@zash.se>
parents:
diff changeset
    18
local host = module.host;
68b5c1ed18dd mod_blocklist: XEP-0191 implementation written for speed and independence from mod_privacy
Kim Alvefur <zash@zash.se>
parents:
diff changeset
    19
local storage = module:open_store();
68b5c1ed18dd mod_blocklist: XEP-0191 implementation written for speed and independence from mod_privacy
Kim Alvefur <zash@zash.se>
parents:
diff changeset
    20
local sessions = prosody.hosts[host].sessions;
68b5c1ed18dd mod_blocklist: XEP-0191 implementation written for speed and independence from mod_privacy
Kim Alvefur <zash@zash.se>
parents:
diff changeset
    21
68b5c1ed18dd mod_blocklist: XEP-0191 implementation written for speed and independence from mod_privacy
Kim Alvefur <zash@zash.se>
parents:
diff changeset
    22
-- Cache of blocklists used since module was loaded
68b5c1ed18dd mod_blocklist: XEP-0191 implementation written for speed and independence from mod_privacy
Kim Alvefur <zash@zash.se>
parents:
diff changeset
    23
local cache = {};
68b5c1ed18dd mod_blocklist: XEP-0191 implementation written for speed and independence from mod_privacy
Kim Alvefur <zash@zash.se>
parents:
diff changeset
    24
if module:get_option_boolean("blocklist_weak_cache") then
68b5c1ed18dd mod_blocklist: XEP-0191 implementation written for speed and independence from mod_privacy
Kim Alvefur <zash@zash.se>
parents:
diff changeset
    25
	-- Lower memory usage, more IO and latency
68b5c1ed18dd mod_blocklist: XEP-0191 implementation written for speed and independence from mod_privacy
Kim Alvefur <zash@zash.se>
parents:
diff changeset
    26
	setmetatable(cache, { __mode = "v" });
68b5c1ed18dd mod_blocklist: XEP-0191 implementation written for speed and independence from mod_privacy
Kim Alvefur <zash@zash.se>
parents:
diff changeset
    27
end
68b5c1ed18dd mod_blocklist: XEP-0191 implementation written for speed and independence from mod_privacy
Kim Alvefur <zash@zash.se>
parents:
diff changeset
    28
68b5c1ed18dd mod_blocklist: XEP-0191 implementation written for speed and independence from mod_privacy
Kim Alvefur <zash@zash.se>
parents:
diff changeset
    29
local null_blocklist = {};
68b5c1ed18dd mod_blocklist: XEP-0191 implementation written for speed and independence from mod_privacy
Kim Alvefur <zash@zash.se>
parents:
diff changeset
    30
68b5c1ed18dd mod_blocklist: XEP-0191 implementation written for speed and independence from mod_privacy
Kim Alvefur <zash@zash.se>
parents:
diff changeset
    31
module:add_feature("urn:xmpp:blocking");
68b5c1ed18dd mod_blocklist: XEP-0191 implementation written for speed and independence from mod_privacy
Kim Alvefur <zash@zash.se>
parents:
diff changeset
    32
68b5c1ed18dd mod_blocklist: XEP-0191 implementation written for speed and independence from mod_privacy
Kim Alvefur <zash@zash.se>
parents:
diff changeset
    33
local function set_blocklist(username, blocklist)
68b5c1ed18dd mod_blocklist: XEP-0191 implementation written for speed and independence from mod_privacy
Kim Alvefur <zash@zash.se>
parents:
diff changeset
    34
	local ok, err = storage:set(username, blocklist);
68b5c1ed18dd mod_blocklist: XEP-0191 implementation written for speed and independence from mod_privacy
Kim Alvefur <zash@zash.se>
parents:
diff changeset
    35
	if not ok then
68b5c1ed18dd mod_blocklist: XEP-0191 implementation written for speed and independence from mod_privacy
Kim Alvefur <zash@zash.se>
parents:
diff changeset
    36
		return ok, err;
68b5c1ed18dd mod_blocklist: XEP-0191 implementation written for speed and independence from mod_privacy
Kim Alvefur <zash@zash.se>
parents:
diff changeset
    37
	end
68b5c1ed18dd mod_blocklist: XEP-0191 implementation written for speed and independence from mod_privacy
Kim Alvefur <zash@zash.se>
parents:
diff changeset
    38
	-- Successful save, update the cache
68b5c1ed18dd mod_blocklist: XEP-0191 implementation written for speed and independence from mod_privacy
Kim Alvefur <zash@zash.se>
parents:
diff changeset
    39
	cache[username] = blocklist;
68b5c1ed18dd mod_blocklist: XEP-0191 implementation written for speed and independence from mod_privacy
Kim Alvefur <zash@zash.se>
parents:
diff changeset
    40
	return true;
68b5c1ed18dd mod_blocklist: XEP-0191 implementation written for speed and independence from mod_privacy
Kim Alvefur <zash@zash.se>
parents:
diff changeset
    41
end
68b5c1ed18dd mod_blocklist: XEP-0191 implementation written for speed and independence from mod_privacy
Kim Alvefur <zash@zash.se>
parents:
diff changeset
    42
68b5c1ed18dd mod_blocklist: XEP-0191 implementation written for speed and independence from mod_privacy
Kim Alvefur <zash@zash.se>
parents:
diff changeset
    43
-- Migrates from the old mod_privacy storage
68b5c1ed18dd mod_blocklist: XEP-0191 implementation written for speed and independence from mod_privacy
Kim Alvefur <zash@zash.se>
parents:
diff changeset
    44
local function migrate_privacy_list(username)
68b5c1ed18dd mod_blocklist: XEP-0191 implementation written for speed and independence from mod_privacy
Kim Alvefur <zash@zash.se>
parents:
diff changeset
    45
	local migrated_data = { [false] = "not empty" };
68b5c1ed18dd mod_blocklist: XEP-0191 implementation written for speed and independence from mod_privacy
Kim Alvefur <zash@zash.se>
parents:
diff changeset
    46
	local legacy_data = module:open_store("privacy"):get(username);
68b5c1ed18dd mod_blocklist: XEP-0191 implementation written for speed and independence from mod_privacy
Kim Alvefur <zash@zash.se>
parents:
diff changeset
    47
	if legacy_data and legacy_data.lists and legacy_data.default then
68b5c1ed18dd mod_blocklist: XEP-0191 implementation written for speed and independence from mod_privacy
Kim Alvefur <zash@zash.se>
parents:
diff changeset
    48
		legacy_data = legacy_data.lists[legacy_data.default];
68b5c1ed18dd mod_blocklist: XEP-0191 implementation written for speed and independence from mod_privacy
Kim Alvefur <zash@zash.se>
parents:
diff changeset
    49
		legacy_data = legacy_data and legacy_data.items;
68b5c1ed18dd mod_blocklist: XEP-0191 implementation written for speed and independence from mod_privacy
Kim Alvefur <zash@zash.se>
parents:
diff changeset
    50
	else
68b5c1ed18dd mod_blocklist: XEP-0191 implementation written for speed and independence from mod_privacy
Kim Alvefur <zash@zash.se>
parents:
diff changeset
    51
		return migrated_data;
68b5c1ed18dd mod_blocklist: XEP-0191 implementation written for speed and independence from mod_privacy
Kim Alvefur <zash@zash.se>
parents:
diff changeset
    52
	end
68b5c1ed18dd mod_blocklist: XEP-0191 implementation written for speed and independence from mod_privacy
Kim Alvefur <zash@zash.se>
parents:
diff changeset
    53
	if legacy_data then
6497
5979eaed12c0 mod_blocklist: Only log message about migrating from mod_privacy when there is data to migrate
Kim Alvefur <zash@zash.se>
parents: 6463
diff changeset
    54
		module:log("info", "Migrating blocklist from mod_privacy storage for user '%s'", username);
6344
68b5c1ed18dd mod_blocklist: XEP-0191 implementation written for speed and independence from mod_privacy
Kim Alvefur <zash@zash.se>
parents:
diff changeset
    55
		local item, jid;
68b5c1ed18dd mod_blocklist: XEP-0191 implementation written for speed and independence from mod_privacy
Kim Alvefur <zash@zash.se>
parents:
diff changeset
    56
		for i = 1, #legacy_data do
68b5c1ed18dd mod_blocklist: XEP-0191 implementation written for speed and independence from mod_privacy
Kim Alvefur <zash@zash.se>
parents:
diff changeset
    57
			item = legacy_data[i];
68b5c1ed18dd mod_blocklist: XEP-0191 implementation written for speed and independence from mod_privacy
Kim Alvefur <zash@zash.se>
parents:
diff changeset
    58
			if item.type == "jid" and item.action == "deny" then
68b5c1ed18dd mod_blocklist: XEP-0191 implementation written for speed and independence from mod_privacy
Kim Alvefur <zash@zash.se>
parents:
diff changeset
    59
				jid = jid_prep(item.value);
68b5c1ed18dd mod_blocklist: XEP-0191 implementation written for speed and independence from mod_privacy
Kim Alvefur <zash@zash.se>
parents:
diff changeset
    60
				if not jid then
68b5c1ed18dd mod_blocklist: XEP-0191 implementation written for speed and independence from mod_privacy
Kim Alvefur <zash@zash.se>
parents:
diff changeset
    61
					module:log("warn", "Invalid JID in privacy store for user '%s' not migrated: %s", username, tostring(item.value));
68b5c1ed18dd mod_blocklist: XEP-0191 implementation written for speed and independence from mod_privacy
Kim Alvefur <zash@zash.se>
parents:
diff changeset
    62
				else
68b5c1ed18dd mod_blocklist: XEP-0191 implementation written for speed and independence from mod_privacy
Kim Alvefur <zash@zash.se>
parents:
diff changeset
    63
					migrated_data[jid] = true;
68b5c1ed18dd mod_blocklist: XEP-0191 implementation written for speed and independence from mod_privacy
Kim Alvefur <zash@zash.se>
parents:
diff changeset
    64
				end
68b5c1ed18dd mod_blocklist: XEP-0191 implementation written for speed and independence from mod_privacy
Kim Alvefur <zash@zash.se>
parents:
diff changeset
    65
			end
68b5c1ed18dd mod_blocklist: XEP-0191 implementation written for speed and independence from mod_privacy
Kim Alvefur <zash@zash.se>
parents:
diff changeset
    66
		end
68b5c1ed18dd mod_blocklist: XEP-0191 implementation written for speed and independence from mod_privacy
Kim Alvefur <zash@zash.se>
parents:
diff changeset
    67
	end
68b5c1ed18dd mod_blocklist: XEP-0191 implementation written for speed and independence from mod_privacy
Kim Alvefur <zash@zash.se>
parents:
diff changeset
    68
	set_blocklist(username, migrated_data);
68b5c1ed18dd mod_blocklist: XEP-0191 implementation written for speed and independence from mod_privacy
Kim Alvefur <zash@zash.se>
parents:
diff changeset
    69
	return migrated_data;
68b5c1ed18dd mod_blocklist: XEP-0191 implementation written for speed and independence from mod_privacy
Kim Alvefur <zash@zash.se>
parents:
diff changeset
    70
end
68b5c1ed18dd mod_blocklist: XEP-0191 implementation written for speed and independence from mod_privacy
Kim Alvefur <zash@zash.se>
parents:
diff changeset
    71
68b5c1ed18dd mod_blocklist: XEP-0191 implementation written for speed and independence from mod_privacy
Kim Alvefur <zash@zash.se>
parents:
diff changeset
    72
local function get_blocklist(username)
68b5c1ed18dd mod_blocklist: XEP-0191 implementation written for speed and independence from mod_privacy
Kim Alvefur <zash@zash.se>
parents:
diff changeset
    73
	local blocklist = cache[username];
68b5c1ed18dd mod_blocklist: XEP-0191 implementation written for speed and independence from mod_privacy
Kim Alvefur <zash@zash.se>
parents:
diff changeset
    74
	if not blocklist then
68b5c1ed18dd mod_blocklist: XEP-0191 implementation written for speed and independence from mod_privacy
Kim Alvefur <zash@zash.se>
parents:
diff changeset
    75
		if not user_exists(username, host) then
68b5c1ed18dd mod_blocklist: XEP-0191 implementation written for speed and independence from mod_privacy
Kim Alvefur <zash@zash.se>
parents:
diff changeset
    76
			return null_blocklist;
68b5c1ed18dd mod_blocklist: XEP-0191 implementation written for speed and independence from mod_privacy
Kim Alvefur <zash@zash.se>
parents:
diff changeset
    77
		end
68b5c1ed18dd mod_blocklist: XEP-0191 implementation written for speed and independence from mod_privacy
Kim Alvefur <zash@zash.se>
parents:
diff changeset
    78
		blocklist = storage:get(username);
68b5c1ed18dd mod_blocklist: XEP-0191 implementation written for speed and independence from mod_privacy
Kim Alvefur <zash@zash.se>
parents:
diff changeset
    79
		if not blocklist then
68b5c1ed18dd mod_blocklist: XEP-0191 implementation written for speed and independence from mod_privacy
Kim Alvefur <zash@zash.se>
parents:
diff changeset
    80
			blocklist = migrate_privacy_list(username);
68b5c1ed18dd mod_blocklist: XEP-0191 implementation written for speed and independence from mod_privacy
Kim Alvefur <zash@zash.se>
parents:
diff changeset
    81
		end
68b5c1ed18dd mod_blocklist: XEP-0191 implementation written for speed and independence from mod_privacy
Kim Alvefur <zash@zash.se>
parents:
diff changeset
    82
		cache[username] = blocklist;
68b5c1ed18dd mod_blocklist: XEP-0191 implementation written for speed and independence from mod_privacy
Kim Alvefur <zash@zash.se>
parents:
diff changeset
    83
	end
68b5c1ed18dd mod_blocklist: XEP-0191 implementation written for speed and independence from mod_privacy
Kim Alvefur <zash@zash.se>
parents:
diff changeset
    84
	return blocklist;
68b5c1ed18dd mod_blocklist: XEP-0191 implementation written for speed and independence from mod_privacy
Kim Alvefur <zash@zash.se>
parents:
diff changeset
    85
end
68b5c1ed18dd mod_blocklist: XEP-0191 implementation written for speed and independence from mod_privacy
Kim Alvefur <zash@zash.se>
parents:
diff changeset
    86
68b5c1ed18dd mod_blocklist: XEP-0191 implementation written for speed and independence from mod_privacy
Kim Alvefur <zash@zash.se>
parents:
diff changeset
    87
module:hook("iq-get/self/urn:xmpp:blocking:blocklist", function (event)
68b5c1ed18dd mod_blocklist: XEP-0191 implementation written for speed and independence from mod_privacy
Kim Alvefur <zash@zash.se>
parents:
diff changeset
    88
	local origin, stanza = event.origin, event.stanza;
68b5c1ed18dd mod_blocklist: XEP-0191 implementation written for speed and independence from mod_privacy
Kim Alvefur <zash@zash.se>
parents:
diff changeset
    89
	local username = origin.username;
68b5c1ed18dd mod_blocklist: XEP-0191 implementation written for speed and independence from mod_privacy
Kim Alvefur <zash@zash.se>
parents:
diff changeset
    90
	local reply = st.reply(stanza):tag("blocklist", { xmlns = "urn:xmpp:blocking" });
68b5c1ed18dd mod_blocklist: XEP-0191 implementation written for speed and independence from mod_privacy
Kim Alvefur <zash@zash.se>
parents:
diff changeset
    91
	local blocklist = get_blocklist(username);
68b5c1ed18dd mod_blocklist: XEP-0191 implementation written for speed and independence from mod_privacy
Kim Alvefur <zash@zash.se>
parents:
diff changeset
    92
	for jid in pairs(blocklist) do
68b5c1ed18dd mod_blocklist: XEP-0191 implementation written for speed and independence from mod_privacy
Kim Alvefur <zash@zash.se>
parents:
diff changeset
    93
		if jid then
68b5c1ed18dd mod_blocklist: XEP-0191 implementation written for speed and independence from mod_privacy
Kim Alvefur <zash@zash.se>
parents:
diff changeset
    94
			reply:tag("item", { jid = jid }):up();
68b5c1ed18dd mod_blocklist: XEP-0191 implementation written for speed and independence from mod_privacy
Kim Alvefur <zash@zash.se>
parents:
diff changeset
    95
		end
68b5c1ed18dd mod_blocklist: XEP-0191 implementation written for speed and independence from mod_privacy
Kim Alvefur <zash@zash.se>
parents:
diff changeset
    96
	end
68b5c1ed18dd mod_blocklist: XEP-0191 implementation written for speed and independence from mod_privacy
Kim Alvefur <zash@zash.se>
parents:
diff changeset
    97
	origin.interested_blocklist = true; -- Gets notified about changes
68b5c1ed18dd mod_blocklist: XEP-0191 implementation written for speed and independence from mod_privacy
Kim Alvefur <zash@zash.se>
parents:
diff changeset
    98
	return origin.send(reply);
68b5c1ed18dd mod_blocklist: XEP-0191 implementation written for speed and independence from mod_privacy
Kim Alvefur <zash@zash.se>
parents:
diff changeset
    99
end);
68b5c1ed18dd mod_blocklist: XEP-0191 implementation written for speed and independence from mod_privacy
Kim Alvefur <zash@zash.se>
parents:
diff changeset
   100
6351
10dc228a45a4 mod_blocklist: Correct comment
Kim Alvefur <zash@zash.se>
parents: 6350
diff changeset
   101
-- Add or remove some jid(s) from the blocklist
6344
68b5c1ed18dd mod_blocklist: XEP-0191 implementation written for speed and independence from mod_privacy
Kim Alvefur <zash@zash.se>
parents:
diff changeset
   102
-- We want this to be atomic and not do a partial update
68b5c1ed18dd mod_blocklist: XEP-0191 implementation written for speed and independence from mod_privacy
Kim Alvefur <zash@zash.se>
parents:
diff changeset
   103
local function edit_blocklist(event)
68b5c1ed18dd mod_blocklist: XEP-0191 implementation written for speed and independence from mod_privacy
Kim Alvefur <zash@zash.se>
parents:
diff changeset
   104
	local origin, stanza = event.origin, event.stanza;
68b5c1ed18dd mod_blocklist: XEP-0191 implementation written for speed and independence from mod_privacy
Kim Alvefur <zash@zash.se>
parents:
diff changeset
   105
	local username = origin.username;
6352
b703e6930e4c mod_blocklist: Use full word as variable name, we can afford that
Kim Alvefur <zash@zash.se>
parents: 6351
diff changeset
   106
	local action = stanza.tags[1];
6344
68b5c1ed18dd mod_blocklist: XEP-0191 implementation written for speed and independence from mod_privacy
Kim Alvefur <zash@zash.se>
parents:
diff changeset
   107
	local new = {};
68b5c1ed18dd mod_blocklist: XEP-0191 implementation written for speed and independence from mod_privacy
Kim Alvefur <zash@zash.se>
parents:
diff changeset
   108
68b5c1ed18dd mod_blocklist: XEP-0191 implementation written for speed and independence from mod_privacy
Kim Alvefur <zash@zash.se>
parents:
diff changeset
   109
	local jid;
6352
b703e6930e4c mod_blocklist: Use full word as variable name, we can afford that
Kim Alvefur <zash@zash.se>
parents: 6351
diff changeset
   110
	for item in action:childtags("item") do
6344
68b5c1ed18dd mod_blocklist: XEP-0191 implementation written for speed and independence from mod_privacy
Kim Alvefur <zash@zash.se>
parents:
diff changeset
   111
		jid = jid_prep(item.attr.jid);
68b5c1ed18dd mod_blocklist: XEP-0191 implementation written for speed and independence from mod_privacy
Kim Alvefur <zash@zash.se>
parents:
diff changeset
   112
		if not jid then
68b5c1ed18dd mod_blocklist: XEP-0191 implementation written for speed and independence from mod_privacy
Kim Alvefur <zash@zash.se>
parents:
diff changeset
   113
			return origin.send(st_error_reply(stanza, "modify", "jid-malformed"));
68b5c1ed18dd mod_blocklist: XEP-0191 implementation written for speed and independence from mod_privacy
Kim Alvefur <zash@zash.se>
parents:
diff changeset
   114
		end
68b5c1ed18dd mod_blocklist: XEP-0191 implementation written for speed and independence from mod_privacy
Kim Alvefur <zash@zash.se>
parents:
diff changeset
   115
		item.attr.jid = jid; -- echo back prepped
68b5c1ed18dd mod_blocklist: XEP-0191 implementation written for speed and independence from mod_privacy
Kim Alvefur <zash@zash.se>
parents:
diff changeset
   116
		new[jid] = is_contact_subscribed(username, host, jid) or false;
68b5c1ed18dd mod_blocklist: XEP-0191 implementation written for speed and independence from mod_privacy
Kim Alvefur <zash@zash.se>
parents:
diff changeset
   117
	end
68b5c1ed18dd mod_blocklist: XEP-0191 implementation written for speed and independence from mod_privacy
Kim Alvefur <zash@zash.se>
parents:
diff changeset
   118
6352
b703e6930e4c mod_blocklist: Use full word as variable name, we can afford that
Kim Alvefur <zash@zash.se>
parents: 6351
diff changeset
   119
	local mode = action.name == "block" or nil;
6344
68b5c1ed18dd mod_blocklist: XEP-0191 implementation written for speed and independence from mod_privacy
Kim Alvefur <zash@zash.se>
parents:
diff changeset
   120
68b5c1ed18dd mod_blocklist: XEP-0191 implementation written for speed and independence from mod_privacy
Kim Alvefur <zash@zash.se>
parents:
diff changeset
   121
	if mode and not next(new) then
68b5c1ed18dd mod_blocklist: XEP-0191 implementation written for speed and independence from mod_privacy
Kim Alvefur <zash@zash.se>
parents:
diff changeset
   122
		-- <block/> element does not contain at least one <item/> child element
68b5c1ed18dd mod_blocklist: XEP-0191 implementation written for speed and independence from mod_privacy
Kim Alvefur <zash@zash.se>
parents:
diff changeset
   123
		return origin.send(st_error_reply(stanza, "modify", "bad-request"));
68b5c1ed18dd mod_blocklist: XEP-0191 implementation written for speed and independence from mod_privacy
Kim Alvefur <zash@zash.se>
parents:
diff changeset
   124
	end
68b5c1ed18dd mod_blocklist: XEP-0191 implementation written for speed and independence from mod_privacy
Kim Alvefur <zash@zash.se>
parents:
diff changeset
   125
68b5c1ed18dd mod_blocklist: XEP-0191 implementation written for speed and independence from mod_privacy
Kim Alvefur <zash@zash.se>
parents:
diff changeset
   126
	local blocklist = get_blocklist(username);
68b5c1ed18dd mod_blocklist: XEP-0191 implementation written for speed and independence from mod_privacy
Kim Alvefur <zash@zash.se>
parents:
diff changeset
   127
68b5c1ed18dd mod_blocklist: XEP-0191 implementation written for speed and independence from mod_privacy
Kim Alvefur <zash@zash.se>
parents:
diff changeset
   128
	local new_blocklist = {};
68b5c1ed18dd mod_blocklist: XEP-0191 implementation written for speed and independence from mod_privacy
Kim Alvefur <zash@zash.se>
parents:
diff changeset
   129
6350
bba5f4ffe75a mod_blocklist: Fix any unblock emptying the blocklist
Kim Alvefur <zash@zash.se>
parents: 6344
diff changeset
   130
	if mode or next(new) then