Software /
code /
prosody
Comparison
plugins/mod_privacy.lua @ 2498:3d08a6cf57ea
mod_privacy: Fixed global access.
author | Waqas Hussain <waqas20@gmail.com> |
---|---|
date | Tue, 26 Jan 2010 01:47:21 +0500 |
parent | 2496:f18b882af1d1 |
child | 2499:145d62abdbfc |
comparison
equal
deleted
inserted
replaced
2496:f18b882af1d1 | 2498:3d08a6cf57ea |
---|---|
8 -- | 8 -- |
9 | 9 |
10 local prosody = prosody; | 10 local prosody = prosody; |
11 local st = require "util.stanza"; | 11 local st = require "util.stanza"; |
12 local datamanager = require "util.datamanager"; | 12 local datamanager = require "util.datamanager"; |
13 local bare_sessions = bare_sessions; | 13 local bare_sessions, full_sessions = bare_sessions, full_sessions; |
14 local util_Jid = require "util.jid"; | 14 local util_Jid = require "util.jid"; |
15 local jid_bare = util_Jid.bare; | 15 local jid_bare = util_Jid.bare; |
16 local jid_split = util_Jid.split; | 16 local jid_split = util_Jid.split; |
17 local load_roster = require "core.rostermanager".load_roster; | 17 local load_roster = require "core.rostermanager".load_roster; |
18 local to_number = _G.tonumber; | 18 local to_number = tonumber; |
19 | 19 |
20 function findNamedList (privacy_lists, name) | 20 function findNamedList (privacy_lists, name) |
21 local ret = nil | 21 local ret = nil |
22 if privacy_lists.lists == nil then | 22 if privacy_lists.lists == nil then |
23 return nil; | 23 return nil; |
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) | 63 function sendUnavailable(origin, to, from) |
64 --[[ example unavailable presence stanza | 64 --[[ example unavailable presence stanza |
65 <presence from="node@host/resource" type="unavailable" to="node@host" > | 65 <presence from="node@host/resource" type="unavailable" to="node@host" > |
66 <status>Logged out</status> | 66 <status>Logged out</status> |
67 </presence> | 67 </presence> |
68 ]]-- | 68 ]]-- |
97 local serialize = require "util.serialization".serialize; | 97 local serialize = require "util.serialization".serialize; |
98 | 98 |
99 | 99 |
100 if item["presence-out"] == true then | 100 if item["presence-out"] == true then |
101 if item.type == "jid" then | 101 if item.type == "jid" then |
102 sendUnavailable(item.value, origin.full_jid); | 102 sendUnavailable(origin, item.value, origin.full_jid); |
103 elseif item.type == "group" then | 103 elseif item.type == "group" then |
104 elseif item.type == "subscription" then | 104 elseif item.type == "subscription" then |
105 elseif item.type == nil then | 105 elseif item.type == nil then |
106 end | 106 end |
107 elseif item["presence-in"] == true then | 107 elseif item["presence-in"] == true then |
108 if item.type == "jid" then | 108 if item.type == "jid" then |
109 sendUnavailable(origin.full_jid, item.value); | 109 sendUnavailable(origin, origin.full_jid, item.value); |
110 elseif item.type == "group" then | 110 elseif item.type == "group" then |
111 elseif item.type == "subscription" then | 111 elseif item.type == "subscription" then |
112 elseif item.type == nil then | 112 elseif item.type == nil then |
113 end | 113 end |
114 end | 114 end |
280 table.sort(list, sortByOrder); | 280 table.sort(list, sortByOrder); |
281 | 281 |
282 privacy_lists.lists[idx] = list; | 282 privacy_lists.lists[idx] = list; |
283 origin.send(st.reply(stanza)); | 283 origin.send(st.reply(stanza)); |
284 if bare_sessions[bare_jid] ~= nil then | 284 if bare_sessions[bare_jid] ~= nil then |
285 iq = st.iq ( { type = "set", id="push1" } ); | 285 local iq = st.iq ( { type = "set", id="push1" } ); |
286 iq:tag ("query", { xmlns = "jabber:iq:privacy" } ); | 286 iq:tag ("query", { xmlns = "jabber:iq:privacy" } ); |
287 iq:tag ("list", { name = list.name } ):up(); | 287 iq:tag ("list", { name = list.name } ):up(); |
288 iq:up(); | 288 iq:up(); |
289 for resource, session in pairs(bare_sessions[bare_jid].sessions) do | 289 for resource, session in pairs(bare_sessions[bare_jid].sessions) do |
290 iq.attr.to = bare_jid.."/"..resource | 290 iq.attr.to = bare_jid.."/"..resource |
309 end | 309 end |
310 end | 310 end |
311 else | 311 else |
312 local idx = findNamedList(privacy_lists, name); | 312 local idx = findNamedList(privacy_lists, name); |
313 if idx ~= nil then | 313 if idx ~= nil then |
314 list = privacy_lists.lists[idx]; | 314 local list = privacy_lists.lists[idx]; |
315 reply = reply:tag("list", {name=list.name}); | 315 reply = reply:tag("list", {name=list.name}); |
316 for _,item in ipairs(list.items) do | 316 for _,item in ipairs(list.items) do |
317 reply:tag("item", {type=item.type, value=item.value, action=item.action, order=item.order}); | 317 reply:tag("item", {type=item.type, value=item.value, action=item.action, order=item.order}); |
318 if item["message"] then reply:tag("message"):up(); end | 318 if item["message"] then reply:tag("message"):up(); end |
319 if item["iq"] then reply:tag("iq"):up(); end | 319 if item["iq"] then reply:tag("iq"):up(); end |