Software /
code /
prosody
Comparison
plugins/mod_vcard.lua @ 1956:ec04b571fa86
mod_vcard: Add vcard_compatibility option to handle vcard stanzas routed to the full JID by ejabberd MUC rooms
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Thu, 15 Oct 2009 23:21:55 +0100 |
parent | 1779:3da808c7bfa2 |
child | 1957:5856b2dcf81e |
comparison
equal
deleted
inserted
replaced
1955:a9a8ef70d14c | 1956:ec04b571fa86 |
---|---|
15 local t_concat, t_insert = table.concat, table.insert; | 15 local t_concat, t_insert = table.concat, table.insert; |
16 | 16 |
17 local jid = require "util.jid" | 17 local jid = require "util.jid" |
18 local jid_split = jid.split; | 18 local jid_split = jid.split; |
19 | 19 |
20 module:add_feature("vcard-temp"); | 20 local xmlns_vcard = "vcard-temp"; |
21 | 21 |
22 module:add_iq_handler({"c2s", "s2sin", "component"}, "vcard-temp", | 22 module:add_feature(xmlns_vcard); |
23 function (session, stanza) | 23 |
24 if stanza.tags[1].name == "vCard" then | 24 function handle_vcard(session, stanza) |
25 local to = stanza.attr.to; | 25 if stanza.tags[1].name == "vCard" then |
26 if stanza.attr.type == "get" then | 26 local to = stanza.attr.to; |
27 local vCard; | 27 if stanza.attr.type == "get" then |
28 if to then | 28 local vCard; |
29 local node, host = jid_split(to); | 29 if to then |
30 if hosts[host] and hosts[host].type == "local" then | 30 local node, host = jid_split(to); |
31 vCard = st.deserialize(datamanager.load(node, host, "vcard")); -- load vCard for user or server | 31 if hosts[host] and hosts[host].type == "local" then |
32 end | 32 vCard = st.deserialize(datamanager.load(node, host, "vcard")); -- load vCard for user or server |
33 else | |
34 vCard = st.deserialize(datamanager.load(session.username, session.host, "vcard"));-- load user's own vCard | |
35 end | |
36 if vCard then | |
37 session.send(st.reply(stanza):add_child(vCard)); -- send vCard! | |
38 else | |
39 session.send(st.error_reply(stanza, "cancel", "item-not-found")); | |
40 end | |
41 elseif stanza.attr.type == "set" then | |
42 if not to or to == session.username.."@"..session.host then | |
43 if datamanager.store(session.username, session.host, "vcard", st.preserialize(stanza.tags[1])) then | |
44 session.send(st.reply(stanza)); | |
45 else | |
46 -- TODO unable to write file, file may be locked, etc, what's the correct error? | |
47 session.send(st.error_reply(stanza, "wait", "internal-server-error")); | |
48 end | |
49 else | |
50 session.send(st.error_reply(stanza, "auth", "forbidden")); | |
51 end | |
52 end | 33 end |
53 return true; | 34 else |
35 vCard = st.deserialize(datamanager.load(session.username, session.host, "vcard"));-- load user's own vCard | |
54 end | 36 end |
55 end); | 37 if vCard then |
38 session.send(st.reply(stanza):add_child(vCard)); -- send vCard! | |
39 else | |
40 session.send(st.error_reply(stanza, "cancel", "item-not-found")); | |
41 end | |
42 elseif stanza.attr.type == "set" then | |
43 if not to or to == session.username.."@"..session.host then | |
44 if datamanager.store(session.username, session.host, "vcard", st.preserialize(stanza.tags[1])) then | |
45 session.send(st.reply(stanza)); | |
46 else | |
47 -- TODO unable to write file, file may be locked, etc, what's the correct error? | |
48 session.send(st.error_reply(stanza, "wait", "internal-server-error")); | |
49 end | |
50 else | |
51 session.send(st.error_reply(stanza, "auth", "forbidden")); | |
52 end | |
53 end | |
54 return true; | |
55 end | |
56 end | |
56 | 57 |
57 local feature_vcard_attr = { var='vcard-temp' }; | 58 module:add_iq_handler({"c2s", "s2sin", "component"}, xmlns_vcard, handle_vcard); |
59 | |
60 -- COMPAT: https://support.process-one.net/browse/EJAB-1045 | |
61 if module:get_option("vcard_compatibility") then | |
62 module:hook("iq/full", function (data) | |
63 local stanza = data.stanza; | |
64 if stanza.attr.type == "get" and stanza.tags[1] | |
65 and stanza.tags[1].attr.xmlns == xmlns_vcard then | |
66 return handle_vcard(data.origin, stanza); | |
67 end | |
68 end, 1); | |
69 end | |
70 | |
71 local feature_vcard_attr = { var=xmlns_vcard }; | |
58 module:add_event_hook("stream-features", | 72 module:add_event_hook("stream-features", |
59 function (session, features) | 73 function (session, features) |
60 if session.type == "c2s" then | 74 if session.type == "c2s" then |
61 features:tag("feature", feature_vcard_attr):up(); | 75 features:tag("feature", feature_vcard_attr):up(); |
62 end | 76 end |