Re: LogSQLMassVirtualHosting and mod_vhost_alias

"Dice R. Random" <[email protected]> Sat, 21 Jan 2006 17:51:25 -0800
Newsgroups gmane.comp.apache.mod-log-sql
Message-ID <[email protected]>
On 1/21/06, Dice R. Random <[email protected]> wrote:
> If that's true then it should be a fairly simple modification, I'll
> get to work on it in an hour or two.

Replying to my own post....

This is the re-worked patch, Works For Me when dealing with .co.uk
sites and various subdomains.  It did reveal some simmilar problems in
our internal directory scheme for the mass virtual hosts though, but
that has nothing to do with mod_log_sql.

Is there some ICANN documentation or something that will guarentee
this is correct?  I didn't see anything when I took a cursory glance
at their site.

It's not that I don't trust that what you said is true, Günther, I
just want to be sure there's actually a policy in place so that this
will work for all domains :)

_______________________________________________
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 10:40:41.000000000 -0800
@@ -52,6 +52,7 @@
 
 typedef struct {
 	int massvirtual;
+	int truncatedomains;
 	int createtables;
 	int forcepreserve;
 	int disablepreserve;
@@ -794,8 +795,28 @@
 
 		/* 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;
+			char *prevdot = NULL;
+
+			p = servername + strlen(servername);
+			while(p != servername) {
+				if(*p == '.') {
+					numdots++;
+					if(numdots >= 2 && (prevdot - p) > 3) {
+						servername = p+1;
+						break;
+					}
+					prevdot = p;
+				}
+				p--;
+			}
+		}
+
+		p = servername;
 		while (*p) {
 			*p = apr_tolower(*p);
 			if (*p == '.') *p = '_';
@@ -1138,6 +1159,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")