~jtaylor/ubuntu/oneiric/gajim/multiple-CVE

« back to all changes in this revision

Viewing changes to src/common/xmpp/transports_nb.py

  • Committer: Bazaar Package Importer
  • Author(s): Nafallo Bjälevik
  • Date: 2009-06-12 13:49:19 UTC
  • mto: (1.5.1 squeeze)
  • mto: This revision was merged to the branch mainline in revision 40.
  • Revision ID: james.westby@ubuntu.com-20090612134919-q5i1vj7b4pubx281
Tags: upstream-0.12.2
Import upstream version 0.12.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
243
243
                IdleObject.__init__(self)
244
244
                PlugIn.__init__(self)
245
245
                self.DBG_LINE='socket'
246
 
                self._exported_methods=[self.send, self.disconnect, self.onreceive, self.set_send_timeout, 
247
 
                        self.start_disconnect, self.set_timeout, self.remove_timeout]
 
246
                self._exported_methods=[self.send, self.disconnect, self.onreceive,
 
247
                        self.set_send_timeout, self.set_send_timeout2, self.start_disconnect,
 
248
                        self.set_timeout, self.remove_timeout]
248
249
                self._server = server
249
250
                self._hostfqdn = server[0]
250
251
                self.on_connect  = on_connect
267
268
                
268
269
                # time to wait for SOME stanza to come and then send keepalive
269
270
                self.sendtimeout = 0
 
271
                self.sendtimeout2 = 0
270
272
                
271
273
                # in case we want to something different than sending keepalives
272
274
                self.on_timeout = None
 
275
                self.on_timeout2 = None
273
276
                
274
277
                # writable, readable  -  keep state of the last pluged flags
275
278
                # This prevents replug of same object with the same flags
288
291
                if self.connect(self._server) is False:
289
292
                        return False
290
293
                return True
291
 
                
 
294
 
292
295
        def read_timeout(self):
293
296
                if self.state == 0:
294
297
                        self.idlequeue.unplug_idle(self.fd)
299
302
                                self.on_timeout()
300
303
                        self.renew_send_timeout()
301
304
 
 
305
        def read_timeout2(self):
 
306
                if self.on_timeout2:
 
307
                        self.on_timeout2()
 
308
                self.renew_send_timeout2()
 
309
 
302
310
        def connect(self,server=None, proxy = None, secure = None):
303
311
                ''' Try to establish connection. '''
304
312
                if not server:
408
416
        def set_timeout(self, timeout):
409
417
                if self.state >= 0 and self.fd > 0:
410
418
                        self.idlequeue.set_read_timeout(self.fd, timeout)
 
419
 
 
420
        def set_timeout2(self, timeout2):
 
421
                if self.state >= 0 and self.fd > 0:
 
422
                        self.idlequeue.set_read_timeout(self.fd, timeout2, self.read_timeout2)
411
423
        
412
424
        def remove_timeout(self):
413
425
                if self.fd:
466
478
                        errtxt = "Connection closed unexpectedly"
467
479
 
468
480
                if errnum in (ERR_DISCONN, errno.ECONNRESET, errno.ENOTCONN, errno.ESHUTDOWN):
469
 
                        log.error("Connection to %s lost: %s [%d]", self.getName(), errtxt, errnum)
 
481
                        log.info("Connection to %s lost: %s [%d]", self.getName(), errtxt, errnum)
470
482
                        self.printed_error = True
471
483
                        if not errors_only:
472
484
                                self.pollend(retry=(errnum in (ERR_DISCONN, errno.ECONNRESET)))
481
493
                                return
482
494
                        elif errnum != 0:
483
495
                                self.DEBUG(errtxt, 'error')
484
 
                                log.error("Connection to %s lost: %s [%d]", self.getName(), errtxt, errnum)
 
496
                                log.info("Connection to %s lost: %s [%d]", self.getName(), errtxt, errnum)
485
497
                                self._owner.disconnected()
486
498
                                self.printed_error = True
487
499
                                if not errors_only and self.state >= 0:
493
505
                        return
494
506
 
495
507
                # we have received some bites, stop the timeout!
 
508
                self.remove_timeout()
496
509
                self.renew_send_timeout()
 
510
                self.renew_send_timeout2()
497
511
                if self.on_receive:
498
512
                        if received.strip():
499
 
                                self.DEBUG(received, 'got')
 
513
                                log.info("Got: %s", received)
500
514
                        if hasattr(self._owner, 'Dispatcher'):
501
515
                                self._owner.Dispatcher.Event('', DATA_RECEIVED, received)
502
516
                        self.on_receive(received)
643
657
                        self.on_timeout = on_timeout
644
658
                else:
645
659
                        self.on_timeout = None
646
 
        
 
660
 
 
661
        def set_send_timeout2(self, timeout2, on_timeout2):
 
662
                self.sendtimeout2 = timeout2
 
663
                if self.sendtimeout2 > 0:
 
664
                        self.on_timeout2 = on_timeout2
 
665
                else:
 
666
                        self.on_timeout2 = None
 
667
 
647
668
        def renew_send_timeout(self):
648
669
                if self.on_timeout and self.sendtimeout > 0:
649
670
                        self.set_timeout(self.sendtimeout)
650
 
                else:
651
 
                        self.remove_timeout()
652
 
        
 
671
 
 
672
        def renew_send_timeout2(self):
 
673
                if self.on_timeout2 and self.sendtimeout2 > 0:
 
674
                        self.set_timeout2(self.sendtimeout2)
 
675
 
653
676
        def getHost(self):
654
677
                ''' Return the 'host' value that is connection is [will be] made to.'''
655
678
                return self._server[0]
1088
1111
                        return
1089
1112
                if reply[1] != "\x00":
1090
1113
                        # Connection failed
1091
 
                        self._owner.disconnected()
1092
1114
                        if ord(reply[1])<9:
1093
1115
                                errors = ['general SOCKS server failure',
1094
1116
                                        'connection not allowed by ruleset',
1103
1125
                        else:
1104
1126
                                txt = 'Invalid proxy reply'
1105
1127
                        self.DEBUG(txt, 'error')
 
1128
                        self._owner.disconnected()
1106
1129
                        self.on_proxy_failure(txt)
1107
1130
                        return
1108
1131
                # Get the bound address/port