From: William Lallemand Date: Mon, 23 Oct 2017 12:36:34 +0000 (+0200) Subject: MEDIUM: cfgparse: post parsing registration X-Git-Tag: v1.8-rc1~220 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=48b4bb4b09a51a8ef8c0d3692550831bd0c67d95;p=thirdparty%2Fhaproxy.git 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 fc96bfea04..230c35fa86 100644 --- a/include/common/cfgparse.h +++ b/include/common/cfgparse.h @@ -75,6 +75,7 @@ int str2listener(char *str, struct proxy *curproxy, struct bind_conf *bind_conf, 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 8a5c8f003b..ed74960a3f 100644 --- a/src/cfgparse.c +++ b/src/cfgparse.c @@ -134,6 +134,16 @@ struct cfg_section { */ 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 @@ int check_config_validity() struct bind_conf *bind_conf; char *err; struct dns_resolvers *curr_resolvers; + struct cfg_postparser *postparser; bind_conf = NULL; /* @@ -9235,6 +9246,11 @@ out_uri_auth_compat: 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 @@ int cfg_register_section(char *section_name, 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 */