#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "initconf.h"
InitConfig *load_init_config(
char *file) {
FILE *in = fopen(file,
"r");
if(in ==
NULL) {
return NULL;
}
InitConfig *conf = malloc(
sizeof(InitConfig));
conf->parser.parse = initconf_parse;
conf->file = file;
conf->directives =
NULL;
int r = cfg_parse_basic_file((ConfigParser*)conf, in);
if(r !=
0) {
free_init_config(conf);
return NULL;
}
fclose(in);
return conf;
}
void free_init_config(InitConfig *conf) {
ucx_mempool_destroy(conf->parser.mp->pool);
free(conf);
}
int initconf_parse(
void *p, ConfigLine *begin, ConfigLine *end,
sstr_t line) {
InitConfig *conf = p;
ConfigDirective *d = cfg_parse_directive(line, conf->parser.mp);
if(d ==
NULL) {
log_ereport(
LOG_FAILURE,
"initconf_parse: directive is null");
return 0;
}
d->begin = begin;
d->end = end;
if(d->type_num ==
INIT_DIRECTIVE) {
conf->directives = ucx_list_append(conf->directives, d);
}
else {
log_ereport(
LOG_WARN,
"Non Init directive in init.conf");
}
return 0;
}