close connection when invalid xml is received

call sys.exc_clear in catched exceptions
This commit is contained in:
Dimitur Kirov 2006-03-10 20:36:15 +00:00
parent adb62eb628
commit 59283050e1
2 changed files with 16 additions and 5 deletions

View File

@ -24,6 +24,7 @@ Dispatcher.SendAndWaitForResponce method will wait for reply stanza before givin
''' '''
import simplexml, sys import simplexml, sys
from xml.parsers.expat import ExpatError
from protocol import * from protocol import *
from client import PlugIn from client import PlugIn
@ -123,7 +124,12 @@ class Dispatcher(PlugIn):
if len(self._pendingExceptions) > 0: if len(self._pendingExceptions) > 0:
_pendingException = self._pendingExceptions.pop() _pendingException = self._pendingExceptions.pop()
raise _pendingException[0], _pendingException[1], _pendingException[2] raise _pendingException[0], _pendingException[1], _pendingException[2]
self.Stream.Parse(data) try:
self.Stream.Parse(data)
except ExpatError:
sys.exc_clear()
self._owner.Connection.disconnect()
return 0
if len(self._pendingExceptions) > 0: if len(self._pendingExceptions) > 0:
_pendingException = self._pendingExceptions.pop() _pendingException = self._pendingExceptions.pop()
raise _pendingException[0], _pendingException[1], _pendingException[2] raise _pendingException[0], _pendingException[1], _pendingException[2]

View File

@ -108,7 +108,8 @@ class NonBlockingTcp(PlugIn, IdleObject):
try: try:
self._sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) self._sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
self._sock.setblocking(False) self._sock.setblocking(False)
except: except:
sys.exc_clear()
if self.on_connect_failure: if self.on_connect_failure:
self.on_connect_failure() self.on_connect_failure()
return False return False
@ -160,7 +161,7 @@ class NonBlockingTcp(PlugIn, IdleObject):
self._sock.close() self._sock.close()
except: except:
# socket is already closed # socket is already closed
pass sys.exc_clear()
# socket descriptor cannot be (un)plugged anymore # socket descriptor cannot be (un)plugged anymore
self.fd = -1 self.fd = -1
if self.on_disconnect: if self.on_disconnect:
@ -263,7 +264,8 @@ class NonBlockingTcp(PlugIn, IdleObject):
# we are not waiting for write # we are not waiting for write
self._plug_idle() self._plug_idle()
self._on_send() self._on_send()
except Exception, e: except Exception:
sys.exc_clear()
if self.state < 0: if self.state < 0:
self.disconnect() self.disconnect()
return return
@ -281,6 +283,7 @@ class NonBlockingTcp(PlugIn, IdleObject):
self._sock.connect(self._server) self._sock.connect(self._server)
except socket.error, e: except socket.error, e:
errnum = e[0] errnum = e[0]
sys.exc_clear()
# in progress, or would block # in progress, or would block
if errnum in (errno.EINPROGRESS, errno.EALREADY, errno.EWOULDBLOCK): if errnum in (errno.EINPROGRESS, errno.EALREADY, errno.EWOULDBLOCK):
return return
@ -378,7 +381,9 @@ class NonBlockingTLS(PlugIn):
def plugout(self,now=0): def plugout(self,now=0):
''' Unregisters TLS handler's from owner's dispatcher. Take note that encription ''' Unregisters TLS handler's from owner's dispatcher. Take note that encription
can not be stopped once started. You can only break the connection and start over.''' can not be stopped once started. You can only break the connection and start over.'''
self._owner.UnregisterHandler('features',self.FeaturesHandler,xmlns=NS_STREAMS) # if dispatcher is not plugged we cannot (un)register handlers
if self._owner.__dict__.has_key('Dispatcher'):
self._owner.UnregisterHandler('features', self.FeaturesHandler,xmlns=NS_STREAMS)
def tls_start(self): def tls_start(self):
if self.on_tls_start: if self.on_tls_start: