diff options
-rw-r--r-- | core/s2smanager.lua | 8 | ||||
-rw-r--r-- | core/sessionmanager.lua | 4 | ||||
-rw-r--r-- | net/adns.lua | 6 | ||||
-rw-r--r-- | net/connlisteners.lua | 11 | ||||
-rw-r--r-- | net/http.lua | 4 | ||||
-rw-r--r-- | net/httpclient_listener.lua | 4 | ||||
-rw-r--r-- | net/httpserver.lua | 4 | ||||
-rw-r--r-- | net/httpserver_listener.lua | 4 | ||||
-rw-r--r-- | net/server.lua | 2 | ||||
-rw-r--r-- | net/server_event.lua | 69 | ||||
-rw-r--r-- | net/server_select.lua | 52 | ||||
-rw-r--r-- | net/xmppclient_listener.lua | 10 | ||||
-rw-r--r-- | net/xmppcomponent_listener.lua | 6 | ||||
-rw-r--r-- | net/xmppserver_listener.lua | 6 | ||||
-rw-r--r-- | plugins/mod_tls.lua | 10 |
15 files changed, 107 insertions, 93 deletions
diff --git a/core/s2smanager.lua b/core/s2smanager.lua index d8edaed0..fb532a73 100644 --- a/core/s2smanager.lua +++ b/core/s2smanager.lua @@ -128,7 +128,7 @@ function new_incoming(conn) open_sessions = open_sessions + 1; local w, log = conn.write, logger_init("s2sin"..tostring(conn):match("[a-f0-9]+$")); session.log = log; - session.sends2s = function (t) log("debug", "sending: %s", (t.top_tag and t:top_tag()) or t:match("^([^>]*>?)")); w(tostring(t)); end + session.sends2s = function (t) log("debug", "sending: %s", (t.top_tag and t:top_tag()) or t:match("^([^>]*>?)"); w(conn, tostring(t)); end incoming_s2s[session] = true; add_task(connect_timeout, function () if session.conn ~= conn or @@ -317,9 +317,9 @@ function make_connect(host_session, connect_host, connect_port) cl.register_outgoing(conn, host_session); local w, log = conn.write, host_session.log; - host_session.sends2s = function (t) log("debug", "sending: %s", (t.top_tag and t:top_tag()) or t:match("^[^>]*>?")); w(tostring(t)); end + host_session.sends2s = function (t) log("debug", "sending: %s", (t.top_tag and t:top_tag()) or t:match("^[^>]*>?")); w(conn, tostring(t)); end - conn.write(format([[<stream:stream xmlns='jabber:server' xmlns:db='jabber:server:dialback' xmlns:stream='http://etherx.jabber.org/streams' from='%s' to='%s' version='1.0' xml:lang='en'>]], from_host, to_host)); + conn:write(format([[<stream:stream xmlns='jabber:server' xmlns:db='jabber:server:dialback' xmlns:stream='http://etherx.jabber.org/streams' from='%s' to='%s' version='1.0' xml:lang='en'>]], from_host, to_host)); log("debug", "Connection attempt in progress..."); add_task(connect_timeout, function () if host_session.conn ~= conn or @@ -391,7 +391,7 @@ function streamopened(session, attr) if send_buffer and #send_buffer > 0 then log("debug", "Sending s2s send_buffer now..."); for i, data in ipairs(send_buffer) do - session.sends2s(data); + session.sends2s(tostring(data)); send_buffer[i] = nil; end end diff --git a/core/sessionmanager.lua b/core/sessionmanager.lua index 08e70d44..7e609f22 100644 --- a/core/sessionmanager.lua +++ b/core/sessionmanager.lua @@ -50,8 +50,8 @@ function new_session(conn) open_sessions = open_sessions + 1; log("debug", "open sessions now: ".. open_sessions); local w = conn.write; - session.send = function (t) w(tostring(t)); end - session.ip = conn.ip(); + session.send = function (t) w(conn, tostring(t)); end + session.ip = conn:ip(); local conn_name = "c2s"..tostring(conn):match("[a-f0-9]+$"); session.log = logger.init(conn_name); diff --git a/net/adns.lua b/net/adns.lua index b0c9a625..c9cb9476 100644 --- a/net/adns.lua +++ b/net/adns.lua @@ -45,10 +45,10 @@ end function new_async_socket(sock, resolver) local newconn, peername = {}, "<unknown>"; local listener = {}; - function listener.incoming(conn, data) + function listener.onincoming(conn, data) dns.feed(sock, data); end - function listener.disconnect(conn, err) + function listener.ondisconnect(conn, err) log("warn", "DNS socket for %s disconnected: %s", peername, err); local servers = resolver.server; if resolver.socketset[newconn.handler] == resolver.best_server and resolver.best_server == #servers then @@ -68,7 +68,7 @@ function new_async_socket(sock, resolver) newconn.handler.setsockname = function (_, ...) return sock:setsockname(...); end newconn.handler.setpeername = function (_, ...) peername = (...); local ret = sock:setpeername(...); _.setsend(sock.send); return ret; end newconn.handler.connect = function (_, ...) return sock:connect(...) end - newconn.handler.send = function (_, data) _.write(data); return _.sendbuffer(); end + newconn.handler.send = function (_, data) _.write(_, data); return _.sendbuffer(); end return newconn.handler; end diff --git a/net/connlisteners.lua b/net/connlisteners.lua index 230d92a4..a9b92a8c 100644 --- a/net/connlisteners.lua +++ b/net/connlisteners.lua @@ -61,9 +61,14 @@ function start(name, udata) end end - return server.addserver(h, - (udata and udata.port) or h.default_port or error("Can't start listener "..name.." because no port was specified, and it has no default port", 0), - (udata and udata.interface) or h.default_interface or "*", (udata and udata.mode) or h.default_mode or 1, (udata and udata.ssl) or nil, 99999999, udata and udata.type == "ssl"); + local interface = (udata and udata.interface) or h.default_interface or "*"; + local port = (udata and udata.port) or h.default_port or error("Can't start listener "..name.." because no port was specified, and it has no default port", 0); + local mode = (udata and udata.mode) or h.default_mode or 1; + local ssl = (udata and udata.ssl) or nil; + local maxclients = 99999999; + local autossl = udata and udata.type == "ssl"; + + return server.addserver(interface, port, h, mode, ssl, autossl); end return _M; diff --git a/net/http.lua b/net/http.lua index 9d2f9b96..34ec11b4 100644 --- a/net/http.lua +++ b/net/http.lua @@ -152,7 +152,7 @@ function request(u, ex, callback) end req.handler, req.conn = server.wrapclient(socket.tcp(), req.host, req.port or 80, listener, "*a"); - req.write = req.handler.write; + req.write = function (...) return req.handler:write(...); end req.conn:settimeout(0); local ok, err = req.conn:connect(req.host, req.port or 80); if not ok and err ~= "timeout" then @@ -200,7 +200,7 @@ end function destroy_request(request) if request.conn then request.handler.close() - listener.disconnect(request.conn, "closed"); + listener.ondisconnect(request.conn, "closed"); end end diff --git a/net/httpclient_listener.lua b/net/httpclient_listener.lua index 69b7946b..6517de44 100644 --- a/net/httpclient_listener.lua +++ b/net/httpclient_listener.lua @@ -15,7 +15,7 @@ local buffers = {}; -- Buffers of partial lines local httpclient = { default_port = 80, default_mode = "*a" }; -function httpclient.listener(conn, data) +function httpclient.onincoming(conn, data) local request = requests[conn]; if not request then @@ -28,7 +28,7 @@ function httpclient.listener(conn, data) end end -function httpclient.disconnect(conn, err) +function httpclient.ondisconnect(conn, err) local request = requests[conn]; if request then request:reader(nil); diff --git a/net/httpserver.lua b/net/httpserver.lua index ddb4475c..51dca166 100644 --- a/net/httpserver.lua +++ b/net/httpserver.lua @@ -209,7 +209,7 @@ end function new_request(handler) return { handler = handler, conn = handler.socket, - write = handler.write, state = "request", + write = function (...) return handler:write(...); end, state = "request", server = http_servers[handler.serverport()], send = send_response, destroy = destroy_request, @@ -230,7 +230,7 @@ function destroy_request(request) end request.handler.close() if request.conn then - listener.disconnect(request.handler, "closed"); + listener.ondisconnect(request.handler, "closed"); end end end diff --git a/net/httpserver_listener.lua b/net/httpserver_listener.lua index 455191fb..5a261a43 100644 --- a/net/httpserver_listener.lua +++ b/net/httpserver_listener.lua @@ -16,7 +16,7 @@ local requests = {}; -- Open requests local httpserver = { default_port = 80, default_mode = "*a" }; -function httpserver.listener(conn, data) +function httpserver.onincoming(conn, data) local request = requests[conn]; if not request then @@ -34,7 +34,7 @@ function httpserver.listener(conn, data) end end -function httpserver.disconnect(conn, err) +function httpserver.ondisconnect(conn, err) local request = requests[conn]; if request and not request.destroyed then request.conn = nil; diff --git a/net/server.lua b/net/server.lua index 507bd81e..15bba603 100644 --- a/net/server.lua +++ b/net/server.lua @@ -9,7 +9,7 @@ if have_luaevent and use_luaevent == true then -- Backwards compatibility for timers, addtimer -- called a function roughly every second - local add_task = require "util.timer"; + local add_task = require "util.timer".add_task; function server.addtimer(f) return add_task(1, function (...) f(...); return 1; end); end diff --git a/net/server_event.lua b/net/server_event.lua index 375ab47e..b467a84d 100644 --- a/net/server_event.lua +++ b/net/server_event.lua @@ -52,6 +52,7 @@ local log = require ("util.logger").init("socket") local function debug(...)
return log("debug", ("%s "):rep(select('#', ...)), ...)
end
+local vdebug = debug;
local bitor = ( function( ) -- thx Rici Lake
local hasbit = function( x, p )
@@ -139,14 +140,14 @@ do self.fatalerror = "connection timeout"
self.listener.ontimeout( self ) -- call timeout listener
self:_close()
- debug( "new connection failed. id:", self, "error:", self.fatalerror )
+ debug( "new connection failed. id:", self.id, "error:", self.fatalerror )
else
if plainssl then -- start ssl session
self:_start_ssl( self.listener.onconnect )
else -- normal connection
self:_start_session( self.listener.onconnect )
end
- debug( "new connection established. id:", self )
+ debug( "new connection established. id:", self.id )
end
self.eventconnect = nil
return -1
@@ -158,28 +159,28 @@ do if self.type == "client" then
local callback = function( )
self:_lock( false, false, false )
- --vdebug( "start listening on client socket with id:", self )
+ --vdebug( "start listening on client socket with id:", self.id )
self.eventread = addevent( base, self.conn, EV_READ, self.readcallback, cfg.READ_TIMEOUT ) -- register callback
- onconnect( self )
+ self:onconnect()
self.eventsession = nil
return -1
end
self.eventsession = addevent( base, nil, EV_TIMEOUT, callback, 0 )
else
self:_lock( false )
- --vdebug( "start listening on server socket with id:", self )
+ --vdebug( "start listening on server socket with id:", self.id )
self.eventread = addevent( base, self.conn, EV_READ, self.readcallback ) -- register callback
end
return true
end
function interface_mt:_start_ssl(arg) -- old socket will be destroyed, therefore we have to close read/write events first
- --vdebug( "starting ssl session with client id:", self )
+ --vdebug( "starting ssl session with client id:", self.id )
local _
_ = self.eventread and self.eventread:close( ) -- close events; this must be called outside of the event callbacks!
_ = self.eventwrite and self.eventwrite:close( )
self.eventread, self.eventwrite = nil, nil
local err
- self.conn, err = ssl.wrap( self.conn, self.sslctx )
+ self.conn, err = ssl.wrap( self.conn, self._sslctx )
if err then
self.fatalerror = err
self.conn = nil -- cannot be used anymore
@@ -198,7 +199,7 @@ do local maxattempt = cfg.MAX_HANDSHAKE_ATTEMPS
while attempt < 1000 do -- no endless loop
attempt = attempt + 1
- debug( "ssl handshake of client with id:", self, "attemp:", attempt )
+ debug( "ssl handshake of client with id:"..tostring(self).."attemp:"..attempt )
if attempt > maxattempt then
self.fatalerror = "max handshake attemps exceeded"
elseif EV_TIMEOUT == event then
@@ -211,16 +212,16 @@ do self.receive = self.conn.receive
local onsomething
if "onconnect" == arg then -- trigger listener
- onsomething = self.listener.onconnect
+ onsomething = self.onconnect
else
- onsomething = self.listener.onsslconnection
+ onsomething = self.onsslconnection
end
self:_start_session( onsomething )
debug( "ssl handshake done" )
self.eventhandshake = nil
return -1
end
- debug( "error during ssl handshake:", err )
+ debug( "error during ssl handshake:", err )
if err == "wantwrite" then
event = EV_WRITE
elseif err == "wantread" then
@@ -248,7 +249,7 @@ do return true
end
function interface_mt:_destroy() -- close this interface + events and call last listener
- debug( "closing client with id:", self )
+ debug( "closing client with id:", self.id )
self:_lock( true, true, true ) -- first of all, lock the interface to avoid further actions
local _
_ = self.eventread and self.eventread:close( ) -- close events; this must be called outside of the event callbacks!
@@ -274,6 +275,7 @@ do interfacelist( "delete", self )
return true
end
+
function interface_mt:_lock(nointerface, noreading, nowriting) -- lock or unlock this interface or events
self.nointerface, self.noreading, self.nowriting = nointerface, noreading, nowriting
return nointerface, noreading, nowriting
@@ -288,7 +290,8 @@ do -- Public methods
function interface_mt:write(data)
- --vdebug( "try to send data to client, id/data:", self, data )
+ if self.nowriting then return nil, "locked" end
+ --vdebug( "try to send data to client, id/data:", self.id, data )
data = tostring( data )
local len = string_len( data )
local total = len + self.writebufferlen
@@ -306,7 +309,8 @@ do return true
end
function interface_mt:close(now)
- debug( "try to close client connection with id:", self )
+ if self.nointerface then return nil, "locked"; end
+ debug( "try to close client connection with id:", self.id )
if self.type == "client" then
self.fatalerror = "client to close"
if ( not self.eventwrite ) or now then -- try to close immediately
@@ -319,7 +323,7 @@ do return nil, "writebuffer not empty, waiting"
end
else
- debug( "try to close server with id:", self, "args:", now )
+ debug( "try to close server with id:", self.id, "args:", now )
self.fatalerror = "server to close"
self:_lock( true )
local count = 0
@@ -353,7 +357,7 @@ do end
function interface_mt:ssl()
- return self.usingssl
+ return self._usingssl
end
function interface_mt:type()
@@ -368,22 +372,25 @@ do return self.addr
end
-
+ function interface_mt:set_sslctx(sslctx)
+ self._sslctx = sslctx;
+ end
function interface_mt:starttls()
- debug( "try to start ssl at client id:", self )
+ debug( "try to start ssl at client id:", self.id )
local err
- if not self.sslctx then -- no ssl available
+ if not self._sslctx then -- no ssl available
err = "no ssl context available"
- elseif self.usingssl then -- startssl was already called
+ elseif self._usingssl then -- startssl was already called
err = "ssl already active"
end
if err then
debug( "error:", err )
return nil, err
end
- self.usingssl = true
+ self._usingssl = true
self.startsslcallback = function( ) -- we have to start the handshake outside of a read/write event
+ self.startsslcallback = nil
self:_start_ssl();
self.eventstarthandshake = nil
return -1
@@ -443,6 +450,7 @@ do _sslctx = sslctx; -- parameters
_usingssl = false; -- client is using ssl;
}
+ interface.id = tostring(interface):match("%x+$");
interface.writecallback = function( event ) -- called on write events
--vdebug( "new client write event, id/ip/port:", interface, ip, port )
if interface.nowriting or ( interface.fatalerror and ( "client to close" ~= interface.fatalerror ) ) then -- leave this event
@@ -457,7 +465,7 @@ do interface.eventwrite = false
return -1
else -- can write :)
- if interface.usingssl then -- handle luasec
+ if interface._usingssl then -- handle luasec
if interface.eventreadtimeout then -- we have to read first
local ret = interface.readcallback( ) -- call readcallback
--vdebug( "tried to read in writecallback, result:", ret )
@@ -467,7 +475,7 @@ do interface.eventwritetimeout = false
end
end
- local succ, err, byte = interface.send( interface.conn, interface.writebuffer, 1, interface.writebufferlen )
+ local succ, err, byte = interface.conn:send( interface.writebuffer, 1, interface.writebufferlen )
--vdebug( "write data:", interface.writebuffer, "error:", err, "part:", byte )
if succ then -- writing succesful
interface.writebuffer = ""
@@ -508,7 +516,7 @@ do end
end
end
- local usingssl, receive = interface._usingssl, interface.receive;
+
interface.readcallback = function( event ) -- called on read events
--vdebug( "new client read event, id/ip/port:", interface, ip, port )
if interface.noreading or interface.fatalerror then -- leave this event
@@ -523,7 +531,7 @@ do interface.eventread = nil
return -1
else -- can read
- if usingssl then -- handle luasec
+ if interface._usingssl then -- handle luasec
if interface.eventwritetimeout then -- ok, in the past writecallback was regged
local ret = interface.writecallback( ) -- call it
--vdebug( "tried to write in readcallback, result:", ret )
@@ -533,8 +541,8 @@ do interface.eventreadtimeout = nil
end
end
- local buffer, err, part = receive( client, pattern ) -- receive buffer with "pattern"
- --vdebug( "read data:", buffer, "error:", err, "part:", part )
+ local buffer, err, part = interface.conn:receive( pattern ) -- receive buffer with "pattern"
+ --vdebug( "read data:", tostring(buffer), "error:", tostring(err), "part:", tostring(part) )
buffer = buffer or part or ""
local len = string_len( buffer )
if len > cfg.MAX_READ_LENGTH then -- check buffer length
@@ -544,7 +552,7 @@ do interface.eventread = nil
return -1
end
- if err and ( "timeout" ~= err ) then
+ if err and ( err ~= "timeout" and err ~= "wantread" ) then
if "wantwrite" == err then -- need to read on write event
if not interface.eventwrite then -- register new write event if needed
interface.eventwrite = addevent( base, interface.conn, EV_WRITE, interface.writecallback, cfg.WRITE_TIMEOUT )
@@ -591,6 +599,7 @@ do fatalerror = false; -- error message
nointerface = true; -- lock/unlock parameter
}
+ interface.id = tostring(interface):match("%x+$");
interface.readcallback = function( event ) -- server handler, called on incoming connections
--vdebug( "server can accept, id/addr/port:", interface, addr, port )
if interface.fatalerror then
@@ -639,9 +648,9 @@ do end
local addserver = ( function( )
- return function( addr, port, listener, pattern, backlog, sslcfg, startssl ) -- TODO: check arguments
+ return function( addr, port, listener, pattern, sslcfg, startssl ) -- TODO: check arguments
--vdebug( "creating new tcp server with following parameters:", addr or "nil", port or "nil", sslcfg or "nil", startssl or "nil")
- local server, err = socket.bind( addr, port, backlog ) -- create server socket
+ local server, err = socket.bind( addr, port, cfg.ACCEPT_QUEUE ) -- create server socket
if not server then
debug( "creating server socket failed because:", err )
return nil, err
diff --git a/net/server_select.lua b/net/server_select.lua index 6ab8ce91..d7970296 100644 --- a/net/server_select.lua +++ b/net/server_select.lua @@ -166,7 +166,7 @@ wrapserver = function( listeners, socket, ip, serverport, pattern, sslctx, maxco local connections = 0
- local dispatch, disconnect = listeners.incoming or listeners.listener, listeners.disconnect
+ local dispatch, disconnect = listeners.onincoming, listeners.ondisconnect
local err
@@ -241,7 +241,7 @@ wrapserver = function( listeners, socket, ip, serverport, pattern, sslctx, maxco for _, handler in pairs( _socketlist ) do
if handler.serverport == serverport then
handler.disconnect( handler, "server closed" )
- handler.close( true )
+ handler:close( true )
end
end
socket:close( )
@@ -300,9 +300,9 @@ wrapconnection = function( server, listeners, socket, ip, serverport, clientport local ssl
- local dispatch = listeners.incoming or listeners.listener
+ local dispatch = listeners.onincoming
local status = listeners.status
- local disconnect = listeners.disconnect
+ local disconnect = listeners.ondisconnect
local bufferqueue = { } -- buffer array
local bufferqueuelen = 0 -- end of buffer array
@@ -331,9 +331,9 @@ wrapconnection = function( server, listeners, socket, ip, serverport, clientport handler.disconnect = function( )
return disconnect
end
- handler.setlistener = function( listeners )
- dispatch = listeners.incoming
- disconnect = listeners.disconnect
+ handler.setlistener = function( self, listeners )
+ dispatch = listeners.onincoming
+ disconnect = listeners.ondisconnect
end
handler.getstats = function( )
return readtraffic, sendtraffic
@@ -400,7 +400,7 @@ wrapconnection = function( server, listeners, socket, ip, serverport, clientport handler.clientport = function( )
return clientport
end
- local write = function( data )
+ local write = function( self, data )
bufferlen = bufferlen + string_len( data )
if bufferlen > maxsendlen then
_closelist[ handler ] = "send buffer exceeded" -- cannot close the client at the moment, have to wait to the end of the cycle
@@ -417,26 +417,26 @@ wrapconnection = function( server, listeners, socket, ip, serverport, clientport return true
end
handler.write = write
- handler.bufferqueue = function( )
+ handler.bufferqueue = function( self )
return bufferqueue
end
- handler.socket = function( )
+ handler.socket = function( self )
return socket
end
- handler.pattern = function( new )
+ handler.pattern = function( self, new )
pattern = new or pattern
return pattern
end
- handler.setsend = function ( newsend )
+ handler.setsend = function ( self, newsend )
send = newsend or send
return send
end
- handler.bufferlen = function( readlen, sendlen )
+ handler.bufferlen = function( self, readlen, sendlen )
maxsendlen = sendlen or maxsendlen
maxreadlen = readlen or maxreadlen
return maxreadlen, maxsendlen
end
- handler.lock = function( switch )
+ handler.lock = function( self, switch )
if switch == true then
handler.write = idfalse
local tmp = _sendlistlen
@@ -507,7 +507,7 @@ wrapconnection = function( server, listeners, socket, ip, serverport, clientport bufferqueuelen = 0
bufferlen = 0
_sendlistlen = removesocket( _sendlist, socket, _sendlistlen ) -- delete socket from writelist
- _ = needtls and handler.starttls(true)
+ _ = needtls and handler:starttls(true)
_writetimes[ handler ] = nil
_ = toclose and handler.close( )
return true
@@ -529,7 +529,7 @@ wrapconnection = function( server, listeners, socket, ip, serverport, clientport -- Set the sslctx
local handshake;
- function handler.set_sslctx(new_sslctx)
+ function handler.set_sslctx(self, new_sslctx)
ssl = true
sslctx = new_sslctx;
local wrote
@@ -564,13 +564,13 @@ wrapconnection = function( server, listeners, socket, ip, serverport, clientport end
end
disconnect( handler, "ssl handshake failed" )
- _ = handler and handler.close( true ) -- forced disconnect
+ _ = handler and handler:close( true ) -- forced disconnect
return false -- handshake failed
end
)
end
if sslctx then -- ssl?
- handler.set_sslctx(sslctx);
+ handler:set_sslctx(sslctx);
if startssl then -- ssl now?
--out_put("server.lua: ", "starting ssl handshake")
local err
@@ -590,7 +590,7 @@ wrapconnection = function( server, listeners, socket, ip, serverport, clientport else
-- We're not automatically doing SSL, so we're not secure (yet)
ssl = false
- handler.starttls = function( now )
+ handler.starttls = function( self, now )
if not now then
--out_put "server.lua: we need to do tls, but delaying until later"
needtls = true
@@ -692,7 +692,7 @@ end ----------------------------------// PUBLIC //--
-addserver = function( listeners, port, addr, pattern, sslctx, maxconnections, startssl ) -- this function provides a way for other scripts to reg a server
+addserver = function( addr, port, listeners, pattern, sslctx, startssl ) -- this function provides a way for other scripts to reg a server
local err
--out_put("server.lua: autossl on ", port, " is ", startssl)
if type( listeners ) ~= "table" then
@@ -715,7 +715,7 @@ addserver = function( listeners, port, addr, pattern, sslctx, maxconnections, st out_error( "server.lua, port ", port, ": ", err )
return nil, err
end
- local handler, err = wrapserver( listeners, server, addr, port, pattern, sslctx, maxconnections, startssl ) -- wrap new server socket
+ local handler, err = wrapserver( listeners, server, addr, port, pattern, sslctx, _maxclientsperserver, startssl ) -- wrap new server socket
if not handler then
server:close( )
return nil, err
@@ -737,14 +737,14 @@ removeserver = function( port ) if not handler then
return nil, "no server found on port '" .. tostring( port ) .. "'"
end
- handler.close( )
+ handler:close( )
_server[ port ] = nil
return true
end
closeall = function( )
for _, handler in pairs( _socketlist ) do
- handler.close( )
+ handler:close( )
_socketlist[ _ ] = nil
end
_readlistlen = 0
@@ -822,7 +822,7 @@ loop = function( ) -- this is the main loop of the program end
for handler, err in pairs( _closelist ) do
handler.disconnect( )( handler, err )
- handler.close( true ) -- forced disconnect
+ handler:close( true ) -- forced disconnect
end
clean( _closelist )
_currenttime = os_time( )
@@ -880,14 +880,14 @@ addtimer( function( ) if os_difftime( _currenttime - timestamp ) > _sendtimeout then
--_writetimes[ handler ] = nil
handler.disconnect( )( handler, "send timeout" )
- handler.close( true ) -- forced disconnect
+ handler:close( true ) -- forced disconnect
end
end
for handler, timestamp in pairs( _readtimes ) do
if os_difftime( _currenttime - timestamp ) > _readtimeout then
--_readtimes[ handler ] = nil
handler.disconnect( )( handler, "read timeout" )
- handler.close( ) -- forced disconnect?
+ handler:close( ) -- forced disconnect?
end
end
end
diff --git a/net/xmppclient_listener.lua b/net/xmppclient_listener.lua index 417dfd4a..fc0dce2c 100644 --- a/net/xmppclient_listener.lua +++ b/net/xmppclient_listener.lua @@ -100,15 +100,15 @@ local function session_close(session, reason) end end session.send("</stream:stream>"); - session.conn.close(); - xmppclient.disconnect(session.conn, (reason and (reason.text or reason.condition)) or reason or "session closed"); + session.conn:close(); + xmppclient.ondisconnect(session.conn, (reason and (reason.text or reason.condition)) or reason or "session closed"); end end -- End of session methods -- -function xmppclient.listener(conn, data) +function xmppclient.onincoming(conn, data) local session = sessions[conn]; if not session then session = sm_new_session(conn); @@ -117,7 +117,7 @@ function xmppclient.listener(conn, data) session.log("info", "Client connected"); -- Client is using legacy SSL (otherwise mod_tls sets this flag) - if conn.ssl() then + if conn:ssl() then session.secure = true; end @@ -133,7 +133,7 @@ function xmppclient.listener(conn, data) end end -function xmppclient.disconnect(conn, err) +function xmppclient.ondisconnect(conn, err) local session = sessions[conn]; if session then (session.log or log)("info", "Client disconnected: %s", err); diff --git a/net/xmppcomponent_listener.lua b/net/xmppcomponent_listener.lua index c16f41a0..b353b1b3 100644 --- a/net/xmppcomponent_listener.lua +++ b/net/xmppcomponent_listener.lua @@ -118,12 +118,12 @@ local function session_close(session, reason) end session.send("</stream:stream>"); session.conn.close(); - component_listener.disconnect(session.conn, "stream error"); + component_listener.ondisconnect(session.conn, "stream error"); end end --- Component connlistener -function component_listener.listener(conn, data) +function component_listener.onincoming(conn, data) local session = sessions[conn]; if not session then local _send = conn.write; @@ -157,7 +157,7 @@ function component_listener.listener(conn, data) end end -function component_listener.disconnect(conn, err) +function component_listener.ondisconnect(conn, err) local session = sessions[conn]; if session then (session.log or log)("info", "component disconnected: %s (%s)", tostring(session.host), tostring(err)); diff --git a/net/xmppserver_listener.lua b/net/xmppserver_listener.lua index c7e02ec5..797ef183 100644 --- a/net/xmppserver_listener.lua +++ b/net/xmppserver_listener.lua @@ -104,14 +104,14 @@ local function session_close(session, reason) session.conn.close(true); -- Force FIXME: timer? end session.conn.close(); - xmppserver.disconnect(session.conn, "stream error"); + xmppserver.ondisconnect(session.conn, "stream error"); end end -- End of session methods -- -function xmppserver.listener(conn, data) +function xmppserver.onincoming(conn, data) local session = sessions[conn]; if not session then session = s2s_new_incoming(conn); @@ -148,7 +148,7 @@ function xmppserver.status(conn, status) end end -function xmppserver.disconnect(conn, err) +function xmppserver.ondisconnect(conn, err) local session = sessions[conn]; if session then if err and err ~= "closed" and session.srv_hosts then diff --git a/plugins/mod_tls.lua b/plugins/mod_tls.lua index 8a450803..706b42c9 100644 --- a/plugins/mod_tls.lua +++ b/plugins/mod_tls.lua @@ -20,9 +20,9 @@ module:add_handler("c2s_unauthed", "starttls", xmlns_starttls, session.send(st.stanza("proceed", { xmlns = xmlns_starttls })); session:reset_stream(); if session.host and hosts[session.host].ssl_ctx_in then - session.conn.set_sslctx(hosts[session.host].ssl_ctx_in); + session.conn:set_sslctx(hosts[session.host].ssl_ctx_in); end - session.conn.starttls(); + session.conn:starttls(); session.log("info", "TLS negotiation started..."); session.secure = false; else @@ -37,9 +37,9 @@ module:add_handler("s2sin_unauthed", "starttls", xmlns_starttls, session.sends2s(st.stanza("proceed", { xmlns = xmlns_starttls })); session:reset_stream(); if session.to_host and hosts[session.to_host].ssl_ctx_in then - session.conn.set_sslctx(hosts[session.to_host].ssl_ctx_in); + session.conn:set_sslctx(hosts[session.to_host].ssl_ctx_in); end - session.conn.starttls(); + session.conn:starttls(); session.log("info", "TLS negotiation started for incoming s2s..."); session.secure = false; else @@ -91,7 +91,7 @@ module:hook_stanza(xmlns_starttls, "proceed", module:log("debug", "Proceeding with TLS on s2sout..."); local format, to_host, from_host = string.format, session.to_host, session.from_host; session:reset_stream(); - session.conn.starttls(true); + session.conn:starttls(true); session.secure = false; return true; end); |