annotate mod_profile/mod_profile.lua @ 1491:e7294423512f

mod_net_dovecotauth: Fix typo in config option
author Kim Alvefur <zash@zash.se>
date Tue, 19 Aug 2014 16:54:30 +0200
parents b291a9423e0f
children 698686dca982
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;
1446
843769eb40c3 mod_profile: Don't include photo in vCard4 version (use XEP-0084 instead)
Kim Alvefur <zash@zash.se>
parents: 1442
diff changeset
9 local t_insert, t_remove = table.insert, table.remove;
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
10
877dc87539ff mod_profile: Replacement for mod_vcard with vcard4 support and integration with mod_pep_plus
Kim Alvefur <zash@zash.se>
parents:
diff changeset
11 local pep_plus;
1420
808950ab007b mod_profile: Integrate with mod_pep_plus by default
Kim Alvefur <zash@zash.se>
parents: 1419
diff changeset
12 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
13 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
14 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
15
1442
253e374824a8 mod_profile: Load profile into PEP on initial presence
Kim Alvefur <zash@zash.se>
parents: 1441
diff changeset
16 local loaded_pep_for = module:shared"loaded-pep-for";
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
17 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
18 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
19
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 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
21 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
22 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
23 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
24 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
25 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
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 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
28 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
29
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 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
31 ["\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
32 ["\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
33 ["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
34 ["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
35 ["<?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
36 }
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 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
38 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
39 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
40 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
41 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
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 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
44 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
45
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 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
47 local pep = pep_plus.get_pep_service(username.."@"..module.host);
1446
843769eb40c3 mod_profile: Don't include photo in vCard4 version (use XEP-0084 instead)
Kim Alvefur <zash@zash.se>
parents: 1442
diff changeset
48 local photo, p = get_item(data, "PHOTO");
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 if vcard.to_vcard4 then
1446
843769eb40c3 mod_profile: Don't include photo in vCard4 version (use XEP-0084 instead)
Kim Alvefur <zash@zash.se>
parents: 1442
diff changeset
50 if p then t_remove(data, p); end
1422
c3882787ae06 mod_profile: Purge nodes before publishing new items
Kim Alvefur <zash@zash.se>
parents: 1420
diff changeset
51 pep:purge("urn:xmpp:vcard4", true);
1424
9892a537e7fc mod_profile: Add id to item tag too.
Kim Alvefur <zash@zash.se>
parents: 1423
diff changeset
52 pep:publish("urn:xmpp:vcard4", true, "current", st.stanza("item", {id="current"})
9892a537e7fc mod_profile: Add id to item tag too.
Kim Alvefur <zash@zash.se>
parents: 1423
diff changeset
53 :add_child(vcard.to_vcard4(data)));
1446
843769eb40c3 mod_profile: Don't include photo in vCard4 version (use XEP-0084 instead)
Kim Alvefur <zash@zash.se>
parents: 1442
diff changeset
54 if p then t_insert(data, p, photo); end
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 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
56
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 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
58 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
59 pep:purge("http://jabber.org/protocol/nick", true);
1424
9892a537e7fc mod_profile: Add id to item tag too.
Kim Alvefur <zash@zash.se>
parents: 1423
diff changeset
60 pep:publish("http://jabber.org/protocol/nick", true, "current", st.stanza("item", {id="current"})
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
61 :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
62 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
63
877dc87539ff mod_profile: Replacement for mod_vcard with vcard4 support and integration with mod_pep_plus
Kim Alvefur <zash@zash.se>
parents:
diff changeset
64 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
65 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
66 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
67
1422
c3882787ae06 mod_profile: Purge nodes before publishing new items
Kim Alvefur <zash@zash.se>
parents: 1420
diff changeset
68 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
69 pep:purge("urn:xmpp:avatar:data", true);
1424
9892a537e7fc mod_profile: Add id to item tag too.
Kim Alvefur <zash@zash.se>
parents: 1423
diff changeset
70 pep:publish("urn:xmpp:avatar:metadata", true, "current", st.stanza("item", {id="current"})
1469
019746bba318 mod_profile: Add the missing <info> child element and move info attributes there
Kim Alvefur <zash@zash.se>
parents: 1446
diff changeset
71 :tag("metadata", { xmlns="urn:xmpp:avatar:metadata" })
019746bba318 mod_profile: Add the missing <info> child element and move info attributes there
Kim Alvefur <zash@zash.se>
parents: 1446
diff changeset
72 :tag("info", {
019746bba318 mod_profile: Add the missing <info> child element and move info attributes there
Kim Alvefur <zash@zash.se>
parents: 1446
diff changeset
73 bytes = tostring(#photo_raw),
019746bba318 mod_profile: Add the missing <info> child element and move info attributes there
Kim Alvefur <zash@zash.se>
parents: 1446
diff changeset
74 id = photo_hash,
019746bba318 mod_profile: Add the missing <info> child element and move info attributes there
Kim Alvefur <zash@zash.se>
parents: 1446
diff changeset
75 type = identify(photo_raw),
019746bba318 mod_profile: Add the missing <info> child element and move info attributes there
Kim Alvefur <zash@zash.se>
parents: 1446
diff changeset
76 }));
1470
b291a9423e0f mod_profile: Fix wrong use of "current" as id for avatar data
Kim Alvefur <zash@zash.se>
parents: 1469
diff changeset
77 pep:publish("urn:xmpp:avatar:data", true, photo_hash, st.stanza("item", {id=photo_hash})
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
78 :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
79 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
80 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
81
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 -- 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
83 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
84
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 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
86 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
87 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
88 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
89 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
90 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
91 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
92 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
93 data = data and st.deserialize(data);
1441
07c9306c2c1f mod_profile: Don't pass old vcard data trough vcard lib
Kim Alvefur <zash@zash.se>
parents: 1424
diff changeset
94 if data then
07c9306c2c1f mod_profile: Don't pass old vcard data trough vcard lib
Kim Alvefur <zash@zash.se>
parents: 1424
diff changeset
95 return origin.send(st.reply(stanza):add_child(data));
07c9306c2c1f mod_profile: Don't pass old vcard data trough vcard lib
Kim Alvefur <zash@zash.se>
parents: 1424
diff changeset
96 end
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
97 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
98 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
99 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
100 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
101 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
102 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
103
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 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
105 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
106 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
107 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
108 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
109 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
110 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
111 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
112 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
113 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
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 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
116 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
117 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
118 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
119
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 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
121 update_pep(username, data);
1442
253e374824a8 mod_profile: Load profile into PEP on initial presence
Kim Alvefur <zash@zash.se>
parents: 1441
diff changeset
122 loaded_pep_for[username] = true;
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
123 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
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 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
126 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
127
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 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
129 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
130
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 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
132 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
133
1442
253e374824a8 mod_profile: Load profile into PEP on initial presence
Kim Alvefur <zash@zash.se>
parents: 1441
diff changeset
134 module:hook("presence/initial", function (event)
253e374824a8 mod_profile: Load profile into PEP on initial presence
Kim Alvefur <zash@zash.se>
parents: 1441
diff changeset
135 local username = event.origin.username
253e374824a8 mod_profile: Load profile into PEP on initial presence
Kim Alvefur <zash@zash.se>
parents: 1441
diff changeset
136 if not loaded_pep_for[username] then
253e374824a8 mod_profile: Load profile into PEP on initial presence
Kim Alvefur <zash@zash.se>
parents: 1441
diff changeset
137 data = storage:get(username);
253e374824a8 mod_profile: Load profile into PEP on initial presence
Kim Alvefur <zash@zash.se>
parents: 1441
diff changeset
138 if data then
253e374824a8 mod_profile: Load profile into PEP on initial presence
Kim Alvefur <zash@zash.se>
parents: 1441
diff changeset
139 update_pep(username, data);
253e374824a8 mod_profile: Load profile into PEP on initial presence
Kim Alvefur <zash@zash.se>
parents: 1441
diff changeset
140 end
253e374824a8 mod_profile: Load profile into PEP on initial presence
Kim Alvefur <zash@zash.se>
parents: 1441
diff changeset
141 loaded_pep_for[username] = true;
253e374824a8 mod_profile: Load profile into PEP on initial presence
Kim Alvefur <zash@zash.se>
parents: 1441
diff changeset
142 end
253e374824a8 mod_profile: Load profile into PEP on initial presence
Kim Alvefur <zash@zash.se>
parents: 1441
diff changeset
143 end);
253e374824a8 mod_profile: Load profile into PEP on initial presence
Kim Alvefur <zash@zash.se>
parents: 1441
diff changeset
144
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
145 -- 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
146 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
147 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
148
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-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
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 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
152 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
153 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
154 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
155 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
156 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
157 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
158
877dc87539ff mod_profile: Replacement for mod_vcard with vcard4 support and integration with mod_pep_plus
Kim Alvefur <zash@zash.se>
parents:
diff changeset
159 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
160 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
161 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
162 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
163 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
164 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
165 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
166 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
167 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
168 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
169 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
170 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
171 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
172 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
173 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
174 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
175