mod_tls: Remove extraneous flag to starttls() for s2sout connecections
[prosody.git] / plugins / mod_component.lua
index fa2c166fb0b7198d1fd493fd71cfd357f7f409da..033317434322944aab372a662ca12803d46ba1f4 100644 (file)
@@ -1,6 +1,6 @@
--- Prosody IM v0.4
--- Copyright (C) 2008-2009 Matthew Wild
--- Copyright (C) 2008-2009 Waqas Hussain
+-- Prosody IM
+-- Copyright (C) 2008-2010 Matthew Wild
+-- Copyright (C) 2008-2010 Waqas Hussain
 -- 
 -- This project is MIT/X11 licensed. Please see the
 -- COPYING file in the source package for more information.
@@ -14,25 +14,14 @@ local hosts = _G.hosts;
 
 local t_concat = table.concat;
 
-local lxp = require "lxp";
-local logger = require "util.logger";
 local config = require "core.configmanager";
-local connlisteners = require "net.connlisteners";
 local cm_register_component = require "core.componentmanager".register_component;
 local cm_deregister_component = require "core.componentmanager".deregister_component;
-local uuid_gen = require "util.uuid".generate;
 local sha1 = require "util.hashes".sha1;
 local st = require "util.stanza";
-local init_xmlhandlers = require "core.xmlhandlers";
-
-local sessions = {};
 
 local log = module._log;
 
-local component_listener = { default_port = 5347; default_mode = "*a"; default_interface = config.get("*", "core", "component_interface") or "127.0.0.1" };
-
-local xmlns_component = 'jabber:component:accept';
-
 --- Handle authentication attempts by components
 function handle_component_auth(session, stanza)
        log("info", "Handling component auth");
@@ -44,7 +33,7 @@ function handle_component_auth(session, stanza)
        
        local secret = config.get(session.user, "core", "component_secret");
        if not secret then
-               (session.log or log)("warn", "Component attempted to identify as %s, but component_password is not set", session.user);
+               (session.log or log)("warn", "Component attempted to identify as %s, but component_secret is not set", session.user);
                session:close("not-authorized");
                return;
        end
@@ -61,10 +50,17 @@ function handle_component_auth(session, stanza)
        -- Authenticated now
        log("info", "Component authenticated: %s", session.host);
        
+       session.component_validate_from = module:get_option_boolean("validate_from_addresses") ~= false;
+       
        -- If component not already created for this host, create one now
        if not hosts[session.host].connected then
                local send = session.send;
-               session.component_session = cm_register_component(session.host, function (_, data) return send(data); end);
+               session.component_session = cm_register_component(session.host, function (_, data) 
+                               if data.attr and data.attr.xmlns == "jabber:client" then
+                                       data.attr.xmlns = nil;
+                               end
+                               return send(data);
+                       end);
                hosts[session.host].connected = true;
                log("info", "Component successfully registered");
        else
@@ -75,4 +71,4 @@ function handle_component_auth(session, stanza)
        session.send(st.stanza("handshake"));
 end
 
-module:add_handler("component", "handshake", xmlns_component, handle_component_auth);
+module:add_handler("component", "handshake", "jabber:component:accept", handle_component_auth);