Software /
code /
prosody
Annotate
plugins/mod_privacy.lua @ 2586:26ead5e16cd3
loggingmanager: Trailing whitespace
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Thu, 11 Feb 2010 11:04:26 +0000 |
parent | 2579:4e0caff152d6 |
child | 2588:741302471a23 |
rev | line source |
---|---|
1522
569d58d21612
Add copyright header to those files missing one
Matthew Wild <mwild1@gmail.com>
parents:
1293
diff
changeset
|
1 -- Prosody IM |
569d58d21612
Add copyright header to those files missing one
Matthew Wild <mwild1@gmail.com>
parents:
1293
diff
changeset
|
2 -- Copyright (C) 2008-2009 Matthew Wild |
569d58d21612
Add copyright header to those files missing one
Matthew Wild <mwild1@gmail.com>
parents:
1293
diff
changeset
|
3 -- Copyright (C) 2008-2009 Waqas Hussain |
2496
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
4 -- Copyright (C) 2009 Thilo Cestonaro |
1522
569d58d21612
Add copyright header to those files missing one
Matthew Wild <mwild1@gmail.com>
parents:
1293
diff
changeset
|
5 -- |
569d58d21612
Add copyright header to those files missing one
Matthew Wild <mwild1@gmail.com>
parents:
1293
diff
changeset
|
6 -- This project is MIT/X11 licensed. Please see the |
569d58d21612
Add copyright header to those files missing one
Matthew Wild <mwild1@gmail.com>
parents:
1293
diff
changeset
|
7 -- COPYING file in the source package for more information. |
569d58d21612
Add copyright header to those files missing one
Matthew Wild <mwild1@gmail.com>
parents:
1293
diff
changeset
|
8 -- |
569d58d21612
Add copyright header to those files missing one
Matthew Wild <mwild1@gmail.com>
parents:
1293
diff
changeset
|
9 |
2496
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
10 local prosody = prosody; |
1293 | 11 local st = require "util.stanza"; |
12 local datamanager = require "util.datamanager"; | |
2498
3d08a6cf57ea
mod_privacy: Fixed global access.
Waqas Hussain <waqas20@gmail.com>
parents:
2496
diff
changeset
|
13 local bare_sessions, full_sessions = bare_sessions, full_sessions; |
2496
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
14 local util_Jid = require "util.jid"; |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
15 local jid_bare = util_Jid.bare; |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
16 local jid_split = util_Jid.split; |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
17 local load_roster = require "core.rostermanager".load_roster; |
2498
3d08a6cf57ea
mod_privacy: Fixed global access.
Waqas Hussain <waqas20@gmail.com>
parents:
2496
diff
changeset
|
18 local to_number = tonumber; |
2496
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
19 |
2500
bffdaeb7ab5e
mod_privacy: Cleaned up code.
Waqas Hussain <waqas20@gmail.com>
parents:
2499
diff
changeset
|
20 function findNamedList(privacy_lists, name) |
bffdaeb7ab5e
mod_privacy: Cleaned up code.
Waqas Hussain <waqas20@gmail.com>
parents:
2499
diff
changeset
|
21 if privacy_lists.lists then |
bffdaeb7ab5e
mod_privacy: Cleaned up code.
Waqas Hussain <waqas20@gmail.com>
parents:
2499
diff
changeset
|
22 for i=1,#privacy_lists.lists do |
bffdaeb7ab5e
mod_privacy: Cleaned up code.
Waqas Hussain <waqas20@gmail.com>
parents:
2499
diff
changeset
|
23 if privacy_lists.lists[i].name == name then |
bffdaeb7ab5e
mod_privacy: Cleaned up code.
Waqas Hussain <waqas20@gmail.com>
parents:
2499
diff
changeset
|
24 return i; |
bffdaeb7ab5e
mod_privacy: Cleaned up code.
Waqas Hussain <waqas20@gmail.com>
parents:
2499
diff
changeset
|
25 end |
2496
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
26 end |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
27 end |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
28 end |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
29 |
2500
bffdaeb7ab5e
mod_privacy: Cleaned up code.
Waqas Hussain <waqas20@gmail.com>
parents:
2499
diff
changeset
|
30 function isListUsed(origin, name, privacy_lists) |
bffdaeb7ab5e
mod_privacy: Cleaned up code.
Waqas Hussain <waqas20@gmail.com>
parents:
2499
diff
changeset
|
31 local user = bare_sessions[origin.username.."@"..origin.host]; |
bffdaeb7ab5e
mod_privacy: Cleaned up code.
Waqas Hussain <waqas20@gmail.com>
parents:
2499
diff
changeset
|
32 if user then |
bffdaeb7ab5e
mod_privacy: Cleaned up code.
Waqas Hussain <waqas20@gmail.com>
parents:
2499
diff
changeset
|
33 for resource, session in pairs(user.sessions) do |
2496
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
34 if resource ~= origin.resource then |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
35 if session.activePrivacyList == name then |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
36 return true; |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
37 elseif session.activePrivacyList == nil and privacy_lists.default == name then |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
38 return true; |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
39 end |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
40 end |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
41 end |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
42 end |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
43 end |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
44 |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
45 function isAnotherSessionUsingDefaultList(origin) |
2500
bffdaeb7ab5e
mod_privacy: Cleaned up code.
Waqas Hussain <waqas20@gmail.com>
parents:
2499
diff
changeset
|
46 local user = bare_sessions[origin.username.."@"..origin.host]; |
bffdaeb7ab5e
mod_privacy: Cleaned up code.
Waqas Hussain <waqas20@gmail.com>
parents:
2499
diff
changeset
|
47 if user then |
bffdaeb7ab5e
mod_privacy: Cleaned up code.
Waqas Hussain <waqas20@gmail.com>
parents:
2499
diff
changeset
|
48 for resource, session in pairs(user.sessions) do |
2496
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
49 if resource ~= origin.resource and session.activePrivacyList == nil then |
2500
bffdaeb7ab5e
mod_privacy: Cleaned up code.
Waqas Hussain <waqas20@gmail.com>
parents:
2499
diff
changeset
|
50 return true; |
2496
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
51 end |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
52 end |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
53 end |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
54 end |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
55 |
2498
3d08a6cf57ea
mod_privacy: Fixed global access.
Waqas Hussain <waqas20@gmail.com>
parents:
2496
diff
changeset
|
56 function sendUnavailable(origin, to, from) |
2496
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
57 --[[ example unavailable presence stanza |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
58 <presence from="node@host/resource" type="unavailable" to="node@host" > |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
59 <status>Logged out</status> |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
60 </presence> |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
61 ]]-- |
2500
bffdaeb7ab5e
mod_privacy: Cleaned up code.
Waqas Hussain <waqas20@gmail.com>
parents:
2499
diff
changeset
|
62 local presence = st.presence({from=from, type="unavailable"}); |
2496
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
63 presence:tag("status"):text("Logged out"); |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
64 |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
65 local node, host = jid_bare(to); |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
66 local bare = node .. "@" .. host; |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
67 |
2500
bffdaeb7ab5e
mod_privacy: Cleaned up code.
Waqas Hussain <waqas20@gmail.com>
parents:
2499
diff
changeset
|
68 local user = bare_sessions[bare]; |
bffdaeb7ab5e
mod_privacy: Cleaned up code.
Waqas Hussain <waqas20@gmail.com>
parents:
2499
diff
changeset
|
69 if user then |
bffdaeb7ab5e
mod_privacy: Cleaned up code.
Waqas Hussain <waqas20@gmail.com>
parents:
2499
diff
changeset
|
70 for resource, session in pairs(user.sessions) do |
2496
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
71 presence.attr.to = session.full_jid; |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
72 module:log("debug", "send unavailable to: %s; from: %s", tostring(presence.attr.to), tostring(presence.attr.from)); |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
73 origin.send(presence); |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
74 end |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
75 end |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
76 end |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
77 |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
78 function sendNeededUnavailablePersences(origin, listnameOrItem) -- TODO implement it correctly! |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
79 if type(listnameOrItem) == "string" then |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
80 local listname = listnameOrItem; |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
81 for _,list in ipairs(privacy_lists.lists) do |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
82 if list.name == listname then |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
83 for _,item in ipairs(list.items) do |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
84 sendNeededUnavailablePersences(origin, item); |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
85 end |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
86 end |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
87 end |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
88 elseif type(listnameOrItem) == "table" then |
2524
b427f5401ce7
mod_privacy: A handful of logging fixes
Matthew Wild <mwild1@gmail.com>
parents:
2523
diff
changeset
|
89 module:log("debug", "got an item, check whether to send unavailable presence stanza or not"); |
2496
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
90 local item = listnameOrItem; |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
91 |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
92 if item["presence-out"] == true then |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
93 if item.type == "jid" then |
2498
3d08a6cf57ea
mod_privacy: Fixed global access.
Waqas Hussain <waqas20@gmail.com>
parents:
2496
diff
changeset
|
94 sendUnavailable(origin, item.value, origin.full_jid); |
2496
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
95 elseif item.type == "group" then |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
96 elseif item.type == "subscription" then |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
97 elseif item.type == nil then |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
98 end |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
99 elseif item["presence-in"] == true then |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
100 if item.type == "jid" then |
2498
3d08a6cf57ea
mod_privacy: Fixed global access.
Waqas Hussain <waqas20@gmail.com>
parents:
2496
diff
changeset
|
101 sendUnavailable(origin, origin.full_jid, item.value); |
2496
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
102 elseif item.type == "group" then |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
103 elseif item.type == "subscription" then |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
104 elseif item.type == nil then |
2516
68a889016a46
mod_privacy: Trailing whitespace (I can't sleep)
Matthew Wild <mwild1@gmail.com>
parents:
2502
diff
changeset
|
105 end |
2496
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
106 end |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
107 else |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
108 module:log("debug", "got unknown type: %s", type(listnameOrItem)); |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
109 end |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
110 end |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
111 |
2500
bffdaeb7ab5e
mod_privacy: Cleaned up code.
Waqas Hussain <waqas20@gmail.com>
parents:
2499
diff
changeset
|
112 function declineList(privacy_lists, origin, stanza, which) |
2496
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
113 if which == "default" then |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
114 if isAnotherSessionUsingDefaultList(origin) then |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
115 return { "cancel", "conflict", "Another session is online and using the default list."}; |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
116 end |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
117 privacy_lists.default = nil; |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
118 origin.send(st.reply(stanza)); |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
119 elseif which == "active" then |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
120 origin.activePrivacyList = nil; |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
121 origin.send(st.reply(stanza)); |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
122 else |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
123 return {"modify", "bad-request", "Neither default nor active list specifed to decline."}; |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
124 end |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
125 return true; |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
126 end |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
127 |
2500
bffdaeb7ab5e
mod_privacy: Cleaned up code.
Waqas Hussain <waqas20@gmail.com>
parents:
2499
diff
changeset
|
128 function activateList(privacy_lists, origin, stanza, which, name) |
2496
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
129 local idx = findNamedList(privacy_lists, name); |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
130 |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
131 if privacy_lists.default == nil then |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
132 privacy_lists.default = ""; |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
133 end |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
134 if origin.activePrivacyList == nil then |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
135 origin.activePrivacyList = ""; |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
136 end |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
137 |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
138 if which == "default" and idx ~= nil then |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
139 if isAnotherSessionUsingDefaultList(origin) then |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
140 return {"cancel", "conflict", "Another session is online and using the default list."}; |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
141 end |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
142 privacy_lists.default = name; |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
143 origin.send(st.reply(stanza)); |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
144 --[[ |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
145 if origin.activePrivacyList == nil then |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
146 sendNeededUnavailablePersences(origin, name); |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
147 end |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
148 ]]-- |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
149 elseif which == "active" and idx ~= nil then |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
150 origin.activePrivacyList = name; |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
151 origin.send(st.reply(stanza)); |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
152 -- sendNeededUnavailablePersences(origin, name); |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
153 else |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
154 return {"modify", "bad-request", "Either not active or default given or unknown list name specified."}; |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
155 end |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
156 return true; |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
157 end |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
158 |
2500
bffdaeb7ab5e
mod_privacy: Cleaned up code.
Waqas Hussain <waqas20@gmail.com>
parents:
2499
diff
changeset
|
159 function deleteList(privacy_lists, origin, stanza, name) |
2496
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
160 local idx = findNamedList(privacy_lists, name); |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
161 |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
162 if idx ~= nil then |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
163 if isListUsed(origin, name, privacy_lists) then |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
164 return {"cancel", "conflict", "Another session is online and using the list which should be deleted."}; |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
165 end |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
166 if privacy_lists.default == name then |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
167 privacy_lists.default = ""; |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
168 end |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
169 if origin.activePrivacyList == name then |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
170 origin.activePrivacyList = ""; |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
171 end |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
172 table.remove(privacy_lists.lists, idx); |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
173 origin.send(st.reply(stanza)); |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
174 return true; |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
175 end |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
176 return {"modify", "bad-request", "Not existing list specifed to be deleted."}; |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
177 end |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
178 |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
179 function createOrReplaceList (privacy_lists, origin, stanza, name, entries, roster) |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
180 local idx = findNamedList(privacy_lists, name); |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
181 local bare_jid = origin.username.."@"..origin.host; |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
182 |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
183 if privacy_lists.lists == nil then |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
184 privacy_lists.lists = {}; |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
185 end |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
186 |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
187 if idx == nil then |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
188 idx = #privacy_lists.lists + 1; |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
189 end |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
190 |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
191 local orderCheck = {}; |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
192 local list = {}; |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
193 list.name = name; |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
194 list.items = {}; |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
195 |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
196 for _,item in ipairs(entries) do |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
197 if to_number(item.attr.order) == nil or to_number(item.attr.order) < 0 or orderCheck[item.attr.order] ~= nil then |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
198 return {"modify", "bad-request", "Order attribute not valid."}; |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
199 end |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
200 |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
201 if item.attr.type ~= nil and item.attr.type ~= "jid" and item.attr.type ~= "subscription" and item.attr.type ~= "group" then |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
202 return {"modify", "bad-request", "Type attribute not valid."}; |
2516
68a889016a46
mod_privacy: Trailing whitespace (I can't sleep)
Matthew Wild <mwild1@gmail.com>
parents:
2502
diff
changeset
|
203 end |
2496
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
204 |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
205 local tmp = {}; |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
206 orderCheck[item.attr.order] = true; |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
207 |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
208 tmp["type"] = item.attr.type; |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
209 tmp["value"] = item.attr.value; |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
210 tmp["action"] = item.attr.action; |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
211 tmp["order"] = to_number(item.attr.order); |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
212 tmp["presence-in"] = false; |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
213 tmp["presence-out"] = false; |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
214 tmp["message"] = false; |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
215 tmp["iq"] = false; |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
216 |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
217 if #item.tags > 0 then |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
218 for _,tag in ipairs(item.tags) do |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
219 tmp[tag.name] = true; |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
220 end |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
221 end |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
222 |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
223 if tmp.type == "group" then |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
224 local found = false; |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
225 local roster = load_roster(origin.username, origin.host); |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
226 for jid,item in pairs(roster) do |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
227 if item.groups ~= nil then |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
228 for group in pairs(item.groups) do |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
229 if group == tmp.value then |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
230 found = true; |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
231 break; |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
232 end |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
233 end |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
234 if found == true then |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
235 break; |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
236 end |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
237 end |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
238 end |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
239 if found == false then |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
240 return {"cancel", "item-not-found", "Specifed roster group not existing."}; |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
241 end |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
242 elseif tmp.type == "subscription" then |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
243 if tmp.value ~= "both" and |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
244 tmp.value ~= "to" and |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
245 tmp.value ~= "from" and |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
246 tmp.value ~= "none" then |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
247 return {"cancel", "bad-request", "Subscription value must be both, to, from or none."}; |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
248 end |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
249 end |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
250 |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
251 if tmp.action ~= "deny" and tmp.action ~= "allow" then |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
252 return {"cancel", "bad-request", "Action must be either deny or allow."}; |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
253 end |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
254 |
2516
68a889016a46
mod_privacy: Trailing whitespace (I can't sleep)
Matthew Wild <mwild1@gmail.com>
parents:
2502
diff
changeset
|
255 --[[ |
2496
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
256 if (privacy_lists.default == name and origin.activePrivacyList == nil) or origin.activePrivacyList == name then |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
257 module:log("debug", "calling sendNeededUnavailablePresences!"); |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
258 -- item is valid and list is active, so send needed unavailable stanzas |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
259 sendNeededUnavailablePersences(origin, tmp); |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
260 end |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
261 ]]-- |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
262 list.items[#list.items + 1] = tmp; |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
263 end |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
264 |
2499
145d62abdbfc
mod_privacy: Reduced a function.
Waqas Hussain <waqas20@gmail.com>
parents:
2498
diff
changeset
|
265 table.sort(list, function(a, b) return a.order < b.order; end); |
2496
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
266 |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
267 privacy_lists.lists[idx] = list; |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
268 origin.send(st.reply(stanza)); |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
269 if bare_sessions[bare_jid] ~= nil then |
2498
3d08a6cf57ea
mod_privacy: Fixed global access.
Waqas Hussain <waqas20@gmail.com>
parents:
2496
diff
changeset
|
270 local iq = st.iq ( { type = "set", id="push1" } ); |
2496
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
271 iq:tag ("query", { xmlns = "jabber:iq:privacy" } ); |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
272 iq:tag ("list", { name = list.name } ):up(); |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
273 iq:up(); |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
274 for resource, session in pairs(bare_sessions[bare_jid].sessions) do |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
275 iq.attr.to = bare_jid.."/"..resource |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
276 session.send(iq); |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
277 end |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
278 else |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
279 return {"cancel", "bad-request", "internal error."}; |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
280 end |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
281 return true; |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
282 end |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
283 |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
284 function getList(privacy_lists, origin, stanza, name) |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
285 local reply = st.reply(stanza); |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
286 reply:tag("query", {xmlns="jabber:iq:privacy"}); |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
287 |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
288 if name == nil then |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
289 reply:tag("active", {name=origin.activePrivacyList or ""}):up(); |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
290 reply:tag("default", {name=privacy_lists.default or ""}):up(); |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
291 if privacy_lists.lists then |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
292 for _,list in ipairs(privacy_lists.lists) do |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
293 reply:tag("list", {name=list.name}):up(); |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
294 end |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
295 end |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
296 else |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
297 local idx = findNamedList(privacy_lists, name); |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
298 if idx ~= nil then |
2498
3d08a6cf57ea
mod_privacy: Fixed global access.
Waqas Hussain <waqas20@gmail.com>
parents:
2496
diff
changeset
|
299 local list = privacy_lists.lists[idx]; |
2496
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
300 reply = reply:tag("list", {name=list.name}); |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
301 for _,item in ipairs(list.items) do |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
302 reply:tag("item", {type=item.type, value=item.value, action=item.action, order=item.order}); |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
303 if item["message"] then reply:tag("message"):up(); end |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
304 if item["iq"] then reply:tag("iq"):up(); end |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
305 if item["presence-in"] then reply:tag("presence-in"):up(); end |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
306 if item["presence-out"] then reply:tag("presence-out"):up(); end |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
307 reply:up(); |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
308 end |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
309 else |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
310 return {"cancel", "item-not-found", "Unknown list specified."}; |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
311 end |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
312 end |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
313 |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
314 origin.send(reply); |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
315 return true; |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
316 end |
1293 | 317 |
318 module:hook("iq/bare/jabber:iq:privacy:query", function(data) | |
319 local origin, stanza = data.origin, data.stanza; | |
320 | |
2496
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
321 if stanza.attr.to == nil then -- only service requests to own bare JID |
1293 | 322 local query = stanza.tags[1]; -- the query element |
2496
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
323 local valid = false; |
1293 | 324 local privacy_lists = datamanager.load(origin.username, origin.host, "privacy") or {}; |
2496
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
325 |
1293 | 326 if stanza.attr.type == "set" then |
2516
68a889016a46
mod_privacy: Trailing whitespace (I can't sleep)
Matthew Wild <mwild1@gmail.com>
parents:
2502
diff
changeset
|
327 if #query.tags == 1 then -- the <query/> element MUST NOT include more than one child element |
2496
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
328 for _,tag in ipairs(query.tags) do |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
329 if tag.name == "active" or tag.name == "default" then |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
330 if tag.attr.name == nil then -- Client declines the use of active / default list |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
331 valid = declineList(privacy_lists, origin, stanza, tag.name); |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
332 else -- Client requests change of active / default list |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
333 valid = activateList(privacy_lists, origin, stanza, tag.name, tag.attr.name); |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
334 end |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
335 elseif tag.name == "list" and tag.attr.name then -- Client adds / edits a privacy list |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
336 if #tag.tags == 0 then -- Client removes a privacy list |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
337 valid = deleteList(privacy_lists, origin, stanza, tag.attr.name); |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
338 else -- Client edits a privacy list |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
339 valid = createOrReplaceList(privacy_lists, origin, stanza, tag.attr.name, tag.tags); |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
340 end |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
341 end |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
342 end |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
343 end |
1293 | 344 elseif stanza.attr.type == "get" then |
2496
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
345 local name = nil; |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
346 local listsToRetrieve = 0; |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
347 if #query.tags >= 1 then |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
348 for _,tag in ipairs(query.tags) do |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
349 if tag.name == "list" then -- Client requests a privacy list from server |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
350 name = tag.attr.name; |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
351 listsToRetrieve = listsToRetrieve + 1; |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
352 end |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
353 end |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
354 end |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
355 if listsToRetrieve == 0 or listsToRetrieve == 1 then |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
356 valid = getList(privacy_lists, origin, stanza, name); |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
357 end |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
358 end |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
359 |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
360 if valid ~= true then |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
361 if valid[0] == nil then |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
362 valid[0] = "cancel"; |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
363 end |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
364 if valid[1] == nil then |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
365 valid[1] = "bad-request"; |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
366 end |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
367 origin.send(st.error_reply(stanza, valid[0], valid[1], valid[2])); |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
368 else |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
369 datamanager.store(origin.username, origin.host, "privacy", privacy_lists); |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
370 end |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
371 return true; |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
372 end |
2500
bffdaeb7ab5e
mod_privacy: Cleaned up code.
Waqas Hussain <waqas20@gmail.com>
parents:
2499
diff
changeset
|
373 end); |
2496
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
374 |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
375 function checkIfNeedToBeBlocked(e, session) |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
376 local origin, stanza = e.origin, e.stanza; |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
377 local privacy_lists = datamanager.load(session.username, session.host, "privacy") or {}; |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
378 local bare_jid = session.username.."@"..session.host; |
2523
0c816b271208
mod_privacy: Remove the giant if/end block that was really causing problems - skipping stanzas with no to/from (like presence broadcast). Also optimised the code a *lot*, these changes untested at the moment though.
Matthew Wild <mwild1@gmail.com>
parents:
2522
diff
changeset
|
379 local to = stanza.attr.to; |
0c816b271208
mod_privacy: Remove the giant if/end block that was really causing problems - skipping stanzas with no to/from (like presence broadcast). Also optimised the code a *lot*, these changes untested at the moment though.
Matthew Wild <mwild1@gmail.com>
parents:
2522
diff
changeset
|
380 local from = stanza.attr.from; |
0c816b271208
mod_privacy: Remove the giant if/end block that was really causing problems - skipping stanzas with no to/from (like presence broadcast). Also optimised the code a *lot*, these changes untested at the moment though.
Matthew Wild <mwild1@gmail.com>
parents:
2522
diff
changeset
|
381 |
2579
4e0caff152d6
mod_privacy: Rename from_user/to_user flags to is_from_user/is_to_user for clarity
Matthew Wild <mwild1@gmail.com>
parents:
2524
diff
changeset
|
382 local is_to_user = bare_jid == jid_bare(to); |
4e0caff152d6
mod_privacy: Rename from_user/to_user flags to is_from_user/is_to_user for clarity
Matthew Wild <mwild1@gmail.com>
parents:
2524
diff
changeset
|
383 local is_from_user = bare_jid == jid_bare(from); |
2523
0c816b271208
mod_privacy: Remove the giant if/end block that was really causing problems - skipping stanzas with no to/from (like presence broadcast). Also optimised the code a *lot*, these changes untested at the moment though.
Matthew Wild <mwild1@gmail.com>
parents:
2522
diff
changeset
|
384 |
0c816b271208
mod_privacy: Remove the giant if/end block that was really causing problems - skipping stanzas with no to/from (like presence broadcast). Also optimised the code a *lot*, these changes untested at the moment though.
Matthew Wild <mwild1@gmail.com>
parents:
2522
diff
changeset
|
385 module:log("debug", "stanza: %s, to: %s, from: %s", tostring(stanza.name), tostring(to), tostring(from)); |
0c816b271208
mod_privacy: Remove the giant if/end block that was really causing problems - skipping stanzas with no to/from (like presence broadcast). Also optimised the code a *lot*, these changes untested at the moment though.
Matthew Wild <mwild1@gmail.com>
parents:
2522
diff
changeset
|
386 |
0c816b271208
mod_privacy: Remove the giant if/end block that was really causing problems - skipping stanzas with no to/from (like presence broadcast). Also optimised the code a *lot*, these changes untested at the moment though.
Matthew Wild <mwild1@gmail.com>
parents:
2522
diff
changeset
|
387 if privacy_lists.lists == nil or |
0c816b271208
mod_privacy: Remove the giant if/end block that was really causing problems - skipping stanzas with no to/from (like presence broadcast). Also optimised the code a *lot*, these changes untested at the moment though.
Matthew Wild <mwild1@gmail.com>
parents:
2522
diff
changeset
|
388 (session.activePrivacyList == nil or session.activePrivacyList == "") and |
0c816b271208
mod_privacy: Remove the giant if/end block that was really causing problems - skipping stanzas with no to/from (like presence broadcast). Also optimised the code a *lot*, these changes untested at the moment though.
Matthew Wild <mwild1@gmail.com>
parents:
2522
diff
changeset
|
389 (privacy_lists.default == nil or privacy_lists.default == "") |
0c816b271208
mod_privacy: Remove the giant if/end block that was really causing problems - skipping stanzas with no to/from (like presence broadcast). Also optimised the code a *lot*, these changes untested at the moment though.
Matthew Wild <mwild1@gmail.com>
parents:
2522
diff
changeset
|
390 then |
0c816b271208
mod_privacy: Remove the giant if/end block that was really causing problems - skipping stanzas with no to/from (like presence broadcast). Also optimised the code a *lot*, these changes untested at the moment though.
Matthew Wild <mwild1@gmail.com>
parents:
2522
diff
changeset
|
391 return; -- Nothing to block, default is Allow all |
0c816b271208
mod_privacy: Remove the giant if/end block that was really causing problems - skipping stanzas with no to/from (like presence broadcast). Also optimised the code a *lot*, these changes untested at the moment though.
Matthew Wild <mwild1@gmail.com>
parents:
2522
diff
changeset
|
392 end |
2579
4e0caff152d6
mod_privacy: Rename from_user/to_user flags to is_from_user/is_to_user for clarity
Matthew Wild <mwild1@gmail.com>
parents:
2524
diff
changeset
|
393 if is_from_user and is_to_user then |
2524
b427f5401ce7
mod_privacy: A handful of logging fixes
Matthew Wild <mwild1@gmail.com>
parents:
2523
diff
changeset
|
394 module:log("debug", "Not blocking communications between user's resources"); |
2523
0c816b271208
mod_privacy: Remove the giant if/end block that was really causing problems - skipping stanzas with no to/from (like presence broadcast). Also optimised the code a *lot*, these changes untested at the moment though.
Matthew Wild <mwild1@gmail.com>
parents:
2522
diff
changeset
|
395 return; -- from one of a user's resource to another => HANDS OFF! |
0c816b271208
mod_privacy: Remove the giant if/end block that was really causing problems - skipping stanzas with no to/from (like presence broadcast). Also optimised the code a *lot*, these changes untested at the moment though.
Matthew Wild <mwild1@gmail.com>
parents:
2522
diff
changeset
|
396 end |
2496
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
397 |
2523
0c816b271208
mod_privacy: Remove the giant if/end block that was really causing problems - skipping stanzas with no to/from (like presence broadcast). Also optimised the code a *lot*, these changes untested at the moment though.
Matthew Wild <mwild1@gmail.com>
parents:
2522
diff
changeset
|
398 local idx; |
0c816b271208
mod_privacy: Remove the giant if/end block that was really causing problems - skipping stanzas with no to/from (like presence broadcast). Also optimised the code a *lot*, these changes untested at the moment though.
Matthew Wild <mwild1@gmail.com>
parents:
2522
diff
changeset
|
399 local list; |
0c816b271208
mod_privacy: Remove the giant if/end block that was really causing problems - skipping stanzas with no to/from (like presence broadcast). Also optimised the code a *lot*, these changes untested at the moment though.
Matthew Wild <mwild1@gmail.com>
parents:
2522
diff
changeset
|
400 local item; |
0c816b271208
mod_privacy: Remove the giant if/end block that was really causing problems - skipping stanzas with no to/from (like presence broadcast). Also optimised the code a *lot*, these changes untested at the moment though.
Matthew Wild <mwild1@gmail.com>
parents:
2522
diff
changeset
|
401 local listname = session.activePrivacyList; |
0c816b271208
mod_privacy: Remove the giant if/end block that was really causing problems - skipping stanzas with no to/from (like presence broadcast). Also optimised the code a *lot*, these changes untested at the moment though.
Matthew Wild <mwild1@gmail.com>
parents:
2522
diff
changeset
|
402 if listname == nil or listname == "" then |
0c816b271208
mod_privacy: Remove the giant if/end block that was really causing problems - skipping stanzas with no to/from (like presence broadcast). Also optimised the code a *lot*, these changes untested at the moment though.
Matthew Wild <mwild1@gmail.com>
parents:
2522
diff
changeset
|
403 listname = privacy_lists.default; -- no active list selected, use default list |
0c816b271208
mod_privacy: Remove the giant if/end block that was really causing problems - skipping stanzas with no to/from (like presence broadcast). Also optimised the code a *lot*, these changes untested at the moment though.
Matthew Wild <mwild1@gmail.com>
parents:
2522
diff
changeset
|
404 end |
0c816b271208
mod_privacy: Remove the giant if/end block that was really causing problems - skipping stanzas with no to/from (like presence broadcast). Also optimised the code a *lot*, these changes untested at the moment though.
Matthew Wild <mwild1@gmail.com>
parents:
2522
diff
changeset
|
405 idx = findNamedList(privacy_lists, listname); |
0c816b271208
mod_privacy: Remove the giant if/end block that was really causing problems - skipping stanzas with no to/from (like presence broadcast). Also optimised the code a *lot*, these changes untested at the moment though.
Matthew Wild <mwild1@gmail.com>
parents:
2522
diff
changeset
|
406 if idx == nil then |
2524
b427f5401ce7
mod_privacy: A handful of logging fixes
Matthew Wild <mwild1@gmail.com>
parents:
2523
diff
changeset
|
407 module:log("debug", "given privacy listname not found. name: %s", listname); |
2523
0c816b271208
mod_privacy: Remove the giant if/end block that was really causing problems - skipping stanzas with no to/from (like presence broadcast). Also optimised the code a *lot*, these changes untested at the moment though.
Matthew Wild <mwild1@gmail.com>
parents:
2522
diff
changeset
|
408 return; |
0c816b271208
mod_privacy: Remove the giant if/end block that was really causing problems - skipping stanzas with no to/from (like presence broadcast). Also optimised the code a *lot*, these changes untested at the moment though.
Matthew Wild <mwild1@gmail.com>
parents:
2522
diff
changeset
|
409 end |
0c816b271208
mod_privacy: Remove the giant if/end block that was really causing problems - skipping stanzas with no to/from (like presence broadcast). Also optimised the code a *lot*, these changes untested at the moment though.
Matthew Wild <mwild1@gmail.com>
parents:
2522
diff
changeset
|
410 list = privacy_lists.lists[idx]; |
0c816b271208
mod_privacy: Remove the giant if/end block that was really causing problems - skipping stanzas with no to/from (like presence broadcast). Also optimised the code a *lot*, these changes untested at the moment though.
Matthew Wild <mwild1@gmail.com>
parents:
2522
diff
changeset
|
411 if list == nil then |
2524
b427f5401ce7
mod_privacy: A handful of logging fixes
Matthew Wild <mwild1@gmail.com>
parents:
2523
diff
changeset
|
412 module:log("debug", "privacy list index wrong. index: %d", idx); |
2523
0c816b271208
mod_privacy: Remove the giant if/end block that was really causing problems - skipping stanzas with no to/from (like presence broadcast). Also optimised the code a *lot*, these changes untested at the moment though.
Matthew Wild <mwild1@gmail.com>
parents:
2522
diff
changeset
|
413 return; |
0c816b271208
mod_privacy: Remove the giant if/end block that was really causing problems - skipping stanzas with no to/from (like presence broadcast). Also optimised the code a *lot*, these changes untested at the moment though.
Matthew Wild <mwild1@gmail.com>
parents:
2522
diff
changeset
|
414 end |
0c816b271208
mod_privacy: Remove the giant if/end block that was really causing problems - skipping stanzas with no to/from (like presence broadcast). Also optimised the code a *lot*, these changes untested at the moment though.
Matthew Wild <mwild1@gmail.com>
parents:
2522
diff
changeset
|
415 for _,item in ipairs(list.items) do |
0c816b271208
mod_privacy: Remove the giant if/end block that was really causing problems - skipping stanzas with no to/from (like presence broadcast). Also optimised the code a *lot*, these changes untested at the moment though.
Matthew Wild <mwild1@gmail.com>
parents:
2522
diff
changeset
|
416 local apply = false; |
0c816b271208
mod_privacy: Remove the giant if/end block that was really causing problems - skipping stanzas with no to/from (like presence broadcast). Also optimised the code a *lot*, these changes untested at the moment though.
Matthew Wild <mwild1@gmail.com>
parents:
2522
diff
changeset
|
417 local block = false; |
0c816b271208
mod_privacy: Remove the giant if/end block that was really causing problems - skipping stanzas with no to/from (like presence broadcast). Also optimised the code a *lot*, these changes untested at the moment though.
Matthew Wild <mwild1@gmail.com>
parents:
2522
diff
changeset
|
418 if ( |
0c816b271208
mod_privacy: Remove the giant if/end block that was really causing problems - skipping stanzas with no to/from (like presence broadcast). Also optimised the code a *lot*, these changes untested at the moment though.
Matthew Wild <mwild1@gmail.com>
parents:
2522
diff
changeset
|
419 (stanza.name == "message" and item.message) or |
0c816b271208
mod_privacy: Remove the giant if/end block that was really causing problems - skipping stanzas with no to/from (like presence broadcast). Also optimised the code a *lot*, these changes untested at the moment though.
Matthew Wild <mwild1@gmail.com>
parents:
2522
diff
changeset
|
420 (stanza.name == "iq" and item.iq) or |
2579
4e0caff152d6
mod_privacy: Rename from_user/to_user flags to is_from_user/is_to_user for clarity
Matthew Wild <mwild1@gmail.com>
parents:
2524
diff
changeset
|
421 (stanza.name == "presence" and is_to_user and item["presence-in"]) or |
4e0caff152d6
mod_privacy: Rename from_user/to_user flags to is_from_user/is_to_user for clarity
Matthew Wild <mwild1@gmail.com>
parents:
2524
diff
changeset
|
422 (stanza.name == "presence" and is_from_user and item["presence-out"]) or |
2523
0c816b271208
mod_privacy: Remove the giant if/end block that was really causing problems - skipping stanzas with no to/from (like presence broadcast). Also optimised the code a *lot*, these changes untested at the moment though.
Matthew Wild <mwild1@gmail.com>
parents:
2522
diff
changeset
|
423 (item.message == false and item.iq == false and item["presence-in"] == false and item["presence-out"] == false) |
0c816b271208
mod_privacy: Remove the giant if/end block that was really causing problems - skipping stanzas with no to/from (like presence broadcast). Also optimised the code a *lot*, these changes untested at the moment though.
Matthew Wild <mwild1@gmail.com>
parents:
2522
diff
changeset
|
424 ) then |
0c816b271208
mod_privacy: Remove the giant if/end block that was really causing problems - skipping stanzas with no to/from (like presence broadcast). Also optimised the code a *lot*, these changes untested at the moment though.
Matthew Wild <mwild1@gmail.com>
parents:
2522
diff
changeset
|
425 apply = true; |
2496
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
426 end |
2523
0c816b271208
mod_privacy: Remove the giant if/end block that was really causing problems - skipping stanzas with no to/from (like presence broadcast). Also optimised the code a *lot*, these changes untested at the moment though.
Matthew Wild <mwild1@gmail.com>
parents:
2522
diff
changeset
|
427 if apply then |
0c816b271208
mod_privacy: Remove the giant if/end block that was really causing problems - skipping stanzas with no to/from (like presence broadcast). Also optimised the code a *lot*, these changes untested at the moment though.
Matthew Wild <mwild1@gmail.com>
parents:
2522
diff
changeset
|
428 local evilJid = {}; |
0c816b271208
mod_privacy: Remove the giant if/end block that was really causing problems - skipping stanzas with no to/from (like presence broadcast). Also optimised the code a *lot*, these changes untested at the moment though.
Matthew Wild <mwild1@gmail.com>
parents:
2522
diff
changeset
|
429 apply = false; |
2579
4e0caff152d6
mod_privacy: Rename from_user/to_user flags to is_from_user/is_to_user for clarity
Matthew Wild <mwild1@gmail.com>
parents:
2524
diff
changeset
|
430 if is_to_user then |
2523
0c816b271208
mod_privacy: Remove the giant if/end block that was really causing problems - skipping stanzas with no to/from (like presence broadcast). Also optimised the code a *lot*, these changes untested at the moment though.
Matthew Wild <mwild1@gmail.com>
parents:
2522
diff
changeset
|
431 module:log("debug", "evil jid is (from): %s", from); |
0c816b271208
mod_privacy: Remove the giant if/end block that was really causing problems - skipping stanzas with no to/from (like presence broadcast). Also optimised the code a *lot*, these changes untested at the moment though.
Matthew Wild <mwild1@gmail.com>
parents:
2522
diff
changeset
|
432 evilJid.node, evilJid.host, evilJid.resource = jid_split(from); |
0c816b271208
mod_privacy: Remove the giant if/end block that was really causing problems - skipping stanzas with no to/from (like presence broadcast). Also optimised the code a *lot*, these changes untested at the moment though.
Matthew Wild <mwild1@gmail.com>
parents:
2522
diff
changeset
|
433 else |
0c816b271208
mod_privacy: Remove the giant if/end block that was really causing problems - skipping stanzas with no to/from (like presence broadcast). Also optimised the code a *lot*, these changes untested at the moment though.
Matthew Wild <mwild1@gmail.com>
parents:
2522
diff
changeset
|
434 module:log("debug", "evil jid is (to): %s", to); |
0c816b271208
mod_privacy: Remove the giant if/end block that was really causing problems - skipping stanzas with no to/from (like presence broadcast). Also optimised the code a *lot*, these changes untested at the moment though.
Matthew Wild <mwild1@gmail.com>
parents:
2522
diff
changeset
|
435 evilJid.node, evilJid.host, evilJid.resource = jid_split(to); |
2496
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
436 end |
2523
0c816b271208
mod_privacy: Remove the giant if/end block that was really causing problems - skipping stanzas with no to/from (like presence broadcast). Also optimised the code a *lot*, these changes untested at the moment though.
Matthew Wild <mwild1@gmail.com>
parents:
2522
diff
changeset
|
437 if item.type == "jid" and |
0c816b271208
mod_privacy: Remove the giant if/end block that was really causing problems - skipping stanzas with no to/from (like presence broadcast). Also optimised the code a *lot*, these changes untested at the moment though.
Matthew Wild <mwild1@gmail.com>
parents:
2522
diff
changeset
|
438 (evilJid.node and evilJid.host and evilJid.resource and item.value == evilJid.node.."@"..evilJid.host.."/"..evilJid.resource) or |
0c816b271208
mod_privacy: Remove the giant if/end block that was really causing problems - skipping stanzas with no to/from (like presence broadcast). Also optimised the code a *lot*, these changes untested at the moment though.
Matthew Wild <mwild1@gmail.com>
parents:
2522
diff
changeset
|
439 (evilJid.node and evilJid.host and item.value == evilJid.node.."@"..evilJid.host) or |
0c816b271208
mod_privacy: Remove the giant if/end block that was really causing problems - skipping stanzas with no to/from (like presence broadcast). Also optimised the code a *lot*, these changes untested at the moment though.
Matthew Wild <mwild1@gmail.com>
parents:
2522
diff
changeset
|
440 (evilJid.host and evilJid.resource and item.value == evilJid.host.."/"..evilJid.resource) or |
0c816b271208
mod_privacy: Remove the giant if/end block that was really causing problems - skipping stanzas with no to/from (like presence broadcast). Also optimised the code a *lot*, these changes untested at the moment though.
Matthew Wild <mwild1@gmail.com>
parents:
2522
diff
changeset
|
441 (evilJid.host and item.value == evilJid.host) then |
0c816b271208
mod_privacy: Remove the giant if/end block that was really causing problems - skipping stanzas with no to/from (like presence broadcast). Also optimised the code a *lot*, these changes untested at the moment though.
Matthew Wild <mwild1@gmail.com>
parents:
2522
diff
changeset
|
442 apply = true; |
0c816b271208
mod_privacy: Remove the giant if/end block that was really causing problems - skipping stanzas with no to/from (like presence broadcast). Also optimised the code a *lot*, these changes untested at the moment though.
Matthew Wild <mwild1@gmail.com>
parents:
2522
diff
changeset
|
443 block = (item.action == "deny"); |
0c816b271208
mod_privacy: Remove the giant if/end block that was really causing problems - skipping stanzas with no to/from (like presence broadcast). Also optimised the code a *lot*, these changes untested at the moment though.
Matthew Wild <mwild1@gmail.com>
parents:
2522
diff
changeset
|
444 elseif item.type == "group" then |
0c816b271208
mod_privacy: Remove the giant if/end block that was really causing problems - skipping stanzas with no to/from (like presence broadcast). Also optimised the code a *lot*, these changes untested at the moment though.
Matthew Wild <mwild1@gmail.com>
parents:
2522
diff
changeset
|
445 local roster = load_roster(session.username, session.host); |
0c816b271208
mod_privacy: Remove the giant if/end block that was really causing problems - skipping stanzas with no to/from (like presence broadcast). Also optimised the code a *lot*, these changes untested at the moment though.
Matthew Wild <mwild1@gmail.com>
parents:
2522
diff
changeset
|
446 local groups = roster[evilJid.node .. "@" .. evilJid.host].groups; |
0c816b271208
mod_privacy: Remove the giant if/end block that was really causing problems - skipping stanzas with no to/from (like presence broadcast). Also optimised the code a *lot*, these changes untested at the moment though.
Matthew Wild <mwild1@gmail.com>
parents:
2522
diff
changeset
|
447 for group in pairs(groups) do |
0c816b271208
mod_privacy: Remove the giant if/end block that was really causing problems - skipping stanzas with no to/from (like presence broadcast). Also optimised the code a *lot*, these changes untested at the moment though.
Matthew Wild <mwild1@gmail.com>
parents:
2522
diff
changeset
|
448 if group == item.value then |
2496
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
449 apply = true; |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
450 block = (item.action == "deny"); |
2523
0c816b271208
mod_privacy: Remove the giant if/end block that was really causing problems - skipping stanzas with no to/from (like presence broadcast). Also optimised the code a *lot*, these changes untested at the moment though.
Matthew Wild <mwild1@gmail.com>
parents:
2522
diff
changeset
|
451 break; |
2496
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
452 end |
2523
0c816b271208
mod_privacy: Remove the giant if/end block that was really causing problems - skipping stanzas with no to/from (like presence broadcast). Also optimised the code a *lot*, these changes untested at the moment though.
Matthew Wild <mwild1@gmail.com>
parents:
2522
diff
changeset
|
453 end |
0c816b271208
mod_privacy: Remove the giant if/end block that was really causing problems - skipping stanzas with no to/from (like presence broadcast). Also optimised the code a *lot*, these changes untested at the moment though.
Matthew Wild <mwild1@gmail.com>
parents:
2522
diff
changeset
|
454 elseif item.type == "subscription" and evilJid.node ~= nil and evilJid.host ~= nil then -- we need a valid bare evil jid |
0c816b271208
mod_privacy: Remove the giant if/end block that was really causing problems - skipping stanzas with no to/from (like presence broadcast). Also optimised the code a *lot*, these changes untested at the moment though.
Matthew Wild <mwild1@gmail.com>
parents:
2522
diff
changeset
|
455 local roster = load_roster(session.username, session.host); |
0c816b271208
mod_privacy: Remove the giant if/end block that was really causing problems - skipping stanzas with no to/from (like presence broadcast). Also optimised the code a *lot*, these changes untested at the moment though.
Matthew Wild <mwild1@gmail.com>
parents:
2522
diff
changeset
|
456 if roster[evilJid.node .. "@" .. evilJid.host].subscription == item.value then |
2496
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
457 apply = true; |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
458 block = (item.action == "deny"); |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
459 end |
2523
0c816b271208
mod_privacy: Remove the giant if/end block that was really causing problems - skipping stanzas with no to/from (like presence broadcast). Also optimised the code a *lot*, these changes untested at the moment though.
Matthew Wild <mwild1@gmail.com>
parents:
2522
diff
changeset
|
460 elseif item.type == nil then |
0c816b271208
mod_privacy: Remove the giant if/end block that was really causing problems - skipping stanzas with no to/from (like presence broadcast). Also optimised the code a *lot*, these changes untested at the moment though.
Matthew Wild <mwild1@gmail.com>
parents:
2522
diff
changeset
|
461 apply = true; |
0c816b271208
mod_privacy: Remove the giant if/end block that was really causing problems - skipping stanzas with no to/from (like presence broadcast). Also optimised the code a *lot*, these changes untested at the moment though.
Matthew Wild <mwild1@gmail.com>
parents:
2522
diff
changeset
|
462 block = (item.action == "deny"); |
2496
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
463 end |
2523
0c816b271208
mod_privacy: Remove the giant if/end block that was really causing problems - skipping stanzas with no to/from (like presence broadcast). Also optimised the code a *lot*, these changes untested at the moment though.
Matthew Wild <mwild1@gmail.com>
parents:
2522
diff
changeset
|
464 end |
0c816b271208
mod_privacy: Remove the giant if/end block that was really causing problems - skipping stanzas with no to/from (like presence broadcast). Also optimised the code a *lot*, these changes untested at the moment though.
Matthew Wild <mwild1@gmail.com>
parents:
2522
diff
changeset
|
465 if apply then |
0c816b271208
mod_privacy: Remove the giant if/end block that was really causing problems - skipping stanzas with no to/from (like presence broadcast). Also optimised the code a *lot*, these changes untested at the moment though.
Matthew Wild <mwild1@gmail.com>
parents:
2522
diff
changeset
|
466 if block then |
2524
b427f5401ce7
mod_privacy: A handful of logging fixes
Matthew Wild <mwild1@gmail.com>
parents:
2523
diff
changeset
|
467 module:log("debug", "stanza blocked: %s, to: %s, from: %s", tostring(stanza.name), tostring(to), tostring(from)); |
2523
0c816b271208
mod_privacy: Remove the giant if/end block that was really causing problems - skipping stanzas with no to/from (like presence broadcast). Also optimised the code a *lot*, these changes untested at the moment though.
Matthew Wild <mwild1@gmail.com>
parents:
2522
diff
changeset
|
468 if stanza.name == "message" then |
0c816b271208
mod_privacy: Remove the giant if/end block that was really causing problems - skipping stanzas with no to/from (like presence broadcast). Also optimised the code a *lot*, these changes untested at the moment though.
Matthew Wild <mwild1@gmail.com>
parents:
2522
diff
changeset
|
469 origin.send(st.error_reply(stanza, "cancel", "service-unavailable")); |
0c816b271208
mod_privacy: Remove the giant if/end block that was really causing problems - skipping stanzas with no to/from (like presence broadcast). Also optimised the code a *lot*, these changes untested at the moment though.
Matthew Wild <mwild1@gmail.com>
parents:
2522
diff
changeset
|
470 elseif stanza.name == "iq" and (stanza.attr.type == "get" or stanza.attr.type == "set") then |
0c816b271208
mod_privacy: Remove the giant if/end block that was really causing problems - skipping stanzas with no to/from (like presence broadcast). Also optimised the code a *lot*, these changes untested at the moment though.
Matthew Wild <mwild1@gmail.com>
parents:
2522
diff
changeset
|
471 origin.send(st.error_reply(stanza, "cancel", "service-unavailable")); |
2496
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
472 end |
2523
0c816b271208
mod_privacy: Remove the giant if/end block that was really causing problems - skipping stanzas with no to/from (like presence broadcast). Also optimised the code a *lot*, these changes untested at the moment though.
Matthew Wild <mwild1@gmail.com>
parents:
2522
diff
changeset
|
473 return true; -- stanza blocked ! |
0c816b271208
mod_privacy: Remove the giant if/end block that was really causing problems - skipping stanzas with no to/from (like presence broadcast). Also optimised the code a *lot*, these changes untested at the moment though.
Matthew Wild <mwild1@gmail.com>
parents:
2522
diff
changeset
|
474 else |
2524
b427f5401ce7
mod_privacy: A handful of logging fixes
Matthew Wild <mwild1@gmail.com>
parents:
2523
diff
changeset
|
475 module:log("debug", "stanza explicitly allowed!") |
2523
0c816b271208
mod_privacy: Remove the giant if/end block that was really causing problems - skipping stanzas with no to/from (like presence broadcast). Also optimised the code a *lot*, these changes untested at the moment though.
Matthew Wild <mwild1@gmail.com>
parents:
2522
diff
changeset
|
476 return; |
1293 | 477 end |
478 end | |
479 end | |
2496
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
480 end |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
481 |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
482 function preCheckIncoming(e) |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
483 local session; |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
484 if e.stanza.attr.to ~= nil then |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
485 local node, host, resource = jid_split(e.stanza.attr.to); |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
486 if node == nil or host == nil then |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
487 return; |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
488 end |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
489 if resource == nil then |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
490 local prio = 0; |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
491 local session_; |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
492 if bare_sessions[node.."@"..host] ~= nil then |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
493 for resource, session_ in pairs(bare_sessions[node.."@"..host].sessions) do |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
494 if session_.priority ~= nil and session_.priority > prio then |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
495 session = session_; |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
496 prio = session_.priority; |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
497 end |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
498 end |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
499 end |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
500 else |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
501 session = full_sessions[node.."@"..host.."/"..resource]; |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
502 end |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
503 if session ~= nil then |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
504 return checkIfNeedToBeBlocked(e, session); |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
505 else |
2500
bffdaeb7ab5e
mod_privacy: Cleaned up code.
Waqas Hussain <waqas20@gmail.com>
parents:
2499
diff
changeset
|
506 module:log("debug", "preCheckIncoming: Couldn't get session for jid: %s@%s/%s", tostring(node), tostring(host), tostring(resource)); |
2496
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
507 end |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
508 end |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
509 end |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
510 |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
511 function preCheckOutgoing(e) |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
512 local session = e.origin; |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
513 if e.stanza.attr.from == nil then |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
514 e.stanza.attr.from = session.username .. "@" .. session.host; |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
515 if session.resource ~= nil then |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
516 e.stanza.attr.from = e.stanza.attr.from .. "/" .. session.resource; |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
517 end |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
518 end |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
519 return checkIfNeedToBeBlocked(e, session); |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
520 end |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
521 |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
522 module:hook("pre-message/full", preCheckOutgoing, 500); |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
523 module:hook("pre-message/bare", preCheckOutgoing, 500); |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
524 module:hook("pre-message/host", preCheckOutgoing, 500); |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
525 module:hook("pre-iq/full", preCheckOutgoing, 500); |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
526 module:hook("pre-iq/bare", preCheckOutgoing, 500); |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
527 module:hook("pre-iq/host", preCheckOutgoing, 500); |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
528 module:hook("pre-presence/full", preCheckOutgoing, 500); |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
529 module:hook("pre-presence/bare", preCheckOutgoing, 500); |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
530 module:hook("pre-presence/host", preCheckOutgoing, 500); |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
531 |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
532 module:hook("message/full", preCheckIncoming, 500); |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
533 module:hook("message/bare", preCheckIncoming, 500); |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
534 module:hook("message/host", preCheckIncoming, 500); |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
535 module:hook("iq/full", preCheckIncoming, 500); |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
536 module:hook("iq/bare", preCheckIncoming, 500); |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
537 module:hook("iq/host", preCheckIncoming, 500); |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
538 module:hook("presence/full", preCheckIncoming, 500); |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
539 module:hook("presence/bare", preCheckIncoming, 500); |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
540 module:hook("presence/host", preCheckIncoming, 500); |