enhancing the directory handling in http-file.c
This commit is contained in:
parent
42765faff6
commit
8613cbffc4
16
bin/webs.c
16
bin/webs.c
@ -76,7 +76,7 @@ done:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void bfmt_dir (hio_svc_htts_t* htts, int fd, hio_svc_htts_file_bfmt_dir_type_t type, const hio_bch_t* name, void* ctx)
|
static void bfmt_dir (hio_svc_htts_t* htts, int fd, const hio_bch_t* qpath, hio_svc_htts_file_bfmt_dir_type_t type, const hio_bch_t* name, void* ctx)
|
||||||
{
|
{
|
||||||
/* TODO: do bufferring */
|
/* TODO: do bufferring */
|
||||||
/* "<a href="urlencoded-name">name</a> */
|
/* "<a href="urlencoded-name">name</a> */
|
||||||
@ -93,8 +93,20 @@ static void bfmt_dir (hio_svc_htts_t* htts, int fd, hio_svc_htts_file_bfmt_dir_t
|
|||||||
{
|
{
|
||||||
HIO_ASSERT (hio_svc_htts_gethio(htts), name != HIO_NULL);
|
HIO_ASSERT (hio_svc_htts_gethio(htts), name != HIO_NULL);
|
||||||
|
|
||||||
|
if (name[0] == '.' && name[1] == '\0') return;
|
||||||
|
|
||||||
|
if (qpath[0] == '\0' || (qpath[0] == '/' && qpath[1] == '\0'))
|
||||||
|
{
|
||||||
|
/* at the root */
|
||||||
|
if (name[0] == '.' && name[1] == '.' && name[2] == '\0') return;
|
||||||
|
}
|
||||||
|
|
||||||
/* TODO: get the directory name
|
/* TODO: get the directory name
|
||||||
check if the entry is a directory or something else */
|
check if the entry is a directory or something else
|
||||||
|
do escaping...
|
||||||
|
show file size?
|
||||||
|
append / if the file is a directory
|
||||||
|
*/
|
||||||
write (fd, "<li><a href=\"", 13);
|
write (fd, "<li><a href=\"", 13);
|
||||||
write (fd, name, strlen(name));
|
write (fd, name, strlen(name));
|
||||||
write (fd, "\">", 2);
|
write (fd, "\">", 2);
|
||||||
|
@ -171,7 +171,7 @@ typedef enum hio_svc_htts_file_bfmt_dir_type_t hio_svc_htts_file_bfmt_dir_type_t
|
|||||||
|
|
||||||
struct hio_svc_htts_file_cbs_t
|
struct hio_svc_htts_file_cbs_t
|
||||||
{
|
{
|
||||||
int (*bfmt_dir) (hio_svc_htts_t* htts, int fd, hio_svc_htts_file_bfmt_dir_type_t type, const hio_bch_t* name, void* ctx);
|
int (*bfmt_dir) (hio_svc_htts_t* htts, int fd, const hio_bch_t* qpath, hio_svc_htts_file_bfmt_dir_type_t type, const hio_bch_t* name, void* ctx);
|
||||||
void *ctx;
|
void *ctx;
|
||||||
};
|
};
|
||||||
typedef struct hio_svc_htts_file_cbs_t hio_svc_htts_file_cbs_t;
|
typedef struct hio_svc_htts_file_cbs_t hio_svc_htts_file_cbs_t;
|
||||||
|
@ -719,12 +719,12 @@ static int open_peer_for_dir_listing (file_t* file, const hio_bch_t* dir_path, i
|
|||||||
if (file->cbs && file->cbs->bfmt_dir)
|
if (file->cbs && file->cbs->bfmt_dir)
|
||||||
{
|
{
|
||||||
/* TODO: can support sorting?? */
|
/* TODO: can support sorting?? */
|
||||||
file->cbs->bfmt_dir (file->htts, alt_fd, HIO_SVC_HTTS_FILE_BFMT_DIR_HEADER, HIO_NULL, file->cbs->ctx);
|
file->cbs->bfmt_dir (file->htts, alt_fd, file->req_qpath, HIO_SVC_HTTS_FILE_BFMT_DIR_HEADER, HIO_NULL, file->cbs->ctx);
|
||||||
while ((de = readdir(dp)))
|
while ((de = readdir(dp)))
|
||||||
{
|
{
|
||||||
file->cbs->bfmt_dir (file->htts, alt_fd, HIO_SVC_HTTS_FILE_BFMT_DIR_ENTRY, de->d_name, file->cbs->ctx);
|
file->cbs->bfmt_dir (file->htts, alt_fd, file->req_qpath, HIO_SVC_HTTS_FILE_BFMT_DIR_ENTRY, de->d_name, file->cbs->ctx);
|
||||||
}
|
}
|
||||||
file->cbs->bfmt_dir (file->htts, alt_fd, HIO_SVC_HTTS_FILE_BFMT_DIR_FOOTER, HIO_NULL, file->cbs->ctx);
|
file->cbs->bfmt_dir (file->htts, alt_fd, file->req_qpath, HIO_SVC_HTTS_FILE_BFMT_DIR_FOOTER, HIO_NULL, file->cbs->ctx);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user