Changeset

83:9d92db30235f

mod_proxy65: make it work from external initiators, too
author Thilo Cestonaro <thilo@cestona.ro>
date Sun, 01 Nov 2009 21:28:14 +0100
parents 82:608dc38b6580
children 84:b47216512a1d
files mod_proxy65/mod_proxy65.lua
diffstat 1 files changed, 16 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/mod_proxy65/mod_proxy65.lua	Sun Nov 01 18:51:09 2009 +0100
+++ b/mod_proxy65/mod_proxy65.lua	Sun Nov 01 21:28:14 2009 +0100
@@ -3,6 +3,12 @@
 -- This project is MIT/X11 licensed. Please see the
 -- COPYING file in the source package for more information.
 --
+--[[
+* to restart the proxy in the console: e.g.
+module:unload("proxy65");
+> server.removeserver(<proxy65_port>);
+module:load("proxy65", <proxy65_jid>);
+]]--
 
 if module:get_host_type() ~= "component" then
 	error("proxy65 should be loaded as a component, please see http://prosody.im/doc/components", 0);
@@ -76,10 +82,13 @@
 				module:log("debug", "initiator connected ... ");
 			end
 			conn.write(string.char(5, 0, 0, 3, sha:len()) .. sha .. string.char(0, 0)); -- VER, REP, RSV, ATYP, BND.ADDR (sha), BND.PORT (2 Byte)
+		else
+			log:module("warn", "Neither data transfer nor initial connect of a participator of a transfer.")
+			conn.close();
 		end
 	else
 		if data ~= nil then
-			module:log("debug", "unknown connection with no authentication data -> closing it");
+			module:log("warn", "unknown connection with no authentication data -> closing it");
 			conn.close();
 		end
 	end
@@ -90,9 +99,9 @@
 	if session then
 		if session.sha and transfers[session.sha] then
 			local initiator, target = transfers[session.sha].initiator, transfers[session.sha].target;
-			if initiator == conn then
+			if initiator == conn and target ~= nil then
 				target.close();
-			elseif target == conn then
+			elseif target == conn and initiator ~= nil then
 			 	initiator.close();
 			end
 		end
@@ -175,7 +184,7 @@
 			replies_cache.stream_host = reply;
 		end
 	else
-		module:log("debug", "Denying use of proxy for %s", tostring(_jid_join(jid_node, jid_host, jid_resource)));
+		module:log("warn", "Denying use of proxy for %s", tostring(_jid_join(jid_node, jid_host, jid_resource)));
 		if err_reply == nil then
 			err_reply = st.iq({type="error", from=host})
 				:query("http://jabber.org/protocol/bytestreams")
@@ -208,7 +217,7 @@
 		end
 	end
 	if from ~= nil and to ~= nil and sid ~= nil then
-		reply = st.iq({type="result", from=host});
+		reply = st.iq({type="result", from=host, to=from});
 		reply.attr.id = stanza.attr.id;
 	end
 	return reply, from, to, sid;
@@ -241,6 +250,8 @@
 					origin.send(reply);
 					transfers[sha].activated = true;
 				end
+			else
+				module:log("error", "activation failed: sid: %s, initiator: %s, target: %s", tostring(sid), tostring(from), tostring(to));
 			end
 		end
 	end