From c494741c09f03268d950b8da27952917518db446 Mon Sep 17 00:00:00 2001 From: Thibaut Horel Date: Wed, 17 Nov 2010 03:52:54 +0100 Subject: Example of alias query handling. The request must be of the form : where xxx is the base64 encoding of the buddy's jabber id whom profile you are requesting. Also tried to make some files more pep8 compliant (coding style) --- plugin.py | 45 +++++++++++++++++++++++++++++++-------------- 1 file changed, 31 insertions(+), 14 deletions(-) (limited to 'plugin.py') diff --git a/plugin.py b/plugin.py index a88d244..d250f97 100644 --- a/plugin.py +++ b/plugin.py @@ -1,32 +1,49 @@ +import logging +import base64 +from xml.etree import cElementTree as ET + from sleekxmpp.xmlstream.stanzabase import ElementBase, registerStanzaPlugin from sleekxmpp.plugins import base from sleekxmpp.xmlstream.handler.callback import Callback from sleekxmpp.xmlstream.matcher.xpath import MatchXPath from sleekxmpp.stanza.iq import Iq -import logging -class AliasQuery(ElementBase) : +import object + +class AliasQuery(ElementBase): namespace = 'alias:query' name = 'query' - plugin_attrib = 'query' - interfaces = set(('node', 'type', 'items','object')) + plugin_attrib = 'alias' + interfaces = set(('node', 'type', 'items', 'object')) sub_interfaces = set(('items')) - -class AliasPlugin(base.base_plugin) : - + +class AliasPlugin(base.base_plugin): + def plugin_init(self) : self.description = 'Plugin to handle alias queries' registerStanzaPlugin(Iq, AliasQuery) - + self.xmpp.registerHandler( Callback('Alias queries', - MatchXPath('{%s}iq/{%s}query' % (self.xmpp.default_ns, + MatchXPath('{%s}iq/{%s}query' % (self.xmpp.default_ns, AliasQuery.namespace)), self.handle_alias_query)) - - def handle_alias_query(self, iq) : - iq.reply().send() - - + + def handle_alias_query(self, iq): + receiver = base64.b64decode(iq['to'].user) + handler = object.ObjectHandler(receiver) + node = iq['alias']['node'] + if node == "" : + node = handler.get_home_node() + if iq['alias']['type'] == 'items': + logging.debug('childs of {} requested'.format(node)) + childs = handler.get_child_list(node, iq['alias']['from']) + test = ET.Element("test") + for child in childs : + test.append(ET.Element("item", {'node':child})) + iq.reply().set_payload(test).send() + + + -- cgit v1.2.3-70-g09d2