summaryrefslogtreecommitdiffstatsabout
diff options
context:
space:
mode:
-rw-r--r--CHANGELOG4
-rw-r--r--Documentation/manual.xml274
-rw-r--r--Makefile.in43
-rw-r--r--mod_log_sql.c234
-rw-r--r--mod_log_sql.h59
-rw-r--r--mod_log_sql_mysql.c33
-rw-r--r--mod_log_sql_ssl.c53
7 files changed, 409 insertions, 291 deletions
diff --git a/CHANGELOG b/CHANGELOG
index 9d5087b..4610c86 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -2,6 +2,10 @@ $Id: CHANGELOG,v 1.18 2004/03/22 20:32:16 urkle Exp $
2?: ? 2?: ?
3* fixed apache.m4 to work with apache 2 setups with different include 3* fixed apache.m4 to work with apache 2 setups with different include
4 directories for APR and APU then core Apache 4 directories for APR and APU then core Apache
5* cleaned up configuration documentation (updated due to deprecated commands)
6* LogSQLLoginInfo updated to support a connection URI
7* new module "registration" macros to clean up new driver modules
8* mysql driver completely separted from core module
5 9
61.96: 2004-03-04 101.96: 2004-03-04
7* fixed LogSQLPreserveFile config parameter 11* fixed LogSQLPreserveFile config parameter
diff --git a/Documentation/manual.xml b/Documentation/manual.xml
index 495b15f..d7dfc12 100644
--- a/Documentation/manual.xml
+++ b/Documentation/manual.xml
@@ -36,6 +36,11 @@
36 </copyright> 36 </copyright>
37 <revhistory> 37 <revhistory>
38 <revision> 38 <revision>
39 <revnumber>1.2</revnumber>
40 <date>2004-04-?</date>
41 <revremark>Updated for mod_log_sql v1.97</revremark>
42 </revision>
43 <revision>
39 <revnumber>1.1</revnumber> 44 <revnumber>1.1</revnumber>
40 <date>2004-03-02</date> 45 <date>2004-03-02</date>
41 <revremark>Updated for mod_log_sql v1.96</revremark> 46 <revremark>Updated for mod_log_sql v1.96</revremark>
@@ -120,50 +125,7 @@
120 </itemizedlist> 125 </itemizedlist>
121 </sect2> 126 </sect2>
122 <sect2> 127 <sect2>
123 <title>Platform Specific Notes</title> 128 <title>Compiling and Installing</title>
124 <remark>This section is currently not applicable as the new autoconf setup should auto-detect everything for your server. The win32 compilation, however, is still on my todo list. This section needs to be overhauled so do not rely completely on any information presented in it. And anyone who compiles the mod_log_sql on these platforms, please report any issues/resolutions to compiling the module.</remark>
125 <para>These installation documents assume a relatively modern GNU/Linux scenario. mod_log_sql has been ported to other platforms; following are notes on compiling the module for those platforms.</para>
126 <sect3 id="Sect.Solaris">
127 <title id="Sect.Solaris.title">Solaris</title>
128 <para>The nanosleep() function used in mod_log_sql relies on linking aginst the librt library. Make the following alterations before proceeding: </para>
129 <orderedlist>
130 <listitem>
131 <para>In Makefile, search for the string "-lmysqlclient -lz" and change it to read "-lmysqlclient -lz -lrt"</para>
132 </listitem>
133 <listitem>
134 <para> In part [step:Linking] of section [sec:Static] below, change "-lmysqlclient -lm -lz" to read "-lmysqlclient -lm -lz -lrt"</para>
135 </listitem>
136 </orderedlist>
137 </sect3>
138 <sect3>
139 <title>BSD</title>
140 <para>No notes are available at present, but they are desired. If you have successfully ported mod_log_sql to BSD, please contact &MaintainerContact; and help fill in this section.</para>
141 </sect3>
142 <sect3>
143 <title>Win32</title>
144 <para>No notes are available at present, but they are desired. If you have successfully ported mod_log_sql to Win32, please contact &MaintainerContact; and help fill in this section.</para>
145 </sect3>
146 <sect3>
147 <title>OS X</title>
148 <para>mod_log_sql should compile and work out-of-the-box on this platform. Here are some notes from a user successfully running the module on OS X:</para>
149 <para>The only changes I had to make were to where I had the various libraries installed. Here are the changes I made to the head of the Makefile: APACHESOURCE = /usr/local/src/apache_1.3.27 (Wasn't sure if this was really needed or not, so I downloaded the Apache source just in case) APACHEINSTALLED = /usr/sbin APACHEHEADERS = /usr/include/httpd APXS = $(APACHEINSTALLED)/apxs MYSQLLIBRARIES = /usr/local/mysql/lib MYSQLHEADERS = /usr/local/mysql/include I'm using a binary installation of MySQL and the default apache installation on OS X Client 10.2.3, the locations of these files may vary depending on how you've installed MySQL and will almost certainly be different if you're using OS X Server.</para>
150 <para> My thanks to Tom Wiebe for being the first (to my knowlege) mod_log_sql user on OS X and for providing these notes.</para>
151 </sect3>
152 <sect3>
153 <title>Digital Unix</title>
154 <para>Digital Unix, like Solaris, needs to be linked against librt; see section <xref endterm="Sect.Solaris.title" linkend="Sect.Solaris"/>. Here are further notes from a user successfully running the module on Digital Unix:</para>
155 <para>Instead of trying to get the module to remember where the MySQL libraries were, I instead compiled apache with the information: LDFLAGS='-rpath /isp/mysql/lib/mysql' ./configure ... Everything worked as expected after that. (The error I got without this was "/sbin/loader: Fatal Error: cannot map libmysqlclient.so" ) Digital Unix (v4.0f, at least ) appears to follow the same requirements needed by Solaris, so simply adding librt to the module made it compile without errors. As for the warnings, here's the text: mod_log_sql.c: In function `extract_request_duration': mod_log_sql.c:292: warning: long int format, different type arg (arg 4) mod_log_sql.c: In function `extract_request_timestamp': mod_log_sql.c:497: warning: long int format, different type arg (arg 4) Poking around in the code, it looks like the compiler was complaining that what time() is returning doesn't play nicely with %ld by default. I just typecast them as (long)'s and the warnings went away ( not that the module wasn't working correctly without them ). The module works very well so far in testing... hasn't dropped a single log entry yet. </para>
156 <para>My thanks to Jim Turner for permitting me to quote him here, and for being the first known user of mod_log_sql on Digital Unix</para>
157 </sect3>
158 </sect2>
159 <sect2>
160 <title>Do I want a DSO or a static module</title>
161 <remark>This section is no longer applicable, as the new autoconf setup only allows DSO with Apache 1.3 and 2.0. This section will be removed shortly.</remark>
162 <para>You need to know the answer to this question before you proceed. The answer is pretty straightforward: what have you done in the past? If you like all your Apache modules to be dynamic, then you should keep doing that. If you're more of an old-school type and prefer to compile the modules right into apache, do that. Both methods work equally well. </para>
163 <para>FWIW, the DSO method is more modern and increasing in popularity because apxs takes care of a lot of dirty little details for you. As you'll see below, the static-module method is a little more complex.</para>
164 </sect2>
165 <sect2>
166 <title>Installation as an Apache DSO (preferred)</title>
167 <orderedlist> 129 <orderedlist>
168 <listitem> 130 <listitem>
169 <para>Unpack the archive into a working directory.</para> 131 <para>Unpack the archive into a working directory.</para>
@@ -233,20 +195,23 @@ $ cd mod_log_sql-1.9</screen>
233 </listitem> 195 </listitem>
234 <listitem> 196 <listitem>
235 <para>Now compile the module with GNU make. You may have to specify gmake on some systems like FreeBSD.</para> 197 <para>Now compile the module with GNU make. You may have to specify gmake on some systems like FreeBSD.</para>
236 <screen>$ make</screen> 198 <screen>$ gmake</screen>
237 </listitem> 199 </listitem>
238 <listitem> 200 <listitem>
239 <para>If there were no errors, you can now install the module(s). If you compiled as a non-root user you may need to switch users with <application>su</application> or <application>sudo</application>.</para> 201 <para>If there were no errors, you can now install the module(s). If you compiled as a non-root user you may need to switch users with <application>su</application> or <application>sudo</application>.</para>
240 <screen>$ su -c "make install" 202 <screen>$ su -c "gmake install"
241Password:</screen> 203Password:</screen>
242 </listitem> 204 </listitem>
243 <listitem> 205 <listitem>
244 <para>Now edit your Apache configuration and load the modules.</para> 206 <para>Now edit your Apache configuration and load the modules.</para>
245 <remark>If you are loading the SSL logging module, you need to make sure it is loaded after mod_ssl and mod_log_sql.</remark> 207 <remark>If you are loading the SSL logging module, you need to make sure it is loaded after mod_ssl and mod_log_sql.</remark>
208 <remark>If you have previously used mod_log_sql version 1.18, the name of the module has changed from sql_log_module to log_sql_module (the first parameter to LoadModule)</remark>
209 <remark>If you are upgrading from any release earlier than 1.97 you need to add an extra LoadModule directive to load the database driver (ie mysql).</remark>
246 <orderedlist> 210 <orderedlist>
247 <listitem> 211 <listitem>
248 <para>Insert these lines to either the main <filename>httpd.conf</filename> or a file included via an include directive.</para> 212 <para>Insert these lines to either the main <filename>httpd.conf</filename> or a file included via an include directive.</para>
249 <programlisting>LoadModule log_sql_module modules/mod_log_sql.so 213 <programlisting>LoadModule log_sql_module modules/mod_log_sql.so
214LoadModule log_sql_mysql_module modules/mod_log_sql_mysql.so
250&lt;IfModule mod_ssl.c&gt; 215&lt;IfModule mod_ssl.c&gt;
251LoadModule log_sql_ssl_module moduels/mod_log_sql_ssl.so 216LoadModule log_sql_ssl_module moduels/mod_log_sql_ssl.so
252&lt;/IfModule&gt;</programlisting> 217&lt;/IfModule&gt;</programlisting>
@@ -255,6 +220,7 @@ LoadModule log_sql_ssl_module moduels/mod_log_sql_ssl.so
255 <listitem> 220 <listitem>
256 <para>If you are using Apache 1.3 you may need add these lines later in the configuration.</para> 221 <para>If you are using Apache 1.3 you may need add these lines later in the configuration.</para>
257 <programlisting>AddModule mod_log_sql.c 222 <programlisting>AddModule mod_log_sql.c
223AddModule mod_log_sql_mysql.c
258&lt;IfModule mod_ssl.c&gt; 224&lt;IfModule mod_ssl.c&gt;
259AddModule mod_log_sql_ssl.c 225AddModule mod_log_sql_ssl.c
260&lt;/IfModule&gt;</programlisting> 226&lt;/IfModule&gt;</programlisting>
@@ -312,14 +278,13 @@ mysql&gt; source create_tables.sql</screen>
312 <para>Use the <application>MySQL</application> 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.</para> 278 <para>Use the <application>MySQL</application> 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.</para>
313 <example> 279 <example>
314 <title>Basic Example</title> 280 <title>Basic Example</title>
315 <programlisting>LogSQLLoginInfo dbmachine.foo.com loguser l0gg3r 281 <programlisting>LogSQLLoginInfo mysql://loguser;l0gg3r@dbmachine.foo.com/apachelogs
316LogSQLDatabase apachelogs
317LogSQLCreateTables on</programlisting> 282LogSQLCreateTables on</programlisting>
318 </example> 283 </example>
319 <para>If your database resides on localhost instead of another host, specify the MySQL server's socket file as follows:</para> 284 <para>If your database resides on localhost instead of another host, specify the MySQL server's socket file as follows:</para>
320 <programlisting>LogSQLSocketFile /your/path/to/mysql.sock</programlisting> 285 <programlisting>LogSQLDBParam socketfile /your/path/to/mysql.sock</programlisting>
321 <para>If your database is listening on a port other than 3306, specify the correct TCP port as follows:</para> 286 <para>If your database is listening on a port other than 3306, specify the correct TCP port as follows:</para>
322 <programlisting>LogSQLTCPPort 1234</programlisting> 287 <programlisting>LogSQLDBParam port 1234</programlisting>
323 </listitem> 288 </listitem>
324 <listitem> 289 <listitem>
325 <para>The actual logging is set up on a virtual-host-by-host basis. So, skip down to the virtual host you want to set up. Instruct this virtual host to log entries to the table "access_log" by inserting a LogSQLTransferLogTable directive. (The LogSQLTransferLogTable directive is the minimum required to log -- other directives that you will learn about later simply tune the module's behavior.)</para> 290 <para>The actual logging is set up on a virtual-host-by-host basis. So, skip down to the virtual host you want to set up. Instruct this virtual host to log entries to the table "access_log" by inserting a LogSQLTransferLogTable directive. (The LogSQLTransferLogTable directive is the minimum required to log -- other directives that you will learn about later simply tune the module's behavior.)</para>
@@ -635,18 +600,55 @@ where a.id=n.id and a.id='PPIDskBRH30AAGPtAsg';</screen>
635 <varlistentry> 600 <varlistentry>
636 <term>LogSQLLoginInfo</term> 601 <term>LogSQLLoginInfo</term>
637 <listitem> 602 <listitem>
638 <cmdsynopsis sepchar=" "> 603 <cmdsynopsis>
639 <command moreinfo="none">LogSQLLoginInfo</command> 604 <command>LogSQLLoginInfo</command>
640 <arg choice="req" rep="norepeat"><replaceable>host</replaceable></arg> 605 <arg choice="req"><replaceable>connection URI</replaceable></arg>
641 <arg choice="req" rep="norepeat"><replaceable>user</replaceable></arg>
642 <arg choice="req" rep="norepeat"><replaceable>password</replaceable></arg>
643 </cmdsynopsis> 606 </cmdsynopsis>
644 <simpara>Example: LogSQLLoginInfo foobar.baz.com logwriter passw0rd</simpara> 607 <simpara>Example: LogSQLLoginInfo mysql://logwriter:passw0rd@foobar.baz.com/Apache_log</simpara>
645 <simpara>Context: main server config</simpara> 608 <simpara>Context: main server config</simpara>
646 <para>Defines the general parameters of the MySQL host to which you will be logging. "host" is the hostname or IP address of the MySQL machine, and is simply "localhost" if the database lives on the same machine as Apache. "user" is the MySQL userid (not a Unix userid!) with INSERT privileges on the table defined in LogSQLTransferLogTable. "password" is that user's password.</para> 609 <para>Defines the basic connection URI to connect to the database with. The format of the connection URI is</para>
610 <simpara>driver://username[:password]@hostname[:port]/database</simpara>
611 <variablelist>
612 <varlistentry>
613 <term>driver</term>
614 <listitem>
615 <simpara>The database driver to use (mysql, pgsql, etc..)</simpara>
616 </listitem>
617 </varlistentry>
618 <varlistentry>
619 <term>username</term>
620 <listitem>
621 <simpara>The database username to login with INSERT privileges on the logging table defined in LogSQLtransferLogTable.</simpara>
622 </listitem>
623 </varlistentry>
624 <varlistentry>
625 <term>password</term>
626 <listitem>
627 <simpara>The password to use for username, and can be omitted if there is no password.</simpara>
628 </listitem>
629 </varlistentry>
630 <varlistentry>
631 <term>hostname</term>
632 <listitem>
633 <simpara>The hostname or Ip address of the Database machine, ans is simple "localhost" if the database lives on the same machine as Apache.</simpara>
634 </listitem>
635 </varlistentry>
636 <varlistentry>
637 <term>port</term>
638 <listitem>
639 <simpara>Port on hostname to connect to the Database, if not specified use the default port for the database.</simpara>
640 </listitem>
641 </varlistentry>
642 <varlistentry>
643 <term>database</term>
644 <listitem>
645 <simpara>The database to connect to on the server.</simpara>
646 </listitem>
647 </varlistentry>
648 </variablelist>
647 <note> 649 <note>
648 <para>This is defined only once in the <filename moreinfo="none">httpd.conf</filename> file.</para> 650 <para>This is defined only once in the <filename moreinfo="none">httpd.conf</filename> file.</para>
649 <para>This directive Must be defined for logging to be enabled. Or the use of LogSQLDBParam</para> 651 <para>This directive Must be defined for logging to be enabled.</para>
650 </note> 652 </note>
651 </listitem> 653 </listitem>
652 </varlistentry> 654 </varlistentry>
@@ -658,12 +660,11 @@ where a.id=n.id and a.id='PPIDskBRH30AAGPtAsg';</screen>
658 <arg choice="req" rep="norepeat"><replaceable>parameter-name</replaceable></arg> 660 <arg choice="req" rep="norepeat"><replaceable>parameter-name</replaceable></arg>
659 <arg choice="req" rep="norepeat"><replaceable>value</replaceable></arg> 661 <arg choice="req" rep="norepeat"><replaceable>value</replaceable></arg>
660 </cmdsynopsis> 662 </cmdsynopsis>
661 <simpara>Example: LogSQLDBParam database loggingdb</simpara> 663 <simpara>Example: LogSQLDBParam socketfile /var/lib/mysql/mysql.socket</simpara>
662 <simpara>Context: main server config</simpara> 664 <simpara>Context: main server config</simpara>
663 <para>This is the new method of specifying Database connection credentials and settings. This can be used to define all Database specific options and allows for a specific database driver to define new configuration attributes without modifying the mod_log_sql core. This is the preferred configuration mechanism.</para> 665 <para>This is the new method of specifying Database connection credentials and settings. This is used to define database driver specific options. For a list of options read the documentation for each specific database driver.</para>
664 <note> 666 <note>
665 <para>Each parameter-name may only be defined once.</para> 667 <para>Each parameter-name may only be defined once.</para>
666 <para>Either this directive defining the minimum of 'database','host','user','passwd' or the use of LogSQlLoginInfo and LogSQLDatabase</para>
667 </note> 668 </note>
668 </listitem> 669 </listitem>
669 </varlistentry> 670 </varlistentry>
@@ -685,60 +686,6 @@ where a.id=n.id and a.id='PPIDskBRH30AAGPtAsg';</screen>
685 </listitem> 686 </listitem>
686 </varlistentry> 687 </varlistentry>
687 <varlistentry> 688 <varlistentry>
688 <term>LogSQLSocketFile [Deprecated]</term>
689 <listitem>
690 <cmdsynopsis sepchar=" ">
691 <command moreinfo="none">LogSQLSocketFile</command>
692 <arg choice="req" rep="norepeat"><replaceable>filename</replaceable></arg>
693 </cmdsynopsis>
694 <simpara>Example: LogSQLSocketFile /tmp/mysql.sock</simpara>
695 <simpara>Default: (database specific)</simpara>
696 <simpara>Default (MySQL): /var/lib/mysql/mysql.sock</simpara>
697 <simpara>Context: main server config</simpara>
698 <para>At Apache runtime you can specify the MySQL socket file to use. Set this once in your main server config to override the default value. This value is irrelevant if your database resides on a separate machine.</para>
699 <para>mod_log_sql will automatically employ the socket for db communications if the database resides on the local host. If the db resides on a separate host the module will automatically use TCP/IP. This is a function of the MySQL API and is not user-configurable.</para>
700 <note>
701 <para>This directive is deprecated in favor of LogSQLDBParam socketfile [socketfilename]</para>
702 <para>This is defined only once in the <filename moreinfo="none">httpd.conf</filename> file.</para>
703 </note>
704 </listitem>
705 </varlistentry>
706 <varlistentry>
707 <term>LogSQLTCPPort [Deprecated]</term>
708 <listitem>
709 <cmdsynopsis sepchar=" ">
710 <command moreinfo="none">LogSQLTCPPort</command>
711 <arg choice="req" rep="norepeat"><replaceable>port-number</replaceable></arg>
712 </cmdsynopsis>
713 <simpara>Example: LogSQLTCPPort 3309</simpara>
714 <simpara>Default: (database specific)</simpara>
715 <simpara>Default (MySQL): 3306</simpara>
716 <simpara>Context: main server config</simpara>
717 <para>Your database may listen on a different port than the default. If so, use this directive to instruct the module which port to use. This directive only applies if the database is on a different machine connected via TCP/IP.</para>
718 <note>
719 <para>This directive is deprecated in favor of LogSQLDBParam tcpport [port-number]</para>
720 <para>This is defined only once in the <filename moreinfo="none">httpd.conf</filename> file.</para>
721 </note>
722 </listitem>
723 </varlistentry>
724 <varlistentry>
725 <term>LogSQLDatabase [Deprecated]</term>
726 <listitem>
727 <cmdsynopsis sepchar=" ">
728 <command moreinfo="none">LogSQLDatabase</command>
729 <arg choice="req" rep="norepeat"><replaceable>database</replaceable></arg>
730 </cmdsynopsis>
731 <simpara>Example: LogSQLDatabase loggingdb</simpara>
732 <simpara>Context: main server config</simpara>
733 <para>Defines the database that is used for logging. "database" must be a valid db on the MySQL host defined in LogSQLLoginInfo</para>
734 <note>
735 <para>This directive is deprecated in favor of LogSQLDBParam database [database-name]</para>
736 <para>This is defined only once in the <filename moreinfo="none">httpd.conf</filename> file.</para>
737 <para>This directive Must be defined for logging to be enabled.</para>
738 </note>
739 </listitem>
740 </varlistentry>
741 <varlistentry>
742 <term>LogSQLForcePreserve</term> 689 <term>LogSQLForcePreserve</term>
743 <listitem> 690 <listitem>
744 <cmdsynopsis sepchar=" "> 691 <cmdsynopsis sepchar=" ">
@@ -801,7 +748,7 @@ where a.id=n.id and a.id='PPIDskBRH30AAGPtAsg';</screen>
801 </cmdsynopsis> 748 </cmdsynopsis>
802 <simpara>Example: LogSQLTransferLogTable access_log_table</simpara> 749 <simpara>Example: LogSQLTransferLogTable access_log_table</simpara>
803 <simpara>Context: virtual host</simpara> 750 <simpara>Context: virtual host</simpara>
804 <para>Defines which table is used for logging of Apache's transfers; this is analogous to Apache's TransferLog directive. table-name must be a valid table within the database defined in LogSQLDatabase.</para> 751 <para>Defines which table is used for logging of Apache's transfers; this is analogous to Apache's TransferLog directive. table-name must be a valid table within the database defined in the LogSQLLoginInfo connection URI.</para>
805 <para>This directive is <emphasis>not</emphasis> necessary if you declare LogSQLMassVirtualHosting On, since that directive activates dynamically-named tables. If you attempt to use LogSqlTransferlogTable at the same time a warning will be logged and it will be ignored, since LogSQLMassVirtualHosting takes priority.</para> 752 <para>This directive is <emphasis>not</emphasis> necessary if you declare LogSQLMassVirtualHosting On, since that directive activates dynamically-named tables. If you attempt to use LogSqlTransferlogTable at the same time a warning will be logged and it will be ignored, since LogSQLMassVirtualHosting takes priority.</para>
806 <note> 753 <note>
807 <para>Requires unless LogSQLMassVirtualHosting is set to On</para> 754 <para>Requires unless LogSQLMassVirtualHosting is set to On</para>
@@ -905,6 +852,20 @@ where a.id=n.id and a.id='PPIDskBRH30AAGPtAsg';</screen>
905 <sect3> 852 <sect3>
906 <title>Configuring What Is logged</title> 853 <title>Configuring What Is logged</title>
907 <variablelist> 854 <variablelist>
855 <varlistentry id="Conf.LogSQLTransferLogFormat">
856 <term>LogSQLTransferLogFormat </term>
857 <listitem>
858 <cmdsynopsis sepchar=" ">
859 <command moreinfo="none">LogSQLTransferLogFormat</command>
860 <arg choice="req" rep="norepeat"><replaceable>format-string</replaceable></arg>
861 </cmdsynopsis>
862 <simpara>Example: LogSQLTransferLogFormat huSUTv</simpara>
863 <simpara>Default: AbHhmRSsTUuv</simpara>
864 <simpara>Context: virtual host</simpara>
865 <para>Each character in the format-string defines an attribute of the request that you wish to log. The default logs the information required to create Combined Log Format logs, plus several extras. Here is the full list of allowable keys, which sometimes resemble their Apache counterparts, but do not always:</para>
866 <para>TODO: Insert Log Format Types Table</para>
867 </listitem>
868 </varlistentry>
908 <varlistentry> 869 <varlistentry>
909 <term>LogSQLRemhostIgnore</term> 870 <term>LogSQLRemhostIgnore</term>
910 <listitem> 871 <listitem>
@@ -915,6 +876,7 @@ where a.id=n.id and a.id='PPIDskBRH30AAGPtAsg';</screen>
915 <simpara>Example: LogSQLRemhostIgnore localnet.com</simpara> 876 <simpara>Example: LogSQLRemhostIgnore localnet.com</simpara>
916 <simpara>Context: virtual host</simpara> 877 <simpara>Context: virtual host</simpara>
917 <para>Lists a series of strings that, if present in the REMOTE_HOST, will cause that request to <emphasis>not</emphasis> be logged. This directive is useful for cutting down on log clutter when you are certain that you want to ignore requests from certain hosts, such as your own internal network machines. See section <xref endterm="Sect.Ignore.title" linkend="Sect.Ignore"/> for some tips for using this directive.</para> 878 <para>Lists a series of strings that, if present in the REMOTE_HOST, will cause that request to <emphasis>not</emphasis> be logged. This directive is useful for cutting down on log clutter when you are certain that you want to ignore requests from certain hosts, such as your own internal network machines. See section <xref endterm="Sect.Ignore.title" linkend="Sect.Ignore"/> for some tips for using this directive.</para>
879 <para>Each string may contain a + or - prefix in a &lt;VirtualHost&gt; context and will cause those strings to be added (+) or removed (-) from the global configuration. Otherwise the global is completely ignored and overridden if defined in a &lt;VirtualHost&gt;</para>
918 <para>Each string is separated by a space, and no regular expressions or globbing are allowed. Each string is evaluated as a substring of the REMOTE_HOST using strstr(). The comparison is case sensitive.</para> 880 <para>Each string is separated by a space, and no regular expressions or globbing are allowed. Each string is evaluated as a substring of the REMOTE_HOST using strstr(). The comparison is case sensitive.</para>
919 </listitem> 881 </listitem>
920 </varlistentry> 882 </varlistentry>
@@ -929,6 +891,7 @@ where a.id=n.id and a.id='PPIDskBRH30AAGPtAsg';</screen>
929 <simpara>Default: if not specified, all requests are 'accepted'</simpara> 891 <simpara>Default: if not specified, all requests are 'accepted'</simpara>
930 <simpara>Context: virtual host</simpara> 892 <simpara>Context: virtual host</simpara>
931 <para>Lists a series of strings that, if present in the URI, will permit that request to be considered for logging (depending on additional filtering by the "ignore" directives). Any request that fails to match one of the LogSQLRequestAccept entries will be discarded.</para> 893 <para>Lists a series of strings that, if present in the URI, will permit that request to be considered for logging (depending on additional filtering by the "ignore" directives). Any request that fails to match one of the LogSQLRequestAccept entries will be discarded.</para>
894 <para>Each string may contain a + or - prefix in a &lt;VirtualHost&gt; context and will cause those strings to be added (+) or removed (-) from the global configuration. Otherwise the global is completely ignored and overridden if defined in a &lt;VirtualHost&gt;</para>
932 <para>This directive is useful for cutting down on log clutter when you are certain that you only want to log certain kinds of requests, and just blanket-ignore everything else. See section <xref endterm="Sect.Ignore.title" linkend="Sect.Ignore"/> for some tips for using this directive.</para> 895 <para>This directive is useful for cutting down on log clutter when you are certain that you only want to log certain kinds of requests, and just blanket-ignore everything else. See section <xref endterm="Sect.Ignore.title" linkend="Sect.Ignore"/> for some tips for using this directive.</para>
933 <para>Each string is separated by a space, and no regular expressions or globbing are allowed. Each string is evaluated as a substring of the URI using strstr(). The comparison is case sensitive.</para> 896 <para>Each string is separated by a space, and no regular expressions or globbing are allowed. Each string is evaluated as a substring of the URI using strstr(). The comparison is case sensitive.</para>
934 <para>This directive is completely optional. It is more general than LogSQLRequestIgnore and is evaluated before LogSQLRequestIgnore . If this directive is not used, <emphasis>all</emphasis> requests are accepted and passed on to the other filtering directives. Therefore, only use this directive if you have a specific reason to do so.</para> 897 <para>This directive is completely optional. It is more general than LogSQLRequestIgnore and is evaluated before LogSQLRequestIgnore . If this directive is not used, <emphasis>all</emphasis> requests are accepted and passed on to the other filtering directives. Therefore, only use this directive if you have a specific reason to do so.</para>
@@ -944,23 +907,10 @@ where a.id=n.id and a.id='PPIDskBRH30AAGPtAsg';</screen>
944 <simpara>Example: LogSQLRequestIgnore root.exe cmd.exe default.ida favicon.ico</simpara> 907 <simpara>Example: LogSQLRequestIgnore root.exe cmd.exe default.ida favicon.ico</simpara>
945 <simpara>Context: virtual host</simpara> 908 <simpara>Context: virtual host</simpara>
946 <para>Lists a series of strings that, if present in the URI, will cause that request to <emphasis>NOT</emphasis> be logged. This directive is useful for cutting down on log clutter when you are certain that you want to ignore requests for certain objects. See section <xref endterm="Sect.Ignore.title" linkend="Sect.Ignore"/> for some tips for using this directive.</para> 909 <para>Lists a series of strings that, if present in the URI, will cause that request to <emphasis>NOT</emphasis> be logged. This directive is useful for cutting down on log clutter when you are certain that you want to ignore requests for certain objects. See section <xref endterm="Sect.Ignore.title" linkend="Sect.Ignore"/> for some tips for using this directive.</para>
910 <para>Each string may contain a + or - prefix in a &lt;VirtualHost&gt; context and will cause those strings to be added (+) or removed (-) from the global configuration. Otherwise the global is completely ignored and overridden if defined in a &lt;VirtualHost&gt;</para>
947 <para>Each string is separated by a space, and no regular expressions or globbing are allowed. Each string is evaluated as a substring of the URI using strstr(). The comparison is case sensitive.</para> 911 <para>Each string is separated by a space, and no regular expressions or globbing are allowed. Each string is evaluated as a substring of the URI using strstr(). The comparison is case sensitive.</para>
948 </listitem> 912 </listitem>
949 </varlistentry> 913 </varlistentry>
950 <varlistentry id="Conf.LogSQLTransferLogFormat">
951 <term>LogSQLTransferLogFormat </term>
952 <listitem>
953 <cmdsynopsis sepchar=" ">
954 <command moreinfo="none">LogSQLTransferLogFormat</command>
955 <arg choice="req" rep="norepeat"><replaceable>format-string</replaceable></arg>
956 </cmdsynopsis>
957 <simpara>Example: LogSQLTransferLogFormat huSUTv</simpara>
958 <simpara>Default: AbHhmRSsTUuv</simpara>
959 <simpara>Context: virtual host</simpara>
960 <para>Each character in the format-string defines an attribute of the request that you wish to log. The default logs the information required to create Combined Log Format logs, plus several extras. Here is the full list of allowable keys, which sometimes resemble their Apache counterparts, but do not always:</para>
961 <para>TODO: Insert Log Format Types Table</para>
962 </listitem>
963 </varlistentry>
964 <varlistentry> 914 <varlistentry>
965 <term>LogSQLWhichCookie</term> 915 <term>LogSQLWhichCookie</term>
966 <listitem> 916 <listitem>
@@ -988,6 +938,7 @@ where a.id=n.id and a.id='PPIDskBRH30AAGPtAsg';</screen>
988 <simpara>Example: logSQLWhichCookies userlogin cookie1 cookie2</simpara> 938 <simpara>Example: logSQLWhichCookies userlogin cookie1 cookie2</simpara>
989 <simpara>Context: virtual host</simpara> 939 <simpara>Context: virtual host</simpara>
990 <para>Defines the list of cookies you would like logged. This works in conjunction with LogSQLCookieLogTable. This directive does <emphasis>not</emphasis> require any additional characters to be added to the LogSQLTransferLogFormat string. The feature is activated simply by including this directive, upon which you will begin populating the separate cookie table with data.</para> 940 <para>Defines the list of cookies you would like logged. This works in conjunction with LogSQLCookieLogTable. This directive does <emphasis>not</emphasis> require any additional characters to be added to the LogSQLTransferLogFormat string. The feature is activated simply by including this directive, upon which you will begin populating the separate cookie table with data.</para>
941 <para>Each string may contain a + or - prefix in a &lt;VirtualHost&gt; context and will cause those strings to be added (+) or removed (-) from the global configuration. Otherwise the global is completely ignored and overridden if defined in a &lt;VirtualHost&gt;</para>
991 <note> 942 <note>
992 <para>The table must be created (see create-tables.sql, included in the package), or LogSQLCreateTables must be set to 'On'.</para> 943 <para>The table must be created (see create-tables.sql, included in the package), or LogSQLCreateTables must be set to 'On'.</para>
993 </note> 944 </note>
@@ -1003,6 +954,7 @@ where a.id=n.id and a.id='PPIDskBRH30AAGPtAsg';</screen>
1003 <simpara>Example: LogSQLWhichHeadersIn UserAgent Accept-Encodeing Host</simpara> 954 <simpara>Example: LogSQLWhichHeadersIn UserAgent Accept-Encodeing Host</simpara>
1004 <simpara>Context: virtual host</simpara> 955 <simpara>Context: virtual host</simpara>
1005 <para>Defines the list of inbound headers you would like logged. This works in conjunction with LogSQLHeadersInLogTable. This directive does not require any additional characters to be added to the LogSQLTransferLogFormat string. The feature is activated simply by including this directive, upon which you will begin populating the separate inbound-headers table with data.</para> 956 <para>Defines the list of inbound headers you would like logged. This works in conjunction with LogSQLHeadersInLogTable. This directive does not require any additional characters to be added to the LogSQLTransferLogFormat string. The feature is activated simply by including this directive, upon which you will begin populating the separate inbound-headers table with data.</para>
957 <para>Each string may contain a + or - prefix in a &lt;VirtualHost&gt; context and will cause those strings to be added (+) or removed (-) from the global configuration. Otherwise the global is completely ignored and overridden if defined in a &lt;VirtualHost&gt;</para>
1006 <note> 958 <note>
1007 <para>The table must be created (see create-tables.sql, included in the package), or LogSQLCreateTables must be set to 'On'.</para> 959 <para>The table must be created (see create-tables.sql, included in the package), or LogSQLCreateTables must be set to 'On'.</para>
1008 </note> 960 </note>
@@ -1018,6 +970,7 @@ where a.id=n.id and a.id='PPIDskBRH30AAGPtAsg';</screen>
1018 <simpara>Example: LogSQLWhichHeadersOut Expires Content-Type Cache-Control</simpara> 970 <simpara>Example: LogSQLWhichHeadersOut Expires Content-Type Cache-Control</simpara>
1019 <simpara>Context: virtual host</simpara> 971 <simpara>Context: virtual host</simpara>
1020 <para>Defines the list of outbound headers you would like logged. This works in conjunction with LogSQLHeadersOutLogTable. This directive does not require any additional characters to be added to the LogSQLTransferLogFormat string. The feature is activated simply by including this directive, upon which you will begin populating the separate outbound-headers table with data.</para> 972 <para>Defines the list of outbound headers you would like logged. This works in conjunction with LogSQLHeadersOutLogTable. This directive does not require any additional characters to be added to the LogSQLTransferLogFormat string. The feature is activated simply by including this directive, upon which you will begin populating the separate outbound-headers table with data.</para>
973 <para>Each string may contain a + or - prefix in a &lt;VirtualHost&gt; context and will cause those strings to be added (+) or removed (-) from the global configuration. Otherwise the global is completely ignored and overridden if defined in a &lt;VirtualHost&gt;</para>
1021 <note> 974 <note>
1022 <para>The table must be created (see create-tables.sql, included in the package), or LogSQLCreateTables must be set to 'On'.</para> 975 <para>The table must be created (see create-tables.sql, included in the package), or LogSQLCreateTables must be set to 'On'.</para>
1023 </note> 976 </note>
@@ -1033,6 +986,7 @@ where a.id=n.id and a.id='PPIDskBRH30AAGPtAsg';</screen>
1033 <simpara>Example: LogSQLWhichNotes mod_gzip_result mod_gzip_ompression_ratio</simpara> 986 <simpara>Example: LogSQLWhichNotes mod_gzip_result mod_gzip_ompression_ratio</simpara>
1034 <simpara>Context: virtual host</simpara> 987 <simpara>Context: virtual host</simpara>
1035 <para>Defines the list of notes you would like logged. This works in conjunction with LogSQLNotesLogTable. This directive does not require any additional characters to be added to the LogSQLTransferLogFormat string. The feature is activated simply by including this directive, upon which you will begin populating the separate notes table with data.</para> 988 <para>Defines the list of notes you would like logged. This works in conjunction with LogSQLNotesLogTable. This directive does not require any additional characters to be added to the LogSQLTransferLogFormat string. The feature is activated simply by including this directive, upon which you will begin populating the separate notes table with data.</para>
989 <para>Each string may contain a + or - prefix in a &lt;VirtualHost&gt; context and will cause those strings to be added (+) or removed (-) from the global configuration. Otherwise the global is completely ignored and overridden if defined in a &lt;VirtualHost&gt;</para>
1036 <note> 990 <note>
1037 <para>The table must be created (see create-tables.sql, included in the package), or LogSQLCreateTables must be set to 'On'.</para> 991 <para>The table must be created (see create-tables.sql, included in the package), or LogSQLCreateTables must be set to 'On'.</para>
1038 </note> 992 </note>
@@ -1040,6 +994,64 @@ where a.id=n.id and a.id='PPIDskBRH30AAGPtAsg';</screen>
1040 </varlistentry> 994 </varlistentry>
1041 </variablelist> 995 </variablelist>
1042 </sect3> 996 </sect3>
997 <sect3>
998 <title>Deprecated Command</title>
999 <variablelist>
1000 <varlistentry>
1001 <term>LogSQLSocketFile [Deprecated]</term>
1002 <listitem>
1003 <cmdsynopsis sepchar=" ">
1004 <command moreinfo="none">LogSQLSocketFile</command>
1005 <arg choice="req" rep="norepeat"><replaceable>filename</replaceable></arg>
1006 </cmdsynopsis>
1007 <simpara>Example: LogSQLSocketFile /tmp/mysql.sock</simpara>
1008 <simpara>Default: (database specific)</simpara>
1009 <simpara>Default (MySQL): /var/lib/mysql/mysql.sock</simpara>
1010 <simpara>Context: main server config</simpara>
1011 <para>At Apache runtime you can specify the MySQL socket file to use. Set this once in your main server config to override the default value. This value is irrelevant if your database resides on a separate machine.</para>
1012 <para>mod_log_sql will automatically employ the socket for db communications if the database resides on the local host. If the db resides on a separate host the module will automatically use TCP/IP. This is a function of the MySQL API and is not user-configurable.</para>
1013 <note>
1014 <para>This directive is deprecated in favor of LogSQLDBParam socketfile [socketfilename]</para>
1015 <para>This is defined only once in the <filename moreinfo="none">httpd.conf</filename> file.</para>
1016 </note>
1017 </listitem>
1018 </varlistentry>
1019 <varlistentry>
1020 <term>LogSQLTCPPort [Deprecated]</term>
1021 <listitem>
1022 <cmdsynopsis sepchar=" ">
1023 <command moreinfo="none">LogSQLTCPPort</command>
1024 <arg choice="req" rep="norepeat"><replaceable>port-number</replaceable></arg>
1025 </cmdsynopsis>
1026 <simpara>Example: LogSQLTCPPort 3309</simpara>
1027 <simpara>Default: (database specific)</simpara>
1028 <simpara>Default (MySQL): 3306</simpara>
1029 <simpara>Context: main server config</simpara>
1030 <para>Your database may listen on a different port than the default. If so, use this directive to instruct the module which port to use. This directive only applies if the database is on a different machine connected via TCP/IP.</para>
1031 <note>
1032 <para>This directive is deprecated in favor of LogSQLDBParam tcpport [port-number]</para>
1033 <para>This is defined only once in the <filename moreinfo="none">httpd.conf</filename> file.</para>
1034 </note>
1035 </listitem>
1036 </varlistentry>
1037 <varlistentry>
1038 <term>LogSQLDatabase [Deprecated]</term>
1039 <listitem>
1040 <cmdsynopsis sepchar=" ">
1041 <command moreinfo="none">LogSQLDatabase</command>
1042 <arg choice="req" rep="norepeat"><replaceable>database</replaceable></arg>
1043 </cmdsynopsis>
1044 <simpara>Example: LogSQLDatabase loggingdb</simpara>
1045 <simpara>Context: main server config</simpara>
1046 <para>Defines the database that is used for logging. "database" must be a valid db on the MySQL host defined in LogSQLLoginInfo</para>
1047 <note>
1048 <para>This directive is deprecated in favor of the URI form of LogSQLLoginInfo.</para>
1049 <para>This is defined only once in the <filename moreinfo="none">httpd.conf</filename> file.</para>
1050 </note>
1051 </listitem>
1052 </varlistentry>
1053 </variablelist>
1054 </sect3>
1043 </sect2> 1055 </sect2>
1044 </sect1> 1056 </sect1>
1045 <sect1> 1057 <sect1>
@@ -1314,7 +1326,7 @@ ErrorLog /var/log/httpd/server-messages </programlisting>
1314 <para>Why do I get the message "insufficient configuration info to establish database link" in my Apache error log?</para> 1326 <para>Why do I get the message "insufficient configuration info to establish database link" in my Apache error log?</para>
1315 </question> 1327 </question>
1316 <answer> 1328 <answer>
1317 <para>At a minimum, LogSQLDatabase and LogSQLLoginInfo and either LogSQLTableName or LogSQLMassVirtualHosting must be defined in order for the module to be able to establish a database link. If these are not defined or are incomplete you will receive this error message.</para> 1329 <para>At a minimum, LogSQLLoginInfo in the URl form and either LogSQLTableName or LogSQLMassVirtualHosting must be defined in order for the module to be able to establish a database link. If these are not defined or are incomplete you will receive this error message.</para>
1318 </answer> 1330 </answer>
1319 </qandaentry> 1331 </qandaentry>
1320 <qandaentry> 1332 <qandaentry>
diff --git a/Makefile.in b/Makefile.in
index 4061629..93acec9 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -2,8 +2,7 @@
2 2
3# Modify these top variables. 3# Modify these top variables.
4SUBDIRS = Documentation contrib 4SUBDIRS = Documentation contrib
5SOURCES = @PACKAGE_NAME@.c \ 5SOURCES = @PACKAGE_NAME@.c
6 @PACKAGE_NAME@_mysql.c
7 6
8HEADERS = mod_log_sql.h \ 7HEADERS = mod_log_sql.h \
9 functions.h \ 8 functions.h \
@@ -14,22 +13,28 @@ HEADERS = mod_log_sql.h \
14 13
15CFLAGS = -Wc,-Wall -Wc,-Werror -Wc,-fno-strict-aliasing 14CFLAGS = -Wc,-Wall -Wc,-Werror -Wc,-fno-strict-aliasing
16 15
17INCLUDES = @MYSQL_CFLAGS@ 16LDADD = @RT_LIBS@
18
19LDADD = @MYSQL_LDFLAGS@ @MYSQL_LIBS@ @RT_LIBS@
20 17
21EXTRA_DIST = AUTHORS INSTALL TODO LICENSE CHANGELOG 18EXTRA_DIST = AUTHORS INSTALL TODO LICENSE CHANGELOG
22 19
23TARGET = @PACKAGE_NAME@@APXS_EXTENSION@ 20TARGET = @PACKAGE_NAME@@APXS_EXTENSION@
24 21
25sslSOURCES = @PACKAGE_NAME@_ssl.c 22sslSOURCES = @PACKAGE_NAME@_ssl.c
26
27sslTARGET = @PACKAGE_NAME@_ssl@APXS_EXTENSION@ 23sslTARGET = @PACKAGE_NAME@_ssl@APXS_EXTENSION@
24sslLDADD =
25sslCFLAGS = @MOD_SSL_CFLAGS@
26sslNAME = log_sql_ssl
27
28mysqlSOURCES = @PACKAGE_NAME@_mysql.c
29mysqlTARGET = @PACKAGE_NAME@_mysql@APXS_EXTENSION@
30mysqlLDADD = @MYSQL_LDFLAGS@ @MYSQL_LIBS@
31mysqlCFLAGS = @MYSQL_CFLAGS@
32mysqlNAME = log_sql_mysql
28 33
29ifeq (@WANT_SSL_MOD@,1) 34ifeq (@WANT_SSL_MOD@,1)
30TARGETS = $(TARGET) $(sslTARGET) 35TARGETS = $(TARGET) $(mysqlTARGET) $(sslTARGET)
31else 36else
32TARGETS = $(TARGET) 37TARGETS = $(TARGET) $(mysqlTARGET)
33endif 38endif
34 39
35#Don't modify anything below here 40#Don't modify anything below here
@@ -39,11 +44,11 @@ PROVIDERS_SUBDIRS = @subdirs@
39srcdir = @abs_srcdir@ 44srcdir = @abs_srcdir@
40builddir = @abs_builddir@ 45builddir = @abs_builddir@
41 46
42OBJ = $(SOURCES:.c=.o) $(sslSOURCES:.c=.o) 47OBJ = $(SOURCES:.c=.o) $(sslSOURCES:.c=.o) $(mysqlSOURCES:.c=.o)
43 48
44LO = $(SOURCES:.c=.lo) $(sslSOURCES:.c=.lo) 49LO = $(SOURCES:.c=.lo) $(sslSOURCES:.c=.lo) $(mysqlSOURCES:.c=.lo)
45 50
46SLO = $(SOURCES:.c=.slo) $(sslSOURCES:.c=.slo) 51SLO = $(SOURCES:.c=.slo) $(sslSOURCES:.c=.slo) $(mysqlSOURCES:.c=.slo)
47 52
48STD_DIST = install-sh \ 53STD_DIST = install-sh \
49 config.sub \ 54 config.sub \
@@ -55,7 +60,8 @@ STD_DIST = install-sh \
55 stamp-h.in \ 60 stamp-h.in \
56 config.h.in 61 config.h.in
57 62
58DISTFILES = $(STD_DIST) $(EXTRA_DIST) $(SOURCES) $(sslSOURCES) $(HEADERS) 63DISTFILES = $(STD_DIST) $(EXTRA_DIST) $(SOURCES) $(sslSOURCES) $(mysqlSOURCES) \
64 $(HEADERS)
59 65
60all: $(TARGETS) all-subdirs 66all: $(TARGETS) all-subdirs
61 67
@@ -78,12 +84,16 @@ TODO: TODO.in
78 @./gen_todo.pl 84 @./gen_todo.pl
79 85
80$(TARGET): $(SOURCES) $(HEADERS) 86$(TARGET): $(SOURCES) $(HEADERS)
81 @@APXS_BIN@ -c -o $(TARGET) $(INCLUDES) $(CFLAGS) \ 87 @@APXS_BIN@ -c -o $(TARGET) $(CFLAGS) \
82 $(LDADD) @DEFS@ @APACHE_DEFS@ $(SOURCES) 88 $(LDADD) @DEFS@ @APACHE_DEFS@ $(SOURCES)
83 89
84$(sslTARGET): $(sslSOURCES) $(HEADERS) 90$(sslTARGET): $(sslSOURCES) $(HEADERS)
85 @@APXS_BIN@ -c -o $(sslTARGET) $(INCLUDES) @MOD_SSL_CFLAGS@ $(CFLAGS) \ 91 @@APXS_BIN@ -c -o $(sslTARGET) $(sslCFLAGS) $(CFLAGS) \
86 @DEFS@ @APACHE_DEFS@ $(sslSOURCES) 92 @DEFS@ @APACHE_DEFS@ $(sslLDADD) $(sslSOURCES)
93
94$(mysqlTARGET): $(mysqlSOURCES) $(HEADERS)
95 @@APXS_BIN@ -c -o $(mysqlTARGET) $(mysqlCFLAGS) $(CFLAGS) \
96 @DEFS@ @APACHE_DEFS@ $(mysqlLDADD) $(mysqlSOURCES)
87 97
88include: 98include:
89 rm -rf include 99 rm -rf include
@@ -91,8 +101,9 @@ include:
91 101
92install: $(TARGETS) install-subdirs 102install: $(TARGETS) install-subdirs
93 @@APXS_BIN@ -i $(TARGET); \ 103 @@APXS_BIN@ -i $(TARGET); \
104 @APXS_BIN@ -n $(mysqlNAME) -i $(mysqlTARGET); \
94 if test @WANT_SSL_MOD@ -eq 1; then \ 105 if test @WANT_SSL_MOD@ -eq 1; then \
95 @APXS_BIN@ -i $(sslTARGET); \ 106 @APXS_BIN@ -n $(sslNAME) -i $(sslTARGET); \
96 fi; \ 107 fi; \
97 echo "*************************************************************************"; \ 108 echo "*************************************************************************"; \
98 echo "*** The mod_log_sql modules have been installed."; \ 109 echo "*** The mod_log_sql modules have been installed."; \
diff --git a/mod_log_sql.c b/mod_log_sql.c
index 3b4e6f4..9309f9a 100644
--- a/mod_log_sql.c
+++ b/mod_log_sql.c
@@ -55,7 +55,9 @@ typedef struct {
55 int createtables; 55 int createtables;
56 int forcepreserve; 56 int forcepreserve;
57 char *machid; 57 char *machid;
58 int announce;
58 logsql_dbconnection db; 59 logsql_dbconnection db;
60 logsql_dbdriver *driver;
59} global_config_t; 61} global_config_t;
60 62
61static global_config_t global_config; 63static global_config_t global_config;
@@ -99,7 +101,7 @@ typedef struct {
99/* list of "handlers" for log types */ 101/* list of "handlers" for log types */
100static apr_array_header_t *logsql_item_list; 102static apr_array_header_t *logsql_item_list;
101 103
102/* Registration Function for extract functions * 104/* Registration function for extract functions *
103 * and update parse cache for transfer_log_format * 105 * and update parse cache for transfer_log_format *
104 * this is exported from the module */ 106 * this is exported from the module */
105LOGSQL_DECLARE(void) log_sql_register_item(server_rec *s, apr_pool_t *p, 107LOGSQL_DECLARE(void) log_sql_register_item(server_rec *s, apr_pool_t *p,
@@ -132,7 +134,14 @@ LOGSQL_DECLARE(void) log_sql_register_item(server_rec *s, apr_pool_t *p,
132 } 134 }
133} 135}
134 136
135/* Include all the extract functions */ 137/* Registration function for database drivers */
138LOGSQL_DECLARE(void) log_sql_register_driver(apr_pool_t *p,
139 logsql_dbdriver *driver)
140{
141 global_config.driver = driver;
142}
143
144/* Include all the core extract functions */
136#include "functions.h" 145#include "functions.h"
137#if defined(WITH_APACHE13) 146#if defined(WITH_APACHE13)
138# include "functions13.h" 147# include "functions13.h"
@@ -156,7 +165,7 @@ static logsql_opendb_ret log_sql_opendb_link(server_rec* s)
156 passwd 165 passwd
157 */ 166 */
158 if (global_config.db.parms) { 167 if (global_config.db.parms) {
159 result = log_sql_mysql_connect(s, &global_config.db); 168 result = global_config.driver->connect(s, &global_config.db);
160 if (result==LOGSQL_OPENDB_FAIL) { 169 if (result==LOGSQL_OPENDB_FAIL) {
161 global_config.db.connected = 0; 170 global_config.db.connected = 0;
162 } else { 171 } else {
@@ -315,25 +324,23 @@ static const char *set_dbparam_slot(cmd_parms *cmd,
315static const char *set_log_sql_info(cmd_parms *cmd, void *dummy, 324static const char *set_log_sql_info(cmd_parms *cmd, void *dummy,
316 const char *host, const char *user, const char *pwd) 325 const char *host, const char *user, const char *pwd)
317{ 326{
318 ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, cmd->server,
319 "%s - %s - %s", host, user, pwd);
320 if (!user) { /* user is null, so only one arg passed */ 327 if (!user) { /* user is null, so only one arg passed */
321 apr_uri_t uri; 328 apr_uri_t uri;
322 apr_uri_parse(cmd->pool, host, &uri); 329 apr_uri_parse(cmd->pool, host, &uri);
323 if (uri.scheme) { 330 if (uri.scheme) {
324 /* set DB plugin */ 331 set_dbparam(cmd, NULL, "driver", uri.scheme);
325 } 332 }
326 if (uri.hostname) { 333 if (uri.hostname) {
327 set_dbparam(cmd, NULL, "host", uri.hostname); 334 set_dbparam(cmd, NULL, "hostname", uri.hostname);
328 } 335 }
329 if (uri.user) { 336 if (uri.user) {
330 set_dbparam(cmd, NULL, "user", uri.user); 337 set_dbparam(cmd, NULL, "username", uri.user);
331 } 338 }
332 if (uri.password) { 339 if (uri.password) {
333 set_dbparam(cmd, NULL, "passwd", uri.password); 340 set_dbparam(cmd, NULL, "password", uri.password);
334 } 341 }
335 if (uri.port_str) { 342 if (uri.port_str) {
336 set_dbparam(cmd, NULL, "tcpport", uri.port_str); 343 set_dbparam(cmd, NULL, "port", uri.port_str);
337 } 344 }
338 if (uri.path) { 345 if (uri.path) {
339 /* extract Database name */ 346 /* extract Database name */
@@ -345,13 +352,13 @@ static const char *set_log_sql_info(cmd_parms *cmd, void *dummy,
345 } 352 }
346 } else { 353 } else {
347 if (*host != '.') { 354 if (*host != '.') {
348 set_dbparam(cmd, NULL, "host", host); 355 set_dbparam(cmd, NULL, "hostname", host);
349 } 356 }
350 if (*user != '.') { 357 if (*user != '.') {
351 set_dbparam(cmd, NULL, "user", user); 358 set_dbparam(cmd, NULL, "username", user);
352 } 359 }
353 if (*pwd != '.') { 360 if (*pwd != '.') {
354 set_dbparam(cmd, NULL, "passwd", pwd); 361 set_dbparam(cmd, NULL, "password", pwd);
355 } 362 }
356 } 363 }
357 return NULL; 364 return NULL;
@@ -380,7 +387,7 @@ static const char *add_server_string_slot(cmd_parms *cmd,
380#if defined(WITH_APACHE20) 387#if defined(WITH_APACHE20)
381static apr_status_t log_sql_close_link(void *data) 388static apr_status_t log_sql_close_link(void *data)
382{ 389{
383 log_sql_mysql_close(&global_config.db); 390 global_config.driver->disconnect(&global_config.db);
384 return APR_SUCCESS; 391 return APR_SUCCESS;
385} 392}
386#elif defined(WITH_APACHE13) 393#elif defined(WITH_APACHE13)
@@ -454,6 +461,10 @@ static void log_sql_module_init(server_rec *s, apr_pool_t *p)
454 log_sql_register_item(s,p,'U', extract_request_uri, "request_uri", 1, 1); 461 log_sql_register_item(s,p,'U', extract_request_uri, "request_uri", 1, 1);
455 log_sql_register_item(s,p,'v', extract_virtual_host, "virtual_host", 0, 1); 462 log_sql_register_item(s,p,'v', extract_virtual_host, "virtual_host", 0, 1);
456 463
464 if (global_config.announce) {
465 ap_add_version_component(p, PACKAGE_NAME"/"PACKAGE_VERSION);
466 }
467
457#if defined(WITH_APACHE20) 468#if defined(WITH_APACHE20)
458 return OK; 469 return OK;
459#endif 470#endif
@@ -478,7 +489,7 @@ static logsql_query_ret safe_sql_insert(request_rec *r, logsql_tabletype table_t
478 return LOGSQL_QUERY_NOLINK; 489 return LOGSQL_QUERY_NOLINK;
479 } 490 }
480 491
481 result = log_sql_mysql_query(r,&global_config.db,query); 492 result = global_config.driver->insert(r,&global_config.db,query);
482 493
483 /* If we ran the query and it returned an error, try to be robust. 494 /* If we ran the query and it returned an error, try to be robust.
484 * (After all, the module thought it had a valid mysql_log connection but the query 495 * (After all, the module thought it had a valid mysql_log connection but the query
@@ -490,7 +501,7 @@ static logsql_query_ret safe_sql_insert(request_rec *r, logsql_tabletype table_t
490 return LOGSQL_QUERY_FAIL; 501 return LOGSQL_QUERY_FAIL;
491 /* TODO: What do we do here */ 502 /* TODO: What do we do here */
492 case LOGSQL_QUERY_FAIL: 503 case LOGSQL_QUERY_FAIL:
493 log_sql_mysql_close(&global_config.db); 504 global_config.driver->disconnect(&global_config.db);
494 global_config.db.connected = 0; 505 global_config.db.connected = 0;
495 /* re-open the connection and try again */ 506 /* re-open the connection and try again */
496 if (log_sql_opendb_link(r->server) != LOGSQL_OPENDB_FAIL) { 507 if (log_sql_opendb_link(r->server) != LOGSQL_OPENDB_FAIL) {
@@ -509,7 +520,7 @@ static logsql_query_ret safe_sql_insert(request_rec *r, logsql_tabletype table_t
509 } 520 }
510 } 521 }
511# endif 522# endif
512 result = log_sql_mysql_query(r,&global_config.db,query); 523 result = global_config.driver->insert(r,&global_config.db,query);
513 if (result == LOGSQL_QUERY_SUCCESS) { 524 if (result == LOGSQL_QUERY_SUCCESS) {
514 return LOGSQL_QUERY_SUCCESS; 525 return LOGSQL_QUERY_SUCCESS;
515 } else { 526 } else {
@@ -530,7 +541,7 @@ static logsql_query_ret safe_sql_insert(request_rec *r, logsql_tabletype table_t
530 if (global_config.createtables) { 541 if (global_config.createtables) {
531 log_error(APLOG_MARK,APLOG_ERR,0,r->server, 542 log_error(APLOG_MARK,APLOG_ERR,0,r->server,
532 "table doesn't exist...creating now"); 543 "table doesn't exist...creating now");
533 if ((result = log_sql_mysql_create(r, &global_config.db, table_type, 544 if ((result = global_config.driver->create_table(r, &global_config.db, table_type,
534 table_name))!=LOGSQL_TABLE_SUCCESS) { 545 table_name))!=LOGSQL_TABLE_SUCCESS) {
535 log_error(APLOG_MARK,APLOG_ERR,result,r->server, 546 log_error(APLOG_MARK,APLOG_ERR,result,r->server,
536 "child attempted but failed to create one or more tables for %s, preserving query", ap_get_server_name(r)); 547 "child attempted but failed to create one or more tables for %s, preserving query", ap_get_server_name(r));
@@ -539,7 +550,7 @@ static logsql_query_ret safe_sql_insert(request_rec *r, logsql_tabletype table_t
539 } else { 550 } else {
540 log_error(APLOG_MARK,APLOG_ERR,result, r->server, 551 log_error(APLOG_MARK,APLOG_ERR,result, r->server,
541 "tables successfully created - retrying query"); 552 "tables successfully created - retrying query");
542 if ((result = log_sql_mysql_query(r,&global_config.db,query))!=LOGSQL_QUERY_SUCCESS) { 553 if ((result = global_config.driver->insert(r,&global_config.db,query))!=LOGSQL_QUERY_SUCCESS) {
543 log_error(APLOG_MARK,APLOG_ERR,result, r->server, 554 log_error(APLOG_MARK,APLOG_ERR,result, r->server,
544 "giving up, preserving query"); 555 "giving up, preserving query");
545 preserve_entry(r, query); 556 preserve_entry(r, query);
@@ -600,20 +611,92 @@ static void *log_sql_make_state(apr_pool_t *p, server_rec *s)
600 return (void *) cls; 611 return (void *) cls;
601} 612}
602 613
614
615/* Iterates through an array of char* and searches for a matching element
616 * Returns 0 if not found, 1 if found */
617static int in_array(apr_array_header_t *ary, const char *elem)
618{
619 int itr;
620 for (itr = 0; itr < ary->nelts; itr++) {
621 if (!strcmp(elem,((char **)ary->elts)[itr])) {
622 return 1;
623 }
624 }
625 return 0;
626}
627
628/* Debugging print */
629#define PRINT_ARRAY(ary) { \
630 char **a_ptr = (char **)(ary->elts); \
631 int a_itr; \
632 fprintf(stderr, "\nPrinting %s\n\n", #ary); \
633 for (a_itr=0; a_itr<ary->nelts; a_itr++) { \
634 fprintf(stderr, "Array Elem: %s\n",a_ptr[a_itr]); \
635 } \
636}
637
638/* Parse through cookie lists and merge based on +/- prefixes */
639#define DO_MERGE_ARRAY(parent,child,pool) \
640if (apr_is_empty_array(child)) { \
641 apr_array_cat(child, parent); \
642} else { \
643 apr_array_header_t *addlist, *dellist; \
644 char **elem, **ptr = (char **)(child->elts); \
645 int itr, overwrite = 0; \
646 addlist = apr_array_make(pool,5,sizeof(char *)); \
647 dellist = apr_array_make(subp,5,sizeof(char *)); \
648\
649 for (itr=0; itr<child->nelts; itr++) { \
650 if (*ptr[itr] == '+') { \
651 elem = (char **)apr_array_push(addlist); \
652 *elem = (ptr[itr]+1); \
653 } else if (*ptr[itr] == '-') { \
654 elem = (char **)apr_array_push(dellist); \
655 *elem = (ptr[itr]+1); \
656 } else { \
657 overwrite = 1; \
658 elem = (char **)apr_array_push(addlist); \
659 *elem = ptr[itr]; \
660 } \
661 } \
662 PRINT_ARRAY(addlist); \
663 PRINT_ARRAY(dellist); \
664 PRINT_ARRAY(parent); \
665 child = apr_array_make(p,1,sizeof(char *)); \
666 ptr = (char **)(parent->elts); \
667 if (overwrite==0) { \
668 /* if we are not overwriting the existing then prepare for merge */ \
669 for (itr=0; itr<parent->nelts; itr++) { \
670 if (!in_array(addlist, ptr[itr]) && !in_array(dellist,ptr[itr])) { \
671 elem = apr_array_push(child); \
672 *elem = apr_pstrdup(p, ptr[itr]); \
673 } \
674 } \
675 } \
676 PRINT_ARRAY(child); \
677 apr_array_cat(child, addlist); \
678 PRINT_ARRAY(child); \
679}
680
603static void *log_sql_merge_state(apr_pool_t *p, void *basev, void *addv) 681static void *log_sql_merge_state(apr_pool_t *p, void *basev, void *addv)
604{ 682{
605 /* Fetch the two states to merge */ 683 /* Fetch the two states to merge */
606 logsql_state *parent = (logsql_state *) basev; 684 logsql_state *parent = (logsql_state *) basev;
607 logsql_state *child = (logsql_state *) addv; 685 logsql_state *child = (logsql_state *) addv;
608 686
687 apr_pool_t *subp;
688
689 apr_pool_create(&subp,p);
690
609 /* Child can override these, otherwise they default to parent's choice. 691 /* Child can override these, otherwise they default to parent's choice.
610 * If the parent didn't set them, create reasonable defaults for the 692 * If the parent didn't set them, create reasonable defaults for the
611 * ones that should have such default settings. Leave the others null. */ 693 * ones that should have such default settings. Leave the others null. */
612 694
613 child->transfer_table_name = child->transfer_table_name ?
614 child->transfer_table_name : parent->transfer_table_name;
615 /* No default for transfer_table_name because we want its absence 695 /* No default for transfer_table_name because we want its absence
616 * to disable logging. */ 696 * to disable logging. */
697 if (!child->transfer_table_name) {
698 child->transfer_table_name = parent->transfer_table_name;
699 }
617 700
618 if (child->transfer_log_format == DEFAULT_TRANSFER_LOG_FMT) { 701 if (child->transfer_log_format == DEFAULT_TRANSFER_LOG_FMT) {
619 child->transfer_log_format = parent->transfer_log_format; 702 child->transfer_log_format = parent->transfer_log_format;
@@ -637,30 +720,20 @@ static void *log_sql_merge_state(apr_pool_t *p, void *basev, void *addv)
637 if (child->cookie_table_name == DEFAULT_COOKIE_TABLE_NAME) 720 if (child->cookie_table_name == DEFAULT_COOKIE_TABLE_NAME)
638 child->cookie_table_name = parent->cookie_table_name; 721 child->cookie_table_name = parent->cookie_table_name;
639 722
640 if (apr_is_empty_array(child->transfer_ignore_list)) 723 DO_MERGE_ARRAY(parent->transfer_ignore_list, child->transfer_ignore_list, subp);
641 apr_array_cat(child->transfer_ignore_list, parent->transfer_ignore_list); 724 DO_MERGE_ARRAY(parent->transfer_accept_list, child->transfer_accept_list, subp);
642 725 DO_MERGE_ARRAY(parent->remhost_ignore_list, child->remhost_ignore_list, subp);
643 if (apr_is_empty_array(child->transfer_accept_list)) 726 DO_MERGE_ARRAY(parent->notes_list, child->notes_list, subp);
644 apr_array_cat(child->transfer_accept_list, parent->transfer_accept_list); 727 DO_MERGE_ARRAY(parent->hin_list, child->hin_list, subp);
645 728 DO_MERGE_ARRAY(parent->hout_list, child->hout_list, subp);
646 if (apr_is_empty_array(child->remhost_ignore_list)) 729 DO_MERGE_ARRAY(parent->cookie_list,child->cookie_list, subp);
647 apr_array_cat(child->remhost_ignore_list, parent->remhost_ignore_list);
648
649 if (apr_is_empty_array(child->notes_list))
650 apr_array_cat(child->notes_list, parent->notes_list);
651
652 if (apr_is_empty_array(child->hin_list))
653 apr_array_cat(child->hin_list, parent->hin_list);
654 730
655 if (apr_is_empty_array(child->hout_list)) 731 apr_pool_destroy(subp);
656 apr_array_cat(child->hout_list, parent->hout_list);
657
658 if (apr_is_empty_array(child->cookie_list))
659 apr_array_cat(child->cookie_list, parent->cookie_list);
660 732
661 if (!child->cookie_name) 733 if (!child->cookie_name)
662 child->cookie_name = parent->cookie_name; 734 child->cookie_name = parent->cookie_name;
663 735
736
664 return (void*) child; 737 return (void*) child;
665} 738}
666 739
@@ -804,7 +877,7 @@ static int log_sql_transaction(request_rec *orig)
804 item->sql_field_name, NULL); 877 item->sql_field_name, NULL);
805 values = apr_pstrcat(r->pool, values, (i ? "," : ""), 878 values = apr_pstrcat(r->pool, values, (i ? "," : ""),
806 (item->string_contents ? "'" : ""), 879 (item->string_contents ? "'" : ""),
807 log_sql_mysql_escape(formatted_item, r->pool,&global_config.db), 880 global_config.driver->escape(formatted_item, r->pool,&global_config.db),
808 (item->string_contents ? "'" : ""), NULL); 881 (item->string_contents ? "'" : ""), NULL);
809 } 882 }
810 883
@@ -821,9 +894,9 @@ static int log_sql_transaction(request_rec *orig)
821 "('", 894 "('",
822 unique_id, 895 unique_id,
823 "','", 896 "','",
824 log_sql_mysql_escape(*ptrptr, r->pool,&global_config.db), 897 global_config.driver->escape(*ptrptr, r->pool,&global_config.db),
825 "','", 898 "','",
826 log_sql_mysql_escape(theitem, r->pool,&global_config.db), 899 global_config.driver->escape(theitem, r->pool,&global_config.db),
827 "')", 900 "')",
828 NULL); 901 NULL);
829 i++; 902 i++;
@@ -849,9 +922,9 @@ static int log_sql_transaction(request_rec *orig)
849 "('", 922 "('",
850 unique_id, 923 unique_id,
851 "','", 924 "','",
852 log_sql_mysql_escape(*ptrptr, r->pool,&global_config.db), 925 global_config.driver->escape(*ptrptr, r->pool,&global_config.db),
853 "','", 926 "','",
854 log_sql_mysql_escape(theitem, r->pool,&global_config.db), 927 global_config.driver->escape(theitem, r->pool,&global_config.db),
855 "')", 928 "')",
856 NULL); 929 NULL);
857 i++; 930 i++;
@@ -878,9 +951,9 @@ static int log_sql_transaction(request_rec *orig)
878 "('", 951 "('",
879 unique_id, 952 unique_id,
880 "','", 953 "','",
881 log_sql_mysql_escape(*ptrptr, r->pool,&global_config.db), 954 global_config.driver->escape(*ptrptr, r->pool,&global_config.db),
882 "','", 955 "','",
883 log_sql_mysql_escape(theitem, r->pool,&global_config.db), 956 global_config.driver->escape(theitem, r->pool,&global_config.db),
884 "')", 957 "')",
885 NULL); 958 NULL);
886 i++; 959 i++;
@@ -907,9 +980,9 @@ static int log_sql_transaction(request_rec *orig)
907 "('", 980 "('",
908 unique_id, 981 unique_id,
909 "','", 982 "','",
910 log_sql_mysql_escape(*ptrptr, r->pool,&global_config.db), 983 global_config.driver->escape(*ptrptr, r->pool,&global_config.db),
911 "','", 984 "','",
912 log_sql_mysql_escape(theitem, r->pool,&global_config.db), 985 global_config.driver->escape(theitem, r->pool,&global_config.db),
913 "')", 986 "')",
914 NULL); 987 NULL);
915 i++; 988 i++;
@@ -1005,7 +1078,34 @@ static int log_sql_transaction(request_rec *orig)
1005 * Structure: command, function called, NULL, where available, how many arguments, verbose description 1078 * Structure: command, function called, NULL, where available, how many arguments, verbose description
1006 */ 1079 */
1007static const command_rec log_sql_cmds[] = { 1080static const command_rec log_sql_cmds[] = {
1081 AP_INIT_FLAG("LogSQLAnnounce", set_global_flag_slot,
1082 (void *)APR_OFFSETOF(global_config_t, announce), RSRC_CONF,
1083 "Whether to announce that mod_log_sql is loaded in the server header")
1084 ,
1085 /* DB connection parameters */
1086 AP_INIT_TAKE13("LogSQLLoginInfo", set_log_sql_info, NULL, RSRC_CONF,
1087 "The database connection URI in the form<br>driver://user:password@hostname:port/database")
1088 ,
1089 AP_INIT_TAKE2("LogSQLDBParam", set_dbparam, NULL, RSRC_CONF,
1090 "First argument is the DB parameter, second is the value to assign")
1091 ,
1092 AP_INIT_FLAG("LogSQLForcePreserve", set_global_flag_slot,
1093 (void *)APR_OFFSETOF(global_config_t, forcepreserve), RSRC_CONF,
1094 "Forces logging to preserve file and bypasses database")
1095 ,
1096 AP_INIT_TAKE1("LogSQLPreserveFile", set_server_string_slot,
1097 (void *)APR_OFFSETOF(logsql_state,preserve_file), RSRC_CONF,
1098 "Name of the file to use for data preservation during database downtime")
1099 ,
1100 AP_INIT_FLAG("LogSQLCreateTables", set_global_nmv_flag_slot,
1101 (void *)APR_OFFSETOF(global_config_t, createtables), RSRC_CONF,
1102 "Turn on module's capability to create its SQL tables on the fly")
1103 ,
1008 /* Table names */ 1104 /* Table names */
1105 AP_INIT_FLAG("LogSQLMassVirtualHosting", set_global_flag_slot,
1106 (void *)APR_OFFSETOF(global_config_t, massvirtual), RSRC_CONF,
1107 "Activates option(s) useful for ISPs performing mass virutal hosting")
1108 ,
1009 AP_INIT_TAKE1("LogSQLTransferLogTable", set_server_nmv_string_slot, 1109 AP_INIT_TAKE1("LogSQLTransferLogTable", set_server_nmv_string_slot,
1010 (void *)APR_OFFSETOF(logsql_state, transfer_table_name), RSRC_CONF, 1110 (void *)APR_OFFSETOF(logsql_state, transfer_table_name), RSRC_CONF,
1011 "The database table that holds the transfer log") 1111 "The database table that holds the transfer log")
@@ -1026,10 +1126,6 @@ static const command_rec log_sql_cmds[] = {
1026 (void *)APR_OFFSETOF(logsql_state, cookie_table_name), RSRC_CONF, 1126 (void *)APR_OFFSETOF(logsql_state, cookie_table_name), RSRC_CONF,
1027 "The database table that holds the cookie info") 1127 "The database table that holds the cookie info")
1028 , 1128 ,
1029 AP_INIT_FLAG("LogSQLMassVirtualHosting", set_global_flag_slot,
1030 (void *)APR_OFFSETOF(global_config_t, massvirtual), RSRC_CONF,
1031 "Activates option(s) useful for ISPs performing mass virutal hosting")
1032 ,
1033 /* Log format */ 1129 /* Log format */
1034 AP_INIT_TAKE1("LogSQLTransferLogFormat", set_logformat_slot, 1130 AP_INIT_TAKE1("LogSQLTransferLogFormat", set_logformat_slot,
1035 NULL, RSRC_CONF, 1131 NULL, RSRC_CONF,
@@ -1053,14 +1149,11 @@ static const command_rec log_sql_cmds[] = {
1053 (void *)APR_OFFSETOF(logsql_state, remhost_ignore_list), RSRC_CONF, 1149 (void *)APR_OFFSETOF(logsql_state, remhost_ignore_list), RSRC_CONF,
1054 "List of remote hosts to ignore. Accesses that match will not be logged to database") 1150 "List of remote hosts to ignore. Accesses that match will not be logged to database")
1055 , 1151 ,
1152 /* Special loggin table configuration */
1056 AP_INIT_TAKE1("LogSQLWhichCookie", set_server_string_slot, 1153 AP_INIT_TAKE1("LogSQLWhichCookie", set_server_string_slot,
1057 (void *)APR_OFFSETOF(logsql_state, cookie_name), RSRC_CONF, 1154 (void *)APR_OFFSETOF(logsql_state, cookie_name), RSRC_CONF,
1058 "The single cookie that you want logged in the access_log when using the 'c' config directive") 1155 "The single cookie that you want logged in the access_log when using the 'c' config directive")
1059 , 1156 ,
1060 AP_INIT_TAKE1("LogSQLPreserveFile", set_server_string_slot,
1061 (void *)APR_OFFSETOF(logsql_state,preserve_file), RSRC_CONF,
1062 "Name of the file to use for data preservation during database downtime")
1063 ,
1064 AP_INIT_ITERATE("LogSQLWhichNotes", add_server_string_slot, 1157 AP_INIT_ITERATE("LogSQLWhichNotes", add_server_string_slot,
1065 (void *)APR_OFFSETOF(logsql_state, notes_list), RSRC_CONF, 1158 (void *)APR_OFFSETOF(logsql_state, notes_list), RSRC_CONF,
1066 "Notes that you would like to log in a separate table") 1159 "Notes that you would like to log in a separate table")
@@ -1077,36 +1170,25 @@ static const command_rec log_sql_cmds[] = {
1077 (void *)APR_OFFSETOF(logsql_state, cookie_list), RSRC_CONF, 1170 (void *)APR_OFFSETOF(logsql_state, cookie_list), RSRC_CONF,
1078 "The cookie(s) that you would like to log in a separate table") 1171 "The cookie(s) that you would like to log in a separate table")
1079 , 1172 ,
1080 /* DB connection parameters */ 1173 AP_INIT_RAW_ARGS("LogSQLDeprecated", ap_set_deprecated, NULL, RSRC_CONF,
1081 AP_INIT_FLAG("LogSQLForcePreserve", set_global_flag_slot, 1174 "<br><b>Deprecated</b><br>The following Commands are deprecated and should not be used.. <br>Read the documentation for more information<br><b>Deprecated</b>")
1082 (void *)APR_OFFSETOF(global_config_t, forcepreserve), RSRC_CONF,
1083 "Forces logging to preserve file and bypasses database")
1084 ,
1085 AP_INIT_FLAG("LogSQLCreateTables", set_global_nmv_flag_slot,
1086 (void *)APR_OFFSETOF(global_config_t, createtables), RSRC_CONF,
1087 "Turn on module's capability to create its SQL tables on the fly")
1088 ,
1089 AP_INIT_TAKE13("LogSQLLoginInfo", set_log_sql_info, NULL, RSRC_CONF,
1090 "The database host, user-id and password for logging")
1091 ,
1092 AP_INIT_TAKE2("LogSQLDBParam", set_dbparam, NULL, RSRC_CONF,
1093 "First argument is the DB parameter, second is the value to assign")
1094 , 1175 ,
1176 /* Deprecated commands */
1095 AP_INIT_TAKE1("LogSQLDatabase", set_dbparam_slot, 1177 AP_INIT_TAKE1("LogSQLDatabase", set_dbparam_slot,
1096 (void *)"database", RSRC_CONF, 1178 (void *)"database", RSRC_CONF,
1097 "The name of the database database for logging") 1179 "<b>(Deprecated) Use LogSQLDBParam database dbname.</b> The name of the database database for logging")
1098 , 1180 ,
1099 AP_INIT_TAKE1("LogSQLTableType", set_dbparam_slot, 1181 AP_INIT_TAKE1("LogSQLTableType", set_dbparam_slot,
1100 (void *)"tabletype", RSRC_CONF, 1182 (void *)"tabletype", RSRC_CONF,
1101 "What kind of table to create (MyISAM, InnoDB,...) when creating tables") 1183 "<b>(Deprecated) Use LogSQLDBParam tabletype type.</b> What kind of table to create (MyISAM, InnoDB,...) when creating tables")
1102 , 1184 ,
1103 AP_INIT_TAKE1("LogSQLSocketFile", set_dbparam_slot, 1185 AP_INIT_TAKE1("LogSQLSocketFile", set_dbparam_slot,
1104 (void *)"socketfile", RSRC_CONF, 1186 (void *)"socketfile", RSRC_CONF,
1105 "Name of the file to employ for socket connections to database") 1187 "<b>(Deprecated) Use LogSQLDBParam socketfile socket.</b> Name of the file to employ for socket connections to database")
1106 , 1188 ,
1107 AP_INIT_TAKE1("LogSQLTCPPort", set_dbparam_slot, 1189 AP_INIT_TAKE1("LogSQLTCPPort", set_dbparam_slot,
1108 (void *)"tcpport", RSRC_CONF, 1190 (void *)"port", RSRC_CONF,
1109 "Port number to use for TCP connections to database, defaults to 3306 if not set") 1191 "<b>(Deprecated) Use LogSQLDBParam port port.</b> Port number to use for TCP connections to database, defaults to 3306 if not set")
1110 , 1192 ,
1111 {NULL} 1193 {NULL}
1112}; 1194};
diff --git a/mod_log_sql.h b/mod_log_sql.h
index 1eed9b4..032bd01 100644
--- a/mod_log_sql.h
+++ b/mod_log_sql.h
@@ -24,9 +24,10 @@
24#define LOGSQL_DECLARE_DATA __declspec(dllimport) 24#define LOGSQL_DECLARE_DATA __declspec(dllimport)
25#endif 25#endif
26 26
27/* Registration function for extract functions */
28
27typedef const char *logsql_item_func(request_rec *r, char *a); 29typedef const char *logsql_item_func(request_rec *r, char *a);
28 30
29/* Registration Function for extract functions */
30LOGSQL_DECLARE(void) log_sql_register_item(server_rec *s, apr_pool_t *p, 31LOGSQL_DECLARE(void) log_sql_register_item(server_rec *s, apr_pool_t *p,
31 char key, logsql_item_func *func, const char *sql_field_name, 32 char key, logsql_item_func *func, const char *sql_field_name,
32 int want_orig_default, int string_contents); 33 int want_orig_default, int string_contents);
@@ -73,14 +74,54 @@ typedef enum {
73 LOGSQL_TABLE_HEADERSIN | LOGSQL_TABLE_HEADERSOUT | LOGSQL_TABLE_COOKIES 74 LOGSQL_TABLE_HEADERSIN | LOGSQL_TABLE_HEADERSOUT | LOGSQL_TABLE_COOKIES
74 75
75/* MySQL module calls */ 76/* MySQL module calls */
76logsql_opendb_ret log_sql_mysql_connect(server_rec *s, logsql_dbconnection *db);
77void log_sql_mysql_close(logsql_dbconnection *db);
78const char *log_sql_mysql_escape(const char *from_str, apr_pool_t *p,
79 logsql_dbconnection *db);
80logsql_query_ret log_sql_mysql_query(request_rec *r,logsql_dbconnection *db,
81 const char *query);
82logsql_table_ret log_sql_mysql_create(request_rec *r, logsql_dbconnection *db,
83 logsql_tabletype table_type, const char *table_name);
84 77
78/* Registration function for database drivers */
79
80typedef struct {
81 /* NULL terminated list of drivers strings */
82 char **provided_drivers;
83 /* create a connection to the underlying database layer */
84 logsql_opendb_ret (*connect)(server_rec *s, logsql_dbconnection *db);
85 /* disconnect from the underlying database layer */
86 void (*disconnect)(logsql_dbconnection *db);
87 /* escape the SQL statement according to database rules */
88 const char *(*escape)(const char *from_str, apr_pool_t *p,
89 logsql_dbconnection *db);
90 /* insert a SQL query statement */
91 logsql_query_ret (*insert)(request_rec *r,logsql_dbconnection *db,
92 const char *query);
93 /* create a SQL table named table_name of table_type */
94 logsql_table_ret (*create_table)(request_rec *r, logsql_dbconnection *db,
95 logsql_tabletype table_type, const char *table_name);
96} logsql_dbdriver;
97
98LOGSQL_DECLARE(void) log_sql_register_driver(apr_pool_t *p,
99 logsql_dbdriver *driver);
100
101/* Module initialization Macros */
102#if defined(WITH_APACHE20)
103# define LOGSQL_REGISTER(driver) \
104 static int post_config(apr_pool_t *p, apr_pool_t *plog, apr_pool_t *ptemp, server_rec *s); \
105 static void register_hooks(apr_pool_t *p) { \
106 ap_hook_post_config(post_config, NULL, NULL, APR_HOOK_REALLY_FIRST); \
107 } \
108 \
109 module AP_MODULE_DECLARE_DATA log_sql_##driver##_module = { \
110 STANDARD20_MODULE_STUFF, \
111 NULL, NULL, NULL, NULL, NULL, register_hooks }; \
112 static int post_config(apr_pool_t *p, apr_pool_t *plog, apr_pool_t *ptemp, server_rec *s)
113#elif defined(WITH_APACHE13)
114# define LOGSQL_REGISTER() \
115 static void module_init(server_rec *s, apr_pool_t *p); \
116 module log_sql_##driver##_module = { \
117 STANDARD_MODULE_STUFF, module_init };
118 static void module_init(server_rec *s, apr_pool_t *p)
119#endif
120
121#if defined(WITH_APACHE20)
122#define LOGSQL_REGISTER_RETURN return OK;
123#elif defined(WITH_APACHE13)
124#define LOGSQL_REGISTER_RETURN
125#endif
85 126
86#endif /* MOD_LOG_SQL_H */ 127#endif /* MOD_LOG_SQL_H */
diff --git a/mod_log_sql_mysql.c b/mod_log_sql_mysql.c
index a3f8bbc..5a654f3 100644
--- a/mod_log_sql_mysql.c
+++ b/mod_log_sql_mysql.c
@@ -29,13 +29,13 @@
29#define MYSQL_ERROR(mysql) ((mysql)?(mysql_error(mysql)):"MySQL server has gone away") 29#define MYSQL_ERROR(mysql) ((mysql)?(mysql_error(mysql)):"MySQL server has gone away")
30 30
31/* Connect to the MYSQL database */ 31/* Connect to the MYSQL database */
32logsql_opendb_ret log_sql_mysql_connect(server_rec *s, logsql_dbconnection *db) 32static logsql_opendb_ret log_sql_mysql_connect(server_rec *s, logsql_dbconnection *db)
33{ 33{
34 const char *host = apr_table_get(db->parms,"host"); 34 const char *host = apr_table_get(db->parms,"hostname");
35 const char *user = apr_table_get(db->parms,"user"); 35 const char *user = apr_table_get(db->parms,"username");
36 const char *passwd = apr_table_get(db->parms,"passwd"); 36 const char *passwd = apr_table_get(db->parms,"password");
37 const char *database = apr_table_get(db->parms,"database"); 37 const char *database = apr_table_get(db->parms,"database");
38 const char *s_tcpport = apr_table_get(db->parms,"tcpport"); 38 const char *s_tcpport = apr_table_get(db->parms,"port");
39 unsigned int tcpport = (s_tcpport)?atoi(s_tcpport):3306; 39 unsigned int tcpport = (s_tcpport)?atoi(s_tcpport):3306;
40 const char *socketfile = apr_table_get(db->parms,"socketfile"); 40 const char *socketfile = apr_table_get(db->parms,"socketfile");
41 MYSQL *dblink = db->handle; 41 MYSQL *dblink = db->handle;
@@ -63,7 +63,7 @@ logsql_opendb_ret log_sql_mysql_connect(server_rec *s, logsql_dbconnection *db)
63} 63}
64 64
65/* Close the DB link */ 65/* Close the DB link */
66void log_sql_mysql_close(logsql_dbconnection *db) 66static void log_sql_mysql_close(logsql_dbconnection *db)
67{ 67{
68 mysql_close((MYSQL *)db->handle); 68 mysql_close((MYSQL *)db->handle);
69} 69}
@@ -71,7 +71,7 @@ void log_sql_mysql_close(logsql_dbconnection *db)
71/* Routine to escape the 'dangerous' characters that would otherwise 71/* Routine to escape the 'dangerous' characters that would otherwise
72 * corrupt the INSERT string: ', \, and " 72 * corrupt the INSERT string: ', \, and "
73 */ 73 */
74const char *log_sql_mysql_escape(const char *from_str, apr_pool_t *p, 74static const char *log_sql_mysql_escape(const char *from_str, apr_pool_t *p,
75 logsql_dbconnection *db) 75 logsql_dbconnection *db)
76{ 76{
77 if (!from_str) 77 if (!from_str)
@@ -110,7 +110,7 @@ const char *log_sql_mysql_escape(const char *from_str, apr_pool_t *p,
110} 110}
111 111
112/* Run a mysql insert query and return a categorized error or success */ 112/* Run a mysql insert query and return a categorized error or success */
113logsql_query_ret log_sql_mysql_query(request_rec *r,logsql_dbconnection *db, 113static logsql_query_ret log_sql_mysql_query(request_rec *r,logsql_dbconnection *db,
114 const char *query) 114 const char *query)
115{ 115{
116 int retval; 116 int retval;
@@ -147,7 +147,7 @@ logsql_query_ret log_sql_mysql_query(request_rec *r,logsql_dbconnection *db,
147} 147}
148 148
149/* Create table table_name of type table_type. */ 149/* Create table table_name of type table_type. */
150logsql_table_ret log_sql_mysql_create(request_rec *r, logsql_dbconnection *db, 150static logsql_table_ret log_sql_mysql_create(request_rec *r, logsql_dbconnection *db,
151 logsql_tabletype table_type, const char *table_name) 151 logsql_tabletype table_type, const char *table_name)
152{ 152{
153 int retval; 153 int retval;
@@ -231,3 +231,18 @@ logsql_table_ret log_sql_mysql_create(request_rec *r, logsql_dbconnection *db,
231 signal(SIGPIPE, handler); 231 signal(SIGPIPE, handler);
232 return LOGSQL_TABLE_SUCCESS; 232 return LOGSQL_TABLE_SUCCESS;
233} 233}
234
235static char *supported_drivers[] = {"mysql",NULL};
236static logsql_dbdriver mysql_driver = {
237 supported_drivers,
238 log_sql_mysql_connect, /* open DB connection */
239 log_sql_mysql_close, /* close DB connection */
240 log_sql_mysql_escape, /* escape query */
241 log_sql_mysql_query, /* insert query */
242 log_sql_mysql_create /* create table */
243};
244
245LOGSQL_REGISTER(mysql) {
246 log_sql_register_driver(p,&mysql_driver);
247 LOGSQL_REGISTER_RETURN;
248}
diff --git a/mod_log_sql_ssl.c b/mod_log_sql_ssl.c
index 5f3a16e..ca4ced7 100644
--- a/mod_log_sql_ssl.c
+++ b/mod_log_sql_ssl.c
@@ -76,58 +76,11 @@ static const char *extract_ssl_cipher(request_rec *r, char *a)
76 } 76 }
77} 77}
78 78
79#if defined(WITH_APACHE20) 79
80static int post_config(apr_pool_t *p, apr_pool_t *plog, apr_pool_t *ptemp, server_rec *s) 80LOGSQL_REGISTER(ssl)
81#elif defined(WITH_APACHE13)
82static void module_init(server_rec *s, apr_pool_t *p)
83#endif
84{ 81{
85 log_sql_register_item(s,p,'q', extract_ssl_keysize, "ssl_keysize", 0, 1); 82 log_sql_register_item(s,p,'q', extract_ssl_keysize, "ssl_keysize", 0, 1);
86 log_sql_register_item(s,p,'Q', extract_ssl_maxkeysize, "ssl_maxkeysize", 0, 1); 83 log_sql_register_item(s,p,'Q', extract_ssl_maxkeysize, "ssl_maxkeysize", 0, 1);
87 log_sql_register_item(s,p,'z', extract_ssl_cipher, "ssl_cipher", 0, 1); 84 log_sql_register_item(s,p,'z', extract_ssl_cipher, "ssl_cipher", 0, 1);
88#if defined(WITH_APACHE20) 85 LOGSQL_REGISTER_RETURN;
89 return OK;
90#endif
91}
92
93/* The configuration array that sets up the hooks into the module. */
94#if defined(WITH_APACHE20)
95static void register_hooks(apr_pool_t *p) {
96 ap_hook_post_config(post_config, NULL, NULL, APR_HOOK_REALLY_FIRST);
97} 86}
98
99module AP_MODULE_DECLARE_DATA log_sql_ssl_module = {
100 STANDARD20_MODULE_STUFF,
101 NULL, /* create per-directory config structures */
102 NULL, /* merge per-directory config structures */
103 NULL, /* create per-server config structures */
104 NULL, /* merge per-server config structures */
105 NULL, /* command handlers */
106 register_hooks /* register hooks */
107};
108#elif defined(WITH_APACHE13)
109module log_sql_ssl_module = {
110 STANDARD_MODULE_STUFF,
111 module_init, /* module initializer */
112 NULL, /* create per-dir config */
113 NULL, /* merge per-dir config */
114 NULL, /* create server config */
115 NULL, /* merge server config */
116 NULL, /* config directive table */
117 NULL, /* [9] content handlers */
118 NULL, /* [2] URI-to-filename translation */
119 NULL, /* [5] check/validate user_id */
120 NULL, /* [6] check authorization */
121 NULL, /* [4] check access by host */
122 NULL, /* [7] MIME type checker/setter */
123 NULL, /* [8] fixups */
124 NULL, /* [10] logger */
125 NULL /* [3] header parser */
126#if MODULE_MAGIC_NUMBER >= 19970728 /* 1.3-dev or later support these additionals... */
127 ,NULL, /* child process initializer */
128 NULL, /* process exit/cleanup */
129 NULL /* [1] post read-request */
130#endif
131
132};
133#endif