diff options
author | Kim Alvefur <zash@zash.se> | 2015-11-24 19:31:37 +0100 |
---|---|---|
committer | Kim Alvefur <zash@zash.se> | 2015-11-24 19:31:37 +0100 |
commit | 44875fdc39c7a78bf0d6319e43c9d225bd9acbf5 (patch) | |
tree | a1f8955aa5ebb2f402a4eb5fb786927874d6e1f4 /util/session.lua | |
parent | a14df709ba6e9f143cf4d2f5d6b788831e5739d9 (diff) | |
download | prosody-44875fdc39c7a78bf0d6319e43c9d225bd9acbf5.tar.gz prosody-44875fdc39c7a78bf0d6319e43c9d225bd9acbf5.zip |
util.session: How would you even send anything to a session?
Diffstat (limited to 'util/session.lua')
-rw-r--r-- | util/session.lua | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/util/session.lua b/util/session.lua index 03ddcf47..fda7fccd 100644 --- a/util/session.lua +++ b/util/session.lua @@ -1,3 +1,4 @@ +local initialize_filters = require "util.filters".initialize; local logger = require "util.logger"; local function new_session(typ) @@ -25,9 +26,40 @@ local function set_conn(session, conn) return session; end +local function set_send(session) + local conn = session.conn; + if not conn then + function session.send(data) + 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; } |