16 if stanza.attr.type == "get" then |
16 if stanza.attr.type == "get" then |
17 local vCard; |
17 local vCard; |
18 if to then |
18 if to then |
19 local node, host = jid_split(to); |
19 local node, host = jid_split(to); |
20 if hosts[host] and hosts[host].type == "local" then |
20 if hosts[host] and hosts[host].type == "local" then |
21 vCard = datamanager.load(node, host, "vCard"); -- load vCard for user or server |
21 vCard = st.deserialize(datamanager.load(node, host, "vCard")); -- load vCard for user or server |
22 end |
22 end |
23 else |
23 else |
24 vCard = datamanager.load(session.username, session.host, "vCard");-- load user's own vCard |
24 vCard = st.deserialize(datamanager.load(session.username, session.host, "vCard"));-- load user's own vCard |
25 end |
25 end |
26 if vCard then |
26 if vCard then |
27 local iq = st.reply(stanza); |
27 local iq = st.reply(stanza); |
28 iq:add_child(vCard); |
28 iq:add_child(vCard); |
29 send(session, iq); -- send vCard! |
29 send(session, iq); -- send vCard! |
30 else |
30 else |
31 send(session, st.error_reply(stanza, "cancel", "item-not-found")); |
31 send(session, st.error_reply(stanza, "cancel", "item-not-found")); |
32 end |
32 end |
33 elseif stanza.attr.type == "set" then |
33 elseif stanza.attr.type == "set" then |
34 if not to or to == session.username.."@"..session.host then |
34 if not to or to == session.username.."@"..session.host then |
35 if datamanager.store(session.username, session.host, "vCard", stanza.tags[1]) then |
35 if datamanager.store(session.username, session.host, "vCard", st.preserialize(stanza.tags[1])) then |
36 send(session, st.reply(stanza)); |
36 send(session, st.reply(stanza)); |
37 else |
37 else |
38 -- TODO unable to write file, file may be locked, etc, what's the correct error? |
38 -- TODO unable to write file, file may be locked, etc, what's the correct error? |
39 send(session, st.error_reply(stanza, "wait", "internal-server-error")); |
39 send(session, st.error_reply(stanza, "wait", "internal-server-error")); |
40 end |
40 end |