Mercurial > prosody-modules
annotate mod_profile/mod_profile.lua @ 4260:c539334dd01a
mod_http_oauth2: Rescope oauth client config into users' storage
This produces client_id of the form owner@host/random and prevents
clients from being deleted by registering an account with the same name
and then deleting the account, as well as having the client
automatically be deleted when the owner account is removed.
On one hand, this leaks the bare JID of the creator to users. On the
other hand, it makes it obvious who made the oauth application.
This module is experimental and only for developers, so this can be
changed if a better method comes up.
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Sat, 21 Nov 2020 23:55:10 +0100 |
parents | 682b05b4017e |
children |
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 |
3185
973caebcb40b
mod_profile: Add copyright header
Kim Alvefur <zash@zash.se>
parents:
3184
diff
changeset
|
2 -- Copyright (C) 2014-2018 Kim Alvefur |
973caebcb40b
mod_profile: Add copyright header
Kim Alvefur <zash@zash.se>
parents:
3184
diff
changeset
|
3 -- |
973caebcb40b
mod_profile: Add copyright header
Kim Alvefur <zash@zash.se>
parents:
3184
diff
changeset
|
4 -- This file is MIT licensed. |
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
|
5 |
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 st = require"util.stanza"; |
1743
8fbe16c83807
mod_profile: Don't use import()
Kim Alvefur <zash@zash.se>
parents:
1516
diff
changeset
|
7 local jid_split = require"util.jid".split; |
8fbe16c83807
mod_profile: Don't use import()
Kim Alvefur <zash@zash.se>
parents:
1516
diff
changeset
|
8 local jid_bare = require"util.jid".bare; |
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
|
9 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
|
10 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
|
11 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
|
12 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
|
13 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
|
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 pep_plus; |
1420
808950ab007b
mod_profile: Integrate with mod_pep_plus by default
Kim Alvefur <zash@zash.se>
parents:
1419
diff
changeset
|
16 if module:get_host_type() == "local" and module:get_option_boolean("vcard_to_pep", true) then |
3207
149cc5ddc64f
mod_profile: Update for mod_pep_plus rename
Kim Alvefur <zash@zash.se>
parents:
3194
diff
changeset
|
17 pep_plus = module:depends"pep"; |
3208
e55172ce68d4
mod_profile: Abort if mod_pep doesn't appear to be the former mod_pep_plus
Kim Alvefur <zash@zash.se>
parents:
3207
diff
changeset
|
18 assert(pep_plus.get_pep_service, "Wrong version of mod_pep loaded, you need to update Prosody"); |
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
|
19 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
|
20 |
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 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
|
22 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
|
23 |
3186
1fe5b156d220
mod_profile: Add support for XEP-0398
Kim Alvefur <zash@zash.se>
parents:
3185
diff
changeset
|
24 module:hook("account-disco-info", function (event) |
1fe5b156d220
mod_profile: Add support for XEP-0398
Kim Alvefur <zash@zash.se>
parents:
3185
diff
changeset
|
25 event.reply:tag("feature", { var = "urn:xmpp:pep-vcard-conversion:0" }):up(); |
1fe5b156d220
mod_profile: Add support for XEP-0398
Kim Alvefur <zash@zash.se>
parents:
3185
diff
changeset
|
26 end); |
1fe5b156d220
mod_profile: Add support for XEP-0398
Kim Alvefur <zash@zash.se>
parents:
3185
diff
changeset
|
27 |
3181
1f2272cda0d7
mod_profile: Ignore shadowed variable name
Kim Alvefur <zash@zash.se>
parents:
2790
diff
changeset
|
28 local function get_item(vcard, name) -- luacheck: ignore 431 |
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
|
29 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
|
30 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
|
31 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
|
32 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
|
33 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
|
34 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
|
35 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
|
36 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
|
37 |
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 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
|
39 ["\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
|
40 ["\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
|
41 ["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
|
42 ["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
|
43 ["<?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
|
44 } |
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 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
|
46 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
|
47 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
|
48 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
|
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 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
|
51 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
|
52 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
|
53 |
3190
76a2aca48b4f
mod_profile: Refactor wrapping of payloads in <item>
Kim Alvefur <zash@zash.se>
parents:
3187
diff
changeset
|
54 local function item_container(id, payload) |
3246
2a54b331f011
mod_profile: Pass item id onto pubsub container element
Kim Alvefur <zash@zash.se>
parents:
3245
diff
changeset
|
55 return id, st.stanza("item", { id = id or "current", xmlns = "http://jabber.org/protocol/pubsub"; }) |
3190
76a2aca48b4f
mod_profile: Refactor wrapping of payloads in <item>
Kim Alvefur <zash@zash.se>
parents:
3187
diff
changeset
|
56 :add_child(payload); |
76a2aca48b4f
mod_profile: Refactor wrapping of payloads in <item>
Kim Alvefur <zash@zash.se>
parents:
3187
diff
changeset
|
57 end |
76a2aca48b4f
mod_profile: Refactor wrapping of payloads in <item>
Kim Alvefur <zash@zash.se>
parents:
3187
diff
changeset
|
58 |
1515
f367d7cbfaa6
mod_profile: Use module:handle_items() for PEP node bootstrapping (see trunk 388786af0dd2)
Kim Alvefur <zash@zash.se>
parents:
1503
diff
changeset
|
59 local function update_pep(username, data, pep) |
2790
5163f7905371
mod_profile: Update get_pep_service() signature to match recent changes to mod_pep_plus (in trunk)
Kim Alvefur <zash@zash.se>
parents:
2413
diff
changeset
|
60 pep = pep or pep_plus.get_pep_service(username); |
1446
843769eb40c3
mod_profile: Don't include photo in vCard4 version (use XEP-0084 instead)
Kim Alvefur <zash@zash.se>
parents:
1442
diff
changeset
|
61 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
|
62 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
|
63 if p then t_remove(data, p); end |
3321
628659e2e6b0
Backed out changeset 395835d89d88: Might still be needed
Kim Alvefur <zash@zash.se>
parents:
3252
diff
changeset
|
64 pep:purge("urn:xmpp:vcard4", true) |
3190
76a2aca48b4f
mod_profile: Refactor wrapping of payloads in <item>
Kim Alvefur <zash@zash.se>
parents:
3187
diff
changeset
|
65 pep:publish("urn:xmpp:vcard4", true, item_container("current", 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
|
66 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
|
67 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
|
68 |
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 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
|
70 if nickname and nickname[1] then |
3321
628659e2e6b0
Backed out changeset 395835d89d88: Might still be needed
Kim Alvefur <zash@zash.se>
parents:
3252
diff
changeset
|
71 pep:purge("http://jabber.org/protocol/nick", true); |
3190
76a2aca48b4f
mod_profile: Refactor wrapping of payloads in <item>
Kim Alvefur <zash@zash.se>
parents:
3187
diff
changeset
|
72 pep:publish("http://jabber.org/protocol/nick", true, item_container("current", |
76a2aca48b4f
mod_profile: Refactor wrapping of payloads in <item>
Kim Alvefur <zash@zash.se>
parents:
3187
diff
changeset
|
73 st.stanza("nick", { xmlns="http://jabber.org/protocol/nick" }):text(nickname[1]))); |
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
|
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 |
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 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
|
77 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
|
78 local photo_hash = sha1(photo_raw, true); |
3245
1d57f485efef
mod_profile: Use type property over content identifiguesstimation
Kim Alvefur <zash@zash.se>
parents:
3208
diff
changeset
|
79 local photo_type = photo.TYPE and photo.TYPE[1]; |
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
|
80 |
3321
628659e2e6b0
Backed out changeset 395835d89d88: Might still be needed
Kim Alvefur <zash@zash.se>
parents:
3252
diff
changeset
|
81 pep:purge("urn:xmpp:avatar:metadata", true); |
628659e2e6b0
Backed out changeset 395835d89d88: Might still be needed
Kim Alvefur <zash@zash.se>
parents:
3252
diff
changeset
|
82 pep:purge("urn:xmpp:avatar:data", true); |
3190
76a2aca48b4f
mod_profile: Refactor wrapping of payloads in <item>
Kim Alvefur <zash@zash.se>
parents:
3187
diff
changeset
|
83 pep:publish("urn:xmpp:avatar:metadata", true, item_container(photo_hash, |
76a2aca48b4f
mod_profile: Refactor wrapping of payloads in <item>
Kim Alvefur <zash@zash.se>
parents:
3187
diff
changeset
|
84 st.stanza("metadata", { xmlns="urn:xmpp:avatar:metadata" }) |
1469
019746bba318
mod_profile: Add the missing <info> child element and move info attributes there
Kim Alvefur <zash@zash.se>
parents:
1446
diff
changeset
|
85 :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
|
86 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
|
87 id = photo_hash, |
3245
1d57f485efef
mod_profile: Use type property over content identifiguesstimation
Kim Alvefur <zash@zash.se>
parents:
3208
diff
changeset
|
88 type = photo_type or identify(photo_raw), |
3190
76a2aca48b4f
mod_profile: Refactor wrapping of payloads in <item>
Kim Alvefur <zash@zash.se>
parents:
3187
diff
changeset
|
89 }))); |
76a2aca48b4f
mod_profile: Refactor wrapping of payloads in <item>
Kim Alvefur <zash@zash.se>
parents:
3187
diff
changeset
|
90 pep:publish("urn:xmpp:avatar:data", true, item_container(photo_hash, |
76a2aca48b4f
mod_profile: Refactor wrapping of payloads in <item>
Kim Alvefur <zash@zash.se>
parents:
3187
diff
changeset
|
91 st.stanza("data", { xmlns="urn:xmpp:avatar:data" }):text(photo[1]))); |
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
|
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 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
|
94 |
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 -- 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
|
96 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
|
97 |
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 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
|
99 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
|
100 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
|
101 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
|
102 if to then username = jid_split(to); end |
1745
851cb0b3d584
mod_profile: Return error on storage error, don't attempt to migrate from old storage
Kim Alvefur <zash@zash.se>
parents:
1744
diff
changeset
|
103 local data, err = storage:get(username); |
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
|
104 if not data then |
1745
851cb0b3d584
mod_profile: Return error on storage error, don't attempt to migrate from old storage
Kim Alvefur <zash@zash.se>
parents:
1744
diff
changeset
|
105 if err then |
851cb0b3d584
mod_profile: Return error on storage error, don't attempt to migrate from old storage
Kim Alvefur <zash@zash.se>
parents:
1744
diff
changeset
|
106 origin.send(st.error_reply(stanza, "cancel", "internal-server-error", err)); |
851cb0b3d584
mod_profile: Return error on storage error, don't attempt to migrate from old storage
Kim Alvefur <zash@zash.se>
parents:
1744
diff
changeset
|
107 return true; |
851cb0b3d584
mod_profile: Return error on storage error, don't attempt to migrate from old storage
Kim Alvefur <zash@zash.se>
parents:
1744
diff
changeset
|
108 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
|
109 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
|
110 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
|
111 if data then |
1744
fbef84033fae
mod_profile: Explicitly return true from handlers, session.send can return nil under some conditions
Kim Alvefur <zash@zash.se>
parents:
1743
diff
changeset
|
112 origin.send(st.reply(stanza):add_child(data)); |
fbef84033fae
mod_profile: Explicitly return true from handlers, session.send can return nil under some conditions
Kim Alvefur <zash@zash.se>
parents:
1743
diff
changeset
|
113 return true; |
1441
07c9306c2c1f
mod_profile: Don't pass old vcard data trough vcard lib
Kim Alvefur <zash@zash.se>
parents:
1424
diff
changeset
|
114 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
|
115 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
|
116 if not data then |
1744
fbef84033fae
mod_profile: Explicitly return true from handlers, session.send can return nil under some conditions
Kim Alvefur <zash@zash.se>
parents:
1743
diff
changeset
|
117 origin.send(st.error_reply(stanza, "cancel", "item-not-found")); |
fbef84033fae
mod_profile: Explicitly return true from handlers, session.send can return nil under some conditions
Kim Alvefur <zash@zash.se>
parents:
1743
diff
changeset
|
118 return 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
|
119 end |
1744
fbef84033fae
mod_profile: Explicitly return true from handlers, session.send can return nil under some conditions
Kim Alvefur <zash@zash.se>
parents:
1743
diff
changeset
|
120 origin.send(st.reply(stanza):add_child(vcard.to_xep54(data))); |
fbef84033fae
mod_profile: Explicitly return true from handlers, session.send can return nil under some conditions
Kim Alvefur <zash@zash.se>
parents:
1743
diff
changeset
|
121 return 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
|
122 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
|
123 |
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 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
|
125 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
|
126 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
|
127 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
|
128 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
|
129 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
|
130 if not is_admin(jid_bare(stanza.attr.from), module.host) then |
1744
fbef84033fae
mod_profile: Explicitly return true from handlers, session.send can return nil under some conditions
Kim Alvefur <zash@zash.se>
parents:
1743
diff
changeset
|
131 origin.send(st.error_reply(stanza, "auth", "forbidden")); |
fbef84033fae
mod_profile: Explicitly return true from handlers, session.send can return nil under some conditions
Kim Alvefur <zash@zash.se>
parents:
1743
diff
changeset
|
132 return 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
|
133 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
|
134 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
|
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 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
|
137 if not ok then |
1744
fbef84033fae
mod_profile: Explicitly return true from handlers, session.send can return nil under some conditions
Kim Alvefur <zash@zash.se>
parents:
1743
diff
changeset
|
138 origin.send(st.error_reply(stanza, "cancel", "internal-server-error", err)); |
fbef84033fae
mod_profile: Explicitly return true from handlers, session.send can return nil under some conditions
Kim Alvefur <zash@zash.se>
parents:
1743
diff
changeset
|
139 return 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
|
140 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
|
141 |
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 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
|
143 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
|
144 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
|
145 |
1744
fbef84033fae
mod_profile: Explicitly return true from handlers, session.send can return nil under some conditions
Kim Alvefur <zash@zash.se>
parents:
1743
diff
changeset
|
146 origin.send(st.reply(stanza)); |
fbef84033fae
mod_profile: Explicitly return true from handlers, session.send can return nil under some conditions
Kim Alvefur <zash@zash.se>
parents:
1743
diff
changeset
|
147 return 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
|
148 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
|
149 |
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 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
|
151 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
|
152 |
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 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
|
154 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
|
155 |
1516
48d95ab404c7
mod_profile: Save photo and nickname from PEP to vCard
Kim Alvefur <zash@zash.se>
parents:
1515
diff
changeset
|
156 local function on_publish(event) |
48d95ab404c7
mod_profile: Save photo and nickname from PEP to vCard
Kim Alvefur <zash@zash.se>
parents:
1515
diff
changeset
|
157 if event.actor == true then return end -- Not from a client |
48d95ab404c7
mod_profile: Save photo and nickname from PEP to vCard
Kim Alvefur <zash@zash.se>
parents:
1515
diff
changeset
|
158 local node, item = event.node, event.item; |
2413
b64c0150d663
mod_profile: Add warning and debug logging in order to catch a weird event
Kim Alvefur <zash@zash.se>
parents:
1745
diff
changeset
|
159 local username, host = jid_split(event.actor); |
b64c0150d663
mod_profile: Add warning and debug logging in order to catch a weird event
Kim Alvefur <zash@zash.se>
parents:
1745
diff
changeset
|
160 if host ~= module.host then |
b64c0150d663
mod_profile: Add warning and debug logging in order to catch a weird event
Kim Alvefur <zash@zash.se>
parents:
1745
diff
changeset
|
161 module:log("warn", "on_publish() called for non-local actor"); |
b64c0150d663
mod_profile: Add warning and debug logging in order to catch a weird event
Kim Alvefur <zash@zash.se>
parents:
1745
diff
changeset
|
162 for k,v in pairs(event) do |
3184 | 163 module:log("debug", "event[%q] = %q", k, v); |
2413
b64c0150d663
mod_profile: Add warning and debug logging in order to catch a weird event
Kim Alvefur <zash@zash.se>
parents:
1745
diff
changeset
|
164 end |
b64c0150d663
mod_profile: Add warning and debug logging in order to catch a weird event
Kim Alvefur <zash@zash.se>
parents:
1745
diff
changeset
|
165 return; |
b64c0150d663
mod_profile: Add warning and debug logging in order to catch a weird event
Kim Alvefur <zash@zash.se>
parents:
1745
diff
changeset
|
166 end |
1516
48d95ab404c7
mod_profile: Save photo and nickname from PEP to vCard
Kim Alvefur <zash@zash.se>
parents:
1515
diff
changeset
|
167 local data = storage:get(username) or {}; |
48d95ab404c7
mod_profile: Save photo and nickname from PEP to vCard
Kim Alvefur <zash@zash.se>
parents:
1515
diff
changeset
|
168 if node == "urn:xmpp:avatar:data" then |
48d95ab404c7
mod_profile: Save photo and nickname from PEP to vCard
Kim Alvefur <zash@zash.se>
parents:
1515
diff
changeset
|
169 local new_photo = item:get_child_text("data", "urn:xmpp:avatar:data"); |
48d95ab404c7
mod_profile: Save photo and nickname from PEP to vCard
Kim Alvefur <zash@zash.se>
parents:
1515
diff
changeset
|
170 new_photo = new_photo and { name = "PHOTO"; ENCODING = { "b" }; new_photo } or nil; |
48d95ab404c7
mod_profile: Save photo and nickname from PEP to vCard
Kim Alvefur <zash@zash.se>
parents:
1515
diff
changeset
|
171 local _, i = get_item(data, "PHOTO") |
48d95ab404c7
mod_profile: Save photo and nickname from PEP to vCard
Kim Alvefur <zash@zash.se>
parents:
1515
diff
changeset
|
172 if new_photo then |
48d95ab404c7
mod_profile: Save photo and nickname from PEP to vCard
Kim Alvefur <zash@zash.se>
parents:
1515
diff
changeset
|
173 data[i or #data+1] = new_photo; |
48d95ab404c7
mod_profile: Save photo and nickname from PEP to vCard
Kim Alvefur <zash@zash.se>
parents:
1515
diff
changeset
|
174 elseif i then |
48d95ab404c7
mod_profile: Save photo and nickname from PEP to vCard
Kim Alvefur <zash@zash.se>
parents:
1515
diff
changeset
|
175 table.remove(data, i); |
48d95ab404c7
mod_profile: Save photo and nickname from PEP to vCard
Kim Alvefur <zash@zash.se>
parents:
1515
diff
changeset
|
176 end |
48d95ab404c7
mod_profile: Save photo and nickname from PEP to vCard
Kim Alvefur <zash@zash.se>
parents:
1515
diff
changeset
|
177 elseif node == "http://jabber.org/protocol/nick" then |
48d95ab404c7
mod_profile: Save photo and nickname from PEP to vCard
Kim Alvefur <zash@zash.se>
parents:
1515
diff
changeset
|
178 local new_nick = item:get_child_text("nick", "http://jabber.org/protocol/nick"); |
48d95ab404c7
mod_profile: Save photo and nickname from PEP to vCard
Kim Alvefur <zash@zash.se>
parents:
1515
diff
changeset
|
179 new_nick = new_nick and new_nick ~= "" and { name = "NICKNAME"; new_nick } or nil; |
48d95ab404c7
mod_profile: Save photo and nickname from PEP to vCard
Kim Alvefur <zash@zash.se>
parents:
1515
diff
changeset
|
180 local _, i = get_item(data, "NICKNAME") |
48d95ab404c7
mod_profile: Save photo and nickname from PEP to vCard
Kim Alvefur <zash@zash.se>
parents:
1515
diff
changeset
|
181 if new_nick then |
48d95ab404c7
mod_profile: Save photo and nickname from PEP to vCard
Kim Alvefur <zash@zash.se>
parents:
1515
diff
changeset
|
182 data[i or #data+1] = new_nick; |
48d95ab404c7
mod_profile: Save photo and nickname from PEP to vCard
Kim Alvefur <zash@zash.se>
parents:
1515
diff
changeset
|
183 elseif i then |
48d95ab404c7
mod_profile: Save photo and nickname from PEP to vCard
Kim Alvefur <zash@zash.se>
parents:
1515
diff
changeset
|
184 table.remove(data, i); |
48d95ab404c7
mod_profile: Save photo and nickname from PEP to vCard
Kim Alvefur <zash@zash.se>
parents:
1515
diff
changeset
|
185 end |
48d95ab404c7
mod_profile: Save photo and nickname from PEP to vCard
Kim Alvefur <zash@zash.se>
parents:
1515
diff
changeset
|
186 else |
48d95ab404c7
mod_profile: Save photo and nickname from PEP to vCard
Kim Alvefur <zash@zash.se>
parents:
1515
diff
changeset
|
187 return; |
48d95ab404c7
mod_profile: Save photo and nickname from PEP to vCard
Kim Alvefur <zash@zash.se>
parents:
1515
diff
changeset
|
188 end |
48d95ab404c7
mod_profile: Save photo and nickname from PEP to vCard
Kim Alvefur <zash@zash.se>
parents:
1515
diff
changeset
|
189 storage:set(username, data); |
48d95ab404c7
mod_profile: Save photo and nickname from PEP to vCard
Kim Alvefur <zash@zash.se>
parents:
1515
diff
changeset
|
190 end |
48d95ab404c7
mod_profile: Save photo and nickname from PEP to vCard
Kim Alvefur <zash@zash.se>
parents:
1515
diff
changeset
|
191 |
1515
f367d7cbfaa6
mod_profile: Use module:handle_items() for PEP node bootstrapping (see trunk 388786af0dd2)
Kim Alvefur <zash@zash.se>
parents:
1503
diff
changeset
|
192 local function pep_service_added(event) |
f367d7cbfaa6
mod_profile: Use module:handle_items() for PEP node bootstrapping (see trunk 388786af0dd2)
Kim Alvefur <zash@zash.se>
parents:
1503
diff
changeset
|
193 local item = event.item; |
f367d7cbfaa6
mod_profile: Use module:handle_items() for PEP node bootstrapping (see trunk 388786af0dd2)
Kim Alvefur <zash@zash.se>
parents:
1503
diff
changeset
|
194 local service, username = item.service, jid_split(item.jid); |
3322
682b05b4017e
mod_profile: Fix PEP event handler to detach on unload
Kim Alvefur <zash@zash.se>
parents:
3321
diff
changeset
|
195 module:hook_object_event(service.events, "item-published", on_publish); |
1515
f367d7cbfaa6
mod_profile: Use module:handle_items() for PEP node bootstrapping (see trunk 388786af0dd2)
Kim Alvefur <zash@zash.se>
parents:
1503
diff
changeset
|
196 local data = storage:get(username); |
f367d7cbfaa6
mod_profile: Use module:handle_items() for PEP node bootstrapping (see trunk 388786af0dd2)
Kim Alvefur <zash@zash.se>
parents:
1503
diff
changeset
|
197 if data then |
f367d7cbfaa6
mod_profile: Use module:handle_items() for PEP node bootstrapping (see trunk 388786af0dd2)
Kim Alvefur <zash@zash.se>
parents:
1503
diff
changeset
|
198 update_pep(username, data, service); |
1442
253e374824a8
mod_profile: Load profile into PEP on initial presence
Kim Alvefur <zash@zash.se>
parents:
1441
diff
changeset
|
199 end |
1515
f367d7cbfaa6
mod_profile: Use module:handle_items() for PEP node bootstrapping (see trunk 388786af0dd2)
Kim Alvefur <zash@zash.se>
parents:
1503
diff
changeset
|
200 end |
f367d7cbfaa6
mod_profile: Use module:handle_items() for PEP node bootstrapping (see trunk 388786af0dd2)
Kim Alvefur <zash@zash.se>
parents:
1503
diff
changeset
|
201 |
f367d7cbfaa6
mod_profile: Use module:handle_items() for PEP node bootstrapping (see trunk 388786af0dd2)
Kim Alvefur <zash@zash.se>
parents:
1503
diff
changeset
|
202 local function pep_service_removed() |
f367d7cbfaa6
mod_profile: Use module:handle_items() for PEP node bootstrapping (see trunk 388786af0dd2)
Kim Alvefur <zash@zash.se>
parents:
1503
diff
changeset
|
203 -- This would happen when mod_pep_plus gets unloaded, but this module gets unloaded before that |
f367d7cbfaa6
mod_profile: Use module:handle_items() for PEP node bootstrapping (see trunk 388786af0dd2)
Kim Alvefur <zash@zash.se>
parents:
1503
diff
changeset
|
204 end |
f367d7cbfaa6
mod_profile: Use module:handle_items() for PEP node bootstrapping (see trunk 388786af0dd2)
Kim Alvefur <zash@zash.se>
parents:
1503
diff
changeset
|
205 |
f367d7cbfaa6
mod_profile: Use module:handle_items() for PEP node bootstrapping (see trunk 388786af0dd2)
Kim Alvefur <zash@zash.se>
parents:
1503
diff
changeset
|
206 function module.load() |
f367d7cbfaa6
mod_profile: Use module:handle_items() for PEP node bootstrapping (see trunk 388786af0dd2)
Kim Alvefur <zash@zash.se>
parents:
1503
diff
changeset
|
207 module:handle_items("pep-service", pep_service_added, pep_service_removed, true); |
f367d7cbfaa6
mod_profile: Use module:handle_items() for PEP node bootstrapping (see trunk 388786af0dd2)
Kim Alvefur <zash@zash.se>
parents:
1503
diff
changeset
|
208 end |
1442
253e374824a8
mod_profile: Load profile into PEP on initial presence
Kim Alvefur <zash@zash.se>
parents:
1441
diff
changeset
|
209 |
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
|
210 -- 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
|
211 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
|
212 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
|
213 |
877dc87539ff
mod_profile: Replacement for mod_vcard with vcard4 support and integration with mod_pep_plus
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
214 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
|
215 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
|
216 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
|
217 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
|
218 if not data then |
1744
fbef84033fae
mod_profile: Explicitly return true from handlers, session.send can return nil under some conditions
Kim Alvefur <zash@zash.se>
parents:
1743
diff
changeset
|
219 origin.send(st.error_reply(stanza, "cancel", "item-not-found")); |
fbef84033fae
mod_profile: Explicitly return true from handlers, session.send can return nil under some conditions
Kim Alvefur <zash@zash.se>
parents:
1743
diff
changeset
|
220 return 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
|
221 end |
1744
fbef84033fae
mod_profile: Explicitly return true from handlers, session.send can return nil under some conditions
Kim Alvefur <zash@zash.se>
parents:
1743
diff
changeset
|
222 origin.send(st.reply(stanza):add_child(vcard.to_vcard4(data))); |
fbef84033fae
mod_profile: Explicitly return true from handlers, session.send can return nil under some conditions
Kim Alvefur <zash@zash.se>
parents:
1743
diff
changeset
|
223 return 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
|
224 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
|
225 |
877dc87539ff
mod_profile: Replacement for mod_vcard with vcard4 support and integration with mod_pep_plus
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
226 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
|
227 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
|
228 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
|
229 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
|
230 if not ok then |
1744
fbef84033fae
mod_profile: Explicitly return true from handlers, session.send can return nil under some conditions
Kim Alvefur <zash@zash.se>
parents:
1743
diff
changeset
|
231 origin.send(st.error_reply(stanza, "cancel", "internal-server-error", err)); |
fbef84033fae
mod_profile: Explicitly return true from handlers, session.send can return nil under some conditions
Kim Alvefur <zash@zash.se>
parents:
1743
diff
changeset
|
232 return 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
|
233 end |
1744
fbef84033fae
mod_profile: Explicitly return true from handlers, session.send can return nil under some conditions
Kim Alvefur <zash@zash.se>
parents:
1743
diff
changeset
|
234 origin.send(st.reply(stanza)); |
fbef84033fae
mod_profile: Explicitly return true from handlers, session.send can return nil under some conditions
Kim Alvefur <zash@zash.se>
parents:
1743
diff
changeset
|
235 return 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
|
236 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
|
237 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
|
238 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
|
239 local origin, stanza = event.origin, event.stanza; |
1744
fbef84033fae
mod_profile: Explicitly return true from handlers, session.send can return nil under some conditions
Kim Alvefur <zash@zash.se>
parents:
1743
diff
changeset
|
240 origin.send(st.error_reply(stanza, "cancel", "feature-not-implemented")); |
fbef84033fae
mod_profile: Explicitly return true from handlers, session.send can return nil under some conditions
Kim Alvefur <zash@zash.se>
parents:
1743
diff
changeset
|
241 return 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
|
242 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
|
243 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
|
244 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
|
245 |
3186
1fe5b156d220
mod_profile: Add support for XEP-0398
Kim Alvefur <zash@zash.se>
parents:
3185
diff
changeset
|
246 local function inject_xep153(event) |
1fe5b156d220
mod_profile: Add support for XEP-0398
Kim Alvefur <zash@zash.se>
parents:
3185
diff
changeset
|
247 local origin, stanza = event.origin, event.stanza; |
1fe5b156d220
mod_profile: Add support for XEP-0398
Kim Alvefur <zash@zash.se>
parents:
3185
diff
changeset
|
248 local username = origin.username; |
3187
7c450c27d4ba
mod_profile: Skip injecting xep153 into presence for sessions with no username
Kim Alvefur <zash@zash.se>
parents:
3186
diff
changeset
|
249 if not username then return end |
3186
1fe5b156d220
mod_profile: Add support for XEP-0398
Kim Alvefur <zash@zash.se>
parents:
3185
diff
changeset
|
250 local pep = pep_plus.get_pep_service(username); |
1fe5b156d220
mod_profile: Add support for XEP-0398
Kim Alvefur <zash@zash.se>
parents:
3185
diff
changeset
|
251 |
3251
60821653c5a9
mod_profile: Only retrieve the last avatar hash from PEP
Kim Alvefur <zash@zash.se>
parents:
3246
diff
changeset
|
252 local ok, avatar_hash = pep:get_last_item("urn:xmpp:avatar:metadata", true); |
60821653c5a9
mod_profile: Only retrieve the last avatar hash from PEP
Kim Alvefur <zash@zash.se>
parents:
3246
diff
changeset
|
253 if ok and avatar_hash then |
3252
eec70a863d16
mod_profile: Only replace avatar update hash if one is found
Kim Alvefur <zash@zash.se>
parents:
3251
diff
changeset
|
254 stanza:remove_children("x", "vcard-temp:x:update"); |
eec70a863d16
mod_profile: Only replace avatar update hash if one is found
Kim Alvefur <zash@zash.se>
parents:
3251
diff
changeset
|
255 local x_update = st.stanza("x", { xmlns = "vcard-temp:x:update" }); |
3251
60821653c5a9
mod_profile: Only retrieve the last avatar hash from PEP
Kim Alvefur <zash@zash.se>
parents:
3246
diff
changeset
|
256 x_update:text_tag("photo", avatar_hash); |
3252
eec70a863d16
mod_profile: Only replace avatar update hash if one is found
Kim Alvefur <zash@zash.se>
parents:
3251
diff
changeset
|
257 stanza:add_direct_child(x_update); |
3186
1fe5b156d220
mod_profile: Add support for XEP-0398
Kim Alvefur <zash@zash.se>
parents:
3185
diff
changeset
|
258 end |
1fe5b156d220
mod_profile: Add support for XEP-0398
Kim Alvefur <zash@zash.se>
parents:
3185
diff
changeset
|
259 end |
1fe5b156d220
mod_profile: Add support for XEP-0398
Kim Alvefur <zash@zash.se>
parents:
3185
diff
changeset
|
260 |
1fe5b156d220
mod_profile: Add support for XEP-0398
Kim Alvefur <zash@zash.se>
parents:
3185
diff
changeset
|
261 if pep_plus then |
3193
92d80b6ce375
mod_profile: Bump priority of xep153 hook to surely run before mod_presence
Kim Alvefur <zash@zash.se>
parents:
3192
diff
changeset
|
262 module:hook("pre-presence/full", inject_xep153, 1) |
92d80b6ce375
mod_profile: Bump priority of xep153 hook to surely run before mod_presence
Kim Alvefur <zash@zash.se>
parents:
3192
diff
changeset
|
263 module:hook("pre-presence/bare", inject_xep153, 1) |
92d80b6ce375
mod_profile: Bump priority of xep153 hook to surely run before mod_presence
Kim Alvefur <zash@zash.se>
parents:
3192
diff
changeset
|
264 module:hook("pre-presence/host", inject_xep153, 1) |
3186
1fe5b156d220
mod_profile: Add support for XEP-0398
Kim Alvefur <zash@zash.se>
parents:
3185
diff
changeset
|
265 end |