1 |
1 |
2 require "util.datamanager" |
2 require "util.datamanager" |
3 local datamanager = datamanager; |
3 local datamanager = datamanager; |
4 |
4 |
5 local st = require "util.stanza" |
5 local st = require "util.stanza" |
6 local send = require "core.sessionmanager".send_to_session |
|
7 local t_concat, t_insert = table.concat, table.insert; |
6 local t_concat, t_insert = table.concat, table.insert; |
8 |
7 |
9 require "util.jid" |
8 require "util.jid" |
10 local jid_split = jid.split; |
9 local jid_split = jid.split; |
11 |
10 |
22 end |
21 end |
23 else |
22 else |
24 vCard = st.deserialize(datamanager.load(session.username, session.host, "vCard"));-- load user's own vCard |
23 vCard = st.deserialize(datamanager.load(session.username, session.host, "vCard"));-- load user's own vCard |
25 end |
24 end |
26 if vCard then |
25 if vCard then |
27 send(session, st.reply(stanza):add_child(vCard)); -- send vCard! |
26 session.send(st.reply(stanza):add_child(vCard)); -- send vCard! |
28 else |
27 else |
29 send(session, st.error_reply(stanza, "cancel", "item-not-found")); |
28 session.send(st.error_reply(stanza, "cancel", "item-not-found")); |
30 end |
29 end |
31 elseif stanza.attr.type == "set" then |
30 elseif stanza.attr.type == "set" then |
32 if not to or to == session.username.."@"..session.host then |
31 if not to or to == session.username.."@"..session.host then |
33 if datamanager.store(session.username, session.host, "vCard", st.preserialize(stanza.tags[1])) then |
32 if datamanager.store(session.username, session.host, "vCard", st.preserialize(stanza.tags[1])) then |
34 send(session, st.reply(stanza)); |
33 session.send(st.reply(stanza)); |
35 else |
34 else |
36 -- TODO unable to write file, file may be locked, etc, what's the correct error? |
35 -- TODO unable to write file, file may be locked, etc, what's the correct error? |
37 send(session, st.error_reply(stanza, "wait", "internal-server-error")); |
36 session.send(st.error_reply(stanza, "wait", "internal-server-error")); |
38 end |
37 end |
39 else |
38 else |
40 send(session, st.error_reply(stanza, "auth", "forbidden")); |
39 session.send(st.error_reply(stanza, "auth", "forbidden")); |
41 end |
40 end |
42 end |
41 end |
43 return true; |
42 return true; |
44 end |
43 end |
45 end); |
44 end); |