apply Alexey patch for TLS error. Now buffer is 1M, so this workaround should prevent TLS crash

This commit is contained in:
Yann Leboulanger 2005-05-20 13:27:39 +00:00
parent 2377437112
commit b5ed8ee163
2 changed files with 11 additions and 46 deletions

View File

@ -109,10 +109,7 @@ class Dispatcher(PlugIn):
Returns:
1) length of processed data if some data were processed;
2) '0' string if no data were processed but link is alive;
3) 0 (zero) if underlying connection is closed.
Take note that in case of disconnection detect during Process() call
disconnect handlers are called automatically.
"""
3) 0 (zero) if underlying connection is closed."""
if (time.time() > self._lastIncome + 60) and not self._natSent: #1 min
iq = Iq('get', NS_LAST, to=self._owner.Server)
self.send(iq)
@ -121,13 +118,11 @@ class Dispatcher(PlugIn):
self._owner.disconnected()
for handler in self._cycleHandlers: handler(self)
if self._owner.Connection.pending_data(timeout):
try: data=self._owner.Connection.receive()
except IOError: return
data=self._owner.Connection.receive()
self.Stream.Parse(data)
if data:
self._lastIncome = time.time()
self._natSent = False
return len(data)
self._lastIncome = time.time()
self._natSent = False
return len(data)
return '0' # It means that nothing is received but link is alive.
def RegisterNamespace(self,xmlns,order='info'):

View File

@ -42,7 +42,6 @@ class error:
"""Serialise exception into pre-cached descriptive string."""
return self._comment
BUFLEN=1024
class TCPsocket(PlugIn):
""" This class defines direct TCP connection method. """
def __init__(self, server=None):
@ -90,30 +89,21 @@ class TCPsocket(PlugIn):
del self._owner.Connection
def receive(self):
""" Reads all pending incoming data.
In case of disconnection calls owner's disconnected() method and then raises IOError exception."""
try: received = self._recv(BUFLEN)
except socket.sslerror,e:
self._seen_data=0
if e[0]==2: return ''
self.DEBUG('Socket error while receiving data','error')
self._owner.disconnected()
raise IOError("Disconnected from server")
""" Reads all pending incoming data. Calls owner's disconnected() method if appropriate."""
try: received = self._recv(1024000)
except: received = ''
while self.pending_data(0):
try: add = self._recv(BUFLEN)
while select.select([self._sock],[],[],0)[0]:
try: add = self._recv(1024000)
except: add=''
received +=add
if not add: break
if len(received): # length of 0 means disconnect
self._seen_data=1
self.DEBUG(received,'got')
else:
self.DEBUG('Socket error while receiving data','error')
self._owner.disconnected()
raise IOError("Disconnected from server")
return received
def send(self,raw_data):
@ -178,23 +168,14 @@ class HTTPPROXYsocket(TCPsocket):
connector.append('Proxy-Authorization: Basic '+credentials)
connector.append('\r\n')
self.send('\r\n'.join(connector))
try: reply = self.receive().replace('\r','')
except IOError:
self.DEBUG('Proxy suddenly disconnected','error')
self._owner.disconnected()
return
reply = self.receive().replace('\r','')
try: proto,code,desc=reply.split('\n')[0].split(' ',2)
except: raise error('Invalid proxy reply')
if code<>'200':
self.DEBUG('Invalid proxy reply: %s %s %s'%(proto,code,desc),'error')
self._owner.disconnected()
return
while reply.find('\n\n') == -1:
try: reply += self.receive().replace('\r','')
except IOError:
self.DEBUG('Proxy suddenly disconnected','error')
self._owner.disconnected()
return
while reply.find('\n\n') == -1: reply += self.receive().replace('\r','')
self.DEBUG("Authentification successfull. Jabber server contacted.",'ok')
return 'ok'
@ -238,25 +219,14 @@ class TLS(PlugIn):
self._owner.Connection.send('<starttls xmlns="%s"/>'%NS_TLS)
raise NodeProcessed
def pending_data(self,timeout=0):
""" Returns true if there possible is a data ready to be read. """
return self._tcpsock._seen_data or select.select([self._tcpsock._sock],[],[],timeout)[0]
def _startSSL(self):
""" Immidiatedly switch socket to TLS mode. Used internally."""
""" Here we should switch pending_data to hint mode."""
tcpsock=self._owner.Connection
tcpsock._sslObj = socket.ssl(tcpsock._sock, None, None)
tcpsock._sslIssuer = tcpsock._sslObj.issuer()
tcpsock._sslServer = tcpsock._sslObj.server()
tcpsock._recv = tcpsock._sslObj.read
tcpsock._send = tcpsock._sslObj.write
tcpsock._seen_data=1
self._tcpsock=tcpsock
tcpsock.pending_data=self.pending_data
tcpsock._sock.setblocking(0)
self.starttls='success'
def StartTLSHandler(self, conn, starttls):