annotate idavoll/pubsub.py @ 21:e01bbbfa8a46

Implemented node creation. Corrected handling of subscribe/options combo.
author Ralph Meijer <ralphm@ik.nu>
date Wed, 06 Oct 2004 21:07:11 +0000
parents 7937d6fbbe2a
children 884268687229
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1
4cc41776b7d7 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
1 from twisted.protocols.jabber import component,jid
2
9701df89c534 First take at notifications
Ralph Meijer <ralphm@ik.nu>
parents: 1
diff changeset
2 from twisted.xish import utility, domish
1
4cc41776b7d7 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
3 from twisted.python import components
4cc41776b7d7 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
4 import backend
4cc41776b7d7 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
5 import xmpp_error
4cc41776b7d7 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
6
2
9701df89c534 First take at notifications
Ralph Meijer <ralphm@ik.nu>
parents: 1
diff changeset
7 NS_COMPONENT = 'jabber:component:accept'
9701df89c534 First take at notifications
Ralph Meijer <ralphm@ik.nu>
parents: 1
diff changeset
8 NS_PUBSUB = 'http://jabber.org/protocol/pubsub'
9701df89c534 First take at notifications
Ralph Meijer <ralphm@ik.nu>
parents: 1
diff changeset
9 NS_PUBSUB_EVENT = NS_PUBSUB + '#event'
16
ce3d0db64da1 Implemented basic subscribing.
Ralph Meijer <ralphm@ik.nu>
parents: 12
diff changeset
10 NS_PUBSUB_ERRORS = NS_PUBSUB + '#errors'
2
9701df89c534 First take at notifications
Ralph Meijer <ralphm@ik.nu>
parents: 1
diff changeset
11
1
4cc41776b7d7 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
12 IQ_GET = '/iq[@type="get"]'
4cc41776b7d7 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
13 IQ_SET = '/iq[@type="set"]'
2
9701df89c534 First take at notifications
Ralph Meijer <ralphm@ik.nu>
parents: 1
diff changeset
14 PUBSUB_ELEMENT = '/pubsub[@xmlns="' + NS_PUBSUB + '"]'
9701df89c534 First take at notifications
Ralph Meijer <ralphm@ik.nu>
parents: 1
diff changeset
15 PUBSUB_GET = IQ_GET + PUBSUB_ELEMENT
9701df89c534 First take at notifications
Ralph Meijer <ralphm@ik.nu>
parents: 1
diff changeset
16 PUBSUB_SET = IQ_SET + PUBSUB_ELEMENT
1
4cc41776b7d7 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
17 PUBSUB_CREATE = PUBSUB_SET + '/create'
4cc41776b7d7 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
18 PUBSUB_PUBLISH = PUBSUB_SET + '/publish'
16
ce3d0db64da1 Implemented basic subscribing.
Ralph Meijer <ralphm@ik.nu>
parents: 12
diff changeset
19 PUBSUB_SUBSCRIBE = PUBSUB_SET + '/subscribe'
7
a8cfb31dc50c Implemented fallback for feature-not-implemented.
Ralph Meijer <ralphm@ik.nu>
parents: 4
diff changeset
20 PUBSUB_OPTIONS_GET = PUBSUB_GET + '/options'
21
e01bbbfa8a46 Implemented node creation.
Ralph Meijer <ralphm@ik.nu>
parents: 18
diff changeset
21 PUBSUB_OPTIONS_SET = PUBSUB_SET + '/options'
7
a8cfb31dc50c Implemented fallback for feature-not-implemented.
Ralph Meijer <ralphm@ik.nu>
parents: 4
diff changeset
22 PUBSUB_CONFIGURE_GET = PUBSUB_GET + '/configure'
21
e01bbbfa8a46 Implemented node creation.
Ralph Meijer <ralphm@ik.nu>
parents: 18
diff changeset
23 PUBSUB_CONFIGURE_SET = PUBSUB_SET + '/configure'
1
4cc41776b7d7 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
24
4
ea195dc1732d Allow publication of more than 1 item.
Ralph Meijer <ralphm@ik.nu>
parents: 2
diff changeset
25 error_map = {
ea195dc1732d Allow publication of more than 1 item.
Ralph Meijer <ralphm@ik.nu>
parents: 2
diff changeset
26 backend.NotAuthorized: 'not-authorized',
ea195dc1732d Allow publication of more than 1 item.
Ralph Meijer <ralphm@ik.nu>
parents: 2
diff changeset
27 backend.NodeNotFound: 'item-not-found',
ea195dc1732d Allow publication of more than 1 item.
Ralph Meijer <ralphm@ik.nu>
parents: 2
diff changeset
28 backend.NoPayloadAllowed: 'bad-request',
ea195dc1732d Allow publication of more than 1 item.
Ralph Meijer <ralphm@ik.nu>
parents: 2
diff changeset
29 backend.PayloadExpected: 'bad-request',
21
e01bbbfa8a46 Implemented node creation.
Ralph Meijer <ralphm@ik.nu>
parents: 18
diff changeset
30 backend.NoInstantNodes: 'not-acceptable',
e01bbbfa8a46 Implemented node creation.
Ralph Meijer <ralphm@ik.nu>
parents: 18
diff changeset
31 backend.NodeExists: 'conflict',
4
ea195dc1732d Allow publication of more than 1 item.
Ralph Meijer <ralphm@ik.nu>
parents: 2
diff changeset
32 }
ea195dc1732d Allow publication of more than 1 item.
Ralph Meijer <ralphm@ik.nu>
parents: 2
diff changeset
33
1
4cc41776b7d7 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
34 class ComponentServiceFromBackend(component.Service, utility.EventDispatcher):
4cc41776b7d7 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
35
4cc41776b7d7 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
36 def __init__(self, backend):
4cc41776b7d7 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
37 utility.EventDispatcher.__init__(self)
4cc41776b7d7 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
38 self.backend = backend
2
9701df89c534 First take at notifications
Ralph Meijer <ralphm@ik.nu>
parents: 1
diff changeset
39 self.backend.pubsub_service = self
1
4cc41776b7d7 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
40 self.addObserver(PUBSUB_PUBLISH, self.onPublish)
21
e01bbbfa8a46 Implemented node creation.
Ralph Meijer <ralphm@ik.nu>
parents: 18
diff changeset
41
e01bbbfa8a46 Implemented node creation.
Ralph Meijer <ralphm@ik.nu>
parents: 18
diff changeset
42 # make sure subscribe and create are handled before resp. options and
e01bbbfa8a46 Implemented node creation.
Ralph Meijer <ralphm@ik.nu>
parents: 18
diff changeset
43 # configure
e01bbbfa8a46 Implemented node creation.
Ralph Meijer <ralphm@ik.nu>
parents: 18
diff changeset
44 self.addObserver(PUBSUB_SUBSCRIBE, self.onSubscribe, 0)
e01bbbfa8a46 Implemented node creation.
Ralph Meijer <ralphm@ik.nu>
parents: 18
diff changeset
45 self.addObserver(PUBSUB_OPTIONS_SET, self.onOptionsSet, 1)
e01bbbfa8a46 Implemented node creation.
Ralph Meijer <ralphm@ik.nu>
parents: 18
diff changeset
46 self.addObserver(PUBSUB_CREATE, self.onSubscribe, 0)
e01bbbfa8a46 Implemented node creation.
Ralph Meijer <ralphm@ik.nu>
parents: 18
diff changeset
47 self.addObserver(PUBSUB_CONFIGURE_SET, self.onConfigureSet, 1)
e01bbbfa8a46 Implemented node creation.
Ralph Meijer <ralphm@ik.nu>
parents: 18
diff changeset
48
7
a8cfb31dc50c Implemented fallback for feature-not-implemented.
Ralph Meijer <ralphm@ik.nu>
parents: 4
diff changeset
49 self.addObserver(PUBSUB_OPTIONS_GET, self.onOptionsGet)
a8cfb31dc50c Implemented fallback for feature-not-implemented.
Ralph Meijer <ralphm@ik.nu>
parents: 4
diff changeset
50 self.addObserver(PUBSUB_CONFIGURE_GET, self.onConfigureGet)
a8cfb31dc50c Implemented fallback for feature-not-implemented.
Ralph Meijer <ralphm@ik.nu>
parents: 4
diff changeset
51 self.addObserver(PUBSUB_GET, self.notImplemented, -1)
a8cfb31dc50c Implemented fallback for feature-not-implemented.
Ralph Meijer <ralphm@ik.nu>
parents: 4
diff changeset
52 self.addObserver(PUBSUB_SET, self.notImplemented, -1)
1
4cc41776b7d7 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
53
4cc41776b7d7 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
54 def componentConnected(self, xmlstream):
4cc41776b7d7 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
55 xmlstream.addObserver(PUBSUB_SET, self.onPubSub)
4cc41776b7d7 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
56 xmlstream.addObserver(PUBSUB_GET, self.onPubSub)
4cc41776b7d7 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
57
9
52bd563b7a5d Add disco support.
Ralph Meijer <ralphm@ik.nu>
parents: 7
diff changeset
58 def getIdentities(self, node):
52bd563b7a5d Add disco support.
Ralph Meijer <ralphm@ik.nu>
parents: 7
diff changeset
59 results = []
52bd563b7a5d Add disco support.
Ralph Meijer <ralphm@ik.nu>
parents: 7
diff changeset
60 if not node:
52bd563b7a5d Add disco support.
Ralph Meijer <ralphm@ik.nu>
parents: 7
diff changeset
61 results.append({
52bd563b7a5d Add disco support.
Ralph Meijer <ralphm@ik.nu>
parents: 7
diff changeset
62 'category': 'pubsub',
52bd563b7a5d Add disco support.
Ralph Meijer <ralphm@ik.nu>
parents: 7
diff changeset
63 'type': 'generic',
52bd563b7a5d Add disco support.
Ralph Meijer <ralphm@ik.nu>
parents: 7
diff changeset
64 'name': 'Generic Pubsub Service'
52bd563b7a5d Add disco support.
Ralph Meijer <ralphm@ik.nu>
parents: 7
diff changeset
65 })
52bd563b7a5d Add disco support.
Ralph Meijer <ralphm@ik.nu>
parents: 7
diff changeset
66 return results
52bd563b7a5d Add disco support.
Ralph Meijer <ralphm@ik.nu>
parents: 7
diff changeset
67
12
d45e921a5d2a Return implemented features
Ralph Meijer <ralphm@ik.nu>
parents: 9
diff changeset
68 def getFeatures(self, node):
d45e921a5d2a Return implemented features
Ralph Meijer <ralphm@ik.nu>
parents: 9
diff changeset
69 return [
d45e921a5d2a Return implemented features
Ralph Meijer <ralphm@ik.nu>
parents: 9
diff changeset
70 "http://jabber.org/protocol/pubsub#outcast-affil",
d45e921a5d2a Return implemented features
Ralph Meijer <ralphm@ik.nu>
parents: 9
diff changeset
71 "http://jabber.org/protocol/pubsub#publisher-affil",
16
ce3d0db64da1 Implemented basic subscribing.
Ralph Meijer <ralphm@ik.nu>
parents: 12
diff changeset
72 "http://jabber.org/protocol/pubsub#persistent-items",
12
d45e921a5d2a Return implemented features
Ralph Meijer <ralphm@ik.nu>
parents: 9
diff changeset
73 ]
d45e921a5d2a Return implemented features
Ralph Meijer <ralphm@ik.nu>
parents: 9
diff changeset
74
1
4cc41776b7d7 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
75 def error(self, failure, iq):
16
ce3d0db64da1 Implemented basic subscribing.
Ralph Meijer <ralphm@ik.nu>
parents: 12
diff changeset
76 try:
ce3d0db64da1 Implemented basic subscribing.
Ralph Meijer <ralphm@ik.nu>
parents: 12
diff changeset
77 r = failure.trap(*error_map.keys())
ce3d0db64da1 Implemented basic subscribing.
Ralph Meijer <ralphm@ik.nu>
parents: 12
diff changeset
78 xmpp_error.error_from_iq(iq, error_map[r], failure.value.msg)
ce3d0db64da1 Implemented basic subscribing.
Ralph Meijer <ralphm@ik.nu>
parents: 12
diff changeset
79 return iq
ce3d0db64da1 Implemented basic subscribing.
Ralph Meijer <ralphm@ik.nu>
parents: 12
diff changeset
80 except:
ce3d0db64da1 Implemented basic subscribing.
Ralph Meijer <ralphm@ik.nu>
parents: 12
diff changeset
81 xmpp_error.error_from_iq(iq, 'internal-server-error')
ce3d0db64da1 Implemented basic subscribing.
Ralph Meijer <ralphm@ik.nu>
parents: 12
diff changeset
82 self.send(iq)
ce3d0db64da1 Implemented basic subscribing.
Ralph Meijer <ralphm@ik.nu>
parents: 12
diff changeset
83 raise
1
4cc41776b7d7 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
84
4cc41776b7d7 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
85 def success(self, result, iq):
4cc41776b7d7 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
86 iq.swapAttributeValues("to", "from")
4cc41776b7d7 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
87 iq["type"] = 'result'
18
7937d6fbbe2a Small code cleanups
Ralph Meijer <ralphm@ik.nu>
parents: 16
diff changeset
88 iq.children = result or []
1
4cc41776b7d7 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
89 return iq
4cc41776b7d7 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
90
7
a8cfb31dc50c Implemented fallback for feature-not-implemented.
Ralph Meijer <ralphm@ik.nu>
parents: 4
diff changeset
91 def notImplemented(self, iq):
a8cfb31dc50c Implemented fallback for feature-not-implemented.
Ralph Meijer <ralphm@ik.nu>
parents: 4
diff changeset
92 self.send(xmpp_error.error_from_iq(iq, 'feature-not-implemented'))
a8cfb31dc50c Implemented fallback for feature-not-implemented.
Ralph Meijer <ralphm@ik.nu>
parents: 4
diff changeset
93
1
4cc41776b7d7 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
94 def onPubSub(self, iq):
4cc41776b7d7 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
95 self.dispatch(iq)
4cc41776b7d7 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
96 iq.handled = True
4cc41776b7d7 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
97
4cc41776b7d7 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
98 def onPublish(self, iq):
4cc41776b7d7 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
99 node = iq.pubsub.publish["node"]
4cc41776b7d7 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
100
4
ea195dc1732d Allow publication of more than 1 item.
Ralph Meijer <ralphm@ik.nu>
parents: 2
diff changeset
101 items = []
ea195dc1732d Allow publication of more than 1 item.
Ralph Meijer <ralphm@ik.nu>
parents: 2
diff changeset
102 for child in iq.pubsub.publish.children:
ea195dc1732d Allow publication of more than 1 item.
Ralph Meijer <ralphm@ik.nu>
parents: 2
diff changeset
103 if child.__class__ == domish.Element and child.name == 'item':
ea195dc1732d Allow publication of more than 1 item.
Ralph Meijer <ralphm@ik.nu>
parents: 2
diff changeset
104 items.append(child)
ea195dc1732d Allow publication of more than 1 item.
Ralph Meijer <ralphm@ik.nu>
parents: 2
diff changeset
105
ea195dc1732d Allow publication of more than 1 item.
Ralph Meijer <ralphm@ik.nu>
parents: 2
diff changeset
106 print items
ea195dc1732d Allow publication of more than 1 item.
Ralph Meijer <ralphm@ik.nu>
parents: 2
diff changeset
107
ea195dc1732d Allow publication of more than 1 item.
Ralph Meijer <ralphm@ik.nu>
parents: 2
diff changeset
108 d = self.backend.do_publish(node, jid.JID(iq["from"]).userhost(), items)
1
4cc41776b7d7 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
109 d.addCallback(self.success, iq)
4cc41776b7d7 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
110 d.addErrback(self.error, iq)
4cc41776b7d7 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
111 d.addCallback(self.send)
4cc41776b7d7 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
112
7
a8cfb31dc50c Implemented fallback for feature-not-implemented.
Ralph Meijer <ralphm@ik.nu>
parents: 4
diff changeset
113 def onOptionsGet(self, iq):
16
ce3d0db64da1 Implemented basic subscribing.
Ralph Meijer <ralphm@ik.nu>
parents: 12
diff changeset
114 xmpp_error.error_from_iq(iq, 'feature-not-implemented')
ce3d0db64da1 Implemented basic subscribing.
Ralph Meijer <ralphm@ik.nu>
parents: 12
diff changeset
115 iq.error.addElement((NS_PUBSUB_ERRORS, 'subscription-options-unavailable'), NS_PUBSUB_ERRORS)
ce3d0db64da1 Implemented basic subscribing.
Ralph Meijer <ralphm@ik.nu>
parents: 12
diff changeset
116 self.send(iq)
7
a8cfb31dc50c Implemented fallback for feature-not-implemented.
Ralph Meijer <ralphm@ik.nu>
parents: 4
diff changeset
117
21
e01bbbfa8a46 Implemented node creation.
Ralph Meijer <ralphm@ik.nu>
parents: 18
diff changeset
118 def onOptionsSet(self, iq):
e01bbbfa8a46 Implemented node creation.
Ralph Meijer <ralphm@ik.nu>
parents: 18
diff changeset
119 if iq.pubsub.subscribe:
e01bbbfa8a46 Implemented node creation.
Ralph Meijer <ralphm@ik.nu>
parents: 18
diff changeset
120 # this should be handled by the subscribe handler
e01bbbfa8a46 Implemented node creation.
Ralph Meijer <ralphm@ik.nu>
parents: 18
diff changeset
121 return
e01bbbfa8a46 Implemented node creation.
Ralph Meijer <ralphm@ik.nu>
parents: 18
diff changeset
122
e01bbbfa8a46 Implemented node creation.
Ralph Meijer <ralphm@ik.nu>
parents: 18
diff changeset
123 xmpp_error.error_from_iq(iq, 'feature-not-implemented')
e01bbbfa8a46 Implemented node creation.
Ralph Meijer <ralphm@ik.nu>
parents: 18
diff changeset
124 iq.error.addElement((NS_PUBSUB_ERRORS, 'subscription-options-unavailable'), NS_PUBSUB_ERRORS)
e01bbbfa8a46 Implemented node creation.
Ralph Meijer <ralphm@ik.nu>
parents: 18
diff changeset
125 self.send(iq)
e01bbbfa8a46 Implemented node creation.
Ralph Meijer <ralphm@ik.nu>
parents: 18
diff changeset
126
7
a8cfb31dc50c Implemented fallback for feature-not-implemented.
Ralph Meijer <ralphm@ik.nu>
parents: 4
diff changeset
127 def onConfigureGet(self, iq):
16
ce3d0db64da1 Implemented basic subscribing.
Ralph Meijer <ralphm@ik.nu>
parents: 12
diff changeset
128 xmpp_error.error_from_iq(iq, 'feature-not-implemented')
ce3d0db64da1 Implemented basic subscribing.
Ralph Meijer <ralphm@ik.nu>
parents: 12
diff changeset
129 iq.error.addElement((NS_PUBSUB_ERRORS, 'node-not-configurable'), NS_PUBSUB_ERRORS)
ce3d0db64da1 Implemented basic subscribing.
Ralph Meijer <ralphm@ik.nu>
parents: 12
diff changeset
130 self.send(iq)
ce3d0db64da1 Implemented basic subscribing.
Ralph Meijer <ralphm@ik.nu>
parents: 12
diff changeset
131
21
e01bbbfa8a46 Implemented node creation.
Ralph Meijer <ralphm@ik.nu>
parents: 18
diff changeset
132 def onConfigureSet(self, iq):
e01bbbfa8a46 Implemented node creation.
Ralph Meijer <ralphm@ik.nu>
parents: 18
diff changeset
133 if iq.pubsub.create:
e01bbbfa8a46 Implemented node creation.
Ralph Meijer <ralphm@ik.nu>
parents: 18
diff changeset
134 # this should be handled by the create handler
e01bbbfa8a46 Implemented node creation.
Ralph Meijer <ralphm@ik.nu>
parents: 18
diff changeset
135 return
e01bbbfa8a46 Implemented node creation.
Ralph Meijer <ralphm@ik.nu>
parents: 18
diff changeset
136
e01bbbfa8a46 Implemented node creation.
Ralph Meijer <ralphm@ik.nu>
parents: 18
diff changeset
137 xmpp_error.error_from_iq(iq, 'feature-not-implemented')
e01bbbfa8a46 Implemented node creation.
Ralph Meijer <ralphm@ik.nu>
parents: 18
diff changeset
138 iq.error.addElement((NS_PUBSUB_ERRORS, 'node-not-configurable'), NS_PUBSUB_ERRORS)
e01bbbfa8a46 Implemented node creation.
Ralph Meijer <ralphm@ik.nu>
parents: 18
diff changeset
139 self.send(iq)
e01bbbfa8a46 Implemented node creation.
Ralph Meijer <ralphm@ik.nu>
parents: 18
diff changeset
140
16
ce3d0db64da1 Implemented basic subscribing.
Ralph Meijer <ralphm@ik.nu>
parents: 12
diff changeset
141 def onSubscribe(self, iq):
21
e01bbbfa8a46 Implemented node creation.
Ralph Meijer <ralphm@ik.nu>
parents: 18
diff changeset
142 if iq.pubsub.options:
e01bbbfa8a46 Implemented node creation.
Ralph Meijer <ralphm@ik.nu>
parents: 18
diff changeset
143 xmpp_error.error_from_iq(iq, 'not-acceptable')
e01bbbfa8a46 Implemented node creation.
Ralph Meijer <ralphm@ik.nu>
parents: 18
diff changeset
144 iq.error.addElement((NS_PUBSUB_ERRORS, 'subscription-options-unavailable'), NS_PUBSUB_ERRORS)
e01bbbfa8a46 Implemented node creation.
Ralph Meijer <ralphm@ik.nu>
parents: 18
diff changeset
145 self.send(iq)
e01bbbfa8a46 Implemented node creation.
Ralph Meijer <ralphm@ik.nu>
parents: 18
diff changeset
146 return
e01bbbfa8a46 Implemented node creation.
Ralph Meijer <ralphm@ik.nu>
parents: 18
diff changeset
147
16
ce3d0db64da1 Implemented basic subscribing.
Ralph Meijer <ralphm@ik.nu>
parents: 12
diff changeset
148 node_id = iq.pubsub.subscribe["node"]
ce3d0db64da1 Implemented basic subscribing.
Ralph Meijer <ralphm@ik.nu>
parents: 12
diff changeset
149 subscriber = jid.JID(iq.pubsub.subscribe["jid"])
ce3d0db64da1 Implemented basic subscribing.
Ralph Meijer <ralphm@ik.nu>
parents: 12
diff changeset
150 requestor = jid.JID(iq["from"]).userhostJID()
ce3d0db64da1 Implemented basic subscribing.
Ralph Meijer <ralphm@ik.nu>
parents: 12
diff changeset
151 d = self.backend.do_subscribe(node_id, subscriber, requestor)
18
7937d6fbbe2a Small code cleanups
Ralph Meijer <ralphm@ik.nu>
parents: 16
diff changeset
152 d.addCallback(self.return_subscription)
7937d6fbbe2a Small code cleanups
Ralph Meijer <ralphm@ik.nu>
parents: 16
diff changeset
153 d.addCallback(self.succeed, iq)
16
ce3d0db64da1 Implemented basic subscribing.
Ralph Meijer <ralphm@ik.nu>
parents: 12
diff changeset
154 d.addErrback(self.error, iq)
ce3d0db64da1 Implemented basic subscribing.
Ralph Meijer <ralphm@ik.nu>
parents: 12
diff changeset
155 d.addCallback(self.send)
ce3d0db64da1 Implemented basic subscribing.
Ralph Meijer <ralphm@ik.nu>
parents: 12
diff changeset
156
18
7937d6fbbe2a Small code cleanups
Ralph Meijer <ralphm@ik.nu>
parents: 16
diff changeset
157 def return_subscription(self, result):
7937d6fbbe2a Small code cleanups
Ralph Meijer <ralphm@ik.nu>
parents: 16
diff changeset
158 reply = domish.Element("pubsub", NS_PUBSUB)
16
ce3d0db64da1 Implemented basic subscribing.
Ralph Meijer <ralphm@ik.nu>
parents: 12
diff changeset
159 entity = reply.addElement("entity")
ce3d0db64da1 Implemented basic subscribing.
Ralph Meijer <ralphm@ik.nu>
parents: 12
diff changeset
160 entity["node"] = result["node"]
ce3d0db64da1 Implemented basic subscribing.
Ralph Meijer <ralphm@ik.nu>
parents: 12
diff changeset
161 entity["jid"] = result["jid"].full()
ce3d0db64da1 Implemented basic subscribing.
Ralph Meijer <ralphm@ik.nu>
parents: 12
diff changeset
162 entity["affiliation"] = result["affiliation"]
ce3d0db64da1 Implemented basic subscribing.
Ralph Meijer <ralphm@ik.nu>
parents: 12
diff changeset
163 entity["subscription"] = result["subscription"]
18
7937d6fbbe2a Small code cleanups
Ralph Meijer <ralphm@ik.nu>
parents: 16
diff changeset
164 return reply
7
a8cfb31dc50c Implemented fallback for feature-not-implemented.
Ralph Meijer <ralphm@ik.nu>
parents: 4
diff changeset
165
4
ea195dc1732d Allow publication of more than 1 item.
Ralph Meijer <ralphm@ik.nu>
parents: 2
diff changeset
166 def do_notification(self, list, node):
1
4cc41776b7d7 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
167
4
ea195dc1732d Allow publication of more than 1 item.
Ralph Meijer <ralphm@ik.nu>
parents: 2
diff changeset
168 for recipient, items in list.items():
ea195dc1732d Allow publication of more than 1 item.
Ralph Meijer <ralphm@ik.nu>
parents: 2
diff changeset
169 self.notify(node, items, recipient)
2
9701df89c534 First take at notifications
Ralph Meijer <ralphm@ik.nu>
parents: 1
diff changeset
170
4
ea195dc1732d Allow publication of more than 1 item.
Ralph Meijer <ralphm@ik.nu>
parents: 2
diff changeset
171 def notify(self, node, itemlist, recipient):
2
9701df89c534 First take at notifications
Ralph Meijer <ralphm@ik.nu>
parents: 1
diff changeset
172 message = domish.Element((NS_COMPONENT, "message"))
9701df89c534 First take at notifications
Ralph Meijer <ralphm@ik.nu>
parents: 1
diff changeset
173 message["from"] = self.parent.jabberId
9701df89c534 First take at notifications
Ralph Meijer <ralphm@ik.nu>
parents: 1
diff changeset
174 message["to"] = recipient
9701df89c534 First take at notifications
Ralph Meijer <ralphm@ik.nu>
parents: 1
diff changeset
175 x = message.addElement((NS_PUBSUB_EVENT, "x"), NS_PUBSUB_EVENT)
9701df89c534 First take at notifications
Ralph Meijer <ralphm@ik.nu>
parents: 1
diff changeset
176 items = x.addElement("items")
9701df89c534 First take at notifications
Ralph Meijer <ralphm@ik.nu>
parents: 1
diff changeset
177 items["node"] = node
4
ea195dc1732d Allow publication of more than 1 item.
Ralph Meijer <ralphm@ik.nu>
parents: 2
diff changeset
178 items.children.extend(itemlist)
2
9701df89c534 First take at notifications
Ralph Meijer <ralphm@ik.nu>
parents: 1
diff changeset
179 self.send(message)
9701df89c534 First take at notifications
Ralph Meijer <ralphm@ik.nu>
parents: 1
diff changeset
180
21
e01bbbfa8a46 Implemented node creation.
Ralph Meijer <ralphm@ik.nu>
parents: 18
diff changeset
181 def onCreate(self, iq):
e01bbbfa8a46 Implemented node creation.
Ralph Meijer <ralphm@ik.nu>
parents: 18
diff changeset
182 if iq.pubsub.options:
e01bbbfa8a46 Implemented node creation.
Ralph Meijer <ralphm@ik.nu>
parents: 18
diff changeset
183 xmpp_error.error_from_iq(iq, 'not-acceptable')
e01bbbfa8a46 Implemented node creation.
Ralph Meijer <ralphm@ik.nu>
parents: 18
diff changeset
184 iq.error.addElement((NS_PUBSUB_ERRORS, 'node-not-configurable'), NS_PUBSUB_ERRORS)
e01bbbfa8a46 Implemented node creation.
Ralph Meijer <ralphm@ik.nu>
parents: 18
diff changeset
185 self.send(iq)
e01bbbfa8a46 Implemented node creation.
Ralph Meijer <ralphm@ik.nu>
parents: 18
diff changeset
186 return
e01bbbfa8a46 Implemented node creation.
Ralph Meijer <ralphm@ik.nu>
parents: 18
diff changeset
187
1
4cc41776b7d7 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
188 node = iq.pubsub.create["node"]
21
e01bbbfa8a46 Implemented node creation.
Ralph Meijer <ralphm@ik.nu>
parents: 18
diff changeset
189 owner = jid.JID(iq["from"]).userhostJID()
1
4cc41776b7d7 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
190
4cc41776b7d7 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
191 try:
21
e01bbbfa8a46 Implemented node creation.
Ralph Meijer <ralphm@ik.nu>
parents: 18
diff changeset
192 d = self.backend.create_node(node, owner)
e01bbbfa8a46 Implemented node creation.
Ralph Meijer <ralphm@ik.nu>
parents: 18
diff changeset
193 d.addCallback(self.return_create_response, iq)
e01bbbfa8a46 Implemented node creation.
Ralph Meijer <ralphm@ik.nu>
parents: 18
diff changeset
194 d.addCallback(self.succeed, iq)
e01bbbfa8a46 Implemented node creation.
Ralph Meijer <ralphm@ik.nu>
parents: 18
diff changeset
195 d.addErrback(self.error, iq)
e01bbbfa8a46 Implemented node creation.
Ralph Meijer <ralphm@ik.nu>
parents: 18
diff changeset
196 d.addCallback(self.send)
1
4cc41776b7d7 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
197 except:
4cc41776b7d7 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
198 pass
4cc41776b7d7 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
199
21
e01bbbfa8a46 Implemented node creation.
Ralph Meijer <ralphm@ik.nu>
parents: 18
diff changeset
200 def return_create_response(self, result, iq):
e01bbbfa8a46 Implemented node creation.
Ralph Meijer <ralphm@ik.nu>
parents: 18
diff changeset
201 if iq.pubsub.create["node"] is None:
e01bbbfa8a46 Implemented node creation.
Ralph Meijer <ralphm@ik.nu>
parents: 18
diff changeset
202 reply = domish.Element('pubsub', NS_PUBSUB)
e01bbbfa8a46 Implemented node creation.
Ralph Meijer <ralphm@ik.nu>
parents: 18
diff changeset
203 entity = reply.addElement('create')
e01bbbfa8a46 Implemented node creation.
Ralph Meijer <ralphm@ik.nu>
parents: 18
diff changeset
204 entity['node'] = result['node_id']
e01bbbfa8a46 Implemented node creation.
Ralph Meijer <ralphm@ik.nu>
parents: 18
diff changeset
205 return reply
1
4cc41776b7d7 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
206
4cc41776b7d7 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
207 components.registerAdapter(ComponentServiceFromBackend, backend.IBackendService, component.IService)
4cc41776b7d7 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
208