Changeset

1166:5499a028d4ae

Automated merge with http://waqas.ath.cx:8000/
author Matthew Wild <mwild1@gmail.com>
date Fri, 15 May 2009 20:38:30 +0100
parents 1165:ec69bcc7ceb5 (diff) 1162:bd1f0e6d50a7 (current diff)
children 1167:5620ea24be94
files
diffstat 1 files changed, 12 insertions(+), 31 deletions(-) [+]
line wrap: on
line diff
--- a/core/stanza_router.lua	Fri May 15 17:33:04 2009 +0200
+++ b/core/stanza_router.lua	Fri May 15 20:38:30 2009 +0100
@@ -43,11 +43,6 @@
 local jid_prepped_split = require "util.jid".prepped_split;
 local print = print;
 local fire_event = require "core.eventmanager2".fire_event;
-local function checked_error_reply(origin, stanza)
-	if (stanza.attr.xmlns == "jabber:client" or stanza.attr.xmlns == "jabber:server") and stanza.attr.type ~= "error" and stanza.attr.type ~= "result" then
-		origin.send(st.error_reply(stanza, "cancel", "service-unavailable")); -- FIXME correct error?
-	end
-end
 
 function core_process_stanza(origin, stanza)
 	(origin.log or log)("debug", "Received[%s]: %s", origin.type, stanza:top_tag())
@@ -106,9 +101,7 @@
 		return; -- FIXME what should we do here?
 	end]] -- FIXME
 
-	if (origin.type == "s2sin" or origin.type == "c2s" or origin.type == "component") and (not xmlns or xmlns == "jabber:server" or xmlns == "jabber:client") then			
-		local event_data = {origin=origin, stanza=stanza};
-		if fire_event(tostring(host or origin.host).."/"..stanza.name, event_data) then return; end
+	if (origin.type == "s2sin" or origin.type == "c2s" or origin.type == "component") and xmlns == "jabber:client" then
 		if origin.type == "s2sin" and not origin.dummy then
 			local host_status = origin.hosts[from_host];
 			if not host_status or not host_status.authed then -- remote server trying to impersonate some other server?
@@ -116,12 +109,13 @@
 				return; -- FIXME what should we do here? does this work with subdomains?
 			end
 		end
-		if not to then
+		local event_data = {origin=origin, stanza=stanza};
+		if fire_event(tostring(host or origin.host).."/"..stanza.name, event_data) then
+			-- event handled
+		elseif not to then
 			core_handle_stanza(origin, stanza);
 		elseif hosts[to] and hosts[to].type == "local" then -- directed at a local server
 			core_handle_stanza(origin, stanza);
-		elseif stanza.attr.xmlns and stanza.attr.xmlns ~= "jabber:client" and stanza.attr.xmlns ~= "jabber:server" then
-			modules_handle_stanza(host or origin.host or origin.to_host, origin, stanza);
 		elseif hosts[to] and hosts[to].type == "component" then -- hack to allow components to handle node@server/resource and server/resource
 			component_handle_stanza(origin, stanza);
 		elseif hosts[to_bare] and hosts[to_bare].type == "component" then -- hack to allow components to handle node@server
@@ -141,28 +135,15 @@
 -- This function handles stanzas which are not routed any further,
 -- that is, they are handled by this server
 function core_handle_stanza(origin, stanza)
-	-- Handlers
-	if modules_handle_stanza(select(2, jid_split(stanza.attr.to)) or origin.host or origin.to_host, origin, stanza) then return; end
-	if origin.type == "c2s" or origin.type == "s2sin" then
-		if origin.type == "c2s" then
-			if stanza.name == "presence" and origin.roster then
-				if stanza.attr.type == nil or stanza.attr.type == "unavailable" and stanza.attr.type ~= "error" then
-					handle_normal_presence(origin, stanza, core_route_stanza);
-				else
-					log("warn", "Unhandled c2s presence: %s", tostring(stanza));
-					checked_error_reply(origin, stanza);
-				end
-			else
-				log("warn", "Unhandled c2s stanza: %s", tostring(stanza));
-				checked_error_reply(origin, stanza);
+	if not modules_handle_stanza(select(2, jid_split(stanza.attr.to)) or origin.host or origin.to_host, origin, stanza) then
+		log("warn", "Unhandled %s stanza: %s", origin.type, tostring(stanza));
+		if stanza.attr.xmlns == "jabber:client" then
+			if stanza.attr.type ~= "error" and stanza.attr.type ~= "result" then
+				origin.send(st.error_reply(stanza, "cancel", "service-unavailable"));
 			end
-		else -- s2s stanzas
-			log("warn", "Unhandled s2s stanza: %s", tostring(stanza));
-			checked_error_reply(origin, stanza);
+		else
+			origin:close("unsupported-stanza-type");
 		end
-	else
-		log("warn", "Unhandled %s stanza: %s", origin.type, tostring(stanza));
-		checked_error_reply(origin, stanza);
 	end
 end