Mercurial > libervia-pubsub
annotate idavoll/idavoll.py @ 35:c51bca11699b
Remove erroneous second invocation of NotificationService and matching
component.IService adapter.
author | Ralph Meijer <ralphm@ik.nu> |
---|---|
date | Sun, 31 Oct 2004 15:57:23 +0000 |
parents | ddc08757ec1d |
children | 7d088c61e131 |
rev | line source |
---|---|
1 | 1 from twisted.protocols.jabber import component |
2 from twisted.application import service | |
8 | 3 from twisted.python import components |
32
ddc08757ec1d
Fire up several component.IServices that match the backend Services.
Ralph Meijer <ralphm@ik.nu>
parents:
26
diff
changeset
|
4 import backend |
26 | 5 import memory_backend |
1 | 6 import pubsub |
7 import xmpp_error | |
8 | |
9 import sys | |
10 | |
8 | 11 NS_DISCO = 'http://jabber.org/protocol/disco' |
12 NS_DISCO_INFO = NS_DISCO + '#info' | |
13 NS_DISCO_ITEMS = NS_DISCO + '#items' | |
14 NS_VERSION = 'jabber:iq:version' | |
15 | |
1 | 16 IQ_GET = '/iq[@type="get"]' |
17 IQ_SET = '/iq[@type="set"]' | |
8 | 18 VERSION = IQ_GET + '/query[@xmlns="' + NS_VERSION + '"]' |
19 DISCO_INFO = IQ_GET + '/query[@xmlns="' + NS_DISCO_INFO + '"]' | |
20 DISCO_ITEMS = IQ_GET + '/query[@xmlns="' + NS_DISCO_ITEMS + '"]' | |
1 | 21 |
22 class IdavollService(component.Service): | |
23 | |
32
ddc08757ec1d
Fire up several component.IServices that match the backend Services.
Ralph Meijer <ralphm@ik.nu>
parents:
26
diff
changeset
|
24 def componentConnected(self, xmlstream): |
ddc08757ec1d
Fire up several component.IServices that match the backend Services.
Ralph Meijer <ralphm@ik.nu>
parents:
26
diff
changeset
|
25 self.xmlstream = xmlstream |
ddc08757ec1d
Fire up several component.IServices that match the backend Services.
Ralph Meijer <ralphm@ik.nu>
parents:
26
diff
changeset
|
26 xmlstream.addObserver(VERSION, self.onVersion, 1) |
ddc08757ec1d
Fire up several component.IServices that match the backend Services.
Ralph Meijer <ralphm@ik.nu>
parents:
26
diff
changeset
|
27 xmlstream.addObserver(DISCO_INFO, self.onDiscoInfo, 1) |
ddc08757ec1d
Fire up several component.IServices that match the backend Services.
Ralph Meijer <ralphm@ik.nu>
parents:
26
diff
changeset
|
28 xmlstream.addObserver(DISCO_ITEMS, self.onDiscoItems, 1) |
ddc08757ec1d
Fire up several component.IServices that match the backend Services.
Ralph Meijer <ralphm@ik.nu>
parents:
26
diff
changeset
|
29 xmlstream.addObserver(IQ_GET, self.iqFallback, -1) |
ddc08757ec1d
Fire up several component.IServices that match the backend Services.
Ralph Meijer <ralphm@ik.nu>
parents:
26
diff
changeset
|
30 xmlstream.addObserver(IQ_SET, self.iqFallback, -1) |
8 | 31 |
32
ddc08757ec1d
Fire up several component.IServices that match the backend Services.
Ralph Meijer <ralphm@ik.nu>
parents:
26
diff
changeset
|
32 def getFeatures(self, node): |
ddc08757ec1d
Fire up several component.IServices that match the backend Services.
Ralph Meijer <ralphm@ik.nu>
parents:
26
diff
changeset
|
33 if not node: |
ddc08757ec1d
Fire up several component.IServices that match the backend Services.
Ralph Meijer <ralphm@ik.nu>
parents:
26
diff
changeset
|
34 return [NS_DISCO_ITEMS, NS_VERSION] |
ddc08757ec1d
Fire up several component.IServices that match the backend Services.
Ralph Meijer <ralphm@ik.nu>
parents:
26
diff
changeset
|
35 |
ddc08757ec1d
Fire up several component.IServices that match the backend Services.
Ralph Meijer <ralphm@ik.nu>
parents:
26
diff
changeset
|
36 def onVersion(self, iq): |
ddc08757ec1d
Fire up several component.IServices that match the backend Services.
Ralph Meijer <ralphm@ik.nu>
parents:
26
diff
changeset
|
37 iq.swapAttributeValues("to", "from") |
ddc08757ec1d
Fire up several component.IServices that match the backend Services.
Ralph Meijer <ralphm@ik.nu>
parents:
26
diff
changeset
|
38 iq["type"] = "result" |
ddc08757ec1d
Fire up several component.IServices that match the backend Services.
Ralph Meijer <ralphm@ik.nu>
parents:
26
diff
changeset
|
39 name = iq.addElement("name", None, 'Idavoll') |
ddc08757ec1d
Fire up several component.IServices that match the backend Services.
Ralph Meijer <ralphm@ik.nu>
parents:
26
diff
changeset
|
40 version = iq.addElement("version", None, '0.1') |
ddc08757ec1d
Fire up several component.IServices that match the backend Services.
Ralph Meijer <ralphm@ik.nu>
parents:
26
diff
changeset
|
41 self.send(iq) |
ddc08757ec1d
Fire up several component.IServices that match the backend Services.
Ralph Meijer <ralphm@ik.nu>
parents:
26
diff
changeset
|
42 iq.handled = True |
1 | 43 |
32
ddc08757ec1d
Fire up several component.IServices that match the backend Services.
Ralph Meijer <ralphm@ik.nu>
parents:
26
diff
changeset
|
44 def onDiscoInfo(self, iq): |
ddc08757ec1d
Fire up several component.IServices that match the backend Services.
Ralph Meijer <ralphm@ik.nu>
parents:
26
diff
changeset
|
45 identities = [] |
ddc08757ec1d
Fire up several component.IServices that match the backend Services.
Ralph Meijer <ralphm@ik.nu>
parents:
26
diff
changeset
|
46 features = [] |
ddc08757ec1d
Fire up several component.IServices that match the backend Services.
Ralph Meijer <ralphm@ik.nu>
parents:
26
diff
changeset
|
47 node = iq.query.getAttribute("node") |
8 | 48 |
32
ddc08757ec1d
Fire up several component.IServices that match the backend Services.
Ralph Meijer <ralphm@ik.nu>
parents:
26
diff
changeset
|
49 for c in self.parent: |
ddc08757ec1d
Fire up several component.IServices that match the backend Services.
Ralph Meijer <ralphm@ik.nu>
parents:
26
diff
changeset
|
50 if components.implements(c, component.IService): |
ddc08757ec1d
Fire up several component.IServices that match the backend Services.
Ralph Meijer <ralphm@ik.nu>
parents:
26
diff
changeset
|
51 if hasattr(c, "getIdentities"): |
ddc08757ec1d
Fire up several component.IServices that match the backend Services.
Ralph Meijer <ralphm@ik.nu>
parents:
26
diff
changeset
|
52 identities.extend(c.getIdentities(node)) |
ddc08757ec1d
Fire up several component.IServices that match the backend Services.
Ralph Meijer <ralphm@ik.nu>
parents:
26
diff
changeset
|
53 if hasattr(c, "getFeatures"): |
ddc08757ec1d
Fire up several component.IServices that match the backend Services.
Ralph Meijer <ralphm@ik.nu>
parents:
26
diff
changeset
|
54 features.extend(c.getFeatures(node)) |
8 | 55 |
32
ddc08757ec1d
Fire up several component.IServices that match the backend Services.
Ralph Meijer <ralphm@ik.nu>
parents:
26
diff
changeset
|
56 if not features and not identities and not node: |
ddc08757ec1d
Fire up several component.IServices that match the backend Services.
Ralph Meijer <ralphm@ik.nu>
parents:
26
diff
changeset
|
57 xmpp_error.error_from_iq(iq, 'item-not-found') |
ddc08757ec1d
Fire up several component.IServices that match the backend Services.
Ralph Meijer <ralphm@ik.nu>
parents:
26
diff
changeset
|
58 else: |
ddc08757ec1d
Fire up several component.IServices that match the backend Services.
Ralph Meijer <ralphm@ik.nu>
parents:
26
diff
changeset
|
59 iq.swapAttributeValues("to", "from") |
ddc08757ec1d
Fire up several component.IServices that match the backend Services.
Ralph Meijer <ralphm@ik.nu>
parents:
26
diff
changeset
|
60 iq["type"] = "result" |
ddc08757ec1d
Fire up several component.IServices that match the backend Services.
Ralph Meijer <ralphm@ik.nu>
parents:
26
diff
changeset
|
61 for identity in identities: |
ddc08757ec1d
Fire up several component.IServices that match the backend Services.
Ralph Meijer <ralphm@ik.nu>
parents:
26
diff
changeset
|
62 i = iq.query.addElement("identity") |
ddc08757ec1d
Fire up several component.IServices that match the backend Services.
Ralph Meijer <ralphm@ik.nu>
parents:
26
diff
changeset
|
63 i.attributes = identity |
ddc08757ec1d
Fire up several component.IServices that match the backend Services.
Ralph Meijer <ralphm@ik.nu>
parents:
26
diff
changeset
|
64 print features |
ddc08757ec1d
Fire up several component.IServices that match the backend Services.
Ralph Meijer <ralphm@ik.nu>
parents:
26
diff
changeset
|
65 for feature in features: |
ddc08757ec1d
Fire up several component.IServices that match the backend Services.
Ralph Meijer <ralphm@ik.nu>
parents:
26
diff
changeset
|
66 f = iq.query.addElement("feature") |
ddc08757ec1d
Fire up several component.IServices that match the backend Services.
Ralph Meijer <ralphm@ik.nu>
parents:
26
diff
changeset
|
67 f["var"] = feature |
8 | 68 |
32
ddc08757ec1d
Fire up several component.IServices that match the backend Services.
Ralph Meijer <ralphm@ik.nu>
parents:
26
diff
changeset
|
69 self.send(iq) |
ddc08757ec1d
Fire up several component.IServices that match the backend Services.
Ralph Meijer <ralphm@ik.nu>
parents:
26
diff
changeset
|
70 iq.handled = True |
8 | 71 |
32
ddc08757ec1d
Fire up several component.IServices that match the backend Services.
Ralph Meijer <ralphm@ik.nu>
parents:
26
diff
changeset
|
72 def onDiscoItems(self, iq): |
ddc08757ec1d
Fire up several component.IServices that match the backend Services.
Ralph Meijer <ralphm@ik.nu>
parents:
26
diff
changeset
|
73 iq.swapAttributeValues("to", "from") |
ddc08757ec1d
Fire up several component.IServices that match the backend Services.
Ralph Meijer <ralphm@ik.nu>
parents:
26
diff
changeset
|
74 iq["type"] = "result" |
ddc08757ec1d
Fire up several component.IServices that match the backend Services.
Ralph Meijer <ralphm@ik.nu>
parents:
26
diff
changeset
|
75 iq.query.children = [] |
ddc08757ec1d
Fire up several component.IServices that match the backend Services.
Ralph Meijer <ralphm@ik.nu>
parents:
26
diff
changeset
|
76 self.send(iq) |
ddc08757ec1d
Fire up several component.IServices that match the backend Services.
Ralph Meijer <ralphm@ik.nu>
parents:
26
diff
changeset
|
77 |
ddc08757ec1d
Fire up several component.IServices that match the backend Services.
Ralph Meijer <ralphm@ik.nu>
parents:
26
diff
changeset
|
78 def iqFallback(self, iq): |
ddc08757ec1d
Fire up several component.IServices that match the backend Services.
Ralph Meijer <ralphm@ik.nu>
parents:
26
diff
changeset
|
79 if iq.handled == True: |
ddc08757ec1d
Fire up several component.IServices that match the backend Services.
Ralph Meijer <ralphm@ik.nu>
parents:
26
diff
changeset
|
80 return |
1 | 81 |
32
ddc08757ec1d
Fire up several component.IServices that match the backend Services.
Ralph Meijer <ralphm@ik.nu>
parents:
26
diff
changeset
|
82 self.send(xmpp_error.error_from_iq(iq, 'service-unavailable')) |
1 | 83 |
84 def makeService(config): | |
32
ddc08757ec1d
Fire up several component.IServices that match the backend Services.
Ralph Meijer <ralphm@ik.nu>
parents:
26
diff
changeset
|
85 serviceCollection = service.MultiService() |
1 | 86 |
32
ddc08757ec1d
Fire up several component.IServices that match the backend Services.
Ralph Meijer <ralphm@ik.nu>
parents:
26
diff
changeset
|
87 # set up Jabber Component |
ddc08757ec1d
Fire up several component.IServices that match the backend Services.
Ralph Meijer <ralphm@ik.nu>
parents:
26
diff
changeset
|
88 sm = component.buildServiceManager(config["jid"], config["secret"], |
ddc08757ec1d
Fire up several component.IServices that match the backend Services.
Ralph Meijer <ralphm@ik.nu>
parents:
26
diff
changeset
|
89 ("tcp:%s:%s" % (config["rhost"], config["rport"]))) |
ddc08757ec1d
Fire up several component.IServices that match the backend Services.
Ralph Meijer <ralphm@ik.nu>
parents:
26
diff
changeset
|
90 |
ddc08757ec1d
Fire up several component.IServices that match the backend Services.
Ralph Meijer <ralphm@ik.nu>
parents:
26
diff
changeset
|
91 b = memory_backend |
ddc08757ec1d
Fire up several component.IServices that match the backend Services.
Ralph Meijer <ralphm@ik.nu>
parents:
26
diff
changeset
|
92 bs = b.BackendService() |
1 | 93 |
32
ddc08757ec1d
Fire up several component.IServices that match the backend Services.
Ralph Meijer <ralphm@ik.nu>
parents:
26
diff
changeset
|
94 component.IService(bs).setServiceParent(sm) |
ddc08757ec1d
Fire up several component.IServices that match the backend Services.
Ralph Meijer <ralphm@ik.nu>
parents:
26
diff
changeset
|
95 |
ddc08757ec1d
Fire up several component.IServices that match the backend Services.
Ralph Meijer <ralphm@ik.nu>
parents:
26
diff
changeset
|
96 bsc = b.PublishService() |
ddc08757ec1d
Fire up several component.IServices that match the backend Services.
Ralph Meijer <ralphm@ik.nu>
parents:
26
diff
changeset
|
97 bsc.setServiceParent(bs) |
ddc08757ec1d
Fire up several component.IServices that match the backend Services.
Ralph Meijer <ralphm@ik.nu>
parents:
26
diff
changeset
|
98 component.IService(bsc).setServiceParent(sm) |
ddc08757ec1d
Fire up several component.IServices that match the backend Services.
Ralph Meijer <ralphm@ik.nu>
parents:
26
diff
changeset
|
99 |
ddc08757ec1d
Fire up several component.IServices that match the backend Services.
Ralph Meijer <ralphm@ik.nu>
parents:
26
diff
changeset
|
100 bsc = b.NotificationService() |
ddc08757ec1d
Fire up several component.IServices that match the backend Services.
Ralph Meijer <ralphm@ik.nu>
parents:
26
diff
changeset
|
101 bsc.setServiceParent(bs) |
ddc08757ec1d
Fire up several component.IServices that match the backend Services.
Ralph Meijer <ralphm@ik.nu>
parents:
26
diff
changeset
|
102 component.IService(bsc).setServiceParent(sm) |
1 | 103 |
32
ddc08757ec1d
Fire up several component.IServices that match the backend Services.
Ralph Meijer <ralphm@ik.nu>
parents:
26
diff
changeset
|
104 bsc = b.NodeCreationService() |
ddc08757ec1d
Fire up several component.IServices that match the backend Services.
Ralph Meijer <ralphm@ik.nu>
parents:
26
diff
changeset
|
105 bsc.setServiceParent(bs) |
ddc08757ec1d
Fire up several component.IServices that match the backend Services.
Ralph Meijer <ralphm@ik.nu>
parents:
26
diff
changeset
|
106 component.IService(bsc).setServiceParent(sm) |
ddc08757ec1d
Fire up several component.IServices that match the backend Services.
Ralph Meijer <ralphm@ik.nu>
parents:
26
diff
changeset
|
107 |
ddc08757ec1d
Fire up several component.IServices that match the backend Services.
Ralph Meijer <ralphm@ik.nu>
parents:
26
diff
changeset
|
108 bsc = b.SubscriptionService() |
ddc08757ec1d
Fire up several component.IServices that match the backend Services.
Ralph Meijer <ralphm@ik.nu>
parents:
26
diff
changeset
|
109 bsc.setServiceParent(bs) |
ddc08757ec1d
Fire up several component.IServices that match the backend Services.
Ralph Meijer <ralphm@ik.nu>
parents:
26
diff
changeset
|
110 component.IService(bsc).setServiceParent(sm) |
1 | 111 |
32
ddc08757ec1d
Fire up several component.IServices that match the backend Services.
Ralph Meijer <ralphm@ik.nu>
parents:
26
diff
changeset
|
112 s = IdavollService() |
ddc08757ec1d
Fire up several component.IServices that match the backend Services.
Ralph Meijer <ralphm@ik.nu>
parents:
26
diff
changeset
|
113 s.setServiceParent(sm) |
1 | 114 |
32
ddc08757ec1d
Fire up several component.IServices that match the backend Services.
Ralph Meijer <ralphm@ik.nu>
parents:
26
diff
changeset
|
115 sm.setServiceParent(serviceCollection) |
1 | 116 |
32
ddc08757ec1d
Fire up several component.IServices that match the backend Services.
Ralph Meijer <ralphm@ik.nu>
parents:
26
diff
changeset
|
117 # other stuff |
ddc08757ec1d
Fire up several component.IServices that match the backend Services.
Ralph Meijer <ralphm@ik.nu>
parents:
26
diff
changeset
|
118 |
ddc08757ec1d
Fire up several component.IServices that match the backend Services.
Ralph Meijer <ralphm@ik.nu>
parents:
26
diff
changeset
|
119 return sm |