mod_storage_sql: Add method for listing stores
[prosody.git] / plugins / mod_component.lua
index 98eaa6deffa95b9b22304e10e06f8cfc0812df69..751de59bf17120b4d3f2627f3a7a34abb4566fb5 100644 (file)
@@ -18,6 +18,8 @@ local jid_split = require "util.jid".split;
 local new_xmpp_stream = require "util.xmppstream".new;
 local uuid_gen = require "util.uuid".generate;
 
+local core_process_stanza = prosody.core_process_stanza;
+
 
 local log = module._log;
 
@@ -43,7 +45,7 @@ function module.add_host(module)
        local function handle_component_auth(event)
                local session, stanza = event.origin, event.stanza;
                
-               if session.type ~= "component" then return; end
+               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);
@@ -76,6 +78,7 @@ function module.add_host(module)
                send = session.send;
                session.on_destroy = on_destroy;
                session.component_validate_from = module:get_option_boolean("validate_from_addresses", true);
+               session.type = "component";
                module:log("info", "External component successfully authenticated");
                session.send(st.stanza("handshake"));
        
@@ -123,7 +126,7 @@ local xmlns_xmpp_streams = "urn:ietf:params:xml:ns:xmpp-streams";
 
 function stream_callbacks.error(session, error, data, data2)
        if session.destroyed then return; end
-       module:log("warn", "Error processing component stream: "..tostring(error));
+       module:log("warn", "Error processing component stream: %s", tostring(error));
        if error == "no-stream" then
                session:close("invalid-namespace");
        elseif error == "parse-error" then
@@ -158,6 +161,7 @@ function stream_callbacks.streamopened(session, attr)
        session.streamid = uuid_gen();
        session.notopen = nil;
        -- Return stream header
+       session.send("<?xml version='1.0'?>");
        session.send(st.stanza("stream:stream", { xmlns=xmlns_component,
                        ["xmlns:stream"]='http://etherx.jabber.org/streams', id=session.streamid, from=session.host }):top_tag());
 end
@@ -167,8 +171,6 @@ function stream_callbacks.streamclosed(session)
        session:close();
 end
 
-local core_process_stanza = core_process_stanza;
-
 function stream_callbacks.handlestanza(session, stanza)
        -- Namespaces are icky.
        if not stanza.attr.xmlns and stanza.name == "handshake" then
@@ -207,7 +209,6 @@ local stream_xmlns_attr = {xmlns='urn:ietf:params:xml:ns:xmpp-streams'};
 local default_stream_attr = { ["xmlns:stream"] = "http://etherx.jabber.org/streams", xmlns = stream_callbacks.default_ns, version = "1.0", id = "" };
 local function session_close(session, reason)
        if session.destroyed then return; end
-       local log = session.log or log;
        if session.conn then
                if session.notopen then
                        session.send("<?xml version='1.0'?>");
@@ -244,7 +245,7 @@ end
 
 function listener.onconnect(conn)
        local _send = conn.write;
-       local session = { type = "component", conn = conn, send = function (data) return _send(conn, tostring(data)); end };
+       local session = { type = "component_unauthed", conn = conn, send = function (data) return _send(conn, tostring(data)); end };
 
        -- Logging functions --
        local conn_name = "jcp"..tostring(conn):match("[a-f0-9]+$");