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
;
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
22 local node
, host
= jid_split(to
);
23 vCard
= st
.deserialize(vcards
:get(node
)); -- load vCard for user or server
25 vCard
= st
.deserialize(vcards
:get(session
.username
));-- 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 else -- stanza.attr.type == "set"
34 if vcards
:set(session
.username
, 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"));
47 module
:hook("iq/bare/vcard-temp:vCard", handle_vcard
);
48 module
:hook("iq/host/vcard-temp:vCard", handle_vcard
);