khttpd: Virtual domain support alpha code

Christoph Lameter (christoph@lameter.com)
Sat, 4 Sep 1999 00:09:57 -0700 (PDT)


One thing that I always need from a webserver is virtual domain support.
Sadly khttpd does not provide that. Attached is a patch that tries to
implement virtual domain support in khttpd.

There is a new file /proc/sys/net/khttpd/virtual controlling virtual
domain behavior. The following values can be set

0 Default. No change.
1 Virtual IP mode. Serve files from
<documentroot>/<AAA.BBB.CCC.DDD>/filename
2 Virtual Host mode. Server files from
<documentroot>/<hostname>/filename

Mode 1 is broken since I did not have the time to track down how to get
the bound IP for the "struct socket" in the khttpd request structure.

And I am not sure that the composition of the filename really belongs into
the rfc.c source. But moving that would require changing lots of things.

Not sure also if all my string arithmetic is that clean.

diff -urN linux-2.3.16/include/linux/sysctl.h linux/include/linux/sysctl.h
--- linux-2.3.16/include/linux/sysctl.h Thu Sep 2 02:38:23 1999
+++ linux/include/linux/sysctl.h Fri Sep 3 23:09:04 1999
@@ -439,7 +439,8 @@
NET_KHTTPD_DYNAMICSTRING= 10,
NET_KHTTPD_SLOPPYMIME = 11,
NET_KHTTPD_THREADS = 12,
- NET_KHTTPD_MAXCONNECT = 13
+ NET_KHTTPD_MAXCONNECT = 13,
+ NET_KHTTPD_VIRTUALMODE = 14
};

/* /proc/sys/net/decnet/conf/<dev> */
diff -urN linux-2.3.16/net/khttpd/README linux/net/khttpd/README
--- linux-2.3.16/net/khttpd/README Fri Aug 20 20:41:57 1999
+++ linux/net/khttpd/README Fri Sep 3 22:42:39 1999
@@ -223,6 +223,12 @@
maxconnect 1000 Maximum number of concurrent
connections

+ virtual 0 Virtual server mode
+ 0 = none. All files served from documentroot/<filename>. Discard Virtual IP and virtual Host information.
+ 1 = Virtual IP. Files served from documentroot/<Numeric-IP>/<filename>
+ 2 = Virtual Host. Files served from documentroot/<Virtualhostname>/<Filename>
+
+
6. More information
-------------------
More information about the architecture of kHTTPd, the mailinglist and
diff -urN linux-2.3.16/net/khttpd/rfc.c linux/net/khttpd/rfc.c
--- linux-2.3.16/net/khttpd/rfc.c Wed Aug 25 22:28:14 1999
+++ linux/net/khttpd/rfc.c Fri Sep 3 23:55:23 1999
@@ -269,6 +269,39 @@
}
#endif

+/*
+
+Get the Document root taking into account virtual domain configuration
+
+*/
+
+int GetDocRoot(char *startp,int length,struct http_request *Head)
+{
+ char *endp=startp;
+
+ strncpy(startp,sysctl_khttpd_docroot,length);
+ endp=startp+strlen(sysctl_khttpd_docroot);
+ if (endp>=startp+length-1) return length;
+
+ if (sysctl_khttpd_virtual_mode)
+ {
+ /* Virtual Mode. Now insert either IP address or Virtual Hostname */
+ if (sysctl_khttpd_virtual_mode == 1)
+ {
+ if (endp>=startp+length-16) return strlen(startp)+1;
+ /* Fill in the target IP address of the request */
+ sprintf(endp,"%d.%d.%d.%d",1,2,3,4);
+ /* NIPQUAD(Head->sock->rcv_saddr) does not work here. sigh */
+ endp+=strlen(endp);
+ } else {
+ endp+=strlen(Head->Host);
+ if (endp>=startp+length-1) return strlen(startp)+1;
+ strcpy(endp,Head->Host);
+ }
+ *endp++='/'; /* Separator between virtual hostname and filename */
+ }
+ return endp-startp+1;
+}


/*
@@ -324,8 +357,7 @@

if (tmp>Endval) continue;

- strncpy(Head->FileName,sysctl_khttpd_docroot,sizeof(Head->FileName));
- PrefixLen = strlen(sysctl_khttpd_docroot);
+ PrefixLen=GetDocRoot(Head->FileName,sizeof(Head->FileName),Head);
Head->FileNameLength = min(255,tmp-Buffer+PrefixLen);

strncat(Head->FileName,Buffer,min(255-PrefixLen,tmp-Buffer));
diff -urN linux-2.3.16/net/khttpd/sysctl.c linux/net/khttpd/sysctl.c
--- linux-2.3.16/net/khttpd/sysctl.c Wed Aug 25 22:28:14 1999
+++ linux/net/khttpd/sysctl.c Fri Sep 3 23:56:35 1999
@@ -63,7 +63,7 @@
int sysctl_khttpd_sloppymime= 0;
int sysctl_khttpd_threads = 2;
int sysctl_khttpd_maxconnect = 1000;
-
+int sysctl_khttpd_virtual_mode = 0;

static struct ctl_table_header *khttpd_table_header;

@@ -227,6 +227,18 @@
NULL,
proc_dosecurestring,
&sysctl_SecureString,
+ NULL,
+ NULL,
+ NULL
+ },
+ { NET_KHTTPD_VIRTUALMODE,
+ "virtual",
+ &sysctl_khttpd_virtual_mode,
+ sizeof(int),
+ 0644,
+ NULL,
+ proc_dointvec,
+ &sysctl_intvec,
NULL,
NULL,
NULL
diff -urN linux-2.3.16/net/khttpd/sysctl.h linux/net/khttpd/sysctl.h
--- linux-2.3.16/net/khttpd/sysctl.h Fri Aug 20 20:41:57 1999
+++ linux/net/khttpd/sysctl.h Fri Sep 3 22:36:41 1999
@@ -13,5 +13,6 @@
extern int sysctl_khttpd_sloppymime;
extern int sysctl_khttpd_threads;
extern int sysctl_khttpd_maxconnect;
+extern int sysctl_khttpd_virtual_mode;

#endif

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/