diff --git a/Documentation/NuttxPortingGuide.html b/Documentation/NuttxPortingGuide.html index ee91135ffc..140c583863 100644 --- a/Documentation/NuttxPortingGuide.html +++ b/Documentation/NuttxPortingGuide.html @@ -2362,7 +2362,10 @@ extern void up_ledoff(int led); CONFIG_THTTPD_SERVER_SOFTWARE: SERVER_SOFTWARE: response
  • - CONFIG_THTTPD_CGI_PATH: + CONFIG_THTTPD_PATH: Server working directory +
  • +
  • + CONFIG_THTTPD_CGI_PATH: Path to CGI executables
  • CONFIG_THTTPD_CGI_PATTERN: Only CGI programs matching this diff --git a/configs/README.txt b/configs/README.txt index c16e22a5cf..9418f6ea8a 100644 --- a/configs/README.txt +++ b/configs/README.txt @@ -358,7 +358,8 @@ defconfig -- This is a configuration file similar to the Linux CONFIG_THTTPD_IPADDR - Server IP address (no host name) CONFIG_THTTPD_SERVER_ADDRESS - SERVER_ADDRESS: response CONFIG_THTTPD_SERVER_SOFTWARE - SERVER_SOFTWARE: response - CONFIG_THTTPD_CGI_PATH - + CONFIG_THTTPD_PATH - Server working directory + CONFIG_THTTPD_CGI_PATH - Path to CGI executables CONFIG_THTTPD_CGI_PATTERN - Only CGI programs matching this pattern will be executed. In fact, if this value is not defined then no CGI logic will be built. diff --git a/configs/eagle100/thttpd/defconfig b/configs/eagle100/thttpd/defconfig index fc78a9dace..b369e70b03 100644 --- a/configs/eagle100/thttpd/defconfig +++ b/configs/eagle100/thttpd/defconfig @@ -483,7 +483,8 @@ CONFIG_NET_RESOLV_ENTRIES=4 # CONFIG_THTTPD_IPADDR - Server IP address (no host name) # CONFIG_THTTPD_SERVER_ADDRESS - SERVER_ADDRESS: response # CONFIG_THTTPD_SERVER_SOFTWARE - SERVER_SOFTWARE: response -# CONFIG_THTTPD_CGI_PATH - +# CONFIG_THTTPD_PATH - Server working directory +# CONFIG_THTTPD_CGI_PATH - Path to CGI executables # CONFIG_THTTPD_CGI_PATTERN - Only CGI programs matching this # pattern will be executed. In fact, if this value is not defined # then no CGI logic will be built. @@ -536,6 +537,7 @@ CONFIG_THTTPD_PORT=80 CONFIG_THTTPD_IPADDR=(10<<24|0<<16|0<<8|2) CONFIG_THTTPD_SERVER_ADDRESS="http://www.nuttx.org" CONFIG_THTTPD_SERVER_SOFTWARE="thttpd/2.25b 29dec2003-NuttX" +CONFIG_THTTPD_PATH="/mnt/www" CONFIG_THTTPD_CGI_PATH="/mnt/www/cgi-bin" CONFIG_THTTPD_CGI_PATTERN="/cgi-bin/*" CONFIG_THTTPD_CGI_PRIORITY=50 diff --git a/examples/thttpd/main.c b/examples/thttpd/main.c index 23c2725654..b0f36b3730 100644 --- a/examples/thttpd/main.c +++ b/examples/thttpd/main.c @@ -93,7 +93,7 @@ #define SECTORSIZE 512 #define NSECTORS(b) (((b)+SECTORSIZE-1)/SECTORSIZE) #define ROMFSDEV "/dev/ram0" -#define MOUNTPT "/mnt/www" +#define MOUNTPT CONFIG_THTTPD_PATH #ifdef CONFIG_CPP_HAVE_VARARGS # ifdef CONFIG_DEBUG diff --git a/lib/lib_strcasecmp.c b/lib/lib_strcasecmp.c index d9c5e5636c..233cd3fc1c 100644 --- a/lib/lib_strcasecmp.c +++ b/lib/lib_strcasecmp.c @@ -54,7 +54,7 @@ #ifndef CONFIG_ARCH_STRCMP int strcasecmp(const char *cs, const char *ct) { - register int result; + int result; for (;;) { if ((result = (int)toupper(*cs) - (int)toupper(*ct)) != 0 || !*cs) diff --git a/lib/lib_strncasecmp.c b/lib/lib_strncasecmp.c index c34396a502..fc8bf7b72f 100644 --- a/lib/lib_strncasecmp.c +++ b/lib/lib_strncasecmp.c @@ -54,7 +54,7 @@ #ifndef CONFIG_ARCH_STRNCASECMP int strncasecmp(const char *cs, const char *ct, size_t nb) { - register int result = 0; + int result = 0; for (; nb > 0; nb--) { if ((result = (int)toupper(*cs) - (int)toupper(*ct)) != 0 || !*cs) diff --git a/netutils/thttpd/config.h b/netutils/thttpd/config.h index 2fe70539a8..dce61a32d8 100644 --- a/netutils/thttpd/config.h +++ b/netutils/thttpd/config.h @@ -88,6 +88,13 @@ # define CONFIG_THTTPD_SERVER_SOFTWARE "thttpd/2.25b 29dec2003-NuttX" # endif +# ifndef CONFIG_THTTPD_PATH +# ifdef CONFIG_CPP_HAVE_WARNING +# warning "CONFIG_THTTPD_PATH not defined" +# endif +# define CONFIG_THTTPD_PATH "/mnt/www" +# endif + # ifndef CONFIG_THTTPD_CGI_PATH # ifdef CONFIG_CPP_HAVE_WARNING # warning "CONFIG_THTTPD_CGI_PATH not defined" diff --git a/netutils/thttpd/libhttpd.c b/netutils/thttpd/libhttpd.c index 238f91076c..60366ecfd5 100644 --- a/netutils/thttpd/libhttpd.c +++ b/netutils/thttpd/libhttpd.c @@ -293,10 +293,6 @@ static void free_httpd_server(httpd_server * hs) free(hs->hostname); } - if (hs->cwd) - { - free(hs->cwd); - } free(hs); } } @@ -736,10 +732,14 @@ static int auth_check(httpd_conn *hc, char *dirname) #ifdef CONFIG_THTTPD_VHOST if (hc->hostdir[0] != '\0') - topdir = hc->hostdir; + { + topdir = hc->hostdir; + } else #endif - topdir = "."; + { + topdir = CONFIG_THTTPD_PATH; + } switch (auth_check2(hc, topdir)) { @@ -1418,7 +1418,7 @@ static char *expand_filename(char *path, char **restP, boolean tildemapped) *restP = r; if (checked[0] == '\0') { - (void)strcpy(checked, "."); + (void)strcpy(checked, CONFIG_THTTPD_PATH); } return checked; } @@ -1807,8 +1807,7 @@ static void ls_child(int argc, char **argv) strlen(hc->origfilename) + 1 + strlen(nameptrs[i])); - if (hc->expnfilename[0] == '\0' || - strcmp(hc->expnfilename, ".") == 0) + if (hc->expnfilename[0] == '\0' || strcmp(hc->expnfilename, ".") == 0) { (void)strcpy(name, nameptrs[i]); (void)strcpy(rname, nameptrs[i]); @@ -2109,11 +2108,11 @@ static void create_environment(httpd_conn *hc) (void)snprintf(buf, sizeof(buf), "/%s", hc->pathinfo); setenv("PATH_INFO", buf, TRUE); - l = strlen(hc->hs->cwd) + strlen(hc->pathinfo) + 1; + l = strlen(CONFIG_THTTPD_PATH) + strlen(hc->pathinfo) + 1; cp2 = NEW(char, l); if (cp2) { - (void)snprintf(cp2, l, "%s%s", hc->hs->cwd, hc->pathinfo); + (void)snprintf(cp2, l, "%s%s", CONFIG_THTTPD_PATH, hc->pathinfo); setenv("PATH_TRANSLATED", cp2, TRUE); } } @@ -3072,7 +3071,7 @@ static int really_start_request(httpd_conn *hc, struct timeval *nowP) cp = strrchr(dirname, '/'); if (!cp) { - (void)strcpy(dirname, "."); + (void)strcpy(dirname, CONFIG_THTTPD_PATH); } else { @@ -3381,12 +3380,10 @@ static size_t sockaddr_len(httpd_sockaddr *saP) * Public Functions ****************************************************************************/ -FAR httpd_server *httpd_initialize(FAR httpd_sockaddr *sa, FAR const char *cwd) +FAR httpd_server *httpd_initialize(FAR httpd_sockaddr *sa) { FAR httpd_server *hs; - nvdbg("cwd: %s\n", cwd); - /* Save the PID of the main thread */ main_thread = getpid(); @@ -3414,12 +3411,6 @@ FAR httpd_server *httpd_initialize(FAR httpd_sockaddr *sa, FAR const char *cwd) } hs->cgi_count = 0; - hs->cwd = strdup(cwd); - if (!hs->cwd) - { - ndbg("out of memory copying cwd\n"); - return (httpd_server *) 0; - } /* Initialize listen sockets */ @@ -3999,7 +3990,7 @@ int httpd_parse_request(httpd_conn *hc) } *url = '\0'; - if (strchr(reqhost, '/') != (char *)0 || reqhost[0] == '.') + if (strchr(reqhost, '/') != NULL || reqhost[0] == '.') { BADREQUEST("reqhost-2"); httpd_send_err(hc, 400, httpd_err400title, "", httpd_err400form, ""); @@ -4048,7 +4039,7 @@ int httpd_parse_request(httpd_conn *hc) if (hc->origfilename[0] == '\0') { - (void)strcpy(hc->origfilename, "."); + (void)strcpy(hc->origfilename, CONFIG_THTTPD_PATH); } /* Extract query string from encoded URL. */ @@ -4386,11 +4377,11 @@ int httpd_parse_request(httpd_conn *hc) if (hc->expnfilename[0] == '/') { - if (strncmp(hc->expnfilename, hc->hs->cwd, strlen(hc->hs->cwd)) == 0) + if (strncmp(hc->expnfilename, CONFIG_THTTPD_PATH, strlen(CONFIG_THTTPD_PATH)) == 0) { /* Elide the current directory. */ - (void)strcpy(hc->expnfilename, &hc->expnfilename[strlen(hc->hs->cwd)]); + (void)strcpy(hc->expnfilename, &hc->expnfilename[strlen(CONFIG_THTTPD_PATH)]); } #ifdef CONFIG_THTTPD_TILDE_MAP2 else if (hc->altdir[0] != '\0' && diff --git a/netutils/thttpd/libhttpd.h b/netutils/thttpd/libhttpd.h index 66410d343a..a2f2e25f28 100644 --- a/netutils/thttpd/libhttpd.h +++ b/netutils/thttpd/libhttpd.h @@ -167,7 +167,6 @@ typedef struct { char *hostname; int cgi_count; - char *cwd; int listen_fd; } httpd_server; @@ -245,7 +244,7 @@ typedef struct * Return (httpd_server*) 0 on error. */ -extern FAR httpd_server *httpd_initialize(FAR httpd_sockaddr *sa, FAR const char *cwd); +extern FAR httpd_server *httpd_initialize(FAR httpd_sockaddr *sa); /* Call to unlisten/close socket(s) listening for new connections. */ diff --git a/netutils/thttpd/thttpd.c b/netutils/thttpd/thttpd.c index 093d892942..bf0f27de48 100644 --- a/netutils/thttpd/thttpd.c +++ b/netutils/thttpd/thttpd.c @@ -752,7 +752,6 @@ static void thttpd_logstats(long secs) int thttpd_main(int argc, char **argv) { - char cwd[MAXPATHLEN + 1]; int num_ready; int cnum; FAR struct connect_s *conn; @@ -775,25 +774,6 @@ int thttpd_main(int argc, char **argv) sa.sin_addr.s_addr = HTONL(CONFIG_THTTPD_IPADDR); #endif - /* Switch directories if requested */ - -#ifdef CONFIG_THTTPD_DIR - ret = chdir(CONFIG_THTTPD_DIR); - if (ret < 0) - { - ndbg("chdir: %d\n", errno); - exit(1); - } -#endif - - /* Get current directory */ - - (void)getcwd(cwd, sizeof(cwd) - 1); - if (cwd[strlen(cwd) - 1] != '/') - { - (void)strcat(cwd, "/"); - } - /* Initialize the fdwatch package to handle all of the configured * socket descriptors */ @@ -822,7 +802,7 @@ int thttpd_main(int argc, char **argv) /* Initialize the HTTP layer */ nvdbg("Calling httpd_initialize()\n"); - hs = httpd_initialize(&sa, cwd); + hs = httpd_initialize(&sa); if (!hs) { ndbg("httpd_initialize() failed\n");