]> code.delx.au - pymsnt/blobdiff - src/legacy/glue.py
Updated rev and url
[pymsnt] / src / legacy / glue.py
index 866f3da69f6832deb92c404aa177f4fdf2832a50..cc3b30c36d340340f70c76cdcf94d2125a1c3f63 100644 (file)
@@ -2,11 +2,11 @@
 # Licensed for distribution under the GPL version 2, check COPYING for details
 
 import os.path
-import utils
-from twisted.internet import task
-from tlib.xmlw import Element
-from tlib import msn
+from twisted.internet import task, error
+from twisted.words.xish.domish import Element
+
 from debug import LogEvent, INFO, WARN, ERROR
+from legacy import msn
 import disco
 import groupchat
 import ft
@@ -17,8 +17,8 @@ import lang
 
 
 
-url = "http://msn-transport.jabberstudio.org"
-version = "0.11-dev"         # The transport version
+url = "http://delx.net.au/projects/pymsnt"
+version = "0.11.3"       # The transport version
 mangle = True            # XDB '@' -> '%' mangling
 id = "msn"               # The transport identifier
 
@@ -36,6 +36,8 @@ defaultAvatar = avatar.AvatarCache().setAvatar(defaultAvatarData)
 
 def reloadConfig():
        msn.MSNConnection.GETALLAVATARS = config.getAllAvatars
+       msn.MSNConnection.BINDADDRESS = config.host
+       msn.setDebug(config._debugLevel >= 4)
 
 def isGroupJID(jid):
        """ Returns True if the JID passed is a valid groupchat JID (for MSN, does not contain '%') """
@@ -108,10 +110,10 @@ def msn2jid(msnid, withResource):
        else:
                if msnid.startswith("tel:+"):
                        msnid = msnid.replace("tel:+", "") + "%tel"
-               jid = msnid.replace('@', '%') + "@" + config.jid + (withResource and "/msn" or "")
+               jid = msnid.replace('@', '%') + "@" + config.jid
                msn2jid_cache[msnid] = jid
                jid2msn_cache[jid] = msnid
-               return jid
+               return msn2jid(msnid, withResource)
 
 # Marks this as the function to be used in jabber:iq:gateway (Service ID Translation)
 def translateAccount(msnid):
@@ -335,9 +337,9 @@ class LegacyConnection(msn.MSNConnection):
                global defaultJabberAvatarData
 
                if av:
-                       msn.MSNConnection.changeAvatar(self, av.getImageData())
+                       msn.MSNConnection.changeAvatar(self, av.getImageData)
                else:
-                       msn.MSNConnection.changeAvatar(self, defaultJabberAvatarData)
+                       msn.MSNConnection.changeAvatar(self, lambda: defaultJabberAvatarData)
        
        def sendTypingNotifications(self):
                if not self.session: return
@@ -378,8 +380,9 @@ class LegacyConnection(msn.MSNConnection):
        
        def connectionLost(self, reason):
                LogEvent(INFO, self.jabberID)
-               text = lang.get(self.session.lang).msnDisconnected % reason
-               self.session.sendMessage(to=self.jabberID, fro=config.jid, body=text)
+               if reason.type != error.ConnectionDone:
+                       text = lang.get(self.session.lang).msnDisconnected % reason
+                       self.session.sendMessage(to=self.jabberID, fro=config.jid, body=text)
                self.session.removeMe() # Tear down the session
 
        def multipleLogin(self):
@@ -403,13 +406,13 @@ class LegacyConnection(msn.MSNConnection):
        
        def loggedIn(self):
                LogEvent(INFO, self.jabberID)
-               self.session.ready = True
        
        def listSynchronized(self):
                LogEvent(INFO, self.jabberID)
                self.session.sendPresence(to=self.jabberID, fro=config.jid)
                self.legacyList.syncJabberLegacyLists()
                self.listSynced = True
+               self.session.ready = True
                #self.legacyList.flushSubscriptionBuffer()
        
        def ourStatusChanged(self, statusCode, screenName, personal):
@@ -481,8 +484,8 @@ class LegacyConnection(msn.MSNConnection):
                if not (c and msnContact): return
 
                show, ptype = state2presence(msnContact.status)
-               status = msnContact.personal.decode("utf-8")
-               screenName = msnContact.screenName.decode("utf-8")
+               status = msnContact.personal.decode("utf-8", "replace")
+               screenName = msnContact.screenName.decode("utf-8", "replace")
 
                c.updateNickname(screenName, push=False)
                c.updatePresence(show, status, ptype, force=True)
@@ -550,10 +553,8 @@ class LegacyList:
        def __init__(self, session):
                self.jabberID = session.jabberID
                self.session = session
-               self.subscriptionBuffer = []
        
        def removeMe(self):
-               self.subscriptionBuffer = None
                self.session = None
 
        def addContact(self, jid):
@@ -563,9 +564,9 @@ class LegacyList:
 
                # Handle adding a contact that has previously been removed
                msnContact = self.session.legacycon.getContacts().getContact(userHandle)
-               self.session.legacycon.remContact(msn.BLOCK_LIST, jid)
-               if msnContact.lists & msn.REVERSE_LIST:
+               if msnContact and msnContact.lists & msn.REVERSE_LIST:
                        self.session.legacycon.contactAddedMe(userHandle)
+               self.authContact(jid)
                self.session.contactList.getContact(jid).contactGrantsAuth()
        
        def removeContact(self, jid):
@@ -576,12 +577,12 @@ class LegacyList:
        
        def authContact(self, jid):
                LogEvent(INFO, self.jabberID)
-               jid = jid2msn(jid)
-               d = self.session.legacycon.remContact(msn.PENDING_LIST, jid)
+               userHandle = jid2msn(jid)
+               d = self.session.legacycon.remContact(msn.PENDING_LIST, userHandle)
                if d:
-                       self.session.legacycon.addContact(msn.REVERSE_LIST, jid)
-               self.session.legacycon.remContact(msn.BLOCK_LIST, jid)
-               self.session.legacycon.addContact(msn.ALLOW_LIST, jid)
+                       self.session.legacycon.addContact(msn.REVERSE_LIST, userHandle)
+               self.session.legacycon.remContact(msn.BLOCK_LIST, userHandle)
+               self.session.legacycon.addContact(msn.ALLOW_LIST, userHandle)
        
        def deauthContact(self, jid):
                LogEvent(INFO, self.jabberID)