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:
parent
e1ec46aeca
commit
534fa87409
@ -2362,7 +2362,10 @@ extern void up_ledoff(int led);
|
||||
<code>CONFIG_THTTPD_SERVER_SOFTWARE</code>: SERVER_SOFTWARE: response
|
||||
</li>
|
||||
<li>
|
||||
<code>CONFIG_THTTPD_CGI_PATH</code>:
|
||||
<code>CONFIG_THTTPD_PATH</code>: Server working directory
|
||||
</li>
|
||||
<li>
|
||||
<code>CONFIG_THTTPD_CGI_PATH</code>: Path to CGI executables
|
||||
</li>
|
||||
<li>
|
||||
<code>CONFIG_THTTPD_CGI_PATTERN</code>: Only CGI programs matching this
|
||||
|
@ -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.
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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)
|
||||
|
@ -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)
|
||||
|
@ -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"
|
||||
|
@ -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");
|
||||
|
Loading…
Reference in New Issue
Block a user