aboutsummaryrefslogtreecommitdiffstats
path: root/plugins/mod_vcard4.lua
diff options
context:
space:
mode:
authorKim Alvefur <zash@zash.se>2018-08-18 13:48:38 +0200
committerKim Alvefur <zash@zash.se>2018-08-18 13:48:38 +0200
commit734b966e3002bf37f3edef7a1845e68bc745b83e (patch)
treeee5dfec1faa670f8c4e614349d03a37f53963a18 /plugins/mod_vcard4.lua
parent3afb5ef61a63ac44da1c2e5a5f710b3594910c82 (diff)
downloadprosody-734b966e3002bf37f3edef7a1845e68bc745b83e.tar.gz
prosody-734b966e3002bf37f3edef7a1845e68bc745b83e.zip
mod_vcard4: Allow access to the vcard4 PEP node via iq syntax
Diffstat (limited to 'plugins/mod_vcard4.lua')
-rw-r--r--plugins/mod_vcard4.lua43
1 files changed, 43 insertions, 0 deletions
diff --git a/plugins/mod_vcard4.lua b/plugins/mod_vcard4.lua
new file mode 100644
index 00000000..1c11847e
--- /dev/null
+++ b/plugins/mod_vcard4.lua
@@ -0,0 +1,43 @@
+local st = require "util.stanza"
+local jid_split = require "util.jid".split;
+
+local mod_pep = module:depends("pep");
+
+module:add_feature("urn:ietf:params:xml:ns:vcard-4.0");
+
+module:hook("iq-get/bare/urn:ietf:params:xml:ns:vcard-4.0:vcard", function (event)
+ local origin, stanza = event.origin, event.stanza;
+
+ local pep_service = mod_pep.get_pep_service(jid_split(stanza.attr.to) or origin.username);
+ local ok, id, item = pep_service:get_last_item("urn:xmpp:vcard4", stanza.attr.from);
+ if ok and item then
+ origin.send(st.reply(stanza):add_child(item.tags[1]));
+ elseif item == "item-not-found" or not id then
+ origin.send(st.error_reply(stanza, "cancel", "item-not-found"));
+ elseif item == "forbidden" then
+ origin.send(st.error_reply(stanza, "auth", "forbidden"));
+ else
+ origin.send(st.error_reply(stanza, "modify", "undefined-condition"));
+ end
+ return true;
+end);
+
+module:hook("iq-set/self/urn:ietf:params:xml:ns:vcard-4.0:vcard", function (event)
+ local origin, stanza = event.origin, event.stanza;
+
+ local vcard4 = st.stanza("item", { xmlns = "http://jabber.org/protocol/pubsub", id = "current" })
+ :add_child(stanza.tags[1]);
+
+ local pep_service = mod_pep.get_pep_service(origin.username);
+
+ local ok, err = pep_service:publish("urn:xmpp:vcard4", origin.full_jid, "current", vcard4);
+ if ok then
+ origin.send(st.reply(stanza));
+ elseif err == "forbidden" then
+ origin.send(st.error_reply(stanza, "auth", "forbidden"));
+ else
+ origin.send(st.error_reply(stanza, "modify", "undefined-condition", err));
+ end
+ return true;
+end);
+