diff options
| author | Zaran <zaran.krleza@gmail.com> | 2011-01-20 01:54:49 +0100 |
|---|---|---|
| committer | Thibaut Horel <thibaut.horel@gmail.com> | 2011-01-20 01:57:07 +0100 |
| commit | 63f4cc0daf8f2629e5d0296de2ae8a74f14b0dc1 (patch) | |
| tree | 750382715e252325615a3bcdb5fa963d8e971100 /server/plugin.py | |
| parent | 95e74be58e597776ee095790403d499b5d62467f (diff) | |
| download | alias-63f4cc0daf8f2629e5d0296de2ae8a74f14b0dc1.tar.gz | |
Simplification of the object module : now use only one class (maybe add some function back later)
Requesting the child items now works
Add a zip example of objects for testing
Diffstat (limited to 'server/plugin.py')
| -rw-r--r-- | server/plugin.py | 24 |
1 files changed, 14 insertions, 10 deletions
diff --git a/server/plugin.py b/server/plugin.py index 62ae958..c3bd81d 100644 --- a/server/plugin.py +++ b/server/plugin.py @@ -1,5 +1,6 @@ import logging import base64 +import hashlib from xml.etree import cElementTree as ET from sleekxmpp.xmlstream.stanzabase import ElementBase, register_stanza_plugin @@ -8,7 +9,8 @@ from sleekxmpp.xmlstream.handler.callback import Callback from sleekxmpp.xmlstream.matcher.xpath import MatchXPath from sleekxmpp.stanza.iq import Iq -import object +from object import Object +from permission import PermissionError class AliasQuery(ElementBase): namespace = 'alias:query' @@ -21,7 +23,7 @@ class AliasQuery(ElementBase): item = AliasItem(None, self) item['node'] = node if permission is not None: - item['permission'] = permission + item['permission'] = str(permission) class AliasItem(ElementBase): namespace = 'alias:query' @@ -38,7 +40,7 @@ class AliasPlugin(base.base_plugin): 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") @@ -48,17 +50,19 @@ class AliasPlugin(base.base_plugin): callee = base64.b64decode(iq['to'].user) except TypeError: logging.error("callee field not base64 encoded") - caller = iq['alias']['from'] - handler = object.ObjectHandler(self.config['root'],callee) + caller = iq['from'].bare node = iq['alias']['node'] if not node: - node = handler.get_home_node() + node = hashlib.sha1(callee).hexdigest() + + node = Object(callee, node) + if iq['alias']['type'] == 'items': logging.debug('childs of {} requested'.format(node)) - childs = handler.get_child_list(node, caller) + childs = Object.get_child_list(node, caller) reply = AliasQuery() - reply['node'] = node + reply['node'] = node.hash reply['type'] = 'items' - for child in childs: - reply.addItem(child, "test") + for name, perm in childs: + reply.addItem(name, perm) iq.reply().set_payload(reply).send()
\ No newline at end of file |
