diff options
author | Vincent Douillet <vincent@vdouillet.fr> | 2024-09-05 12:58:22 +0200 |
---|---|---|
committer | Vincent Douillet <vincent@vdouillet.fr> | 2024-09-06 12:22:20 +0200 |
commit | 35a145fd161fb4d4f19aa9820b50438695b94414 (patch) | |
tree | 00e9f341d5b7e0a6874efbe9fafc0500cf13cd2d /download.c | |
parent | 9b8d38ab209c6e7e747d6d420f1b105fe858c7eb (diff) |
browse: add upload button
Diffstat (limited to 'download.c')
-rw-r--r-- | download.c | 47 |
1 files changed, 10 insertions, 37 deletions
@@ -47,10 +47,10 @@ #include "util.h" /* - * download url = r->pname / DOWNLOAD_URL / file->path / file->name + * download url = r->pname / DOWNLOAD_URL / file->path */ size_t -build_download_url(struct kreq * r, struct file * file) +build_download_url(const struct kreq * r, struct file * file) { char action_url[PATH_MAX]; size_t action_url_len; @@ -60,7 +60,7 @@ build_download_url(struct kreq * r, struct file * file) return 0; action_url_len = url_build(action_url, PATH_MAX, r->pname, DOWNLOAD_URL, - file->path, file->name, NULL); + file->path, NULL); if (action_url_len == 0 || action_url_len >= PATH_MAX) { kutil_warn(r, NULL, "download: action URL overflow: %s", action_url); @@ -79,7 +79,6 @@ build_download_url(struct kreq * r, struct file * file) struct http_ret download(struct kreq * r) { - char *file_name, *data_dir; void *buffer; struct file *f; int fd; @@ -93,16 +92,6 @@ download(struct kreq * r) KHTTP_200, "" }; - /* check that data dir is configured */ - data_dir = config_data_dir(); - if (data_dir == NULL) { - ret = (struct http_ret) { - KHTTP_400, - "download: data dir not configured" - }; - goto end; - } - /* check that the requested URL can be safely processed */ if (strlen(r->path) == 0 || !check_request_path(r->path, r->suffix)) { ret = (struct http_ret) { @@ -131,36 +120,20 @@ download(struct kreq * r) goto end; } } - - path_size = url_build(file_path, PATH_MAX, data_dir, request_path, - NULL); - if (path_size == 0) { + /* build file metadata */ + f = file_new(request_path); + if (f == NULL) { ret = (struct http_ret) { KHTTP_404, - "download: unable to build file path" - }; - goto end; - } - if (path_size >= PATH_MAX) { - ret = (struct http_ret) { - KHTTP_414, - "download: request too long" + "download: file metadata failure" }; goto end; } - /* build file metadata */ - file_name = str_split(request_path, '/'); - if (file_name == NULL) - f = file_new("/", 1, request_path, strlen(request_path)); /* ROOT file */ - else { - f = file_new(request_path, strlen(request_path), file_name, - strlen(file_name)); - free(file_name);/* copied in file_new */ - } - if (f == NULL) { + path_size = file_get_data_path(f, file_path, PATH_MAX); + if (path_size == 0 || path_size >= PATH_MAX) { ret = (struct http_ret) { KHTTP_404, - "download: file metadata failure" + "download: unable to build file path" }; goto end; } |