]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MEDIUM: cfgparse: post parsing registration
authorWilliam Lallemand <wlallemand@haproxy.com>
Mon, 23 Oct 2017 12:36:34 +0000 (14:36 +0200)
committerWilly Tarreau <w@1wt.eu>
Fri, 27 Oct 2017 08:15:56 +0000 (10:15 +0200)
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.

include/common/cfgparse.h
src/cfgparse.c

index fc96bfea049dc144e60384a4c10257b924bde3fa..230c35fa86cc93adee8bc712706040b46d832b25 100644 (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);
index 8a5c8f003bf60347e9d44a69ae1aeb8d83b61362..ed74960a3f45ebaa6c8f0477c6ee1a2291fb2344 100644 (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
  */