]> code.delx.au - pymsnt/commitdiff
Getting there..
authorjamesbunton <jamesbunton@55fbd22a-6204-0410-b2f0-b6c764c7e90a>
Sun, 1 Jan 2006 07:06:35 +0000 (07:06 +0000)
committerjamesbunton <jamesbunton@55fbd22a-6204-0410-b2f0-b6c764c7e90a>
Sun, 1 Jan 2006 07:06:35 +0000 (07:06 +0000)
git-svn-id: http://delx.cjb.net/svn/pymsnt/trunk@68 55fbd22a-6204-0410-b2f0-b6c764c7e90a

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

12 files changed:
src/disco.py
src/housekeep.py
src/jabw.py
src/legacy/glue.py
src/main.py
src/misciq.py
src/register.py
src/session.py
src/tlib/msn/__init__.py
src/tlib/msn/msn.py
src/tlib/msn/msnw.py
src/utils.py

index 5fb0746c41abbc50e053cd285febddee49a8195a..58aeb14402e2f7dfea9c65b536b28933fc58c5e1 100644 (file)
@@ -2,7 +2,7 @@
 # Licensed for distribution under the GPL version 2, check COPYING for details
 
 import utils
-from tlib.xmlw import Element
+from tlib.xmlw import Element, jid
 from twisted.internet.defer import Deferred
 from twisted.internet import reactor
 from debug import LogEvent, INFO, WARN, ERROR
@@ -109,8 +109,8 @@ class ServerDiscovery:
                iqType = el.getAttribute("type")
                ulang = utils.getLang(el)
                try: # Stringprep
-                       froj = utils.jid(fro)
-                       to = utils.jid(to).full()
+                       froj = jid.intern(fro)
+                       to = jid.intern(to).full()
                except Exception, e:
                        LogEvent(WARN, "", "Dropping IQ because of stringprep error")
 
index ee939a0edfcd1faf99faa65fa487ae30b7fc16da..d6399aba777ee514c51e8f1a8365353701482470 100644 (file)
@@ -1,6 +1,8 @@
 # Copyright 2005 James Bunton <james@delx.cjb.net>
 # Licensed for distribution under the GPL version 2, check COPYING for details
 
+import tlib.xmlw
+
 import utils
 import config
 import xdb
@@ -65,7 +67,7 @@ def doSpoolPrepCheck():
        for file in os.listdir(pre):
                try:
                        file = xdb.unmangle(file).decode("utf-8")
-                       filej = utils.jid(file).full()
+                       filej = xmlw.jid.intern(file).full()
                        if(file != filej):
                                file = xdb.mangle(file)
                                filej = xdb.mangle(filej)
index 08c4788fc9863e0fd754e4352213f68f42b66feb..ec2904fe608143e891716aaefa8eb63cb6361546 100644 (file)
@@ -2,7 +2,7 @@
 # Licensed for distribution under the GPL version 2, check COPYING for details
 
 import utils
-from tlib.xmlw import Element
+from tlib.xmlw import Element, jid
 from debug import LogEvent, INFO, WARN, ERROR
 import disco
 
@@ -33,9 +33,8 @@ def sendMessage(pytrans, to, fro, body, mtype=None, delay=None):
 def sendPresence(pytrans, to, fro, show=None, status=None, priority=None, ptype=None, avatarHash=None, nickname=None, payload=[]):
        # Strip the resource off any presence subscribes (as per XMPP RFC 3921 Section 5.1.6)
        # Makes eJabberd behave :)
-       if(ptype == "subscribe"):
-               (user,host,res) = utils.jid(to)
-               to = "%s@%s" % (user, host)
+       if ptype == "subscribe":
+               to = jid.intern(to).userhost()
        
        el = Element((None, "presence"))
        el.attributes["to"] = to
@@ -183,8 +182,8 @@ class JabberConnection:
                fro = el.getAttribute("from")
                to = el.getAttribute("to")
                try:
-                       froj = utils.jid(fro)
-                       toj = utils.jid(to)
+                       froj = jid.intern(fro)
+                       toj = jid.intern(to)
                except Exception, e:
                        LogEvent(WARN, self.jabberID)
                        return
@@ -245,9 +244,9 @@ class JabberConnection:
                """ Handles incoming presence packets """
                #LogEvent(INFO, self.jabberID)
                fro = el.getAttribute("from")
-               froj = utils.jid(fro)
+               froj = jid.intern(fro)
                to = el.getAttribute("to")
-               toj = utils.jid(to)
+               toj = jid.intern(to)
                
                # Grab the contents of the <presence/> packet
                ptype = el.getAttribute("type")
index 917ba65d1e3ea862d3173332fdfdf7ff503d7a05..768ca3370a0dabd8d88e86a0693f9dedccf888a6 100644 (file)
@@ -184,7 +184,7 @@ class LegacyGroupchat(groupchat.BaseGroupchat):
                if switchboardSession:
                        self.switchboardSession = switchboardSession
                else:
-                       self.switchboardSession = msn.MultiSwitchboardSession(self)
+                       self.switchboardSession = msn.MultiSwitchboardSession(self.session.legacycon)
                        
                LogEvent(INFO, self.roomJID())
        
@@ -202,7 +202,7 @@ class LegacyGroupchat(groupchat.BaseGroupchat):
                userHandle = jid2msn(contactJID)
                self.switchboardSession.inviteUser(userHandle)
        
-       def gotMessage(self, userHandle, text)
+       def gotMessage(self, userHandle, text):
                LogEvent(INFO, self.roomJID())
                self.messageReceived(userHandle, text)
 
@@ -391,6 +391,7 @@ class LegacyConnection(msn.MSNConnection):
        
        def contactAvatarChanged(self, userHandle, hash):
                LogEvent(INFO, self.session.jabberID)
+               jid = msn2jid(userHandle)
                c = self.session.contactList.findContact(jid)
                if not c: return
 
@@ -400,13 +401,14 @@ class LegacyConnection(msn.MSNConnection):
                        if av:
                                msnContact = self.getContacts().getContact(userHandle)
                                msnContact.msnobjGot = True
-                               jid = msn2jid(userHandle)
                                c.updateAvatar(av)
                        else:
                                def updateAvatar((imageData,)):
                                        av = self.session.pytrans.avatarCache.setAvatar(imageData)
                                        c.updateAvatar(av)
-                               self.sendAvatarRequest(userHandle).addCallback(updateAvatar)
+                               d = self.sendAvatarRequest(userHandle)
+                               if d:
+                                       d.addCallback(updateAvatar)
                else:
                        # They've turned off their avatar
                        global defaultAvatar
index 8975e4cdbdc1db36602ef1918f67e1f954c2f9d4..edebfeb78de37f2640dcf3bbdda28be19153895c 100644 (file)
@@ -157,7 +157,7 @@ class PyTransport(component.Service):
        def onMessage(self, el):
                fro = el.getAttribute("from")
                try:
-                       froj = utils.jid(fro)
+                       froj = jid.intern(fro)
                except Exception, e:
                        LogEvent(WARN, "", "Failed stringprep.")
                        return
@@ -178,8 +178,8 @@ class PyTransport(component.Service):
                fro = el.getAttribute("from")
                to = el.getAttribute("to")
                try:
-                       froj = utils.jid(fro)
-                       toj = utils.jid(to)
+                       froj = jid.intern(fro)
+                       toj = jid.intern(to)
                except Exception, e:
                        LogEvent(WARN, "", "Failed stringprep.")
                        return
index aaf4703bc84e884bf6db06baa7d27a53c90f6966..732912054b56053ab7bb742fe7c2e1dcb0c409e3 100644 (file)
@@ -28,7 +28,7 @@ class ConnectUsers:
                ID = el.getAttribute("id")
                ulang = utils.getLang(el)
 
-               if config.admins.count(utils.jid(to).userhost()) == 0:
+               if config.admins.count(jid.intern(to).userhost()) == 0:
                        self.pytrans.discovery.sendIqError(to=to, fro=config.jid, ID=ID, xmlns=disco.COMMANDS, etype="cancel", condition="not-authorized")
                        return
 
@@ -129,7 +129,7 @@ class AdHocCommands:
        def incomingIq(self, el):
                itype = el.getAttribute("type")
                fro = el.getAttribute("from")
-               froj = utils.jid(fro)
+               froj = jid.intern(fro)
                to = el.getAttribute("to")
                ID = el.getAttribute("id")
 
@@ -217,7 +217,7 @@ class VCardFactory:
        def incomingIq(self, el):
                itype = el.getAttribute("type")
                fro = el.getAttribute("from")
-               froj = utils.jid(fro)
+               froj = jid.intern(fro)
                to = el.getAttribute("to")
                ID = el.getAttribute("id")
                if(itype != "get" and itype != "error"):
@@ -277,7 +277,7 @@ class IqAvatarFactory:
        def incomingIq(self, el):
                itype = el.getAttribute("type")
                fro = el.getAttribute("from")
-               froj = utils.jid(fro)
+               froj = jid.intern(fro)
                to = el.getAttribute("to")
                ID = el.getAttribute("id")
 
index 9af2270e40d163e48c531962c59c655301fe4180..cdac86845c5145219427f092f8c091754a758189 100644 (file)
@@ -2,7 +2,7 @@
 # Licensed for distribution under the GPL version 2, check COPYING for details
 
 import utils
-from tlib.xmlw import Element
+from tlib.xmlw import Element, jid
 from debug import LogEvent, INFO, WARN, ERROR
 import disco
 import session
@@ -38,11 +38,11 @@ class RegisterManager:
                        (blah1, password, blah3) = self.getRegInfo(jabberID)
                
                reginfo = legacy.formRegEntry(username, password)
-               self.pytrans.xdb.set(utils.jid(jabberID).userhost(), legacy.namespace, reginfo)
+               self.pytrans.xdb.set(jid.intern(jabberID).userhost(), legacy.namespace, reginfo)
        
        def getRegInfo(self, jabberID):
                LogEvent(INFO)
-               result = self.pytrans.xdb.request(utils.jid(jabberID).userhost(), legacy.namespace)
+               result = self.pytrans.xdb.request(jid.intern(jabberID).userhost(), legacy.namespace)
                if(result == None):
                        LogEvent(INFO, "", "Not registered!")
                        return None
@@ -98,7 +98,7 @@ class RegisterManager:
                ID = incoming.getAttribute("id")
                fro = incoming.getAttribute("from")
                LogEvent(INFO)
-               source = utils.jid(fro).userhost()
+               source = jid.intern(fro).userhost()
                ulang = utils.getLang(incoming)
                username = None
                password = None
index 5acae358b53a8dfe95a23595648bdac7aa59c32c..22c00c0a543ac596b37ac91c69e8c4bbe5a949fc 100644 (file)
@@ -1,6 +1,8 @@
 # Copyright 2004-2005 James Bunton <james@delx.cjb.net>
 # Licensed for distribution under the GPL version 2, check COPYING for details
 
+from tlib.xmlw import jid
+
 import utils
 import legacy
 import jabw
@@ -142,7 +144,7 @@ class Session(jabw.JabberConnection):
        def updateNickname(self, nickname):
                self.nickname = nickname
                if not self.nickname:
-                       j = utils.jid(self.jabberID)
+                       j = jid.intern(self.jabberID)
                        self.nickname = j.user
                self.setStatus(self.show, self.status)
        
index f9928c34563206a71c4e9ec098fa1eb3a593b93e..edc622ab29b900cf56446584be1107438cd63f18 100644 (file)
@@ -1,4 +1,4 @@
-from msnw import MSNConnection
+from msnw import MSNConnection, MultiSwitchboardSession
 from msn import FORWARD_LIST, ALLOW_LIST, BLOCK_LIST, REVERSE_LIST, PENDING_LIST
 from msn import STATUS_ONLINE, STATUS_OFFLINE, STATUS_HIDDEN, STATUS_IDLE, STATUS_AWAY, STATUS_BUSY, STATUS_BRB, STATUS_PHONE, STATUS_LUNCH
 from msn import MSNContact, MSNContactList
index 5892dea9eb13a683fe66df1041a512f973dec2c7..e0480ed9f05d5778e579bfd602e4011850d428e8 100644 (file)
@@ -1237,7 +1237,7 @@ class NotificationClient(MSNEventBase):
 
     def handle_PRP(self, params):
         if params[1] == "MFN":
-            self._fireCallback(int(params[0]), unquote(params[2]))
+            self._fireCallback(int(params[0]))
         elif self._getState() == 'SYNC':
             self._getStateData('phone').append((params[0], unquote(params[1])))
         else:
@@ -1890,14 +1890,13 @@ class NotificationClient(MSNEventBase):
 
         @return: A Deferred, the callback for which will be called
                  when the server acknowledges the change.
-                 The callback argument will be a tuple of 1 element,
-                 the new screen name.
+                 The callback argument will be an empty tuple.
         """
 
         id, d = self._createIDMapping()
         self.sendLine("PRP %s MFN %s" % (id, quote(newName)))
         def _cb(r):
-            self.factory.screenName = r[0]
+            self.factory.screenName = newName
             return r
         return d.addCallback(_cb)
 
index 950b8692e04a915f95402d788f380c4230fcfd1c..f0794b652e230e09ffb9d7b61ff66b491292693c 100644 (file)
@@ -16,7 +16,7 @@ from tlib.msn import msn
 
 MAXMESSAGESIZE     = 1400
 SWITCHBOARDTIMEOUT = 30.0*60.0
-GETALLAVATARS      = True
+GETALLAVATARS      = False
 
 
 """
@@ -185,6 +185,7 @@ class MSNConnection:
                @param personal: the user's new personal message.
                """
 
+               if not screenName: screenName = self.username
                if self.notificationClient:
                        count = 0
                        def cb(ignored=None):
@@ -194,7 +195,7 @@ class MSNConnection:
                        self.notificationClient.changeStatus(statusCode.encode("utf-8")).addCallback(cb)
                        self.notificationClient.changeScreenName(screenName.encode("utf-8")).addCallback(cb)
                        if not personal: personal = ""
-                       self.notificationClient.changePersonalMessage(personal.encode("utf-8"))
+                       self.notificationClient.changePersonalMessage(personal.encode("utf-8")).addCallback(cb)
                else:
                        self.savedEvents.statusCode = statusCode
                        self.savedEvents.screenName = screenName
@@ -413,7 +414,7 @@ class NotificationClient(msn.NotificationClient):
        def gotSwitchboardInvitation(self, sessionID, host, port, key, userHandle, screenName):
                LogEvent(INFO, self.factory.msncon.ident)
                sb = self.factory.msncon.switchboardSessions.get(userHandle)
-               if sb:
+               if sb and sb.transport:
                        sb.transport.loseConnection()
                else:
                        sb = OneSwitchboardSession(self.factory.msncon, userHandle)
@@ -445,6 +446,11 @@ class SwitchboardSessionBase(msn.SwitchboardClient):
                del self.msncon
                self.transport.disconnect()
 
+       def loggedIn(self):
+               LogEvent(INFO, self.ident)
+               self.ready = True
+               self.flushBuffer()
+
        def connect(self):
                LogEvent(INFO, self.ident)
                self.ready = False
@@ -551,10 +557,11 @@ class MultiSwitchboardSession(SwitchboardSessionBase):
                after instantiation. """
                userHandle = str(userHandle)
                if self.ready:
-                       LogEvent(INFO, self.ident)
-                       msn.SwitchboardClient.inviteUser(userHandle)
+                       LogEvent(INFO, self.ident, "immediate")
+                       msn.SwitchboardClient.inviteUser(self, userHandle)
                else:
-                       self.funcBuffer.append(lambda: msn.SwitchboardClient.inviteUser(userHandle))
+                       LogEvent(INFO, self.ident, "pending")
+                       self.funcBuffer.append(lambda: msn.SwitchboardClient.inviteUser(self, userHandle))
        
        def gotMessage(self, message):
                self.groupchat.gotMessage(message.userHandle, message.getMessage())
@@ -612,7 +619,7 @@ class OneSwitchboardSession(SwitchboardSessionBase):
                LogEvent(INFO, self.ident)
                if not self.reply:
                        def failCB(arg=None):
-                               LogEvent(INFO, ident, "User has not joined after 30 seconds.")
+                               LogEvent(INFO, self.ident, "User has not joined after 30 seconds.")
                                del self.msncon.switchboardSessions[self.remoteUser]
                        d = self.inviteUser(self.remoteUser)
                        d.addErrback(failCB)
@@ -630,7 +637,7 @@ class OneSwitchboardSession(SwitchboardSessionBase):
                        self._ready()
                if userHandle != self.remoteUser:
                        # Another user has joined, so we now have three participants.
-                       self.switchToMulti(self)
+                       self._switchToMulti(self)
                        self.userJoined(userHandle)
 
        def userLeft(self, userHandle):
index d0184c900b3aa8e8906b310e70a54955ef20c7f4..845c5214837ac97910c9651c028d7f63cbb7e500 100644 (file)
@@ -3,12 +3,6 @@
 
 
 
-try:
-       from twisted.words.protocols.jabber import intern as jid
-except:
-       from tlib.jabber.jid import intern as jid
-
-
 def getLang(el):
        return el.getAttribute((u'http://www.w3.org/XML/1998/namespace', u'lang'))