diff options
| -rw-r--r-- | server.c | 18 |
1 files changed, 14 insertions, 4 deletions
@@ -1,4 +1,5 @@ #include <asm-generic/socket.h> +#include <stdbool.h> #include <errno.h> #include <netdb.h> #include <stddef.h> @@ -48,14 +49,15 @@ static HTTP_METHODS get_require_method(char *method) } } -static int check_file_stat(const char *path, int fd) +static bool sdhd_isdir(const char *path, int fd) { struct stat st; - if (stat(path, &st) == -1 && S_ISDIR(st.st_mode)) { - return -1; + stat(path, &st); + if (S_ISDIR(st.st_mode)) { + return true; } - return 0; + return false; } static int handle_client(int client_fd, char *buf) @@ -72,6 +74,13 @@ static int handle_client(int client_fd, char *buf) char local_path[1024]; snprintf(local_path, sizeof(local_path), "./www%s", path); + printf("Path = %s\n", local_path); + + if (sdhd_isdir(local_path, client_fd)) { + strcat(local_path, "/index.html"); + } + + printf("Path = %s\n", local_path); FILE *fp = fopen(local_path, "r"); if (!fp) { @@ -80,6 +89,7 @@ static int handle_client(int client_fd, char *buf) shsd_sendfile(client_fd, fp); return -1; } + shsd_sendfile(client_fd, fp); return 0; |
