diff options
| -rw-r--r-- | CHANGELOG | 16 | ||||
| -rw-r--r-- | Makefile.in | 35 | ||||
| -rw-r--r-- | apache13.h | 61 | ||||
| -rw-r--r-- | apache20.h | 31 | ||||
| -rw-r--r-- | configure.ac | 30 | ||||
| -rw-r--r-- | functions13.h | 38 | ||||
| -rw-r--r-- | functions20.h | 92 | ||||
| -rw-r--r-- | m4/apache.m4 | 166 | ||||
| -rw-r--r-- | m4/mod_ssl.m4 | 2 | ||||
| -rw-r--r-- | mod_log_sql.c | 331 |
10 files changed, 523 insertions, 279 deletions
| @@ -1,4 +1,4 @@ | |||
| 1 | $Id: CHANGELOG,v 1.5 2004/01/06 00:32:46 urkle Exp $ | 1 | $Id: CHANGELOG,v 1.6 2004/01/20 16:27:34 urkle Exp $ |
| 2 | 2 | ||
| 3 | TODO: | 3 | TODO: |
| 4 | * Port connection portion to other DBMS? Genericize the module? Start with | 4 | * Port connection portion to other DBMS? Genericize the module? Start with |
| @@ -8,17 +8,27 @@ TODO: | |||
| 8 | * LogSQLRotateLogs directive with daily/monthly/weekly/etc. | 8 | * LogSQLRotateLogs directive with daily/monthly/weekly/etc. |
| 9 | * new format char: IP as bigint? ( not w/ ipV6 ) | 9 | * new format char: IP as bigint? ( not w/ ipV6 ) |
| 10 | * socket-based middleman daemon with configurable conns, or connect/disconnect. | 10 | * socket-based middleman daemon with configurable conns, or connect/disconnect. |
| 11 | DBI connection pool when I switch to DBI. | ||
| 11 | * ignore by cookie | 12 | * ignore by cookie |
| 12 | * tools to import logs into SQL | 13 | * tools to import logs into SQL (waiting on permission from author) |
| 13 | * Directive to yes/no create ancillary tables (or just access table) | 14 | * Directive to yes/no create ancillary tables (or just access table) |
| 14 | * break module into separate code files | 15 | * break module into separate code files |
| 15 | separate DB implimentation into sub-modules via provider mechanism | 16 | separate DB implimentation into sub-modules via provider mechanism |
| 16 | separate module for SSL support | 17 | separate module for SSL support |
| 18 | apache version specific code already split into separate files. | ||
| 17 | * add document building to Makefile.in | 19 | * add document building to Makefile.in |
| 18 | * backport patch for apache 1.3 | ||
| 19 | * investigate thread safety issues (libmysqlclient_r) | 20 | * investigate thread safety issues (libmysqlclient_r) |
| 20 | 21 | ||
| 21 | CHANGES: | 22 | CHANGES: |
| 23 | 1.93: 2004-01-20 | ||
| 24 | * Compiles for apache 1.3 AND 2.0 | ||
| 25 | * split apache version specific functions to seperate header files | ||
| 26 | * split apache version specific includes to seperate header files | ||
| 27 | * added wrapper defines for apache 1.3 | ||
| 28 | * updated configure m4 scripts to detect both apache versions at the same time | ||
| 29 | and assign defines as to which version was found. | ||
| 30 | * made install default to not activate module in configuration files. | ||
| 31 | |||
| 22 | 1.92: 2004-01-05 | 32 | 1.92: 2004-01-05 |
| 23 | * fixed compilation issue with mysql 4.x where mysql_error returns const char * | 33 | * fixed compilation issue with mysql 4.x where mysql_error returns const char * |
| 24 | * Have SSL support compiling (though not really tested) | 34 | * 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@ | |||
| 15 | 15 | ||
| 16 | EXTRA_DIST = INSTALL LICENSE CHANGELOG make_combined_log.pl | 16 | EXTRA_DIST = INSTALL LICENSE CHANGELOG make_combined_log.pl |
| 17 | 17 | ||
| 18 | TARGET = @PACKAGE_NAME@.la | 18 | TARGET = @APACHE_OUTPUT_NAME@ |
| 19 | 19 | ||
| 20 | #Don't modify anything below here | 20 | #Don't modify anything below here |
| 21 | 21 | ||
| @@ -44,7 +44,7 @@ DISTFILES = $(STD_DIST) $(EXTRA_DIST) $(SOURCES) $(HEADERS) | |||
| 44 | 44 | ||
| 45 | all: $(TARGET) all-subdirs | 45 | all: $(TARGET) all-subdirs |
| 46 | 46 | ||
| 47 | all-subdirs install-subdirs update-subdirs clean-subdirs distclean-subdirs: | 47 | all-subdirs install-subdirs activate-subdirs clean-subdirs distclean-subdirs: |
| 48 | @otarget=`echo $@|sed s/-subdirs//`; \ | 48 | @otarget=`echo $@|sed s/-subdirs//`; \ |
| 49 | list=' $(PROVIDERS_SUBDIRS) $(SUBDIRS)'; \ | 49 | list=' $(PROVIDERS_SUBDIRS) $(SUBDIRS)'; \ |
| 50 | for i in $$list; do \ | 50 | for i in $$list; do \ |
| @@ -57,28 +57,30 @@ all-subdirs install-subdirs update-subdirs clean-subdirs distclean-subdirs: | |||
| 57 | fi; \ | 57 | fi; \ |
| 58 | (cd $$i && $(MAKE) $$target) || exit 1; \ | 58 | (cd $$i && $(MAKE) $$target) || exit 1; \ |
| 59 | fi; \ | 59 | fi; \ |
| 60 | done; \ | 60 | done; |
| 61 | 61 | ||
| 62 | $(TARGET): | 62 | $(TARGET): |
| 63 | @APXS_BIN@ -c -o @PACKAGE_NAME@.la $(INCLUDES) @MOD_SSL_CFLAGS@ $(CFLAGS) $(LDADD) @DEFS@ $(SOURCES) | 63 | @@APXS_BIN@ -c -o $(TARGET) $(INCLUDES) @MOD_SSL_CFLAGS@ $(CFLAGS) \ |
| 64 | $(LDADD) @DEFS@ @APACHE_DEFS@ $(SOURCES) | ||
| 64 | 65 | ||
| 65 | include: | 66 | include: |
| 66 | rm -rf include | 67 | rm -rf include |
| 67 | ln -s @APACHE_INCDIR@ include | 68 | ln -s @APACHE_INCDIR@ include |
| 68 | 69 | ||
| 69 | install: install-subdirs | 70 | install: install-subdirs |
| 70 | @APXS_BIN@ -i -a $(TARGET) | 71 | @@APXS_BIN@ -i $(TARGET) |
| 71 | 72 | ||
| 72 | update: update-subdirs | 73 | activate: activate-subdirs |
| 73 | @APXS_BIN@ -i $(TARGET) | 74 | @@APXS_BIN@ -i -a $(TARGET) |
| 74 | 75 | ||
| 75 | clean: clean-subdirs | 76 | clean: clean-subdirs |
| 76 | $(RM) $(OBJ) $(SLO) $(LO) $(TARGET) .deps | 77 | $(RM) $(OBJ) $(SLO) $(LO) $(TARGET) .deps |
| 78 | $(RM) -r .libs | ||
| 77 | 79 | ||
| 78 | distclean: clean distclean-subdirs | 80 | distclean: clean distclean-subdirs |
| 79 | $(RM) config.status config.log config.h config.h.in \ | 81 | $(RM) config.status config.log config.h config.h.in \ |
| 80 | configure stamp-h stamp-h.in Makefile aclocal.m4 | 82 | configure stamp-h stamp-h.in Makefile aclocal.m4 |
| 81 | $(RM) -r autom4te-2.53.cache .libs | 83 | $(RM) -r autom4te-2.53.cache |
| 82 | 84 | ||
| 83 | DESTDIR = @PACKAGE_NAME@-@PACKAGE_VERSION@ | 85 | DESTDIR = @PACKAGE_NAME@-@PACKAGE_VERSION@ |
| 84 | DESTTGZ = $(DESTDIR).tar.gz | 86 | DESTTGZ = $(DESTDIR).tar.gz |
| @@ -97,27 +99,28 @@ dist: | |||
| 97 | echo $(NEWDESTDIR); \ | 99 | echo $(NEWDESTDIR); \ |
| 98 | (cd $$i && $(MAKE) DESTDIR=$(builddir)/$(DESTDIR)/$$i $$target) || exit 1; \ | 100 | (cd $$i && $(MAKE) DESTDIR=$(builddir)/$(DESTDIR)/$$i $$target) || exit 1; \ |
| 99 | fi; \ | 101 | fi; \ |
| 100 | done; | 102 | done; \ |
| 101 | if test "$$made_local" != "yes"; then \ | 103 | if test "$$made_local" != "yes"; then \ |
| 102 | $(MAKE) "local-dist" || exit 1; \ | 104 | $(MAKE) "local-dist" || exit 1; \ |
| 103 | fi | 105 | fi; \ |
| 104 | tar -zcf $(DESTTGZ) $(DESTDIR) | 106 | tar -zcf $(DESTTGZ) $(DESTDIR); \ |
| 105 | rm -rf $(DESTDIR) | 107 | rm -rf $(DESTDIR); \ |
| 106 | 108 | ||
| 107 | local-dist: $(DISTFILES) | 109 | local-dist: $(DISTFILES) |
| 108 | mkdir -p $(DESTDIR) | 110 | @mkdir -p $(DESTDIR); \ |
| 109 | cp -dp --parents $(DISTFILES) $(DESTDIR) | 111 | cp -dp --parents $(DISTFILES) $(DESTDIR); |
| 110 | 112 | ||
| 111 | $(builddir)/.deps: depend | 113 | $(builddir)/.deps: depend |
| 112 | 114 | ||
| 113 | depend: $(SOURCES) $(HEADERS) | 115 | depend: $(SOURCES) $(HEADERS) |
| 114 | if test -n "`ls $(srcdir)/*.c 2> /dev/null`"; then \ | 116 | if test -n "`ls $(srcdir)/*.c 2> /dev/null`"; then \ |
| 115 | $(CC) -MM -I@APACHE_INCDIR@ @MOD_SSL_CFLAGS@ $(INCLUDES) -DHAVE_CONFIG_H $(srcdir)/*.c > $(builddir)/.deps || true; \ | 117 | $(CC) -MM -I@APACHE_INCDIR@ @MOD_SSL_CFLAGS@ $(INCLUDES) @DEFS@ \ |
| 118 | @APACHE_DEFS@ $(srcdir)/*.c > $(builddir)/.deps || true; \ | ||
| 116 | fi | 119 | fi |
| 117 | 120 | ||
| 118 | include $(builddir)/.deps | 121 | include $(builddir)/.deps |
| 119 | 122 | ||
| 120 | .PHONY: include all-subdirs update-subdirs install-subdirs \ | 123 | .PHONY: include all-subdirs activate-subdirs install-subdirs \ |
| 121 | clean-subdirs distclean-subdirs dist | 124 | clean-subdirs distclean-subdirs dist |
| 122 | 125 | ||
| 123 | # Regenerate makefiles | 126 | # 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 @@ | |||
| 1 | #ifndef APACHE13_H | ||
| 2 | #define APACHE13_H | ||
| 3 | |||
| 4 | #include "httpd.h" | ||
| 5 | #include "http_config.h" | ||
| 6 | #include "http_log.h" | ||
| 7 | #include "http_core.h" | ||
| 8 | |||
| 9 | /* Defines */ | ||
| 10 | #define AP_MODULE_DECLARE_DATA | ||
| 11 | #define APR_OFF_T_FMT "ld" | ||
| 12 | #define APR_PID_T_FMT "d" | ||
| 13 | #define APR_SUCCESS 0 | ||
| 14 | #define APR_OFFSETOF XtOffsetOf | ||
| 15 | |||
| 16 | /*AP_INIT_TAKE1("LogSQLTransferLogTable", set_server_nmv_string_slot, | ||
| 17 | (void *)APR_OFFSETOF(logsql_state, transfer_table_name), RSRC_CONF, | ||
| 18 | "The database table that holds the transfer log") | ||
| 19 | |||
| 20 | {"LogSQLTransferLogTable", set_log_sql_transfer_table, NULL, RSRC_CONF, TAKE1, | ||
| 21 | "The database table that holds the transfer log"}*/ | ||
| 22 | |||
| 23 | /** method of declaring a directive which takes 1 argument */ | ||
| 24 | # define AP_INIT_TAKE1(directive, func, mconfig, where, help) \ | ||
| 25 | { directive, func, mconfig, where, TAKE1, help } | ||
| 26 | /** method of declaring a directive which takes multiple arguments */ | ||
| 27 | # define AP_INIT_ITERATE(directive, func, mconfig, where, help) \ | ||
| 28 | { directive, func, mconfig, where, ITERATE, help } | ||
| 29 | /** method of declaring a directive which takes 3 arguments */ | ||
| 30 | # define AP_INIT_TAKE3(directive, func, mconfig, where, help) \ | ||
| 31 | { directive, func, mconfig, where, TAKE3, help } | ||
| 32 | /** method of declaring a directive which takes a flag (on/off) as an argument */ | ||
| 33 | # define AP_INIT_FLAG(directive, func, mconfig, where, help) \ | ||
| 34 | { directive, func, mconfig, where, FLAG, help } | ||
| 35 | |||
| 36 | /* Types */ | ||
| 37 | #define apr_pool_t pool | ||
| 38 | #define apr_array_header_t array_header | ||
| 39 | |||
| 40 | /* Functions */ | ||
| 41 | #define ap_get_remote_host(a,b,c,d) ap_get_remote_host(a,b,c) | ||
| 42 | |||
| 43 | #define apr_palloc ap_palloc | ||
| 44 | #define apr_pcalloc ap_pcalloc | ||
| 45 | #define apr_pstrdup ap_pstrdup | ||
| 46 | #define apr_pstrcat ap_pstrcat | ||
| 47 | #define apr_psprintf ap_psprintf | ||
| 48 | #define apr_snprintf ap_snprintf | ||
| 49 | |||
| 50 | #define apr_table_get ap_table_get | ||
| 51 | |||
| 52 | #define apr_array_push ap_push_array | ||
| 53 | #define apr_array_make ap_make_array | ||
| 54 | #define apr_array_cat ap_array_cat | ||
| 55 | #define apr_is_empty_array(t) (((t) == NULL)||((t)->nelts == 0)) | ||
| 56 | |||
| 57 | #define apr_tolower ap_tolower | ||
| 58 | |||
| 59 | #define log_error ap_log_error | ||
| 60 | |||
| 61 | #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 @@ | |||
| 1 | #ifndef APACHE20_H | ||
| 2 | #define APACHE20_H | ||
| 3 | |||
| 4 | #include "apr_strings.h" | ||
| 5 | #include "apr_lib.h" | ||
| 6 | #include "apr_hash.h" | ||
| 7 | #include "apr_optional.h" | ||
| 8 | #define APR_WANT_STRFUNC | ||
| 9 | #include "apr_want.h" | ||
| 10 | #include "apr_tables.h" | ||
| 11 | |||
| 12 | #include "ap_config.h" | ||
| 13 | |||
| 14 | #include "httpd.h" | ||
| 15 | #include "http_config.h" | ||
| 16 | #include "http_core.h" | ||
| 17 | #include "http_log.h" | ||
| 18 | #include "http_protocol.h" | ||
| 19 | |||
| 20 | #include "util_time.h" | ||
| 21 | |||
| 22 | static void log_error(char *file, int line, int level, const server_rec *s, const char *fmt, ...) __attribute__ ((format (printf, 5,6))); | ||
| 23 | static inline void log_error(char *file, int line, int level, const server_rec *s, const char *fmt, ...) | ||
| 24 | { | ||
| 25 | va_list args; | ||
| 26 | va_start(args, fmt); | ||
| 27 | ap_log_error(file,line,level,0,s,fmt,args); | ||
| 28 | va_end(args); | ||
| 29 | } | ||
| 30 | |||
| 31 | #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) | |||
| 8 | dnl Add a test for a compiler. | 8 | dnl Add a test for a compiler. |
| 9 | AC_PROG_CC | 9 | AC_PROG_CC |
| 10 | 10 | ||
| 11 | APACHE_VERSION=2.0.44 | 11 | APACHE20_VERSION=2.0.44 |
| 12 | CHECK_PATH_APACHE($APACHE_VERSION, | 12 | APACHE13_VERSION=1.3.20 |
| 13 | :, | 13 | CHECK_PATH_APACHE($APACHE13_VERSION,$APACHE20_VERSION, |
| 14 | AC_MSG_ERROR([*** Apache version $APACHE_VERSION not found!]) | 14 | :, |
| 15 | ) | 15 | :, |
| 16 | AC_MSG_ERROR([*** The correct version Apache was not found!]) | ||
| 17 | AC_MSG_ERROR([*** You need either Apache 1.3 version $APACHE13_VERSION or greater]) | ||
| 18 | AC_MSG_ERROR([*** or Apache 2.0/2.1 version $APACHE20_VERSION or greater!]) | ||
| 19 | ) | ||
| 16 | 20 | ||
| 17 | CHECK_PATH_MYSQL(:, | 21 | CHECK_PATH_MYSQL(:, |
| 18 | AC_MSG_ERROR([*** Mysql client libraries not found!]) | 22 | AC_MSG_ERROR([*** Mysql client libraries not found!]) |
| @@ -20,10 +24,8 @@ CHECK_PATH_MYSQL(:, | |||
| 20 | 24 | ||
| 21 | CHECK_PATH_MOD_SSL( | 25 | CHECK_PATH_MOD_SSL( |
| 22 | AC_DEFINE(WANT_SSL_LOGGING,,[Define if we want to compile in SSL support.]) | 26 | AC_DEFINE(WANT_SSL_LOGGING,,[Define if we want to compile in SSL support.]) |
| 23 | AC_MSG_WARN([*** Compilng with SSL support!]), | 27 | conf_SSL=1, |
| 24 | AC_MSG_WARN([*** Compiling without SSL support!]) | 28 | conf_SSL=0 |
| 25 | AC_MSG_WARN([*** enable with --enable-ssl to enable]) | ||
| 26 | AC_MSG_WARN([*** and --with-ssl-inc with the the directory for SSL headers]) | ||
| 27 | ) | 29 | ) |
| 28 | 30 | ||
| 29 | AC_CHECK_HEADERS(limits.h) | 31 | AC_CHECK_HEADERS(limits.h) |
| @@ -33,3 +35,13 @@ AC_CONFIG_FILES([stamp-h], [echo timestamp > stamp-h]) | |||
| 33 | dnl Write config.status and the Makefile | 35 | dnl Write config.status and the Makefile |
| 34 | 36 | ||
| 35 | AC_OUTPUT(Makefile Documentation/Makefile) | 37 | AC_OUTPUT(Makefile Documentation/Makefile) |
| 38 | |||
| 39 | AC_MSG_RESULT([------------------------------------]) | ||
| 40 | AC_MSG_RESULT([Apache version : $APACHE_VERSION]) | ||
| 41 | if test $conf_SSL -eq 1; then | ||
| 42 | AC_MSG_RESULT([SSL Support : yes]) | ||
| 43 | else | ||
| 44 | AC_MSG_RESULT([SSL Support : no]) | ||
| 45 | AC_MSG_RESULT([*** Use --enable-ssl to enable SSL support]) | ||
| 46 | AC_MSG_RESULT([*** and --with-ssl-inc for the directory for SSL headers]) | ||
| 47 | 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 @@ | |||
| 1 | static const char *extract_request_time(request_rec *r, char *a) | ||
| 2 | { | ||
| 3 | int timz; | ||
| 4 | struct tm *t; | ||
| 5 | char tstr[MAX_STRING_LEN]; | ||
| 6 | |||
| 7 | t = ap_get_gmtoff(&timz); | ||
| 8 | |||
| 9 | if (a && *a) { /* Custom format */ | ||
| 10 | strftime(tstr, MAX_STRING_LEN, a, t); | ||
| 11 | } else { /* CLF format */ | ||
| 12 | char sign = (timz < 0 ? '-' : '+'); | ||
| 13 | |||
| 14 | if (timz < 0) { | ||
| 15 | timz = -timz; | ||
| 16 | } | ||
| 17 | strftime(tstr, MAX_STRING_LEN, "[%d/%b/%Y:%H:%M:%S ", t); | ||
| 18 | ap_snprintf(tstr + strlen(tstr), sizeof(tstr) - strlen(tstr), "%c%.2d%.2d]", sign, timz / 60, timz % 60); | ||
| 19 | } | ||
| 20 | |||
| 21 | return ap_pstrdup(r->pool, tstr); | ||
| 22 | } | ||
| 23 | |||
| 24 | static const char *extract_request_duration(request_rec *r, char *a) | ||
| 25 | { | ||
| 26 | char duration[22]; /* Long enough for 2^64 */ | ||
| 27 | |||
| 28 | ap_snprintf(duration, sizeof(duration), "%ld", (long) time(NULL) - r->request_time); | ||
| 29 | return ap_pstrdup(r->pool, duration); | ||
| 30 | } | ||
| 31 | |||
| 32 | static const char *extract_request_timestamp(request_rec *r, char *a) | ||
| 33 | { | ||
| 34 | char tstr[32]; | ||
| 35 | |||
| 36 | ap_snprintf(tstr, 32, "%ld", (long) time(NULL)); | ||
| 37 | return ap_pstrdup(r->pool, tstr); | ||
| 38 | } | ||
diff --git a/functions20.h b/functions20.h new file mode 100644 index 0000000..9ff3a63 --- /dev/null +++ b/functions20.h | |||
| @@ -0,0 +1,92 @@ | |||
| 1 | /* functions */ | ||
| 2 | static const char *extract_request_time_custom(request_rec *r, char *a, | ||
| 3 | apr_time_exp_t *xt) | ||
| 4 | { | ||
| 5 | apr_size_t retcode; | ||
| 6 | char tstr[MAX_STRING_LEN]; | ||
| 7 | apr_strftime(tstr, &retcode, sizeof(tstr), a, xt); | ||
| 8 | return apr_pstrdup(r->pool, tstr); | ||
| 9 | } | ||
| 10 | |||
| 11 | #define DEFAULT_REQUEST_TIME_SIZE 32 | ||
| 12 | typedef struct { | ||
| 13 | unsigned t; | ||
| 14 | char timestr[DEFAULT_REQUEST_TIME_SIZE]; | ||
| 15 | unsigned t_validate; | ||
| 16 | } cached_request_time; | ||
| 17 | |||
| 18 | #define TIME_CACHE_SIZE 4 | ||
| 19 | #define TIME_CACHE_MASK 3 | ||
| 20 | static cached_request_time request_time_cache[TIME_CACHE_SIZE]; | ||
| 21 | |||
| 22 | static const char *extract_request_time(request_rec *r, char *a) | ||
| 23 | { | ||
| 24 | apr_time_exp_t xt; | ||
| 25 | |||
| 26 | /* Please read comments in mod_log_config.h for more info about | ||
| 27 | * the I_INSIST....COMPLIANCE define | ||
| 28 | */ | ||
| 29 | if (a && *a) { /* Custom format */ | ||
| 30 | #ifdef I_INSIST_ON_EXTRA_CYCLES_FOR_CLF_COMPLIANCE | ||
| 31 | ap_explode_recent_localtime(&xt, apr_time_now()); | ||
| 32 | #else | ||
| 33 | ap_explode_recent_localtime(&xt, r->request_time); | ||
| 34 | #endif | ||
| 35 | return extract_request_time_custom(r, a, &xt); | ||
| 36 | } else { /* CLF format */ | ||
| 37 | /* This code uses the same technique as ap_explode_recent_localtime(): | ||
| 38 | * optimistic caching with logic to detect and correct race conditions. | ||
| 39 | * See the comments in server/util_time.c for more information. | ||
| 40 | */ | ||
| 41 | cached_request_time* cached_time = apr_palloc(r->pool, | ||
| 42 | sizeof(*cached_time)); | ||
| 43 | #ifdef I_INSIST_ON_EXTRA_CYCLES_FOR_CLF_COMPLIANCE | ||
| 44 | apr_time_t request_time = apr_time_now(); | ||
| 45 | #else | ||
| 46 | apr_time_t request_time = r->request_time; | ||
| 47 | #endif | ||
| 48 | unsigned t_seconds = (unsigned)apr_time_sec(request_time); | ||
| 49 | unsigned i = t_seconds & TIME_CACHE_MASK; | ||
| 50 | memcpy(cached_time, &(request_time_cache[i]), sizeof(*cached_time)); | ||
| 51 | if ((t_seconds != cached_time->t) || | ||
| 52 | (t_seconds != cached_time->t_validate)) { | ||
| 53 | |||
| 54 | /* Invalid or old snapshot, so compute the proper time string | ||
| 55 | * and store it in the cache | ||
| 56 | */ | ||
| 57 | char sign; | ||
| 58 | int timz; | ||
| 59 | |||
| 60 | ap_explode_recent_localtime(&xt, r->request_time); | ||
| 61 | timz = xt.tm_gmtoff; | ||
| 62 | if (timz < 0) { | ||
| 63 | timz = -timz; | ||
| 64 | sign = '-'; | ||
| 65 | } | ||
| 66 | else { | ||
| 67 | sign = '+'; | ||
| 68 | } | ||
| 69 | cached_time->t = t_seconds; | ||
| 70 | apr_snprintf(cached_time->timestr, DEFAULT_REQUEST_TIME_SIZE, | ||
| 71 | "[%02d/%s/%d:%02d:%02d:%02d %c%.2d%.2d]", | ||
| 72 | xt.tm_mday, apr_month_snames[xt.tm_mon], | ||
| 73 | xt.tm_year+1900, xt.tm_hour, xt.tm_min, xt.tm_sec, | ||
| 74 | sign, timz / (60*60), timz % (60*60)); | ||
| 75 | cached_time->t_validate = t_seconds; | ||
| 76 | memcpy(&(request_time_cache[i]), cached_time, | ||
| 77 | sizeof(*cached_time)); | ||
| 78 | } | ||
| 79 | return cached_time->timestr; | ||
| 80 | } | ||
| 81 | } | ||
| 82 | |||
| 83 | static const char *extract_request_duration(request_rec *r, char *a) | ||
| 84 | { | ||
| 85 | apr_time_t duration = apr_time_now() - r->request_time; | ||
| 86 | return apr_psprintf(r->pool, "%" APR_TIME_T_FMT, apr_time_sec(duration)); | ||
| 87 | } | ||
| 88 | |||
| 89 | static const char *extract_request_timestamp(request_rec *r, char *a) | ||
| 90 | { | ||
| 91 | return apr_psprintf(r->pool, "%"APR_TIME_T_FMT, apr_time_sec(apr_time_now())); | ||
| 92 | } | ||
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 @@ | |||
| 1 | dnl CHECK_PATH_APACHE([MINIMUM-VERSION, [ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND]]]) | 1 | dnl TEST_APACHE_VERSION([MINIMUM-VERSION [, ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND]]]) |
| 2 | dnl Test for Apache apxs | 2 | dnl Test for Apache |
| 3 | dnl | 3 | dnl |
| 4 | AC_DEFUN(CHECK_PATH_APACHE, | 4 | AC_DEFUN(TEST_APACHE_VERSION, |
| 5 | [dnl | 5 | [dnl |
| 6 | AC_ARG_WITH( | ||
| 7 | apxs, | ||
| 8 | [AC_HELP_STRING([--with-apxs=PATH],[Location to APXS binary (default: /usr)])], | ||
| 9 | apxs_prefix="$withval", | ||
| 10 | apxs_prefix="/usr" | ||
| 11 | ) | ||
| 12 | AC_ARG_ENABLE(apachetest, | ||
| 13 | [AC_HELP_STRING([--disable-apachetest],[Do not try to compile and run apache version test program])], | ||
| 14 | , | ||
| 15 | enable_apachetest=yes) | ||
| 16 | |||
| 17 | |||
| 18 | AC_REQUIRE([AC_CANONICAL_TARGET]) | 6 | AC_REQUIRE([AC_CANONICAL_TARGET]) |
| 19 | PATH="$apxs_prefix:$apxs_prefix/bin:$apxs_prefix/sbin:$PATH" | ||
| 20 | if test -x $apxs_prefix && test ! -d $apxs_prefix; then | ||
| 21 | APXS_BIN=$apxs_prefix | ||
| 22 | else | ||
| 23 | AC_PATH_PROG(APXS_BIN, apxs, no, [$PATH]) | ||
| 24 | fi | ||
| 25 | min_apache_version=ifelse([$1], ,1.3.1,$1) | ||
| 26 | AC_MSG_CHECKING(for Apache - version >= $min_apache_version) | ||
| 27 | no_apxs="" | ||
| 28 | if test "$APXS_BIN" == "no"; then | ||
| 29 | no_apxs=yes | ||
| 30 | else | ||
| 31 | APACHE_INCDIR=`$APXS_BIN -q INCLUDEDIR` | ||
| 32 | APACHE_CFLAGS=-I$APACHE_INCDIR | ||
| 33 | APACHE_MODDIR=`$APXS_BIN -q LIBEXECDIR` | ||
| 34 | 7 | ||
| 35 | if test "x$enable_apachetest" = "xyes" ; then | 8 | min_apache_version="$1" |
| 36 | ac_save_CFLAGS="$CFLAGS" | 9 | no_apache="" |
| 37 | CFLAGS="$CFLAGS $APACHE_CFLAGS" | 10 | ac_save_CFLAGS="$CFLAGS" |
| 38 | AC_TRY_RUN([ | 11 | CFLAGS="$CFLAGS $APACHE_CFLAGS" |
| 12 | |||
| 13 | AC_TRY_RUN([ | ||
| 39 | #include <stdio.h> | 14 | #include <stdio.h> |
| 40 | #include <stdlib.h> | 15 | #include <stdlib.h> |
| 41 | #include <string.h> | 16 | #include <string.h> |
| @@ -80,37 +55,29 @@ int main (int argc, char *argv[]) | |||
| 80 | ((major2 == major1) && (minor2 > minor1)) || | 55 | ((major2 == major1) && (minor2 > minor1)) || |
| 81 | ((major2 == major1) && (minor2 == minor1) && (micro2 >= micro1))) | 56 | ((major2 == major1) && (minor2 == minor1) && (micro2 >= micro1))) |
| 82 | { | 57 | { |
| 83 | return 0; | 58 | exit(0); |
| 84 | } else { | 59 | } else { |
| 85 | printf("\n*** This module requires apache version %d.%d.%d or greater\n", | 60 | /*printf("\n*** This module requires apache version %d.%d.%d or greater\n", |
| 86 | major1, minor1, micro1); | 61 | major1, minor1, micro1); |
| 87 | printf("*** I found version %d.%d.%d. Please verify the installation directory\n", | 62 | printf("*** I found version %d.%d.%d. Please verify the installation directory\n", |
| 88 | major2, minor2, micro2); | 63 | major2, minor2, micro2); |
| 89 | printf("*** of apache with the --with-apxs configure option.\n"); | 64 | printf("*** of apache with the --with-apxs configure option.\n");*/ |
| 90 | return 1; | 65 | exit(1); |
| 91 | } | 66 | } |
| 92 | } | 67 | } |
| 93 | 68 | ||
| 94 | ],, no_apxs=yes,[echo $ac_n "cross compiling; assumed OK... $ac_c"]) | 69 | ],, no_apache=yes,[echo $ac_n "cross compiling; assumed OK... $ac_c"]) |
| 95 | CFLAGS="$ac_save_CFLAGS" | 70 | CFLAGS="$ac_save_CFLAGS" |
| 96 | fi | 71 | |
| 97 | fi | 72 | if test "x$no_apache" = x ; then |
| 98 | if test "x$no_apxs" = x ; then | ||
| 99 | AC_MSG_RESULT(yes) | ||
| 100 | ifelse([$2], , :, [$2]) | 73 | ifelse([$2], , :, [$2]) |
| 101 | else | 74 | else |
| 102 | AC_MSG_RESULT(no) | 75 | if test -f conf.apachetest ; then |
| 103 | if test "$APXS_BIN" = "no" ; then | 76 | : |
| 104 | echo "*** The apxs binary installed by apache could not be found" | ||
| 105 | echo "*** If apache is installed in PREFIX, make sure PREFIX/bin is in" | ||
| 106 | echo "*** your path, or use the --with-apxs configure option" | ||
| 107 | else | 77 | else |
| 108 | if test -f conf.apachetest ; then | 78 | echo "*** Could not run Apache test program, checking why..." |
| 109 | : | 79 | CFLAGS="$CFLAGS APACHE_CFLAGS" |
| 110 | else | 80 | AC_TRY_LINK([ |
| 111 | echo "*** Could not run Apache test program, checking why..." | ||
| 112 | CFLAGS="$CFLAGS APACHE_CFLAGS" | ||
| 113 | AC_TRY_LINK([ | ||
| 114 | #include <stdio.h> | 81 | #include <stdio.h> |
| 115 | #include "httpd.h" | 82 | #include "httpd.h" |
| 116 | 83 | ||
| @@ -118,17 +85,88 @@ int main(int argc, char *argv[]) | |||
| 118 | { return 0; } | 85 | { return 0; } |
| 119 | #undef main | 86 | #undef main |
| 120 | #define main K_and_R_C_main | 87 | #define main K_and_R_C_main |
| 121 | ], [ return 0; ], | 88 | ], [ return 0; ], |
| 122 | [ echo "*** The test program compiled, but failed to run. Check config.log" ], | 89 | [ echo "*** The test program compiled, but failed to run. Check config.log" ], |
| 123 | [ echo "*** The test program failed to compile or link. Check config.log" ]) | 90 | [ echo "*** The test program failed to compile or link. Check config.log" ]) |
| 124 | CFLAGS="$ac_save_CFLAGS" | 91 | CFLAGS="$ac_save_CFLAGS" |
| 125 | fi | ||
| 126 | fi | 92 | fi |
| 127 | APACHE_CFLAGS="" | ||
| 128 | ifelse([$3], , :, [$3]) | 93 | ifelse([$3], , :, [$3]) |
| 129 | fi | 94 | fi |
| 130 | AC_SUBST(APACHE_CFLAGS) | ||
| 131 | AC_SUBST(APACHE_INCDIR) | ||
| 132 | AC_SUBST(APACHE_MODDIR) | ||
| 133 | rm -f conf.apachetest | 95 | rm -f conf.apachetest |
| 134 | ]) | 96 | ]) |
| 97 | |||
| 98 | dnl CHECK_PATH_APACHE([MINIMUM13-VERSION [, MINIMUM20-VERSION [, | ||
| 99 | dnl ACTION-IF-FOUND13 [, ACTION-IF-FOUND20 [, ACTION-IF-NOT-FOUND]]]) | ||
| 100 | dnl Test for Apache apxs | ||
| 101 | dnl | ||
| 102 | AC_DEFUN(CHECK_PATH_APACHE, | ||
| 103 | [dnl | ||
| 104 | AC_ARG_WITH( | ||
| 105 | apxs, | ||
| 106 | [AC_HELP_STRING([--with-apxs=PATH],[Location to APXS binary (default: /usr)])], | ||
| 107 | apxs_prefix="$withval", | ||
| 108 | apxs_prefix="/usr" | ||
| 109 | ) | ||
| 110 | AC_ARG_ENABLE( | ||
| 111 | apachetest, | ||
| 112 | [AC_HELP_STRING([--disable-apachetest],[Do not try to compile and run apache version test program])], | ||
| 113 | , | ||
| 114 | enable_apachetest=yes | ||
| 115 | ) | ||
| 116 | |||
| 117 | PATH="$apxs_prefix:$apxs_prefix/bin:$apxs_prefix/sbin:$PATH" | ||
| 118 | if test -x $apxs_prefix -a ! -d $apxs_prefix; then | ||
| 119 | APXS_BIN=$apxs_prefix | ||
| 120 | else | ||
| 121 | AC_PATH_PROG(APXS_BIN, apxs, no, [$PATH]) | ||
| 122 | fi | ||
| 123 | min_apache13_version=ifelse([$1], ,no,$1) | ||
| 124 | min_apache20_version=ifelse([$2], ,no,$2) | ||
| 125 | no_apxs="" | ||
| 126 | if test "$APXS_BIN" = "no"; then | ||
| 127 | AC_MSG_ERROR([*** The apxs binary installed by apache could not be found!]) | ||
| 128 | AC_MSG_ERROR([*** If apache is installed in PREFIX, make sure PREFIX/bin is in]) | ||
| 129 | AC_MSG_ERROR([*** your path, or use the --with-apxs configure option]) | ||
| 130 | else | ||
| 131 | APACHE_INCDIR=`$APXS_BIN -q INCLUDEDIR` | ||
| 132 | APACHE_CFLAGS=-I$APACHE_INCDIR | ||
| 133 | APACHE_MODDIR=`$APXS_BIN -q LIBEXECDIR` | ||
| 134 | |||
| 135 | if test "x$enable_apachetest" = "xyes" ; then | ||
| 136 | if test "$min_apache20_version" != "no"; then | ||
| 137 | AC_MSG_CHECKING(for Apache 2.0 version >= $min_apache20_version) | ||
| 138 | TEST_APACHE_VERSION($min_apache20_version, | ||
| 139 | AC_MSG_RESULT(yes) | ||
| 140 | AC_DEFINE(WITH_APACHE20,1,[Define to 1 if we are compiling with Apache 2.0.x]) | ||
| 141 | APACHE_VERSION="20" | ||
| 142 | APACHE_OUTPUT_NAME=$PACKAGE_NAME.la | ||
| 143 | APACHE_DEFS="-DWITH_APACHE20" | ||
| 144 | ifelse([$4], , , $4), | ||
| 145 | AC_MSG_RESULT(no) | ||
| 146 | if test "x$min_apache13_version" = "xno"; then | ||
| 147 | ifelse([$5], , , $5) | ||
| 148 | fi | ||
| 149 | ) | ||
| 150 | fi | ||
| 151 | if test "$min_apache13_version" != "no" -a "x$APACHE_VERSION" = "x"; then | ||
| 152 | AC_MSG_CHECKING(for Apache 1.3 version >= $min_apache13_version) | ||
| 153 | TEST_APACHE_VERSION($min_apache13_version, | ||
| 154 | AC_MSG_RESULT(yes) | ||
| 155 | AC_DEFINE(WITH_APACHE13,1,[Define to 1 if we are compiling with Apache 1.3.x]) | ||
| 156 | APACHE_VERSION="13" | ||
| 157 | APACHE_OUTPUT_NAME=$PACKAGE_NAME.so | ||
| 158 | APACHE_DEFS="-DWITH_APACHE13" | ||
| 159 | ifelse([$3], , , $3), | ||
| 160 | AC_MSG_RESULT(no) | ||
| 161 | ifelse([$5], , , $5) | ||
| 162 | ) | ||
| 163 | fi | ||
| 164 | fi | ||
| 165 | AC_SUBST(APACHE_DEFS) | ||
| 166 | AC_SUBST(APACHE_CFLAGS) | ||
| 167 | AC_SUBST(APACHE_INCDIR) | ||
| 168 | AC_SUBST(APACHE_MODDIR) | ||
| 169 | AC_SUBST(APACHE_VERSION) | ||
| 170 | AC_SUBST(APACHE_OUTPUT_NAME) | ||
| 171 | fi | ||
| 172 | ]) | ||
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( | |||
| 15 | ssl_incdir="$withval", | 15 | ssl_incdir="$withval", |
| 16 | ) | 16 | ) |
| 17 | 17 | ||
| 18 | if test "$ssl_val" = "yes"; then | 18 | if test "x$ssl_val" = "xyes"; then |
| 19 | ac_save_CFLAGS=$CFLAGS | 19 | ac_save_CFLAGS=$CFLAGS |
| 20 | ac_save_CPPFLAGS=$CPPFLAGS | 20 | ac_save_CPPFLAGS=$CPPFLAGS |
| 21 | MOD_SSL_CFLAGS="-I/usr/include/openssl" | 21 | 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 @@ | |||
| 1 | /* $Header: /home/cvs/mod_log_sql/mod_log_sql.c,v 1.6 2004/01/04 03:23:21 urkle Exp $ */ | 1 | /* $Header: /home/cvs/mod_log_sql/mod_log_sql.c,v 1.7 2004/01/20 16:27:34 urkle Exp $ */ |
| 2 | /* --------* | 2 | /* --------* |
| 3 | * DEFINES * | 3 | * DEFINES * |
| 4 | * --------*/ | 4 | * --------*/ |
| @@ -12,24 +12,16 @@ | |||
| 12 | /* ---------* | 12 | /* ---------* |
| 13 | * INCLUDES * | 13 | * INCLUDES * |
| 14 | * ---------*/ | 14 | * ---------*/ |
| 15 | #include "mysql.h" | ||
| 16 | #include "mysqld_error.h" | ||
| 15 | 17 | ||
| 16 | #include "apr_strings.h" | 18 | #if defined(WITH_APACHE20) |
| 17 | #include "apr_lib.h" | 19 | # include "apache20.h" |
| 18 | #include "apr_hash.h" | 20 | #elif defined(WITH_APACHE13) |
| 19 | #include "apr_optional.h" | 21 | # include "apache13.h" |
| 20 | #define APR_WANT_STRFUNC | 22 | #else |
| 21 | #include "apr_want.h" | 23 | # error Unsupported Apache version |
| 22 | #include "apr_tables.h" | 24 | #endif |
| 23 | |||
| 24 | #include "ap_config.h" | ||
| 25 | |||
| 26 | #include "httpd.h" | ||
| 27 | #include "http_config.h" | ||
| 28 | #include "http_core.h" | ||
| 29 | #include "http_log.h" | ||
| 30 | #include "http_protocol.h" | ||
| 31 | |||
| 32 | #include "util_time.h" | ||
| 33 | 25 | ||
| 34 | #ifdef HAVE_CONFIG_H | 26 | #ifdef HAVE_CONFIG_H |
| 35 | /* Undefine these to prevent conflicts between Apache ap_config_auto.h and | 27 | /* Undefine these to prevent conflicts between Apache ap_config_auto.h and |
| @@ -51,8 +43,6 @@ | |||
| 51 | #include <limits.h> | 43 | #include <limits.h> |
| 52 | #endif | 44 | #endif |
| 53 | 45 | ||
| 54 | #include "mysql.h" | ||
| 55 | #include "mysqld_error.h" | ||
| 56 | 46 | ||
| 57 | #ifdef WANT_SSL_LOGGING | 47 | #ifdef WANT_SSL_LOGGING |
| 58 | #include "mod_ssl.h" | 48 | #include "mod_ssl.h" |
| @@ -164,8 +154,11 @@ static const char *extract_remote_logname(request_rec *r, char *a) | |||
| 164 | 154 | ||
| 165 | static const char *extract_remote_user(request_rec *r, char *a) | 155 | static const char *extract_remote_user(request_rec *r, char *a) |
| 166 | { | 156 | { |
| 157 | #ifdef WITH_APACHE13 | ||
| 158 | char *rvalue = r->connection->user; | ||
| 159 | #else | ||
| 167 | char *rvalue = r->user; | 160 | char *rvalue = r->user; |
| 168 | 161 | #endif | |
| 169 | if (rvalue == NULL) { | 162 | if (rvalue == NULL) { |
| 170 | rvalue = "-"; | 163 | rvalue = "-"; |
| 171 | } else if (strlen(rvalue) == 0) { | 164 | } else if (strlen(rvalue) == 0) { |
| @@ -184,7 +177,7 @@ static const char *extract_ssl_keysize(request_rec *r, char *a) | |||
| 184 | if (myCtxConfig(scc,ssc) != NULL) { | 177 | if (myCtxConfig(scc,ssc) != NULL) { |
| 185 | result = ssl_var_lookup(r->pool, r->server, r->connection, r, "SSL_CIPHER_USEKEYSIZE"); | 178 | result = ssl_var_lookup(r->pool, r->server, r->connection, r, "SSL_CIPHER_USEKEYSIZE"); |
| 186 | #ifdef DEBUG | 179 | #ifdef DEBUG |
| 187 | ap_log_error(APLOG_MARK,APLOG_DEBUG,0,r->server,"SSL_KEYSIZE: %s", result); | 180 | log_error(APLOG_MARK,APLOG_DEBUG,0,r->server,"SSL_KEYSIZE: %s", result); |
| 188 | #endif | 181 | #endif |
| 189 | if (result != NULL && result[0] == '\0') | 182 | if (result != NULL && result[0] == '\0') |
| 190 | result = NULL; | 183 | result = NULL; |
| @@ -203,7 +196,7 @@ static const char *extract_ssl_maxkeysize(request_rec *r, char *a) | |||
| 203 | if (myCtxConfig(scc,ssc) != NULL) { | 196 | if (myCtxConfig(scc,ssc) != NULL) { |
| 204 | result = ssl_var_lookup(r->pool, r->server, r->connection, r, "SSL_CIPHER_ALGKEYSIZE"); | 197 | result = ssl_var_lookup(r->pool, r->server, r->connection, r, "SSL_CIPHER_ALGKEYSIZE"); |
| 205 | #ifdef DEBUG | 198 | #ifdef DEBUG |
| 206 | ap_log_error(APLOG_MARK,APLOG_DEBUG,0,r->server,"SSL_ALGKEYSIZE: %s", result); | 199 | log_error(APLOG_MARK,APLOG_DEBUG,0,r->server,"SSL_ALGKEYSIZE: %s", result); |
| 207 | #endif | 200 | #endif |
| 208 | if (result != NULL && result[0] == '\0') | 201 | if (result != NULL && result[0] == '\0') |
| 209 | result = NULL; | 202 | result = NULL; |
| @@ -222,7 +215,7 @@ static const char *extract_ssl_cipher(request_rec *r, char *a) | |||
| 222 | if (myCtxConfig(scc,ssc) != NULL) { | 215 | if (myCtxConfig(scc,ssc) != NULL) { |
| 223 | result = ssl_var_lookup(r->pool, r->server, r->connection, r, "SSL_CIPHER"); | 216 | result = ssl_var_lookup(r->pool, r->server, r->connection, r, "SSL_CIPHER"); |
| 224 | #ifdef DEBUG | 217 | #ifdef DEBUG |
| 225 | ap_log_error(APLOG_MARK,APLOG_DEBUG,0,r->server,"SSL_CIPHER: %s", result); | 218 | log_error(APLOG_MARK,APLOG_DEBUG,0,r->server,"SSL_CIPHER: %s", result); |
| 226 | #endif | 219 | #endif |
| 227 | if (result != NULL && result[0] == '\0') | 220 | if (result != NULL && result[0] == '\0') |
| 228 | result = NULL; | 221 | result = NULL; |
| @@ -295,93 +288,12 @@ static const char *extract_header_out(request_rec *r, char *a) | |||
| 295 | return table_get(r->err_headers_out, a); | 288 | return table_get(r->err_headers_out, a); |
| 296 | } | 289 | } |
| 297 | */ | 290 | */ |
| 298 | static const char *extract_request_time_custom(request_rec *r, char *a, | ||
| 299 | apr_time_exp_t *xt) | ||
| 300 | { | ||
| 301 | apr_size_t retcode; | ||
| 302 | char tstr[MAX_STRING_LEN]; | ||
| 303 | apr_strftime(tstr, &retcode, sizeof(tstr), a, xt); | ||
| 304 | return apr_pstrdup(r->pool, tstr); | ||
| 305 | } | ||
| 306 | |||
| 307 | #define DEFAULT_REQUEST_TIME_SIZE 32 | ||
| 308 | typedef struct { | ||
| 309 | unsigned t; | ||
| 310 | char timestr[DEFAULT_REQUEST_TIME_SIZE]; | ||
| 311 | unsigned t_validate; | ||
| 312 | } cached_request_time; | ||
| 313 | |||
| 314 | #define TIME_CACHE_SIZE 4 | ||
| 315 | #define TIME_CACHE_MASK 3 | ||
| 316 | static cached_request_time request_time_cache[TIME_CACHE_SIZE]; | ||
| 317 | |||
| 318 | static const char *extract_request_time(request_rec *r, char *a) | ||
| 319 | { | ||
| 320 | apr_time_exp_t xt; | ||
| 321 | 291 | ||
| 322 | /* Please read comments in mod_log_config.h for more info about | 292 | #if defined(WITH_APACHE13) |
| 323 | * the I_INSIST....COMPLIANCE define | 293 | #include "functions13.h" |
| 324 | */ | 294 | #elif defined(WITH_APACHE20) |
| 325 | if (a && *a) { /* Custom format */ | 295 | #include "functions20.h" |
| 326 | #ifdef I_INSIST_ON_EXTRA_CYCLES_FOR_CLF_COMPLIANCE | ||
| 327 | ap_explode_recent_localtime(&xt, apr_time_now()); | ||
| 328 | #else | ||
| 329 | ap_explode_recent_localtime(&xt, r->request_time); | ||
| 330 | #endif | ||
| 331 | return extract_request_time_custom(r, a, &xt); | ||
| 332 | } else { /* CLF format */ | ||
| 333 | /* This code uses the same technique as ap_explode_recent_localtime(): | ||
| 334 | * optimistic caching with logic to detect and correct race conditions. | ||
| 335 | * See the comments in server/util_time.c for more information. | ||
| 336 | */ | ||
| 337 | cached_request_time* cached_time = apr_palloc(r->pool, | ||
| 338 | sizeof(*cached_time)); | ||
| 339 | #ifdef I_INSIST_ON_EXTRA_CYCLES_FOR_CLF_COMPLIANCE | ||
| 340 | apr_time_t request_time = apr_time_now(); | ||
| 341 | #else | ||
| 342 | apr_time_t request_time = r->request_time; | ||
| 343 | #endif | 296 | #endif |
| 344 | unsigned t_seconds = (unsigned)apr_time_sec(request_time); | ||
| 345 | unsigned i = t_seconds & TIME_CACHE_MASK; | ||
| 346 | memcpy(cached_time, &(request_time_cache[i]), sizeof(*cached_time)); | ||
| 347 | if ((t_seconds != cached_time->t) || | ||
| 348 | (t_seconds != cached_time->t_validate)) { | ||
| 349 | |||
| 350 | /* Invalid or old snapshot, so compute the proper time string | ||
| 351 | * and store it in the cache | ||
| 352 | */ | ||
| 353 | char sign; | ||
| 354 | int timz; | ||
| 355 | |||
| 356 | ap_explode_recent_localtime(&xt, r->request_time); | ||
| 357 | timz = xt.tm_gmtoff; | ||
| 358 | if (timz < 0) { | ||
| 359 | timz = -timz; | ||
| 360 | sign = '-'; | ||
| 361 | } | ||
| 362 | else { | ||
| 363 | sign = '+'; | ||
| 364 | } | ||
| 365 | cached_time->t = t_seconds; | ||
| 366 | apr_snprintf(cached_time->timestr, DEFAULT_REQUEST_TIME_SIZE, | ||
| 367 | "[%02d/%s/%d:%02d:%02d:%02d %c%.2d%.2d]", | ||
| 368 | xt.tm_mday, apr_month_snames[xt.tm_mon], | ||
| 369 | xt.tm_year+1900, xt.tm_hour, xt.tm_min, xt.tm_sec, | ||
| 370 | sign, timz / (60*60), timz % (60*60)); | ||
| 371 | cached_time->t_validate = t_seconds; | ||
| 372 | memcpy(&(request_time_cache[i]), cached_time, | ||
| 373 | sizeof(*cached_time)); | ||
| 374 | } | ||
| 375 | return cached_time->timestr; | ||
| 376 | } | ||
| 377 | } | ||
| 378 | |||
| 379 | static const char *extract_request_duration(request_rec *r, char *a) | ||
| 380 | { | ||
| 381 | apr_time_t duration = apr_time_now() - r->request_time; | ||
| 382 | return apr_psprintf(r->pool, "%" APR_TIME_T_FMT, apr_time_sec(duration)); | ||
| 383 | } | ||
| 384 | |||
| 385 | static const char *extract_virtual_host(request_rec *r, char *a) | 297 | static const char *extract_virtual_host(request_rec *r, char *a) |
| 386 | { | 298 | { |
| 387 | return apr_pstrdup(r->pool, r->server->server_hostname); | 299 | return apr_pstrdup(r->pool, r->server->server_hostname); |
| @@ -456,7 +368,7 @@ static const char *extract_cookie(request_rec *r, char *a) | |||
| 456 | 368 | ||
| 457 | if (cls->cookie_name != NULL) { | 369 | if (cls->cookie_name != NULL) { |
| 458 | #ifdef DEBUG | 370 | #ifdef DEBUG |
| 459 | ap_log_rerror(APLOG_MARK,APLOG_DEBUG,0, r, | 371 | log_error(APLOG_MARK,APLOG_DEBUG, r->server, |
| 460 | "watching for cookie '%s'", cls->cookie_name); | 372 | "watching for cookie '%s'", cls->cookie_name); |
| 461 | #endif | 373 | #endif |
| 462 | 374 | ||
| @@ -464,7 +376,7 @@ static const char *extract_cookie(request_rec *r, char *a) | |||
| 464 | cookiestr = (char *)apr_table_get(r->headers_in, "cookie2"); | 376 | cookiestr = (char *)apr_table_get(r->headers_in, "cookie2"); |
| 465 | if (cookiestr != NULL) { | 377 | if (cookiestr != NULL) { |
| 466 | #ifdef DEBUG | 378 | #ifdef DEBUG |
| 467 | ap_log_rerror(APLOG_MARK,APLOG_DEBUG,0, r, | 379 | log_error(APLOG_MARK,APLOG_DEBUG, r->server, |
| 468 | "Cookie2: [%s]", cookiestr); | 380 | "Cookie2: [%s]", cookiestr); |
| 469 | #endif | 381 | #endif |
| 470 | /* Does the cookie string contain one with our name? */ | 382 | /* Does the cookie string contain one with our name? */ |
| @@ -486,7 +398,7 @@ static const char *extract_cookie(request_rec *r, char *a) | |||
| 486 | cookiestr = (char *)apr_table_get(r->headers_in, "cookie"); | 398 | cookiestr = (char *)apr_table_get(r->headers_in, "cookie"); |
| 487 | if (cookiestr != NULL) { | 399 | if (cookiestr != NULL) { |
| 488 | #ifdef DEBUG | 400 | #ifdef DEBUG |
| 489 | ap_log_rerror(APLOG_MARK,APLOG_DEBUG,0,r, | 401 | log_error(APLOG_MARK,APLOG_DEBUG,r->server, |
| 490 | "Cookie: [%s]", cookiestr); | 402 | "Cookie: [%s]", cookiestr); |
| 491 | #endif | 403 | #endif |
| 492 | isvalid = strstr(cookiestr, cls->cookie_name); | 404 | isvalid = strstr(cookiestr, cls->cookie_name); |
| @@ -503,7 +415,7 @@ static const char *extract_cookie(request_rec *r, char *a) | |||
| 503 | cookiestr = apr_table_get(r->headers_out, "set-cookie"); | 415 | cookiestr = apr_table_get(r->headers_out, "set-cookie"); |
| 504 | if (cookiestr != NULL) { | 416 | if (cookiestr != NULL) { |
| 505 | #ifdef DEBUG | 417 | #ifdef DEBUG |
| 506 | ap_log_rerror(APLOG_MARK,APLOG_DEBUG,0,r, | 418 | log_error(APLOG_MARK,APLOG_DEBUG,r->server, |
| 507 | "Set-Cookie: [%s]", cookiestr); | 419 | "Set-Cookie: [%s]", cookiestr); |
| 508 | #endif | 420 | #endif |
| 509 | isvalid = strstr(cookiestr, cls->cookie_name); | 421 | isvalid = strstr(cookiestr, cls->cookie_name); |
| @@ -530,15 +442,15 @@ static const char *extract_specific_cookie(request_rec *r, char *a) | |||
| 530 | 442 | ||
| 531 | if (a != NULL) { | 443 | if (a != NULL) { |
| 532 | #ifdef DEBUG | 444 | #ifdef DEBUG |
| 533 | ap_log_rerror(APLOG_MARK,APLOG_DEBUG,0, | 445 | log_error(APLOG_MARK,APLOG_DEBUG, |
| 534 | r,"watching for cookie '%s'", a); | 446 | r->server,"watching for cookie '%s'", a); |
| 535 | #endif | 447 | #endif |
| 536 | 448 | ||
| 537 | /* Fetch out the cookie header */ | 449 | /* Fetch out the cookie header */ |
| 538 | cookiestr = (char *)apr_table_get(r->headers_in, "cookie2"); | 450 | cookiestr = (char *)apr_table_get(r->headers_in, "cookie2"); |
| 539 | if (cookiestr != NULL) { | 451 | if (cookiestr != NULL) { |
| 540 | #ifdef DEBUG | 452 | #ifdef DEBUG |
| 541 | ap_log_rerror(APLOG_MARK,APLOG_DEBUG,0,r, | 453 | log_error(APLOG_MARK,APLOG_DEBUG,r->server, |
| 542 | "Cookie2: [%s]", cookiestr); | 454 | "Cookie2: [%s]", cookiestr); |
| 543 | #endif | 455 | #endif |
| 544 | /* Does the cookie string contain one with our name? */ | 456 | /* Does the cookie string contain one with our name? */ |
| @@ -560,7 +472,7 @@ static const char *extract_specific_cookie(request_rec *r, char *a) | |||
| 560 | cookiestr = (char *)apr_table_get(r->headers_in, "cookie"); | 472 | cookiestr = (char *)apr_table_get(r->headers_in, "cookie"); |
| 561 | if (cookiestr != NULL) { | 473 | if (cookiestr != NULL) { |
| 562 | #ifdef DEBUG | 474 | #ifdef DEBUG |
| 563 | ap_log_rerror(APLOG_MARK,APLOG_DEBUG,0,r, | 475 | log_error(APLOG_MARK,APLOG_DEBUG,r->server, |
| 564 | "Cookie: [%s]", cookiestr); | 476 | "Cookie: [%s]", cookiestr); |
| 565 | #endif | 477 | #endif |
| 566 | isvalid = strstr(cookiestr, a); | 478 | isvalid = strstr(cookiestr, a); |
| @@ -577,7 +489,7 @@ static const char *extract_specific_cookie(request_rec *r, char *a) | |||
| 577 | cookiestr = apr_table_get(r->headers_out, "set-cookie"); | 489 | cookiestr = apr_table_get(r->headers_out, "set-cookie"); |
| 578 | if (cookiestr != NULL) { | 490 | if (cookiestr != NULL) { |
| 579 | #ifdef DEBUG | 491 | #ifdef DEBUG |
| 580 | ap_log_rerror(APLOG_MARK,APLOG_DEBUG,0,r, | 492 | log_error(APLOG_MARK,APLOG_DEBUG,r->server, |
| 581 | "Set-Cookie: [%s]", cookiestr); | 493 | "Set-Cookie: [%s]", cookiestr); |
| 582 | #endif | 494 | #endif |
| 583 | isvalid = strstr(cookiestr, a); | 495 | isvalid = strstr(cookiestr, a); |
| @@ -596,11 +508,6 @@ static const char *extract_specific_cookie(request_rec *r, char *a) | |||
| 596 | } | 508 | } |
| 597 | 509 | ||
| 598 | 510 | ||
| 599 | static const char *extract_request_timestamp(request_rec *r, char *a) | ||
| 600 | { | ||
| 601 | return apr_psprintf(r->pool, "%"APR_TIME_T_FMT, apr_time_sec(apr_time_now())); | ||
| 602 | } | ||
| 603 | |||
| 604 | /* | 511 | /* |
| 605 | static const char *extract_note(request_rec *r, char *a) | 512 | static const char *extract_note(request_rec *r, char *a) |
| 606 | { | 513 | { |
| @@ -730,20 +637,20 @@ static int open_logdb_link(server_rec* s) | |||
| 730 | 637 | ||
| 731 | if (global_config.server_p) { | 638 | if (global_config.server_p) { |
| 732 | #ifdef DEBUG | 639 | #ifdef DEBUG |
| 733 | ap_log_error(APLOG_MARK,APLOG_DEBUG,0,s,"HOST: '%s' PORT: '%d' DB: '%s' USER: '%s' SOCKET: '%s'", | 640 | log_error(APLOG_MARK,APLOG_DEBUG,s,"HOST: '%s' PORT: '%d' DB: '%s' USER: '%s' SOCKET: '%s'", |
| 734 | global_config.dbhost, global_config.tcpport, global_config.dbname, global_config.dbuser, global_config.socketfile); | 641 | global_config.dbhost, global_config.tcpport, global_config.dbname, global_config.dbuser, global_config.socketfile); |
| 735 | #endif | 642 | #endif |
| 736 | return 1; | 643 | return 1; |
| 737 | } else { | 644 | } else { |
| 738 | #ifdef DEBUG | 645 | #ifdef DEBUG |
| 739 | ap_log_error(APLOG_MARK,APLOG_DEBUG,0,s,"mod_log_sql: database connection error: %s",MYSQL_ERROR(&global_config.server)); | 646 | log_error(APLOG_MARK,APLOG_DEBUG,s,"mod_log_sql: database connection error: %s",MYSQL_ERROR(&global_config.server)); |
| 740 | ap_log_error(APLOG_MARK,APLOG_DEBUG,0,s,"HOST: '%s' PORT: '%d' DB: '%s' USER: '%s' SOCKET: '%s'", | 647 | log_error(APLOG_MARK,APLOG_DEBUG,s,"HOST: '%s' PORT: '%d' DB: '%s' USER: '%s' SOCKET: '%s'", |
| 741 | global_config.dbhost, global_config.tcpport, global_config.dbname, global_config.dbuser, global_config.socketfile); | 648 | global_config.dbhost, global_config.tcpport, global_config.dbname, global_config.dbuser, global_config.socketfile); |
| 742 | #endif | 649 | #endif |
| 743 | return 0; | 650 | return 0; |
| 744 | } | 651 | } |
| 745 | } else { | 652 | } else { |
| 746 | ap_log_error(APLOG_MARK,APLOG_ERR,0,s,"mod_log_sql: insufficient configuration info to establish database link"); | 653 | log_error(APLOG_MARK,APLOG_ERR,s,"mod_log_sql: insufficient configuration info to establish database link"); |
| 747 | return 0; | 654 | return 0; |
| 748 | } | 655 | } |
| 749 | } | 656 | } |
| @@ -757,17 +664,30 @@ static int open_logdb_link(server_rec* s) | |||
| 757 | 664 | ||
| 758 | static void preserve_entry(request_rec *r, const char *query) | 665 | static void preserve_entry(request_rec *r, const char *query) |
| 759 | { | 666 | { |
| 760 | apr_file_t *fp; | ||
| 761 | logsql_state *cls = ap_get_module_config(r->server->module_config, | 667 | logsql_state *cls = ap_get_module_config(r->server->module_config, |
| 762 | &log_sql_module); | 668 | &log_sql_module); |
| 763 | 669 | #if defined(WITH_APACHE20) | |
| 764 | if (apr_file_open(&fp, cls->preserve_file,APR_APPEND, APR_OS_DEFAULT, r->pool)!=APR_SUCCESS) { | 670 | apr_file_t *fp; |
| 765 | ap_log_error(APLOG_MARK,APLOG_ERR,0,r->server,"mod_log_sql: attempted append of local preserve file but failed."); | 671 | apr_status_t result; |
| 672 | result = apr_file_open(&fp, cls->preserve_file,APR_APPEND, APR_OS_DEFAULT, r->pool); | ||
| 673 | #elif defined(WITH_APACHE13) | ||
| 674 | FILE *fp; | ||
| 675 | int result; | ||
| 676 | fp = ap_pfopen(r->pool, cls->preserve_file, "a"); | ||
| 677 | result = (fp)?0:1; | ||
| 678 | #endif | ||
| 679 | if (result != APR_SUCCESS) { | ||
| 680 | log_error(APLOG_MARK,APLOG_ERR,r->server,"mod_log_sql: attempted append of local preserve file but failed."); | ||
| 766 | } else { | 681 | } else { |
| 767 | apr_file_printf(fp,"%s;\n", query); | 682 | #if defined(WITH_APACHE20) |
| 768 | apr_file_close(fp); | 683 | apr_file_printf(fp,"%s;\n", query); |
| 684 | apr_file_close(fp); | ||
| 685 | #elif defined(WITH_APACHE13) | ||
| 686 | fprintf(fp,"%s;\n", query); | ||
| 687 | ap_pfclose(r->pool, fp); | ||
| 688 | #endif | ||
| 769 | #ifdef DEBUG | 689 | #ifdef DEBUG |
| 770 | ap_log_error(APLOG_MARK,APLOG_DEBUG,0,r->server,"mod_log_sql: entry preserved in %s", cls->preserve_file); | 690 | log_error(APLOG_MARK,APLOG_DEBUG,r->server,"mod_log_sql: entry preserved in %s", cls->preserve_file); |
| 771 | #endif | 691 | #endif |
| 772 | } | 692 | } |
| 773 | } | 693 | } |
| @@ -822,24 +742,24 @@ static unsigned int safe_sql_query(request_rec *r, const char *query) | |||
| 822 | } | 742 | } |
| 823 | if (retval) { | 743 | if (retval) { |
| 824 | if (global_config.createtables) { | 744 | if (global_config.createtables) { |
| 825 | ap_log_error(APLOG_MARK,APLOG_ERR,0,r->server,"mod_log_sql: table doesn't exist...creating now"); | 745 | log_error(APLOG_MARK,APLOG_ERR,r->server,"mod_log_sql: table doesn't exist...creating now"); |
| 826 | cls = ap_get_module_config(r->server->module_config, &log_sql_module); | 746 | cls = ap_get_module_config(r->server->module_config, &log_sql_module); |
| 827 | if (safe_create_tables(cls, r)) { | 747 | if (safe_create_tables(cls, r)) { |
| 828 | 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)); | 748 | 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)); |
| 829 | preserve_entry(r, query); | 749 | preserve_entry(r, query); |
| 830 | retval = mysql_errno(global_config.server_p); | 750 | retval = mysql_errno(global_config.server_p); |
| 831 | } else { | 751 | } else { |
| 832 | ap_log_error(APLOG_MARK,APLOG_ERR,0,r->server,"mod_log_sql: tables successfully created - retrying query"); | 752 | log_error(APLOG_MARK,APLOG_ERR,r->server,"mod_log_sql: tables successfully created - retrying query"); |
| 833 | if (mysql_query(global_config.server_p, query)) { | 753 | if (mysql_query(global_config.server_p, query)) { |
| 834 | ap_log_error(APLOG_MARK,APLOG_ERR,0,r->server,"mod_log_sql: giving up, preserving query"); | 754 | log_error(APLOG_MARK,APLOG_ERR,r->server,"mod_log_sql: giving up, preserving query"); |
| 835 | preserve_entry(r, query); | 755 | preserve_entry(r, query); |
| 836 | retval = mysql_errno(global_config.server_p); | 756 | retval = mysql_errno(global_config.server_p); |
| 837 | } else | 757 | } else |
| 838 | ap_log_error(APLOG_MARK,APLOG_ERR,0,r->server,"mod_log_sql: query successful after table creation"); | 758 | log_error(APLOG_MARK,APLOG_ERR,r->server,"mod_log_sql: query successful after table creation"); |
| 839 | retval = 0; | 759 | retval = 0; |
| 840 | } | 760 | } |
| 841 | } else { | 761 | } else { |
| 842 | ap_log_error(APLOG_MARK,APLOG_ERR,0,r->server,"mod_log_sql, table doesn't exist, creation denied by configuration, preserving query"); | 762 | log_error(APLOG_MARK,APLOG_ERR,r->server,"mod_log_sql, table doesn't exist, creation denied by configuration, preserving query"); |
| 843 | preserve_entry(r, query); | 763 | preserve_entry(r, query); |
| 844 | retval = ER_NO_SUCH_TABLE; | 764 | retval = ER_NO_SUCH_TABLE; |
| 845 | } | 765 | } |
| @@ -859,25 +779,25 @@ static unsigned int safe_sql_query(request_rec *r, const char *query) | |||
| 859 | real_error = mysql_errno(global_config.server_p); | 779 | real_error = mysql_errno(global_config.server_p); |
| 860 | } | 780 | } |
| 861 | 781 | ||
| 862 | 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)); | 782 | 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)); |
| 863 | mysql_close(global_config.server_p); | 783 | mysql_close(global_config.server_p); |
| 864 | global_config.server_p = NULL; | 784 | global_config.server_p = NULL; |
| 865 | open_logdb_link(r->server); | 785 | open_logdb_link(r->server); |
| 866 | 786 | ||
| 867 | if (global_config.server_p == NULL) { /* still unable to link */ | 787 | if (global_config.server_p == NULL) { /* still unable to link */ |
| 868 | signal(SIGPIPE, handler); | 788 | signal(SIGPIPE, handler); |
| 869 | 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."); | 789 | 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."); |
| 870 | ap_log_error(APLOG_MARK,APLOG_ERR,0,r->server,"mod_log_sql: log entries are being preserved in %s", cls->preserve_file); | 790 | log_error(APLOG_MARK,APLOG_ERR,r->server,"mod_log_sql: log entries are being preserved in %s", cls->preserve_file); |
| 871 | return 1; | 791 | return 1; |
| 872 | } else | 792 | } else |
| 873 | ap_log_error(APLOG_MARK,APLOG_ERR,0,r->server,"mod_log_sql: db reconnect successful"); | 793 | log_error(APLOG_MARK,APLOG_ERR,r->server,"mod_log_sql: db reconnect successful"); |
| 874 | 794 | ||
| 875 | /* First sleep for a tiny amount of time. */ | 795 | /* First sleep for a tiny amount of time. */ |
| 876 | delay.tv_sec = 0; | 796 | delay.tv_sec = 0; |
| 877 | delay.tv_nsec = 250000000; /* max is 999999999 (nine nines) */ | 797 | delay.tv_nsec = 250000000; /* max is 999999999 (nine nines) */ |
| 878 | ret = nanosleep(&delay, &remainder); | 798 | ret = nanosleep(&delay, &remainder); |
| 879 | if (ret && errno != EINTR) | 799 | if (ret && errno != EINTR) |
| 880 | ap_log_error(APLOG_MARK,APLOG_ERR,0,r->server,"mod_log_sql: nanosleep unsuccessful"); | 800 | log_error(APLOG_MARK,APLOG_ERR,r->server,"mod_log_sql: nanosleep unsuccessful"); |
| 881 | 801 | ||
| 882 | /* Then make our second attempt */ | 802 | /* Then make our second attempt */ |
| 883 | retval = mysql_query(global_config.server_p,query); | 803 | retval = mysql_query(global_config.server_p,query); |
| @@ -890,11 +810,11 @@ static unsigned int safe_sql_query(request_rec *r, const char *query) | |||
| 890 | real_error = mysql_errno(global_config.server_p); | 810 | real_error = mysql_errno(global_config.server_p); |
| 891 | } | 811 | } |
| 892 | 812 | ||
| 893 | 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)); | 813 | 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)); |
| 894 | preserve_entry(r, query); | 814 | preserve_entry(r, query); |
| 895 | retval = real_error; | 815 | retval = real_error; |
| 896 | } else | 816 | } else |
| 897 | ap_log_error(APLOG_MARK,APLOG_ERR,0,r->server,"mod_log_sql: second attempt successful"); | 817 | log_error(APLOG_MARK,APLOG_ERR,r->server,"mod_log_sql: second attempt successful"); |
| 898 | 818 | ||
| 899 | /* Restore SIGPIPE to its original handler function */ | 819 | /* Restore SIGPIPE to its original handler function */ |
| 900 | signal(SIGPIPE, handler); | 820 | signal(SIGPIPE, handler); |
| @@ -974,38 +894,38 @@ static int safe_create_tables(logsql_state *cls, request_rec *r) | |||
| 974 | create_cookies= apr_pstrcat(r->pool, createprefix, cls->cookie_table_name, cookies_suffix, type_suffix, NULL); | 894 | create_cookies= apr_pstrcat(r->pool, createprefix, cls->cookie_table_name, cookies_suffix, type_suffix, NULL); |
| 975 | 895 | ||
| 976 | #ifdef DEBUG | 896 | #ifdef DEBUG |
| 977 | ap_log_error(APLOG_MARK,APLOG_DEBUG,0,r->server,"mod_log_sql: create string: %s", create_access); | 897 | log_error(APLOG_MARK,APLOG_DEBUG,r->server,"mod_log_sql: create string: %s", create_access); |
| 978 | ap_log_error(APLOG_MARK,APLOG_DEBUG,0,r->server,"mod_log_sql: create string: %s", create_notes); | 898 | log_error(APLOG_MARK,APLOG_DEBUG,r->server,"mod_log_sql: create string: %s", create_notes); |
| 979 | ap_log_error(APLOG_MARK,APLOG_DEBUG,0,r->server,"mod_log_sql: create string: %s", create_hout); | 899 | log_error(APLOG_MARK,APLOG_DEBUG,r->server,"mod_log_sql: create string: %s", create_hout); |
| 980 | ap_log_error(APLOG_MARK,APLOG_DEBUG,0,r->server,"mod_log_sql: create string: %s", create_hin); | 900 | log_error(APLOG_MARK,APLOG_DEBUG,r->server,"mod_log_sql: create string: %s", create_hin); |
| 981 | ap_log_error(APLOG_MARK,APLOG_DEBUG,0,r->server,"mod_log_sql: create string: %s", create_cookies); | 901 | log_error(APLOG_MARK,APLOG_DEBUG,r->server,"mod_log_sql: create string: %s", create_cookies); |
| 982 | #endif | 902 | #endif |
| 983 | 903 | ||
| 984 | /* Assume that things worked unless told otherwise */ | 904 | /* Assume that things worked unless told otherwise */ |
| 985 | retval = 0; | 905 | retval = 0; |
| 986 | 906 | ||
| 987 | if ((create_results = safe_sql_query(r, create_access))) { | 907 | if ((create_results = safe_sql_query(r, create_access))) { |
| 988 | ap_log_error(APLOG_MARK,APLOG_ERR,0,r->server,"mod_log_sql: failed to create access table"); | 908 | log_error(APLOG_MARK,APLOG_ERR,r->server,"mod_log_sql: failed to create access table"); |
| 989 | retval = create_results; | 909 | retval = create_results; |
| 990 | } | 910 | } |
| 991 | 911 | ||
| 992 | if ((create_results = safe_sql_query(r, create_notes))) { | 912 | if ((create_results = safe_sql_query(r, create_notes))) { |
| 993 | ap_log_error(APLOG_MARK,APLOG_ERR,0,r->server,"mod_log_sql: failed to create notes table"); | 913 | log_error(APLOG_MARK,APLOG_ERR,r->server,"mod_log_sql: failed to create notes table"); |
| 994 | retval = create_results; | 914 | retval = create_results; |
| 995 | } | 915 | } |
| 996 | 916 | ||
| 997 | if ((create_results = safe_sql_query(r, create_hin))) { | 917 | if ((create_results = safe_sql_query(r, create_hin))) { |
| 998 | ap_log_error(APLOG_MARK,APLOG_ERR,0,r->server,"mod_log_sql: failed to create header_in table"); | 918 | log_error(APLOG_MARK,APLOG_ERR,r->server,"mod_log_sql: failed to create header_in table"); |
| 999 | retval = create_results; | 919 | retval = create_results; |
| 1000 | } | 920 | } |
| 1001 | 921 | ||
| 1002 | if ((create_results = safe_sql_query(r, create_hout))) { | 922 | if ((create_results = safe_sql_query(r, create_hout))) { |
| 1003 | ap_log_error(APLOG_MARK,APLOG_ERR,0,r->server,"mod_log_sql: failed to create header_out table"); | 923 | log_error(APLOG_MARK,APLOG_ERR,r->server,"mod_log_sql: failed to create header_out table"); |
| 1004 | retval = create_results; | 924 | retval = create_results; |
| 1005 | } | 925 | } |
| 1006 | 926 | ||
| 1007 | if ((create_results = safe_sql_query(r, create_cookies))) { | 927 | if ((create_results = safe_sql_query(r, create_cookies))) { |
| 1008 | ap_log_error(APLOG_MARK,APLOG_ERR,0,r->server,"mod_log_sql: failed to create cookies table"); | 928 | log_error(APLOG_MARK,APLOG_ERR,r->server,"mod_log_sql: failed to create cookies table"); |
| 1009 | retval = create_results; | 929 | retval = create_results; |
| 1010 | } | 930 | } |
| 1011 | 931 | ||
| @@ -1123,21 +1043,18 @@ static const char *set_log_sql_tcp_port(cmd_parms *parms, void *dummy, const cha | |||
| 1123 | * that are defined in the array 'mysql_lgog_module' (at EOF) * | 1043 | * that are defined in the array 'mysql_lgog_module' (at EOF) * |
| 1124 | *------------------------------------------------------------*/ | 1044 | *------------------------------------------------------------*/ |
| 1125 | 1045 | ||
| 1126 | 1046 | #if defined(WITH_APACHE20) | |
| 1127 | /* | ||
| 1128 | * This function is called when an heavy-weight process (such as a child) is | ||
| 1129 | * being run down or destroyed. As with the child-initialisation function, | ||
| 1130 | * any information that needs to be recorded must be in static cells, since | ||
| 1131 | * there's no configuration record. | ||
| 1132 | * | ||
| 1133 | * There is no return value. | ||
| 1134 | */ | ||
| 1135 | static apr_status_t log_sql_close_link(void *data) | 1047 | static apr_status_t log_sql_close_link(void *data) |
| 1136 | { | 1048 | { |
| 1137 | mysql_close(global_config.server_p); | 1049 | mysql_close(global_config.server_p); |
| 1138 | return APR_SUCCESS; | 1050 | return APR_SUCCESS; |
| 1139 | } | 1051 | } |
| 1140 | 1052 | #elif defined(WITH_APACHE13) | |
| 1053 | static void log_sql_child_exit(server_rec *s, apr_pool_t *p) | ||
| 1054 | { | ||
| 1055 | mysql_close(global_config.server_p); | ||
| 1056 | } | ||
| 1057 | #endif | ||
| 1141 | /* | 1058 | /* |
| 1142 | * This function is called during server initialisation when an heavy-weight | 1059 | * This function is called during server initialisation when an heavy-weight |
| 1143 | * process (such as a child) is being initialised. As with the | 1060 | * 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) | |||
| 1146 | * | 1063 | * |
| 1147 | * There is no return value. | 1064 | * There is no return value. |
| 1148 | */ | 1065 | */ |
| 1066 | #if defined(WITH_APACHE20) | ||
| 1149 | static void log_sql_child_init(apr_pool_t *p, server_rec *s) | 1067 | static void log_sql_child_init(apr_pool_t *p, server_rec *s) |
| 1150 | { | 1068 | { |
| 1151 | apr_pool_cleanup_register(p, NULL, log_sql_close_link, log_sql_close_link); | 1069 | apr_pool_cleanup_register(p, NULL, log_sql_close_link, log_sql_close_link); |
| 1152 | } | 1070 | } |
| 1153 | 1071 | ||
| 1154 | static int log_sql_open(apr_pool_t *pc, apr_pool_t *p, apr_pool_t *pt, server_rec *s) | 1072 | static int log_sql_open(apr_pool_t *pc, apr_pool_t *p, apr_pool_t *pt, server_rec *s) |
| 1073 | #elif defined(WITH_APACHE13) | ||
| 1074 | static void log_sql_child_init(server_rec *s, apr_pool_t *p) | ||
| 1075 | #endif | ||
| 1155 | { | 1076 | { |
| 1156 | int retval; | 1077 | int retval; |
| 1157 | /* Open a link to the database */ | 1078 | /* Open a link to the database */ |
| 1158 | retval = open_logdb_link(s); | 1079 | retval = open_logdb_link(s); |
| 1159 | if (!retval) | 1080 | if (!retval) |
| 1160 | ap_log_error(APLOG_MARK,APLOG_ERR,0,s,"mod_log_sql: child spawned but unable to open database link"); | 1081 | log_error(APLOG_MARK,APLOG_ERR,s,"mod_log_sql: child spawned but unable to open database link"); |
| 1161 | 1082 | ||
| 1162 | #ifdef DEBUG | 1083 | #ifdef DEBUG |
| 1163 | if ( (retval == 1) || (retval == 2) ) | 1084 | if ( (retval == 1) || (retval == 2) ) |
| 1164 | ap_log_error(APLOG_MARK,APLOG_DEBUG,0,s,"mod_log_sql: open_logdb_link successful"); | 1085 | log_error(APLOG_MARK,APLOG_DEBUG,s,"mod_log_sql: open_logdb_link successful"); |
| 1165 | if (retval == 3) | 1086 | if (retval == 3) |
| 1166 | ap_log_error(APLOG_MARK,APLOG_DEBUG,0,s,"mod_log_sql: open_logdb_link said that preservation is forced"); | 1087 | log_error(APLOG_MARK,APLOG_DEBUG,s,"mod_log_sql: open_logdb_link said that preservation is forced"); |
| 1167 | #endif | 1088 | #endif |
| 1089 | #if defined(WITH_APACHE20) | ||
| 1168 | return OK; | 1090 | return OK; |
| 1091 | #endif | ||
| 1169 | } | 1092 | } |
| 1170 | /* | 1093 | /* |
| 1171 | void *log_sql_initializer(server_rec *main_server, apr_pool_t *p) | 1094 | 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) | |||
| 1183 | } | 1106 | } |
| 1184 | */ | 1107 | */ |
| 1185 | 1108 | ||
| 1109 | #if defined(WITH_APACHE20) | ||
| 1110 | static int log_sql_pre_config(apr_pool_t *p, apr_pool_t *plog, apr_pool_t *ptemp) | ||
| 1111 | #elif defined(WITH_APACHE13) | ||
| 1112 | static void log_sql_pre_config(server_rec *s, apr_pool_t *p) | ||
| 1113 | #endif | ||
| 1114 | { | ||
| 1115 | /* Initialize Global configuration */ | ||
| 1116 | if (!global_config.socketfile) | ||
| 1117 | global_config.socketfile = "/tmp/mysql.sock"; | ||
| 1118 | if (!global_config.tcpport) | ||
| 1119 | global_config.tcpport = 3306; | ||
| 1120 | |||
| 1121 | #if defined(WITH_APACHE20) | ||
| 1122 | return OK; | ||
| 1123 | #endif | ||
| 1124 | } | ||
| 1125 | |||
| 1186 | /* | 1126 | /* |
| 1187 | * This function gets called to create a per-server configuration | 1127 | * This function gets called to create a per-server configuration |
| 1188 | * record. It will always be called for the main server and | 1128 | * 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) | |||
| 1192 | * The return value is a pointer to the created module-specific | 1132 | * The return value is a pointer to the created module-specific |
| 1193 | * structure. | 1133 | * structure. |
| 1194 | */ | 1134 | */ |
| 1195 | static int log_sql_pre_config(apr_pool_t *p, apr_pool_t *plog, apr_pool_t *ptemp) | ||
| 1196 | { | ||
| 1197 | /* Initialize Global configuration */ | ||
| 1198 | memset(&global_config,0,sizeof(global_config_t)); | ||
| 1199 | global_config.socketfile = "/tmp/mysql.sock"; | ||
| 1200 | global_config.tcpport = 3306; | ||
| 1201 | return OK; | ||
| 1202 | } | ||
| 1203 | |||
| 1204 | static void *log_sql_make_state(apr_pool_t *p, server_rec *s) | 1135 | static void *log_sql_make_state(apr_pool_t *p, server_rec *s) |
| 1205 | { | 1136 | { |
| 1206 | logsql_state *cls = (logsql_state *) apr_pcalloc(p, sizeof(logsql_state)); | 1137 | logsql_state *cls = (logsql_state *) apr_pcalloc(p, sizeof(logsql_state)); |
| @@ -1460,7 +1391,7 @@ static int log_sql_transaction(request_rec *orig) | |||
| 1460 | global_config.insertdelayed?"delayed":"", cls->notes_table_name, itemsets); | 1391 | global_config.insertdelayed?"delayed":"", cls->notes_table_name, itemsets); |
| 1461 | 1392 | ||
| 1462 | #ifdef DEBUG | 1393 | #ifdef DEBUG |
| 1463 | ap_log_error(APLOG_MARK,APLOG_DEBUG,0,orig->server,"mod_log_sql: note string: %s", note_query); | 1394 | log_error(APLOG_MARK,APLOG_DEBUG,orig->server,"mod_log_sql: note string: %s", note_query); |
| 1464 | #endif | 1395 | #endif |
| 1465 | } | 1396 | } |
| 1466 | 1397 | ||
| @@ -1490,7 +1421,7 @@ static int log_sql_transaction(request_rec *orig) | |||
| 1490 | global_config.insertdelayed?"delayed":"", cls->hout_table_name, itemsets); | 1421 | global_config.insertdelayed?"delayed":"", cls->hout_table_name, itemsets); |
| 1491 | 1422 | ||
| 1492 | #ifdef DEBUG | 1423 | #ifdef DEBUG |
| 1493 | ap_log_error(APLOG_MARK,APLOG_DEBUG,0,orig->server,"mod_log_sql: header_out string: %s", hout_query); | 1424 | log_error(APLOG_MARK,APLOG_DEBUG,orig->server,"mod_log_sql: header_out string: %s", hout_query); |
| 1494 | #endif | 1425 | #endif |
| 1495 | } | 1426 | } |
| 1496 | 1427 | ||
| @@ -1521,7 +1452,7 @@ static int log_sql_transaction(request_rec *orig) | |||
| 1521 | global_config.insertdelayed?"delayed":"", cls->hin_table_name, itemsets); | 1452 | global_config.insertdelayed?"delayed":"", cls->hin_table_name, itemsets); |
| 1522 | 1453 | ||
| 1523 | #ifdef DEBUG | 1454 | #ifdef DEBUG |
| 1524 | ap_log_error(APLOG_MARK,APLOG_DEBUG,0,orig->server,"mod_log_sql: header_in string: %s", hin_query); | 1455 | log_error(APLOG_MARK,APLOG_DEBUG,orig->server,"mod_log_sql: header_in string: %s", hin_query); |
| 1525 | #endif | 1456 | #endif |
| 1526 | } | 1457 | } |
| 1527 | 1458 | ||
| @@ -1553,7 +1484,7 @@ static int log_sql_transaction(request_rec *orig) | |||
| 1553 | global_config.insertdelayed?"delayed":"", cls->cookie_table_name, itemsets); | 1484 | global_config.insertdelayed?"delayed":"", cls->cookie_table_name, itemsets); |
| 1554 | 1485 | ||
| 1555 | #ifdef DEBUG | 1486 | #ifdef DEBUG |
| 1556 | ap_log_error(APLOG_MARK,APLOG_DEBUG,0,orig->server,"mod_log_sql: cookie string: %s", cookie_query); | 1487 | log_error(APLOG_MARK,APLOG_DEBUG,orig->server,"mod_log_sql: cookie string: %s", cookie_query); |
| 1557 | #endif | 1488 | #endif |
| 1558 | } | 1489 | } |
| 1559 | 1490 | ||
| @@ -1563,7 +1494,7 @@ static int log_sql_transaction(request_rec *orig) | |||
| 1563 | global_config.insertdelayed?"delayed":"", cls->transfer_table_name, fields, values); | 1494 | global_config.insertdelayed?"delayed":"", cls->transfer_table_name, fields, values); |
| 1564 | 1495 | ||
| 1565 | #ifdef DEBUG | 1496 | #ifdef DEBUG |
| 1566 | ap_log_error(APLOG_MARK,APLOG_DEBUG,0,r->server,"mod_log_sql: access string: %s", access_query); | 1497 | log_error(APLOG_MARK,APLOG_DEBUG,r->server,"mod_log_sql: access string: %s", access_query); |
| 1567 | #endif | 1498 | #endif |
| 1568 | 1499 | ||
| 1569 | /* If the person activated force-preserve, go ahead and push all the entries | 1500 | /* 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) | |||
| 1571 | */ | 1502 | */ |
| 1572 | if (global_config.forcepreserve) { | 1503 | if (global_config.forcepreserve) { |
| 1573 | #ifdef DEBUG | 1504 | #ifdef DEBUG |
| 1574 | ap_log_error(APLOG_MARK,APLOG_DEBUG,0,orig->server,"mod_log_sql: preservation forced"); | 1505 | log_error(APLOG_MARK,APLOG_DEBUG,orig->server,"mod_log_sql: preservation forced"); |
| 1575 | #endif | 1506 | #endif |
| 1576 | preserve_entry(orig, access_query); | 1507 | preserve_entry(orig, access_query); |
| 1577 | if ( note_query != NULL ) | 1508 | if ( note_query != NULL ) |
| @@ -1610,7 +1541,7 @@ static int log_sql_transaction(request_rec *orig) | |||
| 1610 | return OK; | 1541 | return OK; |
| 1611 | } else { | 1542 | } else { |
| 1612 | /* Whew, we got the DB link back */ | 1543 | /* Whew, we got the DB link back */ |
| 1613 | ap_log_error(APLOG_MARK,APLOG_NOTICE,0,orig->server,"mod_log_sql: child established database connection"); | 1544 | log_error(APLOG_MARK,APLOG_NOTICE,orig->server,"mod_log_sql: child established database connection"); |
| 1614 | } | 1545 | } |
| 1615 | } | 1546 | } |
| 1616 | 1547 | ||
| @@ -1745,6 +1676,7 @@ static const command_rec log_sql_cmds[] = { | |||
| 1745 | , | 1676 | , |
| 1746 | {NULL} | 1677 | {NULL} |
| 1747 | }; | 1678 | }; |
| 1679 | #if defined(WITH_APACHE20) | ||
| 1748 | /* The configuration array that sets up the hooks into the module. */ | 1680 | /* The configuration array that sets up the hooks into the module. */ |
| 1749 | static void register_hooks(apr_pool_t *p) { | 1681 | static void register_hooks(apr_pool_t *p) { |
| 1750 | ap_hook_pre_config(log_sql_pre_config, NULL, NULL, APR_HOOK_REALLY_FIRST); | 1682 | 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 = { | |||
| 1762 | log_sql_cmds, /* command handlers */ | 1694 | log_sql_cmds, /* command handlers */ |
| 1763 | register_hooks /* register hooks */ | 1695 | register_hooks /* register hooks */ |
| 1764 | }; | 1696 | }; |
| 1697 | #elif defined(WITH_APACHE13) | ||
| 1698 | /* The configuration array that sets up the hooks into the module. */ | ||
| 1699 | module log_sql_module = { | ||
| 1700 | STANDARD_MODULE_STUFF, | ||
| 1701 | log_sql_pre_config, /* module initializer */ | ||
| 1702 | NULL, /* create per-dir config */ | ||
| 1703 | NULL, /* merge per-dir config */ | ||
| 1704 | log_sql_make_state, /* create server config */ | ||
| 1705 | log_sql_merge_state, /* merge server config */ | ||
| 1706 | log_sql_cmds, /* config directive table */ | ||
| 1707 | NULL, /* [9] content handlers */ | ||
| 1708 | NULL, /* [2] URI-to-filename translation */ | ||
| 1709 | NULL, /* [5] check/validate user_id */ | ||
| 1710 | NULL, /* [6] check authorization */ | ||
| 1711 | NULL, /* [4] check access by host */ | ||
| 1712 | NULL, /* [7] MIME type checker/setter */ | ||
| 1713 | NULL, /* [8] fixups */ | ||
| 1714 | log_sql_transaction, /* [10] logger */ | ||
| 1715 | NULL /* [3] header parser */ | ||
| 1716 | #if MODULE_MAGIC_NUMBER >= 19970728 /* 1.3-dev or later support these additionals... */ | ||
| 1717 | ,log_sql_child_init, /* child process initializer */ | ||
| 1718 | log_sql_child_exit, /* process exit/cleanup */ | ||
| 1719 | NULL /* [1] post read-request */ | ||
| 1720 | #endif | ||
| 1721 | |||
| 1722 | }; | ||
| 1723 | #endif | ||
