]> code.delx.au - pymsnt/commitdiff
Fixed failedMessage exception.
authorjamesbunton <jamesbunton@55fbd22a-6204-0410-b2f0-b6c764c7e90a>
Tue, 14 Mar 2006 00:23:30 +0000 (00:23 +0000)
committerjamesbunton <jamesbunton@55fbd22a-6204-0410-b2f0-b6c764c7e90a>
Tue, 14 Mar 2006 00:23:30 +0000 (00:23 +0000)
config.jid now responds to presence probes.
config.mailNotifications is now used again.
Fixed self.session.jabberID exceptions in glue.py (sometimes session had been killed)

git-svn-id: http://delx.cjb.net/svn/pymsnt/trunk@124 55fbd22a-6204-0410-b2f0-b6c764c7e90a

committer: jamesbunton <jamesbunton@55fbd22a-6204-0410-b2f0-b6c764c7e90a>

src/baseproto/glue.py
src/legacy/glue.py
src/main.py
src/session.py
src/tlib/msn/msnw.py

index de18e32f1b78886ace5c229f0c17e950af3f84dc..5dd6489f9f49b1067dfb492f202cf81327efd990 100644 (file)
@@ -138,6 +138,11 @@ class LegacyConnection:
                self.session = None
                self.legacyList = None
        
+       def sendShowStatus(self, jid):
+               """ Called when the transport needs to report its current presence to jid.
+               Send the status of the user on the legacy network to the given jid. """
+               pass
+       
        def resourceOffline(self, resource):
                """ Called whenever one of the local user's resources goes offline """
                pass
index 5a3935b8f811ab283e9af60787e17396919cee4a..4c84a12209408eaa4f6446d6f54ae2ef4f8c4823 100644 (file)
@@ -19,7 +19,7 @@ import lang
 
 name = "MSN Transport"   # The name of the transport
 url = "http://msn-transport.jabberstudio.org"
-version = "0.11"         # The transport version
+version = "0.11-dev"         # The transport version
 mangle = True            # XDB '@' -> '%' mangling
 id = "msn"               # The transport identifier
 
@@ -231,7 +231,7 @@ class LegacyConnection(msn.MSNConnection):
                self.remoteNick = ""
 
                # Init the MSN bits
-               msn.MSNConnection.__init__(self, username, password, self.session.jabberID)
+               msn.MSNConnection.__init__(self, username, password, self.jabberID)
 
                # User typing notification stuff
                self.userTyping = dict() # Indexed by contact MSN ID, stores whether the user is typing to this contact
@@ -243,10 +243,10 @@ class LegacyConnection(msn.MSNConnection):
                
                self.legacyList = LegacyList(self.session)
        
-               LogEvent(INFO, self.session.jabberID)
+               LogEvent(INFO, self.jabberID)
        
        def removeMe(self):
-               LogEvent(INFO, self.session.jabberID)
+               LogEvent(INFO, self.jabberID)
        
                self.userTypingSend.stop()
        
@@ -255,15 +255,15 @@ class LegacyConnection(msn.MSNConnection):
                self.session = None
                self.logOut()
        
-       def _sendShowStatus(self):
+
+       # Implemented from baseproto
+       def sendShowStatus(self, jid=None):
                if not self.session: return
                source = config.jid
-               to = self.session.jabberID
-               self.session.sendPresence(to=to, fro=source, show=self.remoteShow, status=self.remoteStatus, nickname=self.remoteNick)
-       
+               if not jid:
+                       jid = self.jabberID
+               self.session.sendPresence(to=jid, fro=source, show=self.remoteShow, status=self.remoteStatus, nickname=self.remoteNick)
        
-
-       # Implemented from baseproto
        def resourceOffline(self, resource):
                pass
 
@@ -322,7 +322,7 @@ class LegacyConnection(msn.MSNConnection):
                for contact in self.contactTyping.keys():
                        self.contactTyping[contact] += 1
                        if self.contactTyping[contact] >= 3:
-                               self.session.sendTypingNotification(self.session.jabberID, msn2jid(contact, True), False)
+                               self.session.sendTypingNotification(self.jabberID, msn2jid(contact, True), False)
                                del self.contactTyping[contact]
        
        def userTypingNotification(self, dest, resource, composing):
@@ -336,89 +336,89 @@ class LegacyConnection(msn.MSNConnection):
 
        # Implement callbacks from msn.MSNConnection
        def connectionFailed(self, reason):
-               LogEvent(INFO, self.session.jabberID)
+               LogEvent(INFO, self.jabberID)
                text = lang.get(self.session.lang).msnConnectFailed % reason
-               self.session.sendMessage(to=self.session.jabberID, fro=config.jid, body=text)
+               self.session.sendMessage(to=self.jabberID, fro=config.jid, body=text)
                self.session.removeMe()
 
        def loginFailed(self, reason):
-               LogEvent(INFO, self.session.jabberID)
+               LogEvent(INFO, self.jabberID)
                text = lang.get(self.session.lang).msnLoginFailure % (self.session.username)
-               self.session.sendErrorMessage(to=self.session.jabberID, fro=config.jid, etype="auth", condition="not-authorized", explanation=text, body="Login Failure")
+               self.session.sendErrorMessage(to=self.jabberID, fro=config.jid, etype="auth", condition="not-authorized", explanation=text, body="Login Failure")
                self.session.removeMe()
        
        def connectionLost(self, reason):
-               LogEvent(INFO, self.session.jabberID)
+               LogEvent(INFO, self.jabberID)
                text = lang.get(self.session.lang).msnDisconnected % reason
-               self.session.sendMessage(to=self.session.jabberID, fro=config.jid, body=text)
+               self.session.sendMessage(to=self.jabberID, fro=config.jid, body=text)
                self.session.removeMe() # Tear down the session
 
        def multipleLogin(self):
-               LogEvent(INFO, self.session.jabberID)
-               self.session.sendMessage(to=self.session.jabberID, fro=config.jid, body=lang.get(self.session.lang).msnMultipleLogin)
+               LogEvent(INFO, self.jabberID)
+               self.session.sendMessage(to=self.jabberID, fro=config.jid, body=lang.get(self.session.lang).msnMultipleLogin)
                self.session.removeMe()
        
        def serverGoingDown(self):
-               LogEvent(INFO, self.session.jabberID)
-               self.session.sendMessage(to=self.session.jabberID, fro=config.jid, body=lang.get(self.session.lang).msnMaintenance)
+               LogEvent(INFO, self.jabberID)
+               self.session.sendMessage(to=self.jabberID, fro=config.jid, body=lang.get(self.session.lang).msnMaintenance)
        
        def accountNotVerified(self):
-               LogEvent(INFO, self.session.jabberID)
+               LogEvent(INFO, self.jabberID)
                text = lang.get(self.session.lang).msnNotVerified % (self.session.username)
-               self.session.sendMessage(to=self.session.jabberID, fro=config.jid, body=text)
+               self.session.sendMessage(to=self.jabberID, fro=config.jid, body=text)
        
        def userMapping(self, passport, jid):
-               LogEvent(INFO, self.session.jabberID)
+               LogEvent(INFO, self.jabberID)
                text = lang.get(self.session.lang).userMapping % (passport, jid)
-               self.session.sendMessage(to=self.session.jabberID, fro=msn2jid(passport, True), body=text)
+               self.session.sendMessage(to=self.jabberID, fro=msn2jid(passport, True), body=text)
        
        def loggedIn(self):
-               LogEvent(INFO, self.session.jabberID)
+               LogEvent(INFO, self.jabberID)
                self.session.ready = True
        
        def listSynchronized(self):
-               LogEvent(INFO, self.session.jabberID)
-               self.session.sendPresence(to=self.session.jabberID, fro=config.jid)
+               LogEvent(INFO, self.jabberID)
+               self.session.sendPresence(to=self.jabberID, fro=config.jid)
                self.legacyList.syncJabberLegacyLists()
                self.listSynced = True
                #self.legacyList.flushSubscriptionBuffer()
        
        def ourStatusChanged(self, statusCode, screenName, personal):
                # Send out a new presence packet to the Jabber user so that the transport icon changes
-               LogEvent(INFO, self.session.jabberID)
+               LogEvent(INFO, self.jabberID)
                self.remoteShow, ptype = state2presence(statusCode)
                self.remoteStatus = personal
                self.remoteNick = screenName
-               self._sendShowStatus()
+               self.sendShowStatus()
 
        def gotMessage(self, remoteUser, text):
-               LogEvent(INFO, self.session.jabberID)
+               LogEvent(INFO, self.jabberID)
                source = msn2jid(remoteUser, True)
-               self.session.sendMessage(self.session.jabberID, fro=source, body=text, mtype="chat")
+               self.session.sendMessage(self.jabberID, fro=source, body=text, mtype="chat")
                self.session.pytrans.statistics.stats["MessageCount"] += 1
        
        def gotGroupchat(self, msnGroupchat, userHandle):
-               LogEvent(INFO, self.session.jabberID)
+               LogEvent(INFO, self.jabberID)
                msnGroupchat.groupchat = LegacyGroupchat(self.session, switchboardSession=msnGroupchat)
                msnGroupchat.groupchat.sendUserInvite(msn2jid(userHandle, True))
        
        def gotContactTyping(self, contact):
-               LogEvent(INFO, self.session.jabberID)
+               LogEvent(INFO, self.jabberID)
                # Check if the contact has only just started typing
                if not self.contactTyping.has_key(contact):
-                       self.session.sendTypingNotification(self.session.jabberID, msn2jid(contact, True), True)
+                       self.session.sendTypingNotification(self.jabberID, msn2jid(contact, True), True)
 
                # Reset the counter
                self.contactTyping[contact] = 0
        
        def failedMessage(self, remoteUser, message):
-               LogEvent(INFO, self.session.jabberID)
+               LogEvent(INFO, self.jabberID)
                self.session.pytrans.statistics.stats["FailedMessageCount"] += 1
                fro = msn2jid(remoteUser, True)
-               self.session.sendErrorMessage(to=self.session.jabberID, fro=fro, etype="wait", condition="recipient-unavailable", explanation=lang.get(self.session.lang).msnFailedMessage, body=message)
+               self.session.sendErrorMessage(to=self.jabberID, fro=fro, etype="wait", condition="recipient-unavailable", explanation=lang.get(self.session.lang).msnFailedMessage, body=message)
        
        def contactAvatarChanged(self, userHandle, hash):
-               LogEvent(INFO, self.session.jabberID)
+               LogEvent(INFO, self.jabberID)
                jid = msn2jid(userHandle, False)
                c = self.session.contactList.findContact(jid)
                if not c: return
@@ -443,7 +443,7 @@ class LegacyConnection(msn.MSNConnection):
                        c.updateAvatar(defaultAvatar)
        
        def contactStatusChanged(self, remoteUser):
-               LogEvent(INFO, self.session.jabberID)
+               LogEvent(INFO, self.jabberID)
                
                msnContact = self.getContacts().getContact(remoteUser)
                c = self.session.contactList.findContact(msn2jid(remoteUser, False))
@@ -457,35 +457,37 @@ class LegacyConnection(msn.MSNConnection):
                c.updatePresence(show, status, ptype, force=True)
        
        def gotFileReceive(self, fileReceive):
-               LogEvent(INFO, self.session.jabberID)
+               LogEvent(INFO, self.jabberID)
                # FIXME
                ft.FTReceive(self.session, msn2jid(fileReceive.userHandle, True), fileReceive)
        
        def contactAddedMe(self, userHandle):
-               LogEvent(INFO, self.session.jabberID)
+               LogEvent(INFO, self.jabberID)
                self.session.contactList.getContact(msn2jid(userHandle, False)).contactRequestsAuth()
        
        def contactRemovedMe(self, userHandle):
-               LogEvent(INFO, self.session.jabberID)
+               LogEvent(INFO, self.jabberID)
                c = self.session.contactList.getContact(msn2jid(userHandle, True))
                c.contactDerequestsAuth()
                c.contactRemovesAuth()
        
        def gotInitialEmailNotification(self, inboxunread, foldersunread):
-               LogEvent(INFO, self.session.jabberID)
-               text = lang.get(self.session.lang).msnInitialMail % (inboxunread, foldersunread)
-               self.session.sendMessage(to=self.session.jabberID, fro=config.jid, body=text, mtype="headline")
+               if config.mailNotifications:
+                       LogEvent(INFO, self.jabberID)
+                       text = lang.get(self.session.lang).msnInitialMail % (inboxunread, foldersunread)
+                       self.session.sendMessage(to=self.jabberID, fro=config.jid, body=text, mtype="headline")
        
        def gotRealtimeEmailNotification(self, mailfrom, fromaddr, subject):
-               LogEvent(INFO, self.session.jabberID)
-               text = lang.get(self.session.lang).msnRealtimeMail % (mailfrom, fromaddr, subject)
-               self.session.sendMessage(to=self.session.jabberID, fro=config.jid, body=text, mtype="headline")
+               if config.mailNotifications:
+                       LogEvent(INFO, self.jabberID)
+                       text = lang.get(self.session.lang).msnRealtimeMail % (mailfrom, fromaddr, subject)
+                       self.session.sendMessage(to=self.jabberID, fro=config.jid, body=text, mtype="headline")
                
        def gotMSNAlert(self, text, actionurl, subscrurl):
-               LogEvent(INFO, self.session.jabberID)
+               LogEvent(INFO, self.jabberID)
 
                el = Element((None, "message"))
-               el.attributes["to"] = self.session.jabberID
+               el.attributes["to"] = self.jabberID
                el.attributes["from"] = config.jid
                el.attributes["type"] = "headline"
                body = el.addElement("body")
@@ -504,7 +506,7 @@ class LegacyConnection(msn.MSNConnection):
                self.session.pytrans.send(el)
        
        def gotAvatarImageData(self, userHandle, imageData):
-               LogEvent(INFO, self.session.jabberID)
+               LogEvent(INFO, self.jabberID)
                av = self.session.pytrans.avatarCache.setAvatar(imageData)
                jid = msn2jid(userHandle, False)
                c = self.session.contactList.findContact(jid)
@@ -515,6 +517,7 @@ class LegacyConnection(msn.MSNConnection):
 
 class LegacyList:
        def __init__(self, session):
+               self.jabberID = session.jabberID
                self.session = session
                self.subscriptionBuffer = []
        
@@ -523,19 +526,19 @@ class LegacyList:
                self.session = None
 
        def addContact(self, jid):
-               LogEvent(INFO, self.session.jabberID)
+               LogEvent(INFO, self.jabberID)
                userHandle = jid2msn(jid)
                self.session.legacycon.addContact(msn.FORWARD_LIST, userHandle)
                self.session.contactList.getContact(jid).contactGrantsAuth()
        
        def removeContact(self, jid):
-               LogEvent(INFO, self.session.jabberID)
+               LogEvent(INFO, self.jabberID)
                jid = jid2msn(jid)
                self.session.legacycon.remContact(msn.FORWARD_LIST, jid)
        
        
        def authContact(self, jid):
-               LogEvent(INFO, self.session.jabberID)
+               LogEvent(INFO, self.jabberID)
                jid = jid2msn(jid)
                d = self.session.legacycon.remContact(msn.PENDING_LIST, jid)
                if d:
@@ -544,7 +547,7 @@ class LegacyList:
                self.session.legacycon.addContact(msn.ALLOW_LIST, jid)
        
        def deauthContact(self, jid):
-               LogEvent(INFO, self.session.jabberID)
+               LogEvent(INFO, self.jabberID)
                jid = jid2msn(jid)
                self.session.legacycon.remContact(msn.ALLOW_LIST, jid)
                self.session.legacycon.addContact(msn.BLOCK_LIST, jid)
@@ -558,8 +561,8 @@ class LegacyList:
 
                # We have to make an MSNContactList from the XDB data, then compare it with the one the server sent
                # Any subscription changes must be sent to the client, as well as changed in the XDB
-               LogEvent(INFO, self.session.jabberID, "Start.")
-               result = self.session.pytrans.xdb.request(self.session.jabberID, disco.IQROSTER)
+               LogEvent(INFO, self.jabberID, "Start.")
+               result = self.session.pytrans.xdb.request(self.jabberID, disco.IQROSTER)
                oldContactList = msn.MSNContactList()
                if result:
                        for item in result.elements():
@@ -626,8 +629,8 @@ class LegacyList:
                        item.attributes["lists"] = str(lists)
                
                # Update the XDB
-               self.session.pytrans.xdb.set(self.session.jabberID, disco.IQROSTER, newXDB)
-               LogEvent(INFO, self.session.jabberID, "End.")
+               self.session.pytrans.xdb.set(self.jabberID, disco.IQROSTER, newXDB)
+               LogEvent(INFO, self.jabberID, "End.")
        
        def saveLegacyList(self):
                contactList = self.session.legacycon.getContacts()
@@ -642,7 +645,7 @@ class LegacyList:
                        item.attributes["subscription"] = msnlist2jabsub(contact.lists) # Backwards compat
                        item.attributes["lists"] = str(contact.lists)
 
-               self.session.pytrans.xdb.set(self.session.jabberID, disco.IQROSTER, newXDB)
-               LogEvent(INFO, self.session.jabberID, "Finished saving list.")
+               self.session.pytrans.xdb.set(self.jabberID, disco.IQROSTER, newXDB)
+               LogEvent(INFO, self.jabberID, "Finished saving list.")
        
 
index 4de6f428a294fcad787d92829fb749621ca695ad..8dca203aeb2e64a9518a79c633786fe14bcb6208 100644 (file)
@@ -242,10 +242,11 @@ class PyTransport(component.Service):
                mtype = el.getAttribute("type")
                s = self.sessions.get(froj.userhost(), None)
                if mtype == "error" and s:
+                       LogEvent(INFO, s.jabberID, "Removing session because of message type=error")
                        s.removeMe()
                elif s:
                        s.onMessage(el)
-               else:
+               elif mtype != "error":
                        to = el.getAttribute("to")
                        ulang = utils.getLang(el)
                        body = None
@@ -265,8 +266,12 @@ class PyTransport(component.Service):
                        LogEvent(WARN, "", "Failed stringprep.")
                        return
 
+               ptype = el.getAttribute("type")
                s = self.sessions.get(froj.userhost())
-               if s:
+               if ptype == "error" and s:
+                       LogEvent(INFO, s.jabberID, "Removing session because of message type=error")
+                       s.removeMe()
+               elif s:
                        s.onPresence(el)
                else:
                        ulang = utils.getLang(el)
index 0f9d91e002603ffbc240e06921546060a5d31633..df5557e08dc958aac871a82b91daf92395cfc489 100644 (file)
@@ -266,7 +266,10 @@ class Session(jabw.JabberConnection):
                
                elif ptype == "probe":
                        LogEvent(INFO, self.jabberID, "Responding to presence probe")
-                       self.contactList.getContact(to).sendPresence(source)
+                       if to == config.jid:
+                               self.legacycon.sendShowStatus(source)
+                       else:
+                               self.contactList.getContact(to).sendPresence(source)
                else:
                        # Not for groupchat
                        self.handleResourcePresence(source, resource, to, tor, priority, ptype, show, status)
index c89889026ece8e48eabedbb60e035cab9a90c582..15e47836d38ff6a81fd7e7568a78cda48369d758 100644 (file)
@@ -625,7 +625,7 @@ class OneSwitchboardSession(SwitchboardSessionBase):
                self.timeout = None
                for message, noerror in self.messageBuffer:
                        if not noerror:
-                               self.failedMessage(self.remoteUser, message)
+                               self.failedMessage(message)
 
        def _ready(self):
                LogEvent(INFO, self.ident)