2 require "util.datamanager"
3 local datamanager = datamanager;
5 local st = require "util.stanza"
6 local t_concat, t_insert = table.concat, table.insert;
9 local jid_split = jid.split;
11 add_iq_handler({"c2s", "s2sin"}, "vcard-temp",
12 function (session, stanza)
13 if stanza.tags[1].name == "vCard" then
14 local to = stanza.attr.to;
15 if stanza.attr.type == "get" then
18 local node, host = jid_split(to);
19 if hosts[host] and hosts[host].type == "local" then
20 vCard = st.deserialize(datamanager.load(node, host, "vCard")); -- load vCard for user or server
23 vCard = st.deserialize(datamanager.load(session.username, session.host, "vCard"));-- load user's own vCard
26 session.send(st.reply(stanza):add_child(vCard)); -- send vCard!
28 session.send(st.error_reply(stanza, "cancel", "item-not-found"));
30 elseif stanza.attr.type == "set" then
31 if not to or to == session.username.."@"..session.host then
32 if datamanager.store(session.username, session.host, "vCard", st.preserialize(stanza.tags[1])) then
33 session.send(st.reply(stanza));
35 -- TODO unable to write file, file may be locked, etc, what's the correct error?
36 session.send(st.error_reply(stanza, "wait", "internal-server-error"));
39 session.send(st.error_reply(stanza, "auth", "forbidden"));
46 add_event_hook("stream-features",
47 function (session, features)
48 if session.type == "c2s" then
49 t_insert(features, "<feature var='vcard-temp'/>");