Hi,

The attached patch adds an option to set the default page to display for a URL 
like
http://hostname/ instead of index.html. The option is compile-time selectable 
and the
filename is config-file choosable. The file may also be a CGI script (if CGI is 
compiled
in).

   text    data     bss     dec     hex filename
  93880    4020    1952   99852   1860c busybox_unstripped
  94054    4028    1952  100034   186c2 busybox_unstripped.new

Any comments?

Thanks,
Alex


       
____________________________________________________________________________________
Pinpoint customers who are looking for what you sell. 
http://searchmarketing.yahoo.com/
Index: networking/httpd.c
===================================================================
--- networking/httpd.c	(revision 20259)
+++ networking/httpd.c	(working copy)
@@ -267,6 +267,9 @@
 #define hdr_buf bb_common_bufsiz1
 	char *hdr_ptr;
 	int hdr_cnt;
+#if ENABLE_FEATURE_HTTPD_START_PAGE
+	const char *start_page;
+#endif
 #if ENABLE_FEATURE_HTTPD_ERROR_PAGES
 	const char *http_error_page[ARRAY_SIZE(http_response_type)];
 #endif
@@ -300,12 +303,14 @@
 #define iobuf             (G.iobuf            )
 #define hdr_ptr           (G.hdr_ptr          )
 #define hdr_cnt           (G.hdr_cnt          )
+#define start_page        (G.start_page       )
 #define http_error_page   (G.http_error_page  )
 #define INIT_G() do { \
 	PTR_TO_GLOBALS = xzalloc(sizeof(G)); \
 	USE_FEATURE_HTTPD_BASIC_AUTH(g_realm = "Web Server Authentication";) \
 	bind_addr_or_port = "80"; \
 	file_size = -1; \
+	USE_FEATURE_HTTPD_START_PAGE(start_page = "";) \
 } while (0)
 
 #if !ENABLE_FEATURE_HTTPD_RANGES
@@ -594,6 +599,15 @@
 		}
 #endif
 
+#if ENABLE_FEATURE_HTTPD_START_PAGE
+		if (flag == FIRST_PARSE && *p0 == 'S') {
+			/* c already points at the character following ':' in parse loop */
+			/* c = strchr(p0, ':'); c++; */
+			start_page = xstrdup(c);
+			continue;
+		}
+#endif
+
 #if ENABLE_FEATURE_HTTPD_BASIC_AUTH
 		if (*p0 == '/') {
 			/* make full path from httpd root / current_path / config_line_path */
@@ -1754,7 +1768,8 @@
 	*tptr = '\0';
 
 	/* Copy URL from after "GET "/"POST " to stack-allocated char[] */
-	urlcopy = alloca((tptr - urlp) + sizeof("/index.html"));
+	urlcopy = alloca((tptr - urlp) + sizeof("/index.html")
+			USE_FEATURE_HTTPD_START_PAGE( + strlen(start_page) + 1));
 	/*if (urlcopy == NULL)
 	 *	send_headers_and_exit(HTTP_INTERNAL_SERVER_ERROR);*/
 	strcpy(urlcopy, urlp);
@@ -1954,21 +1969,23 @@
 	if (stat(tptr, &sb) == 0) {
 		file_size = sb.st_size;
 		last_mod = sb.st_mtime;
-	}
-#if ENABLE_FEATURE_HTTPD_CGI
-	else if (urlp[-1] == '/') {
-		/* It's a dir URL and there is no index.html
-		 * Try cgi-bin/index.cgi */
-		if (access("/cgi-bin/index.cgi"+1, X_OK) == 0) {
-			urlp[0] = '\0';
-			g_query = urlcopy;
-			send_cgi_and_exit("/cgi-bin/index.cgi", prequest, length, cookie, content_type);
+	} else {
+#if ENABLE_FEATURE_HTTPD_CGI && ENABLE_FEATURE_HTTPD_START_PAGE
+		if (urlp[-1] == '/') {
+			/* It's a dir URL and there is no index.html
+			 * Try start_page */
+			if (access(start_page, X_OK) == 0) {
+				urlp[0] = '\0';
+				g_query = urlcopy;
+				strcat(urlcopy, start_page);
+				send_cgi_and_exit(urlcopy, prequest, length, cookie, content_type);
+			}
 		}
+#endif
+		USE_FEATURE_HTTPD_START_PAGE(strcpy(urlp, start_page));
 	}
-#endif
-	/* else {
-	 *	fall through to send_file, it errors out if open fails
-	 * }
+	/*
+	 * fall through to send_file, it errors out if open fails
 	 */
 
 	send_file_and_exit(tptr, TRUE);
Index: networking/Config.in
===================================================================
--- networking/Config.in	(revision 20259)
+++ networking/Config.in	(working copy)
@@ -192,6 +192,20 @@
 	  '/path/e404.html' file instead of the terse '404 NOT FOUND'
 	  message.
 
+config FEATURE_HTTPD_START_PAGE
+	bool "Enable configurable start page"
+	default n
+	depends on HTTPD
+	help
+	  This option allows you to define a custom start page in
+	  the configuration file instead of the default 'index.html'.
+	  For instance, if you add the line:
+	        S:index.php
+	  in the config file, the server will send index.php
+	  (processed by the correct interpreter if index.php is
+	  executable) if index.html does not exist and the request
+	  specifies only a directory.
+
 config IFCONFIG
 	bool "ifconfig"
 	default n
_______________________________________________
busybox mailing list
[email protected]
http://busybox.net/cgi-bin/mailman/listinfo/busybox

Reply via email to