httpd: Configurable index page

Peter Korsgaard jacmet at uclibc.org
Thu Dec 27 20:19:35 UTC 2007


Repost.

Make index page (E.G. index.html) used when a directory is requested
configurable in httpd.conf with the following syntax:

I:index.xml # use index.xml instead of index.html as index page

./scripts/bloat-o-meter /tmp/busybox_{old,new}
function                                             old     new   delta
parse_conf                                          1262    1290     +28
httpd_main                                           630     651     +21
handle_incoming_and_exit                            2093    2105     +12
send_headers                                         612     618      +6
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 4/0 up/down: 67/0)               Total: 67 bytes

---
 networking/httpd.c |   11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

Index: busybox/networking/httpd.c
===================================================================
--- busybox.orig/networking/httpd.c
+++ busybox/networking/httpd.c
@@ -43,6 +43,7 @@
  * A:127.0.0.1       # Allow local loopback connections
  * D:*               # Deny from other IP connections
  * E404:/path/e404.html # /path/e404.html is the 404 (not found) error page
+ * I:index.html      # Show index.html when a directory is requested
  *
  * P:/url:[http://]hostname[:port]/new/path
  *                   # When /urlXXXXXX is requested, reverse proxy
@@ -250,6 +251,7 @@
 	const char *g_query;
 	const char *configFile;
 	const char *home_httpd;
+	const char *index_page;
 
 	const char *found_mime_type;
 	const char *found_moved_temporarily;
@@ -295,6 +297,7 @@
 #define g_query           (G.g_query          )
 #define configFile        (G.configFile       )
 #define home_httpd        (G.home_httpd       )
+#define index_page        (G.index_page       )
 #define found_mime_type   (G.found_mime_type  )
 #define found_moved_temporarily (G.found_moved_temporarily)
 #define last_mod          (G.last_mod         )
@@ -688,6 +691,9 @@
 		}
 #endif
 
+		if (*p0 == 'I')
+			index_page = xstrdup(c);
+
 #if ENABLE_FEATURE_HTTPD_BASIC_AUTH \
  || ENABLE_FEATURE_HTTPD_CONFIG_WITH_MIME_TYPES \
  || ENABLE_FEATURE_HTTPD_CONFIG_WITH_SCRIPT_INTERPR
@@ -1836,7 +1842,7 @@
 	*tptr = '\0';
 
 	/* Copy URL from after "GET "/"POST " to stack-allocated char[] */
-	urlcopy = alloca((tptr - urlp) + sizeof("/index.html"));
+	urlcopy = alloca((tptr - urlp) + 2 + strlen(index_page));
 	/*if (urlcopy == NULL)
 	 *	send_headers_and_exit(HTTP_INTERNAL_SERVER_ERROR);*/
 	strcpy(urlcopy, urlp);
@@ -2087,7 +2093,7 @@
 #endif  /* FEATURE_HTTPD_CGI */
 
 	if (urlp[-1] == '/')
-		strcpy(urlp, "index.html");
+		strcpy(urlp, index_page);
 	if (stat(tptr, &sb) == 0) {
 		file_size = sb.st_size;
 		last_mod = sb.st_mtime;
@@ -2367,6 +2373,7 @@
 		sighup_handler(0);
 	else /* do not install HUP handler in inetd mode */
 #endif
+		index_page = "index.html";
 		parse_conf(default_path_httpd_conf, FIRST_PARSE);
 
 	xfunc_error_retval = 0;

-- 
Bye, Peter Korsgaard



More information about the busybox mailing list