summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--CHANGELOG32
-rw-r--r--CONFIGURATION6
-rw-r--r--INSTALL46
-rw-r--r--LICENSE87
-rw-r--r--Makefile62
-rw-r--r--README42
-rw-r--r--access_log.sql26
-rw-r--r--mod_log_sql.c318
8 files changed, 404 insertions, 215 deletions
diff --git a/CHANGELOG b/CHANGELOG
index 60318c2..24e56a1 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -1,17 +1,39 @@
1$Id: CHANGELOG,v 1.10 2002/04/23 03:46:20 helios Exp $ 1$Id: CHANGELOG,v 1.11 2002/05/14 21:47:14 helios Exp $
2 2
3 3
4TODO: 4TODO:
5* Full commenting of the code. 5* Full commenting of the code.
6* Rethink documentation flow and rewrite? 6* Rethink documentation flow and rewrite?
7* Port connection portion to other DBMS? Genericize the module? Start with PostgreSQL. 7* Port connection portion to other DBMS? Genericize the module? Start with PostgreSQL.
8* Fully test create-table 8* check for mandatory conf directives / syntax quit if not
9* Document new features 9* merge server config into vh config
10* check for mandatory conf directives quit if not 10* port to Apache 2.x
11 11
12 12
13CHANGES: 13CHANGES:
14 14
151.17:
16* Renamed the module mod_log_sql to conform to the project goal of
17 database-inspecificity.
18* Added capability of logging Notes field. This is useful for folks using
19 custom modules that provide loggable info in the notes, e.g. mod_gzip.
20 A new directive MySQLWhichNotes configures which notes to log to the
21 notes_log table.
22* Fixed potential segfault in preserve file function due to silly pfclose
23 placement. (Only affected user if the preserve file couldn't
24 be opened.)
25* Changed default socket file to /tmp/mysql.sock because that's the
26 default on a compiled MySQL.
27* Also check for '-' when I'm creating the table when MySQLMassVirtualHosting
28 is on, and change it to underscore. (Already did this with '.')
29* Took away the prepend of /tmp to the preserve filename. Now the
30 user can specify whatever local path they want. I figure that
31 filesystem permissions will prevent people from doing anything
32 really dumb, and people have requested this change.
33* Better checking in the extract_cookie routine. Before, it could
34 segfault if a person specified "c" but didn't define MySQLWhichCookie.
35
36
151.16: 371.16:
16* Moved all the user DEFINEs inside the .c file -- splitting them 38* Moved all the user DEFINEs inside the .c file -- splitting them
17 between the C and the Makefile was getting just too cumbersome. 39 between the C and the Makefile was getting just too cumbersome.
@@ -25,7 +47,7 @@ CHANGES:
25 version the name of the MySQL socket was hardcoded. Now the user 47 version the name of the MySQL socket was hardcoded. Now the user
26 can configure this at Apache runtime. However, it is a global 48 can configure this at Apache runtime. However, it is a global
27 setting (set once) just like the rest of the actual database info is. 49 setting (set once) just like the rest of the actual database info is.
28 It defaults ot a hardcoded value if the user does not define it. 50 It defaults to a hardcoded value if the user does not define it.
29* A new MySQLCreateTables runtime config directive. Module can now 51* A new MySQLCreateTables runtime config directive. Module can now
30 create the access table on-the-fly. Table creation takes place 52 create the access table on-the-fly. Table creation takes place
31 during the virtual server's first request and is flagged after that to 53 during the virtual server's first request and is flagged after that to
diff --git a/CONFIGURATION b/CONFIGURATION
index 75117c3..9ce05a4 100644
--- a/CONFIGURATION
+++ b/CONFIGURATION
@@ -1,8 +1,8 @@
1$Id: CONFIGURATION,v 1.1 2001/11/28 05:26:54 helios Exp $ 1$Id: CONFIGURATION,v 1.2 2002/05/14 21:47:14 helios Exp $
2 2
3 3
4Run-time configuration directives are fully documented on the 4Run-time configuration directives are fully documented on the
5mod_log_mysql homepage: 5mod_log_sql homepage:
6 6
7http://www.grubbybaby.com/mod_log_mysql/directives.html 7http://www.grubbybaby.com/mod_log_sql/directives.html
8 8
diff --git a/INSTALL b/INSTALL
index c620963..03adc35 100644
--- a/INSTALL
+++ b/INSTALL
@@ -1,4 +1,4 @@
1$Id: INSTALL,v 1.7 2002/04/21 23:01:52 helios Exp $ 1$Id: INSTALL,v 1.8 2002/05/14 21:47:14 helios Exp $
2 2
3 3
4Requirements 4Requirements
@@ -48,8 +48,8 @@ For folks interested in using this module as an Apache DSO:
48 48
491) Unpack the archive into a working directory. 491) Unpack the archive into a working directory.
50 50
51 # tar zxf mod_log_mysql.tar.gz -C /usr/local/src 51 # tar zxf mod_log_sql.tar.gz -C /usr/local/src
52 # cd /usr/local/src/mod_log_mysql 52 # cd /usr/local/src/mod_log_sql
53 53
542) Edit Makefile and make any adjustments for your system. These are 542) Edit Makefile and make any adjustments for your system. These are
55 fully explained in the Makefile. 55 fully explained in the Makefile.
@@ -60,29 +60,29 @@ For folks interested in using this module as an Apache DSO:
60 - The location of your MySQL libraries, find using 'locate libmysqlclient' 60 - The location of your MySQL libraries, find using 'locate libmysqlclient'
61 61
62 FORMAT: 62 FORMAT:
63 # <path>/apxs -i -c -L/path/to/mysqllibs -lmysqlclient -lz mod_log_mysql.c 63 # <path>/apxs -i -c -L/path/to/mysqllibs -lmysqlclient -lz mod_log_sql.c
64 64
65 EXAMPLE: 65 EXAMPLE:
66 # /usr/sbin/apxs -i -c -L/usr/lib/mysql -lmysqlclient -lz mod_log_mysql.c 66 # /usr/sbin/apxs -i -c -L/usr/lib/mysql -lmysqlclient -lz mod_log_sql.c
67 67
68 You should see something like this: 68 You should see something like this:
69 69
70 gcc -fpic -DSHARED_MODULE -I/usr/local/Apache/include -c mod_log_mysql.c 70 gcc -fpic -DSHARED_MODULE -I/usr/local/Apache/include -c mod_log_sql.c
71 ld -Bshareable -o mod_log_mysql.so mod_log_mysql.o 71 ld -Bshareable -o mod_log_sql.so mod_log_sql.o
72 cp mod_log_mysql.so <your path to Apache libexec>/mod_log_mysql.so 72 cp mod_log_sql.so <your path to Apache libexec>/mod_log_sql.so
73 chmod 755 <your path to Apache libexec>/mod_log_mysql.so 73 chmod 755 <your path to Apache libexec>/mod_log_sql.so
74 [activating module blah in /path/to/apache/etc/httpd.conf] 74 [activating module blah in /path/to/apache/etc/httpd.conf]
75 75
764) Add the following stanzas to your httpd.conf file. Put the second stanza 764) Add the following stanzas to your httpd.conf file. Put the second stanza
77 somewhere after the ClearModuleList directive. 77 somewhere after the ClearModuleList directive.
78 78
79 <IfDefine HAVE_LOG_MYSQL> 79 <IfDefine HAVE_LOG_MYSQL>
80 LoadModule mysql_log_module modules/mod_log_mysql.so 80 LoadModule mysql_log_module modules/mod_log_sql.so
81 </IfDefine> 81 </IfDefine>
82 82
83 83
84 <IfDefine HAVE_LOG_MYSQL> 84 <IfDefine HAVE_LOG_MYSQL>
85 AddModule mod_log_mysql.c 85 AddModule mod_log_sql.c
86 </IfDefine> 86 </IfDefine>
87 87
88 88
@@ -99,16 +99,16 @@ Installation (as a static module compiled into httpd)
99 99
1001) Unpack the archive into a working directory. 1001) Unpack the archive into a working directory.
101 101
102 # tar zxf mod_log_mysql.tar.gz -C /usr/local/src 102 # tar zxf mod_log_sql.tar.gz -C /usr/local/src
103 # cd /usr/local/src/mod_log_mysql 103 # cd /usr/local/src/mod_log_sql
104 104
1052) Examine the DEFINEs at the top of mod_log_mysql.c and alter any that 1052) Examine the DEFINEs at the top of mod_log_sql.c and alter any that
106 you choose. Edit Makefile and make any adjustments for your system. 106 you choose. Edit Makefile and make any adjustments for your system.
107 These are fully explained in the Makefile. 107 These are fully explained in the Makefile.
108 108
1093) # make all 1093) # make all
110 (You should receive NO warnings or errors of any kind. 110 (You should receive NO warnings or errors of any kind.
111 If you see messages like this: "mod_log_mysql.c:69: httpd.h: No such 111 If you see messages like this: "mod_log_sql.c:69: httpd.h: No such
112 file or directory" then you do not have your CFLAGS correctly 112 file or directory" then you do not have your CFLAGS correctly
113 pointing to the right include directory.) 113 pointing to the right include directory.)
114 114
@@ -126,7 +126,7 @@ Installation (as a static module compiled into httpd)
126 -L/usr/lib/mysql -lmysqlclient -lm -lz 126 -L/usr/lib/mysql -lmysqlclient -lm -lz
127 127
128 * Find the mod_log_config.o line, and add this line immediately after it: 128 * Find the mod_log_config.o line, and add this line immediately after it:
129 AddModule modules/sql/mod_log_mysql.o 129 AddModule modules/sql/mod_log_sql.o
130 130
131 6b) # cp Configuration.apaci Configuration 131 6b) # cp Configuration.apaci Configuration
132 132
@@ -144,7 +144,7 @@ Installation (as a static module compiled into httpd)
144 144
145 Compiled-in modules: 145 Compiled-in modules:
146 http_core.c 146 http_core.c
147 mod_log_mysql.c <-- That's the line you're looking for. 147 mod_log_sql.c <-- That's the line you're looking for.
148 mod_env.c 148 mod_env.c
149 mod_log_config.c 149 mod_log_config.c
150 mod_mime.c 150 mod_mime.c
@@ -161,7 +161,7 @@ Installation (as a static module compiled into httpd)
161 161
1629) Configure your apache daemon to log to your database. Here's a very 1629) Configure your apache daemon to log to your database. Here's a very
163 basic set of config lines to start you off. Full documentation is 163 basic set of config lines to start you off. Full documentation is
164 available here: http://www.grubbybaby.com/mod_log_mysql/directives.html 164 available here: http://www.grubbybaby.com/mod_log_sql/directives.html
165 165
166 EXAMPLE: Connect to the MySQL database called "apache" running 166 EXAMPLE: Connect to the MySQL database called "apache" running
167 on "dbmachine.foo.com". The module uses username "loguser" and 167 on "dbmachine.foo.com". The module uses username "loguser" and
@@ -186,14 +186,14 @@ Installation (as a static module compiled into httpd)
186 186
187 9a) Special step for users who have a DSO-enabled httpd: 187 9a) Special step for users who have a DSO-enabled httpd:
188 188
189 If you you are building mod_log_mysql as a static module BUT 189 If you you are building mod_log_sql as a static module BUT
190 your httpd is enabled for DSOs, add the following line to your 190 your httpd is enabled for DSOs, add the following line to your
191 httpd.conf: 191 httpd.conf:
192 192
193 AddModule mod_log_mysql.c 193 AddModule mod_log_sql.c
194 194
195 195
19610) If you compiled mod_log_mysql with the ability to make its own tables 19610) If you compiled mod_log_sql with the ability to make its own tables
197 then you can skip this step. Otherwise you need to do it by hand: 197 then you can skip this step. Otherwise you need to do it by hand:
198 198
199 Create a database and table to hold the new log data. I log the 199 Create a database and table to hold the new log data. I log the
@@ -208,7 +208,7 @@ Installation (as a static module compiled into httpd)
208 mysql> create database apache; 208 mysql> create database apache;
209 209
210 Then create the table called "access_log". I enclosed an SQL file 210 Then create the table called "access_log". I enclosed an SQL file
211 that will create every column type that mod_log_mysql supports. 211 that will create every column type that mod_log_sql supports.
212 Unless you're just testing or playing around, this is probably NOT 212 Unless you're just testing or playing around, this is probably NOT
213 what you want, so edit the file first and delete the lines that 213 what you want, so edit the file first and delete the lines that
214 don't pertain to you. Then: 214 don't pertain to you. Then:
@@ -222,7 +222,7 @@ Installation (as a static module compiled into httpd)
222 222
223 mysql> grant insert,create on apache.* to loguser@my.apachemachine.com identified by 'l0gger'; 223 mysql> grant insert,create on apache.* to loguser@my.apachemachine.com identified by 'l0gger';
224 224
225 Security is a very real concern. mod_log_mysql by default is 225 Security is a very real concern. mod_log_sql by default is
226 set up to create the SQL tables it needs. If you have deactivated 226 set up to create the SQL tables it needs. If you have deactivated
227 this capability, then create a user called "loguser" with the password 227 this capability, then create a user called "loguser" with the password
228 "l0gger" with only the capability of INSERT to "access_log": 228 "l0gger" with only the capability of INSERT to "access_log":
diff --git a/LICENSE b/LICENSE
index cd0c286..97de9c4 100644
--- a/LICENSE
+++ b/LICENSE
@@ -1,58 +1,55 @@
1$Id: LICENSE,v 1.1 2001/11/28 05:26:54 helios Exp $ 1$Id: LICENSE,v 1.2 2002/05/14 21:47:14 helios Exp $
2 2
3Copyright (c) 2002 Christopher B. Powell. All rights reserved.
4Portions copyright (c) 2000 The Apache Software Foundation.
3 5
4In compliance with the requirements set forth by The Apache Group,
5the original license to this code is hereby reproduced:
6
7
8====================================================================
9Copyright (c) 1995-1997 The Apache Group. All rights reserved.
10
11Redistribution and use in source and binary forms, with or without 6Redistribution and use in source and binary forms, with or without
12modification, are permitted provided that the following conditions 7modification, are permitted provided that the following conditions
13are met: 8are met:
14 9
151. Redistributions of source code must retain the above copyright 101. Redistributions of source code must retain the above copyright
16 notice, this list of conditions and the following disclaimer. 11 notice, this list of conditions and the following disclaimer.
17 12
182. Redistributions in binary form must reproduce the above copyright 132. Redistributions in binary form must reproduce the above copyright
19 notice, this list of conditions and the following disclaimer in 14 notice, this list of conditions and the following disclaimer in
20 the documentation and/or other materials provided with the 15 the documentation and/or other materials provided with the
21 distribution. 16 distribution.
22 17
233. All advertising materials mentioning features or use of this 183. The end-user documentation included with the redistribution,
24 software must display the following acknowledgment: 19 if any, must include the following acknowledgment:
25 "This product includes software developed by the Apache Group 20 "This product includes software developed by the
26 for use in the Apache HTTP server project (http://www.apache.org/)." 21 Apache Software Foundation (http://www.apache.org/)
27 22 and by Christopher Powell, mod_log_mysql (TM) Module Maintainer
284. The names "Apache Server" and "Apache Group" must not be used to 23 (http://www.grubbybaby.com/mod_log_mysql/)."
29 endorse or promote products derived from this software without 24 Alternately, this acknowledgment may appear in the software itself,
30 prior written permission. 25 if and wherever such third-party acknowledgments normally appear.
31 26
325. Redistributions of any form whatsoever must retain the following 274. The names "mod_log_mysql" and "mod_log_sql" must
33 acknowledgment: 28 not be used to endorse or promote products derived from this
34 "This product includes software developed by the Apache Group 29 software without prior written permission. For written
35 for use in the Apache HTTP server project (http://www.apache.org/)." 30 permission, please contact <chris@grubbybaby.com>.
36 31
37THIS SOFTWARE IS PROVIDED BY THE APACHE GROUP ``AS IS'' AND ANY 325. Products derived from this software may not be called
38EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 33 "mod_log_mysql" or "mod_log_sql", nor may "mod_log_mysql" or
39IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 34 "mod_log_sql" appear in their names, without prior written permission
40PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE APACHE GROUP OR 35 of Christopher B. Powell.
36
376. Redistributions of any form whatsoever must retain the following
38 acknowledgment: "This product includes software developed by
39 Christopher B. Powell <chris@grubbybaby.com> for use in the
40 mod_log_mysql (TM) project (http://www.grubbybaby.com/mod_log_mysql/).
41
42THIS SOFTWARE IS PROVIDED `AS IS'' AND ANY EXPRESSED OR IMPLIED
43WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
44OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
45DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
41ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 46ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
42SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 47SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
43NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 48LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
44LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 49USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
45HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 50ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
46STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 51OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
47ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 52OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
48OF THE POSSIBILITY OF SUCH DAMAGE. 53SUCH DAMAGE.
49====================================================================
50 54
51This software consists of voluntary contributions made by many
52individuals on behalf of the Apache Group and was originally based
53on public domain software written at the National Center for
54Supercomputing Applications, University of Illinois, Urbana-Champaign.
55For more information on the Apache Group and the Apache HTTP server
56project, please see <http://www.apache.org/>.
57 55
58 \ No newline at end of file
diff --git a/Makefile b/Makefile
index 6c3c98f..468f6d6 100644
--- a/Makefile
+++ b/Makefile
@@ -1,5 +1,5 @@
1# $Id: Makefile,v 1.9 2002/04/21 23:01:52 helios Exp $ 1# $Id: Makefile,v 1.10 2002/05/14 21:47:14 helios Exp $
2MLMVERS = 1.16 2MLMVERS = 1.17
3 3
4# Where you unpacked your Apache tarball -- the source. 4# Where you unpacked your Apache tarball -- the source.
5APACHESOURCE = /usr/local/src/apache_1.3.22 5APACHESOURCE = /usr/local/src/apache_1.3.22
@@ -7,16 +7,28 @@ APACHESOURCE = /usr/local/src/apache_1.3.22
7# Where Apache [got|will get] installed 7# Where Apache [got|will get] installed
8APACHEINST = /usr/local/Apache 8APACHEINST = /usr/local/Apache
9 9
10# Set the WANT_SSL_LOGGING define in mod_log_mysql.c if you want to log SSL 10# Do you want to log SSL information?
11# info, or #undef it if you don't. Then use the first CFLAGS if you *do* 11# Yes?
12# WANT_SSL_LOGGING, and confirm the paths. 12# - #define WANT_SSL_LOGGING in mod_log_sql.c
13# - pick (A) below
14# No?
15# - #undef WANT_SSL_LOGGING in mod_log_sql.c
16# - pick (B) below
17
18
19# (A)
13# 20#
21# Modify "/usr/include/mysql" to where YOUR mysql.h can be found,
14# Modify "/usr/local/ssl/include" to where YOUR openssl/*.h files are, 22# Modify "/usr/local/ssl/include" to where YOUR openssl/*.h files are,
15# Modify "/usr/include/db1" to where YOUR ndbm.h can be found, 23# Modify "/usr/include/db1" to where YOUR ndbm.h can be found,
16# Modify "/usr/local/src/apache_1.3.22/src/modules/ssl" to where YOUR mod_ssl.h can be found. 24# Modify "/usr/local/src/apache_1.3.22/src/modules/ssl" to where YOUR mod_ssl.h can be found.
17# 25#
18# How to find your directories: 26# How to find your directories:
19# 27#
28# $ locate mysql.h
29# /usr/include/mysql/mysql.h
30# ^^^^^^^^^^^^^^^^^^
31#
20# $ locate x509.h 32# $ locate x509.h
21# /usr/local/ssl/include/openssl/x509.h 33# /usr/local/ssl/include/openssl/x509.h
22# ^^^^^^^^^^^^^^^^^^^^^^ 34# ^^^^^^^^^^^^^^^^^^^^^^
@@ -28,11 +40,23 @@ APACHEINST = /usr/local/Apache
28# $ locate mod_ssl.h 40# $ locate mod_ssl.h
29# /usr/local/src/apache_1.3.22/src/modules/ssl/mod_ssl.h 41# /usr/local/src/apache_1.3.22/src/modules/ssl/mod_ssl.h
30# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 42# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
43# Now uncomment this CFLAGS and comment out the one further down:
31 44
32CFLAGS = -fpic -O2 -Wall -I${APACHEINST}/include -I/usr/local/ssl/include -I/usr/include/db1 -I${APACHESOURCE}/src/modules/ssl 45CFLAGS = -fpic -O2 -Wall -I${APACHEINST}/include -I/usr/include/mysql -I/usr/local/ssl/include -I/usr/include/db1 -I${APACHESOURCE}/src/modules/ssl
46
47# (B)
48#
49# Modify "/usr/include/mysql" to where YOUR mysql.h can be found,
50#
51# How to find your directories:
52#
53# $ locate mysql.h
54# /usr/include/mysql/mysql.h
55# ^^^^^^^^^^^^^^^^^^
56#
57# Comment out CFLAGS above and uncomment CFLAGS below:
33 58
34# Use this CFLAGS if you don't WANT_SSL_LOGGING: 59#CFLAGS = -fpic -O2 -Wall -I${APACHEINST}/include -I/usr/include/mysql
35#CFLAGS = -fpic -O2 -Wall -I${APACHEINST}/include
36 60
37 61
38# --------------------------------------------------------- 62# ---------------------------------------------------------
@@ -41,24 +65,24 @@ CFLAGS = -fpic -O2 -Wall -I${APACHEINST}/include -I/usr/local/ssl/include -I/
41CC = gcc 65CC = gcc
42INSTALL = /usr/bin/install -m 664 66INSTALL = /usr/bin/install -m 664
43 67
44all: mod_log_mysql.o 68all: mod_log_sql.o
45 69
46mod_log_mysql.o: mod_log_mysql.c Makefile 70mod_log_sql.o: mod_log_sql.c Makefile
47 $(CC) ${CFLAGS} -c mod_log_mysql.c 71 $(CC) ${CFLAGS} -c mod_log_sql.c
48 72
49install: all 73install: all
50 $(INSTALL) -d -m 755 ${APACHESOURCE}/src/modules/sql 74 $(INSTALL) -d -m 755 ${APACHESOURCE}/src/modules/sql
51 $(INSTALL) mod_log_mysql.c ${APACHESOURCE}/src/modules/sql/mod_log_mysql.c 75 $(INSTALL) mod_log_sql.c ${APACHESOURCE}/src/modules/sql/mod_log_sql.c
52 $(INSTALL) Makefile ${APACHESOURCE}/src/modules/sql/Makefile 76 $(INSTALL) Makefile ${APACHESOURCE}/src/modules/sql/Makefile
53 $(INSTALL) mod_log_mysql.o ${APACHESOURCE}/src/modules/sql/mod_log_mysql.o 77 $(INSTALL) mod_log_sql.o ${APACHESOURCE}/src/modules/sql/mod_log_sql.o
54 78
55distro: all 79distro: all
56 cp -f INSTALL ${APACHEINST}/html/mod_log_mysql/ 80 cp -f INSTALL ${APACHEINST}/html/mod_log_sql/
57 cp -f README ${APACHEINST}/html/mod_log_mysql/ 81 cp -f README ${APACHEINST}/html/mod_log_sql/
58 cp -f CHANGELOG ${APACHEINST}/html/mod_log_mysql/ 82 cp -f CHANGELOG ${APACHEINST}/html/mod_log_sql/
59 cd ..; tar zcf mod_log_mysql-${MLMVERS}.tar.gz --exclude mod_log_mysql/CVS mod_log_mysql/; $(INSTALL) mod_log_mysql-${MLMVERS}.tar.gz ${APACHEINST}/html/mod_log_mysql/; rm -f mod_log_mysql-${MLMVERS}.tar.gz 83 cd ..; tar zcf mod_log_sql-${MLMVERS}.tar.gz --exclude mod_log_sql/CVS mod_log_sql/; $(INSTALL) mod_log_sql-${MLMVERS}.tar.gz ${APACHEINST}/html/mod_log_sql/; rm -f mod_log_sql-${MLMVERS}.tar.gz
60 rm -f ${APACHEINST}/html/mod_log_mysql/mod_log_mysql.tar.gz 84 rm -f ${APACHEINST}/html/mod_log_sql/mod_log_sql.tar.gz
61 ln -s mod_log_mysql-${MLMVERS}.tar.gz ${APACHEINST}/html/mod_log_mysql/mod_log_mysql.tar.gz 85 ln -s mod_log_sql-${MLMVERS}.tar.gz ${APACHEINST}/html/mod_log_sql/mod_log_sql.tar.gz
62 86
63clean: 87clean:
64 rm -f *.o *~ 88 rm -f *.o *~
diff --git a/README b/README
index 7bea822..077b6c4 100644
--- a/README
+++ b/README
@@ -1,35 +1,42 @@
1$Id: README,v 1.5 2002/04/21 23:01:53 helios Exp $ 1$Id: README,v 1.6 2002/05/14 21:47:15 helios Exp $
2 2
3 3
4Homepage 4Homepage
5-------- 5--------
6http://www.grubbybaby.com/mod_log_mysql/ 6http://www.grubbybaby.com/mod_log_sql/
7
8 7
9 8
10Approach 9Approach
11-------- 10--------
11This project was formerly known as mod_log_mysql. It has been renamed
12to mod_log_sql in order to reflect the project goal of
13database-inspecificity. The module currently supports MySQL, and
14development for other database backends is underway.
12 15
13In order to save speed and overhead, links are kept alive in between 16In order to save speed and overhead, links are kept alive in between
14queries. This module uses one SQL link per httpd process. Among other 17queries. This module uses one SQL link per httpd process. Among other
15things, this means that this module supports logging into only one 18things, this means that this module supports logging into only one
16MySQL server, and for now, also, only one SQL database. 19MySQL server, and for now, also, only one SQL database. But that's a
20small tradeoff compared to the blinding speed of this module.
17 21
18Virtual hosts are supported in the same manner they are in the regular 22Virtual hosts are supported in the same manner they are in the regular
19logging modules. If you specify a different table for a virtual 23logging modules. You define some basic 'global' directives in the
20host it will be used, otherwise the 'general' would be used. 24main server config, then you define more specific 'local' directives
25inside each virtualhost stanza.
21 26
22SQL links are opened by each child process when it is born. Error reporting 27SQL links are opened by each child process when it is born. Error reporting
23is robust throughout and will let you know about database issues 28is robust throughout and will let you know about database issues
24in the standard Apache error-log for the server or virtual server. 29in the standard Apache error-log for the server or virtual server.
25 30
26A robust "preserve" capability has now been implemented as well. This 31A robust "preserve" capability has now been implemented. This permits
27permits the module to preserve any failed INSERT commands to a local 32the module to preserve any failed INSERT commands to a local file on
28file on its machine. In any situation that the database is unavailable -- 33its machine. In any situation that the database is unavailable -- e.g.
29e.g. the network fails, you reboot the machine, etc. -- mod_log_mysql 34the network fails, you reboot the db host, etc. -- mod_log_sql will
30will note this in the error log and begin appending its log entries to 35note this in the error log and begin appending its log entries to the
31the preserve file. At the time that your MySQL server returns to service, 36preserve file (which is created with the user & group ID of the running
32each of these preserve files is easily imported because it is stored in SQL: 37Apache process, e.g. "nobody" on many Linux installations). At the time
38that your MySQL server returns to service, each of these preserve files
39is easily imported because it is simply a series of SQL insert statements:
33 40
34 # mysql -uadminuser -p mydbname < /tmp/mysql-preserve 41 # mysql -uadminuser -p mydbname < /tmp/mysql-preserve
35 42
@@ -41,11 +48,11 @@ Supported directives
41Please see the web-based documentation for full explanation of all 48Please see the web-based documentation for full explanation of all
42supported run-time directives. 49supported run-time directives.
43 50
44 http://www.grubbybaby.com/mod_log_mysql/directives.html 51 http://www.grubbybaby.com/mod_log_sql/directives.html
45 52
46See the FAQ for some handy examples: 53See the FAQ for some handy examples:
47 54
48 http://www.grubbybaby.com/mod_log_mysql/faq.html 55 http://www.grubbybaby.com/mod_log_sql/faq.html
49 56
50 57
51What gets logged by default? 58What gets logged by default?
@@ -65,8 +72,9 @@ Notes
65 72
66* You will customarily set most of your run-time configuration directives 73* You will customarily set most of your run-time configuration directives
67 on a per-virtualserver basis, with only MySQLMassVirtualHosting, 74 on a per-virtualserver basis, with only MySQLMassVirtualHosting,
68 MySQLLoginInfo and MySQLDatabase 'outside' in the main server config. 75 MySQLLoginInfo, MySQLDatabase, MySQLSocketFile, MySQLCreateTables,
69 Any directives other than those in the main config do NOT get inherited 76 and MySQLMassVirtualHosting 'outside' in the main server config. Any
77 directives other than those in the main config do NOT get inherited
70 by the virutal servers. 78 by the virutal servers.
71 79
72* The 'time_stamp' field is stored in an UNSIGNED INTEGER column, in the 80* The 'time_stamp' field is stored in an UNSIGNED INTEGER column, in the
diff --git a/access_log.sql b/access_log.sql
index a667494..4966c62 100644
--- a/access_log.sql
+++ b/access_log.sql
@@ -1,25 +1,25 @@
1create table access_log ( 1create table access_log (
2 agent varchar(255) not null, 2 agent varchar(255) ,
3 bytes_sent int not null, 3 bytes_sent int ,
4 child_pid smallint unsigned, 4 child_pid smallint unsigned,
5 cookie varchar(255), 5 cookie varchar(255),
6 request_file varchar(255), 6 request_file varchar(255),
7 referer varchar(255) not null, 7 referer varchar(255) ,
8 remote_host varchar(50) not null, 8 remote_host varchar(50) ,
9 remote_logname varchar(50) not null, 9 remote_logname varchar(50) ,
10 remote_user varchar(50) not null, 10 remote_user varchar(50) ,
11 request_duration smallint not null, 11 request_duration smallint ,
12 request_line varchar(255), 12 request_line varchar(255),
13 request_method varchar(6) not null, 13 request_method varchar(6) ,
14 request_protocol varchar(10) not null, 14 request_protocol varchar(10) ,
15 request_time char(28), 15 request_time char(28),
16 request_uri varchar(50) not null, 16 request_uri varchar(50) ,
17 server_port smallint unsigned, 17 server_port smallint unsigned,
18 ssl_cipher varchar(25), 18 ssl_cipher varchar(25),
19 ssl_keysize smallint unsigned, 19 ssl_keysize smallint unsigned,
20 ssl_maxkeysize smallint unsigned, 20 ssl_maxkeysize smallint unsigned,
21 status smallint not null, 21 status smallint ,
22 time_stamp int unsigned not null, 22 time_stamp int unsigned ,
23 virtual_host varchar(50) not null 23 virtual_host varchar(50)
24) 24)
25 25
diff --git a/mod_log_sql.c b/mod_log_sql.c
index 25a5013..84c6115 100644
--- a/mod_log_sql.c
+++ b/mod_log_sql.c
@@ -1,4 +1,4 @@
1/* $Id: mod_log_sql.c,v 1.11 2002/04/23 17:26:15 helios Exp $ */ 1/* $Id: mod_log_sql.c,v 1.12 2002/05/14 21:47:15 helios Exp $ */
2 2
3/* --------* 3/* --------*
4 * DEFINES * 4 * DEFINES *
@@ -20,12 +20,12 @@
20 * INCLUDES * 20 * INCLUDES *
21 * ---------*/ 21 * ---------*/
22#include <time.h> 22#include <time.h>
23#include <mysql/mysql.h>
24#include <stdio.h> 23#include <stdio.h>
25#include "httpd.h" 24#include "httpd.h"
26#include "http_config.h" 25#include "http_config.h"
27#include "http_log.h" 26#include "http_log.h"
28#include "http_core.h" 27#include "http_core.h"
28#include "mysql.h"
29 29
30#if MODULE_MAGIC_NUMBER >= 19980324 /* M_M_N is defined in /usr/local/Apache/include/ap_mmn.h, 19990320 as of this writing. */ 30#if MODULE_MAGIC_NUMBER >= 19980324 /* M_M_N is defined in /usr/local/Apache/include/ap_mmn.h, 19990320 as of this writing. */
31 #include "ap_compat.h" 31 #include "ap_compat.h"
@@ -55,7 +55,7 @@ char *db_name = NULL;
55char *db_host = NULL; 55char *db_host = NULL;
56char *db_user = NULL; 56char *db_user = NULL;
57char *db_pwd = NULL; 57char *db_pwd = NULL;
58char *socket_file = "/var/lib/mysql/mysql.sock"; 58char *socket_file = "/tmp/mysql.sock";
59 59
60typedef const char *(*item_key_func) (request_rec *, char *); 60typedef const char *(*item_key_func) (request_rec *, char *);
61 61
@@ -67,10 +67,12 @@ typedef const char *(*item_key_func) (request_rec *, char *);
67 */ 67 */
68typedef struct { 68typedef struct {
69 int table_made; 69 int table_made;
70 char *transfer_table_name;
71 array_header *referer_ignore_list; 70 array_header *referer_ignore_list;
72 array_header *transfer_ignore_list; 71 array_header *transfer_ignore_list;
73 array_header *remhost_ignore_list; 72 array_header *remhost_ignore_list;
73 array_header *notes_list;
74 char *notes_table_name;
75 char *transfer_table_name;
74 char *transfer_log_format; 76 char *transfer_log_format;
75 char *preserve_file; 77 char *preserve_file;
76 char *cookie_name; 78 char *cookie_name;
@@ -322,64 +324,66 @@ static const char *extract_cookie(request_rec *r, char *a)
322 324
323 log_mysql_state *cls = get_module_config(r->server->module_config, &mysql_log_module); 325 log_mysql_state *cls = get_module_config(r->server->module_config, &mysql_log_module);
324 326
325 #ifdef DEBUG 327 if (cls->cookie_name != NULL) {
326 ap_log_error(APLOG_MARK,DEBUGLEVEL,r->server,"watching for cookie '%s'", cls->cookie_name);
327 #endif
328
329 /* Fetch out the cookie header */
330 cookiestr = (char *)table_get(r->headers_in, "cookie2");
331 if (cookiestr != NULL) {
332 #ifdef DEBUG 328 #ifdef DEBUG
333 ap_log_error(APLOG_MARK,DEBUGLEVEL,r->server,"Cookie2: [%s]", cookiestr); 329 ap_log_error(APLOG_MARK,DEBUGLEVEL,r->server,"watching for cookie '%s'", cls->cookie_name);
334 #endif 330 #endif
335 /* Does the cookie string contain one with our name? */ 331
336 isvalid = strstr(cookiestr, cls->cookie_name); 332 /* Fetch out the cookie header */
337 if (isvalid != NULL) { 333 cookiestr = (char *)table_get(r->headers_in, "cookie2");
338 /* Move past the cookie name and equal sign */ 334 if (cookiestr != NULL) {
339 isvalid += strlen(cls->cookie_name) + 1; 335 #ifdef DEBUG
340 /* Duplicate it into the pool */ 336 ap_log_error(APLOG_MARK,DEBUGLEVEL,r->server,"Cookie2: [%s]", cookiestr);
341 cookiebuf = ap_pstrdup(r->pool, isvalid); 337 #endif
342 /* Segregate just this cookie out of the string 338 /* Does the cookie string contain one with our name? */
343 * with a terminating nul at the first semicolon */ 339 isvalid = strstr(cookiestr, cls->cookie_name);
344 cookieend = strchr(cookiebuf, ';'); 340 if (isvalid != NULL) {
345 if (cookieend != NULL) 341 /* Move past the cookie name and equal sign */
346 *cookieend = '\0'; 342 isvalid += strlen(cls->cookie_name) + 1;
347 return cookiebuf; 343 /* Duplicate it into the pool */
348 } 344 cookiebuf = ap_pstrdup(r->pool, isvalid);
349 } 345 /* Segregate just this cookie out of the string
350 346 * with a terminating nul at the first semicolon */
351 cookiestr = (char *)table_get(r->headers_in, "cookie"); 347 cookieend = strchr(cookiebuf, ';');
352 if (cookiestr != NULL) { 348 if (cookieend != NULL)
353 #ifdef DEBUG 349 *cookieend = '\0';
354 ap_log_error(APLOG_MARK,DEBUGLEVEL,r->server,"Cookie: [%s]", cookiestr); 350 return cookiebuf;
355 #endif 351 }
356 isvalid = strstr(cookiestr, cls->cookie_name);
357 if (isvalid != NULL) {
358 isvalid += strlen(cls->cookie_name) + 1;
359 cookiebuf = ap_pstrdup(r->pool, isvalid);
360 cookieend = strchr(cookiebuf, ';');
361 if (cookieend != NULL)
362 *cookieend = '\0';
363 return cookiebuf;
364 } 352 }
365 }
366 353
367 cookiestr = table_get(r->headers_out, "set-cookie"); 354 cookiestr = (char *)table_get(r->headers_in, "cookie");
368 if (cookiestr != NULL) { 355 if (cookiestr != NULL) {
369 #ifdef DEBUG 356 #ifdef DEBUG
370 ap_log_error(APLOG_MARK,DEBUGLEVEL,r->server,"Set-Cookie: [%s]", cookiestr); 357 ap_log_error(APLOG_MARK,DEBUGLEVEL,r->server,"Cookie: [%s]", cookiestr);
371 #endif 358 #endif
372 isvalid = strstr(cookiestr, cls->cookie_name); 359 isvalid = strstr(cookiestr, cls->cookie_name);
373 if (isvalid != NULL) { 360 if (isvalid != NULL) {
374 isvalid += strlen(cls->cookie_name) + 1; 361 isvalid += strlen(cls->cookie_name) + 1;
375 cookiebuf = ap_pstrdup(r->pool, isvalid); 362 cookiebuf = ap_pstrdup(r->pool, isvalid);
376 cookieend = strchr(cookiebuf, ';'); 363 cookieend = strchr(cookiebuf, ';');
377 if (cookieend != NULL) 364 if (cookieend != NULL)
378 *cookieend = '\0'; 365 *cookieend = '\0';
379 return cookiebuf; 366 return cookiebuf;
367 }
380 } 368 }
381 }
382 369
370 cookiestr = table_get(r->headers_out, "set-cookie");
371 if (cookiestr != NULL) {
372 #ifdef DEBUG
373 ap_log_error(APLOG_MARK,DEBUGLEVEL,r->server,"Set-Cookie: [%s]", cookiestr);
374 #endif
375 isvalid = strstr(cookiestr, cls->cookie_name);
376 if (isvalid != NULL) {
377 isvalid += strlen(cls->cookie_name) + 1;
378 cookiebuf = ap_pstrdup(r->pool, isvalid);
379 cookieend = strchr(cookiebuf, ';');
380 if (cookieend != NULL)
381 *cookieend = '\0';
382 return cookiebuf;
383 }
384 }
385 }
386
383 return "-"; 387 return "-";
384} 388}
385 389
@@ -393,12 +397,26 @@ static const char *extract_request_timestamp(request_rec *r, char *a)
393 397
394static const char *extract_note(request_rec *r, char *a) 398static const char *extract_note(request_rec *r, char *a)
395{ 399{
396 return table_get(r->notes, a); 400 return ap_table_get(r->notes, a);
401
402 /*ap_table_do(extract_table, r, r->notes, NULL);*/
403
397} 404}
398 405
399static const char *extract_env_var(request_rec *r, char *a) 406static const char *extract_env_var(request_rec *r, char *a)
400{ 407{
401 return table_get(r->subprocess_env, "HTTP_USER_AGENT"); 408 return ap_table_get(r->subprocess_env, a);
409}
410
411static const char *extract_unique_id(request_rec *r, char *a)
412{
413 const char *tempid;
414
415 tempid = ap_table_get(r->subprocess_env, "UNIQUE_ID");
416 if (!tempid)
417 return "-";
418 else
419 return tempid;
402} 420}
403 421
404/* End declarations of various extract_ functions */ 422/* End declarations of various extract_ functions */
@@ -421,7 +439,8 @@ struct log_mysql_item_list {
421 { 'H', extract_request_protocol, "request_protocol", 0, 1 }, 439 { 'H', extract_request_protocol, "request_protocol", 0, 1 },
422 { 'h', extract_remote_host, "remote_host", 0, 1 }, 440 { 'h', extract_remote_host, "remote_host", 0, 1 },
423 { 'i', extract_header_in, "header_in", 0, 1 }, 441 { 'i', extract_header_in, "header_in", 0, 1 },
424 { 'l', extract_remote_logname, "remote_logname", 0, 1 }, 442 { 'I', extract_unique_id, "id", 0, 1 },
443 { 'l', extract_remote_logname, "remote_logname", 0, 1 },
425 { 'm', extract_request_method, "request_method", 0, 1 }, 444 { 'm', extract_request_method, "request_method", 0, 1 },
426 { 'n', extract_note, "note", 0, 1 }, 445 { 'n', extract_note, "note", 0, 1 },
427 { 'o', extract_header_out, "header_out", 0, 1 }, 446 { 'o', extract_header_out, "header_out", 0, 1 },
@@ -506,6 +525,31 @@ int open_logdb_link()
506 return 0; 525 return 0;
507} 526}
508 527
528#ifdef DEBUG
529static int trace(void *data, const char *key, const char *val)
530{
531 FILE *fp;
532 request_rec *r = (request_rec *)data;
533
534 fp = pfopen(r->pool, "/tmp/trace", "a");
535
536 if (fp) {
537 fprintf(fp, "Field '%s' == '%s'\n", key, val);
538 }
539
540 pfclose(r->pool, fp);
541
542 return TRUE;
543}
544#endif
545
546const char *extract_table(void *data, const char *key, const char *val)
547{
548 request_rec *r = (request_rec *)data;
549
550 return ap_pstrcat(r->pool, key, " = ", val, " ", NULL);
551}
552
509void preserve_entry(request_rec *r, const char *query) 553void preserve_entry(request_rec *r, const char *query)
510{ 554{
511 FILE *fp; 555 FILE *fp;
@@ -514,9 +558,10 @@ void preserve_entry(request_rec *r, const char *query)
514 fp = pfopen(r->pool, cls->preserve_file, "a"); 558 fp = pfopen(r->pool, cls->preserve_file, "a");
515 if (fp == NULL) 559 if (fp == NULL)
516 ap_log_error(APLOG_MARK,ERRLEVEL,r->server,"attempted append of local offline file but failed."); 560 ap_log_error(APLOG_MARK,ERRLEVEL,r->server,"attempted append of local offline file but failed.");
517 else 561 else {
518 fprintf(fp,"%s;\n", query); 562 fprintf(fp,"%s;\n", query);
519 pfclose(r->pool, fp); 563 pfclose(r->pool, fp);
564 }
520} 565}
521 566
522/*-----------------------------------------------------*/ 567/*-----------------------------------------------------*/
@@ -629,11 +674,11 @@ const char *set_log_mysql_cookie(cmd_parms *parms, void *dummy, char *arg)
629 674
630const char *set_log_mysql_preserve_file(cmd_parms *parms, void *dummy, char *arg) 675const char *set_log_mysql_preserve_file(cmd_parms *parms, void *dummy, char *arg)
631{ 676{
632 char *pfile; 677 /* char *pfile; */
633 log_mysql_state *cls = get_module_config(parms->server->module_config, &mysql_log_module); 678 log_mysql_state *cls = get_module_config(parms->server->module_config, &mysql_log_module);
634 679
635 pfile = ap_pstrcat(parms->pool, "/tmp/", arg, NULL); 680 /* pfile = ap_pstrcat(parms->pool, "/tmp/", arg, NULL); */
636 cls->preserve_file = pfile; 681 cls->preserve_file = arg;
637 return NULL; 682 return NULL;
638} 683}
639 684
@@ -662,6 +707,17 @@ const char *set_transfer_log_mysql_table(cmd_parms *parms, void *dummy, char *ar
662 return NULL; 707 return NULL;
663} 708}
664 709
710const char *set_notes_log_mysql_table(cmd_parms *parms, void *dummy, char *arg)
711{
712 log_mysql_state *cls = get_module_config(parms->server->module_config, &mysql_log_module);
713
714 if (massvirtual != 0)
715 ap_log_error(APLOG_MARK,WARNINGLEVEL,parms->server,"do not set MySQLNotesLogTable when MySQLMassVirtualHosting is On. Ignoring.");
716 else
717 cls->notes_table_name = arg;
718 return NULL;
719}
720
665const char *set_mysql_transfer_log_format(cmd_parms *parms, void *dummy, char *arg) 721const char *set_mysql_transfer_log_format(cmd_parms *parms, void *dummy, char *arg)
666{ 722{
667 log_mysql_state *cls = get_module_config(parms->server->module_config, &mysql_log_module); 723 log_mysql_state *cls = get_module_config(parms->server->module_config, &mysql_log_module);
@@ -677,6 +733,7 @@ const char *set_mysql_socket_file(cmd_parms *parms, void *dummy, char *arg)
677 return NULL; 733 return NULL;
678} 734}
679 735
736
680const char *add_referer_mysql_ignore(cmd_parms *parms, void *dummy, char *arg) 737const char *add_referer_mysql_ignore(cmd_parms *parms, void *dummy, char *arg)
681{ 738{
682 char **addme; 739 char **addme;
@@ -707,6 +764,16 @@ const char *add_remhost_mysql_ignore(cmd_parms *parms, void *dummy, char *arg)
707 return NULL; 764 return NULL;
708} 765}
709 766
767const char *add_mysql_note(cmd_parms *parms, void *dummy, char *arg)
768{
769 char **addme;
770 log_mysql_state *cls = get_module_config(parms->server->module_config, &mysql_log_module);
771
772 addme = push_array(cls->notes_list);
773 *addme = pstrdup(cls->notes_list->pool, arg);
774 return NULL;
775}
776
710 777
711 778
712 779
@@ -780,17 +847,18 @@ void *log_mysql_make_state(pool *p, server_rec *s)
780 847
781 log_mysql_state *cls = (log_mysql_state *) ap_palloc(p, sizeof(log_mysql_state)); 848 log_mysql_state *cls = (log_mysql_state *) ap_palloc(p, sizeof(log_mysql_state));
782 849
783
784 cls->transfer_table_name = NULL; 850 cls->transfer_table_name = NULL;
785 cls->transfer_log_format = NULL; 851 cls->transfer_log_format = NULL;
852 cls->notes_table_name = "notes";
786 853
787 cls->referer_ignore_list = make_array(p, 1, sizeof(char *)); 854 cls->referer_ignore_list = make_array(p, 1, sizeof(char *));
788 cls->transfer_ignore_list = make_array(p, 1, sizeof(char *)); 855 cls->transfer_ignore_list = make_array(p, 1, sizeof(char *));
789 cls->remhost_ignore_list = make_array(p, 1, sizeof(char *)); 856 cls->remhost_ignore_list = make_array(p, 1, sizeof(char *));
790 857 cls->notes_list = make_array(p, 1, sizeof(char *));
791 cls->table_made = 0; 858 cls->table_made = 0;
792 859
793 cls->preserve_file = "/tmp/mysql-preserve"; 860 cls->preserve_file = "/tmp/mysql-preserve";
861 cls->cookie_name = NULL;
794 862
795 return (void *) cls; 863 return (void *) cls;
796} 864}
@@ -803,6 +871,9 @@ command_rec log_mysql_cmds[] = {
803 {"MySQLTransferLogTable", set_transfer_log_mysql_table, NULL, RSRC_CONF, TAKE1, 871 {"MySQLTransferLogTable", set_transfer_log_mysql_table, NULL, RSRC_CONF, TAKE1,
804 "The MySQL table that holds the transfer log"} 872 "The MySQL table that holds the transfer log"}
805 , 873 ,
874 {"MySQLNotesLogTable", set_notes_log_mysql_table, NULL, RSRC_CONF, TAKE1,
875 "The MySQL table that holds the notes"}
876 ,
806 {"MySQLTransferLogFormat", set_mysql_transfer_log_format, NULL, RSRC_CONF, TAKE1, 877 {"MySQLTransferLogFormat", set_mysql_transfer_log_format, NULL, RSRC_CONF, TAKE1,
807 "Instruct the module what information to log to the MySQL transfer log"} 878 "Instruct the module what information to log to the MySQL transfer log"}
808 , 879 ,
@@ -836,6 +907,9 @@ command_rec log_mysql_cmds[] = {
836 {"MySQLSocketFile", set_mysql_socket_file, NULL, RSRC_CONF, TAKE1, 907 {"MySQLSocketFile", set_mysql_socket_file, NULL, RSRC_CONF, TAKE1,
837 "Name of the file to employ for socket connections to MySQL"} 908 "Name of the file to employ for socket connections to MySQL"}
838 , 909 ,
910 {"MySQLWhichNotes", add_mysql_note, NULL, RSRC_CONF, ITERATE,
911 "Members of the 'notes' table that you would like to log"}
912 ,
839 {NULL} 913 {NULL}
840}; 914};
841 915
@@ -848,30 +922,38 @@ int log_mysql_transaction(request_rec *orig)
848{ 922{
849 char **ptrptr, **ptrptr2; 923 char **ptrptr, **ptrptr2;
850 log_mysql_state *cls = get_module_config(orig->server->module_config, &mysql_log_module); 924 log_mysql_state *cls = get_module_config(orig->server->module_config, &mysql_log_module);
851 const char *str; 925 const char *access_query;
852 request_rec *r; 926 request_rec *r;
853 927
854 /* We handle mass virtual hosting differently. Dynamically determine the name 928 /* We handle mass virtual hosting differently. Dynamically determine the name
855 * of the table from the virtual server's name, and flag it for creation. 929 * of the table from the virtual server's name, and flag it for creation.
856 */ 930 */
857 if (massvirtual == 1) { 931 if (massvirtual == 1) {
858 char *base = "access_"; 932 char *access_base = "access_";
859 char *tablename; 933 char *notes_base = "notes_";
934 char *a_tablename;
935 char *n_tablename;
860 int i; 936 int i;
861 937
862 /* Find memory long enough to hold the table name + \0. */ 938 /* Find memory long enough to hold the table name + \0. */
863 tablename = ap_pstrcat(orig->pool, base, ap_get_server_name(orig), NULL); 939 a_tablename = ap_pstrcat(orig->pool, access_base, ap_get_server_name(orig), NULL);
940 n_tablename = ap_pstrcat(orig->pool, notes_base, ap_get_server_name(orig), NULL);
864 941
865 /* Transform any dots to underscores */ 942 /* Transform any dots or dashes to underscores */
866 for (i = 0; i < strlen(tablename); i++) { 943 for (i = 0; i < strlen(a_tablename); i++) {
867 if (tablename[i] == '.') 944 if ( (a_tablename[i] == '.') || (a_tablename[i] == '-') )
868 tablename[i] = '_'; 945 a_tablename[i] = '_';
946 }
947 for (i = 0; i < strlen(n_tablename); i++) {
948 if ( (n_tablename[i] == '.') || (n_tablename[i] == '-') )
949 n_tablename[i] = '_';
869 } 950 }
870 951
871 /* Tell this virtual server its transfer table name, and 952 /* Tell this virtual server its transfer table name, and
872 * turn on create_tables, which is implied by massvirtual. 953 * turn on create_tables, which is implied by massvirtual.
873 */ 954 */
874 cls->transfer_table_name = tablename; 955 cls->transfer_table_name = a_tablename;
956 cls->notes_table_name = n_tablename;
875 create_tables = 1; 957 create_tables = 1;
876 } 958 }
877 959
@@ -880,19 +962,27 @@ int log_mysql_transaction(request_rec *orig)
880 return DECLINED; 962 return DECLINED;
881 } else { 963 } else {
882 const char *thehost; 964 const char *thehost;
965 const char *thenote;
883 char *fields = "", *values = ""; 966 char *fields = "", *values = "";
967 char *notesets = "";
968 char *note_query = "";
969 const char *unique_id;
884 const char *formatted_item; 970 const char *formatted_item;
885 int i, j, length; 971 int i, j, length;
886 char *createstring = NULL; 972 char *create_access = NULL;
973 char *create_notes = NULL;
887 974
888 for (r = orig; r->next; r = r->next) { 975 for (r = orig; r->next; r = r->next) {
889 continue; 976 continue;
890 } 977 }
891 978
979 #ifdef DEBUG
980 /*ap_table_do(trace, orig, orig->subprocess_env, NULL);*/
981 #endif
892 982
893 /* The following is a stolen upsetting mess of pointers, I'm sorry 983 /* The following is a stolen upsetting mess of pointers, I'm sorry.
894 * Anyone with the motiviation and/or the time should feel free 984 * Anyone with the motiviation and/or the time should feel free
895 * to make this cleaner, and while at it, clean the same mess at the RefererLog part :) */ 985 * to make this cleaner. :) */
896 ptrptr2 = (char **) (cls->transfer_ignore_list->elts + (cls->transfer_ignore_list->nelts * cls->transfer_ignore_list->elt_size)); 986 ptrptr2 = (char **) (cls->transfer_ignore_list->elts + (cls->transfer_ignore_list->nelts * cls->transfer_ignore_list->elt_size));
897 987
898 /* Go through each element of the ignore list and compare it to the 988 /* Go through each element of the ignore list and compare it to the
@@ -960,14 +1050,52 @@ int log_mysql_transaction(request_rec *orig)
960 } 1050 }
961 1051
962 1052
1053 /*
1054 fields = pstrcat(r->pool, fields, ",note", NULL);
1055 values = pstrcat(r->pool, values, ",'", NULL);
1056 */
1057
1058 /* Work through the list of notes defined by MySQLNotesToLog */
1059 i = 0;
1060 unique_id = extract_unique_id(r, "");
1061
1062 ptrptr2 = (char **) (cls->notes_list->elts + (cls->notes_list->nelts * cls->notes_list->elt_size));
1063 for (ptrptr = (char **) cls->notes_list->elts; ptrptr < ptrptr2; ptrptr = (char **) ((char *) ptrptr + cls->notes_list->elt_size)) {
1064 /* If the specified note (*ptrptr) exists for the current request... */
1065 if ((thenote = ap_table_get(r->notes, *ptrptr))) {
1066 notesets = ap_pstrcat(r->pool, notesets,
1067 (i > 0 ? "," : ""),
1068 "('",
1069 unique_id,
1070 "','",
1071 escape_query(*ptrptr, r->pool),
1072 "','",
1073 escape_query(thenote, r->pool),
1074 "')",
1075 NULL);
1076 i++;
1077 }
1078 }
1079 note_query = ap_pstrcat(r->pool, note_query, "insert into ", cls->notes_table_name, " (id, item, val) values ", notesets, NULL);
1080 #ifdef DEBUG
1081 ap_log_error(APLOG_MARK,DEBUGLEVEL,orig->server,"note string: %s", note_query);
1082 #endif
1083
1084 /*
1085 values = pstrcat(r->pool, values, "'", NULL);
1086 */
1087
1088
1089
963 /* Is this virtual server's table flagged as made? We flag it as such in order 1090 /* Is this virtual server's table flagged as made? We flag it as such in order
964 * to avoid extra processing with each request. If it's not flagged as made, 1091 * to avoid extra processing with each request. If it's not flagged as made,
965 * set up the CREATE string. 1092 * set up the CREATE string.
966 */ 1093 */
967 if ((cls->table_made != 1) && (create_tables != 0)) { 1094 if ((cls->table_made != 1) && (create_tables != 0)) {
968 char *createprefix = "create table if not exists "; 1095 char *createprefix = "create table if not exists ";
969 char *createsuffix = 1096 char *access_suffix =
970 " (agent varchar(255),\ 1097 " (id char(19),\
1098 agent varchar(255),\
971 bytes_sent int unsigned,\ 1099 bytes_sent int unsigned,\
972 child_pid smallint unsigned,\ 1100 child_pid smallint unsigned,\
973 cookie varchar(255),\ 1101 cookie varchar(255),\
@@ -989,21 +1117,28 @@ int log_mysql_transaction(request_rec *orig)
989 status smallint unsigned,\ 1117 status smallint unsigned,\
990 time_stamp int unsigned,\ 1118 time_stamp int unsigned,\
991 virtual_host varchar(50))"; 1119 virtual_host varchar(50))";
992 1120
1121 char *notes_suffix =
1122 " (id char(19),\
1123 item varchar(80),\
1124 val varchar(80))";
1125
993 /* Find memory long enough to hold the whole CREATE string + \0 */ 1126 /* Find memory long enough to hold the whole CREATE string + \0 */
994 createstring = ap_pstrcat(orig->pool, createprefix, cls->transfer_table_name, createsuffix, NULL); 1127 create_access = ap_pstrcat(orig->pool, createprefix, cls->transfer_table_name, access_suffix, NULL);
1128 create_notes = ap_pstrcat(orig->pool, createprefix, cls->notes_table_name, notes_suffix, NULL);
995 1129
996 #ifdef DEBUG 1130 #ifdef DEBUG
997 ap_log_error(APLOG_MARK,DEBUGLEVEL,orig->server,"create string: %s", createstring); 1131 ap_log_error(APLOG_MARK,DEBUGLEVEL,orig->server,"create string: %s", create_access);
1132 ap_log_error(APLOG_MARK,DEBUGLEVEL,orig->server,"create string: %s", create_notes);
998 #endif 1133 #endif
999 1134
1000 } 1135 }
1001 1136
1002 /* Set up the actual INSERT statement and escape it. */ 1137 /* Set up the actual INSERT statement */
1003 str = ap_pstrcat(r->pool, "insert into ", cls->transfer_table_name, " (", fields, ") values (", values, ")", NULL); 1138 access_query = ap_pstrcat(r->pool, "insert into ", cls->transfer_table_name, " (", fields, ") values (", values, ")", NULL);
1004 1139
1005 #ifdef DEBUG 1140 #ifdef DEBUG
1006 ap_log_error(APLOG_MARK,DEBUGLEVEL,r->server,"insert string: %s", str); 1141 ap_log_error(APLOG_MARK,DEBUGLEVEL,r->server,"insert string: %s", access_query);
1007 #endif 1142 #endif
1008 1143
1009 1144
@@ -1017,7 +1152,8 @@ int log_mysql_transaction(request_rec *orig)
1017 /* Unable to re-establish a DB link, so assume that it's really 1152 /* Unable to re-establish a DB link, so assume that it's really
1018 * gone and send the entry to the preserve file instead. 1153 * gone and send the entry to the preserve file instead.
1019 * Note that we don't keep logging the db error over and over. */ 1154 * Note that we don't keep logging the db error over and over. */
1020 preserve_entry(orig, str); 1155 preserve_entry(orig, access_query);
1156 preserve_entry(orig, note_query);
1021 return OK; 1157 return OK;
1022 } else { 1158 } else {
1023 /* Whew, we got the DB link back */ 1159 /* Whew, we got the DB link back */
@@ -1027,13 +1163,15 @@ int log_mysql_transaction(request_rec *orig)
1027 1163
1028 /* Make the table if we're supposed to */ 1164 /* Make the table if we're supposed to */
1029 if ((cls->table_made != 1) && (create_tables != 0)) { 1165 if ((cls->table_made != 1) && (create_tables != 0)) {
1030 mysql_query(mysql_log,createstring); 1166 mysql_query(mysql_log, create_access);
1167 mysql_query(mysql_log, create_notes);
1031 cls->table_made = 1; 1168 cls->table_made = 1;
1032 } 1169 }
1033 1170
1034 /* Make the insert */ 1171 /* Make the insert */
1035 safe_mysql_query(orig, str); 1172 safe_mysql_query(orig, access_query);
1036 1173 safe_mysql_query(orig, note_query);
1174
1037 return OK; 1175 return OK;
1038 } 1176 }
1039} 1177}