diff --git a/src/main.c b/src/main.c index babea91..aa0e52e 100644 --- a/src/main.c +++ b/src/main.c @@ -1,5 +1,6 @@ #include #include +#include #define NOH_IMPLEMENTATION #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_cstr(&fs_path, "/"); 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)); + + 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")); }