summaryrefslogtreecommitdiffstats
path: root/mod_log_sql_logio.c
diff options
context:
space:
mode:
authorGravatar Edward Rudd 2006-11-07 02:30:59 +0000
committerGravatar Edward Rudd 2006-11-07 02:30:59 +0000
commitae136219f628f697e5c31f0d51375e69e95d986f (patch)
tree80155d3d0f4d09cdf792a6f80266dff768677ec0 /mod_log_sql_logio.c
parent570b73fa8b3823280ffd740a8a9d71f1d69c7e08 (diff)
add logio support
Diffstat (limited to 'mod_log_sql_logio.c')
-rw-r--r--mod_log_sql_logio.c134
1 files changed, 134 insertions, 0 deletions
diff --git a/mod_log_sql_logio.c b/mod_log_sql_logio.c
new file mode 100644
index 0000000..5de477f
--- /dev/null
+++ b/mod_log_sql_logio.c
@@ -0,0 +1,134 @@
1/* $Id: mod_log_sql_ssl.c 140 2004-05-14 03:50:47Z urkle@drip.ws $ */
2
3#if defined(WITH_APACHE20)
4# include "apache20.h"
5#else
6# error Unsupported Apache version
7#endif
8
9#ifdef HAVE_CONFIG_H
10/* Undefine these to prevent conflicts between Apache ap_config_auto.h and
11 * my config.h. Only really needed for Apache < 2.0.48, but it can't hurt.
12 */
13#undef PACKAGE_BUGREPORT
14#undef PACKAGE_NAME
15#undef PACKAGE_STRING
16#undef PACKAGE_TARNAME
17#undef PACKAGE_VERSION
18
19#include "config.h"
20#endif
21
22#include "mod_log_sql.h"
23
24module AP_MODULE_DECLARE_DATA log_sql_logio_module;
25
26// From apachge 2.2's mod_logio.c to provide logging ACTUAL incoming and outgoing bytes
27static const char logio_filter_name[] = "LOG_SQL_INPUT_OUTPUT";
28
29typedef struct {
30 apr_off_t bytes_in;
31 apr_off_t bytes_out;
32} logio_config_t;
33
34static void ap_logio_add_bytes_out(conn_rec *c, apr_off_t bytes){
35 logio_config_t *cf = ap_get_module_config(c->conn_config, &log_sql_logio_module);
36
37 cf->bytes_out += bytes;
38}
39
40static const char *log_bytes_in(request_rec *r, char *a)
41{
42 logio_config_t *cf = ap_get_module_config(r->connection->conn_config,
43 &log_sql_logio_module);
44
45 return apr_off_t_toa(r->pool, cf->bytes_in);
46}
47
48static const char *log_bytes_out(request_rec *r, char *a)
49{
50 logio_config_t *cf = ap_get_module_config(r->connection->conn_config,
51 &log_sql_logio_module);
52
53 return apr_off_t_toa(r->pool, cf->bytes_out);
54}
55
56static int logio_transaction(request_rec *r)
57{
58 logio_config_t *cf = ap_get_module_config(r->connection->conn_config,
59 &log_sql_logio_module);
60
61 cf->bytes_in = cf->bytes_out = 0;
62
63 return OK;
64}
65
66static apr_status_t logio_in_filter(ap_filter_t *f,
67 apr_bucket_brigade *bb,
68 ap_input_mode_t mode,
69 apr_read_type_e block,
70 apr_off_t readbytes) {
71 apr_off_t length;
72 apr_status_t status;
73 logio_config_t *cf = ap_get_module_config(f->c->conn_config, &log_sql_logio_module);
74
75 status = ap_get_brigade(f->next, bb, mode, block, readbytes);
76
77 apr_brigade_length (bb, 0, &length);
78
79 if (length > 0)
80 cf->bytes_in += length;
81
82 return status;
83}
84
85static apr_status_t logio_out_filter(ap_filter_t *f,
86 apr_bucket_brigade *bb) {
87 apr_bucket *b = APR_BRIGADE_LAST(bb);
88
89 /* End of data, make sure we flush */
90 if (APR_BUCKET_IS_EOS(b)) {
91 APR_BUCKET_INSERT_BEFORE(b,
92 apr_bucket_flush_create(f->c->bucket_alloc));
93 }
94
95 return ap_pass_brigade(f->next, bb);
96}
97
98static int logio_pre_conn(conn_rec *c, void *csd) {
99 logio_config_t *cf = apr_pcalloc(c->pool, sizeof(*cf));
100
101 ap_set_module_config(c->conn_config, &log_sql_logio_module, cf);
102
103 ap_add_input_filter(logio_filter_name, NULL, NULL, c);
104 ap_add_output_filter(logio_filter_name, NULL, NULL, c);
105
106 return OK;
107}
108
109static int post_config(apr_pool_t *p, apr_pool_t *plog, apr_pool_t *ptemp, server_rec *s);
110static void register_hooks(apr_pool_t *p) {
111 static const char *pre[] = { "mod_log_sql.c", NULL };
112
113 ap_hook_pre_connection(logio_pre_conn, NULL, NULL, APR_HOOK_MIDDLE);
114 ap_hook_log_transaction(logio_transaction, pre, NULL, APR_HOOK_MIDDLE);
115 ap_hook_post_config(post_config, NULL, NULL, APR_HOOK_REALLY_FIRST);
116
117 ap_register_input_filter(logio_filter_name, logio_in_filter, NULL,
118 AP_FTYPE_NETWORK - 1);
119 ap_register_output_filter(logio_filter_name, logio_out_filter, NULL,
120 AP_FTYPE_NETWORK - 1);
121
122 APR_REGISTER_OPTIONAL_FN(ap_logio_add_bytes_out);
123}
124
125module AP_MODULE_DECLARE_DATA log_sql_logio_module = {
126 STANDARD20_MODULE_STUFF,
127 NULL, NULL, NULL, NULL, NULL, register_hooks
128};
129static int post_config(apr_pool_t *p, apr_pool_t *plog, apr_pool_t *ptemp, server_rec *s)
130{
131 log_sql_register_item(s,p,'i', log_bytes_in, "bytes_in", 0, 0);
132 log_sql_register_item(s,p,'o', log_bytes_out, "bytes_out", 0, 0);
133 return OK;
134}