diff --git a/CMakeLists.txt b/CMakeLists.txt index c9aaadf..63a901f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,6 @@ cmake_minimum_required (VERSION 3.7) project(core - VERSION 0.2.1 + VERSION 0.2.2 LANGUAGES C) add_executable(core src/main.c) diff --git a/core.ini b/core.ini index 1f55048..7c9f16a 100644 --- a/core.ini +++ b/core.ini @@ -1,6 +1,7 @@ [core] server-port = 5000 database = core.sqlite +content-dir = /usr/share/webapps/emgauwa not-found-file = 404.html not-found-file-mime = text/html not-found-content = 404 - NOT FOUND diff --git a/include/config.h b/include/config.h index a00f2af..6dee2f2 100644 --- a/include/config.h +++ b/include/config.h @@ -33,6 +33,7 @@ typedef struct uint16_t server_port; uint16_t discovery_port; uint16_t mqtt_port; + char content_dir[1024]; char not_found_file[256]; char not_found_file_type[256]; char not_found_content[256]; diff --git a/src/config.c b/src/config.c index 90627f4..bc9a87e 100644 --- a/src/config.c +++ b/src/config.c @@ -69,6 +69,11 @@ config_load(IniDispatch *disp, void *config_void) strcpy(config->group, disp->value); return 0; } + if(CONFINI_IS_KEY("core", "content-dir")) + { + strcpy(config->content_dir, disp->value); + return 0; + } if(CONFINI_IS_KEY("core", "not-found-file")) { strcpy(config->not_found_file, disp->value); diff --git a/src/handlers/http.c b/src/handlers/http.c index dc7e36a..3383521 100644 --- a/src/handlers/http.c +++ b/src/handlers/http.c @@ -107,7 +107,10 @@ handle_http_request(struct mg_connection *nc, struct http_message *hm) } LOG_DEBUG("%s\n", request_file); - int access_result = access(request_file, R_OK); + char *request_file_path = malloc(sizeof(char) * (strlen(request_file) + strlen(global_config.content_dir) + 2)); + sprintf(request_file_path, "%s/%s", global_config.content_dir, request_file); + int access_result = access(request_file_path, R_OK); + free(request_file_path); free(request_file_org); if(access_result != -1) { diff --git a/src/main.c b/src/main.c index c005696..493df97 100644 --- a/src/main.c +++ b/src/main.c @@ -59,6 +59,7 @@ main(int argc, const char** argv) strcpy(global_config.user, ""); strcpy(global_config.group, ""); + strcpy(global_config.content_dir, "."); strcpy(global_config.not_found_file, "404.html"); strcpy(global_config.not_found_file_type, "text/html"); strcpy(global_config.not_found_content, "404 - NOT FOUND"); @@ -81,7 +82,7 @@ main(int argc, const char** argv) fclose(ini_file); memset(&global_config.http_server_opts, 0, sizeof(global_config.http_server_opts)); - global_config.http_server_opts.document_root = "."; // Serve current directory + global_config.http_server_opts.document_root = global_config.content_dir; global_config.http_server_opts.enable_directory_listing = "no"; global_config.http_server_opts.extra_headers = "Access-Control-Allow-Origin: *\r\nAccess-Control-Allow-Headers: *\r\nAccess-Control-Allow-Methods: *";