Ticket #3083: stream-dropping-unbound-xmlns-prefix-fix.patch

File stream-dropping-unbound-xmlns-prefix-fix.patch, 2.5 kB (added by bct, 5 months ago)
  • src/common/xmpp/dispatcher_nb.py

    diff --git a/src/common/xmpp/dispatcher_nb.py b/src/common/xmpp/dispatcher_nb.py
    index 515a09d..4f982d9 100644
    a b  
    126126                        1) length of processed data if some data were processed; 
    127127                        2) '0' string if no data were processed but link is alive; 
    128128                        3) 0 (zero) if underlying connection is closed.''' 
     129 
     130                # XXX UNBOUND NAMESPACE PREFIX HACK XXX 
     131                if not hasattr(self, 'drop_chars_until_we_get_an_end_tag_named'): 
     132                        self.drop_chars_until_we_get_an_end_tag_named = None 
     133 
     134                if self.drop_chars_until_we_get_an_end_tag_named: 
     135                        self.buffer += data 
     136 
     137                        import re 
     138                        seeker = re.compile('</'+self.drop_chars_until_we_get_an_end_tag_named+'>') 
     139                        match = seeker.search(self.buffer) 
     140 
     141                        if match: 
     142                                # found the stanza end tag. drop everything before it and continue 
     143                                data = self.buffer[match.end():] 
     144                                self.drop_chars_until_we_get_an_end_tag_named = None 
     145                                self.buffer = '' 
     146 
     147                                self.Stream = simplexml.NodeBuilder() 
     148                                self.Stream._dispatch_depth = 2 
     149                                self.Stream.dispatch = self.dispatch 
     150                                self.Stream.stream_header_received = self._check_stream_start 
     151                                self._owner.debug_flags.append(simplexml.DBG_NODEBUILDER) 
     152                                self.Stream.DEBUG = self._owner.DEBUG 
     153                                self.Stream.features = None 
     154 
     155                                self.Stream.Parse("<stream:stream xmlns:stream='http://etherx.jabber.org/streams' xmlns='jabber:client'>") 
     156                        else: 
     157                                return len(data) 
     158 
     159                # END HACK 
     160 
    129161                for handler in self._cycleHandlers:  
    130162                        handler(self) 
    131163                if len(self._pendingExceptions) > 0: 
     
    138170                                self._owner.Connection.disconnect() 
    139171                                return 0 
    140172                except ExpatError: 
    141                         self.DEBUG('Invalid XML received from server. Forcing disconnect.', 'error') 
    142                         self._owner.Connection.pollend() 
    143                         return 0 
     173                        # XXX THIS IS A TEMPORARY FIX XXX 
     174                        # XXX SINCE SOME SERVERS WILL ACCEPT MESSAGES WITH UNBOUND NAMESPACE PREFIXES XXX 
     175 
     176                        # dropping parts of the stream is *not* a long-term solution 
     177 
     178                        self.DEBUG('Invalid XML received from server. Hackishly trying to recover.', 'error') 
     179 
     180                        self.drop_chars_until_we_get_an_end_tag_named = self.Stream._mini_dom.name 
     181 
     182                        self.buffer = data 
     183 
     184                        return len(data) 
     185 
     186                        # END HACK 
     187 
     188                        # XXX uncomment this when we're no longer hacking around this issue XXX 
     189                        #self._owner.Connection.pollend() 
     190                        #return 0 
    144191                if len(self._pendingExceptions) > 0: 
    145192                         _pendingException = self._pendingExceptions.pop() 
    146193                         raise _pendingException[0], _pendingException[1], _pendingException[2]