]> code.delx.au - pymsnt/blobdiff - src/jabw.py
svninfo no longer needed...
[pymsnt] / src / jabw.py
index 755b49a716540a11506f8176429c7b719c1c9774..031aaf9857e6d5ab08c73b6654a1cf661d61dd87 100644 (file)
@@ -2,7 +2,8 @@
 # Licensed for distribution under the GPL version 2, check COPYING for details
 
 import utils
-from tlib.xmlw import Element, jid
+from twisted.words.xish.domish import Element
+from twisted.words.protocols.jabber.jid import internJID
 from debug import LogEvent, INFO, WARN, ERROR
 import disco
 
@@ -34,8 +35,8 @@ def sendPresence(pytrans, to, fro, show=None, status=None, priority=None, ptype=
        # Strip the resource off any presence subscribes (as per XMPP RFC 3921 Section 5.1.6)
        # Makes eJabberd behave :)
        if ptype in ("subscribe", "subscribed", "unsubscribe", "unsubscribed"):
-               to = jid.intern(to).userhost()
-               fro = jid.intern(fro).userhost()
+               to = internJID(to).userhost()
+               fro = internJID(fro).userhost()
        
        el = Element((None, "presence"))
        el.attributes["to"] = to
@@ -161,21 +162,17 @@ class JabberConnection:
        def sendRosterImport(self, jid, ptype, sub, name="", groups=[]):
                """ Sends a special presence packet. This will work with all clients, but clients that support roster-import will give a better user experience
                IMPORTANT - Only ever use this for contacts that have already been authorised on the legacy service """
-               el = Element((None, "presence"))
-               el.attributes["to"] = self.jabberID
-               el.attributes["from"] = jid
-               el.attributes["type"] = ptype
-               r = el.addElement("x")
-               r.attributes["xmlns"] = disco.SUBSYNC
-               item = r.addElement("item")
+               x = Element((None, "x"))
+               x.attributes["xmlns"] = disco.SUBSYNC
+               item = x.addElement("item")
                item.attributes["subscription"] = sub
-               if(name):
+               if name:
                        item.attributes["name"] = unicode(name)
                for group in groups:
                        g = item.addElement("group")
                        g.addContent(group)
                
-               self.pytrans.send(el)
+               self.sendPresence(to=self.jabberID, fro=jid, ptype=ptype, payload=[x])
        
        def onMessage(self, el):
                """ Handles incoming message packets """
@@ -183,8 +180,8 @@ class JabberConnection:
                fro = el.getAttribute("from")
                to = el.getAttribute("to")
                try:
-                       froj = jid.intern(fro)
-                       toj = jid.intern(to)
+                       froj = internJID(fro)
+                       toj = internJID(to)
                except Exception, e:
                        LogEvent(WARN, self.jabberID)
                        return
@@ -245,15 +242,15 @@ class JabberConnection:
                """ Handles incoming presence packets """
                #LogEvent(INFO, self.jabberID)
                fro = el.getAttribute("from")
-               froj = jid.intern(fro)
+               froj = internJID(fro)
                to = el.getAttribute("to")
-               toj = jid.intern(to)
+               toj = internJID(to)
                
                # Grab the contents of the <presence/> packet
                ptype = el.getAttribute("type")
                if ptype and (ptype.startswith("subscribe") or ptype.startswith("unsubscribe")):
                        LogEvent(INFO, self.jabberID, "Parsed subscription presence packet")
-                       self.subscriptionReceived(toj.userhost(), ptype)
+                       self.subscriptionReceived(fro, toj.userhost(), ptype)
                else:
                        status = None
                        show = None
@@ -267,7 +264,7 @@ class JabberConnection:
                                        show = child.__str__()
                                elif(child.name == "priority"):
                                        priority = child.__str__()
-                               elif(child.defaultUri == disco.XVCARDUPDATE):
+                               elif(child.uri == disco.XVCARDUPDATE):
                                        avatarHash = " "
                                        for child2 in child.elements():
                                                if(child2.name == "photo"):
@@ -299,7 +296,7 @@ class JabberConnection:
                """ Override this method to be notified when presence is received """
                pass
        
-       def subscriptionReceived(self, source, subtype):
+       def subscriptionReceived(self, source, dest, subtype):
                """ Override this method to be notified when a subscription packet is received """
                pass