Changeset

4230:23b68616b6d8

sessionmanager: Fire pre-resource-unbind to allow plugins (such as mod_smacks) to hook and prevent/override session destruction
author Matthew Wild <mwild1@gmail.com>
date Tue, 29 Mar 2011 14:10:00 +0100
parents 4229:f15b4e9ba688
children 4231:a99f82db692a
files core/sessionmanager.lua
diffstat 1 files changed, 11 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/core/sessionmanager.lua	Mon Mar 21 19:39:04 2011 +0000
+++ b/core/sessionmanager.lua	Tue Mar 29 14:10:00 2011 +0100
@@ -108,16 +108,23 @@
 	
 	-- 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);