From 40f0c8fe04858acd724d6221dbf8a357259e5d6b Mon Sep 17 00:00:00 2001 From: Edward Rudd Date: Tue, 20 Jan 2004 16:27:35 +0000 Subject: split out version specific code code compiles under apache 1.3 and 2.0 updated apache m4 script to detect both verions (two minumums) defaulted install to not activate module in configuration file (use make activate) --- CHANGELOG | 16 ++- Makefile.in | 35 ++++--- apache13.h | 61 +++++++++++ apache20.h | 31 ++++++ configure.ac | 30 ++++-- functions13.h | 38 +++++++ functions20.h | 92 ++++++++++++++++ m4/apache.m4 | 166 +++++++++++++++++------------ m4/mod_ssl.m4 | 2 +- mod_log_sql.c | 331 +++++++++++++++++++++++++--------------------------------- 10 files changed, 523 insertions(+), 279 deletions(-) create mode 100644 apache13.h create mode 100644 apache20.h create mode 100644 functions13.h create mode 100644 functions20.h diff --git a/CHANGELOG b/CHANGELOG index 9660209..ffb512a 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,4 +1,4 @@ -$Id: CHANGELOG,v 1.5 2004/01/06 00:32:46 urkle Exp $ +$Id: CHANGELOG,v 1.6 2004/01/20 16:27:34 urkle Exp $ TODO: * Port connection portion to other DBMS? Genericize the module? Start with @@ -8,17 +8,27 @@ TODO: * LogSQLRotateLogs directive with daily/monthly/weekly/etc. * new format char: IP as bigint? ( not w/ ipV6 ) * socket-based middleman daemon with configurable conns, or connect/disconnect. + DBI connection pool when I switch to DBI. * ignore by cookie -* tools to import logs into SQL +* tools to import logs into SQL (waiting on permission from author) * Directive to yes/no create ancillary tables (or just access table) * break module into separate code files separate DB implimentation into sub-modules via provider mechanism separate module for SSL support + apache version specific code already split into separate files. * add document building to Makefile.in -* backport patch for apache 1.3 * investigate thread safety issues (libmysqlclient_r) CHANGES: +1.93: 2004-01-20 +* Compiles for apache 1.3 AND 2.0 +* split apache version specific functions to seperate header files +* split apache version specific includes to seperate header files +* added wrapper defines for apache 1.3 +* updated configure m4 scripts to detect both apache versions at the same time + and assign defines as to which version was found. +* made install default to not activate module in configuration files. + 1.92: 2004-01-05 * fixed compilation issue with mysql 4.x where mysql_error returns const char * * Have SSL support compiling (though not really tested) diff --git a/Makefile.in b/Makefile.in index 7a77d6d..27ba01f 100644 --- a/Makefile.in +++ b/Makefile.in @@ -15,7 +15,7 @@ LDADD = @MYSQL_LDFLAGS@ @MYSQL_LIBS@ EXTRA_DIST = INSTALL LICENSE CHANGELOG make_combined_log.pl -TARGET = @PACKAGE_NAME@.la +TARGET = @APACHE_OUTPUT_NAME@ #Don't modify anything below here @@ -44,7 +44,7 @@ DISTFILES = $(STD_DIST) $(EXTRA_DIST) $(SOURCES) $(HEADERS) all: $(TARGET) all-subdirs -all-subdirs install-subdirs update-subdirs clean-subdirs distclean-subdirs: +all-subdirs install-subdirs activate-subdirs clean-subdirs distclean-subdirs: @otarget=`echo $@|sed s/-subdirs//`; \ list=' $(PROVIDERS_SUBDIRS) $(SUBDIRS)'; \ for i in $$list; do \ @@ -57,28 +57,30 @@ all-subdirs install-subdirs update-subdirs clean-subdirs distclean-subdirs: fi; \ (cd $$i && $(MAKE) $$target) || exit 1; \ fi; \ - done; \ + done; $(TARGET): - @APXS_BIN@ -c -o @PACKAGE_NAME@.la $(INCLUDES) @MOD_SSL_CFLAGS@ $(CFLAGS) $(LDADD) @DEFS@ $(SOURCES) + @@APXS_BIN@ -c -o $(TARGET) $(INCLUDES) @MOD_SSL_CFLAGS@ $(CFLAGS) \ + $(LDADD) @DEFS@ @APACHE_DEFS@ $(SOURCES) include: rm -rf include ln -s @APACHE_INCDIR@ include install: install-subdirs - @APXS_BIN@ -i -a $(TARGET) + @@APXS_BIN@ -i $(TARGET) -update: update-subdirs - @APXS_BIN@ -i $(TARGET) +activate: activate-subdirs + @@APXS_BIN@ -i -a $(TARGET) clean: clean-subdirs $(RM) $(OBJ) $(SLO) $(LO) $(TARGET) .deps + $(RM) -r .libs distclean: clean distclean-subdirs $(RM) config.status config.log config.h config.h.in \ configure stamp-h stamp-h.in Makefile aclocal.m4 - $(RM) -r autom4te-2.53.cache .libs + $(RM) -r autom4te-2.53.cache DESTDIR = @PACKAGE_NAME@-@PACKAGE_VERSION@ DESTTGZ = $(DESTDIR).tar.gz @@ -97,27 +99,28 @@ dist: echo $(NEWDESTDIR); \ (cd $$i && $(MAKE) DESTDIR=$(builddir)/$(DESTDIR)/$$i $$target) || exit 1; \ fi; \ - done; + done; \ if test "$$made_local" != "yes"; then \ $(MAKE) "local-dist" || exit 1; \ - fi - tar -zcf $(DESTTGZ) $(DESTDIR) - rm -rf $(DESTDIR) + fi; \ + tar -zcf $(DESTTGZ) $(DESTDIR); \ + rm -rf $(DESTDIR); \ local-dist: $(DISTFILES) - mkdir -p $(DESTDIR) - cp -dp --parents $(DISTFILES) $(DESTDIR) + @mkdir -p $(DESTDIR); \ + cp -dp --parents $(DISTFILES) $(DESTDIR); $(builddir)/.deps: depend depend: $(SOURCES) $(HEADERS) if test -n "`ls $(srcdir)/*.c 2> /dev/null`"; then \ - $(CC) -MM -I@APACHE_INCDIR@ @MOD_SSL_CFLAGS@ $(INCLUDES) -DHAVE_CONFIG_H $(srcdir)/*.c > $(builddir)/.deps || true; \ + $(CC) -MM -I@APACHE_INCDIR@ @MOD_SSL_CFLAGS@ $(INCLUDES) @DEFS@ \ + @APACHE_DEFS@ $(srcdir)/*.c > $(builddir)/.deps || true; \ fi include $(builddir)/.deps -.PHONY: include all-subdirs update-subdirs install-subdirs \ +.PHONY: include all-subdirs activate-subdirs install-subdirs \ clean-subdirs distclean-subdirs dist # Regenerate makefiles diff --git a/apache13.h b/apache13.h new file mode 100644 index 0000000..3b37986 --- /dev/null +++ b/apache13.h @@ -0,0 +1,61 @@ +#ifndef APACHE13_H +#define APACHE13_H + +#include "httpd.h" +#include "http_config.h" +#include "http_log.h" +#include "http_core.h" + +/* Defines */ +#define AP_MODULE_DECLARE_DATA +#define APR_OFF_T_FMT "ld" +#define APR_PID_T_FMT "d" +#define APR_SUCCESS 0 +#define APR_OFFSETOF XtOffsetOf + +/*AP_INIT_TAKE1("LogSQLTransferLogTable", set_server_nmv_string_slot, + (void *)APR_OFFSETOF(logsql_state, transfer_table_name), RSRC_CONF, + "The database table that holds the transfer log") + +{"LogSQLTransferLogTable", set_log_sql_transfer_table, NULL, RSRC_CONF, TAKE1, + "The database table that holds the transfer log"}*/ + +/** method of declaring a directive which takes 1 argument */ +# define AP_INIT_TAKE1(directive, func, mconfig, where, help) \ + { directive, func, mconfig, where, TAKE1, help } +/** method of declaring a directive which takes multiple arguments */ +# define AP_INIT_ITERATE(directive, func, mconfig, where, help) \ + { directive, func, mconfig, where, ITERATE, help } +/** method of declaring a directive which takes 3 arguments */ +# define AP_INIT_TAKE3(directive, func, mconfig, where, help) \ + { directive, func, mconfig, where, TAKE3, help } +/** method of declaring a directive which takes a flag (on/off) as an argument */ +# define AP_INIT_FLAG(directive, func, mconfig, where, help) \ + { directive, func, mconfig, where, FLAG, help } + +/* Types */ +#define apr_pool_t pool +#define apr_array_header_t array_header + +/* Functions */ +#define ap_get_remote_host(a,b,c,d) ap_get_remote_host(a,b,c) + +#define apr_palloc ap_palloc +#define apr_pcalloc ap_pcalloc +#define apr_pstrdup ap_pstrdup +#define apr_pstrcat ap_pstrcat +#define apr_psprintf ap_psprintf +#define apr_snprintf ap_snprintf + +#define apr_table_get ap_table_get + +#define apr_array_push ap_push_array +#define apr_array_make ap_make_array +#define apr_array_cat ap_array_cat +#define apr_is_empty_array(t) (((t) == NULL)||((t)->nelts == 0)) + +#define apr_tolower ap_tolower + +#define log_error ap_log_error + +#endif /* APACHE13_H */ diff --git a/apache20.h b/apache20.h new file mode 100644 index 0000000..fd111d3 --- /dev/null +++ b/apache20.h @@ -0,0 +1,31 @@ +#ifndef APACHE20_H +#define APACHE20_H + +#include "apr_strings.h" +#include "apr_lib.h" +#include "apr_hash.h" +#include "apr_optional.h" +#define APR_WANT_STRFUNC +#include "apr_want.h" +#include "apr_tables.h" + +#include "ap_config.h" + +#include "httpd.h" +#include "http_config.h" +#include "http_core.h" +#include "http_log.h" +#include "http_protocol.h" + +#include "util_time.h" + +static void log_error(char *file, int line, int level, const server_rec *s, const char *fmt, ...) __attribute__ ((format (printf, 5,6))); +static inline void log_error(char *file, int line, int level, const server_rec *s, const char *fmt, ...) +{ + va_list args; + va_start(args, fmt); + ap_log_error(file,line,level,0,s,fmt,args); + va_end(args); +} + +#endif /* APACHE20_H */ diff --git a/configure.ac b/configure.ac index ed8e25d..63b71db 100644 --- a/configure.ac +++ b/configure.ac @@ -8,11 +8,15 @@ AC_CONFIG_SRCDIR(mod_log_sql.c) dnl Add a test for a compiler. AC_PROG_CC -APACHE_VERSION=2.0.44 -CHECK_PATH_APACHE($APACHE_VERSION, - :, - AC_MSG_ERROR([*** Apache version $APACHE_VERSION not found!]) - ) +APACHE20_VERSION=2.0.44 +APACHE13_VERSION=1.3.20 +CHECK_PATH_APACHE($APACHE13_VERSION,$APACHE20_VERSION, + :, + :, + AC_MSG_ERROR([*** The correct version Apache was not found!]) + AC_MSG_ERROR([*** You need either Apache 1.3 version $APACHE13_VERSION or greater]) + AC_MSG_ERROR([*** or Apache 2.0/2.1 version $APACHE20_VERSION or greater!]) + ) CHECK_PATH_MYSQL(:, AC_MSG_ERROR([*** Mysql client libraries not found!]) @@ -20,10 +24,8 @@ CHECK_PATH_MYSQL(:, CHECK_PATH_MOD_SSL( AC_DEFINE(WANT_SSL_LOGGING,,[Define if we want to compile in SSL support.]) - AC_MSG_WARN([*** Compilng with SSL support!]), - AC_MSG_WARN([*** Compiling without SSL support!]) - AC_MSG_WARN([*** enable with --enable-ssl to enable]) - AC_MSG_WARN([*** and --with-ssl-inc with the the directory for SSL headers]) + conf_SSL=1, + conf_SSL=0 ) AC_CHECK_HEADERS(limits.h) @@ -33,3 +35,13 @@ AC_CONFIG_FILES([stamp-h], [echo timestamp > stamp-h]) dnl Write config.status and the Makefile AC_OUTPUT(Makefile Documentation/Makefile) + +AC_MSG_RESULT([------------------------------------]) +AC_MSG_RESULT([Apache version : $APACHE_VERSION]) +if test $conf_SSL -eq 1; then + AC_MSG_RESULT([SSL Support : yes]) +else + AC_MSG_RESULT([SSL Support : no]) + AC_MSG_RESULT([*** Use --enable-ssl to enable SSL support]) + AC_MSG_RESULT([*** and --with-ssl-inc for the directory for SSL headers]) +fi diff --git a/functions13.h b/functions13.h new file mode 100644 index 0000000..bff37f2 --- /dev/null +++ b/functions13.h @@ -0,0 +1,38 @@ +static const char *extract_request_time(request_rec *r, char *a) +{ + int timz; + struct tm *t; + char tstr[MAX_STRING_LEN]; + + t = ap_get_gmtoff(&timz); + + if (a && *a) { /* Custom format */ + strftime(tstr, MAX_STRING_LEN, a, t); + } else { /* CLF format */ + char sign = (timz < 0 ? '-' : '+'); + + if (timz < 0) { + timz = -timz; + } + strftime(tstr, MAX_STRING_LEN, "[%d/%b/%Y:%H:%M:%S ", t); + ap_snprintf(tstr + strlen(tstr), sizeof(tstr) - strlen(tstr), "%c%.2d%.2d]", sign, timz / 60, timz % 60); + } + + return ap_pstrdup(r->pool, tstr); +} + +static const char *extract_request_duration(request_rec *r, char *a) +{ + char duration[22]; /* Long enough for 2^64 */ + + ap_snprintf(duration, sizeof(duration), "%ld", (long) time(NULL) - r->request_time); + return ap_pstrdup(r->pool, duration); +} + +static const char *extract_request_timestamp(request_rec *r, char *a) +{ + char tstr[32]; + + ap_snprintf(tstr, 32, "%ld", (long) time(NULL)); + return ap_pstrdup(r->pool, tstr); +} diff --git a/functions20.h b/functions20.h new file mode 100644 index 0000000..9ff3a63 --- /dev/null +++ b/functions20.h @@ -0,0 +1,92 @@ +/* functions */ +static const char *extract_request_time_custom(request_rec *r, char *a, + apr_time_exp_t *xt) +{ + apr_size_t retcode; + char tstr[MAX_STRING_LEN]; + apr_strftime(tstr, &retcode, sizeof(tstr), a, xt); + return apr_pstrdup(r->pool, tstr); +} + +#define DEFAULT_REQUEST_TIME_SIZE 32 +typedef struct { + unsigned t; + char timestr[DEFAULT_REQUEST_TIME_SIZE]; + unsigned t_validate; +} cached_request_time; + +#define TIME_CACHE_SIZE 4 +#define TIME_CACHE_MASK 3 +static cached_request_time request_time_cache[TIME_CACHE_SIZE]; + +static const char *extract_request_time(request_rec *r, char *a) +{ + apr_time_exp_t xt; + + /* Please read comments in mod_log_config.h for more info about + * the I_INSIST....COMPLIANCE define + */ + if (a && *a) { /* Custom format */ +#ifdef I_INSIST_ON_EXTRA_CYCLES_FOR_CLF_COMPLIANCE + ap_explode_recent_localtime(&xt, apr_time_now()); +#else + ap_explode_recent_localtime(&xt, r->request_time); +#endif + return extract_request_time_custom(r, a, &xt); + } else { /* CLF format */ + /* This code uses the same technique as ap_explode_recent_localtime(): + * optimistic caching with logic to detect and correct race conditions. + * See the comments in server/util_time.c for more information. + */ + cached_request_time* cached_time = apr_palloc(r->pool, + sizeof(*cached_time)); +#ifdef I_INSIST_ON_EXTRA_CYCLES_FOR_CLF_COMPLIANCE + apr_time_t request_time = apr_time_now(); +#else + apr_time_t request_time = r->request_time; +#endif + unsigned t_seconds = (unsigned)apr_time_sec(request_time); + unsigned i = t_seconds & TIME_CACHE_MASK; + memcpy(cached_time, &(request_time_cache[i]), sizeof(*cached_time)); + if ((t_seconds != cached_time->t) || + (t_seconds != cached_time->t_validate)) { + + /* Invalid or old snapshot, so compute the proper time string + * and store it in the cache + */ + char sign; + int timz; + + ap_explode_recent_localtime(&xt, r->request_time); + timz = xt.tm_gmtoff; + if (timz < 0) { + timz = -timz; + sign = '-'; + } + else { + sign = '+'; + } + cached_time->t = t_seconds; + apr_snprintf(cached_time->timestr, DEFAULT_REQUEST_TIME_SIZE, + "[%02d/%s/%d:%02d:%02d:%02d %c%.2d%.2d]", + xt.tm_mday, apr_month_snames[xt.tm_mon], + xt.tm_year+1900, xt.tm_hour, xt.tm_min, xt.tm_sec, + sign, timz / (60*60), timz % (60*60)); + cached_time->t_validate = t_seconds; + memcpy(&(request_time_cache[i]), cached_time, + sizeof(*cached_time)); + } + return cached_time->timestr; + } +} + +static const char *extract_request_duration(request_rec *r, char *a) +{ + apr_time_t duration = apr_time_now() - r->request_time; + return apr_psprintf(r->pool, "%" APR_TIME_T_FMT, apr_time_sec(duration)); +} + +static const char *extract_request_timestamp(request_rec *r, char *a) +{ + return apr_psprintf(r->pool, "%"APR_TIME_T_FMT, apr_time_sec(apr_time_now())); +} diff --git a/m4/apache.m4 b/m4/apache.m4 index 1e29ac7..93319e3 100644 --- a/m4/apache.m4 +++ b/m4/apache.m4 @@ -1,41 +1,16 @@ -dnl CHECK_PATH_APACHE([MINIMUM-VERSION, [ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND]]]) -dnl Test for Apache apxs +dnl TEST_APACHE_VERSION([MINIMUM-VERSION [, ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND]]]) +dnl Test for Apache dnl -AC_DEFUN(CHECK_PATH_APACHE, +AC_DEFUN(TEST_APACHE_VERSION, [dnl -AC_ARG_WITH( - apxs, - [AC_HELP_STRING([--with-apxs=PATH],[Location to APXS binary (default: /usr)])], - apxs_prefix="$withval", - apxs_prefix="/usr" - ) -AC_ARG_ENABLE(apachetest, - [AC_HELP_STRING([--disable-apachetest],[Do not try to compile and run apache version test program])], - , - enable_apachetest=yes) - - AC_REQUIRE([AC_CANONICAL_TARGET]) - PATH="$apxs_prefix:$apxs_prefix/bin:$apxs_prefix/sbin:$PATH" - if test -x $apxs_prefix && test ! -d $apxs_prefix; then - APXS_BIN=$apxs_prefix - else - AC_PATH_PROG(APXS_BIN, apxs, no, [$PATH]) - fi - min_apache_version=ifelse([$1], ,1.3.1,$1) - AC_MSG_CHECKING(for Apache - version >= $min_apache_version) - no_apxs="" - if test "$APXS_BIN" == "no"; then - no_apxs=yes - else - APACHE_INCDIR=`$APXS_BIN -q INCLUDEDIR` - APACHE_CFLAGS=-I$APACHE_INCDIR - APACHE_MODDIR=`$APXS_BIN -q LIBEXECDIR` - if test "x$enable_apachetest" = "xyes" ; then - ac_save_CFLAGS="$CFLAGS" - CFLAGS="$CFLAGS $APACHE_CFLAGS" - AC_TRY_RUN([ + min_apache_version="$1" + no_apache="" + ac_save_CFLAGS="$CFLAGS" + CFLAGS="$CFLAGS $APACHE_CFLAGS" + + AC_TRY_RUN([ #include #include #include @@ -80,37 +55,29 @@ int main (int argc, char *argv[]) ((major2 == major1) && (minor2 > minor1)) || ((major2 == major1) && (minor2 == minor1) && (micro2 >= micro1))) { - return 0; + exit(0); } else { - printf("\n*** This module requires apache version %d.%d.%d or greater\n", + /*printf("\n*** This module requires apache version %d.%d.%d or greater\n", major1, minor1, micro1); printf("*** I found version %d.%d.%d. Please verify the installation directory\n", major2, minor2, micro2); - printf("*** of apache with the --with-apxs configure option.\n"); - return 1; + printf("*** of apache with the --with-apxs configure option.\n");*/ + exit(1); } } -],, no_apxs=yes,[echo $ac_n "cross compiling; assumed OK... $ac_c"]) - CFLAGS="$ac_save_CFLAGS" - fi - fi - if test "x$no_apxs" = x ; then - AC_MSG_RESULT(yes) +],, no_apache=yes,[echo $ac_n "cross compiling; assumed OK... $ac_c"]) + CFLAGS="$ac_save_CFLAGS" + + if test "x$no_apache" = x ; then ifelse([$2], , :, [$2]) else - AC_MSG_RESULT(no) - if test "$APXS_BIN" = "no" ; then - echo "*** The apxs binary installed by apache could not be found" - echo "*** If apache is installed in PREFIX, make sure PREFIX/bin is in" - echo "*** your path, or use the --with-apxs configure option" + if test -f conf.apachetest ; then + : else - if test -f conf.apachetest ; then - : - else - echo "*** Could not run Apache test program, checking why..." - CFLAGS="$CFLAGS APACHE_CFLAGS" - AC_TRY_LINK([ + echo "*** Could not run Apache test program, checking why..." + CFLAGS="$CFLAGS APACHE_CFLAGS" + AC_TRY_LINK([ #include #include "httpd.h" @@ -118,17 +85,88 @@ int main(int argc, char *argv[]) { return 0; } #undef main #define main K_and_R_C_main -], [ return 0; ], - [ echo "*** The test program compiled, but failed to run. Check config.log" ], - [ echo "*** The test program failed to compile or link. Check config.log" ]) - CFLAGS="$ac_save_CFLAGS" - fi +], [ return 0; ], + [ echo "*** The test program compiled, but failed to run. Check config.log" ], + [ echo "*** The test program failed to compile or link. Check config.log" ]) + CFLAGS="$ac_save_CFLAGS" fi - APACHE_CFLAGS="" ifelse([$3], , :, [$3]) fi - AC_SUBST(APACHE_CFLAGS) - AC_SUBST(APACHE_INCDIR) - AC_SUBST(APACHE_MODDIR) rm -f conf.apachetest ]) + +dnl CHECK_PATH_APACHE([MINIMUM13-VERSION [, MINIMUM20-VERSION [, +dnl ACTION-IF-FOUND13 [, ACTION-IF-FOUND20 [, ACTION-IF-NOT-FOUND]]]) +dnl Test for Apache apxs +dnl +AC_DEFUN(CHECK_PATH_APACHE, +[dnl +AC_ARG_WITH( + apxs, + [AC_HELP_STRING([--with-apxs=PATH],[Location to APXS binary (default: /usr)])], + apxs_prefix="$withval", + apxs_prefix="/usr" + ) +AC_ARG_ENABLE( + apachetest, + [AC_HELP_STRING([--disable-apachetest],[Do not try to compile and run apache version test program])], + , + enable_apachetest=yes + ) + + PATH="$apxs_prefix:$apxs_prefix/bin:$apxs_prefix/sbin:$PATH" + if test -x $apxs_prefix -a ! -d $apxs_prefix; then + APXS_BIN=$apxs_prefix + else + AC_PATH_PROG(APXS_BIN, apxs, no, [$PATH]) + fi + min_apache13_version=ifelse([$1], ,no,$1) + min_apache20_version=ifelse([$2], ,no,$2) + no_apxs="" + if test "$APXS_BIN" = "no"; then + AC_MSG_ERROR([*** The apxs binary installed by apache could not be found!]) + AC_MSG_ERROR([*** If apache is installed in PREFIX, make sure PREFIX/bin is in]) + AC_MSG_ERROR([*** your path, or use the --with-apxs configure option]) + else + APACHE_INCDIR=`$APXS_BIN -q INCLUDEDIR` + APACHE_CFLAGS=-I$APACHE_INCDIR + APACHE_MODDIR=`$APXS_BIN -q LIBEXECDIR` + + if test "x$enable_apachetest" = "xyes" ; then + if test "$min_apache20_version" != "no"; then + AC_MSG_CHECKING(for Apache 2.0 version >= $min_apache20_version) + TEST_APACHE_VERSION($min_apache20_version, + AC_MSG_RESULT(yes) + AC_DEFINE(WITH_APACHE20,1,[Define to 1 if we are compiling with Apache 2.0.x]) + APACHE_VERSION="20" + APACHE_OUTPUT_NAME=$PACKAGE_NAME.la + APACHE_DEFS="-DWITH_APACHE20" + ifelse([$4], , , $4), + AC_MSG_RESULT(no) + if test "x$min_apache13_version" = "xno"; then + ifelse([$5], , , $5) + fi + ) + fi + if test "$min_apache13_version" != "no" -a "x$APACHE_VERSION" = "x"; then + AC_MSG_CHECKING(for Apache 1.3 version >= $min_apache13_version) + TEST_APACHE_VERSION($min_apache13_version, + AC_MSG_RESULT(yes) + AC_DEFINE(WITH_APACHE13,1,[Define to 1 if we are compiling with Apache 1.3.x]) + APACHE_VERSION="13" + APACHE_OUTPUT_NAME=$PACKAGE_NAME.so + APACHE_DEFS="-DWITH_APACHE13" + ifelse([$3], , , $3), + AC_MSG_RESULT(no) + ifelse([$5], , , $5) + ) + fi + fi + AC_SUBST(APACHE_DEFS) + AC_SUBST(APACHE_CFLAGS) + AC_SUBST(APACHE_INCDIR) + AC_SUBST(APACHE_MODDIR) + AC_SUBST(APACHE_VERSION) + AC_SUBST(APACHE_OUTPUT_NAME) + fi +]) diff --git a/m4/mod_ssl.m4 b/m4/mod_ssl.m4 index 457548e..6a852b9 100644 --- a/m4/mod_ssl.m4 +++ b/m4/mod_ssl.m4 @@ -15,7 +15,7 @@ AC_ARG_WITH( ssl_incdir="$withval", ) - if test "$ssl_val" = "yes"; then + if test "x$ssl_val" = "xyes"; then ac_save_CFLAGS=$CFLAGS ac_save_CPPFLAGS=$CPPFLAGS MOD_SSL_CFLAGS="-I/usr/include/openssl" diff --git a/mod_log_sql.c b/mod_log_sql.c index 64896ab..02d5fd4 100644 --- a/mod_log_sql.c +++ b/mod_log_sql.c @@ -1,4 +1,4 @@ -/* $Header: /home/cvs/mod_log_sql/mod_log_sql.c,v 1.6 2004/01/04 03:23:21 urkle Exp $ */ +/* $Header: /home/cvs/mod_log_sql/mod_log_sql.c,v 1.7 2004/01/20 16:27:34 urkle Exp $ */ /* --------* * DEFINES * * --------*/ @@ -12,24 +12,16 @@ /* ---------* * INCLUDES * * ---------*/ +#include "mysql.h" +#include "mysqld_error.h" -#include "apr_strings.h" -#include "apr_lib.h" -#include "apr_hash.h" -#include "apr_optional.h" -#define APR_WANT_STRFUNC -#include "apr_want.h" -#include "apr_tables.h" - -#include "ap_config.h" - -#include "httpd.h" -#include "http_config.h" -#include "http_core.h" -#include "http_log.h" -#include "http_protocol.h" - -#include "util_time.h" +#if defined(WITH_APACHE20) +# include "apache20.h" +#elif defined(WITH_APACHE13) +# include "apache13.h" +#else +# error Unsupported Apache version +#endif #ifdef HAVE_CONFIG_H /* Undefine these to prevent conflicts between Apache ap_config_auto.h and @@ -51,8 +43,6 @@ #include #endif -#include "mysql.h" -#include "mysqld_error.h" #ifdef WANT_SSL_LOGGING #include "mod_ssl.h" @@ -164,8 +154,11 @@ static const char *extract_remote_logname(request_rec *r, char *a) static const char *extract_remote_user(request_rec *r, char *a) { + #ifdef WITH_APACHE13 + char *rvalue = r->connection->user; + #else char *rvalue = r->user; - + #endif if (rvalue == NULL) { rvalue = "-"; } else if (strlen(rvalue) == 0) { @@ -184,7 +177,7 @@ static const char *extract_ssl_keysize(request_rec *r, char *a) if (myCtxConfig(scc,ssc) != NULL) { result = ssl_var_lookup(r->pool, r->server, r->connection, r, "SSL_CIPHER_USEKEYSIZE"); #ifdef DEBUG - ap_log_error(APLOG_MARK,APLOG_DEBUG,0,r->server,"SSL_KEYSIZE: %s", result); + log_error(APLOG_MARK,APLOG_DEBUG,0,r->server,"SSL_KEYSIZE: %s", result); #endif if (result != NULL && result[0] == '\0') result = NULL; @@ -203,7 +196,7 @@ static const char *extract_ssl_maxkeysize(request_rec *r, char *a) if (myCtxConfig(scc,ssc) != NULL) { result = ssl_var_lookup(r->pool, r->server, r->connection, r, "SSL_CIPHER_ALGKEYSIZE"); #ifdef DEBUG - ap_log_error(APLOG_MARK,APLOG_DEBUG,0,r->server,"SSL_ALGKEYSIZE: %s", result); + log_error(APLOG_MARK,APLOG_DEBUG,0,r->server,"SSL_ALGKEYSIZE: %s", result); #endif if (result != NULL && result[0] == '\0') result = NULL; @@ -222,7 +215,7 @@ static const char *extract_ssl_cipher(request_rec *r, char *a) if (myCtxConfig(scc,ssc) != NULL) { result = ssl_var_lookup(r->pool, r->server, r->connection, r, "SSL_CIPHER"); #ifdef DEBUG - ap_log_error(APLOG_MARK,APLOG_DEBUG,0,r->server,"SSL_CIPHER: %s", result); + log_error(APLOG_MARK,APLOG_DEBUG,0,r->server,"SSL_CIPHER: %s", result); #endif if (result != NULL && result[0] == '\0') result = NULL; @@ -295,93 +288,12 @@ static const char *extract_header_out(request_rec *r, char *a) return table_get(r->err_headers_out, a); } */ -static const char *extract_request_time_custom(request_rec *r, char *a, - apr_time_exp_t *xt) -{ - apr_size_t retcode; - char tstr[MAX_STRING_LEN]; - apr_strftime(tstr, &retcode, sizeof(tstr), a, xt); - return apr_pstrdup(r->pool, tstr); -} - -#define DEFAULT_REQUEST_TIME_SIZE 32 -typedef struct { - unsigned t; - char timestr[DEFAULT_REQUEST_TIME_SIZE]; - unsigned t_validate; -} cached_request_time; - -#define TIME_CACHE_SIZE 4 -#define TIME_CACHE_MASK 3 -static cached_request_time request_time_cache[TIME_CACHE_SIZE]; - -static const char *extract_request_time(request_rec *r, char *a) -{ - apr_time_exp_t xt; - /* Please read comments in mod_log_config.h for more info about - * the I_INSIST....COMPLIANCE define - */ - if (a && *a) { /* Custom format */ -#ifdef I_INSIST_ON_EXTRA_CYCLES_FOR_CLF_COMPLIANCE - ap_explode_recent_localtime(&xt, apr_time_now()); -#else - ap_explode_recent_localtime(&xt, r->request_time); -#endif - return extract_request_time_custom(r, a, &xt); - } else { /* CLF format */ - /* This code uses the same technique as ap_explode_recent_localtime(): - * optimistic caching with logic to detect and correct race conditions. - * See the comments in server/util_time.c for more information. - */ - cached_request_time* cached_time = apr_palloc(r->pool, - sizeof(*cached_time)); -#ifdef I_INSIST_ON_EXTRA_CYCLES_FOR_CLF_COMPLIANCE - apr_time_t request_time = apr_time_now(); -#else - apr_time_t request_time = r->request_time; +#if defined(WITH_APACHE13) +#include "functions13.h" +#elif defined(WITH_APACHE20) +#include "functions20.h" #endif - unsigned t_seconds = (unsigned)apr_time_sec(request_time); - unsigned i = t_seconds & TIME_CACHE_MASK; - memcpy(cached_time, &(request_time_cache[i]), sizeof(*cached_time)); - if ((t_seconds != cached_time->t) || - (t_seconds != cached_time->t_validate)) { - - /* Invalid or old snapshot, so compute the proper time string - * and store it in the cache - */ - char sign; - int timz; - - ap_explode_recent_localtime(&xt, r->request_time); - timz = xt.tm_gmtoff; - if (timz < 0) { - timz = -timz; - sign = '-'; - } - else { - sign = '+'; - } - cached_time->t = t_seconds; - apr_snprintf(cached_time->timestr, DEFAULT_REQUEST_TIME_SIZE, - "[%02d/%s/%d:%02d:%02d:%02d %c%.2d%.2d]", - xt.tm_mday, apr_month_snames[xt.tm_mon], - xt.tm_year+1900, xt.tm_hour, xt.tm_min, xt.tm_sec, - sign, timz / (60*60), timz % (60*60)); - cached_time->t_validate = t_seconds; - memcpy(&(request_time_cache[i]), cached_time, - sizeof(*cached_time)); - } - return cached_time->timestr; - } -} - -static const char *extract_request_duration(request_rec *r, char *a) -{ - apr_time_t duration = apr_time_now() - r->request_time; - return apr_psprintf(r->pool, "%" APR_TIME_T_FMT, apr_time_sec(duration)); -} - static const char *extract_virtual_host(request_rec *r, char *a) { return apr_pstrdup(r->pool, r->server->server_hostname); @@ -456,7 +368,7 @@ static const char *extract_cookie(request_rec *r, char *a) if (cls->cookie_name != NULL) { #ifdef DEBUG - ap_log_rerror(APLOG_MARK,APLOG_DEBUG,0, r, + log_error(APLOG_MARK,APLOG_DEBUG, r->server, "watching for cookie '%s'", cls->cookie_name); #endif @@ -464,7 +376,7 @@ static const char *extract_cookie(request_rec *r, char *a) cookiestr = (char *)apr_table_get(r->headers_in, "cookie2"); if (cookiestr != NULL) { #ifdef DEBUG - ap_log_rerror(APLOG_MARK,APLOG_DEBUG,0, r, + log_error(APLOG_MARK,APLOG_DEBUG, r->server, "Cookie2: [%s]", cookiestr); #endif /* Does the cookie string contain one with our name? */ @@ -486,7 +398,7 @@ static const char *extract_cookie(request_rec *r, char *a) cookiestr = (char *)apr_table_get(r->headers_in, "cookie"); if (cookiestr != NULL) { #ifdef DEBUG - ap_log_rerror(APLOG_MARK,APLOG_DEBUG,0,r, + log_error(APLOG_MARK,APLOG_DEBUG,r->server, "Cookie: [%s]", cookiestr); #endif isvalid = strstr(cookiestr, cls->cookie_name); @@ -503,7 +415,7 @@ static const char *extract_cookie(request_rec *r, char *a) cookiestr = apr_table_get(r->headers_out, "set-cookie"); if (cookiestr != NULL) { #ifdef DEBUG - ap_log_rerror(APLOG_MARK,APLOG_DEBUG,0,r, + log_error(APLOG_MARK,APLOG_DEBUG,r->server, "Set-Cookie: [%s]", cookiestr); #endif isvalid = strstr(cookiestr, cls->cookie_name); @@ -530,15 +442,15 @@ static const char *extract_specific_cookie(request_rec *r, char *a) if (a != NULL) { #ifdef DEBUG - ap_log_rerror(APLOG_MARK,APLOG_DEBUG,0, - r,"watching for cookie '%s'", a); + log_error(APLOG_MARK,APLOG_DEBUG, + r->server,"watching for cookie '%s'", a); #endif /* Fetch out the cookie header */ cookiestr = (char *)apr_table_get(r->headers_in, "cookie2"); if (cookiestr != NULL) { #ifdef DEBUG - ap_log_rerror(APLOG_MARK,APLOG_DEBUG,0,r, + log_error(APLOG_MARK,APLOG_DEBUG,r->server, "Cookie2: [%s]", cookiestr); #endif /* Does the cookie string contain one with our name? */ @@ -560,7 +472,7 @@ static const char *extract_specific_cookie(request_rec *r, char *a) cookiestr = (char *)apr_table_get(r->headers_in, "cookie"); if (cookiestr != NULL) { #ifdef DEBUG - ap_log_rerror(APLOG_MARK,APLOG_DEBUG,0,r, + log_error(APLOG_MARK,APLOG_DEBUG,r->server, "Cookie: [%s]", cookiestr); #endif isvalid = strstr(cookiestr, a); @@ -577,7 +489,7 @@ static const char *extract_specific_cookie(request_rec *r, char *a) cookiestr = apr_table_get(r->headers_out, "set-cookie"); if (cookiestr != NULL) { #ifdef DEBUG - ap_log_rerror(APLOG_MARK,APLOG_DEBUG,0,r, + log_error(APLOG_MARK,APLOG_DEBUG,r->server, "Set-Cookie: [%s]", cookiestr); #endif isvalid = strstr(cookiestr, a); @@ -596,11 +508,6 @@ static const char *extract_specific_cookie(request_rec *r, char *a) } -static const char *extract_request_timestamp(request_rec *r, char *a) -{ - return apr_psprintf(r->pool, "%"APR_TIME_T_FMT, apr_time_sec(apr_time_now())); -} - /* static const char *extract_note(request_rec *r, char *a) { @@ -730,20 +637,20 @@ static int open_logdb_link(server_rec* s) if (global_config.server_p) { #ifdef DEBUG - ap_log_error(APLOG_MARK,APLOG_DEBUG,0,s,"HOST: '%s' PORT: '%d' DB: '%s' USER: '%s' SOCKET: '%s'", + log_error(APLOG_MARK,APLOG_DEBUG,s,"HOST: '%s' PORT: '%d' DB: '%s' USER: '%s' SOCKET: '%s'", global_config.dbhost, global_config.tcpport, global_config.dbname, global_config.dbuser, global_config.socketfile); #endif return 1; } else { #ifdef DEBUG - ap_log_error(APLOG_MARK,APLOG_DEBUG,0,s,"mod_log_sql: database connection error: %s",MYSQL_ERROR(&global_config.server)); - ap_log_error(APLOG_MARK,APLOG_DEBUG,0,s,"HOST: '%s' PORT: '%d' DB: '%s' USER: '%s' SOCKET: '%s'", + log_error(APLOG_MARK,APLOG_DEBUG,s,"mod_log_sql: database connection error: %s",MYSQL_ERROR(&global_config.server)); + log_error(APLOG_MARK,APLOG_DEBUG,s,"HOST: '%s' PORT: '%d' DB: '%s' USER: '%s' SOCKET: '%s'", global_config.dbhost, global_config.tcpport, global_config.dbname, global_config.dbuser, global_config.socketfile); #endif return 0; } } else { - ap_log_error(APLOG_MARK,APLOG_ERR,0,s,"mod_log_sql: insufficient configuration info to establish database link"); + log_error(APLOG_MARK,APLOG_ERR,s,"mod_log_sql: insufficient configuration info to establish database link"); return 0; } } @@ -757,17 +664,30 @@ static int open_logdb_link(server_rec* s) static void preserve_entry(request_rec *r, const char *query) { - apr_file_t *fp; logsql_state *cls = ap_get_module_config(r->server->module_config, &log_sql_module); - - if (apr_file_open(&fp, cls->preserve_file,APR_APPEND, APR_OS_DEFAULT, r->pool)!=APR_SUCCESS) { - ap_log_error(APLOG_MARK,APLOG_ERR,0,r->server,"mod_log_sql: attempted append of local preserve file but failed."); + #if defined(WITH_APACHE20) + apr_file_t *fp; + apr_status_t result; + result = apr_file_open(&fp, cls->preserve_file,APR_APPEND, APR_OS_DEFAULT, r->pool); + #elif defined(WITH_APACHE13) + FILE *fp; + int result; + fp = ap_pfopen(r->pool, cls->preserve_file, "a"); + result = (fp)?0:1; + #endif + if (result != APR_SUCCESS) { + log_error(APLOG_MARK,APLOG_ERR,r->server,"mod_log_sql: attempted append of local preserve file but failed."); } else { - apr_file_printf(fp,"%s;\n", query); - apr_file_close(fp); + #if defined(WITH_APACHE20) + apr_file_printf(fp,"%s;\n", query); + apr_file_close(fp); + #elif defined(WITH_APACHE13) + fprintf(fp,"%s;\n", query); + ap_pfclose(r->pool, fp); + #endif #ifdef DEBUG - ap_log_error(APLOG_MARK,APLOG_DEBUG,0,r->server,"mod_log_sql: entry preserved in %s", cls->preserve_file); + log_error(APLOG_MARK,APLOG_DEBUG,r->server,"mod_log_sql: entry preserved in %s", cls->preserve_file); #endif } } @@ -822,24 +742,24 @@ static unsigned int safe_sql_query(request_rec *r, const char *query) } if (retval) { if (global_config.createtables) { - ap_log_error(APLOG_MARK,APLOG_ERR,0,r->server,"mod_log_sql: table doesn't exist...creating now"); + log_error(APLOG_MARK,APLOG_ERR,r->server,"mod_log_sql: table doesn't exist...creating now"); cls = ap_get_module_config(r->server->module_config, &log_sql_module); if (safe_create_tables(cls, r)) { - ap_log_error(APLOG_MARK,APLOG_ERR,0,r->server,"mod_log_sql: child attempted but failed to create one or more tables for %s, preserving query", ap_get_server_name(r)); + log_error(APLOG_MARK,APLOG_ERR,r->server,"mod_log_sql: child attempted but failed to create one or more tables for %s, preserving query", ap_get_server_name(r)); preserve_entry(r, query); retval = mysql_errno(global_config.server_p); } else { - ap_log_error(APLOG_MARK,APLOG_ERR,0,r->server,"mod_log_sql: tables successfully created - retrying query"); + log_error(APLOG_MARK,APLOG_ERR,r->server,"mod_log_sql: tables successfully created - retrying query"); if (mysql_query(global_config.server_p, query)) { - ap_log_error(APLOG_MARK,APLOG_ERR,0,r->server,"mod_log_sql: giving up, preserving query"); + log_error(APLOG_MARK,APLOG_ERR,r->server,"mod_log_sql: giving up, preserving query"); preserve_entry(r, query); retval = mysql_errno(global_config.server_p); } else - ap_log_error(APLOG_MARK,APLOG_ERR,0,r->server,"mod_log_sql: query successful after table creation"); + log_error(APLOG_MARK,APLOG_ERR,r->server,"mod_log_sql: query successful after table creation"); retval = 0; } } else { - ap_log_error(APLOG_MARK,APLOG_ERR,0,r->server,"mod_log_sql, table doesn't exist, creation denied by configuration, preserving query"); + log_error(APLOG_MARK,APLOG_ERR,r->server,"mod_log_sql, table doesn't exist, creation denied by configuration, preserving query"); preserve_entry(r, query); retval = ER_NO_SUCH_TABLE; } @@ -859,25 +779,25 @@ static unsigned int safe_sql_query(request_rec *r, const char *query) real_error = mysql_errno(global_config.server_p); } - ap_log_error(APLOG_MARK,APLOG_ERR,0,r->server,"mod_log_sql: first attempt failed, API said: error %d, \"%s\"", real_error, MYSQL_ERROR(global_config.server_p)); + log_error(APLOG_MARK,APLOG_ERR,r->server,"mod_log_sql: first attempt failed, API said: error %d, \"%s\"", real_error, MYSQL_ERROR(global_config.server_p)); mysql_close(global_config.server_p); global_config.server_p = NULL; open_logdb_link(r->server); if (global_config.server_p == NULL) { /* still unable to link */ signal(SIGPIPE, handler); - ap_log_error(APLOG_MARK,APLOG_ERR,0,r->server,"mod_log_sql: reconnect failed, unable to reach database. SQL logging stopped until child regains a db connection."); - ap_log_error(APLOG_MARK,APLOG_ERR,0,r->server,"mod_log_sql: log entries are being preserved in %s", cls->preserve_file); + log_error(APLOG_MARK,APLOG_ERR,r->server,"mod_log_sql: reconnect failed, unable to reach database. SQL logging stopped until child regains a db connection."); + log_error(APLOG_MARK,APLOG_ERR,r->server,"mod_log_sql: log entries are being preserved in %s", cls->preserve_file); return 1; } else - ap_log_error(APLOG_MARK,APLOG_ERR,0,r->server,"mod_log_sql: db reconnect successful"); + log_error(APLOG_MARK,APLOG_ERR,r->server,"mod_log_sql: db reconnect successful"); /* First sleep for a tiny amount of time. */ delay.tv_sec = 0; delay.tv_nsec = 250000000; /* max is 999999999 (nine nines) */ ret = nanosleep(&delay, &remainder); if (ret && errno != EINTR) - ap_log_error(APLOG_MARK,APLOG_ERR,0,r->server,"mod_log_sql: nanosleep unsuccessful"); + log_error(APLOG_MARK,APLOG_ERR,r->server,"mod_log_sql: nanosleep unsuccessful"); /* Then make our second attempt */ retval = mysql_query(global_config.server_p,query); @@ -890,11 +810,11 @@ static unsigned int safe_sql_query(request_rec *r, const char *query) real_error = mysql_errno(global_config.server_p); } - ap_log_error(APLOG_MARK,APLOG_ERR,0,r->server,"mod_log_sql: second attempt failed, API said: error %d, \"%s\" -- preserving", real_error, MYSQL_ERROR(global_config.server_p)); + log_error(APLOG_MARK,APLOG_ERR,r->server,"mod_log_sql: second attempt failed, API said: error %d, \"%s\" -- preserving", real_error, MYSQL_ERROR(global_config.server_p)); preserve_entry(r, query); retval = real_error; } else - ap_log_error(APLOG_MARK,APLOG_ERR,0,r->server,"mod_log_sql: second attempt successful"); + log_error(APLOG_MARK,APLOG_ERR,r->server,"mod_log_sql: second attempt successful"); /* Restore SIGPIPE to its original handler function */ signal(SIGPIPE, handler); @@ -974,38 +894,38 @@ static int safe_create_tables(logsql_state *cls, request_rec *r) create_cookies= apr_pstrcat(r->pool, createprefix, cls->cookie_table_name, cookies_suffix, type_suffix, NULL); #ifdef DEBUG - ap_log_error(APLOG_MARK,APLOG_DEBUG,0,r->server,"mod_log_sql: create string: %s", create_access); - ap_log_error(APLOG_MARK,APLOG_DEBUG,0,r->server,"mod_log_sql: create string: %s", create_notes); - ap_log_error(APLOG_MARK,APLOG_DEBUG,0,r->server,"mod_log_sql: create string: %s", create_hout); - ap_log_error(APLOG_MARK,APLOG_DEBUG,0,r->server,"mod_log_sql: create string: %s", create_hin); - ap_log_error(APLOG_MARK,APLOG_DEBUG,0,r->server,"mod_log_sql: create string: %s", create_cookies); + log_error(APLOG_MARK,APLOG_DEBUG,r->server,"mod_log_sql: create string: %s", create_access); + log_error(APLOG_MARK,APLOG_DEBUG,r->server,"mod_log_sql: create string: %s", create_notes); + log_error(APLOG_MARK,APLOG_DEBUG,r->server,"mod_log_sql: create string: %s", create_hout); + log_error(APLOG_MARK,APLOG_DEBUG,r->server,"mod_log_sql: create string: %s", create_hin); + log_error(APLOG_MARK,APLOG_DEBUG,r->server,"mod_log_sql: create string: %s", create_cookies); #endif /* Assume that things worked unless told otherwise */ retval = 0; if ((create_results = safe_sql_query(r, create_access))) { - ap_log_error(APLOG_MARK,APLOG_ERR,0,r->server,"mod_log_sql: failed to create access table"); + log_error(APLOG_MARK,APLOG_ERR,r->server,"mod_log_sql: failed to create access table"); retval = create_results; } if ((create_results = safe_sql_query(r, create_notes))) { - ap_log_error(APLOG_MARK,APLOG_ERR,0,r->server,"mod_log_sql: failed to create notes table"); + log_error(APLOG_MARK,APLOG_ERR,r->server,"mod_log_sql: failed to create notes table"); retval = create_results; } if ((create_results = safe_sql_query(r, create_hin))) { - ap_log_error(APLOG_MARK,APLOG_ERR,0,r->server,"mod_log_sql: failed to create header_in table"); + log_error(APLOG_MARK,APLOG_ERR,r->server,"mod_log_sql: failed to create header_in table"); retval = create_results; } if ((create_results = safe_sql_query(r, create_hout))) { - ap_log_error(APLOG_MARK,APLOG_ERR,0,r->server,"mod_log_sql: failed to create header_out table"); + log_error(APLOG_MARK,APLOG_ERR,r->server,"mod_log_sql: failed to create header_out table"); retval = create_results; } if ((create_results = safe_sql_query(r, create_cookies))) { - ap_log_error(APLOG_MARK,APLOG_ERR,0,r->server,"mod_log_sql: failed to create cookies table"); + log_error(APLOG_MARK,APLOG_ERR,r->server,"mod_log_sql: failed to create cookies table"); retval = create_results; } @@ -1123,21 +1043,18 @@ static const char *set_log_sql_tcp_port(cmd_parms *parms, void *dummy, const cha * that are defined in the array 'mysql_lgog_module' (at EOF) * *------------------------------------------------------------*/ - -/* - * This function is called when an heavy-weight process (such as a child) is - * being run down or destroyed. As with the child-initialisation function, - * any information that needs to be recorded must be in static cells, since - * there's no configuration record. - * - * There is no return value. - */ +#if defined(WITH_APACHE20) static apr_status_t log_sql_close_link(void *data) { mysql_close(global_config.server_p); return APR_SUCCESS; } - +#elif defined(WITH_APACHE13) +static void log_sql_child_exit(server_rec *s, apr_pool_t *p) +{ + mysql_close(global_config.server_p); +} +#endif /* * This function is called during server initialisation when an heavy-weight * process (such as a child) is being initialised. As with the @@ -1146,26 +1063,32 @@ static apr_status_t log_sql_close_link(void *data) * * There is no return value. */ +#if defined(WITH_APACHE20) static void log_sql_child_init(apr_pool_t *p, server_rec *s) { apr_pool_cleanup_register(p, NULL, log_sql_close_link, log_sql_close_link); } static int log_sql_open(apr_pool_t *pc, apr_pool_t *p, apr_pool_t *pt, server_rec *s) +#elif defined(WITH_APACHE13) +static void log_sql_child_init(server_rec *s, apr_pool_t *p) +#endif { int retval; /* Open a link to the database */ retval = open_logdb_link(s); if (!retval) - ap_log_error(APLOG_MARK,APLOG_ERR,0,s,"mod_log_sql: child spawned but unable to open database link"); + log_error(APLOG_MARK,APLOG_ERR,s,"mod_log_sql: child spawned but unable to open database link"); #ifdef DEBUG if ( (retval == 1) || (retval == 2) ) - ap_log_error(APLOG_MARK,APLOG_DEBUG,0,s,"mod_log_sql: open_logdb_link successful"); + log_error(APLOG_MARK,APLOG_DEBUG,s,"mod_log_sql: open_logdb_link successful"); if (retval == 3) - ap_log_error(APLOG_MARK,APLOG_DEBUG,0,s,"mod_log_sql: open_logdb_link said that preservation is forced"); + log_error(APLOG_MARK,APLOG_DEBUG,s,"mod_log_sql: open_logdb_link said that preservation is forced"); #endif +#if defined(WITH_APACHE20) return OK; +#endif } /* void *log_sql_initializer(server_rec *main_server, apr_pool_t *p) @@ -1183,6 +1106,23 @@ void *log_sql_initializer(server_rec *main_server, apr_pool_t *p) } */ +#if defined(WITH_APACHE20) +static int log_sql_pre_config(apr_pool_t *p, apr_pool_t *plog, apr_pool_t *ptemp) +#elif defined(WITH_APACHE13) +static void log_sql_pre_config(server_rec *s, apr_pool_t *p) +#endif +{ + /* Initialize Global configuration */ + if (!global_config.socketfile) + global_config.socketfile = "/tmp/mysql.sock"; + if (!global_config.tcpport) + global_config.tcpport = 3306; + +#if defined(WITH_APACHE20) + return OK; +#endif +} + /* * This function gets called to create a per-server configuration * record. It will always be called for the main server and @@ -1192,15 +1132,6 @@ void *log_sql_initializer(server_rec *main_server, apr_pool_t *p) * The return value is a pointer to the created module-specific * structure. */ -static int log_sql_pre_config(apr_pool_t *p, apr_pool_t *plog, apr_pool_t *ptemp) -{ - /* Initialize Global configuration */ - memset(&global_config,0,sizeof(global_config_t)); - global_config.socketfile = "/tmp/mysql.sock"; - global_config.tcpport = 3306; - return OK; -} - static void *log_sql_make_state(apr_pool_t *p, server_rec *s) { logsql_state *cls = (logsql_state *) apr_pcalloc(p, sizeof(logsql_state)); @@ -1460,7 +1391,7 @@ static int log_sql_transaction(request_rec *orig) global_config.insertdelayed?"delayed":"", cls->notes_table_name, itemsets); #ifdef DEBUG - ap_log_error(APLOG_MARK,APLOG_DEBUG,0,orig->server,"mod_log_sql: note string: %s", note_query); + log_error(APLOG_MARK,APLOG_DEBUG,orig->server,"mod_log_sql: note string: %s", note_query); #endif } @@ -1490,7 +1421,7 @@ static int log_sql_transaction(request_rec *orig) global_config.insertdelayed?"delayed":"", cls->hout_table_name, itemsets); #ifdef DEBUG - ap_log_error(APLOG_MARK,APLOG_DEBUG,0,orig->server,"mod_log_sql: header_out string: %s", hout_query); + log_error(APLOG_MARK,APLOG_DEBUG,orig->server,"mod_log_sql: header_out string: %s", hout_query); #endif } @@ -1521,7 +1452,7 @@ static int log_sql_transaction(request_rec *orig) global_config.insertdelayed?"delayed":"", cls->hin_table_name, itemsets); #ifdef DEBUG - ap_log_error(APLOG_MARK,APLOG_DEBUG,0,orig->server,"mod_log_sql: header_in string: %s", hin_query); + log_error(APLOG_MARK,APLOG_DEBUG,orig->server,"mod_log_sql: header_in string: %s", hin_query); #endif } @@ -1553,7 +1484,7 @@ static int log_sql_transaction(request_rec *orig) global_config.insertdelayed?"delayed":"", cls->cookie_table_name, itemsets); #ifdef DEBUG - ap_log_error(APLOG_MARK,APLOG_DEBUG,0,orig->server,"mod_log_sql: cookie string: %s", cookie_query); + log_error(APLOG_MARK,APLOG_DEBUG,orig->server,"mod_log_sql: cookie string: %s", cookie_query); #endif } @@ -1563,7 +1494,7 @@ static int log_sql_transaction(request_rec *orig) global_config.insertdelayed?"delayed":"", cls->transfer_table_name, fields, values); #ifdef DEBUG - ap_log_error(APLOG_MARK,APLOG_DEBUG,0,r->server,"mod_log_sql: access string: %s", access_query); + log_error(APLOG_MARK,APLOG_DEBUG,r->server,"mod_log_sql: access string: %s", access_query); #endif /* If the person activated force-preserve, go ahead and push all the entries @@ -1571,7 +1502,7 @@ static int log_sql_transaction(request_rec *orig) */ if (global_config.forcepreserve) { #ifdef DEBUG - ap_log_error(APLOG_MARK,APLOG_DEBUG,0,orig->server,"mod_log_sql: preservation forced"); + log_error(APLOG_MARK,APLOG_DEBUG,orig->server,"mod_log_sql: preservation forced"); #endif preserve_entry(orig, access_query); if ( note_query != NULL ) @@ -1610,7 +1541,7 @@ static int log_sql_transaction(request_rec *orig) return OK; } else { /* Whew, we got the DB link back */ - ap_log_error(APLOG_MARK,APLOG_NOTICE,0,orig->server,"mod_log_sql: child established database connection"); + log_error(APLOG_MARK,APLOG_NOTICE,orig->server,"mod_log_sql: child established database connection"); } } @@ -1745,6 +1676,7 @@ static const command_rec log_sql_cmds[] = { , {NULL} }; +#if defined(WITH_APACHE20) /* The configuration array that sets up the hooks into the module. */ static void register_hooks(apr_pool_t *p) { ap_hook_pre_config(log_sql_pre_config, NULL, NULL, APR_HOOK_REALLY_FIRST); @@ -1762,3 +1694,30 @@ module AP_MODULE_DECLARE_DATA log_sql_module = { log_sql_cmds, /* command handlers */ register_hooks /* register hooks */ }; +#elif defined(WITH_APACHE13) +/* The configuration array that sets up the hooks into the module. */ +module log_sql_module = { + STANDARD_MODULE_STUFF, + log_sql_pre_config, /* module initializer */ + NULL, /* create per-dir config */ + NULL, /* merge per-dir config */ + log_sql_make_state, /* create server config */ + log_sql_merge_state, /* merge server config */ + log_sql_cmds, /* config directive table */ + NULL, /* [9] content handlers */ + NULL, /* [2] URI-to-filename translation */ + NULL, /* [5] check/validate user_id */ + NULL, /* [6] check authorization */ + NULL, /* [4] check access by host */ + NULL, /* [7] MIME type checker/setter */ + NULL, /* [8] fixups */ + log_sql_transaction, /* [10] logger */ + NULL /* [3] header parser */ +#if MODULE_MAGIC_NUMBER >= 19970728 /* 1.3-dev or later support these additionals... */ + ,log_sql_child_init, /* child process initializer */ + log_sql_child_exit, /* process exit/cleanup */ + NULL /* [1] post read-request */ +#endif + +}; +#endif -- cgit