]> code.delx.au - pymsnt/blobdiff - src/disco.py
Hopefully fixed weird exception errors.
[pymsnt] / src / disco.py
index c2431e2369acea7ac37508566269a1a9e32f6c50..f9aac5b7e89208cf76f9d02d37a50b744fa37a13 100644 (file)
@@ -1,20 +1,17 @@
 # Copyright 2004-2005 James Bunton <james@delx.cjb.net>
 # 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 debug import LogEvent, INFO, WARN, ERROR
+
 from twisted.internet.defer import Deferred
 from twisted.internet import reactor
-from debug import LogEvent, INFO, WARN, ERROR
+from tlib.xmlw import Element, jid
+
 import sys
-import config
-import legacy
+
 import lang
+import utils
+import config
 
 XMPP_STANZAS  = "urn:ietf:params:xml:ns:xmpp-stanzas"
 DISCO         = "http://jabber.org/protocol/disco"
@@ -22,9 +19,10 @@ DISCO_ITEMS   = DISCO + "#items"
 DISCO_INFO    = DISCO + "#info"
 COMMANDS      = "http://jabber.org/protocol/commands"
 CAPS          = "http://jabber.org/protocol/caps"
-SUBSYNC       = "http://jabber.org/protocol/roster-subsync"
+SUBSYNC       = "http://delx.cjb.net/protocol/roster-subsync"
 MUC           = "http://jabber.org/protocol/muc"
 MUC_USER      = MUC + "#user"
+FEATURE_NEG   = "http://jabber.org/protocol/feature-neg"
 SI            = "http://jabber.org/protocol/si"
 FT            = "http://jabber.org/protocol/si/profile/file-transfer"
 S5B           = "http://jabber.org/protocol/bytestreams"
@@ -40,6 +38,7 @@ XCONFERENCE   = "jabber:x:conference"
 XEVENT        = "jabber:x:event"
 XDELAY        = "jabber:x:delay"
 XAVATAR       = "jabber:x:avatar"
+XDATA         = "jabber:x:data"
 STORAGEAVATAR = "storage:client:avatar"
 XVCARDUPDATE  = "vcard-temp:x:update"
 VCARDTEMP     = "vcard-temp"
@@ -71,7 +70,7 @@ class ServerDiscovery:
                Returns a deferred which will fire with the matching IQ response as it's sole argument. """
                def checkDeferred():
                        if(not d.called):
-                               d.errback()
+                               d.errback("Timeout")
                                del self.deferredIqs[(jid, ID)]
 
                jid = el.getAttribute("to")
@@ -114,9 +113,9 @@ class ServerDiscovery:
                iqType = el.getAttribute("type")
                ulang = utils.getLang(el)
                try: # Stringprep
-                       froj = jid.JID(fro)
-                       to = jid.JID(to).full()
-               except Exception, e:
+                       froj = jid.intern(fro)
+                       to = jid.intern(to).full()
+               except Exception:
                        LogEvent(WARN, "", "Dropping IQ because of stringprep error")
 
                # Check if it's a response to a send IQ
@@ -131,7 +130,7 @@ class ServerDiscovery:
                LogEvent(INFO, "", "Looking for handler")
 
                for query in el.elements():
-                       xmlns = query.defaultUri
+                       xmlns = query.uri
                        node = query.getAttribute("node")
                        
                        if xmlns.startswith(DISCO) and node:
@@ -151,6 +150,8 @@ class ServerDiscovery:
 
                        if to.find('@') > 0:
                                searchjid = "USER"
+                       elif config.compjid and to == config.compjid:
+                               searchjid = config.jid
                        else:
                                searchjid = to
                        for (feature, handler) in self.features.get(searchjid, []):
@@ -176,7 +177,8 @@ class ServerDiscovery:
                query.attributes["xmlns"] = DISCO_INFO
                
                searchjid = jid
-               if(jid.find('@') > 0): searchjid = "USER"
+               if jid.find('@') > 0: searchjid = "USER"
+               if config.compjid and jid == config.compjid: searchjid = config.jid
                # Add any identities
                for (category, ctype, name) in self.identities.get(searchjid, []):
                        identity = query.addElement("identity")
@@ -204,7 +206,8 @@ class ServerDiscovery:
                query.attributes["xmlns"] = DISCO_ITEMS
 
                searchjid = jid
-               if(jid.find('@') > 0): searchjid = "USER"
+               if jid.find('@') > 0: searchjid = "USER"
+               if config.compjid and jid == config.compjid: searchjid = config.jid
                for node in self.nodes.get(searchjid, []):
                        handler, name, rootnode = self.nodes[jid][node]
                        if rootnode:
@@ -229,6 +232,7 @@ class ServerDiscovery:
                error.attributes["type"] = etype
                error.attributes["code"] = str(utils.errorCodeMap[condition])
                cond = error.addElement(condition)
+               cond.attributes["xmlns"] = XMPP_STANZAS
                self.pytrans.send(el)
 
 
@@ -260,8 +264,11 @@ class DiscoRequest:
 
                features = []
 
-               query = el.getElement("query")
-               if not query:
+               for child in el.elements():
+                       if child.name == "query":
+                               query = child
+                               break
+               else:
                        return []
 
                for child in query.elements():