74 lines
2 KiB
C
74 lines
2 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(IniDispatch *disp, void *config_void)
|
|
{
|
|
config_t *config = (config_t*)config_void;
|
|
|
|
if(disp->type == INI_KEY)
|
|
{
|
|
if(CONFINI_IS_KEY("core", "database"))
|
|
{
|
|
config->database = malloc(sizeof(char) * (strlen(disp->value) + 1));
|
|
strcpy(config->database, disp->value);
|
|
return 0;
|
|
}
|
|
if(CONFINI_IS_KEY("core", "log-level"))
|
|
{
|
|
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;
|
|
}
|
|
if(CONFINI_IS_KEY("core", "discovery-port"))
|
|
{
|
|
config->discovery_port = atoi(disp->value);
|
|
return 0;
|
|
}
|
|
if(CONFINI_IS_KEY("core", "server-port"))
|
|
{
|
|
strcpy(config->server_port, disp->value);
|
|
return 0;
|
|
}
|
|
}
|
|
return 0;
|
|
}
|
|
|