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