1 /* conf.c - Config file reader
2 * Copyright 2000-2004 srvx Development Team
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version. Important limitations are
8 * listed in the COPYING file that accompanies this software.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, email srvx-maintainers@srvx.net.
22 static dict_t conf_db;
23 static conf_reload_func *reload_funcs;
24 static int num_rfs, size_rfs;
27 conf_register_reload(conf_reload_func crf)
29 if (num_rfs >= size_rfs) {
32 reload_funcs = realloc(reload_funcs, size_rfs*sizeof(conf_reload_func));
35 reload_funcs = calloc(size_rfs, sizeof(conf_reload_func));
38 reload_funcs[num_rfs++] = crf;
45 conf_call_reload_funcs(void)
48 for (i=0; i<num_rfs; i++) reload_funcs[i]();
52 conf_read(const char *conf_file_name)
54 dict_t old_conf = conf_db;
55 if (!(conf_db = parse_database(conf_file_name))) {
59 conf_call_reload_funcs();
61 if (old_conf && old_conf != conf_db) {
62 free_database(old_conf);
67 log_module(MAIN_LOG, LOG_ERROR, "Reverting to previous configuration.");
68 free_database(conf_db);
76 free_database(conf_db);
81 conf_get_node(const char *full_path)
83 return database_get_path(conf_db, full_path);
87 conf_get_data(const char *full_path, enum recdb_type type)
89 return database_get_data(conf_db, full_path, type);
93 conf_enum_root(dict_iterator_f it, void *extra)
95 return dict_foreach(conf_db, it, extra);