Comparison

plugins/mod_privacy.lua @ 5500:eeea0eb2602a

mod_auth_internal_hashed, mod_auth_internal_plain, mod_privacy, mod_private, mod_register, mod_vcard, mod_muc: Use module:open_store()
author Kim Alvefur <zash@zash.se>
date Fri, 19 Apr 2013 16:14:06 +0200
parent 5393:57c4964eff0b
child 5776:bd0ff8ae98a8
child 6365:75bd55e84112
comparison
equal deleted inserted replaced
5498:2a67235e1d4d 5500:eeea0eb2602a
8 -- 8 --
9 9
10 module:add_feature("jabber:iq:privacy"); 10 module:add_feature("jabber:iq:privacy");
11 11
12 local st = require "util.stanza"; 12 local st = require "util.stanza";
13 local datamanager = require "util.datamanager";
14 local bare_sessions, full_sessions = prosody.bare_sessions, prosody.full_sessions; 13 local bare_sessions, full_sessions = prosody.bare_sessions, prosody.full_sessions;
15 local util_Jid = require "util.jid"; 14 local util_Jid = require "util.jid";
16 local jid_bare = util_Jid.bare; 15 local jid_bare = util_Jid.bare;
17 local jid_split, jid_join = util_Jid.split, util_Jid.join; 16 local jid_split, jid_join = util_Jid.split, util_Jid.join;
18 local load_roster = require "core.rostermanager".load_roster; 17 local load_roster = require "core.rostermanager".load_roster;
19 local to_number = tonumber; 18 local to_number = tonumber;
19
20 local privacy_storage = module:open_store();
20 21
21 function isListUsed(origin, name, privacy_lists) 22 function isListUsed(origin, name, privacy_lists)
22 local user = bare_sessions[origin.username.."@"..origin.host]; 23 local user = bare_sessions[origin.username.."@"..origin.host];
23 if user then 24 if user then
24 for resource, session in pairs(user.sessions) do 25 for resource, session in pairs(user.sessions) do
215 local origin, stanza = data.origin, data.stanza; 216 local origin, stanza = data.origin, data.stanza;
216 217
217 if stanza.attr.to == nil then -- only service requests to own bare JID 218 if stanza.attr.to == nil then -- only service requests to own bare JID
218 local query = stanza.tags[1]; -- the query element 219 local query = stanza.tags[1]; -- the query element
219 local valid = false; 220 local valid = false;
220 local privacy_lists = datamanager.load(origin.username, origin.host, "privacy") or { lists = {} }; 221 local privacy_lists = privacy_storage:get(origin.username) or { lists = {} };
221 222
222 if privacy_lists.lists[1] then -- Code to migrate from old privacy lists format, remove in 0.8 223 if privacy_lists.lists[1] then -- Code to migrate from old privacy lists format, remove in 0.8
223 module:log("info", "Upgrading format of stored privacy lists for %s@%s", origin.username, origin.host); 224 module:log("info", "Upgrading format of stored privacy lists for %s@%s", origin.username, origin.host);
224 local lists = privacy_lists.lists; 225 local lists = privacy_lists.lists;
225 for idx, list in ipairs(lists) do 226 for idx, list in ipairs(lists) do
270 if valid[2] == nil then 271 if valid[2] == nil then
271 valid[2] = "bad-request"; 272 valid[2] = "bad-request";
272 end 273 end
273 origin.send(st.error_reply(stanza, valid[1], valid[2], valid[3])); 274 origin.send(st.error_reply(stanza, valid[1], valid[2], valid[3]));
274 else 275 else
275 datamanager.store(origin.username, origin.host, "privacy", privacy_lists); 276 privacy_storage:set(origin.username, privacy_lists);
276 end 277 end
277 return true; 278 return true;
278 end 279 end
279 end); 280 end);
280 281
281 function checkIfNeedToBeBlocked(e, session) 282 function checkIfNeedToBeBlocked(e, session)
282 local origin, stanza = e.origin, e.stanza; 283 local origin, stanza = e.origin, e.stanza;
283 local privacy_lists = datamanager.load(session.username, session.host, "privacy") or {}; 284 local privacy_lists = privacy_storage:get(session.username) or {};
284 local bare_jid = session.username.."@"..session.host; 285 local bare_jid = session.username.."@"..session.host;
285 local to = stanza.attr.to or bare_jid; 286 local to = stanza.attr.to or bare_jid;
286 local from = stanza.attr.from; 287 local from = stanza.attr.from;
287 288
288 local is_to_user = bare_jid == jid_bare(to); 289 local is_to_user = bare_jid == jid_bare(to);