annotate idavoll/pubsub.py @ 90:59378610b16e

Implement node purging and node deletion.
author Ralph Meijer <ralphm@ik.nu>
date Wed, 17 Nov 2004 20:43:13 +0000
parents ec557449d1aa
children ea3b2410c01c
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
73
5d7a924ebddb Reworked disco support.
Ralph Meijer <ralphm@ik.nu>
parents: 68
diff changeset
8 import disco
1
4cc41776b7d7 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
9
2
9701df89c534 First take at notifications
Ralph Meijer <ralphm@ik.nu>
parents: 1
diff changeset
10 NS_COMPONENT = 'jabber:component:accept'
9701df89c534 First take at notifications
Ralph Meijer <ralphm@ik.nu>
parents: 1
diff changeset
11 NS_PUBSUB = 'http://jabber.org/protocol/pubsub'
9701df89c534 First take at notifications
Ralph Meijer <ralphm@ik.nu>
parents: 1
diff changeset
12 NS_PUBSUB_EVENT = NS_PUBSUB + '#event'
16
ce3d0db64da1 Implemented basic subscribing.
Ralph Meijer <ralphm@ik.nu>
parents: 12
diff changeset
13 NS_PUBSUB_ERRORS = NS_PUBSUB + '#errors'
2
9701df89c534 First take at notifications
Ralph Meijer <ralphm@ik.nu>
parents: 1
diff changeset
14
1
4cc41776b7d7 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
15 IQ_GET = '/iq[@type="get"]'
4cc41776b7d7 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
16 IQ_SET = '/iq[@type="set"]'
2
9701df89c534 First take at notifications
Ralph Meijer <ralphm@ik.nu>
parents: 1
diff changeset
17 PUBSUB_ELEMENT = '/pubsub[@xmlns="' + NS_PUBSUB + '"]'
9701df89c534 First take at notifications
Ralph Meijer <ralphm@ik.nu>
parents: 1
diff changeset
18 PUBSUB_GET = IQ_GET + PUBSUB_ELEMENT
9701df89c534 First take at notifications
Ralph Meijer <ralphm@ik.nu>
parents: 1
diff changeset
19 PUBSUB_SET = IQ_SET + PUBSUB_ELEMENT
1
4cc41776b7d7 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
20 PUBSUB_CREATE = PUBSUB_SET + '/create'
4cc41776b7d7 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
21 PUBSUB_PUBLISH = PUBSUB_SET + '/publish'
16
ce3d0db64da1 Implemented basic subscribing.
Ralph Meijer <ralphm@ik.nu>
parents: 12
diff changeset
22 PUBSUB_SUBSCRIBE = PUBSUB_SET + '/subscribe'
38
c9ddca3cce20 Change exception classes to include stanza error.
Ralph Meijer <ralphm@ik.nu>
parents: 31
diff changeset
23 PUBSUB_UNSUBSCRIBE = PUBSUB_SET + '/unsubscribe'
7
a8cfb31dc50c Implemented fallback for feature-not-implemented.
Ralph Meijer <ralphm@ik.nu>
parents: 4
diff changeset
24 PUBSUB_OPTIONS_GET = PUBSUB_GET + '/options'
21
e01bbbfa8a46 Implemented node creation.
Ralph Meijer <ralphm@ik.nu>
parents: 18
diff changeset
25 PUBSUB_OPTIONS_SET = PUBSUB_SET + '/options'
7
a8cfb31dc50c Implemented fallback for feature-not-implemented.
Ralph Meijer <ralphm@ik.nu>
parents: 4
diff changeset
26 PUBSUB_CONFIGURE_GET = PUBSUB_GET + '/configure'
21
e01bbbfa8a46 Implemented node creation.
Ralph Meijer <ralphm@ik.nu>
parents: 18
diff changeset
27 PUBSUB_CONFIGURE_SET = PUBSUB_SET + '/configure'
60
f6b7a06b8870 Implement retrieving affiliations.
Ralph Meijer <ralphm@ik.nu>
parents: 58
diff changeset
28 PUBSUB_AFFILIATIONS = PUBSUB_GET + '/affiliations'
81
995ba223a43b Implemented ComponentServiceToItemRetrievalService.
Ralph Meijer <ralphm@ik.nu>
parents: 73
diff changeset
29 PUBSUB_ITEMS = PUBSUB_GET + '/items'
85
ec557449d1aa Implement node retraction, with storage support for pgsql.
Ralph Meijer <ralphm@ik.nu>
parents: 83
diff changeset
30 PUBSUB_RETRACT = PUBSUB_SET + '/retract'
90
59378610b16e Implement node purging and node deletion.
Ralph Meijer <ralphm@ik.nu>
parents: 85
diff changeset
31 PUBSUB_PURGE = PUBSUB_SET + '/purge'
59378610b16e Implement node purging and node deletion.
Ralph Meijer <ralphm@ik.nu>
parents: 85
diff changeset
32 PUBSUB_DELETE = PUBSUB_SET + '/delete'
1
4cc41776b7d7 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
33
38
c9ddca3cce20 Change exception classes to include stanza error.
Ralph Meijer <ralphm@ik.nu>
parents: 31
diff changeset
34 class Error(Exception):
31
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
35 pubsub_error = None
38
c9ddca3cce20 Change exception classes to include stanza error.
Ralph Meijer <ralphm@ik.nu>
parents: 31
diff changeset
36 stanza_error = None
31
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
37 msg = ''
23
884268687229 Simplify call chain by mapping incoming requests directly to method
Ralph Meijer <ralphm@ik.nu>
parents: 21
diff changeset
38
38
c9ddca3cce20 Change exception classes to include stanza error.
Ralph Meijer <ralphm@ik.nu>
parents: 31
diff changeset
39 class NotImplemented(Error):
c9ddca3cce20 Change exception classes to include stanza error.
Ralph Meijer <ralphm@ik.nu>
parents: 31
diff changeset
40 stanza_error = 'feature-not-implemented'
23
884268687229 Simplify call chain by mapping incoming requests directly to method
Ralph Meijer <ralphm@ik.nu>
parents: 21
diff changeset
41
47
31eb00734cc5 Check for malformed unsubscribe request.
Ralph Meijer <ralphm@ik.nu>
parents: 38
diff changeset
42 class BadRequest(Error):
31eb00734cc5 Check for malformed unsubscribe request.
Ralph Meijer <ralphm@ik.nu>
parents: 38
diff changeset
43 stanza_error = 'bad-request'
31eb00734cc5 Check for malformed unsubscribe request.
Ralph Meijer <ralphm@ik.nu>
parents: 38
diff changeset
44
38
c9ddca3cce20 Change exception classes to include stanza error.
Ralph Meijer <ralphm@ik.nu>
parents: 31
diff changeset
45 class OptionsUnavailable(Error):
c9ddca3cce20 Change exception classes to include stanza error.
Ralph Meijer <ralphm@ik.nu>
parents: 31
diff changeset
46 stanza_error = 'feature-not-implemented'
31
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
47 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
48
38
c9ddca3cce20 Change exception classes to include stanza error.
Ralph Meijer <ralphm@ik.nu>
parents: 31
diff changeset
49 class SubscriptionOptionsUnavailable(Error):
c9ddca3cce20 Change exception classes to include stanza error.
Ralph Meijer <ralphm@ik.nu>
parents: 31
diff changeset
50 stanza_error = 'not-acceptable'
31
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
51 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
52
38
c9ddca3cce20 Change exception classes to include stanza error.
Ralph Meijer <ralphm@ik.nu>
parents: 31
diff changeset
53 class NodeNotConfigurable(Error):
c9ddca3cce20 Change exception classes to include stanza error.
Ralph Meijer <ralphm@ik.nu>
parents: 31
diff changeset
54 stanza_error = 'feature-not-implemented'
31
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
55 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
56
38
c9ddca3cce20 Change exception classes to include stanza error.
Ralph Meijer <ralphm@ik.nu>
parents: 31
diff changeset
57 class CreateNodeNotConfigurable(Error):
c9ddca3cce20 Change exception classes to include stanza error.
Ralph Meijer <ralphm@ik.nu>
parents: 31
diff changeset
58 stanza_error = 'not-acceptable'
31
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
59 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
60
47
31eb00734cc5 Check for malformed unsubscribe request.
Ralph Meijer <ralphm@ik.nu>
parents: 38
diff changeset
61
31eb00734cc5 Check for malformed unsubscribe request.
Ralph Meijer <ralphm@ik.nu>
parents: 38
diff changeset
62
4
ea195dc1732d Allow publication of more than 1 item.
Ralph Meijer <ralphm@ik.nu>
parents: 2
diff changeset
63 error_map = {
38
c9ddca3cce20 Change exception classes to include stanza error.
Ralph Meijer <ralphm@ik.nu>
parents: 31
diff changeset
64 backend.NotAuthorized: ('not-authorized', None),
c9ddca3cce20 Change exception classes to include stanza error.
Ralph Meijer <ralphm@ik.nu>
parents: 31
diff changeset
65 backend.NodeNotFound: ('item-not-found', None),
c9ddca3cce20 Change exception classes to include stanza error.
Ralph Meijer <ralphm@ik.nu>
parents: 31
diff changeset
66 backend.NoPayloadAllowed: ('bad-request', None),
c9ddca3cce20 Change exception classes to include stanza error.
Ralph Meijer <ralphm@ik.nu>
parents: 31
diff changeset
67 backend.PayloadExpected: ('bad-request', None),
c9ddca3cce20 Change exception classes to include stanza error.
Ralph Meijer <ralphm@ik.nu>
parents: 31
diff changeset
68 backend.NoInstantNodes: ('not-acceptable', None),
c9ddca3cce20 Change exception classes to include stanza error.
Ralph Meijer <ralphm@ik.nu>
parents: 31
diff changeset
69 backend.NodeExists: ('conflict', None),
c9ddca3cce20 Change exception classes to include stanza error.
Ralph Meijer <ralphm@ik.nu>
parents: 31
diff changeset
70 backend.NotImplemented: ('feature-not-implemented', None),
c9ddca3cce20 Change exception classes to include stanza error.
Ralph Meijer <ralphm@ik.nu>
parents: 31
diff changeset
71 backend.NotSubscribed: ('not-authorized', 'requestor-not-subscribed'),
4
ea195dc1732d Allow publication of more than 1 item.
Ralph Meijer <ralphm@ik.nu>
parents: 2
diff changeset
72 }
ea195dc1732d Allow publication of more than 1 item.
Ralph Meijer <ralphm@ik.nu>
parents: 2
diff changeset
73
31
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
74 class Service(component.Service):
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
75
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
76 __implements__ = component.IService
1
4cc41776b7d7 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
77
31
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
78 def __init__(self, backend):
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
79 self.backend = backend
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
80
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
81 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
82 try:
38
c9ddca3cce20 Change exception classes to include stanza error.
Ralph Meijer <ralphm@ik.nu>
parents: 31
diff changeset
83 e = failure.trap(Error, *error_map.keys())
81
995ba223a43b Implemented ComponentServiceToItemRetrievalService.
Ralph Meijer <ralphm@ik.nu>
parents: 73
diff changeset
84 except:
995ba223a43b Implemented ComponentServiceToItemRetrievalService.
Ralph Meijer <ralphm@ik.nu>
parents: 73
diff changeset
85 failure.printBriefTraceback()
995ba223a43b Implemented ComponentServiceToItemRetrievalService.
Ralph Meijer <ralphm@ik.nu>
parents: 73
diff changeset
86 xmpp_error.error_from_iq(iq, 'internal-server-error')
995ba223a43b Implemented ComponentServiceToItemRetrievalService.
Ralph Meijer <ralphm@ik.nu>
parents: 73
diff changeset
87 return iq
995ba223a43b Implemented ComponentServiceToItemRetrievalService.
Ralph Meijer <ralphm@ik.nu>
parents: 73
diff changeset
88 else:
38
c9ddca3cce20 Change exception classes to include stanza error.
Ralph Meijer <ralphm@ik.nu>
parents: 31
diff changeset
89 if e == Error:
c9ddca3cce20 Change exception classes to include stanza error.
Ralph Meijer <ralphm@ik.nu>
parents: 31
diff changeset
90 stanza_error = failure.value.stanza_error
c9ddca3cce20 Change exception classes to include stanza error.
Ralph Meijer <ralphm@ik.nu>
parents: 31
diff changeset
91 pubsub_error = failure.value.pubsub_error
c9ddca3cce20 Change exception classes to include stanza error.
Ralph Meijer <ralphm@ik.nu>
parents: 31
diff changeset
92 msg = ''
c9ddca3cce20 Change exception classes to include stanza error.
Ralph Meijer <ralphm@ik.nu>
parents: 31
diff changeset
93 else:
c9ddca3cce20 Change exception classes to include stanza error.
Ralph Meijer <ralphm@ik.nu>
parents: 31
diff changeset
94 stanza_error, pubsub_error = error_map[e]
c9ddca3cce20 Change exception classes to include stanza error.
Ralph Meijer <ralphm@ik.nu>
parents: 31
diff changeset
95 msg = failure.value.msg
c9ddca3cce20 Change exception classes to include stanza error.
Ralph Meijer <ralphm@ik.nu>
parents: 31
diff changeset
96
c9ddca3cce20 Change exception classes to include stanza error.
Ralph Meijer <ralphm@ik.nu>
parents: 31
diff changeset
97 xmpp_error.error_from_iq(iq, stanza_error, msg)
c9ddca3cce20 Change exception classes to include stanza error.
Ralph Meijer <ralphm@ik.nu>
parents: 31
diff changeset
98 if pubsub_error:
c9ddca3cce20 Change exception classes to include stanza error.
Ralph Meijer <ralphm@ik.nu>
parents: 31
diff changeset
99 iq.error.addElement((NS_PUBSUB_ERRORS, pubsub_error))
31
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
100 return iq
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
101
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
102 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
103 iq.swapAttributeValues("to", "from")
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
104 iq["type"] = 'result'
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
105 iq.children = result or []
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
106 return iq
9
52bd563b7a5d Add disco support.
Ralph Meijer <ralphm@ik.nu>
parents: 7
diff changeset
107
31
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
108 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
109 try:
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
110 d = handler(iq)
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
111 except:
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
112 d = defer.fail()
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
113
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
114 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
115 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
116 d.addCallback(self.send)
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
117 iq.handled = True
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
118
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
119 class ComponentServiceFromService(Service):
12
d45e921a5d2a Return implemented features
Ralph Meijer <ralphm@ik.nu>
parents: 9
diff changeset
120
73
5d7a924ebddb Reworked disco support.
Ralph Meijer <ralphm@ik.nu>
parents: 68
diff changeset
121 def get_disco_info(self, node):
5d7a924ebddb Reworked disco support.
Ralph Meijer <ralphm@ik.nu>
parents: 68
diff changeset
122 info = []
31
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
123
56
55fa890ef60b Match backend's supported_*() methods in getFeatures() of ComponentServiceFromService.
Ralph Meijer <ralphm@ik.nu>
parents: 48
diff changeset
124 if not node:
73
5d7a924ebddb Reworked disco support.
Ralph Meijer <ralphm@ik.nu>
parents: 68
diff changeset
125 info.append(disco.Identity('pubsub', 'generic',
5d7a924ebddb Reworked disco support.
Ralph Meijer <ralphm@ik.nu>
parents: 68
diff changeset
126 'Generic Pubsub Service'))
5d7a924ebddb Reworked disco support.
Ralph Meijer <ralphm@ik.nu>
parents: 68
diff changeset
127
56
55fa890ef60b Match backend's supported_*() methods in getFeatures() of ComponentServiceFromService.
Ralph Meijer <ralphm@ik.nu>
parents: 48
diff changeset
128 if self.backend.supports_publisher_affiliation():
73
5d7a924ebddb Reworked disco support.
Ralph Meijer <ralphm@ik.nu>
parents: 68
diff changeset
129 info.append(disco.Feature(NS_PUBSUB + "#publisher-affiliation"))
31
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
130
56
55fa890ef60b Match backend's supported_*() methods in getFeatures() of ComponentServiceFromService.
Ralph Meijer <ralphm@ik.nu>
parents: 48
diff changeset
131 if self.backend.supports_outcast_affiliation():
73
5d7a924ebddb Reworked disco support.
Ralph Meijer <ralphm@ik.nu>
parents: 68
diff changeset
132 info.append(disco.Feature(NS_PUBSUB + "#outcast-affiliation"))
31
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
133
56
55fa890ef60b Match backend's supported_*() methods in getFeatures() of ComponentServiceFromService.
Ralph Meijer <ralphm@ik.nu>
parents: 48
diff changeset
134 if self.backend.supports_persistent_items():
73
5d7a924ebddb Reworked disco support.
Ralph Meijer <ralphm@ik.nu>
parents: 68
diff changeset
135 info.append(disco.Feature(NS_PUBSUB + "#persistent-items"))
5d7a924ebddb Reworked disco support.
Ralph Meijer <ralphm@ik.nu>
parents: 68
diff changeset
136
5d7a924ebddb Reworked disco support.
Ralph Meijer <ralphm@ik.nu>
parents: 68
diff changeset
137 return defer.succeed(info)
5d7a924ebddb Reworked disco support.
Ralph Meijer <ralphm@ik.nu>
parents: 68
diff changeset
138 else:
5d7a924ebddb Reworked disco support.
Ralph Meijer <ralphm@ik.nu>
parents: 68
diff changeset
139 d = self.backend.get_node_type(node)
5d7a924ebddb Reworked disco support.
Ralph Meijer <ralphm@ik.nu>
parents: 68
diff changeset
140 d.addCallback(lambda x: [disco.Identity('pubsub', x)])
5d7a924ebddb Reworked disco support.
Ralph Meijer <ralphm@ik.nu>
parents: 68
diff changeset
141 d.addErrback(lambda _: [])
5d7a924ebddb Reworked disco support.
Ralph Meijer <ralphm@ik.nu>
parents: 68
diff changeset
142 return d
31
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
143
73
5d7a924ebddb Reworked disco support.
Ralph Meijer <ralphm@ik.nu>
parents: 68
diff changeset
144 def get_disco_items(self, node):
5d7a924ebddb Reworked disco support.
Ralph Meijer <ralphm@ik.nu>
parents: 68
diff changeset
145 if node:
5d7a924ebddb Reworked disco support.
Ralph Meijer <ralphm@ik.nu>
parents: 68
diff changeset
146 return defer.succeed([])
5d7a924ebddb Reworked disco support.
Ralph Meijer <ralphm@ik.nu>
parents: 68
diff changeset
147
5d7a924ebddb Reworked disco support.
Ralph Meijer <ralphm@ik.nu>
parents: 68
diff changeset
148 d = self.backend.get_nodes()
5d7a924ebddb Reworked disco support.
Ralph Meijer <ralphm@ik.nu>
parents: 68
diff changeset
149 d.addCallback(lambda nodes: [disco.Item(self.parent.jabberId, node)
5d7a924ebddb Reworked disco support.
Ralph Meijer <ralphm@ik.nu>
parents: 68
diff changeset
150 for node in nodes])
5d7a924ebddb Reworked disco support.
Ralph Meijer <ralphm@ik.nu>
parents: 68
diff changeset
151 return d
31
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
152
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
153 components.registerAdapter(ComponentServiceFromService, backend.IBackendService, component.IService)
1
4cc41776b7d7 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
154
31
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
155 class ComponentServiceFromNotificationService(Service):
23
884268687229 Simplify call chain by mapping incoming requests directly to method
Ralph Meijer <ralphm@ik.nu>
parents: 21
diff changeset
156
38
c9ddca3cce20 Change exception classes to include stanza error.
Ralph Meijer <ralphm@ik.nu>
parents: 31
diff changeset
157 def componentConnected(self, xmlstream):
31
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
158 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
159
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
160 def notify(self, object):
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
161 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
162 items = object["items"]
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
163 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
164 d.addCallback(self._notify, node_id)
7
a8cfb31dc50c Implemented fallback for feature-not-implemented.
Ralph Meijer <ralphm@ik.nu>
parents: 4
diff changeset
165
31
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
166 def _notify(self, list, node_id):
38
c9ddca3cce20 Change exception classes to include stanza error.
Ralph Meijer <ralphm@ik.nu>
parents: 31
diff changeset
167 print list
31
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
168 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
169 self._notify_recipient(recipient, node_id, items)
1
4cc41776b7d7 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
170
31
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
171 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
172 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
173 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
174 message["to"] = recipient
38
c9ddca3cce20 Change exception classes to include stanza error.
Ralph Meijer <ralphm@ik.nu>
parents: 31
diff changeset
175 event = message.addElement((NS_PUBSUB_EVENT, "event"))
31
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
176 items = event.addElement("items")
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
177 items["node"] = node_id
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
178 items.children.extend(itemlist)
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
179 self.send(message)
1
4cc41776b7d7 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
180
31
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
181 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
182
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
183 class ComponentServiceFromPublishService(Service):
4
ea195dc1732d Allow publication of more than 1 item.
Ralph Meijer <ralphm@ik.nu>
parents: 2
diff changeset
184
31
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
185 def componentConnected(self, xmlstream):
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
186 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
187
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
188 def onPublish(self, iq):
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
189 self.handler_wrapper(self._onPublish, iq)
4
ea195dc1732d Allow publication of more than 1 item.
Ralph Meijer <ralphm@ik.nu>
parents: 2
diff changeset
190
31
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
191 def _onPublish(self, iq):
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
192 node = iq.pubsub.publish["node"]
1
4cc41776b7d7 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
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 items = []
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
195 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
196 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
197 items.append(child)
7
a8cfb31dc50c Implemented fallback for feature-not-implemented.
Ralph Meijer <ralphm@ik.nu>
parents: 4
diff changeset
198
31
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
199 print items
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
200
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
201 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
202 jid.JID(iq["from"]).userhostJID())
21
e01bbbfa8a46 Implemented node creation.
Ralph Meijer <ralphm@ik.nu>
parents: 18
diff changeset
203
31
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
204 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
205
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
206 class ComponentServiceFromSubscriptionService(Service):
16
ce3d0db64da1 Implemented basic subscribing.
Ralph Meijer <ralphm@ik.nu>
parents: 12
diff changeset
207
31
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
208 def componentConnected(self, xmlstream):
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
209 xmlstream.addObserver(PUBSUB_SUBSCRIBE, self.onSubscribe)
38
c9ddca3cce20 Change exception classes to include stanza error.
Ralph Meijer <ralphm@ik.nu>
parents: 31
diff changeset
210 xmlstream.addObserver(PUBSUB_UNSUBSCRIBE, self.onUnsubscribe)
c9ddca3cce20 Change exception classes to include stanza error.
Ralph Meijer <ralphm@ik.nu>
parents: 31
diff changeset
211 xmlstream.addObserver(PUBSUB_OPTIONS_GET, self.onOptionsGet)
c9ddca3cce20 Change exception classes to include stanza error.
Ralph Meijer <ralphm@ik.nu>
parents: 31
diff changeset
212 xmlstream.addObserver(PUBSUB_OPTIONS_SET, self.onOptionsSet)
58
3e2e0040e3e0 Return support for the pubsub#subscribe feature.
Ralph Meijer <ralphm@ik.nu>
parents: 56
diff changeset
213
73
5d7a924ebddb Reworked disco support.
Ralph Meijer <ralphm@ik.nu>
parents: 68
diff changeset
214 def get_disco_info(self, node):
5d7a924ebddb Reworked disco support.
Ralph Meijer <ralphm@ik.nu>
parents: 68
diff changeset
215 info = []
58
3e2e0040e3e0 Return support for the pubsub#subscribe feature.
Ralph Meijer <ralphm@ik.nu>
parents: 56
diff changeset
216
3e2e0040e3e0 Return support for the pubsub#subscribe feature.
Ralph Meijer <ralphm@ik.nu>
parents: 56
diff changeset
217 if not node:
73
5d7a924ebddb Reworked disco support.
Ralph Meijer <ralphm@ik.nu>
parents: 68
diff changeset
218 info.append(disco.Feature(NS_PUBSUB + '#subscribe'))
58
3e2e0040e3e0 Return support for the pubsub#subscribe feature.
Ralph Meijer <ralphm@ik.nu>
parents: 56
diff changeset
219
73
5d7a924ebddb Reworked disco support.
Ralph Meijer <ralphm@ik.nu>
parents: 68
diff changeset
220 return defer.succeed(info)
31
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
221
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
222 def onSubscribe(self, iq):
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
223 self.handler_wrapper(self._onSubscribe, iq)
21
e01bbbfa8a46 Implemented node creation.
Ralph Meijer <ralphm@ik.nu>
parents: 18
diff changeset
224
31
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
225 def _onSubscribe(self, iq):
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
226 if iq.pubsub.options:
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
227 raise SubscribeOptionsUnavailable
21
e01bbbfa8a46 Implemented node creation.
Ralph Meijer <ralphm@ik.nu>
parents: 18
diff changeset
228
48
671ead538758 Check for malformed subscription request.
Ralph Meijer <ralphm@ik.nu>
parents: 47
diff changeset
229 try:
671ead538758 Check for malformed subscription request.
Ralph Meijer <ralphm@ik.nu>
parents: 47
diff changeset
230 node_id = iq.pubsub.subscribe["node"]
671ead538758 Check for malformed subscription request.
Ralph Meijer <ralphm@ik.nu>
parents: 47
diff changeset
231 subscriber = jid.JID(iq.pubsub.subscribe["jid"])
671ead538758 Check for malformed subscription request.
Ralph Meijer <ralphm@ik.nu>
parents: 47
diff changeset
232 except KeyError:
671ead538758 Check for malformed subscription request.
Ralph Meijer <ralphm@ik.nu>
parents: 47
diff changeset
233 raise BadRequest
671ead538758 Check for malformed subscription request.
Ralph Meijer <ralphm@ik.nu>
parents: 47
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 requestor = jid.JID(iq["from"]).userhostJID()
38
c9ddca3cce20 Change exception classes to include stanza error.
Ralph Meijer <ralphm@ik.nu>
parents: 31
diff changeset
236 d = self.backend.subscribe(node_id, subscriber, requestor)
31
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
237 d.addCallback(self.return_subscription)
38
c9ddca3cce20 Change exception classes to include stanza error.
Ralph Meijer <ralphm@ik.nu>
parents: 31
diff changeset
238 return d
7
a8cfb31dc50c Implemented fallback for feature-not-implemented.
Ralph Meijer <ralphm@ik.nu>
parents: 4
diff changeset
239
31
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
240 def return_subscription(self, result):
60
f6b7a06b8870 Implement retrieving affiliations.
Ralph Meijer <ralphm@ik.nu>
parents: 58
diff changeset
241 reply = domish.Element((NS_PUBSUB, "pubsub"))
31
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
242 entity = reply.addElement("entity")
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
243 entity["node"] = result["node"]
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
244 entity["jid"] = result["jid"].full()
48
671ead538758 Check for malformed subscription request.
Ralph Meijer <ralphm@ik.nu>
parents: 47
diff changeset
245 entity["affiliation"] = result["affiliation"] or 'none'
31
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
246 entity["subscription"] = result["subscription"]
38
c9ddca3cce20 Change exception classes to include stanza error.
Ralph Meijer <ralphm@ik.nu>
parents: 31
diff changeset
247 return [reply]
c9ddca3cce20 Change exception classes to include stanza error.
Ralph Meijer <ralphm@ik.nu>
parents: 31
diff changeset
248
c9ddca3cce20 Change exception classes to include stanza error.
Ralph Meijer <ralphm@ik.nu>
parents: 31
diff changeset
249 def onUnsubscribe(self, iq):
c9ddca3cce20 Change exception classes to include stanza error.
Ralph Meijer <ralphm@ik.nu>
parents: 31
diff changeset
250 self.handler_wrapper(self._onUnsubscribe, iq)
c9ddca3cce20 Change exception classes to include stanza error.
Ralph Meijer <ralphm@ik.nu>
parents: 31
diff changeset
251
c9ddca3cce20 Change exception classes to include stanza error.
Ralph Meijer <ralphm@ik.nu>
parents: 31
diff changeset
252 def _onUnsubscribe(self, iq):
47
31eb00734cc5 Check for malformed unsubscribe request.
Ralph Meijer <ralphm@ik.nu>
parents: 38
diff changeset
253 try:
31eb00734cc5 Check for malformed unsubscribe request.
Ralph Meijer <ralphm@ik.nu>
parents: 38
diff changeset
254 node_id = iq.pubsub.unsubscribe["node"]
48
671ead538758 Check for malformed subscription request.
Ralph Meijer <ralphm@ik.nu>
parents: 47
diff changeset
255 subscriber = jid.JID(iq.pubsub.unsubscribe["jid"])
47
31eb00734cc5 Check for malformed unsubscribe request.
Ralph Meijer <ralphm@ik.nu>
parents: 38
diff changeset
256 except KeyError:
31eb00734cc5 Check for malformed unsubscribe request.
Ralph Meijer <ralphm@ik.nu>
parents: 38
diff changeset
257 raise BadRequest
31eb00734cc5 Check for malformed unsubscribe request.
Ralph Meijer <ralphm@ik.nu>
parents: 38
diff changeset
258
38
c9ddca3cce20 Change exception classes to include stanza error.
Ralph Meijer <ralphm@ik.nu>
parents: 31
diff changeset
259 requestor = jid.JID(iq["from"]).userhostJID()
c9ddca3cce20 Change exception classes to include stanza error.
Ralph Meijer <ralphm@ik.nu>
parents: 31
diff changeset
260 return self.backend.unsubscribe(node_id, subscriber, requestor)
c9ddca3cce20 Change exception classes to include stanza error.
Ralph Meijer <ralphm@ik.nu>
parents: 31
diff changeset
261
c9ddca3cce20 Change exception classes to include stanza error.
Ralph Meijer <ralphm@ik.nu>
parents: 31
diff changeset
262 def onOptionsGet(self, iq):
c9ddca3cce20 Change exception classes to include stanza error.
Ralph Meijer <ralphm@ik.nu>
parents: 31
diff changeset
263 self.handler_wrapper(self._onOptionsGet, iq)
c9ddca3cce20 Change exception classes to include stanza error.
Ralph Meijer <ralphm@ik.nu>
parents: 31
diff changeset
264
c9ddca3cce20 Change exception classes to include stanza error.
Ralph Meijer <ralphm@ik.nu>
parents: 31
diff changeset
265 def _onOptionsGet(self, iq):
c9ddca3cce20 Change exception classes to include stanza error.
Ralph Meijer <ralphm@ik.nu>
parents: 31
diff changeset
266 raise OptionsUnavailable
c9ddca3cce20 Change exception classes to include stanza error.
Ralph Meijer <ralphm@ik.nu>
parents: 31
diff changeset
267
c9ddca3cce20 Change exception classes to include stanza error.
Ralph Meijer <ralphm@ik.nu>
parents: 31
diff changeset
268 def onOptionsSet(self, iq):
c9ddca3cce20 Change exception classes to include stanza error.
Ralph Meijer <ralphm@ik.nu>
parents: 31
diff changeset
269 self.handler_wrapper(self._onOptionsSet, iq)
c9ddca3cce20 Change exception classes to include stanza error.
Ralph Meijer <ralphm@ik.nu>
parents: 31
diff changeset
270
c9ddca3cce20 Change exception classes to include stanza error.
Ralph Meijer <ralphm@ik.nu>
parents: 31
diff changeset
271 def _onOptionsSet(self, iq):
c9ddca3cce20 Change exception classes to include stanza error.
Ralph Meijer <ralphm@ik.nu>
parents: 31
diff changeset
272 raise OptionsUnavailable
23
884268687229 Simplify call chain by mapping incoming requests directly to method
Ralph Meijer <ralphm@ik.nu>
parents: 21
diff changeset
273
31
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
274 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
275
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
276 class ComponentServiceFromNodeCreationService(Service):
23
884268687229 Simplify call chain by mapping incoming requests directly to method
Ralph Meijer <ralphm@ik.nu>
parents: 21
diff changeset
277
68
a3d67cbab9c4 Return deferreds from getFeatures() and getIdentities().
Ralph Meijer <ralphm@ik.nu>
parents: 60
diff changeset
278 def componentConnected(self, xmlstream):
a3d67cbab9c4 Return deferreds from getFeatures() and getIdentities().
Ralph Meijer <ralphm@ik.nu>
parents: 60
diff changeset
279 xmlstream.addObserver(PUBSUB_CREATE, self.onCreate)
a3d67cbab9c4 Return deferreds from getFeatures() and getIdentities().
Ralph Meijer <ralphm@ik.nu>
parents: 60
diff changeset
280 xmlstream.addObserver(PUBSUB_CONFIGURE_GET, self.onConfigureGet)
a3d67cbab9c4 Return deferreds from getFeatures() and getIdentities().
Ralph Meijer <ralphm@ik.nu>
parents: 60
diff changeset
281 xmlstream.addObserver(PUBSUB_CONFIGURE_SET, self.onConfigureSet)
a3d67cbab9c4 Return deferreds from getFeatures() and getIdentities().
Ralph Meijer <ralphm@ik.nu>
parents: 60
diff changeset
282
73
5d7a924ebddb Reworked disco support.
Ralph Meijer <ralphm@ik.nu>
parents: 68
diff changeset
283 def get_disco_info(self, node):
5d7a924ebddb Reworked disco support.
Ralph Meijer <ralphm@ik.nu>
parents: 68
diff changeset
284 info = []
56
55fa890ef60b Match backend's supported_*() methods in getFeatures() of ComponentServiceFromService.
Ralph Meijer <ralphm@ik.nu>
parents: 48
diff changeset
285
55fa890ef60b Match backend's supported_*() methods in getFeatures() of ComponentServiceFromService.
Ralph Meijer <ralphm@ik.nu>
parents: 48
diff changeset
286 if not node:
73
5d7a924ebddb Reworked disco support.
Ralph Meijer <ralphm@ik.nu>
parents: 68
diff changeset
287 info.append(disco.Feature(NS_PUBSUB + "#create-nodes"))
56
55fa890ef60b Match backend's supported_*() methods in getFeatures() of ComponentServiceFromService.
Ralph Meijer <ralphm@ik.nu>
parents: 48
diff changeset
288
55fa890ef60b Match backend's supported_*() methods in getFeatures() of ComponentServiceFromService.
Ralph Meijer <ralphm@ik.nu>
parents: 48
diff changeset
289 if self.backend.supports_instant_nodes():
73
5d7a924ebddb Reworked disco support.
Ralph Meijer <ralphm@ik.nu>
parents: 68
diff changeset
290 info.append(disco.Feature(NS_PUBSUB + "#instant-nodes"))
56
55fa890ef60b Match backend's supported_*() methods in getFeatures() of ComponentServiceFromService.
Ralph Meijer <ralphm@ik.nu>
parents: 48
diff changeset
291
73
5d7a924ebddb Reworked disco support.
Ralph Meijer <ralphm@ik.nu>
parents: 68
diff changeset
292 return defer.succeed(info)
31
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
293
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
294 def onCreate(self, iq):
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
295 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
296
31
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
297 def _onCreate(self, iq):
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
298 if iq.pubsub.options:
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
299 raise CreateNodeNotConfigurable
23
884268687229 Simplify call chain by mapping incoming requests directly to method
Ralph Meijer <ralphm@ik.nu>
parents: 21
diff changeset
300
56
55fa890ef60b Match backend's supported_*() methods in getFeatures() of ComponentServiceFromService.
Ralph Meijer <ralphm@ik.nu>
parents: 48
diff changeset
301 node = iq.pubsub.create.getAttribute("node")
55fa890ef60b Match backend's supported_*() methods in getFeatures() of ComponentServiceFromService.
Ralph Meijer <ralphm@ik.nu>
parents: 48
diff changeset
302
31
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
303 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
304
31
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
305 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
306 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
307 return d
2
9701df89c534 First take at notifications
Ralph Meijer <ralphm@ik.nu>
parents: 1
diff changeset
308
31
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
309 def return_create_response(self, result, iq):
83
f3f31aa491df Fix handling of node creation.
Ralph Meijer <ralphm@ik.nu>
parents: 81
diff changeset
310 node_id = iq.pubsub.create.getAttribute("node")
f3f31aa491df Fix handling of node creation.
Ralph Meijer <ralphm@ik.nu>
parents: 81
diff changeset
311 if not node_id or node_id != result:
60
f6b7a06b8870 Implement retrieving affiliations.
Ralph Meijer <ralphm@ik.nu>
parents: 58
diff changeset
312 reply = domish.Element((NS_PUBSUB, 'pubsub'))
31
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
313 entity = reply.addElement('create')
83
f3f31aa491df Fix handling of node creation.
Ralph Meijer <ralphm@ik.nu>
parents: 81
diff changeset
314 entity['node'] = result
60
f6b7a06b8870 Implement retrieving affiliations.
Ralph Meijer <ralphm@ik.nu>
parents: 58
diff changeset
315 return [reply]
31
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
316
38
c9ddca3cce20 Change exception classes to include stanza error.
Ralph Meijer <ralphm@ik.nu>
parents: 31
diff changeset
317 def onConfigureGet(self, iq):
c9ddca3cce20 Change exception classes to include stanza error.
Ralph Meijer <ralphm@ik.nu>
parents: 31
diff changeset
318 self.handler_wrapper(self._onConfigureGet, iq)
c9ddca3cce20 Change exception classes to include stanza error.
Ralph Meijer <ralphm@ik.nu>
parents: 31
diff changeset
319
c9ddca3cce20 Change exception classes to include stanza error.
Ralph Meijer <ralphm@ik.nu>
parents: 31
diff changeset
320 def _onConfigureGet(self, iq):
c9ddca3cce20 Change exception classes to include stanza error.
Ralph Meijer <ralphm@ik.nu>
parents: 31
diff changeset
321 raise NodeNotConfigurable
c9ddca3cce20 Change exception classes to include stanza error.
Ralph Meijer <ralphm@ik.nu>
parents: 31
diff changeset
322
c9ddca3cce20 Change exception classes to include stanza error.
Ralph Meijer <ralphm@ik.nu>
parents: 31
diff changeset
323 def onConfigureSet(self, iq):
c9ddca3cce20 Change exception classes to include stanza error.
Ralph Meijer <ralphm@ik.nu>
parents: 31
diff changeset
324 self.handler_wrapper(self._onConfigureSet, iq)
c9ddca3cce20 Change exception classes to include stanza error.
Ralph Meijer <ralphm@ik.nu>
parents: 31
diff changeset
325
c9ddca3cce20 Change exception classes to include stanza error.
Ralph Meijer <ralphm@ik.nu>
parents: 31
diff changeset
326 def _onConfigureSet(self, iq):
c9ddca3cce20 Change exception classes to include stanza error.
Ralph Meijer <ralphm@ik.nu>
parents: 31
diff changeset
327 raise NodeNotConfigurable
c9ddca3cce20 Change exception classes to include stanza error.
Ralph Meijer <ralphm@ik.nu>
parents: 31
diff changeset
328
31
fa866793075d Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents: 25
diff changeset
329 components.registerAdapter(ComponentServiceFromNodeCreationService, backend.INodeCreationService, component.IService)
60
f6b7a06b8870 Implement retrieving affiliations.
Ralph Meijer <ralphm@ik.nu>
parents: 58
diff changeset
330
f6b7a06b8870 Implement retrieving affiliations.
Ralph Meijer <ralphm@ik.nu>
parents: 58
diff changeset
331 class ComponentServiceFromAffiliationsService(Service):
f6b7a06b8870 Implement retrieving affiliations.
Ralph Meijer <ralphm@ik.nu>
parents: 58
diff changeset
332
f6b7a06b8870 Implement retrieving affiliations.
Ralph Meijer <ralphm@ik.nu>
parents: 58
diff changeset
333 def componentConnected(self, xmlstream):
f6b7a06b8870 Implement retrieving affiliations.
Ralph Meijer <ralphm@ik.nu>
parents: 58
diff changeset
334 xmlstream.addObserver(PUBSUB_AFFILIATIONS, self.onAffiliations)
f6b7a06b8870 Implement retrieving affiliations.
Ralph Meijer <ralphm@ik.nu>
parents: 58
diff changeset
335
f6b7a06b8870 Implement retrieving affiliations.
Ralph Meijer <ralphm@ik.nu>
parents: 58
diff changeset
336 def onAffiliations(self, iq):
f6b7a06b8870 Implement retrieving affiliations.
Ralph Meijer <ralphm@ik.nu>
parents: 58
diff changeset
337 self.handler_wrapper(self._onAffiliations, iq)
f6b7a06b8870 Implement retrieving affiliations.
Ralph Meijer <ralphm@ik.nu>
parents: 58
diff changeset
338
f6b7a06b8870 Implement retrieving affiliations.
Ralph Meijer <ralphm@ik.nu>
parents: 58
diff changeset
339 def _onAffiliations(self, iq):
f6b7a06b8870 Implement retrieving affiliations.
Ralph Meijer <ralphm@ik.nu>
parents: 58
diff changeset
340 d = self.backend.get_affiliations(jid.JID(iq["from"]).userhostJID())
f6b7a06b8870 Implement retrieving affiliations.
Ralph Meijer <ralphm@ik.nu>
parents: 58
diff changeset
341 d.addCallback(self._return_affiliations_response, iq)
f6b7a06b8870 Implement retrieving affiliations.
Ralph Meijer <ralphm@ik.nu>
parents: 58
diff changeset
342 return d
f6b7a06b8870 Implement retrieving affiliations.
Ralph Meijer <ralphm@ik.nu>
parents: 58
diff changeset
343
f6b7a06b8870 Implement retrieving affiliations.
Ralph Meijer <ralphm@ik.nu>
parents: 58
diff changeset
344 def _return_affiliations_response(self, result, iq):
f6b7a06b8870 Implement retrieving affiliations.
Ralph Meijer <ralphm@ik.nu>
parents: 58
diff changeset
345 reply = domish.Element((NS_PUBSUB, 'pubsub'))
f6b7a06b8870 Implement retrieving affiliations.
Ralph Meijer <ralphm@ik.nu>
parents: 58
diff changeset
346 affiliations = reply.addElement('affiliations')
f6b7a06b8870 Implement retrieving affiliations.
Ralph Meijer <ralphm@ik.nu>
parents: 58
diff changeset
347 for r in result:
f6b7a06b8870 Implement retrieving affiliations.
Ralph Meijer <ralphm@ik.nu>
parents: 58
diff changeset
348 entity = affiliations.addElement('entity')
f6b7a06b8870 Implement retrieving affiliations.
Ralph Meijer <ralphm@ik.nu>
parents: 58
diff changeset
349 entity['node'] = r['node']
f6b7a06b8870 Implement retrieving affiliations.
Ralph Meijer <ralphm@ik.nu>
parents: 58
diff changeset
350 entity['jid'] = r['jid'].full()
f6b7a06b8870 Implement retrieving affiliations.
Ralph Meijer <ralphm@ik.nu>
parents: 58
diff changeset
351 entity['affiliation'] = r['affiliation'] or 'none'
f6b7a06b8870 Implement retrieving affiliations.
Ralph Meijer <ralphm@ik.nu>
parents: 58
diff changeset
352 entity['subscription'] = r['subscription'] or 'none'
f6b7a06b8870 Implement retrieving affiliations.
Ralph Meijer <ralphm@ik.nu>
parents: 58
diff changeset
353 return [reply]
f6b7a06b8870 Implement retrieving affiliations.
Ralph Meijer <ralphm@ik.nu>
parents: 58
diff changeset
354
f6b7a06b8870 Implement retrieving affiliations.
Ralph Meijer <ralphm@ik.nu>
parents: 58
diff changeset
355 components.registerAdapter(ComponentServiceFromAffiliationsService, backend.IAffiliationsService, component.IService)
81
995ba223a43b Implemented ComponentServiceToItemRetrievalService.
Ralph Meijer <ralphm@ik.nu>
parents: 73
diff changeset
356
995ba223a43b Implemented ComponentServiceToItemRetrievalService.
Ralph Meijer <ralphm@ik.nu>
parents: 73
diff changeset
357 class ComponentServiceFromItemRetrievalService(Service):
995ba223a43b Implemented ComponentServiceToItemRetrievalService.
Ralph Meijer <ralphm@ik.nu>
parents: 73
diff changeset
358
995ba223a43b Implemented ComponentServiceToItemRetrievalService.
Ralph Meijer <ralphm@ik.nu>
parents: 73
diff changeset
359 def componentConnected(self, xmlstream):
995ba223a43b Implemented ComponentServiceToItemRetrievalService.
Ralph Meijer <ralphm@ik.nu>
parents: 73
diff changeset
360 xmlstream.addObserver(PUBSUB_ITEMS, self.onItems)
995ba223a43b Implemented ComponentServiceToItemRetrievalService.
Ralph Meijer <ralphm@ik.nu>
parents: 73
diff changeset
361
83
f3f31aa491df Fix handling of node creation.
Ralph Meijer <ralphm@ik.nu>
parents: 81
diff changeset
362 def get_disco_info(self, node):
f3f31aa491df Fix handling of node creation.
Ralph Meijer <ralphm@ik.nu>
parents: 81
diff changeset
363 info = []
f3f31aa491df Fix handling of node creation.
Ralph Meijer <ralphm@ik.nu>
parents: 81
diff changeset
364
f3f31aa491df Fix handling of node creation.
Ralph Meijer <ralphm@ik.nu>
parents: 81
diff changeset
365 if not node:
f3f31aa491df Fix handling of node creation.
Ralph Meijer <ralphm@ik.nu>
parents: 81
diff changeset
366 info.append(disco.Feature(NS_PUBSUB + "#retrieve-items"))
f3f31aa491df Fix handling of node creation.
Ralph Meijer <ralphm@ik.nu>
parents: 81
diff changeset
367
f3f31aa491df Fix handling of node creation.
Ralph Meijer <ralphm@ik.nu>
parents: 81
diff changeset
368 return defer.succeed(info)
f3f31aa491df Fix handling of node creation.
Ralph Meijer <ralphm@ik.nu>
parents: 81
diff changeset
369
81
995ba223a43b Implemented ComponentServiceToItemRetrievalService.
Ralph Meijer <ralphm@ik.nu>
parents: 73
diff changeset
370 def onItems(self, iq):
995ba223a43b Implemented ComponentServiceToItemRetrievalService.
Ralph Meijer <ralphm@ik.nu>
parents: 73
diff changeset
371 self.handler_wrapper(self._onItems, iq)
995ba223a43b Implemented ComponentServiceToItemRetrievalService.
Ralph Meijer <ralphm@ik.nu>
parents: 73
diff changeset
372
995ba223a43b Implemented ComponentServiceToItemRetrievalService.
Ralph Meijer <ralphm@ik.nu>
parents: 73
diff changeset
373 def _onItems(self, iq):
995ba223a43b Implemented ComponentServiceToItemRetrievalService.
Ralph Meijer <ralphm@ik.nu>
parents: 73
diff changeset
374 try:
995ba223a43b Implemented ComponentServiceToItemRetrievalService.
Ralph Meijer <ralphm@ik.nu>
parents: 73
diff changeset
375 node_id = iq.pubsub.items["node"]
995ba223a43b Implemented ComponentServiceToItemRetrievalService.
Ralph Meijer <ralphm@ik.nu>
parents: 73
diff changeset
376 except KeyError:
995ba223a43b Implemented ComponentServiceToItemRetrievalService.
Ralph Meijer <ralphm@ik.nu>
parents: 73
diff changeset
377 raise BadRequest
995ba223a43b Implemented ComponentServiceToItemRetrievalService.
Ralph Meijer <ralphm@ik.nu>
parents: 73
diff changeset
378
995ba223a43b Implemented ComponentServiceToItemRetrievalService.
Ralph Meijer <ralphm@ik.nu>
parents: 73
diff changeset
379 max_items = iq.pubsub.items.getAttribute('max_items')
995ba223a43b Implemented ComponentServiceToItemRetrievalService.
Ralph Meijer <ralphm@ik.nu>
parents: 73
diff changeset
380
995ba223a43b Implemented ComponentServiceToItemRetrievalService.
Ralph Meijer <ralphm@ik.nu>
parents: 73
diff changeset
381 if max_items:
995ba223a43b Implemented ComponentServiceToItemRetrievalService.
Ralph Meijer <ralphm@ik.nu>
parents: 73
diff changeset
382 try:
995ba223a43b Implemented ComponentServiceToItemRetrievalService.
Ralph Meijer <ralphm@ik.nu>
parents: 73
diff changeset
383 max_items = int(max_items)
995ba223a43b Implemented ComponentServiceToItemRetrievalService.
Ralph Meijer <ralphm@ik.nu>
parents: 73
diff changeset
384 except ValueError:
995ba223a43b Implemented ComponentServiceToItemRetrievalService.
Ralph Meijer <ralphm@ik.nu>
parents: 73
diff changeset
385 raise BadRequest
995ba223a43b Implemented ComponentServiceToItemRetrievalService.
Ralph Meijer <ralphm@ik.nu>
parents: 73
diff changeset
386
995ba223a43b Implemented ComponentServiceToItemRetrievalService.
Ralph Meijer <ralphm@ik.nu>
parents: 73
diff changeset
387 item_ids = []
995ba223a43b Implemented ComponentServiceToItemRetrievalService.
Ralph Meijer <ralphm@ik.nu>
parents: 73
diff changeset
388 for child in iq.pubsub.items.children:
995ba223a43b Implemented ComponentServiceToItemRetrievalService.
Ralph Meijer <ralphm@ik.nu>
parents: 73
diff changeset
389 if child.name == 'item' and child.uri == NS_PUBSUB:
995ba223a43b Implemented ComponentServiceToItemRetrievalService.
Ralph Meijer <ralphm@ik.nu>
parents: 73
diff changeset
390 try:
995ba223a43b Implemented ComponentServiceToItemRetrievalService.
Ralph Meijer <ralphm@ik.nu>
parents: 73
diff changeset
391 item_ids.append(child["id"])
995ba223a43b Implemented ComponentServiceToItemRetrievalService.
Ralph Meijer <ralphm@ik.nu>
parents: 73
diff changeset
392 except KeyError:
995ba223a43b Implemented ComponentServiceToItemRetrievalService.
Ralph Meijer <ralphm@ik.nu>
parents: 73
diff changeset
393 raise BadRequest
995ba223a43b Implemented ComponentServiceToItemRetrievalService.
Ralph Meijer <ralphm@ik.nu>
parents: 73
diff changeset
394
995ba223a43b Implemented ComponentServiceToItemRetrievalService.
Ralph Meijer <ralphm@ik.nu>
parents: 73
diff changeset
395 d = self.backend.get_items(node_id, jid.JID(iq["from"]), max_items,
995ba223a43b Implemented ComponentServiceToItemRetrievalService.
Ralph Meijer <ralphm@ik.nu>
parents: 73
diff changeset
396 item_ids)
995ba223a43b Implemented ComponentServiceToItemRetrievalService.
Ralph Meijer <ralphm@ik.nu>
parents: 73
diff changeset
397 d.addCallback(self._return_items_response, node_id)
995ba223a43b Implemented ComponentServiceToItemRetrievalService.
Ralph Meijer <ralphm@ik.nu>
parents: 73
diff changeset
398 return d
995ba223a43b Implemented ComponentServiceToItemRetrievalService.
Ralph Meijer <ralphm@ik.nu>
parents: 73
diff changeset
399
995ba223a43b Implemented ComponentServiceToItemRetrievalService.
Ralph Meijer <ralphm@ik.nu>
parents: 73
diff changeset
400 def _return_items_response(self, result, node_id):
995ba223a43b Implemented ComponentServiceToItemRetrievalService.
Ralph Meijer <ralphm@ik.nu>
parents: 73
diff changeset
401 reply = domish.Element((NS_PUBSUB, 'pubsub'))
995ba223a43b Implemented ComponentServiceToItemRetrievalService.
Ralph Meijer <ralphm@ik.nu>
parents: 73
diff changeset
402 items = reply.addElement('items')
995ba223a43b Implemented ComponentServiceToItemRetrievalService.
Ralph Meijer <ralphm@ik.nu>
parents: 73
diff changeset
403 items["node"] = node_id
995ba223a43b Implemented ComponentServiceToItemRetrievalService.
Ralph Meijer <ralphm@ik.nu>
parents: 73
diff changeset
404 try:
995ba223a43b Implemented ComponentServiceToItemRetrievalService.
Ralph Meijer <ralphm@ik.nu>
parents: 73
diff changeset
405 for r in result:
995ba223a43b Implemented ComponentServiceToItemRetrievalService.
Ralph Meijer <ralphm@ik.nu>
parents: 73
diff changeset
406 items.addRawXml(r)
995ba223a43b Implemented ComponentServiceToItemRetrievalService.
Ralph Meijer <ralphm@ik.nu>
parents: 73
diff changeset
407 except Exception, e:
995ba223a43b Implemented ComponentServiceToItemRetrievalService.
Ralph Meijer <ralphm@ik.nu>
parents: 73
diff changeset
408 print e
995ba223a43b Implemented ComponentServiceToItemRetrievalService.
Ralph Meijer <ralphm@ik.nu>
parents: 73
diff changeset
409
995ba223a43b Implemented ComponentServiceToItemRetrievalService.
Ralph Meijer <ralphm@ik.nu>
parents: 73
diff changeset
410 return [reply]
995ba223a43b Implemented ComponentServiceToItemRetrievalService.
Ralph Meijer <ralphm@ik.nu>
parents: 73
diff changeset
411
995ba223a43b Implemented ComponentServiceToItemRetrievalService.
Ralph Meijer <ralphm@ik.nu>
parents: 73
diff changeset
412 components.registerAdapter(ComponentServiceFromItemRetrievalService, backend.IItemRetrievalService, component.IService)
85
ec557449d1aa Implement node retraction, with storage support for pgsql.
Ralph Meijer <ralphm@ik.nu>
parents: 83
diff changeset
413
ec557449d1aa Implement node retraction, with storage support for pgsql.
Ralph Meijer <ralphm@ik.nu>
parents: 83
diff changeset
414 class ComponentServiceFromRetractionService(Service):
ec557449d1aa Implement node retraction, with storage support for pgsql.
Ralph Meijer <ralphm@ik.nu>
parents: 83
diff changeset
415
ec557449d1aa Implement node retraction, with storage support for pgsql.
Ralph Meijer <ralphm@ik.nu>
parents: 83
diff changeset
416 def componentConnected(self, xmlstream):
ec557449d1aa Implement node retraction, with storage support for pgsql.
Ralph Meijer <ralphm@ik.nu>
parents: 83
diff changeset
417 xmlstream.addObserver(PUBSUB_RETRACT, self.onRetract)
90
59378610b16e Implement node purging and node deletion.
Ralph Meijer <ralphm@ik.nu>
parents: 85
diff changeset
418 xmlstream.addObserver(PUBSUB_PURGE, self.onPurge)
85
ec557449d1aa Implement node retraction, with storage support for pgsql.
Ralph Meijer <ralphm@ik.nu>
parents: 83
diff changeset
419
ec557449d1aa Implement node retraction, with storage support for pgsql.
Ralph Meijer <ralphm@ik.nu>
parents: 83
diff changeset
420 def onRetract(self, iq):
ec557449d1aa Implement node retraction, with storage support for pgsql.
Ralph Meijer <ralphm@ik.nu>
parents: 83
diff changeset
421 self.handler_wrapper(self._onRetract, iq)
ec557449d1aa Implement node retraction, with storage support for pgsql.
Ralph Meijer <ralphm@ik.nu>
parents: 83
diff changeset
422
ec557449d1aa Implement node retraction, with storage support for pgsql.
Ralph Meijer <ralphm@ik.nu>
parents: 83
diff changeset
423 def _onRetract(self, iq):
ec557449d1aa Implement node retraction, with storage support for pgsql.
Ralph Meijer <ralphm@ik.nu>
parents: 83
diff changeset
424 try:
ec557449d1aa Implement node retraction, with storage support for pgsql.
Ralph Meijer <ralphm@ik.nu>
parents: 83
diff changeset
425 node = iq.pubsub.retract["node"]
ec557449d1aa Implement node retraction, with storage support for pgsql.
Ralph Meijer <ralphm@ik.nu>
parents: 83
diff changeset
426 except KeyError:
ec557449d1aa Implement node retraction, with storage support for pgsql.
Ralph Meijer <ralphm@ik.nu>
parents: 83
diff changeset
427 raise BadRequest
ec557449d1aa Implement node retraction, with storage support for pgsql.
Ralph Meijer <ralphm@ik.nu>
parents: 83
diff changeset
428
ec557449d1aa Implement node retraction, with storage support for pgsql.
Ralph Meijer <ralphm@ik.nu>
parents: 83
diff changeset
429 item_ids = []
ec557449d1aa Implement node retraction, with storage support for pgsql.
Ralph Meijer <ralphm@ik.nu>
parents: 83
diff changeset
430 for child in iq.pubsub.retract.children:
ec557449d1aa Implement node retraction, with storage support for pgsql.
Ralph Meijer <ralphm@ik.nu>
parents: 83
diff changeset
431 if child.__class__ == domish.Element and child.name == 'item':
ec557449d1aa Implement node retraction, with storage support for pgsql.
Ralph Meijer <ralphm@ik.nu>
parents: 83
diff changeset
432 try:
ec557449d1aa Implement node retraction, with storage support for pgsql.
Ralph Meijer <ralphm@ik.nu>
parents: 83
diff changeset
433 item_ids.append(child["id"])
ec557449d1aa Implement node retraction, with storage support for pgsql.
Ralph Meijer <ralphm@ik.nu>
parents: 83
diff changeset
434 except KeyError:
ec557449d1aa Implement node retraction, with storage support for pgsql.
Ralph Meijer <ralphm@ik.nu>
parents: 83
diff changeset
435 raise BadRequest
ec557449d1aa Implement node retraction, with storage support for pgsql.
Ralph Meijer <ralphm@ik.nu>
parents: 83
diff changeset
436
ec557449d1aa Implement node retraction, with storage support for pgsql.
Ralph Meijer <ralphm@ik.nu>
parents: 83
diff changeset
437 print item_ids
ec557449d1aa Implement node retraction, with storage support for pgsql.
Ralph Meijer <ralphm@ik.nu>
parents: 83
diff changeset
438
ec557449d1aa Implement node retraction, with storage support for pgsql.
Ralph Meijer <ralphm@ik.nu>
parents: 83
diff changeset
439 return self.backend.retract_item(node, item_ids,
ec557449d1aa Implement node retraction, with storage support for pgsql.
Ralph Meijer <ralphm@ik.nu>
parents: 83
diff changeset
440 jid.JID(iq["from"]).userhostJID())
ec557449d1aa Implement node retraction, with storage support for pgsql.
Ralph Meijer <ralphm@ik.nu>
parents: 83
diff changeset
441
90
59378610b16e Implement node purging and node deletion.
Ralph Meijer <ralphm@ik.nu>
parents: 85
diff changeset
442 def onPurge(self, iq):
59378610b16e Implement node purging and node deletion.
Ralph Meijer <ralphm@ik.nu>
parents: 85
diff changeset
443 self.handler_wrapper(self._onPurge, iq)
59378610b16e Implement node purging and node deletion.
Ralph Meijer <ralphm@ik.nu>
parents: 85
diff changeset
444
59378610b16e Implement node purging and node deletion.
Ralph Meijer <ralphm@ik.nu>
parents: 85
diff changeset
445 def _onPurge(self, iq):
59378610b16e Implement node purging and node deletion.
Ralph Meijer <ralphm@ik.nu>
parents: 85
diff changeset
446 try:
59378610b16e Implement node purging and node deletion.
Ralph Meijer <ralphm@ik.nu>
parents: 85
diff changeset
447 node = iq.pubsub.purge["node"]
59378610b16e Implement node purging and node deletion.
Ralph Meijer <ralphm@ik.nu>
parents: 85
diff changeset
448 except KeyError:
59378610b16e Implement node purging and node deletion.
Ralph Meijer <ralphm@ik.nu>
parents: 85
diff changeset
449 raise BadRequest
59378610b16e Implement node purging and node deletion.
Ralph Meijer <ralphm@ik.nu>
parents: 85
diff changeset
450
59378610b16e Implement node purging and node deletion.
Ralph Meijer <ralphm@ik.nu>
parents: 85
diff changeset
451 return self.backend.purge_node(node, jid.JID(iq["from"]).userhostJID())
59378610b16e Implement node purging and node deletion.
Ralph Meijer <ralphm@ik.nu>
parents: 85
diff changeset
452
85
ec557449d1aa Implement node retraction, with storage support for pgsql.
Ralph Meijer <ralphm@ik.nu>
parents: 83
diff changeset
453 components.registerAdapter(ComponentServiceFromRetractionService, backend.IRetractionService, component.IService)
90
59378610b16e Implement node purging and node deletion.
Ralph Meijer <ralphm@ik.nu>
parents: 85
diff changeset
454
59378610b16e Implement node purging and node deletion.
Ralph Meijer <ralphm@ik.nu>
parents: 85
diff changeset
455 class ComponentServiceFromNodeDeletionService(Service):
59378610b16e Implement node purging and node deletion.
Ralph Meijer <ralphm@ik.nu>
parents: 85
diff changeset
456
59378610b16e Implement node purging and node deletion.
Ralph Meijer <ralphm@ik.nu>
parents: 85
diff changeset
457 def __init__(self, backend):
59378610b16e Implement node purging and node deletion.
Ralph Meijer <ralphm@ik.nu>
parents: 85
diff changeset
458 Service.__init__(self, backend)
59378610b16e Implement node purging and node deletion.
Ralph Meijer <ralphm@ik.nu>
parents: 85
diff changeset
459 self.subscribers = []
59378610b16e Implement node purging and node deletion.
Ralph Meijer <ralphm@ik.nu>
parents: 85
diff changeset
460
59378610b16e Implement node purging and node deletion.
Ralph Meijer <ralphm@ik.nu>
parents: 85
diff changeset
461 def componentConnected(self, xmlstream):
59378610b16e Implement node purging and node deletion.
Ralph Meijer <ralphm@ik.nu>
parents: 85
diff changeset
462 self.backend.register_pre_delete(self._pre_delete)
59378610b16e Implement node purging and node deletion.
Ralph Meijer <ralphm@ik.nu>
parents: 85
diff changeset
463 xmlstream.addObserver(PUBSUB_DELETE, self.onDelete)
59378610b16e Implement node purging and node deletion.
Ralph Meijer <ralphm@ik.nu>
parents: 85
diff changeset
464
59378610b16e Implement node purging and node deletion.
Ralph Meijer <ralphm@ik.nu>
parents: 85
diff changeset
465 def _pre_delete(self, node_id):
59378610b16e Implement node purging and node deletion.
Ralph Meijer <ralphm@ik.nu>
parents: 85
diff changeset
466 d = self.backend.get_subscribers(node_id)
59378610b16e Implement node purging and node deletion.
Ralph Meijer <ralphm@ik.nu>
parents: 85
diff changeset
467 d.addCallback(self._return_deferreds, node_id)
59378610b16e Implement node purging and node deletion.
Ralph Meijer <ralphm@ik.nu>
parents: 85
diff changeset
468 return d
59378610b16e Implement node purging and node deletion.
Ralph Meijer <ralphm@ik.nu>
parents: 85
diff changeset
469
59378610b16e Implement node purging and node deletion.
Ralph Meijer <ralphm@ik.nu>
parents: 85
diff changeset
470 def _return_deferreds(self, subscribers, node_id):
59378610b16e Implement node purging and node deletion.
Ralph Meijer <ralphm@ik.nu>
parents: 85
diff changeset
471 d = defer.Deferred()
59378610b16e Implement node purging and node deletion.
Ralph Meijer <ralphm@ik.nu>
parents: 85
diff changeset
472 d.addCallback(self._notify, subscribers, node_id)
59378610b16e Implement node purging and node deletion.
Ralph Meijer <ralphm@ik.nu>
parents: 85
diff changeset
473 return [d]
59378610b16e Implement node purging and node deletion.
Ralph Meijer <ralphm@ik.nu>
parents: 85
diff changeset
474
59378610b16e Implement node purging and node deletion.
Ralph Meijer <ralphm@ik.nu>
parents: 85
diff changeset
475 def _notify(self, result, subscribers, node_id):
59378610b16e Implement node purging and node deletion.
Ralph Meijer <ralphm@ik.nu>
parents: 85
diff changeset
476 message = domish.Element((NS_COMPONENT, "message"))
59378610b16e Implement node purging and node deletion.
Ralph Meijer <ralphm@ik.nu>
parents: 85
diff changeset
477 message["from"] = self.parent.jabberId
59378610b16e Implement node purging and node deletion.
Ralph Meijer <ralphm@ik.nu>
parents: 85
diff changeset
478 event = message.addElement((NS_PUBSUB_EVENT, "event"))
59378610b16e Implement node purging and node deletion.
Ralph Meijer <ralphm@ik.nu>
parents: 85
diff changeset
479 event.addElement("delete")["node"] = node_id
59378610b16e Implement node purging and node deletion.
Ralph Meijer <ralphm@ik.nu>
parents: 85
diff changeset
480
59378610b16e Implement node purging and node deletion.
Ralph Meijer <ralphm@ik.nu>
parents: 85
diff changeset
481 for subscriber in subscribers:
59378610b16e Implement node purging and node deletion.
Ralph Meijer <ralphm@ik.nu>
parents: 85
diff changeset
482 message["to"] = subscriber
59378610b16e Implement node purging and node deletion.
Ralph Meijer <ralphm@ik.nu>
parents: 85
diff changeset
483 print message.toXml()
59378610b16e Implement node purging and node deletion.
Ralph Meijer <ralphm@ik.nu>
parents: 85
diff changeset
484 self.send(message)
59378610b16e Implement node purging and node deletion.
Ralph Meijer <ralphm@ik.nu>
parents: 85
diff changeset
485
59378610b16e Implement node purging and node deletion.
Ralph Meijer <ralphm@ik.nu>
parents: 85
diff changeset
486 def onDelete(self, iq):
59378610b16e Implement node purging and node deletion.
Ralph Meijer <ralphm@ik.nu>
parents: 85
diff changeset
487 self.handler_wrapper(self._onDelete, iq)
59378610b16e Implement node purging and node deletion.
Ralph Meijer <ralphm@ik.nu>
parents: 85
diff changeset
488
59378610b16e Implement node purging and node deletion.
Ralph Meijer <ralphm@ik.nu>
parents: 85
diff changeset
489 def _onDelete(self, iq):
59378610b16e Implement node purging and node deletion.
Ralph Meijer <ralphm@ik.nu>
parents: 85
diff changeset
490 try:
59378610b16e Implement node purging and node deletion.
Ralph Meijer <ralphm@ik.nu>
parents: 85
diff changeset
491 node = iq.pubsub.delete["node"]
59378610b16e Implement node purging and node deletion.
Ralph Meijer <ralphm@ik.nu>
parents: 85
diff changeset
492 except KeyError:
59378610b16e Implement node purging and node deletion.
Ralph Meijer <ralphm@ik.nu>
parents: 85
diff changeset
493 raise BadRequest
59378610b16e Implement node purging and node deletion.
Ralph Meijer <ralphm@ik.nu>
parents: 85
diff changeset
494
59378610b16e Implement node purging and node deletion.
Ralph Meijer <ralphm@ik.nu>
parents: 85
diff changeset
495 return self.backend.delete_node(node, jid.JID(iq["from"]).userhostJID())
59378610b16e Implement node purging and node deletion.
Ralph Meijer <ralphm@ik.nu>
parents: 85
diff changeset
496
59378610b16e Implement node purging and node deletion.
Ralph Meijer <ralphm@ik.nu>
parents: 85
diff changeset
497 components.registerAdapter(ComponentServiceFromNodeDeletionService, backend.INodeDeletionService, component.IService)