[Mod_log_sql] Patch to use ServerName when using LogSQLMassVirtualHosting option

Raymond Sundland raymond at sundland.com
Tue Apr 10 16:49:45 EDT 2007


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,

 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.outoforder.cc/pipermail/mod_log_sql/attachments/20070410/19a7597b/attachment.html 


More information about the Mod_log_sql mailing list