comparison mod_privacy/mod_privacy.lua @ 58:b07193056935

mod_privacy: save the part already coded for presence-out/-in getting active stuff but disabled it.
author Thilo Cestonaro <thilo@cestona.ro>
date Tue, 20 Oct 2009 20:27:10 +0200
parents ea756d96584f
children
comparison
equal deleted inserted replaced
57:cddcea7c091a 58:b07193056935
58 end 58 end
59 end 59 end
60 return ret; 60 return ret;
61 end 61 end
62 62
63 function sendUnavailable(to, from)
64 --[[ example unavailable presence stanza
65 <presence from="node@host/resource" type="unavailable" to="node@host" >
66 <status>Logged out</status>
67 </presence>
68 ]]--
69 local presence = st.presence({from=from, type="unavailable"})
70 presence:tag("status"):text("Logged out");
71
72 local node, host = jid_bare(to);
73 local bare = node .. "@" .. host;
74
75 if bare_sessions[bare].sessions ~= nil then
76 for resource, session in pairs(bare_sessions[bare].sessions) do
77 presence.attr.to = session.full_jid;
78 module:log("debug", "send unavailable to: %s; from: %s", tostring(presence.attr.to), tostring(presence.attr.from));
79 origin.send(presence);
80 end
81 end
82 end
83
84 function sendNeededUnavailablePersences(origin, listnameOrItem) -- TODO implement it correctly!
85 if type(listnameOrItem) == "string" then
86 local listname = listnameOrItem;
87 for _,list in ipairs(privacy_lists.lists) do
88 if list.name == listname then
89 for _,item in ipairs(list.items) do
90 sendNeededUnavailablePersences(origin, item);
91 end
92 end
93 end
94 elseif type(listnameOrItem) == "table" then
95 module:log("debug", "got an item, check wether to send unavailable presence stanza or not");
96 local item = listnameOrItem;
97 local serialize = require "util.serialization".serialize;
98
99
100 if item["presence-out"] == true then
101 if item.type == "jid" then
102 sendUnavailable(item.value, origin.full_jid);
103 elseif item.type == "group" then
104 elseif item.type == "subscription" then
105 elseif item.type == nil then
106 end
107 elseif item["presence-in"] == true then
108 if item.type == "jid" then
109 sendUnavailable(origin.full_jid, item.value);
110 elseif item.type == "group" then
111 elseif item.type == "subscription" then
112 elseif item.type == nil then
113 end
114 end
115 else
116 module:log("debug", "got unknown type: %s", type(listnameOrItem));
117 end
118 end
119
63 function declineList (privacy_lists, origin, stanza, which) 120 function declineList (privacy_lists, origin, stanza, which)
64 if which == "default" then 121 if which == "default" then
65 if isAnotherSessionUsingDefaultList(origin) then 122 if isAnotherSessionUsingDefaultList(origin) then
66 return { "cancel", "conflict", "Another session is online and using the default list."}; 123 return { "cancel", "conflict", "Another session is online and using the default list."};
67 end 124 end
90 if isAnotherSessionUsingDefaultList(origin) then 147 if isAnotherSessionUsingDefaultList(origin) then
91 return {"cancel", "conflict", "Another session is online and using the default list."}; 148 return {"cancel", "conflict", "Another session is online and using the default list."};
92 end 149 end
93 privacy_lists.default = name; 150 privacy_lists.default = name;
94 origin.send(st.reply(stanza)); 151 origin.send(st.reply(stanza));
152 --[[
153 if origin.activePrivacyList == nil then
154 sendNeededUnavailablePersences(origin, name);
155 end
156 ]]--
95 elseif which == "active" and idx ~= nil then 157 elseif which == "active" and idx ~= nil then
96 origin.activePrivacyList = name; 158 origin.activePrivacyList = name;
97 origin.send(st.reply(stanza)); 159 origin.send(st.reply(stanza));
160 -- sendNeededUnavailablePersences(origin, name);
98 else 161 else
99 return {"modify", "bad-request", "Either not active or default given or unknown list name specified."}; 162 return {"modify", "bad-request", "Either not active or default given or unknown list name specified."};
100 end 163 end
101 return true; 164 return true;
102 end 165 end
202 265
203 if tmp.action ~= "deny" and tmp.action ~= "allow" then 266 if tmp.action ~= "deny" and tmp.action ~= "allow" then
204 return {"cancel", "bad-request", "Action must be either deny or allow."}; 267 return {"cancel", "bad-request", "Action must be either deny or allow."};
205 end 268 end
206 269
270 --[[
271 if (privacy_lists.default == name and origin.activePrivacyList == nil) or origin.activePrivacyList == name then
272 module:log("debug", "calling sendNeededUnavailablePresences!");
273 -- item is valid and list is active, so send needed unavailable stanzas
274 sendNeededUnavailablePersences(origin, tmp);
275 end
276 ]]--
207 list.items[#list.items + 1] = tmp; 277 list.items[#list.items + 1] = tmp;
208 end 278 end
209 279
210 table.sort(list, sortByOrder); 280 table.sort(list, sortByOrder);
211 281