]> code.delx.au - pymsnt/blobdiff - src/jabw.py
New resources don't get spammed with presence from offline contacts.
[pymsnt] / src / jabw.py
index 0d0a1f51604e886ed0fee0b75bf1290b0b7aacea..71058369d1af6894f39ce9ba19db1b87a6876064 100644 (file)
@@ -2,12 +2,7 @@
 # Licensed for distribution under the GPL version 2, check COPYING for details
 
 import utils
-if(utils.checkTwisted()):
-       from twisted.xish.domish import Element
-       from twisted.words.protocols.jabber import jid
-else:
-       from tlib.domish import Element
-       from tlib.jabber import jid
+from tlib.xmlw import Element, jid
 from debug import LogEvent, INFO, WARN, ERROR
 import disco
 
@@ -38,9 +33,9 @@ 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) = jid.parse(to)
-               to = "%s@%s" % (user, host)
+       if ptype in ("subscribe", "subscribed", "unsubscribe", "unsubscribed"):
+               to = jid.intern(to).userhost()
+               fro = jid.intern(fro).userhost()
        
        el = Element((None, "presence"))
        el.attributes["to"] = to
@@ -87,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"] = "urn:ietf:params:xml:ns:xmpp-stanzas"
+       desc.attributes["xmlns"] = XMPP_STANZAS
        text = error.addElement("text")
-       text.attributes["xmlns"] = "urn:ietf:params:xml:ns:xmpp-stanzas"
+       text.attributes["xmlns"] = XMPP_STANZAS
        text.addContent(explanation)
        if(body and len(body) > 0):
                b = el.addElement("body")
@@ -188,8 +183,8 @@ class JabberConnection:
                fro = el.getAttribute("from")
                to = el.getAttribute("to")
                try:
-                       froj = jid.JID(fro)
-                       toj = jid.JID(to)
+                       froj = jid.intern(fro)
+                       toj = jid.intern(to)
                except Exception, e:
                        LogEvent(WARN, self.jabberID)
                        return
@@ -250,9 +245,9 @@ class JabberConnection:
                """ Handles incoming presence packets """
                #LogEvent(INFO, self.jabberID)
                fro = el.getAttribute("from")
-               froj = jid.JID(fro)
+               froj = jid.intern(fro)
                to = el.getAttribute("to")
-               toj = jid.JID(to)
+               toj = jid.intern(to)
                
                # Grab the contents of the <presence/> packet
                ptype = el.getAttribute("type")