diff options
| author | Xavier Del Campo Romero <xavi.dcr@tutanota.com> | 2023-09-09 00:47:14 +0200 |
|---|---|---|
| committer | Xavier Del Campo Romero <xavi.dcr@tutanota.com> | 2023-09-09 00:50:22 +0200 |
| commit | fcef3b99b86312aaeb9e1cae88179abbfda90dff (patch) | |
| tree | 6491361196c84db29b46675fb6563d406bf78f6c | |
| parent | 7471da3886355199185a3b05a45b4c9b845d5a89 (diff) | |
| download | slcl-fcef3b99b86312aaeb9e1cae88179abbfda90dff.tar.gz | |
Check directory on uploads
For historical reasons, slweb used to check for a name called "dir" on
multipart/form-data POST requests. However, stricly speaking this is
application logic, so it has been now moved from slweb to slcl.
This has resulted in a couple of breaking changes in slweb that had to
be updated on slcl.
| -rw-r--r-- | main.c | 19 | ||||
| m--------- | slweb | 0 |
2 files changed, 16 insertions, 3 deletions
@@ -1139,12 +1139,25 @@ end: return ret; } +static const char *get_upload_dir(const struct http_post *const po) +{ + for (size_t i = 0; i < po->npairs; i++) + { + const struct http_post_pair *p = &po->pairs[i]; + + if (!strcmp(p->name, "dir")) + return p->value; + } + + return NULL; +} + static int upload_files(const struct http_payload *const p, struct http_response *const r, const struct auth *const a) { const struct http_post *const po = &p->u.post; const char *const root = auth_dir(a), *const user = p->cookie.field, - *const dir = po->dir; + *const dir = get_upload_dir(po); if (!po->files) { @@ -1181,9 +1194,9 @@ static int upload_files(const struct http_payload *const p, return page_bad_request(r); } - for (size_t i = 0; i < po->n; i++) + for (size_t i = 0; i < po->nfiles; i++) { - if (upload_file(&po->files[i], user, root, po->dir)) + if (upload_file(&po->files[i], user, root, dir)) { fprintf(stderr, "%s: upload_file failed\n", __func__); return -1; diff --git a/slweb b/slweb -Subproject 6c7faa7f9063aca15345c9aeb95d651a5fe983f +Subproject 34d716082a0136056373f3d0c6ed7abce45484b |
