util.encodings: Spell out all IDNA 2008 options ICU has
[prosody.git] / plugins / mod_vcard.lua
blobb1a4c6e839f532443f512076701e85a9bbe4a13d
1 -- Prosody IM
2 -- Copyright (C) 2008-2010 Matthew Wild
3 -- Copyright (C) 2008-2010 Waqas Hussain
4 --
5 -- This project is MIT/X11 licensed. Please see the
6 -- COPYING file in the source package for more information.
7 --
9 local st = require "util.stanza"
10 local jid_split = require "util.jid".split;
12 local vcards = module:open_store();
14 module:add_feature("vcard-temp");
16 local function handle_vcard(event)
17 local session, stanza = event.origin, event.stanza;
18 local to = stanza.attr.to;
19 if stanza.attr.type == "get" then
20 local vCard;
21 if to then
22 local node, host = jid_split(to);
23 vCard = st.deserialize(vcards:get(node)); -- load vCard for user or server
24 else
25 vCard = st.deserialize(vcards:get(session.username));-- load user's own vCard
26 end
27 if vCard then
28 session.send(st.reply(stanza):add_child(vCard)); -- send vCard!
29 else
30 session.send(st.error_reply(stanza, "cancel", "item-not-found"));
31 end
32 else -- stanza.attr.type == "set"
33 if not to then
34 if vcards:set(session.username, st.preserialize(stanza.tags[1])) then
35 session.send(st.reply(stanza));
36 else
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"));
39 end
40 else
41 session.send(st.error_reply(stanza, "auth", "forbidden"));
42 end
43 end
44 return true;
45 end
47 module:hook("iq/bare/vcard-temp:vCard", handle_vcard);
48 module:hook("iq/host/vcard-temp:vCard", handle_vcard);