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.
This commit is contained in:
William Lallemand 2017-10-23 14:36:34 +02:00 committed by Willy Tarreau
parent d2ff56d2a3
commit 48b4bb4b09
2 changed files with 38 additions and 0 deletions

View File

@ -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);

View File

@ -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
*/