diff --git a/src/plugins/plugin_xep_0092.py b/src/plugins/plugin_xep_0092.py index 59e666fb..2f00221d 100644 --- a/src/plugins/plugin_xep_0092.py +++ b/src/plugins/plugin_xep_0092.py @@ -19,11 +19,13 @@ from sat.core.i18n import _ from sat.core.constants import Const as C +from twisted.internet import reactor, defer from wokkel import compat from sat.core import exceptions from logging import debug, info, warning, error NS_VERSION = "jabber:iq:version" +TIMEOUT = 10 PLUGIN_INFO = { "name": "Software Version Plugin", @@ -58,17 +60,16 @@ class XEP_0092(object): - os: operating system of the queried entity """ client = self.host.getClient(profile_key) - def getVersion(available): - if not available: - raise exceptions.FeatureNotFound + def getVersion(dummy): iq_elt = compat.IQ(client.xmlstream, 'get') iq_elt['to'] = jid_.full() iq_elt.addElement("query", NS_VERSION) d = iq_elt.send() d.addCallback(self._gotVersion) return d - d = self.host.hasFeature(NS_VERSION, jid_, client.profile) + d = self.host.checkFeature(NS_VERSION, jid_, client.profile) d.addCallback(getVersion) + reactor.callLater(TIMEOUT, d.cancel) # XXX: timeout needed because some clients don't answer the IQ return d def _gotVersion(self, iq_elt): @@ -98,8 +99,11 @@ class XEP_0092(object): if os: whois_msg.append(_("Operating system: %s") % os) def versionEb(failure): - failure.trap(exceptions.FeatureNotFound) - whois_msg.append(_("Software informations not available")) + failure.trap(exceptions.FeatureNotFound, defer.CancelledError) + if failure.check(failure,exceptions.FeatureNotFound): + whois_msg.append(_("Software version not available")) + else: + whois_msg.append(_("Client software version request timeout")) d = self.getVersion(target_jid, profile) d.addCallbacks(versionCb, versionEb)