From f18ede1c887805a2e9e11aaa9aec39eb30fefe0e Mon Sep 17 00:00:00 2001 From: Yann Leboulanger Date: Tue, 13 Oct 2009 19:26:56 +0200 Subject: [PATCH] detect incoming MUC error presences from the ID. Fixes #5309 --- src/common/connection.py | 14 ++++++++++++-- src/common/connection_handlers.py | 9 +++++++++ 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/src/common/connection.py b/src/common/connection.py index 4ff4a7270..39a0cc5ca 100644 --- a/src/common/connection.py +++ b/src/common/connection.py @@ -39,6 +39,7 @@ import operator import time import locale +import hmac try: randomsource = random.SystemRandom() @@ -190,6 +191,7 @@ class Connection(ConnectionHandlers): self.vcard_supported = False self.private_storage_supported = True self.streamError = '' + self.secret_hmac = str(random.random())[2:] # END __init__ def put_event(self, ev): @@ -1775,8 +1777,12 @@ class Connection(ConnectionHandlers): last_log = 0 self.last_history_time[room_jid] = last_log - p = common.xmpp.Presence(to = '%s/%s' % (room_jid, nick), - show = show, status = self.status) + p = common.xmpp.Presence(to='%s/%s' % (room_jid, nick), + show=show, status=self.status) + h = hmac.new(self.secret_hmac, room_jid).hexdigest()[:6] + id_ = self.connection.getAnID() + id_ = 'gajim_muc_' + id_ + '_' + h + p.setID(id_) if gajim.config.get('send_sha_in_gc_presence'): p = self.add_sha(p) self.add_lang(p) @@ -1843,6 +1849,10 @@ class Connection(ConnectionHandlers): xmpp_show = helpers.get_xmpp_show(show) p = common.xmpp.Presence(to = '%s/%s' % (jid, nick), typ = ptype, show = xmpp_show, status = status) + h = hmac.new(self.secret_hmac, jid).hexdigest()[:6] + id_ = self.connection.getAnID() + id_ = 'gajim_muc_' + id_ + '_' + h + p.setID(id_) if gajim.config.get('send_sha_in_gc_presence') and show != 'offline': p = self.add_sha(p, ptype != 'unavailable') self.add_lang(p) diff --git a/src/common/connection_handlers.py b/src/common/connection_handlers.py index dcd61a946..c221cfb8b 100644 --- a/src/common/connection_handlers.py +++ b/src/common/connection_handlers.py @@ -34,6 +34,7 @@ import socket import sys import operator import hashlib +import hmac from time import (altzone, daylight, gmtime, localtime, mktime, strftime, time as time_time, timezone, tzname) @@ -2207,6 +2208,7 @@ class ConnectionHandlers(ConnectionVcard, ConnectionBytestream, ConnectionDisco, return jid_stripped, resource = gajim.get_room_and_nick_from_fjid(who) timestamp = None + id_ = prs.getID() is_gc = False # is it a GC presence ? sigTag = None ns_muc_user_x = None @@ -2246,6 +2248,13 @@ class ConnectionHandlers(ConnectionVcard, ConnectionBytestream, ConnectionDisco, if self.connection.getRoster().getItem(agent): # to be sure it's a transport contact transport_auto_auth = True + if not is_gc and id_ and id_.startswith('gajim_muc_') and \ + ptype == 'error': + # Error presences may not include sent stanza, so we don't detect it's + # a muc preence. So detect it by ID + h = hmac.new(self.secret_hmac, jid_stripped).hexdigest()[:6] + if id_.split('_')[-1] = h: + is_gc = True status = prs.getStatus() or '' show = prs.getShow() if not show in gajim.SHOW_LIST: