comparison idavoll/pubsub.py @ 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 b9c449f4c167
children f4d725a94202
comparison
equal deleted inserted replaced
100:0228725b705b 101:b75fcc554358
4 from twisted.internet import defer 4 from twisted.internet import defer
5 5
6 import backend 6 import backend
7 import xmpp_error 7 import xmpp_error
8 import disco 8 import disco
9 import data_form
9 10
10 NS_COMPONENT = 'jabber:component:accept' 11 NS_COMPONENT = 'jabber:component:accept'
11 NS_PUBSUB = 'http://jabber.org/protocol/pubsub' 12 NS_PUBSUB = 'http://jabber.org/protocol/pubsub'
12 NS_PUBSUB_EVENT = NS_PUBSUB + '#event' 13 NS_PUBSUB_EVENT = NS_PUBSUB + '#event'
13 NS_PUBSUB_ERRORS = NS_PUBSUB + '#errors' 14 NS_PUBSUB_ERRORS = NS_PUBSUB + '#errors'
14 NS_PUBSUB_OWNER = NS_PUBSUB + "#owner" 15 NS_PUBSUB_OWNER = NS_PUBSUB + "#owner"
15 NS_X_DATA = 'jabber:x:data'
16 16
17 IQ_GET = '/iq[@type="get"]' 17 IQ_GET = '/iq[@type="get"]'
18 IQ_SET = '/iq[@type="set"]' 18 IQ_SET = '/iq[@type="set"]'
19 PUBSUB_ELEMENT = '/pubsub[@xmlns="' + NS_PUBSUB + '"]' 19 PUBSUB_ELEMENT = '/pubsub[@xmlns="' + NS_PUBSUB + '"]'
20 PUBSUB_OWNER_ELEMENT = '/pubsub[@xmlns="' + NS_PUBSUB_OWNER + '"]' 20 PUBSUB_OWNER_ELEMENT = '/pubsub[@xmlns="' + NS_PUBSUB_OWNER + '"]'
138 info.append(disco.Feature(NS_PUBSUB + "#persistent-items")) 138 info.append(disco.Feature(NS_PUBSUB + "#persistent-items"))
139 139
140 return defer.succeed(info) 140 return defer.succeed(info)
141 else: 141 else:
142 d = self.backend.get_node_type(node) 142 d = self.backend.get_node_type(node)
143 d.addCallback(lambda x: [disco.Identity('pubsub', x)]) 143 d.addCallback(self._add_identity, [], node)
144 d.addErrback(lambda _: []) 144 d.addErrback(lambda _: [])
145 return d 145 return d
146
147 def _add_identity(self, node_type, result_list, node):
148 result_list.append(disco.Identity('pubsub', node_type))
149 d = self.backend.get_node_meta_data(node)
150 d.addCallback(self._add_meta_data, node_type, result_list)
151 return d
152
153 def _add_meta_data(self, meta_data, node_type, result_list):
154 form = data_form.Form(type="result", form_type=NS_PUBSUB + "#meta-data")
155 for meta_datum in meta_data:
156 form.add_field_single(**meta_datum)
157 form.add_field_single("text-single",
158 "pubsub#node_type",
159 "The type of node (collection or leaf)",
160 node_type)
161 result_list.append(form)
162 return result_list
146 163
147 def get_disco_items(self, node): 164 def get_disco_items(self, node):
148 if node or self.hide_nodes: 165 if node or self.hide_nodes:
149 return defer.succeed([]) 166 return defer.succeed([])
150 167
333 def _return_configuration_response(self, options, node_id): 350 def _return_configuration_response(self, options, node_id):
334 reply = domish.Element((NS_PUBSUB_OWNER, "pubsub")) 351 reply = domish.Element((NS_PUBSUB_OWNER, "pubsub"))
335 configure = reply.addElement("configure") 352 configure = reply.addElement("configure")
336 if node_id: 353 if node_id:
337 configure["node"] = node_id 354 configure["node"] = node_id
338 form = configure.addElement((NS_X_DATA, "x")) 355 form = data_form.Form(type="form",
339 form["type"] = "form" 356 form_type=NS_PUBSUB + "#node_config")
340 field = form.addElement("field")
341 field["var"] = "FORM_TYPE"
342 field["type"] = "hidden"
343 field.addElement("value", content=NS_PUBSUB + "#node_config")
344 357
345 for option in options: 358 for option in options:
346 field = form.addElement("field") 359 form.add_field_single(**option)
347 field["var"] = option["var"] 360
348 field["type"] = option["type"] 361 configure.addChild(form)
349 field["label"] = option["label"]
350 field.addElement("value", content=option["value"])
351 362
352 return [reply] 363 return [reply]
353 364
354 def onConfigureSet(self, iq): 365 def onConfigureSet(self, iq):
355 self.handler_wrapper(self._onConfigureSet, iq) 366 self.handler_wrapper(self._onConfigureSet, iq)