httpd: Configurable index page

Peter Korsgaard jacmet at uclibc.org
Mon Dec 10 08:34:15 UTC 2007


>>>>> "Peter" == Peter Korsgaard <jacmet at uclibc.org> writes:

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

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

Comments?

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

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

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

 Peter> -- 
 Peter> Bye, Peter Korsgaard

-- 
Bye, Peter Korsgaard



More information about the busybox mailing list