2011-01-09 03:38:13 +00:00
|
|
|
"""
|
|
|
|
SleekXMPP: The Sleek XMPP Library
|
|
|
|
Copyright (C) 2010 Nathanael C. Fritz
|
|
|
|
This file is part of SleekXMPP.
|
|
|
|
|
|
|
|
See the file LICENSE for copying permission.
|
|
|
|
"""
|
|
|
|
|
|
|
|
import logging
|
|
|
|
|
|
|
|
import sleekxmpp
|
|
|
|
from sleekxmpp import Iq
|
|
|
|
from sleekxmpp.xmlstream import register_stanza_plugin
|
|
|
|
from sleekxmpp.xmlstream.handler import Callback
|
|
|
|
from sleekxmpp.xmlstream.matcher import StanzaPath
|
2012-03-12 06:07:40 +00:00
|
|
|
from sleekxmpp.plugins import BasePlugin
|
|
|
|
from sleekxmpp.plugins.xep_0092 import Version, stanza
|
2011-01-09 03:38:13 +00:00
|
|
|
|
|
|
|
|
|
|
|
log = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
|
2012-03-12 06:07:40 +00:00
|
|
|
class XEP_0092(BasePlugin):
|
2011-01-09 03:38:13 +00:00
|
|
|
|
|
|
|
"""
|
|
|
|
XEP-0092: Software Version
|
|
|
|
"""
|
|
|
|
|
2012-03-12 06:07:40 +00:00
|
|
|
name = 'xep_0092'
|
|
|
|
description = 'XEP-0092: Software Version'
|
|
|
|
dependencies = set(['xep_0030'])
|
|
|
|
stanza = stanza
|
2012-07-27 06:04:16 +00:00
|
|
|
default_config = {
|
|
|
|
'software_name': 'SleekXMPP',
|
|
|
|
'version': sleekxmpp.__version__,
|
|
|
|
'os': ''
|
|
|
|
}
|
2012-03-12 06:07:40 +00:00
|
|
|
|
2011-01-09 03:38:13 +00:00
|
|
|
def plugin_init(self):
|
|
|
|
"""
|
|
|
|
Start the XEP-0092 plugin.
|
|
|
|
"""
|
2012-07-27 06:04:16 +00:00
|
|
|
if 'name' in self.config:
|
|
|
|
self.software_name = self.config['name']
|
2011-01-09 03:38:13 +00:00
|
|
|
|
|
|
|
self.xmpp.register_handler(
|
|
|
|
Callback('Software Version',
|
2011-03-18 21:30:29 +00:00
|
|
|
StanzaPath('iq@type=get/software_version'),
|
2011-01-09 03:38:13 +00:00
|
|
|
self._handle_version))
|
|
|
|
|
|
|
|
register_stanza_plugin(Iq, Version)
|
|
|
|
|
2012-07-10 08:37:44 +00:00
|
|
|
def plugin_end(self):
|
|
|
|
self.xmpp.remove_handler('Software Version')
|
|
|
|
self.xmpp['xep_0030'].del_feature(feature='jabber:iq:version')
|
|
|
|
|
|
|
|
def session_bind(self, jid):
|
2011-01-09 03:38:13 +00:00
|
|
|
self.xmpp.plugin['xep_0030'].add_feature('jabber:iq:version')
|
|
|
|
|
|
|
|
def _handle_version(self, iq):
|
|
|
|
"""
|
|
|
|
Respond to a software version query.
|
|
|
|
|
|
|
|
Arguments:
|
|
|
|
iq -- The Iq stanza containing the software version query.
|
|
|
|
"""
|
|
|
|
iq.reply()
|
2012-07-27 06:04:16 +00:00
|
|
|
iq['software_version']['name'] = self.software_name
|
2011-01-09 03:38:13 +00:00
|
|
|
iq['software_version']['version'] = self.version
|
|
|
|
iq['software_version']['os'] = self.os
|
|
|
|
iq.send()
|
|
|
|
|
|
|
|
def get_version(self, jid, ifrom=None):
|
|
|
|
"""
|
|
|
|
Retrieve the software version of a remote agent.
|
|
|
|
|
|
|
|
Arguments:
|
|
|
|
jid -- The JID of the entity to query.
|
|
|
|
"""
|
|
|
|
iq = self.xmpp.Iq()
|
|
|
|
iq['to'] = jid
|
2011-08-27 05:04:06 +00:00
|
|
|
iq['from'] = ifrom
|
2011-01-09 03:38:13 +00:00
|
|
|
iq['type'] = 'get'
|
|
|
|
iq['query'] = Version.namespace
|
|
|
|
|
|
|
|
result = iq.send()
|
|
|
|
|
|
|
|
if result and result['type'] != 'error':
|
2012-06-05 23:54:26 +00:00
|
|
|
values = result['software_version'].values
|
|
|
|
del values['lang']
|
|
|
|
return values
|
2011-01-09 03:38:13 +00:00
|
|
|
return False
|
2012-07-27 06:04:16 +00:00
|
|
|
|
|
|
|
|
|
|
|
XEP_0092.getVersion = XEP_0092.get_version
|