Changeset

4822:5ef05f32bc42

mod_s2s, s2smanager, mod_dialback: Move addition of session.send() on s2sin to after they are authenticated (thus from mod_s2s to s2smanager). Update mod_dialback to fire route/remote directly, as session.send() is no longer available for s2sin_unauthed. Fixes #291.
author Matthew Wild <mwild1@gmail.com>
date Thu, 10 May 2012 22:59:01 +0100
parents 4821:deec69fc33e5
children 4833:b7a6e86ab87d
files core/s2smanager.lua plugins/mod_dialback.lua plugins/mod_s2s/mod_s2s.lua
diffstat 3 files changed, 22 insertions(+), 21 deletions(-) [+]
line wrap: on
line diff
--- a/core/s2smanager.lua	Fri May 04 02:28:10 2012 +0100
+++ b/core/s2smanager.lua	Thu May 10 22:59:01 2012 +0100
@@ -117,10 +117,15 @@
 	local event_data = { session = session };
 	if session.type == "s2sout" then
 		prosody.events.fire_event("s2sout-established", event_data);
-		hosts[session.from_host].events.fire_event("s2sout-established", event_data);
+		hosts[from].events.fire_event("s2sout-established", event_data);
 	else
+		local host_session = hosts[to];
+		session.send = function(stanza)
+			host_session.events.fire_event("route/remote", { from_host = to, to_host = from, stanza = stanza });
+		end;
+
 		prosody.events.fire_event("s2sin-established", event_data);
-		hosts[session.to_host].events.fire_event("s2sin-established", event_data);
+		hosts[to].events.fire_event("s2sin-established", event_data);
 	end
 	
 	if session.direction == "outgoing" then
--- a/plugins/mod_dialback.lua	Fri May 04 02:28:10 2012 +0100
+++ b/plugins/mod_dialback.lua	Thu May 10 22:59:01 2012 +0100
@@ -64,28 +64,29 @@
 		-- he wants to be identified through dialback
 		-- We need to check the key with the Authoritative server
 		local attr = stanza.attr;
-		origin.hosts[attr.from] = { dialback_key = stanza[1] };
+		local to, from = attr.to, attr.from;
+		
+		origin.hosts[from] = { dialback_key = stanza[1] };
 		
-		if not hosts[attr.to] then
+		if not hosts[to] then
 			-- Not a host that we serve
-			origin.log("info", "%s tried to connect to %s, which we don't serve", attr.from, attr.to);
+			origin.log("info", "%s tried to connect to %s, which we don't serve", from, to);
 			origin:close("host-unknown");
 			return true;
 		end
 		
-		dialback_requests[attr.from.."/"..origin.streamid] = origin;
+		dialback_requests[from.."/"..origin.streamid] = origin;
 		
-		if not origin.from_host then
-			-- Just used for friendlier logging
-			origin.from_host = attr.from;
-		end
-		if not origin.to_host then
-			-- Just used for friendlier logging
-			origin.to_host = attr.to;
-		end
+		-- COMPAT: ejabberd, gmail and perhaps others do not always set 'to' and 'from'
+		-- on streams. We fill in the session's to/from here instead.
+		if not origin.from_host then origin.from_host = from; end
+		if not origin.to_host then origin.to_host = to;	end
 		
-		origin.log("debug", "asking %s if key %s belongs to them", attr.from, stanza[1]);
-		origin.send(st.stanza("db:verify", { from = attr.to, to = attr.from, id = origin.streamid }):text(stanza[1]));
+		origin.log("debug", "asking %s if key %s belongs to them", from, stanza[1]);
+		module:fire_event("route/remote", {
+			from_host = to, to_host = from;
+			stanza = st.stanza("db:verify", { from = to, to = from, id = origin.streamid }):text(stanza[1]);
+		});
 		return true;
 	end
 end);
--- a/plugins/mod_s2s/mod_s2s.lua	Fri May 04 02:28:10 2012 +0100
+++ b/plugins/mod_s2s/mod_s2s.lua	Thu May 10 22:59:01 2012 +0100
@@ -253,11 +253,6 @@
 			log("debug", "Sending stream features: %s", tostring(features));
 			send(features);
 		end
-		
-		local host_session = hosts[to];
-		session.send = function(stanza)
-			host_session.events.fire_event("route/remote", { from_host = to, to_host = from, stanza = stanza})
-		end;
 	elseif session.direction == "outgoing" then
 		-- If we are just using the connection for verifying dialback keys, we won't try and auth it
 		if not attr.id then error("stream response did not give us a streamid!!!"); end