From ae545380a189672a3e8ef1612f5650a01a750e8c Mon Sep 17 00:00:00 2001 From: jamesbunton Date: Sun, 16 Apr 2006 10:20:33 +0000 Subject: [PATCH] Fixed tel:+ jid being invalid. Added cache to (hopefully) speed things up. git-svn-id: http://delx.cjb.net/svn/pymsnt/trunk@135 55fbd22a-6204-0410-b2f0-b6c764c7e90a committer: jamesbunton --- src/jabw.py | 4 ++-- src/lang.py | 2 +- src/legacy/glue.py | 35 ++++++++++++++++++++++++++++++++--- src/tlib/msn/msnw.py | 6 +++--- 4 files changed, 38 insertions(+), 9 deletions(-) diff --git a/src/jabw.py b/src/jabw.py index 7105836..755b49a 100644 --- a/src/jabw.py +++ b/src/jabw.py @@ -82,9 +82,9 @@ def sendErrorMessage(pytrans, to, fro, etype, condition, explanation, body=None) error.attributes["type"] = etype error.attributes["code"] = str(utils.errorCodeMap[condition]) desc = error.addElement(condition) - desc.attributes["xmlns"] = XMPP_STANZAS + desc.attributes["xmlns"] = disco.XMPP_STANZAS text = error.addElement("text") - text.attributes["xmlns"] = XMPP_STANZAS + text.attributes["xmlns"] = disco.XMPP_STANZAS text.addContent(explanation) if(body and len(body) > 0): b = el.addElement("body") diff --git a/src/lang.py b/src/lang.py index 477188a..9ad46d1 100644 --- a/src/lang.py +++ b/src/lang.py @@ -159,7 +159,7 @@ class strings: class de: # German - Florian Holzhauer registerText = u"Bitte trage Deine MSN-Passport-ID (user@hotmail.com) als User ein, sowie Dein Passwort und Deinen Nickname.\n Mehr Informationen zu diesem Gateway findest Du unter http://msn-transport.jabberstudio.org/docs/users" - gatewayTranslator = u"Enter the user's MSN account." # FIXMELANG!! + gatewayTranslator = u"Enter the user's MSN account." userMapping = u"The MSN contact %s has a Jabber ID %s. It is recommended to talk to this person through Jabber." notLoggedIn = u"Fehler. Du musst beim Gateway eingeloggt sein bevor Du Nachrichten schicken kannst." notRegistered = u"Sorry, Du scheinst Dich bei diesem Gateway noch nicht registriert zu haben. Bitte registriere Dich und versuche es noch einmal. Bei Problemen wendest Du Dich am besten an Deinen Jabber-Administrator" diff --git a/src/legacy/glue.py b/src/legacy/glue.py index 30f0581..d9dbdd1 100644 --- a/src/legacy/glue.py +++ b/src/legacy/glue.py @@ -94,16 +94,45 @@ def updateStats(statistics): #stats["FailedAvatarCount"] = msnp2p.MSNP2P_Avatar.ERROR_COUNT +msn2jid_cache = {} def msn2jid(msnid, withResource): """ Converts a MSN passport into a JID representation to be used with the transport """ - return msnid.replace('@', '%') + "@" + config.jid + (withResource and "/msn" or "") + global msn2jid_cache + global jid2msn_cache + + if msn2jid_cache.has_key(msnid): + jid = msn2jid_cache[msnid] + if withResource: + jid += "/msn" + return jid + else: + if msnid.startswith("tel:+"): + msnid = msnid.replace("tel:+", "") + "%tel" + jid = msnid.replace('@', '%') + "@" + config.jid + (withResource and "/msn" or "") + msn2jid_cache[msnid] = jid + jid2msn_cache[jid] = msnid + return jid # Marks this as the function to be used in jabber:iq:gateway (Service ID Translation) -translateAccount = lambda a: msn2jid(a, False) +def translateAccount(msnid): + return msn2jid(msnid, False) +jid2msn_cache = {} def jid2msn(jid): """ Converts a JID representation of a MSN passport into the original MSN passport """ - return unicode(jid[:jid.find('@')].replace('%', '@')).split("/")[0] + global jid2msn_cache + global msn2jid_cache + + if jid2msn_cache.has_key(jid): + msnid = jid2msn_cache[jid] + return msnid + else: + if jid.index("%tel@") > 0: + jid = "tel:+" + jid.replace("%tel@", "@") + msnid = unicode(jid[:jid.find('@')].replace('%', '@')).split("/")[0] + jid2msn_cache[jid] = msnid + msn2jid_cache[msnid] = jid + return msnid def presence2state(show, ptype): diff --git a/src/tlib/msn/msnw.py b/src/tlib/msn/msnw.py index c4f7c34..0b4f427 100644 --- a/src/tlib/msn/msnw.py +++ b/src/tlib/msn/msnw.py @@ -50,6 +50,7 @@ class MSNConnection: def _getNotificationReferral(self): def timeout(): + self.timeout = None if not d.called: d.errback() self.logOut() # Clean up everything @@ -65,6 +66,7 @@ class MSNConnection: def _gotNotificationReferral(self, (host, port)): self.timeout.cancel() + self.timeout = None # Create the NotificationClient self.notificationFactory = msn.NotificationFactory() self.notificationFactory.userHandle = self.username @@ -649,9 +651,7 @@ class OneSwitchboardSession(SwitchboardSessionBase): del self.remoteUser self.contactCount = 0 self.msncon.gotGroupchat(self, userHandle) - if not self.groupchat: - LogEvent(ERROR, self.ident) - raise Exception("YouNeedAGroupchat-WeHaveAProblemError") # FIXME + assert self.groupchat def failedMessage(self, text): self.msncon.failedMessage(self.remoteUser, text) -- 2.39.2