comparison idavoll/pubsub.py @ 7:a8cfb31dc50c

Implemented fallback for feature-not-implemented. Implemented custom response for subscription options and node configuration not implemented.
author Ralph Meijer <ralphm@ik.nu>
date Sun, 27 Jun 2004 15:08:24 +0000
parents ea195dc1732d
children 52bd563b7a5d
comparison
equal deleted inserted replaced
6:76efc9114469 7:a8cfb31dc50c
13 PUBSUB_ELEMENT = '/pubsub[@xmlns="' + NS_PUBSUB + '"]' 13 PUBSUB_ELEMENT = '/pubsub[@xmlns="' + NS_PUBSUB + '"]'
14 PUBSUB_GET = IQ_GET + PUBSUB_ELEMENT 14 PUBSUB_GET = IQ_GET + PUBSUB_ELEMENT
15 PUBSUB_SET = IQ_SET + PUBSUB_ELEMENT 15 PUBSUB_SET = IQ_SET + PUBSUB_ELEMENT
16 PUBSUB_CREATE = PUBSUB_SET + '/create' 16 PUBSUB_CREATE = PUBSUB_SET + '/create'
17 PUBSUB_PUBLISH = PUBSUB_SET + '/publish' 17 PUBSUB_PUBLISH = PUBSUB_SET + '/publish'
18 PUBSUB_OPTIONS_GET = PUBSUB_GET + '/options'
19 PUBSUB_CONFIGURE_GET = PUBSUB_GET + '/configure'
18 20
19 error_map = { 21 error_map = {
20 backend.NotAuthorized: 'not-authorized', 22 backend.NotAuthorized: 'not-authorized',
21 backend.NodeNotFound: 'item-not-found', 23 backend.NodeNotFound: 'item-not-found',
22 backend.NoPayloadAllowed: 'bad-request', 24 backend.NoPayloadAllowed: 'bad-request',
23 backend.EmptyPayloadExpected: 'bad-request',
24 backend.PayloadExpected: 'bad-request', 25 backend.PayloadExpected: 'bad-request',
25 } 26 }
26 27
27 class ComponentServiceFromBackend(component.Service, utility.EventDispatcher): 28 class ComponentServiceFromBackend(component.Service, utility.EventDispatcher):
28 29
29 def __init__(self, backend): 30 def __init__(self, backend):
30 utility.EventDispatcher.__init__(self) 31 utility.EventDispatcher.__init__(self)
31 self.backend = backend 32 self.backend = backend
32 self.backend.pubsub_service = self 33 self.backend.pubsub_service = self
33 self.addObserver(PUBSUB_PUBLISH, self.onPublish) 34 self.addObserver(PUBSUB_PUBLISH, self.onPublish)
35 self.addObserver(PUBSUB_OPTIONS_GET, self.onOptionsGet)
36 self.addObserver(PUBSUB_CONFIGURE_GET, self.onConfigureGet)
37 self.addObserver(PUBSUB_GET, self.notImplemented, -1)
38 self.addObserver(PUBSUB_SET, self.notImplemented, -1)
34 39
35 def componentConnected(self, xmlstream): 40 def componentConnected(self, xmlstream):
36 xmlstream.addObserver(PUBSUB_SET, self.onPubSub) 41 xmlstream.addObserver(PUBSUB_SET, self.onPubSub)
37 xmlstream.addObserver(PUBSUB_GET, self.onPubSub) 42 xmlstream.addObserver(PUBSUB_GET, self.onPubSub)
38 43
46 def success(self, result, iq): 51 def success(self, result, iq):
47 iq.swapAttributeValues("to", "from") 52 iq.swapAttributeValues("to", "from")
48 iq["type"] = 'result' 53 iq["type"] = 'result'
49 iq.children = [] 54 iq.children = []
50 return iq 55 return iq
56
57 def notImplemented(self, iq):
58 self.send(xmpp_error.error_from_iq(iq, 'feature-not-implemented'))
51 59
52 def onPubSub(self, iq): 60 def onPubSub(self, iq):
53 self.dispatch(iq) 61 self.dispatch(iq)
54 iq.handled = True 62 iq.handled = True
55 63
65 73
66 d = self.backend.do_publish(node, jid.JID(iq["from"]).userhost(), items) 74 d = self.backend.do_publish(node, jid.JID(iq["from"]).userhost(), items)
67 d.addCallback(self.success, iq) 75 d.addCallback(self.success, iq)
68 d.addErrback(self.error, iq) 76 d.addErrback(self.error, iq)
69 d.addCallback(self.send) 77 d.addCallback(self.send)
78
79 def onOptionsGet(self, iq):
80 self.send(xmpp_error.error_from_iq(iq, 'feature-not-implemented', 'No subscriber options available'))
81
82 def onConfigureGet(self, iq):
83 self.send(xmpp_error.error_from_iq(iq, 'feature-not-implemented', 'Node can not be configured'))
70 84
71 def do_notification(self, list, node): 85 def do_notification(self, list, node):
72 86
73 for recipient, items in list.items(): 87 for recipient, items in list.items():
74 self.notify(node, items, recipient) 88 self.notify(node, items, recipient)