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