Changeset

107:67ff8f55db4a

Merge with MattJ
author Kim Alvefur <zash@zash.se>
date Mon, 01 Apr 2013 21:29:59 +0200
parents 106:c33848e79bfc (diff) 101:956242b7d5df (current diff)
children 108:ded3938232f0
files squishy
diffstat 4 files changed, 115 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/clix.lua	Sun Mar 31 02:56:39 2013 +0100
+++ b/clix.lua	Mon Apr 01 21:29:59 2013 +0200
@@ -58,8 +58,12 @@
 		io.stderr:write("The specified account (", opts.account or "default", ") wasn't found in the config file\n");
 		return nil;
 	end
-	verse.set_log_handler(io.stderr, opts.quiet and {} or not opts.verbose and {"info", "error"});
+	verse.set_log_handler(io.stderr, opts.quiet and {} or not opts.verbose and {"info", "warn", "error"});
 	local conn = verse.new(verse.new_logger("clix"));
+	if opts.raw then
+		conn:hook("incoming-raw", print, 1000);
+		conn:hook("outgoing-raw", print, 1000);
+	end
 	for _, plugin in ipairs(plugins or {}) do
 		conn:add_plugin(plugin);
 	end
@@ -82,7 +86,7 @@
 		conn:close();
 	end);
 	conn:hook("disconnected", function (info)
-		if info.reason then
+		if info and info.reason and info.reason ~= "stream closed"  then
 			conn:warn("Disconnecting: %s", tostring(info.reason));
 		end
 		verse.quit();
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/clix/adhoc.lua	Mon Apr 01 21:29:59 2013 +0200
@@ -0,0 +1,84 @@
+local dataforms = require "util.dataforms";
+
+-- TODO Cleanup, commit
+return function (opts, arg)
+	if opts.short_help then
+		print("Execute an Ad-Hoc Command");
+		return;
+	end
+	local function on_connect(conn)
+		if opts.node then
+			conn:execute_command(opts.to or conn.host, opts.node, function(cmd)
+				conn:info("status: %s", cmd.status);
+				local note = cmd.note;
+				if note then
+					conn[note.attr.type or "info"](conn, note:get_text());
+				end
+				if cmd.status == "executing" then
+					local data = {};
+					for i=1,#arg do
+						local k,v = arg[i]:match"^([^=]+)=(.*)";
+						if k and v then
+							data[k] = v; --FIXME multiple
+						end
+					end
+					local command_form_layout = dataforms.from_stanza(cmd.form)
+					if opts.interactive then
+						for i=1,#command_form_layout do
+							local item = command_form_layout[i];
+							if item.type ~= "hidden" and not data[item.name] then
+								-- FIXME Current value isn't shown
+								io.stderr:write(item.label..": ");
+								if item.type:match"%-multi" then
+									local t = { };
+										repeat
+										local line = io.read("*l");
+										if line and line ~= "" then
+											t[#t+1] = line;
+										end
+									until not line or line == "";
+									if item.type == "text-multi" then
+										t = table.concat(t, "\n");
+									end
+									data[item.name] = t;
+								--elseif item.type == "list-single" then
+									--data[item.name] = { (io.read("*l")) };
+								else
+									data[item.name] = io.read("*l");
+								end
+							end
+						end
+					end
+					cmd:next(command_form_layout:form(data, "submit"));
+				elseif cmd.status == "completed" then
+					if cmd.form then
+						local command_form_layout = dataforms.from_stanza(cmd.form)
+						local data = command_form_layout:data(cmd.form);
+						for i, item in ipairs(command_form_layout) do
+							if item.type ~= "hidden" then
+								print("== " .. item.name .. " ==")
+								print(data[item.name]);
+							end
+						end
+
+					end
+					conn:close();
+				else
+					conn:warn("unhandled command status: %s", tostring(cmd.status));
+				end
+			end);
+		else
+			conn:disco_items(opts.to or conn.host, "http://jabber.org/protocol/commands", function(items)
+				-- TODO It would be neat to be able to choose from this list
+				if items then
+					for i=1,#items do
+						print(items[i].name, items[i].node);
+					end
+				end
+				conn:close();
+			end);
+		end
+	end
+	clix_connect(opts, on_connect, {"adhoc"});
+end
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/clix/ping.lua	Mon Apr 01 21:29:59 2013 +0200
@@ -0,0 +1,24 @@
+return function (opts, arg)
+	if opts.short_help then
+		print("Measure the round-trip latency time of a given JID");
+		return;
+	end
+	if #arg == 0 or opts.help then
+		return 0;
+	end
+	local conn;
+	local function on_reply(time, jid, reply)
+		if time then
+			print(string.format("%s latency: %1.3fs", jid, time));
+		else
+			print("Error requesting ping ("..(reply.condition or "unknown")..")"..(reply.text and (": "..reply.text) or ""));
+		end
+		conn:close();
+	end
+	local function on_connect(_conn)
+		conn = _conn;
+		conn:add_plugin("ping");
+		conn:ping(arg[1], on_reply);
+	end
+	clix_connect(opts, on_connect);
+end
--- a/squishy	Sun Mar 31 02:56:39 2013 +0100
+++ b/squishy	Mon Apr 01 21:29:59 2013 +0200
@@ -2,6 +2,7 @@
 	"send";
 	"receive";
 	"version";
+	"ping";
 	"bounce";
 	"mirror";
 	"raw";