summaryrefslogtreecommitdiff
path: root/browse.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 /browse.c
parent4be89075c5bb5793f8c79da8f8df1accc1f0168f (diff)
get data dir from env variable
Diffstat (limited to 'browse.c')
-rw-r--r--browse.c13
1 files changed, 12 insertions, 1 deletions
diff --git a/browse.c b/browse.c
index 51f41dd..868388f 100644
--- a/browse.c
+++ b/browse.c
@@ -208,6 +208,7 @@ browse(struct kreq * r)
{
size_t url_len;
char current_dir[PATH_MAX];
+ char *data_dir;
struct file *file;
struct page_template *tmpl;
struct http_ret ret;
@@ -223,6 +224,16 @@ browse(struct kreq * r)
KHTTP_200, ""
};
+ /* check that data dir is configured */
+ data_dir = config_data_dir();
+ if (data_dir == NULL) {
+ ret = (struct http_ret) {
+ KHTTP_400,
+ "browse: data dir is not configured"
+ };
+ goto end;
+ }
+
/* check that the requested URL can be safely processed */
if (!check_request_path(r->path, r->suffix)) {
ret = (struct http_ret) {
@@ -232,7 +243,7 @@ browse(struct kreq * r)
goto end;
}
/* list requested directory content */
- url_len = url_build(current_dir, PATH_MAX, DATA_DIR, r->path,
+ url_len = url_build(current_dir, PATH_MAX, data_dir, r->path,
NULL);
if (url_len == 0) {
ret = (struct http_ret) {