aboutsummaryrefslogtreecommitdiffstats
path: root/server/plugin.py
diff options
context:
space:
mode:
authorThibaut Horel <thibaut.horel@gmail.com>2010-12-31 19:19:25 +0100
committerThibaut Horel <thibaut.horel@gmail.com>2010-12-31 19:19:25 +0100
commitd90aec17e2201f256783a531c548dcc9857c889d (patch)
tree56b6d0580ee1993c73e67c63d4a452a81bbaaf1e /server/plugin.py
parentaf76bcdf7a947702eaa19d39f5b9ecfcd7ec6fd2 (diff)
downloadalias-d90aec17e2201f256783a531c548dcc9857c889d.tar.gz
Cleanup of repository. Bases of webclient.
* remove sleekxmpp (install guideline in server/README) * move server code to server directory * webclient directory with basic strophejs example
Diffstat (limited to 'server/plugin.py')
-rw-r--r--server/plugin.py61
1 files changed, 61 insertions, 0 deletions
diff --git a/server/plugin.py b/server/plugin.py
new file mode 100644
index 0000000..df05908
--- /dev/null
+++ b/server/plugin.py
@@ -0,0 +1,61 @@
+import logging
+import base64
+from xml.etree import cElementTree as ET
+
+from sleekxmpp.xmlstream.stanzabase import ElementBase, register_stanza_plugin
+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 object
+
+class AliasQuery(ElementBase):
+ namespace = 'alias:query'
+ name = 'query'
+ plugin_attrib = 'alias'
+ interfaces = set(('node', 'type', 'items', 'object'))
+ sub_interfaces = set(('items'))
+
+ def addItem(self, node, permission = None):
+ item = AliasItem(None, self)
+ item['node'] = node
+ if permission is not None:
+ item['permission'] = permission
+
+class AliasItem(ElementBase):
+ namespace = 'alias:query'
+ name = 'item'
+ plugin_attrib = 'item'
+ interfaces = set(('node', 'permission'))
+
+class AliasPlugin(base.base_plugin):
+
+ def plugin_init(self):
+ self.description = 'Plugin to handle alias queries'
+ register_stanza_plugin(Iq, AliasQuery)
+ query_parser = MatchXPath('{{{}}}iq/{{{}}}query'.format(self.xmpp.default_ns,
+ AliasQuery.namespace))
+ self.xmpp.register_handler(Callback('Alias queries', query_parser,
+ self.handle_alias_query))
+
+ def post_init(self):
+ base.base_plugin.post_init(self)
+ self.xmpp.plugin['xep_0030'].add_feature("alias:query")
+
+ def handle_alias_query(self, iq):
+ callee = base64.b64decode(iq['to'].user)
+ caller = iq['alias']['from']
+ handler = object.ObjectHandler(callee)
+ node = iq['alias']['node']
+ if not node:
+ node = handler.get_home_node()
+ if iq['alias']['type'] == 'items':
+ logging.debug('childs of {} requested'.format(node))
+ childs = handler.get_child_list(node, caller)
+ reply = AliasQuery()
+ reply['node'] = node
+ reply['type'] = 'items'
+ for child in childs:
+ reply.addItem(child, "test")
+ iq.reply().set_payload(reply).send() \ No newline at end of file