aboutsummaryrefslogtreecommitdiffstats
path: root/plugins
diff options
context:
space:
mode:
authorWaqas Hussain <waqas20@gmail.com>2009-01-03 18:44:39 +0500
committerWaqas Hussain <waqas20@gmail.com>2009-01-03 18:44:39 +0500
commit65877cc124443e72cb7d0d8613ab18509c55d58c (patch)
treeec5b3f2a0cf1da7502d29b09986226ee489b396a /plugins
parent6ef4323a0df781cf155046bb88bce90032edae23 (diff)
downloadprosody-65877cc124443e72cb7d0d8613ab18509c55d58c.tar.gz
prosody-65877cc124443e72cb7d0d8613ab18509c55d58c.zip
mod_console: replace all \n with \r\n in the output, and send \0 as a marker character after every response
Diffstat (limited to 'plugins')
-rw-r--r--plugins/mod_console.lua82
1 files changed, 42 insertions, 40 deletions
diff --git a/plugins/mod_console.lua b/plugins/mod_console.lua
index d6383a78..b5831df1 100644
--- a/plugins/mod_console.lua
+++ b/plugins/mod_console.lua
@@ -30,7 +30,7 @@ local default_env_mt = { __index = def_env };
console = {};
function console:new_session(conn)
- local w = conn.write;
+ local w = function(s) conn.write(s:gsub("\n", "\r\n")); end;
local session = { conn = conn;
send = function (t) w(tostring(t)); end;
print = function (t) w("| "..tostring(t).."\n"); end;
@@ -61,50 +61,52 @@ function console_listener.listener(conn, data)
end
if data then
-- Handle data
-
- if data:match("[!.]$") then
- local command = data:lower();
- command = data:match("^%w+") or data:match("%p");
- if commands[command] then
- commands[command](session, data);
- return;
+ (function(session, data)
+ if data:match("[!.]$") then
+ local command = data:lower();
+ command = data:match("^%w+") or data:match("%p");
+ if commands[command] then
+ commands[command](session, data);
+ return;
+ end
end
- end
-
- session.env._ = data;
-
- local chunk, err = loadstring("return "..data);
- if not chunk then
- chunk, err = loadstring(data);
+
+ session.env._ = data;
+
+ local chunk, err = loadstring("return "..data);
if not chunk then
- err = err:gsub("^%[string .-%]:%d+: ", "");
- err = err:gsub("^:%d+: ", "");
- err = err:gsub("'<eof>'", "the end of the line");
- session.print("Sorry, I couldn't understand that... "..err);
+ chunk, err = loadstring(data);
+ if not chunk then
+ err = err:gsub("^%[string .-%]:%d+: ", "");
+ err = err:gsub("^:%d+: ", "");
+ err = err:gsub("'<eof>'", "the end of the line");
+ session.print("Sorry, I couldn't understand that... "..err);
+ return;
+ end
+ end
+
+ setfenv(chunk, session.env);
+ local ranok, taskok, message = pcall(chunk);
+
+ if not ranok then
+ session.print("Fatal error while running command, it did not complete");
+ session.print("Error: "..taskok);
return;
end
- end
-
- setfenv(chunk, session.env);
- local ranok, taskok, message = pcall(chunk);
-
- if not ranok then
- session.print("Fatal error while running command, it did not complete");
- session.print("Error: "..taskok);
- return;
- end
-
- if not message then
- session.print("Result: "..tostring(taskok));
- return;
- elseif (not taskok) and message then
- session.print("Command completed with a problem");
- session.print("Message: "..tostring(message));
- return;
- end
-
- session.print("OK: "..tostring(message));
+
+ if not message then
+ session.print("Result: "..tostring(taskok));
+ return;
+ elseif (not taskok) and message then
+ session.print("Command completed with a problem");
+ session.print("Message: "..tostring(message));
+ return;
+ end
+
+ session.print("OK: "..tostring(message));
+ end)(session, data);
end
+ session.send(string.char(0));
end
function console_listener.disconnect(conn, err)