Mercurial > prosody-modules
comparison mod_smacks/mod_smacks.lua @ 3955:017f60608fc8
mod_smacks: also count outgoing MAM messages
mod_smacks doesn't count outgoing MAM messages, which causes warnings in Prosody such as:
> The client says it handled 41 new stanzas, but we only sent 2
It seems mod_smacks is in the wrong here and that it's too strict in trying to determine what is a valid stanza to count.
In RFC6120:
> Definition of XML Stanza: An XML stanza is the basic unit of meaning
> in XMPP. A stanza is a first-level element (at depth=1 of the stream)
> whose element name is "message", "presence", or "iq" and whose
> qualifying namespace is 'jabber:client' or 'jabber:server'.
| author | JC Brand <jc@opkode.com> |
|---|---|
| date | Thu, 26 Mar 2020 11:57:02 +0100 |
| parents | e93e58b33bf6 |
| children | ebc1f1d962c5 |
comparison
equal
deleted
inserted
replaced
| 3954:7a2998e48545 | 3955:017f60608fc8 |
|---|---|
| 15 local dep = require "util.dependencies"; | 15 local dep = require "util.dependencies"; |
| 16 local cache = dep.softreq("util.cache"); -- only available in prosody 0.10+ | 16 local cache = dep.softreq("util.cache"); -- only available in prosody 0.10+ |
| 17 local uuid_generate = require "util.uuid".generate; | 17 local uuid_generate = require "util.uuid".generate; |
| 18 local jid = require "util.jid"; | 18 local jid = require "util.jid"; |
| 19 | 19 |
| 20 local t_insert, t_remove = table.insert, table.remove; | 20 local t_remove = table.remove; |
| 21 local math_min = math.min; | 21 local math_min = math.min; |
| 22 local math_max = math.max; | 22 local math_max = math.max; |
| 23 local os_time = os.time; | 23 local os_time = os.time; |
| 24 local tonumber, tostring = tonumber, tostring; | 24 local tonumber, tostring = tonumber, tostring; |
| 25 local add_filter = require "util.filters".add_filter; | 25 local add_filter = require "util.filters".add_filter; |
| 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 | |
| 202 local function outgoing_stanza_filter(stanza, session) | 210 local function outgoing_stanza_filter(stanza, session) |
| 203 local is_stanza = stanza.attr and not stanza.attr.xmlns and not stanza.name:find":"; | 211 if is_stanza(stanza) and not stanza._cached then |
| 204 if is_stanza and not stanza._cached then -- Stanza in default stream namespace | |
| 205 local queue = session.outgoing_stanza_queue; | 212 local queue = session.outgoing_stanza_queue; |
| 206 local cached_stanza = st.clone(stanza); | 213 local cached_stanza = st.clone(stanza); |
| 207 cached_stanza._cached = true; | 214 cached_stanza._cached = true; |
| 208 | 215 |
| 209 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 |
| 224 end | 231 end |
| 225 return stanza; | 232 return stanza; |
| 226 end | 233 end |
| 227 | 234 |
| 228 local function count_incoming_stanzas(stanza, session) | 235 local function count_incoming_stanzas(stanza, session) |
| 229 if not stanza.attr.xmlns then | 236 if is_stanza(stanza) then |
| 230 session.handled_stanza_count = session.handled_stanza_count + 1; | 237 session.handled_stanza_count = session.handled_stanza_count + 1; |
| 231 session.log("debug", "Handled %d incoming stanzas", session.handled_stanza_count); | 238 session.log("debug", "Handled %d incoming stanzas", session.handled_stanza_count); |
| 232 end | 239 end |
| 233 return stanza; | 240 return stanza; |
| 234 end | 241 end |
