diff options
| author | Xavier Del Campo Romero <xavi.dcr@tutanota.com> | 2023-03-08 18:50:15 +0100 |
|---|---|---|
| committer | Xavier Del Campo Romero <xavi.dcr@tutanota.com> | 2023-03-08 18:50:15 +0100 |
| commit | f4c16b8e56f38463ac866223aa68e4582518f7d7 (patch) | |
| tree | 5f152a43298aee99d200322d9f87eb6eb613f3d7 | |
| parent | 7176bd3c94950e9aa0731cc4f9bb266974dd59da (diff) | |
| download | slcl-f4c16b8e56f38463ac866223aa68e4582518f7d7.tar.gz | |
main.c: Always append trailing slash to directories
Otherwise, slcl would fail to generate the URLs for the elements inside
a directory, because of how cust_dirname worked, which also turned out
to be redundant.
| -rw-r--r-- | main.c | 46 |
1 files changed, 8 insertions, 38 deletions
@@ -451,30 +451,6 @@ static bool path_isrel(const char *const path) return false; } -static char *cust_dirname(char *const d) -{ - /* - path dirname cust_dirname - /usr/lib /usr /usr/ - /usr/ / /usr/ - usr . . - / / / - . . . - .. . . - */ - - if (!strcmp(d, ".")) - return d; - - char *const s = strrchr(d, '/'); - - if (!s) - return "."; - - *(s + 1) = '\0'; - return d; -} - static int getnode(const struct http_payload *const p, struct http_response *const r, void *const user) { @@ -496,10 +472,11 @@ static int getnode(const struct http_payload *const p, } int ret = -1; - struct dynstr root, d; - char *const dird = strdup(p->resource), *dir = NULL; - const char *const adir = auth_dir(a); + struct dynstr dir, root, d; + const char *const adir = auth_dir(a), + *const sep = p->resource[strlen(p->resource) - 1] != '/' ? "/" : ""; + dynstr_init(&dir); dynstr_init(&d); dynstr_init(&root); @@ -508,16 +485,9 @@ static int getnode(const struct http_payload *const p, fprintf(stderr, "%s: auth_dir failed\n", __func__); goto end; } - else if (!dird) - { - fprintf(stderr, "%s: strdup(3) failed: %s\n", - __func__, strerror(errno)); - goto end; - } - else if (!(dir = cust_dirname(dird))) + else if (dynstr_append(&dir, "%s%s", p->resource, sep)) { - fprintf(stderr, "%s: dirname(3) failed: %s\n", - __func__, strerror(errno)); + fprintf(stderr, "%s: dynstr_append dird failed\n", __func__); goto end; } else if (dynstr_append(&root, "%s/user/%s/", adir, username) @@ -547,12 +517,12 @@ static int getnode(const struct http_payload *const p, .max = max }, *const ppq = available ? &pq : NULL; - ret = page_resource(r, dir, root.str, d.str, ppq); + ret = page_resource(r, dir.str, root.str, d.str, ppq); end: + dynstr_free(&dir); dynstr_free(&d); dynstr_free(&root); - free(dird); return ret; } |
