summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Makefile.in27
-rw-r--r--configure.ac18
-rw-r--r--mod_log_sql_logio.c134
3 files changed, 172 insertions, 7 deletions
diff --git a/Makefile.in b/Makefile.in
index d42c5d9..2865d5f 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -18,7 +18,7 @@ CFLAGS += -Wc,-Werror
18endif 18endif
19 19
20EXTRA_DIST = AUTHORS INSTALL TODO LICENSE CHANGELOG \ 20EXTRA_DIST = AUTHORS INSTALL TODO LICENSE CHANGELOG \
21 build-apache13.bat build-apache2.bat 21 build-apache13.bat build-apache2.bat \
22 22
23coreSOURCES = @PACKAGE_NAME@.c 23coreSOURCES = @PACKAGE_NAME@.c
24coreTARGET = @PACKAGE_NAME@@APXS_EXTENSION@ 24coreTARGET = @PACKAGE_NAME@@APXS_EXTENSION@
@@ -37,6 +37,16 @@ ifeq (@WANT_SSL_MOD@,1)
37TARGETS += $(sslTARGET) 37TARGETS += $(sslTARGET)
38endif 38endif
39 39
40logioSOURCES = @PACKAGE_NAME@_logio.c
41logioTARGET = @PACKAGE_NAME@_logio@APXS_EXTENSION@
42logioLDADD =
43logioCFLAGS =
44logioNAME = log_sql_logio
45
46ifeq (@WANT_LOGIO_MOD@,1)
47TARGETS += $(logioTARGET)
48endif
49
40mysqlSOURCES = @PACKAGE_NAME@_mysql.c 50mysqlSOURCES = @PACKAGE_NAME@_mysql.c
41mysqlTARGET = @PACKAGE_NAME@_mysql@APXS_EXTENSION@ 51mysqlTARGET = @PACKAGE_NAME@_mysql@APXS_EXTENSION@
42mysqlLDADD = @MYSQL_LDFLAGS@ @MYSQL_LIBS@ 52mysqlLDADD = @MYSQL_LDFLAGS@ @MYSQL_LIBS@
@@ -74,13 +84,13 @@ PROVIDERS_SUBDIRS = @subdirs@
74srcdir = @abs_srcdir@ 84srcdir = @abs_srcdir@
75builddir = @abs_builddir@ 85builddir = @abs_builddir@
76 86
77OBJ = $(coreSOURCES:.c=.o) $(sslSOURCES:.c=.o) $(mysqlSOURCES:.c=.o) \ 87OBJ = $(coreSOURCES:.c=.o) $(logioSOURCES:.c=.o) $(sslSOURCES:.c=.o) $(mysqlSOURCES:.c=.o) \
78 $(dbiSOURCES:.c=.o) $(pgsqlSOURCES:.c=.o) 88 $(dbiSOURCES:.c=.o) $(pgsqlSOURCES:.c=.o)
79 89
80LO = $(coreSOURCES:.c=.lo) $(sslSOURCES:.c=.lo) $(mysqlSOURCES:.c=.lo) \ 90LO = $(coreSOURCES:.c=.lo) $(logioSOURCES:.c=.lo) $(sslSOURCES:.c=.lo) $(mysqlSOURCES:.c=.lo) \
81 $(dbiSOURCES:.c=.lo) $(pgsqlSOURCES:.c=.lo) 91 $(dbiSOURCES:.c=.lo) $(pgsqlSOURCES:.c=.lo)
82 92
83SLO = $(coreSOURCES:.c=.slo) $(sslSOURCES:.c=.slo) $(mysqlSOURCES:.c=.slo) \ 93SLO = $(coreSOURCES:.c=.slo) $(logioSOURCES:.c=.slo) $(sslSOURCES:.c=.slo) $(mysqlSOURCES:.c=.slo) \
84 $(dbiSOURCES:.c=.slo) $(pgsqlSOURCES:.c=.slo) 94 $(dbiSOURCES:.c=.slo) $(pgsqlSOURCES:.c=.slo)
85 95
86STD_DIST = install-sh \ 96STD_DIST = install-sh \
@@ -94,7 +104,7 @@ STD_DIST = install-sh \
94 config.h.in 104 config.h.in
95 105
96DISTFILES = $(STD_DIST) $(EXTRA_DIST) $(coreSOURCES) $(HEADERS) \ 106DISTFILES = $(STD_DIST) $(EXTRA_DIST) $(coreSOURCES) $(HEADERS) \
97 $(sslSOURCES) $(mysqlSOURCES) $(pgsqlSOURCES) $(dbiSOURCES) 107 $(sslSOURCES) $(logioSOURCES) $(mysqlSOURCES) $(pgsqlSOURCES) $(dbiSOURCES)
98 108
99all: $(TARGETS) all-subdirs 109all: $(TARGETS) all-subdirs
100 110
@@ -120,6 +130,10 @@ $(coreTARGET): $(coreSOURCES) $(HEADERS)
120 @@APXS_BIN@ -c -o $(coreTARGET) $(coreCFLAGS) $(CFLAGS) \ 130 @@APXS_BIN@ -c -o $(coreTARGET) $(coreCFLAGS) $(CFLAGS) \
121 @DEFS@ @AP_DEFS@ $(coreLDADD) $(coreSOURCES) 131 @DEFS@ @AP_DEFS@ $(coreLDADD) $(coreSOURCES)
122 132
133$(logioTARGET): $(logioSOURCES) $(HEADERS)
134 @@APXS_BIN@ -c -o $(logioTARGET) $(logioCFLAGS) $(CFLAGS) \
135 @DEFS@ @AP_DEFS@ $(logioLDADD) $(logioSOURCES)
136
123$(sslTARGET): $(sslSOURCES) $(HEADERS) 137$(sslTARGET): $(sslSOURCES) $(HEADERS)
124 @@APXS_BIN@ -c -o $(sslTARGET) $(sslCFLAGS) $(CFLAGS) \ 138 @@APXS_BIN@ -c -o $(sslTARGET) $(sslCFLAGS) $(CFLAGS) \
125 @DEFS@ @AP_DEFS@ $(sslLDADD) $(sslSOURCES) 139 @DEFS@ @AP_DEFS@ $(sslLDADD) $(sslSOURCES)
@@ -150,6 +164,9 @@ install: $(TARGETS) install-subdirs
150 if test @WANT_SSL_MOD@ -eq 1; then \ 164 if test @WANT_SSL_MOD@ -eq 1; then \
151 @APXS_BIN@ -n $(sslNAME) -i $(sslTARGET); \ 165 @APXS_BIN@ -n $(sslNAME) -i $(sslTARGET); \
152 fi; \ 166 fi; \
167 if test @WANT_LOGIO_MOD@ -eq 1; then \
168 @APXS_BIN@ -n $(logioNAME) -i $(logioTARGET); \
169 fi; \
153 echo "*************************************************************************"; \ 170 echo "*************************************************************************"; \
154 echo "*** The mod_log_sql modules have been installed."; \ 171 echo "*** The mod_log_sql modules have been installed."; \
155 echo "*** Please edit your Apache configuration files and"; \ 172 echo "*** Please edit your Apache configuration files and"; \
diff --git a/configure.ac b/configure.ac
index b8a7318..ee2d474 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1,5 +1,5 @@
1dnl Required initializer 1dnl Required initializer
2AC_INIT(mod_log_sql, 1.100) 2AC_INIT(mod_log_sql, 1.101)
3OOO_CONFIG_NICE(config.nice) 3OOO_CONFIG_NICE(config.nice)
4AC_PREREQ(2.53) 4AC_PREREQ(2.53)
5AC_CONFIG_HEADERS(config.h) 5AC_CONFIG_HEADERS(config.h)
@@ -21,6 +21,13 @@ CHECK_APACHE($APACHE13_VERSION,$APACHE20_VERSION,
21 AC_MSG_ERROR([*** or Apache 2.0/2.1 version $APACHE20_VERSION or greater!]) 21 AC_MSG_ERROR([*** or Apache 2.0/2.1 version $APACHE20_VERSION or greater!])
22 ) 22 )
23 23
24if test $AP_VERSION = "2.0"; then
25 WANT_LOGIO_MOD=1
26else
27 WANT_LOGIO_MOD=0
28fi
29AC_SUBST(WANT_LOGIO_MOD)
30
24CHECK_MYSQL( 31CHECK_MYSQL(
25 WANT_MYSQL_MOD=1, 32 WANT_MYSQL_MOD=1,
26 AC_MSG_WARN([*** Mysql client libraries not found!]) 33 AC_MSG_WARN([*** Mysql client libraries not found!])
@@ -50,7 +57,7 @@ AC_SUBST(WANT_SSL_MOD)
50 57
51case "$target" in 58case "$target" in
52 *-*-solaris* | *-*-osf* ) 59 *-*-solaris* | *-*-osf* )
53 if test $AP_VERSION -eq 1.3; then 60 if test $AP_VERSION = "1.3"; then
54 RT_LIBS=-lrt 61 RT_LIBS=-lrt
55 fi 62 fi
56 ;; 63 ;;
@@ -81,6 +88,13 @@ else
81 AC_MSG_RESULT([SSL Support : no]) 88 AC_MSG_RESULT([SSL Support : no])
82 AC_MSG_RESULT([*** Make sure OpenSSL headers, and mod_ssl.h are installed.]) 89 AC_MSG_RESULT([*** Make sure OpenSSL headers, and mod_ssl.h are installed.])
83fi 90fi
91if test $WANT_LOGIO_MOD -eq 1; then
92 AC_MSG_RESULT([LogIO Module : yes])
93else
94 AC_MSG_RESULT([LogIO Module : no])
95 AC_MSG_RESULT([*** Logio does not work with Apache 1.3.])
96fi
97
84AC_MSG_RESULT([Enabled drivers :]) 98AC_MSG_RESULT([Enabled drivers :])
85if test $WANT_MYSQL_MOD -eq 1; then 99if test $WANT_MYSQL_MOD -eq 1; then
86 AC_MSG_RESULT([ MySQL Driver]) 100 AC_MSG_RESULT([ MySQL Driver])
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}