fixed bugs in bin/webs.c
This commit is contained in:
parent
34e9e03b8c
commit
f6cadbf6c1
23
bin/webs.c
23
bin/webs.c
@ -23,7 +23,7 @@ typedef struct arg_info_t arg_info_t;
|
|||||||
|
|
||||||
struct htts_ext_t
|
struct htts_ext_t
|
||||||
{
|
{
|
||||||
arg_info_t* ai;
|
const arg_info_t* ai;
|
||||||
};
|
};
|
||||||
typedef struct htts_ext_t htts_ext_t;
|
typedef struct htts_ext_t htts_ext_t;
|
||||||
|
|
||||||
@ -102,7 +102,7 @@ static int file_open_dir_list (hio_svc_htts_t* htts, const hio_bch_t* qpath, con
|
|||||||
|
|
||||||
if (ext->ai->file_load_index_page)
|
if (ext->ai->file_load_index_page)
|
||||||
{
|
{
|
||||||
const hio_bch_t* index_path;
|
hio_bch_t* index_path;
|
||||||
|
|
||||||
index_path = hio_svc_htts_dupmergepaths(htts, dir_path, "index.html");
|
index_path = hio_svc_htts_dupmergepaths(htts, dir_path, "index.html");
|
||||||
if (HIO_UNLIKELY(!index_path)) goto oops;
|
if (HIO_UNLIKELY(!index_path)) goto oops;
|
||||||
@ -135,7 +135,7 @@ static int file_open_dir_list (hio_svc_htts_t* htts, const hio_bch_t* qpath, con
|
|||||||
unlink (file_path);
|
unlink (file_path);
|
||||||
|
|
||||||
write (fd, "<html><body>", 12);
|
write (fd, "<html><body>", 12);
|
||||||
if (qpath[0] == '\0' || (qpath[0] == '/' && qpath[1] == '\0'))
|
if (!(qpath[0] == '\0' || (qpath[0] == '/' && qpath[1] == '\0')))
|
||||||
write (fd, "<li><a href=\"..\">..</a>", 23);
|
write (fd, "<li><a href=\"..\">..</a>", 23);
|
||||||
|
|
||||||
/* TODO: sorting, other informatino like size, */
|
/* TODO: sorting, other informatino like size, */
|
||||||
@ -143,17 +143,28 @@ static int file_open_dir_list (hio_svc_htts_t* htts, const hio_bch_t* qpath, con
|
|||||||
while ((de = readdir(dp)))
|
while ((de = readdir(dp)))
|
||||||
{
|
{
|
||||||
struct stat st;
|
struct stat st;
|
||||||
|
hio_bch_t* tmp_path;
|
||||||
|
int n;
|
||||||
|
|
||||||
if ((de->d_name[0] == '.' && de->d_name[1] == '\0') ||
|
if ((de->d_name[0] == '.' && de->d_name[1] == '\0') ||
|
||||||
(de->d_name[0] == '.' && de->d_name[1] == '.' && de->d_name[2] == '\0')) continue;
|
(de->d_name[0] == '.' && de->d_name[1] == '.' && de->d_name[2] == '\0')) continue;
|
||||||
|
|
||||||
if (stat(de->d_name, &st) <= -1) continue;
|
tmp_path = hio_svc_htts_dupmergepaths(htts, dir_path, de->d_name);
|
||||||
|
if (HIO_UNLIKELY(!tmp_path)) continue;
|
||||||
|
n = stat(tmp_path, &st);
|
||||||
|
hio_freemem (hio, tmp_path);
|
||||||
|
if (HIO_UNLIKELY(n <= -1)) continue;
|
||||||
|
|
||||||
write (fd, "<li><a href=\"", 13);
|
write (fd, "<li><a href=\"", 13);
|
||||||
write (fd, de->d_name, strlen(de->d_name)); /* TOOD: url escaping*/
|
{
|
||||||
|
char tmp[1000]; /* TODO:use dynamic buffer?? */
|
||||||
|
hio_perenc_http_bcstr(0, de->d_name, tmp, HIO_NULL); /* url encoding */
|
||||||
|
//write (fd, de->d_name, strlen(de->d_name));
|
||||||
|
write (fd, tmp, strlen(tmp));
|
||||||
|
}
|
||||||
if (S_ISDIR(st.st_mode)) write (fd, "/", 1);
|
if (S_ISDIR(st.st_mode)) write (fd, "/", 1);
|
||||||
write (fd, "\">", 2);
|
write (fd, "\">", 2);
|
||||||
write (fd, de->d_name, strlen(de->d_name));
|
write (fd, de->d_name, strlen(de->d_name)); /* TODO: html entity encoding */
|
||||||
if (S_ISDIR(st.st_mode)) write (fd, "/", 1);
|
if (S_ISDIR(st.st_mode)) write (fd, "/", 1);
|
||||||
write (fd, "</a>", 4);
|
write (fd, "</a>", 4);
|
||||||
}
|
}
|
||||||
|
@ -236,7 +236,7 @@ HIO_EXPORT int hio_is_perenced_http_bcstr (
|
|||||||
* The hio_perdec_http_bcstr() function performs percent-decoding over a string.
|
* The hio_perdec_http_bcstr() function performs percent-decoding over a string.
|
||||||
* The caller must ensure that the output buffer \a buf is large enough.
|
* The caller must ensure that the output buffer \a buf is large enough.
|
||||||
* If \a ndecs is not #HIO_NULL, it is set to the number of characters
|
* If \a ndecs is not #HIO_NULL, it is set to the number of characters
|
||||||
* decoded. 0 means no characters in the input string required decoding
|
* decoded. 0 means no characters in the input string required decoding
|
||||||
* \return the length of the output string.
|
* \return the length of the output string.
|
||||||
*/
|
*/
|
||||||
HIO_EXPORT hio_oow_t hio_perdec_http_bcstr (
|
HIO_EXPORT hio_oow_t hio_perdec_http_bcstr (
|
||||||
@ -259,7 +259,7 @@ HIO_EXPORT hio_oow_t hio_perdec_http_bcs (
|
|||||||
* The hio_perenc_http_bcstr() function performs percent-encoding over a string.
|
* The hio_perenc_http_bcstr() function performs percent-encoding over a string.
|
||||||
* The caller must ensure that the output buffer \a buf is large enough.
|
* The caller must ensure that the output buffer \a buf is large enough.
|
||||||
* If \a nencs is not #HIO_NULL, it is set to the number of characters
|
* If \a nencs is not #HIO_NULL, it is set to the number of characters
|
||||||
* encoded. 0 means no characters in the input string required encoding.
|
* encoded. 0 means no characters in the input string required encoding.
|
||||||
* \return the length of the output string.
|
* \return the length of the output string.
|
||||||
*/
|
*/
|
||||||
HIO_EXPORT hio_oow_t hio_perenc_http_bcstr (
|
HIO_EXPORT hio_oow_t hio_perenc_http_bcstr (
|
||||||
|
Loading…
Reference in New Issue
Block a user