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