From 67c9312d37e9ddcf7c6aea6aa1f8b2820f69a006 Mon Sep 17 00:00:00 2001 From: Yann Leboulanger Date: Fri, 16 Sep 2005 15:19:01 +0000 Subject: [PATCH] SRV lookup is now an option and is turned off when we use SSL --- src/common/config.py | 1 + src/common/connection.py | 7 +++++-- src/common/xmpp/client.py | 10 +++++----- src/common/xmpp/transports.py | 12 ++++++------ 4 files changed, 17 insertions(+), 13 deletions(-) diff --git a/src/common/config.py b/src/common/config.py index 77912ec46..a74de341e 100644 --- a/src/common/config.py +++ b/src/common/config.py @@ -166,6 +166,7 @@ class Config: 'keyid': [ opt_str, '' ], 'keyname': [ opt_str, '' ], 'usessl': [ opt_bool, False ], + 'use_srv': [ opt_bool, True ], 'use_custom_host': [ opt_bool, False ], 'custom_port': [ opt_int, 5222 ], 'custom_host': [ opt_str, '' ], diff --git a/src/common/connection.py b/src/common/connection.py index 7062977ce..ebb05c075 100644 --- a/src/common/connection.py +++ b/src/common/connection.py @@ -1326,14 +1326,17 @@ class Connection: p = 5222 # autodetect [for SSL in 5223/443 and for TLS if broadcasted] secur = None + use_srv = gajim.config.get_per('accounts', self.name, 'use_srv') if usessl: p = 5223 - secur=1 #1 means force SSL no matter what the port will be + secur = 1 #1 means force SSL no matter what the port will be + use_srv = False # wants ssl? disable srv lookup if gajim.config.get_per('accounts', self.name, 'use_custom_host'): h = gajim.config.get_per('accounts', self.name, 'custom_host') p = gajim.config.get_per('accounts', self.name, 'custom_port') + use_srv = False - con_type = con.connect((h, p), proxy = proxy, secure=secur) #FIXME: blocking + con_type = con.connect((h, p), proxy=proxy, secure=secur, use_srv=use_srv) if not con_type: gajim.log.debug("Couldn't connect to %s" % self.name) if not self.retrycount: diff --git a/src/common/xmpp/client.py b/src/common/xmpp/client.py index 95c4641df..39b6dab27 100644 --- a/src/common/xmpp/client.py +++ b/src/common/xmpp/client.py @@ -156,11 +156,11 @@ class CommonClient: if hasattr(self, 'Connection'): return self.Connection._sock.getsockname() - def connect(self,server=None,proxy=None, ssl=None): + def connect(self,server=None,proxy=None, ssl=None, use_srv=None): """ Make a tcp/ip connection, protect it with tls/ssl if possible and start XMPP stream. """ if not server: server=(self.Server,self.Port) - if proxy: connected=transports.HTTPPROXYsocket(proxy,server).PlugIn(self) - else: connected=transports.TCPsocket(server).PlugIn(self) + if proxy: connected=transports.HTTPPROXYsocket(proxy,server,use_srv).PlugIn(self) + else: connected=transports.TCPsocket(server,use_srv).PlugIn(self) if not connected: return self._Server,self._Proxy=server,proxy self.connected='tcp' @@ -179,7 +179,7 @@ class CommonClient: class Client(CommonClient): """ Example client class, based on CommonClient. """ - def connect(self,server=None,proxy=None, secure=None): + def connect(self,server=None,proxy=None,secure=None,use_srv=True): """ Connect to jabber server. If you want to specify different ip/port to connect to you can pass it as tuple as first parameter. If there is HTTP proxy between you and server - specify it's address and credentials (if needed) in the second argument @@ -188,7 +188,7 @@ class Client(CommonClient): If you want to disable tls/ssl support completely, set it to 0 Example: connect(('192.168.5.5',5222),{'host':'proxy.my.net','port':8080,'user':'me','password':'secret'}) Returns '' (on no connection) or 'tcp' or 'tls', depending on the result.""" - if not CommonClient.connect(self,server,proxy,secure) or secure<>None and not secure: return self.connected + if not CommonClient.connect(self,server,proxy,secure,use_srv) or secure<>None and not secure: return self.connected transports.TLS().PlugIn(self) if not self.Dispatcher.Stream._document_attrs.has_key('version') or not self.Dispatcher.Stream._document_attrs['version']=='1.0': return self.connected while not self.Dispatcher.Stream.features and self.Process(): pass # If we get version 1.0 stream the features tag MUST BE presented diff --git a/src/common/xmpp/transports.py b/src/common/xmpp/transports.py index a9f1f3bbf..c7e0f97a5 100644 --- a/src/common/xmpp/transports.py +++ b/src/common/xmpp/transports.py @@ -61,7 +61,7 @@ class error: class TCPsocket(PlugIn): """ This class defines direct TCP connection method. """ - def __init__(self, server=None): + def __init__(self, server=None, use_srv=True): """ Cache connection point 'server'. 'server' is the tuple of (host, port) absolutely the same as standart tcp socket uses. """ PlugIn.__init__(self) @@ -69,7 +69,7 @@ class TCPsocket(PlugIn): self._exported_methods=[self.send,self.disconnect] # SRV resolver - if HAVE_DNSPYTHON or HAVE_PYDNS: + if use_srv and (HAVE_DNSPYTHON or HAVE_PYDNS): host, port = server possible_queries = ['_xmpp-client._tcp.' + host] @@ -78,8 +78,8 @@ class TCPsocket(PlugIn): if HAVE_DNSPYTHON: answers = [x for x in dns.resolver.query(query, 'SRV')] if answers: - host = str (answers[0].target) - port = int (answers[0].port) + host = str(answers[0].target) + port = int(answers[0].port) break elif HAVE_PYDNS: # ensure we haven't cached an old configuration @@ -189,12 +189,12 @@ class HTTPPROXYsocket(TCPsocket): """ HTTP (CONNECT) proxy connection class. Uses TCPsocket as the base class redefines only connect method. Allows to use HTTP proxies like squid with (optionally) simple authentication (using login and password). """ - def __init__(self,proxy,server): + def __init__(self,proxy,server,use_srv=True): """ Caches proxy and target addresses. 'proxy' argument is a dictionary with mandatory keys 'host' and 'port' (proxy address) and optional keys 'user' and 'password' to use for authentication. 'server' argument is a tuple of host and port - just like TCPsocket uses. """ - TCPsocket.__init__(self,server) + TCPsocket.__init__(self,server,use_srv) self.DBG_LINE=DBG_CONNECT_PROXY self._proxy=proxy