Mercurial > prosody-modules
annotate mod_privacy_lists/mod_privacy_lists.lua @ 1474:d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Sun, 27 Jul 2014 14:38:04 +0100 |
parents | |
children | 58d48afca54d |
rev | line source |
---|---|
1474
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1 -- Prosody IM |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2 -- Copyright (C) 2009-2010 Matthew Wild |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
3 -- Copyright (C) 2009-2010 Waqas Hussain |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
4 -- Copyright (C) 2009 Thilo Cestonaro |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
5 -- |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
6 -- This project is MIT/X11 licensed. Please see the |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
7 -- COPYING file in the source package for more information. |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
8 -- |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
9 |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
10 module:add_feature("jabber:iq:privacy"); |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
11 |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
12 local st = require "util.stanza"; |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
13 local bare_sessions, full_sessions = prosody.bare_sessions, prosody.full_sessions; |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
14 local util_Jid = require "util.jid"; |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
15 local jid_bare = util_Jid.bare; |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
16 local jid_split, jid_join = util_Jid.split, util_Jid.join; |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
17 local load_roster = require "core.rostermanager".load_roster; |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
18 local to_number = tonumber; |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
19 |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
20 local privacy_storage = module:open_store(); |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
21 |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
22 function isListUsed(origin, name, privacy_lists) |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
23 local user = bare_sessions[origin.username.."@"..origin.host]; |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
24 if user then |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
25 for resource, session in pairs(user.sessions) do |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
26 if resource ~= origin.resource then |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
27 if session.activePrivacyList == name then |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
28 return true; |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
29 elseif session.activePrivacyList == nil and privacy_lists.default == name then |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
30 return true; |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
31 end |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
32 end |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
33 end |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
34 end |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
35 end |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
36 |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
37 function isAnotherSessionUsingDefaultList(origin) |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
38 local user = bare_sessions[origin.username.."@"..origin.host]; |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
39 if user then |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
40 for resource, session in pairs(user.sessions) do |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
41 if resource ~= origin.resource and session.activePrivacyList == nil then |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
42 return true; |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
43 end |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
44 end |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
45 end |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
46 end |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
47 |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
48 function declineList(privacy_lists, origin, stanza, which) |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
49 if which == "default" then |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
50 if isAnotherSessionUsingDefaultList(origin) then |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
51 return { "cancel", "conflict", "Another session is online and using the default list."}; |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
52 end |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
53 privacy_lists.default = nil; |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
54 origin.send(st.reply(stanza)); |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
55 elseif which == "active" then |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
56 origin.activePrivacyList = nil; |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
57 origin.send(st.reply(stanza)); |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
58 else |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
59 return {"modify", "bad-request", "Neither default nor active list specifed to decline."}; |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
60 end |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
61 return true; |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
62 end |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
63 |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
64 function activateList(privacy_lists, origin, stanza, which, name) |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
65 local list = privacy_lists.lists[name]; |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
66 |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
67 if which == "default" and list then |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
68 if isAnotherSessionUsingDefaultList(origin) then |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
69 return {"cancel", "conflict", "Another session is online and using the default list."}; |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
70 end |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
71 privacy_lists.default = name; |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
72 origin.send(st.reply(stanza)); |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
73 elseif which == "active" and list then |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
74 origin.activePrivacyList = name; |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
75 origin.send(st.reply(stanza)); |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
76 elseif not list then |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
77 return {"cancel", "item-not-found", "No such list: "..name}; |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
78 else |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
79 return {"modify", "bad-request", "No list chosen to be active or default."}; |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
80 end |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
81 return true; |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
82 end |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
83 |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
84 function deleteList(privacy_lists, origin, stanza, name) |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
85 local list = privacy_lists.lists[name]; |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
86 |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
87 if list then |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
88 if isListUsed(origin, name, privacy_lists) then |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
89 return {"cancel", "conflict", "Another session is online and using the list which should be deleted."}; |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
90 end |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
91 if privacy_lists.default == name then |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
92 privacy_lists.default = nil; |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
93 end |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
94 if origin.activePrivacyList == name then |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
95 origin.activePrivacyList = nil; |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
96 end |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
97 privacy_lists.lists[name] = nil; |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
98 origin.send(st.reply(stanza)); |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
99 return true; |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
100 end |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
101 return {"modify", "bad-request", "Not existing list specifed to be deleted."}; |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
102 end |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
103 |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
104 function createOrReplaceList (privacy_lists, origin, stanza, name, entries) |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
105 local bare_jid = origin.username.."@"..origin.host; |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
106 |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
107 if privacy_lists.lists == nil then |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
108 privacy_lists.lists = {}; |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
109 end |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
110 |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
111 local list = {}; |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
112 privacy_lists.lists[name] = list; |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
113 |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
114 local orderCheck = {}; |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
115 list.name = name; |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
116 list.items = {}; |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
117 |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
118 for _,item in ipairs(entries) do |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
119 if to_number(item.attr.order) == nil or to_number(item.attr.order) < 0 or orderCheck[item.attr.order] ~= nil then |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
120 return {"modify", "bad-request", "Order attribute not valid."}; |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
121 end |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
122 |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
123 if item.attr.type ~= nil and item.attr.type ~= "jid" and item.attr.type ~= "subscription" and item.attr.type ~= "group" then |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
124 return {"modify", "bad-request", "Type attribute not valid."}; |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
125 end |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
126 |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
127 local tmp = {}; |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
128 orderCheck[item.attr.order] = true; |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
129 |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
130 tmp["type"] = item.attr.type; |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
131 tmp["value"] = item.attr.value; |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
132 tmp["action"] = item.attr.action; |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
133 tmp["order"] = to_number(item.attr.order); |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
134 tmp["presence-in"] = false; |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
135 tmp["presence-out"] = false; |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
136 tmp["message"] = false; |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
137 tmp["iq"] = false; |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
138 |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
139 if #item.tags > 0 then |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
140 for _,tag in ipairs(item.tags) do |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
141 tmp[tag.name] = true; |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
142 end |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
143 end |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
144 |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
145 if tmp.type == "subscription" then |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
146 if tmp.value ~= "both" and |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
147 tmp.value ~= "to" and |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
148 tmp.value ~= "from" and |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
149 tmp.value ~= "none" then |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
150 return {"cancel", "bad-request", "Subscription value must be both, to, from or none."}; |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
151 end |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
152 end |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
153 |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
154 if tmp.action ~= "deny" and tmp.action ~= "allow" then |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
155 return {"cancel", "bad-request", "Action must be either deny or allow."}; |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
156 end |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
157 list.items[#list.items + 1] = tmp; |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
158 end |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
159 |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
160 table.sort(list, function(a, b) return a.order < b.order; end); |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
161 |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
162 origin.send(st.reply(stanza)); |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
163 if bare_sessions[bare_jid] ~= nil then |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
164 local iq = st.iq ( { type = "set", id="push1" } ); |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
165 iq:tag ("query", { xmlns = "jabber:iq:privacy" } ); |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
166 iq:tag ("list", { name = list.name } ):up(); |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
167 iq:up(); |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
168 for resource, session in pairs(bare_sessions[bare_jid].sessions) do |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
169 iq.attr.to = bare_jid.."/"..resource |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
170 session.send(iq); |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
171 end |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
172 else |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
173 return {"cancel", "bad-request", "internal error."}; |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
174 end |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
175 return true; |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
176 end |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
177 |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
178 function getList(privacy_lists, origin, stanza, name) |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
179 local reply = st.reply(stanza); |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
180 reply:tag("query", {xmlns="jabber:iq:privacy"}); |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
181 |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
182 if name == nil then |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
183 if privacy_lists.lists then |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
184 if origin.activePrivacyList then |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
185 reply:tag("active", {name=origin.activePrivacyList}):up(); |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
186 end |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
187 if privacy_lists.default then |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
188 reply:tag("default", {name=privacy_lists.default}):up(); |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
189 end |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
190 for name,list in pairs(privacy_lists.lists) do |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
191 reply:tag("list", {name=name}):up(); |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
192 end |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
193 end |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
194 else |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
195 local list = privacy_lists.lists[name]; |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
196 if list then |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
197 reply = reply:tag("list", {name=list.name}); |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
198 for _,item in ipairs(list.items) do |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
199 reply:tag("item", {type=item.type, value=item.value, action=item.action, order=item.order}); |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
200 if item["message"] then reply:tag("message"):up(); end |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
201 if item["iq"] then reply:tag("iq"):up(); end |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
202 if item["presence-in"] then reply:tag("presence-in"):up(); end |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
203 if item["presence-out"] then reply:tag("presence-out"):up(); end |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
204 reply:up(); |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
205 end |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
206 else |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
207 return {"cancel", "item-not-found", "Unknown list specified."}; |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
208 end |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
209 end |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
210 |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
211 origin.send(reply); |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
212 return true; |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
213 end |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
214 |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
215 module:hook("iq/bare/jabber:iq:privacy:query", function(data) |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
216 local origin, stanza = data.origin, data.stanza; |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
217 |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
218 if stanza.attr.to == nil then -- only service requests to own bare JID |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
219 local query = stanza.tags[1]; -- the query element |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
220 local valid = false; |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
221 local privacy_lists = privacy_storage:get(origin.username) or { lists = {} }; |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
222 |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
223 if privacy_lists.lists[1] then -- Code to migrate from old privacy lists format, remove in 0.8 |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
224 module:log("info", "Upgrading format of stored privacy lists for %s@%s", origin.username, origin.host); |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
225 local lists = privacy_lists.lists; |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
226 for idx, list in ipairs(lists) do |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
227 lists[list.name] = list; |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
228 lists[idx] = nil; |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
229 end |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
230 end |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
231 |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
232 if stanza.attr.type == "set" then |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
233 if #query.tags == 1 then -- the <query/> element MUST NOT include more than one child element |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
234 for _,tag in ipairs(query.tags) do |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
235 if tag.name == "active" or tag.name == "default" then |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
236 if tag.attr.name == nil then -- Client declines the use of active / default list |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
237 valid = declineList(privacy_lists, origin, stanza, tag.name); |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
238 else -- Client requests change of active / default list |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
239 valid = activateList(privacy_lists, origin, stanza, tag.name, tag.attr.name); |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
240 end |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
241 elseif tag.name == "list" and tag.attr.name then -- Client adds / edits a privacy list |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
242 if #tag.tags == 0 then -- Client removes a privacy list |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
243 valid = deleteList(privacy_lists, origin, stanza, tag.attr.name); |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
244 else -- Client edits a privacy list |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
245 valid = createOrReplaceList(privacy_lists, origin, stanza, tag.attr.name, tag.tags); |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
246 end |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
247 end |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
248 end |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
249 end |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
250 elseif stanza.attr.type == "get" then |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
251 local name = nil; |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
252 local listsToRetrieve = 0; |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
253 if #query.tags >= 1 then |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
254 for _,tag in ipairs(query.tags) do |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
255 if tag.name == "list" then -- Client requests a privacy list from server |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
256 name = tag.attr.name; |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
257 listsToRetrieve = listsToRetrieve + 1; |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
258 end |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
259 end |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
260 end |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
261 if listsToRetrieve == 0 or listsToRetrieve == 1 then |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
262 valid = getList(privacy_lists, origin, stanza, name); |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
263 end |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
264 end |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
265 |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
266 if valid ~= true then |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
267 valid = valid or { "cancel", "bad-request", "Couldn't understand request" }; |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
268 if valid[1] == nil then |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
269 valid[1] = "cancel"; |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
270 end |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
271 if valid[2] == nil then |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
272 valid[2] = "bad-request"; |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
273 end |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
274 origin.send(st.error_reply(stanza, valid[1], valid[2], valid[3])); |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
275 else |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
276 privacy_storage:set(origin.username, privacy_lists); |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
277 end |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
278 return true; |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
279 end |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
280 end); |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
281 |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
282 function checkIfNeedToBeBlocked(e, session) |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
283 local origin, stanza = e.origin, e.stanza; |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
284 local privacy_lists = privacy_storage:get(session.username) or {}; |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
285 local bare_jid = session.username.."@"..session.host; |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
286 local to = stanza.attr.to or bare_jid; |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
287 local from = stanza.attr.from; |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
288 |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
289 local is_to_user = bare_jid == jid_bare(to); |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
290 local is_from_user = bare_jid == jid_bare(from); |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
291 |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
292 --module:log("debug", "stanza: %s, to: %s, from: %s", tostring(stanza.name), tostring(to), tostring(from)); |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
293 |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
294 if privacy_lists.lists == nil or |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
295 not (session.activePrivacyList or privacy_lists.default) |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
296 then |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
297 return; -- Nothing to block, default is Allow all |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
298 end |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
299 if is_from_user and is_to_user then |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
300 --module:log("debug", "Not blocking communications between user's resources"); |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
301 return; -- from one of a user's resource to another => HANDS OFF! |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
302 end |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
303 |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
304 local listname = session.activePrivacyList; |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
305 if listname == nil then |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
306 listname = privacy_lists.default; -- no active list selected, use default list |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
307 end |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
308 local list = privacy_lists.lists[listname]; |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
309 if not list then -- should never happen |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
310 module:log("warn", "given privacy list not found. name: %s for user %s", listname, bare_jid); |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
311 return; |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
312 end |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
313 for _,item in ipairs(list.items) do |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
314 local apply = false; |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
315 local block = false; |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
316 if ( |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
317 (stanza.name == "message" and item.message) or |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
318 (stanza.name == "iq" and item.iq) or |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
319 (stanza.name == "presence" and is_to_user and item["presence-in"]) or |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
320 (stanza.name == "presence" and is_from_user and item["presence-out"]) or |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
321 (item.message == false and item.iq == false and item["presence-in"] == false and item["presence-out"] == false) |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
322 ) then |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
323 apply = true; |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
324 end |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
325 if apply then |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
326 local evilJid = {}; |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
327 apply = false; |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
328 if is_to_user then |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
329 --module:log("debug", "evil jid is (from): %s", from); |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
330 evilJid.node, evilJid.host, evilJid.resource = jid_split(from); |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
331 else |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
332 --module:log("debug", "evil jid is (to): %s", to); |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
333 evilJid.node, evilJid.host, evilJid.resource = jid_split(to); |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
334 end |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
335 if item.type == "jid" and |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
336 (evilJid.node and evilJid.host and evilJid.resource and item.value == evilJid.node.."@"..evilJid.host.."/"..evilJid.resource) or |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
337 (evilJid.node and evilJid.host and item.value == evilJid.node.."@"..evilJid.host) or |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
338 (evilJid.host and evilJid.resource and item.value == evilJid.host.."/"..evilJid.resource) or |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
339 (evilJid.host and item.value == evilJid.host) then |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
340 apply = true; |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
341 block = (item.action == "deny"); |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
342 elseif item.type == "group" then |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
343 local roster = load_roster(session.username, session.host); |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
344 local roster_entry = roster[jid_join(evilJid.node, evilJid.host)]; |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
345 if roster_entry then |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
346 local groups = roster_entry.groups; |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
347 for group in pairs(groups) do |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
348 if group == item.value then |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
349 apply = true; |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
350 block = (item.action == "deny"); |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
351 break; |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
352 end |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
353 end |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
354 end |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
355 elseif item.type == "subscription" then -- we need a valid bare evil jid |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
356 local roster = load_roster(session.username, session.host); |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
357 local roster_entry = roster[jid_join(evilJid.node, evilJid.host)]; |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
358 if (not(roster_entry) and item.value == "none") |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
359 or (roster_entry and roster_entry.subscription == item.value) then |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
360 apply = true; |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
361 block = (item.action == "deny"); |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
362 end |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
363 elseif item.type == nil then |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
364 apply = true; |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
365 block = (item.action == "deny"); |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
366 end |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
367 end |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
368 if apply then |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
369 if block then |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
370 -- drop and not bounce groupchat messages, otherwise users will get kicked |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
371 if stanza.attr.type == "groupchat" then |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
372 return true; |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
373 end |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
374 module:log("debug", "stanza blocked: %s, to: %s, from: %s", tostring(stanza.name), tostring(to), tostring(from)); |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
375 if stanza.name == "message" then |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
376 origin.send(st.error_reply(stanza, "cancel", "service-unavailable")); |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
377 elseif stanza.name == "iq" and (stanza.attr.type == "get" or stanza.attr.type == "set") then |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
378 origin.send(st.error_reply(stanza, "cancel", "service-unavailable")); |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
379 end |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
380 return true; -- stanza blocked ! |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
381 else |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
382 --module:log("debug", "stanza explicitly allowed!") |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
383 return; |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
384 end |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
385 end |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
386 end |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
387 end |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
388 |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
389 function preCheckIncoming(e) |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
390 local session; |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
391 if e.stanza.attr.to ~= nil then |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
392 local node, host, resource = jid_split(e.stanza.attr.to); |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
393 if node == nil or host == nil then |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
394 return; |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
395 end |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
396 if resource == nil then |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
397 local prio = 0; |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
398 if bare_sessions[node.."@"..host] ~= nil then |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
399 for resource, session_ in pairs(bare_sessions[node.."@"..host].sessions) do |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
400 if session_.priority ~= nil and session_.priority > prio then |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
401 session = session_; |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
402 prio = session_.priority; |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
403 end |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
404 end |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
405 end |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
406 else |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
407 session = full_sessions[node.."@"..host.."/"..resource]; |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
408 end |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
409 if session ~= nil then |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
410 return checkIfNeedToBeBlocked(e, session); |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
411 else |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
412 --module:log("debug", "preCheckIncoming: Couldn't get session for jid: %s@%s/%s", tostring(node), tostring(host), tostring(resource)); |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
413 end |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
414 end |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
415 end |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
416 |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
417 function preCheckOutgoing(e) |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
418 local session = e.origin; |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
419 if e.stanza.attr.from == nil then |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
420 e.stanza.attr.from = session.username .. "@" .. session.host; |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
421 if session.resource ~= nil then |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
422 e.stanza.attr.from = e.stanza.attr.from .. "/" .. session.resource; |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
423 end |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
424 end |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
425 if session.username then -- FIXME do properly |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
426 return checkIfNeedToBeBlocked(e, session); |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
427 end |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
428 end |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
429 |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
430 module:hook("pre-message/full", preCheckOutgoing, 500); |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
431 module:hook("pre-message/bare", preCheckOutgoing, 500); |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
432 module:hook("pre-message/host", preCheckOutgoing, 500); |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
433 module:hook("pre-iq/full", preCheckOutgoing, 500); |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
434 module:hook("pre-iq/bare", preCheckOutgoing, 500); |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
435 module:hook("pre-iq/host", preCheckOutgoing, 500); |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
436 module:hook("pre-presence/full", preCheckOutgoing, 500); |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
437 module:hook("pre-presence/bare", preCheckOutgoing, 500); |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
438 module:hook("pre-presence/host", preCheckOutgoing, 500); |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
439 |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
440 module:hook("message/full", preCheckIncoming, 500); |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
441 module:hook("message/bare", preCheckIncoming, 500); |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
442 module:hook("message/host", preCheckIncoming, 500); |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
443 module:hook("iq/full", preCheckIncoming, 500); |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
444 module:hook("iq/bare", preCheckIncoming, 500); |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
445 module:hook("iq/host", preCheckIncoming, 500); |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
446 module:hook("presence/full", preCheckIncoming, 500); |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
447 module:hook("presence/bare", preCheckIncoming, 500); |
d4233dce479f
mod_privacy_lists: Import mod_privacy from 0.9
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
448 module:hook("presence/host", preCheckIncoming, 500); |