annotate mod_privacy/mod_privacy.lua @ 17:ccb07c0efc7e

mod_privacy: prepare everything for the "is used" checking stuff...
author Thilo Cestonaro <thilo@cestona.ro>
date Mon, 28 Sep 2009 22:22:22 +0200
parents 35e74c1094a7
children 2df11ec081fe
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 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);
17
ccb07c0efc7e mod_privacy: prepare everything for the "is used" checking stuff...
Thilo Cestonaro <thilo@cestona.ro>
parents: 16
diff changeset
40 if which == "default" then
ccb07c0efc7e mod_privacy: prepare everything for the "is used" checking stuff...
Thilo Cestonaro <thilo@cestona.ro>
parents: 16
diff changeset
41 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
42 elseif which == "active" then
ccb07c0efc7e mod_privacy: prepare everything for the "is used" checking stuff...
Thilo Cestonaro <thilo@cestona.ro>
parents: 16
diff changeset
43 origin.activePrivacyList = nil;
ccb07c0efc7e mod_privacy: prepare everything for the "is used" checking stuff...
Thilo Cestonaro <thilo@cestona.ro>
parents: 16
diff changeset
44 end
8
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
45 origin.send(st.reply(stanza));
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
46 return true;
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
47 end
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
48
10
7d70faba234c some error reporting during list editing
Thilo Cestonaro <thilo@cestona.ro>
parents: 8
diff changeset
49 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
50 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
51 local ret = false;
10
7d70faba234c some error reporting during list editing
Thilo Cestonaro <thilo@cestona.ro>
parents: 8
diff changeset
52 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
53
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
54 if privacy_lists[which] == nil then
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
55 privacy_lists[which] = "";
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
56 end
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
57
17
ccb07c0efc7e mod_privacy: prepare everything for the "is used" checking stuff...
Thilo Cestonaro <thilo@cestona.ro>
parents: 16
diff changeset
58 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
59 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
60 ret = true;
ccb07c0efc7e mod_privacy: prepare everything for the "is used" checking stuff...
Thilo Cestonaro <thilo@cestona.ro>
parents: 16
diff changeset
61 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
62 origin.activePrivacyList = name;
ccb07c0efc7e mod_privacy: prepare everything for the "is used" checking stuff...
Thilo Cestonaro <thilo@cestona.ro>
parents: 16
diff changeset
63 ret = true;
ccb07c0efc7e mod_privacy: prepare everything for the "is used" checking stuff...
Thilo Cestonaro <thilo@cestona.ro>
parents: 16
diff changeset
64 end
ccb07c0efc7e mod_privacy: prepare everything for the "is used" checking stuff...
Thilo Cestonaro <thilo@cestona.ro>
parents: 16
diff changeset
65 if ret == true then
8
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
66 origin.send(st.reply(stanza));
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
67 end
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
68 return ret;
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
69 end
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
70
10
7d70faba234c some error reporting during list editing
Thilo Cestonaro <thilo@cestona.ro>
parents: 8
diff changeset
71 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
72 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
73 local ret = false;
10
7d70faba234c some error reporting during list editing
Thilo Cestonaro <thilo@cestona.ro>
parents: 8
diff changeset
74 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
75
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
76 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
77 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
78 origin.send(st.reply(stanza));
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
79 ret = true;
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
80 end
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
81 return ret;
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
82 end
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
83
10
7d70faba234c some error reporting during list editing
Thilo Cestonaro <thilo@cestona.ro>
parents: 8
diff changeset
84 local function sortByOrder(a, b)
7d70faba234c some error reporting during list editing
Thilo Cestonaro <thilo@cestona.ro>
parents: 8
diff changeset
85 if a.order < b.order then
7d70faba234c some error reporting during list editing
Thilo Cestonaro <thilo@cestona.ro>
parents: 8
diff changeset
86 return true;
7d70faba234c some error reporting during list editing
Thilo Cestonaro <thilo@cestona.ro>
parents: 8
diff changeset
87 end
7d70faba234c some error reporting during list editing
Thilo Cestonaro <thilo@cestona.ro>
parents: 8
diff changeset
88 return false;
7d70faba234c some error reporting during list editing
Thilo Cestonaro <thilo@cestona.ro>
parents: 8
diff changeset
89 end
7d70faba234c some error reporting during list editing
Thilo Cestonaro <thilo@cestona.ro>
parents: 8
diff changeset
90
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
91 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
92 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
93 local ret = true;
10
7d70faba234c some error reporting during list editing
Thilo Cestonaro <thilo@cestona.ro>
parents: 8
diff changeset
94 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
95 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
96
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
97 if privacy_lists.lists == nil then
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
98 privacy_lists.lists = {};
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
99 end
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 if idx == nil then
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
102 idx = #privacy_lists.lists + 1;
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
103 end
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
104
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
105 local orderCheck = {};
8
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
106 local list = {};
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
107 list.name = name;
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
108 list.items = {};
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
109
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
110 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
111 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
112 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
113 end
14
0892941186f2 mod_privacy: Make tmp variable a local
Matthew Wild <mwild1@gmail.com>
parents: 10
diff changeset
114 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
115 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
116
8
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
117 tmp["type"] = item.attr.type;
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
118 tmp["value"] = item.attr.value;
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
119 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
120 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
121 tmp["presence-in"] = false;
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
122 tmp["presence-out"] = false;
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
123 tmp["message"] = false;
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
124 tmp["iq"] = false;
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
125
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
126 if #item.tags > 0 then
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
127 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
128 tmp[tag.name] = true;
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
129 end
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
130 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
131
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 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
133 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
134 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
135 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
136 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
137 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
138 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
139 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
140 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
141 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
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 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
144 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
145 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
146 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
147 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
148 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
149 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
150 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
151 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
152 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
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 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
155
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 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
157 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
158 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
159
8
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
160 list.items[#list.items + 1] = tmp;
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
161 end
10
7d70faba234c some error reporting during list editing
Thilo Cestonaro <thilo@cestona.ro>
parents: 8
diff changeset
162
7d70faba234c some error reporting during list editing
Thilo Cestonaro <thilo@cestona.ro>
parents: 8
diff changeset
163 table.sort(list, sortByOrder);
8
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
164
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
165 privacy_lists.lists[idx] = list;
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
166 origin.send(st.reply(stanza));
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
167 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
168 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
169 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
170 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
171 iq:up();
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
172 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
173 iq.attr.to = bare_jid.."/"..resource
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
174 session.send(iq);
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 end
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
177 return true;
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
178 end
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
179
10
7d70faba234c some error reporting during list editing
Thilo Cestonaro <thilo@cestona.ro>
parents: 8
diff changeset
180 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
181 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
182 local ret = false;
8
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
183 local reply = st.reply(stanza);
10
7d70faba234c some error reporting during list editing
Thilo Cestonaro <thilo@cestona.ro>
parents: 8
diff changeset
184 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
185
10
7d70faba234c some error reporting during list editing
Thilo Cestonaro <thilo@cestona.ro>
parents: 8
diff changeset
186 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
187 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
188 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
189 if privacy_lists.lists then
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
190 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
191 reply:tag("list", {name=list.name}):up();
10
7d70faba234c some error reporting during list editing
Thilo Cestonaro <thilo@cestona.ro>
parents: 8
diff changeset
192 end
7d70faba234c some error reporting during list editing
Thilo Cestonaro <thilo@cestona.ro>
parents: 8
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 end
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
195 else
10
7d70faba234c some error reporting during list editing
Thilo Cestonaro <thilo@cestona.ro>
parents: 8
diff changeset
196 local idx = findNamedList(privacy_lists, name);
11
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
197 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
198 if idx ~= nil then
7d70faba234c some error reporting during list editing
Thilo Cestonaro <thilo@cestona.ro>
parents: 8
diff changeset
199 list = privacy_lists.lists[idx];
7d70faba234c some error reporting during list editing
Thilo Cestonaro <thilo@cestona.ro>
parents: 8
diff changeset
200 reply = reply:tag("list", {name=list.name});
7d70faba234c some error reporting during list editing
Thilo Cestonaro <thilo@cestona.ro>
parents: 8
diff changeset
201 for _,item in ipairs(list.items) do
7d70faba234c some error reporting during list editing
Thilo Cestonaro <thilo@cestona.ro>
parents: 8
diff changeset
202 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
203 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
204 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
205 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
206 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
207 reply:up();
7d70faba234c some error reporting during list editing
Thilo Cestonaro <thilo@cestona.ro>
parents: 8
diff changeset
208 end
7d70faba234c some error reporting during list editing
Thilo Cestonaro <thilo@cestona.ro>
parents: 8
diff changeset
209 ret = true;
8
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
210 end
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
211 end
10
7d70faba234c some error reporting during list editing
Thilo Cestonaro <thilo@cestona.ro>
parents: 8
diff changeset
212
7d70faba234c some error reporting during list editing
Thilo Cestonaro <thilo@cestona.ro>
parents: 8
diff changeset
213 if ret then
7d70faba234c some error reporting during list editing
Thilo Cestonaro <thilo@cestona.ro>
parents: 8
diff changeset
214 origin.send(reply);
7d70faba234c some error reporting during list editing
Thilo Cestonaro <thilo@cestona.ro>
parents: 8
diff changeset
215 end
8
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
216 return ret;
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
217 end
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
218
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
219 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
220 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
221
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
222 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
223 local err_reply = nil;
8
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
224 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
225 local valid = false;
10
7d70faba234c some error reporting during list editing
Thilo Cestonaro <thilo@cestona.ro>
parents: 8
diff changeset
226 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
227
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
228 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
229 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
230 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
231 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
232 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
233 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
234 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
235 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
236 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
237 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
238 valid = false;
ccb07c0efc7e mod_privacy: prepare everything for the "is used" checking stuff...
Thilo Cestonaro <thilo@cestona.ro>
parents: 16
diff changeset
239 end
8
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 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
242 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
243 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
244 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
245 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
246 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
247 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
248 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
249 end
8
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 end
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
254 elseif stanza.attr.type == "get" then
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
255 local name = nil;
10
7d70faba234c some error reporting during list editing
Thilo Cestonaro <thilo@cestona.ro>
parents: 8
diff changeset
256 local listsToRetrieve = 0;
8
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
257 if #query.tags >= 1 then
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
258 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
259 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
260 name = tag.attr.name;
10
7d70faba234c some error reporting during list editing
Thilo Cestonaro <thilo@cestona.ro>
parents: 8
diff changeset
261 listsToRetrieve = listsToRetrieve + 1;
8
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
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
264 end
10
7d70faba234c some error reporting during list editing
Thilo Cestonaro <thilo@cestona.ro>
parents: 8
diff changeset
265 if listsToRetrieve == 0 or listsToRetrieve == 1 then
7d70faba234c some error reporting during list editing
Thilo Cestonaro <thilo@cestona.ro>
parents: 8
diff changeset
266 valid = getList(privacy_lists, origin, stanza, name);
7d70faba234c some error reporting during list editing
Thilo Cestonaro <thilo@cestona.ro>
parents: 8
diff changeset
267 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
268 end
8
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
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
271 if valid == false then
10
7d70faba234c some error reporting during list editing
Thilo Cestonaro <thilo@cestona.ro>
parents: 8
diff changeset
272 if err_reply == nil then
7d70faba234c some error reporting during list editing
Thilo Cestonaro <thilo@cestona.ro>
parents: 8
diff changeset
273 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
274 end
7d70faba234c some error reporting during list editing
Thilo Cestonaro <thilo@cestona.ro>
parents: 8
diff changeset
275 origin.send(err_reply);
8
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
276 else
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
277 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
278 end
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
279 return true;
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
280 end
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
281 return false;
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
282 end, 500);
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
283
17
ccb07c0efc7e mod_privacy: prepare everything for the "is used" checking stuff...
Thilo Cestonaro <thilo@cestona.ro>
parents: 16
diff changeset
284 function checkIfNeedToBeBlocked(e, session)
10
7d70faba234c some error reporting during list editing
Thilo Cestonaro <thilo@cestona.ro>
parents: 8
diff changeset
285 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
286 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
287 local bare_jid = session.username.."@"..session.host;
11
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
288
17
ccb07c0efc7e mod_privacy: prepare everything for the "is used" checking stuff...
Thilo Cestonaro <thilo@cestona.ro>
parents: 16
diff changeset
289 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
290 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
291
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
292 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
293 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
294 return; -- Nothing to block, default is Allow all
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
295 end
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
296
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
297 local idx;
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
298 local list;
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
299 local item;
17
ccb07c0efc7e mod_privacy: prepare everything for the "is used" checking stuff...
Thilo Cestonaro <thilo@cestona.ro>
parents: 16
diff changeset
300 local listname = session.activePrivacyList;
11
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
301 if listname == nil then
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
302 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
303 end
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
304 idx = findNamedList(privacy_lists, listname);
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
305 if idx == nil then
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
306 module:log("info", "given privacy listname not found.");
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
307 return;
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
308 end
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
309 list = privacy_lists.lists[idx];
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
310 if list == nil then
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
311 module:log("info", "privacy list index wrong.");
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
312 return;
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
313 end
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
314 for _,item in ipairs(list.items) do
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
315 local apply = false;
17
ccb07c0efc7e mod_privacy: prepare everything for the "is used" checking stuff...
Thilo Cestonaro <thilo@cestona.ro>
parents: 16
diff changeset
316 local block = false;
11
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
317 if (stanza.name == "message" and item.message) or
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
318 (stanza.name == "iq" and item.iq) 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.to) == bare_jid and item["presence-in"]) or
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
320 (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
321 (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
322 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
323 apply = true;
11
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
324 end
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
325 if apply then
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
326 local evilJid = {};
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
327 apply = false;
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
328 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
329 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
330 else
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
331 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
332 end
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
333 if item.type == "jid" and
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
334 (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
335 (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
336 (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
337 (evilJid.host and item.value == evilJid.host) then
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
338 module:log("debug", "jid matched.");
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
339 apply = true;
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
340 block = (item.action == "deny");
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
341 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
342 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
343 local groups = roster.groups;
11
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
344 for _,group in ipairs(groups) do
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
345 if group == item.value then
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
346 module:log("debug", "group matched.");
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
347 apply = true;
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
348 block = (item.action == "deny");
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
349 break;
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 end
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
352 elseif item.type == "subscription" then
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
353 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
354 module:log("debug", "subscription matched.");
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
355 apply = true;
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
356 block = (item.action == "deny");
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
357 end
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
358 elseif item.type == nil then
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
359 module:log("debug", "no item.type, so matched.");
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
360 apply = true;
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
361 block = (item.action == "deny");
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 end
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
364 if apply then
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
365 if block then
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
366 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
367 if stanza.name == "message" then
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
368 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
369 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
370 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
371 end
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
372 return true; -- stanza blocked !
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
373 else
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
374 module:log("info", "stanza explicit allowed!")
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
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
377 end
10
7d70faba234c some error reporting during list editing
Thilo Cestonaro <thilo@cestona.ro>
parents: 8
diff changeset
378 end
11
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
379 return;
8
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
380 end
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
381
11
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
382 function preCheckIncoming(e)
17
ccb07c0efc7e mod_privacy: prepare everything for the "is used" checking stuff...
Thilo Cestonaro <thilo@cestona.ro>
parents: 16
diff changeset
383 local session;
11
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
384 if e.stanza.attr.to ~= nil then
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
385 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
386 if node == nil or host == nil then
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
387 return;
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
388 end
17
ccb07c0efc7e mod_privacy: prepare everything for the "is used" checking stuff...
Thilo Cestonaro <thilo@cestona.ro>
parents: 16
diff changeset
389 if resource == nil then
ccb07c0efc7e mod_privacy: prepare everything for the "is used" checking stuff...
Thilo Cestonaro <thilo@cestona.ro>
parents: 16
diff changeset
390 local prio = 0;
ccb07c0efc7e mod_privacy: prepare everything for the "is used" checking stuff...
Thilo Cestonaro <thilo@cestona.ro>
parents: 16
diff changeset
391 local session_;
ccb07c0efc7e mod_privacy: prepare everything for the "is used" checking stuff...
Thilo Cestonaro <thilo@cestona.ro>
parents: 16
diff changeset
392 for _,session_ in ipairs(bare_sessions[node.."@"..host].sessions) do
ccb07c0efc7e mod_privacy: prepare everything for the "is used" checking stuff...
Thilo Cestonaro <thilo@cestona.ro>
parents: 16
diff changeset
393 if session_.priority > prio then
ccb07c0efc7e mod_privacy: prepare everything for the "is used" checking stuff...
Thilo Cestonaro <thilo@cestona.ro>
parents: 16
diff changeset
394 session = session_;
ccb07c0efc7e mod_privacy: prepare everything for the "is used" checking stuff...
Thilo Cestonaro <thilo@cestona.ro>
parents: 16
diff changeset
395 prio = session_.priority;
ccb07c0efc7e mod_privacy: prepare everything for the "is used" checking stuff...
Thilo Cestonaro <thilo@cestona.ro>
parents: 16
diff changeset
396 end
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 else
ccb07c0efc7e mod_privacy: prepare everything for the "is used" checking stuff...
Thilo Cestonaro <thilo@cestona.ro>
parents: 16
diff changeset
399 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
400 end
ccb07c0efc7e mod_privacy: prepare everything for the "is used" checking stuff...
Thilo Cestonaro <thilo@cestona.ro>
parents: 16
diff changeset
401 return checkIfNeedToBeBlocked(e, session);
11
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
402 end
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
403 return;
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
404 end
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 function preCheckOutgoing(e)
17
ccb07c0efc7e mod_privacy: prepare everything for the "is used" checking stuff...
Thilo Cestonaro <thilo@cestona.ro>
parents: 16
diff changeset
407 local session;
11
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
408 if e.stanza.attr.from ~= nil then
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
409 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
410 if node == nil or host == nil then
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
411 return;
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
412 end
17
ccb07c0efc7e mod_privacy: prepare everything for the "is used" checking stuff...
Thilo Cestonaro <thilo@cestona.ro>
parents: 16
diff changeset
413 if resource == nil then
ccb07c0efc7e mod_privacy: prepare everything for the "is used" checking stuff...
Thilo Cestonaro <thilo@cestona.ro>
parents: 16
diff changeset
414 local prio = 0;
ccb07c0efc7e mod_privacy: prepare everything for the "is used" checking stuff...
Thilo Cestonaro <thilo@cestona.ro>
parents: 16
diff changeset
415 local session_;
ccb07c0efc7e mod_privacy: prepare everything for the "is used" checking stuff...
Thilo Cestonaro <thilo@cestona.ro>
parents: 16
diff changeset
416 for _,session_ in ipairs(bare_sessions[node.."@"..host].sessions) do
ccb07c0efc7e mod_privacy: prepare everything for the "is used" checking stuff...
Thilo Cestonaro <thilo@cestona.ro>
parents: 16
diff changeset
417 if session_.priority > prio then
ccb07c0efc7e mod_privacy: prepare everything for the "is used" checking stuff...
Thilo Cestonaro <thilo@cestona.ro>
parents: 16
diff changeset
418 session = session_;
ccb07c0efc7e mod_privacy: prepare everything for the "is used" checking stuff...
Thilo Cestonaro <thilo@cestona.ro>
parents: 16
diff changeset
419 prio = session_.priority;
ccb07c0efc7e mod_privacy: prepare everything for the "is used" checking stuff...
Thilo Cestonaro <thilo@cestona.ro>
parents: 16
diff changeset
420 end
ccb07c0efc7e mod_privacy: prepare everything for the "is used" checking stuff...
Thilo Cestonaro <thilo@cestona.ro>
parents: 16
diff changeset
421 end
ccb07c0efc7e mod_privacy: prepare everything for the "is used" checking stuff...
Thilo Cestonaro <thilo@cestona.ro>
parents: 16
diff changeset
422 else
ccb07c0efc7e mod_privacy: prepare everything for the "is used" checking stuff...
Thilo Cestonaro <thilo@cestona.ro>
parents: 16
diff changeset
423 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
424 end
ccb07c0efc7e mod_privacy: prepare everything for the "is used" checking stuff...
Thilo Cestonaro <thilo@cestona.ro>
parents: 16
diff changeset
425 return checkIfNeedToBeBlocked(e, session);
11
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
426 end
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
427 return;
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
428 end
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
429
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
430
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
431 module:hook("pre-message/full", preCheckOutgoing, 500);
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
432 module:hook("pre-message/bare", preCheckOutgoing, 500);
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
433 module:hook("pre-message/host", preCheckOutgoing, 500);
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
434 module:hook("pre-iq/full", preCheckOutgoing, 500);
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
435 module:hook("pre-iq/bare", preCheckOutgoing, 500);
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
436 module:hook("pre-iq/host", preCheckOutgoing, 500);
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
437 module:hook("pre-presence/full", preCheckOutgoing, 500);
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
438 module:hook("pre-presence/bare", preCheckOutgoing, 500);
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
439 module:hook("pre-presence/host", preCheckOutgoing, 500);
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 module:hook("message/full", preCheckIncoming, 500);
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
442 module:hook("message/bare", preCheckIncoming, 500);
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
443 module:hook("message/host", preCheckIncoming, 500);
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
444 module:hook("iq/full", preCheckIncoming, 500);
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
445 module:hook("iq/bare", preCheckIncoming, 500);
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
446 module:hook("iq/host", preCheckIncoming, 500);
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
447 module:hook("presence/full", preCheckIncoming, 500);
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
448 module:hook("presence/bare", preCheckIncoming, 500);
529819205379 do the first real blocking actions
Thilo Cestonaro <thilo@cestona.ro>
parents: 10
diff changeset
449 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
450
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
451 -- 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
452 -- helpers.log_events(prosody.events, "*");
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
453
10502594a49b adds mod_privacy; lists creating, editing and deletion working.
Thilo Cestonaro <thilo@cestona.ro>
parents:
diff changeset
454 module:log("info", "mod_privacy loaded ...");