changeset 4d5a335069ef in /home/hg/repos/gajim

details:http://hg.gajim.org/gajim?cmd=changeset;node=4d5a335069ef
description: detect incoming MUC error presences from the ID. Fixes #5309

diffstat:

 src/common/connection.py          |  14 ++++++++++++--
 src/common/connection_handlers.py |   9 +++++++++
 2 files changed, 21 insertions(+), 2 deletions(-)

diffs (78 lines):

diff -r 6ba8d19efca7 -r 4d5a335069ef src/common/connection.py
--- a/src/common/connection.py  Tue Oct 13 17:38:42 2009 +0300
+++ b/src/common/connection.py  Tue Oct 13 19:26:56 2009 +0200
@@ -39,6 +39,7 @@
 
 import time
 import locale
+import hmac
 
 try:
        randomsource = random.SystemRandom()
@@ -190,6 +191,7 @@
                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 @@
                                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 @@
                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 -r 6ba8d19efca7 -r 4d5a335069ef src/common/connection_handlers.py
--- a/src/common/connection_handlers.py Tue Oct 13 17:38:42 2009 +0300
+++ b/src/common/connection_handlers.py Tue Oct 13 19:26:56 2009 +0200
@@ -34,6 +34,7 @@
 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 @@
                        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 @@
                                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:
_______________________________________________
Commits mailing list
Commits@gajim.org
http://lists.gajim.org/cgi-bin/listinfo/commits

Reply via email to