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);
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;
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"));
end
function stream_callbacks.streamopened(session, attr)
- if not hosts[attr.to].modules.component then
+ if not hosts[attr.to] or not hosts[attr.to].modules.component then
session:close{ condition = "host-unknown", text = tostring(attr.to).." does not match any configured external components" };
return;
end
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
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'?>");
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]+$");