Annotate

mod_profile/mod_profile.lua @ 1423:4852fc446d26

mod_profile: Use the item id "current" as recomended in the Singleton Nodes section of XEP-0060
author Kim Alvefur <zash@zash.se>
date Fri, 30 May 2014 14:57:34 +0200
parent 1422:c3882787ae06
child 1424:9892a537e7fc
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1419
877dc87539ff mod_profile: Replacement for mod_vcard with vcard4 support and integration with mod_pep_plus
Kim Alvefur <zash@zash.se>
parents:
diff changeset
1 -- mod_profile
877dc87539ff mod_profile: Replacement for mod_vcard with vcard4 support and integration with mod_pep_plus
Kim Alvefur <zash@zash.se>
parents:
diff changeset
2
877dc87539ff mod_profile: Replacement for mod_vcard with vcard4 support and integration with mod_pep_plus
Kim Alvefur <zash@zash.se>
parents:
diff changeset
3 local st = require"util.stanza";
877dc87539ff mod_profile: Replacement for mod_vcard with vcard4 support and integration with mod_pep_plus
Kim Alvefur <zash@zash.se>
parents:
diff changeset
4 local jid_split, jid_bare = import("util.jid", "split", "bare");
877dc87539ff mod_profile: Replacement for mod_vcard with vcard4 support and integration with mod_pep_plus
Kim Alvefur <zash@zash.se>
parents:
diff changeset
5 local is_admin = require"core.usermanager".is_admin;
877dc87539ff mod_profile: Replacement for mod_vcard with vcard4 support and integration with mod_pep_plus
Kim Alvefur <zash@zash.se>
parents:
diff changeset
6 local vcard = require"util.vcard";
877dc87539ff mod_profile: Replacement for mod_vcard with vcard4 support and integration with mod_pep_plus
Kim Alvefur <zash@zash.se>
parents:
diff changeset
7 local base64 = require"util.encodings".base64;
877dc87539ff mod_profile: Replacement for mod_vcard with vcard4 support and integration with mod_pep_plus
Kim Alvefur <zash@zash.se>
parents:
diff changeset
8 local sha1 = require"util.hashes".sha1;
877dc87539ff mod_profile: Replacement for mod_vcard with vcard4 support and integration with mod_pep_plus
Kim Alvefur <zash@zash.se>
parents:
diff changeset
9
877dc87539ff mod_profile: Replacement for mod_vcard with vcard4 support and integration with mod_pep_plus
Kim Alvefur <zash@zash.se>
parents:
diff changeset
10 local pep_plus;
1420
808950ab007b mod_profile: Integrate with mod_pep_plus by default
Kim Alvefur <zash@zash.se>
parents: 1419
diff changeset
11 if module:get_host_type() == "local" and module:get_option_boolean("vcard_to_pep", true) then
1419
877dc87539ff mod_profile: Replacement for mod_vcard with vcard4 support and integration with mod_pep_plus
Kim Alvefur <zash@zash.se>
parents:
diff changeset
12 pep_plus = module:depends"pep_plus";
877dc87539ff mod_profile: Replacement for mod_vcard with vcard4 support and integration with mod_pep_plus
Kim Alvefur <zash@zash.se>
parents:
diff changeset
13 end
877dc87539ff mod_profile: Replacement for mod_vcard with vcard4 support and integration with mod_pep_plus
Kim Alvefur <zash@zash.se>
parents:
diff changeset
14
877dc87539ff mod_profile: Replacement for mod_vcard with vcard4 support and integration with mod_pep_plus
Kim Alvefur <zash@zash.se>
parents:
diff changeset
15 local storage = module:open_store();
877dc87539ff mod_profile: Replacement for mod_vcard with vcard4 support and integration with mod_pep_plus
Kim Alvefur <zash@zash.se>
parents:
diff changeset
16 local legacy_storage = module:open_store("vcard");
877dc87539ff mod_profile: Replacement for mod_vcard with vcard4 support and integration with mod_pep_plus
Kim Alvefur <zash@zash.se>
parents:
diff changeset
17
877dc87539ff mod_profile: Replacement for mod_vcard with vcard4 support and integration with mod_pep_plus
Kim Alvefur <zash@zash.se>
parents:
diff changeset
18 local function get_item(vcard, name)
877dc87539ff mod_profile: Replacement for mod_vcard with vcard4 support and integration with mod_pep_plus
Kim Alvefur <zash@zash.se>
parents:
diff changeset
19 local item;
877dc87539ff mod_profile: Replacement for mod_vcard with vcard4 support and integration with mod_pep_plus
Kim Alvefur <zash@zash.se>
parents:
diff changeset
20 for i=1, #vcard do
877dc87539ff mod_profile: Replacement for mod_vcard with vcard4 support and integration with mod_pep_plus
Kim Alvefur <zash@zash.se>
parents:
diff changeset
21 item=vcard[i];
877dc87539ff mod_profile: Replacement for mod_vcard with vcard4 support and integration with mod_pep_plus
Kim Alvefur <zash@zash.se>
parents:
diff changeset
22 if item.name == name then
877dc87539ff mod_profile: Replacement for mod_vcard with vcard4 support and integration with mod_pep_plus
Kim Alvefur <zash@zash.se>
parents:
diff changeset
23 return item, i;
877dc87539ff mod_profile: Replacement for mod_vcard with vcard4 support and integration with mod_pep_plus
Kim Alvefur <zash@zash.se>
parents:
diff changeset
24 end
877dc87539ff mod_profile: Replacement for mod_vcard with vcard4 support and integration with mod_pep_plus
Kim Alvefur <zash@zash.se>
parents:
diff changeset
25 end
877dc87539ff mod_profile: Replacement for mod_vcard with vcard4 support and integration with mod_pep_plus
Kim Alvefur <zash@zash.se>
parents:
diff changeset
26 end
877dc87539ff mod_profile: Replacement for mod_vcard with vcard4 support and integration with mod_pep_plus
Kim Alvefur <zash@zash.se>
parents:
diff changeset
27
877dc87539ff mod_profile: Replacement for mod_vcard with vcard4 support and integration with mod_pep_plus
Kim Alvefur <zash@zash.se>
parents:
diff changeset
28 local magic_mime = {
877dc87539ff mod_profile: Replacement for mod_vcard with vcard4 support and integration with mod_pep_plus
Kim Alvefur <zash@zash.se>
parents:
diff changeset
29 ["\137PNG\r\n\026\n"] = "image/png";
877dc87539ff mod_profile: Replacement for mod_vcard with vcard4 support and integration with mod_pep_plus
Kim Alvefur <zash@zash.se>
parents:
diff changeset
30 ["\255\216"] = "image/jpeg";
877dc87539ff mod_profile: Replacement for mod_vcard with vcard4 support and integration with mod_pep_plus
Kim Alvefur <zash@zash.se>
parents:
diff changeset
31 ["GIF87a"] = "image/gif";
877dc87539ff mod_profile: Replacement for mod_vcard with vcard4 support and integration with mod_pep_plus
Kim Alvefur <zash@zash.se>
parents:
diff changeset
32 ["GIF89a"] = "image/gif";
877dc87539ff mod_profile: Replacement for mod_vcard with vcard4 support and integration with mod_pep_plus
Kim Alvefur <zash@zash.se>
parents:
diff changeset
33 ["<?xml"] = "image/svg+xml";
877dc87539ff mod_profile: Replacement for mod_vcard with vcard4 support and integration with mod_pep_plus
Kim Alvefur <zash@zash.se>
parents:
diff changeset
34 }
877dc87539ff mod_profile: Replacement for mod_vcard with vcard4 support and integration with mod_pep_plus
Kim Alvefur <zash@zash.se>
parents:
diff changeset
35 local function identify(data)
877dc87539ff mod_profile: Replacement for mod_vcard with vcard4 support and integration with mod_pep_plus
Kim Alvefur <zash@zash.se>
parents:
diff changeset
36 for magic, mime in pairs(magic_mime) do
877dc87539ff mod_profile: Replacement for mod_vcard with vcard4 support and integration with mod_pep_plus
Kim Alvefur <zash@zash.se>
parents:
diff changeset
37 if data:sub(1, #magic) == magic then
877dc87539ff mod_profile: Replacement for mod_vcard with vcard4 support and integration with mod_pep_plus
Kim Alvefur <zash@zash.se>
parents:
diff changeset
38 return mime;
877dc87539ff mod_profile: Replacement for mod_vcard with vcard4 support and integration with mod_pep_plus
Kim Alvefur <zash@zash.se>
parents:
diff changeset
39 end
877dc87539ff mod_profile: Replacement for mod_vcard with vcard4 support and integration with mod_pep_plus
Kim Alvefur <zash@zash.se>
parents:
diff changeset
40 end
877dc87539ff mod_profile: Replacement for mod_vcard with vcard4 support and integration with mod_pep_plus
Kim Alvefur <zash@zash.se>
parents:
diff changeset
41 return "application/octet-stream";
877dc87539ff mod_profile: Replacement for mod_vcard with vcard4 support and integration with mod_pep_plus
Kim Alvefur <zash@zash.se>
parents:
diff changeset
42 end
877dc87539ff mod_profile: Replacement for mod_vcard with vcard4 support and integration with mod_pep_plus
Kim Alvefur <zash@zash.se>
parents:
diff changeset
43
877dc87539ff mod_profile: Replacement for mod_vcard with vcard4 support and integration with mod_pep_plus
Kim Alvefur <zash@zash.se>
parents:
diff changeset
44 local function update_pep(username, data)
877dc87539ff mod_profile: Replacement for mod_vcard with vcard4 support and integration with mod_pep_plus
Kim Alvefur <zash@zash.se>
parents:
diff changeset
45 local pep = pep_plus.get_pep_service(username.."@"..module.host);
877dc87539ff mod_profile: Replacement for mod_vcard with vcard4 support and integration with mod_pep_plus
Kim Alvefur <zash@zash.se>
parents:
diff changeset
46 if vcard.to_vcard4 then
1422
c3882787ae06 mod_profile: Purge nodes before publishing new items
Kim Alvefur <zash@zash.se>
parents: 1420
diff changeset
47 pep:purge("urn:xmpp:vcard4", true);
1423
4852fc446d26 mod_profile: Use the item id "current" as recomended in the Singleton Nodes section of XEP-0060
Kim Alvefur <zash@zash.se>
parents: 1422
diff changeset
48 pep:publish("urn:xmpp:vcard4", true, "current", st.stanza("item"):add_child(vcard.to_vcard4(data)));
1419
877dc87539ff mod_profile: Replacement for mod_vcard with vcard4 support and integration with mod_pep_plus
Kim Alvefur <zash@zash.se>
parents:
diff changeset
49 end
877dc87539ff mod_profile: Replacement for mod_vcard with vcard4 support and integration with mod_pep_plus
Kim Alvefur <zash@zash.se>
parents:
diff changeset
50
877dc87539ff mod_profile: Replacement for mod_vcard with vcard4 support and integration with mod_pep_plus
Kim Alvefur <zash@zash.se>
parents:
diff changeset
51 local nickname = get_item(data, "NICKNAME");
877dc87539ff mod_profile: Replacement for mod_vcard with vcard4 support and integration with mod_pep_plus
Kim Alvefur <zash@zash.se>
parents:
diff changeset
52 if nickname and nickname[1] then
1422
c3882787ae06 mod_profile: Purge nodes before publishing new items
Kim Alvefur <zash@zash.se>
parents: 1420
diff changeset
53 pep:purge("http://jabber.org/protocol/nick", true);
1423
4852fc446d26 mod_profile: Use the item id "current" as recomended in the Singleton Nodes section of XEP-0060
Kim Alvefur <zash@zash.se>
parents: 1422
diff changeset
54 pep:publish("http://jabber.org/protocol/nick", true, "current", st.stanza("item")
1419
877dc87539ff mod_profile: Replacement for mod_vcard with vcard4 support and integration with mod_pep_plus
Kim Alvefur <zash@zash.se>
parents:
diff changeset
55 :tag("nick", { xmlns="http://jabber.org/protocol/nick" }):text(nickname[1]));
877dc87539ff mod_profile: Replacement for mod_vcard with vcard4 support and integration with mod_pep_plus
Kim Alvefur <zash@zash.se>
parents:
diff changeset
56 end
877dc87539ff mod_profile: Replacement for mod_vcard with vcard4 support and integration with mod_pep_plus
Kim Alvefur <zash@zash.se>
parents:
diff changeset
57
877dc87539ff mod_profile: Replacement for mod_vcard with vcard4 support and integration with mod_pep_plus
Kim Alvefur <zash@zash.se>
parents:
diff changeset
58 local photo = get_item(data, "PHOTO");
877dc87539ff mod_profile: Replacement for mod_vcard with vcard4 support and integration with mod_pep_plus
Kim Alvefur <zash@zash.se>
parents:
diff changeset
59 if photo and photo[1] then
877dc87539ff mod_profile: Replacement for mod_vcard with vcard4 support and integration with mod_pep_plus
Kim Alvefur <zash@zash.se>
parents:
diff changeset
60 local photo_raw = base64.decode(photo[1]);
877dc87539ff mod_profile: Replacement for mod_vcard with vcard4 support and integration with mod_pep_plus
Kim Alvefur <zash@zash.se>
parents:
diff changeset
61 local photo_hash = sha1(photo_raw, true);
877dc87539ff mod_profile: Replacement for mod_vcard with vcard4 support and integration with mod_pep_plus
Kim Alvefur <zash@zash.se>
parents:
diff changeset
62
1422
c3882787ae06 mod_profile: Purge nodes before publishing new items
Kim Alvefur <zash@zash.se>
parents: 1420
diff changeset
63 pep:purge("urn:xmpp:avatar:metadata", true);
c3882787ae06 mod_profile: Purge nodes before publishing new items
Kim Alvefur <zash@zash.se>
parents: 1420
diff changeset
64 pep:purge("urn:xmpp:avatar:data", true);
1423
4852fc446d26 mod_profile: Use the item id "current" as recomended in the Singleton Nodes section of XEP-0060
Kim Alvefur <zash@zash.se>
parents: 1422
diff changeset
65 pep:publish("urn:xmpp:avatar:metadata", true, "current", st.stanza("item")
1419
877dc87539ff mod_profile: Replacement for mod_vcard with vcard4 support and integration with mod_pep_plus
Kim Alvefur <zash@zash.se>
parents:
diff changeset
66 :tag("metadata", {
877dc87539ff mod_profile: Replacement for mod_vcard with vcard4 support and integration with mod_pep_plus
Kim Alvefur <zash@zash.se>
parents:
diff changeset
67 xmlns="urn:xmpp:avatar:metadata",
877dc87539ff mod_profile: Replacement for mod_vcard with vcard4 support and integration with mod_pep_plus
Kim Alvefur <zash@zash.se>
parents:
diff changeset
68 bytes = tostring(#photo_raw),
877dc87539ff mod_profile: Replacement for mod_vcard with vcard4 support and integration with mod_pep_plus
Kim Alvefur <zash@zash.se>
parents:
diff changeset
69 id = photo_hash,
877dc87539ff mod_profile: Replacement for mod_vcard with vcard4 support and integration with mod_pep_plus
Kim Alvefur <zash@zash.se>
parents:
diff changeset
70 type = identify(photo_raw),
877dc87539ff mod_profile: Replacement for mod_vcard with vcard4 support and integration with mod_pep_plus
Kim Alvefur <zash@zash.se>
parents:
diff changeset
71 }));
877dc87539ff mod_profile: Replacement for mod_vcard with vcard4 support and integration with mod_pep_plus
Kim Alvefur <zash@zash.se>
parents:
diff changeset
72 pep:publish("urn:xmpp:avatar:data", true, photo_hash, st.stanza("item")
877dc87539ff mod_profile: Replacement for mod_vcard with vcard4 support and integration with mod_pep_plus
Kim Alvefur <zash@zash.se>
parents:
diff changeset
73 :tag("data", { xmlns="urn:xmpp:avatar:data" }):text(photo[1]));
877dc87539ff mod_profile: Replacement for mod_vcard with vcard4 support and integration with mod_pep_plus
Kim Alvefur <zash@zash.se>
parents:
diff changeset
74 end
877dc87539ff mod_profile: Replacement for mod_vcard with vcard4 support and integration with mod_pep_plus
Kim Alvefur <zash@zash.se>
parents:
diff changeset
75 end
877dc87539ff mod_profile: Replacement for mod_vcard with vcard4 support and integration with mod_pep_plus
Kim Alvefur <zash@zash.se>
parents:
diff changeset
76
877dc87539ff mod_profile: Replacement for mod_vcard with vcard4 support and integration with mod_pep_plus
Kim Alvefur <zash@zash.se>
parents:
diff changeset
77 -- The "temporary" vCard XEP-0054 part
877dc87539ff mod_profile: Replacement for mod_vcard with vcard4 support and integration with mod_pep_plus
Kim Alvefur <zash@zash.se>
parents:
diff changeset
78 module:add_feature("vcard-temp");
877dc87539ff mod_profile: Replacement for mod_vcard with vcard4 support and integration with mod_pep_plus
Kim Alvefur <zash@zash.se>
parents:
diff changeset
79
877dc87539ff mod_profile: Replacement for mod_vcard with vcard4 support and integration with mod_pep_plus
Kim Alvefur <zash@zash.se>
parents:
diff changeset
80 local function handle_get(event)
877dc87539ff mod_profile: Replacement for mod_vcard with vcard4 support and integration with mod_pep_plus
Kim Alvefur <zash@zash.se>
parents:
diff changeset
81 local origin, stanza = event.origin, event.stanza;
877dc87539ff mod_profile: Replacement for mod_vcard with vcard4 support and integration with mod_pep_plus
Kim Alvefur <zash@zash.se>
parents:
diff changeset
82 local username = origin.username;
877dc87539ff mod_profile: Replacement for mod_vcard with vcard4 support and integration with mod_pep_plus
Kim Alvefur <zash@zash.se>
parents:
diff changeset
83 local to = stanza.attr.to;
877dc87539ff mod_profile: Replacement for mod_vcard with vcard4 support and integration with mod_pep_plus
Kim Alvefur <zash@zash.se>
parents:
diff changeset
84 if to then username = jid_split(to); end
877dc87539ff mod_profile: Replacement for mod_vcard with vcard4 support and integration with mod_pep_plus
Kim Alvefur <zash@zash.se>
parents:
diff changeset
85 local data = storage:get(username);
877dc87539ff mod_profile: Replacement for mod_vcard with vcard4 support and integration with mod_pep_plus
Kim Alvefur <zash@zash.se>
parents:
diff changeset
86 if not data then
877dc87539ff mod_profile: Replacement for mod_vcard with vcard4 support and integration with mod_pep_plus
Kim Alvefur <zash@zash.se>
parents:
diff changeset
87 data = legacy_storage:get(username);
877dc87539ff mod_profile: Replacement for mod_vcard with vcard4 support and integration with mod_pep_plus
Kim Alvefur <zash@zash.se>
parents:
diff changeset
88 data = data and st.deserialize(data);
877dc87539ff mod_profile: Replacement for mod_vcard with vcard4 support and integration with mod_pep_plus
Kim Alvefur <zash@zash.se>
parents:
diff changeset
89 end
877dc87539ff mod_profile: Replacement for mod_vcard with vcard4 support and integration with mod_pep_plus
Kim Alvefur <zash@zash.se>
parents:
diff changeset
90 if not data then
877dc87539ff mod_profile: Replacement for mod_vcard with vcard4 support and integration with mod_pep_plus
Kim Alvefur <zash@zash.se>
parents:
diff changeset
91 return origin.send(st.error_reply(stanza, "cancel", "item-not-found"));
877dc87539ff mod_profile: Replacement for mod_vcard with vcard4 support and integration with mod_pep_plus
Kim Alvefur <zash@zash.se>
parents:
diff changeset
92 end
877dc87539ff mod_profile: Replacement for mod_vcard with vcard4 support and integration with mod_pep_plus
Kim Alvefur <zash@zash.se>
parents:
diff changeset
93 return origin.send(st.reply(stanza):add_child(vcard.to_xep54(data)));
877dc87539ff mod_profile: Replacement for mod_vcard with vcard4 support and integration with mod_pep_plus
Kim Alvefur <zash@zash.se>
parents:
diff changeset
94 end
877dc87539ff mod_profile: Replacement for mod_vcard with vcard4 support and integration with mod_pep_plus
Kim Alvefur <zash@zash.se>
parents:
diff changeset
95
877dc87539ff mod_profile: Replacement for mod_vcard with vcard4 support and integration with mod_pep_plus
Kim Alvefur <zash@zash.se>
parents:
diff changeset
96 local function handle_set(event)
877dc87539ff mod_profile: Replacement for mod_vcard with vcard4 support and integration with mod_pep_plus
Kim Alvefur <zash@zash.se>
parents:
diff changeset
97 local origin, stanza = event.origin, event.stanza;
877dc87539ff mod_profile: Replacement for mod_vcard with vcard4 support and integration with mod_pep_plus
Kim Alvefur <zash@zash.se>
parents:
diff changeset
98 local data = vcard.from_xep54(stanza.tags[1]);
877dc87539ff mod_profile: Replacement for mod_vcard with vcard4 support and integration with mod_pep_plus
Kim Alvefur <zash@zash.se>
parents:
diff changeset
99 local username = origin.username;
877dc87539ff mod_profile: Replacement for mod_vcard with vcard4 support and integration with mod_pep_plus
Kim Alvefur <zash@zash.se>
parents:
diff changeset
100 local to = stanza.attr.to;
877dc87539ff mod_profile: Replacement for mod_vcard with vcard4 support and integration with mod_pep_plus
Kim Alvefur <zash@zash.se>
parents:
diff changeset
101 if to then
877dc87539ff mod_profile: Replacement for mod_vcard with vcard4 support and integration with mod_pep_plus
Kim Alvefur <zash@zash.se>
parents:
diff changeset
102 if not is_admin(jid_bare(stanza.attr.from), module.host) then
877dc87539ff mod_profile: Replacement for mod_vcard with vcard4 support and integration with mod_pep_plus
Kim Alvefur <zash@zash.se>
parents:
diff changeset
103 return origin.send(st.error_reply(stanza, "auth", "forbidden"));
877dc87539ff mod_profile: Replacement for mod_vcard with vcard4 support and integration with mod_pep_plus
Kim Alvefur <zash@zash.se>
parents:
diff changeset
104 end
877dc87539ff mod_profile: Replacement for mod_vcard with vcard4 support and integration with mod_pep_plus
Kim Alvefur <zash@zash.se>
parents:
diff changeset
105 username = jid_split(to);
877dc87539ff mod_profile: Replacement for mod_vcard with vcard4 support and integration with mod_pep_plus
Kim Alvefur <zash@zash.se>
parents:
diff changeset
106 end
877dc87539ff mod_profile: Replacement for mod_vcard with vcard4 support and integration with mod_pep_plus
Kim Alvefur <zash@zash.se>
parents:
diff changeset
107 local ok, err = storage:set(username, data);
877dc87539ff mod_profile: Replacement for mod_vcard with vcard4 support and integration with mod_pep_plus
Kim Alvefur <zash@zash.se>
parents:
diff changeset
108 if not ok then
877dc87539ff mod_profile: Replacement for mod_vcard with vcard4 support and integration with mod_pep_plus
Kim Alvefur <zash@zash.se>
parents:
diff changeset
109 return origin.send(st.error_reply(stanza, "cancel", "internal-server-error", err));
877dc87539ff mod_profile: Replacement for mod_vcard with vcard4 support and integration with mod_pep_plus
Kim Alvefur <zash@zash.se>
parents:
diff changeset
110 end
877dc87539ff mod_profile: Replacement for mod_vcard with vcard4 support and integration with mod_pep_plus
Kim Alvefur <zash@zash.se>
parents:
diff changeset
111
877dc87539ff mod_profile: Replacement for mod_vcard with vcard4 support and integration with mod_pep_plus
Kim Alvefur <zash@zash.se>
parents:
diff changeset
112 if pep_plus and username then
877dc87539ff mod_profile: Replacement for mod_vcard with vcard4 support and integration with mod_pep_plus
Kim Alvefur <zash@zash.se>
parents:
diff changeset
113 update_pep(username, data);
877dc87539ff mod_profile: Replacement for mod_vcard with vcard4 support and integration with mod_pep_plus
Kim Alvefur <zash@zash.se>
parents:
diff changeset
114 end
877dc87539ff mod_profile: Replacement for mod_vcard with vcard4 support and integration with mod_pep_plus
Kim Alvefur <zash@zash.se>
parents:
diff changeset
115
877dc87539ff mod_profile: Replacement for mod_vcard with vcard4 support and integration with mod_pep_plus
Kim Alvefur <zash@zash.se>
parents:
diff changeset
116 return origin.send(st.reply(stanza));
877dc87539ff mod_profile: Replacement for mod_vcard with vcard4 support and integration with mod_pep_plus
Kim Alvefur <zash@zash.se>
parents:
diff changeset
117 end
877dc87539ff mod_profile: Replacement for mod_vcard with vcard4 support and integration with mod_pep_plus
Kim Alvefur <zash@zash.se>
parents:
diff changeset
118
877dc87539ff mod_profile: Replacement for mod_vcard with vcard4 support and integration with mod_pep_plus
Kim Alvefur <zash@zash.se>
parents:
diff changeset
119 module:hook("iq-get/bare/vcard-temp:vCard", handle_get);
877dc87539ff mod_profile: Replacement for mod_vcard with vcard4 support and integration with mod_pep_plus
Kim Alvefur <zash@zash.se>
parents:
diff changeset
120 module:hook("iq-get/host/vcard-temp:vCard", handle_get);
877dc87539ff mod_profile: Replacement for mod_vcard with vcard4 support and integration with mod_pep_plus
Kim Alvefur <zash@zash.se>
parents:
diff changeset
121
877dc87539ff mod_profile: Replacement for mod_vcard with vcard4 support and integration with mod_pep_plus
Kim Alvefur <zash@zash.se>
parents:
diff changeset
122 module:hook("iq-set/bare/vcard-temp:vCard", handle_set);
877dc87539ff mod_profile: Replacement for mod_vcard with vcard4 support and integration with mod_pep_plus
Kim Alvefur <zash@zash.se>
parents:
diff changeset
123 module:hook("iq-set/host/vcard-temp:vCard", handle_set);
877dc87539ff mod_profile: Replacement for mod_vcard with vcard4 support and integration with mod_pep_plus
Kim Alvefur <zash@zash.se>
parents:
diff changeset
124
877dc87539ff mod_profile: Replacement for mod_vcard with vcard4 support and integration with mod_pep_plus
Kim Alvefur <zash@zash.se>
parents:
diff changeset
125 -- The vCard4 part
877dc87539ff mod_profile: Replacement for mod_vcard with vcard4 support and integration with mod_pep_plus
Kim Alvefur <zash@zash.se>
parents:
diff changeset
126 if vcard.to_vcard4 then
877dc87539ff mod_profile: Replacement for mod_vcard with vcard4 support and integration with mod_pep_plus
Kim Alvefur <zash@zash.se>
parents:
diff changeset
127 module:add_feature("urn:ietf:params:xml:ns:vcard-4.0");
877dc87539ff mod_profile: Replacement for mod_vcard with vcard4 support and integration with mod_pep_plus
Kim Alvefur <zash@zash.se>
parents:
diff changeset
128
877dc87539ff mod_profile: Replacement for mod_vcard with vcard4 support and integration with mod_pep_plus
Kim Alvefur <zash@zash.se>
parents:
diff changeset
129 module:hook("iq-get/bare/urn:ietf:params:xml:ns:vcard-4.0:vcard", function(event)
877dc87539ff mod_profile: Replacement for mod_vcard with vcard4 support and integration with mod_pep_plus
Kim Alvefur <zash@zash.se>
parents:
diff changeset
130 local origin, stanza = event.origin, event.stanza;
877dc87539ff mod_profile: Replacement for mod_vcard with vcard4 support and integration with mod_pep_plus
Kim Alvefur <zash@zash.se>
parents:
diff changeset
131 local username = jid_split(stanza.attr.to) or origin.username;
877dc87539ff mod_profile: Replacement for mod_vcard with vcard4 support and integration with mod_pep_plus
Kim Alvefur <zash@zash.se>
parents:
diff changeset
132 local data = storage:get(username);
877dc87539ff mod_profile: Replacement for mod_vcard with vcard4 support and integration with mod_pep_plus
Kim Alvefur <zash@zash.se>
parents:
diff changeset
133 if not data then
877dc87539ff mod_profile: Replacement for mod_vcard with vcard4 support and integration with mod_pep_plus
Kim Alvefur <zash@zash.se>
parents:
diff changeset
134 return origin.send(st.error_reply(stanza, "cancel", "item-not-found"));
877dc87539ff mod_profile: Replacement for mod_vcard with vcard4 support and integration with mod_pep_plus
Kim Alvefur <zash@zash.se>
parents:
diff changeset
135 end
877dc87539ff mod_profile: Replacement for mod_vcard with vcard4 support and integration with mod_pep_plus
Kim Alvefur <zash@zash.se>
parents:
diff changeset
136 return origin.send(st.reply(stanza):add_child(vcard.to_vcard4(data)));
877dc87539ff mod_profile: Replacement for mod_vcard with vcard4 support and integration with mod_pep_plus
Kim Alvefur <zash@zash.se>
parents:
diff changeset
137 end);
877dc87539ff mod_profile: Replacement for mod_vcard with vcard4 support and integration with mod_pep_plus
Kim Alvefur <zash@zash.se>
parents:
diff changeset
138
877dc87539ff mod_profile: Replacement for mod_vcard with vcard4 support and integration with mod_pep_plus
Kim Alvefur <zash@zash.se>
parents:
diff changeset
139 if vcard.from_vcard4 then
877dc87539ff mod_profile: Replacement for mod_vcard with vcard4 support and integration with mod_pep_plus
Kim Alvefur <zash@zash.se>
parents:
diff changeset
140 module:hook("iq-set/self/urn:ietf:params:xml:ns:vcard-4.0:vcard", function(event)
877dc87539ff mod_profile: Replacement for mod_vcard with vcard4 support and integration with mod_pep_plus
Kim Alvefur <zash@zash.se>
parents:
diff changeset
141 local origin, stanza = event.origin, event.stanza;
877dc87539ff mod_profile: Replacement for mod_vcard with vcard4 support and integration with mod_pep_plus
Kim Alvefur <zash@zash.se>
parents:
diff changeset
142 local ok, err = storage:set(origin.username, vcard.from_vcard4(stanza.tags[1]));
877dc87539ff mod_profile: Replacement for mod_vcard with vcard4 support and integration with mod_pep_plus
Kim Alvefur <zash@zash.se>
parents:
diff changeset
143 if not ok then
877dc87539ff mod_profile: Replacement for mod_vcard with vcard4 support and integration with mod_pep_plus
Kim Alvefur <zash@zash.se>
parents:
diff changeset
144 return origin.send(st.error_reply(stanza, "cancel", "internal-server-error", err));
877dc87539ff mod_profile: Replacement for mod_vcard with vcard4 support and integration with mod_pep_plus
Kim Alvefur <zash@zash.se>
parents:
diff changeset
145 end
877dc87539ff mod_profile: Replacement for mod_vcard with vcard4 support and integration with mod_pep_plus
Kim Alvefur <zash@zash.se>
parents:
diff changeset
146 return origin.send(st.reply(stanza));
877dc87539ff mod_profile: Replacement for mod_vcard with vcard4 support and integration with mod_pep_plus
Kim Alvefur <zash@zash.se>
parents:
diff changeset
147 end);
877dc87539ff mod_profile: Replacement for mod_vcard with vcard4 support and integration with mod_pep_plus
Kim Alvefur <zash@zash.se>
parents:
diff changeset
148 else
877dc87539ff mod_profile: Replacement for mod_vcard with vcard4 support and integration with mod_pep_plus
Kim Alvefur <zash@zash.se>
parents:
diff changeset
149 module:hook("iq-set/self/urn:ietf:params:xml:ns:vcard-4.0:vcard", function(event)
877dc87539ff mod_profile: Replacement for mod_vcard with vcard4 support and integration with mod_pep_plus
Kim Alvefur <zash@zash.se>
parents:
diff changeset
150 local origin, stanza = event.origin, event.stanza;
877dc87539ff mod_profile: Replacement for mod_vcard with vcard4 support and integration with mod_pep_plus
Kim Alvefur <zash@zash.se>
parents:
diff changeset
151 return origin.send(st.error_reply(stanza, "cancel", "feature-not-implemented"));
877dc87539ff mod_profile: Replacement for mod_vcard with vcard4 support and integration with mod_pep_plus
Kim Alvefur <zash@zash.se>
parents:
diff changeset
152 end);
877dc87539ff mod_profile: Replacement for mod_vcard with vcard4 support and integration with mod_pep_plus
Kim Alvefur <zash@zash.se>
parents:
diff changeset
153 end
877dc87539ff mod_profile: Replacement for mod_vcard with vcard4 support and integration with mod_pep_plus
Kim Alvefur <zash@zash.se>
parents:
diff changeset
154 end
877dc87539ff mod_profile: Replacement for mod_vcard with vcard4 support and integration with mod_pep_plus
Kim Alvefur <zash@zash.se>
parents:
diff changeset
155