Software /
code /
prosody
Comparison
plugins/mod_privacy.lua @ 2590:2d7e2a28d1d5
mod_privacy: Remove use of to identify unspecified privacy list
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Thu, 11 Feb 2010 18:49:17 +0000 |
parent | 2589:39f5a068dc41 |
child | 2614:7a589e9e2372 |
comparison
equal
deleted
inserted
replaced
2589:39f5a068dc41 | 2590:2d7e2a28d1d5 |
---|---|
116 end | 116 end |
117 | 117 |
118 function activateList(privacy_lists, origin, stanza, which, name) | 118 function activateList(privacy_lists, origin, stanza, which, name) |
119 local list = privacy_lists.lists[name]; | 119 local list = privacy_lists.lists[name]; |
120 | 120 |
121 if privacy_lists.default == nil then | |
122 privacy_lists.default = ""; | |
123 end | |
124 if origin.activePrivacyList == nil then | |
125 origin.activePrivacyList = ""; | |
126 end | |
127 | |
128 if which == "default" and list then | 121 if which == "default" and list then |
129 if isAnotherSessionUsingDefaultList(origin) then | 122 if isAnotherSessionUsingDefaultList(origin) then |
130 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."}; |
131 end | 124 end |
132 privacy_lists.default = name; | 125 privacy_lists.default = name; |
152 if list then | 145 if list then |
153 if isListUsed(origin, name, privacy_lists) then | 146 if isListUsed(origin, name, privacy_lists) then |
154 return {"cancel", "conflict", "Another session is online and using the list which should be deleted."}; | 147 return {"cancel", "conflict", "Another session is online and using the list which should be deleted."}; |
155 end | 148 end |
156 if privacy_lists.default == name then | 149 if privacy_lists.default == name then |
157 privacy_lists.default = ""; | 150 privacy_lists.default = nil; |
158 end | 151 end |
159 if origin.activePrivacyList == name then | 152 if origin.activePrivacyList == name then |
160 origin.activePrivacyList = ""; | 153 origin.activePrivacyList = nil; |
161 end | 154 end |
162 privacy_lists.lists[name] = nil; | 155 privacy_lists.lists[name] = nil; |
163 origin.send(st.reply(stanza)); | 156 origin.send(st.reply(stanza)); |
164 return true; | 157 return true; |
165 end | 158 end |
270 function getList(privacy_lists, origin, stanza, name) | 263 function getList(privacy_lists, origin, stanza, name) |
271 local reply = st.reply(stanza); | 264 local reply = st.reply(stanza); |
272 reply:tag("query", {xmlns="jabber:iq:privacy"}); | 265 reply:tag("query", {xmlns="jabber:iq:privacy"}); |
273 | 266 |
274 if name == nil then | 267 if name == nil then |
275 reply:tag("active", {name=origin.activePrivacyList or ""}):up(); | |
276 reply:tag("default", {name=privacy_lists.default or ""}):up(); | |
277 if privacy_lists.lists then | 268 if privacy_lists.lists then |
269 if origin.ActivePrivacyList then | |
270 reply:tag("active", {name=origin.activePrivacyList}):up(); | |
271 end | |
272 if privacy_lists.default then | |
273 reply:tag("default", {name=privacy_lists.default}):up(); | |
274 end | |
278 for _,list in ipairs(privacy_lists.lists) do | 275 for _,list in ipairs(privacy_lists.lists) do |
279 reply:tag("list", {name=list.name}):up(); | 276 reply:tag("list", {name=list.name}):up(); |
280 end | 277 end |
281 end | 278 end |
282 else | 279 else |
369 local is_from_user = bare_jid == jid_bare(from); | 366 local is_from_user = bare_jid == jid_bare(from); |
370 | 367 |
371 module:log("debug", "stanza: %s, to: %s, from: %s", tostring(stanza.name), tostring(to), tostring(from)); | 368 module:log("debug", "stanza: %s, to: %s, from: %s", tostring(stanza.name), tostring(to), tostring(from)); |
372 | 369 |
373 if privacy_lists.lists == nil or | 370 if privacy_lists.lists == nil or |
374 (session.activePrivacyList == nil or session.activePrivacyList == "") and | 371 not (session.activePrivacyList or privacy_lists.default) |
375 (privacy_lists.default == nil or privacy_lists.default == "") | |
376 then | 372 then |
377 return; -- Nothing to block, default is Allow all | 373 return; -- Nothing to block, default is Allow all |
378 end | 374 end |
379 if is_from_user and is_to_user then | 375 if is_from_user and is_to_user then |
380 module:log("debug", "Not blocking communications between user's resources"); | 376 module:log("debug", "Not blocking communications between user's resources"); |
381 return; -- from one of a user's resource to another => HANDS OFF! | 377 return; -- from one of a user's resource to another => HANDS OFF! |
382 end | 378 end |
383 | 379 |
384 local item; | 380 local item; |
385 local listname = session.activePrivacyList; | 381 local listname = session.activePrivacyList; |
386 if listname == nil or listname == "" then | 382 if listname == nil then |
387 listname = privacy_lists.default; -- no active list selected, use default list | 383 listname = privacy_lists.default; -- no active list selected, use default list |
388 end | 384 end |
389 local list = privacy_lists.lists[listname]; | 385 local list = privacy_lists.lists[listname]; |
390 if not list then | 386 if not list then |
391 module:log("debug", "given privacy list not found. name: %s", listname); | 387 module:log("debug", "given privacy list not found. name: %s", listname); |