Comparison

plugins/mod_private.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 5371:706206e191e8
child 5776:bd0ff8ae98a8
comparison
equal deleted inserted replaced
5498:2a67235e1d4d 5500:eeea0eb2602a
7 -- 7 --
8 8
9 9
10 local st = require "util.stanza" 10 local st = require "util.stanza"
11 11
12 local datamanager = require "util.datamanager" 12 local private_storage = module:open_store();
13 13
14 module:add_feature("jabber:iq:private"); 14 module:add_feature("jabber:iq:private");
15 15
16 module:hook("iq/self/jabber:iq:private:query", function(event) 16 module:hook("iq/self/jabber:iq:private:query", function(event)
17 local origin, stanza = event.origin, event.stanza; 17 local origin, stanza = event.origin, event.stanza;
18 local type = stanza.attr.type; 18 local type = stanza.attr.type;
19 local query = stanza.tags[1]; 19 local query = stanza.tags[1];
20 if #query.tags == 1 then 20 if #query.tags == 1 then
21 local tag = query.tags[1]; 21 local tag = query.tags[1];
22 local key = tag.name..":"..tag.attr.xmlns; 22 local key = tag.name..":"..tag.attr.xmlns;
23 local data, err = datamanager.load(origin.username, origin.host, "private"); 23 local data, err = private_storage:get(origin.username);
24 if err then 24 if err then
25 origin.send(st.error_reply(stanza, "wait", "internal-server-error")); 25 origin.send(st.error_reply(stanza, "wait", "internal-server-error"));
26 return true; 26 return true;
27 end 27 end
28 if stanza.attr.type == "get" then 28 if stanza.attr.type == "get" then
37 data[key] = nil; 37 data[key] = nil;
38 else 38 else
39 data[key] = st.preserialize(tag); 39 data[key] = st.preserialize(tag);
40 end 40 end
41 -- TODO delete datastore if empty 41 -- TODO delete datastore if empty
42 if datamanager.store(origin.username, origin.host, "private", data) then 42 if private_storage:set(origin.username, data) then
43 origin.send(st.reply(stanza)); 43 origin.send(st.reply(stanza));
44 else 44 else
45 origin.send(st.error_reply(stanza, "wait", "internal-server-error")); 45 origin.send(st.error_reply(stanza, "wait", "internal-server-error"));
46 end 46 end
47 end 47 end