annotate mod_vcard_muc/mod_vcard_muc.lua @ 6319:04c3273cb81f

mod_auth_cyrus: Add empty 'profile' table to SASL handler objects This is for compatibility with Prosody's built-in util.sasl objects. A SASL profile table usually includes methods supported by the backend, which can be used by SASL mechanism handlers to perform operations (such as testing the password). It also optionally contains a 'cb' field with channel binding method handlers. The Cyrus backend doesn't support channel binding, and doesn't have the same concept of auth backend methods (it handles all that internally, and Prosody has no insight or control over it). Thus, we create an empty profile which informs Prosody that the SASL handler does not support any of the auth or channel binding methods. Some features will not work, but they didn't work anyway. This just makes it explicit. This fixes a traceback in mod_sasl2_fast, which expected SASL handlers to always contain a 'profile' field.
author Matthew Wild <mwild1@gmail.com>
date Thu, 04 Sep 2025 10:14:46 +0100
parents 3e7fe14921d0
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3043
6cc44e69443a mod_vcard_muc: Initial commit
Michel Le Bihan <michel@lebihan.pl>
parents:
diff changeset
1 -- Prosody IM
6cc44e69443a mod_vcard_muc: Initial commit
Michel Le Bihan <michel@lebihan.pl>
parents:
diff changeset
2 -- Copyright (C) 2008-2010 Matthew Wild
6cc44e69443a mod_vcard_muc: Initial commit
Michel Le Bihan <michel@lebihan.pl>
parents:
diff changeset
3 -- Copyright (C) 2008-2010 Waqas Hussain
6cc44e69443a mod_vcard_muc: Initial commit
Michel Le Bihan <michel@lebihan.pl>
parents:
diff changeset
4 -- Copyright (C) 2018 Michel Le Bihan
6cc44e69443a mod_vcard_muc: Initial commit
Michel Le Bihan <michel@lebihan.pl>
parents:
diff changeset
5 --
6cc44e69443a mod_vcard_muc: Initial commit
Michel Le Bihan <michel@lebihan.pl>
parents:
diff changeset
6 -- This project is MIT/X11 licensed. Please see the
6cc44e69443a mod_vcard_muc: Initial commit
Michel Le Bihan <michel@lebihan.pl>
parents:
diff changeset
7 -- COPYING file in the source package for more information.
6cc44e69443a mod_vcard_muc: Initial commit
Michel Le Bihan <michel@lebihan.pl>
parents:
diff changeset
8 --
6166
3e7fe14921d0 mod_vcard_muc: Add conflict with Prosody versions that have native MUC vcards
Matthew Wild <mwild1@gmail.com>
parents: 5904
diff changeset
9 --% conflicts: muc_vcard
3043
6cc44e69443a mod_vcard_muc: Initial commit
Michel Le Bihan <michel@lebihan.pl>
parents:
diff changeset
10
6cc44e69443a mod_vcard_muc: Initial commit
Michel Le Bihan <michel@lebihan.pl>
parents:
diff changeset
11 local st = require "util.stanza"
6cc44e69443a mod_vcard_muc: Initial commit
Michel Le Bihan <michel@lebihan.pl>
parents:
diff changeset
12 local jid_split = require "util.jid".split;
6cc44e69443a mod_vcard_muc: Initial commit
Michel Le Bihan <michel@lebihan.pl>
parents:
diff changeset
13 local base64 = require"util.encodings".base64;
6cc44e69443a mod_vcard_muc: Initial commit
Michel Le Bihan <michel@lebihan.pl>
parents:
diff changeset
14 local sha1 = require"util.hashes".sha1;
6cc44e69443a mod_vcard_muc: Initial commit
Michel Le Bihan <michel@lebihan.pl>
parents:
diff changeset
15
6cc44e69443a mod_vcard_muc: Initial commit
Michel Le Bihan <michel@lebihan.pl>
parents:
diff changeset
16 local mod_muc = module:depends"muc";
6cc44e69443a mod_vcard_muc: Initial commit
Michel Le Bihan <michel@lebihan.pl>
parents:
diff changeset
17
6cc44e69443a mod_vcard_muc: Initial commit
Michel Le Bihan <michel@lebihan.pl>
parents:
diff changeset
18 local vcards = module:open_store();
6cc44e69443a mod_vcard_muc: Initial commit
Michel Le Bihan <michel@lebihan.pl>
parents:
diff changeset
19
6cc44e69443a mod_vcard_muc: Initial commit
Michel Le Bihan <michel@lebihan.pl>
parents:
diff changeset
20 module:add_feature("vcard-temp");
6cc44e69443a mod_vcard_muc: Initial commit
Michel Le Bihan <michel@lebihan.pl>
parents:
diff changeset
21
3077
f16b021e8a61 mod_vcard_muc: Get room from rooms table when get_room_from_jid API is not supported
Michel Le Bihan <michel@lebihan.pl>
parents: 3046
diff changeset
22 local get_room_from_jid = rawget(mod_muc, "get_room_from_jid") or
f16b021e8a61 mod_vcard_muc: Get room from rooms table when get_room_from_jid API is not supported
Michel Le Bihan <michel@lebihan.pl>
parents: 3046
diff changeset
23 function (jid)
f16b021e8a61 mod_vcard_muc: Get room from rooms table when get_room_from_jid API is not supported
Michel Le Bihan <michel@lebihan.pl>
parents: 3046
diff changeset
24 local rooms = rawget(mod_muc, "rooms");
f16b021e8a61 mod_vcard_muc: Get room from rooms table when get_room_from_jid API is not supported
Michel Le Bihan <michel@lebihan.pl>
parents: 3046
diff changeset
25 return rooms[jid];
f16b021e8a61 mod_vcard_muc: Get room from rooms table when get_room_from_jid API is not supported
Michel Le Bihan <michel@lebihan.pl>
parents: 3046
diff changeset
26 end
f16b021e8a61 mod_vcard_muc: Get room from rooms table when get_room_from_jid API is not supported
Michel Le Bihan <michel@lebihan.pl>
parents: 3046
diff changeset
27
3655
d7b589dec591 mod_vcard_muc: Factor out avatar hash retrieval into a function for easier reuse
Kim Alvefur <zash@zash.se>
parents: 3077
diff changeset
28 local function get_photo_hash(room)
d7b589dec591 mod_vcard_muc: Factor out avatar hash retrieval into a function for easier reuse
Kim Alvefur <zash@zash.se>
parents: 3077
diff changeset
29 local room_node = jid_split(room.jid);
3043
6cc44e69443a mod_vcard_muc: Initial commit
Michel Le Bihan <michel@lebihan.pl>
parents:
diff changeset
30 local vcard = st.deserialize(vcards:get(room_node));
6cc44e69443a mod_vcard_muc: Initial commit
Michel Le Bihan <michel@lebihan.pl>
parents:
diff changeset
31 if vcard then
6cc44e69443a mod_vcard_muc: Initial commit
Michel Le Bihan <michel@lebihan.pl>
parents:
diff changeset
32 local photo = vcard:get_child("PHOTO");
6cc44e69443a mod_vcard_muc: Initial commit
Michel Le Bihan <michel@lebihan.pl>
parents:
diff changeset
33
6cc44e69443a mod_vcard_muc: Initial commit
Michel Le Bihan <michel@lebihan.pl>
parents:
diff changeset
34 if photo then
6cc44e69443a mod_vcard_muc: Initial commit
Michel Le Bihan <michel@lebihan.pl>
parents:
diff changeset
35 local photo_b64 = photo:get_child_text("BINVAL");
6cc44e69443a mod_vcard_muc: Initial commit
Michel Le Bihan <michel@lebihan.pl>
parents:
diff changeset
36 local photo_raw = photo_b64 and base64.decode(photo_b64);
3655
d7b589dec591 mod_vcard_muc: Factor out avatar hash retrieval into a function for easier reuse
Kim Alvefur <zash@zash.se>
parents: 3077
diff changeset
37 return sha1(photo_raw, true);
3043
6cc44e69443a mod_vcard_muc: Initial commit
Michel Le Bihan <michel@lebihan.pl>
parents:
diff changeset
38 end
6cc44e69443a mod_vcard_muc: Initial commit
Michel Le Bihan <michel@lebihan.pl>
parents:
diff changeset
39 end
6cc44e69443a mod_vcard_muc: Initial commit
Michel Le Bihan <michel@lebihan.pl>
parents:
diff changeset
40
3655
d7b589dec591 mod_vcard_muc: Factor out avatar hash retrieval into a function for easier reuse
Kim Alvefur <zash@zash.se>
parents: 3077
diff changeset
41 end
d7b589dec591 mod_vcard_muc: Factor out avatar hash retrieval into a function for easier reuse
Kim Alvefur <zash@zash.se>
parents: 3077
diff changeset
42
4300
3f3b672b7616 mod_vcard_muc: Pass room object around instead of JID, hopefully fixing traceback
Matthew Wild <mwild1@gmail.com>
parents: 4043
diff changeset
43 local function broadcast_presence(room, to)
3656
3e0f4d727825 mod_vcard_muc: Add an alternative method of signaling avatar change
Kim Alvefur <zash@zash.se>
parents: 3655
diff changeset
44 local photo_hash = get_photo_hash(room);
4300
3f3b672b7616 mod_vcard_muc: Pass room object around instead of JID, hopefully fixing traceback
Matthew Wild <mwild1@gmail.com>
parents: 4043
diff changeset
45 local presence_vcard = st.presence({to = to, from = room.jid})
3043
6cc44e69443a mod_vcard_muc: Initial commit
Michel Le Bihan <michel@lebihan.pl>
parents:
diff changeset
46 :tag("x", { xmlns = "vcard-temp:x:update" })
6cc44e69443a mod_vcard_muc: Initial commit
Michel Le Bihan <michel@lebihan.pl>
parents:
diff changeset
47 :tag("photo"):text(photo_hash):up();
6cc44e69443a mod_vcard_muc: Initial commit
Michel Le Bihan <michel@lebihan.pl>
parents:
diff changeset
48
6cc44e69443a mod_vcard_muc: Initial commit
Michel Le Bihan <michel@lebihan.pl>
parents:
diff changeset
49 if to == nil then
6cc44e69443a mod_vcard_muc: Initial commit
Michel Le Bihan <michel@lebihan.pl>
parents:
diff changeset
50 room:broadcast_message(presence_vcard);
6cc44e69443a mod_vcard_muc: Initial commit
Michel Le Bihan <michel@lebihan.pl>
parents:
diff changeset
51 else
6cc44e69443a mod_vcard_muc: Initial commit
Michel Le Bihan <michel@lebihan.pl>
parents:
diff changeset
52 module:send(presence_vcard);
6cc44e69443a mod_vcard_muc: Initial commit
Michel Le Bihan <michel@lebihan.pl>
parents:
diff changeset
53 end
6cc44e69443a mod_vcard_muc: Initial commit
Michel Le Bihan <michel@lebihan.pl>
parents:
diff changeset
54 end
6cc44e69443a mod_vcard_muc: Initial commit
Michel Le Bihan <michel@lebihan.pl>
parents:
diff changeset
55
6cc44e69443a mod_vcard_muc: Initial commit
Michel Le Bihan <michel@lebihan.pl>
parents:
diff changeset
56 local function handle_vcard(event)
6cc44e69443a mod_vcard_muc: Initial commit
Michel Le Bihan <michel@lebihan.pl>
parents:
diff changeset
57 local session, stanza = event.origin, event.stanza;
6cc44e69443a mod_vcard_muc: Initial commit
Michel Le Bihan <michel@lebihan.pl>
parents:
diff changeset
58
6cc44e69443a mod_vcard_muc: Initial commit
Michel Le Bihan <michel@lebihan.pl>
parents:
diff changeset
59 local room_jid = stanza.attr.to;
6cc44e69443a mod_vcard_muc: Initial commit
Michel Le Bihan <michel@lebihan.pl>
parents:
diff changeset
60 local room_node = jid_split(room_jid);
6cc44e69443a mod_vcard_muc: Initial commit
Michel Le Bihan <michel@lebihan.pl>
parents:
diff changeset
61 local room = get_room_from_jid(room_jid);
4043
a533abe6ffd0 mod_vcard_muc: Fix #1414 issue with nil room being queried when a stanza with a nonexisting MUC localpart was sent
Michel Le Bihan <michel@lebihan.pl>
parents: 3656
diff changeset
62 if not room then
a533abe6ffd0 mod_vcard_muc: Fix #1414 issue with nil room being queried when a stanza with a nonexisting MUC localpart was sent
Michel Le Bihan <michel@lebihan.pl>
parents: 3656
diff changeset
63 session.send(st.error_reply(stanza, "cancel", "item-not-found"))
a533abe6ffd0 mod_vcard_muc: Fix #1414 issue with nil room being queried when a stanza with a nonexisting MUC localpart was sent
Michel Le Bihan <michel@lebihan.pl>
parents: 3656
diff changeset
64 return true;
a533abe6ffd0 mod_vcard_muc: Fix #1414 issue with nil room being queried when a stanza with a nonexisting MUC localpart was sent
Michel Le Bihan <michel@lebihan.pl>
parents: 3656
diff changeset
65 end
3043
6cc44e69443a mod_vcard_muc: Initial commit
Michel Le Bihan <michel@lebihan.pl>
parents:
diff changeset
66
6cc44e69443a mod_vcard_muc: Initial commit
Michel Le Bihan <michel@lebihan.pl>
parents:
diff changeset
67 local from = stanza.attr.from;
6cc44e69443a mod_vcard_muc: Initial commit
Michel Le Bihan <michel@lebihan.pl>
parents:
diff changeset
68 local from_affiliation = room:get_affiliation(from);
6cc44e69443a mod_vcard_muc: Initial commit
Michel Le Bihan <michel@lebihan.pl>
parents:
diff changeset
69
6cc44e69443a mod_vcard_muc: Initial commit
Michel Le Bihan <michel@lebihan.pl>
parents:
diff changeset
70 if stanza.attr.type == "get" then
6cc44e69443a mod_vcard_muc: Initial commit
Michel Le Bihan <michel@lebihan.pl>
parents:
diff changeset
71 local vCard;
6cc44e69443a mod_vcard_muc: Initial commit
Michel Le Bihan <michel@lebihan.pl>
parents:
diff changeset
72 vCard = st.deserialize(vcards:get(room_node));
6cc44e69443a mod_vcard_muc: Initial commit
Michel Le Bihan <michel@lebihan.pl>
parents:
diff changeset
73
6cc44e69443a mod_vcard_muc: Initial commit
Michel Le Bihan <michel@lebihan.pl>
parents:
diff changeset
74 if vCard then
6cc44e69443a mod_vcard_muc: Initial commit
Michel Le Bihan <michel@lebihan.pl>
parents:
diff changeset
75 session.send(st.reply(stanza):add_child(vCard)); -- send vCard!
6cc44e69443a mod_vcard_muc: Initial commit
Michel Le Bihan <michel@lebihan.pl>
parents:
diff changeset
76 else
6cc44e69443a mod_vcard_muc: Initial commit
Michel Le Bihan <michel@lebihan.pl>
parents:
diff changeset
77 session.send(st.error_reply(stanza, "cancel", "item-not-found"));
6cc44e69443a mod_vcard_muc: Initial commit
Michel Le Bihan <michel@lebihan.pl>
parents:
diff changeset
78 end
6cc44e69443a mod_vcard_muc: Initial commit
Michel Le Bihan <michel@lebihan.pl>
parents:
diff changeset
79 else
5290
dddac5a3f447 mod_vcard_muc: take roles into account for access check
Jonas Schäfer <jonas@wielicki.name>
parents: 4300
diff changeset
80 if from_affiliation == "owner" or (module.may and module:may("muc:automatic-ownership", from)) then
3043
6cc44e69443a mod_vcard_muc: Initial commit
Michel Le Bihan <michel@lebihan.pl>
parents:
diff changeset
81 if vcards:set(room_node, st.preserialize(stanza.tags[1])) then
6cc44e69443a mod_vcard_muc: Initial commit
Michel Le Bihan <michel@lebihan.pl>
parents:
diff changeset
82 session.send(st.reply(stanza):tag("vCard", { xmlns = "vcard-temp" }));
4300
3f3b672b7616 mod_vcard_muc: Pass room object around instead of JID, hopefully fixing traceback
Matthew Wild <mwild1@gmail.com>
parents: 4043
diff changeset
83 broadcast_presence(room, nil)
3656
3e0f4d727825 mod_vcard_muc: Add an alternative method of signaling avatar change
Kim Alvefur <zash@zash.se>
parents: 3655
diff changeset
84
3e0f4d727825 mod_vcard_muc: Add an alternative method of signaling avatar change
Kim Alvefur <zash@zash.se>
parents: 3655
diff changeset
85 room:broadcast_message(st.message({ from = room.jid, type = "groupchat" })
3e0f4d727825 mod_vcard_muc: Add an alternative method of signaling avatar change
Kim Alvefur <zash@zash.se>
parents: 3655
diff changeset
86 :tag("x", { xmlns = "http://jabber.org/protocol/muc#user" })
3e0f4d727825 mod_vcard_muc: Add an alternative method of signaling avatar change
Kim Alvefur <zash@zash.se>
parents: 3655
diff changeset
87 :tag("status", { code = "104" }));
3043
6cc44e69443a mod_vcard_muc: Initial commit
Michel Le Bihan <michel@lebihan.pl>
parents:
diff changeset
88 else
6cc44e69443a mod_vcard_muc: Initial commit
Michel Le Bihan <michel@lebihan.pl>
parents:
diff changeset
89 -- TODO unable to write file, file may be locked, etc, what's the correct error?
6cc44e69443a mod_vcard_muc: Initial commit
Michel Le Bihan <michel@lebihan.pl>
parents:
diff changeset
90 session.send(st.error_reply(stanza, "wait", "internal-server-error"));
6cc44e69443a mod_vcard_muc: Initial commit
Michel Le Bihan <michel@lebihan.pl>
parents:
diff changeset
91 end
6cc44e69443a mod_vcard_muc: Initial commit
Michel Le Bihan <michel@lebihan.pl>
parents:
diff changeset
92 else
6cc44e69443a mod_vcard_muc: Initial commit
Michel Le Bihan <michel@lebihan.pl>
parents:
diff changeset
93 session.send(st.error_reply(stanza, "auth", "forbidden"));
6cc44e69443a mod_vcard_muc: Initial commit
Michel Le Bihan <michel@lebihan.pl>
parents:
diff changeset
94 end
6cc44e69443a mod_vcard_muc: Initial commit
Michel Le Bihan <michel@lebihan.pl>
parents:
diff changeset
95 end
6cc44e69443a mod_vcard_muc: Initial commit
Michel Le Bihan <michel@lebihan.pl>
parents:
diff changeset
96 return true;
6cc44e69443a mod_vcard_muc: Initial commit
Michel Le Bihan <michel@lebihan.pl>
parents:
diff changeset
97 end
6cc44e69443a mod_vcard_muc: Initial commit
Michel Le Bihan <michel@lebihan.pl>
parents:
diff changeset
98
6cc44e69443a mod_vcard_muc: Initial commit
Michel Le Bihan <michel@lebihan.pl>
parents:
diff changeset
99
6cc44e69443a mod_vcard_muc: Initial commit
Michel Le Bihan <michel@lebihan.pl>
parents:
diff changeset
100 module:hook("iq/bare/vcard-temp:vCard", handle_vcard);
6cc44e69443a mod_vcard_muc: Initial commit
Michel Le Bihan <michel@lebihan.pl>
parents:
diff changeset
101 module:hook("iq/host/vcard-temp:vCard", handle_vcard);
6cc44e69443a mod_vcard_muc: Initial commit
Michel Le Bihan <michel@lebihan.pl>
parents:
diff changeset
102
6cc44e69443a mod_vcard_muc: Initial commit
Michel Le Bihan <michel@lebihan.pl>
parents:
diff changeset
103 module:hook("muc-disco#info", function(event)
6cc44e69443a mod_vcard_muc: Initial commit
Michel Le Bihan <michel@lebihan.pl>
parents:
diff changeset
104 event.reply:tag("feature", { var = "vcard-temp" }):up();
3656
3e0f4d727825 mod_vcard_muc: Add an alternative method of signaling avatar change
Kim Alvefur <zash@zash.se>
parents: 3655
diff changeset
105
3e0f4d727825 mod_vcard_muc: Add an alternative method of signaling avatar change
Kim Alvefur <zash@zash.se>
parents: 3655
diff changeset
106 table.insert(event.form, {
5903
6fb26b6691c0 mod_vcard_muc: use XEP-0486 form field for avatar hashes
Jonas Schäfer <jonas@wielicki.name>
parents: 5290
diff changeset
107 name = "muc#roominfo_avatarhash",
5904
d3a72777f149 mod_vcard_muc: fix field type for XEP-0486 field
Jonas Schäfer <jonas@wielicki.name>
parents: 5903
diff changeset
108 type = "text-multi",
3656
3e0f4d727825 mod_vcard_muc: Add an alternative method of signaling avatar change
Kim Alvefur <zash@zash.se>
parents: 3655
diff changeset
109 });
5903
6fb26b6691c0 mod_vcard_muc: use XEP-0486 form field for avatar hashes
Jonas Schäfer <jonas@wielicki.name>
parents: 5290
diff changeset
110 event.formdata["muc#roominfo_avatarhash"] = get_photo_hash(event.room);
3043
6cc44e69443a mod_vcard_muc: Initial commit
Michel Le Bihan <michel@lebihan.pl>
parents:
diff changeset
111 end);
3046
d0db28768980 mod_vcard_muc: Send presence on muc-occupant-session-new event
Michel Le Bihan <michel@lebihan.pl>
parents: 3043
diff changeset
112
d0db28768980 mod_vcard_muc: Send presence on muc-occupant-session-new event
Michel Le Bihan <michel@lebihan.pl>
parents: 3043
diff changeset
113 module:hook("muc-occupant-session-new", function(event)
4300
3f3b672b7616 mod_vcard_muc: Pass room object around instead of JID, hopefully fixing traceback
Matthew Wild <mwild1@gmail.com>
parents: 4043
diff changeset
114 broadcast_presence(event.room, event.jid);
3046
d0db28768980 mod_vcard_muc: Send presence on muc-occupant-session-new event
Michel Le Bihan <michel@lebihan.pl>
parents: 3043
diff changeset
115 end)