Rename to slixmpp
[slixmpp.git] / slixmpp / plugins / xep_0092 / version.py
blob398f6b309646655d81a8417155c8936dddc77717
1 """
2 Slixmpp: The Slick XMPP Library
3 Copyright (C) 2010 Nathanael C. Fritz
4 This file is part of Slixmpp.
6 See the file LICENSE for copying permission.
7 """
9 import logging
11 import slixmpp
12 from slixmpp import Iq
13 from slixmpp.xmlstream import register_stanza_plugin
14 from slixmpp.xmlstream.handler import Callback
15 from slixmpp.xmlstream.matcher import StanzaPath
16 from slixmpp.plugins import BasePlugin
17 from slixmpp.plugins.xep_0092 import Version, stanza
20 log = logging.getLogger(__name__)
23 class XEP_0092(BasePlugin):
25 """
26 XEP-0092: Software Version
27 """
29 name = 'xep_0092'
30 description = 'XEP-0092: Software Version'
31 dependencies = set(['xep_0030'])
32 stanza = stanza
33 default_config = {
34 'software_name': 'Slixmpp',
35 'version': slixmpp.__version__,
36 'os': ''
39 def plugin_init(self):
40 """
41 Start the XEP-0092 plugin.
42 """
43 if 'name' in self.config:
44 self.software_name = self.config['name']
46 self.xmpp.register_handler(
47 Callback('Software Version',
48 StanzaPath('iq@type=get/software_version'),
49 self._handle_version))
51 register_stanza_plugin(Iq, Version)
53 def plugin_end(self):
54 self.xmpp.remove_handler('Software Version')
55 self.xmpp['xep_0030'].del_feature(feature='jabber:iq:version')
57 def session_bind(self, jid):
58 self.xmpp.plugin['xep_0030'].add_feature('jabber:iq:version')
60 def _handle_version(self, iq):
61 """
62 Respond to a software version query.
64 Arguments:
65 iq -- The Iq stanza containing the software version query.
66 """
67 iq.reply()
68 iq['software_version']['name'] = self.software_name
69 iq['software_version']['version'] = self.version
70 iq['software_version']['os'] = self.os
71 iq.send()
73 def get_version(self, jid, ifrom=None, block=True, timeout=None, callback=None):
74 """
75 Retrieve the software version of a remote agent.
77 Arguments:
78 jid -- The JID of the entity to query.
79 """
80 iq = self.xmpp.Iq()
81 iq['to'] = jid
82 iq['from'] = ifrom
83 iq['type'] = 'get'
84 iq['query'] = Version.namespace
85 return iq.send(block=block, timeout=timeout, callback=callback)