Mercurial > libervia-pubsub
comparison idavoll/tap.py @ 167:ef22e4150caa
Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Author: ralphm
Fixes: #4
author | Ralph Meijer <ralphm@ik.nu> |
---|---|
date | Wed, 03 Oct 2007 12:41:43 +0000 |
parents | 1701c0e2c707 |
children | 96afb248df5e |
comparison
equal
deleted
inserted
replaced
166:5abb017bd687 | 167:ef22e4150caa |
---|---|
1 # Copyright (c) 2003-2006 Ralph Meijer | 1 # Copyright (c) 2003-2007 Ralph Meijer |
2 # See LICENSE for details. | 2 # See LICENSE for details. |
3 | 3 |
4 from twisted.application import internet, service | 4 from twisted.application import service |
5 from twisted.internet import interfaces | |
6 from twisted.python import usage | 5 from twisted.python import usage |
7 import idavoll | 6 from twisted.words.protocols.jabber.jid import JID |
7 | |
8 from wokkel.component import Component | |
9 from wokkel.disco import DiscoHandler | |
10 from wokkel.generic import FallbackHandler, VersionHandler | |
11 from wokkel.iwokkel import IPubSubService | |
12 | |
13 from idavoll.backend import BackendService | |
14 | |
15 __version__ = '0.6.0' | |
8 | 16 |
9 class Options(usage.Options): | 17 class Options(usage.Options): |
10 optParameters = [ | 18 optParameters = [ |
11 ('jid', None, 'pubsub'), | 19 ('jid', None, 'pubsub'), |
12 ('secret', None, 'secret'), | 20 ('secret', None, 'secret'), |
20 | 28 |
21 optFlags = [ | 29 optFlags = [ |
22 ('verbose', 'v', 'Show traffic'), | 30 ('verbose', 'v', 'Show traffic'), |
23 ('hide-nodes', None, 'Hide all nodes for disco') | 31 ('hide-nodes', None, 'Hide all nodes for disco') |
24 ] | 32 ] |
25 | 33 |
26 def postOptions(self): | 34 def postOptions(self): |
27 if self['backend'] not in ['pgsql', 'memory']: | 35 if self['backend'] not in ['pgsql', 'memory']: |
28 raise usage.UsageError, "Unknown backend!" | 36 raise usage.UsageError, "Unknown backend!" |
29 | 37 |
30 def makeService(config): | 38 def makeService(config): |
31 return idavoll.makeService(config) | 39 s = service.MultiService() |
40 | |
41 cs = Component(config["rhost"], int(config["rport"]), | |
42 config["jid"], config["secret"]) | |
43 cs.setServiceParent(s) | |
44 | |
45 cs.factory.maxDelay = 900 | |
46 | |
47 if config["verbose"]: | |
48 cs.logTraffic = True | |
49 | |
50 FallbackHandler().setHanderParent(cs) | |
51 VersionHandler('Idavoll', __version__).setHanderParent(cs) | |
52 DiscoHandler().setHanderParent(cs) | |
53 | |
54 if config['backend'] == 'pgsql': | |
55 from idavoll.pgsql_storage import Storage | |
56 st = Storage(user=config['dbuser'], | |
57 database=config['dbname'], | |
58 password=config['dbpass']) | |
59 elif config['backend'] == 'memory': | |
60 from idavoll.memory_storage import Storage | |
61 st = Storage() | |
62 | |
63 bs = BackendService(st) | |
64 bs.setServiceParent(s) | |
65 | |
66 ps = IPubSubService(bs) | |
67 ps.setHanderParent(cs) | |
68 ps.hideNodes = config["hide-nodes"] | |
69 ps.serviceJID = JID(config["jid"]) | |
70 | |
71 return s |