Make the port optional in <streamhost/>

XEP-0065 section 9.2 says “The "port" attribute specifies the port to
connect to.  This attribute MAY be present.  The value MUST be a valid
port number in decimal form.  If not specified, the port value is
"1080" (in accordance with RFC 1928).”

This fixes a traceback when a streamhost is advertised with the default
port.
This commit is contained in:
Emmanuel Gil Peyrot 2016-08-02 14:09:22 +01:00
parent 02d9d02fb2
commit 873fa6fdae
1 changed files with 6 additions and 2 deletions

View File

@ -84,9 +84,13 @@ class Proxy65Manager:
for item in query.getChildren():
if item.getName() == 'streamhost':
host = item.getAttr('host')
port = item.getAttr('port')
jid = item.getAttr('jid')
if not host or not port or not jid:
port = item.getAttr('port')
try:
port = int(port)
except ValueError, TypeError:
port = 1080
if not host or not jid:
self.proxies[proxy]._on_connect_failure()
self.proxies[proxy].resolve_result(host, port, jid)
# we can have only one streamhost