X-Git-Url: https://code.delx.au/pymsnt/blobdiff_plain/0d1ee2592602e2580e1870a834f1e185d86ec58f..96463e0e6d5899acaf739004207a78ade1efa922:/src/tlib/msn/msn.py diff --git a/src/tlib/msn/msn.py b/src/tlib/msn/msn.py index bcc9aaa..1993086 100644 --- a/src/tlib/msn/msn.py +++ b/src/tlib/msn/msn.py @@ -99,7 +99,7 @@ import msnp11chl # Twisted imports from twisted.internet import reactor, task from twisted.internet.defer import Deferred -from twisted.internet.protocol import ClientFactory +from twisted.internet.protocol import ReconnectingClientFactory, ClientFactory try: from twisted.internet.ssl import ClientContextFactory except ImportError: @@ -786,11 +786,12 @@ class MSNEventBase(LineReceiver): raise NotImplementedError def sendLine(self, line): - if LINEDEBUG: log.msg(">> " + line) + if LINEDEBUG: log.msg("<< " + line) LineReceiver.sendLine(self, line) def lineReceived(self, line): - if LINEDEBUG: log.msg("<< " + line) + if LINEDEBUG: log.msg(">> " + line) + if not self.connected: return if self.currentMessage: self.currentMessage.readPos += len(line+"\r\n") try: @@ -811,8 +812,10 @@ class MSNEventBase(LineReceiver): if len(cmd) != 3: raise MSNProtocolError, "Invalid Command, %s" % repr(cmd) if cmd.isdigit(): - if self.ids.has_key(params.split(' ')[0]): - self.ids[id].errback(int(cmd)) + id = params.split(' ')[0] + if id.isdigit() and self.ids.has_key(int(id)): + id = int(id) + self.ids[id][0].errback(int(cmd)) del self.ids[id] return else: # we received an error which doesn't map to a sent command @@ -827,6 +830,7 @@ class MSNEventBase(LineReceiver): self.handle_UNKNOWN(cmd, params.split(' ')) def rawDataReceived(self, data): + if not self.connected: return extra = "" self.currentMessage.readPos += len(data) diff = self.currentMessage.readPos - self.currentMessage.length @@ -973,6 +977,7 @@ class NotificationClient(MSNEventBase): MSNEventBase.connectionMade(self) self._setState('CONNECTED') self.sendLine("VER %s %s" % (self._nextTransactionID(), MSN_PROTOCOL_VERSION)) + self.factory.resetDelay() def connectionLost(self, reason): self._setState('DISCONNECTED') @@ -1386,6 +1391,7 @@ class NotificationClient(MSNEventBase): def handle_OUT(self, params): checkParamLen(len(params), 1, 'OUT') + self.factory.stopTrying() if params[0] == "OTH": self.multipleLogin() elif params[0] == "SSD": self.serverGoingDown() else: raise MSNProtocolError, "Invalid Parameters received for OUT" # debug @@ -1991,10 +1997,11 @@ class NotificationClient(MSNEventBase): if self.pingCheckTask: self.pingCheckTask.stop() self.pingCheckTask = None + self.factory.stopTrying() self.sendLine("OUT") self.transport.loseConnection() -class NotificationFactory(ClientFactory): +class NotificationFactory(ReconnectingClientFactory): """ Factory for the NotificationClient protocol. This is basically responsible for keeping @@ -2017,6 +2024,8 @@ class NotificationFactory(ClientFactory): (the whole URL is required) @ivar status: The status of the client -- this is generally kept up to date by the default command handlers + @ivar maxRetries: The number of times the factory will reconnect + if the connection dies because of a network error. """ contacts = None @@ -2026,6 +2035,7 @@ class NotificationFactory(ClientFactory): passportServer = 'https://nexus.passport.com/rdr/pprdr.asp' status = 'FLN' protocol = NotificationClient + maxRetries = 5 class SwitchboardClient(MSNEventBase): @@ -2171,15 +2181,15 @@ class SwitchboardClient(MSNEventBase): """ cTypes = [s.lstrip() for s in message.getHeader('Content-Type').split(';')] if self._checkTyping(message, cTypes): return 0 - if 'text/x-msmsgsinvite' in cTypes: +# if 'text/x-msmsgsinvite' in cTypes: # header like info is sent as part of the message body. - info = {} - for line in message.message.split('\r\n'): - try: - key, val = line.split(':') - info[key] = val.lstrip() - except ValueError: continue - if self._checkFileInvitation(message, info): return 0 +# info = {} +# for line in message.message.split('\r\n'): +# try: +# key, val = line.split(':') +# info[key] = val.lstrip() +# except ValueError: continue +# if self._checkFileInvitation(message, info): return 0 elif 'application/x-msnmsgrp2p' in cTypes: self._handleP2PMessage(message) return 0 @@ -2367,6 +2377,7 @@ class SwitchboardClient(MSNEventBase): def bufferClosed(data): d.callback((data,)) buffer = StringBuffer(bufferClosed) + buffer.error = lambda: None slpLink = SLPLink_AvatarReceive(remoteUser=msnContact.userHandle, switchboard=self, consumer=buffer, context=msnContact.msnobj.text) self.slpLinks[slpLink.sessionID] = slpLink return d @@ -3013,10 +3024,12 @@ class SLPLink_AvatarReceive(SLPLink_Receive): "AppID" : 1,\ "Context" : context} self.sendSLPMessage("INVITE", "application/x-msnmsgr-sessionreqbody", data) + self.handlePacket = self.wait_dataprep def handleSLPMessage(self, slpMessage): if slpMessage.status == "200": - self.handlePacket = self.wait_dataprep + pass + #self.handlePacket = self.wait_dataprep # Moved upwards else: if MSNP2PDEBUG: log.msg("SLPLink is over due to error or BYE") self.killLink()