Merged in masayuki2009/nuttx.apps/fix_webserver_with_period (pull request #183)
netutils/webserver: Fix directory listing containing period in name Signed-off-by: Masayuki Ishikawa <Masayuki.Ishikawa@jp.sony.com> Approved-by: Gregory Nutt <gnutt@nuttx.org>
This commit is contained in:
parent
2bb4834775
commit
9eff955556
@ -199,6 +199,7 @@ uint16_t httpd_fs_count(char *name);
|
|||||||
int httpd_send_datachunk(int sockfd, void *data, int len, bool chunked);
|
int httpd_send_datachunk(int sockfd, void *data, int len, bool chunked);
|
||||||
|
|
||||||
#ifdef CONFIG_NETUTILS_HTTPD_DIRLIST
|
#ifdef CONFIG_NETUTILS_HTTPD_DIRLIST
|
||||||
|
bool httpd_is_file(FAR const char *filename);
|
||||||
ssize_t httpd_dirlist(int outfd, FAR struct httpd_fs_file *file);
|
ssize_t httpd_dirlist(int outfd, FAR struct httpd_fs_file *file);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -494,11 +494,7 @@ static int send_headers(struct httpd_state *pstate, int status, int len)
|
|||||||
ptr = strrchr(pstate->ht_filename, ISO_period);
|
ptr = strrchr(pstate->ht_filename, ISO_period);
|
||||||
if (ptr == NULL)
|
if (ptr == NULL)
|
||||||
{
|
{
|
||||||
#ifdef CONFIG_NETUTILS_HTTPD_DIRLIST
|
|
||||||
mime = "text/html";
|
|
||||||
#else
|
|
||||||
mime = "application/octet-stream";
|
mime = "application/octet-stream";
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -514,6 +510,15 @@ static int send_headers(struct httpd_state *pstate, int status, int len)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef CONFIG_NETUTILS_HTTPD_DIRLIST
|
||||||
|
if (false == httpd_is_file(pstate->ht_filename))
|
||||||
|
{
|
||||||
|
/* we assume that it's a directory */
|
||||||
|
|
||||||
|
mime = "text/html";
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
if (len >= 0)
|
if (len >= 0)
|
||||||
{
|
{
|
||||||
(void)snprintf(contentlen, HTTPD_MAX_CONTENTLEN,
|
(void)snprintf(contentlen, HTTPD_MAX_CONTENTLEN,
|
||||||
|
@ -114,6 +114,38 @@
|
|||||||
* Public Functions
|
* Public Functions
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: httpd_is_file
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
bool httpd_is_file(FAR const char *filename)
|
||||||
|
{
|
||||||
|
char *path;
|
||||||
|
int fd;
|
||||||
|
bool ret = false;
|
||||||
|
|
||||||
|
path = malloc(CONFIG_NAME_MAX);
|
||||||
|
ASSERT(path);
|
||||||
|
|
||||||
|
snprintf(path, CONFIG_NAME_MAX, "%s/%s",
|
||||||
|
CONFIG_NETUTILS_HTTPD_PATH, filename);
|
||||||
|
|
||||||
|
fd = open(path, "O_RDONLY");
|
||||||
|
|
||||||
|
if (-1 != fd)
|
||||||
|
{
|
||||||
|
close(fd);
|
||||||
|
ret = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
free(path);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: httpd_dirlist
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
ssize_t httpd_dirlist(int outfd, FAR struct httpd_fs_file *file)
|
ssize_t httpd_dirlist(int outfd, FAR struct httpd_fs_file *file)
|
||||||
{
|
{
|
||||||
struct dirent *dent;
|
struct dirent *dent;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user