diff -urN thttpd-2.21/Makefile.in thttpd-2.21-mnx/Makefile.in
--- thttpd-2.21/Makefile.in	Thu Mar 29 21:36:21 2001
+++ thttpd-2.21-mnx/Makefile.in	Fri Oct 19 15:13:21 2001
@@ -39,7 +39,7 @@
 # CONFIGURE: The group that the web directory belongs to.  This is so that
 # the makeweb program can be installed set-group-id to that group, and make
 # subdirectories.  If you're not going to use makeweb, ignore this.
-WEBGROUP =	www
+WEBGROUP =	www-data
 
 # CONFIGURE: Directory for CGI executables.
 CGIBINDIR =	$(WEBDIR)/cgi-bin
@@ -51,7 +51,7 @@
 DEFS =		@DEFS@
 INCLS =		-I.
 CFLAGS =	$(CCOPT) $(DEFS) $(INCLS)
-LDFLAGS =	@LDFLAGS@
+LDFLAGS =	@LDFLAGS@ -lmysqlclient
 LIBS =		@LIBS@
 NETLIBS =	@V_NETLIBS@
 INSTALL =	@INSTALL@
@@ -62,7 +62,7 @@
 	@rm -f $@
 	$(CC) $(CFLAGS) -c $*.c
 
-SRC =		thttpd.c libhttpd.c fdwatch.c mmc.c timers.c match.c tdate_parse.c syslog.c
+SRC =		thttpd.c libhttpd.c fdwatch.c mmc.c timers.c match.c tdate_parse.c syslog.c vhost.c
 
 OBJ =		$(SRC:.c=.o) @LIBOBJS@
 
@@ -163,11 +163,12 @@
 	  rm -rf $$name ; \
 	  gzip $$name.tar
 
-thttpd.o:	config.h version.h libhttpd.h fdwatch.h mmc.h timers.h match.h
+thttpd.o:	config.h version.h libhttpd.h fdwatch.h mmc.h timers.h match.h vhostconf.h
 libhttpd.o:	config.h version.h libhttpd.h mime_encodings.h mime_types.h \
-		mmc.h timers.h match.h tdate_parse.h
+		mmc.h timers.h match.h tdate_parse.h vhostconf.h
 fdwatch.o:	fdwatch.h
 mmc.o:		mmc.h
 timers.o:	timers.h
 match.o:	match.h
 tdate_parse.o:	tdate_parse.h
+vhost.o:	vhostconf.h
diff -urN thttpd-2.21/config.h thttpd-2.21-mnx/config.h
--- thttpd-2.21/config.h	Tue Apr 10 00:57:36 2001
+++ thttpd-2.21-mnx/config.h	Fri Oct 19 18:36:32 2001
@@ -183,9 +183,7 @@
 ** having to give the -v command line flag.  You can still disable it at
 ** runtime with the -nov flag.
 */
-#ifdef notdef
 #define ALWAYS_VHOST
-#endif
 
 /* CONFIGURE: If you're using the vhost feature and you have a LOT of
 ** virtual hostnames (like, hundreds or thousands), you will want to
@@ -214,6 +212,12 @@
 #define VHOST_DIRLEVELS 2
 #define VHOST_DIRLEVELS 3
 #endif
+/* CONFIGURE:
+** You can use the mapping between vhost and path from a mysql table, just define
+** it here:
+*/
+
+#define VHOST_MYSQL
 
 /* CONFIGURE: Define this if you want to always use a global passwd file,
 ** without having to give the -P command line flag.  You can still disable
@@ -227,7 +231,7 @@
 ** initializing.  If this user (or the one specified by the -u flag) does
 ** not exist, the program will refuse to run.
 */
-#define DEFAULT_USER "nobody"
+#define DEFAULT_USER "www-data"
 
 /* CONFIGURE: When started as root, the program can automatically chdir()
 ** to the home directory of the user specified by -u or DEFAULT_USER.
@@ -316,7 +320,7 @@
 /* CONFIGURE: A list of index filenames to check.  The files are searched
 ** for in this order.
 */
-#define INDEX_NAMES "index.html", "index.htm", "Default.htm", "index.cgi"
+#define INDEX_NAMES "index.html", "index.htm"
 
 /* CONFIGURE: If this is defined then thttpd will automatically generate
 ** index pages for directories that don't have an explicit index file.
diff -urN thttpd-2.21/libhttpd.c thttpd-2.21-mnx/libhttpd.c
--- thttpd-2.21/libhttpd.c	Sat Apr 21 03:11:32 2001
+++ thttpd-2.21-mnx/libhttpd.c	Fri Oct 19 18:42:53 2001
@@ -76,6 +76,11 @@
 #  include <ndir.h>
 # endif
 #endif
+#ifdef VHOST_MYSQL
+#include "vhostconf.h"
+extern struct node *vh_list;
+extern int vh_list_len;
+#endif
 
 extern char* crypt( const char* key, const char* setting );
 
@@ -1295,6 +1300,9 @@
     int i;
     char* cp2;
 #endif /* VHOST_DIRLEVELS */
+#ifdef VHOST_MYSQL
+    int tmp;
+#endif
 
     /* Figure out the virtual hostname. */
     if ( hc->reqhost[0] != '\0' )
@@ -1347,9 +1355,34 @@
 	*cp2++ = '/';
 	}
     (void) strcpy( cp2, hc->hostname );
-#else /* VHOST_DIRLEVELS */
+#endif
+#ifdef VHOST_MYSQL
+    tmp=bin_search(vh_list,vh_list_len,hc->hostname);
+    /*
+     XXX handle not found cases
+     */
+    if (tmp==-1)
+    {
+	    /* not found , fall back to default method*/
+	    httpd_realloc_str( &hc->hostdir, &hc->maxhostdir, strlen( hc->hostname ) );
+	    (void) strcpy( hc->hostdir, hc->hostname );
+    }
+    else
+    {
+	    httpd_realloc_str(&hc->hostdir,&maxtempfilename,
+			      strlen(vh_list[tmp].path));
+	    (void) strcpy (hc->hostdir,vh_list[tmp].path);
+            maxtempfilename=0;
+    }
+    /*
+     XXX FIX!!! stupid ifdefs, etc
+     */
+#endif
+#ifndef VHOST_MYSQL
+#ifndef VHOST_DIRLEVELS
     httpd_realloc_str( &hc->hostdir, &hc->maxhostdir, strlen( hc->hostname ) );
     (void) strcpy( hc->hostdir, hc->hostname );
+#endif
 #endif /* VHOST_DIRLEVELS */
 
     /* Prepend hostdir to the filename. */
diff -urN thttpd-2.21/thttpd.c thttpd-2.21-mnx/thttpd.c
--- thttpd-2.21/thttpd.c	Sun Apr 15 19:09:20 2001
+++ thttpd-2.21-mnx/thttpd.c	Fri Oct 19 18:13:06 2001
@@ -58,6 +58,12 @@
 #include "mmc.h"
 #include "timers.h"
 #include "match.h"
+#ifdef VHOST_MYSQL
+#include "vhostconf.h"
+extern struct node *vh_list;
+extern int vh_list_len;
+#endif
+
 
 
 static char* argv0;
@@ -381,6 +387,16 @@
 	(void) fprintf( pidfp, "%d\n", (int) getpid() );
 	(void) fclose( pidfp );
 	}
+
+    /*
+     It's better to load the data from the mysql DB now, because
+     after the chroot() the mysql socket may be unavialable
+     */
+
+#ifdef VHOST_MYSQL
+    vh_list=vh_init_struct(&vh_list_len);
+    if (vh_list==NULL) exit(1);
+#endif
 
     /* Chroot if requested. */
     if ( do_chroot )
diff -urN thttpd-2.21/vhost.c thttpd-2.21-mnx/vhost.c
--- thttpd-2.21/vhost.c	Thu Jan  1 02:00:00 1970
+++ thttpd-2.21-mnx/vhost.c	Fri Oct 19 18:19:26 2001
@@ -0,0 +1,97 @@
+
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <string.h>
+#include <mysql/mysql.h>
+
+#include "vhostconf.h"
+
+struct node *vh_list;
+int vh_list_len;
+
+/*
+ Allocates memory for *tmp, and loads the vhost map in it. Sets n accordingly.
+ */
+
+struct node *vh_init_struct(int *n)
+{
+
+	MYSQL *conn;
+	MYSQL_RES * result;
+	MYSQL_ROW row;
+        struct node *tmp;
+
+
+	conn=mysql_init(NULL);
+	if (conn==NULL)
+	{
+		syslog(LOG_ERR,"Error initalizing mysql handle");
+                return NULL;
+	}
+	if (mysql_real_connect(conn,DBHOST,DBUSER,DBPASS,DBNAME,0,NULL,0)==NULL)
+	{
+		syslog(LOG_ERR,"Error connecting to the database");
+                return NULL;
+	}
+
+	/*
+	 I use string constant for the query, because I haven't thought of a way to
+         make it more flexible for the moment.
+	 */
+
+
+	if(mysql_real_query(conn,QUERY,strlen(QUERY)+1)!=0)
+	{
+		syslog(LOG_ERR,"Error querying the database");
+		return NULL;
+	}
+	result=mysql_store_result(conn);
+	/*
+	 Okay, we have the results , let's allocate some memory and parse them
+	 */
+
+	tmp=(struct node *) malloc(sizeof(struct node) * mysql_num_rows(result));
+
+	row=mysql_fetch_row(result);
+        (*n)=0;
+	while (row!=NULL)
+	{
+                tmp[*n].vhost=strdup(row[0]);
+                tmp[*n].path=strdup(row[1]);
+		(*n)++;
+		row=mysql_fetch_row(result);
+	}
+        (*n)--;
+        return tmp;
+}
+
+/*
+ Searches for vhost position in *table
+ Uses simple binary search in sorted array, tests proved that it's fast enough
+ (30 000 searches in 30 000 elements array took about 100 ms , not like the
+ linear search,that took about 100 s )
+ */
+
+int bin_search(struct node *tbl, int n, char *tosrch)
+{
+	int k,i,left,right;
+
+	left=0;
+	right=n;
+	while (left!=right)
+	{
+		i=(left+right)/2;
+		k=strcmp(tosrch,tbl[i].vhost);
+		if (k==0) return i;
+		if (k<0) right=i;
+		else
+			if (left==i) return -1 ;
+			else left=i;
+
+	}
+        return -1;
+
+}
+
diff -urN thttpd-2.21/vhostconf.h thttpd-2.21-mnx/vhostconf.h
--- thttpd-2.21/vhostconf.h	Thu Jan  1 02:00:00 1970
+++ thttpd-2.21-mnx/vhostconf.h	Fri Oct 19 18:16:46 2001
@@ -0,0 +1,25 @@
+#define DBHOST "localhost"
+#define DBNAME "test0"
+#define DBUSER "root"
+#define DBPASS ""
+#define QUERY "select hostname,path from vhost order by hostname"
+#include <syslog.h>
+
+
+
+struct node
+{
+
+    char *vhost;
+    char *path;
+    char *adv;
+
+};
+
+/* forward declarations */
+
+struct node *vh_init_struct(int *n);
+int bin_search(struct node *tbl, int n,char *tosrch);
+
+
+
