Comparison

plugins/mod_c2s.lua @ 4548:e6e5c76ff009

sessionmanager, mod_c2s: Move timeout logic to mod_c2s
author Matthew Wild <mwild1@gmail.com>
date Mon, 23 Jan 2012 00:56:57 +0000
parent 4543:db27a4c18b6a
child 4551:8f25f3b1c62f
comparison
equal deleted inserted replaced
4547:d9d777e97e8f 4548:e6e5c76ff009
6 -- COPYING file in the source package for more information. 6 -- COPYING file in the source package for more information.
7 -- 7 --
8 8
9 module:set_global(); 9 module:set_global();
10 10
11 local add_task = require "util.timer".add_task;
11 local new_xmpp_stream = require "util.xmppstream".new; 12 local new_xmpp_stream = require "util.xmppstream".new;
12 local nameprep = require "util.encodings".stringprep.nameprep; 13 local nameprep = require "util.encodings".stringprep.nameprep;
13 local portmanager = require "core.portmanager"; 14 local portmanager = require "core.portmanager";
14 local sessionmanager = require "core.sessionmanager"; 15 local sessionmanager = require "core.sessionmanager";
15 local st = require "util.stanza"; 16 local st = require "util.stanza";
22 23
23 local xmlns_xmpp_streams = "urn:ietf:params:xml:ns:xmpp-streams"; 24 local xmlns_xmpp_streams = "urn:ietf:params:xml:ns:xmpp-streams";
24 25
25 local log = module._log; 26 local log = module._log;
26 27
28 local c2s_timeout = module:get_option_number("c2s_timeout");
27 local opt_keepalives = module:get_option_boolean("tcp_keepalives", false); 29 local opt_keepalives = module:get_option_boolean("tcp_keepalives", false);
28 30
29 local sessions = module:shared("sessions"); 31 local sessions = module:shared("sessions");
30 32
31 local stream_callbacks = { default_ns = "jabber:client", handlestanza = core_process_stanza }; 33 local stream_callbacks = { default_ns = "jabber:client", handlestanza = core_process_stanza };
184 log("debug", "Received invalid XML (%s) %d bytes: %s", tostring(err), #data, data:sub(1, 300):gsub("[\r\n]+", " "):gsub("[%z\1-\31]", "_")); 186 log("debug", "Received invalid XML (%s) %d bytes: %s", tostring(err), #data, data:sub(1, 300):gsub("[\r\n]+", " "):gsub("[%z\1-\31]", "_"));
185 session:close("not-well-formed"); 187 session:close("not-well-formed");
186 end 188 end
187 end 189 end
188 190
191
192 if c2s_timeout then
193 add_task(c2s_timeout, function ()
194 if session.type == "c2s_unauthed" then
195 session:close("connection-timeout");
196 end
197 end);
198 end
199
189 session.dispatch_stanza = stream_callbacks.handlestanza; 200 session.dispatch_stanza = stream_callbacks.handlestanza;
190 end 201 end
191 202
192 function listener.onincoming(conn, data) 203 function listener.onincoming(conn, data)
193 local session = sessions[conn]; 204 local session = sessions[conn];