Changeset 9877
- Timestamp:
- 07/03/08 01:29:10 (2 months ago)
- Location:
- branches/bosh_support/src
- Files:
-
- 1 added
- 12 modified
-
common/connection.py (modified) (3 diffs)
-
common/xmpp/auth_nb.py (modified) (24 diffs)
-
common/xmpp/bosh.py (added)
-
common/xmpp/client_nb.py (modified) (12 diffs)
-
common/xmpp/client.py (modified) (4 diffs)
-
common/xmpp/dispatcher_nb.py (modified) (14 diffs)
-
common/xmpp/idlequeue.py (modified) (4 diffs)
-
common/xmpp/__init__.py (modified) (1 diff)
-
common/xmpp/roster_nb.py (modified) (5 diffs)
-
common/xmpp/simplexml.py (modified) (7 diffs)
-
common/xmpp/tls_nb.py (modified) (6 diffs)
-
common/xmpp/transports_nb.py (modified) (20 diffs)
-
gajim.py (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
branches/bosh_support/src/common/connection.py
r9867 r9877 209 209 def _disconnectedReconnCB(self): 210 210 '''Called when we are disconnected''' 211 log. error('disconnectedReconnCB')211 log.info('disconnectedReconnCB called') 212 212 if gajim.account_is_connected(self.name): 213 213 # we cannot change our status to offline or connecting … … 532 532 533 533 if self._proxy and self._proxy['type'] == 'bosh': 534 clientClass = common.xmpp. BOSHClient534 clientClass = common.xmpp.bosh.BOSHClient 535 535 else: 536 536 clientClass = common.xmpp.NonBlockingClient 537 537 538 if gajim.verbose: 539 con = common.xmpp.NonBlockingClient( 540 hostname=self._current_host['host'], 541 port=port, 542 caller=self, 543 idlequeue=gajim.idlequeue) 544 else: 545 con = common.xmpp.NonBlockingClient( 546 hostname=self._current_host['host'], 547 debug=[], 548 port=port, 549 caller=self, 550 idlequeue=gajim.idlequeue) 538 # there was: 539 # "if gajim.verbose:" 540 # here 541 con = clientClass( 542 domain=self._hostname, 543 caller=self, 544 idlequeue=gajim.idlequeue) 551 545 552 546 self.last_connection = con … … 556 550 if self.on_connect_success == self._on_new_account: 557 551 con.RegisterDisconnectHandler(self._on_new_account) 552 553 # FIXME: BOSH properties should be in proxy dictionary - loaded from 554 # config 555 if self._proxy and self._proxy['type'] == 'bosh': 556 self._proxy['bosh_hold'] = '1' 557 self._proxy['bosh_wait'] = '60' 558 558 559 559 560 log.info('Connecting to %s: [%s:%d]', self.name, 560 561 self._current_host['host'], port) 561 562 con.connect( 563 hostname=self._current_host['host'], 564 port=port, 562 565 on_connect=self.on_connect_success, 563 566 on_proxy_failure=self.on_proxy_failure, -
branches/bosh_support/src/common/xmpp/auth_nb.py
r9867 r9877 22 22 from client import PlugIn 23 23 import sha,base64,random,dispatcher_nb 24 25 import logging 26 log = logging.getLogger('gajim.c.x.auth_nb') 27 24 28 25 29 import md5 … … 129 133 if not feats.getTag('mechanisms', namespace=NS_SASL): 130 134 self.startsasl='not-supported' 131 self.DEBUG('SASL not supported by server', 'error')135 log.error('SASL not supported by server') 132 136 return 133 137 mecs=[] … … 146 150 else: 147 151 self.startsasl='failure' 148 self.DEBUG('I can only use DIGEST-MD5 and PLAIN mecanisms.', 'error')152 log.error('I can only use DIGEST-MD5 and PLAIN mecanisms.') 149 153 return 150 154 self.startsasl='in-process' … … 162 166 except: 163 167 reason = challenge 164 self.DEBUG('Failed SASL authentification: %s' % reason, 'error')168 log.error('Failed SASL authentification: %s' % reason) 165 169 if self.on_sasl : 166 170 self.on_sasl () … … 168 172 elif challenge.getName() == 'success': 169 173 self.startsasl='success' 170 self.DEBUG('Successfully authenticated with remote server.', 'ok')174 log.info('Successfully authenticated with remote server.') 171 175 handlers=self._owner.Dispatcher.dumpHandlers() 172 176 print '6' * 79 … … 183 187 incoming_data = challenge.getData() 184 188 data=base64.decodestring(incoming_data) 185 self.DEBUG('Got challenge:'+data,'ok')189 log.info('Got challenge:'+data) 186 190 chal = challenge_splitter(data) 187 191 if not self.realm and chal.has_key('realm'): … … 225 229 else: 226 230 self.startsasl='failure' 227 self.DEBUG('Failed SASL authentification: unknown challenge', 'error')231 log.error('Failed SASL authentification: unknown challenge') 228 232 if self.on_sasl : 229 233 self.on_sasl () … … 237 241 ''' Caches username, password and resource for auth. ''' 238 242 PlugIn.__init__(self) 239 self.DBG_LINE ='gen_auth'240 243 self.user = user 241 244 self.password= password … … 249 252 if not self.resource: 250 253 return self.authComponent(owner) 251 self.DEBUG('Querying server about possible auth methods', 'start')254 log.info('Querying server about possible auth methods') 252 255 self.owner = owner 253 256 … … 258 261 def _on_username(self, resp): 259 262 if not isResultNode(resp): 260 self.DEBUG('No result node arrived! Aborting...','error')263 log.error('No result node arrived! Aborting...') 261 264 return self.on_auth(None) 262 265 iq=Iq(typ='set',node=resp) … … 266 269 267 270 if query.getTag('digest'): 268 self.DEBUG("Performing digest authentication",'ok')271 log.info("Performing digest authentication") 269 272 query.setTagData('digest', 270 273 sha.new(self.owner.Dispatcher.Stream._document_attrs['id']+self.password).hexdigest()) … … 275 278 token=query.getTagData('token') 276 279 seq=query.getTagData('sequence') 277 self.DEBUG("Performing zero-k authentication",'ok')280 log.info("Performing zero-k authentication") 278 281 hash = sha.new(sha.new(self.password).hexdigest()+token).hexdigest() 279 282 for foo in xrange(int(seq)): … … 282 285 self._method='0k' 283 286 else: 284 self.DEBUG("Sequre methods unsupported, performing plain text authentication",'warn')287 log.warn("Sequre methods unsupported, performing plain text authentication") 285 288 query.setTagData('password',self.password) 286 289 self._method='plain' … … 289 292 def _on_auth(self, resp): 290 293 if isResultNode(resp): 291 self.DEBUG('Sucessfully authenticated with remove host.','ok')294 log.info('Sucessfully authenticated with remove host.') 292 295 self.owner.User=self.user 293 296 self.owner.Resource=self.resource 294 297 self.owner._registered_name=self.owner.User+'@'+self.owner.Server+'/'+self.owner.Resource 295 298 return self.on_auth(self._method) 296 self.DEBUG('Authentication failed!','error')299 log.error('Authentication failed!') 297 300 return self.on_auth(None) 298 301 … … 310 313 self.Dispatcher.ProcessNonBlocking(data) 311 314 if not self.handshake: 312 self.DEBUG('waiting on handshake', 'notify')315 log.info('waiting on handshake') 313 316 return 314 317 self._owner.onreceive(None) … … 330 333 def __init__(self): 331 334 PlugIn.__init__(self) 332 self.DBG_LINE='bind'333 335 self.bound=None 334 336 … … 337 339 if not feats.getTag('bind',namespace=NS_BIND): 338 340 self.bound='failure' 339 self.DEBUG('Server does not requested binding.','error')341 log.error('Server does not requested binding.') 340 342 return 341 343 if feats.getTag('session',namespace=NS_SESSION): self.session=1 … … 373 375 if isResultNode(resp): 374 376 self.bound.append(resp.getTag('bind').getTagData('jid')) 375 self.DEBUG('Successfully bound %s.'%self.bound[-1],'ok')377 log.info('Successfully bound %s.'%self.bound[-1]) 376 378 jid=JID(resp.getTag('bind').getTagData('jid')) 377 379 self._owner.User=jid.getNode() … … 380 382 payload=[Node('session', attrs={'xmlns':NS_SESSION})]), func=self._on_session) 381 383 elif resp: 382 self.DEBUG('Binding failed: %s.' % resp.getTag('error'),'error')384 log.error('Binding failed: %s.' % resp.getTag('error')) 383 385 self.on_bound(None) 384 386 else: 385 self.DEBUG('Binding failed: timeout expired.', 'error')387 log.error('Binding failed: timeout expired.') 386 388 self.on_bound(None) 387 389 … … 389 391 self._owner.onreceive(None) 390 392 if isResultNode(resp): 391 self.DEBUG('Successfully opened session.', 'ok')393 log.info('Successfully opened session.') 392 394 self.session = 1 393 395 self.on_bound('ok') 394 396 else: 395 self.DEBUG('Session open failed.', 'error')397 log.error('Session open failed.') 396 398 self.session = 0 397 399 self.on_bound(None) 398 400 self._owner.onreceive(None) 399 401 if isResultNode(resp): 400 self.DEBUG('Successfully opened session.', 'ok')402 log.info('Successfully opened session.') 401 403 self.session = 1 402 404 self.on_bound('ok') 403 405 else: 404 self.DEBUG('Session open failed.', 'error')406 log.error('Session open failed.') 405 407 self.session = 0 406 408 self.on_bound(None) … … 412 414 def __init__(self): 413 415 PlugIn.__init__(self) 414 self.DBG_LINE='bind'415 416 self.bound=None 416 417 self.needsUnregister=None … … 449 450 def _on_bind_reponse(self, res): 450 451 if resp and resp.getAttr('error'): 451 self.DEBUG('Binding failed: %s.' % resp.getAttr('error'), 'error')452 log.error('Binding failed: %s.' % resp.getAttr('error')) 452 453 elif resp: 453 self.DEBUG('Successfully bound.', 'ok')454 log.info('Successfully bound.') 454 455 if self.on_bind: 455 456 self.on_bind('ok') 456 457 else: 457 self.DEBUG('Binding failed: timeout expired.', 'error')458 log.error('Binding failed: timeout expired.') 458 459 if self.on_bind: 459 460 self.on_bind(None) … … 463 464 if not feats.getTag('bind',namespace=NS_BIND): 464 465 self.bound='failure' 465 self.DEBUG('Server does not requested binding.','error')466 log.error('Server does not requested binding.') 466 467 return 467 468 if feats.getTag('session',namespace=NS_SESSION): self.session=1 … … 474 475 resp=self._owner.SendAndWaitForResponse(Protocol('bind',attrs={'name':domain},xmlns=NS_COMPONENT_1)) 475 476 if resp and resp.getAttr('error'): 476 self.DEBUG('Binding failed: %s.'%resp.getAttr('error'),'error')477 log.error('Binding failed: %s.'%resp.getAttr('error')) 477 478 elif resp: 478 self.DEBUG('Successfully bound.','ok')479 log.info('Successfully bound.') 479 480 return 'ok' 480 481 else: 481 self.DEBUG('Binding failed: timeout expired.','error')482 log.error('Binding failed: timeout expired.') 482 483 return '' -
branches/bosh_support/src/common/xmpp/client_nb.py
r9870 r9877 23 23 24 24 import socket 25 import debug26 import random27 25 28 26 import transports_nb, tls_nb, dispatcher_nb, auth_nb, roster_nb, protocol … … 32 30 log = logging.getLogger('gajim.c.x.client_nb') 33 31 34 consoleloghandler = logging.StreamHandler()35 consoleloghandler.setLevel(logging.DEBUG)36 consoleloghandler.setFormatter(37 logging.Formatter('%(levelname)s: %(message)s')38 )39 log.setLevel(logging.DEBUG)40 log.addHandler(consoleloghandler)41 log.propagate = False42 43 32 44 33 class NBCommonClient: 45 34 ''' Base for Client and Component classes.''' 46 def __init__(self, hostname, idlequeue, port=5222, debug=['always', 'nodebuilder'], caller=None):35 def __init__(self, domain, idlequeue, caller=None): 47 36 48 37 ''' Caches connection data: 49 :param hostname: hostname of machine where the XMPP server is running (from Account 50 of from SRV request) and port to connect to. 38 :param domain: domain - for to: attribute (from account info) 51 39 :param idlequeue: processing idlequeue 52 40 :param port: port of listening XMPP server 53 :param debug: specifies the debug IDs that will go into debug output. You can either54 specifiy an "include" or "exclude" list. The latter is done via adding "always"55 pseudo-ID to the list. Full list: ['nodebuilder', 'dispatcher', 'gen_auth',56 'SASL_auth', 'bind', 'socket', 'CONNECTproxy', 'TLS', 'roster', 'browser', 'ibb'].57 TODO: get rid of debug.py using58 41 :param caller: calling object - it has to implement certain methods (necessary?) 59 42 60 43 ''' 61 44 62 self.DBG = DBG_CLIENT63 64 45 self.Namespace = protocol.NS_CLIENT 65 46 … … 68 49 self.disconnect_handlers = [] 69 50 70 # XMPP server and port from account or SRV 71 self.Server = hostname 72 self.Port = port 51 self.Server = domain 73 52 74 53 # caller is who initiated this client, it is sed to register the EventDispatcher 75 54 self._caller = caller 76 if debug and type(debug) != list:77 debug = ['always', 'nodebuilder']78 self._DEBUG = Debug.Debug(debug)79 self.DEBUG = self._DEBUG.Show80 self.debug_flags = self._DEBUG.debug_flags81 self.debug_flags.append(self.DBG)82 55 self._owner = self 83 56 self._registered_name = None … … 99 72 100 73 self.connected='' 101 self.DEBUG(self.DBG,'Disconnect detected','stop')74 log.debug('Client disconnected..') 102 75 for i in reversed(self.disconnect_handlers): 103 self.DEBUG(self.DBG, 'Calling disc handler %s' % i, 'stop')76 log.debug('Calling disconnect handler %s' % i) 104 77 i() 105 78 if self.__dict__.has_key('NonBlockingRoster'): … … 121 94 122 95 123 def send(self, stanza, is_message = False,now = False):96 def send(self, stanza, now = False): 124 97 ''' interface for putting stanzas on wire. Puts ID to stanza if needed and 125 98 sends it via socket wrapper''' 126 99 (id, stanza_to_send) = self.Dispatcher.assign_id(stanza) 127 100 128 if is_message: 129 # somehow zeroconf-specific 130 self.Connection.send(stanza_to_send, True, now = now) 131 else: 132 self.Connection.send(stanza_to_send, now = now) 101 self.Connection.send(stanza_to_send, now = now) 133 102 return id 134 103 135 104 136 105 137 def connect(self, on_connect, on_connect_failure, on_proxy_failure=None, proxy=None, secure=None): 106 def connect(self, on_connect, on_connect_failure, hostname=None, port=5222, 107 on_proxy_failure=None, proxy=None, secure=None): 138 108 ''' 139 109 Open XMPP connection (open streams in both directions). 110 :param hostname: hostname of XMPP server from SRV request 111 :param port: port number of XMPP server 140 112 :param on_connect: called after stream is successfully opened 141 113 :param on_connect_failure: called when error occures during connection … … 147 119 :param secure: 148 120 ''' 149 121 self.Port = port 122 if hostname: 123 xmpp_hostname = hostname 124 else: 125 xmpp_hostname = self.Server 126 150 127 self.on_connect = on_connect 151 128 self.on_connect_failure=on_connect_failure … … 156 133 if proxy: 157 134 # with proxies, client connects to proxy instead of directly to 158 # XMPP server from __init__.159 # tcp_server is hostname used for socket connecting135 # XMPP server ((hostname, port)) 136 # tcp_server is machine used for socket connection 160 137 tcp_server=proxy['host'] 161 138 tcp_port=proxy['port'] … … 169 146 type_ = proxy['type'] 170 147 if type_ == 'socks5': 148 # SOCKS5 proxy 171 149 self.socket = transports_nb.NBSOCKS5ProxySocket( 172 150 on_disconnect=self.on_disconnect, 173 151 proxy_creds=proxy_creds, 174 xmpp_server=( self.Server, self.Port))152 xmpp_server=(xmpp_hostname, self.Port)) 175 153 elif type_ == 'http': 154 # HTTP CONNECT to proxy 176 155 self.socket = transports_nb.NBHTTPProxySocket( 177 156 on_disconnect=self.on_disconnect, 178 157 proxy_creds=proxy_creds, 179 xmpp_server=( self.Server, self.Port))158 xmpp_server=(xmpp_hostname, self.Port)) 180 159 elif type_ == 'bosh': 160 # BOSH - XMPP over HTTP 181 161 tcp_server = transports_nb.urisplit(tcp_server)[1] 182 self.socket = transports_nb.NonBlockingH ttpBOSH(162 self.socket = transports_nb.NonBlockingHTTP( 183 163 on_disconnect=self.on_disconnect, 184 bosh_uri = proxy['host'],185 bosh_port = tcp_port)164 http_uri = proxy['host'], 165 http_port = tcp_port) 186 166 else: 187 167 # HTTP CONNECT to proxy from environment variables … … 189 169 on_disconnect=self.on_disconnect, 190 170 proxy_creds=(None, None), 191 xmpp_server=( self.Server, self.Port))171 xmpp_server=(xmpp_hostname, self.Port)) 192 172 else: 193 173 self._on_tcp_failure = self._on_connect_failure 194 tcp_server= self.Server174 tcp_server=xmpp_hostname 195 175 tcp_port=self.Port 196 176 self.socket = transports_nb.NonBlockingTcp(on_disconnect = self.on_disconnect) … … 222 202 '''iterates over IP addresses from getaddinfo''' 223 203 if err_message: 224 self.DEBUG(self.DBG,err_message,'connect')204 log.debug('While looping over DNS A records: %s' % connect) 225 205 if self.ip_addresses == []: 226 206 self._on_tcp_failure(err_message='Run out of hosts for name %s:%s' % … … 306 286 self.connected = None 307 287 if err_message: 308 self.DEBUG(self.DBG, err_message, 'connecting')288 log.debug('While connecting: %s' % err_message) 309 289 if self.socket: 310 290 self.socket.disconnect() … … 461 441 462 442 463 class BOSHClient(NBCommonClient):464 '''465 Client class implementing BOSH.466 '''467 def __init__(self, *args, **kw):468 '''Preceeds constructor of NBCommonClient and sets some of values that will469 be used as attributes in <body> tag'''470 self.Namespace = NS_HTTP_BIND471 # BOSH parameters should be given via Advanced Configuration Editor472 self.bosh_hold = 1473 se
