diff --git a/bin/webs.c b/bin/webs.c index d3a2221..4c59569 100644 --- a/bin/webs.c +++ b/bin/webs.c @@ -74,6 +74,32 @@ done: } } + +static void bfmt_dir (hio_svc_htts_t* htts, int fd, const hio_bch_t* name, int type, void* ctx) +{ + /* TODO: do bufferring */ + /* "name */ + if (name) + { +/* TODO: get the directory name +check if the entry is a directory or something else */ + write (fd, "
  • ", 2); + write (fd, name, strlen(name)); + write (fd, "", 4); + } + else if (type == 0) + { + write (fd, "", 12); + + } + else + { + write (fd, "", 14); + } +} + static int process_http_request (hio_svc_htts_t* htts, hio_dev_sck_t* csck, hio_htre_t* req) { htts_ext_t* ext = hio_svc_htts_getxtn(htts); @@ -81,6 +107,8 @@ static int process_http_request (hio_svc_htts_t* htts, hio_dev_sck_t* csck, hio_ hio_http_method_t mth; const hio_bch_t* qpath; + static hio_svc_htts_file_cbs_t fcbs = { bfmt_dir, HIO_NULL }; + hio_htre_perdecqpath (req); mth = hio_htre_getqmethodtype(req); @@ -97,7 +125,7 @@ static int process_http_request (hio_svc_htts_t* htts, hio_dev_sck_t* csck, hio_ /* TODO: make HIO_SVC_HTTS_FILE_DIR a cli option */ int fopts = 0; if (ext->ai->file_list_dir) fopts |= HIO_SVC_HTTS_FILE_LIST_DIR; - if (hio_svc_htts_dofile(htts, csck, req, ext->ai->docroot, qpath, HIO_NULL, fopts, HIO_NULL) <= -1) goto oops; + if (hio_svc_htts_dofile(htts, csck, req, ext->ai->docroot, qpath, HIO_NULL, fopts, &fcbs) <= -1) goto oops; } #if 0 else diff --git a/lib/hio-http.h b/lib/hio-http.h index d6c4d9e..11c38a6 100644 --- a/lib/hio-http.h +++ b/lib/hio-http.h @@ -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; diff --git a/lib/http-file.c b/lib/http-file.c index 1bae85c..4ceb3b8 100644 --- a/lib/http-file.c +++ b/lib/http-file.c @@ -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;