annotate mod_privacy/mod_privacy.lua @ 19:e400ee8471b0

mod_privacy: removed trunk dependency; make it work when no lists already are exiting
author Thilo Cestonaro <thilo@cestona.ro>
date Tue, 29 Sep 2009 12:59:42 +0200
parents 2df11ec081fe
children 2675dc25445b
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
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 st = require "util.stanza";
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
12 local datamanager = require "util.datamanager";
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
13 local bare_sessions = bare_sessions;
11
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
14 local util_Jid = require "util.jid";
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
15 local jid_bare = util_Jid.bare;
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
16 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
17 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
18 local to_number = _G.tonumber;
8
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
19
10
7d70faba234c some error reporting during list editing
Thilo Cestonaro <thilo@cestona.ro>
parents: 8
diff changeset
20 function findNamedList (privacy_lists, name)
8
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
21 local ret = nil
11
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
22 if privacy_lists.lists == nil then
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
23 module:log("debug", "no lists loaded.")
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
24 return nil;
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
25 end
8
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
26
11
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
27 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
28 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
29 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
30 ret = i;
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
31 break;
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
32 end
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 return ret;
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
35 end
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
36
10
7d70faba234c some error reporting during list editing
Thilo Cestonaro <thilo@cestona.ro>
parents: 8
diff changeset
37 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
38 module:log("info", "User requests to decline the use of privacy list: %s", which);
17
ccb07c0efc7e mod_privacy: prepare everything for the "is used" checking stuff...
Thilo Cestonaro <thilo@cestona.ro>
parents: 16
diff changeset
39 if which == "default" then
ccb07c0efc7e mod_privacy: prepare everything for the "is used" checking stuff...
Thilo Cestonaro <thilo@cestona.ro>
parents: 16
diff changeset
40 privacy_lists.default = nil; -- TODO check if used!
ccb07c0efc7e mod_privacy: prepare everything for the "is used" checking stuff...
Thilo Cestonaro <thilo@cestona.ro>
parents: 16
diff changeset
41 elseif which == "active" then
ccb07c0efc7e mod_privacy: prepare everything for the "is used" checking stuff...
Thilo Cestonaro <thilo@cestona.ro>
parents: 16
diff changeset
42 origin.activePrivacyList = nil;
ccb07c0efc7e mod_privacy: prepare everything for the "is used" checking stuff...
Thilo Cestonaro <thilo@cestona.ro>
parents: 16
diff changeset
43 end
8
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
44 origin.send(st.reply(stanza));
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
45 return true;
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
46 end
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
47
10
7d70faba234c some error reporting during list editing
Thilo Cestonaro <thilo@cestona.ro>
parents: 8
diff changeset
48 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
49 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
50 local ret = false;
10
7d70faba234c some error reporting during list editing
Thilo Cestonaro <thilo@cestona.ro>
parents: 8
diff changeset
51 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
52
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
53 if privacy_lists[which] == nil then
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
54 privacy_lists[which] = "";
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
55 end
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
56
17
ccb07c0efc7e mod_privacy: prepare everything for the "is used" checking stuff...
Thilo Cestonaro <thilo@cestona.ro>
parents: 16
diff changeset
57 if which == "default" and privacy_lists.default ~= name and idx ~= nil then
ccb07c0efc7e mod_privacy: prepare everything for the "is used" checking stuff...
Thilo Cestonaro <thilo@cestona.ro>
parents: 16
diff changeset
58 privacy_lists.default = name; -- TODO check if used!
ccb07c0efc7e mod_privacy: prepare everything for the "is used" checking stuff...
Thilo Cestonaro <thilo@cestona.ro>
parents: 16
diff changeset
59 ret = true;
ccb07c0efc7e mod_privacy: prepare everything for the "is used" checking stuff...
Thilo Cestonaro <thilo@cestona.ro>
parents: 16
diff changeset
60 elseif which == "active" and origin.activePrivacyList ~= name and idx ~= nil then
ccb07c0efc7e mod_privacy: prepare everything for the "is used" checking stuff...
Thilo Cestonaro <thilo@cestona.ro>
parents: 16
diff changeset
61 origin.activePrivacyList = name;
ccb07c0efc7e mod_privacy: prepare everything for the "is used" checking stuff...
Thilo Cestonaro <thilo@cestona.ro>
parents: 16
diff changeset
62 ret = true;
ccb07c0efc7e mod_privacy: prepare everything for the "is used" checking stuff...
Thilo Cestonaro <thilo@cestona.ro>
parents: 16
diff changeset
63 end
ccb07c0efc7e mod_privacy: prepare everything for the "is used" checking stuff...
Thilo Cestonaro <thilo@cestona.ro>
parents: 16
diff changeset
64 if ret == true then
8
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
65 origin.send(st.reply(stanza));
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
66 end
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
67 return ret;
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
68 end
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
69
10
7d70faba234c some error reporting during list editing
Thilo Cestonaro <thilo@cestona.ro>
parents: 8
diff changeset
70 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
71 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
72 local ret = false;
10
7d70faba234c some error reporting during list editing
Thilo Cestonaro <thilo@cestona.ro>
parents: 8
diff changeset
73 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
74
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
75 if idx ~= nil then
17
ccb07c0efc7e mod_privacy: prepare everything for the "is used" checking stuff...
Thilo Cestonaro <thilo@cestona.ro>
parents: 16
diff changeset
76 table.remove(privacy_lists.lists, idx); -- TODO check if used!
8
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
77 origin.send(st.reply(stanza));
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
78 ret = true;
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
79 end
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
80 return ret;
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
81 end
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
82
10
7d70faba234c some error reporting during list editing
Thilo Cestonaro <thilo@cestona.ro>
parents: 8
diff changeset
83 local function sortByOrder(a, b)
7d70faba234c some error reporting during list editing
Thilo Cestonaro <thilo@cestona.ro>
parents: 8
diff changeset
84 if a.order < b.order then
7d70faba234c some error reporting during list editing
Thilo Cestonaro <thilo@cestona.ro>
parents: 8
diff changeset
85 return true;
7d70faba234c some error reporting during list editing
Thilo Cestonaro <thilo@cestona.ro>
parents: 8
diff changeset
86 end
7d70faba234c some error reporting during list editing
Thilo Cestonaro <thilo@cestona.ro>
parents: 8
diff changeset
87 return false;
7d70faba234c some error reporting during list editing
Thilo Cestonaro <thilo@cestona.ro>
parents: 8
diff changeset
88 end
7d70faba234c some error reporting during list editing
Thilo Cestonaro <thilo@cestona.ro>
parents: 8
diff changeset
89
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
90 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
91 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
92 local ret = true;
10
7d70faba234c some error reporting during list editing
Thilo Cestonaro <thilo@cestona.ro>
parents: 8
diff changeset
93 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
94 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
95
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
96 if privacy_lists.lists == nil then
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
97 privacy_lists.lists = {};
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
98 end
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
99
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
100 if idx == nil then
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
101 idx = #privacy_lists.lists + 1;
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
102 end
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
103
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
104 local orderCheck = {};
8
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
105 local list = {};
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
106 list.name = name;
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
107 list.items = {};
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
108
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
109 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
110 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
111 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
112 end
14
0892941186f2 mod_privacy: Make tmp variable a local
Matthew Wild <mwild1@gmail.com>
parents: 10
diff changeset
113 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
114 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
115
8
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
116 tmp["type"] = item.attr.type;
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
117 tmp["value"] = item.attr.value;
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
118 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
119 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
120 tmp["presence-in"] = false;
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
121 tmp["presence-out"] = false;
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
122 tmp["message"] = false;
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
123 tmp["iq"] = false;
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
124
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
125 if #item.tags > 0 then
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
126 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
127 tmp[tag.name] = true;
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
128 end
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
129 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
130
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 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
132 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
133 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
134 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
135 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
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 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
139 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
140 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
141 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
142 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
143 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
144 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
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 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
147 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
148 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
149 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
150 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
151 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
152 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
153 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
154
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
155 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
156 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
157 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
158
8
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
159 list.items[#list.items + 1] = tmp;
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
160 end
10
7d70faba234c some error reporting during list editing
Thilo Cestonaro <thilo@cestona.ro>
parents: 8
diff changeset
161
7d70faba234c some error reporting during list editing
Thilo Cestonaro <thilo@cestona.ro>
parents: 8
diff changeset
162 table.sort(list, sortByOrder);
8
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
163
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
164 privacy_lists.lists[idx] = list;
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
165 origin.send(st.reply(stanza));
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
166 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
167 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
168 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
169 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
170 iq:up();
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
171 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
172 iq.attr.to = bare_jid.."/"..resource
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
173 session.send(iq);
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
174 end
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
175 end
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
176 return true;
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
177 end
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
178
10
7d70faba234c some error reporting during list editing
Thilo Cestonaro <thilo@cestona.ro>
parents: 8
diff changeset
179 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
180 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
181 local ret = false;
8
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
182 local reply = st.reply(stanza);
10
7d70faba234c some error reporting during list editing
Thilo Cestonaro <thilo@cestona.ro>
parents: 8
diff changeset
183 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
184
10
7d70faba234c some error reporting during list editing
Thilo Cestonaro <thilo@cestona.ro>
parents: 8
diff changeset
185 if name == nil then
17
ccb07c0efc7e mod_privacy: prepare everything for the "is used" checking stuff...
Thilo Cestonaro <thilo@cestona.ro>
parents: 16
diff changeset
186 reply:tag("active", {name=origin.activePrivacyList or ""}):up();
8
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
187 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
188 if privacy_lists.lists then
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
189 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
190 reply:tag("list", {name=list.name}):up();
10
7d70faba234c some error reporting during list editing
Thilo Cestonaro <thilo@cestona.ro>
parents: 8
diff changeset
191 end
8
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
192 end
19
e400ee8471b0 mod_privacy: removed trunk dependency; make it work when no lists already are exiting
Thilo Cestonaro <thilo@cestona.ro>
parents: 18
diff changeset
193 ret = true;
8
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
194 else
10
7d70faba234c some error reporting during list editing
Thilo Cestonaro <thilo@cestona.ro>
parents: 8
diff changeset
195 local idx = findNamedList(privacy_lists, name);
11
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
196 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
197 if idx ~= nil then
7d70faba234c some error reporting during list editing
Thilo Cestonaro <thilo@cestona.ro>
parents: 8
diff changeset
198 list = privacy_lists.lists[idx];
7d70faba234c some error reporting during list editing
Thilo Cestonaro <thilo@cestona.ro>
parents: 8
diff changeset
199 reply = reply:tag("list", {name=list.name});
7d70faba234c some error reporting during list editing
Thilo Cestonaro <thilo@cestona.ro>
parents: 8
diff changeset
200 for _,item in ipairs(list.items) do
7d70faba234c some error reporting during list editing
Thilo Cestonaro <thilo@cestona.ro>
parents: 8
diff changeset
201 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
202 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
203 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
204 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
205 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
206 reply:up();
7d70faba234c some error reporting during list editing
Thilo Cestonaro <thilo@cestona.ro>
parents: 8
diff changeset
207 end
7d70faba234c some error reporting during list editing
Thilo Cestonaro <thilo@cestona.ro>
parents: 8
diff changeset
208 ret = true;
8
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
209 end
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
210 end
10
7d70faba234c some error reporting during list editing
Thilo Cestonaro <thilo@cestona.ro>
parents: 8
diff changeset
211
7d70faba234c some error reporting during list editing
Thilo Cestonaro <thilo@cestona.ro>
parents: 8
diff changeset
212 if ret then
7d70faba234c some error reporting during list editing
Thilo Cestonaro <thilo@cestona.ro>
parents: 8
diff changeset
213 origin.send(reply);
7d70faba234c some error reporting during list editing
Thilo Cestonaro <thilo@cestona.ro>
parents: 8
diff changeset
214 end
8
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
215 return ret;
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
216 end
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
217
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
218 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
219 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
220
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
221 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
222 local err_reply = nil;
8
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
223 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
224 local valid = false;
10
7d70faba234c some error reporting during list editing
Thilo Cestonaro <thilo@cestona.ro>
parents: 8
diff changeset
225 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
226
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
227 if stanza.attr.type == "set" then
17
ccb07c0efc7e mod_privacy: prepare everything for the "is used" checking stuff...
Thilo Cestonaro <thilo@cestona.ro>
parents: 16
diff changeset
228 if #query.tags == 1 then -- the <query/> element MUST NOT include more than one child element
8
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
229 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
230 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
231 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
232 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
233 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
234 valid = activateList(privacy_lists, origin, stanza, tag.name, tag.attr.name);
17
ccb07c0efc7e mod_privacy: prepare everything for the "is used" checking stuff...
Thilo Cestonaro <thilo@cestona.ro>
parents: 16
diff changeset
235 if valid ~= true and valid ~= false then
ccb07c0efc7e mod_privacy: prepare everything for the "is used" checking stuff...
Thilo Cestonaro <thilo@cestona.ro>
parents: 16
diff changeset
236 err_reply = st.error_reply(stanza, "cancel", valid);
ccb07c0efc7e mod_privacy: prepare everything for the "is used" checking stuff...
Thilo Cestonaro <thilo@cestona.ro>
parents: 16
diff changeset
237 valid = false;
ccb07c0efc7e mod_privacy: prepare everything for the "is used" checking stuff...
Thilo Cestonaro <thilo@cestona.ro>
parents: 16
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 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
241 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
242 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
243 else -- Client edits a privacy list
17
ccb07c0efc7e mod_privacy: prepare everything for the "is used" checking stuff...
Thilo Cestonaro <thilo@cestona.ro>
parents: 16
diff changeset
244 valid = createOrReplaceList(privacy_lists, origin, stanza, tag.attr.name, tag.tags); -- TODO check if used!
ccb07c0efc7e mod_privacy: prepare everything for the "is used" checking stuff...
Thilo Cestonaro <thilo@cestona.ro>
parents: 16
diff changeset
245 if valid ~= true and valid ~= false 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
246 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
247 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
248 end
8
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
249 end
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
250 end
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 elseif stanza.attr.type == "get" then
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
254 local name = nil;
10
7d70faba234c some error reporting during list editing
Thilo Cestonaro <thilo@cestona.ro>
parents: 8
diff changeset
255 local listsToRetrieve = 0;
8
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
256 if #query.tags >= 1 then
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
257 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
258 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
259 name = tag.attr.name;
10
7d70faba234c some error reporting during list editing
Thilo Cestonaro <thilo@cestona.ro>
parents: 8
diff changeset
260 listsToRetrieve = listsToRetrieve + 1;
8
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
261 end
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
262 end
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
263 end
10
7d70faba234c some error reporting during list editing
Thilo Cestonaro <thilo@cestona.ro>
parents: 8
diff changeset
264 if listsToRetrieve == 0 or listsToRetrieve == 1 then
7d70faba234c some error reporting during list editing
Thilo Cestonaro <thilo@cestona.ro>
parents: 8
diff changeset
265 valid = getList(privacy_lists, origin, stanza, name);
7d70faba234c some error reporting during list editing
Thilo Cestonaro <thilo@cestona.ro>
parents: 8
diff changeset
266 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
267 end
8
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
268 end
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
269
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
270 if valid == false then
10
7d70faba234c some error reporting during list editing
Thilo Cestonaro <thilo@cestona.ro>
parents: 8
diff changeset
271 if err_reply == nil then
7d70faba234c some error reporting during list editing
Thilo Cestonaro <thilo@cestona.ro>
parents: 8
diff changeset
272 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
273 end
7d70faba234c some error reporting during list editing
Thilo Cestonaro <thilo@cestona.ro>
parents: 8
diff changeset
274 origin.send(err_reply);
8
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
275 else
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
276 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
277 end
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
278 return true;
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
279 end
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
280 return false;
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
281 end, 500);
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
282
17
ccb07c0efc7e mod_privacy: prepare everything for the "is used" checking stuff...
Thilo Cestonaro <thilo@cestona.ro>
parents: 16
diff changeset
283 function checkIfNeedToBeBlocked(e, session)
10
7d70faba234c some error reporting during list editing
Thilo Cestonaro <thilo@cestona.ro>
parents: 8
diff changeset
284 local origin, stanza = e.origin, e.stanza;
17
ccb07c0efc7e mod_privacy: prepare everything for the "is used" checking stuff...
Thilo Cestonaro <thilo@cestona.ro>
parents: 16
diff changeset
285 local privacy_lists = datamanager.load(session.username, session.host, "privacy") or {};
ccb07c0efc7e mod_privacy: prepare everything for the "is used" checking stuff...
Thilo Cestonaro <thilo@cestona.ro>
parents: 16
diff changeset
286 local bare_jid = session.username.."@"..session.host;
11
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
287
17
ccb07c0efc7e mod_privacy: prepare everything for the "is used" checking stuff...
Thilo Cestonaro <thilo@cestona.ro>
parents: 16
diff changeset
288 module:log("debug", "checkIfNeedToBeBlocked: username: %s, host: %s", session.username, session.host);
11
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
289 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
290
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
291 if privacy_lists.lists ~= nil and stanza.attr.to ~= nil and stanza.attr.from ~= nil then
17
ccb07c0efc7e mod_privacy: prepare everything for the "is used" checking stuff...
Thilo Cestonaro <thilo@cestona.ro>
parents: 16
diff changeset
292 if session.activePrivacyList == nil and privacy_lists.default == nil then
11
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
293 return; -- Nothing to block, default is Allow all
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
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
296 local idx;
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
297 local list;
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
298 local item;
17
ccb07c0efc7e mod_privacy: prepare everything for the "is used" checking stuff...
Thilo Cestonaro <thilo@cestona.ro>
parents: 16
diff changeset
299 local listname = session.activePrivacyList;
11
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
300 if listname == nil then
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
301 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
302 end
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
303 idx = findNamedList(privacy_lists, listname);
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
304 if idx == nil then
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
305 module:log("info", "given privacy listname not found.");
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
306 return;
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
307 end
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
308 list = privacy_lists.lists[idx];
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
309 if list == nil then
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
310 module:log("info", "privacy list index wrong.");
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
311 return;
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
312 end
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
313 for _,item in ipairs(list.items) do
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
314 local apply = false;
17
ccb07c0efc7e mod_privacy: prepare everything for the "is used" checking stuff...
Thilo Cestonaro <thilo@cestona.ro>
parents: 16
diff changeset
315 local block = false;
11
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
316 if (stanza.name == "message" and item.message) or
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
317 (stanza.name == "iq" and item.iq) or
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
318 (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
319 (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
320 (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
321 module:log("debug", "stanza type matched.");
17
ccb07c0efc7e mod_privacy: prepare everything for the "is used" checking stuff...
Thilo Cestonaro <thilo@cestona.ro>
parents: 16
diff changeset
322 apply = true;
11
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 apply then
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
325 local evilJid = {};
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
326 apply = false;
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
327 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
328 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
329 else
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
330 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
331 end
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
332 if item.type == "jid" and
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
333 (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
334 (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
335 (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
336 (evilJid.host and item.value == evilJid.host) then
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
337 module:log("debug", "jid 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 elseif item.type == "group" then
17
ccb07c0efc7e mod_privacy: prepare everything for the "is used" checking stuff...
Thilo Cestonaro <thilo@cestona.ro>
parents: 16
diff changeset
341 local roster = load_roster(session.username, session.host);
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
342 local groups = roster.groups;
11
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
343 for _,group in ipairs(groups) do
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
344 if group == item.value then
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
345 module:log("debug", "group 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 break;
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
349 end
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
350 end
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
351 elseif item.type == "subscription" then
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
352 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
353 module:log("debug", "subscription matched.");
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
354 apply = true;
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
355 block = (item.action == "deny");
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
356 end
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
357 elseif item.type == nil then
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
358 module:log("debug", "no item.type, so matched.");
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
359 apply = true;
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
360 block = (item.action == "deny");
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
361 end
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 if apply then
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
364 if block then
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
365 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
366 if stanza.name == "message" then
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
367 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
368 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
369 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
370 end
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
371 return true; -- stanza blocked !
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
372 else
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
373 module:log("info", "stanza explicit allowed!")
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
374 end
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
375 end
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
376 end
10
7d70faba234c some error reporting during list editing
Thilo Cestonaro <thilo@cestona.ro>
parents: 8
diff changeset
377 end
11
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
378 return;
8
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
379 end
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
380
11
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
381 function preCheckIncoming(e)
17
ccb07c0efc7e mod_privacy: prepare everything for the "is used" checking stuff...
Thilo Cestonaro <thilo@cestona.ro>
parents: 16
diff changeset
382 local session;
11
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
383 if e.stanza.attr.to ~= nil then
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
384 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
385 if node == nil or host == nil then
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
386 return;
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
387 end
17
ccb07c0efc7e mod_privacy: prepare everything for the "is used" checking stuff...
Thilo Cestonaro <thilo@cestona.ro>
parents: 16
diff changeset
388 if resource == nil then
ccb07c0efc7e mod_privacy: prepare everything for the "is used" checking stuff...
Thilo Cestonaro <thilo@cestona.ro>
parents: 16
diff changeset
389 local prio = 0;
ccb07c0efc7e mod_privacy: prepare everything for the "is used" checking stuff...
Thilo Cestonaro <thilo@cestona.ro>
parents: 16
diff changeset
390 local session_;
18
2df11ec081fe mod_privacy: make finding the right session working
Thilo Cestonaro <thilo@cestona.ro>
parents: 17
diff changeset
391 if bare_sessions[node.."@"..host] ~= nil then
2df11ec081fe mod_privacy: make finding the right session working
Thilo Cestonaro <thilo@cestona.ro>
parents: 17
diff changeset
392 for resource, session_ in pairs(bare_sessions[node.."@"..host].sessions) do
2df11ec081fe mod_privacy: make finding the right session working
Thilo Cestonaro <thilo@cestona.ro>
parents: 17
diff changeset
393 if session_.priority > prio then
2df11ec081fe mod_privacy: make finding the right session working
Thilo Cestonaro <thilo@cestona.ro>
parents: 17
diff changeset
394 session = session_;
2df11ec081fe mod_privacy: make finding the right session working
Thilo Cestonaro <thilo@cestona.ro>
parents: 17
diff changeset
395 prio = session_.priority;
2df11ec081fe mod_privacy: make finding the right session working
Thilo Cestonaro <thilo@cestona.ro>
parents: 17
diff changeset
396 end
17
ccb07c0efc7e mod_privacy: prepare everything for the "is used" checking stuff...
Thilo Cestonaro <thilo@cestona.ro>
parents: 16
diff changeset
397 end
ccb07c0efc7e mod_privacy: prepare everything for the "is used" checking stuff...
Thilo Cestonaro <thilo@cestona.ro>
parents: 16
diff changeset
398 end
ccb07c0efc7e mod_privacy: prepare everything for the "is used" checking stuff...
Thilo Cestonaro <thilo@cestona.ro>
parents: 16
diff changeset
399 else
ccb07c0efc7e mod_privacy: prepare everything for the "is used" checking stuff...
Thilo Cestonaro <thilo@cestona.ro>
parents: 16
diff changeset
400 session = full_sessions[node.."@"..host.."/"..resource];
ccb07c0efc7e mod_privacy: prepare everything for the "is used" checking stuff...
Thilo Cestonaro <thilo@cestona.ro>
parents: 16
diff changeset
401 end
18
2df11ec081fe mod_privacy: make finding the right session working
Thilo Cestonaro <thilo@cestona.ro>
parents: 17
diff changeset
402 if session ~= nil then
2df11ec081fe mod_privacy: make finding the right session working
Thilo Cestonaro <thilo@cestona.ro>
parents: 17
diff changeset
403 return checkIfNeedToBeBlocked(e, session);
2df11ec081fe mod_privacy: make finding the right session working
Thilo Cestonaro <thilo@cestona.ro>
parents: 17
diff changeset
404 else
2df11ec081fe mod_privacy: make finding the right session working
Thilo Cestonaro <thilo@cestona.ro>
parents: 17
diff changeset
405 module:log("debug", "preCheckIncoming: Couldn't get session for jid: %s@%s/%s", node or "nil", host or "nil", resource or "nil")
2df11ec081fe mod_privacy: make finding the right session working
Thilo Cestonaro <thilo@cestona.ro>
parents: 17
diff changeset
406 end
11
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
407 end
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
408 return;
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
409 end
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
410
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
411 function preCheckOutgoing(e)
17
ccb07c0efc7e mod_privacy: prepare everything for the "is used" checking stuff...
Thilo Cestonaro <thilo@cestona.ro>
parents: 16
diff changeset
412 local session;
11
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
413 if e.stanza.attr.from ~= nil then
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
414 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
415 if node == nil or host == nil then
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
416 return;
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
417 end
17
ccb07c0efc7e mod_privacy: prepare everything for the "is used" checking stuff...
Thilo Cestonaro <thilo@cestona.ro>
parents: 16
diff changeset
418 if resource == nil then
ccb07c0efc7e mod_privacy: prepare everything for the "is used" checking stuff...
Thilo Cestonaro <thilo@cestona.ro>
parents: 16
diff changeset
419 local prio = 0;
ccb07c0efc7e mod_privacy: prepare everything for the "is used" checking stuff...
Thilo Cestonaro <thilo@cestona.ro>
parents: 16
diff changeset
420 local session_;
18
2df11ec081fe mod_privacy: make finding the right session working
Thilo Cestonaro <thilo@cestona.ro>
parents: 17
diff changeset
421 if bare_sessions[node.."@"..host] ~= nil then
2df11ec081fe mod_privacy: make finding the right session working
Thilo Cestonaro <thilo@cestona.ro>
parents: 17
diff changeset
422 for resource, session_ in pairs(bare_sessions[node.."@"..host].sessions) do
2df11ec081fe mod_privacy: make finding the right session working
Thilo Cestonaro <thilo@cestona.ro>
parents: 17
diff changeset
423 if session_.priority > prio then
2df11ec081fe mod_privacy: make finding the right session working
Thilo Cestonaro <thilo@cestona.ro>
parents: 17
diff changeset
424 session = session_;
2df11ec081fe mod_privacy: make finding the right session working
Thilo Cestonaro <thilo@cestona.ro>
parents: 17
diff changeset
425 prio = session_.priority;
2df11ec081fe mod_privacy: make finding the right session working
Thilo Cestonaro <thilo@cestona.ro>
parents: 17
diff changeset
426 end
17
ccb07c0efc7e mod_privacy: prepare everything for the "is used" checking stuff...
Thilo Cestonaro <thilo@cestona.ro>
parents: 16
diff changeset
427 end
ccb07c0efc7e mod_privacy: prepare everything for the "is used" checking stuff...
Thilo Cestonaro <thilo@cestona.ro>
parents: 16
diff changeset
428 end
ccb07c0efc7e mod_privacy: prepare everything for the "is used" checking stuff...
Thilo Cestonaro <thilo@cestona.ro>
parents: 16
diff changeset
429 else
ccb07c0efc7e mod_privacy: prepare everything for the "is used" checking stuff...
Thilo Cestonaro <thilo@cestona.ro>
parents: 16
diff changeset
430 session = full_sessions[node.."@"..host.."/"..resource];
ccb07c0efc7e mod_privacy: prepare everything for the "is used" checking stuff...
Thilo Cestonaro <thilo@cestona.ro>
parents: 16
diff changeset
431 end
18
2df11ec081fe mod_privacy: make finding the right session working
Thilo Cestonaro <thilo@cestona.ro>
parents: 17
diff changeset
432 if session ~= nil then
2df11ec081fe mod_privacy: make finding the right session working
Thilo Cestonaro <thilo@cestona.ro>
parents: 17
diff changeset
433 return checkIfNeedToBeBlocked(e, session);
2df11ec081fe mod_privacy: make finding the right session working
Thilo Cestonaro <thilo@cestona.ro>
parents: 17
diff changeset
434 else
2df11ec081fe mod_privacy: make finding the right session working
Thilo Cestonaro <thilo@cestona.ro>
parents: 17
diff changeset
435 module:log("debug", "preCheckOutgoing: Couldn't get session for jid: %s@%s/%s", node or "nil", host or "nil", resource or "nil")
2df11ec081fe mod_privacy: make finding the right session working
Thilo Cestonaro <thilo@cestona.ro>
parents: 17
diff changeset
436 end
11
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
437 end
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
438 return;
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
439 end
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
440
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
441
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
442 module:hook("pre-message/full", preCheckOutgoing, 500);
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
443 module:hook("pre-message/bare", preCheckOutgoing, 500);
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
444 module:hook("pre-message/host", preCheckOutgoing, 500);
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
445 module:hook("pre-iq/full", preCheckOutgoing, 500);
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
446 module:hook("pre-iq/bare", preCheckOutgoing, 500);
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
447 module:hook("pre-iq/host", preCheckOutgoing, 500);
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
448 module:hook("pre-presence/full", preCheckOutgoing, 500);
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
449 module:hook("pre-presence/bare", preCheckOutgoing, 500);
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
450 module:hook("pre-presence/host", preCheckOutgoing, 500);
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
451
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
452 module:hook("message/full", preCheckIncoming, 500);
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
453 module:hook("message/bare", preCheckIncoming, 500);
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
454 module:hook("message/host", preCheckIncoming, 500);
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
455 module:hook("iq/full", preCheckIncoming, 500);
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
456 module:hook("iq/bare", preCheckIncoming, 500);
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
457 module:hook("iq/host", preCheckIncoming, 500);
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
458 module:hook("presence/full", preCheckIncoming, 500);
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
459 module:hook("presence/bare", preCheckIncoming, 500);
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
460 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
461
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
462 module:log("info", "mod_privacy loaded ...");