Browse Source

* config process includes now

master
Alex 'AdUser' Z 9 years ago
parent
commit
d13fe58751
  1. 2
      src/backend-test.c
  2. 19
      src/config.c
  3. 2
      src/config.h
  4. 2
      src/main.c

2
src/backend-test.c

@ -19,7 +19,7 @@ int main(int argc, char *argv[]) {
usage();
memset(&config, 0x0, sizeof(config));
if (f2b_config_load(&config, argv[1]) != true) {
if (f2b_config_load(&config, argv[1], false) != true) {
f2b_log_msg(log_error, "can't load config");
return EXIT_FAILURE;
}

19
src/config.c

@ -2,6 +2,8 @@
#include "config.h"
#include "log.h"
#include <glob.h>
f2b_config_param_t *
f2b_config_param_create(const char *src) {
f2b_config_param_t *param = NULL;
@ -164,7 +166,7 @@ f2b_config_section_find(f2b_config_section_t *section, const char *name) {
}
bool
f2b_config_load(f2b_config_t *config, const char *path) {
f2b_config_load(f2b_config_t *config, const char *path, bool recursion) {
f2b_config_section_t *section = NULL; /* always points to current section */
f2b_config_param_t *param = NULL; /* temp pointer */
FILE *f = NULL; /* config file fd */
@ -233,7 +235,20 @@ f2b_config_load(f2b_config_t *config, const char *path) {
} /* while */
fclose(f);
/* TODO: process includes */
if (recursion && config->main && (param = f2b_config_param_find(config->main->param, "includes"))) {
char pattern[PATH_MAX] = "";
glob_t globbuf;
snprintf(pattern, sizeof(pattern), "%s/*.conf", param->value);
if (glob(pattern, 0, NULL, &globbuf) != 0) {
f2b_log_msg(log_error, "glob on 'includes' dir failed");
return false;
}
for (size_t i = 0; i < globbuf.gl_pathc; i++) {
f2b_config_load(config, globbuf.gl_pathv[i], false);
/* TODO: includes processing are not fatal? hmm... good question */
}
globfree(&globbuf);
}
return true;
}

2
src/config.h

@ -45,6 +45,6 @@ f2b_config_section_t * f2b_config_section_create(const char *line);
f2b_config_section_t * f2b_config_section_find (f2b_config_section_t *s, const char *name);
f2b_config_section_t * f2b_config_section_append(f2b_config_t *c, f2b_config_section_t *s);
bool f2b_config_load(f2b_config_t *c, const char *path);
bool f2b_config_load(f2b_config_t *c, const char *path, bool recursion);
void f2b_config_free(f2b_config_t *c);
#endif /* CONFIG_H_ */

2
src/main.c

@ -64,7 +64,7 @@ int main(int argc, char *argv[]) {
if (!config_file)
usage(EXIT_FAILURE);
memset(&config, 0x0, sizeof(config));
if (f2b_config_load(&config, config_file) != true) {
if (f2b_config_load(&config, config_file, true) != true) {
f2b_log_msg(log_error, "can't load config from '%s'", config_file);
return EXIT_FAILURE;
}

Loading…
Cancel
Save