/me glares at waqas for messing up the repo

Tue, 04 Nov 2008 22:42:06 +0000

author
Matthew Wild <mwild1@gmail.com>
date
Tue, 04 Nov 2008 22:42:06 +0000
changeset 215
ec90acc13ba3
parent 214
353f379e0eed (diff)
parent 213
181f5cc6215b (current diff)
child 216
35f626e29fb0

/me glares at waqas for messing up the repo

core/componentmanager.lua file | annotate | diff | comparison | revisions
core/stanza_router.lua file | annotate | diff | comparison | revisions
--- a/core/componentmanager.lua	Tue Nov 04 17:43:48 2008 +0500
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,35 +0,0 @@
-
-
-local log = require "util.logger".init("componentmanager")
-local jid_split = require "util.jid".split;
-local hosts = hosts;
-
-local components = {};
-
-module "componentmanager"
-
-function handle_stanza(origin, stanza)
-	local node, host = jid_split(stanza.attr.to);
-	local component = components[host];
-	if not component then component = components[node.."@"..host]; end -- hack to allow hooking node@server
-	if not component then component = components[stanza.attr.to]; end -- hack to allow hooking node@server/resource and server/resource
-	if component then
-		log("debug", "stanza being handled by component: "..host);
-		component(origin, stanza);
-	else
-		log("error", "Component manager recieved a stanza for a non-existing component: " .. stanza.attr.to);
-	end
-end
-
-function register_component(host, component)
-	if not hosts[host] then
-		-- TODO check for host well-formedness
-		components[host] = component;
-		hosts[host] = {type = "component", connected = true};
-		log("debug", "component added: "..host);
-	else
-		log("error", "Attempt to set component for existing host: "..host);
-	end
-end
-
-return _M;
\ No newline at end of file
--- a/core/stanza_router.lua	Tue Nov 04 17:43:48 2008 +0500
+++ b/core/stanza_router.lua	Tue Nov 04 22:42:06 2008 +0000
@@ -60,8 +60,8 @@
 	local from_bare = from_node and (from_node.."@"..from_host) or from_host; -- bare JID
 
 	if origin.type == "s2sin" then
-		if origin.host ~= from_host then -- remote server trying to impersonate some other server?
-			log("warn", "origin.host ~= from_host");
+		if origin.from_host ~= from_host then -- remote server trying to impersonate some other server?
+			log("warn", "Received a stanza claiming to be from %s, over a conn authed for %s!", from, origin.from_host);
 			return; -- FIXME what should we do here? does this work with subdomains?
 		end
 	end
@@ -75,6 +75,8 @@
 		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(origin, stanza);
 	elseif hosts[to_bare] and hosts[to_bare].type == "component" then -- hack to allow components to handle node@server
 		component_handle_stanza(origin, stanza);
 	elseif hosts[to] and hosts[to].type == "component" then -- hack to allow components to handle node@server/resource and server/resource
@@ -85,8 +87,6 @@
 		handle_outbound_presence_subscriptions_and_probes(origin, stanza, from_bare, to_bare);
 	elseif stanza.name == "iq" and not resource then -- directed at bare JID
 		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(origin, stanza);
 	elseif origin.type == "c2s" or origin.type == "s2sin" then
 		core_route_stanza(origin, stanza);
 	else
@@ -370,6 +370,12 @@
 		log("debug", "sending s2s stanza: %s", tostring(stanza));
 		send_s2s(origin.host, host, stanza); -- TODO handle remote routing errors
 		stanza.attr.xmlns = xmlns; -- reset
+	elseif origin.type == "component" or origin.type == "local" then
+		-- Route via s2s for components and modules
+		log("debug", "Routing outgoing stanza for %s to %s", origin.host, host);
+		for k,v in pairs(origin) do print("origin:", tostring(k), tostring(v)); end
+		print(tostring(host), tostring(from_host))
+		send_s2s(origin.host, host, stanza);
 	else
 		log("warn", "received stanza from unhandled connection type: %s", origin.type);
 	end
@@ -379,3 +385,5 @@
 function handle_stanza_toremote(stanza)
 	log("error", "Stanza bound for remote host, but s2s is not implemented");
 end
+
+

mercurial