tools/migration/prosody-migrator.lua: Refactor store handler loading to report errors...
[prosody.git] / core / sessionmanager.lua
index c4dee5b792b09db020b056823be2582902e24632..426763f51b575a06fa922a097d63cf1b36aeb134 100644 (file)
@@ -86,6 +86,7 @@ local resting_session = { -- Resting, not dead
                close = function (session)
                        session.log("debug", "Attempt to close already-closed session");
                end;
+               filter = function (type, data) return data; end;
        }; resting_session.__index = resting_session;
 
 function retire_session(session)
@@ -107,16 +108,23 @@ function destroy_session(session, err)
        
        -- Remove session/resource from user's session list
        if session.full_jid then
-               hosts[session.host].sessions[session.username].sessions[session.resource] = nil;
+               local host_session = hosts[session.host];
+               
+               -- Allow plugins to prevent session destruction
+               if host_session.events.fire_event("pre-resource-unbind", {session=session, error=err}) then
+                       return;
+               end
+               
+               host_session.sessions[session.username].sessions[session.resource] = nil;
                full_sessions[session.full_jid] = nil;
                
-               if not next(hosts[session.host].sessions[session.username].sessions) then
+               if not next(host_session.sessions[session.username].sessions) then
                        log("debug", "All resources of %s are now offline", session.username);
-                       hosts[session.host].sessions[session.username] = nil;
+                       host_session.sessions[session.username] = nil;
                        bare_sessions[session.username..'@'..session.host] = nil;
                end
 
-               hosts[session.host].events.fire_event("resource-unbind", {session=session, error=err});
+               host_session.events.fire_event("resource-unbind", {session=session, error=err});
        end
        
        retire_session(session);