basic proxy authentication for BOSH connections implemented
This commit is contained in:
parent
af3f1a9dd4
commit
56e0ad7a96
|
@ -431,7 +431,6 @@ class Connection(ConnectionHandlers):
|
||||||
proxy = {}
|
proxy = {}
|
||||||
proxyptr = gajim.config.get_per('proxies',p)
|
proxyptr = gajim.config.get_per('proxies',p)
|
||||||
for key in proxyptr.keys(): proxy[key]=proxyptr[key][1]
|
for key in proxyptr.keys(): proxy[key]=proxyptr[key][1]
|
||||||
print proxy
|
|
||||||
|
|
||||||
elif gajim.config.get_per('accounts', self.name, 'use_env_http_proxy'):
|
elif gajim.config.get_per('accounts', self.name, 'use_env_http_proxy'):
|
||||||
try:
|
try:
|
||||||
|
|
|
@ -20,7 +20,7 @@ In TCP-derived transports it is file descriptor of socket'''
|
||||||
|
|
||||||
class NonBlockingBOSH(NonBlockingTransport):
|
class NonBlockingBOSH(NonBlockingTransport):
|
||||||
def __init__(self, raise_event, on_disconnect, idlequeue, xmpp_server, domain,
|
def __init__(self, raise_event, on_disconnect, idlequeue, xmpp_server, domain,
|
||||||
bosh_dict):
|
bosh_dict, proxy_creds):
|
||||||
NonBlockingTransport.__init__(self, raise_event, on_disconnect, idlequeue)
|
NonBlockingTransport.__init__(self, raise_event, on_disconnect, idlequeue)
|
||||||
|
|
||||||
self.bosh_sid = None
|
self.bosh_sid = None
|
||||||
|
@ -42,7 +42,9 @@ class NonBlockingBOSH(NonBlockingTransport):
|
||||||
self.bosh_uri = bosh_dict['bosh_uri']
|
self.bosh_uri = bosh_dict['bosh_uri']
|
||||||
self.bosh_port = bosh_dict['bosh_port']
|
self.bosh_port = bosh_dict['bosh_port']
|
||||||
self.bosh_content = bosh_dict['bosh_content']
|
self.bosh_content = bosh_dict['bosh_content']
|
||||||
|
self.over_proxy = bosh_dict['bosh_useproxy']
|
||||||
|
self.use_proxy_auth = bosh_dict['useauth']
|
||||||
|
self.proxy_creds = proxy_creds
|
||||||
self.wait_cb_time = None
|
self.wait_cb_time = None
|
||||||
self.http_socks = []
|
self.http_socks = []
|
||||||
self.stanza_buffer = []
|
self.stanza_buffer = []
|
||||||
|
@ -289,8 +291,6 @@ class NonBlockingBOSH(NonBlockingTransport):
|
||||||
return t
|
return t
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def connect_and_flush(self, socket):
|
def connect_and_flush(self, socket):
|
||||||
socket.connect(
|
socket.connect(
|
||||||
conn_5tuple = self.conn_5tuple,
|
conn_5tuple = self.conn_5tuple,
|
||||||
|
@ -334,15 +334,21 @@ class NonBlockingBOSH(NonBlockingTransport):
|
||||||
|
|
||||||
|
|
||||||
def get_new_http_socket(self):
|
def get_new_http_socket(self):
|
||||||
|
http_dict = {'http_uri': self.bosh_uri,
|
||||||
|
'http_port': self.bosh_port,
|
||||||
|
'http_version': self.http_version,
|
||||||
|
'http_persistent': self.http_persistent,
|
||||||
|
'over_proxy': self.over_proxy}
|
||||||
|
if self.use_proxy_auth:
|
||||||
|
http_dict['proxy_user'], http_dict['proxy_pass'] = self.proxy_creds
|
||||||
|
|
||||||
|
|
||||||
s = NonBlockingHTTPBOSH(
|
s = NonBlockingHTTPBOSH(
|
||||||
raise_event=self.raise_event,
|
raise_event=self.raise_event,
|
||||||
on_disconnect=self.disconnect,
|
on_disconnect=self.disconnect,
|
||||||
idlequeue = self.idlequeue,
|
idlequeue = self.idlequeue,
|
||||||
on_http_request_possible = self.on_http_request_possible,
|
on_http_request_possible = self.on_http_request_possible,
|
||||||
http_uri = self.bosh_uri,
|
http_dict = http_dict,
|
||||||
http_port = self.bosh_port,
|
|
||||||
http_version = self.http_version,
|
|
||||||
http_persistent = self.http_persistent,
|
|
||||||
on_persistent_fallback = self.on_persistent_fallback)
|
on_persistent_fallback = self.on_persistent_fallback)
|
||||||
s.onreceive(self.on_received_http)
|
s.onreceive(self.on_received_http)
|
||||||
s.set_stanza_build_cb(self.build_stanza)
|
s.set_stanza_build_cb(self.build_stanza)
|
||||||
|
|
|
@ -71,6 +71,7 @@ class NBCommonClient:
|
||||||
|
|
||||||
self.connected=''
|
self.connected=''
|
||||||
log.debug('Client disconnected..')
|
log.debug('Client disconnected..')
|
||||||
|
print 'ffffffffffffffffff'
|
||||||
for i in reversed(self.disconnect_handlers):
|
for i in reversed(self.disconnect_handlers):
|
||||||
log.debug('Calling disconnect handler %s' % i)
|
log.debug('Calling disconnect handler %s' % i)
|
||||||
i()
|
i()
|
||||||
|
@ -393,10 +394,11 @@ class NonBlockingClient(NBCommonClient):
|
||||||
|
|
||||||
if proxy['type'] == 'bosh':
|
if proxy['type'] == 'bosh':
|
||||||
self.socket = bosh.NonBlockingBOSH(
|
self.socket = bosh.NonBlockingBOSH(
|
||||||
on_disconnect=self.on_disconnect,
|
on_disconnect = self.on_disconnect,
|
||||||
raise_event = self.raise_event,
|
raise_event = self.raise_event,
|
||||||
idlequeue = self.idlequeue,
|
idlequeue = self.idlequeue,
|
||||||
xmpp_server=(xmpp_hostname, self.Port),
|
proxy_creds = (proxy_user, proxy_pass),
|
||||||
|
xmpp_server = (xmpp_hostname, self.Port),
|
||||||
domain = self.Server,
|
domain = self.Server,
|
||||||
bosh_dict = proxy)
|
bosh_dict = proxy)
|
||||||
self.protocol_type = 'BOSH'
|
self.protocol_type = 'BOSH'
|
||||||
|
@ -408,19 +410,19 @@ class NonBlockingClient(NBCommonClient):
|
||||||
elif proxy['type'] == 'http':
|
elif proxy['type'] == 'http':
|
||||||
proxy_class = transports_nb.NBHTTPProxySocket
|
proxy_class = transports_nb.NBHTTPProxySocket
|
||||||
self.socket = proxy_class(
|
self.socket = proxy_class(
|
||||||
on_disconnect=self.on_disconnect,
|
on_disconnect = self.on_disconnect,
|
||||||
raise_event = self.raise_event,
|
raise_event = self.raise_event,
|
||||||
idlequeue = self.idlequeue,
|
idlequeue = self.idlequeue,
|
||||||
proxy_creds=(proxy_user, proxy_pass),
|
proxy_creds = (proxy_user, proxy_pass),
|
||||||
xmpp_server=(xmpp_hostname, self.Port))
|
xmpp_server = (xmpp_hostname, self.Port))
|
||||||
else:
|
else:
|
||||||
self._on_tcp_failure = self._on_connect_failure
|
self._on_tcp_failure = self._on_connect_failure
|
||||||
tcp_host=xmpp_hostname
|
tcp_host=xmpp_hostname
|
||||||
tcp_port=self.Port
|
tcp_port=self.Port
|
||||||
self.socket = transports_nb.NonBlockingTCP(
|
self.socket = transports_nb.NonBlockingTCP(
|
||||||
|
on_disconnect = self.on_disconnect,
|
||||||
raise_event = self.raise_event,
|
raise_event = self.raise_event,
|
||||||
idlequeue = self.idlequeue,
|
idlequeue = self.idlequeue)
|
||||||
on_disconnect = self.on_disconnect)
|
|
||||||
|
|
||||||
self.socket.PlugIn(self)
|
self.socket.PlugIn(self)
|
||||||
|
|
||||||
|
|
|
@ -480,19 +480,24 @@ class NonBlockingHTTP(NonBlockingTCP):
|
||||||
'''
|
'''
|
||||||
|
|
||||||
def __init__(self, raise_event, on_disconnect, idlequeue, on_http_request_possible,
|
def __init__(self, raise_event, on_disconnect, idlequeue, on_http_request_possible,
|
||||||
http_uri, http_port, on_persistent_fallback, http_version='HTTP/1.1',
|
on_persistent_fallback, http_dict):
|
||||||
http_persistent=False):
|
|
||||||
|
|
||||||
NonBlockingTCP.__init__(self, raise_event, on_disconnect, idlequeue)
|
NonBlockingTCP.__init__(self, raise_event, on_disconnect, idlequeue)
|
||||||
|
|
||||||
self.http_protocol, self.http_host, self.http_path = urisplit(http_uri)
|
self.http_protocol, self.http_host, self.http_path = urisplit(http_dict['http_uri'])
|
||||||
if self.http_protocol is None:
|
if self.http_protocol is None:
|
||||||
self.http_protocol = 'http'
|
self.http_protocol = 'http'
|
||||||
if self.http_path == '':
|
if self.http_path == '':
|
||||||
http_path = '/'
|
self.http_path = '/'
|
||||||
self.http_port = http_port
|
self.http_port = http_dict['http_port']
|
||||||
self.http_version = http_version
|
self.http_version = http_dict['http_version']
|
||||||
self.http_persistent = http_persistent
|
self.http_persistent = http_dict['http_persistent']
|
||||||
|
self.over_proxy = http_dict['over_proxy']
|
||||||
|
if http_dict.has_key('proxy_user') and http_dict.has_key('proxy_pass'):
|
||||||
|
self.proxy_user, self.proxy_pass = http_dict['proxy_user'], http_dict['proxy_pass']
|
||||||
|
else:
|
||||||
|
self.proxy_user, self.proxy_pass = None, None
|
||||||
|
|
||||||
# buffer for partial responses
|
# buffer for partial responses
|
||||||
self.recvbuff = ''
|
self.recvbuff = ''
|
||||||
self.expected_length = 0
|
self.expected_length = 0
|
||||||
|
@ -574,11 +579,15 @@ class NonBlockingHTTP(NonBlockingTCP):
|
||||||
headers = ['%s %s %s' % (method, absolute_uri, self.http_version),
|
headers = ['%s %s %s' % (method, absolute_uri, self.http_version),
|
||||||
'Host: %s:%s' % (self.http_host, self.http_port),
|
'Host: %s:%s' % (self.http_host, self.http_port),
|
||||||
'Content-Type: text/xml; charset=utf-8',
|
'Content-Type: text/xml; charset=utf-8',
|
||||||
'Content-Length: %s' % len(str(httpbody)),
|
'Content-Length: %s' % len(str(httpbody))]
|
||||||
'Proxy-Connection: keep-alive',
|
if self.over_proxy:
|
||||||
'Pragma: no-cache',
|
headers.append('Proxy-Connection: keep-alive')
|
||||||
'Accept-Encoding: gzip, deflate',
|
headers.append('Pragma: no-cache')
|
||||||
'\r\n']
|
if self.proxy_user and self.proxy_pass:
|
||||||
|
credentials = '%s:%s' % (self.proxy_user, self.proxy_pass)
|
||||||
|
credentials = base64.encodestring(credentials).strip()
|
||||||
|
headers.append('Proxy-Authorization: Basic %s' % credentials)
|
||||||
|
headers.append('\r\n')
|
||||||
headers = '\r\n'.join(headers)
|
headers = '\r\n'.join(headers)
|
||||||
return('%s%s\r\n' % (headers, httpbody))
|
return('%s%s\r\n' % (headers, httpbody))
|
||||||
|
|
||||||
|
@ -678,7 +687,7 @@ class NBHTTPProxySocket(NBProxySocket):
|
||||||
'Proxy-Connection: Keep-Alive',
|
'Proxy-Connection: Keep-Alive',
|
||||||
'Pragma: no-cache',
|
'Pragma: no-cache',
|
||||||
'Host: %s:%s' % self.xmpp_server,
|
'Host: %s:%s' % self.xmpp_server,
|
||||||
'User-Agent: HTTPPROXYsocket/v0.1']
|
'User-Agent: Gajim']
|
||||||
if self.proxy_user and self.proxy_pass:
|
if self.proxy_user and self.proxy_pass:
|
||||||
credentials = '%s:%s' % (self.proxy_user, self.proxy_pass)
|
credentials = '%s:%s' % (self.proxy_user, self.proxy_pass)
|
||||||
credentials = base64.encodestring(credentials).strip()
|
credentials = base64.encodestring(credentials).strip()
|
||||||
|
|
Loading…
Reference in New Issue