annotate idavoll/idavoll.py @ 41:ea3d3544a52e

Rewrite using separated backend interfaces. The backend also uses a separate class for the actual storage.
author Ralph Meijer <ralphm@ik.nu>
date Sun, 31 Oct 2004 21:11:03 +0000
parents c51bca11699b
children 7d088c61e131
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
4cc41776b7d7 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
2 from twisted.application import service
8
688992a789e4 Add disco support
Ralph Meijer <ralphm@ik.nu>
parents: 1
diff changeset
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
c77fdb7ef161 Follow move of memory backend.
Ralph Meijer <ralphm@ik.nu>
parents: 17
diff changeset
5 import memory_backend
1
4cc41776b7d7 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
6 import pubsub
4cc41776b7d7 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
7 import xmpp_error
4cc41776b7d7 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
8
4cc41776b7d7 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
9 import sys
4cc41776b7d7 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
10
8
688992a789e4 Add disco support
Ralph Meijer <ralphm@ik.nu>
parents: 1
diff changeset
11 NS_DISCO = 'http://jabber.org/protocol/disco'
688992a789e4 Add disco support
Ralph Meijer <ralphm@ik.nu>
parents: 1
diff changeset
12 NS_DISCO_INFO = NS_DISCO + '#info'
688992a789e4 Add disco support
Ralph Meijer <ralphm@ik.nu>
parents: 1
diff changeset
13 NS_DISCO_ITEMS = NS_DISCO + '#items'
688992a789e4 Add disco support
Ralph Meijer <ralphm@ik.nu>
parents: 1
diff changeset
14 NS_VERSION = 'jabber:iq:version'
688992a789e4 Add disco support
Ralph Meijer <ralphm@ik.nu>
parents: 1
diff changeset
15
1
4cc41776b7d7 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
16 IQ_GET = '/iq[@type="get"]'
4cc41776b7d7 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
17 IQ_SET = '/iq[@type="set"]'
8
688992a789e4 Add disco support
Ralph Meijer <ralphm@ik.nu>
parents: 1
diff changeset
18 VERSION = IQ_GET + '/query[@xmlns="' + NS_VERSION + '"]'
688992a789e4 Add disco support
Ralph Meijer <ralphm@ik.nu>
parents: 1
diff changeset
19 DISCO_INFO = IQ_GET + '/query[@xmlns="' + NS_DISCO_INFO + '"]'
688992a789e4 Add disco support
Ralph Meijer <ralphm@ik.nu>
parents: 1
diff changeset
20 DISCO_ITEMS = IQ_GET + '/query[@xmlns="' + NS_DISCO_ITEMS + '"]'
1
4cc41776b7d7 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
21
4cc41776b7d7 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
22 class IdavollService(component.Service):
4cc41776b7d7 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
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
688992a789e4 Add disco support
Ralph Meijer <ralphm@ik.nu>
parents: 1
diff changeset
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
4cc41776b7d7 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
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
688992a789e4 Add disco support
Ralph Meijer <ralphm@ik.nu>
parents: 1
diff changeset
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
688992a789e4 Add disco support
Ralph Meijer <ralphm@ik.nu>
parents: 1
diff changeset
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
688992a789e4 Add disco support
Ralph Meijer <ralphm@ik.nu>
parents: 1
diff changeset
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
688992a789e4 Add disco support
Ralph Meijer <ralphm@ik.nu>
parents: 1
diff changeset
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
4cc41776b7d7 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
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
4cc41776b7d7 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
83
4cc41776b7d7 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
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
4cc41776b7d7 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
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
4cc41776b7d7 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
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
4cc41776b7d7 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
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
4cc41776b7d7 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
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
4cc41776b7d7 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
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
4cc41776b7d7 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
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