summaryrefslogtreecommitdiff
path: root/download.c
diff options
context:
space:
mode:
Diffstat (limited to 'download.c')
-rw-r--r--download.c37
1 files changed, 9 insertions, 28 deletions
diff --git a/download.c b/download.c
index f4a1881..bff1dd6 100644
--- a/download.c
+++ b/download.c
@@ -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);