summaryrefslogtreecommitdiff
path: root/sleekxmpp/plugins/xep_0030/disco.py
diff options
context:
space:
mode:
Diffstat (limited to 'sleekxmpp/plugins/xep_0030/disco.py')
-rw-r--r--sleekxmpp/plugins/xep_0030/disco.py94
1 files changed, 72 insertions, 22 deletions
diff --git a/sleekxmpp/plugins/xep_0030/disco.py b/sleekxmpp/plugins/xep_0030/disco.py
index 92ee5ec6..a976b988 100644
--- a/sleekxmpp/plugins/xep_0030/disco.py
+++ b/sleekxmpp/plugins/xep_0030/disco.py
@@ -90,6 +90,10 @@ class xep_0030(base_plugin):
self.description = 'Service Discovery'
self.stanza = sleekxmpp.plugins.xep_0030.stanza
+ # Retain some backwards compatibility
+ self.getInfo = self.get_info
+ self.getItems = self.get_items
+
self.xmpp.register_handler(
Callback('Disco Info',
StanzaPath('iq/disco_info'),
@@ -116,6 +120,12 @@ class xep_0030(base_plugin):
'jid': {},
'node': {}}
+ def post_init(self):
+ """Handle cross-plugin dependencies."""
+ base_plugin.post_init(self)
+ if self.xmpp['xep_0059']:
+ register_stanza_plugin(DiscoItems, self.xmpp['xep_0059'].stanza.Set)
+
def set_node_handler(self, htype, jid=None, node=None, handler=None):
"""
Add a node handler for the given hierarchy level and
@@ -167,7 +177,10 @@ class xep_0030(base_plugin):
elif node is None:
self._handlers[htype]['jid'][jid] = handler
elif jid is None:
- jid = self.xmpp.boundjid.full
+ if self.xmpp.is_component:
+ jid = self.xmpp.boundjid.full
+ else:
+ jid = self.xmpp.boundjid.bare
self._handlers[htype]['node'][(jid, node)] = handler
else:
self._handlers[htype]['node'][(jid, node)] = handler
@@ -225,6 +238,9 @@ class xep_0030(base_plugin):
by executing the local node handlers, or if a disco#info stanza
must be generated and sent.
+ If requesting items from a local JID/node, then only a DiscoInfo
+ stanza will be returned. Otherwise, an Iq stanza will be returned.
+
Arguments:
jid -- Request info from this JID.
node -- The particular node to query.
@@ -236,7 +252,8 @@ class xep_0030(base_plugin):
ifrom -- Specifiy the sender's JID.
block -- If true, block and wait for the stanzas' reply.
timeout -- The time in seconds to block while waiting for
- a reply. If None, then wait indefinitely.
+ a reply. If None, then wait indefinitely. The
+ timeout value is only used when block=True.
callback -- Optional callback to execute when a reply is
received instead of blocking and waiting for
the reply.
@@ -248,7 +265,8 @@ class xep_0030(base_plugin):
return self._fix_default_info(info)
iq = self.xmpp.Iq()
- iq['from'] = kwargs.get('ifrom', '')
+ # Check dfrom parameter for backwards compatibility
+ iq['from'] = kwargs.get('ifrom', kwargs.get('dfrom', ''))
iq['to'] = jid
iq['type'] = 'get'
iq['disco_info']['node'] = node if node else ''
@@ -265,6 +283,9 @@ class xep_0030(base_plugin):
executing the local node handlers, or if a disco#items stanza must
be generated and sent.
+ If requesting items from a local JID/node, then only a DiscoItems
+ stanza will be returned. Otherwise, an Iq stanza will be returned.
+
Arguments:
jid -- Request info from this JID.
node -- The particular node to query.
@@ -280,18 +301,25 @@ class xep_0030(base_plugin):
callback -- Optional callback to execute when a reply is
received instead of blocking and waiting for
the reply.
+ iterator -- If True, return a result set iterator using
+ the XEP-0059 plugin, if the plugin is loaded.
+ Otherwise the parameter is ignored.
"""
if local or jid is None:
return self._run_node_handler('get_items', jid, node, kwargs)
iq = self.xmpp.Iq()
- iq['from'] = kwargs.get('ifrom', '')
+ # Check dfrom parameter for backwards compatibility
+ iq['from'] = kwargs.get('ifrom', kwargs.get('dfrom', ''))
iq['to'] = jid
iq['type'] = 'get'
iq['disco_items']['node'] = node if node else ''
- return iq.send(timeout=kwargs.get('timeout', None),
- block=kwargs.get('block', None),
- callback=kwargs.get('callback', None))
+ if kwargs.get('iterator', False) and self.xmpp['xep_0059']:
+ return self.xmpp['xep_0059'].iterate(iq, 'disco_items')
+ else:
+ return iq.send(timeout=kwargs.get('timeout', None),
+ block=kwargs.get('block', None),
+ callback=kwargs.get('callback', None))
def set_items(self, jid=None, node=None, **kwargs):
"""
@@ -317,7 +345,7 @@ class xep_0030(base_plugin):
"""
self._run_node_handler('del_items', jid, node, kwargs)
- def add_item(self, jid=None, node=None, **kwargs):
+ def add_item(self, jid='', name='', node=None, subnode='', ijid=None):
"""
Add a new item element to the given JID/node combination.
@@ -325,13 +353,18 @@ class xep_0030(base_plugin):
a node value to reference non-addressable entities.
Arguments:
- jid -- The JID to modify.
- node -- The node to modify.
- ijid -- The JID for the item.
- inode -- Optional node for the item.
+ jid -- The JID for the item.
name -- Optional name for the item.
+ node -- The node to modify.
+ subnode -- Optional node for the item.
+ ijid -- The JID to modify.
"""
- self._run_node_handler('add_item', jid, node, kwargs)
+ if not jid:
+ jid = self.xmpp.boundjid.full
+ kwargs = {'ijid': jid,
+ 'name': name,
+ 'inode': subnode}
+ self._run_node_handler('add_item', ijid, node, kwargs)
def del_item(self, jid=None, node=None, **kwargs):
"""
@@ -345,7 +378,7 @@ class xep_0030(base_plugin):
"""
self._run_node_handler('del_item', jid, node, kwargs)
- def add_identity(self, jid=None, node=None, **kwargs):
+ def add_identity(self, category='', itype='', name='', node=None, jid=None, lang=None):
"""
Add a new identity to the given JID/node combination.
@@ -358,24 +391,29 @@ class xep_0030(base_plugin):
names are different. A category and type is always required.
Arguments:
- jid -- The JID to modify.
- node -- The node to modify.
category -- The identity's category.
itype -- The identity's type.
name -- Optional name for the identity.
lang -- Optional two-letter language code.
+ node -- The node to modify.
+ jid -- The JID to modify.
"""
+ kwargs = {'category': category,
+ 'itype': itype,
+ 'name': name,
+ 'lang': lang}
self._run_node_handler('add_identity', jid, node, kwargs)
- def add_feature(self, jid=None, node=None, **kwargs):
+ def add_feature(self, feature, node=None, jid=None):
"""
Add a feature to a JID/node combination.
Arguments:
- jid -- The JID to modify.
- node -- The node to modify.
feature -- The namespace of the supported feature.
+ node -- The node to modify.
+ jid -- The JID to modify.
"""
+ kwargs = {'feature': feature}
self._run_node_handler('add_feature', jid, node, kwargs)
def del_identity(self, jid=None, node=None, **kwargs):
@@ -467,7 +505,10 @@ class xep_0030(base_plugin):
data -- Optional, custom data to pass to the handler.
"""
if jid is None:
- jid = self.xmpp.boundjid.full
+ if self.xmpp.is_component:
+ jid = self.xmpp.boundjid.full
+ else:
+ jid = self.xmpp.boundjid.bare
if node is None:
node = ''
@@ -493,8 +534,12 @@ class xep_0030(base_plugin):
if iq['type'] == 'get':
log.debug("Received disco info query from " + \
"<%s> to <%s>." % (iq['from'], iq['to']))
+ if self.xmpp.is_component:
+ jid = iq['to'].full
+ else:
+ jid = iq['to'].bare
info = self._run_node_handler('get_info',
- iq['to'].full,
+ jid,
iq['disco_info']['node'],
iq)
iq.reply()
@@ -519,8 +564,12 @@ class xep_0030(base_plugin):
if iq['type'] == 'get':
log.debug("Received disco items query from " + \
"<%s> to <%s>." % (iq['from'], iq['to']))
+ if self.xmpp.is_component:
+ jid = iq['to'].full
+ else:
+ jid = iq['to'].bare
items = self._run_node_handler('get_items',
- iq['to'].full,
+ jid,
iq['disco_items']['node'])
iq.reply()
if items:
@@ -557,3 +606,4 @@ class xep_0030(base_plugin):
"Using default disco#info feature.")
info.add_feature(info.namespace)
return info
+