core-legacy/config.c

104 lines
2.9 KiB
C
Raw Normal View History

2020-05-05 09:42:02 +00:00
#include <stdlib.h>
#include <string.h>
#include <logger.h>
#include <config.h>
config_t global_config;
#define CONFINI_IS_KEY(SECTION, KEY) \
(ini_array_match(SECTION, disp->append_to, '.', disp->format) && \
ini_string_match_ii(KEY, disp->data, disp->format))
2020-05-28 17:13:57 +00:00
int
config_load_log_level(IniDispatch *disp, config_t *config)
{
if(strcasecmp(disp->value, "trace") == 0)
{
config->log_level = LOG_LEVEL_TRACE;
return 0;
}
if(strcasecmp(disp->value, "debug") == 0)
{
config->log_level = LOG_LEVEL_DEBUG;
return 0;
}
if(strcasecmp(disp->value, "info") == 0)
{
config->log_level = LOG_LEVEL_INFO;
return 0;
}
if(strcasecmp(disp->value, "warn") == 0)
{
config->log_level = LOG_LEVEL_WARN;
return 0;
}
if(strcasecmp(disp->value, "error") == 0)
{
config->log_level = LOG_LEVEL_ERROR;
return 0;
}
if(strcasecmp(disp->value, "fatal") == 0)
{
config->log_level = LOG_LEVEL_FATAL;
return 0;
}
LOG_WARN("invalid log-level '%s'\n", disp->value);
return 0;
}
2020-05-05 09:42:02 +00:00
int
config_load(IniDispatch *disp, void *config_void)
{
config_t *config = (config_t*)config_void;
if(disp->type == INI_KEY)
{
2020-06-02 22:47:49 +00:00
if(CONFINI_IS_KEY("core", "server-port"))
{
strcpy(config->server_port, disp->value);
return 0;
}
2020-05-05 09:42:02 +00:00
if(CONFINI_IS_KEY("core", "database"))
{
config->database = malloc(sizeof(char) * (strlen(disp->value) + 1));
strcpy(config->database, disp->value);
return 0;
}
2020-06-02 22:47:49 +00:00
if(CONFINI_IS_KEY("core", "not-found-file"))
{
config->not_found_file = malloc(sizeof(char) * (strlen(disp->value) + 1));
strcpy(config->not_found_file, disp->value);
return 0;
}
if(CONFINI_IS_KEY("core", "not-found-file-type"))
{
config->not_found_file_type = malloc(sizeof(char) * (strlen(disp->value) + 1));
strcpy(config->not_found_file_type, disp->value);
return 0;
}
if(CONFINI_IS_KEY("core", "not-found-content"))
{
config->not_found_content = malloc(sizeof(char) * (strlen(disp->value) + 1));
strcpy(config->not_found_content, disp->value);
return 0;
}
if(CONFINI_IS_KEY("core", "not-found-content-type"))
{
config->not_found_content_type = malloc(sizeof(char) * (strlen(disp->value) + 1));
strcpy(config->not_found_content_type, disp->value);
return 0;
}
2020-05-05 09:42:02 +00:00
if(CONFINI_IS_KEY("core", "log-level"))
{
2020-05-28 17:13:57 +00:00
return config_load_log_level(disp, config);
2020-05-05 09:42:02 +00:00
}
if(CONFINI_IS_KEY("core", "discovery-port"))
{
config->discovery_port = atoi(disp->value);
return 0;
}
}
return 0;
}