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