Merge with Florob
authorMatthew Wild <mwild1@gmail.com>
Sat, 28 Jul 2012 00:14:31 +0000 (01:14 +0100)
committerMatthew Wild <mwild1@gmail.com>
Sat, 28 Jul 2012 00:14:31 +0000 (01:14 +0100)
1  2 
core/moduleapi.lua
core/rostermanager.lua
plugins/mod_admin_telnet.lua
prosodyctl
util/datamanager.lua

index 2bcf9b84d7cf8a10be6f92b84bf4e61d19240fa1,572dc1797de9322c40833fe75458b1650197ea3f..5407782677e4075252a3211294d9b67174682d6f
@@@ -14,10 -14,8 +14,8 @@@ local logger = require "util.logger"
  local pluginloader = require "util.pluginloader";
  local timer = require "util.timer";
  
- local multitable_new = require "util.multitable".new;
  local t_insert, t_remove, t_concat = table.insert, table.remove, table.concat;
 -local error, setmetatable, setfenv, type = error, setmetatable, setfenv, type;
 +local error, setmetatable, type = error, setmetatable, type;
  local ipairs, pairs, select, unpack = ipairs, pairs, select, unpack;
  local tonumber, tostring = tonumber, tostring;
  
Simple merge
index cdac7d4e950f168d5f1e1231d8ab27f8f31e27b6,ca37ca7aefbe38679f8cb76479242b754579450d..ebd817b598dc745572fbf0c00c73c9195616df45
@@@ -13,11 -13,8 +13,11 @@@ local _G = _G
  local prosody = _G.prosody;
  local hosts = prosody.hosts;
  
- local console_listener = { default_port = 5582; default_mode = "*l"; interface = "127.0.0.1" };
+ local console_listener = { default_port = 5582; default_mode = "*a"; interface = "127.0.0.1" };
  
 +local hostmanager = require "core.hostmanager";
 +local modulemanager = require "core.modulemanager";
 +
  local iterators = require "util.iterators";
  local keys, values = iterators.keys, iterators.values;
  local jid = require "util.jid";
@@@ -81,67 -77,75 +82,74 @@@ en
  function console_listener.onincoming(conn, data)
        local session = sessions[conn];
  
-       -- Handle data
-       (function(session, data)
-               local useglobalenv;
-               
-               if data:match("^>") then
-                       data = data:gsub("^>", "");
-                       useglobalenv = true;
-               elseif data == "\004" then
-                       commands["bye"](session, data);
-                       return;
-               else
-                       local command = data:lower();
-                       command = data:match("^%w+") or data:match("%p");
-                       if commands[command] then
-                               commands[command](session, data);
-                               return;
+       local partial = session.partial_data;
+       if partial then
+               data = partial..data;
+       end
+       for line in data:gmatch("[^\n]*[\n\004]") do
+               -- Handle data (loop allows us to break to add \0 after response)
+               repeat
+                       local useglobalenv;
+                       if line:match("^>") then
+                               line = line:gsub("^>", "");
+                               useglobalenv = true;
+                       elseif line == "\004" then
+                               commands["bye"](session, line);
+                               break;
+                       else
+                               local command = line:match("^%w+") or line:match("%p");
+                               if commands[command] then
+                                       commands[command](session, line);
+                                       break;
+                               end
                        end
-               end
  
-               session.env._ = data;
-               
-               local chunkname = "=console";
-               local env = (useglobalenv and redirect_output(_G, session)) or session.env or nil
-               local chunk, err = envload("return "..data, chunkname, env);
-               if not chunk then
-                       chunk, err = envload(data, chunkname, env);
+                       session.env._ = line;
+                       
+                       local chunkname = "=console";
 -                      local chunk, err = loadstring("return "..line, chunkname);
++                      local env = (useglobalenv and redirect_output(_G, session)) or session.env or nil
++                      local chunk, err = envload("return "..line, chunkname, env);
                        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;
 -                              chunk, err = loadstring(line, chunkname);
++                              chunk, err = envload(line, chunkname, env);
+                               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);
+                                       break;
+                               end
                        end
-               end
-               
-               local ranok, taskok, message = pcall(chunk);
 -                      
 -                      setfenv(chunk, (useglobalenv and redirect_output(_G, session)) or session.env or nil);
 -                      
 +              
-               if not (ranok or message or useglobalenv) and commands[data:lower()] then
-                       commands[data:lower()](session, data);
-                       return;
-               end
-               
-               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
+                       local ranok, taskok, message = pcall(chunk);
+                       
+                       if not (ranok or message or useglobalenv) and commands[line:lower()] then
+                               commands[line:lower()](session, line);
+                               break;
+                       end
+                       
+                       if not ranok then
+                               session.print("Fatal error while running command, it did not complete");
+                               session.print("Error: "..taskok);
+                               break;
+                       end
+                       
+                       if not message then
+                               session.print("Result: "..tostring(taskok));
+                               break;
+                       elseif (not taskok) and message then
+                               session.print("Command completed with a problem");
+                               session.print("Message: "..tostring(message));
+                               break;
+                       end
+                       
+                       session.print("OK: "..tostring(message));
+               until true
                
-               session.print("OK: "..tostring(message));
-       end)(session, data);
-       
-       session.send(string.char(0));
+               session.send(string.char(0));
+       end
+       session.partial_data = data:match("[^\n]+$");
  end
  
  function console_listener.ondisconnect(conn, err)
diff --cc prosodyctl
Simple merge
index 884d11615d613824beec568a5f787c4900a6d3bb,30c1e29812f77c1ff893a0ad1fd311374bd7c6bd..344d2eb1f3947a9b9bc722937bf3ad6f4a275077
@@@ -124,10 -123,10 +124,10 @@@ function load(username, host, datastore
                        return nil, "Error reading storage";
                end
        end
 -      setfenv(data, {});
 +
        local success, ret = pcall(data);
        if not success then
-               log("error", "Unable to load "..datastore.." storage ('"..ret.."') for user: "..(username or "nil").."@"..(host or "nil"));
+               log("error", "Unable to load %s storage ('%s') for user: %s@%s", datastore, ret, username or "nil", host or "nil");
                return nil, "Error reading storage";
        end
        return ret;
@@@ -217,10 -215,11 +217,10 @@@ function list_load(username, host, data
                        return nil, "Error reading storage";
                end
        end
 -      local items = {};
 -      setfenv(data, {item = function(i) t_insert(items, i); end});
 +
        local success, ret = pcall(data);
        if not success then
-               log("error", "Unable to load "..datastore.." storage ('"..ret.."') for user: "..(username or "nil").."@"..(host or "nil"));
+               log("error", "Unable to load %s storage ('%s') for user: %s@%s", datastore, ret, username or "nil", host or "nil");
                return nil, "Error reading storage";
        end
        return items;