Comparison

core/sessionmanager.lua @ 3143:887a6374f51c

sessionmanager: Initialize new sessions for filtering, and add filters for outgoing bytes and stanzas
author Matthew Wild <mwild1@gmail.com>
date Wed, 02 Jun 2010 17:51:14 +0100
parent 3091:d6a059af2077
child 3145:675241be2935
comparison
equal deleted inserted replaced
3142:3cf02e5e632b 3143:887a6374f51c
24 local rm_load_roster = require "core.rostermanager".load_roster; 24 local rm_load_roster = require "core.rostermanager".load_roster;
25 local config_get = require "core.configmanager".get; 25 local config_get = require "core.configmanager".get;
26 local nameprep = require "util.encodings".stringprep.nameprep; 26 local nameprep = require "util.encodings".stringprep.nameprep;
27 local resourceprep = require "util.encodings".stringprep.resourceprep; 27 local resourceprep = require "util.encodings".stringprep.resourceprep;
28 28
29 local filters_initialize = require "util.filters".initialize;
29 local fire_event = require "core.eventmanager".fire_event; 30 local fire_event = require "core.eventmanager".fire_event;
30 local add_task = require "util.timer".add_task; 31 local add_task = require "util.timer".add_task;
31 local gettime = require "socket".gettime; 32 local gettime = require "socket".gettime;
32 33
33 local st = require "util.stanza"; 34 local st = require "util.stanza";
47 session.trace = newproxy(true); 48 session.trace = newproxy(true);
48 getmetatable(session.trace).__gc = function () open_sessions = open_sessions - 1; end; 49 getmetatable(session.trace).__gc = function () open_sessions = open_sessions - 1; end;
49 end 50 end
50 open_sessions = open_sessions + 1; 51 open_sessions = open_sessions + 1;
51 log("debug", "open sessions now: ".. open_sessions); 52 log("debug", "open sessions now: ".. open_sessions);
53
54 local filter = filters_initialize(session);
52 local w = conn.write; 55 local w = conn.write;
53 session.send = function (t) w(conn, tostring(t)); end 56 session.send = function (t)
57 if t.name then
58 t = filter("stanzas/out", t);
59 end
60 if t then
61 t = filter("bytes/out", tostring(t));
62 if t then
63 return w(conn, t);
64 end
65 end
66 end
54 session.ip = conn:ip(); 67 session.ip = conn:ip();
55 local conn_name = "c2s"..tostring(conn):match("[a-f0-9]+$"); 68 local conn_name = "c2s"..tostring(conn):match("[a-f0-9]+$");
56 session.log = logger.init(conn_name); 69 session.log = logger.init(conn_name);
57 70
58 if c2s_timeout then 71 if c2s_timeout then