Add www_path configuration option and update related parsing logic
This commit is contained in:
@@ -26,3 +26,6 @@ enable_http2 = false
|
|||||||
|
|
||||||
# Enable WebSocket support
|
# Enable WebSocket support
|
||||||
enable_websocket = false
|
enable_websocket = false
|
||||||
|
|
||||||
|
# Path to www
|
||||||
|
www_path = www
|
||||||
@@ -15,6 +15,7 @@ typedef enum {
|
|||||||
CONFIG_VERBOSE,
|
CONFIG_VERBOSE,
|
||||||
CONFIG_ENABLE_HTTP2,
|
CONFIG_ENABLE_HTTP2,
|
||||||
CONFIG_ENABLE_WEBSOCKET,
|
CONFIG_ENABLE_WEBSOCKET,
|
||||||
|
CONFIG_WWW_PATH,
|
||||||
CONFIG_UNKNOWN
|
CONFIG_UNKNOWN
|
||||||
|
|
||||||
} ConfigKey;
|
} ConfigKey;
|
||||||
@@ -62,6 +63,7 @@ static ConfigKey get_config_key(const char *key) {
|
|||||||
{"verbose", CONFIG_VERBOSE},
|
{"verbose", CONFIG_VERBOSE},
|
||||||
{"enable_http2", CONFIG_ENABLE_HTTP2},
|
{"enable_http2", CONFIG_ENABLE_HTTP2},
|
||||||
{"enable_websocket",CONFIG_ENABLE_WEBSOCKET},
|
{"enable_websocket",CONFIG_ENABLE_WEBSOCKET},
|
||||||
|
{"www_path", CONFIG_WWW_PATH},
|
||||||
{NULL, CONFIG_UNKNOWN}
|
{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);
|
printf("load_config: enable_websocket = %d\n", config->enable_websocket);
|
||||||
break;
|
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:
|
case CONFIG_UNKNOWN:
|
||||||
default:
|
default:
|
||||||
fprintf(stderr, "Warning: Unknown config option '%s' on line %d\n", key, line_number);
|
fprintf(stderr, "Warning: Unknown config option '%s' on line %d\n", key, line_number);
|
||||||
|
|||||||
@@ -557,7 +557,7 @@ void *handle_http_client(void *arg) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
char filepath[512];
|
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);
|
(*sanitized_url == '/' && sanitized_url[1] == '\0') ? "/index.html" : sanitized_url);
|
||||||
free(sanitized_url);
|
free(sanitized_url);
|
||||||
|
|
||||||
@@ -779,7 +779,7 @@ void *handle_https_client(void *arg) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
char filepath[512];
|
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);
|
(*sanitized_url == '/' && sanitized_url[1] == '\0') ? "/index.html" : sanitized_url);
|
||||||
free(sanitized_url);
|
free(sanitized_url);
|
||||||
log_event("Filepath:");
|
log_event("Filepath:");
|
||||||
|
|||||||
@@ -13,4 +13,5 @@ void init_config(ServerConfig *config) {
|
|||||||
strcpy(config->server_name, "127.0.0.1");
|
strcpy(config->server_name, "127.0.0.1");
|
||||||
config->enable_http2 = false;
|
config->enable_http2 = false;
|
||||||
config->enable_websocket = false;
|
config->enable_websocket = false;
|
||||||
|
strcpy(config->www_path, "www");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ typedef struct {
|
|||||||
int verbose;
|
int verbose;
|
||||||
bool enable_http2;
|
bool enable_http2;
|
||||||
bool enable_websocket;
|
bool enable_websocket;
|
||||||
|
char www_path[256];
|
||||||
} ServerConfig;
|
} ServerConfig;
|
||||||
|
|
||||||
int load_config(const char *filename, ServerConfig *config);
|
int load_config(const char *filename, ServerConfig *config);
|
||||||
|
|||||||
Reference in New Issue
Block a user