changeset 3956:ebc1f1d962c5

mod_stanzas: tighten up stanza check and add explanatory text
author JC Brand <jc@opkode.com>
date Fri, 27 Mar 2020 11:56:14 +0100 (2020-03-27)
parents 017f60608fc8
children 7e96b95924bd
files mod_smacks/mod_smacks.lua
diffstat 1 files changed, 10 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/mod_smacks/mod_smacks.lua	Thu Mar 26 11:57:02 2020 +0100
+++ b/mod_smacks/mod_smacks.lua	Fri Mar 27 11:56:14 2020 +0100
@@ -199,16 +199,16 @@
 	end
 end
 
-local function is_stanza(stanza)
-	return stanza.attr and
-		(	not stanza.attr.xmlns or
-			stanza.attr.xmlns == 'jabber:client' or
-			stanza.attr.xmlns == 'jabber:server'
-		) and not stanza.name:find":";
-end
+local function outgoing_stanza_filter(stanza, session)
+	-- XXX: Normally you wouldn't have to check the xmlns for a stanza as it's
+	-- supposed to be nil.
+	-- However, when using mod_smacks with mod_websocket, then mod_websocket's
+	-- stanzas/out filter can get called before this one and adds the xmlns.
+	local is_stanza = stanza.attr and
+		(not stanza.attr.xmlns or stanza.attr.xmlns == 'jabber:client')
+		and not stanza.name:find":";
 
-local function outgoing_stanza_filter(stanza, session)
-	if is_stanza(stanza) and not stanza._cached then
+	if is_stanza and not stanza._cached then
 		local queue = session.outgoing_stanza_queue;
 		local cached_stanza = st.clone(stanza);
 		cached_stanza._cached = true;
@@ -233,7 +233,7 @@
 end
 
 local function count_incoming_stanzas(stanza, session)
-	if is_stanza(stanza) then
+	if not stanza.attr.xmlns then
 		session.handled_stanza_count = session.handled_stanza_count + 1;
 		session.log("debug", "Handled %d incoming stanzas", session.handled_stanza_count);
 	end