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)
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)
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
page = error.NoResource(message="404 File Not Found")
return page.render(request)
-oobSite = server.Site(FileTransfer())
-# FIXME
-#reactor.listenTCP(int(config.ftOOBPort), oobSite)
import groupchat
import ft
import avatar
-import msnw
import config
import lang
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 '%') """
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
"""
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
# 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
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
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)
self.userTypingSend.stop()
- msnw.MSNConnection.removeMe(self)
+ msn.MSNConnection.removeMe(self)
self.legacyList.removeMe()
self.legacyList = None
self.session = None
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)
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
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.")
+
+
+++ /dev/null
-# 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.")
-
-