comparison mod_smacks/mod_smacks.lua @ 927:a9dfa7232d88

Merge
author Matthew Wild <mwild1@gmail.com>
date Tue, 12 Mar 2013 12:10:25 +0000
parents 720b8268778e
children fabff75bfc3f
comparison
equal deleted inserted replaced
926:f88381a39c56 927:a9dfa7232d88
80 if cached_stanza and cached_stanza:get_child("delay", xmlns_delay) == nil then 80 if cached_stanza and cached_stanza:get_child("delay", xmlns_delay) == nil then
81 cached_stanza = cached_stanza:tag("delay", { xmlns = xmlns_delay, from = session.host, stamp = datetime.datetime()}); 81 cached_stanza = cached_stanza:tag("delay", { xmlns = xmlns_delay, from = session.host, stamp = datetime.datetime()});
82 end 82 end
83 83
84 queue[#queue+1] = cached_stanza; 84 queue[#queue+1] = cached_stanza;
85 end
86 if session.hibernating then
87 -- The session is hibernating, no point in sending the stanza
88 -- over a dead connection. It will be delivered upon resumption.
89 return true;
85 end 90 end
86 local ok, err = _send(stanza); 91 local ok, err = _send(stanza);
87 if ok and #queue > max_unacked_stanzas and not session.awaiting_ack and attr and not attr.xmlns then 92 if ok and #queue > max_unacked_stanzas and not session.awaiting_ack and attr and not attr.xmlns then
88 session.awaiting_ack = true; 93 session.awaiting_ack = true;
89 return _send(st.stanza("r", sm_attr)); 94 return _send(st.stanza("r", sm_attr));
201 end 206 end
202 end 207 end
203 208
204 module:hook("pre-resource-unbind", function (event) 209 module:hook("pre-resource-unbind", function (event)
205 local session, err = event.session, event.error; 210 local session, err = event.session, event.error;
206 if session.smacks and err ~= "session closed" then 211 if session.smacks and err then
207 if not session.resumption_token then 212 if not session.resumption_token then
208 local queue = session.outgoing_stanza_queue; 213 local queue = session.outgoing_stanza_queue;
209 if #queue > 0 then 214 if #queue > 0 then
210 module:log("warn", "Destroying session with %d unacked stanzas:", #queue); 215 module:log("warn", "Destroying session with %d unacked stanzas:", #queue);
211 for i=1,#queue do 216 for i=1,#queue do
242 247
243 end 248 end
244 end); 249 end);
245 250
246 module:hook_stanza(xmlns_sm, "resume", function (session, stanza) 251 module:hook_stanza(xmlns_sm, "resume", function (session, stanza)
252 if session.full_jid then
253 session.log("debug", "Tried to resume after resource binding");
254 session.send(st.stanza("failed", sm_attr)
255 :tag("unexpected-request", { xmlns = xmlns_errors })
256 );
257 return true;
258 end
259
247 local id = stanza.attr.previd; 260 local id = stanza.attr.previd;
248 local original_session = session_registry[id]; 261 local original_session = session_registry[id];
249 if not original_session then 262 if not original_session then
250 session.log("debug", "Tried to resume non-existent session with id %s", id); 263 session.log("debug", "Tried to resume non-existent session with id %s", id);
251 session.send(st.stanza("failed", sm_attr) 264 session.send(st.stanza("failed", sm_attr)