98 lines
2.4 KiB
C
98 lines
2.4 KiB
C
#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))
|
|
|
|
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;
|
|
}
|
|
|
|
int
|
|
config_load(IniDispatch *disp, void *config_void)
|
|
{
|
|
config_t *config = (config_t*)config_void;
|
|
|
|
if(disp->type == INI_KEY)
|
|
{
|
|
if(CONFINI_IS_KEY("core", "server-port"))
|
|
{
|
|
strcpy(config->server_port, disp->value);
|
|
return 0;
|
|
}
|
|
if(CONFINI_IS_KEY("core", "database"))
|
|
{
|
|
strcpy(config->database, disp->value);
|
|
return 0;
|
|
}
|
|
if(CONFINI_IS_KEY("core", "not-found-file"))
|
|
{
|
|
strcpy(config->not_found_file, disp->value);
|
|
return 0;
|
|
}
|
|
if(CONFINI_IS_KEY("core", "not-found-file-type"))
|
|
{
|
|
strcpy(config->not_found_file_type, disp->value);
|
|
return 0;
|
|
}
|
|
if(CONFINI_IS_KEY("core", "not-found-content"))
|
|
{
|
|
strcpy(config->not_found_content, disp->value);
|
|
return 0;
|
|
}
|
|
if(CONFINI_IS_KEY("core", "not-found-content-type"))
|
|
{
|
|
strcpy(config->not_found_content_type, disp->value);
|
|
return 0;
|
|
}
|
|
if(CONFINI_IS_KEY("core", "log-level"))
|
|
{
|
|
return config_load_log_level(disp, config);
|
|
}
|
|
if(CONFINI_IS_KEY("core", "discovery-port"))
|
|
{
|
|
config->discovery_port = atoi(disp->value);
|
|
return 0;
|
|
}
|
|
}
|
|
return 0;
|
|
}
|