annotate idavoll/idavoll.py @ 64:0072fc44fca8

Add note about incorrect text in section 8.1.7 of JEP-0060.
author Ralph Meijer <ralphm@ik.nu>
date Sat, 06 Nov 2004 21:05:12 +0000
parents 60e95c60252d
children cdf17c4d3bf9
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
1
4cc41776b7d7 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
5 import pubsub
4cc41776b7d7 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
6 import xmpp_error
4cc41776b7d7 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
7
4cc41776b7d7 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
8 import sys
4cc41776b7d7 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
9
8
688992a789e4 Add disco support
Ralph Meijer <ralphm@ik.nu>
parents: 1
diff changeset
10 NS_DISCO = 'http://jabber.org/protocol/disco'
688992a789e4 Add disco support
Ralph Meijer <ralphm@ik.nu>
parents: 1
diff changeset
11 NS_DISCO_INFO = NS_DISCO + '#info'
688992a789e4 Add disco support
Ralph Meijer <ralphm@ik.nu>
parents: 1
diff changeset
12 NS_DISCO_ITEMS = NS_DISCO + '#items'
688992a789e4 Add disco support
Ralph Meijer <ralphm@ik.nu>
parents: 1
diff changeset
13 NS_VERSION = 'jabber:iq:version'
688992a789e4 Add disco support
Ralph Meijer <ralphm@ik.nu>
parents: 1
diff changeset
14
1
4cc41776b7d7 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
15 IQ_GET = '/iq[@type="get"]'
4cc41776b7d7 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
16 IQ_SET = '/iq[@type="set"]'
8
688992a789e4 Add disco support
Ralph Meijer <ralphm@ik.nu>
parents: 1
diff changeset
17 VERSION = IQ_GET + '/query[@xmlns="' + NS_VERSION + '"]'
688992a789e4 Add disco support
Ralph Meijer <ralphm@ik.nu>
parents: 1
diff changeset
18 DISCO_INFO = IQ_GET + '/query[@xmlns="' + NS_DISCO_INFO + '"]'
688992a789e4 Add disco support
Ralph Meijer <ralphm@ik.nu>
parents: 1
diff changeset
19 DISCO_ITEMS = IQ_GET + '/query[@xmlns="' + NS_DISCO_ITEMS + '"]'
1
4cc41776b7d7 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
20
4cc41776b7d7 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
21 class IdavollService(component.Service):
4cc41776b7d7 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
22
32
ddc08757ec1d Fire up several component.IServices that match the backend Services.
Ralph Meijer <ralphm@ik.nu>
parents: 26
diff changeset
23 def componentConnected(self, xmlstream):
ddc08757ec1d Fire up several component.IServices that match the backend Services.
Ralph Meijer <ralphm@ik.nu>
parents: 26
diff changeset
24 self.xmlstream = xmlstream
ddc08757ec1d Fire up several component.IServices that match the backend Services.
Ralph Meijer <ralphm@ik.nu>
parents: 26
diff changeset
25 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
26 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
27 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
28 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
29 xmlstream.addObserver(IQ_SET, self.iqFallback, -1)
8
688992a789e4 Add disco support
Ralph Meijer <ralphm@ik.nu>
parents: 1
diff changeset
30
32
ddc08757ec1d Fire up several component.IServices that match the backend Services.
Ralph Meijer <ralphm@ik.nu>
parents: 26
diff changeset
31 def getFeatures(self, node):
57
445a61f872b6 Use NodeCreationService for pgsql backend, too.
Ralph Meijer <ralphm@ik.nu>
parents: 52
diff changeset
32 features = []
445a61f872b6 Use NodeCreationService for pgsql backend, too.
Ralph Meijer <ralphm@ik.nu>
parents: 52
diff changeset
33
32
ddc08757ec1d Fire up several component.IServices that match the backend Services.
Ralph Meijer <ralphm@ik.nu>
parents: 26
diff changeset
34 if not node:
57
445a61f872b6 Use NodeCreationService for pgsql backend, too.
Ralph Meijer <ralphm@ik.nu>
parents: 52
diff changeset
35 features.extend([NS_DISCO_ITEMS, NS_VERSION])
445a61f872b6 Use NodeCreationService for pgsql backend, too.
Ralph Meijer <ralphm@ik.nu>
parents: 52
diff changeset
36
445a61f872b6 Use NodeCreationService for pgsql backend, too.
Ralph Meijer <ralphm@ik.nu>
parents: 52
diff changeset
37 return features
32
ddc08757ec1d Fire up several component.IServices that match the backend Services.
Ralph Meijer <ralphm@ik.nu>
parents: 26
diff changeset
38
ddc08757ec1d Fire up several component.IServices that match the backend Services.
Ralph Meijer <ralphm@ik.nu>
parents: 26
diff changeset
39 def onVersion(self, iq):
ddc08757ec1d Fire up several component.IServices that match the backend Services.
Ralph Meijer <ralphm@ik.nu>
parents: 26
diff changeset
40 iq.swapAttributeValues("to", "from")
ddc08757ec1d Fire up several component.IServices that match the backend Services.
Ralph Meijer <ralphm@ik.nu>
parents: 26
diff changeset
41 iq["type"] = "result"
ddc08757ec1d Fire up several component.IServices that match the backend Services.
Ralph Meijer <ralphm@ik.nu>
parents: 26
diff changeset
42 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
43 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
44 self.send(iq)
ddc08757ec1d Fire up several component.IServices that match the backend Services.
Ralph Meijer <ralphm@ik.nu>
parents: 26
diff changeset
45 iq.handled = True
1
4cc41776b7d7 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
46
32
ddc08757ec1d Fire up several component.IServices that match the backend Services.
Ralph Meijer <ralphm@ik.nu>
parents: 26
diff changeset
47 def onDiscoInfo(self, iq):
ddc08757ec1d Fire up several component.IServices that match the backend Services.
Ralph Meijer <ralphm@ik.nu>
parents: 26
diff changeset
48 identities = []
ddc08757ec1d Fire up several component.IServices that match the backend Services.
Ralph Meijer <ralphm@ik.nu>
parents: 26
diff changeset
49 features = []
ddc08757ec1d Fire up several component.IServices that match the backend Services.
Ralph Meijer <ralphm@ik.nu>
parents: 26
diff changeset
50 node = iq.query.getAttribute("node")
8
688992a789e4 Add disco support
Ralph Meijer <ralphm@ik.nu>
parents: 1
diff changeset
51
32
ddc08757ec1d Fire up several component.IServices that match the backend Services.
Ralph Meijer <ralphm@ik.nu>
parents: 26
diff changeset
52 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
53 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
54 if hasattr(c, "getIdentities"):
ddc08757ec1d Fire up several component.IServices that match the backend Services.
Ralph Meijer <ralphm@ik.nu>
parents: 26
diff changeset
55 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
56 if hasattr(c, "getFeatures"):
ddc08757ec1d Fire up several component.IServices that match the backend Services.
Ralph Meijer <ralphm@ik.nu>
parents: 26
diff changeset
57 features.extend(c.getFeatures(node))
8
688992a789e4 Add disco support
Ralph Meijer <ralphm@ik.nu>
parents: 1
diff changeset
58
57
445a61f872b6 Use NodeCreationService for pgsql backend, too.
Ralph Meijer <ralphm@ik.nu>
parents: 52
diff changeset
59 if node and not features and not identities:
32
ddc08757ec1d Fire up several component.IServices that match the backend Services.
Ralph Meijer <ralphm@ik.nu>
parents: 26
diff changeset
60 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
61 else:
ddc08757ec1d Fire up several component.IServices that match the backend Services.
Ralph Meijer <ralphm@ik.nu>
parents: 26
diff changeset
62 iq.swapAttributeValues("to", "from")
ddc08757ec1d Fire up several component.IServices that match the backend Services.
Ralph Meijer <ralphm@ik.nu>
parents: 26
diff changeset
63 iq["type"] = "result"
ddc08757ec1d Fire up several component.IServices that match the backend Services.
Ralph Meijer <ralphm@ik.nu>
parents: 26
diff changeset
64 for identity in identities:
ddc08757ec1d Fire up several component.IServices that match the backend Services.
Ralph Meijer <ralphm@ik.nu>
parents: 26
diff changeset
65 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
66 i.attributes = identity
ddc08757ec1d Fire up several component.IServices that match the backend Services.
Ralph Meijer <ralphm@ik.nu>
parents: 26
diff changeset
67 print features
ddc08757ec1d Fire up several component.IServices that match the backend Services.
Ralph Meijer <ralphm@ik.nu>
parents: 26
diff changeset
68 for feature in features:
ddc08757ec1d Fire up several component.IServices that match the backend Services.
Ralph Meijer <ralphm@ik.nu>
parents: 26
diff changeset
69 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
70 f["var"] = feature
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 self.send(iq)
ddc08757ec1d Fire up several component.IServices that match the backend Services.
Ralph Meijer <ralphm@ik.nu>
parents: 26
diff changeset
73 iq.handled = True
8
688992a789e4 Add disco support
Ralph Meijer <ralphm@ik.nu>
parents: 1
diff changeset
74
32
ddc08757ec1d Fire up several component.IServices that match the backend Services.
Ralph Meijer <ralphm@ik.nu>
parents: 26
diff changeset
75 def onDiscoItems(self, iq):
ddc08757ec1d Fire up several component.IServices that match the backend Services.
Ralph Meijer <ralphm@ik.nu>
parents: 26
diff changeset
76 iq.swapAttributeValues("to", "from")
ddc08757ec1d Fire up several component.IServices that match the backend Services.
Ralph Meijer <ralphm@ik.nu>
parents: 26
diff changeset
77 iq["type"] = "result"
ddc08757ec1d Fire up several component.IServices that match the backend Services.
Ralph Meijer <ralphm@ik.nu>
parents: 26
diff changeset
78 iq.query.children = []
ddc08757ec1d Fire up several component.IServices that match the backend Services.
Ralph Meijer <ralphm@ik.nu>
parents: 26
diff changeset
79 self.send(iq)
ddc08757ec1d Fire up several component.IServices that match the backend Services.
Ralph Meijer <ralphm@ik.nu>
parents: 26
diff changeset
80
ddc08757ec1d Fire up several component.IServices that match the backend Services.
Ralph Meijer <ralphm@ik.nu>
parents: 26
diff changeset
81 def iqFallback(self, iq):
ddc08757ec1d Fire up several component.IServices that match the backend Services.
Ralph Meijer <ralphm@ik.nu>
parents: 26
diff changeset
82 if iq.handled == True:
ddc08757ec1d Fire up several component.IServices that match the backend Services.
Ralph Meijer <ralphm@ik.nu>
parents: 26
diff changeset
83 return
1
4cc41776b7d7 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
84
32
ddc08757ec1d Fire up several component.IServices that match the backend Services.
Ralph Meijer <ralphm@ik.nu>
parents: 26
diff changeset
85 self.send(xmpp_error.error_from_iq(iq, 'service-unavailable'))
1
4cc41776b7d7 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
86
4cc41776b7d7 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
87 def makeService(config):
32
ddc08757ec1d Fire up several component.IServices that match the backend Services.
Ralph Meijer <ralphm@ik.nu>
parents: 26
diff changeset
88 serviceCollection = service.MultiService()
1
4cc41776b7d7 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
89
32
ddc08757ec1d Fire up several component.IServices that match the backend Services.
Ralph Meijer <ralphm@ik.nu>
parents: 26
diff changeset
90 # set up Jabber Component
ddc08757ec1d Fire up several component.IServices that match the backend Services.
Ralph Meijer <ralphm@ik.nu>
parents: 26
diff changeset
91 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
92 ("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
93
42
7d088c61e131 Make choice of backend an option to mktap. This includes the database
Ralph Meijer <ralphm@ik.nu>
parents: 35
diff changeset
94 if config['backend'] == 'pgsql':
7d088c61e131 Make choice of backend an option to mktap. This includes the database
Ralph Meijer <ralphm@ik.nu>
parents: 35
diff changeset
95 import pgsql_backend as b
7d088c61e131 Make choice of backend an option to mktap. This includes the database
Ralph Meijer <ralphm@ik.nu>
parents: 35
diff changeset
96 st = b.Storage(user=config['dbuser'], database=config['dbname'])
7d088c61e131 Make choice of backend an option to mktap. This includes the database
Ralph Meijer <ralphm@ik.nu>
parents: 35
diff changeset
97 elif config['backend'] == 'memory':
7d088c61e131 Make choice of backend an option to mktap. This includes the database
Ralph Meijer <ralphm@ik.nu>
parents: 35
diff changeset
98 import memory_backend as b
43
9685b7e291ef Moved common stuff out of pgsql_backend.py to backend.py.
Ralph Meijer <ralphm@ik.nu>
parents: 42
diff changeset
99 st = b.Storage()
42
7d088c61e131 Make choice of backend an option to mktap. This includes the database
Ralph Meijer <ralphm@ik.nu>
parents: 35
diff changeset
100
43
9685b7e291ef Moved common stuff out of pgsql_backend.py to backend.py.
Ralph Meijer <ralphm@ik.nu>
parents: 42
diff changeset
101 bs = b.BackendService(st)
1
4cc41776b7d7 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
102
32
ddc08757ec1d Fire up several component.IServices that match the backend Services.
Ralph Meijer <ralphm@ik.nu>
parents: 26
diff changeset
103 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
104
ddc08757ec1d Fire up several component.IServices that match the backend Services.
Ralph Meijer <ralphm@ik.nu>
parents: 26
diff changeset
105 bsc = b.PublishService()
ddc08757ec1d Fire up several component.IServices that match the backend Services.
Ralph Meijer <ralphm@ik.nu>
parents: 26
diff changeset
106 bsc.setServiceParent(bs)
ddc08757ec1d Fire up several component.IServices that match the backend Services.
Ralph Meijer <ralphm@ik.nu>
parents: 26
diff changeset
107 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
108
ddc08757ec1d Fire up several component.IServices that match the backend Services.
Ralph Meijer <ralphm@ik.nu>
parents: 26
diff changeset
109 bsc = b.NotificationService()
ddc08757ec1d Fire up several component.IServices that match the backend Services.
Ralph Meijer <ralphm@ik.nu>
parents: 26
diff changeset
110 bsc.setServiceParent(bs)
ddc08757ec1d Fire up several component.IServices that match the backend Services.
Ralph Meijer <ralphm@ik.nu>
parents: 26
diff changeset
111 component.IService(bsc).setServiceParent(sm)
1
4cc41776b7d7 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
112
52
0947b46c0968 Use ISubscriptionService support of PostgreSQL backend.
Ralph Meijer <ralphm@ik.nu>
parents: 43
diff changeset
113 bsc = b.SubscriptionService()
0947b46c0968 Use ISubscriptionService support of PostgreSQL backend.
Ralph Meijer <ralphm@ik.nu>
parents: 43
diff changeset
114 bsc.setServiceParent(bs)
0947b46c0968 Use ISubscriptionService support of PostgreSQL backend.
Ralph Meijer <ralphm@ik.nu>
parents: 43
diff changeset
115 component.IService(bsc).setServiceParent(sm)
0947b46c0968 Use ISubscriptionService support of PostgreSQL backend.
Ralph Meijer <ralphm@ik.nu>
parents: 43
diff changeset
116
57
445a61f872b6 Use NodeCreationService for pgsql backend, too.
Ralph Meijer <ralphm@ik.nu>
parents: 52
diff changeset
117 bsc = b.NodeCreationService()
445a61f872b6 Use NodeCreationService for pgsql backend, too.
Ralph Meijer <ralphm@ik.nu>
parents: 52
diff changeset
118 bsc.setServiceParent(bs)
445a61f872b6 Use NodeCreationService for pgsql backend, too.
Ralph Meijer <ralphm@ik.nu>
parents: 52
diff changeset
119 component.IService(bsc).setServiceParent(sm)
32
ddc08757ec1d Fire up several component.IServices that match the backend Services.
Ralph Meijer <ralphm@ik.nu>
parents: 26
diff changeset
120
63
60e95c60252d Setup AffiliationsService and matching protocol adapter for the pgsql
Ralph Meijer <ralphm@ik.nu>
parents: 57
diff changeset
121 if config['backend'] == 'pgsql':
60e95c60252d Setup AffiliationsService and matching protocol adapter for the pgsql
Ralph Meijer <ralphm@ik.nu>
parents: 57
diff changeset
122 bsc = b.AffiliationsService()
60e95c60252d Setup AffiliationsService and matching protocol adapter for the pgsql
Ralph Meijer <ralphm@ik.nu>
parents: 57
diff changeset
123 bsc.setServiceParent(bs)
60e95c60252d Setup AffiliationsService and matching protocol adapter for the pgsql
Ralph Meijer <ralphm@ik.nu>
parents: 57
diff changeset
124 component.IService(bsc).setServiceParent(sm)
60e95c60252d Setup AffiliationsService and matching protocol adapter for the pgsql
Ralph Meijer <ralphm@ik.nu>
parents: 57
diff changeset
125
32
ddc08757ec1d Fire up several component.IServices that match the backend Services.
Ralph Meijer <ralphm@ik.nu>
parents: 26
diff changeset
126 s = IdavollService()
ddc08757ec1d Fire up several component.IServices that match the backend Services.
Ralph Meijer <ralphm@ik.nu>
parents: 26
diff changeset
127 s.setServiceParent(sm)
1
4cc41776b7d7 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
128
32
ddc08757ec1d Fire up several component.IServices that match the backend Services.
Ralph Meijer <ralphm@ik.nu>
parents: 26
diff changeset
129 sm.setServiceParent(serviceCollection)
1
4cc41776b7d7 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
130
32
ddc08757ec1d Fire up several component.IServices that match the backend Services.
Ralph Meijer <ralphm@ik.nu>
parents: 26
diff changeset
131 # other stuff
ddc08757ec1d Fire up several component.IServices that match the backend Services.
Ralph Meijer <ralphm@ik.nu>
parents: 26
diff changeset
132
ddc08757ec1d Fire up several component.IServices that match the backend Services.
Ralph Meijer <ralphm@ik.nu>
parents: 26
diff changeset
133 return sm