2 -- Copyright (C) 2008-2010 Matthew Wild
3 -- Copyright (C) 2008-2010 Waqas Hussain
5 -- This project is MIT/X11 licensed. Please see the
6 -- COPYING file in the source package for more information.
9 local st = require "util.stanza"
10 local jid_split = require "util.jid".split;
11 local datamanager = require "util.datamanager"
13 module:add_feature("vcard-temp");
15 local function handle_vcard(event)
16 local session, stanza = event.origin, event.stanza;
17 local to = stanza.attr.to;
18 if stanza.attr.type == "get" then
21 local node, host = jid_split(to);
22 vCard = st.deserialize(datamanager.load(node, host, "vcard")); -- load vCard for user or server
24 vCard = st.deserialize(datamanager.load(session.username, session.host, "vcard"));-- load user's own vCard
27 session.send(st.reply(stanza):add_child(vCard)); -- send vCard!
29 session.send(st.error_reply(stanza, "cancel", "item-not-found"));
33 if datamanager.store(session.username, session.host, "vcard", st.preserialize(stanza.tags[1])) then
34 session.send(st.reply(stanza));
36 -- TODO unable to write file, file may be locked, etc, what's the correct error?
37 session.send(st.error_reply(stanza, "wait", "internal-server-error"));
40 session.send(st.error_reply(stanza, "auth", "forbidden"));
46 module:hook("iq/bare/vcard-temp:vCard", handle_vcard);
47 module:hook("iq/host/vcard-temp:vCard", handle_vcard);
50 if module:get_option("vcard_compatibility") ~= nil then
51 module:log("error", "The vcard_compatibility option has been removed, see"..
52 "mod_compat_vcard in prosody-modules if you still need this.");