From 2d71c1472c64bc47348fc4c6337a2e903e2649b3 Mon Sep 17 00:00:00 2001
From: Edward Rudd
Date: Wed, 7 Apr 2004 06:21:24 +0000
Subject: Added registration function for database drivers completely separated
mysql driver added optional server announce (LogSQLAnnouce On) cleaned up
internal names of Database parameters added code to allow +/- of logged
cookies,headers, and notes, as well as remhostignore, request allow and
request ignore. reorganized command_rec again made bigger not about
deprecated commands updated documentation
---
CHANGELOG | 4 +
Documentation/manual.xml | 274 +++++++++++++++++++++++++----------------------
Makefile.in | 43 +++++---
mod_log_sql.c | 234 +++++++++++++++++++++++++++-------------
mod_log_sql.h | 59 ++++++++--
mod_log_sql_mysql.c | 33 ++++--
mod_log_sql_ssl.c | 53 +--------
7 files changed, 409 insertions(+), 291 deletions(-)
diff --git a/CHANGELOG b/CHANGELOG
index 9d5087b..4610c86 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -2,6 +2,10 @@ $Id: CHANGELOG,v 1.18 2004/03/22 20:32:16 urkle Exp $
?: ?
* fixed apache.m4 to work with apache 2 setups with different include
directories for APR and APU then core Apache
+* cleaned up configuration documentation (updated due to deprecated commands)
+* LogSQLLoginInfo updated to support a connection URI
+* new module "registration" macros to clean up new driver modules
+* mysql driver completely separted from core module
1.96: 2004-03-04
* fixed LogSQLPreserveFile config parameter
diff --git a/Documentation/manual.xml b/Documentation/manual.xml
index 495b15f..d7dfc12 100644
--- a/Documentation/manual.xml
+++ b/Documentation/manual.xml
@@ -35,6 +35,11 @@
Edward Rudd
+
+ 1.2
+ 2004-04-?
+ Updated for mod_log_sql v1.97
+
1.1
2004-03-02
@@ -120,50 +125,7 @@
- Platform Specific Notes
- This section is currently not applicable as the new autoconf setup should auto-detect everything for your server. The win32 compilation, however, is still on my todo list. This section needs to be overhauled so do not rely completely on any information presented in it. And anyone who compiles the mod_log_sql on these platforms, please report any issues/resolutions to compiling the module.
- These installation documents assume a relatively modern GNU/Linux scenario. mod_log_sql has been ported to other platforms; following are notes on compiling the module for those platforms.
-
- Solaris
- The nanosleep() function used in mod_log_sql relies on linking aginst the librt library. Make the following alterations before proceeding:
-
-
- In Makefile, search for the string "-lmysqlclient -lz" and change it to read "-lmysqlclient -lz -lrt"
-
-
- In part [step:Linking] of section [sec:Static] below, change "-lmysqlclient -lm -lz" to read "-lmysqlclient -lm -lz -lrt"
-
-
-
-
- BSD
- No notes are available at present, but they are desired. If you have successfully ported mod_log_sql to BSD, please contact &MaintainerContact; and help fill in this section.
-
-
- Win32
- No notes are available at present, but they are desired. If you have successfully ported mod_log_sql to Win32, please contact &MaintainerContact; and help fill in this section.
-
-
- OS X
- mod_log_sql should compile and work out-of-the-box on this platform. Here are some notes from a user successfully running the module on OS X:
- The only changes I had to make were to where I had the various libraries installed. Here are the changes I made to the head of the Makefile: APACHESOURCE = /usr/local/src/apache_1.3.27 (Wasn't sure if this was really needed or not, so I downloaded the Apache source just in case) APACHEINSTALLED = /usr/sbin APACHEHEADERS = /usr/include/httpd APXS = $(APACHEINSTALLED)/apxs MYSQLLIBRARIES = /usr/local/mysql/lib MYSQLHEADERS = /usr/local/mysql/include I'm using a binary installation of MySQL and the default apache installation on OS X Client 10.2.3, the locations of these files may vary depending on how you've installed MySQL and will almost certainly be different if you're using OS X Server.
- My thanks to Tom Wiebe for being the first (to my knowlege) mod_log_sql user on OS X and for providing these notes.
-
-
- Digital Unix
- Digital Unix, like Solaris, needs to be linked against librt; see section . Here are further notes from a user successfully running the module on Digital Unix:
- Instead of trying to get the module to remember where the MySQL libraries were, I instead compiled apache with the information: LDFLAGS='-rpath /isp/mysql/lib/mysql' ./configure ... Everything worked as expected after that. (The error I got without this was "/sbin/loader: Fatal Error: cannot map libmysqlclient.so" ) Digital Unix (v4.0f, at least ) appears to follow the same requirements needed by Solaris, so simply adding librt to the module made it compile without errors. As for the warnings, here's the text: mod_log_sql.c: In function `extract_request_duration': mod_log_sql.c:292: warning: long int format, different type arg (arg 4) mod_log_sql.c: In function `extract_request_timestamp': mod_log_sql.c:497: warning: long int format, different type arg (arg 4) Poking around in the code, it looks like the compiler was complaining that what time() is returning doesn't play nicely with %ld by default. I just typecast them as (long)'s and the warnings went away ( not that the module wasn't working correctly without them ). The module works very well so far in testing... hasn't dropped a single log entry yet.
- My thanks to Jim Turner for permitting me to quote him here, and for being the first known user of mod_log_sql on Digital Unix
-
-
-
- Do I want a DSO or a static module
- This section is no longer applicable, as the new autoconf setup only allows DSO with Apache 1.3 and 2.0. This section will be removed shortly.
- You need to know the answer to this question before you proceed. The answer is pretty straightforward: what have you done in the past? If you like all your Apache modules to be dynamic, then you should keep doing that. If you're more of an old-school type and prefer to compile the modules right into apache, do that. Both methods work equally well.
- FWIW, the DSO method is more modern and increasing in popularity because apxs takes care of a lot of dirty little details for you. As you'll see below, the static-module method is a little more complex.
-
-
- Installation as an Apache DSO (preferred)
+ Compiling and Installing
Unpack the archive into a working directory.
@@ -233,20 +195,23 @@ $ cd mod_log_sql-1.9
Now compile the module with GNU make. You may have to specify gmake on some systems like FreeBSD.
- $ make
+ $ gmake
If there were no errors, you can now install the module(s). If you compiled as a non-root user you may need to switch users with su or sudo.
- $ su -c "make install"
+ $ su -c "gmake install"
Password:
Now edit your Apache configuration and load the modules.
If you are loading the SSL logging module, you need to make sure it is loaded after mod_ssl and mod_log_sql.
+ If you have previously used mod_log_sql version 1.18, the name of the module has changed from sql_log_module to log_sql_module (the first parameter to LoadModule)
+ If you are upgrading from any release earlier than 1.97 you need to add an extra LoadModule directive to load the database driver (ie mysql).
Insert these lines to either the main httpd.conf or a file included via an include directive.
LoadModule log_sql_module modules/mod_log_sql.so
+LoadModule log_sql_mysql_module modules/mod_log_sql_mysql.so
<IfModule mod_ssl.c>
LoadModule log_sql_ssl_module moduels/mod_log_sql_ssl.so
</IfModule>
@@ -255,6 +220,7 @@ LoadModule log_sql_ssl_module moduels/mod_log_sql_ssl.so
If you are using Apache 1.3 you may need add these lines later in the configuration.
AddModule mod_log_sql.c
+AddModule mod_log_sql_mysql.c
<IfModule mod_ssl.c>
AddModule mod_log_sql_ssl.c
</IfModule>
@@ -312,14 +278,13 @@ mysql> source create_tables.sql
Use the MySQL database called "apachelogs" running on "dbmachine.foo.com". Use username "loguser" and password "l0gg3r" to authenticate to the database. Permit the module create tables for us.
Basic Example
- LogSQLLoginInfo dbmachine.foo.com loguser l0gg3r
-LogSQLDatabase apachelogs
+ LogSQLLoginInfo mysql://loguser;l0gg3r@dbmachine.foo.com/apachelogs
LogSQLCreateTables on
If your database resides on localhost instead of another host, specify the MySQL server's socket file as follows:
- LogSQLSocketFile /your/path/to/mysql.sock
+ LogSQLDBParam socketfile /your/path/to/mysql.sock
If your database is listening on a port other than 3306, specify the correct TCP port as follows:
- LogSQLTCPPort 1234
+ LogSQLDBParam port 1234
The actual logging is set up on a virtual-host-by-host basis. So, skip down to the virtual host you want to set up. Instruct this virtual host to log entries to the table "access_log" by inserting a LogSQLTransferLogTable directive. (The LogSQLTransferLogTable directive is the minimum required to log -- other directives that you will learn about later simply tune the module's behavior.)
@@ -635,18 +600,55 @@ where a.id=n.id and a.id='PPIDskBRH30AAGPtAsg';
LogSQLLoginInfo
-
- LogSQLLoginInfo
- host
- user
- password
+
+ LogSQLLoginInfo
+ connection URI
- Example: LogSQLLoginInfo foobar.baz.com logwriter passw0rd
+ Example: LogSQLLoginInfo mysql://logwriter:passw0rd@foobar.baz.com/Apache_log
Context: main server config
- Defines the general parameters of the MySQL host to which you will be logging. "host" is the hostname or IP address of the MySQL machine, and is simply "localhost" if the database lives on the same machine as Apache. "user" is the MySQL userid (not a Unix userid!) with INSERT privileges on the table defined in LogSQLTransferLogTable. "password" is that user's password.
+ Defines the basic connection URI to connect to the database with. The format of the connection URI is
+ driver://username[:password]@hostname[:port]/database
+
+
+ driver
+
+ The database driver to use (mysql, pgsql, etc..)
+
+
+
+ username
+
+ The database username to login with INSERT privileges on the logging table defined in LogSQLtransferLogTable.
+
+
+
+ password
+
+ The password to use for username, and can be omitted if there is no password.
+
+
+
+ hostname
+
+ The hostname or Ip address of the Database machine, ans is simple "localhost" if the database lives on the same machine as Apache.
+
+
+
+ port
+
+ Port on hostname to connect to the Database, if not specified use the default port for the database.
+
+
+
+ database
+
+ The database to connect to on the server.
+
+
+
This is defined only once in the httpd.conf file.
- This directive Must be defined for logging to be enabled. Or the use of LogSQLDBParam
+ This directive Must be defined for logging to be enabled.
@@ -658,12 +660,11 @@ where a.id=n.id and a.id='PPIDskBRH30AAGPtAsg';
parameter-name
value
- Example: LogSQLDBParam database loggingdb
+ Example: LogSQLDBParam socketfile /var/lib/mysql/mysql.socket
Context: main server config
- This is the new method of specifying Database connection credentials and settings. This can be used to define all Database specific options and allows for a specific database driver to define new configuration attributes without modifying the mod_log_sql core. This is the preferred configuration mechanism.
+ This is the new method of specifying Database connection credentials and settings. This is used to define database driver specific options. For a list of options read the documentation for each specific database driver.
Each parameter-name may only be defined once.
- Either this directive defining the minimum of 'database','host','user','passwd' or the use of LogSQlLoginInfo and LogSQLDatabase
@@ -684,60 +685,6 @@ where a.id=n.id and a.id='PPIDskBRH30AAGPtAsg';
-
- LogSQLSocketFile [Deprecated]
-
-
- LogSQLSocketFile
- filename
-
- Example: LogSQLSocketFile /tmp/mysql.sock
- Default: (database specific)
- Default (MySQL): /var/lib/mysql/mysql.sock
- Context: main server config
- At Apache runtime you can specify the MySQL socket file to use. Set this once in your main server config to override the default value. This value is irrelevant if your database resides on a separate machine.
- mod_log_sql will automatically employ the socket for db communications if the database resides on the local host. If the db resides on a separate host the module will automatically use TCP/IP. This is a function of the MySQL API and is not user-configurable.
-
- This directive is deprecated in favor of LogSQLDBParam socketfile [socketfilename]
- This is defined only once in the httpd.conf file.
-
-
-
-
- LogSQLTCPPort [Deprecated]
-
-
- LogSQLTCPPort
- port-number
-
- Example: LogSQLTCPPort 3309
- Default: (database specific)
- Default (MySQL): 3306
- Context: main server config
- Your database may listen on a different port than the default. If so, use this directive to instruct the module which port to use. This directive only applies if the database is on a different machine connected via TCP/IP.
-
- This directive is deprecated in favor of LogSQLDBParam tcpport [port-number]
- This is defined only once in the httpd.conf file.
-
-
-
-
- LogSQLDatabase [Deprecated]
-
-
- LogSQLDatabase
- database
-
- Example: LogSQLDatabase loggingdb
- Context: main server config
- Defines the database that is used for logging. "database" must be a valid db on the MySQL host defined in LogSQLLoginInfo
-
- This directive is deprecated in favor of LogSQLDBParam database [database-name]
- This is defined only once in the httpd.conf file.
- This directive Must be defined for logging to be enabled.
-
-
-
LogSQLForcePreserve
@@ -801,7 +748,7 @@ where a.id=n.id and a.id='PPIDskBRH30AAGPtAsg';
Example: LogSQLTransferLogTable access_log_table
Context: virtual host
- Defines which table is used for logging of Apache's transfers; this is analogous to Apache's TransferLog directive. table-name must be a valid table within the database defined in LogSQLDatabase.
+ Defines which table is used for logging of Apache's transfers; this is analogous to Apache's TransferLog directive. table-name must be a valid table within the database defined in the LogSQLLoginInfo connection URI.
This directive is not necessary if you declare LogSQLMassVirtualHosting On, since that directive activates dynamically-named tables. If you attempt to use LogSqlTransferlogTable at the same time a warning will be logged and it will be ignored, since LogSQLMassVirtualHosting takes priority.
Requires unless LogSQLMassVirtualHosting is set to On
@@ -905,6 +852,20 @@ where a.id=n.id and a.id='PPIDskBRH30AAGPtAsg';
Configuring What Is logged
+
+ LogSQLTransferLogFormat
+
+
+ LogSQLTransferLogFormat
+ format-string
+
+ Example: LogSQLTransferLogFormat huSUTv
+ Default: AbHhmRSsTUuv
+ Context: virtual host
+ Each character in the format-string defines an attribute of the request that you wish to log. The default logs the information required to create Combined Log Format logs, plus several extras. Here is the full list of allowable keys, which sometimes resemble their Apache counterparts, but do not always:
+ TODO: Insert Log Format Types Table
+
+
LogSQLRemhostIgnore
@@ -915,6 +876,7 @@ where a.id=n.id and a.id='PPIDskBRH30AAGPtAsg';
Example: LogSQLRemhostIgnore localnet.com
Context: virtual host
Lists a series of strings that, if present in the REMOTE_HOST, will cause that request to not be logged. This directive is useful for cutting down on log clutter when you are certain that you want to ignore requests from certain hosts, such as your own internal network machines. See section for some tips for using this directive.
+ Each string may contain a + or - prefix in a <VirtualHost> context and will cause those strings to be added (+) or removed (-) from the global configuration. Otherwise the global is completely ignored and overridden if defined in a <VirtualHost>
Each string is separated by a space, and no regular expressions or globbing are allowed. Each string is evaluated as a substring of the REMOTE_HOST using strstr(). The comparison is case sensitive.
@@ -929,6 +891,7 @@ where a.id=n.id and a.id='PPIDskBRH30AAGPtAsg';
Default: if not specified, all requests are 'accepted'
Context: virtual host
Lists a series of strings that, if present in the URI, will permit that request to be considered for logging (depending on additional filtering by the "ignore" directives). Any request that fails to match one of the LogSQLRequestAccept entries will be discarded.
+ Each string may contain a + or - prefix in a <VirtualHost> context and will cause those strings to be added (+) or removed (-) from the global configuration. Otherwise the global is completely ignored and overridden if defined in a <VirtualHost>
This directive is useful for cutting down on log clutter when you are certain that you only want to log certain kinds of requests, and just blanket-ignore everything else. See section for some tips for using this directive.
Each string is separated by a space, and no regular expressions or globbing are allowed. Each string is evaluated as a substring of the URI using strstr(). The comparison is case sensitive.
This directive is completely optional. It is more general than LogSQLRequestIgnore and is evaluated before LogSQLRequestIgnore . If this directive is not used, all requests are accepted and passed on to the other filtering directives. Therefore, only use this directive if you have a specific reason to do so.
@@ -944,23 +907,10 @@ where a.id=n.id and a.id='PPIDskBRH30AAGPtAsg';
Example: LogSQLRequestIgnore root.exe cmd.exe default.ida favicon.ico
Context: virtual host
Lists a series of strings that, if present in the URI, will cause that request to NOT be logged. This directive is useful for cutting down on log clutter when you are certain that you want to ignore requests for certain objects. See section for some tips for using this directive.
+ Each string may contain a + or - prefix in a <VirtualHost> context and will cause those strings to be added (+) or removed (-) from the global configuration. Otherwise the global is completely ignored and overridden if defined in a <VirtualHost>
Each string is separated by a space, and no regular expressions or globbing are allowed. Each string is evaluated as a substring of the URI using strstr(). The comparison is case sensitive.
-
- LogSQLTransferLogFormat
-
-
- LogSQLTransferLogFormat
- format-string
-
- Example: LogSQLTransferLogFormat huSUTv
- Default: AbHhmRSsTUuv
- Context: virtual host
- Each character in the format-string defines an attribute of the request that you wish to log. The default logs the information required to create Combined Log Format logs, plus several extras. Here is the full list of allowable keys, which sometimes resemble their Apache counterparts, but do not always:
- TODO: Insert Log Format Types Table
-
-
LogSQLWhichCookie
@@ -988,6 +938,7 @@ where a.id=n.id and a.id='PPIDskBRH30AAGPtAsg';
Example: logSQLWhichCookies userlogin cookie1 cookie2
Context: virtual host
Defines the list of cookies you would like logged. This works in conjunction with LogSQLCookieLogTable. This directive does not require any additional characters to be added to the LogSQLTransferLogFormat string. The feature is activated simply by including this directive, upon which you will begin populating the separate cookie table with data.
+ Each string may contain a + or - prefix in a <VirtualHost> context and will cause those strings to be added (+) or removed (-) from the global configuration. Otherwise the global is completely ignored and overridden if defined in a <VirtualHost>
The table must be created (see create-tables.sql, included in the package), or LogSQLCreateTables must be set to 'On'.
@@ -1003,6 +954,7 @@ where a.id=n.id and a.id='PPIDskBRH30AAGPtAsg';
Example: LogSQLWhichHeadersIn UserAgent Accept-Encodeing Host
Context: virtual host
Defines the list of inbound headers you would like logged. This works in conjunction with LogSQLHeadersInLogTable. This directive does not require any additional characters to be added to the LogSQLTransferLogFormat string. The feature is activated simply by including this directive, upon which you will begin populating the separate inbound-headers table with data.
+ Each string may contain a + or - prefix in a <VirtualHost> context and will cause those strings to be added (+) or removed (-) from the global configuration. Otherwise the global is completely ignored and overridden if defined in a <VirtualHost>
The table must be created (see create-tables.sql, included in the package), or LogSQLCreateTables must be set to 'On'.
@@ -1018,6 +970,7 @@ where a.id=n.id and a.id='PPIDskBRH30AAGPtAsg';
Example: LogSQLWhichHeadersOut Expires Content-Type Cache-Control
Context: virtual host
Defines the list of outbound headers you would like logged. This works in conjunction with LogSQLHeadersOutLogTable. This directive does not require any additional characters to be added to the LogSQLTransferLogFormat string. The feature is activated simply by including this directive, upon which you will begin populating the separate outbound-headers table with data.
+ Each string may contain a + or - prefix in a <VirtualHost> context and will cause those strings to be added (+) or removed (-) from the global configuration. Otherwise the global is completely ignored and overridden if defined in a <VirtualHost>
The table must be created (see create-tables.sql, included in the package), or LogSQLCreateTables must be set to 'On'.
@@ -1033,6 +986,7 @@ where a.id=n.id and a.id='PPIDskBRH30AAGPtAsg';
Example: LogSQLWhichNotes mod_gzip_result mod_gzip_ompression_ratio
Context: virtual host
Defines the list of notes you would like logged. This works in conjunction with LogSQLNotesLogTable. This directive does not require any additional characters to be added to the LogSQLTransferLogFormat string. The feature is activated simply by including this directive, upon which you will begin populating the separate notes table with data.
+ Each string may contain a + or - prefix in a <VirtualHost> context and will cause those strings to be added (+) or removed (-) from the global configuration. Otherwise the global is completely ignored and overridden if defined in a <VirtualHost>
The table must be created (see create-tables.sql, included in the package), or LogSQLCreateTables must be set to 'On'.
@@ -1040,6 +994,64 @@ where a.id=n.id and a.id='PPIDskBRH30AAGPtAsg';
+
+ Deprecated Command
+
+
+ LogSQLSocketFile [Deprecated]
+
+
+ LogSQLSocketFile
+ filename
+
+ Example: LogSQLSocketFile /tmp/mysql.sock
+ Default: (database specific)
+ Default (MySQL): /var/lib/mysql/mysql.sock
+ Context: main server config
+ At Apache runtime you can specify the MySQL socket file to use. Set this once in your main server config to override the default value. This value is irrelevant if your database resides on a separate machine.
+ mod_log_sql will automatically employ the socket for db communications if the database resides on the local host. If the db resides on a separate host the module will automatically use TCP/IP. This is a function of the MySQL API and is not user-configurable.
+
+ This directive is deprecated in favor of LogSQLDBParam socketfile [socketfilename]
+ This is defined only once in the httpd.conf file.
+
+
+
+
+ LogSQLTCPPort [Deprecated]
+
+
+ LogSQLTCPPort
+ port-number
+
+ Example: LogSQLTCPPort 3309
+ Default: (database specific)
+ Default (MySQL): 3306
+ Context: main server config
+ Your database may listen on a different port than the default. If so, use this directive to instruct the module which port to use. This directive only applies if the database is on a different machine connected via TCP/IP.
+
+ This directive is deprecated in favor of LogSQLDBParam tcpport [port-number]
+ This is defined only once in the httpd.conf file.
+
+
+
+
+ LogSQLDatabase [Deprecated]
+
+
+ LogSQLDatabase
+ database
+
+ Example: LogSQLDatabase loggingdb
+ Context: main server config
+ Defines the database that is used for logging. "database" must be a valid db on the MySQL host defined in LogSQLLoginInfo
+
+ This directive is deprecated in favor of the URI form of LogSQLLoginInfo.
+ This is defined only once in the httpd.conf file.
+
+
+
+
+
@@ -1314,7 +1326,7 @@ ErrorLog /var/log/httpd/server-messages
Why do I get the message "insufficient configuration info to establish database link" in my Apache error log?
- At a minimum, LogSQLDatabase and LogSQLLoginInfo and either LogSQLTableName or LogSQLMassVirtualHosting must be defined in order for the module to be able to establish a database link. If these are not defined or are incomplete you will receive this error message.
+ At a minimum, LogSQLLoginInfo in the URl form and either LogSQLTableName or LogSQLMassVirtualHosting must be defined in order for the module to be able to establish a database link. If these are not defined or are incomplete you will receive this error message.
diff --git a/Makefile.in b/Makefile.in
index 4061629..93acec9 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -2,8 +2,7 @@
# Modify these top variables.
SUBDIRS = Documentation contrib
-SOURCES = @PACKAGE_NAME@.c \
- @PACKAGE_NAME@_mysql.c
+SOURCES = @PACKAGE_NAME@.c
HEADERS = mod_log_sql.h \
functions.h \
@@ -14,22 +13,28 @@ HEADERS = mod_log_sql.h \
CFLAGS = -Wc,-Wall -Wc,-Werror -Wc,-fno-strict-aliasing
-INCLUDES = @MYSQL_CFLAGS@
-
-LDADD = @MYSQL_LDFLAGS@ @MYSQL_LIBS@ @RT_LIBS@
+LDADD = @RT_LIBS@
EXTRA_DIST = AUTHORS INSTALL TODO LICENSE CHANGELOG
TARGET = @PACKAGE_NAME@@APXS_EXTENSION@
sslSOURCES = @PACKAGE_NAME@_ssl.c
-
sslTARGET = @PACKAGE_NAME@_ssl@APXS_EXTENSION@
+sslLDADD =
+sslCFLAGS = @MOD_SSL_CFLAGS@
+sslNAME = log_sql_ssl
+
+mysqlSOURCES = @PACKAGE_NAME@_mysql.c
+mysqlTARGET = @PACKAGE_NAME@_mysql@APXS_EXTENSION@
+mysqlLDADD = @MYSQL_LDFLAGS@ @MYSQL_LIBS@
+mysqlCFLAGS = @MYSQL_CFLAGS@
+mysqlNAME = log_sql_mysql
ifeq (@WANT_SSL_MOD@,1)
-TARGETS = $(TARGET) $(sslTARGET)
+TARGETS = $(TARGET) $(mysqlTARGET) $(sslTARGET)
else
-TARGETS = $(TARGET)
+TARGETS = $(TARGET) $(mysqlTARGET)
endif
#Don't modify anything below here
@@ -39,11 +44,11 @@ PROVIDERS_SUBDIRS = @subdirs@
srcdir = @abs_srcdir@
builddir = @abs_builddir@
-OBJ = $(SOURCES:.c=.o) $(sslSOURCES:.c=.o)
+OBJ = $(SOURCES:.c=.o) $(sslSOURCES:.c=.o) $(mysqlSOURCES:.c=.o)
-LO = $(SOURCES:.c=.lo) $(sslSOURCES:.c=.lo)
+LO = $(SOURCES:.c=.lo) $(sslSOURCES:.c=.lo) $(mysqlSOURCES:.c=.lo)
-SLO = $(SOURCES:.c=.slo) $(sslSOURCES:.c=.slo)
+SLO = $(SOURCES:.c=.slo) $(sslSOURCES:.c=.slo) $(mysqlSOURCES:.c=.slo)
STD_DIST = install-sh \
config.sub \
@@ -55,7 +60,8 @@ STD_DIST = install-sh \
stamp-h.in \
config.h.in
-DISTFILES = $(STD_DIST) $(EXTRA_DIST) $(SOURCES) $(sslSOURCES) $(HEADERS)
+DISTFILES = $(STD_DIST) $(EXTRA_DIST) $(SOURCES) $(sslSOURCES) $(mysqlSOURCES) \
+ $(HEADERS)
all: $(TARGETS) all-subdirs
@@ -78,12 +84,16 @@ TODO: TODO.in
@./gen_todo.pl
$(TARGET): $(SOURCES) $(HEADERS)
- @@APXS_BIN@ -c -o $(TARGET) $(INCLUDES) $(CFLAGS) \
+ @@APXS_BIN@ -c -o $(TARGET) $(CFLAGS) \
$(LDADD) @DEFS@ @APACHE_DEFS@ $(SOURCES)
$(sslTARGET): $(sslSOURCES) $(HEADERS)
- @@APXS_BIN@ -c -o $(sslTARGET) $(INCLUDES) @MOD_SSL_CFLAGS@ $(CFLAGS) \
- @DEFS@ @APACHE_DEFS@ $(sslSOURCES)
+ @@APXS_BIN@ -c -o $(sslTARGET) $(sslCFLAGS) $(CFLAGS) \
+ @DEFS@ @APACHE_DEFS@ $(sslLDADD) $(sslSOURCES)
+
+$(mysqlTARGET): $(mysqlSOURCES) $(HEADERS)
+ @@APXS_BIN@ -c -o $(mysqlTARGET) $(mysqlCFLAGS) $(CFLAGS) \
+ @DEFS@ @APACHE_DEFS@ $(mysqlLDADD) $(mysqlSOURCES)
include:
rm -rf include
@@ -91,8 +101,9 @@ include:
install: $(TARGETS) install-subdirs
@@APXS_BIN@ -i $(TARGET); \
+ @APXS_BIN@ -n $(mysqlNAME) -i $(mysqlTARGET); \
if test @WANT_SSL_MOD@ -eq 1; then \
- @APXS_BIN@ -i $(sslTARGET); \
+ @APXS_BIN@ -n $(sslNAME) -i $(sslTARGET); \
fi; \
echo "*************************************************************************"; \
echo "*** The mod_log_sql modules have been installed."; \
diff --git a/mod_log_sql.c b/mod_log_sql.c
index 3b4e6f4..9309f9a 100644
--- a/mod_log_sql.c
+++ b/mod_log_sql.c
@@ -55,7 +55,9 @@ typedef struct {
int createtables;
int forcepreserve;
char *machid;
+ int announce;
logsql_dbconnection db;
+ logsql_dbdriver *driver;
} global_config_t;
static global_config_t global_config;
@@ -99,7 +101,7 @@ typedef struct {
/* list of "handlers" for log types */
static apr_array_header_t *logsql_item_list;
-/* Registration Function for extract functions *
+/* Registration function for extract functions *
* and update parse cache for transfer_log_format *
* this is exported from the module */
LOGSQL_DECLARE(void) log_sql_register_item(server_rec *s, apr_pool_t *p,
@@ -132,7 +134,14 @@ LOGSQL_DECLARE(void) log_sql_register_item(server_rec *s, apr_pool_t *p,
}
}
-/* Include all the extract functions */
+/* Registration function for database drivers */
+LOGSQL_DECLARE(void) log_sql_register_driver(apr_pool_t *p,
+ logsql_dbdriver *driver)
+{
+ global_config.driver = driver;
+}
+
+/* Include all the core extract functions */
#include "functions.h"
#if defined(WITH_APACHE13)
# include "functions13.h"
@@ -156,7 +165,7 @@ static logsql_opendb_ret log_sql_opendb_link(server_rec* s)
passwd
*/
if (global_config.db.parms) {
- result = log_sql_mysql_connect(s, &global_config.db);
+ result = global_config.driver->connect(s, &global_config.db);
if (result==LOGSQL_OPENDB_FAIL) {
global_config.db.connected = 0;
} else {
@@ -315,25 +324,23 @@ static const char *set_dbparam_slot(cmd_parms *cmd,
static const char *set_log_sql_info(cmd_parms *cmd, void *dummy,
const char *host, const char *user, const char *pwd)
{
- ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, cmd->server,
- "%s - %s - %s", host, user, pwd);
if (!user) { /* user is null, so only one arg passed */
apr_uri_t uri;
apr_uri_parse(cmd->pool, host, &uri);
if (uri.scheme) {
- /* set DB plugin */
+ set_dbparam(cmd, NULL, "driver", uri.scheme);
}
if (uri.hostname) {
- set_dbparam(cmd, NULL, "host", uri.hostname);
+ set_dbparam(cmd, NULL, "hostname", uri.hostname);
}
if (uri.user) {
- set_dbparam(cmd, NULL, "user", uri.user);
+ set_dbparam(cmd, NULL, "username", uri.user);
}
if (uri.password) {
- set_dbparam(cmd, NULL, "passwd", uri.password);
+ set_dbparam(cmd, NULL, "password", uri.password);
}
if (uri.port_str) {
- set_dbparam(cmd, NULL, "tcpport", uri.port_str);
+ set_dbparam(cmd, NULL, "port", uri.port_str);
}
if (uri.path) {
/* extract Database name */
@@ -345,13 +352,13 @@ static const char *set_log_sql_info(cmd_parms *cmd, void *dummy,
}
} else {
if (*host != '.') {
- set_dbparam(cmd, NULL, "host", host);
+ set_dbparam(cmd, NULL, "hostname", host);
}
if (*user != '.') {
- set_dbparam(cmd, NULL, "user", user);
+ set_dbparam(cmd, NULL, "username", user);
}
if (*pwd != '.') {
- set_dbparam(cmd, NULL, "passwd", pwd);
+ set_dbparam(cmd, NULL, "password", pwd);
}
}
return NULL;
@@ -380,7 +387,7 @@ static const char *add_server_string_slot(cmd_parms *cmd,
#if defined(WITH_APACHE20)
static apr_status_t log_sql_close_link(void *data)
{
- log_sql_mysql_close(&global_config.db);
+ global_config.driver->disconnect(&global_config.db);
return APR_SUCCESS;
}
#elif defined(WITH_APACHE13)
@@ -454,6 +461,10 @@ static void log_sql_module_init(server_rec *s, apr_pool_t *p)
log_sql_register_item(s,p,'U', extract_request_uri, "request_uri", 1, 1);
log_sql_register_item(s,p,'v', extract_virtual_host, "virtual_host", 0, 1);
+ if (global_config.announce) {
+ ap_add_version_component(p, PACKAGE_NAME"/"PACKAGE_VERSION);
+ }
+
#if defined(WITH_APACHE20)
return OK;
#endif
@@ -478,7 +489,7 @@ static logsql_query_ret safe_sql_insert(request_rec *r, logsql_tabletype table_t
return LOGSQL_QUERY_NOLINK;
}
- result = log_sql_mysql_query(r,&global_config.db,query);
+ result = global_config.driver->insert(r,&global_config.db,query);
/* If we ran the query and it returned an error, try to be robust.
* (After all, the module thought it had a valid mysql_log connection but the query
@@ -490,7 +501,7 @@ static logsql_query_ret safe_sql_insert(request_rec *r, logsql_tabletype table_t
return LOGSQL_QUERY_FAIL;
/* TODO: What do we do here */
case LOGSQL_QUERY_FAIL:
- log_sql_mysql_close(&global_config.db);
+ global_config.driver->disconnect(&global_config.db);
global_config.db.connected = 0;
/* re-open the connection and try again */
if (log_sql_opendb_link(r->server) != LOGSQL_OPENDB_FAIL) {
@@ -509,7 +520,7 @@ static logsql_query_ret safe_sql_insert(request_rec *r, logsql_tabletype table_t
}
}
# endif
- result = log_sql_mysql_query(r,&global_config.db,query);
+ result = global_config.driver->insert(r,&global_config.db,query);
if (result == LOGSQL_QUERY_SUCCESS) {
return LOGSQL_QUERY_SUCCESS;
} else {
@@ -530,7 +541,7 @@ static logsql_query_ret safe_sql_insert(request_rec *r, logsql_tabletype table_t
if (global_config.createtables) {
log_error(APLOG_MARK,APLOG_ERR,0,r->server,
"table doesn't exist...creating now");
- if ((result = log_sql_mysql_create(r, &global_config.db, table_type,
+ if ((result = global_config.driver->create_table(r, &global_config.db, table_type,
table_name))!=LOGSQL_TABLE_SUCCESS) {
log_error(APLOG_MARK,APLOG_ERR,result,r->server,
"child attempted but failed to create one or more tables for %s, preserving query", ap_get_server_name(r));
@@ -539,7 +550,7 @@ static logsql_query_ret safe_sql_insert(request_rec *r, logsql_tabletype table_t
} else {
log_error(APLOG_MARK,APLOG_ERR,result, r->server,
"tables successfully created - retrying query");
- if ((result = log_sql_mysql_query(r,&global_config.db,query))!=LOGSQL_QUERY_SUCCESS) {
+ if ((result = global_config.driver->insert(r,&global_config.db,query))!=LOGSQL_QUERY_SUCCESS) {
log_error(APLOG_MARK,APLOG_ERR,result, r->server,
"giving up, preserving query");
preserve_entry(r, query);
@@ -600,20 +611,92 @@ static void *log_sql_make_state(apr_pool_t *p, server_rec *s)
return (void *) cls;
}
+
+/* Iterates through an array of char* and searches for a matching element
+ * Returns 0 if not found, 1 if found */
+static int in_array(apr_array_header_t *ary, const char *elem)
+{
+ int itr;
+ for (itr = 0; itr < ary->nelts; itr++) {
+ if (!strcmp(elem,((char **)ary->elts)[itr])) {
+ return 1;
+ }
+ }
+ return 0;
+}
+
+/* Debugging print */
+#define PRINT_ARRAY(ary) { \
+ char **a_ptr = (char **)(ary->elts); \
+ int a_itr; \
+ fprintf(stderr, "\nPrinting %s\n\n", #ary); \
+ for (a_itr=0; a_itrnelts; a_itr++) { \
+ fprintf(stderr, "Array Elem: %s\n",a_ptr[a_itr]); \
+ } \
+}
+
+/* Parse through cookie lists and merge based on +/- prefixes */
+#define DO_MERGE_ARRAY(parent,child,pool) \
+if (apr_is_empty_array(child)) { \
+ apr_array_cat(child, parent); \
+} else { \
+ apr_array_header_t *addlist, *dellist; \
+ char **elem, **ptr = (char **)(child->elts); \
+ int itr, overwrite = 0; \
+ addlist = apr_array_make(pool,5,sizeof(char *)); \
+ dellist = apr_array_make(subp,5,sizeof(char *)); \
+\
+ for (itr=0; itrnelts; itr++) { \
+ if (*ptr[itr] == '+') { \
+ elem = (char **)apr_array_push(addlist); \
+ *elem = (ptr[itr]+1); \
+ } else if (*ptr[itr] == '-') { \
+ elem = (char **)apr_array_push(dellist); \
+ *elem = (ptr[itr]+1); \
+ } else { \
+ overwrite = 1; \
+ elem = (char **)apr_array_push(addlist); \
+ *elem = ptr[itr]; \
+ } \
+ } \
+ PRINT_ARRAY(addlist); \
+ PRINT_ARRAY(dellist); \
+ PRINT_ARRAY(parent); \
+ child = apr_array_make(p,1,sizeof(char *)); \
+ ptr = (char **)(parent->elts); \
+ if (overwrite==0) { \
+ /* if we are not overwriting the existing then prepare for merge */ \
+ for (itr=0; itrnelts; itr++) { \
+ if (!in_array(addlist, ptr[itr]) && !in_array(dellist,ptr[itr])) { \
+ elem = apr_array_push(child); \
+ *elem = apr_pstrdup(p, ptr[itr]); \
+ } \
+ } \
+ } \
+ PRINT_ARRAY(child); \
+ apr_array_cat(child, addlist); \
+ PRINT_ARRAY(child); \
+}
+
static void *log_sql_merge_state(apr_pool_t *p, void *basev, void *addv)
{
/* Fetch the two states to merge */
logsql_state *parent = (logsql_state *) basev;
logsql_state *child = (logsql_state *) addv;
+ apr_pool_t *subp;
+
+ apr_pool_create(&subp,p);
+
/* Child can override these, otherwise they default to parent's choice.
* If the parent didn't set them, create reasonable defaults for the
* ones that should have such default settings. Leave the others null. */
- child->transfer_table_name = child->transfer_table_name ?
- child->transfer_table_name : parent->transfer_table_name;
/* No default for transfer_table_name because we want its absence
* to disable logging. */
+ if (!child->transfer_table_name) {
+ child->transfer_table_name = parent->transfer_table_name;
+ }
if (child->transfer_log_format == DEFAULT_TRANSFER_LOG_FMT) {
child->transfer_log_format = parent->transfer_log_format;
@@ -637,30 +720,20 @@ static void *log_sql_merge_state(apr_pool_t *p, void *basev, void *addv)
if (child->cookie_table_name == DEFAULT_COOKIE_TABLE_NAME)
child->cookie_table_name = parent->cookie_table_name;
- if (apr_is_empty_array(child->transfer_ignore_list))
- apr_array_cat(child->transfer_ignore_list, parent->transfer_ignore_list);
-
- if (apr_is_empty_array(child->transfer_accept_list))
- apr_array_cat(child->transfer_accept_list, parent->transfer_accept_list);
-
- if (apr_is_empty_array(child->remhost_ignore_list))
- apr_array_cat(child->remhost_ignore_list, parent->remhost_ignore_list);
-
- if (apr_is_empty_array(child->notes_list))
- apr_array_cat(child->notes_list, parent->notes_list);
-
- if (apr_is_empty_array(child->hin_list))
- apr_array_cat(child->hin_list, parent->hin_list);
+ DO_MERGE_ARRAY(parent->transfer_ignore_list, child->transfer_ignore_list, subp);
+ DO_MERGE_ARRAY(parent->transfer_accept_list, child->transfer_accept_list, subp);
+ DO_MERGE_ARRAY(parent->remhost_ignore_list, child->remhost_ignore_list, subp);
+ DO_MERGE_ARRAY(parent->notes_list, child->notes_list, subp);
+ DO_MERGE_ARRAY(parent->hin_list, child->hin_list, subp);
+ DO_MERGE_ARRAY(parent->hout_list, child->hout_list, subp);
+ DO_MERGE_ARRAY(parent->cookie_list,child->cookie_list, subp);
- if (apr_is_empty_array(child->hout_list))
- apr_array_cat(child->hout_list, parent->hout_list);
-
- if (apr_is_empty_array(child->cookie_list))
- apr_array_cat(child->cookie_list, parent->cookie_list);
+ apr_pool_destroy(subp);
if (!child->cookie_name)
child->cookie_name = parent->cookie_name;
+
return (void*) child;
}
@@ -804,7 +877,7 @@ static int log_sql_transaction(request_rec *orig)
item->sql_field_name, NULL);
values = apr_pstrcat(r->pool, values, (i ? "," : ""),
(item->string_contents ? "'" : ""),
- log_sql_mysql_escape(formatted_item, r->pool,&global_config.db),
+ global_config.driver->escape(formatted_item, r->pool,&global_config.db),
(item->string_contents ? "'" : ""), NULL);
}
@@ -821,9 +894,9 @@ static int log_sql_transaction(request_rec *orig)
"('",
unique_id,
"','",
- log_sql_mysql_escape(*ptrptr, r->pool,&global_config.db),
+ global_config.driver->escape(*ptrptr, r->pool,&global_config.db),
"','",
- log_sql_mysql_escape(theitem, r->pool,&global_config.db),
+ global_config.driver->escape(theitem, r->pool,&global_config.db),
"')",
NULL);
i++;
@@ -849,9 +922,9 @@ static int log_sql_transaction(request_rec *orig)
"('",
unique_id,
"','",
- log_sql_mysql_escape(*ptrptr, r->pool,&global_config.db),
+ global_config.driver->escape(*ptrptr, r->pool,&global_config.db),
"','",
- log_sql_mysql_escape(theitem, r->pool,&global_config.db),
+ global_config.driver->escape(theitem, r->pool,&global_config.db),
"')",
NULL);
i++;
@@ -878,9 +951,9 @@ static int log_sql_transaction(request_rec *orig)
"('",
unique_id,
"','",
- log_sql_mysql_escape(*ptrptr, r->pool,&global_config.db),
+ global_config.driver->escape(*ptrptr, r->pool,&global_config.db),
"','",
- log_sql_mysql_escape(theitem, r->pool,&global_config.db),
+ global_config.driver->escape(theitem, r->pool,&global_config.db),
"')",
NULL);
i++;
@@ -907,9 +980,9 @@ static int log_sql_transaction(request_rec *orig)
"('",
unique_id,
"','",
- log_sql_mysql_escape(*ptrptr, r->pool,&global_config.db),
+ global_config.driver->escape(*ptrptr, r->pool,&global_config.db),
"','",
- log_sql_mysql_escape(theitem, r->pool,&global_config.db),
+ global_config.driver->escape(theitem, r->pool,&global_config.db),
"')",
NULL);
i++;
@@ -1005,7 +1078,34 @@ static int log_sql_transaction(request_rec *orig)
* Structure: command, function called, NULL, where available, how many arguments, verbose description
*/
static const command_rec log_sql_cmds[] = {
+ AP_INIT_FLAG("LogSQLAnnounce", set_global_flag_slot,
+ (void *)APR_OFFSETOF(global_config_t, announce), RSRC_CONF,
+ "Whether to announce that mod_log_sql is loaded in the server header")
+ ,
+ /* DB connection parameters */
+ AP_INIT_TAKE13("LogSQLLoginInfo", set_log_sql_info, NULL, RSRC_CONF,
+ "The database connection URI in the form
driver://user:password@hostname:port/database")
+ ,
+ AP_INIT_TAKE2("LogSQLDBParam", set_dbparam, NULL, RSRC_CONF,
+ "First argument is the DB parameter, second is the value to assign")
+ ,
+ AP_INIT_FLAG("LogSQLForcePreserve", set_global_flag_slot,
+ (void *)APR_OFFSETOF(global_config_t, forcepreserve), RSRC_CONF,
+ "Forces logging to preserve file and bypasses database")
+ ,
+ AP_INIT_TAKE1("LogSQLPreserveFile", set_server_string_slot,
+ (void *)APR_OFFSETOF(logsql_state,preserve_file), RSRC_CONF,
+ "Name of the file to use for data preservation during database downtime")
+ ,
+ AP_INIT_FLAG("LogSQLCreateTables", set_global_nmv_flag_slot,
+ (void *)APR_OFFSETOF(global_config_t, createtables), RSRC_CONF,
+ "Turn on module's capability to create its SQL tables on the fly")
+ ,
/* Table names */
+ AP_INIT_FLAG("LogSQLMassVirtualHosting", set_global_flag_slot,
+ (void *)APR_OFFSETOF(global_config_t, massvirtual), RSRC_CONF,
+ "Activates option(s) useful for ISPs performing mass virutal hosting")
+ ,
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")
@@ -1026,10 +1126,6 @@ static const command_rec log_sql_cmds[] = {
(void *)APR_OFFSETOF(logsql_state, cookie_table_name), RSRC_CONF,
"The database table that holds the cookie info")
,
- AP_INIT_FLAG("LogSQLMassVirtualHosting", set_global_flag_slot,
- (void *)APR_OFFSETOF(global_config_t, massvirtual), RSRC_CONF,
- "Activates option(s) useful for ISPs performing mass virutal hosting")
- ,
/* Log format */
AP_INIT_TAKE1("LogSQLTransferLogFormat", set_logformat_slot,
NULL, RSRC_CONF,
@@ -1053,14 +1149,11 @@ static const command_rec log_sql_cmds[] = {
(void *)APR_OFFSETOF(logsql_state, remhost_ignore_list), RSRC_CONF,
"List of remote hosts to ignore. Accesses that match will not be logged to database")
,
+ /* Special loggin table configuration */
AP_INIT_TAKE1("LogSQLWhichCookie", set_server_string_slot,
(void *)APR_OFFSETOF(logsql_state, cookie_name), RSRC_CONF,
"The single cookie that you want logged in the access_log when using the 'c' config directive")
,
- AP_INIT_TAKE1("LogSQLPreserveFile", set_server_string_slot,
- (void *)APR_OFFSETOF(logsql_state,preserve_file), RSRC_CONF,
- "Name of the file to use for data preservation during database downtime")
- ,
AP_INIT_ITERATE("LogSQLWhichNotes", add_server_string_slot,
(void *)APR_OFFSETOF(logsql_state, notes_list), RSRC_CONF,
"Notes that you would like to log in a separate table")
@@ -1077,36 +1170,25 @@ static const command_rec log_sql_cmds[] = {
(void *)APR_OFFSETOF(logsql_state, cookie_list), RSRC_CONF,
"The cookie(s) that you would like to log in a separate table")
,
- /* DB connection parameters */
- AP_INIT_FLAG("LogSQLForcePreserve", set_global_flag_slot,
- (void *)APR_OFFSETOF(global_config_t, forcepreserve), RSRC_CONF,
- "Forces logging to preserve file and bypasses database")
- ,
- AP_INIT_FLAG("LogSQLCreateTables", set_global_nmv_flag_slot,
- (void *)APR_OFFSETOF(global_config_t, createtables), RSRC_CONF,
- "Turn on module's capability to create its SQL tables on the fly")
- ,
- AP_INIT_TAKE13("LogSQLLoginInfo", set_log_sql_info, NULL, RSRC_CONF,
- "The database host, user-id and password for logging")
- ,
- AP_INIT_TAKE2("LogSQLDBParam", set_dbparam, NULL, RSRC_CONF,
- "First argument is the DB parameter, second is the value to assign")
+ AP_INIT_RAW_ARGS("LogSQLDeprecated", ap_set_deprecated, NULL, RSRC_CONF,
+ "
Deprecated
The following Commands are deprecated and should not be used..
Read the documentation for more information
Deprecated")
,
+ /* Deprecated commands */
AP_INIT_TAKE1("LogSQLDatabase", set_dbparam_slot,
(void *)"database", RSRC_CONF,
- "The name of the database database for logging")
+ "(Deprecated) Use LogSQLDBParam database dbname. The name of the database database for logging")
,
AP_INIT_TAKE1("LogSQLTableType", set_dbparam_slot,
(void *)"tabletype", RSRC_CONF,
- "What kind of table to create (MyISAM, InnoDB,...) when creating tables")
+ "(Deprecated) Use LogSQLDBParam tabletype type. What kind of table to create (MyISAM, InnoDB,...) when creating tables")
,
AP_INIT_TAKE1("LogSQLSocketFile", set_dbparam_slot,
(void *)"socketfile", RSRC_CONF,
- "Name of the file to employ for socket connections to database")
+ "(Deprecated) Use LogSQLDBParam socketfile socket. Name of the file to employ for socket connections to database")
,
AP_INIT_TAKE1("LogSQLTCPPort", set_dbparam_slot,
- (void *)"tcpport", RSRC_CONF,
- "Port number to use for TCP connections to database, defaults to 3306 if not set")
+ (void *)"port", RSRC_CONF,
+ "(Deprecated) Use LogSQLDBParam port port. Port number to use for TCP connections to database, defaults to 3306 if not set")
,
{NULL}
};
diff --git a/mod_log_sql.h b/mod_log_sql.h
index 1eed9b4..032bd01 100644
--- a/mod_log_sql.h
+++ b/mod_log_sql.h
@@ -24,9 +24,10 @@
#define LOGSQL_DECLARE_DATA __declspec(dllimport)
#endif
+/* Registration function for extract functions */
+
typedef const char *logsql_item_func(request_rec *r, char *a);
-/* Registration Function for extract functions */
LOGSQL_DECLARE(void) log_sql_register_item(server_rec *s, apr_pool_t *p,
char key, logsql_item_func *func, const char *sql_field_name,
int want_orig_default, int string_contents);
@@ -73,14 +74,54 @@ typedef enum {
LOGSQL_TABLE_HEADERSIN | LOGSQL_TABLE_HEADERSOUT | LOGSQL_TABLE_COOKIES
/* MySQL module calls */
-logsql_opendb_ret log_sql_mysql_connect(server_rec *s, logsql_dbconnection *db);
-void log_sql_mysql_close(logsql_dbconnection *db);
-const char *log_sql_mysql_escape(const char *from_str, apr_pool_t *p,
- logsql_dbconnection *db);
-logsql_query_ret log_sql_mysql_query(request_rec *r,logsql_dbconnection *db,
- const char *query);
-logsql_table_ret log_sql_mysql_create(request_rec *r, logsql_dbconnection *db,
- logsql_tabletype table_type, const char *table_name);
+/* Registration function for database drivers */
+
+typedef struct {
+ /* NULL terminated list of drivers strings */
+ char **provided_drivers;
+ /* create a connection to the underlying database layer */
+ logsql_opendb_ret (*connect)(server_rec *s, logsql_dbconnection *db);
+ /* disconnect from the underlying database layer */
+ void (*disconnect)(logsql_dbconnection *db);
+ /* escape the SQL statement according to database rules */
+ const char *(*escape)(const char *from_str, apr_pool_t *p,
+ logsql_dbconnection *db);
+ /* insert a SQL query statement */
+ logsql_query_ret (*insert)(request_rec *r,logsql_dbconnection *db,
+ const char *query);
+ /* create a SQL table named table_name of table_type */
+ logsql_table_ret (*create_table)(request_rec *r, logsql_dbconnection *db,
+ logsql_tabletype table_type, const char *table_name);
+} logsql_dbdriver;
+
+LOGSQL_DECLARE(void) log_sql_register_driver(apr_pool_t *p,
+ logsql_dbdriver *driver);
+
+/* Module initialization Macros */
+#if defined(WITH_APACHE20)
+# define LOGSQL_REGISTER(driver) \
+ static int post_config(apr_pool_t *p, apr_pool_t *plog, apr_pool_t *ptemp, server_rec *s); \
+ static void register_hooks(apr_pool_t *p) { \
+ ap_hook_post_config(post_config, NULL, NULL, APR_HOOK_REALLY_FIRST); \
+ } \
+ \
+ module AP_MODULE_DECLARE_DATA log_sql_##driver##_module = { \
+ STANDARD20_MODULE_STUFF, \
+ NULL, NULL, NULL, NULL, NULL, register_hooks }; \
+ static int post_config(apr_pool_t *p, apr_pool_t *plog, apr_pool_t *ptemp, server_rec *s)
+#elif defined(WITH_APACHE13)
+# define LOGSQL_REGISTER() \
+ static void module_init(server_rec *s, apr_pool_t *p); \
+ module log_sql_##driver##_module = { \
+ STANDARD_MODULE_STUFF, module_init };
+ static void module_init(server_rec *s, apr_pool_t *p)
+#endif
+
+#if defined(WITH_APACHE20)
+#define LOGSQL_REGISTER_RETURN return OK;
+#elif defined(WITH_APACHE13)
+#define LOGSQL_REGISTER_RETURN
+#endif
#endif /* MOD_LOG_SQL_H */
diff --git a/mod_log_sql_mysql.c b/mod_log_sql_mysql.c
index a3f8bbc..5a654f3 100644
--- a/mod_log_sql_mysql.c
+++ b/mod_log_sql_mysql.c
@@ -29,13 +29,13 @@
#define MYSQL_ERROR(mysql) ((mysql)?(mysql_error(mysql)):"MySQL server has gone away")
/* Connect to the MYSQL database */
-logsql_opendb_ret log_sql_mysql_connect(server_rec *s, logsql_dbconnection *db)
+static logsql_opendb_ret log_sql_mysql_connect(server_rec *s, logsql_dbconnection *db)
{
- const char *host = apr_table_get(db->parms,"host");
- const char *user = apr_table_get(db->parms,"user");
- const char *passwd = apr_table_get(db->parms,"passwd");
+ const char *host = apr_table_get(db->parms,"hostname");
+ const char *user = apr_table_get(db->parms,"username");
+ const char *passwd = apr_table_get(db->parms,"password");
const char *database = apr_table_get(db->parms,"database");
- const char *s_tcpport = apr_table_get(db->parms,"tcpport");
+ const char *s_tcpport = apr_table_get(db->parms,"port");
unsigned int tcpport = (s_tcpport)?atoi(s_tcpport):3306;
const char *socketfile = apr_table_get(db->parms,"socketfile");
MYSQL *dblink = db->handle;
@@ -63,7 +63,7 @@ logsql_opendb_ret log_sql_mysql_connect(server_rec *s, logsql_dbconnection *db)
}
/* Close the DB link */
-void log_sql_mysql_close(logsql_dbconnection *db)
+static void log_sql_mysql_close(logsql_dbconnection *db)
{
mysql_close((MYSQL *)db->handle);
}
@@ -71,7 +71,7 @@ void log_sql_mysql_close(logsql_dbconnection *db)
/* Routine to escape the 'dangerous' characters that would otherwise
* corrupt the INSERT string: ', \, and "
*/
-const char *log_sql_mysql_escape(const char *from_str, apr_pool_t *p,
+static const char *log_sql_mysql_escape(const char *from_str, apr_pool_t *p,
logsql_dbconnection *db)
{
if (!from_str)
@@ -110,7 +110,7 @@ const char *log_sql_mysql_escape(const char *from_str, apr_pool_t *p,
}
/* Run a mysql insert query and return a categorized error or success */
-logsql_query_ret log_sql_mysql_query(request_rec *r,logsql_dbconnection *db,
+static logsql_query_ret log_sql_mysql_query(request_rec *r,logsql_dbconnection *db,
const char *query)
{
int retval;
@@ -147,7 +147,7 @@ logsql_query_ret log_sql_mysql_query(request_rec *r,logsql_dbconnection *db,
}
/* Create table table_name of type table_type. */
-logsql_table_ret log_sql_mysql_create(request_rec *r, logsql_dbconnection *db,
+static logsql_table_ret log_sql_mysql_create(request_rec *r, logsql_dbconnection *db,
logsql_tabletype table_type, const char *table_name)
{
int retval;
@@ -231,3 +231,18 @@ logsql_table_ret log_sql_mysql_create(request_rec *r, logsql_dbconnection *db,
signal(SIGPIPE, handler);
return LOGSQL_TABLE_SUCCESS;
}
+
+static char *supported_drivers[] = {"mysql",NULL};
+static logsql_dbdriver mysql_driver = {
+ supported_drivers,
+ log_sql_mysql_connect, /* open DB connection */
+ log_sql_mysql_close, /* close DB connection */
+ log_sql_mysql_escape, /* escape query */
+ log_sql_mysql_query, /* insert query */
+ log_sql_mysql_create /* create table */
+};
+
+LOGSQL_REGISTER(mysql) {
+ log_sql_register_driver(p,&mysql_driver);
+ LOGSQL_REGISTER_RETURN;
+}
diff --git a/mod_log_sql_ssl.c b/mod_log_sql_ssl.c
index 5f3a16e..ca4ced7 100644
--- a/mod_log_sql_ssl.c
+++ b/mod_log_sql_ssl.c
@@ -76,58 +76,11 @@ static const char *extract_ssl_cipher(request_rec *r, char *a)
}
}
-#if defined(WITH_APACHE20)
-static int post_config(apr_pool_t *p, apr_pool_t *plog, apr_pool_t *ptemp, server_rec *s)
-#elif defined(WITH_APACHE13)
-static void module_init(server_rec *s, apr_pool_t *p)
-#endif
+
+LOGSQL_REGISTER(ssl)
{
log_sql_register_item(s,p,'q', extract_ssl_keysize, "ssl_keysize", 0, 1);
log_sql_register_item(s,p,'Q', extract_ssl_maxkeysize, "ssl_maxkeysize", 0, 1);
log_sql_register_item(s,p,'z', extract_ssl_cipher, "ssl_cipher", 0, 1);
-#if defined(WITH_APACHE20)
- return OK;
-#endif
-}
-
-/* The configuration array that sets up the hooks into the module. */
-#if defined(WITH_APACHE20)
-static void register_hooks(apr_pool_t *p) {
- ap_hook_post_config(post_config, NULL, NULL, APR_HOOK_REALLY_FIRST);
+ LOGSQL_REGISTER_RETURN;
}
-
-module AP_MODULE_DECLARE_DATA log_sql_ssl_module = {
- STANDARD20_MODULE_STUFF,
- NULL, /* create per-directory config structures */
- NULL, /* merge per-directory config structures */
- NULL, /* create per-server config structures */
- NULL, /* merge per-server config structures */
- NULL, /* command handlers */
- register_hooks /* register hooks */
-};
-#elif defined(WITH_APACHE13)
-module log_sql_ssl_module = {
- STANDARD_MODULE_STUFF,
- module_init, /* module initializer */
- NULL, /* create per-dir config */
- NULL, /* merge per-dir config */
- NULL, /* create server config */
- NULL, /* merge server config */
- NULL, /* 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 */
- NULL, /* [10] logger */
- NULL /* [3] header parser */
-#if MODULE_MAGIC_NUMBER >= 19970728 /* 1.3-dev or later support these additionals... */
- ,NULL, /* child process initializer */
- NULL, /* process exit/cleanup */
- NULL /* [1] post read-request */
-#endif
-
-};
-#endif
--
cgit