Software /
code /
prosody
Comparison
util/session.lua @ 10411:db2a06b9ff98
Merge 0.11->trunk
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Sat, 16 Nov 2019 16:52:31 +0100 |
parent | 10110:3fa3872588a8 |
child | 12640:999b1c59af6f |
comparison
equal
deleted
inserted
replaced
10410:659b577f280c | 10411:db2a06b9ff98 |
---|---|
2 local logger = require "util.logger"; | 2 local logger = require "util.logger"; |
3 | 3 |
4 local function new_session(typ) | 4 local function new_session(typ) |
5 local session = { | 5 local session = { |
6 type = typ .. "_unauthed"; | 6 type = typ .. "_unauthed"; |
7 base_type = typ; | |
7 }; | 8 }; |
8 return session; | 9 return session; |
9 end | 10 end |
10 | 11 |
11 local function set_id(session) | 12 local function set_id(session) |
12 local id = session.type .. tostring(session):match("%x+$"):lower(); | 13 local id = session.base_type .. tostring(session):match("%x+$"):lower(); |
13 session.id = id; | 14 session.id = id; |
14 return session; | 15 return session; |
15 end | 16 end |
16 | 17 |
17 local function set_logger(session) | 18 local function set_logger(session) |
28 | 29 |
29 local function set_send(session) | 30 local function set_send(session) |
30 local conn = session.conn; | 31 local conn = session.conn; |
31 if not conn then | 32 if not conn then |
32 function session.send(data) | 33 function session.send(data) |
33 session.log("debug", "Discarding data sent to unconnected session: %s", tostring(data)); | 34 session.log("debug", "Discarding data sent to unconnected session: %s", data); |
34 return false; | 35 return false; |
35 end | 36 end |
36 return session; | 37 return session; |
37 end | 38 end |
38 local filter = initialize_filters(session); | 39 local filter = initialize_filters(session); |
44 if t then | 45 if t then |
45 t = filter("bytes/out", tostring(t)); | 46 t = filter("bytes/out", tostring(t)); |
46 if t then | 47 if t then |
47 local ret, err = w(conn, t); | 48 local ret, err = w(conn, t); |
48 if not ret then | 49 if not ret then |
49 session.log("debug", "Error writing to connection: %s", tostring(err)); | 50 session.log("debug", "Error writing to connection: %s", err); |
50 return false, err; | 51 return false, err; |
51 end | 52 end |
52 end | 53 end |
53 end | 54 end |
54 return true; | 55 return true; |