diff --git a/server.conf b/server.conf index 1dd113c..da49ebd 100644 --- a/server.conf +++ b/server.conf @@ -25,4 +25,7 @@ verbose = true enable_http2 = false # Enable WebSocket support -enable_websocket = false \ No newline at end of file +enable_websocket = false + +# Path to www +www_path = www \ No newline at end of file diff --git a/src/config_parser.c b/src/config_parser.c index 4e9f340..fa20d75 100644 --- a/src/config_parser.c +++ b/src/config_parser.c @@ -15,6 +15,7 @@ typedef enum { CONFIG_VERBOSE, CONFIG_ENABLE_HTTP2, CONFIG_ENABLE_WEBSOCKET, + CONFIG_WWW_PATH, CONFIG_UNKNOWN } ConfigKey; @@ -62,6 +63,7 @@ static ConfigKey get_config_key(const char *key) { {"verbose", CONFIG_VERBOSE}, {"enable_http2", CONFIG_ENABLE_HTTP2}, {"enable_websocket",CONFIG_ENABLE_WEBSOCKET}, + {"www_path", CONFIG_WWW_PATH}, {NULL, CONFIG_UNKNOWN} }; @@ -173,6 +175,12 @@ int load_config(const char *filename, ServerConfig *config) { printf("load_config: enable_websocket = %d\n", config->enable_websocket); break; + case CONFIG_WWW_PATH: + strncpy(config->www_path, value, sizeof(config->www_path) - 1); + config->www_path[sizeof(config->www_path) - 1] = '\0'; + printf("load_config: www_path = %s\n", config->www_path); + break; + case CONFIG_UNKNOWN: default: fprintf(stderr, "Warning: Unknown config option '%s' on line %d\n", key, line_number); diff --git a/src/server.c b/src/server.c index 8d29a38..dc506e0 100644 --- a/src/server.c +++ b/src/server.c @@ -557,7 +557,7 @@ void *handle_http_client(void *arg) { } char filepath[512]; - snprintf(filepath, sizeof(filepath), "www%s", + snprintf(filepath, sizeof(filepath), "%s%s", config.www_path, (*sanitized_url == '/' && sanitized_url[1] == '\0') ? "/index.html" : sanitized_url); free(sanitized_url); @@ -779,7 +779,7 @@ void *handle_https_client(void *arg) { } char filepath[512]; - snprintf(filepath, sizeof(filepath), "www%s", + snprintf(filepath, sizeof(filepath), "%s%s", config.www_path, (*sanitized_url == '/' && sanitized_url[1] == '\0') ? "/index.html" : sanitized_url); free(sanitized_url); log_event("Filepath:"); diff --git a/src/server_config.c b/src/server_config.c index 668993b..192d499 100644 --- a/src/server_config.c +++ b/src/server_config.c @@ -13,4 +13,5 @@ void init_config(ServerConfig *config) { strcpy(config->server_name, "127.0.0.1"); config->enable_http2 = false; config->enable_websocket = false; + strcpy(config->www_path, "www"); } diff --git a/src/server_config.h b/src/server_config.h index d38e32d..18ad304 100644 --- a/src/server_config.h +++ b/src/server_config.h @@ -14,6 +14,7 @@ typedef struct { int verbose; bool enable_http2; bool enable_websocket; + char www_path[256]; } ServerConfig; int load_config(const char *filename, ServerConfig *config);