aboutsummaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
Diffstat (limited to 'core')
-rw-r--r--core/sessionmanager.lua41
-rw-r--r--core/usermanager.lua2
-rw-r--r--core/xmlhandlers.lua11
3 files changed, 51 insertions, 3 deletions
diff --git a/core/sessionmanager.lua b/core/sessionmanager.lua
index b257e532..3366120e 100644
--- a/core/sessionmanager.lua
+++ b/core/sessionmanager.lua
@@ -1,26 +1,62 @@
local tonumber, tostring = tonumber, tostring;
-local ipairs, print= ipairs, print;
-
+local ipairs, pairs, print= ipairs, pairs, print;
+local collectgarbage = collectgarbage;
local m_random = import("math", "random");
local format = import("string", "format");
local hosts = hosts;
+local sessions = sessions;
local modulemanager = require "core.modulemanager";
local log = require "util.logger".init("sessionmanager");
local error = error;
local uuid_generate = require "util.uuid".uuid_generate;
+
+local newproxy = newproxy;
+local getmetatable = getmetatable;
+
module "sessionmanager"
function new_session(conn)
local session = { conn = conn, notopen = true, priority = 0, type = "c2s_unauthed" };
+ if true then
+ session.trace = newproxy(true);
+ getmetatable(session.trace).__gc = function () print("Session got collected") end;
+ end
local w = conn.write;
session.send = function (t) w(tostring(t)); end
return session;
end
function destroy_session(session)
+ if not (session and session.disconnect) then return; end
+ log("debug", "Destroying session...");
+ session.disconnect();
+ if session.username then
+ if session.resource then
+ hosts[session.host].sessions[session.username].sessions[session.resource] = nil;
+ end
+ local nomore = true;
+ for res, ssn in pairs(hosts[session.host].sessions[session.username]) do
+ nomore = false;
+ end
+ if nomore then
+ hosts[session.host].sessions[session.username] = nil;
+ end
+ end
+ session.conn = nil;
+ session.disconnect = nil;
+ for k in pairs(session) do
+ if k ~= "trace" then
+ session[k] = nil;
+ end
+ end
+ collectgarbage("collect");
+ collectgarbage("collect");
+ collectgarbage("collect");
+ collectgarbage("collect");
+ collectgarbage("collect");
end
function send_to_session(session, data)
@@ -34,6 +70,7 @@ function make_authenticated(session, username)
if session.type == "c2s_unauthed" then
session.type = "c2s";
end
+ return true;
end
function bind_resource(session, resource)
diff --git a/core/usermanager.lua b/core/usermanager.lua
index a67ad368..0f303b24 100644
--- a/core/usermanager.lua
+++ b/core/usermanager.lua
@@ -1,10 +1,12 @@
require "util.datamanager"
local datamanager = datamanager;
+local log = require "util.logger".init("usermanager");
module "usermanager"
function validate_credentials(host, username, password)
+ log("debug", "User '%s' is being validated", username);
local credentials = datamanager.load(username, host, "accounts") or {};
if password == credentials.password then return true; end
return false;
diff --git a/core/xmlhandlers.lua b/core/xmlhandlers.lua
index 1ce7527d..ebc8f91d 100644
--- a/core/xmlhandlers.lua
+++ b/core/xmlhandlers.lua
@@ -10,6 +10,7 @@ local t_insert = table.insert;
local t_remove = table.remove;
local t_concat = table.concat;
local t_concatall = function (t, sep) local tt = {}; for _, s in ipairs(t) do t_insert(tt, tostring(s)); end return t_concat(tt, sep); end
+local sm_destroy_session = import("core.sessionmanager", "destroy_session");
local error = error;
@@ -60,7 +61,15 @@ function init_xmlhandlers(session)
end
function xml_handlers:EndElement(name)
curr_ns,name = name:match("^(.+):(%w+)$");
- if (not stanza) or #stanza.last_add < 0 or (#stanza.last_add > 0 and name ~= stanza.last_add[#stanza.last_add].name) then error("XML parse error in client stream"); end
+ if (not stanza) or #stanza.last_add < 0 or (#stanza.last_add > 0 and name ~= stanza.last_add[#stanza.last_add].name) then
+ if name == "stream" then
+ log("debug", "Stream closed");
+ sm_destroy_session(session);
+ return;
+ else
+ error("XML parse error in client stream");
+ end
+ end
if stanza and #chardata > 0 then
-- We have some character data in the buffer
stanza:text(t_concat(chardata));