From 7d12dbcc653dccbdbe5ac24a3231410b3bd71769 Mon Sep 17 00:00:00 2001 From: Yann Leboulanger Date: Tue, 18 Sep 2012 16:07:11 +0200 Subject: [PATCH] decrypt GPG messages one after the other. Fixes #7229 --- src/common/connection_handlers.py | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/src/common/connection_handlers.py b/src/common/connection_handlers.py index 9953e2dbc..2354cdcc9 100644 --- a/src/common/connection_handlers.py +++ b/src/common/connection_handlers.py @@ -767,6 +767,9 @@ class ConnectionHandlersBase: # keep track of sessions this connection has with other JIDs self.sessions = {} + # We decrypt GPG messages one after the other. Keep queue in mem + self.gpg_messages_to_decrypt = [] + gajim.ged.register_event_handler('iq-error-received', ged.CORE, self._nec_iq_error_received) gajim.ged.register_event_handler('presence-received', ged.CORE, @@ -965,6 +968,14 @@ class ConnectionHandlersBase: if sess.enable_encryption: sess.terminate_e2e() + def decrypt_thread(encmsg, keyID, obj): + decmsg = self.gpg.decrypt(encmsg, keyID) + decmsg = self.connection.Dispatcher.replace_non_character(decmsg) + # \x00 chars are not allowed in C (so in GTK) + obj.msgtxt = helpers.decode_string(decmsg.replace('\x00', '')) + obj.encrypted = 'xep27' + self.gpg_messages_to_decrypt.remove([encmsg, keyID, obj]) + def _nec_message_received(self, obj): if obj.conn.name != self.name: return @@ -982,20 +993,18 @@ class ConnectionHandlersBase: keyID = gajim.config.get_per('accounts', self.name, 'keyid') if keyID: - def decrypt_thread(encmsg, keyID, obj): - decmsg = self.gpg.decrypt(encmsg, keyID) - decmsg = self.connection.Dispatcher.replace_non_character( - decmsg) - # \x00 chars are not allowed in C (so in GTK) - obj.msgtxt = helpers.decode_string(decmsg.replace('\x00', - '')) - obj.encrypted = 'xep27' - gajim.thread_interface(decrypt_thread, [encmsg, keyID, obj], - self._on_message_decrypted, [obj]) + self.gpg_messages_to_decrypt.append([encmsg, keyID, obj]) + if len(self.gpg_messages_to_decrypt) == 1: + gajim.thread_interface(self.decrypt_thread, [encmsg, keyID, + obj], self._on_message_decrypted, [obj]) return self._on_message_decrypted(None, obj) def _on_message_decrypted(self, output, obj): + if len(self.gpg_messages_to_decrypt): + encmsg, keyID, obj = self.gpg_messages_to_decrypt[0] + gajim.thread_interface(self.decrypt_thread, [encmsg, keyID, obj], + self._on_message_decrypted, [obj]) gajim.nec.push_incoming_event(DecryptedMessageReceivedEvent(None, conn=self, msg_obj=obj))