From 7194260f9803002afcc48ed5c6f93f8fef5cb656 Mon Sep 17 00:00:00 2001
From: Jefry Lagrange <jefry.reyes@gmail.com>
Date: Tue, 7 Jun 2011 18:48:53 -0400
Subject: [PATCH] connects when server can't resume stream

---
 src/common/xmpp/dispatcher_nb.py |  2 +-
 src/common/xmpp/smacks.py        | 32 +++++++++++++++++++++++---------
 2 files changed, 24 insertions(+), 10 deletions(-)

diff --git a/src/common/xmpp/dispatcher_nb.py b/src/common/xmpp/dispatcher_nb.py
index d3f5b7cb36..ca321e8783 100644
--- a/src/common/xmpp/dispatcher_nb.py
+++ b/src/common/xmpp/dispatcher_nb.py
@@ -535,7 +535,7 @@ class XMPPDispatcher(PlugIn):
                 if self._owner._registered_name and not stanza.getAttr('from'):
                     stanza.setAttr('from', self._owner._registered_name)
                     
-        if self.sm:
+        if self.sm and self.sm.enabled:
             self.sm.uqueue.append(stanza)
             self.sm.out_h = self.sm.out_h + 1
             if len(self.sm.uqueue) > self.sm.max_queue:
diff --git a/src/common/xmpp/smacks.py b/src/common/xmpp/smacks.py
index 9f360cd65c..c0fa77c0ea 100644
--- a/src/common/xmpp/smacks.py
+++ b/src/common/xmpp/smacks.py
@@ -24,7 +24,8 @@ class Smacks():
         self.max_queue = 5  
         self._owner = None
         self.resuming = False
-    
+        self.enabled = False # If SM is enabled 
+        
     def set_owner(self, owner):
         self._owner = owner
         
@@ -50,6 +51,8 @@ class Smacks():
         
         if r == 'false' or r == 'False' or r == '0':
             self.negociate(False)
+            
+        self.enabled = True
 
     def negociate(self, resume=True):
         # Every time we attempt to negociate, we must erase all previous info
@@ -69,7 +72,7 @@ class Smacks():
             log.error('Attempted to resume without a valid session id ')
             return
         resume = Acks()
-        resume.buildResume(self.in_h, self.session_id)
+        resume.buildResume(self.in_h, None)#self.session_id)
         self._owner.Connection.send(resume, True)            
     
     def send_ack(self, disp, stanza):
@@ -105,17 +108,28 @@ class Smacks():
                 for i in self.uqueue:
                     self._owner.Connection.send(i, False)
             
-    def error_handling(self, disp, stanza): # NEEDS TESTING
+    def error_handling(self, disp, stanza):
         
-        tag = stanza.getTag('item-not-found')
         # If the server doesn't recognize previd, forget about resuming
         # Ask for service discovery, etc..
-        if tag: 
-            self.negociate()
+        if stanza.getTag('item-not-found'): 
+            self.enabled = False
             self.resuming = False
+            self.negociate()
             self.con._discover_server_at_connection(self.con.connection)
+            return
         
-        tag = stanza.getTag('feature-not-implemented')
         # Doesn't support resumption
-        if tag:
-            self.negociate(False)
\ No newline at end of file
+        if stanza.getTag('feature-not-implemented'):
+            self.enabled = False
+            self.negociate(False)
+            return
+        
+        if stanza.getTag('unexpected-request'):
+            self.enabled = False
+            log.error('Gajim failed to negociate Stream Management')
+            return
+        
+
+
+        
\ No newline at end of file
-- 
GitLab