From ec06ba32ef1bfb3de7fd87ddc9c43468d5f5684e Mon Sep 17 00:00:00 2001 From: Christopher Powell Date: Tue, 15 Jan 2002 18:40:14 +0000 Subject: Ported to mysql_real_connect, made a change for the mass-virtual-hosting folks, and enabled a socket name DEFINE. --- diff --git a/CHANGELOG b/CHANGELOG index 5479725..7d9fba0 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,13 +1,27 @@ -$Id: CHANGELOG,v 1.4 2001/12/07 03:52:56 helios Exp $ +$Id: CHANGELOG,v 1.5 2002/01/15 18:40:14 helios Exp $ TODO: * Full commenting of the code. * Rethink documentation flow and rewrite? +* Message queueing during server downtime? CHANGES: +1.13: + +* Now use ap_get_server_name() in extract_virtual_host() to fix the + instances where mass-virtual-hosting sites were getting the wrong + server-name written to the log. +* Now use mysql_real_connect() instead of mysql_connect(). The + latter's use was deprecated and did not work in MySQL 4. +* There is now a DEFINE for the socket name. This is used by the + mysql_real_connect() function and is relevant only if the db resides + on localhost. It is irrelevant if the db resides on a networked + machine and is ignored in that case (although it still must be defined + for the connect to work). + 1.12: * Added a mysql_close() call to get rid of those annoying MySQL diff --git a/INSTALL b/INSTALL index 86807a2..7f2e061 100644 --- a/INSTALL +++ b/INSTALL @@ -1,4 +1,4 @@ -$Id: INSTALL,v 1.3 2002/01/02 20:47:44 helios Exp $ +$Id: INSTALL,v 1.4 2002/01/15 18:40:14 helios Exp $ Requirements @@ -31,10 +31,7 @@ Requirements Installation (as an Apache DSO) =============================== -For folks interested in using this module as an Apache DSO, these -instructions are currently UNTESTED but should work. (I would be -grateful to hear back from a DSO user as to my accuracy with these -instructions.) +For folks interested in using this module as an Apache DSO: 0) Perform all the following steps as root so that you have install privs, etc. @@ -44,7 +41,10 @@ instructions.) # tar zxf mod_log_mysql.tar.gz -C /usr/local/src # cd /usr/local/src/mod_log_mysql -2) Instruct apxs to compile and install the module as a DSO. You need +2) Edit Makefile and make any adjustments for your system. These are + fully explained in the Makefile. + +3) Instruct apxs to compile and install the module as a DSO. You need to know two things before you run apxs: - The location of the apxs binary, find using 'locate apxs' - The location of your MySQL libraries, find using 'locate libmysqlclient' @@ -57,13 +57,14 @@ instructions.) ld -Bshareable -o mod_log_mysql.so mod_log_mysql.o cp mod_log_mysql.so /mod_log_mysql.so chmod 755 /mod_log_mysql.so - [activating module foo' in /path/to/apache/etc/httpd.conf] + [activating module blah in /path/to/apache/etc/httpd.conf] -3) Now go to step (9) in the instructions below to configure httpd.conf... +4) Now go to step (9) in the instructions below to configure httpd.conf... Installation (as a static module compiled into httpd) ===================================================== + [This is what I do, FYI.] 0) Perform all the following steps as root so that you have install @@ -74,10 +75,8 @@ Installation (as a static module compiled into httpd) # tar zxf mod_log_mysql.tar.gz -C /usr/local/src # cd /usr/local/src/mod_log_mysql -2) Edit Makefile and make any adjustments for your system: make sure - that APACHEDIR points to the location of your Apache source code, - and that CFLAGS points to the location of your Apache installation - directory (where your httpd binary lives). +2) Edit Makefile and make any adjustments for your system. These are + fully explained in the Makefile. 3) # make all (You should receive NO warnings or errors of any kind. @@ -133,8 +132,8 @@ Installation (as a static module compiled into httpd) # cp -f ./httpd /usr/local/Apache/bin/ 9) Configure your apache daemon to log to your database. Here's a very - basic set of config lines to start you off. Full docs on them are - included after this section. + basic set of config lines to start you off. Full documentation is + available here: http://www.grubbybaby.com/mod_log_mysql/directives.html EXAMPLE: Connect to the MySQL database called "apache" running on "dbmachine.foo.com". The module uses username "loguser" and @@ -157,7 +156,7 @@ Installation (as a static module compiled into httpd) - 9a) For users who have a DSO-enabled httpd: + 9a) Special step for users who have a DSO-enabled httpd: If you you are building mod_log_mysql as a static module BUT your httpd is enabled for DSOs, add the following line to your @@ -186,9 +185,9 @@ Installation (as a static module compiled into httpd) mysql> source access_log.sql -11) Create a specific mysql userid that httpd will use to authenticate +11) Create a specific MySQL userid that httpd will use to authenticate and enter data. This userid need not be an actual Unix user. It - is a userid specific to mysql with specific privileges. To create a + is a userid internal to MySQL with specific privileges. To create a user called "loguser" with the password "l0gger" with only the capability of INSERT to "access_log": diff --git a/Makefile b/Makefile index 5744be4..65e0cd5 100644 --- a/Makefile +++ b/Makefile @@ -1,37 +1,47 @@ -# $Id: Makefile,v 1.4 2001/12/07 03:52:56 helios Exp $ +# $Id: Makefile,v 1.5 2002/01/15 18:40:14 helios Exp $ +MLMVERS = 1.13 -# Verify that this points to the right place... -APACHEDIR = /usr/local/src/apache_1.3.22 +# Where you unpacked your Apache tarball -- the source. +APACHESOURCE = /usr/local/src/apache_1.3.22 -# Use the first one if you want mod_log_mysql to be able to log -# SSL variables like keysize or cipher. Use the second one if -# you don't use SSL or don't care to log it. -DEFS = -DWANT_SSL_LOGGING -#DEFS = +# Where Apache [got|will get] installed +APACHEINST = /usr/local/Apache -# Use this one if you do WANT_SSL_LOGGING, and confirm the last three paths. -# Point "/usr/local/ssl/include" to where your openssl/*.h files are, -# Point "/usr/include/db1" to where ndbm.h can be found, -# Point "/usr/local/src/apache_1.3.22/src/modules/ssl" to where mod_ssl.h can be found. +# Use the first DEFS line if you want mod_log_mysql to be able to log SSL +# variables like keysize or cipher. Use the second one if you don't use SSL +# or don't care to log it. # -# How to find your directories: +# If your MySQL db is running on the same machine as Apache, modify the +# MYSQLSOCKET path to point to your MySQL socket. This define has no effect +# if your MySQL machine is a networked (TCP/IP) machine. + +DEFS = -DMYSQLSOCKET="\"/var/lib/mysql/mysql.sock\"" -DWANT_SSL_LOGGING +#DEFS = -DMYSQLSOCKET="\"/var/lib/mysql/mysql.sock\"" + +# Use the first CFLAGS if you *do* WANT_SSL_LOGGING, and confirm the paths. # -# $ locate http_core.h -# /usr/local/Apache/include/http_core.h +# Modify "/usr/local/ssl/include" to where YOUR openssl/*.h files are, +# Modify "/usr/include/db1" to where YOUR ndbm.h can be found, +# Modify "/usr/local/src/apache_1.3.22/src/modules/ssl" to where YOUR mod_ssl.h can be found. +# +# How to find your directories: # # $ locate x509.h # /usr/local/ssl/include/openssl/x509.h +# ^^^^^^^^^^^^^^^^^^^^^^ # # $ locate ndbm.h # /usr/include/db1/ndbm.h +# ^^^^^^^^^^^^^^^^ # # $ locate mod_ssl.h # /usr/local/src/apache_1.3.22/src/modules/ssl/mod_ssl.h +# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -CFLAGS = -fpic -O2 -Wall -I/usr/local/Apache/include -I/usr/local/ssl/include -I/usr/include/db1 -I/usr/local/src/apache_1.3.22/src/modules/ssl +CFLAGS = -fpic -O2 -Wall -I${APACHEINST}/include -I/usr/local/ssl/include -I/usr/include/db1 -I${APACHESOURCE}/src/modules/ssl -# Use this one if you don't WANT_SSL_LOGGING: -#CFLAGS = -fpic -O2 -Wall -I/usr/local/Apache/include +# Use this CFLAGS if you don't WANT_SSL_LOGGING: +#CFLAGS = -fpic -O2 -Wall -I${APACHEINST}/include # --------------------------------------------------------- @@ -46,13 +56,13 @@ mod_log_mysql.o: mod_log_mysql.c Makefile $(CC) ${CFLAGS} ${DEFS} -c mod_log_mysql.c install: all - $(INSTALL) mod_log_mysql.o ${APACHEDIR}/src/mod_log_mysql.o + $(INSTALL) mod_log_mysql.o ${APACHESOURCE}/src/mod_log_mysql.o distro: all - cp -f INSTALL /usr/local/Apache/html/mod_log_mysql/ - cp -f README /usr/local/Apache/html/mod_log_mysql/ - cp -f CHANGELOG /usr/local/Apache/html/mod_log_mysql/ - cd ..; tar zcf mod_log_mysql.tar.gz --exclude mod_log_mysql/CVS mod_log_mysql/; $(INSTALL) mod_log_mysql.tar.gz /usr/local/Apache/html/mod_log_mysql/; rm -f mod_log_mysql.tar.gz + cp -f INSTALL ${APACHEINST}/html/mod_log_mysql/ + cp -f README ${APACHEINST}/html/mod_log_mysql/ + cp -f CHANGELOG ${APACHEINST}/html/mod_log_mysql/ + 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 clean: rm -f *.o *~ diff --git a/mod_log_sql.c b/mod_log_sql.c index efbf45c..6780b74 100644 --- a/mod_log_sql.c +++ b/mod_log_sql.c @@ -1,11 +1,11 @@ -/* $Id: mod_log_sql.c,v 1.4 2001/12/07 03:52:56 helios Exp $ */ +/* $Id: mod_log_sql.c,v 1.5 2002/01/15 18:40:14 helios Exp $ */ /* DEFINES */ #define MYSQL_ERROR(mysql) ((mysql)?(mysql_error(mysql)):"MySQL server has gone away") #define ERRLEVEL APLOG_ERR|APLOG_NOERRNO #define DEBUGLEVEL APLOG_INFO|APLOG_NOERRNO -/* (DEBUG and WANT_SSL_LOGGING are defined in the Makefile DEFS line.) */ +/* (MYSQLSOCKET, DEBUG and WANT_SSL_LOGGING are defined in the Makefile DEFS line.) */ @@ -245,7 +245,7 @@ static const char *extract_request_duration(request_rec *r, char *a) static const char *extract_virtual_host(request_rec *r, char *a) { - return pstrdup(r->pool, r->server->server_hostname); + return ap_get_server_name(r); } static const char *extract_server_port(request_rec *r, char *a) @@ -469,13 +469,8 @@ void open_logdb_link() return; } if (db_name) { /* open an SQL link */ - mysql_log = mysql_connect(&sql_server, db_host, db_user, db_pwd); - if (mysql_log) { /* link opened */ - if (mysql_select_db(mysql_log, db_name) != 0) { /* unable to select database */ - mysql_close(mysql_log); - mysql_log = NULL; - } - } + mysql_init(&sql_server); + mysql_log = mysql_real_connect(&sql_server, db_host, db_user, db_pwd, db_name, 0, MYSQLSOCKET, 0); } } -- cgit v0.9.2