clix.raw: Track and print response to iq stanza given as cli argument

Sat, 10 Apr 2021 00:13:23 +0200

author
Kim Alvefur <zash@zash.se>
date
Sat, 10 Apr 2021 00:13:23 +0200
changeset 150
af9b9acb10d6
parent 149
014e73c329c5
child 151
5398623682d7

clix.raw: Track and print response to iq stanza given as cli argument

While fire-and-forget is okay for messages and presence, it's kinda
useless for a lot of IQs uses, so this is pretty nice!

clix/raw.lua file | annotate | diff | comparison | revisions
--- a/clix/raw.lua	Sat Apr 10 00:21:05 2021 +0200
+++ b/clix/raw.lua	Sat Apr 10 00:13:23 2021 +0200
@@ -1,4 +1,5 @@
 local verse = require "verse";
+local xml = require "util.xml";
 short_opts.i = "interactive";
 short_opts.e = "echo";
 
@@ -113,8 +114,15 @@
 			if not send_xml then
 				send_xml = table.concat(args, " ");
 			end
-			conn:send(send_xml);
-			conn:close();
+			send_xml = assert(xml.parse(send_xml));
+			if send_xml.name == "iq" then
+				conn:send_iq(send_xml, function ()
+					conn:close();
+				end);
+			else
+				conn:send(send_xml);
+				conn:close();
+			end
 		end
 
 	end

mercurial