Changeset

18:2df11ec081fe

mod_privacy: make finding the right session working
author Thilo Cestonaro <thilo@cestona.ro>
date Mon, 28 Sep 2009 22:36:01 +0200
parents 17:ccb07c0efc7e
children 19:e400ee8471b0
files mod_privacy/mod_privacy.lua
diffstat 1 files changed, 22 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/mod_privacy/mod_privacy.lua	Mon Sep 28 22:22:22 2009 +0200
+++ b/mod_privacy/mod_privacy.lua	Mon Sep 28 22:36:01 2009 +0200
@@ -389,16 +389,22 @@
 		if resource == nil then
 			local prio = 0;
 			local session_;
-			for _,session_ in ipairs(bare_sessions[node.."@"..host].sessions) do
-				if session_.priority > prio then
-					session = session_;
-					prio = session_.priority;
+			if bare_sessions[node.."@"..host] ~= nil then
+				for resource, session_ in pairs(bare_sessions[node.."@"..host].sessions) do
+					if session_.priority > prio then
+						session = session_;
+						prio = session_.priority;
+					end
 				end
 			end
 		else
 			session = full_sessions[node.."@"..host.."/"..resource];
 		end
-		return checkIfNeedToBeBlocked(e, session);
+		if session ~= nil then
+			return checkIfNeedToBeBlocked(e, session);
+		else
+			module:log("debug", "preCheckIncoming: Couldn't get session for jid: %s@%s/%s", node or "nil", host or "nil", resource or "nil")
+		end
 	end
 	return;
 end
@@ -413,16 +419,22 @@
 		if resource == nil then
 			local prio = 0;
 			local session_;
-			for _,session_ in ipairs(bare_sessions[node.."@"..host].sessions) do
-				if session_.priority > prio then
-					session = session_;
-					prio = session_.priority;
+			if bare_sessions[node.."@"..host] ~= nil then
+				for resource, session_ in pairs(bare_sessions[node.."@"..host].sessions) do
+					if session_.priority > prio then
+						session = session_;
+						prio = session_.priority;
+					end
 				end
 			end
 		else
 			session = full_sessions[node.."@"..host.."/"..resource];
 		end
-		return checkIfNeedToBeBlocked(e, session);
+		if session ~= nil then
+			return checkIfNeedToBeBlocked(e, session);
+		else
+			module:log("debug", "preCheckOutgoing: Couldn't get session for jid: %s@%s/%s", node or "nil", host or "nil", resource or "nil")
+		end
 	end
 	return;
 end