Software /
code /
prosody
Comparison
core/sessionmanager.lua @ 1872:1905eca82ddf
sessionmanager: Add c2s_timeout option for unauthenticated client connections
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Sat, 03 Oct 2009 02:41:28 +0100 |
parent | 1684:645e18990211 |
child | 1873:3b770710a1ee |
comparison
equal
deleted
inserted
replaced
1871:838d1317bca4 | 1872:1905eca82ddf |
---|---|
26 local rm_load_roster = require "core.rostermanager".load_roster; | 26 local rm_load_roster = require "core.rostermanager".load_roster; |
27 local config_get = require "core.configmanager".get; | 27 local config_get = require "core.configmanager".get; |
28 local nameprep = require "util.encodings".stringprep.nameprep; | 28 local nameprep = require "util.encodings".stringprep.nameprep; |
29 | 29 |
30 local fire_event = require "core.eventmanager".fire_event; | 30 local fire_event = require "core.eventmanager".fire_event; |
31 | 31 local add_task = require "util.timer".add_task; |
32 local gettime = require "socket".gettime; | 32 local gettime = require "socket".gettime; |
33 | 33 |
34 local st = require "util.stanza"; | 34 local st = require "util.stanza"; |
35 | |
36 local c2s_timeout = config_get("*", "core", "c2s_timeout"); | |
35 | 37 |
36 local newproxy = newproxy; | 38 local newproxy = newproxy; |
37 local getmetatable = getmetatable; | 39 local getmetatable = getmetatable; |
38 | 40 |
39 module "sessionmanager" | 41 module "sessionmanager" |
51 local w = conn.write; | 53 local w = conn.write; |
52 session.send = function (t) w(tostring(t)); end | 54 session.send = function (t) w(tostring(t)); end |
53 session.ip = conn.ip(); | 55 session.ip = conn.ip(); |
54 local conn_name = "c2s"..tostring(conn):match("[a-f0-9]+$"); | 56 local conn_name = "c2s"..tostring(conn):match("[a-f0-9]+$"); |
55 session.log = logger.init(conn_name); | 57 session.log = logger.init(conn_name); |
58 | |
59 if c2s_timeout then | |
60 add_task(c2s_timeout, function () | |
61 if session.type == "c2s_unauthed" then | |
62 session:close("connection-timeout"); | |
63 end | |
64 end); | |
65 end | |
56 | 66 |
57 return session; | 67 return session; |
58 end | 68 end |
59 | 69 |
60 function destroy_session(session, err) | 70 function destroy_session(session, err) |