]> code.delx.au - pymsnt/commitdiff
Initial integration of new msnw. Untested.
authorjamesbunton <jamesbunton@55fbd22a-6204-0410-b2f0-b6c764c7e90a>
Fri, 23 Dec 2005 08:15:35 +0000 (08:15 +0000)
committerjamesbunton <jamesbunton@55fbd22a-6204-0410-b2f0-b6c764c7e90a>
Fri, 23 Dec 2005 08:15:35 +0000 (08:15 +0000)
git-svn-id: http://delx.cjb.net/svn/pymsnt/trunk@61 55fbd22a-6204-0410-b2f0-b6c764c7e90a

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

config-example.xml
src/ft.py
src/legacy/glue.py
src/legacy/legacylist.py [deleted file]
src/main.py

index 4aaf4adbb1f6423992d34709860269e2dc727f75..7ddef05eeb39efd86bf6fb9728290886bed47574 100644 (file)
@@ -47,9 +47,6 @@ Do not include the jid of the transport -->
 
 
 <!-- File transfer settings -->
-<!-- The lowest and highest ports to give to MSN clients when they are sending files to us. These should be open in the firewall -->
-<ftLowPort>6891</ftLowPort>
-<ftHighPort>6899</ftHighPort>
 <!-- Please give the port to listen for HTTP GETs here (Used in OOB file transfers). -->
 <ftOOBPort>8080</ftOOBPort>
 <!-- Please give the root URL the transport should send to clients. (You can use an Apache reverse proxy to put this on your ordinary website) -->
index a671fba143b49b244790f44dd8ca2a873d72607e..a649be9dcee76d4f6ed9d66a024e6202d2b9bf62 100644 (file)
--- a/src/ft.py
+++ b/src/ft.py
@@ -66,24 +66,17 @@ class FTReceive:
                LogEvent(ERROR)
 
        def messageOobMode(self):
-               def messageOobModeCB(ignored=None):
-                       global oobSite
-                       filename = str(random.randint(0, sys.maxint))
-                       oobSite.resource.putFile(self, filename)
-                       m = Element((None, "message"))
-                       m.attributes["to"] = self.session.jabberID
-                       m.attributes["from"] = self.senderJID
-                       m.addElement("body").addContent(config.ftOOBRoot + "/" + filename)
-                       x = m.addElement("x")
-                       x.attributes["xmlns"] = disco.XOOB
-                       x.addElement("url").addContent(config.ftOOBRoot + "/" + filename)
-                       self.session.pytrans.send(m)
-
-               d = self.legacyftp.accept()
-               d.addCallback(messageOobModeCB)
-               d.addErrback(self.error)
+               filename = str(random.randint(0, sys.maxint))
+               self.session.pytrans.ftOOB.putFile(self, filename)
+               m = Element((None, "message"))
+               m.attributes["to"] = self.session.jabberID
+               m.attributes["from"] = self.senderJID
+               m.addElement("body").addContent(config.ftOOBRoot + "/" + filename)
+               x = m.addElement("x")
+               x.attributes["xmlns"] = disco.XOOB
+               x.addElement("url").addContent(config.ftOOBRoot + "/" + filename)
+               self.session.pytrans.send(m)
 
-       
        def error(self, ignored=None):
                # FIXME
                LogEvent(WARN)
@@ -101,7 +94,7 @@ from debug import LogEvent, INFO, WARN, ERROR
 class Connector:
        def __init__(self, ftReceive, ftHttpPush):
                self.ftReceive, self.ftHttpPush = ftReceive, ftHttpPush
-               self.ftReceive.legacyftp.writeTo(self)
+               self.ftReceive.legacyftp.accept(self)
        
        def write(self, data):
                self.ftHttpPush.write(data)
@@ -113,10 +106,12 @@ class Connector:
                self.ftHttpPush.finish()
                self.ftReceive.error()
 
-class FileTransfer(resource.Resource):
+class FileTransferOOB(resource.Resource):
        def __init__(self):
                self.isLeaf = True
                self.files = {}
+               self.oobSite = server.Site(self)
+               reactor.listenTCP(int(config.ftOOBPort), oobSite)
 
        def putFile(self, file, filename):
                self.files[filename] = file
@@ -133,8 +128,5 @@ class FileTransfer(resource.Resource):
                        page = error.NoResource(message="404 File Not Found")
                        return page.render(request)
 
-oobSite = server.Site(FileTransfer())
-# FIXME
-#reactor.listenTCP(int(config.ftOOBPort), oobSite)
 
 
index 00c181f6e7c0bd1abea920b9bf45d51b4f852543..985d9dc723f0a60f4c3ce96fe8dc5742a2f692a2 100644 (file)
@@ -10,7 +10,6 @@ import sha
 import groupchat
 import ft
 import avatar
-import msnw
 import config
 import lang
 
@@ -24,11 +23,16 @@ mangle = True            # XDB '@' -> '%' mangling
 id = "msn"               # The transport identifier
 
 
-# Load the default avatar
+# Load the default avatars
 f = open("src/legacy/defaultJabberAvatar.png")
 defaultJabberAvatarData = f.read()
 f.close()
 
+f = open("src/legacy/defaultAvatar.png")
+defaultAvatarData = f.read()
+f.close()
+defaultAvatar = avatar.AvatarCache().setAvatar(defaultAvatarData)
+
 
 def isGroupJID(jid):
        """ Returns True if the JID passed is a valid groupchat JID (for MSN, does not contain '%') """
@@ -130,6 +134,41 @@ def state2presence(state):
                return (None, "unavailable")
 
 
+def getGroupNames(msnContact, msnContactList):
+       """ Gets a list of groups that this contact is in """
+       groups = []
+       for groupGUID in msnContact.groups:
+               try:
+                       groups.append(msnContactList.groups[groupGUID])
+               except KeyError:
+                       pass
+       return groups
+
+def msnlist2jabsub(lists):
+       """ Converts MSN contact lists ORed together into the corresponding Jabber subscription state """
+       if lists & msn.FORWARD_LIST and lists & msn.REVERSE_LIST:
+               return "both"
+       elif lists & msn.REVERSE_LIST:
+               return "from"
+       elif lists & msn.FORWARD_LIST:
+               return "to"
+       else:
+               return "none"
+
+
+def jabsub2msnlist(sub):
+       """ Converts a Jabber subscription state into the corresponding MSN contact lists ORed together """
+       if sub == "to":
+               return msn.FORWARD_LIST
+       elif sub == "from":
+               return msn.REVERSE_LIST
+       elif sub == "both":
+               return (msn.FORWARD_LIST | msn.REVERSE_LIST)
+       else:
+               return 0
+
+
+
 
 
 # This class handles groupchats with the legacy protocol
@@ -142,7 +181,7 @@ class LegacyGroupchat(groupchat.BaseGroupchat):
                """
                groupchat.BaseGroupchat.__init__(self, session, resource, ID)
                if not existing:
-                       self.switchboardSession = msnw.GroupchatSwitchboardSession(self, makeSwitchboard=True)
+                       self.switchboardSession = msn.GroupchatSwitchboardSession(self, makeSwitchboard=True)
                else:
                        self.switchboardSession = switchboardSession
                        
@@ -168,7 +207,7 @@ class LegacyGroupchat(groupchat.BaseGroupchat):
 
 
 # This class handles most interaction with the legacy protocol
-class LegacyConnection(msnw.MSNConnection):
+class LegacyConnection(msn.MSNConnection):
        """ A glue class that connects to the legacy network """
        def __init__(self, username, password, session):
                self.session = session
@@ -180,7 +219,7 @@ class LegacyConnection(msnw.MSNConnection):
                self.remoteNick = ""
 
                # Init the MSN bits
-               msnw.MSNConnection.__init__(self, username, password)
+               msn.MSNConnection.__init__(self, username, password)
 
                # User typing notification stuff
                self.userTyping = dict() # Indexed by contact MSN ID, stores whether the user is typing to this contact
@@ -190,8 +229,7 @@ class LegacyConnection(msnw.MSNConnection):
                self.userTypingSend = task.LoopingCall(self.sendTypingNotifications)
                self.userTypingSend.start(5.0)
                
-               import legacylist # Is in here to prevent an ImportError loop
-               self.legacyList = legacylist.LegacyList(self.session)
+               self.legacyList = LegacyList(self.session)
        
                LogEvent(INFO, self.session.jabberID)
        
@@ -200,7 +238,7 @@ class LegacyConnection(msnw.MSNConnection):
        
                self.userTypingSend.stop()
        
-               msnw.MSNConnection.removeMe(self)
+               msn.MSNConnection.removeMe(self)
                self.legacyList.removeMe()
                self.legacyList = None
                self.session = None
@@ -221,7 +259,7 @@ class LegacyConnection(msnw.MSNConnection):
                if self.userTyping.has_key(dest):
                        del self.userTyping[dest]
                try:
-                       msnw.MSNConnection.sendMessage(self, dest, resource, body, noerror)
+                       msn.MSNConnection.sendMessage(self, dest, resource, body, noerror)
                        self.session.pytrans.statistics.stats["MessageCount"] += 1
                except:
                        self.failedMessage(dest, body)
@@ -251,15 +289,15 @@ class LegacyConnection(msnw.MSNConnection):
        
        def setStatus(self, nickname, show, status):
                statusCode = presence2state(show, None)
-               msnw.MSNConnection.changeStatus(self, statusCode, nickname, status)
+               msn.MSNConnection.changeStatus(self, statusCode, nickname, status)
        
        def updateAvatar(self, av=None):
                global defaultJabberAvatarData
 
                if av:
-                       msnw.MSNConnection.changeAvatar(self, av.getImageData())
+                       msn.MSNConnection.changeAvatar(self, av.getImageData())
                else:
-                       msnw.MSNConnection.changeAvatar(self, defaultJabberAvatarData)
+                       msn.MSNConnection.changeAvatar(self, defaultJabberAvatarData)
        
        def sendTypingNotifications(self):
                if not self.session: return
@@ -443,3 +481,134 @@ class LegacyConnection(msnw.MSNConnection):
                self.session.removeMe() # Tear down the session
 
 
+class LegacyList:
+       def __init__(self, session):
+               self.session = session
+               self.subscriptionBuffer = []
+       
+       def removeMe(self):
+               self.subscriptionBuffer = None
+               self.session = None
+
+       def addContact(self, jid):
+               LogEvent(INFO, self.session.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)
+               jid = jid2msn(jid)
+               self.session.legacycon.remContact(msn.FORWARD_LIST, jid)
+       
+       
+       def authContact(self, jid):
+               LogEvent(INFO, self.session.jabberID)
+               jid = jid2msn(jid)
+               d = self.session.legacycon.remContact(msn.PENDING_LIST, jid)
+               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)
+       
+       def deauthContact(self, jid):
+               LogEvent(INFO, self.session.jabberID)
+               jid = jid2msn(jid)
+               self.session.legacycon.remContact(msn.ALLOW_LIST, jid)
+               self.session.legacycon.addContact(msn.BLOCK_LIST, jid)
+
+
+
+       def syncJabberLegacyLists(self):
+               """ Synchronises the MSN contact list on server with the Jabber contact list """
+
+               global defaultAvatar
+
+               # 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)
+               oldContactList = msn.MSNContactList()
+               if result:
+                       for item in result.elements():
+                               user = item.getAttribute("jid")
+                               sub = item.getAttribute("subscription")
+                               lists = item.getAttribute("lists")
+                               if not lists:
+                                       lists = jabsub2msnlist(sub) # Backwards compatible
+                               lists = int(lists)
+                               contact = msn.MSNContact(userHandle=user, screenName="", lists=lists)
+                               oldContactList.addContact(contact)
+               
+               newXDB = Element((None, "query"))
+               newXDB.attributes["xmlns"] = disco.IQROSTER
+               
+               contactList = self.session.legacycon.getContacts()
+
+
+               # Convienence functions
+               def addedToList(num):
+                       return (not (oldLists & num) and (lists & num))
+               def removedFromList(num):
+                       return ((oldLists & num) and not (lists & num))
+               
+               for contact in contactList.contacts.values():
+                       # Compare with the XDB <item/> entry
+                       oldContact = oldContactList.getContact(contact.userHandle)
+                       if oldContact == None:
+                               oldLists = 0
+                       else:
+                               oldLists = oldContact.lists
+                       lists = contact.lists
+                       
+                       # Create the Jabber representation of the
+                       # contact base on the old list data and then
+                       # sync it with current
+                       jabContact = self.session.contactList.createContact(msn2jid(contact.userHandle), msnlist2jabsub(oldLists))
+                       jabContact.updateAvatar(defaultAvatar, push=False)
+
+                       if addedToList(msn.FORWARD_LIST):
+                               jabContact.syncGroups(getGroupNames(contact, contactList), push=False)
+                               jabContact.syncContactGrantedAuth()
+
+                       if removedFromList(msn.FORWARD_LIST):
+                               jabContact.syncContactRemovedAuth()
+
+                       if addedToList(msn.ALLOW_LIST):
+                               jabContact.syncUserGrantedAuth()
+
+                       if addedToList(msn.BLOCK_LIST) or removedFromList(msn.ALLOW_LIST):
+                               jabContact.syncUserRemovedAuth()
+
+                       if (not (lists & msn.ALLOW_LIST) and not (lists & msn.BLOCK_LIST) and (lists & msn.REVERSE_LIST)) or (lists & msn.PENDING_LIST):
+                               jabContact.contactRequestsAuth()
+
+                       if removedFromList(msn.REVERSE_LIST):
+                               jabContact.contactDerequestsAuth()
+                       
+                       item = newXDB.addElement("item")
+                       item.attributes["jid"] = contact.userHandle
+                       item.attributes["subscription"] = msnlist2jabsub(lists)
+                       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.")
+       
+       def saveLegacyList(self):
+               contactList = self.session.legacycon.getContacts()
+               if not contactList: return
+
+               newXDB = Element((None, "query"))
+               newXDB.attributes["xmlns"] = disco.IQROSTER
+       
+               for contact in contactList.contacts.values():
+                       item = newXDB.addElement("item")
+                       item.attributes["jid"] = contact.userHandle
+                       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.")
+       
+
diff --git a/src/legacy/legacylist.py b/src/legacy/legacylist.py
deleted file mode 100644 (file)
index 8ede7fe..0000000
+++ /dev/null
@@ -1,184 +0,0 @@
-# Copyright 2004-2005 James Bunton <james@delx.cjb.net>
-# Licensed for distribution under the GPL version 2, check COPYING for details
-
-import utils
-from tlib.xmlw import Element
-from tlib import msn
-from legacy import glue
-from debug import LogEvent, INFO, WARN, ERROR
-import avatar
-import disco
-
-
-# Default avatar for MSN contacts
-f = open("src/legacy/defaultAvatar.png")
-defaultAvatarData = f.read()
-f.close()
-defaultAvatar = avatar.AvatarCache().setAvatar(defaultAvatarData)
-
-
-def getGroupNames(msnContact, msnContactList):
-       groups = []
-       for groupGUID in msnContact.groups:
-               try:
-                       groups.append(msnContactList.groups[groupGUID])
-               except KeyError:
-                       pass
-       return groups
-
-def msnlist2jabsub(lists):
-       """ Converts MSN contact lists ORed together into the corresponding Jabber subscription state """
-       if lists & msn.FORWARD_LIST and lists & msn.REVERSE_LIST:
-               return "both"
-       elif lists & msn.REVERSE_LIST:
-               return "from"
-       elif lists & msn.FORWARD_LIST:
-               return "to"
-       else:
-               return "none"
-
-
-def jabsub2msnlist(sub):
-       """ Converts a Jabber subscription state into the corresponding MSN contact lists ORed together """
-       if sub == "to":
-               return msn.FORWARD_LIST
-       elif sub == "from":
-               return msn.REVERSE_LIST
-       elif sub == "both":
-               return (msn.FORWARD_LIST | msn.REVERSE_LIST)
-       else:
-               return 0
-
-
-
-class LegacyList:
-       def __init__(self, session):
-               self.session = session
-               self.subscriptionBuffer = []
-       
-       def removeMe(self):
-               self.subscriptionBuffer = None
-               self.session = None
-
-       def addContact(self, jid):
-               LogEvent(INFO, self.session.jabberID)
-               userHandle = glue.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)
-               jid = glue.jid2msn(jid)
-               self.session.legacycon.remContact(msn.FORWARD_LIST, jid)
-       
-       
-       def authContact(self, jid):
-               LogEvent(INFO, self.session.jabberID)
-               jid = glue.jid2msn(jid)
-               d = self.session.legacycon.remContact(msn.PENDING_LIST, jid)
-               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)
-       
-       def deauthContact(self, jid):
-               LogEvent(INFO, self.session.jabberID)
-               jid = glue.jid2msn(jid)
-               self.session.legacycon.remContact(msn.ALLOW_LIST, jid)
-               self.session.legacycon.addContact(msn.BLOCK_LIST, jid)
-
-
-
-       def syncJabberLegacyLists(self):
-               """ Synchronises the MSN contact list on server with the Jabber contact list """
-
-               global defaultAvatar
-
-               # 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)
-               oldContactList = msn.MSNContactList()
-               if result:
-                       for item in result.elements():
-                               user = item.getAttribute("jid")
-                               sub = item.getAttribute("subscription")
-                               lists = item.getAttribute("lists")
-                               if not lists:
-                                       lists = jabsub2msnlist(sub) # Backwards compatible
-                               lists = int(lists)
-                               contact = msn.MSNContact(userHandle=user, screenName="", lists=lists)
-                               oldContactList.addContact(contact)
-               
-               newXDB = Element((None, "query"))
-               newXDB.attributes["xmlns"] = disco.IQROSTER
-               
-               contactList = self.session.legacycon.getContacts()
-
-
-               # Convienence functions
-               def addedToList(num):
-                       return (not (oldLists & num) and (lists & num))
-               def removedFromList(num):
-                       return ((oldLists & num) and not (lists & num))
-               
-               for contact in contactList.contacts.values():
-                       # Compare with the XDB <item/> entry
-                       oldContact = oldContactList.getContact(contact.userHandle)
-                       if oldContact == None:
-                               oldLists = 0
-                       else:
-                               oldLists = oldContact.lists
-                       lists = contact.lists
-                       
-                       # Create the Jabber representation of the
-                       # contact base on the old list data and then
-                       # sync it with current
-                       jabContact = self.session.contactList.createContact(glue.msn2jid(contact.userHandle), msnlist2jabsub(oldLists))
-                       jabContact.updateAvatar(defaultAvatar, push=False)
-
-                       if addedToList(msn.FORWARD_LIST):
-                               jabContact.syncGroups(getGroupNames(contact, contactList), push=False)
-                               jabContact.syncContactGrantedAuth()
-
-                       if removedFromList(msn.FORWARD_LIST):
-                               jabContact.syncContactRemovedAuth()
-
-                       if addedToList(msn.ALLOW_LIST):
-                               jabContact.syncUserGrantedAuth()
-
-                       if addedToList(msn.BLOCK_LIST) or removedFromList(msn.ALLOW_LIST):
-                               jabContact.syncUserRemovedAuth()
-
-                       if (not (lists & msn.ALLOW_LIST) and not (lists & msn.BLOCK_LIST) and (lists & msn.REVERSE_LIST)) or (lists & msn.PENDING_LIST):
-                               jabContact.contactRequestsAuth()
-
-                       if removedFromList(msn.REVERSE_LIST):
-                               jabContact.contactDerequestsAuth()
-                       
-                       item = newXDB.addElement("item")
-                       item.attributes["jid"] = contact.userHandle
-                       item.attributes["subscription"] = msnlist2jabsub(lists)
-                       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.")
-       
-       def saveLegacyList(self):
-               contactList = self.session.legacycon.getContacts()
-               if not contactList: return
-
-               newXDB = Element((None, "query"))
-               newXDB.attributes["xmlns"] = disco.IQROSTER
-       
-               for contact in contactList.contacts.values():
-                       item = newXDB.addElement("item")
-                       item.attributes["jid"] = contact.userHandle
-                       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.")
-       
-
index 0799098d5779c0a4f341c26a97d476b55befa56d..8975e4cdbdc1db36602ef1918f67e1f954c2f9d4 100644 (file)
@@ -27,6 +27,7 @@ import jabw
 import disco
 import register
 import misciq
+import ft
 import lang
 import legacy
 import housekeep
@@ -59,6 +60,7 @@ class PyTransport(component.Service):
                self.vCardFactory = misciq.VCardFactory(self)
                self.iqAvatarFactor = misciq.IqAvatarFactory(self)
                self.connectUsers = misciq.ConnectUsers(self)
+               self.ftOOB = ft.FileTransferOOB()
                self.statistics = misciq.Statistics(self)
                self.startTime = int(time.time())