2 local st = require "util.stanza"
4 local jid_split = require "util.jid".split;
5 local datamanager = require "util.datamanager"
7 add_iq_handler("c2s", "jabber:iq:private",
8 function (session, stanza)
9 local type = stanza.attr.type;
10 local query = stanza.tags[1];
11 if (type == "get" or type == "set") and query.name == "query" then
12 local node, host = jid_split(stanza.attr.to);
13 if not(node or host) or (node == session.username and host == session.host) then
14 node, host = session.username, session.host;
15 if #query.tags == 1 then
16 local tag = query.tags[1];
17 local key = tag.name..":"..tag.attr.xmlns;
18 local data = datamanager.load(node, host, "private");
19 if stanza.attr.type == "get" then
20 if data and data[key] then
21 session.send(st.reply(stanza):tag("query", {xmlns = "jabber:iq:private"}):add_child(st.deserialize(data[key])));
23 session.send(st.reply(stanza):add_child(stanza.tags[1]));
26 if not data then data = {}; end;
30 data[key] = st.preserialize(tag);
32 -- TODO delete datastore if empty
33 if datamanager.store(node, host, "private", data) then
34 session.send(st.reply(stanza));
36 session.send(st.error_reply(stanza, "wait", "internal-server-error"));
40 session.send(st.error_reply(stanza, "modify", "bad-format"));
43 session.send(st.error_reply(stanza, "cancel", "forbidden"));