Patch to use ServerName when using LogSQLMassVirtualHosting option

"Raymond Sundland" <raymond-3q8uVqRWQyRWk0Htik3J/[email protected]> Tue, 10 Apr 2007 16:49:45 -0400
Newsgroups gmane.comp.apache.mod-log-sql
Message-ID <[email protected]>
This is a multi-part message in MIME format.

--===============0846418406==
Content-Type: multipart/alternative;
	boundary="----=_NextPart_000_001E_01C77B90.3FA1BDA0"

This is a multi-part message in MIME format.

------=_NextPart_000_001E_01C77B90.3FA1BDA0
Content-Type: text/plain;
	charset="us-ascii"
Content-Transfer-Encoding: 7bit

Hi,

 

Since there does not seem to be much activity, I do not know how far this
email will go.  I started to use mod_log_sql recently on my FreeBSD box and
noticed the LogSQLMassVirtualHosting option used the hostname of the request
host (equivalent to the server's HTTP_HOST variable) to create it's dynamic
tables.  After conferring with someone on IRC who also used mod_log_sql, I
wrote a small patch that will provide an option for either using the
HTTP_HOST for the table name or the ServerName defined in your httpd.conf or
VirtualHost configuration.

 

Basically, I created a new option called LogSQLUseServerName which can be
set to either on or off.  Off is the default and replicates the current
behavior.  On will make it use ServerName to create your tables.

 

Patch as follows (use patch -p0 < patch) to apply to source.  I wrote this
patch from 101 so it may not work with earlier versions.  Disclaimer:  I am
not a C developer, only a part time code hacker so the code may not be 100%
sane (but I believe it is).  Use at your own risk.  Feel free to "fix" if
necessary, just do us all a favor and give it back to us.

 

Thanks.

 

--- mod_log_sql.c.old  Mon Nov  6 18:43:23 2006
+++ mod_log_sql.c      Sun Apr  8 22:24:49 2007
@@ -55,6 +55,7 @@
        int createtables;
        int forcepreserve;
        int disablepreserve;
+       int use_servername;
        char *machid;
        int announce;
        logsql_dbconnection db;
@@ -806,7 +807,16 @@
 
 
               /* Determine the hostname and convert it to all lower-case;
*/
-              char *servername = apr_pstrdup(orig->pool,(char
*)ap_get_server_name(orig));
+              char *servername;
+              if( global_config.use_servername ) {
+                      servername = apr_pstrdup(orig->pool,(char
*)orig->server->server_hostname);
+                      // log_error(APLOG_MARK,APLOG_ERR,0,orig->server,
"use_servername defined in config");
+              }
+              else {
+                      servername = apr_pstrdup(orig->pool,(char
*)ap_get_server_name(orig));
+              }
+              // log_error(APLOG_MARK,APLOG_ERR,0,orig->server, "using
servername %s", servername);
+                              
 
               char *p=servername;
               while (*p) {
@@ -1181,6 +1191,11 @@
         (void *)APR_OFFSETOF(global_config_t, machid), RSRC_CONF,
         "Machine ID that the module will log, useful in web clusters to
differentiate machines")
        ,
+       /* Use ServerName or the Request Header Name? */
+        AP_INIT_FLAG("LogSQLUseServerName", set_global_flag_slot,
+         (void *)APR_OFFSETOF(global_config_t, use_servername), RSRC_CONF,
+         "Determines whether we are going to use the Virtual Host
ServerName to create our tables or the request header")
+        ,
        /* Limits on logging */
        AP_INIT_ITERATE("LogSQLRequestAccept", add_server_string_slot,
         (void *)APR_OFFSETOF(logsql_state, transfer_accept_list),
RSRC_CONF,

 


------=_NextPart_000_001E_01C77B90.3FA1BDA0
Content-Type: text/html;
	charset="us-ascii"
Content-Transfer-Encoding: quoted-printable

<html>

<head>
<META HTTP-EQUIV=3D"Content-Type" CONTENT=3D"text/html; =
charset=3Dus-ascii">
<meta name=3DGenerator content=3D"Microsoft Word 11 (filtered)">
<style>
<!--
 /* Style Definitions */
 p.MsoNormal, li.MsoNormal, div.MsoNormal
	{margin:0in;
	margin-bottom:.0001pt;
	font-size:12.0pt;
	font-family:"Times New Roman";}
a:link, span.MsoHyperlink
	{color:blue;
	text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
	{color:purple;
	text-decoration:underline;}
pre
	{margin:0in;
	margin-bottom:.0001pt;
	font-size:10.0pt;
	font-family:"Courier New";}
span.EmailStyle17
	{font-family:Arial;
	color:windowtext;}
@page Section1
	{size:8.5in 11.0in;
	margin:1.0in 1.25in 1.0in 1.25in;}
div.Section1
	{page:Section1;}
-->
</style>

</head>

<body lang=3DEN-US link=3Dblue vlink=3Dpurple>

<div class=3DSection1>

<p class=3DMsoNormal><font size=3D2 face=3DArial><span =
style=3D'font-size:10.0pt;
font-family:Arial'>Hi,</span></font></p>

<p class=3DMsoNormal><font size=3D2 face=3DArial><span =
style=3D'font-size:10.0pt;
font-family:Arial'>&nbsp;</span></font></p>

<p class=3DMsoNormal><font size=3D2 face=3DArial><span =
style=3D'font-size:10.0pt;
font-family:Arial'>Since there does not seem to be much activity, I do =
not know
how far this email will go.&nbsp; I started to use mod_log_sql recently =
on my
FreeBSD box and noticed the LogSQLMassVirtualHosting option used the =
hostname
of the request host (equivalent to the server&#8217;s HTTP_HOST =
variable) to
create it&#8217;s dynamic tables.&nbsp; After conferring with someone on =
IRC who
also used mod_log_sql, I wrote a small patch that will provide an option =
for
either using the HTTP_HOST for the table name or the ServerName defined =
in your
httpd.conf or VirtualHost configuration.</span></font></p>

<p class=3DMsoNormal><font size=3D2 face=3DArial><span =
style=3D'font-size:10.0pt;
font-family:Arial'>&nbsp;</span></font></p>

<p class=3DMsoNormal><font size=3D2 face=3DArial><span =
style=3D'font-size:10.0pt;
font-family:Arial'>Basically, I created a new option called =
LogSQLUseServerName
which can be set to either on or off.&nbsp; Off is the default and =
replicates the
current behavior.&nbsp; On will make it use ServerName to create your =
tables.</span></font></p>

<p class=3DMsoNormal><font size=3D2 face=3DArial><span =
style=3D'font-size:10.0pt;
font-family:Arial'>&nbsp;</span></font></p>

<p class=3DMsoNormal><font size=3D2 face=3DArial><span =
style=3D'font-size:10.0pt;
font-family:Arial'>Patch as follows (use patch &#8211;p0 &lt; patch) to =
apply
to source.&nbsp; I wrote this patch from 101 so it may not work with =
earlier versions.&nbsp;
Disclaimer:&nbsp; I am not a C developer, only a part time code hacker =
so the code
may not be 100% sane (but I believe it is).&nbsp; Use at your own =
risk.&nbsp; Feel free
to &#8220;fix&#8221; if necessary, just do us all a favor and give it =
back to
us.</span></font></p>

<p class=3DMsoNormal><font size=3D2 face=3DArial><span =
style=3D'font-size:10.0pt;
font-family:Arial'>&nbsp;</span></font></p>

<p class=3DMsoNormal><font size=3D2 face=3DArial><span =
style=3D'font-size:10.0pt;
font-family:Arial'>Thanks.</span></font></p>

<p class=3DMsoNormal><font size=3D2 face=3DArial><span =
style=3D'font-size:10.0pt;
font-family:Arial'>&nbsp;</span></font></p>

<pre><font size=3D2 face=3D"Courier New"><span =
style=3D'font-size:10.0pt'>--- mod_log_sql.c.old&nbsp; Mon Nov&nbsp; 6 =
18:43:23 2006</span></font></pre><pre><font
size=3D2 face=3D"Courier New"><span style=3D'font-size:10.0pt'>+++ =
mod_log_sql.c&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Sun Apr&nbsp; 8 22:24:49 =
2007</span></font></pre><pre><font
size=3D2 face=3D"Courier New"><span style=3D'font-size:10.0pt'>@@ -55,6 =
+55,7 @@</span></font></pre><pre><font
size=3D2 face=3D"Courier New"><span style=3D'font-size:10.0pt'> =
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; int =
createtables;</span></font></pre><pre><font
size=3D2 face=3D"Courier New"><span style=3D'font-size:10.0pt'> =
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; int =
forcepreserve;</span></font></pre><pre><font
size=3D2 face=3D"Courier New"><span style=3D'font-size:10.0pt'> =
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; int =
disablepreserve;</span></font></pre><pre><font
size=3D2 face=3D"Courier New"><span =
style=3D'font-size:10.0pt'>+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; int =
use_servername;</span></font></pre><pre><font
size=3D2 face=3D"Courier New"><span style=3D'font-size:10.0pt'> =
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; char =
*machid;</span></font></pre><pre><font
size=3D2 face=3D"Courier New"><span style=3D'font-size:10.0pt'> =
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; int =
announce;</span></font></pre><pre><font
size=3D2 face=3D"Courier New"><span style=3D'font-size:10.0pt'> =
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; logsql_dbconnection =
db;</span></font></pre><pre><font
size=3D2 face=3D"Courier New"><span style=3D'font-size:10.0pt'>@@ -806,7 =
+807,16 @@</span></font></pre><pre><font
size=3D2 face=3D"Courier New"><span style=3D'font-size:10.0pt'> =
</span></font></pre><pre><font
size=3D2 face=3D"Courier New"><span =
style=3D'font-size:10.0pt'>&nbsp;</span></font></pre><pre><font
size=3D2 face=3D"Courier New"><span =
style=3D'font-size:10.0pt'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /* Determine the hostname and =
convert it to all lower-case; */</span></font></pre><pre><font
size=3D2 face=3D"Courier New"><span =
style=3D'font-size:10.0pt'>-&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb=
sp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; char *servername =3D =
apr_pstrdup(orig-&gt;pool,(char =
*)ap_get_server_name(orig));</span></font></pre><pre><font
size=3D2 face=3D"Courier New"><span =
style=3D'font-size:10.0pt'>+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb=
sp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; char =
*servername;</span></font></pre><pre><font
size=3D2 face=3D"Courier New"><span =
style=3D'font-size:10.0pt'>+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb=
sp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if( global_config.use_servername ) =
{</span></font></pre><pre><font
size=3D2 face=3D"Courier New"><span =
style=3D'font-size:10.0pt'>+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb=
sp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p;&nbsp; servername =3D apr_pstrdup(orig-&gt;pool,(char =
*)orig-&gt;server-&gt;server_hostname);</span></font></pre><pre><font
size=3D2 face=3D"Courier New"><span =
style=3D'font-size:10.0pt'>+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb=
sp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p;&nbsp; // log_error(APLOG_MARK,APLOG_ERR,0,orig-&gt;server, =
&quot;use_servername defined in =
config&quot;);</span></font></pre><pre><font
size=3D2 face=3D"Courier New"><span =
style=3D'font-size:10.0pt'>+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb=
sp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</span></font></pre><pre><font
size=3D2 face=3D"Courier New"><span =
style=3D'font-size:10.0pt'>+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb=
sp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; else {</span></font></pre><pre><font
size=3D2 face=3D"Courier New"><span =
style=3D'font-size:10.0pt'>+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb=
sp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p;&nbsp; servername =3D apr_pstrdup(orig-&gt;pool,(char =
*)ap_get_server_name(orig));</span></font></pre><pre><font
size=3D2 face=3D"Courier New"><span =
style=3D'font-size:10.0pt'>+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb=
sp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</span></font></pre><pre><font
size=3D2 face=3D"Courier New"><span =
style=3D'font-size:10.0pt'>+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb=
sp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // =
log_error(APLOG_MARK,APLOG_ERR,0,orig-&gt;server, &quot;using servername =
%s&quot;, servername);</span></font></pre><pre><font
size=3D2 face=3D"Courier New"><span =
style=3D'font-size:10.0pt'>+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb=
sp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
</span></font></pre><pre><font
size=3D2 face=3D"Courier New"><span style=3D'font-size:10.0pt'> =
</span></font></pre><pre><font
size=3D2 face=3D"Courier New"><span =
style=3D'font-size:10.0pt'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; char =
*p=3Dservername;</span></font></pre><pre><font
size=3D2 face=3D"Courier New"><span style=3D'font-size:10.0pt'> =
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&=
nbsp; while (*p) {</span></font></pre><pre><font
size=3D2 face=3D"Courier New"><span style=3D'font-size:10.0pt'>@@ =
-1181,6 +1191,11 @@</span></font></pre><pre><font
size=3D2 face=3D"Courier New"><span style=3D'font-size:10.0pt'> =
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;(void =
*)APR_OFFSETOF(global_config_t, machid), =
RSRC_CONF,</span></font></pre><pre><font
size=3D2 face=3D"Courier New"><span style=3D'font-size:10.0pt'> =
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&quot;Machine ID that the =
module will log, useful in web clusters to differentiate =
machines&quot;)</span></font></pre><pre><font
size=3D2 face=3D"Courier New"><span style=3D'font-size:10.0pt'> =
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ,</span></font></pre><pre><font
size=3D2 face=3D"Courier New"><span =
style=3D'font-size:10.0pt'>+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /* Use =
ServerName or the Request Header Name? */</span></font></pre><pre><font
size=3D2 face=3D"Courier New"><span =
style=3D'font-size:10.0pt'>+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
AP_INIT_FLAG(&quot;LogSQLUseServerName&quot;, =
set_global_flag_slot,</span></font></pre><pre><font
size=3D2 face=3D"Courier New"><span =
style=3D'font-size:10.0pt'>+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb=
sp; (void *)APR_OFFSETOF(global_config_t, use_servername), =
RSRC_CONF,</span></font></pre><pre><font
size=3D2 face=3D"Courier New"><span =
style=3D'font-size:10.0pt'>+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb=
sp; &quot;Determines whether we are going to use the Virtual Host =
ServerName to create our tables or the request =
header&quot;)</span></font></pre><pre><font
size=3D2 face=3D"Courier New"><span =
style=3D'font-size:10.0pt'>+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
,</span></font></pre><pre><font
size=3D2 face=3D"Courier New"><span style=3D'font-size:10.0pt'> =
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /* Limits on logging =
*/</span></font></pre><pre><font
size=3D2 face=3D"Courier New"><span style=3D'font-size:10.0pt'> =
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
AP_INIT_ITERATE(&quot;LogSQLRequestAccept&quot;, =
add_server_string_slot,</span></font></pre><pre><font
size=3D2 face=3D"Courier New"><span style=3D'font-size:10.0pt'> =
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;(void =
*)APR_OFFSETOF(logsql_state, transfer_accept_list), =
RSRC_CONF,</span></font></pre>

<p class=3DMsoNormal><font size=3D2 face=3DArial><span =
style=3D'font-size:10.0pt;
font-family:Arial'>&nbsp;</span></font></p>

</div>

</body>

</html>

------=_NextPart_000_001E_01C77B90.3FA1BDA0--


--===============0846418406==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

_______________________________________________
Download the latest version at http://www.outoforder.cc/projects/apache/mod_log_sql/

To unsubscribe send an e-mail to 
mod_log_sql-unsubscribe-7qY7E20V6GW73k+5HYS8LQqVMODqnSLI@public.gmane.org

--===============0846418406==--