# HG changeset patch # User Matthew Wild # Date 1679596100 0 # Node ID 3a9b9c98304a42468ade223b63dfe14481d8112b # Parent 249197af6c019e88525d73da988d0ba55aa77253 Add support for component connections diff -r 249197af6c01 -r 3a9b9c98304a main.lua --- a/main.lua Thu Mar 23 18:27:22 2023 +0000 +++ b/main.lua Thu Mar 23 18:28:20 2023 +0000 @@ -21,7 +21,10 @@ local serve_origin = nil; local only_tags, skip_tags; -local property_rules = {}; +local property_rules = { + -- Components connect to localhost by default, regardless of their hostname + { class = "component", properties = { connect_host = "localhost" } }; +}; local function apply_object_properties(class, name, object) for _, rule in ipairs(property_rules) do @@ -54,6 +57,12 @@ elseif opt == "--host" or opt == "-h" then local host = get_value(); table.insert(property_rules, { class = "client", properties = { connect_host = host } }); + elseif opt == "--component-port" then + local port = assert(tonumber(get_value()), "port number must be a number"); + table.insert(property_rules, { class = "component", properties = { connect_port = port } }); + elseif opt == "--component-host" then + local host = get_value(); + table.insert(property_rules, { class = "component", properties = { connect_host = host } }); elseif opt == "--out" or opt == "-o" then result_log_filename = get_value(); elseif opt == "--server-log" or opt == "-s" then @@ -152,7 +161,7 @@ object.handler = o; object.script = script; apply_object_properties(object.type, object.name, object); - if object.type == "client" and not object.stanza_timeout then + if (object.type == "client" or object.type == "component") and not object.stanza_timeout then object.stanza_timeout = action_timeout - 1; end o._validate(object); diff -r 249197af6c01 -r 3a9b9c98304a scansion/console.lua --- a/scansion/console.lua Thu Mar 23 18:27:22 2023 +0000 +++ b/scansion/console.lua Thu Mar 23 18:28:20 2023 +0000 @@ -51,7 +51,7 @@ table.insert(l, action.annotation); end table.insert(l, data.object.." "..action); - if data.extra and obj_type == "client" and (action == "sends" or action == "receives") then + if data.extra and (obj_type == "client" or obj_type == "component") and (action == "sends" or action == "receives") then table.insert(l, "\n"..pretty(lines(data.extra), 4).."\n"); end return lines(l); diff -r 249197af6c01 -r 3a9b9c98304a scansion/objects/component.lua --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/scansion/objects/component.lua Thu Mar 23 18:28:20 2023 +0000 @@ -0,0 +1,18 @@ +local async = require "scansion.async"; +local client = require "scansion.objects.client"; +require "verse".init("component"); + +return setmetatable({ + connects = function (component) + local wait, done = async.waiter(); + component.stream:hook("ready", function () + component.stream.conn:pause() + component.log"ready" + done() + component.log("ready done") + end); + component.stream:debug("Connecting as a component..."); + component.stream:connect_component(component.jid, component.password); + wait(); + end; +}, { __index = client }); diff -r 249197af6c01 -r 3a9b9c98304a squishy --- a/squishy Thu Mar 23 18:27:22 2023 +0000 +++ b/squishy Thu Mar 23 18:28:20 2023 +0000 @@ -9,6 +9,7 @@ Module "scansion.helpers" Module "scansion.iterators" Module "scansion.objects.client" +Module "scansion.objects.component" Module "scansion.queue" Module "scansion.stanzacmp" Module "scansion.xml"