From ae136219f628f697e5c31f0d51375e69e95d986f Mon Sep 17 00:00:00 2001 From: Edward Rudd Date: Tue, 7 Nov 2006 02:30:59 +0000 Subject: add logio support --- Makefile.in | 27 +++++++++-- configure.ac | 18 ++++++- mod_log_sql_logio.c | 134 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 172 insertions(+), 7 deletions(-) create mode 100644 mod_log_sql_logio.c 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 endif EXTRA_DIST = AUTHORS INSTALL TODO LICENSE CHANGELOG \ - build-apache13.bat build-apache2.bat + build-apache13.bat build-apache2.bat \ coreSOURCES = @PACKAGE_NAME@.c coreTARGET = @PACKAGE_NAME@@APXS_EXTENSION@ @@ -37,6 +37,16 @@ ifeq (@WANT_SSL_MOD@,1) TARGETS += $(sslTARGET) endif +logioSOURCES = @PACKAGE_NAME@_logio.c +logioTARGET = @PACKAGE_NAME@_logio@APXS_EXTENSION@ +logioLDADD = +logioCFLAGS = +logioNAME = log_sql_logio + +ifeq (@WANT_LOGIO_MOD@,1) +TARGETS += $(logioTARGET) +endif + mysqlSOURCES = @PACKAGE_NAME@_mysql.c mysqlTARGET = @PACKAGE_NAME@_mysql@APXS_EXTENSION@ mysqlLDADD = @MYSQL_LDFLAGS@ @MYSQL_LIBS@ @@ -74,13 +84,13 @@ PROVIDERS_SUBDIRS = @subdirs@ srcdir = @abs_srcdir@ builddir = @abs_builddir@ -OBJ = $(coreSOURCES:.c=.o) $(sslSOURCES:.c=.o) $(mysqlSOURCES:.c=.o) \ +OBJ = $(coreSOURCES:.c=.o) $(logioSOURCES:.c=.o) $(sslSOURCES:.c=.o) $(mysqlSOURCES:.c=.o) \ $(dbiSOURCES:.c=.o) $(pgsqlSOURCES:.c=.o) -LO = $(coreSOURCES:.c=.lo) $(sslSOURCES:.c=.lo) $(mysqlSOURCES:.c=.lo) \ +LO = $(coreSOURCES:.c=.lo) $(logioSOURCES:.c=.lo) $(sslSOURCES:.c=.lo) $(mysqlSOURCES:.c=.lo) \ $(dbiSOURCES:.c=.lo) $(pgsqlSOURCES:.c=.lo) -SLO = $(coreSOURCES:.c=.slo) $(sslSOURCES:.c=.slo) $(mysqlSOURCES:.c=.slo) \ +SLO = $(coreSOURCES:.c=.slo) $(logioSOURCES:.c=.slo) $(sslSOURCES:.c=.slo) $(mysqlSOURCES:.c=.slo) \ $(dbiSOURCES:.c=.slo) $(pgsqlSOURCES:.c=.slo) STD_DIST = install-sh \ @@ -94,7 +104,7 @@ STD_DIST = install-sh \ config.h.in DISTFILES = $(STD_DIST) $(EXTRA_DIST) $(coreSOURCES) $(HEADERS) \ - $(sslSOURCES) $(mysqlSOURCES) $(pgsqlSOURCES) $(dbiSOURCES) + $(sslSOURCES) $(logioSOURCES) $(mysqlSOURCES) $(pgsqlSOURCES) $(dbiSOURCES) all: $(TARGETS) all-subdirs @@ -120,6 +130,10 @@ $(coreTARGET): $(coreSOURCES) $(HEADERS) @@APXS_BIN@ -c -o $(coreTARGET) $(coreCFLAGS) $(CFLAGS) \ @DEFS@ @AP_DEFS@ $(coreLDADD) $(coreSOURCES) +$(logioTARGET): $(logioSOURCES) $(HEADERS) + @@APXS_BIN@ -c -o $(logioTARGET) $(logioCFLAGS) $(CFLAGS) \ + @DEFS@ @AP_DEFS@ $(logioLDADD) $(logioSOURCES) + $(sslTARGET): $(sslSOURCES) $(HEADERS) @@APXS_BIN@ -c -o $(sslTARGET) $(sslCFLAGS) $(CFLAGS) \ @DEFS@ @AP_DEFS@ $(sslLDADD) $(sslSOURCES) @@ -150,6 +164,9 @@ install: $(TARGETS) install-subdirs if test @WANT_SSL_MOD@ -eq 1; then \ @APXS_BIN@ -n $(sslNAME) -i $(sslTARGET); \ fi; \ + if test @WANT_LOGIO_MOD@ -eq 1; then \ + @APXS_BIN@ -n $(logioNAME) -i $(logioTARGET); \ + fi; \ echo "*************************************************************************"; \ echo "*** The mod_log_sql modules have been installed."; \ 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 @@ dnl Required initializer -AC_INIT(mod_log_sql, 1.100) +AC_INIT(mod_log_sql, 1.101) OOO_CONFIG_NICE(config.nice) AC_PREREQ(2.53) AC_CONFIG_HEADERS(config.h) @@ -21,6 +21,13 @@ CHECK_APACHE($APACHE13_VERSION,$APACHE20_VERSION, AC_MSG_ERROR([*** or Apache 2.0/2.1 version $APACHE20_VERSION or greater!]) ) +if test $AP_VERSION = "2.0"; then + WANT_LOGIO_MOD=1 +else + WANT_LOGIO_MOD=0 +fi +AC_SUBST(WANT_LOGIO_MOD) + CHECK_MYSQL( WANT_MYSQL_MOD=1, AC_MSG_WARN([*** Mysql client libraries not found!]) @@ -50,7 +57,7 @@ AC_SUBST(WANT_SSL_MOD) case "$target" in *-*-solaris* | *-*-osf* ) - if test $AP_VERSION -eq 1.3; then + if test $AP_VERSION = "1.3"; then RT_LIBS=-lrt fi ;; @@ -81,6 +88,13 @@ else AC_MSG_RESULT([SSL Support : no]) AC_MSG_RESULT([*** Make sure OpenSSL headers, and mod_ssl.h are installed.]) fi +if test $WANT_LOGIO_MOD -eq 1; then + AC_MSG_RESULT([LogIO Module : yes]) +else + AC_MSG_RESULT([LogIO Module : no]) + AC_MSG_RESULT([*** Logio does not work with Apache 1.3.]) +fi + AC_MSG_RESULT([Enabled drivers :]) if test $WANT_MYSQL_MOD -eq 1; then 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 @@ +/* $Id: mod_log_sql_ssl.c 140 2004-05-14 03:50:47Z urkle@drip.ws $ */ + +#if defined(WITH_APACHE20) +# include "apache20.h" +#else +# error Unsupported Apache version +#endif + +#ifdef HAVE_CONFIG_H +/* Undefine these to prevent conflicts between Apache ap_config_auto.h and + * my config.h. Only really needed for Apache < 2.0.48, but it can't hurt. + */ +#undef PACKAGE_BUGREPORT +#undef PACKAGE_NAME +#undef PACKAGE_STRING +#undef PACKAGE_TARNAME +#undef PACKAGE_VERSION + +#include "config.h" +#endif + +#include "mod_log_sql.h" + +module AP_MODULE_DECLARE_DATA log_sql_logio_module; + +// From apachge 2.2's mod_logio.c to provide logging ACTUAL incoming and outgoing bytes +static const char logio_filter_name[] = "LOG_SQL_INPUT_OUTPUT"; + +typedef struct { + apr_off_t bytes_in; + apr_off_t bytes_out; +} logio_config_t; + +static void ap_logio_add_bytes_out(conn_rec *c, apr_off_t bytes){ + logio_config_t *cf = ap_get_module_config(c->conn_config, &log_sql_logio_module); + + cf->bytes_out += bytes; +} + +static const char *log_bytes_in(request_rec *r, char *a) +{ + logio_config_t *cf = ap_get_module_config(r->connection->conn_config, + &log_sql_logio_module); + + return apr_off_t_toa(r->pool, cf->bytes_in); +} + +static const char *log_bytes_out(request_rec *r, char *a) +{ + logio_config_t *cf = ap_get_module_config(r->connection->conn_config, + &log_sql_logio_module); + + return apr_off_t_toa(r->pool, cf->bytes_out); +} + +static int logio_transaction(request_rec *r) +{ + logio_config_t *cf = ap_get_module_config(r->connection->conn_config, + &log_sql_logio_module); + + cf->bytes_in = cf->bytes_out = 0; + + return OK; +} + +static apr_status_t logio_in_filter(ap_filter_t *f, + apr_bucket_brigade *bb, + ap_input_mode_t mode, + apr_read_type_e block, + apr_off_t readbytes) { + apr_off_t length; + apr_status_t status; + logio_config_t *cf = ap_get_module_config(f->c->conn_config, &log_sql_logio_module); + + status = ap_get_brigade(f->next, bb, mode, block, readbytes); + + apr_brigade_length (bb, 0, &length); + + if (length > 0) + cf->bytes_in += length; + + return status; +} + +static apr_status_t logio_out_filter(ap_filter_t *f, + apr_bucket_brigade *bb) { + apr_bucket *b = APR_BRIGADE_LAST(bb); + + /* End of data, make sure we flush */ + if (APR_BUCKET_IS_EOS(b)) { + APR_BUCKET_INSERT_BEFORE(b, + apr_bucket_flush_create(f->c->bucket_alloc)); + } + + return ap_pass_brigade(f->next, bb); +} + +static int logio_pre_conn(conn_rec *c, void *csd) { + logio_config_t *cf = apr_pcalloc(c->pool, sizeof(*cf)); + + ap_set_module_config(c->conn_config, &log_sql_logio_module, cf); + + ap_add_input_filter(logio_filter_name, NULL, NULL, c); + ap_add_output_filter(logio_filter_name, NULL, NULL, c); + + return OK; +} + +static int post_config(apr_pool_t *p, apr_pool_t *plog, apr_pool_t *ptemp, server_rec *s); +static void register_hooks(apr_pool_t *p) { + static const char *pre[] = { "mod_log_sql.c", NULL }; + + ap_hook_pre_connection(logio_pre_conn, NULL, NULL, APR_HOOK_MIDDLE); + ap_hook_log_transaction(logio_transaction, pre, NULL, APR_HOOK_MIDDLE); + ap_hook_post_config(post_config, NULL, NULL, APR_HOOK_REALLY_FIRST); + + ap_register_input_filter(logio_filter_name, logio_in_filter, NULL, + AP_FTYPE_NETWORK - 1); + ap_register_output_filter(logio_filter_name, logio_out_filter, NULL, + AP_FTYPE_NETWORK - 1); + + APR_REGISTER_OPTIONAL_FN(ap_logio_add_bytes_out); +} + +module AP_MODULE_DECLARE_DATA log_sql_logio_module = { + STANDARD20_MODULE_STUFF, + NULL, NULL, NULL, NULL, NULL, register_hooks +}; +static int post_config(apr_pool_t *p, apr_pool_t *plog, apr_pool_t *ptemp, server_rec *s) +{ + log_sql_register_item(s,p,'i', log_bytes_in, "bytes_in", 0, 0); + log_sql_register_item(s,p,'o', log_bytes_out, "bytes_out", 0, 0); + return OK; +} -- cgit