comparison idavoll/pubsub.py @ 73:5d7a924ebddb

Reworked disco support. Actually return disco items.
author Ralph Meijer <ralphm@ik.nu>
date Sun, 07 Nov 2004 14:21:09 +0000
parents a3d67cbab9c4
children 995ba223a43b
comparison
equal deleted inserted replaced
72:a914cad421c5 73:5d7a924ebddb
3 from twisted.python import components 3 from twisted.python import components
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 9
9 NS_COMPONENT = 'jabber:component:accept' 10 NS_COMPONENT = 'jabber:component:accept'
10 NS_PUBSUB = 'http://jabber.org/protocol/pubsub' 11 NS_PUBSUB = 'http://jabber.org/protocol/pubsub'
11 NS_PUBSUB_EVENT = NS_PUBSUB + '#event' 12 NS_PUBSUB_EVENT = NS_PUBSUB + '#event'
12 NS_PUBSUB_ERRORS = NS_PUBSUB + '#errors' 13 NS_PUBSUB_ERRORS = NS_PUBSUB + '#errors'
111 d.addCallback(self.send) 112 d.addCallback(self.send)
112 iq.handled = True 113 iq.handled = True
113 114
114 class ComponentServiceFromService(Service): 115 class ComponentServiceFromService(Service):
115 116
116 def getIdentities(self, node): 117 def get_disco_info(self, node):
118 info = []
119
120 if not node:
121 info.append(disco.Identity('pubsub', 'generic',
122 'Generic Pubsub Service'))
123
124 if self.backend.supports_publisher_affiliation():
125 info.append(disco.Feature(NS_PUBSUB + "#publisher-affiliation"))
126
127 if self.backend.supports_outcast_affiliation():
128 info.append(disco.Feature(NS_PUBSUB + "#outcast-affiliation"))
129
130 if self.backend.supports_persistent_items():
131 info.append(disco.Feature(NS_PUBSUB + "#persistent-items"))
132
133 return defer.succeed(info)
134 else:
135 d = self.backend.get_node_type(node)
136 d.addCallback(lambda x: [disco.Identity('pubsub', x)])
137 d.addErrback(lambda _: [])
138 return d
139
140 def get_disco_items(self, node):
117 if node: 141 if node:
118 d = self.backend.get_node_type(node) 142 return defer.succeed([])
119 d.addCallback(lambda x: [{'category': 'pubsub', 'type': x}]) 143
120 d.addErrback(lambda x: []) 144 d = self.backend.get_nodes()
121 return d 145 d.addCallback(lambda nodes: [disco.Item(self.parent.jabberId, node)
122 else: 146 for node in nodes])
123 return defer.succeed({'category': 'pubsub', 147 return d
124 'type': 'generic',
125 'name': 'Generic Pubsub Service'})
126
127 def getFeatures(self, node):
128 features = []
129
130 if not node:
131 if self.backend.supports_publisher_affiliation():
132 features.append(NS_PUBSUB + "#publisher-affiliation")
133
134 if self.backend.supports_outcast_affiliation():
135 features.append(NS_PUBSUB + "#outcast-affiliation")
136
137 if self.backend.supports_persistent_items():
138 features.append(NS_PUBSUB + "#persistent-items")
139
140 return defer.succeed(features)
141 148
142 components.registerAdapter(ComponentServiceFromService, backend.IBackendService, component.IService) 149 components.registerAdapter(ComponentServiceFromService, backend.IBackendService, component.IService)
143 150
144 class ComponentServiceFromNotificationService(Service): 151 class ComponentServiceFromNotificationService(Service):
145 152
198 xmlstream.addObserver(PUBSUB_SUBSCRIBE, self.onSubscribe) 205 xmlstream.addObserver(PUBSUB_SUBSCRIBE, self.onSubscribe)
199 xmlstream.addObserver(PUBSUB_UNSUBSCRIBE, self.onUnsubscribe) 206 xmlstream.addObserver(PUBSUB_UNSUBSCRIBE, self.onUnsubscribe)
200 xmlstream.addObserver(PUBSUB_OPTIONS_GET, self.onOptionsGet) 207 xmlstream.addObserver(PUBSUB_OPTIONS_GET, self.onOptionsGet)
201 xmlstream.addObserver(PUBSUB_OPTIONS_SET, self.onOptionsSet) 208 xmlstream.addObserver(PUBSUB_OPTIONS_SET, self.onOptionsSet)
202 209
203 def getFeatures(self, node): 210 def get_disco_info(self, node):
204 features = [] 211 info = []
205 212
206 if not node: 213 if not node:
207 features.append(NS_PUBSUB + "#subscribe") 214 info.append(disco.Feature(NS_PUBSUB + '#subscribe'))
208 215
209 return defer.succeed(features) 216 return defer.succeed(info)
210 217
211 def onSubscribe(self, iq): 218 def onSubscribe(self, iq):
212 self.handler_wrapper(self._onSubscribe, iq) 219 self.handler_wrapper(self._onSubscribe, iq)
213 220
214 def _onSubscribe(self, iq): 221 def _onSubscribe(self, iq):
267 def componentConnected(self, xmlstream): 274 def componentConnected(self, xmlstream):
268 xmlstream.addObserver(PUBSUB_CREATE, self.onCreate) 275 xmlstream.addObserver(PUBSUB_CREATE, self.onCreate)
269 xmlstream.addObserver(PUBSUB_CONFIGURE_GET, self.onConfigureGet) 276 xmlstream.addObserver(PUBSUB_CONFIGURE_GET, self.onConfigureGet)
270 xmlstream.addObserver(PUBSUB_CONFIGURE_SET, self.onConfigureSet) 277 xmlstream.addObserver(PUBSUB_CONFIGURE_SET, self.onConfigureSet)
271 278
272 def getFeatures(self, node): 279 def get_disco_info(self, node):
273 features = [] 280 info = []
274 281
275 if not node: 282 if not node:
276 features.append(NS_PUBSUB + "#create-nodes") 283 info.append(disco.Feature(NS_PUBSUB + "#create-nodes"))
277 284
278 if self.backend.supports_instant_nodes(): 285 if self.backend.supports_instant_nodes():
279 features.append(NS_PUBSUB + "#instant-nodes") 286 info.append(disco.Feature(NS_PUBSUB + "#instant-nodes"))
280 287
281 return defer.succeed(features) 288 return defer.succeed(info)
282 289
283 def onCreate(self, iq): 290 def onCreate(self, iq):
284 self.handler_wrapper(self._onCreate, iq) 291 self.handler_wrapper(self._onCreate, iq)
285 292
286 def _onCreate(self, iq): 293 def _onCreate(self, iq):