# HG changeset patch # User Waqas Hussain # Date 1287193118 -18000 # Node ID f41e1cfe92f4b8dd2fbf2c4c22846c2dad5290a9 # Parent 73909cca846cb9a533da0f45ef8354eb9d112078 mod_component: Updated to use the new events API. diff -r 73909cca846c -r f41e1cfe92f4 plugins/mod_component.lua --- 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);