changeset 101:b75fcc554358

Added support for disco info meta data.
author Ralph Meijer <ralphm@ik.nu>
date Sun, 02 Jan 2005 20:10:02 +0000
parents 0228725b705b
children f4d725a94202
files idavoll/backend.py idavoll/idavoll.py idavoll/pubsub.py
diffstat 3 files changed, 69 insertions(+), 32 deletions(-) [+]
line wrap: on
line diff
--- a/idavoll/backend.py	Sun Jan 02 20:09:31 2005 +0000
+++ b/idavoll/backend.py	Sun Jan 02 20:10:02 2005 +0000
@@ -171,6 +171,18 @@
 
     __implements__ = IBackendService,
 
+    options = {"pubsub#persist_items":
+                  {"type": "boolean",
+                   "label": "Persist items to storage"},
+               "pubsub#deliver_payloads":
+                  {"type": "boolean",
+                   "label": "Deliver payloads with event notifications"},
+              }
+
+    default_config = {"pubsub#persist_items": True,
+                      "pubsub#deliver_payloads": True,
+                     }
+
     def __init__(self, storage):
         service.MultiService.__init__(self)
         utility.EventDispatcher.__init__(self)
@@ -191,6 +203,23 @@
     def get_nodes(self):
         return self.storage.get_nodes()
 
+    def get_node_meta_data(self, node_id):
+        d = self.storage.get_node_configuration(node_id)
+
+        d.addCallback(self._make_meta_data)
+        return d
+
+    def _make_meta_data(self, meta_data):
+        options = []
+        for key, value in meta_data.iteritems():
+            if self.options.has_key(key):
+                option = {"var": key}
+                option.update(self.options[key])
+                option["value"] = value
+                options.append(option)
+
+        return options
+
 class PublishService(service.Service):
     
     __implements__ = IPublishService,
@@ -305,14 +334,6 @@
 
     __implements__ = INodeCreationService,
 
-    options = {"pubsub#persist_items":
-                  {"type": "boolean",
-                   "label": "Persist items to storage"},
-               "pubsub#deliver_payloads":
-                  { "type": "boolean",
-                   "label": "Deliver payloads with event notifications"}
-              }
-
     def supports_instant_nodes(self):
         return True
 
@@ -329,28 +350,26 @@
         if node_id:
             d = self.parent.storage.get_node_configuration(node_id)
         else:
-            d = defer.succeed({"pubsub#persist_items": True,
-                               "pubsub#deliver_payloads": True})
+            # XXX: this is disabled in pubsub.py
+            d = defer.succeed(self.parent.default_config)
 
         d.addCallback(self._make_config)
         return d
 
     def _make_config(self, config):
         options = []
-        for key, value in config.iteritems():
+        for key, value in self.parent.options.iteritems():
             option = {"var": key}
-            option.update(self.options[key])
-            if option["type"] == "boolean":
-                option["value"] = str(int(bool(value)))
-            else:
-                option["value"] = str(value)
+            option.update(value)
+            if config.has_key(key):
+                option["value"] = config[key]
             options.append(option)
 
         return options
 
     def set_node_configuration(self, node_id, options, requestor):
         for key in options.iterkeys():
-            if not self.options.has_key(key):
+            if not self.parent.options.has_key(key):
                 raise InvalidConfigurationOption
 
         d = self.parent.storage.get_affiliation(node_id, requestor)
--- a/idavoll/idavoll.py	Sun Jan 02 20:09:31 2005 +0000
+++ b/idavoll/idavoll.py	Sun Jan 02 20:10:02 2005 +0000
@@ -69,11 +69,18 @@
         else:
             iq.swapAttributeValues("to", "from")
             iq["type"] = "result"
-            iq.query.children = info
+            for item in info:
+                #domish.Element.addChild should probably do this for all
+                # subclasses of Element
+                item.parent = iq.query
+
+                iq.query.addChild(item)
 
         return iq
 
-    def _error(self, results, iq):
+    def _error(self, result, iq):
+        print "Got error on index %d:" % result.value[1]
+        result.value[0].printBriefTraceback()
         return xmpp_error.error_from_iq(iq, 'internal-server-error')
 
     def onDiscoItems(self, iq):
--- a/idavoll/pubsub.py	Sun Jan 02 20:09:31 2005 +0000
+++ b/idavoll/pubsub.py	Sun Jan 02 20:10:02 2005 +0000
@@ -6,13 +6,13 @@
 import backend
 import xmpp_error
 import disco
+import data_form
 
 NS_COMPONENT = 'jabber:component:accept'
 NS_PUBSUB = 'http://jabber.org/protocol/pubsub'
 NS_PUBSUB_EVENT = NS_PUBSUB + '#event'
 NS_PUBSUB_ERRORS = NS_PUBSUB + '#errors'
 NS_PUBSUB_OWNER = NS_PUBSUB + "#owner"
-NS_X_DATA = 'jabber:x:data'
 
 IQ_GET = '/iq[@type="get"]'
 IQ_SET = '/iq[@type="set"]'
@@ -140,10 +140,27 @@
             return defer.succeed(info)
         else:
             d = self.backend.get_node_type(node)
-            d.addCallback(lambda x: [disco.Identity('pubsub', x)])
+            d.addCallback(self._add_identity, [], node)
             d.addErrback(lambda _: [])
             return d
 
+    def _add_identity(self, node_type, result_list, node):
+        result_list.append(disco.Identity('pubsub', node_type))
+        d = self.backend.get_node_meta_data(node)
+        d.addCallback(self._add_meta_data, node_type, result_list)
+        return d
+
+    def _add_meta_data(self, meta_data, node_type, result_list):
+        form = data_form.Form(type="result", form_type=NS_PUBSUB + "#meta-data")
+        for meta_datum in meta_data:
+            form.add_field_single(**meta_datum)
+        form.add_field_single("text-single",
+                              "pubsub#node_type",
+                              "The type of node (collection or leaf)",
+                              node_type)
+        result_list.append(form)
+        return result_list
+
     def get_disco_items(self, node):
         if node or self.hide_nodes:
             return defer.succeed([])
@@ -335,19 +352,13 @@
         configure = reply.addElement("configure")
         if node_id:
             configure["node"] = node_id
-        form = configure.addElement((NS_X_DATA, "x"))
-        form["type"] = "form"
-        field = form.addElement("field")
-        field["var"] = "FORM_TYPE"
-        field["type"] = "hidden"
-        field.addElement("value", content=NS_PUBSUB + "#node_config")
+        form = data_form.Form(type="form",
+                              form_type=NS_PUBSUB + "#node_config")
 
         for option in options:
-            field = form.addElement("field")
-            field["var"] = option["var"]
-            field["type"] = option["type"]
-            field["label"] = option["label"]
-            field.addElement("value", content=option["value"])
+            form.add_field_single(**option)
+
+        configure.addChild(form)
 
         return [reply]