aboutsummaryrefslogtreecommitdiffstats
path: root/plugin.py
diff options
context:
space:
mode:
authorThibaut Horel <thibaut.horel@gmail.com>2010-11-17 03:52:54 +0100
committerThibaut Horel <thibaut.horel@gmail.com>2010-11-17 03:52:54 +0100
commitc494741c09f03268d950b8da27952917518db446 (patch)
tree1fbbd798240db8b996fe9aa5b015930a7dd00b7c /plugin.py
parentb8106bd66fad5bafdec50da344e6a23f2dc78c00 (diff)
downloadalias-c494741c09f03268d950b8da27952917518db446.tar.gz
Example of alias query handling.
The request must be of the form : <iq to='xxx@object.alias.fr.nf'> <query xmlns='alias:query' type='items'/> </iq> 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)
Diffstat (limited to 'plugin.py')
-rw-r--r--plugin.py45
1 files changed, 31 insertions, 14 deletions
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()
+
+
+