From 0d8d2676e9b345eb66d2d3a145fbf64d1429a9b2 Mon Sep 17 00:00:00 2001 From: Christopher Powell Date: Wed, 18 Dec 2002 01:06:33 +0000 Subject: Delayed inserts, includes, better table creation, renamed global vars, --- diff --git a/CHANGELOG b/CHANGELOG index 66151e7..2e925bd 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,10 +1,9 @@ -$Id: CHANGELOG,v 1.18 2002/12/10 19:43:21 helios Exp $ +$Id: CHANGELOG,v 1.19 2002/12/18 01:06:32 helios Exp $ TODO: * Rethink documentation flow and rewrite? * Port connection portion to other DBMS? Genericize the module? Start with PostgreSQL. -* check for mandatory conf directives / syntax quit if not * GNU autoconf * merge server config into vh config * port to Apache 2.x @@ -12,7 +11,7 @@ TODO: cause performance degradation? If so fix. * LogSQLRotateLogs directive with daily/monthly/weekly/etc. * new format char: IP as bigint? -* socket-based middleman daemon with configurable conns? +* socket-based middleman daemon with configurable conns, or connect/disconnect. * ignore by cookie CHANGES: @@ -28,20 +27,31 @@ CHANGES: are made only on ER_NO_SUCH_TABLE. This should solve all the multiple- creation-attempt issues as well as reduce overhead. * safe_mysql_query reworked; it now can be counted on to preserve_entry() - if the query doesn't succeed. (Before, preserve_entry() was called - separately.) -* Always return SIGPIPE to handler before leaving safe_mysql_query(). + if the query doesn't succeed. [Before, preserve_entry() was called + separately.] +* Always reset SIGPIPE to handler before leaving safe_mysql_query(). * New directive LogSQLRequestAccept, another filter for excluding things from being logged. * Alphabetized the directives in the reference section of the docs. +* New format char 'a' lets one log the request arguments, i.e. the + part of a CGI request after the ? character. Also put a column for + this in the create_tables.sql file. Thanks to Dave Wilson for this. * Reorganized the FAQ by section. +* Renamed global variables (e.g. tcp_port -> logsql_tcpport) throughout + the code in order to ensure against naming conflicts. tcp_port, in + particular, seemed to be causing problems / segfaults on certain systems. +* Renamed safe_mysql_query() to safe_sql_query(). +* Now check for minimum configuration info to establish db link and + log an error if it's insufficient. +* Log a message if the config is insufficient for logging. + 1.17: * Renamed the module mod_log_sql to conform to the project goal of database-inspecificity. * Added capability of logging Notes field. This is useful for folks using custom modules that provide loggable info in the notes, e.g. mod_gzip. - A new directive MySQLWhichNotes configures which notes to log to the + A new directive LogSQLWhichNotes configures which notes to log to the notes_log table. * Added capability of logging inbound and outbound headers. New directives LogSQLWhichHeadersIn and LogSQLWhichHeadersOut configure which headers to diff --git a/Documentation/documentation.lyx b/Documentation/documentation.lyx index 69f09ae..ba02f76 100644 --- a/Documentation/documentation.lyx +++ b/Documentation/documentation.lyx @@ -422,24 +422,31 @@ Perform all the following steps as root so that you have install privs, \end_deeper \layout Enumerate -You must know the paths to some installed software before continuing. +Edit Makefile and change the values of the variables in the first section. + \begin_deeper \layout Enumerate -These are +These paths are \series bold necessary: \begin_deeper -\layout Itemize +\layout Description -The location where you installed Apache -- usually /usr/local/apache, 'locate - apxs' can help you find it. -\layout Itemize +APACHEINSTALLED: the location where you installed Apache -- usually /usr/local/a +pache, 'locate apxs' can help you find it. +\layout Description -The location of your MySQL libraries, find using 'locate libmysqlclient.so' -\layout Itemize +APACHEHEADERS: The location of your Apache header files, find using 'locate + httpd.h' +\layout Description + +MYSQLLIBRARIES: The location of your MySQL libraries, find using 'locate + libmysqlclient.so' +\layout Description -The location of your MySQL header files, find using 'locate mysql.h' +MYSQLHEADERS: The location of your MySQL header files, find using 'locate + mysql.h' \end_deeper \layout Enumerate @@ -450,12 +457,13 @@ Optional : if you compiled mod_ssl for Apache and want to log SSL data such as 'keysize' and 'cipher type': \begin_deeper -\layout Itemize +\layout Description -The location of your SSL header files, find using 'locate mod_ssl.h' -\layout Itemize +MODSSLHEADERS: the location of your mod_ssl header files, find using 'locate + mod_ssl.h' +\layout Description -The location of your db1 header files, find using 'locate ndbm.h' +DB1HEADERS: the location of your db1 header files, find using 'locate ndbm.h' \end_deeper \layout Standard @@ -473,13 +481,9 @@ such as the cipher type. \end_deeper \layout Enumerate -Now that you know these things, edit Makefile and replace the stock values - with your own. -\begin_deeper -\layout Standard - IMPORTANT: If you are not logging SSL info, comment out MODSSLHDRS by putting a # character in front of it: +\begin_deeper \layout LyX-Code #MODSSLHDRS=/usr/include/... @@ -496,15 +500,14 @@ Instruct apxs to compile the module as a DSO. You should see output similar to the following: \layout LyX-Code -/usr/local/Apache/bin/apxs -Wc,-O2 -Wc,-Wall -Wc,-DEAPI -c -I/usr/incl... - +/usr/local/Apache/bin/apxs -Wc,-O2 -Wc,-Wall -Wc,-DEAPI -c -I/usr/... \layout LyX-Code -gcc -DLINUX=22 -DNO_DBM_REWRITEMAP -DMOD_SSL=208111 -DUSE_HSREGEX -DEAPI... +gcc -DLINUX=22 -DNO_DBM_REWRITEMAP -DMOD_SSL=208111 -DUSE_HS... \layout LyX-Code -gcc -shared -o mod_log_sql.so mod_log_sql.o -Wc,-O2 -Wc,-Wall -Wc,-DEAPI... +gcc -shared -o mod_log_sql.so mod_log_sql.o -Wc,-O2 -Wc,-Wall -Wc... \layout Standard You should see no errors and have a new file called "mod_log_sql.so" in your @@ -650,7 +653,8 @@ Unpack the archive into a working directory. \end_inset -You must know the paths to some installed software before continuing. +Edit Makefile and change the values of the variables in the first section. + \begin_deeper \layout Enumerate @@ -658,21 +662,29 @@ These are \series bold necessary: \begin_deeper -\layout Itemize +\layout Description -The location where you installed Apache -- usually /usr/local/apache, 'locate - apxs' can help you find it. - -\layout Itemize +APACHEINSTALLED: the location where you installed Apache -- usually /usr/local/a +pache, 'locate apxs' can help you find it. +\layout Description -The location of your Apache *sources*, find using 'locate ABOUT_APACHE' - -\layout Itemize +APACHESOURCE: the location of your Apache +\series bold +sources +\series default +, find using 'locate ABOUT_APACHE' +\layout Description -The location of your MySQL header files, find using 'locate mysql.h' -\layout Itemize +APACHEHEADERS: The location of your Apache header files, find using 'locate + httpd.h' +\layout Description + +MYSQLLIBRARIES: The location of your MySQL libraries, find using 'locate + libmysqlclient.so' +\layout Description -The location of your MySQL libraries, find using 'locate libmysqlclient.so' +MYSQLHEADERS: The location of your MySQL header files, find using 'locate + mysql.h' \end_deeper \layout Enumerate @@ -683,12 +695,13 @@ Optional : if you compiled mod_ssl for Apache and want to log SSL data such as 'keysize' and 'cipher type': \begin_deeper -\layout Itemize +\layout Description -The location of your mod_ssl header files, find using 'locate mod_ssl.h' -\layout Itemize +MODSSLHEADERS: the location of your mod_ssl header files, find using 'locate + mod_ssl.h' +\layout Description -The location of your db1 header files, find using 'locate ndbm.h' +DB1HEADERS: the location of your db1 header files, find using 'locate ndbm.h' \end_deeper \layout Standard @@ -706,13 +719,9 @@ if you want to log SSL-specific data \end_deeper \layout Enumerate -Now that you know these things, edit Makefile and replace the stock values - with your own. -\begin_deeper -\layout Standard - IMPORTANT: If you are not logging SSL info, comment out MODSSLHDRS by putting a # character in front of it: +\begin_deeper \layout LyX-Code #MODSSLHDRS=/usr/include/... @@ -987,15 +996,6 @@ A very basic logging setup in Apache Tell the module what database to use and the appropriate authentication information. \begin_deeper -\layout Quote - - -\series bold -Example: -\series default - Use the MySQL database called "apachelogs" running on "dbmachine.foo.com". - Use username "loguser" and password "l0gger" to authenticate to the database. - Let the module create tables for us. \layout Standard So, edit httpd.conf and insert the following lines somewhere after any LoadModule @@ -1014,9 +1014,29 @@ global, not inside any VirtualHost stanza \emph default . + You will also note that you are embedding a password in the file. + Therefore you are advised to +\begin_inset Quotes eld +\end_inset + +chmod 660 httpd.conf +\begin_inset Quotes erd +\end_inset + + to prevent unauthorized regular users from viewing your database user and + password. +\layout Standard + + +\series bold +Example +\series default +: 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. \layout LyX-Code -LogSQLLoginInfo dbmachine.foo.com loguser l0gger +LogSQLLoginInfo dbmachine.foo.com loguser l0gg3r \layout LyX-Code LogSQLDatabase apachelogs @@ -1111,74 +1131,18 @@ Several lines of output should follow, corresponding to your hits on the You now have basic functionality. Don't disable your regular Apache logs until you feel comfortable that the database is behaving as you'd like and that things are going well. + If you do not see any entries in the access_log, please consult section + +\begin_inset LatexCommand \ref{faq:NothingLogged} + +\end_inset + + of the FAQ on how to debug and fix the situation. \end_deeper \layout Enumerate You can now activate the advanced features of mod_log_sql, which are described in the next section. - If you do not see any entries in the access_log, then something is preventing - the inserts from happening. - This could be caused by several things: -\begin_deeper -\layout Itemize - -Improper privileges set up in the MySQL database -\layout Itemize - -You aren't hitting a VirtualHost that has a -\noun on -LogSQLTransferLogTable -\noun default - entry -\layout Itemize - -You didn't specify the right database host or login information -\layout Standard - -So, first examine the MySQL log that you established in step -\begin_inset LatexCommand \ref{step:EnaLog} - -\end_inset - - of section -\begin_inset LatexCommand \ref{sub:PrepDb} - -\end_inset - -. - Ensure that the INSERT statements are not being rejected because of a malformed - table name or other typographical error. - By enabling that log, you instructed MySQL to log every connection and - command it receives -- if you see no INSERT attempts in the log, the module - isn't successfully connecting to the database. - If you see nothing at all in the log -- not even a record of your administrativ -e connection attempts, then you did not enable the log correctly. - If you do see INSERT attempts but they are failing, the log should tell - you why. -\layout Standard - -Second, confirm that your -\noun on -LogSQL* -\noun default - directives are all correct. -\layout Standard - -Third, examine the Apache -\noun on - -\noun default -error logs for messages from mod_log_sql; the module will offer hints as - to why it cannot connect, etc. - -\layout Standard - -The next thing to do is recompile the module with debugging output activated. - change the "#undef DEBUG" on line 8 of mod_log_sql.c to "#define DEBUG" - and recompile/reinstall. - The module will now output copious notes about what it is doing, and this - will help you (and the maintainer) solve the problem. -\end_deeper \layout Subsection How to tune logging with run-time directives @@ -2537,8 +2501,9 @@ Optimizing for a busy database A busy MySQL database will have SELECT statements running concurrently with INSERT and UPDATE statements. - A long-running SELECT can block INSERTs, therefore will block mod_log_sql. - This may be solved by compiling mod_log_sql for + A long-running SELECT can in certain circumstances block INSERTs and therefore + block mod_log_sql. + A workaround is to compile mod_log_sql for \begin_inset Quotes eld \end_inset @@ -2907,7 +2872,15 @@ host \begin_inset Quotes erd \end_inset - is the hostname or IP address of the MySQL machine. + is the hostname or IP address of the MySQL machine, and is simply +\begin_inset Quotes eld +\end_inset + +localhost +\begin_inset Quotes erd +\end_inset + + if the database lives on the same machine as Apache. \begin_inset Quotes eld \end_inset @@ -3397,7 +3370,7 @@ Each character in the format-string defines an attribute of the request \size footnotesize \begin_inset Tabular - + @@ -3515,6 +3488,48 @@ Mozilla/4.0 (compat; MSIE 6.0; Windows) \layout Standard +a +\end_inset + + +\begin_inset Text + +\layout Standard + +CGI request arguments +\end_inset + + +\begin_inset Text + +\layout Standard + +request_args +\end_inset + + +\begin_inset Text + +\layout Standard + +varchar(255) +\end_inset + + +\begin_inset Text + +\layout Standard + +user=Smith&cart=1231&item=532 +\end_inset + + + + +\begin_inset Text + +\layout Standard + \size footnotesize b @@ -5724,6 +5739,273 @@ Please contact course. \layout Subsection +Problems +\layout Subsubsection + +Apache segfaults when using PHP and mod_log_sql +\layout Standard + +This occurs if you compiled PHP with MySQL database support. + PHP utilizes its internal, bundled MySQL libraries by default. + These conflict with the +\begin_inset Quotes eld +\end_inset + +real +\begin_inset Quotes erd +\end_inset + + MySQL libraries linked by mod_log_sql, causing the segmentation fault. + +\layout Standard + +The solution is to configure PHP to link against the real MySQL libraries + and recompile mod_php. + Apache will run properly once the modules are all using the same version + of the MySQL libraries. +\layout Subsubsection + + +\begin_inset LatexCommand \label{faq:NothingLogged} + +\end_inset + +Apache appears to start up fine, but nothing is getting logged in the database +\layout Standard + +If you do not see any entries in the access_log, then something is preventing + the inserts from happening. + This could be caused by several things: +\layout Itemize + +Improper privileges set up in the MySQL database +\layout Itemize + +You aren't hitting a VirtualHost that has a LogSQLTransferLogTable entry + +\layout Itemize + +You didn't specify the right database host or login information +\layout Itemize + +Another factor is preventing a connection to the database +\layout Standard + +Important: it is improper to ask for help before you have followed these + steps. +\layout Standard + +First examine the MySQL log that you established in step +\begin_inset LatexCommand \ref{step:EnaLog} + +\end_inset + + of section +\begin_inset LatexCommand \ref{sub:PrepDb} + +\end_inset + +. + Ensure that the INSERT statements are not being rejected because of a malformed + table name or other typographical error. + By enabling that log, you instructed MySQL to log every connection and + command it receives -- if you see no INSERT attempts in the log, the module + isn't successfully connecting to the database. + If you see nothing at all in the log -- not even a record of your administrativ +e connection attempts, then you did not enable the log correctly. + If you do see INSERT attempts but they are failing, the log should tell + you why. +\layout Standard + +Second, confirm that your +\noun on +LogSQL* +\noun default + directives are all correct. +\layout Standard + +Third, examine the Apache +\noun on + +\noun default +error logs for messages from mod_log_sql; the module will offer hints as + to why it cannot connect, etc. + +\layout Standard + +The next thing to do is recompile the module with debugging output activated. + change the "#undef DEBUG" on line 8 of mod_log_sql.c to "#define DEBUG" + and recompile/reinstall. + The module will now output copious notes about what it is doing, and this + will help you (and the maintainer) solve the problem. + In order to see the debugging messages, ensure that you make them visible + using the +\noun on +LogLevel +\noun default +directive +\series bold +in the main server config as well as in each +\noun on +VirtualHost +\noun default +config: +\layout LyX-Code + +LogLevel debug +\layout LyX-Code + +ErrorLog /var/log/httpd/server-messages +\layout Subsubsection + +Why do I get the message +\begin_inset Quotes eld +\end_inset + +configuration info is insufficient to log +\begin_inset Quotes erd +\end_inset + + in my Apache error log? +\layout Standard + +At a minimum, +\noun on +LogSQLTransferLogTable +\noun default + must be defined for the module to even attempt logging. + If this directive is not defined for the server (or virtual server) you + will receive this error message. + +\layout Subsubsection + +Why do I get the message +\begin_inset Quotes eld +\end_inset + +insufficient configuration info to establish database link +\begin_inset Quotes erd +\end_inset + + in my Apache error log? +\layout Standard + +At a minimum, +\noun on +LogSQLDatabase +\noun default + and +\noun on +LogSQLLoginInfo +\noun default +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. +\layout Subsubsection + +My database cannot handle all the open connections from mod_log_sql, is + there anything I can do? +\layout Standard + +The rule of thumb: if you have +\emph on +n +\emph default +webservers each configured to support +\emph on +y +\emph default + +\noun on +MaxClients +\noun default +, then your database must be able to handle +\begin_inset Formula $n\times y$ +\end_inset + + simultenous connections +\emph on +in the worst case. + +\emph default +Certainly you must use common sense, consider reasonable traffic expectations + and structure things accordingly. +\layout Standard + +Tweaking my.cnf to scale to high connection loads is imperative. + But if hardware limitations prevent your MySQL server from gracefully handling + the number of incoming connections, it would be beneficial to upgrade the + memory or CPU on that server in order to handle the load. + +\layout Standard + +Jeremy Zawodny, a highly respected MySQL user and contributor to Linux Magazine, + has this very helpful and highly appropriate article on tuning MySQL: +\begin_inset LatexCommand \url{http://jeremy.zawodny.com/blog/archives/000173.html} + +\end_inset + + +\layout Standard + +Please remember that mod_log_sql's overriding principle is +\series bold +performance +\series default + -- that is what the target audience demands and expects. + Other database logging solutions do not open and maintain many database + connections, but their performance suffers drastically. + For example, pgLOGd funnels all log connections through a separate daemon + that connects to the database, but that bottlenecks the entire process. + mod_log_sql achieves performance numbers an order of magnitude greater + than the alternatives because it dispenses with the overhead associated + with rapid connection cycling, and it doesn't attempt to shoehorn all the + database traffic through a single extra daemon or proxy process. +\layout Subsubsection + +Why do I occasionally see a +\begin_inset Quotes eld +\end_inset + +lost connection to MySQL server +\begin_inset Quotes erd +\end_inset + + message in my Apache error log? +\layout Standard + +This message may appear every now and then in your Apache error log, especially + on very lightly loaded servers. + This doesn't mean that anything is necessarily wrong. + Within each httpd child process, mod_log_sql will open (and keep open) + a connection to the MySQL server. + MySQL, however, will close connections that haven't been used in a while; + the default timeout is 8 hours. + When this occurs, mod_log_sql will notice and re-open the connection. + That event is what is being logged, and looks like this: +\layout LyX-Code + +[Tue Nov 12 19:04:10 2002] [error] mod_log_sql: first attempt failed, +\layout LyX-Code + + API said: error 2013, Lost connection to MySQL server during query +\layout LyX-Code + +[Tue Nov 12 19:04:10 2002] [error] mod_log_sql: reconnect successful +\layout LyX-Code + +[Tue Nov 12 19:04:10 2002] [error] mod_log_sql: second attempt successful +\layout Standard + +Reference: +\begin_inset LatexCommand \url[MySQL documentation]{(http://www.mysql.com/documentation/mysql/bychapter/manual_Problems.html#Gone_away)} + +\end_inset + + +\layout Subsection + Performance and Tuning \layout Subsubsection @@ -6007,58 +6289,7 @@ ps would lead you to believe. \layout Subsubsection -My database cannot handle all the open connections from mod_log_sql, is - there anything I can do? -\layout Standard - -The rule of thumb: if you have -\emph on -n -\emph default -webservers each configured to support -\emph on -y -\emph default - -\noun on -MaxClients -\noun default -, then your database must be able to handle -\begin_inset Formula $n\times y$ -\end_inset - - simultenous connections -\emph on -in the worst case. - -\emph default -Certainly you must use common sense, consider reasonable traffic expectations - and structure things accordingly. -\layout Standard - -Tweaking my.cnf to scale to high connection loads is imperative. - But if hardware limitations prevent your MySQL server from gracefully handling - the number of incoming connections, it would be beneficial to upgrade the - memory or CPU on that server in order to handle the load. - -\layout Standard - -Please remember that mod_log_sql's overriding principle is -\series bold -performance -\series default - -- that is what the target audience demands and expects. - Other database logging solutions do not open and maintain many database - connections, but their performance suffers drastically. - For example, pgLOGd funnels all log connections through a separate daemon - that connects to the database, but that bottlenecks the entire process. - mod_log_sql achieves performance numbers an order of magnitude greater - than the alternatives because it dispenses with the overhead associated - with rapid connection cycling, and it doesn't attempt to shoehorn all the - database traffic through a single extra daemon or proxy process. -\layout Subsubsection - -My webservers cannot handle all the traffic that my site receives, is there +My webserver cannot handle all the traffic that my site receives, is there anything I can do? \layout Standard @@ -6068,48 +6299,6 @@ If you have exhausted all the tuning possibilities on your existing server, In fact, users of such a setup are mod_log_sql's target audience! \layout Subsubsection -Why do I occasionally see a -\begin_inset Quotes eld -\end_inset - -lost connection to MySQL server -\begin_inset Quotes erd -\end_inset - - message in my error-log? -\layout Standard - -This message may appear every now and then in your Apache error log, especially - on very lightly loaded servers. - This doesn't mean that anything is necessarily wrong. - Within each httpd child process, mod_log_sql will open (and keep open) - a connection to the MySQL server. - MySQL, however, will close connections that haven't been used in a while; - the default timeout is 8 hours. - When this occurs, mod_log_sql will notice and re-open the connection. - That event is what is being logged, and looks like this: -\layout LyX-Code - -[Tue Nov 12 19:04:10 2002] [error] mod_log_sql: first attempt failed, -\layout LyX-Code - - API said: error 2013, Lost connection to MySQL server during query -\layout LyX-Code - -[Tue Nov 12 19:04:10 2002] [error] mod_log_sql: reconnect successful -\layout LyX-Code - -[Tue Nov 12 19:04:10 2002] [error] mod_log_sql: second attempt successful -\layout Standard - -Reference: -\begin_inset LatexCommand \url[MySQL documentation]{(http://www.mysql.com/documentation/mysql/bychapter/manual_Problems.html#Gone_away)} - -\end_inset - - -\layout Subsubsection - \begin_inset LatexCommand \label{sub:DelayedInsFAQ} @@ -6165,6 +6354,12 @@ As of MySQL version 3.23.52, the error return functions disagree after a failed tell if anything went wrong with a delayed insert. \layout Standard +Instead of delayed inserts, you may wish to utilize InnoDB tables (instead + of the standard MyISAM tables). + InnoDB tables suppot row-level locking and are recommended for high-volume + databases. +\layout Standard + If after understanding these problems you still wish to enable delayed inserts, section \begin_inset LatexCommand \ref{sub:DelayedIns} diff --git a/Makefile b/Makefile index eb4ffdf..5a9c69a 100644 --- a/Makefile +++ b/Makefile @@ -1,19 +1,20 @@ -# $Id: Makefile,v 1.19 2002/12/10 20:37:28 helios Exp $ +# $Id: Makefile,v 1.20 2002/12/18 01:06:33 helios Exp $ ########################################################################### # Important: # Adjust these values as outlined in section "Installation" in the docs. # Not all are needed at all times. -APACHESOURCE = /usr/local/src/apache_1.3.27-dso -APACHEINST = /usr/local/Apache -APXS = $(APACHEINST)/bin/apxs +APACHESOURCE = /usr/local/src/apache_1.3.27-dso +APACHEINSTALLED = /usr/local/Apache +APACHEHEADERS = /usr/local/Apache/include +APXS = $(APACHEINSTALLED)/bin/apxs -MYSQLLIBS = /usr/lib -MYSQLHDRS = /usr/include/mysql +MYSQLLIBRARIES = /usr/lib +MYSQLHEADERS = /usr/include/mysql -MODSSLHDRS = /usr/local/src/apache_1.3.27-dso/src/modules/ssl -DB1HDRS = /usr/include/db1 +#MODSSLHEADERS = /usr/local/src/apache_1.3.27-dso/src/modules/ssl +#DB1HEADERS = /usr/include/db1 ########################################################################### # Don't uncomment this without reading the "Optimizing for a busy database" @@ -24,7 +25,7 @@ DB1HDRS = /usr/include/db1 ########################################################################### # Rarely if ever have to touch below here. -MLMVERS = 1.18pre1 +MLMVERS = 1.18 #APXSGDB = -Wc,-g APXSOPTS = -Wc,-O2 -Wc,-Wall STATOPTS = -fpic -O2 -Wall @@ -38,12 +39,12 @@ LINKS = /usr/bin/lynx L2H = /usr/bin/latex2html WEBSERV = gw0.corp -STATFLAGS = -I$(APACHEINST)/include -SOFLAGS = -L$(MYSQLLIBS) -lmysqlclient -lz -ifdef MODSSLHDRS - FLAGS = -DEAPI -I$(MYSQLHDRS) $(MYSQLDELAYED) -I$(MODSSLHDRS) -I$(DB1HDRS) -DWANT_SSL_LOGGING +STATFLAGS = -I$(APACHEHEADERS) +SOFLAGS = -L$(MYSQLLIBRARIES) -lmysqlclient -lz +ifdef MODSSLHEADERS + FLAGS = -DEAPI -I$(MYSQLHEADERS) $(MYSQLDELAYED) -I$(MODSSLHEADERS) -I$(DB1HEADERS) -DWANT_SSL_LOGGING else - FLAGS = -DEAPI -I$(MYSQLHDRS) $(MYSQLDELAYED) + FLAGS = -DEAPI -I$(MYSQLHEADERS) $(MYSQLDELAYED) endif all: @@ -80,15 +81,15 @@ clean: $(RM) -f Documentation/*.txt distro: documentation - @scp CHANGELOG $(WEBSERV):$(APACHEINST)/html/mod_log_sql/docs - @scp Documentation/*.ps $(WEBSERV):$(APACHEINST)/html/mod_log_sql/docs - @scp Documentation/HTML/*.html $(WEBSERV):$(APACHEINST)/html/mod_log_sql/docs/ - @scp Documentation/HTML/*.png $(WEBSERV):$(APACHEINST)/html/mod_log_sql/docs/ - @cd ..; tar zcf mod_log_sql-$(MLMVERS).tar.gz --exclude mod_log_sql/CVS --exclude mod_log_sql/Documentation/CVS --exclude mod_log_sql/Documentation/HTML/CVS --exclude ".directory" mod_log_sql/; scp mod_log_sql-$(MLMVERS).tar.gz $(WEBSERV):$(APACHEINST)/html/mod_log_sql/; rm -f mod_log_sql-$(MLMVERS).tar.gz - @ssh $(WEBSERV) "ln -sf mod_log_sql-$(MLMVERS).tar.gz $(APACHEINST)/html/mod_log_sql/mod_log_sql.tar.gz" + @scp CHANGELOG $(WEBSERV):$(APACHEINSTALLED)/html/mod_log_sql/docs + @scp Documentation/*.ps $(WEBSERV):$(APACHEINSTALLED)/html/mod_log_sql/docs + @scp Documentation/HTML/*.html $(WEBSERV):$(APACHEINSTALLED)/html/mod_log_sql/docs/ + @scp Documentation/HTML/*.png $(WEBSERV):$(APACHEINSTALLED)/html/mod_log_sql/docs/ + @cd ..; tar zcf mod_log_sql-$(MLMVERS).tar.gz --exclude mod_log_sql/CVS --exclude mod_log_sql/Documentation/CVS --exclude mod_log_sql/Documentation/HTML/CVS --exclude ".directory" mod_log_sql/; scp mod_log_sql-$(MLMVERS).tar.gz $(WEBSERV):$(APACHEINSTALLED)/html/mod_log_sql/; rm -f mod_log_sql-$(MLMVERS).tar.gz + @ssh $(WEBSERV) "ln -sf mod_log_sql-$(MLMVERS).tar.gz $(APACHEINSTALLED)/html/mod_log_sql/mod_log_sql.tar.gz" pre-distro: documentation - @cd ..; tar zcf mod_log_sql-$(MLMVERS).tar.gz --exclude mod_log_sql/CVS --exclude mod_log_sql/Documentation/CVS --exclude mod_log_sql/Documentation/HTML/CVS --exclude ".directory" mod_log_sql/; scp mod_log_sql-$(MLMVERS).tar.gz $(WEBSERV):$(APACHEINST)/html/mod_log_sql/; rm -f mod_log_sql-$(MLMVERS).tar.gz + @cd ..; tar zcf mod_log_sql-$(MLMVERS).tar.gz --exclude mod_log_sql/CVS --exclude mod_log_sql/Documentation/CVS --exclude mod_log_sql/Documentation/HTML/CVS --exclude ".directory" mod_log_sql/; scp mod_log_sql-$(MLMVERS).tar.gz $(WEBSERV):$(APACHEINSTALLED)/html/mod_log_sql/; rm -f mod_log_sql-$(MLMVERS).tar.gz documentation: Documentation/documentation.lyx @echo "Creating LaTeX docs..." diff --git a/create_tables.sql b/create_tables.sql index bc19a10..dbcfbe4 100644 --- a/create_tables.sql +++ b/create_tables.sql @@ -15,7 +15,8 @@ create table access_log ( request_method varchar(10) , request_protocol varchar(10) , request_time char(28), - request_uri varchar(50) , + request_uri varchar(50), + request_args varchar(255), server_port smallint unsigned, ssl_cipher varchar(25), ssl_keysize smallint unsigned, diff --git a/mod_log_sql.c b/mod_log_sql.c index d58839b..d604e78 100644 --- a/mod_log_sql.c +++ b/mod_log_sql.c @@ -1,4 +1,3 @@ -/* $Id: mod_log_sql.c,v 1.21 2002/12/10 20:37:28 helios Exp $ */ /* --------* * DEFINES * @@ -48,22 +47,23 @@ module sql_log_module; * on a per-virtual-server basis. Every virtual server 'knows' the * same versions of these variables. */ -MYSQL sql_server, *mysql_log = NULL; - -int massvirtual = 0; -int create_tables = 0; -int force_preserve = 0; -char *db_name = NULL; -char *db_host = NULL; -char *db_user = NULL; -char *db_pwd = NULL; -char *mach_id = NULL; -char *socket_file = "/tmp/mysql.sock"; -unsigned int tcp_port = 3306; +MYSQL logsql_server, *logsql_server_p = NULL; + +int logsql_massvirtual = 0; +int logsql_createtables = 0; +int logsql_forcepreserve = 0; +char *logsql_dbname = NULL; +char *logsql_dbhost = NULL; +char *logsql_dbuser = NULL; +char *logsql_dbpwd = NULL; +char *logsql_machid = NULL; +char *logsql_socketfile = "/tmp/mysql.sock"; +unsigned int logsql_tcpport = 3306; + #ifdef WANT_DELAYED_MYSQL_INSERT - char *insert_stmt = "insert delayed into "; + char *logsql_insertclause = "insert delayed into "; #else - char *insert_stmt = "insert into "; + char *logsql_insertclause = "insert into "; #endif typedef const char *(*item_key_func) (request_rec *, char *); @@ -90,14 +90,14 @@ typedef struct { char *transfer_log_format; char *preserve_file; char *cookie_name; -} log_sql_state; +} logsql_state; /* -----------------* * HELPER FUNCTIONS * * -----------------*/ -int safe_create_tables(log_sql_state *cls, request_rec *r); +int safe_create_tables(logsql_state *cls, request_rec *r); static char *format_integer(pool *p, int i) { @@ -220,6 +220,11 @@ static const char *extract_request_uri(request_rec *r, char *a) return r->uri; } +static const char *extract_request_args(request_rec *r, char *a) +{ + return r->args; +} + static const char *extract_status(request_rec *r, char *a) { return pfmt(r->pool, r->status); @@ -295,10 +300,10 @@ static const char *extract_virtual_host(request_rec *r, char *a) static const char *extract_machine_id(request_rec *r, char *a) { - if (!mach_id) + if (!logsql_machid) return "-"; else - return mach_id; + return logsql_machid; } static const char *extract_server_port(request_rec *r, char *a) @@ -349,7 +354,7 @@ static const char *extract_cookie(request_rec *r, char *a) char *isvalid; char *cookiebuf; - log_sql_state *cls = get_module_config(r->server->module_config, &sql_log_module); + logsql_state *cls = get_module_config(r->server->module_config, &sql_log_module); if (cls->cookie_name != NULL) { #ifdef DEBUG @@ -530,6 +535,7 @@ struct log_sql_item_list { } log_sql_item_keys[] = { { 'A', extract_agent, "agent", 1, 1 }, + { 'a', extract_request_args, "request_args", 1, 1 }, { 'b', extract_bytes_sent, "bytes_sent", 0, 0 }, { 'c', extract_cookie, "cookie", 0, 1 }, { 'e', extract_env_var, "env_var", 0, 1 }, @@ -580,7 +586,7 @@ const char *escape_query(const char *from_str, pool *p) return from_str; } - if (!mysql_log) { + if (!logsql_server_p) { /* Well, I would have liked to use the current database charset. mysql is * unavailable, however, so I fall back to the slightly less respectful * mysql_escape_string() function that uses the default charset. @@ -590,7 +596,7 @@ const char *escape_query(const char *from_str, pool *p) /* MySQL is available, so I'll go ahead and respect the current charset when * I perform the escape. */ - retval = mysql_real_escape_string(mysql_log, to_str, from_str, length); + retval = mysql_real_escape_string(logsql_server_p, to_str, from_str, length); } if (retval) @@ -609,33 +615,34 @@ int open_logdb_link(server_rec* s) 0 if unsuccessful */ - if (force_preserve) + if (logsql_forcepreserve) return 3; - if (mysql_log) + if (logsql_server_p) return 2; - if (db_name) { - mysql_init(&sql_server); - mysql_log = mysql_real_connect(&sql_server, db_host, db_user, db_pwd, db_name, tcp_port, socket_file, 0); + if ((logsql_dbname) && (logsql_dbhost) && (logsql_dbuser) && (logsql_dbpwd)) { + mysql_init(&logsql_server); + logsql_server_p = mysql_real_connect(&logsql_server, logsql_dbhost, logsql_dbuser, logsql_dbpwd, logsql_dbname, logsql_tcpport, logsql_socketfile, 0); - if (mysql_log) { + if (logsql_server_p) { #ifdef DEBUG ap_log_error(APLOG_MARK,DEBUGLEVEL,s,"HOST: '%s' PORT: '%d' DB: '%s' USER: '%s' SOCKET: '%s'", - db_host, tcp_port, db_name, db_user, socket_file); + logsql_dbhost, logsql_tcpport, logsql_dbname, logsql_dbuser, logsql_socketfile); #endif return 1; } else { #ifdef DEBUG - ap_log_error(APLOG_MARK,DEBUGLEVEL,s,"mod_log_sql: database connection error: %s",MYSQL_ERROR(&sql_server)); + ap_log_error(APLOG_MARK,DEBUGLEVEL,s,"mod_log_sql: database connection error: %s",MYSQL_ERROR(&logsql_server)); ap_log_error(APLOG_MARK,DEBUGLEVEL,s,"HOST: '%s' PORT: '%d' DB: '%s' USER: '%s' SOCKET: '%s'", - db_host, tcp_port, db_name, db_user, socket_file); + logsql_dbhost, logsql_tcpport, logsql_dbname, logsql_dbuser, logsql_socketfile); #endif return 0; } + } else { + ap_log_error(APLOG_MARK,ERRLEVEL,s,"mod_log_sql: insufficient configuration info to establish database link"); + return 0; } - - return 0; } const char *extract_table(void *data, const char *key, const char *val) @@ -648,7 +655,7 @@ const char *extract_table(void *data, const char *key, const char *val) void preserve_entry(request_rec *r, const char *query) { FILE *fp; - log_sql_state *cls = get_module_config(r->server->module_config, &sql_log_module); + logsql_state *cls = get_module_config(r->server->module_config, &sql_log_module); fp = pfopen(r->pool, cls->preserve_file, "a"); if (fp == NULL) @@ -664,7 +671,7 @@ void preserve_entry(request_rec *r, const char *query) /*-----------------------------------------------------*/ -/* safe_mysql_query: perform a database query with */ +/* safe_sql_query: perform a database query with */ /* a degree of safety and error checking. */ /* */ /* Parms: request record, SQL insert statement */ @@ -673,13 +680,13 @@ void preserve_entry(request_rec *r, const char *query) /* 2 if insert delayed failed (kluge) */ /* the actual MySQL return code on error */ /*-----------------------------------------------------*/ -unsigned int safe_mysql_query(request_rec *r, const char *query) +unsigned int safe_sql_query(request_rec *r, const char *query) { int retval; struct timespec delay, remainder; int ret; void (*handler) (int); - log_sql_state *cls; + logsql_state *cls; unsigned int real_error; #ifdef WANT_DELAYED_MYSQL_INSERT char *real_error_str; @@ -689,10 +696,10 @@ unsigned int safe_mysql_query(request_rec *r, const char *query) handler = signal(SIGPIPE, SIG_IGN); /* First attempt for the query */ - if (!mysql_log) { + if (!logsql_server_p) { signal(SIGPIPE, handler); return 1; - } else if (!(retval = mysql_query(mysql_log, query))) { + } else if (!(retval = mysql_query(logsql_server_p, query))) { signal(SIGPIPE, handler); return 0; } @@ -701,9 +708,9 @@ unsigned int safe_mysql_query(request_rec *r, const char *query) * (After all, the module thought it had a valid mysql_log connection but the query * could have failed for a number of reasons, so we have to be extra-safe and check.) */ #ifdef WANT_DELAYED_MYSQL_INSERT - real_error_str = MYSQL_ERROR(mysql_log); + real_error_str = MYSQL_ERROR(logsql_server_p); #else - real_error = mysql_errno(mysql_log); + real_error = mysql_errno(logsql_server_p); #endif /* Check to see if the error is "nonexistent table" */ @@ -712,19 +719,19 @@ unsigned int safe_mysql_query(request_rec *r, const char *query) #else if (real_error == ER_NO_SUCH_TABLE) { #endif - if (create_tables) { + if (logsql_createtables) { ap_log_error(APLOG_MARK,ERRLEVEL,r->server,"mod_log_sql: table doesn't exist...creating now"); cls = get_module_config(r->server->module_config, &sql_log_module); if (safe_create_tables(cls, r)) { ap_log_error(APLOG_MARK,ERRLEVEL,r->server,"mod_log_sql: child attempted but failed to create one or more tables for %s, preserving query", ap_get_server_name(r)); preserve_entry(r, query); - retval = mysql_errno(mysql_log); + retval = mysql_errno(logsql_server_p); } else { ap_log_error(APLOG_MARK,ERRLEVEL,r->server,"mod_log_sql: tables successfully created - retrying query"); - if (mysql_query(mysql_log, query)) { + if (mysql_query(logsql_server_p, query)) { ap_log_error(APLOG_MARK,ERRLEVEL,r->server,"mod_log_sql: giving up, preserving query"); preserve_entry(r, query); - retval = mysql_errno(mysql_log); + retval = mysql_errno(logsql_server_p); } else ap_log_error(APLOG_MARK,ERRLEVEL,r->server,"mod_log_sql: query successful after table creation"); retval = 0; @@ -747,14 +754,14 @@ unsigned int safe_mysql_query(request_rec *r, const char *query) #ifdef WANT_DELAYED_MYSQL_INSERT real_error = 2; #else - real_error = mysql_errno(mysql_log); + real_error = mysql_errno(logsql_server_p); #endif - ap_log_error(APLOG_MARK,ERRLEVEL,r->server,"mod_log_sql: first attempt failed, API said: error %d, \"%s\"", real_error, MYSQL_ERROR(mysql_log)); - mysql_close(mysql_log); - mysql_log = NULL; + ap_log_error(APLOG_MARK,ERRLEVEL,r->server,"mod_log_sql: first attempt failed, API said: error %d, \"%s\"", real_error, MYSQL_ERROR(logsql_server_p)); + mysql_close(logsql_server_p); + logsql_server_p = NULL; open_logdb_link(r->server); - if (mysql_log == NULL) { /* still unable to link */ + if (logsql_server_p == NULL) { /* still unable to link */ signal(SIGPIPE, handler); ap_log_error(APLOG_MARK,ERRLEVEL,r->server,"mod_log_sql: reconnect failed, unable to reach database. SQL logging stopped until child regains a db connection."); ap_log_error(APLOG_MARK,ERRLEVEL,r->server,"mod_log_sql: log entries are being preserved in %s", cls->preserve_file); @@ -770,16 +777,16 @@ unsigned int safe_mysql_query(request_rec *r, const char *query) ap_log_error(APLOG_MARK,ERRLEVEL,r->server,"mod_log_sql: nanosleep unsuccessful"); /* Then make our second attempt */ - retval = mysql_query(mysql_log,query); + retval = mysql_query(logsql_server_p,query); /* If this one also failed, log that and append to our local offline file */ if (retval) { #ifdef WANT_DELAYED_MYSQL_INSERT real_error = 2; #else - real_error = mysql_errno(mysql_log); + real_error = mysql_errno(logsql_server_p); #endif - ap_log_error(APLOG_MARK,ERRLEVEL,r->server,"mod_log_sql: second attempt failed, API said: error %d, \"%s\" -- preserving", real_error, MYSQL_ERROR(mysql_log)); + ap_log_error(APLOG_MARK,ERRLEVEL,r->server,"mod_log_sql: second attempt failed, API said: error %d, \"%s\" -- preserving", real_error, MYSQL_ERROR(logsql_server_p)); preserve_entry(r, query); retval = real_error; } else @@ -798,7 +805,7 @@ unsigned int safe_mysql_query(request_rec *r, const char *query) /* Returns: 0 on no errors */ /* mysql error code on failure */ /*-----------------------------------------------------*/ -int safe_create_tables(log_sql_state *cls, request_rec *r) +int safe_create_tables(logsql_state *cls, request_rec *r) { int retval; unsigned int create_results; @@ -827,6 +834,7 @@ int safe_create_tables(log_sql_state *cls, request_rec *r) request_protocol varchar(10),\ request_time char(28),\ request_uri varchar(50),\ + request_args varchar(255),\ server_port smallint unsigned,\ ssl_cipher varchar(25),\ ssl_keysize smallint unsigned,\ @@ -868,27 +876,27 @@ int safe_create_tables(log_sql_state *cls, request_rec *r) /* Assume that things worked unless told otherwise */ retval = 0; - if ((create_results = safe_mysql_query(r, create_access))) { + if ((create_results = safe_sql_query(r, create_access))) { ap_log_error(APLOG_MARK,ERRLEVEL,r->server,"mod_log_sql: failed to create access table"); retval = create_results; } - if ((create_results = safe_mysql_query(r, create_notes))) { + if ((create_results = safe_sql_query(r, create_notes))) { ap_log_error(APLOG_MARK,ERRLEVEL,r->server,"mod_log_sql: failed to create notes table"); retval = create_results; } - if ((create_results = safe_mysql_query(r, create_hin))) { + if ((create_results = safe_sql_query(r, create_hin))) { ap_log_error(APLOG_MARK,ERRLEVEL,r->server,"mod_log_sql: failed to create header_out table"); retval = create_results; } - if ((create_results = safe_mysql_query(r, create_hout))) { + if ((create_results = safe_sql_query(r, create_hout))) { ap_log_error(APLOG_MARK,ERRLEVEL,r->server,"mod_log_sql: failed to create header_in table"); retval = create_results; } - if ((create_results = safe_mysql_query(r, create_cookies))) { + if ((create_results = safe_sql_query(r, create_cookies))) { ap_log_error(APLOG_MARK,ERRLEVEL,r->server,"mod_log_sql: failed to create cookies table"); retval = create_results; } @@ -903,40 +911,40 @@ int safe_create_tables(log_sql_state *cls, request_rec *r) const char *set_log_sql_massvirtual(cmd_parms *parms, void *dummy, int flag) { - massvirtual = ( flag ? 1 : 0); + logsql_massvirtual = ( flag ? 1 : 0); return NULL; } const char *set_log_sql_force_preserve(cmd_parms *parms, void *dummy, int flag) { - force_preserve = ( flag ? 1 : 0); + logsql_forcepreserve = ( flag ? 1 : 0); return NULL; } const char *set_log_sql_machine_id(cmd_parms *parms, void *dummy, char *arg) { - mach_id = arg; + logsql_machid = arg; return NULL; } const char *set_log_sql_create(cmd_parms *parms, void *dummy, int flag) { - if (massvirtual) + if (logsql_massvirtual) ap_log_error(APLOG_MARK,WARNINGLEVEL,parms->server,"mod_log_sql: do not set LogSQLCreateTables when LogSQLMassVirtualHosting is On. Ignoring."); else - create_tables = ( flag ? 1 : 0); + logsql_createtables = ( flag ? 1 : 0); return NULL; } const char *set_log_sql_db(cmd_parms *parms, void *dummy, char *arg) { - db_name = arg; + logsql_dbname = arg; return NULL; } const char *set_log_sql_cookie(cmd_parms *parms, void *dummy, char *arg) { - log_sql_state *cls = get_module_config(parms->server->module_config, &sql_log_module); + logsql_state *cls = get_module_config(parms->server->module_config, &sql_log_module); cls->cookie_name = arg; return NULL; @@ -945,7 +953,7 @@ const char *set_log_sql_cookie(cmd_parms *parms, void *dummy, char *arg) const char *set_log_sql_preserve_file(cmd_parms *parms, void *dummy, char *arg) { /* char *pfile; */ - log_sql_state *cls = get_module_config(parms->server->module_config, &sql_log_module); + logsql_state *cls = get_module_config(parms->server->module_config, &sql_log_module); /* pfile = ap_pstrcat(parms->pool, "/tmp/", arg, NULL); */ cls->preserve_file = arg; @@ -955,22 +963,22 @@ const char *set_log_sql_preserve_file(cmd_parms *parms, void *dummy, char *arg) const char *set_log_sql_info(cmd_parms *parms, void *dummy, char *host, char *user, char *pwd) { if (*host != '.') { - db_host = host; + logsql_dbhost = host; } if (*user != '.') { - db_user = user; + logsql_dbuser = user; } if (*pwd != '.') { - db_pwd = pwd; + logsql_dbpwd = pwd; } return NULL; } const char *set_log_sql_transfer_table(cmd_parms *parms, void *dummy, char *arg) { - log_sql_state *cls = get_module_config(parms->server->module_config, &sql_log_module); + logsql_state *cls = get_module_config(parms->server->module_config, &sql_log_module); - if (massvirtual != 0) + if (logsql_massvirtual != 0) ap_log_error(APLOG_MARK,WARNINGLEVEL,parms->server,"mod_log_sql: do not set LogSQLTransferLogTable when LogSQLMassVirtualHosting is On. Ignoring."); else cls->transfer_table_name = arg; @@ -979,9 +987,9 @@ const char *set_log_sql_transfer_table(cmd_parms *parms, void *dummy, char *arg) const char *set_log_sql_cookie_table(cmd_parms *parms, void *dummy, char *arg) { - log_sql_state *cls = get_module_config(parms->server->module_config, &sql_log_module); + logsql_state *cls = get_module_config(parms->server->module_config, &sql_log_module); - if (massvirtual != 0) + if (logsql_massvirtual != 0) ap_log_error(APLOG_MARK,WARNINGLEVEL,parms->server,"mod_log_sql: do not set LogSQLCookieLogTable when LogSQLMassVirtualHosting is On. Ignoring."); else cls->cookie_table_name = arg; @@ -990,9 +998,9 @@ const char *set_log_sql_cookie_table(cmd_parms *parms, void *dummy, char *arg) const char *set_log_sql_notes_table(cmd_parms *parms, void *dummy, char *arg) { - log_sql_state *cls = get_module_config(parms->server->module_config, &sql_log_module); + logsql_state *cls = get_module_config(parms->server->module_config, &sql_log_module); - if (massvirtual != 0) + if (logsql_massvirtual != 0) ap_log_error(APLOG_MARK,WARNINGLEVEL,parms->server,"mod_log_sql: do not set LogSQLNotesLogTable when LogSQLMassVirtualHosting is On. Ignoring."); else cls->notes_table_name = arg; @@ -1001,9 +1009,9 @@ const char *set_log_sql_notes_table(cmd_parms *parms, void *dummy, char *arg) const char *set_log_sql_hin_table(cmd_parms *parms, void *dummy, char *arg) { - log_sql_state *cls = get_module_config(parms->server->module_config, &sql_log_module); + logsql_state *cls = get_module_config(parms->server->module_config, &sql_log_module); - if (massvirtual != 0) + if (logsql_massvirtual != 0) ap_log_error(APLOG_MARK,WARNINGLEVEL,parms->server,"mod_log_sql: do not set LogSQLHeadersInLogTable when LogSQLMassVirtualHosting is On. Ignoring."); else cls->hin_table_name = arg; @@ -1012,9 +1020,9 @@ const char *set_log_sql_hin_table(cmd_parms *parms, void *dummy, char *arg) const char *set_log_sql_hout_table(cmd_parms *parms, void *dummy, char *arg) { - log_sql_state *cls = get_module_config(parms->server->module_config, &sql_log_module); + logsql_state *cls = get_module_config(parms->server->module_config, &sql_log_module); - if (massvirtual != 0) + if (logsql_massvirtual != 0) ap_log_error(APLOG_MARK,WARNINGLEVEL,parms->server,"mod_log_sql: do not set LogSQLHeadersOutLogTable when LogSQLMassVirtualHosting is On. Ignoring."); else cls->hout_table_name = arg; @@ -1023,7 +1031,7 @@ const char *set_log_sql_hout_table(cmd_parms *parms, void *dummy, char *arg) const char *set_log_sql_transfer_log_format(cmd_parms *parms, void *dummy, char *arg) { - log_sql_state *cls = get_module_config(parms->server->module_config, &sql_log_module); + logsql_state *cls = get_module_config(parms->server->module_config, &sql_log_module); cls->transfer_log_format = arg; return NULL; @@ -1031,14 +1039,14 @@ const char *set_log_sql_transfer_log_format(cmd_parms *parms, void *dummy, char const char *set_log_sql_socket_file(cmd_parms *parms, void *dummy, char *arg) { - socket_file = arg; + logsql_socketfile = arg; return NULL; } const char *set_log_sql_tcp_port(cmd_parms *parms, void *dummy, char *arg) { - tcp_port = (unsigned int)atoi(arg); + logsql_tcpport = (unsigned int)atoi(arg); return NULL; } @@ -1046,7 +1054,7 @@ const char *set_log_sql_tcp_port(cmd_parms *parms, void *dummy, char *arg) const char *add_log_sql_transfer_accept(cmd_parms *parms, void *dummy, char *arg) { char **addme; - log_sql_state *cls = get_module_config(parms->server->module_config, &sql_log_module); + logsql_state *cls = get_module_config(parms->server->module_config, &sql_log_module); addme = push_array(cls->transfer_accept_list); *addme = pstrdup(cls->transfer_accept_list->pool, arg); @@ -1056,7 +1064,7 @@ const char *add_log_sql_transfer_accept(cmd_parms *parms, void *dummy, char *arg const char *add_log_sql_transfer_ignore(cmd_parms *parms, void *dummy, char *arg) { char **addme; - log_sql_state *cls = get_module_config(parms->server->module_config, &sql_log_module); + logsql_state *cls = get_module_config(parms->server->module_config, &sql_log_module); addme = push_array(cls->transfer_ignore_list); *addme = pstrdup(cls->transfer_ignore_list->pool, arg); @@ -1066,7 +1074,7 @@ const char *add_log_sql_transfer_ignore(cmd_parms *parms, void *dummy, char *arg const char *add_log_sql_remhost_ignore(cmd_parms *parms, void *dummy, char *arg) { char **addme; - log_sql_state *cls = get_module_config(parms->server->module_config, &sql_log_module); + logsql_state *cls = get_module_config(parms->server->module_config, &sql_log_module); addme = push_array(cls->remhost_ignore_list); *addme = pstrdup(cls->remhost_ignore_list->pool, arg); @@ -1076,7 +1084,7 @@ const char *add_log_sql_remhost_ignore(cmd_parms *parms, void *dummy, char *arg) const char *add_log_sql_note(cmd_parms *parms, void *dummy, char *arg) { char **addme; - log_sql_state *cls = get_module_config(parms->server->module_config, &sql_log_module); + logsql_state *cls = get_module_config(parms->server->module_config, &sql_log_module); addme = push_array(cls->notes_list); *addme = pstrdup(cls->notes_list->pool, arg); @@ -1086,7 +1094,7 @@ const char *add_log_sql_note(cmd_parms *parms, void *dummy, char *arg) const char *add_log_sql_hout(cmd_parms *parms, void *dummy, char *arg) { char **addme; - log_sql_state *cls = get_module_config(parms->server->module_config, &sql_log_module); + logsql_state *cls = get_module_config(parms->server->module_config, &sql_log_module); addme = push_array(cls->hout_list); *addme = pstrdup(cls->hout_list->pool, arg); @@ -1096,7 +1104,7 @@ const char *add_log_sql_hout(cmd_parms *parms, void *dummy, char *arg) const char *add_log_sql_hin(cmd_parms *parms, void *dummy, char *arg) { char **addme; - log_sql_state *cls = get_module_config(parms->server->module_config, &sql_log_module); + logsql_state *cls = get_module_config(parms->server->module_config, &sql_log_module); addme = push_array(cls->hin_list); *addme = pstrdup(cls->hin_list->pool, arg); @@ -1106,7 +1114,7 @@ const char *add_log_sql_hin(cmd_parms *parms, void *dummy, char *arg) const char *add_log_sql_cookie(cmd_parms *parms, void *dummy, char *arg) { char **addme; - log_sql_state *cls = get_module_config(parms->server->module_config, &sql_log_module); + logsql_state *cls = get_module_config(parms->server->module_config, &sql_log_module); addme = push_array(cls->cookie_list); *addme = pstrdup(cls->cookie_list->pool, arg); @@ -1135,7 +1143,7 @@ static void log_sql_child_init(server_rec *s, pool *p) /* Open a link to the database */ retval = open_logdb_link(s); - if (retval == 0) + if (!retval) ap_log_error(APLOG_MARK,ERRLEVEL,s,"mod_log_sql: child spawned but unable to open database link"); #ifdef DEBUG @@ -1156,7 +1164,7 @@ static void log_sql_child_init(server_rec *s, pool *p) */ static void log_sql_child_exit(server_rec *s, pool *p) { - mysql_close(mysql_log); + mysql_close(logsql_server_p); } @@ -1165,7 +1173,7 @@ void *log_sql_initializer(server_rec *main_server, pool *p) { server_rec *s; - log_sql_state main_conf = ap_get_module_config(main_server->module_config, &sql_log_module); + logsql_state main_conf = ap_get_module_config(main_server->module_config, &sql_log_module); for (server_rec *s = main_server; s; s = s->next) { conf = ap_get_module_config(s->module_config, &sql_log_module); @@ -1188,7 +1196,7 @@ void *log_sql_initializer(server_rec *main_server, pool *p) void *log_sql_make_state(pool *p, server_rec *s) { - log_sql_state *cls = (log_sql_state *) ap_palloc(p, sizeof(log_sql_state)); + logsql_state *cls = (logsql_state *) ap_palloc(p, sizeof(logsql_state)); /* These defaults are overridable in the httpd.conf file. */ cls->transfer_table_name = NULL; /* No default b/c we want its absence to disable logging */ @@ -1296,14 +1304,14 @@ command_rec log_sql_cmds[] = { int log_sql_transaction(request_rec *orig) { char **ptrptr, **ptrptr2; - log_sql_state *cls = get_module_config(orig->server->module_config, &sql_log_module); + logsql_state *cls = get_module_config(orig->server->module_config, &sql_log_module); const char *access_query; request_rec *r; /* We handle mass virtual hosting differently. Dynamically determine the name * of the table from the virtual server's name, and flag it for creation. */ - if (massvirtual) { + if (logsql_massvirtual) { char *access_base = "access_"; char *notes_base = "notes_"; char *hout_base = "headout_"; @@ -1353,11 +1361,12 @@ int log_sql_transaction(request_rec *orig) cls->hout_table_name = o_tablename; cls->hin_table_name = i_tablename; cls->cookie_table_name = c_tablename; - create_tables = 1; + logsql_createtables = 1; } /* Do we have enough info to log? */ - if ( cls->transfer_table_name == NULL ) { + if (!cls->transfer_table_name) { + ap_log_error(APLOG_MARK,ERRLEVEL,orig->server,"mod_log_sql: configuration info is insufficient to log (hint: LogSQLTransferLogTable)"); return DECLINED; } else { const char *thehost; @@ -1476,7 +1485,7 @@ int log_sql_transaction(request_rec *orig) } } if ( itemsets != "" ) { - note_query = ap_pstrcat(r->pool, insert_stmt, "`", cls->notes_table_name, "` (id, item, val) values ", itemsets, NULL); + note_query = ap_pstrcat(r->pool, logsql_insertclause, "`", cls->notes_table_name, "` (id, item, val) values ", itemsets, NULL); #ifdef DEBUG ap_log_error(APLOG_MARK,DEBUGLEVEL,orig->server,"mod_log_sql: note string: %s", note_query); #endif @@ -1504,7 +1513,7 @@ int log_sql_transaction(request_rec *orig) } } if ( itemsets != "" ) { - hout_query = ap_pstrcat(r->pool, insert_stmt, "`", cls->hout_table_name, "` (id, item, val) values ", itemsets, NULL); + hout_query = ap_pstrcat(r->pool, logsql_insertclause, "`", cls->hout_table_name, "` (id, item, val) values ", itemsets, NULL); #ifdef DEBUG ap_log_error(APLOG_MARK,DEBUGLEVEL,orig->server,"mod_log_sql: header_out string: %s", hout_query); #endif @@ -1533,7 +1542,7 @@ int log_sql_transaction(request_rec *orig) } } if ( itemsets != "" ) { - hin_query = ap_pstrcat(r->pool, insert_stmt, "`", cls->hin_table_name, "` (id, item, val) values ", itemsets, NULL); + hin_query = ap_pstrcat(r->pool, logsql_insertclause, "`", cls->hin_table_name, "` (id, item, val) values ", itemsets, NULL); #ifdef DEBUG ap_log_error(APLOG_MARK,DEBUGLEVEL,orig->server,"mod_log_sql: header_in string: %s", hin_query); #endif @@ -1563,7 +1572,7 @@ int log_sql_transaction(request_rec *orig) } if ( itemsets != "" ) { - cookie_query = ap_pstrcat(r->pool, insert_stmt, "`", cls->cookie_table_name, "` (id, item, val) values ", itemsets, NULL); + cookie_query = ap_pstrcat(r->pool, logsql_insertclause, "`", cls->cookie_table_name, "` (id, item, val) values ", itemsets, NULL); #ifdef DEBUG ap_log_error(APLOG_MARK,DEBUGLEVEL,orig->server,"mod_log_sql: cookie string: %s", cookie_query); #endif @@ -1571,7 +1580,7 @@ int log_sql_transaction(request_rec *orig) /* Set up the actual INSERT statement */ - access_query = ap_pstrcat(r->pool, insert_stmt, "`", cls->transfer_table_name, "` (", fields, ") values (", values, ")", NULL); + access_query = ap_pstrcat(r->pool, logsql_insertclause, "`", cls->transfer_table_name, "` (", fields, ") values (", values, ")", NULL); #ifdef DEBUG ap_log_error(APLOG_MARK,DEBUGLEVEL,r->server,"mod_log_sql: access string: %s", access_query); @@ -1580,7 +1589,7 @@ int log_sql_transaction(request_rec *orig) /* If the person activated force-preserve, go ahead and push all the entries * into the preserve file, then return. */ - if (force_preserve) { + if (logsql_forcepreserve) { #ifdef DEBUG ap_log_error(APLOG_MARK,DEBUGLEVEL,orig->server,"mod_log_sql: preservation forced"); #endif @@ -1597,15 +1606,15 @@ int log_sql_transaction(request_rec *orig) } /* How's our mysql link integrity? */ - if (mysql_log == NULL) { + if (logsql_server_p == NULL) { /* Make a try to establish the link */ open_logdb_link(r->server); - if (mysql_log == NULL) { + if (logsql_server_p == NULL) { /* Unable to re-establish a DB link, so assume that it's really * gone and send the entry to the preserve file instead. - * This short-circuits safe_mysql_query() during a db outage and therefore + * This short-circuits safe_sql_query() during a db outage and therefore * we don't keep logging the db error over and over. */ preserve_entry(orig, access_query); @@ -1630,20 +1639,20 @@ int log_sql_transaction(request_rec *orig) /* ---> i.e. we have a good MySQL connection. <--- */ /* Make the access-table insert */ - safe_mysql_query(orig, access_query); + safe_sql_query(orig, access_query); /* Log the optional notes, headers, etc. */ if (note_query) - safe_mysql_query(orig, note_query); + safe_sql_query(orig, note_query); if (hout_query) - safe_mysql_query(orig, hout_query); + safe_sql_query(orig, hout_query); if (hin_query) - safe_mysql_query(orig, hin_query); + safe_sql_query(orig, hin_query); if (cookie_query) - safe_mysql_query(orig, cookie_query); + safe_sql_query(orig, cookie_query); return OK; } -- cgit v0.9.2