1
|
1 from twisted.protocols.jabber import component |
|
2 from twisted.application import service |
|
3 import backend |
|
4 import pubsub |
|
5 import xmpp_error |
|
6 |
|
7 import sys |
|
8 |
|
9 IQ_GET = '/iq[@type="get"]' |
|
10 IQ_SET = '/iq[@type="set"]' |
|
11 VERSION = IQ_GET + '/query[@xmlns="jabber:iq:version"]' |
|
12 |
|
13 class IdavollService(component.Service): |
|
14 |
|
15 def componentConnected(self, xmlstream): |
|
16 self.xmlstream = xmlstream |
|
17 xmlstream.addObserver(VERSION, self.onVersion, 1) |
|
18 xmlstream.addObserver(IQ_GET, self.iqFallback, -1) |
|
19 xmlstream.addObserver(IQ_SET, self.iqFallback, -1) |
|
20 |
|
21 def onVersion(self, iq): |
|
22 print "version?" |
|
23 iq.swapAttributeValues("to", "from") |
|
24 iq["type"] = "result" |
|
25 name = iq.addElement("name", None, 'Idavoll') |
|
26 version = iq.addElement("version", None, '0.1') |
|
27 self.send(iq) |
|
28 iq.handled = True |
|
29 |
|
30 def iqFallback(self, iq): |
|
31 if iq.handled == True: |
|
32 return |
|
33 |
|
34 self.send(xmpp_error.error_from_iq(iq, 'feature-not-implemented')) |
|
35 |
|
36 def makeService(config): |
|
37 serviceCollection = service.MultiService() |
|
38 |
|
39 pss = backend.MemoryBackendService() |
|
40 |
|
41 # set up Jabber Component |
|
42 c = component.buildServiceManager(config["jid"], config["secret"], |
|
43 ("tcp:%s:%s" % (config["rhost"], config["rport"]))) |
|
44 |
|
45 s = component.IService(pss) |
|
46 s.jid = config["jid"] |
|
47 s.setServiceParent(c) |
|
48 |
|
49 s = IdavollService() |
|
50 s.setServiceParent(c) |
|
51 |
|
52 c.setServiceParent(serviceCollection) |
|
53 |
|
54 # other stuff |
|
55 |
|
56 return c |