mod_privacy/mod_privacy.lua
author Thilo Cestonaro <thilo@cestona.ro>
Mon, 28 Sep 2009 18:17:20 +0200
changeset 16 35e74c1094a7
parent 15 14b18ef8b554
child 17 ccb07c0efc7e
permissions -rw-r--r--
mod_privacy: order must be non-negativ integer and unique, group must be existing in the roster, subscription can only be to,from,both or none, action must be either deny or allow.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
8
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
     1
-- Prosody IM
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
     2
-- Copyright (C) 2008-2009 Matthew Wild
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
     3
-- Copyright (C) 2008-2009 Waqas Hussain
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
     4
-- Copyright (C) 2009 Thilo Cestonaro
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
     5
-- 
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
     6
-- This project is MIT/X11 licensed. Please see the
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
     7
-- COPYING file in the source package for more information.
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
     8
--
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
     9
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
    10
local prosody = prosody;
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
    11
local helpers = require "util/helpers";
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
    12
local st = require "util.stanza";
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
    13
local datamanager = require "util.datamanager";
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
    14
local bare_sessions = bare_sessions;
11
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
    15
local util_Jid = require "util.jid";
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
    16
local jid_bare = util_Jid.bare;
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
    17
local jid_split = util_Jid.split;
16
35e74c1094a7 mod_privacy: order must be non-negativ integer and unique, group must be existing in the roster, subscription can only be to,from,both or none, action must be either deny or allow.
Thilo Cestonaro <thilo@cestona.ro>
parents: 15
diff changeset
    18
local load_roster = require "core.rostermanager".load_roster;
35e74c1094a7 mod_privacy: order must be non-negativ integer and unique, group must be existing in the roster, subscription can only be to,from,both or none, action must be either deny or allow.
Thilo Cestonaro <thilo@cestona.ro>
parents: 15
diff changeset
    19
local to_number = _G.tonumber;
8
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
    20
10
7d70faba234c some error reporting during list editing
Thilo Cestonaro <thilo@cestona.ro>
parents: 8
diff changeset
    21
function findNamedList (privacy_lists, name)
8
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
    22
	local ret = nil
11
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
    23
	if privacy_lists.lists == nil then
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
    24
		module:log("debug", "no lists loaded.")
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
    25
		return nil;
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
    26
	end
8
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
    27
11
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
    28
	module:log("debug", "searching for list: %s", name);
8
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
    29
	for i=1, #privacy_lists.lists do
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
    30
		if privacy_lists.lists[i].name == name then
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
    31
			ret = i;
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
    32
			break;
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
    33
		end
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
    34
	end
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
    35
	return ret;
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
    36
end
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
    37
10
7d70faba234c some error reporting during list editing
Thilo Cestonaro <thilo@cestona.ro>
parents: 8
diff changeset
    38
function declineList (privacy_lists, origin, stanza, which)
8
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
    39
	module:log("info", "User requests to decline the use of privacy list: %s", which);
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
    40
	privacy_lists[which] = nil;
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
    41
	origin.send(st.reply(stanza));
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
    42
	return true;
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
    43
end
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
    44
10
7d70faba234c some error reporting during list editing
Thilo Cestonaro <thilo@cestona.ro>
parents: 8
diff changeset
    45
function activateList (privacy_lists, origin, stanza, which, name)
8
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
    46
	module:log("info", "User requests to change the privacy list: %s, to be list named %s", which, name);
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
    47
	local ret = false;
10
7d70faba234c some error reporting during list editing
Thilo Cestonaro <thilo@cestona.ro>
parents: 8
diff changeset
    48
	local idx = findNamedList(privacy_lists, name);
8
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
    49
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
    50
	if privacy_lists[which] == nil then
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
    51
		privacy_lists[which] = "";
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
    52
	end
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
    53
	
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
    54
	if privacy_lists[which] ~= name and idx ~= nil then
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
    55
		privacy_lists[which] = name;
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
    56
		origin.send(st.reply(stanza));
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
    57
		ret = true;
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
    58
	end
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
    59
	return ret;
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
    60
end
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
    61
10
7d70faba234c some error reporting during list editing
Thilo Cestonaro <thilo@cestona.ro>
parents: 8
diff changeset
    62
function deleteList (privacy_lists, origin, stanza, name)
8
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
    63
	module:log("info", "User requests to delete privacy list: %s", name);
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
    64
	local ret = false;
10
7d70faba234c some error reporting during list editing
Thilo Cestonaro <thilo@cestona.ro>
parents: 8
diff changeset
    65
	local idx = findNamedList(privacy_lists, name);
8
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
    66
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
    67
	if idx ~= nil then
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
    68
		table.remove(privacy_lists.lists, idx);
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
    69
		origin.send(st.reply(stanza));
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
    70
		ret = true;
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
    71
	end
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
    72
	return ret;
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
    73
end
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
    74
10
7d70faba234c some error reporting during list editing
Thilo Cestonaro <thilo@cestona.ro>
parents: 8
diff changeset
    75
local function sortByOrder(a, b)
7d70faba234c some error reporting during list editing
Thilo Cestonaro <thilo@cestona.ro>
parents: 8
diff changeset
    76
	if a.order < b.order then
7d70faba234c some error reporting during list editing
Thilo Cestonaro <thilo@cestona.ro>
parents: 8
diff changeset
    77
		return true;
7d70faba234c some error reporting during list editing
Thilo Cestonaro <thilo@cestona.ro>
parents: 8
diff changeset
    78
	end
7d70faba234c some error reporting during list editing
Thilo Cestonaro <thilo@cestona.ro>
parents: 8
diff changeset
    79
	return false;
7d70faba234c some error reporting during list editing
Thilo Cestonaro <thilo@cestona.ro>
parents: 8
diff changeset
    80
end
7d70faba234c some error reporting during list editing
Thilo Cestonaro <thilo@cestona.ro>
parents: 8
diff changeset
    81
16
35e74c1094a7 mod_privacy: order must be non-negativ integer and unique, group must be existing in the roster, subscription can only be to,from,both or none, action must be either deny or allow.
Thilo Cestonaro <thilo@cestona.ro>
parents: 15
diff changeset
    82
function createOrReplaceList (privacy_lists, origin, stanza, name, entries, roster)
8
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
    83
	module:log("info", "User requests to create / replace list named %s, item count: %d", name, #entries);
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
    84
	local ret = true;
10
7d70faba234c some error reporting during list editing
Thilo Cestonaro <thilo@cestona.ro>
parents: 8
diff changeset
    85
	local idx = findNamedList(privacy_lists, name);
8
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
    86
	local bare_jid = origin.username.."@"..origin.host;
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
    87
	
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
    88
	if privacy_lists.lists == nil then
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
    89
		privacy_lists.lists = {};
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
    90
	end
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
    91
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
    92
	if idx == nil then
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
    93
		idx = #privacy_lists.lists + 1;
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
    94
	end
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
    95
16
35e74c1094a7 mod_privacy: order must be non-negativ integer and unique, group must be existing in the roster, subscription can only be to,from,both or none, action must be either deny or allow.
Thilo Cestonaro <thilo@cestona.ro>
parents: 15
diff changeset
    96
	local orderCheck = {};
8
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
    97
	local list = {};
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
    98
	list.name = name;
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
    99
	list.items = {};
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   100
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   101
	for _,item in ipairs(entries) do
16
35e74c1094a7 mod_privacy: order must be non-negativ integer and unique, group must be existing in the roster, subscription can only be to,from,both or none, action must be either deny or allow.
Thilo Cestonaro <thilo@cestona.ro>
parents: 15
diff changeset
   102
		if to_number(item.attr.order) == nil or to_number(item.attr.order) < 0 or orderCheck[item.attr.order] ~= nil then
35e74c1094a7 mod_privacy: order must be non-negativ integer and unique, group must be existing in the roster, subscription can only be to,from,both or none, action must be either deny or allow.
Thilo Cestonaro <thilo@cestona.ro>
parents: 15
diff changeset
   103
			return "bad-request";
35e74c1094a7 mod_privacy: order must be non-negativ integer and unique, group must be existing in the roster, subscription can only be to,from,both or none, action must be either deny or allow.
Thilo Cestonaro <thilo@cestona.ro>
parents: 15
diff changeset
   104
		end
14
0892941186f2 mod_privacy: Make tmp variable a local
Matthew Wild <mwild1@gmail.com>
parents: 10
diff changeset
   105
		local tmp = {};
16
35e74c1094a7 mod_privacy: order must be non-negativ integer and unique, group must be existing in the roster, subscription can only be to,from,both or none, action must be either deny or allow.
Thilo Cestonaro <thilo@cestona.ro>
parents: 15
diff changeset
   106
		orderCheck[item.attr.order] = true;
35e74c1094a7 mod_privacy: order must be non-negativ integer and unique, group must be existing in the roster, subscription can only be to,from,both or none, action must be either deny or allow.
Thilo Cestonaro <thilo@cestona.ro>
parents: 15
diff changeset
   107
		
8
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   108
		tmp["type"] = item.attr.type;
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   109
		tmp["value"] = item.attr.value;
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   110
		tmp["action"] = item.attr.action;
16
35e74c1094a7 mod_privacy: order must be non-negativ integer and unique, group must be existing in the roster, subscription can only be to,from,both or none, action must be either deny or allow.
Thilo Cestonaro <thilo@cestona.ro>
parents: 15
diff changeset
   111
		tmp["order"] = to_number(item.attr.order);
8
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   112
		tmp["presence-in"] = false;
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   113
		tmp["presence-out"] = false;
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   114
		tmp["message"] = false;
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   115
		tmp["iq"] = false;
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   116
		
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   117
		if #item.tags > 0 then
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   118
			for _,tag in ipairs(item.tags) do
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   119
				tmp[tag.name] = true;
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   120
			end
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   121
		end
16
35e74c1094a7 mod_privacy: order must be non-negativ integer and unique, group must be existing in the roster, subscription can only be to,from,both or none, action must be either deny or allow.
Thilo Cestonaro <thilo@cestona.ro>
parents: 15
diff changeset
   122
		
35e74c1094a7 mod_privacy: order must be non-negativ integer and unique, group must be existing in the roster, subscription can only be to,from,both or none, action must be either deny or allow.
Thilo Cestonaro <thilo@cestona.ro>
parents: 15
diff changeset
   123
		if tmp.type == "group" then
35e74c1094a7 mod_privacy: order must be non-negativ integer and unique, group must be existing in the roster, subscription can only be to,from,both or none, action must be either deny or allow.
Thilo Cestonaro <thilo@cestona.ro>
parents: 15
diff changeset
   124
			local found = false;
35e74c1094a7 mod_privacy: order must be non-negativ integer and unique, group must be existing in the roster, subscription can only be to,from,both or none, action must be either deny or allow.
Thilo Cestonaro <thilo@cestona.ro>
parents: 15
diff changeset
   125
			local roster = load_roster(origin.username, origin.host);
35e74c1094a7 mod_privacy: order must be non-negativ integer and unique, group must be existing in the roster, subscription can only be to,from,both or none, action must be either deny or allow.
Thilo Cestonaro <thilo@cestona.ro>
parents: 15
diff changeset
   126
			local groups = roster.groups;
35e74c1094a7 mod_privacy: order must be non-negativ integer and unique, group must be existing in the roster, subscription can only be to,from,both or none, action must be either deny or allow.
Thilo Cestonaro <thilo@cestona.ro>
parents: 15
diff changeset
   127
			if groups == nil then
35e74c1094a7 mod_privacy: order must be non-negativ integer and unique, group must be existing in the roster, subscription can only be to,from,both or none, action must be either deny or allow.
Thilo Cestonaro <thilo@cestona.ro>
parents: 15
diff changeset
   128
				return "item-not-found";
35e74c1094a7 mod_privacy: order must be non-negativ integer and unique, group must be existing in the roster, subscription can only be to,from,both or none, action must be either deny or allow.
Thilo Cestonaro <thilo@cestona.ro>
parents: 15
diff changeset
   129
			end
35e74c1094a7 mod_privacy: order must be non-negativ integer and unique, group must be existing in the roster, subscription can only be to,from,both or none, action must be either deny or allow.
Thilo Cestonaro <thilo@cestona.ro>
parents: 15
diff changeset
   130
			for _,group in ipairs(groups) do
35e74c1094a7 mod_privacy: order must be non-negativ integer and unique, group must be existing in the roster, subscription can only be to,from,both or none, action must be either deny or allow.
Thilo Cestonaro <thilo@cestona.ro>
parents: 15
diff changeset
   131
				if group == tmp.value then
35e74c1094a7 mod_privacy: order must be non-negativ integer and unique, group must be existing in the roster, subscription can only be to,from,both or none, action must be either deny or allow.
Thilo Cestonaro <thilo@cestona.ro>
parents: 15
diff changeset
   132
					found = true;
35e74c1094a7 mod_privacy: order must be non-negativ integer and unique, group must be existing in the roster, subscription can only be to,from,both or none, action must be either deny or allow.
Thilo Cestonaro <thilo@cestona.ro>
parents: 15
diff changeset
   133
				end
35e74c1094a7 mod_privacy: order must be non-negativ integer and unique, group must be existing in the roster, subscription can only be to,from,both or none, action must be either deny or allow.
Thilo Cestonaro <thilo@cestona.ro>
parents: 15
diff changeset
   134
			end
35e74c1094a7 mod_privacy: order must be non-negativ integer and unique, group must be existing in the roster, subscription can only be to,from,both or none, action must be either deny or allow.
Thilo Cestonaro <thilo@cestona.ro>
parents: 15
diff changeset
   135
			if found == false then
35e74c1094a7 mod_privacy: order must be non-negativ integer and unique, group must be existing in the roster, subscription can only be to,from,both or none, action must be either deny or allow.
Thilo Cestonaro <thilo@cestona.ro>
parents: 15
diff changeset
   136
				return "item-not-found";
35e74c1094a7 mod_privacy: order must be non-negativ integer and unique, group must be existing in the roster, subscription can only be to,from,both or none, action must be either deny or allow.
Thilo Cestonaro <thilo@cestona.ro>
parents: 15
diff changeset
   137
			end
35e74c1094a7 mod_privacy: order must be non-negativ integer and unique, group must be existing in the roster, subscription can only be to,from,both or none, action must be either deny or allow.
Thilo Cestonaro <thilo@cestona.ro>
parents: 15
diff changeset
   138
		elseif tmp.type == "subscription" then
35e74c1094a7 mod_privacy: order must be non-negativ integer and unique, group must be existing in the roster, subscription can only be to,from,both or none, action must be either deny or allow.
Thilo Cestonaro <thilo@cestona.ro>
parents: 15
diff changeset
   139
			if	tmp.value ~= "both" and
35e74c1094a7 mod_privacy: order must be non-negativ integer and unique, group must be existing in the roster, subscription can only be to,from,both or none, action must be either deny or allow.
Thilo Cestonaro <thilo@cestona.ro>
parents: 15
diff changeset
   140
				tmp.value ~= "to" and
35e74c1094a7 mod_privacy: order must be non-negativ integer and unique, group must be existing in the roster, subscription can only be to,from,both or none, action must be either deny or allow.
Thilo Cestonaro <thilo@cestona.ro>
parents: 15
diff changeset
   141
				tmp.value ~= "from" and
35e74c1094a7 mod_privacy: order must be non-negativ integer and unique, group must be existing in the roster, subscription can only be to,from,both or none, action must be either deny or allow.
Thilo Cestonaro <thilo@cestona.ro>
parents: 15
diff changeset
   142
				tmp.value ~= "none" then
35e74c1094a7 mod_privacy: order must be non-negativ integer and unique, group must be existing in the roster, subscription can only be to,from,both or none, action must be either deny or allow.
Thilo Cestonaro <thilo@cestona.ro>
parents: 15
diff changeset
   143
				return "bad-request";
35e74c1094a7 mod_privacy: order must be non-negativ integer and unique, group must be existing in the roster, subscription can only be to,from,both or none, action must be either deny or allow.
Thilo Cestonaro <thilo@cestona.ro>
parents: 15
diff changeset
   144
			end
35e74c1094a7 mod_privacy: order must be non-negativ integer and unique, group must be existing in the roster, subscription can only be to,from,both or none, action must be either deny or allow.
Thilo Cestonaro <thilo@cestona.ro>
parents: 15
diff changeset
   145
		end
35e74c1094a7 mod_privacy: order must be non-negativ integer and unique, group must be existing in the roster, subscription can only be to,from,both or none, action must be either deny or allow.
Thilo Cestonaro <thilo@cestona.ro>
parents: 15
diff changeset
   146
		
35e74c1094a7 mod_privacy: order must be non-negativ integer and unique, group must be existing in the roster, subscription can only be to,from,both or none, action must be either deny or allow.
Thilo Cestonaro <thilo@cestona.ro>
parents: 15
diff changeset
   147
		if tmp.action ~= "deny" and tmp.action ~= "allow" then
35e74c1094a7 mod_privacy: order must be non-negativ integer and unique, group must be existing in the roster, subscription can only be to,from,both or none, action must be either deny or allow.
Thilo Cestonaro <thilo@cestona.ro>
parents: 15
diff changeset
   148
			return "bad-request";
35e74c1094a7 mod_privacy: order must be non-negativ integer and unique, group must be existing in the roster, subscription can only be to,from,both or none, action must be either deny or allow.
Thilo Cestonaro <thilo@cestona.ro>
parents: 15
diff changeset
   149
		end
35e74c1094a7 mod_privacy: order must be non-negativ integer and unique, group must be existing in the roster, subscription can only be to,from,both or none, action must be either deny or allow.
Thilo Cestonaro <thilo@cestona.ro>
parents: 15
diff changeset
   150
		
8
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   151
		list.items[#list.items + 1] = tmp;
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   152
	end
10
7d70faba234c some error reporting during list editing
Thilo Cestonaro <thilo@cestona.ro>
parents: 8
diff changeset
   153
	
7d70faba234c some error reporting during list editing
Thilo Cestonaro <thilo@cestona.ro>
parents: 8
diff changeset
   154
	table.sort(list, sortByOrder);
8
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   155
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   156
	privacy_lists.lists[idx] = list;
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   157
	origin.send(st.reply(stanza));
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   158
	if bare_sessions[bare_jid] ~= nil then
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   159
		iq = st.iq ( { type = "set", id="push1" } );
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   160
		iq:tag ("query", { xmlns = "jabber:iq:privacy" } );
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   161
		iq:tag ("list", { name = list.name } ):up();
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   162
		iq:up();
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   163
		for resource, session in pairs(bare_sessions[bare_jid].sessions) do
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   164
			iq.attr.to = bare_jid.."/"..resource
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   165
			session.send(iq);
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   166
		end
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   167
	end
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   168
	return true;
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   169
end
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   170
10
7d70faba234c some error reporting during list editing
Thilo Cestonaro <thilo@cestona.ro>
parents: 8
diff changeset
   171
function getList(privacy_lists, origin, stanza, name)
8
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   172
	module:log("info", "User requests list named: %s", name or "nil");
10
7d70faba234c some error reporting during list editing
Thilo Cestonaro <thilo@cestona.ro>
parents: 8
diff changeset
   173
	local ret = false;
8
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   174
	local reply = st.reply(stanza);
10
7d70faba234c some error reporting during list editing
Thilo Cestonaro <thilo@cestona.ro>
parents: 8
diff changeset
   175
	reply:tag("query", {xmlns="jabber:iq:privacy"});
8
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   176
10
7d70faba234c some error reporting during list editing
Thilo Cestonaro <thilo@cestona.ro>
parents: 8
diff changeset
   177
	if name == nil then
8
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   178
		reply:tag("active", {name=privacy_lists.active or ""}):up();
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   179
		reply:tag("default", {name=privacy_lists.default or ""}):up();
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   180
		if privacy_lists.lists then
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   181
			for _,list in ipairs(privacy_lists.lists) do
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   182
				reply:tag("list", {name=list.name}):up();
10
7d70faba234c some error reporting during list editing
Thilo Cestonaro <thilo@cestona.ro>
parents: 8
diff changeset
   183
			end
7d70faba234c some error reporting during list editing
Thilo Cestonaro <thilo@cestona.ro>
parents: 8
diff changeset
   184
			ret = true;	
8
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   185
		end
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   186
	else
10
7d70faba234c some error reporting during list editing
Thilo Cestonaro <thilo@cestona.ro>
parents: 8
diff changeset
   187
		local idx = findNamedList(privacy_lists, name);
11
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
   188
		module:log("debug", "list idx: %d", idx or -1);
10
7d70faba234c some error reporting during list editing
Thilo Cestonaro <thilo@cestona.ro>
parents: 8
diff changeset
   189
		if idx ~= nil then
7d70faba234c some error reporting during list editing
Thilo Cestonaro <thilo@cestona.ro>
parents: 8
diff changeset
   190
			list = privacy_lists.lists[idx];
7d70faba234c some error reporting during list editing
Thilo Cestonaro <thilo@cestona.ro>
parents: 8
diff changeset
   191
			reply = reply:tag("list", {name=list.name});
7d70faba234c some error reporting during list editing
Thilo Cestonaro <thilo@cestona.ro>
parents: 8
diff changeset
   192
			for _,item in ipairs(list.items) do
7d70faba234c some error reporting during list editing
Thilo Cestonaro <thilo@cestona.ro>
parents: 8
diff changeset
   193
				reply:tag("item", {type=item.type, value=item.value, action=item.action, order=item.order});
7d70faba234c some error reporting during list editing
Thilo Cestonaro <thilo@cestona.ro>
parents: 8
diff changeset
   194
				if item["message"] then reply:tag("message"):up(); end
7d70faba234c some error reporting during list editing
Thilo Cestonaro <thilo@cestona.ro>
parents: 8
diff changeset
   195
				if item["iq"] then reply:tag("iq"):up(); end
7d70faba234c some error reporting during list editing
Thilo Cestonaro <thilo@cestona.ro>
parents: 8
diff changeset
   196
				if item["presence-in"] then reply:tag("presence-in"):up(); end
7d70faba234c some error reporting during list editing
Thilo Cestonaro <thilo@cestona.ro>
parents: 8
diff changeset
   197
				if item["presence-out"] then reply:tag("presence-out"):up(); end
7d70faba234c some error reporting during list editing
Thilo Cestonaro <thilo@cestona.ro>
parents: 8
diff changeset
   198
				reply:up();
7d70faba234c some error reporting during list editing
Thilo Cestonaro <thilo@cestona.ro>
parents: 8
diff changeset
   199
			end
7d70faba234c some error reporting during list editing
Thilo Cestonaro <thilo@cestona.ro>
parents: 8
diff changeset
   200
			ret = true;
8
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   201
		end
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   202
	end
10
7d70faba234c some error reporting during list editing
Thilo Cestonaro <thilo@cestona.ro>
parents: 8
diff changeset
   203
7d70faba234c some error reporting during list editing
Thilo Cestonaro <thilo@cestona.ro>
parents: 8
diff changeset
   204
	if ret then
7d70faba234c some error reporting during list editing
Thilo Cestonaro <thilo@cestona.ro>
parents: 8
diff changeset
   205
		origin.send(reply);
7d70faba234c some error reporting during list editing
Thilo Cestonaro <thilo@cestona.ro>
parents: 8
diff changeset
   206
	end
8
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   207
	return ret;
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   208
end
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   209
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   210
--          "[tagname]/[target-type]/[payload-namespace]:[payload-tagname]"
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   211
module:hook("iq/bare/jabber:iq:privacy:query", function(data)
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   212
	local origin, stanza = data.origin, data.stanza;
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   213
	
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   214
	if stanza.attr.to == nil then -- only service requests to own bare JID
10
7d70faba234c some error reporting during list editing
Thilo Cestonaro <thilo@cestona.ro>
parents: 8
diff changeset
   215
		local err_reply = nil;
8
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   216
		local query = stanza.tags[1]; -- the query element
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   217
		local valid = false;
10
7d70faba234c some error reporting during list editing
Thilo Cestonaro <thilo@cestona.ro>
parents: 8
diff changeset
   218
		local privacy_lists = datamanager.load(origin.username, origin.host, "privacy") or {};
8
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   219
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   220
		if stanza.attr.type == "set" then
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   221
			if #query.tags >= 1 then
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   222
				for _,tag in ipairs(query.tags) do
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   223
					if tag.name == "active" or tag.name == "default" then
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   224
						if tag.attr.name == nil then -- Client declines the use of active / default list
10
7d70faba234c some error reporting during list editing
Thilo Cestonaro <thilo@cestona.ro>
parents: 8
diff changeset
   225
							valid = declineList(privacy_lists, origin, stanza, tag.name);
8
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   226
						else -- Client requests change of active / default list
10
7d70faba234c some error reporting during list editing
Thilo Cestonaro <thilo@cestona.ro>
parents: 8
diff changeset
   227
							valid = activateList(privacy_lists, origin, stanza, tag.name, tag.attr.name);
7d70faba234c some error reporting during list editing
Thilo Cestonaro <thilo@cestona.ro>
parents: 8
diff changeset
   228
							err_reply = st.error_reply(stanza, "cancel", "item-not-found");
8
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   229
						end
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   230
					elseif tag.name == "list" and tag.attr.name then -- Client adds / edits a privacy list
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   231
						if #tag.tags == 0 then -- Client removes a privacy list
10
7d70faba234c some error reporting during list editing
Thilo Cestonaro <thilo@cestona.ro>
parents: 8
diff changeset
   232
							valid = deleteList(privacy_lists, origin, stanza, tag.attr.name);
8
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   233
						else -- Client edits a privacy list
10
7d70faba234c some error reporting during list editing
Thilo Cestonaro <thilo@cestona.ro>
parents: 8
diff changeset
   234
							valid = createOrReplaceList(privacy_lists, origin, stanza, tag.attr.name, tag.tags)
16
35e74c1094a7 mod_privacy: order must be non-negativ integer and unique, group must be existing in the roster, subscription can only be to,from,both or none, action must be either deny or allow.
Thilo Cestonaro <thilo@cestona.ro>
parents: 15
diff changeset
   235
							if valid ~= true then
35e74c1094a7 mod_privacy: order must be non-negativ integer and unique, group must be existing in the roster, subscription can only be to,from,both or none, action must be either deny or allow.
Thilo Cestonaro <thilo@cestona.ro>
parents: 15
diff changeset
   236
								err_reply = st.error_reply(stanza, "cancel", valid);
35e74c1094a7 mod_privacy: order must be non-negativ integer and unique, group must be existing in the roster, subscription can only be to,from,both or none, action must be either deny or allow.
Thilo Cestonaro <thilo@cestona.ro>
parents: 15
diff changeset
   237
								valid = false;
35e74c1094a7 mod_privacy: order must be non-negativ integer and unique, group must be existing in the roster, subscription can only be to,from,both or none, action must be either deny or allow.
Thilo Cestonaro <thilo@cestona.ro>
parents: 15
diff changeset
   238
							end
8
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   239
						end
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   240
					end
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   241
				end
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   242
			end
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   243
		elseif stanza.attr.type == "get" then
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   244
			local name = nil;
10
7d70faba234c some error reporting during list editing
Thilo Cestonaro <thilo@cestona.ro>
parents: 8
diff changeset
   245
			local listsToRetrieve = 0;
8
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   246
			if #query.tags >= 1 then
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   247
				for _,tag in ipairs(query.tags) do
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   248
					if tag.name == "list" then -- Client requests a privacy list from server
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   249
						name = tag.attr.name;
10
7d70faba234c some error reporting during list editing
Thilo Cestonaro <thilo@cestona.ro>
parents: 8
diff changeset
   250
						listsToRetrieve = listsToRetrieve + 1;
8
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   251
					end
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   252
				end
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   253
			end
10
7d70faba234c some error reporting during list editing
Thilo Cestonaro <thilo@cestona.ro>
parents: 8
diff changeset
   254
			if listsToRetrieve == 0 or listsToRetrieve == 1 then
7d70faba234c some error reporting during list editing
Thilo Cestonaro <thilo@cestona.ro>
parents: 8
diff changeset
   255
				valid = getList(privacy_lists, origin, stanza, name);
7d70faba234c some error reporting during list editing
Thilo Cestonaro <thilo@cestona.ro>
parents: 8
diff changeset
   256
				err_reply = st.error_reply(stanza, "cancel", "item-not-found");
7d70faba234c some error reporting during list editing
Thilo Cestonaro <thilo@cestona.ro>
parents: 8
diff changeset
   257
			end
8
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   258
		end
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   259
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   260
		if valid == false then
10
7d70faba234c some error reporting during list editing
Thilo Cestonaro <thilo@cestona.ro>
parents: 8
diff changeset
   261
			if err_reply == nil then
7d70faba234c some error reporting during list editing
Thilo Cestonaro <thilo@cestona.ro>
parents: 8
diff changeset
   262
				err_reply = st.error_reply(stanza, "modify", "bad-request");
7d70faba234c some error reporting during list editing
Thilo Cestonaro <thilo@cestona.ro>
parents: 8
diff changeset
   263
			end
7d70faba234c some error reporting during list editing
Thilo Cestonaro <thilo@cestona.ro>
parents: 8
diff changeset
   264
			origin.send(err_reply);
8
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   265
		else
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   266
			datamanager.store(origin.username, origin.host, "privacy", privacy_lists);
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   267
		end
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   268
		return true;
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   269
	end
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   270
	return false;
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   271
end, 500);
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   272
11
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
   273
function checkIfNeedToBeBlocked(e, node_, host_)
10
7d70faba234c some error reporting during list editing
Thilo Cestonaro <thilo@cestona.ro>
parents: 8
diff changeset
   274
	local origin, stanza = e.origin, e.stanza;
11
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
   275
	local privacy_lists = datamanager.load(node_, host_, "privacy") or {};
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
   276
	local bare_jid = node_.."@"..host_;
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
   277
	
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
   278
	module:log("debug", "checkIfNeedToBeBlocked: username: %s, host: %s", node_, host_);
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
   279
	module:log("debug", "stanza: %s, to: %s, form: %s", stanza.name, stanza.attr.to or "nil", stanza.attr.from or "nil");
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
   280
	
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
   281
	if privacy_lists.lists ~= nil and stanza.attr.to ~= nil and stanza.attr.from ~= nil then
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
   282
		if privacy_lists.active == nil and privacy_lists.default == nil then 
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
   283
			return; -- Nothing to block, default is Allow all
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
   284
		end
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
   285
	
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
   286
		local idx;
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
   287
		local list;
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
   288
		local item;
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
   289
		local block = false;
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
   290
		local apply = false;
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
   291
		local listname = privacy_lists.active;
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
   292
		if listname == nil then
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
   293
			listname = privacy_lists.default; -- no active list selected, use default list
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
   294
		end
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
   295
		idx = findNamedList(privacy_lists, listname);
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
   296
		if idx == nil then
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
   297
			module:log("info", "given privacy listname not found.");
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
   298
			return;
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
   299
		end
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
   300
		list = privacy_lists.lists[idx];
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
   301
		if list == nil then
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
   302
			module:log("info", "privacy list index wrong.");
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
   303
			return;
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
   304
		end
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
   305
		for _,item in ipairs(list.items) do
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
   306
			local apply = false;
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
   307
			block = false;
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
   308
			if	(stanza.name == "message" and item.message) or
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
   309
				(stanza.name == "iq" and item.iq) or
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
   310
				(stanza.name == "presence" and jid_bare(stanza.attr.to) == bare_jid and item["presence-in"]) or
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
   311
				(stanza.name == "presence" and jid_bare(stanza.attr.from) == bare_jid and item["presence-out"]) or
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
   312
				(item.message == false and item.iq == false and item["presence-in"] == false and item["presence-in"] == false) then
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
   313
				module:log("debug", "stanza type matched.");
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
   314
					apply = true;
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
   315
			end
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
   316
			if apply then
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
   317
				local evilJid = {};
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
   318
				apply = false;
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
   319
				if jid_bare(stanza.attr.to) == bare_jid then
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
   320
					evilJid.node, evilJid.host, evilJid.resource = jid_split(stanza.attr.from);
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
   321
				else
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
   322
					evilJid.node, evilJid.host, evilJid.resource = jid_split(stanza.attr.to);
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
   323
				end
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
   324
				if	item.type == "jid" and 
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
   325
					(evilJid.node and evilJid.host and evilJid.resource and item.value == evilJid.node.."@"..evilJid.host.."/"..evilJid.resource) or
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
   326
					(evilJid.node and evilJid.host and item.value == evilJid.node.."@"..evilJid.host) or
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
   327
					(evilJid.host and evilJid.resource and item.value == evilJid.host.."/"..evilJid.resource) or
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
   328
					(evilJid.host and item.value == evilJid.host) then
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
   329
					module:log("debug", "jid matched.");
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
   330
					apply = true;
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
   331
					block = (item.action == "deny");
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
   332
				elseif item.type == "group" then
16
35e74c1094a7 mod_privacy: order must be non-negativ integer and unique, group must be existing in the roster, subscription can only be to,from,both or none, action must be either deny or allow.
Thilo Cestonaro <thilo@cestona.ro>
parents: 15
diff changeset
   333
					local roster = load_roster(node_, host_);
35e74c1094a7 mod_privacy: order must be non-negativ integer and unique, group must be existing in the roster, subscription can only be to,from,both or none, action must be either deny or allow.
Thilo Cestonaro <thilo@cestona.ro>
parents: 15
diff changeset
   334
					local groups = roster.groups;
11
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
   335
					for _,group in ipairs(groups) do
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
   336
						if group == item.value then
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
   337
							module:log("debug", "group matched.");
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
   338
							apply = true;
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
   339
							block = (item.action == "deny");
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
   340
							break;
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
   341
						end
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
   342
					end
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
   343
				elseif item.type == "subscription" then
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
   344
					if origin.roster[jid_bare(stanza.from)].subscription == item.value then
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
   345
						module:log("debug", "subscription matched.");
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
   346
						apply = true;
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
   347
						block = (item.action == "deny");
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
   348
					end
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
   349
				elseif item.type == nil then
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
   350
					module:log("debug", "no item.type, so matched.");
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
   351
					apply = true;
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
   352
					block = (item.action == "deny");
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
   353
				end
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
   354
			end
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
   355
			if apply then
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
   356
				if block then
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
   357
					module:log("info", "stanza blocked: %s, to: %s, from: %s", stanza.name, stanza.attr.to or "nil", stanza.attr.from or "nil");
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
   358
					if stanza.name == "message" then
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
   359
						origin.send(st.error_reply(stanza, "cancel", "service-unavailable"));
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
   360
					elseif stanza.name == "iq" and (stanza.attr.type == "get" or stanza.attr.type == "set") then
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
   361
						origin.send(st.error_reply(stanza, "cancel", "service-unavailable"));
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
   362
					end
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
   363
					return true; -- stanza blocked !
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
   364
				else
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
   365
					module:log("info", "stanza explicit allowed!")
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
   366
				end
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
   367
			end
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
   368
		end
10
7d70faba234c some error reporting during list editing
Thilo Cestonaro <thilo@cestona.ro>
parents: 8
diff changeset
   369
	end
11
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
   370
	return;
8
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   371
end
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   372
11
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
   373
function preCheckIncoming(e)
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
   374
	if e.stanza.attr.to ~= nil then
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
   375
		local node, host, resource = jid_split(e.stanza.attr.to);
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
   376
		if node == nil or host == nil then
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
   377
			return;
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
   378
		end
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
   379
		return checkIfNeedToBeBlocked(e, node, host);
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
   380
	end
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
   381
	return;
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
   382
end
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
   383
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
   384
function preCheckOutgoing(e)
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
   385
	if e.stanza.attr.from ~= nil then
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
   386
		local node, host, resource = jid_split(e.stanza.attr.from);
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
   387
		if node == nil or host == nil then
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
   388
			return;
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
   389
		end
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
   390
		return checkIfNeedToBeBlocked(e, node, host);
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
   391
	end
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
   392
	return;
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
   393
end
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
   394
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
   395
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
   396
module:hook("pre-message/full", preCheckOutgoing, 500);
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
   397
module:hook("pre-message/bare", preCheckOutgoing, 500);
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
   398
module:hook("pre-message/host", preCheckOutgoing, 500);
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
   399
module:hook("pre-iq/full", preCheckOutgoing, 500);
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
   400
module:hook("pre-iq/bare", preCheckOutgoing, 500);
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
   401
module:hook("pre-iq/host", preCheckOutgoing, 500);
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
   402
module:hook("pre-presence/full", preCheckOutgoing, 500);
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
   403
module:hook("pre-presence/bare", preCheckOutgoing, 500);
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
   404
module:hook("pre-presence/host", preCheckOutgoing, 500);
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
   405
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
   406
module:hook("message/full", preCheckIncoming, 500);
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
   407
module:hook("message/bare", preCheckIncoming, 500);
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
   408
module:hook("message/host", preCheckIncoming, 500);
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
   409
module:hook("iq/full", preCheckIncoming, 500);
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
   410
module:hook("iq/bare", preCheckIncoming, 500);
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
   411
module:hook("iq/host", preCheckIncoming, 500);
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
   412
module:hook("presence/full", preCheckIncoming, 500);
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
   413
module:hook("presence/bare", preCheckIncoming, 500);
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
   414
module:hook("presence/host", preCheckIncoming, 500);
8
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   415
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   416
-- helpers.log_events(hosts["albastru.de"].events, "albastru.de");
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   417
-- helpers.log_events(prosody.events, "*");
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   418
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
   419
module:log("info", "mod_privacy loaded ...");