annotate idavoll/tap.py @ 213:a321f9300054

Actually log requests if verbose.
author Ralph Meijer <ralphm@ik.nu>
date Thu, 18 Jun 2009 10:27:11 +0000
parents bfc198af5d27
children f94c3eb38b75
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
211
bfc198af5d27 Release Idavoll 0.9.0.
Ralph Meijer <ralphm@ik.nu>
parents: 208
diff changeset
1 # Copyright (c) 2003-2009 Ralph Meijer
155
5191ba7c4df8 Work towards first release 0.5.0.
Ralph Meijer <ralphm@ik.nu>
parents: 97
diff changeset
2 # See LICENSE for details.
5191ba7c4df8 Work towards first release 0.5.0.
Ralph Meijer <ralphm@ik.nu>
parents: 97
diff changeset
3
167
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 163
diff changeset
4 from twisted.application import service
1
4cc41776b7d7 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
5 from twisted.python import usage
167
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 163
diff changeset
6 from twisted.words.protocols.jabber.jid import JID
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 163
diff changeset
7
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 163
diff changeset
8 from wokkel.component import Component
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 163
diff changeset
9 from wokkel.disco import DiscoHandler
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 163
diff changeset
10 from wokkel.generic import FallbackHandler, VersionHandler
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 163
diff changeset
11 from wokkel.iwokkel import IPubSubService
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 163
diff changeset
12
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 163
diff changeset
13 from idavoll.backend import BackendService
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 163
diff changeset
14
211
bfc198af5d27 Release Idavoll 0.9.0.
Ralph Meijer <ralphm@ik.nu>
parents: 208
diff changeset
15 __version__ = '0.9.0'
1
4cc41776b7d7 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
16
4cc41776b7d7 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
17 class Options(usage.Options):
156
6250905b72f6 Fix spacing errors. Do 0.5.0 release.
Ralph Meijer <ralphm@ik.nu>
parents: 155
diff changeset
18 optParameters = [
170
958e69630e52 Provide twistd parameters for connecting to a remote PostgreSQL database.
Ralph Meijer <ralphm@ik.nu>
parents: 169
diff changeset
19 ('jid', None, 'pubsub', 'JID this component will be available at'),
958e69630e52 Provide twistd parameters for connecting to a remote PostgreSQL database.
Ralph Meijer <ralphm@ik.nu>
parents: 169
diff changeset
20 ('secret', None, 'secret', 'Jabber server component secret'),
958e69630e52 Provide twistd parameters for connecting to a remote PostgreSQL database.
Ralph Meijer <ralphm@ik.nu>
parents: 169
diff changeset
21 ('rhost', None, '127.0.0.1', 'Jabber server host'),
958e69630e52 Provide twistd parameters for connecting to a remote PostgreSQL database.
Ralph Meijer <ralphm@ik.nu>
parents: 169
diff changeset
22 ('rport', None, '5347', 'Jabber server port'),
958e69630e52 Provide twistd parameters for connecting to a remote PostgreSQL database.
Ralph Meijer <ralphm@ik.nu>
parents: 169
diff changeset
23 ('backend', None, 'memory', 'Choice of storage backend'),
190
6e6c89eca9db Make sure optional PostgreSQL connect parameters are passed as None, require
Ralph Meijer <ralphm@ik.nu>
parents: 189
diff changeset
24 ('dbuser', None, None, 'Database user (pgsql backend)'),
170
958e69630e52 Provide twistd parameters for connecting to a remote PostgreSQL database.
Ralph Meijer <ralphm@ik.nu>
parents: 169
diff changeset
25 ('dbname', None, 'pubsub', 'Database name (pgsql backend)'),
190
6e6c89eca9db Make sure optional PostgreSQL connect parameters are passed as None, require
Ralph Meijer <ralphm@ik.nu>
parents: 189
diff changeset
26 ('dbpass', None, None, 'Database password (pgsql backend)'),
6e6c89eca9db Make sure optional PostgreSQL connect parameters are passed as None, require
Ralph Meijer <ralphm@ik.nu>
parents: 189
diff changeset
27 ('dbhost', None, None, 'Database host (pgsql backend)'),
6e6c89eca9db Make sure optional PostgreSQL connect parameters are passed as None, require
Ralph Meijer <ralphm@ik.nu>
parents: 189
diff changeset
28 ('dbport', None, None, 'Database port (pgsql backend)'),
156
6250905b72f6 Fix spacing errors. Do 0.5.0 release.
Ralph Meijer <ralphm@ik.nu>
parents: 155
diff changeset
29 ]
76
66fac7cd9edc Added -v (--verbose) flag to print out all traffic.
Ralph Meijer <ralphm@ik.nu>
parents: 42
diff changeset
30
156
6250905b72f6 Fix spacing errors. Do 0.5.0 release.
Ralph Meijer <ralphm@ik.nu>
parents: 155
diff changeset
31 optFlags = [
6250905b72f6 Fix spacing errors. Do 0.5.0 release.
Ralph Meijer <ralphm@ik.nu>
parents: 155
diff changeset
32 ('verbose', 'v', 'Show traffic'),
6250905b72f6 Fix spacing errors. Do 0.5.0 release.
Ralph Meijer <ralphm@ik.nu>
parents: 155
diff changeset
33 ('hide-nodes', None, 'Hide all nodes for disco')
6250905b72f6 Fix spacing errors. Do 0.5.0 release.
Ralph Meijer <ralphm@ik.nu>
parents: 155
diff changeset
34 ]
167
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 163
diff changeset
35
156
6250905b72f6 Fix spacing errors. Do 0.5.0 release.
Ralph Meijer <ralphm@ik.nu>
parents: 155
diff changeset
36 def postOptions(self):
6250905b72f6 Fix spacing errors. Do 0.5.0 release.
Ralph Meijer <ralphm@ik.nu>
parents: 155
diff changeset
37 if self['backend'] not in ['pgsql', 'memory']:
6250905b72f6 Fix spacing errors. Do 0.5.0 release.
Ralph Meijer <ralphm@ik.nu>
parents: 155
diff changeset
38 raise usage.UsageError, "Unknown backend!"
1
4cc41776b7d7 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
39
177
faf1c9bc2612 Add HTTP gateway in a separate plugin.
Ralph Meijer <ralphm@ik.nu>
parents: 176
diff changeset
40 self['jid'] = JID(self['jid'])
faf1c9bc2612 Add HTTP gateway in a separate plugin.
Ralph Meijer <ralphm@ik.nu>
parents: 176
diff changeset
41
1
4cc41776b7d7 Initial revision
Ralph Meijer <ralphm@ik.nu>
parents:
diff changeset
42 def makeService(config):
167
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 163
diff changeset
43 s = service.MultiService()
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 163
diff changeset
44
176
17fc5dd77158 Move around service setup.
Ralph Meijer <ralphm@ik.nu>
parents: 170
diff changeset
45 # Create backend service with storage
167
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 163
diff changeset
46
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 163
diff changeset
47 if config['backend'] == 'pgsql':
204
b4bf0a5ce50d Implement storage facilities for the HTTP gateway.
Ralph Meijer <ralphm@ik.nu>
parents: 193
diff changeset
48 from twisted.enterprise import adbapi
167
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 163
diff changeset
49 from idavoll.pgsql_storage import Storage
204
b4bf0a5ce50d Implement storage facilities for the HTTP gateway.
Ralph Meijer <ralphm@ik.nu>
parents: 193
diff changeset
50 dbpool = adbapi.ConnectionPool('pyPgSQL.PgSQL',
b4bf0a5ce50d Implement storage facilities for the HTTP gateway.
Ralph Meijer <ralphm@ik.nu>
parents: 193
diff changeset
51 user=config['dbuser'],
b4bf0a5ce50d Implement storage facilities for the HTTP gateway.
Ralph Meijer <ralphm@ik.nu>
parents: 193
diff changeset
52 password=config['dbuser'],
b4bf0a5ce50d Implement storage facilities for the HTTP gateway.
Ralph Meijer <ralphm@ik.nu>
parents: 193
diff changeset
53 database=config['dbname'],
b4bf0a5ce50d Implement storage facilities for the HTTP gateway.
Ralph Meijer <ralphm@ik.nu>
parents: 193
diff changeset
54 host=config['dbpass'],
b4bf0a5ce50d Implement storage facilities for the HTTP gateway.
Ralph Meijer <ralphm@ik.nu>
parents: 193
diff changeset
55 port=config['dbport'],
b4bf0a5ce50d Implement storage facilities for the HTTP gateway.
Ralph Meijer <ralphm@ik.nu>
parents: 193
diff changeset
56 cp_reconnect=True,
b4bf0a5ce50d Implement storage facilities for the HTTP gateway.
Ralph Meijer <ralphm@ik.nu>
parents: 193
diff changeset
57 client_encoding='utf-8',
b4bf0a5ce50d Implement storage facilities for the HTTP gateway.
Ralph Meijer <ralphm@ik.nu>
parents: 193
diff changeset
58 )
b4bf0a5ce50d Implement storage facilities for the HTTP gateway.
Ralph Meijer <ralphm@ik.nu>
parents: 193
diff changeset
59 st = Storage(dbpool)
167
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 163
diff changeset
60 elif config['backend'] == 'memory':
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 163
diff changeset
61 from idavoll.memory_storage import Storage
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 163
diff changeset
62 st = Storage()
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 163
diff changeset
63
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 163
diff changeset
64 bs = BackendService(st)
177
faf1c9bc2612 Add HTTP gateway in a separate plugin.
Ralph Meijer <ralphm@ik.nu>
parents: 176
diff changeset
65 bs.setName('backend')
167
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 163
diff changeset
66 bs.setServiceParent(s)
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 163
diff changeset
67
176
17fc5dd77158 Move around service setup.
Ralph Meijer <ralphm@ik.nu>
parents: 170
diff changeset
68 # Set up XMPP server-side component with publish-subscribe capabilities
17fc5dd77158 Move around service setup.
Ralph Meijer <ralphm@ik.nu>
parents: 170
diff changeset
69
17fc5dd77158 Move around service setup.
Ralph Meijer <ralphm@ik.nu>
parents: 170
diff changeset
70 cs = Component(config["rhost"], int(config["rport"]),
177
faf1c9bc2612 Add HTTP gateway in a separate plugin.
Ralph Meijer <ralphm@ik.nu>
parents: 176
diff changeset
71 config["jid"].full(), config["secret"])
faf1c9bc2612 Add HTTP gateway in a separate plugin.
Ralph Meijer <ralphm@ik.nu>
parents: 176
diff changeset
72 cs.setName('component')
176
17fc5dd77158 Move around service setup.
Ralph Meijer <ralphm@ik.nu>
parents: 170
diff changeset
73 cs.setServiceParent(s)
17fc5dd77158 Move around service setup.
Ralph Meijer <ralphm@ik.nu>
parents: 170
diff changeset
74
17fc5dd77158 Move around service setup.
Ralph Meijer <ralphm@ik.nu>
parents: 170
diff changeset
75 cs.factory.maxDelay = 900
17fc5dd77158 Move around service setup.
Ralph Meijer <ralphm@ik.nu>
parents: 170
diff changeset
76
17fc5dd77158 Move around service setup.
Ralph Meijer <ralphm@ik.nu>
parents: 170
diff changeset
77 if config["verbose"]:
17fc5dd77158 Move around service setup.
Ralph Meijer <ralphm@ik.nu>
parents: 170
diff changeset
78 cs.logTraffic = True
17fc5dd77158 Move around service setup.
Ralph Meijer <ralphm@ik.nu>
parents: 170
diff changeset
79
17fc5dd77158 Move around service setup.
Ralph Meijer <ralphm@ik.nu>
parents: 170
diff changeset
80 FallbackHandler().setHandlerParent(cs)
17fc5dd77158 Move around service setup.
Ralph Meijer <ralphm@ik.nu>
parents: 170
diff changeset
81 VersionHandler('Idavoll', __version__).setHandlerParent(cs)
17fc5dd77158 Move around service setup.
Ralph Meijer <ralphm@ik.nu>
parents: 170
diff changeset
82 DiscoHandler().setHandlerParent(cs)
17fc5dd77158 Move around service setup.
Ralph Meijer <ralphm@ik.nu>
parents: 170
diff changeset
83
167
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 163
diff changeset
84 ps = IPubSubService(bs)
169
96afb248df5e Fix typos in service creation. Make disco not respond when a resource is provided.
Ralph Meijer <ralphm@ik.nu>
parents: 167
diff changeset
85 ps.setHandlerParent(cs)
167
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 163
diff changeset
86 ps.hideNodes = config["hide-nodes"]
177
faf1c9bc2612 Add HTTP gateway in a separate plugin.
Ralph Meijer <ralphm@ik.nu>
parents: 176
diff changeset
87 ps.serviceJID = config["jid"]
167
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 163
diff changeset
88
ef22e4150caa Move protocol implementations (pubsub, disco, forms) to and depend on wokkel.
Ralph Meijer <ralphm@ik.nu>
parents: 163
diff changeset
89 return s