Comparison

plugins/mod_private.lua @ 310:b28b51746fe7

Fixed mod_private to use session.send for sending stanzas
author Waqas Hussain <waqas20@gmail.com>
date Sun, 16 Nov 2008 04:39:48 +0500
parent 185:a67c88ce1c6a
child 421:63be85693710
comparison
equal deleted inserted replaced
309:d9c8825b7332 310:b28b51746fe7
1 1
2 local st = require "util.stanza" 2 local st = require "util.stanza"
3 local send = require "core.sessionmanager".send_to_session
4 3
5 local jid_split = require "util.jid".split; 4 local jid_split = require "util.jid".split;
6 local datamanager = require "util.datamanager" 5 local datamanager = require "util.datamanager"
7 6
8 add_iq_handler("c2s", "jabber:iq:private", 7 add_iq_handler("c2s", "jabber:iq:private",
17 local tag = query.tags[1]; 16 local tag = query.tags[1];
18 local key = tag.name..":"..tag.attr.xmlns; 17 local key = tag.name..":"..tag.attr.xmlns;
19 local data = datamanager.load(node, host, "private"); 18 local data = datamanager.load(node, host, "private");
20 if stanza.attr.type == "get" then 19 if stanza.attr.type == "get" then
21 if data and data[key] then 20 if data and data[key] then
22 send(session, st.reply(stanza):tag("query", {xmlns = "jabber:iq:private"}):add_child(st.deserialize(data[key]))); 21 session.send(st.reply(stanza):tag("query", {xmlns = "jabber:iq:private"}):add_child(st.deserialize(data[key])));
23 else 22 else
24 send(session, st.reply(stanza):add_child(stanza.tags[1])); 23 session.send(st.reply(stanza):add_child(stanza.tags[1]));
25 end 24 end
26 else -- set 25 else -- set
27 if not data then data = {}; end; 26 if not data then data = {}; end;
28 if #tag == 0 then 27 if #tag == 0 then
29 data[key] = nil; 28 data[key] = nil;
30 else 29 else
31 data[key] = st.preserialize(tag); 30 data[key] = st.preserialize(tag);
32 end 31 end
33 -- TODO delete datastore if empty 32 -- TODO delete datastore if empty
34 if datamanager.store(node, host, "private", data) then 33 if datamanager.store(node, host, "private", data) then
35 send(session, st.reply(stanza)); 34 session.send(st.reply(stanza));
36 else 35 else
37 send(session, st.error_reply(stanza, "wait", "internal-server-error")); 36 session.send(st.error_reply(stanza, "wait", "internal-server-error"));
38 end 37 end
39 end 38 end
40 else 39 else
41 send(session, st.error_reply(stanza, "modify", "bad-format")); 40 session.send(st.error_reply(stanza, "modify", "bad-format"));
42 end 41 end
43 else 42 else
44 send(session, st.error_reply(stanza, "cancel", "forbidden")); 43 session.send(st.error_reply(stanza, "cancel", "forbidden"));
45 end 44 end
46 end 45 end
47 end); 46 end);