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