Software /
code /
clix
Changeset
19:3a0a156e0a79
clix.raw: New command to set up a raw XML in/out session with the server
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Thu, 07 Jan 2010 20:58:52 +0000 |
parents | 18:6ad3ea055905 |
children | 20:80cc61512f10 |
files | clix/raw.lua |
diffstat | 1 files changed, 39 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/clix/raw.lua Thu Jan 07 20:58:52 2010 +0000 @@ -0,0 +1,39 @@ +short_opts.i = "interactive"; +short_opts.e = "echo"; + +return function (opts, args) + local function on_connect(conn) + conn:hook("incoming-raw", print); + io.stderr:write("Connected as ", conn.jid, "\n"); + if opts.interactive or opts.stdin then + local stdin = { + getfd = function () return 0; end; + dirty = function (self) return false; end; + settimeout = function () end; + send = function (_, d) return #d, 0; end; + close = function () end; + receive = function (_, patt) + local data = io.stdin:read(patt); + if opts.echo then + io.write(data, patt == "*l" and "\n" or ""); + end + return data; + end + }; + local function on_incoming(stdin, data) + conn:send(data); + if not opts.interactive then + conn:close(); + end + end + stdin = require "net.server".wrapclient(stdin, "stdin", 0, { + onincoming = on_incoming, ondisconnect = function () end + }, "*l"); + else + conn:send(table.concat(arg, " ")); + conn:close(); + end + + end + return clix_connect(opts, on_connect); +end