mirror of
https://github.com/apache/nuttx.git
synced 2026-06-06 08:36:24 +08:00
Get rid of cwd in THTTPD
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@2021 42af7a65-404d-4744-a932-0658087f49c3
This commit is contained in:
@@ -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"
|
||||
|
||||
+16
-25
@@ -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' &&
|
||||
|
||||
@@ -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. */
|
||||
|
||||
|
||||
@@ -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");
|
||||
|
||||
Reference in New Issue
Block a user