Mercurial > libervia-pubsub
annotate idavoll/pubsub.py @ 109:9fb8f0867d02
Use storage.
author | Ralph Meijer <ralphm@ik.nu> |
---|---|
date | Fri, 08 Apr 2005 10:16:53 +0000 |
parents | 8d8946e67fcb |
children | 7043839982ba |
rev | line source |
---|---|
105 | 1 from twisted.words.protocols.jabber import component,jid |
2 | 2 from twisted.xish import utility, domish |
1 | 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 |
105 | 5 from zope.interface import implements |
23
884268687229
Simplify call chain by mapping incoming requests directly to method
Ralph Meijer <ralphm@ik.nu>
parents:
21
diff
changeset
|
6 |
1 | 7 import backend |
8 import xmpp_error | |
73 | 9 import disco |
101
b75fcc554358
Added support for disco info meta data.
Ralph Meijer <ralphm@ik.nu>
parents:
98
diff
changeset
|
10 import data_form |
1 | 11 |
2 | 12 NS_COMPONENT = 'jabber:component:accept' |
13 NS_PUBSUB = 'http://jabber.org/protocol/pubsub' | |
14 NS_PUBSUB_EVENT = NS_PUBSUB + '#event' | |
16 | 15 NS_PUBSUB_ERRORS = NS_PUBSUB + '#errors' |
95
3ad74552bbc7
Merge from RELENG_0: Implemented node configuration.
Ralph Meijer <ralphm@ik.nu>
parents:
93
diff
changeset
|
16 NS_PUBSUB_OWNER = NS_PUBSUB + "#owner" |
2 | 17 |
1 | 18 IQ_GET = '/iq[@type="get"]' |
19 IQ_SET = '/iq[@type="set"]' | |
2 | 20 PUBSUB_ELEMENT = '/pubsub[@xmlns="' + NS_PUBSUB + '"]' |
95
3ad74552bbc7
Merge from RELENG_0: Implemented node configuration.
Ralph Meijer <ralphm@ik.nu>
parents:
93
diff
changeset
|
21 PUBSUB_OWNER_ELEMENT = '/pubsub[@xmlns="' + NS_PUBSUB_OWNER + '"]' |
2 | 22 PUBSUB_GET = IQ_GET + PUBSUB_ELEMENT |
23 PUBSUB_SET = IQ_SET + PUBSUB_ELEMENT | |
95
3ad74552bbc7
Merge from RELENG_0: Implemented node configuration.
Ralph Meijer <ralphm@ik.nu>
parents:
93
diff
changeset
|
24 PUBSUB_OWNER_GET = IQ_GET + PUBSUB_OWNER_ELEMENT |
3ad74552bbc7
Merge from RELENG_0: Implemented node configuration.
Ralph Meijer <ralphm@ik.nu>
parents:
93
diff
changeset
|
25 PUBSUB_OWNER_SET = IQ_SET + PUBSUB_OWNER_ELEMENT |
1 | 26 PUBSUB_CREATE = PUBSUB_SET + '/create' |
27 PUBSUB_PUBLISH = PUBSUB_SET + '/publish' | |
16 | 28 PUBSUB_SUBSCRIBE = PUBSUB_SET + '/subscribe' |
38
c9ddca3cce20
Change exception classes to include stanza error.
Ralph Meijer <ralphm@ik.nu>
parents:
31
diff
changeset
|
29 PUBSUB_UNSUBSCRIBE = PUBSUB_SET + '/unsubscribe' |
7
a8cfb31dc50c
Implemented fallback for feature-not-implemented.
Ralph Meijer <ralphm@ik.nu>
parents:
4
diff
changeset
|
30 PUBSUB_OPTIONS_GET = PUBSUB_GET + '/options' |
21 | 31 PUBSUB_OPTIONS_SET = PUBSUB_SET + '/options' |
95
3ad74552bbc7
Merge from RELENG_0: Implemented node configuration.
Ralph Meijer <ralphm@ik.nu>
parents:
93
diff
changeset
|
32 PUBSUB_CONFIGURE_GET = PUBSUB_OWNER_GET + '/configure' |
3ad74552bbc7
Merge from RELENG_0: Implemented node configuration.
Ralph Meijer <ralphm@ik.nu>
parents:
93
diff
changeset
|
33 PUBSUB_CONFIGURE_SET = PUBSUB_OWNER_SET + '/configure' |
60
f6b7a06b8870
Implement retrieving affiliations.
Ralph Meijer <ralphm@ik.nu>
parents:
58
diff
changeset
|
34 PUBSUB_AFFILIATIONS = PUBSUB_GET + '/affiliations' |
81
995ba223a43b
Implemented ComponentServiceToItemRetrievalService.
Ralph Meijer <ralphm@ik.nu>
parents:
73
diff
changeset
|
35 PUBSUB_ITEMS = PUBSUB_GET + '/items' |
85
ec557449d1aa
Implement node retraction, with storage support for pgsql.
Ralph Meijer <ralphm@ik.nu>
parents:
83
diff
changeset
|
36 PUBSUB_RETRACT = PUBSUB_SET + '/retract' |
90
59378610b16e
Implement node purging and node deletion.
Ralph Meijer <ralphm@ik.nu>
parents:
85
diff
changeset
|
37 PUBSUB_PURGE = PUBSUB_SET + '/purge' |
59378610b16e
Implement node purging and node deletion.
Ralph Meijer <ralphm@ik.nu>
parents:
85
diff
changeset
|
38 PUBSUB_DELETE = PUBSUB_SET + '/delete' |
1 | 39 |
38
c9ddca3cce20
Change exception classes to include stanza error.
Ralph Meijer <ralphm@ik.nu>
parents:
31
diff
changeset
|
40 class Error(Exception): |
31
fa866793075d
Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents:
25
diff
changeset
|
41 pubsub_error = None |
38
c9ddca3cce20
Change exception classes to include stanza error.
Ralph Meijer <ralphm@ik.nu>
parents:
31
diff
changeset
|
42 stanza_error = None |
31
fa866793075d
Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents:
25
diff
changeset
|
43 msg = '' |
23
884268687229
Simplify call chain by mapping incoming requests directly to method
Ralph Meijer <ralphm@ik.nu>
parents:
21
diff
changeset
|
44 |
38
c9ddca3cce20
Change exception classes to include stanza error.
Ralph Meijer <ralphm@ik.nu>
parents:
31
diff
changeset
|
45 class NotImplemented(Error): |
c9ddca3cce20
Change exception classes to include stanza error.
Ralph Meijer <ralphm@ik.nu>
parents:
31
diff
changeset
|
46 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
|
47 |
47
31eb00734cc5
Check for malformed unsubscribe request.
Ralph Meijer <ralphm@ik.nu>
parents:
38
diff
changeset
|
48 class BadRequest(Error): |
31eb00734cc5
Check for malformed unsubscribe request.
Ralph Meijer <ralphm@ik.nu>
parents:
38
diff
changeset
|
49 stanza_error = 'bad-request' |
31eb00734cc5
Check for malformed unsubscribe request.
Ralph Meijer <ralphm@ik.nu>
parents:
38
diff
changeset
|
50 |
38
c9ddca3cce20
Change exception classes to include stanza error.
Ralph Meijer <ralphm@ik.nu>
parents:
31
diff
changeset
|
51 class OptionsUnavailable(Error): |
c9ddca3cce20
Change exception classes to include stanza error.
Ralph Meijer <ralphm@ik.nu>
parents:
31
diff
changeset
|
52 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
|
53 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
|
54 |
38
c9ddca3cce20
Change exception classes to include stanza error.
Ralph Meijer <ralphm@ik.nu>
parents:
31
diff
changeset
|
55 class NodeNotConfigurable(Error): |
c9ddca3cce20
Change exception classes to include stanza error.
Ralph Meijer <ralphm@ik.nu>
parents:
31
diff
changeset
|
56 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
|
57 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
|
58 |
4
ea195dc1732d
Allow publication of more than 1 item.
Ralph Meijer <ralphm@ik.nu>
parents:
2
diff
changeset
|
59 error_map = { |
38
c9ddca3cce20
Change exception classes to include stanza error.
Ralph Meijer <ralphm@ik.nu>
parents:
31
diff
changeset
|
60 backend.NotAuthorized: ('not-authorized', None), |
c9ddca3cce20
Change exception classes to include stanza error.
Ralph Meijer <ralphm@ik.nu>
parents:
31
diff
changeset
|
61 backend.NodeNotFound: ('item-not-found', None), |
c9ddca3cce20
Change exception classes to include stanza error.
Ralph Meijer <ralphm@ik.nu>
parents:
31
diff
changeset
|
62 backend.NoPayloadAllowed: ('bad-request', None), |
c9ddca3cce20
Change exception classes to include stanza error.
Ralph Meijer <ralphm@ik.nu>
parents:
31
diff
changeset
|
63 backend.PayloadExpected: ('bad-request', None), |
c9ddca3cce20
Change exception classes to include stanza error.
Ralph Meijer <ralphm@ik.nu>
parents:
31
diff
changeset
|
64 backend.NoInstantNodes: ('not-acceptable', None), |
c9ddca3cce20
Change exception classes to include stanza error.
Ralph Meijer <ralphm@ik.nu>
parents:
31
diff
changeset
|
65 backend.NodeExists: ('conflict', None), |
c9ddca3cce20
Change exception classes to include stanza error.
Ralph Meijer <ralphm@ik.nu>
parents:
31
diff
changeset
|
66 backend.NotImplemented: ('feature-not-implemented', None), |
c9ddca3cce20
Change exception classes to include stanza error.
Ralph Meijer <ralphm@ik.nu>
parents:
31
diff
changeset
|
67 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
|
68 } |
ea195dc1732d
Allow publication of more than 1 item.
Ralph Meijer <ralphm@ik.nu>
parents:
2
diff
changeset
|
69 |
31
fa866793075d
Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents:
25
diff
changeset
|
70 class Service(component.Service): |
fa866793075d
Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents:
25
diff
changeset
|
71 |
105 | 72 implements(component.IService) |
1 | 73 |
31
fa866793075d
Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents:
25
diff
changeset
|
74 def __init__(self, backend): |
fa866793075d
Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents:
25
diff
changeset
|
75 self.backend = backend |
fa866793075d
Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents:
25
diff
changeset
|
76 |
fa866793075d
Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents:
25
diff
changeset
|
77 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
|
78 try: |
38
c9ddca3cce20
Change exception classes to include stanza error.
Ralph Meijer <ralphm@ik.nu>
parents:
31
diff
changeset
|
79 e = failure.trap(Error, *error_map.keys()) |
81
995ba223a43b
Implemented ComponentServiceToItemRetrievalService.
Ralph Meijer <ralphm@ik.nu>
parents:
73
diff
changeset
|
80 except: |
995ba223a43b
Implemented ComponentServiceToItemRetrievalService.
Ralph Meijer <ralphm@ik.nu>
parents:
73
diff
changeset
|
81 failure.printBriefTraceback() |
995ba223a43b
Implemented ComponentServiceToItemRetrievalService.
Ralph Meijer <ralphm@ik.nu>
parents:
73
diff
changeset
|
82 xmpp_error.error_from_iq(iq, 'internal-server-error') |
995ba223a43b
Implemented ComponentServiceToItemRetrievalService.
Ralph Meijer <ralphm@ik.nu>
parents:
73
diff
changeset
|
83 return iq |
995ba223a43b
Implemented ComponentServiceToItemRetrievalService.
Ralph Meijer <ralphm@ik.nu>
parents:
73
diff
changeset
|
84 else: |
38
c9ddca3cce20
Change exception classes to include stanza error.
Ralph Meijer <ralphm@ik.nu>
parents:
31
diff
changeset
|
85 if e == Error: |
c9ddca3cce20
Change exception classes to include stanza error.
Ralph Meijer <ralphm@ik.nu>
parents:
31
diff
changeset
|
86 stanza_error = failure.value.stanza_error |
c9ddca3cce20
Change exception classes to include stanza error.
Ralph Meijer <ralphm@ik.nu>
parents:
31
diff
changeset
|
87 pubsub_error = failure.value.pubsub_error |
c9ddca3cce20
Change exception classes to include stanza error.
Ralph Meijer <ralphm@ik.nu>
parents:
31
diff
changeset
|
88 msg = '' |
c9ddca3cce20
Change exception classes to include stanza error.
Ralph Meijer <ralphm@ik.nu>
parents:
31
diff
changeset
|
89 else: |
c9ddca3cce20
Change exception classes to include stanza error.
Ralph Meijer <ralphm@ik.nu>
parents:
31
diff
changeset
|
90 stanza_error, pubsub_error = error_map[e] |
c9ddca3cce20
Change exception classes to include stanza error.
Ralph Meijer <ralphm@ik.nu>
parents:
31
diff
changeset
|
91 msg = failure.value.msg |
c9ddca3cce20
Change exception classes to include stanza error.
Ralph Meijer <ralphm@ik.nu>
parents:
31
diff
changeset
|
92 |
c9ddca3cce20
Change exception classes to include stanza error.
Ralph Meijer <ralphm@ik.nu>
parents:
31
diff
changeset
|
93 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
|
94 if pubsub_error: |
c9ddca3cce20
Change exception classes to include stanza error.
Ralph Meijer <ralphm@ik.nu>
parents:
31
diff
changeset
|
95 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
|
96 return iq |
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 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
|
99 iq.swapAttributeValues("to", "from") |
fa866793075d
Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents:
25
diff
changeset
|
100 iq["type"] = 'result' |
95
3ad74552bbc7
Merge from RELENG_0: Implemented node configuration.
Ralph Meijer <ralphm@ik.nu>
parents:
93
diff
changeset
|
101 iq.children = [] |
3ad74552bbc7
Merge from RELENG_0: Implemented node configuration.
Ralph Meijer <ralphm@ik.nu>
parents:
93
diff
changeset
|
102 if result: |
3ad74552bbc7
Merge from RELENG_0: Implemented node configuration.
Ralph Meijer <ralphm@ik.nu>
parents:
93
diff
changeset
|
103 for child in result: |
3ad74552bbc7
Merge from RELENG_0: Implemented node configuration.
Ralph Meijer <ralphm@ik.nu>
parents:
93
diff
changeset
|
104 iq.addChild(child) |
3ad74552bbc7
Merge from RELENG_0: Implemented node configuration.
Ralph Meijer <ralphm@ik.nu>
parents:
93
diff
changeset
|
105 |
31
fa866793075d
Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents:
25
diff
changeset
|
106 return iq |
9 | 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 | 120 |
97
cf918d581da5
Enable admin to hide all nodes when the service is queried using disco items.
Ralph Meijer <ralphm@ik.nu>
parents:
96
diff
changeset
|
121 def __init__(self, backend): |
cf918d581da5
Enable admin to hide all nodes when the service is queried using disco items.
Ralph Meijer <ralphm@ik.nu>
parents:
96
diff
changeset
|
122 Service.__init__(self, backend) |
cf918d581da5
Enable admin to hide all nodes when the service is queried using disco items.
Ralph Meijer <ralphm@ik.nu>
parents:
96
diff
changeset
|
123 self.hide_nodes = False |
cf918d581da5
Enable admin to hide all nodes when the service is queried using disco items.
Ralph Meijer <ralphm@ik.nu>
parents:
96
diff
changeset
|
124 |
73 | 125 def get_disco_info(self, node): |
126 info = [] | |
31
fa866793075d
Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents:
25
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 not node: |
73 | 129 info.append(disco.Identity('pubsub', 'generic', |
130 'Generic Pubsub Service')) | |
131 | |
56
55fa890ef60b
Match backend's supported_*() methods in getFeatures() of ComponentServiceFromService.
Ralph Meijer <ralphm@ik.nu>
parents:
48
diff
changeset
|
132 if self.backend.supports_publisher_affiliation(): |
73 | 133 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
|
134 |
56
55fa890ef60b
Match backend's supported_*() methods in getFeatures() of ComponentServiceFromService.
Ralph Meijer <ralphm@ik.nu>
parents:
48
diff
changeset
|
135 if self.backend.supports_outcast_affiliation(): |
73 | 136 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
|
137 |
56
55fa890ef60b
Match backend's supported_*() methods in getFeatures() of ComponentServiceFromService.
Ralph Meijer <ralphm@ik.nu>
parents:
48
diff
changeset
|
138 if self.backend.supports_persistent_items(): |
73 | 139 info.append(disco.Feature(NS_PUBSUB + "#persistent-items")) |
140 | |
141 return defer.succeed(info) | |
142 else: | |
102
f4d725a94202
Fix bug in how errors are handled in disco info request.
Ralph Meijer <ralphm@ik.nu>
parents:
101
diff
changeset
|
143 try: |
f4d725a94202
Fix bug in how errors are handled in disco info request.
Ralph Meijer <ralphm@ik.nu>
parents:
101
diff
changeset
|
144 d = self.backend.get_node_type(node) |
104 | 145 d.addCallback(self._add_identity, [], node) |
102
f4d725a94202
Fix bug in how errors are handled in disco info request.
Ralph Meijer <ralphm@ik.nu>
parents:
101
diff
changeset
|
146 d.addErrback(lambda _: []) |
f4d725a94202
Fix bug in how errors are handled in disco info request.
Ralph Meijer <ralphm@ik.nu>
parents:
101
diff
changeset
|
147 except backend.NodeNotFound: |
f4d725a94202
Fix bug in how errors are handled in disco info request.
Ralph Meijer <ralphm@ik.nu>
parents:
101
diff
changeset
|
148 return defer.succeed([]) |
73 | 149 return d |
31
fa866793075d
Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents:
25
diff
changeset
|
150 |
101
b75fcc554358
Added support for disco info meta data.
Ralph Meijer <ralphm@ik.nu>
parents:
98
diff
changeset
|
151 def _add_identity(self, node_type, result_list, node): |
b75fcc554358
Added support for disco info meta data.
Ralph Meijer <ralphm@ik.nu>
parents:
98
diff
changeset
|
152 result_list.append(disco.Identity('pubsub', node_type)) |
b75fcc554358
Added support for disco info meta data.
Ralph Meijer <ralphm@ik.nu>
parents:
98
diff
changeset
|
153 d = self.backend.get_node_meta_data(node) |
b75fcc554358
Added support for disco info meta data.
Ralph Meijer <ralphm@ik.nu>
parents:
98
diff
changeset
|
154 d.addCallback(self._add_meta_data, node_type, result_list) |
b75fcc554358
Added support for disco info meta data.
Ralph Meijer <ralphm@ik.nu>
parents:
98
diff
changeset
|
155 return d |
b75fcc554358
Added support for disco info meta data.
Ralph Meijer <ralphm@ik.nu>
parents:
98
diff
changeset
|
156 |
b75fcc554358
Added support for disco info meta data.
Ralph Meijer <ralphm@ik.nu>
parents:
98
diff
changeset
|
157 def _add_meta_data(self, meta_data, node_type, result_list): |
b75fcc554358
Added support for disco info meta data.
Ralph Meijer <ralphm@ik.nu>
parents:
98
diff
changeset
|
158 form = data_form.Form(type="result", form_type=NS_PUBSUB + "#meta-data") |
b75fcc554358
Added support for disco info meta data.
Ralph Meijer <ralphm@ik.nu>
parents:
98
diff
changeset
|
159 for meta_datum in meta_data: |
b75fcc554358
Added support for disco info meta data.
Ralph Meijer <ralphm@ik.nu>
parents:
98
diff
changeset
|
160 form.add_field_single(**meta_datum) |
b75fcc554358
Added support for disco info meta data.
Ralph Meijer <ralphm@ik.nu>
parents:
98
diff
changeset
|
161 form.add_field_single("text-single", |
b75fcc554358
Added support for disco info meta data.
Ralph Meijer <ralphm@ik.nu>
parents:
98
diff
changeset
|
162 "pubsub#node_type", |
b75fcc554358
Added support for disco info meta data.
Ralph Meijer <ralphm@ik.nu>
parents:
98
diff
changeset
|
163 "The type of node (collection or leaf)", |
b75fcc554358
Added support for disco info meta data.
Ralph Meijer <ralphm@ik.nu>
parents:
98
diff
changeset
|
164 node_type) |
b75fcc554358
Added support for disco info meta data.
Ralph Meijer <ralphm@ik.nu>
parents:
98
diff
changeset
|
165 result_list.append(form) |
b75fcc554358
Added support for disco info meta data.
Ralph Meijer <ralphm@ik.nu>
parents:
98
diff
changeset
|
166 return result_list |
b75fcc554358
Added support for disco info meta data.
Ralph Meijer <ralphm@ik.nu>
parents:
98
diff
changeset
|
167 |
73 | 168 def get_disco_items(self, node): |
97
cf918d581da5
Enable admin to hide all nodes when the service is queried using disco items.
Ralph Meijer <ralphm@ik.nu>
parents:
96
diff
changeset
|
169 if node or self.hide_nodes: |
73 | 170 return defer.succeed([]) |
171 | |
172 d = self.backend.get_nodes() | |
173 d.addCallback(lambda nodes: [disco.Item(self.parent.jabberId, node) | |
174 for node in nodes]) | |
175 return d | |
31
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 components.registerAdapter(ComponentServiceFromService, backend.IBackendService, component.IService) |
1 | 178 |
31
fa866793075d
Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents:
25
diff
changeset
|
179 class ComponentServiceFromNotificationService(Service): |
23
884268687229
Simplify call chain by mapping incoming requests directly to method
Ralph Meijer <ralphm@ik.nu>
parents:
21
diff
changeset
|
180 |
38
c9ddca3cce20
Change exception classes to include stanza error.
Ralph Meijer <ralphm@ik.nu>
parents:
31
diff
changeset
|
181 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
|
182 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
|
183 |
fa866793075d
Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents:
25
diff
changeset
|
184 def notify(self, object): |
fa866793075d
Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents:
25
diff
changeset
|
185 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
|
186 items = object["items"] |
fa866793075d
Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents:
25
diff
changeset
|
187 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
|
188 d.addCallback(self._notify, node_id) |
7
a8cfb31dc50c
Implemented fallback for feature-not-implemented.
Ralph Meijer <ralphm@ik.nu>
parents:
4
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 _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
|
191 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
|
192 self._notify_recipient(recipient, node_id, items) |
1 | 193 |
31
fa866793075d
Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents:
25
diff
changeset
|
194 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
|
195 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
|
196 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
|
197 message["to"] = recipient |
38
c9ddca3cce20
Change exception classes to include stanza error.
Ralph Meijer <ralphm@ik.nu>
parents:
31
diff
changeset
|
198 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
|
199 items = event.addElement("items") |
fa866793075d
Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents:
25
diff
changeset
|
200 items["node"] = node_id |
fa866793075d
Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents:
25
diff
changeset
|
201 items.children.extend(itemlist) |
fa866793075d
Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents:
25
diff
changeset
|
202 self.send(message) |
1 | 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(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
|
205 |
fa866793075d
Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents:
25
diff
changeset
|
206 class ComponentServiceFromPublishService(Service): |
4
ea195dc1732d
Allow publication of more than 1 item.
Ralph Meijer <ralphm@ik.nu>
parents:
2
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_PUBLISH, self.onPublish) |
fa866793075d
Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents:
25
diff
changeset
|
210 |
93
ea3b2410c01c
Ignore unsupported configure and option elements.
Ralph Meijer <ralphm@ik.nu>
parents:
90
diff
changeset
|
211 def get_disco_info(self, node): |
ea3b2410c01c
Ignore unsupported configure and option elements.
Ralph Meijer <ralphm@ik.nu>
parents:
90
diff
changeset
|
212 info = [] |
ea3b2410c01c
Ignore unsupported configure and option elements.
Ralph Meijer <ralphm@ik.nu>
parents:
90
diff
changeset
|
213 |
ea3b2410c01c
Ignore unsupported configure and option elements.
Ralph Meijer <ralphm@ik.nu>
parents:
90
diff
changeset
|
214 if not node: |
ea3b2410c01c
Ignore unsupported configure and option elements.
Ralph Meijer <ralphm@ik.nu>
parents:
90
diff
changeset
|
215 info.append(disco.Feature(NS_PUBSUB + "#item-ids")) |
ea3b2410c01c
Ignore unsupported configure and option elements.
Ralph Meijer <ralphm@ik.nu>
parents:
90
diff
changeset
|
216 |
ea3b2410c01c
Ignore unsupported configure and option elements.
Ralph Meijer <ralphm@ik.nu>
parents:
90
diff
changeset
|
217 return defer.succeed(info) |
ea3b2410c01c
Ignore unsupported configure and option elements.
Ralph Meijer <ralphm@ik.nu>
parents:
90
diff
changeset
|
218 |
31
fa866793075d
Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents:
25
diff
changeset
|
219 def onPublish(self, iq): |
fa866793075d
Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents:
25
diff
changeset
|
220 self.handler_wrapper(self._onPublish, iq) |
4
ea195dc1732d
Allow publication of more than 1 item.
Ralph Meijer <ralphm@ik.nu>
parents:
2
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 _onPublish(self, iq): |
fa866793075d
Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents:
25
diff
changeset
|
223 node = iq.pubsub.publish["node"] |
1 | 224 |
31
fa866793075d
Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents:
25
diff
changeset
|
225 items = [] |
fa866793075d
Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents:
25
diff
changeset
|
226 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
|
227 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
|
228 items.append(child) |
7
a8cfb31dc50c
Implemented fallback for feature-not-implemented.
Ralph Meijer <ralphm@ik.nu>
parents:
4
diff
changeset
|
229 |
31
fa866793075d
Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents:
25
diff
changeset
|
230 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
|
231 jid.JID(iq["from"]).userhostJID()) |
21 | 232 |
31
fa866793075d
Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents:
25
diff
changeset
|
233 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
|
234 |
fa866793075d
Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents:
25
diff
changeset
|
235 class ComponentServiceFromSubscriptionService(Service): |
16 | 236 |
31
fa866793075d
Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents:
25
diff
changeset
|
237 def componentConnected(self, xmlstream): |
fa866793075d
Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents:
25
diff
changeset
|
238 xmlstream.addObserver(PUBSUB_SUBSCRIBE, self.onSubscribe) |
38
c9ddca3cce20
Change exception classes to include stanza error.
Ralph Meijer <ralphm@ik.nu>
parents:
31
diff
changeset
|
239 xmlstream.addObserver(PUBSUB_UNSUBSCRIBE, self.onUnsubscribe) |
c9ddca3cce20
Change exception classes to include stanza error.
Ralph Meijer <ralphm@ik.nu>
parents:
31
diff
changeset
|
240 xmlstream.addObserver(PUBSUB_OPTIONS_GET, self.onOptionsGet) |
c9ddca3cce20
Change exception classes to include stanza error.
Ralph Meijer <ralphm@ik.nu>
parents:
31
diff
changeset
|
241 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
|
242 |
73 | 243 def get_disco_info(self, node): |
244 info = [] | |
58
3e2e0040e3e0
Return support for the pubsub#subscribe feature.
Ralph Meijer <ralphm@ik.nu>
parents:
56
diff
changeset
|
245 |
3e2e0040e3e0
Return support for the pubsub#subscribe feature.
Ralph Meijer <ralphm@ik.nu>
parents:
56
diff
changeset
|
246 if not node: |
73 | 247 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
|
248 |
73 | 249 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
|
250 |
fa866793075d
Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents:
25
diff
changeset
|
251 def onSubscribe(self, iq): |
fa866793075d
Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents:
25
diff
changeset
|
252 self.handler_wrapper(self._onSubscribe, iq) |
21 | 253 |
31
fa866793075d
Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents:
25
diff
changeset
|
254 def _onSubscribe(self, iq): |
48
671ead538758
Check for malformed subscription request.
Ralph Meijer <ralphm@ik.nu>
parents:
47
diff
changeset
|
255 try: |
671ead538758
Check for malformed subscription request.
Ralph Meijer <ralphm@ik.nu>
parents:
47
diff
changeset
|
256 node_id = iq.pubsub.subscribe["node"] |
671ead538758
Check for malformed subscription request.
Ralph Meijer <ralphm@ik.nu>
parents:
47
diff
changeset
|
257 subscriber = jid.JID(iq.pubsub.subscribe["jid"]) |
671ead538758
Check for malformed subscription request.
Ralph Meijer <ralphm@ik.nu>
parents:
47
diff
changeset
|
258 except KeyError: |
671ead538758
Check for malformed subscription request.
Ralph Meijer <ralphm@ik.nu>
parents:
47
diff
changeset
|
259 raise BadRequest |
671ead538758
Check for malformed subscription request.
Ralph Meijer <ralphm@ik.nu>
parents:
47
diff
changeset
|
260 |
31
fa866793075d
Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents:
25
diff
changeset
|
261 requestor = jid.JID(iq["from"]).userhostJID() |
38
c9ddca3cce20
Change exception classes to include stanza error.
Ralph Meijer <ralphm@ik.nu>
parents:
31
diff
changeset
|
262 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
|
263 d.addCallback(self.return_subscription) |
38
c9ddca3cce20
Change exception classes to include stanza error.
Ralph Meijer <ralphm@ik.nu>
parents:
31
diff
changeset
|
264 return d |
7
a8cfb31dc50c
Implemented fallback for feature-not-implemented.
Ralph Meijer <ralphm@ik.nu>
parents:
4
diff
changeset
|
265 |
31
fa866793075d
Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents:
25
diff
changeset
|
266 def return_subscription(self, result): |
60
f6b7a06b8870
Implement retrieving affiliations.
Ralph Meijer <ralphm@ik.nu>
parents:
58
diff
changeset
|
267 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
|
268 entity = reply.addElement("entity") |
fa866793075d
Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents:
25
diff
changeset
|
269 entity["node"] = result["node"] |
fa866793075d
Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents:
25
diff
changeset
|
270 entity["jid"] = result["jid"].full() |
48
671ead538758
Check for malformed subscription request.
Ralph Meijer <ralphm@ik.nu>
parents:
47
diff
changeset
|
271 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
|
272 entity["subscription"] = result["subscription"] |
38
c9ddca3cce20
Change exception classes to include stanza error.
Ralph Meijer <ralphm@ik.nu>
parents:
31
diff
changeset
|
273 return [reply] |
c9ddca3cce20
Change exception classes to include stanza error.
Ralph Meijer <ralphm@ik.nu>
parents:
31
diff
changeset
|
274 |
c9ddca3cce20
Change exception classes to include stanza error.
Ralph Meijer <ralphm@ik.nu>
parents:
31
diff
changeset
|
275 def onUnsubscribe(self, iq): |
c9ddca3cce20
Change exception classes to include stanza error.
Ralph Meijer <ralphm@ik.nu>
parents:
31
diff
changeset
|
276 self.handler_wrapper(self._onUnsubscribe, iq) |
c9ddca3cce20
Change exception classes to include stanza error.
Ralph Meijer <ralphm@ik.nu>
parents:
31
diff
changeset
|
277 |
c9ddca3cce20
Change exception classes to include stanza error.
Ralph Meijer <ralphm@ik.nu>
parents:
31
diff
changeset
|
278 def _onUnsubscribe(self, iq): |
47
31eb00734cc5
Check for malformed unsubscribe request.
Ralph Meijer <ralphm@ik.nu>
parents:
38
diff
changeset
|
279 try: |
31eb00734cc5
Check for malformed unsubscribe request.
Ralph Meijer <ralphm@ik.nu>
parents:
38
diff
changeset
|
280 node_id = iq.pubsub.unsubscribe["node"] |
48
671ead538758
Check for malformed subscription request.
Ralph Meijer <ralphm@ik.nu>
parents:
47
diff
changeset
|
281 subscriber = jid.JID(iq.pubsub.unsubscribe["jid"]) |
47
31eb00734cc5
Check for malformed unsubscribe request.
Ralph Meijer <ralphm@ik.nu>
parents:
38
diff
changeset
|
282 except KeyError: |
31eb00734cc5
Check for malformed unsubscribe request.
Ralph Meijer <ralphm@ik.nu>
parents:
38
diff
changeset
|
283 raise BadRequest |
31eb00734cc5
Check for malformed unsubscribe request.
Ralph Meijer <ralphm@ik.nu>
parents:
38
diff
changeset
|
284 |
38
c9ddca3cce20
Change exception classes to include stanza error.
Ralph Meijer <ralphm@ik.nu>
parents:
31
diff
changeset
|
285 requestor = jid.JID(iq["from"]).userhostJID() |
c9ddca3cce20
Change exception classes to include stanza error.
Ralph Meijer <ralphm@ik.nu>
parents:
31
diff
changeset
|
286 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
|
287 |
c9ddca3cce20
Change exception classes to include stanza error.
Ralph Meijer <ralphm@ik.nu>
parents:
31
diff
changeset
|
288 def onOptionsGet(self, iq): |
c9ddca3cce20
Change exception classes to include stanza error.
Ralph Meijer <ralphm@ik.nu>
parents:
31
diff
changeset
|
289 self.handler_wrapper(self._onOptionsGet, iq) |
c9ddca3cce20
Change exception classes to include stanza error.
Ralph Meijer <ralphm@ik.nu>
parents:
31
diff
changeset
|
290 |
c9ddca3cce20
Change exception classes to include stanza error.
Ralph Meijer <ralphm@ik.nu>
parents:
31
diff
changeset
|
291 def _onOptionsGet(self, iq): |
c9ddca3cce20
Change exception classes to include stanza error.
Ralph Meijer <ralphm@ik.nu>
parents:
31
diff
changeset
|
292 raise OptionsUnavailable |
c9ddca3cce20
Change exception classes to include stanza error.
Ralph Meijer <ralphm@ik.nu>
parents:
31
diff
changeset
|
293 |
c9ddca3cce20
Change exception classes to include stanza error.
Ralph Meijer <ralphm@ik.nu>
parents:
31
diff
changeset
|
294 def onOptionsSet(self, iq): |
c9ddca3cce20
Change exception classes to include stanza error.
Ralph Meijer <ralphm@ik.nu>
parents:
31
diff
changeset
|
295 self.handler_wrapper(self._onOptionsSet, iq) |
c9ddca3cce20
Change exception classes to include stanza error.
Ralph Meijer <ralphm@ik.nu>
parents:
31
diff
changeset
|
296 |
c9ddca3cce20
Change exception classes to include stanza error.
Ralph Meijer <ralphm@ik.nu>
parents:
31
diff
changeset
|
297 def _onOptionsSet(self, iq): |
c9ddca3cce20
Change exception classes to include stanza error.
Ralph Meijer <ralphm@ik.nu>
parents:
31
diff
changeset
|
298 raise OptionsUnavailable |
23
884268687229
Simplify call chain by mapping incoming requests directly to method
Ralph Meijer <ralphm@ik.nu>
parents:
21
diff
changeset
|
299 |
31
fa866793075d
Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents:
25
diff
changeset
|
300 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
|
301 |
fa866793075d
Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents:
25
diff
changeset
|
302 class ComponentServiceFromNodeCreationService(Service): |
23
884268687229
Simplify call chain by mapping incoming requests directly to method
Ralph Meijer <ralphm@ik.nu>
parents:
21
diff
changeset
|
303 |
68
a3d67cbab9c4
Return deferreds from getFeatures() and getIdentities().
Ralph Meijer <ralphm@ik.nu>
parents:
60
diff
changeset
|
304 def componentConnected(self, xmlstream): |
a3d67cbab9c4
Return deferreds from getFeatures() and getIdentities().
Ralph Meijer <ralphm@ik.nu>
parents:
60
diff
changeset
|
305 xmlstream.addObserver(PUBSUB_CREATE, self.onCreate) |
a3d67cbab9c4
Return deferreds from getFeatures() and getIdentities().
Ralph Meijer <ralphm@ik.nu>
parents:
60
diff
changeset
|
306 xmlstream.addObserver(PUBSUB_CONFIGURE_GET, self.onConfigureGet) |
a3d67cbab9c4
Return deferreds from getFeatures() and getIdentities().
Ralph Meijer <ralphm@ik.nu>
parents:
60
diff
changeset
|
307 xmlstream.addObserver(PUBSUB_CONFIGURE_SET, self.onConfigureSet) |
a3d67cbab9c4
Return deferreds from getFeatures() and getIdentities().
Ralph Meijer <ralphm@ik.nu>
parents:
60
diff
changeset
|
308 |
73 | 309 def get_disco_info(self, node): |
310 info = [] | |
56
55fa890ef60b
Match backend's supported_*() methods in getFeatures() of ComponentServiceFromService.
Ralph Meijer <ralphm@ik.nu>
parents:
48
diff
changeset
|
311 |
55fa890ef60b
Match backend's supported_*() methods in getFeatures() of ComponentServiceFromService.
Ralph Meijer <ralphm@ik.nu>
parents:
48
diff
changeset
|
312 if not node: |
73 | 313 info.append(disco.Feature(NS_PUBSUB + "#create-nodes")) |
95
3ad74552bbc7
Merge from RELENG_0: Implemented node configuration.
Ralph Meijer <ralphm@ik.nu>
parents:
93
diff
changeset
|
314 info.append(disco.Feature(NS_PUBSUB + "#config-node")) |
56
55fa890ef60b
Match backend's supported_*() methods in getFeatures() of ComponentServiceFromService.
Ralph Meijer <ralphm@ik.nu>
parents:
48
diff
changeset
|
315 |
55fa890ef60b
Match backend's supported_*() methods in getFeatures() of ComponentServiceFromService.
Ralph Meijer <ralphm@ik.nu>
parents:
48
diff
changeset
|
316 if self.backend.supports_instant_nodes(): |
73 | 317 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
|
318 |
73 | 319 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
|
320 |
fa866793075d
Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents:
25
diff
changeset
|
321 def onCreate(self, iq): |
fa866793075d
Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents:
25
diff
changeset
|
322 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
|
323 |
31
fa866793075d
Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents:
25
diff
changeset
|
324 def _onCreate(self, iq): |
56
55fa890ef60b
Match backend's supported_*() methods in getFeatures() of ComponentServiceFromService.
Ralph Meijer <ralphm@ik.nu>
parents:
48
diff
changeset
|
325 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
|
326 |
31
fa866793075d
Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents:
25
diff
changeset
|
327 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
|
328 |
31
fa866793075d
Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents:
25
diff
changeset
|
329 d = self.backend.create_node(node, owner) |
95
3ad74552bbc7
Merge from RELENG_0: Implemented node configuration.
Ralph Meijer <ralphm@ik.nu>
parents:
93
diff
changeset
|
330 d.addCallback(self._return_create_response, iq) |
31
fa866793075d
Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents:
25
diff
changeset
|
331 return d |
2 | 332 |
95
3ad74552bbc7
Merge from RELENG_0: Implemented node configuration.
Ralph Meijer <ralphm@ik.nu>
parents:
93
diff
changeset
|
333 def _return_create_response(self, result, iq): |
83 | 334 node_id = iq.pubsub.create.getAttribute("node") |
335 if not node_id or node_id != result: | |
60
f6b7a06b8870
Implement retrieving affiliations.
Ralph Meijer <ralphm@ik.nu>
parents:
58
diff
changeset
|
336 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
|
337 entity = reply.addElement('create') |
83 | 338 entity['node'] = result |
60
f6b7a06b8870
Implement retrieving affiliations.
Ralph Meijer <ralphm@ik.nu>
parents:
58
diff
changeset
|
339 return [reply] |
31
fa866793075d
Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents:
25
diff
changeset
|
340 |
38
c9ddca3cce20
Change exception classes to include stanza error.
Ralph Meijer <ralphm@ik.nu>
parents:
31
diff
changeset
|
341 def onConfigureGet(self, iq): |
c9ddca3cce20
Change exception classes to include stanza error.
Ralph Meijer <ralphm@ik.nu>
parents:
31
diff
changeset
|
342 self.handler_wrapper(self._onConfigureGet, iq) |
c9ddca3cce20
Change exception classes to include stanza error.
Ralph Meijer <ralphm@ik.nu>
parents:
31
diff
changeset
|
343 |
c9ddca3cce20
Change exception classes to include stanza error.
Ralph Meijer <ralphm@ik.nu>
parents:
31
diff
changeset
|
344 def _onConfigureGet(self, iq): |
95
3ad74552bbc7
Merge from RELENG_0: Implemented node configuration.
Ralph Meijer <ralphm@ik.nu>
parents:
93
diff
changeset
|
345 try: |
3ad74552bbc7
Merge from RELENG_0: Implemented node configuration.
Ralph Meijer <ralphm@ik.nu>
parents:
93
diff
changeset
|
346 node_id = iq.pubsub.configure["node"] |
3ad74552bbc7
Merge from RELENG_0: Implemented node configuration.
Ralph Meijer <ralphm@ik.nu>
parents:
93
diff
changeset
|
347 except KeyError: |
3ad74552bbc7
Merge from RELENG_0: Implemented node configuration.
Ralph Meijer <ralphm@ik.nu>
parents:
93
diff
changeset
|
348 raise NodeNotConfigurable |
3ad74552bbc7
Merge from RELENG_0: Implemented node configuration.
Ralph Meijer <ralphm@ik.nu>
parents:
93
diff
changeset
|
349 |
3ad74552bbc7
Merge from RELENG_0: Implemented node configuration.
Ralph Meijer <ralphm@ik.nu>
parents:
93
diff
changeset
|
350 d = self.backend.get_node_configuration(node_id) |
3ad74552bbc7
Merge from RELENG_0: Implemented node configuration.
Ralph Meijer <ralphm@ik.nu>
parents:
93
diff
changeset
|
351 d.addCallback(self._return_configuration_response, node_id) |
3ad74552bbc7
Merge from RELENG_0: Implemented node configuration.
Ralph Meijer <ralphm@ik.nu>
parents:
93
diff
changeset
|
352 return d |
3ad74552bbc7
Merge from RELENG_0: Implemented node configuration.
Ralph Meijer <ralphm@ik.nu>
parents:
93
diff
changeset
|
353 |
3ad74552bbc7
Merge from RELENG_0: Implemented node configuration.
Ralph Meijer <ralphm@ik.nu>
parents:
93
diff
changeset
|
354 def _return_configuration_response(self, options, node_id): |
3ad74552bbc7
Merge from RELENG_0: Implemented node configuration.
Ralph Meijer <ralphm@ik.nu>
parents:
93
diff
changeset
|
355 reply = domish.Element((NS_PUBSUB_OWNER, "pubsub")) |
3ad74552bbc7
Merge from RELENG_0: Implemented node configuration.
Ralph Meijer <ralphm@ik.nu>
parents:
93
diff
changeset
|
356 configure = reply.addElement("configure") |
3ad74552bbc7
Merge from RELENG_0: Implemented node configuration.
Ralph Meijer <ralphm@ik.nu>
parents:
93
diff
changeset
|
357 if node_id: |
3ad74552bbc7
Merge from RELENG_0: Implemented node configuration.
Ralph Meijer <ralphm@ik.nu>
parents:
93
diff
changeset
|
358 configure["node"] = node_id |
101
b75fcc554358
Added support for disco info meta data.
Ralph Meijer <ralphm@ik.nu>
parents:
98
diff
changeset
|
359 form = data_form.Form(type="form", |
b75fcc554358
Added support for disco info meta data.
Ralph Meijer <ralphm@ik.nu>
parents:
98
diff
changeset
|
360 form_type=NS_PUBSUB + "#node_config") |
95
3ad74552bbc7
Merge from RELENG_0: Implemented node configuration.
Ralph Meijer <ralphm@ik.nu>
parents:
93
diff
changeset
|
361 |
3ad74552bbc7
Merge from RELENG_0: Implemented node configuration.
Ralph Meijer <ralphm@ik.nu>
parents:
93
diff
changeset
|
362 for option in options: |
101
b75fcc554358
Added support for disco info meta data.
Ralph Meijer <ralphm@ik.nu>
parents:
98
diff
changeset
|
363 form.add_field_single(**option) |
b75fcc554358
Added support for disco info meta data.
Ralph Meijer <ralphm@ik.nu>
parents:
98
diff
changeset
|
364 |
b75fcc554358
Added support for disco info meta data.
Ralph Meijer <ralphm@ik.nu>
parents:
98
diff
changeset
|
365 configure.addChild(form) |
95
3ad74552bbc7
Merge from RELENG_0: Implemented node configuration.
Ralph Meijer <ralphm@ik.nu>
parents:
93
diff
changeset
|
366 |
3ad74552bbc7
Merge from RELENG_0: Implemented node configuration.
Ralph Meijer <ralphm@ik.nu>
parents:
93
diff
changeset
|
367 return [reply] |
38
c9ddca3cce20
Change exception classes to include stanza error.
Ralph Meijer <ralphm@ik.nu>
parents:
31
diff
changeset
|
368 |
c9ddca3cce20
Change exception classes to include stanza error.
Ralph Meijer <ralphm@ik.nu>
parents:
31
diff
changeset
|
369 def onConfigureSet(self, iq): |
c9ddca3cce20
Change exception classes to include stanza error.
Ralph Meijer <ralphm@ik.nu>
parents:
31
diff
changeset
|
370 self.handler_wrapper(self._onConfigureSet, iq) |
c9ddca3cce20
Change exception classes to include stanza error.
Ralph Meijer <ralphm@ik.nu>
parents:
31
diff
changeset
|
371 |
c9ddca3cce20
Change exception classes to include stanza error.
Ralph Meijer <ralphm@ik.nu>
parents:
31
diff
changeset
|
372 def _onConfigureSet(self, iq): |
95
3ad74552bbc7
Merge from RELENG_0: Implemented node configuration.
Ralph Meijer <ralphm@ik.nu>
parents:
93
diff
changeset
|
373 try: |
3ad74552bbc7
Merge from RELENG_0: Implemented node configuration.
Ralph Meijer <ralphm@ik.nu>
parents:
93
diff
changeset
|
374 node_id = iq.pubsub.configure["node"] |
3ad74552bbc7
Merge from RELENG_0: Implemented node configuration.
Ralph Meijer <ralphm@ik.nu>
parents:
93
diff
changeset
|
375 except KeyError: |
3ad74552bbc7
Merge from RELENG_0: Implemented node configuration.
Ralph Meijer <ralphm@ik.nu>
parents:
93
diff
changeset
|
376 raise BadRequest |
3ad74552bbc7
Merge from RELENG_0: Implemented node configuration.
Ralph Meijer <ralphm@ik.nu>
parents:
93
diff
changeset
|
377 |
3ad74552bbc7
Merge from RELENG_0: Implemented node configuration.
Ralph Meijer <ralphm@ik.nu>
parents:
93
diff
changeset
|
378 requestor = jid.JID(iq["from"]).userhostJID() |
3ad74552bbc7
Merge from RELENG_0: Implemented node configuration.
Ralph Meijer <ralphm@ik.nu>
parents:
93
diff
changeset
|
379 |
3ad74552bbc7
Merge from RELENG_0: Implemented node configuration.
Ralph Meijer <ralphm@ik.nu>
parents:
93
diff
changeset
|
380 for element in iq.pubsub.configure.elements(): |
3ad74552bbc7
Merge from RELENG_0: Implemented node configuration.
Ralph Meijer <ralphm@ik.nu>
parents:
93
diff
changeset
|
381 if element.name != 'x' or element.uri != NS_X_DATA: |
3ad74552bbc7
Merge from RELENG_0: Implemented node configuration.
Ralph Meijer <ralphm@ik.nu>
parents:
93
diff
changeset
|
382 continue |
3ad74552bbc7
Merge from RELENG_0: Implemented node configuration.
Ralph Meijer <ralphm@ik.nu>
parents:
93
diff
changeset
|
383 |
3ad74552bbc7
Merge from RELENG_0: Implemented node configuration.
Ralph Meijer <ralphm@ik.nu>
parents:
93
diff
changeset
|
384 type = element.getAttribute("type") |
3ad74552bbc7
Merge from RELENG_0: Implemented node configuration.
Ralph Meijer <ralphm@ik.nu>
parents:
93
diff
changeset
|
385 if type == "cancel": |
3ad74552bbc7
Merge from RELENG_0: Implemented node configuration.
Ralph Meijer <ralphm@ik.nu>
parents:
93
diff
changeset
|
386 return None |
3ad74552bbc7
Merge from RELENG_0: Implemented node configuration.
Ralph Meijer <ralphm@ik.nu>
parents:
93
diff
changeset
|
387 elif type != "submit": |
3ad74552bbc7
Merge from RELENG_0: Implemented node configuration.
Ralph Meijer <ralphm@ik.nu>
parents:
93
diff
changeset
|
388 continue |
3ad74552bbc7
Merge from RELENG_0: Implemented node configuration.
Ralph Meijer <ralphm@ik.nu>
parents:
93
diff
changeset
|
389 |
3ad74552bbc7
Merge from RELENG_0: Implemented node configuration.
Ralph Meijer <ralphm@ik.nu>
parents:
93
diff
changeset
|
390 try: |
3ad74552bbc7
Merge from RELENG_0: Implemented node configuration.
Ralph Meijer <ralphm@ik.nu>
parents:
93
diff
changeset
|
391 options = self._get_form_options(element) |
3ad74552bbc7
Merge from RELENG_0: Implemented node configuration.
Ralph Meijer <ralphm@ik.nu>
parents:
93
diff
changeset
|
392 except: |
3ad74552bbc7
Merge from RELENG_0: Implemented node configuration.
Ralph Meijer <ralphm@ik.nu>
parents:
93
diff
changeset
|
393 raise BadRequest |
3ad74552bbc7
Merge from RELENG_0: Implemented node configuration.
Ralph Meijer <ralphm@ik.nu>
parents:
93
diff
changeset
|
394 |
3ad74552bbc7
Merge from RELENG_0: Implemented node configuration.
Ralph Meijer <ralphm@ik.nu>
parents:
93
diff
changeset
|
395 if options["FORM_TYPE"] == NS_PUBSUB + "#node_config": |
3ad74552bbc7
Merge from RELENG_0: Implemented node configuration.
Ralph Meijer <ralphm@ik.nu>
parents:
93
diff
changeset
|
396 del options["FORM_TYPE"] |
3ad74552bbc7
Merge from RELENG_0: Implemented node configuration.
Ralph Meijer <ralphm@ik.nu>
parents:
93
diff
changeset
|
397 return self.backend.set_node_configuration(node_id, |
3ad74552bbc7
Merge from RELENG_0: Implemented node configuration.
Ralph Meijer <ralphm@ik.nu>
parents:
93
diff
changeset
|
398 options, |
3ad74552bbc7
Merge from RELENG_0: Implemented node configuration.
Ralph Meijer <ralphm@ik.nu>
parents:
93
diff
changeset
|
399 requestor) |
3ad74552bbc7
Merge from RELENG_0: Implemented node configuration.
Ralph Meijer <ralphm@ik.nu>
parents:
93
diff
changeset
|
400 |
3ad74552bbc7
Merge from RELENG_0: Implemented node configuration.
Ralph Meijer <ralphm@ik.nu>
parents:
93
diff
changeset
|
401 raise BadRequest |
3ad74552bbc7
Merge from RELENG_0: Implemented node configuration.
Ralph Meijer <ralphm@ik.nu>
parents:
93
diff
changeset
|
402 |
3ad74552bbc7
Merge from RELENG_0: Implemented node configuration.
Ralph Meijer <ralphm@ik.nu>
parents:
93
diff
changeset
|
403 def _get_form_options(self, form): |
3ad74552bbc7
Merge from RELENG_0: Implemented node configuration.
Ralph Meijer <ralphm@ik.nu>
parents:
93
diff
changeset
|
404 options = {} |
3ad74552bbc7
Merge from RELENG_0: Implemented node configuration.
Ralph Meijer <ralphm@ik.nu>
parents:
93
diff
changeset
|
405 |
3ad74552bbc7
Merge from RELENG_0: Implemented node configuration.
Ralph Meijer <ralphm@ik.nu>
parents:
93
diff
changeset
|
406 for element in form.elements(): |
3ad74552bbc7
Merge from RELENG_0: Implemented node configuration.
Ralph Meijer <ralphm@ik.nu>
parents:
93
diff
changeset
|
407 if element.name == 'field' and element.uri == NS_X_DATA: |
3ad74552bbc7
Merge from RELENG_0: Implemented node configuration.
Ralph Meijer <ralphm@ik.nu>
parents:
93
diff
changeset
|
408 options[element["var"]] = str(element.value) |
3ad74552bbc7
Merge from RELENG_0: Implemented node configuration.
Ralph Meijer <ralphm@ik.nu>
parents:
93
diff
changeset
|
409 |
3ad74552bbc7
Merge from RELENG_0: Implemented node configuration.
Ralph Meijer <ralphm@ik.nu>
parents:
93
diff
changeset
|
410 return options |
38
c9ddca3cce20
Change exception classes to include stanza error.
Ralph Meijer <ralphm@ik.nu>
parents:
31
diff
changeset
|
411 |
31
fa866793075d
Split up implementation in several Services that match the division
Ralph Meijer <ralphm@ik.nu>
parents:
25
diff
changeset
|
412 components.registerAdapter(ComponentServiceFromNodeCreationService, backend.INodeCreationService, component.IService) |
60
f6b7a06b8870
Implement retrieving affiliations.
Ralph Meijer <ralphm@ik.nu>
parents:
58
diff
changeset
|
413 |
f6b7a06b8870
Implement retrieving affiliations.
Ralph Meijer <ralphm@ik.nu>
parents:
58
diff
changeset
|
414 class ComponentServiceFromAffiliationsService(Service): |
f6b7a06b8870
Implement retrieving affiliations.
Ralph Meijer <ralphm@ik.nu>
parents:
58
diff
changeset
|
415 |
f6b7a06b8870
Implement retrieving affiliations.
Ralph Meijer <ralphm@ik.nu>
parents:
58
diff
changeset
|
416 def componentConnected(self, xmlstream): |
f6b7a06b8870
Implement retrieving affiliations.
Ralph Meijer <ralphm@ik.nu>
parents:
58
diff
changeset
|
417 xmlstream.addObserver(PUBSUB_AFFILIATIONS, self.onAffiliations) |
f6b7a06b8870
Implement retrieving affiliations.
Ralph Meijer <ralphm@ik.nu>
parents:
58
diff
changeset
|
418 |
f6b7a06b8870
Implement retrieving affiliations.
Ralph Meijer <ralphm@ik.nu>
parents:
58
diff
changeset
|
419 def onAffiliations(self, iq): |
f6b7a06b8870
Implement retrieving affiliations.
Ralph Meijer <ralphm@ik.nu>
parents:
58
diff
changeset
|
420 self.handler_wrapper(self._onAffiliations, iq) |
f6b7a06b8870
Implement retrieving affiliations.
Ralph Meijer <ralphm@ik.nu>
parents:
58
diff
changeset
|
421 |
f6b7a06b8870
Implement retrieving affiliations.
Ralph Meijer <ralphm@ik.nu>
parents:
58
diff
changeset
|
422 def _onAffiliations(self, iq): |
f6b7a06b8870
Implement retrieving affiliations.
Ralph Meijer <ralphm@ik.nu>
parents:
58
diff
changeset
|
423 d = self.backend.get_affiliations(jid.JID(iq["from"]).userhostJID()) |
f6b7a06b8870
Implement retrieving affiliations.
Ralph Meijer <ralphm@ik.nu>
parents:
58
diff
changeset
|
424 d.addCallback(self._return_affiliations_response, iq) |
f6b7a06b8870
Implement retrieving affiliations.
Ralph Meijer <ralphm@ik.nu>
parents:
58
diff
changeset
|
425 return d |
f6b7a06b8870
Implement retrieving affiliations.
Ralph Meijer <ralphm@ik.nu>
parents:
58
diff
changeset
|
426 |
f6b7a06b8870
Implement retrieving affiliations.
Ralph Meijer <ralphm@ik.nu>
parents:
58
diff
changeset
|
427 def _return_affiliations_response(self, result, iq): |
f6b7a06b8870
Implement retrieving affiliations.
Ralph Meijer <ralphm@ik.nu>
parents:
58
diff
changeset
|
428 reply = domish.Element((NS_PUBSUB, 'pubsub')) |
f6b7a06b8870
Implement retrieving affiliations.
Ralph Meijer <ralphm@ik.nu>
parents:
58
diff
changeset
|
429 affiliations = reply.addElement('affiliations') |
f6b7a06b8870
Implement retrieving affiliations.
Ralph Meijer <ralphm@ik.nu>
parents:
58
diff
changeset
|
430 for r in result: |
f6b7a06b8870
Implement retrieving affiliations.
Ralph Meijer <ralphm@ik.nu>
parents:
58
diff
changeset
|
431 entity = affiliations.addElement('entity') |
f6b7a06b8870
Implement retrieving affiliations.
Ralph Meijer <ralphm@ik.nu>
parents:
58
diff
changeset
|
432 entity['node'] = r['node'] |
f6b7a06b8870
Implement retrieving affiliations.
Ralph Meijer <ralphm@ik.nu>
parents:
58
diff
changeset
|
433 entity['jid'] = r['jid'].full() |
f6b7a06b8870
Implement retrieving affiliations.
Ralph Meijer <ralphm@ik.nu>
parents:
58
diff
changeset
|
434 entity['affiliation'] = r['affiliation'] or 'none' |
f6b7a06b8870
Implement retrieving affiliations.
Ralph Meijer <ralphm@ik.nu>
parents:
58
diff
changeset
|
435 entity['subscription'] = r['subscription'] or 'none' |
f6b7a06b8870
Implement retrieving affiliations.
Ralph Meijer <ralphm@ik.nu>
parents:
58
diff
changeset
|
436 return [reply] |
f6b7a06b8870
Implement retrieving affiliations.
Ralph Meijer <ralphm@ik.nu>
parents:
58
diff
changeset
|
437 |
f6b7a06b8870
Implement retrieving affiliations.
Ralph Meijer <ralphm@ik.nu>
parents:
58
diff
changeset
|
438 components.registerAdapter(ComponentServiceFromAffiliationsService, backend.IAffiliationsService, component.IService) |
81
995ba223a43b
Implemented ComponentServiceToItemRetrievalService.
Ralph Meijer <ralphm@ik.nu>
parents:
73
diff
changeset
|
439 |
995ba223a43b
Implemented ComponentServiceToItemRetrievalService.
Ralph Meijer <ralphm@ik.nu>
parents:
73
diff
changeset
|
440 class ComponentServiceFromItemRetrievalService(Service): |
995ba223a43b
Implemented ComponentServiceToItemRetrievalService.
Ralph Meijer <ralphm@ik.nu>
parents:
73
diff
changeset
|
441 |
995ba223a43b
Implemented ComponentServiceToItemRetrievalService.
Ralph Meijer <ralphm@ik.nu>
parents:
73
diff
changeset
|
442 def componentConnected(self, xmlstream): |
995ba223a43b
Implemented ComponentServiceToItemRetrievalService.
Ralph Meijer <ralphm@ik.nu>
parents:
73
diff
changeset
|
443 xmlstream.addObserver(PUBSUB_ITEMS, self.onItems) |
995ba223a43b
Implemented ComponentServiceToItemRetrievalService.
Ralph Meijer <ralphm@ik.nu>
parents:
73
diff
changeset
|
444 |
83 | 445 def get_disco_info(self, node): |
446 info = [] | |
447 | |
448 if not node: | |
449 info.append(disco.Feature(NS_PUBSUB + "#retrieve-items")) | |
450 | |
451 return defer.succeed(info) | |
452 | |
81
995ba223a43b
Implemented ComponentServiceToItemRetrievalService.
Ralph Meijer <ralphm@ik.nu>
parents:
73
diff
changeset
|
453 def onItems(self, iq): |
995ba223a43b
Implemented ComponentServiceToItemRetrievalService.
Ralph Meijer <ralphm@ik.nu>
parents:
73
diff
changeset
|
454 self.handler_wrapper(self._onItems, iq) |
995ba223a43b
Implemented ComponentServiceToItemRetrievalService.
Ralph Meijer <ralphm@ik.nu>
parents:
73
diff
changeset
|
455 |
995ba223a43b
Implemented ComponentServiceToItemRetrievalService.
Ralph Meijer <ralphm@ik.nu>
parents:
73
diff
changeset
|
456 def _onItems(self, iq): |
995ba223a43b
Implemented ComponentServiceToItemRetrievalService.
Ralph Meijer <ralphm@ik.nu>
parents:
73
diff
changeset
|
457 try: |
995ba223a43b
Implemented ComponentServiceToItemRetrievalService.
Ralph Meijer <ralphm@ik.nu>
parents:
73
diff
changeset
|
458 node_id = iq.pubsub.items["node"] |
995ba223a43b
Implemented ComponentServiceToItemRetrievalService.
Ralph Meijer <ralphm@ik.nu>
parents:
73
diff
changeset
|
459 except KeyError: |
995ba223a43b
Implemented ComponentServiceToItemRetrievalService.
Ralph Meijer <ralphm@ik.nu>
parents:
73
diff
changeset
|
460 raise BadRequest |
995ba223a43b
Implemented ComponentServiceToItemRetrievalService.
Ralph Meijer <ralphm@ik.nu>
parents:
73
diff
changeset
|
461 |
995ba223a43b
Implemented ComponentServiceToItemRetrievalService.
Ralph Meijer <ralphm@ik.nu>
parents:
73
diff
changeset
|
462 max_items = iq.pubsub.items.getAttribute('max_items') |
995ba223a43b
Implemented ComponentServiceToItemRetrievalService.
Ralph Meijer <ralphm@ik.nu>
parents:
73
diff
changeset
|
463 |
995ba223a43b
Implemented ComponentServiceToItemRetrievalService.
Ralph Meijer <ralphm@ik.nu>
parents:
73
diff
changeset
|
464 if max_items: |
995ba223a43b
Implemented ComponentServiceToItemRetrievalService.
Ralph Meijer <ralphm@ik.nu>
parents:
73
diff
changeset
|
465 try: |
995ba223a43b
Implemented ComponentServiceToItemRetrievalService.
Ralph Meijer <ralphm@ik.nu>
parents:
73
diff
changeset
|
466 max_items = int(max_items) |
995ba223a43b
Implemented ComponentServiceToItemRetrievalService.
Ralph Meijer <ralphm@ik.nu>
parents:
73
diff
changeset
|
467 except ValueError: |
995ba223a43b
Implemented ComponentServiceToItemRetrievalService.
Ralph Meijer <ralphm@ik.nu>
parents:
73
diff
changeset
|
468 raise BadRequest |
995ba223a43b
Implemented ComponentServiceToItemRetrievalService.
Ralph Meijer <ralphm@ik.nu>
parents:
73
diff
changeset
|
469 |
995ba223a43b
Implemented ComponentServiceToItemRetrievalService.
Ralph Meijer <ralphm@ik.nu>
parents:
73
diff
changeset
|
470 item_ids = [] |
995ba223a43b
Implemented ComponentServiceToItemRetrievalService.
Ralph Meijer <ralphm@ik.nu>
parents:
73
diff
changeset
|
471 for child in iq.pubsub.items.children: |
995ba223a43b
Implemented ComponentServiceToItemRetrievalService.
Ralph Meijer <ralphm@ik.nu>
parents:
73
diff
changeset
|
472 if child.name == 'item' and child.uri == NS_PUBSUB: |
995ba223a43b
Implemented ComponentServiceToItemRetrievalService.
Ralph Meijer <ralphm@ik.nu>
parents:
73
diff
changeset
|
473 try: |
995ba223a43b
Implemented ComponentServiceToItemRetrievalService.
Ralph Meijer <ralphm@ik.nu>
parents:
73
diff
changeset
|
474 item_ids.append(child["id"]) |
995ba223a43b
Implemented ComponentServiceToItemRetrievalService.
Ralph Meijer <ralphm@ik.nu>
parents:
73
diff
changeset
|
475 except KeyError: |
995ba223a43b
Implemented ComponentServiceToItemRetrievalService.
Ralph Meijer <ralphm@ik.nu>
parents:
73
diff
changeset
|
476 raise BadRequest |
995ba223a43b
Implemented ComponentServiceToItemRetrievalService.
Ralph Meijer <ralphm@ik.nu>
parents:
73
diff
changeset
|
477 |
995ba223a43b
Implemented ComponentServiceToItemRetrievalService.
Ralph Meijer <ralphm@ik.nu>
parents:
73
diff
changeset
|
478 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
|
479 item_ids) |
995ba223a43b
Implemented ComponentServiceToItemRetrievalService.
Ralph Meijer <ralphm@ik.nu>
parents:
73
diff
changeset
|
480 d.addCallback(self._return_items_response, node_id) |
995ba223a43b
Implemented ComponentServiceToItemRetrievalService.
Ralph Meijer <ralphm@ik.nu>
parents:
73
diff
changeset
|
481 return d |
995ba223a43b
Implemented ComponentServiceToItemRetrievalService.
Ralph Meijer <ralphm@ik.nu>
parents:
73
diff
changeset
|
482 |
995ba223a43b
Implemented ComponentServiceToItemRetrievalService.
Ralph Meijer <ralphm@ik.nu>
parents:
73
diff
changeset
|
483 def _return_items_response(self, result, node_id): |
995ba223a43b
Implemented ComponentServiceToItemRetrievalService.
Ralph Meijer <ralphm@ik.nu>
parents:
73
diff
changeset
|
484 reply = domish.Element((NS_PUBSUB, 'pubsub')) |
995ba223a43b
Implemented ComponentServiceToItemRetrievalService.
Ralph Meijer <ralphm@ik.nu>
parents:
73
diff
changeset
|
485 items = reply.addElement('items') |
995ba223a43b
Implemented ComponentServiceToItemRetrievalService.
Ralph Meijer <ralphm@ik.nu>
parents:
73
diff
changeset
|
486 items["node"] = node_id |
98 | 487 for r in result: |
488 items.addRawXml(r) | |
81
995ba223a43b
Implemented ComponentServiceToItemRetrievalService.
Ralph Meijer <ralphm@ik.nu>
parents:
73
diff
changeset
|
489 |
995ba223a43b
Implemented ComponentServiceToItemRetrievalService.
Ralph Meijer <ralphm@ik.nu>
parents:
73
diff
changeset
|
490 return [reply] |
995ba223a43b
Implemented ComponentServiceToItemRetrievalService.
Ralph Meijer <ralphm@ik.nu>
parents:
73
diff
changeset
|
491 |
995ba223a43b
Implemented ComponentServiceToItemRetrievalService.
Ralph Meijer <ralphm@ik.nu>
parents:
73
diff
changeset
|
492 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
|
493 |
ec557449d1aa
Implement node retraction, with storage support for pgsql.
Ralph Meijer <ralphm@ik.nu>
parents:
83
diff
changeset
|
494 class ComponentServiceFromRetractionService(Service): |
ec557449d1aa
Implement node retraction, with storage support for pgsql.
Ralph Meijer <ralphm@ik.nu>
parents:
83
diff
changeset
|
495 |
ec557449d1aa
Implement node retraction, with storage support for pgsql.
Ralph Meijer <ralphm@ik.nu>
parents:
83
diff
changeset
|
496 def componentConnected(self, xmlstream): |
ec557449d1aa
Implement node retraction, with storage support for pgsql.
Ralph Meijer <ralphm@ik.nu>
parents:
83
diff
changeset
|
497 xmlstream.addObserver(PUBSUB_RETRACT, self.onRetract) |
90
59378610b16e
Implement node purging and node deletion.
Ralph Meijer <ralphm@ik.nu>
parents:
85
diff
changeset
|
498 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
|
499 |
96
f289c3e1dd0a
Announce pubsub#delete-any feature.
Ralph Meijer <ralphm@ik.nu>
parents:
95
diff
changeset
|
500 def get_disco_info(self, node): |
f289c3e1dd0a
Announce pubsub#delete-any feature.
Ralph Meijer <ralphm@ik.nu>
parents:
95
diff
changeset
|
501 info = [] |
f289c3e1dd0a
Announce pubsub#delete-any feature.
Ralph Meijer <ralphm@ik.nu>
parents:
95
diff
changeset
|
502 |
f289c3e1dd0a
Announce pubsub#delete-any feature.
Ralph Meijer <ralphm@ik.nu>
parents:
95
diff
changeset
|
503 if not node: |
f289c3e1dd0a
Announce pubsub#delete-any feature.
Ralph Meijer <ralphm@ik.nu>
parents:
95
diff
changeset
|
504 info.append(disco.Feature(NS_PUBSUB + "#delete-any")) |
f289c3e1dd0a
Announce pubsub#delete-any feature.
Ralph Meijer <ralphm@ik.nu>
parents:
95
diff
changeset
|
505 |
f289c3e1dd0a
Announce pubsub#delete-any feature.
Ralph Meijer <ralphm@ik.nu>
parents:
95
diff
changeset
|
506 return defer.succeed(info) |
f289c3e1dd0a
Announce pubsub#delete-any feature.
Ralph Meijer <ralphm@ik.nu>
parents:
95
diff
changeset
|
507 |
85
ec557449d1aa
Implement node retraction, with storage support for pgsql.
Ralph Meijer <ralphm@ik.nu>
parents:
83
diff
changeset
|
508 def onRetract(self, iq): |
ec557449d1aa
Implement node retraction, with storage support for pgsql.
Ralph Meijer <ralphm@ik.nu>
parents:
83
diff
changeset
|
509 self.handler_wrapper(self._onRetract, iq) |
ec557449d1aa
Implement node retraction, with storage support for pgsql.
Ralph Meijer <ralphm@ik.nu>
parents:
83
diff
changeset
|
510 |
ec557449d1aa
Implement node retraction, with storage support for pgsql.
Ralph Meijer <ralphm@ik.nu>
parents:
83
diff
changeset
|
511 def _onRetract(self, iq): |
ec557449d1aa
Implement node retraction, with storage support for pgsql.
Ralph Meijer <ralphm@ik.nu>
parents:
83
diff
changeset
|
512 try: |
ec557449d1aa
Implement node retraction, with storage support for pgsql.
Ralph Meijer <ralphm@ik.nu>
parents:
83
diff
changeset
|
513 node = iq.pubsub.retract["node"] |
ec557449d1aa
Implement node retraction, with storage support for pgsql.
Ralph Meijer <ralphm@ik.nu>
parents:
83
diff
changeset
|
514 except KeyError: |
ec557449d1aa
Implement node retraction, with storage support for pgsql.
Ralph Meijer <ralphm@ik.nu>
parents:
83
diff
changeset
|
515 raise BadRequest |
ec557449d1aa
Implement node retraction, with storage support for pgsql.
Ralph Meijer <ralphm@ik.nu>
parents:
83
diff
changeset
|
516 |
ec557449d1aa
Implement node retraction, with storage support for pgsql.
Ralph Meijer <ralphm@ik.nu>
parents:
83
diff
changeset
|
517 item_ids = [] |
ec557449d1aa
Implement node retraction, with storage support for pgsql.
Ralph Meijer <ralphm@ik.nu>
parents:
83
diff
changeset
|
518 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
|
519 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
|
520 try: |
ec557449d1aa
Implement node retraction, with storage support for pgsql.
Ralph Meijer <ralphm@ik.nu>
parents:
83
diff
changeset
|
521 item_ids.append(child["id"]) |
ec557449d1aa
Implement node retraction, with storage support for pgsql.
Ralph Meijer <ralphm@ik.nu>
parents:
83
diff
changeset
|
522 except KeyError: |
ec557449d1aa
Implement node retraction, with storage support for pgsql.
Ralph Meijer <ralphm@ik.nu>
parents:
83
diff
changeset
|
523 raise BadRequest |
ec557449d1aa
Implement node retraction, with storage support for pgsql.
Ralph Meijer <ralphm@ik.nu>
parents:
83
diff
changeset
|
524 |
ec557449d1aa
Implement node retraction, with storage support for pgsql.
Ralph Meijer <ralphm@ik.nu>
parents:
83
diff
changeset
|
525 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
|
526 jid.JID(iq["from"]).userhostJID()) |
ec557449d1aa
Implement node retraction, with storage support for pgsql.
Ralph Meijer <ralphm@ik.nu>
parents:
83
diff
changeset
|
527 |
90
59378610b16e
Implement node purging and node deletion.
Ralph Meijer <ralphm@ik.nu>
parents:
85
diff
changeset
|
528 def onPurge(self, iq): |
59378610b16e
Implement node purging and node deletion.
Ralph Meijer <ralphm@ik.nu>
parents:
85
diff
changeset
|
529 self.handler_wrapper(self._onPurge, iq) |
59378610b16e
Implement node purging and node deletion.
Ralph Meijer <ralphm@ik.nu>
parents:
85
diff
changeset
|
530 |
59378610b16e
Implement node purging and node deletion.
Ralph Meijer <ralphm@ik.nu>
parents:
85
diff
changeset
|
531 def _onPurge(self, iq): |
59378610b16e
Implement node purging and node deletion.
Ralph Meijer <ralphm@ik.nu>
parents:
85
diff
changeset
|
532 try: |
59378610b16e
Implement node purging and node deletion.
Ralph Meijer <ralphm@ik.nu>
parents:
85
diff
changeset
|
533 node = iq.pubsub.purge["node"] |
59378610b16e
Implement node purging and node deletion.
Ralph Meijer <ralphm@ik.nu>
parents:
85
diff
changeset
|
534 except KeyError: |
59378610b16e
Implement node purging and node deletion.
Ralph Meijer <ralphm@ik.nu>
parents:
85
diff
changeset
|
535 raise BadRequest |
59378610b16e
Implement node purging and node deletion.
Ralph Meijer <ralphm@ik.nu>
parents:
85
diff
changeset
|
536 |
59378610b16e
Implement node purging and node deletion.
Ralph Meijer <ralphm@ik.nu>
parents:
85
diff
changeset
|
537 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
|
538 |
85
ec557449d1aa
Implement node retraction, with storage support for pgsql.
Ralph Meijer <ralphm@ik.nu>
parents:
83
diff
changeset
|
539 components.registerAdapter(ComponentServiceFromRetractionService, backend.IRetractionService, component.IService) |
90
59378610b16e
Implement node purging and node deletion.
Ralph Meijer <ralphm@ik.nu>
parents:
85
diff
changeset
|
540 |
59378610b16e
Implement node purging and node deletion.
Ralph Meijer <ralphm@ik.nu>
parents:
85
diff
changeset
|
541 class ComponentServiceFromNodeDeletionService(Service): |
59378610b16e
Implement node purging and node deletion.
Ralph Meijer <ralphm@ik.nu>
parents:
85
diff
changeset
|
542 |
59378610b16e
Implement node purging and node deletion.
Ralph Meijer <ralphm@ik.nu>
parents:
85
diff
changeset
|
543 def __init__(self, backend): |
59378610b16e
Implement node purging and node deletion.
Ralph Meijer <ralphm@ik.nu>
parents:
85
diff
changeset
|
544 Service.__init__(self, backend) |
59378610b16e
Implement node purging and node deletion.
Ralph Meijer <ralphm@ik.nu>
parents:
85
diff
changeset
|
545 self.subscribers = [] |
59378610b16e
Implement node purging and node deletion.
Ralph Meijer <ralphm@ik.nu>
parents:
85
diff
changeset
|
546 |
59378610b16e
Implement node purging and node deletion.
Ralph Meijer <ralphm@ik.nu>
parents:
85
diff
changeset
|
547 def componentConnected(self, xmlstream): |
59378610b16e
Implement node purging and node deletion.
Ralph Meijer <ralphm@ik.nu>
parents:
85
diff
changeset
|
548 self.backend.register_pre_delete(self._pre_delete) |
59378610b16e
Implement node purging and node deletion.
Ralph Meijer <ralphm@ik.nu>
parents:
85
diff
changeset
|
549 xmlstream.addObserver(PUBSUB_DELETE, self.onDelete) |
59378610b16e
Implement node purging and node deletion.
Ralph Meijer <ralphm@ik.nu>
parents:
85
diff
changeset
|
550 |
59378610b16e
Implement node purging and node deletion.
Ralph Meijer <ralphm@ik.nu>
parents:
85
diff
changeset
|
551 def _pre_delete(self, node_id): |
59378610b16e
Implement node purging and node deletion.
Ralph Meijer <ralphm@ik.nu>
parents:
85
diff
changeset
|
552 d = self.backend.get_subscribers(node_id) |
59378610b16e
Implement node purging and node deletion.
Ralph Meijer <ralphm@ik.nu>
parents:
85
diff
changeset
|
553 d.addCallback(self._return_deferreds, node_id) |
59378610b16e
Implement node purging and node deletion.
Ralph Meijer <ralphm@ik.nu>
parents:
85
diff
changeset
|
554 return d |
59378610b16e
Implement node purging and node deletion.
Ralph Meijer <ralphm@ik.nu>
parents:
85
diff
changeset
|
555 |
59378610b16e
Implement node purging and node deletion.
Ralph Meijer <ralphm@ik.nu>
parents:
85
diff
changeset
|
556 def _return_deferreds(self, subscribers, node_id): |
59378610b16e
Implement node purging and node deletion.
Ralph Meijer <ralphm@ik.nu>
parents:
85
diff
changeset
|
557 d = defer.Deferred() |
59378610b16e
Implement node purging and node deletion.
Ralph Meijer <ralphm@ik.nu>
parents:
85
diff
changeset
|
558 d.addCallback(self._notify, subscribers, node_id) |
59378610b16e
Implement node purging and node deletion.
Ralph Meijer <ralphm@ik.nu>
parents:
85
diff
changeset
|
559 return [d] |
59378610b16e
Implement node purging and node deletion.
Ralph Meijer <ralphm@ik.nu>
parents:
85
diff
changeset
|
560 |
59378610b16e
Implement node purging and node deletion.
Ralph Meijer <ralphm@ik.nu>
parents:
85
diff
changeset
|
561 def _notify(self, result, subscribers, node_id): |
59378610b16e
Implement node purging and node deletion.
Ralph Meijer <ralphm@ik.nu>
parents:
85
diff
changeset
|
562 message = domish.Element((NS_COMPONENT, "message")) |
59378610b16e
Implement node purging and node deletion.
Ralph Meijer <ralphm@ik.nu>
parents:
85
diff
changeset
|
563 message["from"] = self.parent.jabberId |
59378610b16e
Implement node purging and node deletion.
Ralph Meijer <ralphm@ik.nu>
parents:
85
diff
changeset
|
564 event = message.addElement((NS_PUBSUB_EVENT, "event")) |
59378610b16e
Implement node purging and node deletion.
Ralph Meijer <ralphm@ik.nu>
parents:
85
diff
changeset
|
565 event.addElement("delete")["node"] = node_id |
59378610b16e
Implement node purging and node deletion.
Ralph Meijer <ralphm@ik.nu>
parents:
85
diff
changeset
|
566 |
59378610b16e
Implement node purging and node deletion.
Ralph Meijer <ralphm@ik.nu>
parents:
85
diff
changeset
|
567 for subscriber in subscribers: |
59378610b16e
Implement node purging and node deletion.
Ralph Meijer <ralphm@ik.nu>
parents:
85
diff
changeset
|
568 message["to"] = subscriber |
59378610b16e
Implement node purging and node deletion.
Ralph Meijer <ralphm@ik.nu>
parents:
85
diff
changeset
|
569 self.send(message) |
59378610b16e
Implement node purging and node deletion.
Ralph Meijer <ralphm@ik.nu>
parents:
85
diff
changeset
|
570 |
59378610b16e
Implement node purging and node deletion.
Ralph Meijer <ralphm@ik.nu>
parents:
85
diff
changeset
|
571 def onDelete(self, iq): |
59378610b16e
Implement node purging and node deletion.
Ralph Meijer <ralphm@ik.nu>
parents:
85
diff
changeset
|
572 self.handler_wrapper(self._onDelete, iq) |
59378610b16e
Implement node purging and node deletion.
Ralph Meijer <ralphm@ik.nu>
parents:
85
diff
changeset
|
573 |
59378610b16e
Implement node purging and node deletion.
Ralph Meijer <ralphm@ik.nu>
parents:
85
diff
changeset
|
574 def _onDelete(self, iq): |
59378610b16e
Implement node purging and node deletion.
Ralph Meijer <ralphm@ik.nu>
parents:
85
diff
changeset
|
575 try: |
59378610b16e
Implement node purging and node deletion.
Ralph Meijer <ralphm@ik.nu>
parents:
85
diff
changeset
|
576 node = iq.pubsub.delete["node"] |
59378610b16e
Implement node purging and node deletion.
Ralph Meijer <ralphm@ik.nu>
parents:
85
diff
changeset
|
577 except KeyError: |
59378610b16e
Implement node purging and node deletion.
Ralph Meijer <ralphm@ik.nu>
parents:
85
diff
changeset
|
578 raise BadRequest |
59378610b16e
Implement node purging and node deletion.
Ralph Meijer <ralphm@ik.nu>
parents:
85
diff
changeset
|
579 |
59378610b16e
Implement node purging and node deletion.
Ralph Meijer <ralphm@ik.nu>
parents:
85
diff
changeset
|
580 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
|
581 |
59378610b16e
Implement node purging and node deletion.
Ralph Meijer <ralphm@ik.nu>
parents:
85
diff
changeset
|
582 components.registerAdapter(ComponentServiceFromNodeDeletionService, backend.INodeDeletionService, component.IService) |