aboutsummaryrefslogtreecommitdiffstats
path: root/plugin.py
diff options
context:
space:
mode:
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()
+
+
+