]> code.delx.au - pymsnt/blobdiff - src/jabw.py
Subscription requests outside of sessions are now responded to with an error
[pymsnt] / src / jabw.py
index f063cefa2e12d4d55a8d308272d71d2e4cdca0e1..e6f2897302744288a6dd37df0396c0fc149cb954 100644 (file)
@@ -33,8 +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":
+       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
@@ -81,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"] = disco.XMPP_STANZAS
        text = error.addElement("text")
-       text.attributes["xmlns"] = "urn:ietf:params:xml:ns:xmpp-stanzas"
+       text.attributes["xmlns"] = disco.XMPP_STANZAS
        text.addContent(explanation)
        if(body and len(body) > 0):
                b = el.addElement("body")
@@ -252,10 +253,7 @@ class JabberConnection:
                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)
-               elif ptype == "probe":
-                       LogEvent(INFO, self.jabberID, "Parsed presence probe")
-                       self.contactList.getContact(toj.userhost()).sendPresence(fro)
+                       self.subscriptionReceived(fro, toj.userhost(), ptype)
                else:
                        status = None
                        show = None
@@ -269,7 +267,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"):
@@ -301,7 +299,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