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 require "core.discomanager".set("vcard", "vcard-temp");
13 module:add_iq_handler({"c2s", "s2sin"}, "vcard-temp",
14 function (session, stanza)
15 if stanza.tags[1].name == "vCard" then
16 local to = stanza.attr.to;
17 if stanza.attr.type == "get" then
20 local node, host = jid_split(to);
21 if hosts[host] and hosts[host].type == "local" then
22 vCard = st.deserialize(datamanager.load(node, host, "vCard")); -- load vCard for user or server
25 vCard = st.deserialize(datamanager.load(session.username, session.host, "vCard"));-- load user's own vCard
28 session.send(st.reply(stanza):add_child(vCard)); -- send vCard!
30 session.send(st.error_reply(stanza, "cancel", "item-not-found"));
32 elseif stanza.attr.type == "set" then
33 if not to or to == session.username.."@"..session.host then
34 if datamanager.store(session.username, session.host, "vCard", st.preserialize(stanza.tags[1])) then
35 session.send(st.reply(stanza));
37 -- TODO unable to write file, file may be locked, etc, what's the correct error?
38 session.send(st.error_reply(stanza, "wait", "internal-server-error"));
41 session.send(st.error_reply(stanza, "auth", "forbidden"));
48 local feature_vcard_attr = { var='vcard-temp' };
49 module:add_event_hook("stream-features",
50 function (session, features)
51 if session.type == "c2s" then
52 features:tag("feature", feature_vcard_attr):up();