Software /
code /
prosody
Annotate
plugins/mod_privacy.lua @ 2496:f18b882af1d1
mod_privacy: Imported from prosody-modules.
author | Waqas Hussain <waqas20@gmail.com> |
---|---|
date | Tue, 26 Jan 2010 01:32:39 +0500 |
parent | 1522:569d58d21612 |
child | 2498:3d08a6cf57ea |
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"; | |
2496
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
13 local bare_sessions = bare_sessions; |
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; |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
18 local to_number = _G.tonumber; |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
19 |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
20 function findNamedList (privacy_lists, name) |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
21 local ret = nil |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
22 if privacy_lists.lists == nil then |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
23 return nil; |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
24 end |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
25 |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
26 for i=1, #privacy_lists.lists do |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
27 if privacy_lists.lists[i].name == name then |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
28 ret = i; |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
29 break; |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
30 end |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
31 end |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
32 return ret; |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
33 end |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
34 |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
35 function isListUsed(origin, name, privacy_lists) |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
36 if bare_sessions[origin.username.."@"..origin.host].sessions ~= nil then |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
37 for resource, session in pairs(bare_sessions[origin.username.."@"..origin.host].sessions) do |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
38 if resource ~= origin.resource then |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
39 if session.activePrivacyList == name then |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
40 return true; |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
41 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
|
42 return true; |
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 end |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
45 end |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
46 end |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
47 return false; |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
48 end |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
49 |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
50 function isAnotherSessionUsingDefaultList(origin) |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
51 local ret = false |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
52 if bare_sessions[origin.username.."@"..origin.host].sessions ~= nil then |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
53 for resource, session in pairs(bare_sessions[origin.username.."@"..origin.host].sessions) do |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
54 if resource ~= origin.resource and session.activePrivacyList == nil then |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
55 ret = true; |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
56 break; |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
57 end |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
58 end |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
59 end |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
60 return ret; |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
61 end |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
62 |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
63 function sendUnavailable(to, from) |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
64 --[[ example unavailable presence stanza |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
65 <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
|
66 <status>Logged out</status> |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
67 </presence> |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
68 ]]-- |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
69 local presence = st.presence({from=from, type="unavailable"}) |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
70 presence:tag("status"):text("Logged out"); |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
71 |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
72 local node, host = jid_bare(to); |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
73 local bare = node .. "@" .. host; |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
74 |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
75 if bare_sessions[bare].sessions ~= nil then |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
76 for resource, session in pairs(bare_sessions[bare].sessions) do |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
77 presence.attr.to = session.full_jid; |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
78 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
|
79 origin.send(presence); |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
80 end |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
81 end |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
82 end |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
83 |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
84 function sendNeededUnavailablePersences(origin, listnameOrItem) -- TODO implement it correctly! |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
85 if type(listnameOrItem) == "string" then |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
86 local listname = listnameOrItem; |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
87 for _,list in ipairs(privacy_lists.lists) do |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
88 if list.name == listname then |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
89 for _,item in ipairs(list.items) do |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
90 sendNeededUnavailablePersences(origin, item); |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
91 end |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
92 end |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
93 end |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
94 elseif type(listnameOrItem) == "table" then |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
95 module:log("debug", "got an item, check wether to send unavailable presence stanza or not"); |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
96 local item = listnameOrItem; |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
97 local serialize = require "util.serialization".serialize; |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
98 |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
99 |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
100 if item["presence-out"] == true then |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
101 if item.type == "jid" then |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
102 sendUnavailable(item.value, origin.full_jid); |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
103 elseif item.type == "group" then |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
104 elseif item.type == "subscription" then |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
105 elseif item.type == nil then |
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 elseif item["presence-in"] == true then |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
108 if item.type == "jid" then |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
109 sendUnavailable(origin.full_jid, item.value); |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
110 elseif item.type == "group" then |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
111 elseif item.type == "subscription" then |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
112 elseif item.type == nil then |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
113 end |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
114 end |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
115 else |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
116 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
|
117 end |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
118 end |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
119 |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
120 function declineList (privacy_lists, origin, stanza, which) |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
121 if which == "default" then |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
122 if isAnotherSessionUsingDefaultList(origin) then |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
123 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
|
124 end |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
125 privacy_lists.default = nil; |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
126 origin.send(st.reply(stanza)); |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
127 elseif which == "active" then |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
128 origin.activePrivacyList = nil; |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
129 origin.send(st.reply(stanza)); |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
130 else |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
131 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
|
132 end |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
133 return true; |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
134 end |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
135 |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
136 function activateList (privacy_lists, origin, stanza, which, name) |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
137 local idx = findNamedList(privacy_lists, name); |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
138 |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
139 if privacy_lists.default == nil then |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
140 privacy_lists.default = ""; |
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 if origin.activePrivacyList == nil then |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
143 origin.activePrivacyList = ""; |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
144 end |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
145 |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
146 if which == "default" and idx ~= nil then |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
147 if isAnotherSessionUsingDefaultList(origin) then |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
148 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
|
149 end |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
150 privacy_lists.default = 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 --[[ |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
153 if origin.activePrivacyList == nil then |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
154 sendNeededUnavailablePersences(origin, name); |
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 ]]-- |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
157 elseif which == "active" and idx ~= nil then |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
158 origin.activePrivacyList = name; |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
159 origin.send(st.reply(stanza)); |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
160 -- sendNeededUnavailablePersences(origin, name); |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
161 else |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
162 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
|
163 end |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
164 return true; |
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 |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
167 function deleteList (privacy_lists, origin, stanza, name) |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
168 local idx = findNamedList(privacy_lists, name); |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
169 |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
170 if idx ~= nil then |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
171 if isListUsed(origin, name, privacy_lists) then |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
172 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
|
173 end |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
174 if privacy_lists.default == name then |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
175 privacy_lists.default = ""; |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
176 end |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
177 if origin.activePrivacyList == name then |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
178 origin.activePrivacyList = ""; |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
179 end |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
180 table.remove(privacy_lists.lists, idx); |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
181 origin.send(st.reply(stanza)); |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
182 return true; |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
183 end |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
184 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
|
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 local function sortByOrder(a, b) |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
188 if a.order < b.order then |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
189 return true; |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
190 end |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
191 return false; |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
192 end |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
193 |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
194 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
|
195 local idx = findNamedList(privacy_lists, name); |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
196 local bare_jid = origin.username.."@"..origin.host; |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
197 |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
198 if privacy_lists.lists == nil then |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
199 privacy_lists.lists = {}; |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
200 end |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
201 |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
202 if idx == nil then |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
203 idx = #privacy_lists.lists + 1; |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
204 end |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
205 |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
206 local orderCheck = {}; |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
207 local list = {}; |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
208 list.name = name; |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
209 list.items = {}; |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
210 |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
211 for _,item in ipairs(entries) do |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
212 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
|
213 return {"modify", "bad-request", "Order attribute not valid."}; |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
214 end |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
215 |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
216 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
|
217 return {"modify", "bad-request", "Type attribute not valid."}; |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
218 end |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
219 |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
220 local tmp = {}; |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
221 orderCheck[item.attr.order] = true; |
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 tmp["type"] = item.attr.type; |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
224 tmp["value"] = item.attr.value; |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
225 tmp["action"] = item.attr.action; |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
226 tmp["order"] = to_number(item.attr.order); |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
227 tmp["presence-in"] = false; |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
228 tmp["presence-out"] = false; |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
229 tmp["message"] = false; |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
230 tmp["iq"] = false; |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
231 |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
232 if #item.tags > 0 then |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
233 for _,tag in ipairs(item.tags) do |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
234 tmp[tag.name] = true; |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
235 end |
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 |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
238 if tmp.type == "group" then |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
239 local found = false; |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
240 local roster = load_roster(origin.username, origin.host); |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
241 for jid,item in pairs(roster) do |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
242 if item.groups ~= nil then |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
243 for group in pairs(item.groups) do |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
244 if group == tmp.value then |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
245 found = true; |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
246 break; |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
247 end |
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 if found == true then |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
250 break; |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
251 end |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
252 end |
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 if found == false then |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
255 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
|
256 end |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
257 elseif tmp.type == "subscription" then |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
258 if tmp.value ~= "both" and |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
259 tmp.value ~= "to" and |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
260 tmp.value ~= "from" and |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
261 tmp.value ~= "none" then |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
262 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
|
263 end |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
264 end |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
265 |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
266 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
|
267 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
|
268 end |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
269 |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
270 --[[ |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
271 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
|
272 module:log("debug", "calling sendNeededUnavailablePresences!"); |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
273 -- 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
|
274 sendNeededUnavailablePersences(origin, tmp); |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
275 end |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
276 ]]-- |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
277 list.items[#list.items + 1] = tmp; |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
278 end |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
279 |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
280 table.sort(list, sortByOrder); |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
281 |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
282 privacy_lists.lists[idx] = list; |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
283 origin.send(st.reply(stanza)); |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
284 if bare_sessions[bare_jid] ~= nil then |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
285 iq = st.iq ( { type = "set", id="push1" } ); |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
286 iq:tag ("query", { xmlns = "jabber:iq:privacy" } ); |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
287 iq:tag ("list", { name = list.name } ):up(); |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
288 iq:up(); |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
289 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
|
290 iq.attr.to = bare_jid.."/"..resource |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
291 session.send(iq); |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
292 end |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
293 else |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
294 return {"cancel", "bad-request", "internal error."}; |
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 return true; |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
297 end |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
298 |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
299 function getList(privacy_lists, origin, stanza, name) |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
300 local reply = st.reply(stanza); |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
301 reply:tag("query", {xmlns="jabber:iq:privacy"}); |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
302 |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
303 if name == nil then |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
304 reply:tag("active", {name=origin.activePrivacyList or ""}):up(); |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
305 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
|
306 if privacy_lists.lists then |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
307 for _,list in ipairs(privacy_lists.lists) do |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
308 reply:tag("list", {name=list.name}):up(); |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
309 end |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
310 end |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
311 else |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
312 local idx = findNamedList(privacy_lists, name); |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
313 if idx ~= nil then |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
314 list = privacy_lists.lists[idx]; |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
315 reply = reply:tag("list", {name=list.name}); |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
316 for _,item in ipairs(list.items) do |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
317 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
|
318 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
|
319 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
|
320 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
|
321 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
|
322 reply:up(); |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
323 end |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
324 else |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
325 return {"cancel", "item-not-found", "Unknown list specified."}; |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
326 end |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
327 end |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
328 |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
329 origin.send(reply); |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
330 return true; |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
331 end |
1293 | 332 |
333 module:hook("iq/bare/jabber:iq:privacy:query", function(data) | |
334 local origin, stanza = data.origin, data.stanza; | |
335 | |
2496
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
336 if stanza.attr.to == nil then -- only service requests to own bare JID |
1293 | 337 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
|
338 local valid = false; |
1293 | 339 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
|
340 |
1293 | 341 if stanza.attr.type == "set" then |
2496
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
342 if #query.tags == 1 then -- the <query/> element MUST NOT include more than one child element |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
343 for _,tag in ipairs(query.tags) do |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
344 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
|
345 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
|
346 valid = declineList(privacy_lists, origin, stanza, tag.name); |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
347 else -- Client requests change of active / default list |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
348 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
|
349 end |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
350 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
|
351 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
|
352 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
|
353 else -- Client edits a privacy list |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
354 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
|
355 end |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
356 end |
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 |
1293 | 359 elseif stanza.attr.type == "get" then |
2496
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
360 local name = nil; |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
361 local listsToRetrieve = 0; |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
362 if #query.tags >= 1 then |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
363 for _,tag in ipairs(query.tags) do |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
364 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
|
365 name = tag.attr.name; |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
366 listsToRetrieve = listsToRetrieve + 1; |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
367 end |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
368 end |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
369 end |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
370 if listsToRetrieve == 0 or listsToRetrieve == 1 then |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
371 valid = getList(privacy_lists, origin, stanza, name); |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
372 end |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
373 end |
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 if valid ~= true then |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
376 if valid[0] == nil then |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
377 valid[0] = "cancel"; |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
378 end |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
379 if valid[1] == nil then |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
380 valid[1] = "bad-request"; |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
381 end |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
382 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
|
383 else |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
384 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
|
385 end |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
386 return true; |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
387 end |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
388 return false; |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
389 end, 500); |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
390 |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
391 function checkIfNeedToBeBlocked(e, session) |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
392 local origin, stanza = e.origin, e.stanza; |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
393 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
|
394 local bare_jid = session.username.."@"..session.host; |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
395 |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
396 module:log("debug", "stanza: %s, to: %s, from: %s", tostring(stanza.name), tostring(stanza.attr.to), tostring(stanza.attr.from)); |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
397 |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
398 if stanza.attr.to ~= nil and stanza.attr.from ~= nil then |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
399 if privacy_lists.lists == nil or |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
400 (session.activePrivacyList == nil or session.activePrivacyList == "") and |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
401 (privacy_lists.default == nil or privacy_lists.default == "") |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
402 then |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
403 return; -- Nothing to block, default is Allow all |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
404 end |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
405 if jid_bare(stanza.attr.from) == bare_jid and jid_bare(stanza.attr.to) == bare_jid then |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
406 module:log("debug", "Never block communications from one of a user's resources to another."); |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
407 return; -- from one of a user's resource to another => HANDS OFF! |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
408 end |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
409 |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
410 local idx; |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
411 local list; |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
412 local item; |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
413 local listname = session.activePrivacyList; |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
414 if listname == nil or listname == "" then |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
415 listname = privacy_lists.default; -- no active list selected, use default list |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
416 end |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
417 idx = findNamedList(privacy_lists, listname); |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
418 if idx == nil then |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
419 module:log("error", "given privacy listname not found. name: %s", listname); |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
420 return; |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
421 end |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
422 list = privacy_lists.lists[idx]; |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
423 if list == nil then |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
424 module:log("info", "privacy list index wrong. index: %d", idx); |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
425 return; |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
426 end |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
427 for _,item in ipairs(list.items) do |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
428 local apply = false; |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
429 local block = false; |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
430 if ( |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
431 (stanza.name == "message" and item.message) or |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
432 (stanza.name == "iq" and item.iq) or |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
433 (stanza.name == "presence" and jid_bare(stanza.attr.to) == bare_jid and item["presence-in"]) or |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
434 (stanza.name == "presence" and jid_bare(stanza.attr.from) == bare_jid and item["presence-out"]) or |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
435 (item.message == false and item.iq == false and item["presence-in"] == false and item["presence-in"] == false) |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
436 ) then |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
437 apply = true; |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
438 end |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
439 if apply then |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
440 local evilJid = {}; |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
441 apply = false; |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
442 if jid_bare(stanza.attr.to) == bare_jid then |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
443 module:log("debug", "evil jid is (from): %s", stanza.attr.from); |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
444 evilJid.node, evilJid.host, evilJid.resource = jid_split(stanza.attr.from); |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
445 else |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
446 module:log("debug", "evil jid is (to): %s", stanza.attr.to); |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
447 evilJid.node, evilJid.host, evilJid.resource = jid_split(stanza.attr.to); |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
448 end |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
449 if item.type == "jid" and |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
450 (evilJid.node and evilJid.host and evilJid.resource and item.value == evilJid.node.."@"..evilJid.host.."/"..evilJid.resource) or |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
451 (evilJid.node and evilJid.host and item.value == evilJid.node.."@"..evilJid.host) or |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
452 (evilJid.host and evilJid.resource and item.value == evilJid.host.."/"..evilJid.resource) or |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
453 (evilJid.host and item.value == evilJid.host) then |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
454 apply = true; |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
455 block = (item.action == "deny"); |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
456 elseif item.type == "group" then |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
457 local roster = load_roster(session.username, session.host); |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
458 local groups = roster[evilJid.node .. "@" .. evilJid.host].groups; |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
459 for group in pairs(groups) do |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
460 if group == item.value then |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
461 apply = true; |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
462 block = (item.action == "deny"); |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
463 break; |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
464 end |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
465 end |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
466 elseif item.type == "subscription" and evilJid.node ~= nil and evilJid.host ~= nil then -- we need a valid bare evil jid |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
467 local roster = load_roster(session.username, session.host); |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
468 if roster[evilJid.node .. "@" .. evilJid.host].subscription == item.value then |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
469 apply = true; |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
470 block = (item.action == "deny"); |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
471 end |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
472 elseif item.type == nil then |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
473 apply = true; |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
474 block = (item.action == "deny"); |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
475 end |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
476 end |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
477 if apply then |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
478 if block then |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
479 module:log("info", "stanza blocked: %s, to: %s, from: %s", tostring(stanza.name), tostring(stanza.attr.to), tostring(stanza.attr.from)); |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
480 if stanza.name == "message" then |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
481 origin.send(st.error_reply(stanza, "cancel", "service-unavailable")); |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
482 elseif stanza.name == "iq" and (stanza.attr.type == "get" or stanza.attr.type == "set") then |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
483 origin.send(st.error_reply(stanza, "cancel", "service-unavailable")); |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
484 end |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
485 return true; -- stanza blocked ! |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
486 else |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
487 module:log("info", "stanza explicit allowed!") |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
488 return; |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
489 end |
1293 | 490 end |
491 end | |
492 end | |
2496
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
493 return; |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
494 end |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
495 |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
496 function preCheckIncoming(e) |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
497 local session; |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
498 if e.stanza.attr.to ~= nil then |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
499 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
|
500 if node == nil or host == nil then |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
501 return; |
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 resource == nil then |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
504 local prio = 0; |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
505 local session_; |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
506 if bare_sessions[node.."@"..host] ~= nil then |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
507 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
|
508 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
|
509 session = session_; |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
510 prio = session_.priority; |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
511 end |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
512 end |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
513 end |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
514 else |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
515 session = full_sessions[node.."@"..host.."/"..resource]; |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
516 end |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
517 if session ~= nil then |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
518 return checkIfNeedToBeBlocked(e, session); |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
519 else |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
520 module:log("debug", "preCheckIncoming: Couldn't get session for jid: %s@%s/%s", tostring(node), tostring(host), tostring(resource)) |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
521 end |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
522 end |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
523 return; |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
524 end |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
525 |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
526 function preCheckOutgoing(e) |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
527 local session = e.origin; |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
528 if e.stanza.attr.from == nil then |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
529 e.stanza.attr.from = session.username .. "@" .. session.host; |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
530 if session.resource ~= nil then |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
531 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
|
532 end |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
533 end |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
534 return checkIfNeedToBeBlocked(e, session); |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
535 end |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
536 |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
537 |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
538 module:hook("pre-message/full", preCheckOutgoing, 500); |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
539 module:hook("pre-message/bare", preCheckOutgoing, 500); |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
540 module:hook("pre-message/host", preCheckOutgoing, 500); |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
541 module:hook("pre-iq/full", preCheckOutgoing, 500); |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
542 module:hook("pre-iq/bare", preCheckOutgoing, 500); |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
543 module:hook("pre-iq/host", preCheckOutgoing, 500); |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
544 module:hook("pre-presence/full", preCheckOutgoing, 500); |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
545 module:hook("pre-presence/bare", preCheckOutgoing, 500); |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
546 module:hook("pre-presence/host", preCheckOutgoing, 500); |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
547 |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
548 module:hook("message/full", preCheckIncoming, 500); |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
549 module:hook("message/bare", preCheckIncoming, 500); |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
550 module:hook("message/host", preCheckIncoming, 500); |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
551 module:hook("iq/full", preCheckIncoming, 500); |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
552 module:hook("iq/bare", preCheckIncoming, 500); |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
553 module:hook("iq/host", preCheckIncoming, 500); |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
554 module:hook("presence/full", preCheckIncoming, 500); |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
555 module:hook("presence/bare", preCheckIncoming, 500); |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
556 module:hook("presence/host", preCheckIncoming, 500); |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
557 |
f18b882af1d1
mod_privacy: Imported from prosody-modules.
Waqas Hussain <waqas20@gmail.com>
parents:
1522
diff
changeset
|
558 module:log("info", "mod_privacy loaded ..."); |