mod_component: Updated to use the new events API.

Sat, 16 Oct 2010 06:38:38 +0500

author
Waqas Hussain <waqas20@gmail.com>
date
Sat, 16 Oct 2010 06:38:38 +0500
changeset 3531
f41e1cfe92f4
parent 3530
73909cca846c
child 3532
4f2cd1c688e1

mod_component: Updated to use the new events API.

plugins/mod_component.lua file | annotate | diff | comparison | revisions
--- a/plugins/mod_component.lua	Sat Oct 16 06:25:55 2010 +0500
+++ b/plugins/mod_component.lua	Sat Oct 16 06:38:38 2010 +0500
@@ -23,19 +23,23 @@
 local log = module._log;
 
 --- Handle authentication attempts by components
-function handle_component_auth(session, stanza)
+function handle_component_auth(event)
+	local session, stanza = event.origin, event.stanza;
+	
+	if session.type ~= "component" then return; end
+
 	log("info", "Handling component auth");
 	if (not session.host) or #stanza.tags > 0 then
 		(session.log or log)("warn", "Component handshake invalid");
 		session:close("not-authorized");
-		return;
+		return true;
 	end
 	
 	local secret = config.get(session.host, "core", "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;
+		return true;
 	end
 	
 	local supplied_token = t_concat(stanza);
@@ -43,7 +47,7 @@
 	if supplied_token:lower() ~= calculated_token:lower() then
 		log("info", "Component for %s authentication failed", session.host);
 		session:close{ condition = "not-authorized", text = "Given token does not match calculated token" };
-		return;
+		return true;
 	end
 	
 	
@@ -69,6 +73,7 @@
 	
 	-- Signal successful authentication
 	session.send(st.stanza("handshake"));
+	return true;
 end
 
-module:add_handler("component", "handshake", "jabber:component:accept", handle_component_auth);
+module:hook("stanza/jabber:component:accept:handshake", handle_component_auth);

mercurial