Software /
code /
prosody
Comparison
plugins/mod_smacks.lua @ 11984:a86ae74da96c
mod_smacks: Avoid duplicated queueing using flag on session instead of stanza
Mutating the stanza like this is Really Bad Practice.
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Thu, 02 Dec 2021 13:56:50 +0100 |
parent | 11983:27f2539b4f87 |
child | 11985:3740cf7a66a3 |
comparison
equal
deleted
inserted
replaced
11983:27f2539b4f87 | 11984:a86ae74da96c |
---|---|
196 local function outgoing_stanza_filter(stanza, session) | 196 local function outgoing_stanza_filter(stanza, session) |
197 -- XXX: Normally you wouldn't have to check the xmlns for a stanza as it's | 197 -- XXX: Normally you wouldn't have to check the xmlns for a stanza as it's |
198 -- supposed to be nil. | 198 -- supposed to be nil. |
199 -- However, when using mod_smacks with mod_websocket, then mod_websocket's | 199 -- However, when using mod_smacks with mod_websocket, then mod_websocket's |
200 -- stanzas/out filter can get called before this one and adds the xmlns. | 200 -- stanzas/out filter can get called before this one and adds the xmlns. |
201 if session.resending_unacked then return stanza end | |
201 local is_stanza = st.is_stanza(stanza) and | 202 local is_stanza = st.is_stanza(stanza) and |
202 (not stanza.attr.xmlns or stanza.attr.xmlns == 'jabber:client') | 203 (not stanza.attr.xmlns or stanza.attr.xmlns == 'jabber:client') |
203 and not stanza.name:find":"; | 204 and not stanza.name:find":"; |
204 | 205 |
205 if is_stanza and not stanza._cached then | 206 if is_stanza then |
206 local queue = session.outgoing_stanza_queue; | 207 local queue = session.outgoing_stanza_queue; |
207 local cached_stanza = st.clone(stanza); | 208 local cached_stanza = st.clone(stanza); |
208 cached_stanza._cached = true; | |
209 | 209 |
210 if cached_stanza.name ~= "iq" and cached_stanza:get_child("delay", xmlns_delay) == nil then | 210 if cached_stanza.name ~= "iq" and cached_stanza:get_child("delay", xmlns_delay) == nil then |
211 cached_stanza = cached_stanza:tag("delay", { | 211 cached_stanza = cached_stanza:tag("delay", { |
212 xmlns = xmlns_delay, | 212 xmlns = xmlns_delay, |
213 from = jid.bare(session.full_jid or session.host), | 213 from = jid.bare(session.full_jid or session.host), |
609 -- ...they are what is now left in the outgoing stanza queue | 609 -- ...they are what is now left in the outgoing stanza queue |
610 -- We have to use the send of "session" because we don't want to add our resent stanzas | 610 -- We have to use the send of "session" because we don't want to add our resent stanzas |
611 -- to the outgoing queue again | 611 -- to the outgoing queue again |
612 local queue = original_session.outgoing_stanza_queue; | 612 local queue = original_session.outgoing_stanza_queue; |
613 session.log("debug", "resending all unacked stanzas that are still queued after resume, #queue = %d", #queue); | 613 session.log("debug", "resending all unacked stanzas that are still queued after resume, #queue = %d", #queue); |
614 session.resending_unacked = true; | |
614 for i=1,#queue do | 615 for i=1,#queue do |
615 session.send(queue[i]); | 616 session.send(queue[i]); |
616 end | 617 end |
618 session.resending_unacked = nil; | |
617 session.log("debug", "all stanzas resent, now disabling send() in this migrated session, #queue = %d", #queue); | 619 session.log("debug", "all stanzas resent, now disabling send() in this migrated session, #queue = %d", #queue); |
618 function session.send(stanza) -- luacheck: ignore 432 | 620 function session.send(stanza) -- luacheck: ignore 432 |
619 migrated_session_log("error", "Tried to send stanza on old session migrated by smacks resume (maybe there is a bug?): %s", tostring(stanza)); | 621 migrated_session_log("error", "Tried to send stanza on old session migrated by smacks resume (maybe there is a bug?): %s", tostring(stanza)); |
620 return false; | 622 return false; |
621 end | 623 end |