MEDIUM: cfgparse: post parsing registration
Allow to register a function which will be called after the
configuration file parsing, at the end of the check_config_validity().
It's useful fo checking dependencies between sections or for resolving
keywords, pointers or values.
diff --git a/include/common/cfgparse.h b/include/common/cfgparse.h
index fc96bfe..230c35f 100644
--- a/include/common/cfgparse.h
+++ b/include/common/cfgparse.h
@@ -75,6 +75,7 @@
int cfg_register_section(char *section_name,
int (*section_parser)(const char *, int, char **, int),
int (*post_section_parser)());
+int cfg_register_postparser(char *name, int (*func)());
void cfg_unregister_sections(void);
void cfg_backup_sections(struct list *backup_sections);
void cfg_restore_sections(struct list *backup_sections);
diff --git a/src/cfgparse.c b/src/cfgparse.c
index 8a5c8f0..ed74960 100644
--- a/src/cfgparse.c
+++ b/src/cfgparse.c
@@ -134,6 +134,16 @@
*/
struct list sections = LIST_HEAD_INIT(sections);
+/* store post configuration parsing */
+
+struct cfg_postparser {
+ struct list list;
+ char *name;
+ int (*func)();
+};
+
+struct list postparsers = LIST_HEAD_INIT(postparsers);
+
/* some of the most common options which are also the easiest to handle */
struct cfg_opt {
const char *name;
@@ -7384,6 +7394,7 @@
struct bind_conf *bind_conf;
char *err;
struct dns_resolvers *curr_resolvers;
+ struct cfg_postparser *postparser;
bind_conf = NULL;
/*
@@ -9235,6 +9246,11 @@
global.tune.max_http_hdr * sizeof(struct hdr_idx_elem),
MEM_F_SHARED);
+ list_for_each_entry(postparser, &postparsers, list) {
+ if (postparser->func)
+ cfgerr += postparser->func();
+ }
+
if (cfgerr > 0)
err_code |= ERR_ALERT | ERR_FATAL;
out:
@@ -9292,6 +9308,27 @@
return 1;
}
+/* this function register a new function which will be called once the haproxy
+ * configuration file has been parsed. It's useful to check dependencies
+ * between sections or to resolve items once everything is parsed.
+ */
+int cfg_register_postparser(char *name, int (*func)())
+{
+ struct cfg_postparser *cp;
+
+ cp = calloc(1, sizeof(*cp));
+ if (!cp) {
+ Alert("register postparser '%s': out of memory.\n", name);
+ return 0;
+ }
+ cp->name = name;
+ cp->func = func;
+
+ LIST_ADDQ(&postparsers, &cp->list);
+
+ return 1;
+}
+
/*
* free all config section entries
*/