Diff

core/stanza_router.lua @ 1406:83c6fb3d9e73

stanza_router: Removed old routing code
author Waqas Hussain <waqas20@gmail.com>
date Thu, 25 Jun 2009 07:57:57 +0500
parent 1370:3a467e6885f0
child 1407:85ec12aec35f
line wrap: on
line diff
--- a/core/stanza_router.lua	Thu Jun 25 01:38:53 2009 +0100
+++ b/core/stanza_router.lua	Thu Jun 25 07:57:57 2009 +0500
@@ -213,88 +213,7 @@
 
 	local host_session = hosts[host]
 	if host_session and host_session.type == "local" then
-		-- Local host
-		local user = host_session.sessions[node];
-		if user then
-			local res = user.sessions[resource];
-			if res then -- resource is online...
-				res.send(stanza); -- Yay \o/
-			else
-				-- if we get here, resource was not specified or was unavailable
-				if stanza.name == "presence" then
-					if stanza.attr.type ~= nil and stanza.attr.type ~= "unavailable" and stanza.attr.type ~= "error" then
-						-- inbound presence subscriptions and probes, already handled, so should never get here
-					elseif not resource then -- sender is available or unavailable or error
-						for _, session in pairs(user.sessions) do -- presence broadcast to all user resources.
-							if session.full_jid then -- FIXME should this be just for available resources? Do we need to check subscription?
-								stanza.attr.to = session.full_jid; -- reset at the end of function
-								session.send(stanza);
-							end
-						end
-					end
-				elseif stanza.name == "message" then -- select a resource to recieve message
-					stanza.attr.to = to_bare;
-					if stanza.attr.type == 'headline' then
-						for _, session in pairs(user.sessions) do -- find resource with greatest priority
-							if session.presence and session.priority >= 0 then
-								session.send(stanza);
-							end
-						end
-					elseif stanza.attr.type == 'groupchat' then
-						-- Groupchat message sent to offline resource
-						origin.send(st.error_reply(stanza, "cancel", "service-unavailable"));
-					else
-						local count = 0;
-						for _, session in ipairs(select_best_resources(user)) do
-							session.send(stanza);
-							count = count + 1;
-						end
-						if count == 0 and (stanza.attr.type == "chat" or stanza.attr.type == "normal" or not stanza.attr.type) then
-							offlinemanager.store(node, host, stanza);
-							-- TODO deal with storage errors
-						end
-					end
-				elseif stanza.attr.type == "get" or stanza.attr.type == "set" then
-					origin.send(st.error_reply(stanza, "cancel", "service-unavailable"));
-				end
-			end
-		else
-			-- user not online
-			if user_exists(node, host) then
-				if stanza.name == "presence" then
-					if stanza.attr.type ~= nil and stanza.attr.type ~= "unavailable" and stanza.attr.type ~= "error" then
-						-- inbound presence subscriptions and probes, already handled, so should never get here
-					else
-						-- TODO send unavailable presence or unsubscribed
-					end
-				elseif stanza.name == "message" then -- FIXME if full jid, then send out to resources with highest priority
-					stanza.attr.to = to_bare; -- TODO not in RFC, but seems obvious. Should discuss on the mailing list.
-					if stanza.attr.type == "chat" or stanza.attr.type == "normal" or not stanza.attr.type then
-						offlinemanager.store(node, host, stanza);
-						-- FIXME don't store messages with only chat state notifications
-					elseif stanza.attr.type == "groupchat" then
-						local reply = st.error_reply(stanza, "cancel", "service-unavailable");
-						reply.attr.from = to;
-						origin.send(reply);
-					end
-					-- TODO allow configuration of offline storage
-					-- TODO send error if not storing offline
-				elseif stanza.name == "iq" and (stanza.attr.type == "get" or stanza.attr.type == "set") then
-					origin.send(st.error_reply(stanza, "cancel", "service-unavailable"));
-				end
-			else -- user does not exist
-				-- TODO we would get here for nodeless JIDs too. Do something fun maybe? Echo service? Let plugins use xmpp:server/resource addresses?
-				if stanza.name == "presence" then
-					local t = stanza.attr.type;
-					if t == "subscribe" or t == "probe" then
-						origin.send(st.presence({from = to_bare, to = from_bare, type = "unsubscribed"}));
-					end
-					-- else ignore
-				elseif stanza.attr.type ~= "error" and (stanza.name ~= "iq" or stanza.attr.type ~= "result") then
-					origin.send(st.error_reply(stanza, "cancel", "service-unavailable"));
-				end
-			end
-		end
+		-- old stanza routing code removed
 	elseif origin.type == "c2s" then
 		-- Remote host
 		local xmlns = stanza.attr.xmlns;