IMPORTANT: due to a drive failure, as of 13-Mar-2021, the Mercurial repository had to be re-mirrored, which changed every commit SHA. The old SHAs and trees are backed up in the vault branches. Please migrate to the new branches as soon as you can.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
prosody/util/session.lua

65 lines
1.3 KiB

local initialize_filters = require "util.filters".initialize;
local logger = require "util.logger";
local function new_session(typ)
local session = {
type = typ .. "_unauthed";
};
return session;
end
local function set_id(session)
local id = session.type .. tostring(session):match("%x+$"):lower();
session.id = id;
return session;
end
local function set_logger(session)
local log = logger.init(session.id);
session.log = log;
return session;
end
local function set_conn(session, conn)
session.conn = conn;
session.ip = conn:ip();
return session;
end
local function set_send(session)
local conn = session.conn;
if not conn then
function session.send(data)
session.log("debug", "Discarding data sent to unconnected session: %s", tostring(data));
return false;
end
return session;
end
local filter = initialize_filters(session);
local w = conn.write;
session.send = function (t)
if t.name then
t = filter("stanzas/out", t);
end
if t then
t = filter("bytes/out", tostring(t));
if t then
local ret, err = w(conn, t);
if not ret then
session.log("debug", "Error writing to connection: %s", tostring(err));
return false, err;
end
end
end
return true;
end
return session;
end
return {
new = new_session;
set_id = set_id;
set_logger = set_logger;
set_conn = set_conn;
set_send = set_send;
}