Check if requested OPDS dir exists
This commit is contained in:
17
src/main.c
17
src/main.c
@@ -1,5 +1,6 @@
|
|||||||
#include <microhttpd.h>
|
#include <microhttpd.h>
|
||||||
#include <sha256.h>
|
#include <sha256.h>
|
||||||
|
#include <dirent.h>
|
||||||
#define NOH_IMPLEMENTATION
|
#define NOH_IMPLEMENTATION
|
||||||
#include "noh.h"
|
#include "noh.h"
|
||||||
|
|
||||||
@@ -29,8 +30,24 @@ static enum MHD_Result handle_opds(struct MHD_Connection *connection, SV url, SV
|
|||||||
noh_string_append_sv(&fs_path, username);
|
noh_string_append_sv(&fs_path, username);
|
||||||
noh_string_append_cstr(&fs_path, "/");
|
noh_string_append_cstr(&fs_path, "/");
|
||||||
noh_string_append_sv(&fs_path, url);
|
noh_string_append_sv(&fs_path, url);
|
||||||
|
noh_string_append_null(&fs_path);
|
||||||
|
|
||||||
noh_log(NOH_INFO, "Physical path: "Nsv_Fmt, Nsv_Arg(fs_path));
|
noh_log(NOH_INFO, "Physical path: "Nsv_Fmt, Nsv_Arg(fs_path));
|
||||||
|
|
||||||
|
DIR* dir = opendir(fs_path.elems);
|
||||||
|
if (dir) {
|
||||||
|
noh_log(NOH_INFO, "Exists.");
|
||||||
|
closedir(dir);
|
||||||
|
} else if (ENOENT == errno) {
|
||||||
|
noh_log(NOH_INFO, "Does not exist.");
|
||||||
|
closedir(dir);
|
||||||
|
/* Directory does not exist. */
|
||||||
|
} else {
|
||||||
|
noh_log(NOH_ERROR, "Opening directory failed.");
|
||||||
|
return send_response(connection, 500, sv(""));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
return send_response(connection, 200, sv("TODO: OPDS\n"));
|
return send_response(connection, 200, sv("TODO: OPDS\n"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user