# HG changeset patch # User Matthew Wild # Date 1286464687 -3600 # Node ID 08fa42e1ab06bddc87bac0bdb1d47340d618e6b7 # Parent 57de4a7840ef3690b4c1438e468de23cfba89a10 mod_smacks: Fixes for monkey-patched sessionmanager.destroy to handle stream resumption, and to fall back to stock destroy() if the session is not smacks-enabled. diff -r 57de4a7840ef -r 08fa42e1ab06 mod_smacks/mod_smacks.lua --- a/mod_smacks/mod_smacks.lua Thu Oct 07 16:16:49 2010 +0100 +++ b/mod_smacks/mod_smacks.lua Thu Oct 07 16:18:07 2010 +0100 @@ -4,11 +4,13 @@ local math_min = math.min; local tonumber, tostring = tonumber, tostring; local add_filter = require "util.filters".add_filter; +local timer = require "util.timer"; local xmlns_sm = "urn:xmpp:sm:2"; local sm_attr = { xmlns = xmlns_sm }; +local resume_timeout = 300; local max_unacked_stanzas = 0; module:add_event_hook("stream-features", @@ -121,13 +123,24 @@ local _destroy_session = sessionmanager.destroy_session; function sessionmanager.destroy_session(session, err) if session.smacks then - local queue = session.outgoing_stanza_queue; - if #queue > 0 then - module:log("warn", "Destroying session with %d unacked stanzas:", #queue); - for i=1,#queue do - module:log("warn", "::%s", tostring(queue[i])); + if not session.resumption_token then + local queue = session.outgoing_stanza_queue; + if #queue > 0 then + module:log("warn", "Destroying session with %d unacked stanzas:", #queue); + for i=1,#queue do + module:log("warn", "::%s", tostring(queue[i])); + end + handle_unacked_stanzas(session); end - handle_unacked_stanzas(session); + else + session.hibernating = true; + timer.add_task(resume_timeout, function () + if session.hibernating then + session.resumption_token = nil; + sessionmanager.destroy_session(session); -- Re-destroy + end + end); + return; -- Postpone destruction for now end end return _destroy_session(session, err);