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. If you want ssl/tls support to be discovered and enable automatically - leave third argument as None. (ssl will be autodetected only if port is 5223 or 443) If you want to force SSL start (i.e. if port 5223 or 443 is remapped to some non-standard port) then set it to 1. 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':'******','password':'******'}) Returns '' or 'tcp' or 'tls', depending on the result.""" 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(1): pass # If we get version 1.0 stream the features tag MUST BE presented if not self.Dispatcher.Stream.features.getTag('starttls'): return self.connected # TLS not supported by server while not self.TLS.starttls and self.Process(1): pass if not hasattr(self, 'TLS') or self.TLS.starttls != 'success': self.event('tls_failed') return self.connected self.connected = 'tls' return self.connected
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. Returns None or 'tcp' or 'tls', depending on the result.""" if not server: server = (self.Server, self.Port) if proxy: sock = transports.HTTPPROXYsocket(proxy, server, use_srv) else: sock = transports.TCPsocket(server, use_srv) connected = sock.PlugIn(self) if not connected: sock.PlugOut() return self._Server, self._Proxy = server, proxy self.connected = 'tcp' if (ssl is None and self.Connection.getPort() in (5223, 443)) or ssl: try: # FIXME. This should be done in transports.py transports.TLS().PlugIn(self, now=1) self.connected = 'ssl' except socket.sslerror: return dispatcher.Dispatcher().PlugIn(self) while self.Dispatcher.Stream._document_attrs is None: if not self.Process(1): return if self.Dispatcher.Stream._document_attrs.has_key( 'version' ) and self.Dispatcher.Stream._document_attrs['version'] == '1.0': while not self.Dispatcher.Stream.features and self.Process(1): pass # If we get version 1.0 stream the features tag MUST BE presented return self.connected
def connect(self, secureMode=SECURE_DISABLE, useResolver=True): """ Connect to jabber server. If you want TLS/SSL support to be discovered and enable automatically, set third argument as SECURE_AUTO (SSL will be autodetected only if port is 5223 or 443) If you want to force SSL start (i.e. if port 5223 or 443 is remapped to some non-standard port) then set it to SECURE_FORCE. If you want to disable TLS/SSL support completely, set it to SECURE_DISABLE. Returns None or "TCP", "SSL" "TLS", depending on the result. """ sock = transports.TCPSocket(useResolver) connectType = sock.plugIn(self) if not connectType: sock.plugOut() return None self.connectType = C_TCP isSSLPort = self.port in (5223, 443) if (secureMode == SECURE_AUTO and isSSLPort) or secureMode == SECURE_FORCE: # FIXME. This should be done in transports.py try: transports.TLS().plugIn(self, forceSSL=True) self.connectType = C_SSL except socket.sslerror: self.TLS.PlugOut() return None dispatcher.Dispatcher().plugIn(self) while self.Dispatcher.stream._document_attrs is None: if not self.process(1): return None # If we get version 1.0 stream the features tag MUST BE presented if self.Dispatcher.stream._document_attrs.get("version") == "1.0": while not self.Dispatcher.features and self.process(1): pass if secureMode == SECURE_AUTO and not isSSLPort: # If we get version 1.0 stream the features tag MUST BE presented if self.Dispatcher.stream._document_attrs.get("version") == "1.0": transports.TLS().plugIn(self) if transports.TLS_UNSUPPORTED == self.TLS.state: self.TLS.PlugOut() return self.connectType while not self.TLS.state and self.process(1): pass if self.TLS.state != transports.TLS_SUCCESS: self.TLS.plugOut() return None self.connectType = C_TLS return self.connectType
def connect(self, server=None, proxy=None): 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 not connected: return self._Server, self._Proxy = server, proxy self.connected = 'tcp' if self.Connection.getPort() == 5223: transports.TLS().PlugIn(self, now=1) self.connected = 'tls' dispatcher.Dispatcher().PlugIn(self) while self.Dispatcher.Stream._document_attrs is None: self.Process(1) return self.connected
def connect(self, server=None, proxy=None): if not CommonClient.connect(self, server, proxy): 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 if not self.Dispatcher.Stream.features.getTag('starttls'): return self.connected # TLS not supported by server while not self.TLS.starttls and self.Process(): pass if self.TLS.starttls <> 'success': self.event('tls_failed') return self.connected self.connected = 'tls' return self.connected