Start listing entries in directory
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1,2 +1,3 @@
|
||||
output/
|
||||
library/
|
||||
|
||||
|
||||
26
src/main.c
26
src/main.c
@@ -13,6 +13,8 @@ This will ignore any auth headers and always log in with username demo.
|
||||
#define SV Noh_String_View
|
||||
#define sv noh_sv_from_cstr
|
||||
|
||||
Noh_Arena temp;
|
||||
|
||||
static enum MHD_Result send_response(struct MHD_Connection *connection, int status, SV message) {
|
||||
struct MHD_Response *response = MHD_create_response_from_buffer(
|
||||
message.count, (void*)message.elems, MHD_RESPMEM_PERSISTENT);
|
||||
@@ -34,20 +36,29 @@ static enum MHD_Result handle_opds(struct MHD_Connection *connection, SV url, SV
|
||||
|
||||
noh_log(NOH_INFO, "Physical path: "Nsv_Fmt, Nsv_Arg(fs_path));
|
||||
|
||||
DIR* dir = opendir(fs_path.elems);
|
||||
DIR *dir = opendir(fs_path.elems);
|
||||
if (dir) {
|
||||
noh_log(NOH_INFO, "Exists.");
|
||||
|
||||
noh_arena_save(&temp);
|
||||
struct dirent *entry = noh_arena_alloc(&temp, sizeof(struct dirent));
|
||||
while ((entry = readdir(dir)) != NULL) {
|
||||
(void)entry;
|
||||
noh_log(NOH_INFO, "Entry..");
|
||||
}
|
||||
noh_arena_reset(&temp);
|
||||
|
||||
closedir(dir);
|
||||
} else if (ENOENT == errno) {
|
||||
noh_log(NOH_INFO, "Does not exist.");
|
||||
|
||||
} else if (errno == ENOENT) {
|
||||
closedir(dir);
|
||||
/* Directory does not exist. */
|
||||
return send_response(connection, 404, sv("That 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"));
|
||||
}
|
||||
|
||||
@@ -125,6 +136,7 @@ int main(int argc, char **argv)
|
||||
char *library_path = noh_shift_args(&argc, &argv);
|
||||
SV base_path = sv(library_path);
|
||||
|
||||
temp = noh_arena_init(4 * 1024);
|
||||
struct MHD_Daemon *server;
|
||||
|
||||
// Start the HTTP server
|
||||
@@ -136,11 +148,11 @@ int main(int argc, char **argv)
|
||||
MHD_OPTION_END);
|
||||
|
||||
if (!server) {
|
||||
fprintf(stderr, "Failed to start server\n");
|
||||
noh_log(NOH_ERROR, "Failed to start server.");
|
||||
return 1;
|
||||
}
|
||||
|
||||
printf("Server is running on http://0.0.0.0:%d\n", port);
|
||||
noh_log(NOH_INFO, "Server is running on http://0.0.0.0:%d", port);
|
||||
|
||||
// Keep the server running
|
||||
getchar();
|
||||
|
||||
Reference in New Issue
Block a user