]> code.delx.au - pymsnt/blobdiff - src/tlib/msn/msn.py
Handle MSN error conditions
[pymsnt] / src / tlib / msn / msn.py
index 1ad7cfd9cd04ae06eff61f61a0be7817a3fe9792..fcab164707075d7226403463c5bf87c342695b07 100644 (file)
@@ -154,7 +154,7 @@ STATUS_LUNCH   = 'LUN'
 
 PINGSPEED = 50.0
 
-DEBUGALL = False
+DEBUGALL = True
 LINEDEBUG = False
 MESSAGEDEBUG = False
 MSNP2PDEBUG = False
@@ -346,7 +346,7 @@ class PassportLogin(HTTPClient):
     def connectionMade(self):
         self.sendCommand('GET', self.path)
         self.sendHeader('Authorization', 'Passport1.4 OrgVerb=GET,OrgURL=http://messenger.msn.com,' +
-                                         'sign-in=%s,pwd=%s,%s' % (quote(self.userHandle), self.passwd,self.authData))
+                                         'sign-in=%s,pwd=%s,%s' % (quote(self.userHandle), quote(self.passwd), self.authData))
         self.sendHeader('Host', self.host)
         self.endHeaders()
         self.headers = {}
@@ -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
@@ -2029,7 +2033,7 @@ class NotificationFactory(ReconnectingClientFactory):
     screenName = ''
     password = ''
     passportServer = 'https://nexus.passport.com/rdr/pprdr.asp'
-    status = 'FLN'
+    status = 'NLN'
     protocol = NotificationClient
     maxRetries = 5
 
@@ -2177,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
@@ -3062,6 +3066,7 @@ errorCodes = {
     301 : "Too many FND responses",
     302 : "Not logged in",
 
+    400 : "Message not allowed",
     402 : "Error accessing contact list",
     403 : "Error accessing contact list",