summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--CHANGELOG24
-rw-r--r--Documentation/documentation.lyx623
-rw-r--r--Makefile43
-rw-r--r--create_tables.sql3
-rw-r--r--mod_log_sql.c233
5 files changed, 571 insertions, 355 deletions
diff --git a/CHANGELOG b/CHANGELOG
index 66151e7..2e925bd 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -1,10 +1,9 @@
1$Id: CHANGELOG,v 1.18 2002/12/10 19:43:21 helios Exp $ 1$Id: CHANGELOG,v 1.19 2002/12/18 01:06:32 helios Exp $
2 2
3TODO: 3TODO:
4* Rethink documentation flow and rewrite? 4* Rethink documentation flow and rewrite?
5* Port connection portion to other DBMS? Genericize the module? Start with 5* Port connection portion to other DBMS? Genericize the module? Start with
6 PostgreSQL. 6 PostgreSQL.
7* check for mandatory conf directives / syntax quit if not
8* GNU autoconf 7* GNU autoconf
9* merge server config into vh config 8* merge server config into vh config
10* port to Apache 2.x 9* port to Apache 2.x
@@ -12,7 +11,7 @@ TODO:
12 cause performance degradation? If so fix. 11 cause performance degradation? If so fix.
13* LogSQLRotateLogs directive with daily/monthly/weekly/etc. 12* LogSQLRotateLogs directive with daily/monthly/weekly/etc.
14* new format char: IP as bigint? 13* new format char: IP as bigint?
15* socket-based middleman daemon with configurable conns? 14* socket-based middleman daemon with configurable conns, or connect/disconnect.
16* ignore by cookie 15* ignore by cookie
17 16
18CHANGES: 17CHANGES:
@@ -28,20 +27,31 @@ CHANGES:
28 are made only on ER_NO_SUCH_TABLE. This should solve all the multiple- 27 are made only on ER_NO_SUCH_TABLE. This should solve all the multiple-
29 creation-attempt issues as well as reduce overhead. 28 creation-attempt issues as well as reduce overhead.
30* safe_mysql_query reworked; it now can be counted on to preserve_entry() 29* safe_mysql_query reworked; it now can be counted on to preserve_entry()
31 if the query doesn't succeed. (Before, preserve_entry() was called 30 if the query doesn't succeed. [Before, preserve_entry() was called
32 separately.) 31 separately.]
33* Always return SIGPIPE to handler before leaving safe_mysql_query(). 32* Always reset SIGPIPE to handler before leaving safe_mysql_query().
34* New directive LogSQLRequestAccept, another filter for excluding things 33* New directive LogSQLRequestAccept, another filter for excluding things
35 from being logged. 34 from being logged.
36* Alphabetized the directives in the reference section of the docs. 35* Alphabetized the directives in the reference section of the docs.
36* New format char 'a' lets one log the request arguments, i.e. the
37 part of a CGI request after the ? character. Also put a column for
38 this in the create_tables.sql file. Thanks to Dave Wilson for this.
37* Reorganized the FAQ by section. 39* Reorganized the FAQ by section.
40* Renamed global variables (e.g. tcp_port -> logsql_tcpport) throughout
41 the code in order to ensure against naming conflicts. tcp_port, in
42 particular, seemed to be causing problems / segfaults on certain systems.
43* Renamed safe_mysql_query() to safe_sql_query().
44* Now check for minimum configuration info to establish db link and
45 log an error if it's insufficient.
46* Log a message if the config is insufficient for logging.
47
38 48
391.17: 491.17:
40* Renamed the module mod_log_sql to conform to the project goal of 50* Renamed the module mod_log_sql to conform to the project goal of
41 database-inspecificity. 51 database-inspecificity.
42* Added capability of logging Notes field. This is useful for folks using 52* Added capability of logging Notes field. This is useful for folks using
43 custom modules that provide loggable info in the notes, e.g. mod_gzip. 53 custom modules that provide loggable info in the notes, e.g. mod_gzip.
44 A new directive MySQLWhichNotes configures which notes to log to the 54 A new directive LogSQLWhichNotes configures which notes to log to the
45 notes_log table. 55 notes_log table.
46* Added capability of logging inbound and outbound headers. New directives 56* Added capability of logging inbound and outbound headers. New directives
47 LogSQLWhichHeadersIn and LogSQLWhichHeadersOut configure which headers to 57 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,
422\end_deeper 422\end_deeper
423\layout Enumerate 423\layout Enumerate
424 424
425You must know the paths to some installed software before continuing. 425Edit Makefile and change the values of the variables in the first section.
426
426\begin_deeper 427\begin_deeper
427\layout Enumerate 428\layout Enumerate
428 429
429These are 430These paths are
430\series bold 431\series bold
431necessary: 432necessary:
432\begin_deeper 433\begin_deeper
433\layout Itemize 434\layout Description
434 435
435The location where you installed Apache -- usually /usr/local/apache, 'locate 436APACHEINSTALLED: the location where you installed Apache -- usually /usr/local/a
436 apxs' can help you find it. 437pache, 'locate apxs' can help you find it.
437\layout Itemize 438\layout Description
438 439
439The location of your MySQL libraries, find using 'locate libmysqlclient.so' 440APACHEHEADERS: The location of your Apache header files, find using 'locate
440\layout Itemize 441 httpd.h'
442\layout Description
443
444MYSQLLIBRARIES: The location of your MySQL libraries, find using 'locate
445 libmysqlclient.so'
446\layout Description
441 447
442The location of your MySQL header files, find using 'locate mysql.h' 448MYSQLHEADERS: The location of your MySQL header files, find using 'locate
449 mysql.h'
443\end_deeper 450\end_deeper
444\layout Enumerate 451\layout Enumerate
445 452
@@ -450,12 +457,13 @@ Optional
450: if you compiled mod_ssl for Apache and want to log SSL data such as 'keysize' 457: if you compiled mod_ssl for Apache and want to log SSL data such as 'keysize'
451 and 'cipher type': 458 and 'cipher type':
452\begin_deeper 459\begin_deeper
453\layout Itemize 460\layout Description
454 461
455The location of your SSL header files, find using 'locate mod_ssl.h' 462MODSSLHEADERS: the location of your mod_ssl header files, find using 'locate
456\layout Itemize 463 mod_ssl.h'
464\layout Description
457 465
458The location of your db1 header files, find using 'locate ndbm.h' 466DB1HEADERS: the location of your db1 header files, find using 'locate ndbm.h'
459\end_deeper 467\end_deeper
460\layout Standard 468\layout Standard
461 469
@@ -473,13 +481,9 @@ such as the cipher type.
473\end_deeper 481\end_deeper
474\layout Enumerate 482\layout Enumerate
475 483
476Now that you know these things, edit Makefile and replace the stock values
477 with your own.
478\begin_deeper
479\layout Standard
480
481IMPORTANT: If you are not logging SSL info, comment out MODSSLHDRS by putting 484IMPORTANT: If you are not logging SSL info, comment out MODSSLHDRS by putting
482 a # character in front of it: 485 a # character in front of it:
486\begin_deeper
483\layout LyX-Code 487\layout LyX-Code
484 488
485#MODSSLHDRS=/usr/include/... 489#MODSSLHDRS=/usr/include/...
@@ -496,15 +500,14 @@ Instruct apxs to compile the module as a DSO.
496You should see output similar to the following: 500You should see output similar to the following:
497\layout LyX-Code 501\layout LyX-Code
498 502
499/usr/local/Apache/bin/apxs -Wc,-O2 -Wc,-Wall -Wc,-DEAPI -c -I/usr/incl... 503/usr/local/Apache/bin/apxs -Wc,-O2 -Wc,-Wall -Wc,-DEAPI -c -I/usr/...
500
501\layout LyX-Code 504\layout LyX-Code
502 505
503gcc -DLINUX=22 -DNO_DBM_REWRITEMAP -DMOD_SSL=208111 -DUSE_HSREGEX -DEAPI... 506gcc -DLINUX=22 -DNO_DBM_REWRITEMAP -DMOD_SSL=208111 -DUSE_HS...
504 507
505\layout LyX-Code 508\layout LyX-Code
506 509
507gcc -shared -o mod_log_sql.so mod_log_sql.o -Wc,-O2 -Wc,-Wall -Wc,-DEAPI... 510gcc -shared -o mod_log_sql.so mod_log_sql.o -Wc,-O2 -Wc,-Wall -Wc...
508\layout Standard 511\layout Standard
509 512
510You should see no errors and have a new file called "mod_log_sql.so" in your 513You 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.
650 653
651\end_inset 654\end_inset
652 655
653You must know the paths to some installed software before continuing. 656Edit Makefile and change the values of the variables in the first section.
657
654\begin_deeper 658\begin_deeper
655\layout Enumerate 659\layout Enumerate
656 660
@@ -658,21 +662,29 @@ These are
658\series bold 662\series bold
659necessary: 663necessary:
660\begin_deeper 664\begin_deeper
661\layout Itemize 665\layout Description
662 666
663The location where you installed Apache -- usually /usr/local/apache, 'locate 667APACHEINSTALLED: the location where you installed Apache -- usually /usr/local/a
664 apxs' can help you find it. 668pache, 'locate apxs' can help you find it.
665 669\layout Description
666\layout Itemize
667 670
668The location of your Apache *sources*, find using 'locate ABOUT_APACHE' 671APACHESOURCE: the location of your Apache
669 672\series bold
670\layout Itemize 673sources
674\series default
675, find using 'locate ABOUT_APACHE'
676\layout Description
671 677
672The location of your MySQL header files, find using 'locate mysql.h' 678APACHEHEADERS: The location of your Apache header files, find using 'locate
673\layout Itemize 679 httpd.h'
680\layout Description
681
682MYSQLLIBRARIES: The location of your MySQL libraries, find using 'locate
683 libmysqlclient.so'
684\layout Description
674 685
675The location of your MySQL libraries, find using 'locate libmysqlclient.so' 686MYSQLHEADERS: The location of your MySQL header files, find using 'locate
687 mysql.h'
676\end_deeper 688\end_deeper
677\layout Enumerate 689\layout Enumerate
678 690
@@ -683,12 +695,13 @@ Optional
683: if you compiled mod_ssl for Apache and want to log SSL data such as 'keysize' 695: if you compiled mod_ssl for Apache and want to log SSL data such as 'keysize'
684 and 'cipher type': 696 and 'cipher type':
685\begin_deeper 697\begin_deeper
686\layout Itemize 698\layout Description
687 699
688The location of your mod_ssl header files, find using 'locate mod_ssl.h' 700MODSSLHEADERS: the location of your mod_ssl header files, find using 'locate
689\layout Itemize 701 mod_ssl.h'
702\layout Description
690 703
691The location of your db1 header files, find using 'locate ndbm.h' 704DB1HEADERS: the location of your db1 header files, find using 'locate ndbm.h'
692\end_deeper 705\end_deeper
693\layout Standard 706\layout Standard
694 707
@@ -706,13 +719,9 @@ if you want to log SSL-specific data
706\end_deeper 719\end_deeper
707\layout Enumerate 720\layout Enumerate
708 721
709Now that you know these things, edit Makefile and replace the stock values
710 with your own.
711\begin_deeper
712\layout Standard
713
714IMPORTANT: If you are not logging SSL info, comment out MODSSLHDRS by putting 722IMPORTANT: If you are not logging SSL info, comment out MODSSLHDRS by putting
715 a # character in front of it: 723 a # character in front of it:
724\begin_deeper
716\layout LyX-Code 725\layout LyX-Code
717 726
718#MODSSLHDRS=/usr/include/... 727#MODSSLHDRS=/usr/include/...
@@ -987,15 +996,6 @@ A very basic logging setup in Apache
987Tell the module what database to use and the appropriate authentication 996Tell the module what database to use and the appropriate authentication
988 information. 997 information.
989\begin_deeper 998\begin_deeper
990\layout Quote
991
992
993\series bold
994Example:
995\series default
996 Use the MySQL database called "apachelogs" running on "dbmachine.foo.com".
997 Use username "loguser" and password "l0gger" to authenticate to the database.
998 Let the module create tables for us.
999\layout Standard 999\layout Standard
1000 1000
1001So, edit httpd.conf and insert the following lines somewhere after any LoadModule 1001So, edit httpd.conf and insert the following lines somewhere after any LoadModule
@@ -1014,9 +1014,29 @@ global,
1014 not inside any VirtualHost stanza 1014 not inside any VirtualHost stanza
1015\emph default 1015\emph default
1016. 1016.
1017 You will also note that you are embedding a password in the file.
1018 Therefore you are advised to
1019\begin_inset Quotes eld
1020\end_inset
1021
1022chmod 660 httpd.conf
1023\begin_inset Quotes erd
1024\end_inset
1025
1026 to prevent unauthorized regular users from viewing your database user and
1027 password.
1028\layout Standard
1029
1030
1031\series bold
1032Example
1033\series default
1034: Use the MySQL database called "apachelogs" running on "dbmachine.foo.com".
1035 Use username "loguser" and password "l0gg3r" to authenticate to the database.
1036 Permit the module create tables for us.
1017\layout LyX-Code 1037\layout LyX-Code
1018 1038
1019LogSQLLoginInfo dbmachine.foo.com loguser l0gger 1039LogSQLLoginInfo dbmachine.foo.com loguser l0gg3r
1020\layout LyX-Code 1040\layout LyX-Code
1021 1041
1022LogSQLDatabase apachelogs 1042LogSQLDatabase apachelogs
@@ -1111,74 +1131,18 @@ Several lines of output should follow, corresponding to your hits on the
1111 You now have basic functionality. 1131 You now have basic functionality.
1112 Don't disable your regular Apache logs until you feel comfortable that 1132 Don't disable your regular Apache logs until you feel comfortable that
1113 the database is behaving as you'd like and that things are going well. 1133 the database is behaving as you'd like and that things are going well.
1134 If you do not see any entries in the access_log, please consult section
1135
1136\begin_inset LatexCommand \ref{faq:NothingLogged}
1137
1138\end_inset
1139
1140 of the FAQ on how to debug and fix the situation.
1114\end_deeper 1141\end_deeper
1115\layout Enumerate 1142\layout Enumerate
1116 1143
1117You can now activate the advanced features of mod_log_sql, which are described 1144You can now activate the advanced features of mod_log_sql, which are described
1118 in the next section. 1145 in the next section.
1119 If you do not see any entries in the access_log, then something is preventing
1120 the inserts from happening.
1121 This could be caused by several things:
1122\begin_deeper
1123\layout Itemize
1124
1125Improper privileges set up in the MySQL database
1126\layout Itemize
1127
1128You aren't hitting a VirtualHost that has a
1129\noun on
1130LogSQLTransferLogTable
1131\noun default
1132 entry
1133\layout Itemize
1134
1135You didn't specify the right database host or login information
1136\layout Standard
1137
1138So, first examine the MySQL log that you established in step
1139\begin_inset LatexCommand \ref{step:EnaLog}
1140
1141\end_inset
1142
1143 of section
1144\begin_inset LatexCommand \ref{sub:PrepDb}
1145
1146\end_inset
1147
1148.
1149 Ensure that the INSERT statements are not being rejected because of a malformed
1150 table name or other typographical error.
1151 By enabling that log, you instructed MySQL to log every connection and
1152 command it receives -- if you see no INSERT attempts in the log, the module
1153 isn't successfully connecting to the database.
1154 If you see nothing at all in the log -- not even a record of your administrativ
1155e connection attempts, then you did not enable the log correctly.
1156 If you do see INSERT attempts but they are failing, the log should tell
1157 you why.
1158\layout Standard
1159
1160Second, confirm that your
1161\noun on
1162LogSQL*
1163\noun default
1164 directives are all correct.
1165\layout Standard
1166
1167Third, examine the Apache
1168\noun on
1169
1170\noun default
1171error logs for messages from mod_log_sql; the module will offer hints as
1172 to why it cannot connect, etc.
1173
1174\layout Standard
1175
1176The next thing to do is recompile the module with debugging output activated.
1177 change the "#undef DEBUG" on line 8 of mod_log_sql.c to "#define DEBUG"
1178 and recompile/reinstall.
1179 The module will now output copious notes about what it is doing, and this
1180 will help you (and the maintainer) solve the problem.
1181\end_deeper
1182\layout Subsection 1146\layout Subsection
1183 1147
1184How to tune logging with run-time directives 1148How to tune logging with run-time directives
@@ -2537,8 +2501,9 @@ Optimizing for a busy database
2537 2501
2538A busy MySQL database will have SELECT statements running concurrently with 2502A busy MySQL database will have SELECT statements running concurrently with
2539 INSERT and UPDATE statements. 2503 INSERT and UPDATE statements.
2540 A long-running SELECT can block INSERTs, therefore will block mod_log_sql. 2504 A long-running SELECT can in certain circumstances block INSERTs and therefore
2541 This may be solved by compiling mod_log_sql for 2505 block mod_log_sql.
2506 A workaround is to compile mod_log_sql for
2542\begin_inset Quotes eld 2507\begin_inset Quotes eld
2543\end_inset 2508\end_inset
2544 2509
@@ -2907,7 +2872,15 @@ host
2907\begin_inset Quotes erd 2872\begin_inset Quotes erd
2908\end_inset 2873\end_inset
2909 2874
2910 is the hostname or IP address of the MySQL machine. 2875 is the hostname or IP address of the MySQL machine, and is simply
2876\begin_inset Quotes eld
2877\end_inset
2878
2879localhost
2880\begin_inset Quotes erd
2881\end_inset
2882
2883 if the database lives on the same machine as Apache.
2911 2884
2912\begin_inset Quotes eld 2885\begin_inset Quotes eld
2913\end_inset 2886\end_inset
@@ -3397,7 +3370,7 @@ Each character in the format-string defines an attribute of the request
3397\size footnotesize 3370\size footnotesize
3398 3371
3399\begin_inset Tabular 3372\begin_inset Tabular
3400<lyxtabular version="3" rows="21" columns="5"> 3373<lyxtabular version="3" rows="22" columns="5">
3401<features> 3374<features>
3402<column alignment="center" valignment="top" leftline="true" rightline="true" width="0pt"> 3375<column alignment="center" valignment="top" leftline="true" rightline="true" width="0pt">
3403<column alignment="left" valignment="top" width="0pt"> 3376<column alignment="left" valignment="top" width="0pt">
@@ -3515,6 +3488,48 @@ Mozilla/4.0 (compat; MSIE 6.0; Windows)
3515 3488
3516\layout Standard 3489\layout Standard
3517 3490
3491a
3492\end_inset
3493</cell>
3494<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3495\begin_inset Text
3496
3497\layout Standard
3498
3499CGI request arguments
3500\end_inset
3501</cell>
3502<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3503\begin_inset Text
3504
3505\layout Standard
3506
3507request_args
3508\end_inset
3509</cell>
3510<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3511\begin_inset Text
3512
3513\layout Standard
3514
3515varchar(255)
3516\end_inset
3517</cell>
3518<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3519\begin_inset Text
3520
3521\layout Standard
3522
3523user=Smith&cart=1231&item=532
3524\end_inset
3525</cell>
3526</row>
3527<row topline="true">
3528<cell alignment="center" valignment="top" topline="true" leftline="true" usebox="none">
3529\begin_inset Text
3530
3531\layout Standard
3532
3518 3533
3519\size footnotesize 3534\size footnotesize
3520b 3535b
@@ -5724,6 +5739,273 @@ Please contact
5724 course. 5739 course.
5725\layout Subsection 5740\layout Subsection
5726 5741
5742Problems
5743\layout Subsubsection
5744
5745Apache segfaults when using PHP and mod_log_sql
5746\layout Standard
5747
5748This occurs if you compiled PHP with MySQL database support.
5749 PHP utilizes its internal, bundled MySQL libraries by default.
5750 These conflict with the
5751\begin_inset Quotes eld
5752\end_inset
5753
5754real
5755\begin_inset Quotes erd
5756\end_inset
5757
5758 MySQL libraries linked by mod_log_sql, causing the segmentation fault.
5759
5760\layout Standard
5761
5762The solution is to configure PHP to link against the real MySQL libraries
5763 and recompile mod_php.
5764 Apache will run properly once the modules are all using the same version
5765 of the MySQL libraries.
5766\layout Subsubsection
5767
5768
5769\begin_inset LatexCommand \label{faq:NothingLogged}
5770
5771\end_inset
5772
5773Apache appears to start up fine, but nothing is getting logged in the database
5774\layout Standard
5775
5776If you do not see any entries in the access_log, then something is preventing
5777 the inserts from happening.
5778 This could be caused by several things:
5779\layout Itemize
5780
5781Improper privileges set up in the MySQL database
5782\layout Itemize
5783
5784You aren't hitting a VirtualHost that has a LogSQLTransferLogTable entry
5785
5786\layout Itemize
5787
5788You didn't specify the right database host or login information
5789\layout Itemize
5790
5791Another factor is preventing a connection to the database
5792\layout Standard
5793
5794Important: it is improper to ask for help before you have followed these
5795 steps.
5796\layout Standard
5797
5798First examine the MySQL log that you established in step
5799\begin_inset LatexCommand \ref{step:EnaLog}
5800
5801\end_inset
5802
5803 of section
5804\begin_inset LatexCommand \ref{sub:PrepDb}
5805
5806\end_inset
5807
5808.
5809 Ensure that the INSERT statements are not being rejected because of a malformed
5810 table name or other typographical error.
5811 By enabling that log, you instructed MySQL to log every connection and
5812 command it receives -- if you see no INSERT attempts in the log, the module
5813 isn't successfully connecting to the database.
5814 If you see nothing at all in the log -- not even a record of your administrativ
5815e connection attempts, then you did not enable the log correctly.
5816 If you do see INSERT attempts but they are failing, the log should tell
5817 you why.
5818\layout Standard
5819
5820Second, confirm that your
5821\noun on
5822LogSQL*
5823\noun default
5824 directives are all correct.
5825\layout Standard
5826
5827Third, examine the Apache
5828\noun on
5829
5830\noun default
5831error logs for messages from mod_log_sql; the module will offer hints as
5832 to why it cannot connect, etc.
5833
5834\layout Standard
5835
5836The next thing to do is recompile the module with debugging output activated.
5837 change the "#undef DEBUG" on line 8 of mod_log_sql.c to "#define DEBUG"
5838 and recompile/reinstall.
5839 The module will now output copious notes about what it is doing, and this
5840 will help you (and the maintainer) solve the problem.
5841 In order to see the debugging messages, ensure that you make them visible
5842 using the
5843\noun on
5844LogLevel
5845\noun default
5846directive
5847\series bold
5848in the main server config as well as in each
5849\noun on
5850VirtualHost
5851\noun default
5852config:
5853\layout LyX-Code
5854
5855LogLevel debug
5856\layout LyX-Code
5857
5858ErrorLog /var/log/httpd/server-messages
5859\layout Subsubsection
5860
5861Why do I get the message
5862\begin_inset Quotes eld
5863\end_inset
5864
5865configuration info is insufficient to log
5866\begin_inset Quotes erd
5867\end_inset
5868
5869 in my Apache error log?
5870\layout Standard
5871
5872At a minimum,
5873\noun on
5874LogSQLTransferLogTable
5875\noun default
5876 must be defined for the module to even attempt logging.
5877 If this directive is not defined for the server (or virtual server) you
5878 will receive this error message.
5879
5880\layout Subsubsection
5881
5882Why do I get the message
5883\begin_inset Quotes eld
5884\end_inset
5885
5886insufficient configuration info to establish database link
5887\begin_inset Quotes erd
5888\end_inset
5889
5890 in my Apache error log?
5891\layout Standard
5892
5893At a minimum,
5894\noun on
5895LogSQLDatabase
5896\noun default
5897 and
5898\noun on
5899LogSQLLoginInfo
5900\noun default
5901must be defined in order for the module to be able to establish a database
5902 link.
5903 If these are not defined or are incomplete you will receive this error
5904 message.
5905\layout Subsubsection
5906
5907My database cannot handle all the open connections from mod_log_sql, is
5908 there anything I can do?
5909\layout Standard
5910
5911The rule of thumb: if you have
5912\emph on
5913n
5914\emph default
5915webservers each configured to support
5916\emph on
5917y
5918\emph default
5919
5920\noun on
5921MaxClients
5922\noun default
5923, then your database must be able to handle
5924\begin_inset Formula $n\times y$
5925\end_inset
5926
5927 simultenous connections
5928\emph on
5929in the worst case.
5930
5931\emph default
5932Certainly you must use common sense, consider reasonable traffic expectations
5933 and structure things accordingly.
5934\layout Standard
5935
5936Tweaking my.cnf to scale to high connection loads is imperative.
5937 But if hardware limitations prevent your MySQL server from gracefully handling
5938 the number of incoming connections, it would be beneficial to upgrade the
5939 memory or CPU on that server in order to handle the load.
5940
5941\layout Standard
5942
5943Jeremy Zawodny, a highly respected MySQL user and contributor to Linux Magazine,
5944 has this very helpful and highly appropriate article on tuning MySQL:
5945\begin_inset LatexCommand \url{http://jeremy.zawodny.com/blog/archives/000173.html}
5946
5947\end_inset
5948
5949
5950\layout Standard
5951
5952Please remember that mod_log_sql's overriding principle is
5953\series bold
5954performance
5955\series default
5956 -- that is what the target audience demands and expects.
5957 Other database logging solutions do not open and maintain many database
5958 connections, but their performance suffers drastically.
5959 For example, pgLOGd funnels all log connections through a separate daemon
5960 that connects to the database, but that bottlenecks the entire process.
5961 mod_log_sql achieves performance numbers an order of magnitude greater
5962 than the alternatives because it dispenses with the overhead associated
5963 with rapid connection cycling, and it doesn't attempt to shoehorn all the
5964 database traffic through a single extra daemon or proxy process.
5965\layout Subsubsection
5966
5967Why do I occasionally see a
5968\begin_inset Quotes eld
5969\end_inset
5970
5971lost connection to MySQL server
5972\begin_inset Quotes erd
5973\end_inset
5974
5975 message in my Apache error log?
5976\layout Standard
5977
5978This message may appear every now and then in your Apache error log, especially
5979 on very lightly loaded servers.
5980 This doesn't mean that anything is necessarily wrong.
5981 Within each httpd child process, mod_log_sql will open (and keep open)
5982 a connection to the MySQL server.
5983 MySQL, however, will close connections that haven't been used in a while;
5984 the default timeout is 8 hours.
5985 When this occurs, mod_log_sql will notice and re-open the connection.
5986 That event is what is being logged, and looks like this:
5987\layout LyX-Code
5988
5989[Tue Nov 12 19:04:10 2002] [error] mod_log_sql: first attempt failed,
5990\layout LyX-Code
5991
5992 API said: error 2013, Lost connection to MySQL server during query
5993\layout LyX-Code
5994
5995[Tue Nov 12 19:04:10 2002] [error] mod_log_sql: reconnect successful
5996\layout LyX-Code
5997
5998[Tue Nov 12 19:04:10 2002] [error] mod_log_sql: second attempt successful
5999\layout Standard
6000
6001Reference:
6002\begin_inset LatexCommand \url[MySQL documentation]{(http://www.mysql.com/documentation/mysql/bychapter/manual_Problems.html#Gone_away)}
6003
6004\end_inset
6005
6006
6007\layout Subsection
6008
5727Performance and Tuning 6009Performance and Tuning
5728\layout Subsubsection 6010\layout Subsubsection
5729 6011
@@ -6007,58 +6289,7 @@ ps
6007 would lead you to believe. 6289 would lead you to believe.
6008\layout Subsubsection 6290\layout Subsubsection
6009 6291
6010My database cannot handle all the open connections from mod_log_sql, is 6292My webserver cannot handle all the traffic that my site receives, is there
6011 there anything I can do?
6012\layout Standard
6013
6014The rule of thumb: if you have
6015\emph on
6016n
6017\emph default
6018webservers each configured to support
6019\emph on
6020y
6021\emph default
6022
6023\noun on
6024MaxClients
6025\noun default
6026, then your database must be able to handle
6027\begin_inset Formula $n\times y$
6028\end_inset
6029
6030 simultenous connections
6031\emph on
6032in the worst case.
6033
6034\emph default
6035Certainly you must use common sense, consider reasonable traffic expectations
6036 and structure things accordingly.
6037\layout Standard
6038
6039Tweaking my.cnf to scale to high connection loads is imperative.
6040 But if hardware limitations prevent your MySQL server from gracefully handling
6041 the number of incoming connections, it would be beneficial to upgrade the
6042 memory or CPU on that server in order to handle the load.
6043
6044\layout Standard
6045
6046Please remember that mod_log_sql's overriding principle is
6047\series bold
6048performance
6049\series default
6050 -- that is what the target audience demands and expects.
6051 Other database logging solutions do not open and maintain many database
6052 connections, but their performance suffers drastically.
6053 For example, pgLOGd funnels all log connections through a separate daemon
6054 that connects to the database, but that bottlenecks the entire process.
6055 mod_log_sql achieves performance numbers an order of magnitude greater
6056 than the alternatives because it dispenses with the overhead associated
6057 with rapid connection cycling, and it doesn't attempt to shoehorn all the
6058 database traffic through a single extra daemon or proxy process.
6059\layout Subsubsection
6060
6061My webservers cannot handle all the traffic that my site receives, is there
6062 anything I can do? 6293 anything I can do?
6063\layout Standard 6294\layout Standard
6064 6295
@@ -6068,48 +6299,6 @@ If you have exhausted all the tuning possibilities on your existing server,
6068 In fact, users of such a setup are mod_log_sql's target audience! 6299 In fact, users of such a setup are mod_log_sql's target audience!
6069\layout Subsubsection 6300\layout Subsubsection
6070 6301
6071Why do I occasionally see a
6072\begin_inset Quotes eld
6073\end_inset
6074
6075lost connection to MySQL server
6076\begin_inset Quotes erd
6077\end_inset
6078
6079 message in my error-log?
6080\layout Standard
6081
6082This message may appear every now and then in your Apache error log, especially
6083 on very lightly loaded servers.
6084 This doesn't mean that anything is necessarily wrong.
6085 Within each httpd child process, mod_log_sql will open (and keep open)
6086 a connection to the MySQL server.
6087 MySQL, however, will close connections that haven't been used in a while;
6088 the default timeout is 8 hours.
6089 When this occurs, mod_log_sql will notice and re-open the connection.
6090 That event is what is being logged, and looks like this:
6091\layout LyX-Code
6092
6093[Tue Nov 12 19:04:10 2002] [error] mod_log_sql: first attempt failed,
6094\layout LyX-Code
6095
6096 API said: error 2013, Lost connection to MySQL server during query
6097\layout LyX-Code
6098
6099[Tue Nov 12 19:04:10 2002] [error] mod_log_sql: reconnect successful
6100\layout LyX-Code
6101
6102[Tue Nov 12 19:04:10 2002] [error] mod_log_sql: second attempt successful
6103\layout Standard
6104
6105Reference:
6106\begin_inset LatexCommand \url[MySQL documentation]{(http://www.mysql.com/documentation/mysql/bychapter/manual_Problems.html#Gone_away)}
6107
6108\end_inset
6109
6110
6111\layout Subsubsection
6112
6113 6302
6114\begin_inset LatexCommand \label{sub:DelayedInsFAQ} 6303\begin_inset LatexCommand \label{sub:DelayedInsFAQ}
6115 6304
@@ -6165,6 +6354,12 @@ As of MySQL version 3.23.52, the error return functions disagree after a failed
6165 tell if anything went wrong with a delayed insert. 6354 tell if anything went wrong with a delayed insert.
6166\layout Standard 6355\layout Standard
6167 6356
6357Instead of delayed inserts, you may wish to utilize InnoDB tables (instead
6358 of the standard MyISAM tables).
6359 InnoDB tables suppot row-level locking and are recommended for high-volume
6360 databases.
6361\layout Standard
6362
6168If after understanding these problems you still wish to enable delayed inserts, 6363If after understanding these problems you still wish to enable delayed inserts,
6169 section 6364 section
6170\begin_inset LatexCommand \ref{sub:DelayedIns} 6365\begin_inset LatexCommand \ref{sub:DelayedIns}
diff --git a/Makefile b/Makefile
index eb4ffdf..5a9c69a 100644
--- a/Makefile
+++ b/Makefile
@@ -1,19 +1,20 @@
1# $Id: Makefile,v 1.19 2002/12/10 20:37:28 helios Exp $ 1# $Id: Makefile,v 1.20 2002/12/18 01:06:33 helios Exp $
2 2
3########################################################################### 3###########################################################################
4# Important: 4# Important:
5# Adjust these values as outlined in section "Installation" in the docs. 5# Adjust these values as outlined in section "Installation" in the docs.
6# Not all are needed at all times. 6# Not all are needed at all times.
7 7
8APACHESOURCE = /usr/local/src/apache_1.3.27-dso 8APACHESOURCE = /usr/local/src/apache_1.3.27-dso
9APACHEINST = /usr/local/Apache 9APACHEINSTALLED = /usr/local/Apache
10APXS = $(APACHEINST)/bin/apxs 10APACHEHEADERS = /usr/local/Apache/include
11APXS = $(APACHEINSTALLED)/bin/apxs
11 12
12MYSQLLIBS = /usr/lib 13MYSQLLIBRARIES = /usr/lib
13MYSQLHDRS = /usr/include/mysql 14MYSQLHEADERS = /usr/include/mysql
14 15
15MODSSLHDRS = /usr/local/src/apache_1.3.27-dso/src/modules/ssl 16#MODSSLHEADERS = /usr/local/src/apache_1.3.27-dso/src/modules/ssl
16DB1HDRS = /usr/include/db1 17#DB1HEADERS = /usr/include/db1
17 18
18########################################################################### 19###########################################################################
19# Don't uncomment this without reading the "Optimizing for a busy database" 20# Don't uncomment this without reading the "Optimizing for a busy database"
@@ -24,7 +25,7 @@ DB1HDRS = /usr/include/db1
24########################################################################### 25###########################################################################
25# Rarely if ever have to touch below here. 26# Rarely if ever have to touch below here.
26 27
27MLMVERS = 1.18pre1 28MLMVERS = 1.18
28#APXSGDB = -Wc,-g 29#APXSGDB = -Wc,-g
29APXSOPTS = -Wc,-O2 -Wc,-Wall 30APXSOPTS = -Wc,-O2 -Wc,-Wall
30STATOPTS = -fpic -O2 -Wall 31STATOPTS = -fpic -O2 -Wall
@@ -38,12 +39,12 @@ LINKS = /usr/bin/lynx
38L2H = /usr/bin/latex2html 39L2H = /usr/bin/latex2html
39WEBSERV = gw0.corp 40WEBSERV = gw0.corp
40 41
41STATFLAGS = -I$(APACHEINST)/include 42STATFLAGS = -I$(APACHEHEADERS)
42SOFLAGS = -L$(MYSQLLIBS) -lmysqlclient -lz 43SOFLAGS = -L$(MYSQLLIBRARIES) -lmysqlclient -lz
43ifdef MODSSLHDRS 44ifdef MODSSLHEADERS
44 FLAGS = -DEAPI -I$(MYSQLHDRS) $(MYSQLDELAYED) -I$(MODSSLHDRS) -I$(DB1HDRS) -DWANT_SSL_LOGGING 45 FLAGS = -DEAPI -I$(MYSQLHEADERS) $(MYSQLDELAYED) -I$(MODSSLHEADERS) -I$(DB1HEADERS) -DWANT_SSL_LOGGING
45else 46else
46 FLAGS = -DEAPI -I$(MYSQLHDRS) $(MYSQLDELAYED) 47 FLAGS = -DEAPI -I$(MYSQLHEADERS) $(MYSQLDELAYED)
47endif 48endif
48 49
49all: 50all:
@@ -80,15 +81,15 @@ clean:
80 $(RM) -f Documentation/*.txt 81 $(RM) -f Documentation/*.txt
81 82
82distro: documentation 83distro: documentation
83 @scp CHANGELOG $(WEBSERV):$(APACHEINST)/html/mod_log_sql/docs 84 @scp CHANGELOG $(WEBSERV):$(APACHEINSTALLED)/html/mod_log_sql/docs
84 @scp Documentation/*.ps $(WEBSERV):$(APACHEINST)/html/mod_log_sql/docs 85 @scp Documentation/*.ps $(WEBSERV):$(APACHEINSTALLED)/html/mod_log_sql/docs
85 @scp Documentation/HTML/*.html $(WEBSERV):$(APACHEINST)/html/mod_log_sql/docs/ 86 @scp Documentation/HTML/*.html $(WEBSERV):$(APACHEINSTALLED)/html/mod_log_sql/docs/
86 @scp Documentation/HTML/*.png $(WEBSERV):$(APACHEINST)/html/mod_log_sql/docs/ 87 @scp Documentation/HTML/*.png $(WEBSERV):$(APACHEINSTALLED)/html/mod_log_sql/docs/
87 @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 88 @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
88 @ssh $(WEBSERV) "ln -sf mod_log_sql-$(MLMVERS).tar.gz $(APACHEINST)/html/mod_log_sql/mod_log_sql.tar.gz" 89 @ssh $(WEBSERV) "ln -sf mod_log_sql-$(MLMVERS).tar.gz $(APACHEINSTALLED)/html/mod_log_sql/mod_log_sql.tar.gz"
89 90
90pre-distro: documentation 91pre-distro: documentation
91 @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 92 @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
92 93
93documentation: Documentation/documentation.lyx 94documentation: Documentation/documentation.lyx
94 @echo "Creating LaTeX docs..." 95 @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 (
15 request_method varchar(10) , 15 request_method varchar(10) ,
16 request_protocol varchar(10) , 16 request_protocol varchar(10) ,
17 request_time char(28), 17 request_time char(28),
18 request_uri varchar(50) , 18 request_uri varchar(50),
19 request_args varchar(255),
19 server_port smallint unsigned, 20 server_port smallint unsigned,
20 ssl_cipher varchar(25), 21 ssl_cipher varchar(25),
21 ssl_keysize smallint unsigned, 22 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 @@
1/* $Id: mod_log_sql.c,v 1.21 2002/12/10 20:37:28 helios Exp $ */
2 1
3/* --------* 2/* --------*
4 * DEFINES * 3 * DEFINES *
@@ -48,22 +47,23 @@ module sql_log_module;
48 * on a per-virtual-server basis. Every virtual server 'knows' the 47 * on a per-virtual-server basis. Every virtual server 'knows' the
49 * same versions of these variables. 48 * same versions of these variables.
50 */ 49 */
51MYSQL sql_server, *mysql_log = NULL; 50MYSQL logsql_server, *logsql_server_p = NULL;
52 51
53int massvirtual = 0; 52int logsql_massvirtual = 0;
54int create_tables = 0; 53int logsql_createtables = 0;
55int force_preserve = 0; 54int logsql_forcepreserve = 0;
56char *db_name = NULL; 55char *logsql_dbname = NULL;
57char *db_host = NULL; 56char *logsql_dbhost = NULL;
58char *db_user = NULL; 57char *logsql_dbuser = NULL;
59char *db_pwd = NULL; 58char *logsql_dbpwd = NULL;
60char *mach_id = NULL; 59char *logsql_machid = NULL;
61char *socket_file = "/tmp/mysql.sock"; 60char *logsql_socketfile = "/tmp/mysql.sock";
62unsigned int tcp_port = 3306; 61unsigned int logsql_tcpport = 3306;
62
63#ifdef WANT_DELAYED_MYSQL_INSERT 63#ifdef WANT_DELAYED_MYSQL_INSERT
64 char *insert_stmt = "insert delayed into "; 64 char *logsql_insertclause = "insert delayed into ";
65#else 65#else
66 char *insert_stmt = "insert into "; 66 char *logsql_insertclause = "insert into ";
67#endif 67#endif
68 68
69typedef const char *(*item_key_func) (request_rec *, char *); 69typedef const char *(*item_key_func) (request_rec *, char *);
@@ -90,14 +90,14 @@ typedef struct {
90 char *transfer_log_format; 90 char *transfer_log_format;
91 char *preserve_file; 91 char *preserve_file;
92 char *cookie_name; 92 char *cookie_name;
93} log_sql_state; 93} logsql_state;
94 94
95 95
96/* -----------------* 96/* -----------------*
97 * HELPER FUNCTIONS * 97 * HELPER FUNCTIONS *
98 * -----------------*/ 98 * -----------------*/
99 99
100int safe_create_tables(log_sql_state *cls, request_rec *r); 100int safe_create_tables(logsql_state *cls, request_rec *r);
101 101
102static char *format_integer(pool *p, int i) 102static char *format_integer(pool *p, int i)
103{ 103{
@@ -220,6 +220,11 @@ static const char *extract_request_uri(request_rec *r, char *a)
220 return r->uri; 220 return r->uri;
221} 221}
222 222
223static const char *extract_request_args(request_rec *r, char *a)
224{
225 return r->args;
226}
227
223static const char *extract_status(request_rec *r, char *a) 228static const char *extract_status(request_rec *r, char *a)
224{ 229{
225 return pfmt(r->pool, r->status); 230 return pfmt(r->pool, r->status);
@@ -295,10 +300,10 @@ static const char *extract_virtual_host(request_rec *r, char *a)
295 300
296static const char *extract_machine_id(request_rec *r, char *a) 301static const char *extract_machine_id(request_rec *r, char *a)
297{ 302{
298 if (!mach_id) 303 if (!logsql_machid)
299 return "-"; 304 return "-";
300 else 305 else
301 return mach_id; 306 return logsql_machid;
302} 307}
303 308
304static const char *extract_server_port(request_rec *r, char *a) 309static const char *extract_server_port(request_rec *r, char *a)
@@ -349,7 +354,7 @@ static const char *extract_cookie(request_rec *r, char *a)
349 char *isvalid; 354 char *isvalid;
350 char *cookiebuf; 355 char *cookiebuf;
351 356
352 log_sql_state *cls = get_module_config(r->server->module_config, &sql_log_module); 357 logsql_state *cls = get_module_config(r->server->module_config, &sql_log_module);
353 358
354 if (cls->cookie_name != NULL) { 359 if (cls->cookie_name != NULL) {
355 #ifdef DEBUG 360 #ifdef DEBUG
@@ -530,6 +535,7 @@ struct log_sql_item_list {
530 } log_sql_item_keys[] = { 535 } log_sql_item_keys[] = {
531 536
532 { 'A', extract_agent, "agent", 1, 1 }, 537 { 'A', extract_agent, "agent", 1, 1 },
538 { 'a', extract_request_args, "request_args", 1, 1 },
533 { 'b', extract_bytes_sent, "bytes_sent", 0, 0 }, 539 { 'b', extract_bytes_sent, "bytes_sent", 0, 0 },
534 { 'c', extract_cookie, "cookie", 0, 1 }, 540 { 'c', extract_cookie, "cookie", 0, 1 },
535 { 'e', extract_env_var, "env_var", 0, 1 }, 541 { 'e', extract_env_var, "env_var", 0, 1 },
@@ -580,7 +586,7 @@ const char *escape_query(const char *from_str, pool *p)
580 return from_str; 586 return from_str;
581 } 587 }
582 588
583 if (!mysql_log) { 589 if (!logsql_server_p) {
584 /* Well, I would have liked to use the current database charset. mysql is 590 /* Well, I would have liked to use the current database charset. mysql is
585 * unavailable, however, so I fall back to the slightly less respectful 591 * unavailable, however, so I fall back to the slightly less respectful
586 * mysql_escape_string() function that uses the default charset. 592 * mysql_escape_string() function that uses the default charset.
@@ -590,7 +596,7 @@ const char *escape_query(const char *from_str, pool *p)
590 /* MySQL is available, so I'll go ahead and respect the current charset when 596 /* MySQL is available, so I'll go ahead and respect the current charset when
591 * I perform the escape. 597 * I perform the escape.
592 */ 598 */
593 retval = mysql_real_escape_string(mysql_log, to_str, from_str, length); 599 retval = mysql_real_escape_string(logsql_server_p, to_str, from_str, length);
594 } 600 }
595 601
596 if (retval) 602 if (retval)
@@ -609,33 +615,34 @@ int open_logdb_link(server_rec* s)
609 0 if unsuccessful 615 0 if unsuccessful
610 */ 616 */
611 617
612 if (force_preserve) 618 if (logsql_forcepreserve)
613 return 3; 619 return 3;
614 620
615 if (mysql_log) 621 if (logsql_server_p)
616 return 2; 622 return 2;
617 623
618 if (db_name) { 624 if ((logsql_dbname) && (logsql_dbhost) && (logsql_dbuser) && (logsql_dbpwd)) {
619 mysql_init(&sql_server); 625 mysql_init(&logsql_server);
620 mysql_log = mysql_real_connect(&sql_server, db_host, db_user, db_pwd, db_name, tcp_port, socket_file, 0); 626 logsql_server_p = mysql_real_connect(&logsql_server, logsql_dbhost, logsql_dbuser, logsql_dbpwd, logsql_dbname, logsql_tcpport, logsql_socketfile, 0);
621 627
622 if (mysql_log) { 628 if (logsql_server_p) {
623 #ifdef DEBUG 629 #ifdef DEBUG
624 ap_log_error(APLOG_MARK,DEBUGLEVEL,s,"HOST: '%s' PORT: '%d' DB: '%s' USER: '%s' SOCKET: '%s'", 630 ap_log_error(APLOG_MARK,DEBUGLEVEL,s,"HOST: '%s' PORT: '%d' DB: '%s' USER: '%s' SOCKET: '%s'",
625 db_host, tcp_port, db_name, db_user, socket_file); 631 logsql_dbhost, logsql_tcpport, logsql_dbname, logsql_dbuser, logsql_socketfile);
626 #endif 632 #endif
627 return 1; 633 return 1;
628 } else { 634 } else {
629 #ifdef DEBUG 635 #ifdef DEBUG
630 ap_log_error(APLOG_MARK,DEBUGLEVEL,s,"mod_log_sql: database connection error: %s",MYSQL_ERROR(&sql_server)); 636 ap_log_error(APLOG_MARK,DEBUGLEVEL,s,"mod_log_sql: database connection error: %s",MYSQL_ERROR(&logsql_server));
631 ap_log_error(APLOG_MARK,DEBUGLEVEL,s,"HOST: '%s' PORT: '%d' DB: '%s' USER: '%s' SOCKET: '%s'", 637 ap_log_error(APLOG_MARK,DEBUGLEVEL,s,"HOST: '%s' PORT: '%d' DB: '%s' USER: '%s' SOCKET: '%s'",
632 db_host, tcp_port, db_name, db_user, socket_file); 638 logsql_dbhost, logsql_tcpport, logsql_dbname, logsql_dbuser, logsql_socketfile);
633 #endif 639 #endif
634 return 0; 640 return 0;
635 } 641 }
642 } else {
643 ap_log_error(APLOG_MARK,ERRLEVEL,s,"mod_log_sql: insufficient configuration info to establish database link");
644 return 0;
636 } 645 }
637
638 return 0;
639} 646}
640 647
641const char *extract_table(void *data, const char *key, const char *val) 648const 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)
648void preserve_entry(request_rec *r, const char *query) 655void preserve_entry(request_rec *r, const char *query)
649{ 656{
650 FILE *fp; 657 FILE *fp;
651 log_sql_state *cls = get_module_config(r->server->module_config, &sql_log_module); 658 logsql_state *cls = get_module_config(r->server->module_config, &sql_log_module);
652 659
653 fp = pfopen(r->pool, cls->preserve_file, "a"); 660 fp = pfopen(r->pool, cls->preserve_file, "a");
654 if (fp == NULL) 661 if (fp == NULL)
@@ -664,7 +671,7 @@ void preserve_entry(request_rec *r, const char *query)
664 671
665 672
666/*-----------------------------------------------------*/ 673/*-----------------------------------------------------*/
667/* safe_mysql_query: perform a database query with */ 674/* safe_sql_query: perform a database query with */
668/* a degree of safety and error checking. */ 675/* a degree of safety and error checking. */
669/* */ 676/* */
670/* Parms: request record, SQL insert statement */ 677/* Parms: request record, SQL insert statement */
@@ -673,13 +680,13 @@ void preserve_entry(request_rec *r, const char *query)
673/* 2 if insert delayed failed (kluge) */ 680/* 2 if insert delayed failed (kluge) */
674/* the actual MySQL return code on error */ 681/* the actual MySQL return code on error */
675/*-----------------------------------------------------*/ 682/*-----------------------------------------------------*/
676unsigned int safe_mysql_query(request_rec *r, const char *query) 683unsigned int safe_sql_query(request_rec *r, const char *query)
677{ 684{
678 int retval; 685 int retval;
679 struct timespec delay, remainder; 686 struct timespec delay, remainder;
680 int ret; 687 int ret;
681 void (*handler) (int); 688 void (*handler) (int);
682 log_sql_state *cls; 689 logsql_state *cls;
683 unsigned int real_error; 690 unsigned int real_error;
684 #ifdef WANT_DELAYED_MYSQL_INSERT 691 #ifdef WANT_DELAYED_MYSQL_INSERT
685 char *real_error_str; 692 char *real_error_str;
@@ -689,10 +696,10 @@ unsigned int safe_mysql_query(request_rec *r, const char *query)
689 handler = signal(SIGPIPE, SIG_IGN); 696 handler = signal(SIGPIPE, SIG_IGN);
690 697
691 /* First attempt for the query */ 698 /* First attempt for the query */
692 if (!mysql_log) { 699 if (!logsql_server_p) {
693 signal(SIGPIPE, handler); 700 signal(SIGPIPE, handler);
694 return 1; 701 return 1;
695 } else if (!(retval = mysql_query(mysql_log, query))) { 702 } else if (!(retval = mysql_query(logsql_server_p, query))) {
696 signal(SIGPIPE, handler); 703 signal(SIGPIPE, handler);
697 return 0; 704 return 0;
698 } 705 }
@@ -701,9 +708,9 @@ unsigned int safe_mysql_query(request_rec *r, const char *query)
701 * (After all, the module thought it had a valid mysql_log connection but the query 708 * (After all, the module thought it had a valid mysql_log connection but the query
702 * could have failed for a number of reasons, so we have to be extra-safe and check.) */ 709 * could have failed for a number of reasons, so we have to be extra-safe and check.) */
703 #ifdef WANT_DELAYED_MYSQL_INSERT 710 #ifdef WANT_DELAYED_MYSQL_INSERT
704 real_error_str = MYSQL_ERROR(mysql_log); 711 real_error_str = MYSQL_ERROR(logsql_server_p);
705 #else 712 #else
706 real_error = mysql_errno(mysql_log); 713 real_error = mysql_errno(logsql_server_p);
707 #endif 714 #endif
708 715
709 /* Check to see if the error is "nonexistent table" */ 716 /* Check to see if the error is "nonexistent table" */
@@ -712,19 +719,19 @@ unsigned int safe_mysql_query(request_rec *r, const char *query)
712 #else 719 #else
713 if (real_error == ER_NO_SUCH_TABLE) { 720 if (real_error == ER_NO_SUCH_TABLE) {
714 #endif 721 #endif
715 if (create_tables) { 722 if (logsql_createtables) {
716 ap_log_error(APLOG_MARK,ERRLEVEL,r->server,"mod_log_sql: table doesn't exist...creating now"); 723 ap_log_error(APLOG_MARK,ERRLEVEL,r->server,"mod_log_sql: table doesn't exist...creating now");
717 cls = get_module_config(r->server->module_config, &sql_log_module); 724 cls = get_module_config(r->server->module_config, &sql_log_module);
718 if (safe_create_tables(cls, r)) { 725 if (safe_create_tables(cls, r)) {
719 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)); 726 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));
720 preserve_entry(r, query); 727 preserve_entry(r, query);
721 retval = mysql_errno(mysql_log); 728 retval = mysql_errno(logsql_server_p);
722 } else { 729 } else {
723 ap_log_error(APLOG_MARK,ERRLEVEL,r->server,"mod_log_sql: tables successfully created - retrying query"); 730 ap_log_error(APLOG_MARK,ERRLEVEL,r->server,"mod_log_sql: tables successfully created - retrying query");
724 if (mysql_query(mysql_log, query)) { 731 if (mysql_query(logsql_server_p, query)) {
725 ap_log_error(APLOG_MARK,ERRLEVEL,r->server,"mod_log_sql: giving up, preserving query"); 732 ap_log_error(APLOG_MARK,ERRLEVEL,r->server,"mod_log_sql: giving up, preserving query");
726 preserve_entry(r, query); 733 preserve_entry(r, query);
727 retval = mysql_errno(mysql_log); 734 retval = mysql_errno(logsql_server_p);
728 } else 735 } else
729 ap_log_error(APLOG_MARK,ERRLEVEL,r->server,"mod_log_sql: query successful after table creation"); 736 ap_log_error(APLOG_MARK,ERRLEVEL,r->server,"mod_log_sql: query successful after table creation");
730 retval = 0; 737 retval = 0;
@@ -747,14 +754,14 @@ unsigned int safe_mysql_query(request_rec *r, const char *query)
747 #ifdef WANT_DELAYED_MYSQL_INSERT 754 #ifdef WANT_DELAYED_MYSQL_INSERT
748 real_error = 2; 755 real_error = 2;
749 #else 756 #else
750 real_error = mysql_errno(mysql_log); 757 real_error = mysql_errno(logsql_server_p);
751 #endif 758 #endif
752 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)); 759 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));
753 mysql_close(mysql_log); 760 mysql_close(logsql_server_p);
754 mysql_log = NULL; 761 logsql_server_p = NULL;
755 open_logdb_link(r->server); 762 open_logdb_link(r->server);
756 763
757 if (mysql_log == NULL) { /* still unable to link */ 764 if (logsql_server_p == NULL) { /* still unable to link */
758 signal(SIGPIPE, handler); 765 signal(SIGPIPE, handler);
759 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."); 766 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.");
760 ap_log_error(APLOG_MARK,ERRLEVEL,r->server,"mod_log_sql: log entries are being preserved in %s", cls->preserve_file); 767 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)
770 ap_log_error(APLOG_MARK,ERRLEVEL,r->server,"mod_log_sql: nanosleep unsuccessful"); 777 ap_log_error(APLOG_MARK,ERRLEVEL,r->server,"mod_log_sql: nanosleep unsuccessful");
771 778
772 /* Then make our second attempt */ 779 /* Then make our second attempt */
773 retval = mysql_query(mysql_log,query); 780 retval = mysql_query(logsql_server_p,query);
774 781
775 /* If this one also failed, log that and append to our local offline file */ 782 /* If this one also failed, log that and append to our local offline file */
776 if (retval) { 783 if (retval) {
777 #ifdef WANT_DELAYED_MYSQL_INSERT 784 #ifdef WANT_DELAYED_MYSQL_INSERT
778 real_error = 2; 785 real_error = 2;
779 #else 786 #else
780 real_error = mysql_errno(mysql_log); 787 real_error = mysql_errno(logsql_server_p);
781 #endif 788 #endif
782 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)); 789 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));
783 preserve_entry(r, query); 790 preserve_entry(r, query);
784 retval = real_error; 791 retval = real_error;
785 } else 792 } else
@@ -798,7 +805,7 @@ unsigned int safe_mysql_query(request_rec *r, const char *query)
798/* Returns: 0 on no errors */ 805/* Returns: 0 on no errors */
799/* mysql error code on failure */ 806/* mysql error code on failure */
800/*-----------------------------------------------------*/ 807/*-----------------------------------------------------*/
801int safe_create_tables(log_sql_state *cls, request_rec *r) 808int safe_create_tables(logsql_state *cls, request_rec *r)
802{ 809{
803 int retval; 810 int retval;
804 unsigned int create_results; 811 unsigned int create_results;
@@ -827,6 +834,7 @@ int safe_create_tables(log_sql_state *cls, request_rec *r)
827 request_protocol varchar(10),\ 834 request_protocol varchar(10),\
828 request_time char(28),\ 835 request_time char(28),\
829 request_uri varchar(50),\ 836 request_uri varchar(50),\
837 request_args varchar(255),\
830 server_port smallint unsigned,\ 838 server_port smallint unsigned,\
831 ssl_cipher varchar(25),\ 839 ssl_cipher varchar(25),\
832 ssl_keysize smallint unsigned,\ 840 ssl_keysize smallint unsigned,\
@@ -868,27 +876,27 @@ int safe_create_tables(log_sql_state *cls, request_rec *r)
868 /* Assume that things worked unless told otherwise */ 876 /* Assume that things worked unless told otherwise */
869 retval = 0; 877 retval = 0;
870 878
871 if ((create_results = safe_mysql_query(r, create_access))) { 879 if ((create_results = safe_sql_query(r, create_access))) {
872 ap_log_error(APLOG_MARK,ERRLEVEL,r->server,"mod_log_sql: failed to create access table"); 880 ap_log_error(APLOG_MARK,ERRLEVEL,r->server,"mod_log_sql: failed to create access table");
873 retval = create_results; 881 retval = create_results;
874 } 882 }
875 883
876 if ((create_results = safe_mysql_query(r, create_notes))) { 884 if ((create_results = safe_sql_query(r, create_notes))) {
877 ap_log_error(APLOG_MARK,ERRLEVEL,r->server,"mod_log_sql: failed to create notes table"); 885 ap_log_error(APLOG_MARK,ERRLEVEL,r->server,"mod_log_sql: failed to create notes table");
878 retval = create_results; 886 retval = create_results;
879 } 887 }
880 888
881 if ((create_results = safe_mysql_query(r, create_hin))) { 889 if ((create_results = safe_sql_query(r, create_hin))) {
882 ap_log_error(APLOG_MARK,ERRLEVEL,r->server,"mod_log_sql: failed to create header_out table"); 890 ap_log_error(APLOG_MARK,ERRLEVEL,r->server,"mod_log_sql: failed to create header_out table");
883 retval = create_results; 891 retval = create_results;
884 } 892 }
885 893
886 if ((create_results = safe_mysql_query(r, create_hout))) { 894 if ((create_results = safe_sql_query(r, create_hout))) {
887 ap_log_error(APLOG_MARK,ERRLEVEL,r->server,"mod_log_sql: failed to create header_in table"); 895 ap_log_error(APLOG_MARK,ERRLEVEL,r->server,"mod_log_sql: failed to create header_in table");
888 retval = create_results; 896 retval = create_results;
889 } 897 }
890 898
891 if ((create_results = safe_mysql_query(r, create_cookies))) { 899 if ((create_results = safe_sql_query(r, create_cookies))) {
892 ap_log_error(APLOG_MARK,ERRLEVEL,r->server,"mod_log_sql: failed to create cookies table"); 900 ap_log_error(APLOG_MARK,ERRLEVEL,r->server,"mod_log_sql: failed to create cookies table");
893 retval = create_results; 901 retval = create_results;
894 } 902 }
@@ -903,40 +911,40 @@ int safe_create_tables(log_sql_state *cls, request_rec *r)
903 911
904const char *set_log_sql_massvirtual(cmd_parms *parms, void *dummy, int flag) 912const char *set_log_sql_massvirtual(cmd_parms *parms, void *dummy, int flag)
905{ 913{
906 massvirtual = ( flag ? 1 : 0); 914 logsql_massvirtual = ( flag ? 1 : 0);
907 return NULL; 915 return NULL;
908} 916}
909 917
910const char *set_log_sql_force_preserve(cmd_parms *parms, void *dummy, int flag) 918const char *set_log_sql_force_preserve(cmd_parms *parms, void *dummy, int flag)
911{ 919{
912 force_preserve = ( flag ? 1 : 0); 920 logsql_forcepreserve = ( flag ? 1 : 0);
913 return NULL; 921 return NULL;
914} 922}
915 923
916const char *set_log_sql_machine_id(cmd_parms *parms, void *dummy, char *arg) 924const char *set_log_sql_machine_id(cmd_parms *parms, void *dummy, char *arg)
917{ 925{
918 mach_id = arg; 926 logsql_machid = arg;
919 return NULL; 927 return NULL;
920} 928}
921 929
922const char *set_log_sql_create(cmd_parms *parms, void *dummy, int flag) 930const char *set_log_sql_create(cmd_parms *parms, void *dummy, int flag)
923{ 931{
924 if (massvirtual) 932 if (logsql_massvirtual)
925 ap_log_error(APLOG_MARK,WARNINGLEVEL,parms->server,"mod_log_sql: do not set LogSQLCreateTables when LogSQLMassVirtualHosting is On. Ignoring."); 933 ap_log_error(APLOG_MARK,WARNINGLEVEL,parms->server,"mod_log_sql: do not set LogSQLCreateTables when LogSQLMassVirtualHosting is On. Ignoring.");
926 else 934 else
927 create_tables = ( flag ? 1 : 0); 935 logsql_createtables = ( flag ? 1 : 0);
928 return NULL; 936 return NULL;
929} 937}
930 938
931const char *set_log_sql_db(cmd_parms *parms, void *dummy, char *arg) 939const char *set_log_sql_db(cmd_parms *parms, void *dummy, char *arg)
932{ 940{
933 db_name = arg; 941 logsql_dbname = arg;
934 return NULL; 942 return NULL;
935} 943}
936 944
937const char *set_log_sql_cookie(cmd_parms *parms, void *dummy, char *arg) 945const char *set_log_sql_cookie(cmd_parms *parms, void *dummy, char *arg)
938{ 946{
939 log_sql_state *cls = get_module_config(parms->server->module_config, &sql_log_module); 947 logsql_state *cls = get_module_config(parms->server->module_config, &sql_log_module);
940 948
941 cls->cookie_name = arg; 949 cls->cookie_name = arg;
942 return NULL; 950 return NULL;
@@ -945,7 +953,7 @@ const char *set_log_sql_cookie(cmd_parms *parms, void *dummy, char *arg)
945const char *set_log_sql_preserve_file(cmd_parms *parms, void *dummy, char *arg) 953const char *set_log_sql_preserve_file(cmd_parms *parms, void *dummy, char *arg)
946{ 954{
947 /* char *pfile; */ 955 /* char *pfile; */
948 log_sql_state *cls = get_module_config(parms->server->module_config, &sql_log_module); 956 logsql_state *cls = get_module_config(parms->server->module_config, &sql_log_module);
949 957
950 /* pfile = ap_pstrcat(parms->pool, "/tmp/", arg, NULL); */ 958 /* pfile = ap_pstrcat(parms->pool, "/tmp/", arg, NULL); */
951 cls->preserve_file = arg; 959 cls->preserve_file = arg;
@@ -955,22 +963,22 @@ const char *set_log_sql_preserve_file(cmd_parms *parms, void *dummy, char *arg)
955const char *set_log_sql_info(cmd_parms *parms, void *dummy, char *host, char *user, char *pwd) 963const char *set_log_sql_info(cmd_parms *parms, void *dummy, char *host, char *user, char *pwd)
956{ 964{
957 if (*host != '.') { 965 if (*host != '.') {
958 db_host = host; 966 logsql_dbhost = host;
959 } 967 }
960 if (*user != '.') { 968 if (*user != '.') {
961 db_user = user; 969 logsql_dbuser = user;
962 } 970 }
963 if (*pwd != '.') { 971 if (*pwd != '.') {
964 db_pwd = pwd; 972 logsql_dbpwd = pwd;
965 } 973 }
966 return NULL; 974 return NULL;
967} 975}
968 976
969const char *set_log_sql_transfer_table(cmd_parms *parms, void *dummy, char *arg) 977const char *set_log_sql_transfer_table(cmd_parms *parms, void *dummy, char *arg)
970{ 978{
971 log_sql_state *cls = get_module_config(parms->server->module_config, &sql_log_module); 979 logsql_state *cls = get_module_config(parms->server->module_config, &sql_log_module);
972 980
973 if (massvirtual != 0) 981 if (logsql_massvirtual != 0)
974 ap_log_error(APLOG_MARK,WARNINGLEVEL,parms->server,"mod_log_sql: do not set LogSQLTransferLogTable when LogSQLMassVirtualHosting is On. Ignoring."); 982 ap_log_error(APLOG_MARK,WARNINGLEVEL,parms->server,"mod_log_sql: do not set LogSQLTransferLogTable when LogSQLMassVirtualHosting is On. Ignoring.");
975 else 983 else
976 cls->transfer_table_name = arg; 984 cls->transfer_table_name = arg;
@@ -979,9 +987,9 @@ const char *set_log_sql_transfer_table(cmd_parms *parms, void *dummy, char *arg)
979 987
980const char *set_log_sql_cookie_table(cmd_parms *parms, void *dummy, char *arg) 988const char *set_log_sql_cookie_table(cmd_parms *parms, void *dummy, char *arg)
981{ 989{
982 log_sql_state *cls = get_module_config(parms->server->module_config, &sql_log_module); 990 logsql_state *cls = get_module_config(parms->server->module_config, &sql_log_module);
983 991
984 if (massvirtual != 0) 992 if (logsql_massvirtual != 0)
985 ap_log_error(APLOG_MARK,WARNINGLEVEL,parms->server,"mod_log_sql: do not set LogSQLCookieLogTable when LogSQLMassVirtualHosting is On. Ignoring."); 993 ap_log_error(APLOG_MARK,WARNINGLEVEL,parms->server,"mod_log_sql: do not set LogSQLCookieLogTable when LogSQLMassVirtualHosting is On. Ignoring.");
986 else 994 else
987 cls->cookie_table_name = arg; 995 cls->cookie_table_name = arg;
@@ -990,9 +998,9 @@ const char *set_log_sql_cookie_table(cmd_parms *parms, void *dummy, char *arg)
990 998
991const char *set_log_sql_notes_table(cmd_parms *parms, void *dummy, char *arg) 999const char *set_log_sql_notes_table(cmd_parms *parms, void *dummy, char *arg)
992{ 1000{
993 log_sql_state *cls = get_module_config(parms->server->module_config, &sql_log_module); 1001 logsql_state *cls = get_module_config(parms->server->module_config, &sql_log_module);
994 1002
995 if (massvirtual != 0) 1003 if (logsql_massvirtual != 0)
996 ap_log_error(APLOG_MARK,WARNINGLEVEL,parms->server,"mod_log_sql: do not set LogSQLNotesLogTable when LogSQLMassVirtualHosting is On. Ignoring."); 1004 ap_log_error(APLOG_MARK,WARNINGLEVEL,parms->server,"mod_log_sql: do not set LogSQLNotesLogTable when LogSQLMassVirtualHosting is On. Ignoring.");
997 else 1005 else
998 cls->notes_table_name = arg; 1006 cls->notes_table_name = arg;
@@ -1001,9 +1009,9 @@ const char *set_log_sql_notes_table(cmd_parms *parms, void *dummy, char *arg)
1001 1009
1002const char *set_log_sql_hin_table(cmd_parms *parms, void *dummy, char *arg) 1010const char *set_log_sql_hin_table(cmd_parms *parms, void *dummy, char *arg)
1003{ 1011{
1004 log_sql_state *cls = get_module_config(parms->server->module_config, &sql_log_module); 1012 logsql_state *cls = get_module_config(parms->server->module_config, &sql_log_module);
1005 1013
1006 if (massvirtual != 0) 1014 if (logsql_massvirtual != 0)
1007 ap_log_error(APLOG_MARK,WARNINGLEVEL,parms->server,"mod_log_sql: do not set LogSQLHeadersInLogTable when LogSQLMassVirtualHosting is On. Ignoring."); 1015 ap_log_error(APLOG_MARK,WARNINGLEVEL,parms->server,"mod_log_sql: do not set LogSQLHeadersInLogTable when LogSQLMassVirtualHosting is On. Ignoring.");
1008 else 1016 else
1009 cls->hin_table_name = arg; 1017 cls->hin_table_name = arg;
@@ -1012,9 +1020,9 @@ const char *set_log_sql_hin_table(cmd_parms *parms, void *dummy, char *arg)
1012 1020
1013const char *set_log_sql_hout_table(cmd_parms *parms, void *dummy, char *arg) 1021const char *set_log_sql_hout_table(cmd_parms *parms, void *dummy, char *arg)
1014{ 1022{
1015 log_sql_state *cls = get_module_config(parms->server->module_config, &sql_log_module); 1023 logsql_state *cls = get_module_config(parms->server->module_config, &sql_log_module);
1016 1024
1017 if (massvirtual != 0) 1025 if (logsql_massvirtual != 0)
1018 ap_log_error(APLOG_MARK,WARNINGLEVEL,parms->server,"mod_log_sql: do not set LogSQLHeadersOutLogTable when LogSQLMassVirtualHosting is On. Ignoring."); 1026 ap_log_error(APLOG_MARK,WARNINGLEVEL,parms->server,"mod_log_sql: do not set LogSQLHeadersOutLogTable when LogSQLMassVirtualHosting is On. Ignoring.");
1019 else 1027 else
1020 cls->hout_table_name = arg; 1028 cls->hout_table_name = arg;
@@ -1023,7 +1031,7 @@ const char *set_log_sql_hout_table(cmd_parms *parms, void *dummy, char *arg)
1023 1031
1024const char *set_log_sql_transfer_log_format(cmd_parms *parms, void *dummy, char *arg) 1032const char *set_log_sql_transfer_log_format(cmd_parms *parms, void *dummy, char *arg)
1025{ 1033{
1026 log_sql_state *cls = get_module_config(parms->server->module_config, &sql_log_module); 1034 logsql_state *cls = get_module_config(parms->server->module_config, &sql_log_module);
1027 1035
1028 cls->transfer_log_format = arg; 1036 cls->transfer_log_format = arg;
1029 return NULL; 1037 return NULL;
@@ -1031,14 +1039,14 @@ const char *set_log_sql_transfer_log_format(cmd_parms *parms, void *dummy, char
1031 1039
1032const char *set_log_sql_socket_file(cmd_parms *parms, void *dummy, char *arg) 1040const char *set_log_sql_socket_file(cmd_parms *parms, void *dummy, char *arg)
1033{ 1041{
1034 socket_file = arg; 1042 logsql_socketfile = arg;
1035 1043
1036 return NULL; 1044 return NULL;
1037} 1045}
1038 1046
1039const char *set_log_sql_tcp_port(cmd_parms *parms, void *dummy, char *arg) 1047const char *set_log_sql_tcp_port(cmd_parms *parms, void *dummy, char *arg)
1040{ 1048{
1041 tcp_port = (unsigned int)atoi(arg); 1049 logsql_tcpport = (unsigned int)atoi(arg);
1042 1050
1043 return NULL; 1051 return NULL;
1044} 1052}
@@ -1046,7 +1054,7 @@ const char *set_log_sql_tcp_port(cmd_parms *parms, void *dummy, char *arg)
1046const char *add_log_sql_transfer_accept(cmd_parms *parms, void *dummy, char *arg) 1054const char *add_log_sql_transfer_accept(cmd_parms *parms, void *dummy, char *arg)
1047{ 1055{
1048 char **addme; 1056 char **addme;
1049 log_sql_state *cls = get_module_config(parms->server->module_config, &sql_log_module); 1057 logsql_state *cls = get_module_config(parms->server->module_config, &sql_log_module);
1050 1058
1051 addme = push_array(cls->transfer_accept_list); 1059 addme = push_array(cls->transfer_accept_list);
1052 *addme = pstrdup(cls->transfer_accept_list->pool, arg); 1060 *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
1056const char *add_log_sql_transfer_ignore(cmd_parms *parms, void *dummy, char *arg) 1064const char *add_log_sql_transfer_ignore(cmd_parms *parms, void *dummy, char *arg)
1057{ 1065{
1058 char **addme; 1066 char **addme;
1059 log_sql_state *cls = get_module_config(parms->server->module_config, &sql_log_module); 1067 logsql_state *cls = get_module_config(parms->server->module_config, &sql_log_module);
1060 1068
1061 addme = push_array(cls->transfer_ignore_list); 1069 addme = push_array(cls->transfer_ignore_list);
1062 *addme = pstrdup(cls->transfer_ignore_list->pool, arg); 1070 *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
1066const char *add_log_sql_remhost_ignore(cmd_parms *parms, void *dummy, char *arg) 1074const char *add_log_sql_remhost_ignore(cmd_parms *parms, void *dummy, char *arg)
1067{ 1075{
1068 char **addme; 1076 char **addme;
1069 log_sql_state *cls = get_module_config(parms->server->module_config, &sql_log_module); 1077 logsql_state *cls = get_module_config(parms->server->module_config, &sql_log_module);
1070 1078
1071 addme = push_array(cls->remhost_ignore_list); 1079 addme = push_array(cls->remhost_ignore_list);
1072 *addme = pstrdup(cls->remhost_ignore_list->pool, arg); 1080 *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)
1076const char *add_log_sql_note(cmd_parms *parms, void *dummy, char *arg) 1084const char *add_log_sql_note(cmd_parms *parms, void *dummy, char *arg)
1077{ 1085{
1078 char **addme; 1086 char **addme;
1079 log_sql_state *cls = get_module_config(parms->server->module_config, &sql_log_module); 1087 logsql_state *cls = get_module_config(parms->server->module_config, &sql_log_module);
1080 1088
1081 addme = push_array(cls->notes_list); 1089 addme = push_array(cls->notes_list);
1082 *addme = pstrdup(cls->notes_list->pool, arg); 1090 *addme = pstrdup(cls->notes_list->pool, arg);
@@ -1086,7 +1094,7 @@ const char *add_log_sql_note(cmd_parms *parms, void *dummy, char *arg)
1086const char *add_log_sql_hout(cmd_parms *parms, void *dummy, char *arg) 1094const char *add_log_sql_hout(cmd_parms *parms, void *dummy, char *arg)
1087{ 1095{
1088 char **addme; 1096 char **addme;
1089 log_sql_state *cls = get_module_config(parms->server->module_config, &sql_log_module); 1097 logsql_state *cls = get_module_config(parms->server->module_config, &sql_log_module);
1090 1098
1091 addme = push_array(cls->hout_list); 1099 addme = push_array(cls->hout_list);
1092 *addme = pstrdup(cls->hout_list->pool, arg); 1100 *addme = pstrdup(cls->hout_list->pool, arg);
@@ -1096,7 +1104,7 @@ const char *add_log_sql_hout(cmd_parms *parms, void *dummy, char *arg)
1096const char *add_log_sql_hin(cmd_parms *parms, void *dummy, char *arg) 1104const char *add_log_sql_hin(cmd_parms *parms, void *dummy, char *arg)
1097{ 1105{
1098 char **addme; 1106 char **addme;
1099 log_sql_state *cls = get_module_config(parms->server->module_config, &sql_log_module); 1107 logsql_state *cls = get_module_config(parms->server->module_config, &sql_log_module);
1100 1108
1101 addme = push_array(cls->hin_list); 1109 addme = push_array(cls->hin_list);
1102 *addme = pstrdup(cls->hin_list->pool, arg); 1110 *addme = pstrdup(cls->hin_list->pool, arg);
@@ -1106,7 +1114,7 @@ const char *add_log_sql_hin(cmd_parms *parms, void *dummy, char *arg)
1106const char *add_log_sql_cookie(cmd_parms *parms, void *dummy, char *arg) 1114const char *add_log_sql_cookie(cmd_parms *parms, void *dummy, char *arg)
1107{ 1115{
1108 char **addme; 1116 char **addme;
1109 log_sql_state *cls = get_module_config(parms->server->module_config, &sql_log_module); 1117 logsql_state *cls = get_module_config(parms->server->module_config, &sql_log_module);
1110 1118
1111 addme = push_array(cls->cookie_list); 1119 addme = push_array(cls->cookie_list);
1112 *addme = pstrdup(cls->cookie_list->pool, arg); 1120 *addme = pstrdup(cls->cookie_list->pool, arg);
@@ -1135,7 +1143,7 @@ static void log_sql_child_init(server_rec *s, pool *p)
1135 1143
1136 /* Open a link to the database */ 1144 /* Open a link to the database */
1137 retval = open_logdb_link(s); 1145 retval = open_logdb_link(s);
1138 if (retval == 0) 1146 if (!retval)
1139 ap_log_error(APLOG_MARK,ERRLEVEL,s,"mod_log_sql: child spawned but unable to open database link"); 1147 ap_log_error(APLOG_MARK,ERRLEVEL,s,"mod_log_sql: child spawned but unable to open database link");
1140 1148
1141 #ifdef DEBUG 1149 #ifdef DEBUG
@@ -1156,7 +1164,7 @@ static void log_sql_child_init(server_rec *s, pool *p)
1156 */ 1164 */
1157static void log_sql_child_exit(server_rec *s, pool *p) 1165static void log_sql_child_exit(server_rec *s, pool *p)
1158{ 1166{
1159 mysql_close(mysql_log); 1167 mysql_close(logsql_server_p);
1160} 1168}
1161 1169
1162 1170
@@ -1165,7 +1173,7 @@ void *log_sql_initializer(server_rec *main_server, pool *p)
1165{ 1173{
1166 server_rec *s; 1174 server_rec *s;
1167 1175
1168 log_sql_state main_conf = ap_get_module_config(main_server->module_config, &sql_log_module); 1176 logsql_state main_conf = ap_get_module_config(main_server->module_config, &sql_log_module);
1169 1177
1170 for (server_rec *s = main_server; s; s = s->next) { 1178 for (server_rec *s = main_server; s; s = s->next) {
1171 conf = ap_get_module_config(s->module_config, &sql_log_module); 1179 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)
1188void *log_sql_make_state(pool *p, server_rec *s) 1196void *log_sql_make_state(pool *p, server_rec *s)
1189{ 1197{
1190 1198
1191 log_sql_state *cls = (log_sql_state *) ap_palloc(p, sizeof(log_sql_state)); 1199 logsql_state *cls = (logsql_state *) ap_palloc(p, sizeof(logsql_state));
1192 1200
1193 /* These defaults are overridable in the httpd.conf file. */ 1201 /* These defaults are overridable in the httpd.conf file. */
1194 cls->transfer_table_name = NULL; /* No default b/c we want its absence to disable logging */ 1202 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[] = {
1296int log_sql_transaction(request_rec *orig) 1304int log_sql_transaction(request_rec *orig)
1297{ 1305{
1298 char **ptrptr, **ptrptr2; 1306 char **ptrptr, **ptrptr2;
1299 log_sql_state *cls = get_module_config(orig->server->module_config, &sql_log_module); 1307 logsql_state *cls = get_module_config(orig->server->module_config, &sql_log_module);
1300 const char *access_query; 1308 const char *access_query;
1301 request_rec *r; 1309 request_rec *r;
1302 1310
1303 /* We handle mass virtual hosting differently. Dynamically determine the name 1311 /* We handle mass virtual hosting differently. Dynamically determine the name
1304 * of the table from the virtual server's name, and flag it for creation. 1312 * of the table from the virtual server's name, and flag it for creation.
1305 */ 1313 */
1306 if (massvirtual) { 1314 if (logsql_massvirtual) {
1307 char *access_base = "access_"; 1315 char *access_base = "access_";
1308 char *notes_base = "notes_"; 1316 char *notes_base = "notes_";
1309 char *hout_base = "headout_"; 1317 char *hout_base = "headout_";
@@ -1353,11 +1361,12 @@ int log_sql_transaction(request_rec *orig)
1353 cls->hout_table_name = o_tablename; 1361 cls->hout_table_name = o_tablename;
1354 cls->hin_table_name = i_tablename; 1362 cls->hin_table_name = i_tablename;
1355 cls->cookie_table_name = c_tablename; 1363 cls->cookie_table_name = c_tablename;
1356 create_tables = 1; 1364 logsql_createtables = 1;
1357 } 1365 }
1358 1366
1359 /* Do we have enough info to log? */ 1367 /* Do we have enough info to log? */
1360 if ( cls->transfer_table_name == NULL ) { 1368 if (!cls->transfer_table_name) {
1369 ap_log_error(APLOG_MARK,ERRLEVEL,orig->server,"mod_log_sql: configuration info is insufficient to log (hint: LogSQLTransferLogTable)");
1361 return DECLINED; 1370 return DECLINED;
1362 } else { 1371 } else {
1363 const char *thehost; 1372 const char *thehost;
@@ -1476,7 +1485,7 @@ int log_sql_transaction(request_rec *orig)
1476 } 1485 }
1477 } 1486 }
1478 if ( itemsets != "" ) { 1487 if ( itemsets != "" ) {
1479 note_query = ap_pstrcat(r->pool, insert_stmt, "`", cls->notes_table_name, "` (id, item, val) values ", itemsets, NULL); 1488 note_query = ap_pstrcat(r->pool, logsql_insertclause, "`", cls->notes_table_name, "` (id, item, val) values ", itemsets, NULL);
1480 #ifdef DEBUG 1489 #ifdef DEBUG
1481 ap_log_error(APLOG_MARK,DEBUGLEVEL,orig->server,"mod_log_sql: note string: %s", note_query); 1490 ap_log_error(APLOG_MARK,DEBUGLEVEL,orig->server,"mod_log_sql: note string: %s", note_query);
1482 #endif 1491 #endif
@@ -1504,7 +1513,7 @@ int log_sql_transaction(request_rec *orig)
1504 } 1513 }
1505 } 1514 }
1506 if ( itemsets != "" ) { 1515 if ( itemsets != "" ) {
1507 hout_query = ap_pstrcat(r->pool, insert_stmt, "`", cls->hout_table_name, "` (id, item, val) values ", itemsets, NULL); 1516 hout_query = ap_pstrcat(r->pool, logsql_insertclause, "`", cls->hout_table_name, "` (id, item, val) values ", itemsets, NULL);
1508 #ifdef DEBUG 1517 #ifdef DEBUG
1509 ap_log_error(APLOG_MARK,DEBUGLEVEL,orig->server,"mod_log_sql: header_out string: %s", hout_query); 1518 ap_log_error(APLOG_MARK,DEBUGLEVEL,orig->server,"mod_log_sql: header_out string: %s", hout_query);
1510 #endif 1519 #endif
@@ -1533,7 +1542,7 @@ int log_sql_transaction(request_rec *orig)
1533 } 1542 }
1534 } 1543 }
1535 if ( itemsets != "" ) { 1544 if ( itemsets != "" ) {
1536 hin_query = ap_pstrcat(r->pool, insert_stmt, "`", cls->hin_table_name, "` (id, item, val) values ", itemsets, NULL); 1545 hin_query = ap_pstrcat(r->pool, logsql_insertclause, "`", cls->hin_table_name, "` (id, item, val) values ", itemsets, NULL);
1537 #ifdef DEBUG 1546 #ifdef DEBUG
1538 ap_log_error(APLOG_MARK,DEBUGLEVEL,orig->server,"mod_log_sql: header_in string: %s", hin_query); 1547 ap_log_error(APLOG_MARK,DEBUGLEVEL,orig->server,"mod_log_sql: header_in string: %s", hin_query);
1539 #endif 1548 #endif
@@ -1563,7 +1572,7 @@ int log_sql_transaction(request_rec *orig)
1563 1572
1564 } 1573 }
1565 if ( itemsets != "" ) { 1574 if ( itemsets != "" ) {
1566 cookie_query = ap_pstrcat(r->pool, insert_stmt, "`", cls->cookie_table_name, "` (id, item, val) values ", itemsets, NULL); 1575 cookie_query = ap_pstrcat(r->pool, logsql_insertclause, "`", cls->cookie_table_name, "` (id, item, val) values ", itemsets, NULL);
1567 #ifdef DEBUG 1576 #ifdef DEBUG
1568 ap_log_error(APLOG_MARK,DEBUGLEVEL,orig->server,"mod_log_sql: cookie string: %s", cookie_query); 1577 ap_log_error(APLOG_MARK,DEBUGLEVEL,orig->server,"mod_log_sql: cookie string: %s", cookie_query);
1569 #endif 1578 #endif
@@ -1571,7 +1580,7 @@ int log_sql_transaction(request_rec *orig)
1571 1580
1572 1581
1573 /* Set up the actual INSERT statement */ 1582 /* Set up the actual INSERT statement */
1574 access_query = ap_pstrcat(r->pool, insert_stmt, "`", cls->transfer_table_name, "` (", fields, ") values (", values, ")", NULL); 1583 access_query = ap_pstrcat(r->pool, logsql_insertclause, "`", cls->transfer_table_name, "` (", fields, ") values (", values, ")", NULL);
1575 1584
1576 #ifdef DEBUG 1585 #ifdef DEBUG
1577 ap_log_error(APLOG_MARK,DEBUGLEVEL,r->server,"mod_log_sql: access string: %s", access_query); 1586 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)
1580 /* If the person activated force-preserve, go ahead and push all the entries 1589 /* If the person activated force-preserve, go ahead and push all the entries
1581 * into the preserve file, then return. 1590 * into the preserve file, then return.
1582 */ 1591 */
1583 if (force_preserve) { 1592 if (logsql_forcepreserve) {
1584 #ifdef DEBUG 1593 #ifdef DEBUG
1585 ap_log_error(APLOG_MARK,DEBUGLEVEL,orig->server,"mod_log_sql: preservation forced"); 1594 ap_log_error(APLOG_MARK,DEBUGLEVEL,orig->server,"mod_log_sql: preservation forced");
1586 #endif 1595 #endif
@@ -1597,15 +1606,15 @@ int log_sql_transaction(request_rec *orig)
1597 } 1606 }
1598 1607
1599 /* How's our mysql link integrity? */ 1608 /* How's our mysql link integrity? */
1600 if (mysql_log == NULL) { 1609 if (logsql_server_p == NULL) {
1601 1610
1602 /* Make a try to establish the link */ 1611 /* Make a try to establish the link */
1603 open_logdb_link(r->server); 1612 open_logdb_link(r->server);
1604 1613
1605 if (mysql_log == NULL) { 1614 if (logsql_server_p == NULL) {
1606 /* Unable to re-establish a DB link, so assume that it's really 1615 /* Unable to re-establish a DB link, so assume that it's really
1607 * gone and send the entry to the preserve file instead. 1616 * gone and send the entry to the preserve file instead.
1608 * This short-circuits safe_mysql_query() during a db outage and therefore 1617 * This short-circuits safe_sql_query() during a db outage and therefore
1609 * we don't keep logging the db error over and over. 1618 * we don't keep logging the db error over and over.
1610 */ 1619 */
1611 preserve_entry(orig, access_query); 1620 preserve_entry(orig, access_query);
@@ -1630,20 +1639,20 @@ int log_sql_transaction(request_rec *orig)
1630 /* ---> i.e. we have a good MySQL connection. <--- */ 1639 /* ---> i.e. we have a good MySQL connection. <--- */
1631 1640
1632 /* Make the access-table insert */ 1641 /* Make the access-table insert */
1633 safe_mysql_query(orig, access_query); 1642 safe_sql_query(orig, access_query);
1634 1643
1635 /* Log the optional notes, headers, etc. */ 1644 /* Log the optional notes, headers, etc. */
1636 if (note_query) 1645 if (note_query)
1637 safe_mysql_query(orig, note_query); 1646 safe_sql_query(orig, note_query);
1638 1647
1639 if (hout_query) 1648 if (hout_query)
1640 safe_mysql_query(orig, hout_query); 1649 safe_sql_query(orig, hout_query);
1641 1650
1642 if (hin_query) 1651 if (hin_query)
1643 safe_mysql_query(orig, hin_query); 1652 safe_sql_query(orig, hin_query);
1644 1653
1645 if (cookie_query) 1654 if (cookie_query)
1646 safe_mysql_query(orig, cookie_query); 1655 safe_sql_query(orig, cookie_query);
1647 1656
1648 return OK; 1657 return OK;
1649 } 1658 }