Re: LogSQLMassVirtualHosting and mod_vhost_alias

"Dice R. Random" <[email protected]> Sat, 21 Jan 2006 14:56:51 -0800
Newsgroups gmane.comp.apache.mod-log-sql
Message-ID <[email protected]>
On 1/21/06, Edward Rudd <[email protected]> wrote:
> actually it is pulled from the request record of the "requested'
> hostname.  i have a feature  on http://issues.outoforder.cc/ to address
> this exact issue. (issue # 27).  i will be starting development sometime
> this week.

OK, thanks for the clarification :)

I'm rather impatient to get this new configuration up and running for
our clients, so I went ahead and wrote a patch against
mod_log_sql-1.100 that impliments this functionality.  I added on a
configuration directive 'LogSQLTruncateDomains', added a flag to the
global configuration structure, and tacked on some additional logic to
the log_sql_transaction function.  The end result is that if you
enable LogSQLTruncateDomains *and* LogSQLMassVirtualHosting then, for
the purposes of the logging table name, any hostname of the form
foo.bar.etc.domain.tld will be truncated to simply domain.tld.

I've tested this and it works on my system, but I don't claim to have
tested it extensively so there could very well be a bug for some other
configurations.

The patch is attached, of course.

_______________________________________________
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
mod_log_sql-truncatedomains.patch (text/x-patch, 1.6 KB)
diff -aurN mod_log_sql-1.100-orig/mod_log_sql.c mod_log_sql-1.100/mod_log_sql.c
--- mod_log_sql-1.100-orig/mod_log_sql.c	2005-01-11 14:03:41.000000000 -0800
+++ mod_log_sql-1.100/mod_log_sql.c	2006-01-21 07:40:12.000000000 -0800
@@ -52,6 +52,7 @@
 
 typedef struct {
 	int massvirtual;
+	int truncatedomains;
 	int createtables;
 	int forcepreserve;
 	int disablepreserve;
@@ -794,8 +795,26 @@
 
 		/* Determine the hostname and convert it to all lower-case; */
 		char *servername = apr_pstrdup(orig->pool,(char *)ap_get_server_name(orig));
+		char *p;
 
-		char *p=servername;
+		/* Optionally truncate the hostname to domain.tld format */
+		if(global_config.truncatedomains) {
+			int numdots = 0;
+
+			p = servername + strlen(servername);
+			while(p != servername) {
+				if(*p == '.') {
+					numdots++;
+					if(numdots == 2) {
+						servername = p+1;
+						break;
+					}
+				}
+				p--;
+			}
+		}
+
+		p = servername;
 		while (*p) {
 			*p = apr_tolower(*p);
 			if (*p == '.') *p = '_';
@@ -1138,6 +1157,10 @@
 	 (void *)APR_OFFSETOF(global_config_t, massvirtual), RSRC_CONF,
 	 "Activates option(s) useful for ISPs performing mass virutal hosting")
 	,
+	AP_INIT_FLAG("LogSQLTruncateDomains", set_global_flag_slot,
+	 (void *)APR_OFFSETOF(global_config_t, truncatedomains), RSRC_CONF,
+	 "Truncates domains to domain.tld format when naming log tables with LogSQLMassVirtualHosting")
+	,
 	AP_INIT_TAKE1("LogSQLTransferLogTable", set_server_nmv_string_slot,
 	 (void *)APR_OFFSETOF(logsql_state, transfer_table_name), RSRC_CONF, 
 	 "The database table that holds the transfer log")