Add support for component connections default tip

Thu, 23 Mar 2023 18:28:20 +0000

author
Matthew Wild <mwild1@gmail.com>
date
Thu, 23 Mar 2023 18:28:20 +0000
changeset 181
3a9b9c98304a
parent 180
249197af6c01

Add support for component connections

main.lua file | annotate | diff | comparison | revisions
scansion/console.lua file | annotate | diff | comparison | revisions
scansion/objects/component.lua file | annotate | diff | comparison | revisions
squishy file | annotate | diff | comparison | revisions
--- 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);
--- 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);
--- /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 });
--- 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"

mercurial