Software /
code /
prosody
Comparison
util/session.lua @ 6941:33fbc835697d
util.session: How would you even send anything to a session?
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Tue, 24 Nov 2015 19:31:37 +0100 |
parent | 6940:2be5e19485aa |
child | 7181:8af558965da3 |
comparison
equal
deleted
inserted
replaced
6940:2be5e19485aa | 6941:33fbc835697d |
---|---|
1 local initialize_filters = require "util.filters".initialize; | |
1 local logger = require "util.logger"; | 2 local logger = require "util.logger"; |
2 | 3 |
3 local function new_session(typ) | 4 local function new_session(typ) |
4 local session = { | 5 local session = { |
5 type = typ .. "_unauthed"; | 6 type = typ .. "_unauthed"; |
23 session.conn = conn; | 24 session.conn = conn; |
24 session.ip = conn:ip(); | 25 session.ip = conn:ip(); |
25 return session; | 26 return session; |
26 end | 27 end |
27 | 28 |
29 local function set_send(session) | |
30 local conn = session.conn; | |
31 if not conn then | |
32 function session.send(data) | |
33 log("debug", "Discarding data sent to unconnected session: %s", tostring(data)); | |
34 return false; | |
35 end | |
36 return session; | |
37 end | |
38 local filter = initialize_filters(session); | |
39 local w = conn.write; | |
40 session.send = function (t) | |
41 if t.name then | |
42 t = filter("stanzas/out", t); | |
43 end | |
44 if t then | |
45 t = filter("bytes/out", tostring(t)); | |
46 if t then | |
47 local ret, err = w(conn, t); | |
48 if not ret then | |
49 session.log("debug", "Error writing to connection: %s", tostring(err)); | |
50 return false, err; | |
51 end | |
52 end | |
53 end | |
54 return true; | |
55 end | |
56 return session; | |
57 end | |
58 | |
28 return { | 59 return { |
29 new = new_session; | 60 new = new_session; |
30 set_id = set_id; | 61 set_id = set_id; |
31 set_logger = set_logger; | 62 set_logger = set_logger; |
32 set_conn = set_conn; | 63 set_conn = set_conn; |
64 set_send = set_send; | |
33 } | 65 } |