comparison mod_smacks/mod_smacks.lua @ 1517:8ac4438925cf

mod_smacks: Examine the state of the stanza *before* it was send
author Florian Zeitz <florob@babelmonkeys.de>
date Tue, 30 Sep 2014 01:17:10 +0200
parents feca77ad88ac
children 9475fe14d58d
comparison
equal deleted inserted replaced
1516:48d95ab404c7 1517:8ac4438925cf
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 attr = stanza.attr; 85 local xmlns = stanza.attr and stanza.attr.xmlns;
86 if attr and not attr.xmlns then -- Stanza in default stream namespace 86 if not xmlns then -- Stanza in default stream namespace
87 local cached_stanza = st.clone(stanza); 87 local cached_stanza = st.clone(stanza);
88 88
89 if cached_stanza and cached_stanza:get_child("delay", xmlns_delay) == nil then 89 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()}); 90 cached_stanza = cached_stanza:tag("delay", { xmlns = xmlns_delay, from = session.host, stamp = datetime.datetime()});
91 end 91 end
98 -- The session is hibernating, no point in sending the stanza 98 -- The session is hibernating, no point in sending the stanza
99 -- over a dead connection. It will be delivered upon resumption. 99 -- over a dead connection. It will be delivered upon resumption.
100 return true; 100 return true;
101 end 101 end
102 local ok, err = _send(stanza); 102 local ok, err = _send(stanza);
103 if ok and #queue > max_unacked_stanzas and not session.awaiting_ack and attr and not attr.xmlns then 103 if ok and #queue > max_unacked_stanzas and not session.awaiting_ack and not xmlns then
104 session.awaiting_ack = true; 104 session.awaiting_ack = true;
105 return _send(st.stanza("r", sm_attr)); 105 return _send(st.stanza("r", sm_attr));
106 end 106 end
107 return ok, err; 107 return ok, err;
108 end 108 end