diff options
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; } |