Annotate

plugins/mod_vcard4.lua @ 9279:d5c771097ea7

Merge 0.10->trunk
author Kim Alvefur <zash@zash.se>
date Sat, 08 Sep 2018 11:42:22 +0200
parent 9261:9db9e37610b7
child 9283:e977b64ebd81
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
9261
9db9e37610b7 mod_vcard4: Allow access to the vcard4 PEP node via iq syntax
Kim Alvefur <zash@zash.se>
parents:
diff changeset
1 local st = require "util.stanza"
9db9e37610b7 mod_vcard4: Allow access to the vcard4 PEP node via iq syntax
Kim Alvefur <zash@zash.se>
parents:
diff changeset
2 local jid_split = require "util.jid".split;
9db9e37610b7 mod_vcard4: Allow access to the vcard4 PEP node via iq syntax
Kim Alvefur <zash@zash.se>
parents:
diff changeset
3
9db9e37610b7 mod_vcard4: Allow access to the vcard4 PEP node via iq syntax
Kim Alvefur <zash@zash.se>
parents:
diff changeset
4 local mod_pep = module:depends("pep");
9db9e37610b7 mod_vcard4: Allow access to the vcard4 PEP node via iq syntax
Kim Alvefur <zash@zash.se>
parents:
diff changeset
5
9db9e37610b7 mod_vcard4: Allow access to the vcard4 PEP node via iq syntax
Kim Alvefur <zash@zash.se>
parents:
diff changeset
6 module:add_feature("urn:ietf:params:xml:ns:vcard-4.0");
9db9e37610b7 mod_vcard4: Allow access to the vcard4 PEP node via iq syntax
Kim Alvefur <zash@zash.se>
parents:
diff changeset
7
9db9e37610b7 mod_vcard4: Allow access to the vcard4 PEP node via iq syntax
Kim Alvefur <zash@zash.se>
parents:
diff changeset
8 module:hook("iq-get/bare/urn:ietf:params:xml:ns:vcard-4.0:vcard", function (event)
9db9e37610b7 mod_vcard4: Allow access to the vcard4 PEP node via iq syntax
Kim Alvefur <zash@zash.se>
parents:
diff changeset
9 local origin, stanza = event.origin, event.stanza;
9db9e37610b7 mod_vcard4: Allow access to the vcard4 PEP node via iq syntax
Kim Alvefur <zash@zash.se>
parents:
diff changeset
10
9db9e37610b7 mod_vcard4: Allow access to the vcard4 PEP node via iq syntax
Kim Alvefur <zash@zash.se>
parents:
diff changeset
11 local pep_service = mod_pep.get_pep_service(jid_split(stanza.attr.to) or origin.username);
9db9e37610b7 mod_vcard4: Allow access to the vcard4 PEP node via iq syntax
Kim Alvefur <zash@zash.se>
parents:
diff changeset
12 local ok, id, item = pep_service:get_last_item("urn:xmpp:vcard4", stanza.attr.from);
9db9e37610b7 mod_vcard4: Allow access to the vcard4 PEP node via iq syntax
Kim Alvefur <zash@zash.se>
parents:
diff changeset
13 if ok and item then
9db9e37610b7 mod_vcard4: Allow access to the vcard4 PEP node via iq syntax
Kim Alvefur <zash@zash.se>
parents:
diff changeset
14 origin.send(st.reply(stanza):add_child(item.tags[1]));
9db9e37610b7 mod_vcard4: Allow access to the vcard4 PEP node via iq syntax
Kim Alvefur <zash@zash.se>
parents:
diff changeset
15 elseif item == "item-not-found" or not id then
9db9e37610b7 mod_vcard4: Allow access to the vcard4 PEP node via iq syntax
Kim Alvefur <zash@zash.se>
parents:
diff changeset
16 origin.send(st.error_reply(stanza, "cancel", "item-not-found"));
9db9e37610b7 mod_vcard4: Allow access to the vcard4 PEP node via iq syntax
Kim Alvefur <zash@zash.se>
parents:
diff changeset
17 elseif item == "forbidden" then
9db9e37610b7 mod_vcard4: Allow access to the vcard4 PEP node via iq syntax
Kim Alvefur <zash@zash.se>
parents:
diff changeset
18 origin.send(st.error_reply(stanza, "auth", "forbidden"));
9db9e37610b7 mod_vcard4: Allow access to the vcard4 PEP node via iq syntax
Kim Alvefur <zash@zash.se>
parents:
diff changeset
19 else
9db9e37610b7 mod_vcard4: Allow access to the vcard4 PEP node via iq syntax
Kim Alvefur <zash@zash.se>
parents:
diff changeset
20 origin.send(st.error_reply(stanza, "modify", "undefined-condition"));
9db9e37610b7 mod_vcard4: Allow access to the vcard4 PEP node via iq syntax
Kim Alvefur <zash@zash.se>
parents:
diff changeset
21 end
9db9e37610b7 mod_vcard4: Allow access to the vcard4 PEP node via iq syntax
Kim Alvefur <zash@zash.se>
parents:
diff changeset
22 return true;
9db9e37610b7 mod_vcard4: Allow access to the vcard4 PEP node via iq syntax
Kim Alvefur <zash@zash.se>
parents:
diff changeset
23 end);
9db9e37610b7 mod_vcard4: Allow access to the vcard4 PEP node via iq syntax
Kim Alvefur <zash@zash.se>
parents:
diff changeset
24
9db9e37610b7 mod_vcard4: Allow access to the vcard4 PEP node via iq syntax
Kim Alvefur <zash@zash.se>
parents:
diff changeset
25 module:hook("iq-set/self/urn:ietf:params:xml:ns:vcard-4.0:vcard", function (event)
9db9e37610b7 mod_vcard4: Allow access to the vcard4 PEP node via iq syntax
Kim Alvefur <zash@zash.se>
parents:
diff changeset
26 local origin, stanza = event.origin, event.stanza;
9db9e37610b7 mod_vcard4: Allow access to the vcard4 PEP node via iq syntax
Kim Alvefur <zash@zash.se>
parents:
diff changeset
27
9db9e37610b7 mod_vcard4: Allow access to the vcard4 PEP node via iq syntax
Kim Alvefur <zash@zash.se>
parents:
diff changeset
28 local vcard4 = st.stanza("item", { xmlns = "http://jabber.org/protocol/pubsub", id = "current" })
9db9e37610b7 mod_vcard4: Allow access to the vcard4 PEP node via iq syntax
Kim Alvefur <zash@zash.se>
parents:
diff changeset
29 :add_child(stanza.tags[1]);
9db9e37610b7 mod_vcard4: Allow access to the vcard4 PEP node via iq syntax
Kim Alvefur <zash@zash.se>
parents:
diff changeset
30
9db9e37610b7 mod_vcard4: Allow access to the vcard4 PEP node via iq syntax
Kim Alvefur <zash@zash.se>
parents:
diff changeset
31 local pep_service = mod_pep.get_pep_service(origin.username);
9db9e37610b7 mod_vcard4: Allow access to the vcard4 PEP node via iq syntax
Kim Alvefur <zash@zash.se>
parents:
diff changeset
32
9db9e37610b7 mod_vcard4: Allow access to the vcard4 PEP node via iq syntax
Kim Alvefur <zash@zash.se>
parents:
diff changeset
33 local ok, err = pep_service:publish("urn:xmpp:vcard4", origin.full_jid, "current", vcard4);
9db9e37610b7 mod_vcard4: Allow access to the vcard4 PEP node via iq syntax
Kim Alvefur <zash@zash.se>
parents:
diff changeset
34 if ok then
9db9e37610b7 mod_vcard4: Allow access to the vcard4 PEP node via iq syntax
Kim Alvefur <zash@zash.se>
parents:
diff changeset
35 origin.send(st.reply(stanza));
9db9e37610b7 mod_vcard4: Allow access to the vcard4 PEP node via iq syntax
Kim Alvefur <zash@zash.se>
parents:
diff changeset
36 elseif err == "forbidden" then
9db9e37610b7 mod_vcard4: Allow access to the vcard4 PEP node via iq syntax
Kim Alvefur <zash@zash.se>
parents:
diff changeset
37 origin.send(st.error_reply(stanza, "auth", "forbidden"));
9db9e37610b7 mod_vcard4: Allow access to the vcard4 PEP node via iq syntax
Kim Alvefur <zash@zash.se>
parents:
diff changeset
38 else
9db9e37610b7 mod_vcard4: Allow access to the vcard4 PEP node via iq syntax
Kim Alvefur <zash@zash.se>
parents:
diff changeset
39 origin.send(st.error_reply(stanza, "modify", "undefined-condition", err));
9db9e37610b7 mod_vcard4: Allow access to the vcard4 PEP node via iq syntax
Kim Alvefur <zash@zash.se>
parents:
diff changeset
40 end
9db9e37610b7 mod_vcard4: Allow access to the vcard4 PEP node via iq syntax
Kim Alvefur <zash@zash.se>
parents:
diff changeset
41 return true;
9db9e37610b7 mod_vcard4: Allow access to the vcard4 PEP node via iq syntax
Kim Alvefur <zash@zash.se>
parents:
diff changeset
42 end);
9db9e37610b7 mod_vcard4: Allow access to the vcard4 PEP node via iq syntax
Kim Alvefur <zash@zash.se>
parents:
diff changeset
43