summaryrefslogtreecommitdiff
path: root/url.c
diff options
context:
space:
mode:
authorVincent Douillet <vincent@vdouillet.fr>2024-08-29 17:46:14 +0200
committerVincent Douillet <vincent@vdouillet.fr>2024-08-29 21:53:35 +0200
commitf005928d63165d28b32851f04f29055a4d0cdad5 (patch)
tree5386f28a558046dbe6e93b439f5e026441224c56 /url.c
parent4be89075c5bb5793f8c79da8f8df1accc1f0168f (diff)
get data dir from env variable
Diffstat (limited to 'url.c')
-rw-r--r--url.c16
1 files changed, 10 insertions, 6 deletions
diff --git a/url.c b/url.c
index 228efeb..3e82821 100644
--- a/url.c
+++ b/url.c
@@ -41,10 +41,14 @@ bool
check_request_path(char *path, char *suffix)
{
char p[PATH_MAX], resolved[PATH_MAX];
- char *rp;
+ char *rp, *data_dir;
+
+ data_dir = config_data_dir();
+ if (data_dir == NULL)
+ return false;
/* build absolute path from DATA_DIR */
- if (strlcpy(p, DATA_DIR, sizeof(p)) >= sizeof(p))
+ if (strlcpy(p, data_dir, sizeof(p)) >= sizeof(p))
return false;
if (strlcat(p, "/", sizeof(p)) >= sizeof(p))
return false;
@@ -52,9 +56,9 @@ check_request_path(char *path, char *suffix)
return false;
if (strlen(suffix) > 0) {
/* add suffix */
- if(strlcat(p, ".", sizeof(p)) >= sizeof(p))
+ if (strlcat(p, ".", sizeof(p)) >= sizeof(p))
return false;
- if(strlcat(p, suffix, sizeof(p)) >= sizeof(p))
+ if (strlcat(p, suffix, sizeof(p)) >= sizeof(p))
return false;
}
@@ -65,7 +69,7 @@ check_request_path(char *path, char *suffix)
/* path must start with DATA_DIR */
rp[PATH_MAX - 1] = '\0';
- if (strstr(rp, DATA_DIR) != rp)
+ if (strstr(rp, data_dir) != rp)
return false;
return true;
@@ -92,7 +96,7 @@ url_build(char *dst, size_t dst_size,...)
if (path[0] == '.' && path[1] == '\0')
continue;
- if (path[0] != '/' && dst[w_size - 1] != '/')
+ if (path[0] != '/' && w_size > 0 && dst[w_size - 1] != '/')
strlcat(dst, "/", dst_size);
w_size = strlcat(dst, path, dst_size);