]> code.delx.au - pymsnt/blobdiff - src/misciq.py
Fixed bug with version number.
[pymsnt] / src / misciq.py
index 1056cc8d5ebb172b449686950742ad80c28b2ef6..f66dc63e9ada36c2e4d2c4d1561fd88b33af3d1a 100644 (file)
@@ -3,7 +3,8 @@
 
 import utils
 from twisted.internet import reactor, task, protocol, error
-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 jabw
 import legacy
@@ -29,7 +30,7 @@ class ConnectUsers:
                ID = el.getAttribute("id")
                ulang = utils.getLang(el)
 
-               if config.admins.count(jid.intern(to).userhost()) == 0:
+               if config.admins.count(internJID(to).userhost()) == 0:
                        self.pytrans.discovery.sendIqError(to=to, fro=config.jid, ID=ID, xmlns=disco.COMMANDS, etype="cancel", condition="not-authorized")
                        return
 
@@ -130,7 +131,7 @@ class AdHocCommands:
        def incomingIq(self, el):
                itype = el.getAttribute("type")
                fro = el.getAttribute("from")
-               froj = jid.intern(fro)
+               froj = internJID(fro)
                to = el.getAttribute("to")
                ID = el.getAttribute("id")
 
@@ -138,7 +139,7 @@ class AdHocCommands:
 
                node = None
                for child in el.elements():
-                       xmlns = child.defaultUri
+                       xmlns = child.uri
                        node = child.getAttribute("node")
 
                        handled = False
@@ -218,9 +219,9 @@ class VCardFactory:
        def incomingIq(self, el):
                itype = el.getAttribute("type")
                fro = el.getAttribute("from")
-               froj = jid.intern(fro)
+               froj = internJID(fro)
                to = el.getAttribute("to")
-               toj = jid.intern(to)
+               toj = internJID(to)
                ID = el.getAttribute("id")
                if itype != "get" and itype != "error":
                        self.pytrans.discovery.sendIqError(to=fro, fro=config.jid, ID=ID, xmlns="vcard-temp", etype="cancel", condition="feature-not-implemented")
@@ -255,9 +256,9 @@ class VCardFactory:
                vCard.attributes["xmlns"] = "vcard-temp"
                if toGateway:
                        FN = vCard.addElement("FN")
-                       FN.addContent(legacy.name)
+                       FN.addContent(config.discoName)
                        DESC = vCard.addElement("DESC")
-                       DESC.addContent(legacy.name)
+                       DESC.addContent(config.discoName)
                        URL = vCard.addElement("URL")
                        URL.addContent(legacy.url)
                else:
@@ -279,9 +280,9 @@ class IqAvatarFactory:
        def incomingIq(self, el):
                itype = el.getAttribute("type")
                fro = el.getAttribute("from")
-               froj = jid.intern(fro)
+               froj = internJID(fro)
                to = el.getAttribute("to")
-               toj = jid.intern(to)
+               toj = internJID(to)
                ID = el.getAttribute("id")
 
                if(itype != "get" and itype != "error"):
@@ -431,6 +432,8 @@ class VersionTeller:
                self.pytrans = pytrans
                self.pytrans.discovery.addFeature(disco.IQVERSION, self.incomingIq, config.jid)
                self.pytrans.discovery.addFeature(disco.IQVERSION, self.incomingIq, "USER")
+               self.version = legacy.version
+               self.os = "Python" + ".".join([str(x) for x in sys.version_info[0:3]]) + " - " + sys.platform
        
        def incomingIq(self, el):
                eltype = el.getAttribute("type")
@@ -449,11 +452,11 @@ class VersionTeller:
                query = iq.addElement("query")
                query.attributes["xmlns"] = disco.IQVERSION
                name = query.addElement("name")
-               name.addContent(legacy.name)
+               name.addContent(config.discoName)
                version = query.addElement("version")
-               version.addContent(legacy.version)
+               version.addContent(self.version)
                os = query.addElement("os")
-               os.addContent("Python" + ".".join([str(x) for x in sys.version_info[0:3]]) + " - " + sys.platform)
+               os.addContent(self.os)
                
                self.pytrans.send(iq)
 
@@ -483,8 +486,8 @@ class FileTransferOOBSend:
                else:
                        return errOut()
 
-               froj = jid.intern(el.getAttribute("from"))
-               toj = jid.intern(el.getAttribute("to"))
+               froj = internJID(el.getAttribute("from"))
+               toj = internJID(el.getAttribute("to"))
                session = self.pytrans.sessions.get(froj.userhost(), None)
                if not session:
                        return errOut()
@@ -542,8 +545,8 @@ class Socks5FileTransfer:
                def errOut():
                        self.pytrans.discovery.sendIqError(to=el.getAttribute("from"), fro=el.getAttribute("to"), ID=ID, xmlns=disco.SI, etype="cancel", condition="bad-request")
 
-               toj = jid.intern(el.getAttribute("to"))
-               froj = jid.intern(el.getAttribute("from"))
+               toj = internJID(el.getAttribute("to"))
+               froj = internJID(el.getAttribute("from"))
                session = self.pytrans.sessions.get(froj.userhost(), None)
                if not session:
                        return errOut()
@@ -552,7 +555,7 @@ class Socks5FileTransfer:
                if not (si and si.getAttribute("profile") == disco.FT):
                        return errOut()
                file = si.file
-               if not (file and file.defaultUri == disco.FT):
+               if not (file and file.uri == disco.FT):
                        return errOut()
                try:
                        sid = si["id"]
@@ -565,10 +568,10 @@ class Socks5FileTransfer:
 
                # Check that we can use socks5 bytestreams
                feature = si.feature
-               if not (feature and feature.defaultUri == disco.FEATURE_NEG):
+               if not (feature and feature.uri == disco.FEATURE_NEG):
                        return errOut()
                x = feature.x
-               if not (x and x.defaultUri == disco.XDATA):
+               if not (x and x.uri == disco.XDATA):
                        return errOut()
                field = x.field
                if not (field and field.getAttribute("var") == "stream-method"):
@@ -614,8 +617,8 @@ class Socks5FileTransfer:
                if el.getAttribute("type") != "set":
                        return errOut()
 
-               toj = jid.intern(el.getAttribute("to"))
-               froj = jid.intern(el.getAttribute("from"))
+               toj = internJID(el.getAttribute("to"))
+               froj = internJID(el.getAttribute("from"))
 
                query = el.query
                if not (query and query.getAttribute("mode", "tcp") == "tcp"):
@@ -654,6 +657,10 @@ class Socks5FileTransfer:
                                except error.NotConnectingError:
                                        pass
 
+                       if factory.streamHostTimeout:
+                               factory.streamHostTimeout.cancel()
+                               factory.streamHostTimeout = None
+
                        iq = Element((None, "iq"))
                        iq["type"] = "result"
                        iq["from"] = toj.full()
@@ -667,12 +674,15 @@ class Socks5FileTransfer:
 
 
                # Try the streamhosts
+               LogEvent(INFO)
                factory = protocol.ClientFactory()
                factory.protocol = ft.JEP65ConnectionSend
                factory.consumer = consumer
                factory.hash = utils.socks5Hash(sid, froj.full(), toj.full())
                factory.madeConnection = gotStreamhost
                factory.connectors = []
+               factory.streamHostTimeout = reactor.callLater(120, consumer.error)
+
                for streamhost in streamhosts:
                        factory.connectors.append(reactor.connectTCP(streamhost[1], streamhost[2], factory))