diff options
author | Vincent Douillet <vincent@vdouillet.fr> | 2024-05-13 22:04:01 +0200 |
---|---|---|
committer | Vincent Douillet <vincent@vdouillet.fr> | 2024-05-13 22:31:42 +0200 |
commit | 4be89075c5bb5793f8c79da8f8df1accc1f0168f (patch) | |
tree | 6407385f4d4827651a10a495f829a6bfa0109f3a /download.c | |
parent | 10eb77f9323110c55f88195c5b8207eb524baa73 (diff) |
fix encodings in headers and file paths
Diffstat (limited to 'download.c')
-rw-r--r-- | download.c | 37 |
1 files changed, 9 insertions, 28 deletions
@@ -42,6 +42,7 @@ #include "download.h" #include "file.h" #include "http.h" +#include "str.h" #include "url.h" #include "util.h" @@ -75,32 +76,6 @@ build_download_url(struct kreq * r, struct file * file) return action_url_len; } -static char * -strsplit(char *str, char c) -{ - char *right, *result; - size_t right_len; - - right = strrchr(str, c); - if (!right || right == str) - return NULL; - - /* move right part to new buffer */ - right_len = strlen(right); - result = malloc(sizeof(char) * right_len); - if (result == NULL) - return NULL; - - if (strlcpy(result, right + 1, right_len) >= right_len) { - free(result); - return NULL; - } - /* remove right part from src buffer */ - *right = '\0'; - - return result; -} - struct http_ret download(struct kreq * r) { @@ -164,7 +139,7 @@ download(struct kreq * r) goto end; } /* build file metadata */ - file_name = strsplit(request_path, '/'); + file_name = str_split(request_path, '/'); if (file_name == NULL) f = file_new("/", 1, request_path, strlen(request_path)); /* ROOT file */ else { @@ -200,7 +175,13 @@ download(struct kreq * r) } } /* write the file */ - http_open_file(r, KHTTP_200, f); + if (!http_open_file(r, KHTTP_200, f)) { + ret = (struct http_ret) { + KHTTP_500, + "download: filename url encoding failed" + }; + goto end; + } if (f->size > 0) K_OK(khttp_write(r, (const char *) buffer, f->size), r); |