Report the original stream:error stanza to clients.
[punjab-krb5-preauth] / punjab / session.py
index a01d076..0bb58a5 100644 (file)
@@ -22,6 +22,11 @@ from punjab.xmpp import ns
 import time
 import error
 
+try:
+    from twisted.internet import ssl
+except ImportError:
+    log.msg("SSL ERROR: You do not have ssl support this may cause problems with tls client connections.")
+
 
 
 class XMPPClientConnector(SRVConnector):
@@ -78,16 +83,17 @@ def make_session(pint, attrs, session_type='BOSH'):
         s.authenticator.useTls = 1
     else:
         s.authenticator.useTls = 0
-        # reactor.connectTCP(s.hostname, s.port, s)
+
     if pint.v:
-        log.msg('================================== %s connect ==================================' % (str(time.time()),))
+        log.msg('================================== %s connect to %s:%s ==================================' % (str(time.time()),s.hostname,s.port))
+        
     connect_srv = True
     if attrs.has_key('route'):
         connect_srv = False
     if s.hostname in ['localhost', '127.0.0.1']:
         connect_srv = False
     if not connect_srv:
-        reactor.connectTCP(s.hostname, s.port, s)
+        reactor.connectTCP(s.hostname, s.port, s, bindAddress=pint.bindAddress)
     else:
         connector = XMPPClientConnector(reactor, s.hostname, s)
         connector.connect()
@@ -169,6 +175,7 @@ class Session(jabber.JabberClientFactory, server.Session):
         
         self.cache_data = {}
         self.verbose    = self.pint.v
+        self.noisy      = self.verbose
 
         self.version = attrs.get('version', 0.0)
                 
@@ -236,7 +243,7 @@ class Session(jabber.JabberClientFactory, server.Session):
         """ Log incoming data on the xmlstream """
         if self.pint.v:
             try:
-                log.msg("SID: %s => RECV: %s" % (self.sid, unicode(buf, 'utf-8').encode('ascii', 'replace')))
+                log.msg("SID: %s => RECV: %r" % (self.sid, buf,))
             except:
                 log.err()
         if self.use_raw and self.authid:
@@ -249,7 +256,7 @@ class Session(jabber.JabberClientFactory, server.Session):
     def rawDataOut(self, buf):
         """ Log outgoing data on the xmlstream """
         try:
-            log.msg("SID: %s => SEND: %s" % (self.sid, unicode(buf, 'utf-8').encode('ascii', 'replace')))
+            log.msg("SID: %s => SEND: %r" % (self.sid, buf,))
         except:
             log.err()
 
@@ -303,6 +310,7 @@ class Session(jabber.JabberClientFactory, server.Session):
         if self.verbose and not getattr(self, 'terminated', False):
             log.msg(self.sid)
             log.msg(self.rid)
+            log.msg(self.waiting_requests)
             log.msg('SESSION -> We have expired')
         self.disconnect()
     
@@ -335,7 +343,6 @@ class Session(jabber.JabberClientFactory, server.Session):
         request by returning a deferred which will get called back
         when there is data or when the wait timeout expires.
         """
-        
         # queue this request
         if d is None:
             d = defer.Deferred()
@@ -344,10 +351,9 @@ class Session(jabber.JabberClientFactory, server.Session):
         if not rid:
             rid = self.rid - 1
         self.appendWaitingRequest(d, rid)
-
         # check if there is any data to send back to a request
         self.returnWaitingRequests()
-
+        
         # make sure we aren't queueing too many requests
         self.clearWaitingRequests(self.hold)
         return d
@@ -452,6 +458,9 @@ class Session(jabber.JabberClientFactory, server.Session):
         # If we get tls, then we should start tls, wait and then return
         # Here we wait, the tls initializer will start it
         if starttls and self.secure:
+            if self.verbose:
+                log.msg("Wait until starttls is completed.")
+                log.msg(initializers)
             return
         self.elems.append(f)
         if len(self.waiting_requests) > 0:
@@ -508,11 +517,7 @@ class Session(jabber.JabberClientFactory, server.Session):
     def streamError(self, streamerror):
         """called when we get a stream:error stanza"""
         
-        try: # a workaround for a bug in twisted.words.protocols.jabber.error
-            err_elem = streamerror.value.getElement()
-            err_elem.toXml()
-        except: # no matter what the exception we just return None
-            err_elem = None
+        err_elem = getattr(streamerror.value, "element")
 
         e = self.buildRemoteError(err_elem)
         do_expire = True