comparison mod_smacks/mod_smacks.lua @ 1518:9475fe14d58d

mod_smacks: Correctly check if what is being sent is a stanza
author Kim Alvefur <zash@zash.se>
date Wed, 08 Oct 2014 12:56:21 +0200
parents 8ac4438925cf
children 2881d532f385
comparison
equal deleted inserted replaced
1517:8ac4438925cf 1518:9475fe14d58d
80 queue = session.outgoing_stanza_queue; 80 queue = session.outgoing_stanza_queue;
81 end 81 end
82 82
83 local _send = session.sends2s or session.send; 83 local _send = session.sends2s or session.send;
84 local function new_send(stanza) 84 local function new_send(stanza)
85 local xmlns = stanza.attr and stanza.attr.xmlns; 85 local is_stanza = stanza.attr and not stanza.attr.xmlns;
86 if not xmlns then -- Stanza in default stream namespace 86 if is_stanza then -- Stanza in default stream namespace
87 module:log("debug", "st.clone( %s ) -- %s a stanza", tostring(stanza), is_stanza and "is" or "is not");
87 local cached_stanza = st.clone(stanza); 88 local cached_stanza = st.clone(stanza);
88 89
89 if cached_stanza and cached_stanza:get_child("delay", xmlns_delay) == nil then 90 if cached_stanza and cached_stanza:get_child("delay", xmlns_delay) == nil then
90 cached_stanza = cached_stanza:tag("delay", { xmlns = xmlns_delay, from = session.host, stamp = datetime.datetime()}); 91 cached_stanza = cached_stanza:tag("delay", { xmlns = xmlns_delay, from = session.host, stamp = datetime.datetime()});
91 end 92 end
98 -- The session is hibernating, no point in sending the stanza 99 -- The session is hibernating, no point in sending the stanza
99 -- over a dead connection. It will be delivered upon resumption. 100 -- over a dead connection. It will be delivered upon resumption.
100 return true; 101 return true;
101 end 102 end
102 local ok, err = _send(stanza); 103 local ok, err = _send(stanza);
103 if ok and #queue > max_unacked_stanzas and not session.awaiting_ack and not xmlns then 104 if ok and #queue > max_unacked_stanzas and not session.awaiting_ack and is_stanza then
104 session.awaiting_ack = true; 105 session.awaiting_ack = true;
105 return _send(st.stanza("r", sm_attr)); 106 return _send(st.stanza("r", sm_attr));
106 end 107 end
107 return ok, err; 108 return ok, err;
108 end 109 end