directory formatting code in http server file handler

This commit is contained in:
2022-12-23 14:44:55 +00:00
parent b4cadfeed3
commit 56bd1af653
3 changed files with 46 additions and 14 deletions

View File

@ -163,7 +163,8 @@ enum hio_svc_htts_txt_option_t
struct hio_svc_htts_file_cbs_t
{
int (*bfmt_dir) (hio_svc_htts_t* htts, const hio_bch_t* name);
int (*bfmt_dir) (hio_svc_htts_t* htts, int fd, const hio_bch_t* name, int type, void* ctx);
void *ctx;
};
typedef struct hio_svc_htts_file_cbs_t hio_svc_htts_file_cbs_t;

View File

@ -735,25 +735,28 @@ static int open_peer_with_mode (file_t* file, const hio_bch_t* actual_file, int
struct dirent* de;
unlink (alt_file);
while ((de = readdir(dp)))
if (file->cbs && file->cbs->bfmt_dir)
{
/* TODO: do buffering ... */
#if 0
/* TODO: call a directory entry formatter callback?? */
if (file->cbs && file->cbs->bfmt_dir)
file->cbs->bfmt_dir (file->htts, alt_fd, HIO_NULL, 0, file->cbs->ctx);
while ((de = readdir(dp)))
{
file->cbs->bfmt_dir(file->htts, de->d_name);
file->cbs->bfmt_dir (file->htts, alt_fd, de->d_name, 1, file->cbs->ctx);
}
#endif
if (strcmp(de->d_name, ".") != 0)
{
write (alt_fd, de->d_name, strlen(de->d_name));
write (alt_fd, "\n", 1);
file->cbs->bfmt_dir (file->htts, alt_fd, HIO_NULL, 2, file->cbs->ctx);
}
else
{
while ((de = readdir(dp)))
{
if (strcmp(de->d_name, ".") != 0)
{
write (alt_fd, de->d_name, strlen(de->d_name));
write (alt_fd, "\n", 1);
}
}
}
lseek (alt_fd, SEEK_SET, 0);
close (file->peer);
file->peer = alt_fd;
opened_file = alt_file;