annotate mod_muc_ping/mod_muc_ping.lua @ 4651:8231774f5bfd

mod_cloud_notify_encrypted: Ensure body substring remains valid UTF-8 The `body:sub()` call risks splitting the string in the middle of a multi-byte UTF-8 sequence. This should have been caught by util.stanza validation, but that would have caused some havoc, at the very least causing the notification to not be sent. There have been no reports of this happening. Likely because this module isn't widely deployed among users with languages that use many longer UTF-8 sequences. The util.encodings.utf8.valid() function is O(n) where only the last sequence really needs to be checked, but it's in C and expected to be fast.
author Kim Alvefur <zash@zash.se>
date Sun, 22 Aug 2021 13:22:59 +0200
parents a0ca5d0a49ba
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3349
35dc7c38e362 mod_muc_ping: Implements the Server Optimization part of XEP-0410: MUC Self-Ping
Kim Alvefur <zash@zash.se>
parents:
diff changeset
1 local st = require "util.stanza";
35dc7c38e362 mod_muc_ping: Implements the Server Optimization part of XEP-0410: MUC Self-Ping
Kim Alvefur <zash@zash.se>
parents:
diff changeset
2 local jid_bare = import("util.jid", "bare");
35dc7c38e362 mod_muc_ping: Implements the Server Optimization part of XEP-0410: MUC Self-Ping
Kim Alvefur <zash@zash.se>
parents:
diff changeset
3
35dc7c38e362 mod_muc_ping: Implements the Server Optimization part of XEP-0410: MUC Self-Ping
Kim Alvefur <zash@zash.se>
parents:
diff changeset
4 local mod_muc = module:depends"muc";
35dc7c38e362 mod_muc_ping: Implements the Server Optimization part of XEP-0410: MUC Self-Ping
Kim Alvefur <zash@zash.se>
parents:
diff changeset
5 local rooms = rawget(mod_muc, "rooms");
35dc7c38e362 mod_muc_ping: Implements the Server Optimization part of XEP-0410: MUC Self-Ping
Kim Alvefur <zash@zash.se>
parents:
diff changeset
6 if not rooms then
35dc7c38e362 mod_muc_ping: Implements the Server Optimization part of XEP-0410: MUC Self-Ping
Kim Alvefur <zash@zash.se>
parents:
diff changeset
7 module:log("warn", "mod_%s is compatible with Prosody up to 0.10.x", module.name);
35dc7c38e362 mod_muc_ping: Implements the Server Optimization part of XEP-0410: MUC Self-Ping
Kim Alvefur <zash@zash.se>
parents:
diff changeset
8 return;
35dc7c38e362 mod_muc_ping: Implements the Server Optimization part of XEP-0410: MUC Self-Ping
Kim Alvefur <zash@zash.se>
parents:
diff changeset
9 end
35dc7c38e362 mod_muc_ping: Implements the Server Optimization part of XEP-0410: MUC Self-Ping
Kim Alvefur <zash@zash.se>
parents:
diff changeset
10
35dc7c38e362 mod_muc_ping: Implements the Server Optimization part of XEP-0410: MUC Self-Ping
Kim Alvefur <zash@zash.se>
parents:
diff changeset
11 module:hook("iq/full", function (event)
35dc7c38e362 mod_muc_ping: Implements the Server Optimization part of XEP-0410: MUC Self-Ping
Kim Alvefur <zash@zash.se>
parents:
diff changeset
12 local origin, stanza = event.origin, event.stanza;
35dc7c38e362 mod_muc_ping: Implements the Server Optimization part of XEP-0410: MUC Self-Ping
Kim Alvefur <zash@zash.se>
parents:
diff changeset
13 if stanza.attr.type ~= "get" or not stanza:get_child("ping", "urn:xmpp:ping") then
35dc7c38e362 mod_muc_ping: Implements the Server Optimization part of XEP-0410: MUC Self-Ping
Kim Alvefur <zash@zash.se>
parents:
diff changeset
14 return;
35dc7c38e362 mod_muc_ping: Implements the Server Optimization part of XEP-0410: MUC Self-Ping
Kim Alvefur <zash@zash.se>
parents:
diff changeset
15 end
35dc7c38e362 mod_muc_ping: Implements the Server Optimization part of XEP-0410: MUC Self-Ping
Kim Alvefur <zash@zash.se>
parents:
diff changeset
16
35dc7c38e362 mod_muc_ping: Implements the Server Optimization part of XEP-0410: MUC Self-Ping
Kim Alvefur <zash@zash.se>
parents:
diff changeset
17 local from = stanza.attr.from;
35dc7c38e362 mod_muc_ping: Implements the Server Optimization part of XEP-0410: MUC Self-Ping
Kim Alvefur <zash@zash.se>
parents:
diff changeset
18 local room_nick = stanza.attr.to;
35dc7c38e362 mod_muc_ping: Implements the Server Optimization part of XEP-0410: MUC Self-Ping
Kim Alvefur <zash@zash.se>
parents:
diff changeset
19 local room_jid = jid_bare(room_nick);
35dc7c38e362 mod_muc_ping: Implements the Server Optimization part of XEP-0410: MUC Self-Ping
Kim Alvefur <zash@zash.se>
parents:
diff changeset
20
35dc7c38e362 mod_muc_ping: Implements the Server Optimization part of XEP-0410: MUC Self-Ping
Kim Alvefur <zash@zash.se>
parents:
diff changeset
21 local room = rooms[room_jid];
35dc7c38e362 mod_muc_ping: Implements the Server Optimization part of XEP-0410: MUC Self-Ping
Kim Alvefur <zash@zash.se>
parents:
diff changeset
22 if not room then return; end
35dc7c38e362 mod_muc_ping: Implements the Server Optimization part of XEP-0410: MUC Self-Ping
Kim Alvefur <zash@zash.se>
parents:
diff changeset
23
35dc7c38e362 mod_muc_ping: Implements the Server Optimization part of XEP-0410: MUC Self-Ping
Kim Alvefur <zash@zash.se>
parents:
diff changeset
24 if room._jid_nick[from] == room_nick then
35dc7c38e362 mod_muc_ping: Implements the Server Optimization part of XEP-0410: MUC Self-Ping
Kim Alvefur <zash@zash.se>
parents:
diff changeset
25 origin.send(st.reply(stanza));
35dc7c38e362 mod_muc_ping: Implements the Server Optimization part of XEP-0410: MUC Self-Ping
Kim Alvefur <zash@zash.se>
parents:
diff changeset
26 return true;
35dc7c38e362 mod_muc_ping: Implements the Server Optimization part of XEP-0410: MUC Self-Ping
Kim Alvefur <zash@zash.se>
parents:
diff changeset
27 end
35dc7c38e362 mod_muc_ping: Implements the Server Optimization part of XEP-0410: MUC Self-Ping
Kim Alvefur <zash@zash.se>
parents:
diff changeset
28 end);
35dc7c38e362 mod_muc_ping: Implements the Server Optimization part of XEP-0410: MUC Self-Ping
Kim Alvefur <zash@zash.se>
parents:
diff changeset
29
35dc7c38e362 mod_muc_ping: Implements the Server Optimization part of XEP-0410: MUC Self-Ping
Kim Alvefur <zash@zash.se>
parents:
diff changeset
30 module:hook("muc-disco#info", function(event)
35dc7c38e362 mod_muc_ping: Implements the Server Optimization part of XEP-0410: MUC Self-Ping
Kim Alvefur <zash@zash.se>
parents:
diff changeset
31 event.reply:tag("feature", {var="urn:xmpp:ping"}):up();
3647
a0ca5d0a49ba mod_muc_ping: Advertise XEP-0410 feature
Kim Alvefur <zash@zash.se>
parents: 3349
diff changeset
32 event.reply:tag("feature", {var = "http://jabber.org/protocol/muc#self-ping-optimization"}):up();
3349
35dc7c38e362 mod_muc_ping: Implements the Server Optimization part of XEP-0410: MUC Self-Ping
Kim Alvefur <zash@zash.se>
parents:
diff changeset
33 end);