annotate idavoll/pubsub.py @ 31:fa866793075d

Split up implementation in several Services that match the division in the backend interfaces. Add appropriate adapter calls.
author Ralph Meijer <ralphm@ik.nu>
date Tue, 26 Oct 2004 16:29:44 +0000
parents 256dcda26752
children c9ddca3cce20
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1
4cc41776b7d7 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
1 from twisted.protocols.jabber import component,jid
2
9701df89c534 First take at notifications
Ralph Meijer <ralphm@ik.nu>
parents: 1
diff changeset
2 from twisted.xish import utility, domish
1
4cc41776b7d7 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
3 from twisted.python import components
23
884268687229 Simplify call chain by mapping incoming requests directly to method
Ralph Meijer <ralphm@ik.nu>
parents: 21
diff changeset
4 from twisted.internet import defer
884268687229 Simplify call chain by mapping incoming requests directly to method
Ralph Meijer <ralphm@ik.nu>
parents: 21
diff changeset
5
1
4cc41776b7d7 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
6 import backend
4cc41776b7d7 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
7 import xmpp_error
4cc41776b7d7 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
8
2
9701df89c534 First take at notifications
Ralph Meijer <ralphm@ik.nu>
parents: 1
diff changeset
9 NS_COMPONENT = 'jabber:component:accept'
9701df89c534 First take at notifications
Ralph Meijer <ralphm@ik.nu>
parents: 1
diff changeset
10 NS_PUBSUB = 'http://jabber.org/protocol/pubsub'
9701df89c534 First take at notifications
Ralph Meijer <ralphm@ik.nu>
parents: 1
diff changeset
11 NS_PUBSUB_EVENT = NS_PUBSUB + '#event'
16
ce3d0db64da1 Implemented basic subscribing.
Ralph Meijer <ralphm@ik.nu>
parents: 12
diff changeset
12 NS_PUBSUB_ERRORS = NS_PUBSUB + '#errors'
2
9701df89c534 First take at notifications
Ralph Meijer <ralphm@ik.nu>
parents: 1
diff changeset
13
1
4cc41776b7d7 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
14 IQ_GET = '/iq[@type="get"]'
4cc41776b7d7 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
15 IQ_SET = '/iq[@type="set"]'
2
9701df89c534 First take at notifications
Ralph Meijer <ralphm@ik.nu>
parents: 1
diff changeset
16 PUBSUB_ELEMENT = '/pubsub[@xmlns="' + NS_PUBSUB + '"]'
9701df89c534 First take at notifications
Ralph Meijer <ralphm@ik.nu>
parents: 1
diff changeset
17 PUBSUB_GET = IQ_GET + PUBSUB_ELEMENT
9701df89c534 First take at notifications
Ralph Meijer <ralphm@ik.nu>
parents: 1
diff changeset
18 PUBSUB_SET = IQ_SET + PUBSUB_ELEMENT
1
4cc41776b7d7 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
19 PUBSUB_CREATE = PUBSUB_SET + '/create'
4cc41776b7d7 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
20 PUBSUB_PUBLISH = PUBSUB_SET + '/publish'
16
ce3d0db64da1 Implemented basic subscribing.
Ralph Meijer <ralphm@ik.nu>
parents: 12
diff changeset
21 PUBSUB_SUBSCRIBE = PUBSUB_SET + '/subscribe'
7
a8cfb31dc50c Implemented fallback for feature-not-implemented.
Ralph Meijer <ralphm@ik.nu>
parents: 4
diff changeset
22 PUBSUB_OPTIONS_GET = PUBSUB_GET + '/options'
21
e01bbbfa8a46 Implemented node creation.
Ralph Meijer <ralphm@ik.nu>
parents: 18
diff changeset
23 PUBSUB_OPTIONS_SET = PUBSUB_SET + '/options'
7
a8cfb31dc50c Implemented fallback for feature-not-implemented.
Ralph Meijer <ralphm@ik.nu>
parents: 4
diff changeset
24 PUBSUB_CONFIGURE_GET = PUBSUB_GET + '/configure'
21
e01bbbfa8a46 Implemented node creation.
Ralph Meijer <ralphm@ik.nu>
parents: 18
diff changeset
25 PUBSUB_CONFIGURE_SET = PUBSUB_SET + '/configure'
1
4cc41776b7d7 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
26
23
884268687229 Simplify call chain by mapping incoming requests directly to method
Ralph Meijer <ralphm@ik.nu>
parents: 21
diff changeset
27 class PubSubError(Exception):
31
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
28 pubsub_error = None
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
29 msg = ''
23
884268687229 Simplify call chain by mapping incoming requests directly to method
Ralph Meijer <ralphm@ik.nu>
parents: 21
diff changeset
30
884268687229 Simplify call chain by mapping incoming requests directly to method
Ralph Meijer <ralphm@ik.nu>
parents: 21
diff changeset
31 class NotImplemented(PubSubError):
31
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
32 pass
23
884268687229 Simplify call chain by mapping incoming requests directly to method
Ralph Meijer <ralphm@ik.nu>
parents: 21
diff changeset
33
884268687229 Simplify call chain by mapping incoming requests directly to method
Ralph Meijer <ralphm@ik.nu>
parents: 21
diff changeset
34 class OptionsUnavailable(PubSubError):
31
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
35 pubsub_error = 'subscription-options-unavailable'
23
884268687229 Simplify call chain by mapping incoming requests directly to method
Ralph Meijer <ralphm@ik.nu>
parents: 21
diff changeset
36
884268687229 Simplify call chain by mapping incoming requests directly to method
Ralph Meijer <ralphm@ik.nu>
parents: 21
diff changeset
37 class SubscriptionOptionsUnavailable(PubSubError):
31
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
38 pubsub_error = 'subscription-options-unavailable'
23
884268687229 Simplify call chain by mapping incoming requests directly to method
Ralph Meijer <ralphm@ik.nu>
parents: 21
diff changeset
39
884268687229 Simplify call chain by mapping incoming requests directly to method
Ralph Meijer <ralphm@ik.nu>
parents: 21
diff changeset
40 class NodeNotConfigurable(PubSubError):
31
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
41 pubsub_error = 'node-not-configurable'
23
884268687229 Simplify call chain by mapping incoming requests directly to method
Ralph Meijer <ralphm@ik.nu>
parents: 21
diff changeset
42
884268687229 Simplify call chain by mapping incoming requests directly to method
Ralph Meijer <ralphm@ik.nu>
parents: 21
diff changeset
43 class CreateNodeNotConfigurable(PubSubError):
31
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
44 pubsub_error = 'node-not-configurable'
23
884268687229 Simplify call chain by mapping incoming requests directly to method
Ralph Meijer <ralphm@ik.nu>
parents: 21
diff changeset
45
4
ea195dc1732d Allow publication of more than 1 item.
Ralph Meijer <ralphm@ik.nu>
parents: 2
diff changeset
46 error_map = {
31
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
47 backend.NotAuthorized: 'not-authorized',
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
48 backend.NodeNotFound: 'item-not-found',
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
49 backend.NoPayloadAllowed: 'bad-request',
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
50 backend.PayloadExpected: 'bad-request',
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
51 backend.NoInstantNodes: 'not-acceptable',
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
52 backend.NodeExists: 'conflict',
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
53 backend.NotImplemented: 'feature-not-implemented',
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
54 NotImplemented: 'feature-not-implemented',
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
55 OptionsUnavailable: 'feature-not-implemented',
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
56 SubscriptionOptionsUnavailable: 'not-acceptable',
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
57 NodeNotConfigurable: 'feature-not-implemented',
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
58 CreateNodeNotConfigurable: 'not-acceptable',
4
ea195dc1732d Allow publication of more than 1 item.
Ralph Meijer <ralphm@ik.nu>
parents: 2
diff changeset
59 }
ea195dc1732d Allow publication of more than 1 item.
Ralph Meijer <ralphm@ik.nu>
parents: 2
diff changeset
60
31
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
61 class Service(component.Service):
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
62
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
63 __implements__ = component.IService
1
4cc41776b7d7 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
64
31
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
65 def __init__(self, backend):
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
66 self.backend = backend
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
67
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
68 def componentConnected(self, xmlstream):
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
69 pass
1
4cc41776b7d7 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
70
31
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
71 def error(self, failure, iq):
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
72 try:
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
73 r = failure.trap(*error_map.keys())
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
74 xmpp_error.error_from_iq(iq, error_map[r], failure.value.msg)
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
75 if isinstance(failure.value, PubSubError) and \
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
76 failure.value.pubsub_error is not None:
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
77 iq.error.addElement((NS_PUBSUB_ERRORS,
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
78 failure.value.pubsub_error),
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
79 NS_PUBSUB_ERRORS)
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
80 return iq
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
81 except:
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
82 xmpp_error.error_from_iq(iq, 'internal-server-error')
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
83 self.send(iq)
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
84 raise
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
85
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
86 def success(self, result, iq):
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
87 iq.swapAttributeValues("to", "from")
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
88 iq["type"] = 'result'
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
89 iq.children = result or []
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
90 return iq
9
52bd563b7a5d Add disco support.
Ralph Meijer <ralphm@ik.nu>
parents: 7
diff changeset
91
31
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
92 def handler_wrapper(self, handler, iq):
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
93 try:
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
94 d = handler(iq)
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
95 except:
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
96 d = defer.fail()
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
97
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
98 d.addCallback(self.success, iq)
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
99 d.addErrback(self.error, iq)
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
100 d.addCallback(self.send)
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
101 iq.handled = True
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
102
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
103 class ComponentServiceFromService(Service):
12
d45e921a5d2a Return implemented features
Ralph Meijer <ralphm@ik.nu>
parents: 9
diff changeset
104
31
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
105 def getIdentities(self, node):
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
106 results = []
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
107 if not node:
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
108 results.append({
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
109 'category': 'pubsub',
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
110 'type': 'generic',
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
111 'name': 'Generic Pubsub Service'
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
112 })
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
113 return results
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
114
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
115 def getFeatures(self, node):
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
116 features = []
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
117
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
118 affiliations = self.backend.get_supported_affiliations()
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
119 if 'outcast' in affiliations:
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
120 features.append("http://jabber.org/protocol/pubsub#outcast-affil")
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
121
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
122 if 'publisher' in affiliations:
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
123 features.append("http://jabber.org/protocol/pubsub#publisher-affil")
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
124
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
125 # "http://jabber.org/protocol/pubsub#persistent-items"
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
126
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
127 return features
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
128
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
129 components.registerAdapter(ComponentServiceFromService, backend.IBackendService, component.IService)
1
4cc41776b7d7 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
130
31
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
131 class ComponentServiceFromNotificationService(Service):
23
884268687229 Simplify call chain by mapping incoming requests directly to method
Ralph Meijer <ralphm@ik.nu>
parents: 21
diff changeset
132
31
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
133 def __init__(self, backend):
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
134 Service.__init__(self, backend)
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
135 self.backend.register_notifier(self.notify)
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
136
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
137 def notify(self, object):
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
138 node_id = object["node_id"]
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
139 items = object["items"]
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
140 d = self.backend.get_notification_list(node_id, items)
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
141 d.addCallback(self._notify, node_id)
7
a8cfb31dc50c Implemented fallback for feature-not-implemented.
Ralph Meijer <ralphm@ik.nu>
parents: 4
diff changeset
142
31
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
143 def _notify(self, list, node_id):
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
144 for recipient, items in list.items():
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
145 self._notify_recipient(recipient, node_id, items)
1
4cc41776b7d7 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
146
31
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
147 def _notify_recipient(self, recipient, node_id, itemlist):
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
148 message = domish.Element((NS_COMPONENT, "message"))
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
149 message["from"] = self.parent.jabberId
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
150 message["to"] = recipient
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
151 event = message.addElement((NS_PUBSUB_EVENT, "event"), NS_PUBSUB_EVENT)
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
152 items = event.addElement("items")
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
153 items["node"] = node_id
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
154 items.children.extend(itemlist)
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
155 self.send(message)
1
4cc41776b7d7 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
156
31
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
157 components.registerAdapter(ComponentServiceFromNotificationService, backend.INotificationService, component.IService)
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
158
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
159 class ComponentServiceFromPublishService(Service):
4
ea195dc1732d Allow publication of more than 1 item.
Ralph Meijer <ralphm@ik.nu>
parents: 2
diff changeset
160
31
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
161 def componentConnected(self, xmlstream):
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
162 xmlstream.addObserver(PUBSUB_PUBLISH, self.onPublish)
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
163
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
164 def onPublish(self, iq):
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
165 self.handler_wrapper(self._onPublish, iq)
4
ea195dc1732d Allow publication of more than 1 item.
Ralph Meijer <ralphm@ik.nu>
parents: 2
diff changeset
166
31
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
167 def _onPublish(self, iq):
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
168 node = iq.pubsub.publish["node"]
1
4cc41776b7d7 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
169
31
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
170 items = []
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
171 for child in iq.pubsub.publish.children:
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
172 if child.__class__ == domish.Element and child.name == 'item':
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
173 items.append(child)
7
a8cfb31dc50c Implemented fallback for feature-not-implemented.
Ralph Meijer <ralphm@ik.nu>
parents: 4
diff changeset
174
31
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
175 print items
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
176
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
177 return self.backend.publish(node, items,
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
178 jid.JID(iq["from"]).userhostJID())
21
e01bbbfa8a46 Implemented node creation.
Ralph Meijer <ralphm@ik.nu>
parents: 18
diff changeset
179
31
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
180 components.registerAdapter(ComponentServiceFromPublishService, backend.IPublishService, component.IService)
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
181
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
182 class ComponentServiceFromSubscriptionService(Service):
16
ce3d0db64da1 Implemented basic subscribing.
Ralph Meijer <ralphm@ik.nu>
parents: 12
diff changeset
183
31
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
184 def componentConnected(self, xmlstream):
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
185 xmlstream.addObserver(PUBSUB_SUBSCRIBE, self.onSubscribe)
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
186
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
187 def onSubscribe(self, iq):
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
188 self.handler_wrapper(self._onSubscribe, iq)
21
e01bbbfa8a46 Implemented node creation.
Ralph Meijer <ralphm@ik.nu>
parents: 18
diff changeset
189
31
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
190 def _onSubscribe(self, iq):
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
191 if iq.pubsub.options:
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
192 raise SubscribeOptionsUnavailable
21
e01bbbfa8a46 Implemented node creation.
Ralph Meijer <ralphm@ik.nu>
parents: 18
diff changeset
193
31
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
194 node_id = iq.pubsub.subscribe["node"]
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
195 subscriber = jid.JID(iq.pubsub.subscribe["jid"])
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
196 requestor = jid.JID(iq["from"]).userhostJID()
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
197 d = self.backend.do_subscribe(node_id, subscriber, requestor)
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
198 d.addCallback(self.return_subscription)
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
199 d.addCallback(self.succeed, iq)
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
200 d.addErrback(self.error, iq)
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
201 d.addCallback(self.send)
16
ce3d0db64da1 Implemented basic subscribing.
Ralph Meijer <ralphm@ik.nu>
parents: 12
diff changeset
202
31
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
203 def _onConfigureGet(self, iq):
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
204 raise NodeNotConfigurable
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
205
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
206 def _onConfigureSet(self, iq):
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
207 raise NodeNotConfigurable
7
a8cfb31dc50c Implemented fallback for feature-not-implemented.
Ralph Meijer <ralphm@ik.nu>
parents: 4
diff changeset
208
31
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
209 def return_subscription(self, result):
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
210 reply = domish.Element("pubsub", NS_PUBSUB)
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
211 entity = reply.addElement("entity")
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
212 entity["node"] = result["node"]
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
213 entity["jid"] = result["jid"].full()
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
214 entity["affiliation"] = result["affiliation"]
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
215 entity["subscription"] = result["subscription"]
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
216 return reply
23
884268687229 Simplify call chain by mapping incoming requests directly to method
Ralph Meijer <ralphm@ik.nu>
parents: 21
diff changeset
217
31
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
218 components.registerAdapter(ComponentServiceFromSubscriptionService, backend.ISubscriptionService, component.IService)
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
219
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
220 class ComponentServiceFromNodeCreationService(Service):
23
884268687229 Simplify call chain by mapping incoming requests directly to method
Ralph Meijer <ralphm@ik.nu>
parents: 21
diff changeset
221
31
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
222 def componentConnected(self, xmlstream):
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
223 xmlstream.addObserver(PUBSUB_CREATE, self.onCreate)
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
224
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
225 def onCreate(self, iq):
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
226 self.handler_wrapper(self._onCreate, iq)
23
884268687229 Simplify call chain by mapping incoming requests directly to method
Ralph Meijer <ralphm@ik.nu>
parents: 21
diff changeset
227
31
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
228 def _onCreate(self, iq):
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
229 if iq.pubsub.options:
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
230 raise CreateNodeNotConfigurable
23
884268687229 Simplify call chain by mapping incoming requests directly to method
Ralph Meijer <ralphm@ik.nu>
parents: 21
diff changeset
231
31
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
232 node = iq.pubsub.create["node"]
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
233 owner = jid.JID(iq["from"]).userhostJID()
23
884268687229 Simplify call chain by mapping incoming requests directly to method
Ralph Meijer <ralphm@ik.nu>
parents: 21
diff changeset
234
31
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
235 d = self.backend.create_node(node, owner)
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
236 d.addCallback(self.return_create_response, iq)
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
237 return d
2
9701df89c534 First take at notifications
Ralph Meijer <ralphm@ik.nu>
parents: 1
diff changeset
238
31
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
239 def _onOptionsGet(self, iq):
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
240 raise OptionsUnavailable
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
241
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
242 def _onOptionsSet(self, iq):
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
243 raise OptionsUnavailable
1
4cc41776b7d7 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
244
31
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
245 def return_create_response(self, result, iq):
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
246 if iq.pubsub.create["node"] is None:
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
247 reply = domish.Element('pubsub', NS_PUBSUB)
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
248 entity = reply.addElement('create')
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
249 entity['node'] = result['node_id']
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
250 return reply
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
251
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
252 components.registerAdapter(ComponentServiceFromNodeCreationService, backend.INodeCreationService, component.IService)