diff options
author | Tobias Markmann <tm@ayena.de> | 2009-03-03 17:48:04 +0100 |
---|---|---|
committer | Tobias Markmann <tm@ayena.de> | 2009-03-03 17:48:04 +0100 |
commit | 7a7a89844a038b071f02fd1af309ba9ebbcda7de (patch) | |
tree | 73946c977be10a965d59de85b3ce6ba3743bc771 /net | |
parent | 3d1e7adbbc0afb8395f02ecd42fe3c38ce6a8d36 (diff) | |
parent | b6b9906c3c653935b55ad79ad4a2c41118f0a0e3 (diff) | |
download | prosody-7a7a89844a038b071f02fd1af309ba9ebbcda7de.tar.gz prosody-7a7a89844a038b071f02fd1af309ba9ebbcda7de.zip |
Merged with main tip.
Diffstat (limited to 'net')
-rw-r--r-- | net/server.lua | 29 | ||||
-rw-r--r-- | net/xmppclient_listener.lua | 5 |
2 files changed, 23 insertions, 11 deletions
diff --git a/net/server.lua b/net/server.lua index a5c8e24c..8d0d3b1a 100644 --- a/net/server.lua +++ b/net/server.lua @@ -369,7 +369,9 @@ wrapconnection = function( server, listeners, socket, ip, serverport, clientport end
bufferqueuelen = bufferqueuelen + 1
bufferqueue[ bufferqueuelen ] = data
- _writetimes[ handler ] = _writetimes[ handler ] or _currenttime
+ if handler then
+ _writetimes[ handler ] = _writetimes[ handler ] or _currenttime
+ end
return true
end
handler.write = write
@@ -436,7 +438,7 @@ wrapconnection = function( server, listeners, socket, ip, serverport, clientport --out_put( "server.lua: read data '", buffer, "', error: ", err )
return dispatch( handler, buffer, err )
else -- connections was closed or fatal error
- out_put( "server.lua: client ", ip, ":", clientport, " error: ", err )
+ out_put( "server.lua: client ", ip, ":", tostring(clientport), " error: ", tostring(err) )
fatalerror = true
disconnect( handler, err )
_ = handler and handler.close( )
@@ -470,7 +472,7 @@ wrapconnection = function( server, listeners, socket, ip, serverport, clientport out_put( "server.lua: client ", ip, ":", clientport, " error: ", err )
fatalerror = true
disconnect( handler, err )
- handler.close( )
+ _ = handler and handler.close( )
return false
end
end
@@ -478,16 +480,19 @@ wrapconnection = function( server, listeners, socket, ip, serverport, clientport if sslctx then -- ssl?
ssl = true
local wrote
+ local read
local handshake = coroutine_wrap( function( client ) -- create handshake coroutine
local err
for i = 1, 10 do -- 10 handshake attemps
+ _sendlistlen = ( wrote and removesocket( _sendlist, socket, _sendlistlen ) ) or _sendlistlen
+ _readlistlen = ( read and removesocket( _readlist, socket, _readlistlen ) ) or _readlistlen
+ read, wrote = nil, nil
_, err = client:dohandshake( )
if not err then
- --out_put( "server.lua: ssl handshake done" )
- _sendlistlen = ( wrote and removesocket( _sendlist, socket, _sendlistlen ) ) or _sendlistlen
+ out_put( "server.lua: ssl handshake done" )
handler.readbuffer = _readbuffer -- when handshake is done, replace the handshake function with regular functions
handler.sendbuffer = _sendbuffer
- --return dispatch( handler )
+ -- return dispatch( handler )
return true
else
out_put( "server.lua: error during ssl handshake: ", err )
@@ -495,12 +500,18 @@ wrapconnection = function( server, listeners, socket, ip, serverport, clientport _sendlistlen = _sendlistlen + 1
_sendlist[ _sendlistlen ] = client
wrote = true
+ elseif err == "wantread" and not read then
+ _readlistlen = _readlistlen + 1
+ _readlist [ _readlistlen ] = client
+ read = true
+ else
+ break;
end
--coroutine_yield( handler, nil, err ) -- handshake not finished
coroutine_yield( )
end
end
- disconnect( handler, "max handshake attemps exceeded" )
+ disconnect( handler, "ssl handshake failed" )
handler.close( true ) -- forced disconnect
return false -- handshake failed
end
@@ -556,8 +567,8 @@ wrapconnection = function( server, listeners, socket, ip, serverport, clientport handler.starttls = nil
needtls = nil
- handler.receivedata = handler.handshake
- handler.dispatchdata = handler.handshake
+ handler.readbuffer = handshake
+ handler.sendbuffer = handshake
handshake( socket ) -- do handshake
end
handler.readbuffer = _readbuffer
diff --git a/net/xmppclient_listener.lua b/net/xmppclient_listener.lua index ad1fd948..e7a87c1e 100644 --- a/net/xmppclient_listener.lua +++ b/net/xmppclient_listener.lua @@ -29,9 +29,10 @@ local stream_callbacks = { stream_tag = "http://etherx.jabber.org/streams|stream function stream_callbacks.error(session, error, data) if error == "no-stream" then + session.log("debug", "Invalid opening stream header"); session:close("invalid-namespace"); - else - session.log("debug", "Client XML parse error: %s", tostring(error)); + elseif session.close then + (session.log or log)("debug", "Client XML parse error: %s", tostring(error)); session:close("xml-not-well-formed"); end end |