Changeset

6774:3965662ae091

Merge 0.9->0.10
author Kim Alvefur <zash@zash.se>
date Mon, 10 Aug 2015 22:16:05 +0200
parents 6772:805baeca56b6 (current diff) 6773:ef22c17cc24d (diff)
children 6775:22c8deb43daf 6777:5de6b93d0190
files plugins/mod_component.lua
diffstat 1 files changed, 16 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- a/plugins/mod_component.lua	Fri Aug 07 13:31:12 2015 +0200
+++ b/plugins/mod_component.lua	Mon Aug 10 22:16:05 2015 +0200
@@ -33,7 +33,7 @@
 	if module:get_host_type() ~= "component" then
 		error("Don't load mod_component manually, it should be for a component, please see http://prosody.im/doc/components", 0);
 	end
-
+	
 	local env = module.environment;
 	env.connected = false;
 
@@ -44,26 +44,26 @@
 		send = nil;
 		session.on_destroy = nil;
 	end
-
+	
 	-- Handle authentication attempts by component
 	local function handle_component_auth(event)
 		local session, stanza = event.origin, event.stanza;
-
+		
 		if session.type ~= "component_unauthed" then return; end
-
+	
 		if (not session.host) or #stanza.tags > 0 then
 			(session.log or log)("warn", "Invalid component handshake for host: %s", session.host);
 			session:close("not-authorized");
 			return true;
 		end
-
+		
 		local secret = module:get_option("component_secret");
 		if not secret then
 			(session.log or log)("warn", "Component attempted to identify as %s, but component_secret is not set", session.host);
 			session:close("not-authorized");
 			return true;
 		end
-
+		
 		local supplied_token = t_concat(stanza);
 		local calculated_token = sha1(session.streamid..secret, true);
 		if supplied_token:lower() ~= calculated_token:lower() then
@@ -71,13 +71,13 @@
 			session:close{ condition = "not-authorized", text = "Given token does not match calculated token" };
 			return true;
 		end
-
+		
 		if env.connected then
 			module:log("error", "Second component attempted to connect, denying connection");
 			session:close{ condition = "conflict", text = "Component already connected" };
 			return true;
 		end
-
+		
 		env.connected = true;
 		send = session.send;
 		session.on_destroy = on_destroy;
@@ -85,7 +85,8 @@
 		session.type = "component";
 		module:log("info", "External component successfully authenticated");
 		session.send(st.stanza("handshake"));
-
+		module:fire_event("component-authenticated", { session = session });
+	
 		return true;
 	end
 	module:hook("stanza/jabber:component:accept:handshake", handle_component_auth, -1);
@@ -116,7 +117,7 @@
 		end
 		return true;
 	end
-
+	
 	module:hook("iq/bare", handle_stanza, -1);
 	module:hook("message/bare", handle_stanza, -1);
 	module:hook("presence/bare", handle_stanza, -1);
@@ -273,14 +274,14 @@
 	if opt_keepalives then
 		conn:setoption("keepalive", opt_keepalives);
 	end
-
+	
 	session.log("info", "Incoming Jabber component connection");
-
+	
 	local stream = new_xmpp_stream(session, stream_callbacks);
 	session.stream = stream;
-
+	
 	session.notopen = true;
-
+	
 	function session.reset_stream()
 		session.notopen = true;
 		session.stream:reset();
@@ -292,7 +293,7 @@
 		module:log("debug", "Received invalid XML (%s) %d bytes: %s", tostring(err), #data, data:sub(1, 300):gsub("[\r\n]+", " "):gsub("[%z\1-\31]", "_"));
 		session:close("not-well-formed");
 	end
-
+	
 	session.dispatch_stanza = stream_callbacks.handlestanza;
 
 	sessions[conn] = session;