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