diff options
Diffstat (limited to 'util/adminstream.lua')
-rw-r--r-- | util/adminstream.lua | 38 |
1 files changed, 20 insertions, 18 deletions
diff --git a/util/adminstream.lua b/util/adminstream.lua index 4075aa05..5387c906 100644 --- a/util/adminstream.lua +++ b/util/adminstream.lua @@ -1,15 +1,15 @@ -local st = require "util.stanza"; -local new_xmpp_stream = require "util.xmppstream".new; -local sessionlib = require "util.session"; -local gettime = require "util.time".now; -local runner = require "util.async".runner; -local add_task = require "util.timer".add_task; -local events = require "util.events"; -local server = require "net.server"; +local st = require "prosody.util.stanza"; +local new_xmpp_stream = require "prosody.util.xmppstream".new; +local sessionlib = require "prosody.util.session"; +local gettime = require "prosody.util.time".now; +local runner = require "prosody.util.async".runner; +local add_task = require "prosody.util.timer".add_task; +local events = require "prosody.util.events"; +local server = require "prosody.net.server"; local stream_close_timeout = 5; -local log = require "util.logger".init("adminstream"); +local log = require "prosody.util.logger".init("adminstream"); local xmlns_xmpp_streams = "urn:ietf:params:xml:ns:xmpp-streams"; @@ -145,7 +145,7 @@ local function new_connection(socket_path, listeners) -- constructor was exported instead of a module table. Due to the lack of a -- proper release of LuaSocket, distros have settled on shipping either the -- last RC tag or some commit since then. - -- Here we accomodate both variants. + -- Here we accommodate both variants. unix = { stream = unix }; end if type(unix) ~= "table" then @@ -185,9 +185,12 @@ local function new_connection(socket_path, listeners) end local function new_server(sessions, stanza_handler) - local listeners = {}; + local s = { + events = events.new(); + listeners = {}; + }; - function listeners.onconnect(conn) + function s.listeners.onconnect(conn) log("debug", "New connection"); local session = sessionlib.new("admin"); sessionlib.set_id(session); @@ -241,29 +244,28 @@ local function new_server(sessions, stanza_handler) sessions[conn] = session; end - function listeners.onincoming(conn, data) + function s.listeners.onincoming(conn, data) local session = sessions[conn]; if session then session.data(data); end end - function listeners.ondisconnect(conn, err) + function s.listeners.ondisconnect(conn, err) local session = sessions[conn]; if session then session.log("info", "Admin client disconnected: %s", err or "connection closed"); session.conn = nil; sessions[conn] = nil; + s.events.fire_event("disconnected", { session = session }); end end - function listeners.onreadtimeout(conn) + function s.listeners.onreadtimeout(conn) return conn:send(" "); end - return { - listeners = listeners; - }; + return s; end local function new_client() |