diff options
Diffstat (limited to 'page.c')
| -rw-r--r-- | page.c | 26 |
1 files changed, 25 insertions, 1 deletions
@@ -1,6 +1,7 @@ #define _POSIX_C_SOURCE 200809L #include "page.h" +#include "zip.h" #include <libweb/html.h> #include <libweb/http.h> #include <dynstr.h> @@ -1812,6 +1813,21 @@ static bool preview(const struct page_resource *const pr) return false; } +static bool download(const struct page_resource *const pr) +{ + for (size_t i = 0; i < pr->n_args; i++) + { + const struct http_arg *const a = &pr->args[i]; + + if (!strcmp(a->key, "download") + && (!strcmp(a->value, "1") + || !strcasecmp(a->value, "true"))) + return true; + } + + return false; +} + int page_resource(const struct page_resource *const pr) { int ret = -1; @@ -1840,7 +1856,15 @@ int page_resource(const struct page_resource *const pr) if (S_ISDIR(m)) { - if ((ret = list_dir(pr))) + if (download(pr)) + { + if ((ret = zip(pr->res, pr->r))) + { + fprintf(stderr, "%s: zip_dir failed\n", __func__); + goto end; + } + } + else if ((ret = list_dir(pr))) { if (ret < 0) { |
