summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authormathieui <mathieui@mathieui.net>2014-04-27 22:38:24 +0200
committermathieui <mathieui@mathieui.net>2014-04-27 22:38:24 +0200
commit31716565a74bcc3c41569297c4c8ddfe731ba364 (patch)
treee414e99ceed61988956b60684e5bf14ead3ce898 /src
parent3fb3d8db3d566f231ea6ff6afd559a0185d8bff7 (diff)
downloadpoezio-31716565a74bcc3c41569297c4c8ddfe731ba364.tar.gz
poezio-31716565a74bcc3c41569297c4c8ddfe731ba364.tar.bz2
poezio-31716565a74bcc3c41569297c4c8ddfe731ba364.tar.xz
poezio-31716565a74bcc3c41569297c4c8ddfe731ba364.zip
Provide our own wrapper for checking the host category (ref #2511?)
xmpp.plugin['xep_0030'].has_identity appears to be unreliable at best, so we provide our own. Might help the case of carbons not displayed.
Diffstat (limited to 'src')
-rw-r--r--src/core/handlers.py37
-rw-r--r--src/fixes.py15
2 files changed, 39 insertions, 13 deletions
diff --git a/src/core/handlers.py b/src/core/handlers.py
index 58217e8f..bc666736 100644
--- a/src/core/handlers.py
+++ b/src/core/handlers.py
@@ -14,12 +14,13 @@ from gettext import gettext as _
from sleekxmpp import InvalidJID
from sleekxmpp.xmlstream.stanzabase import StanzaBase
+import bookmark
import common
-import xhtml
+import fixes
import pep
import tabs
-import bookmark
import windows
+import xhtml
import multiuserchat as muc
from common import safeJID
from config import config
@@ -49,30 +50,42 @@ def on_session_start_features(self, _):
features = self.xmpp.plugin['xep_0030'].get_info(jid=self.xmpp.boundjid.domain, callback=callback, block=False)
def on_carbon_received(self, message):
+ """
+ Carbon <received/> received
+ """
recv = message['carbon_received']
- if recv['from'].bare not in roster or roster[recv['from'].bare].subscription == 'none':
+ if (recv['from'].bare not in roster or
+ roster[recv['from'].bare].subscription == 'none'):
try:
- if self.xmpp.plugin['xep_0030'].has_identity(jid=recv['from'].server, category="conference"):
+ if fixes.has_identity(self.xmpp, recv['from'].server,
+ identity='conference'):
+ log.debug('%s has category conference, ignoring carbon',
+ recv['from'].server)
return
except:
- pass
- else:
- return
+ log.debug('Traceback when getting the identity of a server:',
+ exc_info=True)
recv['to'] = self.xmpp.boundjid.full
if recv['receipt']:
return self.on_receipt(recv)
self.on_normal_message(recv)
def on_carbon_sent(self, message):
+ """
+ Carbon <sent/> received
+ """
sent = message['carbon_sent']
- if sent['to'].bare not in roster or roster[sent['to'].bare].subscription == 'none':
+ if (sent['to'].bare not in roster or
+ roster[sent['to'].bare].subscription == 'none'):
try:
- if self.xmpp.plugin['xep_0030'].has_identity(jid=sent['to'].server, category="conference"):
+ if fixes.has_identity(self.xmpp, sent['to'].server,
+ identity='conference'):
+ log.debug('%s has category conference, ignoring carbon',
+ sent['to'].server)
return
except:
- pass
- else:
- return
+ log.debug('Traceback when getting the identity of a server:',
+ exc_info=True)
sent['from'] = self.xmpp.boundjid.full
self.on_normal_message(sent)
diff --git a/src/fixes.py b/src/fixes.py
index 69106c81..b7c8d03b 100644
--- a/src/fixes.py
+++ b/src/fixes.py
@@ -1,4 +1,3 @@
-from sleekxmpp.xmlstream import ET
"""
Module used to provide fixes for sleekxmpp functions not yet fixed
upstream.
@@ -7,6 +6,20 @@ TODO: Check that they are fixed and remove those hacks
"""
+from sleekxmpp.xmlstream import ET
+import logging
+
+log = logging.getLogger(__name__)
+
+def has_identity(xmpp, jid, identity):
+ try:
+ iq = xmpp.plugin['xep_0030'].get_info(jid=jid, block=True, timeout=1)
+ ident = lambda x: x[0]
+ return identity in map(ident, iq['disco_info']['identities'])
+ except:
+ log.debug('Traceback while retrieving identity', exc_info=True)
+ return False
+
def get_version(xmpp, jid, callback=None, **kwargs):
def handle_result(res):
if res and res['type'] != 'error':