Comparison

mod_smacks/mod_smacks.lua @ 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
parent 3955:017f60608fc8
child 3968:bf5d91769f99
comparison
equal deleted inserted replaced
3955:017f60608fc8 3956:ebc1f1d962c5
197 session.log("debug", "Calling delayed_ack_function directly (still waiting for ack)"); 197 session.log("debug", "Calling delayed_ack_function directly (still waiting for ack)");
198 delayed_ack_function(session); 198 delayed_ack_function(session);
199 end 199 end
200 end 200 end
201 201
202 local function is_stanza(stanza)
203 return stanza.attr and
204 ( not stanza.attr.xmlns or
205 stanza.attr.xmlns == 'jabber:client' or
206 stanza.attr.xmlns == 'jabber:server'
207 ) and not stanza.name:find":";
208 end
209
210 local function outgoing_stanza_filter(stanza, session) 202 local function outgoing_stanza_filter(stanza, session)
211 if is_stanza(stanza) and not stanza._cached then 203 -- XXX: Normally you wouldn't have to check the xmlns for a stanza as it's
204 -- supposed to be nil.
205 -- However, when using mod_smacks with mod_websocket, then mod_websocket's
206 -- stanzas/out filter can get called before this one and adds the xmlns.
207 local is_stanza = stanza.attr and
208 (not stanza.attr.xmlns or stanza.attr.xmlns == 'jabber:client')
209 and not stanza.name:find":";
210
211 if is_stanza and not stanza._cached then
212 local queue = session.outgoing_stanza_queue; 212 local queue = session.outgoing_stanza_queue;
213 local cached_stanza = st.clone(stanza); 213 local cached_stanza = st.clone(stanza);
214 cached_stanza._cached = true; 214 cached_stanza._cached = true;
215 215
216 if cached_stanza and cached_stanza.name ~= "iq" and cached_stanza:get_child("delay", xmlns_delay) == nil then 216 if cached_stanza and cached_stanza.name ~= "iq" and cached_stanza:get_child("delay", xmlns_delay) == nil then
231 end 231 end
232 return stanza; 232 return stanza;
233 end 233 end
234 234
235 local function count_incoming_stanzas(stanza, session) 235 local function count_incoming_stanzas(stanza, session)
236 if is_stanza(stanza) then 236 if not stanza.attr.xmlns then
237 session.handled_stanza_count = session.handled_stanza_count + 1; 237 session.handled_stanza_count = session.handled_stanza_count + 1;
238 session.log("debug", "Handled %d incoming stanzas", session.handled_stanza_count); 238 session.log("debug", "Handled %d incoming stanzas", session.handled_stanza_count);
239 end 239 end
240 return stanza; 240 return stanza;
241 end 241 end