mod_s2s: Ensure that to/from on stream headers are always correct, fixes #338
authorMatthew Wild <mwild1@gmail.com>
Mon, 29 Apr 2013 00:33:39 +0100
changeset 5533 df3c78221f26
parent 5532 d5cbcdcdb2f7
child 5534 522e99b898a0
child 5535 0df0afc041d7
mod_s2s: Ensure that to/from on stream headers are always correct, fixes #338
plugins/mod_s2s/mod_s2s.lua
--- a/plugins/mod_s2s/mod_s2s.lua	Sun Apr 28 16:22:01 2013 +0200
+++ b/plugins/mod_s2s/mod_s2s.lua	Mon Apr 29 00:33:39 2013 +0100
@@ -348,7 +348,7 @@
 			end
 		end
 
-		session:open_stream()
+		session:open_stream(session.to_host, session.from_host)
 		if session.version >= 1.0 then
 			local features = st.stanza("stream:features");
 			
@@ -448,7 +448,11 @@
 	local log = session.log or log;
 	if session.conn then
 		if session.notopen then
-			session:open_stream()
+			if session.direction == "incoming" then
+				session:open_stream(session.to_host, session.from_host);
+			else
+				session:open_stream(session.from_host, session.to_host);
+			end
 		end
 		if reason then -- nil == no err, initiated by us, false == initiated by remote
 			if type(reason) == "string" then -- assume stream error
@@ -496,8 +500,6 @@
 end
 
 function session_open_stream(session, from, to)
-	local from = from or session.from_host;
-	local to = to or session.to_host;
 	local attr = {
 		["xmlns:stream"] = 'http://etherx.jabber.org/streams',
 		xmlns = 'jabber:server',
@@ -506,8 +508,7 @@
 		id = session.streamid,
 		from = from, to = to,
 	}
-	local local_host = session.direction == "outgoing" and from or to;
-	if not local_host or (hosts[local_host] and hosts[local_host].modules.dialback) then
+	if not from or (hosts[from] and hosts[from].modules.dialback) then
 		attr["xmlns:db"] = 'jabber:server:dialback';
 	end