Replace ini with toml

This commit is contained in:
Tobias Reisinger 2020-11-17 23:13:01 +01:00
parent 97a19135ce
commit 5796f88e05
11 changed files with 242 additions and 5726 deletions

View file

@ -3,7 +3,6 @@
#include <string.h>
#include <syslog.h>
#include <confini.h>
#include <mongoose.h>
#include <cache.h>
@ -62,23 +61,16 @@ main(int argc, const char** argv)
cli_parse(argc, argv, global_config);
FILE * const ini_file = fopen(global_config->file, "rb");
if(ini_file == NULL)
config_load(global_config);
if(global_config->logging.file == NULL)
{
LOGGER_CRIT("config file '%s' was not found\n", global_config->file);
exit(1);
}
if(load_ini_file(ini_file, INI_DEFAULT_FORMAT, NULL, config_load, global_config))
{
LOGGER_CRIT("unable to parse ini file\n");
exit(1);
global_config->logging.file = stdout;
}
fclose(ini_file);
if(global_config->log_file == NULL)
if(global_config->include)
{
global_config->log_file = stdout;
config_load_directory(global_config, global_config->include);
}
LOGGER_DEBUG("Loaded config from %s\n", global_config->file);
@ -91,20 +83,20 @@ main(int argc, const char** argv)
mg_mgr_init(&mgr, NULL);
char address[100];
sprintf(address, "tcp://0.0.0.0:%u", global_config->server_port);
sprintf(address, "tcp://0.0.0.0:%u", global_config->ports.server);
struct mg_connection *c_http = mg_bind(&mgr, address, handler_http);
if(c_http == NULL)
{
LOGGER_CRIT("failed to bind http server to port %u\n", global_config->server_port);
LOGGER_CRIT("failed to bind http server to port %u\n", global_config->ports.server);
exit(1);
}
mg_set_protocol_http_websocket(c_http);
sprintf(address, "tcp://0.0.0.0:%u", global_config->mqtt_port);
sprintf(address, "tcp://0.0.0.0:%u", global_config->ports.mqtt);
struct mg_connection *c_mqtt = mg_bind(&mgr, address, handler_mqtt);
if(c_mqtt == NULL)
{
LOGGER_CRIT("failed to bind mqtt server to port %u\n", global_config->mqtt_port);
LOGGER_CRIT("failed to bind mqtt server to port %u\n", global_config->ports.mqtt);
exit(1);
}
mg_mqtt_broker_init(&brk, NULL);