local format = import("string", "format");
local hosts = hosts;
-local sessions = sessions;
+local full_sessions = full_sessions;
+local bare_sessions = bare_sessions;
local modulemanager = require "core.modulemanager";
local log = require "util.logger".init("sessionmanager");
getmetatable(session.trace).__gc = function () open_sessions = open_sessions - 1; end;
end
open_sessions = open_sessions + 1;
- log("info", "open sessions now: ".. open_sessions);
+ log("debug", "open sessions now: ".. open_sessions);
local w = conn.write;
session.send = function (t) w(tostring(t)); end
session.ip = conn.ip();
end
function destroy_session(session, err)
- (session.log or log)("info", "Destroying session");
+ (session.log or log)("info", "Destroying session for %s (%s@%s)", session.full_jid or "(unknown)", session.username or "(unknown)", session.host or "(unknown)");
-- Send unavailable presence
if session.presence then
if hosts[session.host] and hosts[session.host].sessions[session.username] then
if session.resource then
hosts[session.host].sessions[session.username].sessions[session.resource] = nil;
+ full_sessions[session.full_jid] = nil;
end
if not next(hosts[session.host].sessions[session.username].sessions) then
log("debug", "All resources of %s are now offline", session.username);
hosts[session.host].sessions[session.username] = nil;
+ bare_sessions[session.host..'@'..session.username] = nil;
end
else
log("error", "host or session table didn't exist, please report this! Host: %s [%s] Sessions: %s [%s]",
if session.type == "c2s_unauthed" then
session.type = "c2s";
end
+ session.log("info", "Authenticated as %s@%s", username or "(unknown)", session.host or "(unknown)");
return true;
end
--FIXME: Randomly-generated resources must be unique per-user, and never conflict with existing
if not hosts[session.host].sessions[session.username] then
- hosts[session.host].sessions[session.username] = { sessions = {} };
+ local sessions = { sessions = {} };
+ hosts[session.host].sessions[session.username] = sessions;
+ bare_sessions[session.host..'@'..session.username] = sessions;
else
local sessions = hosts[session.host].sessions[session.username].sessions;
local limit = config_get(session.host, "core", "max_resources") or 10;
session.resource = resource;
session.full_jid = session.username .. '@' .. session.host .. '/' .. resource;
hosts[session.host].sessions[session.username].sessions[resource] = session;
+ full_sessions[session.full_jid] = session;
session.roster = rm_load_roster(session.username, session.host);
session:close{ condition = "host-unknown", text = "This server does not serve "..tostring(session.host)};
return;
end
+
+ -- If session.secure is *false* (not nil) then it means we /were/ encrypting
+ -- since we now have a new stream header, session is secured
+ if session.secure == false then
+ session.secure = true;
+ end
local features = st.stanza("stream:features");
fire_event("stream-features", session, features);
send(features);
- (session.log or log)("info", "Sent reply <stream:stream> to client");
+ (session.log or log)("debug", "Sent reply <stream:stream> to client");
session.notopen = nil;
end