Changeset 9877

Show
Ignore:
Timestamp:
07/03/08 01:29:10 (2 months ago)
Author:
tomk
Message:

moved bosh code from client_nb.py to bosh.py, replaced debug logging with debug.py by logging in whole xmpppy (debug.py is now unused)

Location:
branches/bosh_support/src
Files:
1 added
12 modified

Legend:

Unmodified
Added
Removed
  • branches/bosh_support/src/common/connection.py

    r9867 r9877  
    209209        def _disconnectedReconnCB(self): 
    210210                '''Called when we are disconnected''' 
    211                 log.error('disconnectedReconnCB') 
     211                log.info('disconnectedReconnCB called') 
    212212                if gajim.account_is_connected(self.name): 
    213213                        # we cannot change our status to offline or connecting 
     
    532532 
    533533                        if self._proxy and self._proxy['type'] == 'bosh':  
    534                                 clientClass = common.xmpp.BOSHClient 
     534                                clientClass = common.xmpp.bosh.BOSHClient 
    535535                        else: 
    536536                                clientClass = common.xmpp.NonBlockingClient 
    537537 
    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) 
    551545 
    552546                        self.last_connection = con 
     
    556550                        if self.on_connect_success == self._on_new_account: 
    557551                                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 
    558559                         
    559560                        log.info('Connecting to %s: [%s:%d]', self.name, 
    560561                                self._current_host['host'], port) 
    561562                        con.connect( 
     563                                hostname=self._current_host['host'], 
     564                                port=port, 
    562565                                on_connect=self.on_connect_success, 
    563566                                on_proxy_failure=self.on_proxy_failure, 
  • branches/bosh_support/src/common/xmpp/auth_nb.py

    r9867 r9877  
    2222from client import PlugIn 
    2323import sha,base64,random,dispatcher_nb 
     24 
     25import logging 
     26log = logging.getLogger('gajim.c.x.auth_nb') 
     27 
    2428 
    2529import md5 
     
    129133                if not feats.getTag('mechanisms', namespace=NS_SASL): 
    130134                        self.startsasl='not-supported' 
    131                         self.DEBUG('SASL not supported by server', 'error') 
     135                        log.error('SASL not supported by server') 
    132136                        return 
    133137                mecs=[] 
     
    146150                else: 
    147151                        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.') 
    149153                        return 
    150154                self.startsasl='in-process' 
     
    162166                        except:  
    163167                                reason = challenge 
    164                         self.DEBUG('Failed SASL authentification: %s' % reason, 'error') 
     168                        log.error('Failed SASL authentification: %s' % reason) 
    165169                        if self.on_sasl : 
    166170                                self.on_sasl () 
     
    168172                elif challenge.getName() == 'success': 
    169173                        self.startsasl='success' 
    170                         self.DEBUG('Successfully authenticated with remote server.', 'ok') 
     174                        log.info('Successfully authenticated with remote server.') 
    171175                        handlers=self._owner.Dispatcher.dumpHandlers() 
    172176                        print '6' * 79 
     
    183187                incoming_data = challenge.getData() 
    184188                data=base64.decodestring(incoming_data) 
    185                 self.DEBUG('Got challenge:'+data,'ok') 
     189                log.info('Got challenge:'+data) 
    186190                chal = challenge_splitter(data) 
    187191                if not self.realm and chal.has_key('realm'): 
     
    225229                else:  
    226230                        self.startsasl='failure' 
    227                         self.DEBUG('Failed SASL authentification: unknown challenge', 'error') 
     231                        log.error('Failed SASL authentification: unknown challenge') 
    228232                if self.on_sasl : 
    229233                                self.on_sasl () 
     
    237241                ''' Caches username, password and resource for auth. ''' 
    238242                PlugIn.__init__(self) 
    239                 self.DBG_LINE ='gen_auth' 
    240243                self.user = user 
    241244                self.password= password 
     
    249252                if not self.resource:  
    250253                        return self.authComponent(owner) 
    251                 self.DEBUG('Querying server about possible auth methods', 'start') 
     254                log.info('Querying server about possible auth methods') 
    252255                self.owner = owner  
    253256                 
     
    258261        def _on_username(self, resp): 
    259262                if not isResultNode(resp): 
    260                         self.DEBUG('No result node arrived! Aborting...','error') 
     263                        log.error('No result node arrived! Aborting...') 
    261264                        return self.on_auth(None) 
    262265                iq=Iq(typ='set',node=resp) 
     
    266269 
    267270                if query.getTag('digest'): 
    268                         self.DEBUG("Performing digest authentication",'ok') 
     271                        log.info("Performing digest authentication") 
    269272                        query.setTagData('digest',  
    270273                                sha.new(self.owner.Dispatcher.Stream._document_attrs['id']+self.password).hexdigest()) 
     
    275278                        token=query.getTagData('token') 
    276279                        seq=query.getTagData('sequence') 
    277                         self.DEBUG("Performing zero-k authentication",'ok') 
     280                        log.info("Performing zero-k authentication") 
    278281                        hash = sha.new(sha.new(self.password).hexdigest()+token).hexdigest() 
    279282                        for foo in xrange(int(seq)):  
     
    282285                        self._method='0k' 
    283286                else: 
    284                         self.DEBUG("Sequre methods unsupported, performing plain text authentication",'warn') 
     287                        log.warn("Sequre methods unsupported, performing plain text authentication") 
    285288                        query.setTagData('password',self.password) 
    286289                        self._method='plain' 
     
    289292        def _on_auth(self, resp): 
    290293                if isResultNode(resp): 
    291                         self.DEBUG('Sucessfully authenticated with remove host.','ok') 
     294                        log.info('Sucessfully authenticated with remove host.') 
    292295                        self.owner.User=self.user 
    293296                        self.owner.Resource=self.resource 
    294297                        self.owner._registered_name=self.owner.User+'@'+self.owner.Server+'/'+self.owner.Resource 
    295298                        return self.on_auth(self._method) 
    296                 self.DEBUG('Authentication failed!','error') 
     299                log.error('Authentication failed!') 
    297300                return self.on_auth(None) 
    298301 
     
    310313                        self.Dispatcher.ProcessNonBlocking(data) 
    311314                if not self.handshake: 
    312                         self.DEBUG('waiting on handshake', 'notify') 
     315                        log.info('waiting on handshake') 
    313316                        return 
    314317                self._owner.onreceive(None) 
     
    330333        def __init__(self): 
    331334                PlugIn.__init__(self) 
    332                 self.DBG_LINE='bind' 
    333335                self.bound=None 
    334336 
     
    337339                if not feats.getTag('bind',namespace=NS_BIND): 
    338340                        self.bound='failure' 
    339                         self.DEBUG('Server does not requested binding.','error') 
     341                        log.error('Server does not requested binding.') 
    340342                        return 
    341343                if feats.getTag('session',namespace=NS_SESSION): self.session=1 
     
    373375                if isResultNode(resp): 
    374376                        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]) 
    376378                        jid=JID(resp.getTag('bind').getTagData('jid')) 
    377379                        self._owner.User=jid.getNode() 
     
    380382                                payload=[Node('session', attrs={'xmlns':NS_SESSION})]), func=self._on_session) 
    381383                elif resp: 
    382                         self.DEBUG('Binding failed: %s.' % resp.getTag('error'),'error') 
     384                        log.error('Binding failed: %s.' % resp.getTag('error')) 
    383385                        self.on_bound(None) 
    384386                else: 
    385                         self.DEBUG('Binding failed: timeout expired.', 'error') 
     387                        log.error('Binding failed: timeout expired.') 
    386388                        self.on_bound(None) 
    387389                         
     
    389391                self._owner.onreceive(None) 
    390392                if isResultNode(resp): 
    391                         self.DEBUG('Successfully opened session.', 'ok') 
     393                        log.info('Successfully opened session.') 
    392394                        self.session = 1 
    393395                        self.on_bound('ok') 
    394396                else: 
    395                         self.DEBUG('Session open failed.', 'error') 
     397                        log.error('Session open failed.') 
    396398                        self.session = 0 
    397399                        self.on_bound(None) 
    398400                self._owner.onreceive(None) 
    399401                if isResultNode(resp): 
    400                         self.DEBUG('Successfully opened session.', 'ok') 
     402                        log.info('Successfully opened session.') 
    401403                        self.session = 1 
    402404                        self.on_bound('ok') 
    403405                else: 
    404                         self.DEBUG('Session open failed.', 'error') 
     406                        log.error('Session open failed.') 
    405407                        self.session = 0 
    406408                        self.on_bound(None) 
     
    412414        def __init__(self): 
    413415                PlugIn.__init__(self) 
    414                 self.DBG_LINE='bind' 
    415416                self.bound=None 
    416417                self.needsUnregister=None 
     
    449450        def _on_bind_reponse(self, res): 
    450451                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')) 
    452453                elif resp: 
    453                         self.DEBUG('Successfully bound.', 'ok') 
     454                        log.info('Successfully bound.') 
    454455                        if self.on_bind: 
    455456                                self.on_bind('ok') 
    456457                else: 
    457                         self.DEBUG('Binding failed: timeout expired.', 'error') 
     458                        log.error('Binding failed: timeout expired.') 
    458459                if self.on_bind: 
    459460                        self.on_bind(None) 
     
    463464                if not feats.getTag('bind',namespace=NS_BIND): 
    464465                        self.bound='failure' 
    465                         self.DEBUG('Server does not requested binding.','error') 
     466                        log.error('Server does not requested binding.') 
    466467                        return 
    467468                if feats.getTag('session',namespace=NS_SESSION): self.session=1 
     
    474475                resp=self._owner.SendAndWaitForResponse(Protocol('bind',attrs={'name':domain},xmlns=NS_COMPONENT_1)) 
    475476                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')) 
    477478                elif resp: 
    478                         self.DEBUG('Successfully bound.','ok') 
     479                        log.info('Successfully bound.') 
    479480                        return 'ok' 
    480481                else: 
    481                         self.DEBUG('Binding failed: timeout expired.','error') 
     482                        log.error('Binding failed: timeout expired.') 
    482483                        return '' 
  • branches/bosh_support/src/common/xmpp/client_nb.py

    r9870 r9877  
    2323 
    2424import socket 
    25 import debug 
    26 import random 
    2725 
    2826import transports_nb, tls_nb, dispatcher_nb, auth_nb, roster_nb, protocol 
     
    3230log = logging.getLogger('gajim.c.x.client_nb') 
    3331 
    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 = False 
    42  
    4332 
    4433class NBCommonClient: 
    4534        ''' 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): 
    4736                 
    4837                ''' 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) 
    5139                :param idlequeue: processing idlequeue 
    5240                :param port: port of listening XMPP server 
    53                 :param debug: specifies the debug IDs that will go into debug output. You can either 
    54                         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 using 
    5841                :param caller: calling object - it has to implement certain methods (necessary?) 
    5942                         
    6043                ''' 
    6144                 
    62                 self.DBG = DBG_CLIENT 
    63  
    6445                self.Namespace = protocol.NS_CLIENT 
    6546 
     
    6849                self.disconnect_handlers = [] 
    6950 
    70                 # XMPP server and port from account or SRV 
    71                 self.Server = hostname 
    72                 self.Port = port 
     51                self.Server = domain 
    7352                 
    7453                # caller is who initiated this client, it is sed to register the EventDispatcher 
    7554                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.Show 
    80                 self.debug_flags = self._DEBUG.debug_flags 
    81                 self.debug_flags.append(self.DBG) 
    8255                self._owner = self 
    8356                self._registered_name = None 
     
    9972                 
    10073                self.connected='' 
    101                 self.DEBUG(self.DBG,'Disconnect detected','stop') 
     74                log.debug('Client disconnected..') 
    10275                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) 
    10477                        i() 
    10578                if self.__dict__.has_key('NonBlockingRoster'): 
     
    12194                 
    12295 
    123         def send(self, stanza, is_message = False, now = False): 
     96        def send(self, stanza, now = False): 
    12497                ''' interface for putting stanzas on wire. Puts ID to stanza if needed and 
    12598                sends it via socket wrapper''' 
    12699                (id, stanza_to_send) = self.Dispatcher.assign_id(stanza) 
    127100 
    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) 
    133102                return id 
    134103 
    135104 
    136105 
    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): 
    138108                '''  
    139109                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 
    140112                :param on_connect: called after stream is successfully opened 
    141113                :param on_connect_failure: called when error occures during connection 
     
    147119                :param secure: 
    148120                ''' 
    149                  
     121                self.Port = port 
     122                if hostname: 
     123                        xmpp_hostname = hostname 
     124                else: 
     125                        xmpp_hostname = self.Server 
     126 
    150127                self.on_connect = on_connect 
    151128                self.on_connect_failure=on_connect_failure 
     
    156133                if proxy: 
    157134                        # with proxies, client connects to proxy instead of directly to 
    158                         # XMPP server from __init__.  
    159                         # tcp_server is hostname used for socket connecting 
     135                        # XMPP server ((hostname, port)) 
     136                        # tcp_server is machine used for socket connection 
    160137                        tcp_server=proxy['host']                         
    161138                        tcp_port=proxy['port'] 
     
    169146                                type_ = proxy['type'] 
    170147                                if type_ == 'socks5': 
     148                                        # SOCKS5 proxy 
    171149                                        self.socket = transports_nb.NBSOCKS5ProxySocket( 
    172150                                                on_disconnect=self.on_disconnect, 
    173151                                                proxy_creds=proxy_creds, 
    174                                                 xmpp_server=(self.Server, self.Port)) 
     152                                                xmpp_server=(xmpp_hostname, self.Port)) 
    175153                                elif type_ == 'http': 
     154                                        # HTTP CONNECT to proxy 
    176155                                        self.socket = transports_nb.NBHTTPProxySocket( 
    177156                                                on_disconnect=self.on_disconnect, 
    178157                                                proxy_creds=proxy_creds, 
    179                                                 xmpp_server=(self.Server, self.Port)) 
     158                                                xmpp_server=(xmpp_hostname, self.Port)) 
    180159                                elif type_ == 'bosh': 
     160                                        # BOSH - XMPP over HTTP 
    181161                                        tcp_server = transports_nb.urisplit(tcp_server)[1] 
    182                                         self.socket = transports_nb.NonBlockingHttpBOSH( 
     162                                        self.socket = transports_nb.NonBlockingHTTP( 
    183163                                                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) 
    186166                        else: 
    187167                                # HTTP CONNECT to proxy from environment variables 
     
    189169                                        on_disconnect=self.on_disconnect, 
    190170                                        proxy_creds=(None, None), 
    191                                         xmpp_server=(self.Server, self.Port)) 
     171                                        xmpp_server=(xmpp_hostname, self.Port)) 
    192172                else:  
    193173                        self._on_tcp_failure = self._on_connect_failure 
    194                         tcp_server=self.Server 
     174                        tcp_server=xmpp_hostname 
    195175                        tcp_port=self.Port 
    196176                        self.socket = transports_nb.NonBlockingTcp(on_disconnect = self.on_disconnect) 
     
    222202                '''iterates over IP addresses from getaddinfo''' 
    223203                if err_message: 
    224                         self.DEBUG(self.DBG,err_message,'connect') 
     204                        log.debug('While looping over DNS A records: %s' % connect) 
    225205                if self.ip_addresses == []: 
    226206                        self._on_tcp_failure(err_message='Run out of hosts for name %s:%s' %  
     
    306286                self.connected = None 
    307287                if err_message: 
    308                         self.DEBUG(self.DBG, err_message, 'connecting') 
     288                        log.debug('While connecting: %s' % err_message) 
    309289                if self.socket: 
    310290                        self.socket.disconnect() 
     
    461441 
    462442 
    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 will 
    469                 be used as attributes in <body> tag''' 
    470                 self.Namespace = NS_HTTP_BIND 
    471                 # BOSH parameters should be given via Advanced Configuration Editor 
    472                 self.bosh_hold = 1 
    473                 se