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
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
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")
node = None
for child in el.elements():
- xmlns = child.defaultUri
+ xmlns = child.uri
node = child.getAttribute("node")
handled = False
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")
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:
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 = 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")
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)
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()
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()
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"]
# 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"):
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"):
except error.NotConnectingError:
pass
+ if factory.streamHostTimeout:
+ factory.streamHostTimeout.cancel()
+ factory.streamHostTimeout = None
+
iq = Element((None, "iq"))
iq["type"] = "result"
iq["from"] = toj.full()
# 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))