From: Willy Tarreau Date: Thu, 8 Oct 2026 16:48:46 +0000 (+0200) Subject: CLEANUP: cfgparse-listen: simplify the second half of cfg_parse_listen() X-Git-Tag: v3.5-dev9~110 X-Git-Url: https://git.kaiwu.me/$%7BGITURL%7D$%7Bcid%7D?a=commitdiff_plain;h=347fb7cf78dacea52e9c7b747fffd9f5cb881680;p=haproxy.git CLEANUP: cfgparse-listen: simplify the second half of cfg_parse_listen() All the proxy keywords are now registered in cfg_kws, so the function only has to create the sections ("listen", "frontend", "backend" and "defaults") and to look the keyword up in the registered lists. The historical indented block that was dealing with known keywords is no longer necessary and it's the right moment to reindent the few tens of remaining lines. --- diff --git a/src/cfgparse-listen.c b/src/cfgparse-listen.c index dccb6692f..c6bc23755 100644 --- a/src/cfgparse-listen.c +++ b/src/cfgparse-listen.c @@ -38,6 +38,7 @@ /* some keywords that are still being parsed using strcmp() and are not * registered anywhere. They are used as suggestions for mistyped words. + * DO NOT ADD ANY NEW KEYWORDS HERE, THAT MUST NO LONGER BE NECESSARY! */ static const char *common_kw_list[] = { "listen", "frontend", "backend", "defaults", @@ -300,11 +301,13 @@ int cfg_parse_listen_match_option(const char *file, int linenum, int kwm, return 0; } +/* main proxy section keyword parser */ int cfg_parse_listen(const char *file, int linenum, char **args, int kwm) { static struct proxy *curr_defproxy = NULL; - const char *err; - int rc; + struct cfg_kw_list *kwl; + const char *err, *best; + int rc, index; int err_code = 0; char *errmsg = NULL; const char *file_prev = NULL; @@ -537,49 +540,41 @@ int cfg_parse_listen(const char *file, int linenum, char **args, int kwm) curproxy->conf.args.line = linenum; /* Now let's parse the proxy-specific keywords */ - { - struct cfg_kw_list *kwl; - const char *best; - int index; - - list_for_each_entry(kwl, &cfg_keywords.list, list) { - for (index = 0; kwl->kw[index].kw != NULL; index++) { - if (kwl->kw[index].section != CFG_LISTEN) - continue; - if (strcmp(kwl->kw[index].kw, args[0]) == 0) { - if (check_kw_experimental(&kwl->kw[index], file, linenum, &errmsg)) { - ha_alert("%s\n", errmsg); - err_code |= ERR_ALERT | ERR_FATAL; - goto out; - } - - /* prepare error message just in case */ - rc = kwl->kw[index].parse(args, CFG_LISTEN, curproxy, curr_defproxy, file, linenum, &errmsg); - if (rc < 0) { - if (errmsg) - ha_alert("parsing [%s:%d] : %s\n", file, linenum, errmsg); - err_code |= ERR_ALERT | ERR_FATAL; - goto out; - } - else if (rc > 0) { - if (errmsg) - ha_warning("parsing [%s:%d] : %s\n", file, linenum, errmsg); - err_code |= ERR_WARN; - goto out; - } - goto out; - } + list_for_each_entry(kwl, &cfg_keywords.list, list) { + for (index = 0; kwl->kw[index].kw != NULL; index++) { + if (kwl->kw[index].section != CFG_LISTEN) + continue; + if (strcmp(kwl->kw[index].kw, args[0]) != 0) + continue; + + if (check_kw_experimental(&kwl->kw[index], file, linenum, &errmsg)) { + ha_alert("%s\n", errmsg); + err_code |= ERR_ALERT | ERR_FATAL; + goto out; } - } - best = cfg_find_best_match(args[0], &cfg_keywords.list, CFG_LISTEN, common_kw_list); - if (best) - ha_alert("parsing [%s:%d] : unknown keyword '%s' in '%s' section; did you mean '%s' maybe ?\n", file, linenum, args[0], cursection, best); - else - ha_alert("parsing [%s:%d] : unknown keyword '%s' in '%s' section\n", file, linenum, args[0], cursection); - err_code |= ERR_ALERT | ERR_FATAL; - goto out; + rc = kwl->kw[index].parse(args, CFG_LISTEN, curproxy, curr_defproxy, file, linenum, &errmsg); + if (rc < 0) { + if (errmsg) + ha_alert("parsing [%s:%d] : %s\n", file, linenum, errmsg); + err_code |= ERR_ALERT | ERR_FATAL; + } + else if (rc > 0) { + if (errmsg) + ha_warning("parsing [%s:%d] : %s\n", file, linenum, errmsg); + err_code |= ERR_WARN; + } + goto out; + } } + + best = cfg_find_best_match(args[0], &cfg_keywords.list, CFG_LISTEN, common_kw_list); + if (best) + ha_alert("parsing [%s:%d] : unknown keyword '%s' in '%s' section; did you mean '%s' maybe ?\n", file, linenum, args[0], cursection, best); + else + ha_alert("parsing [%s:%d] : unknown keyword '%s' in '%s' section\n", file, linenum, args[0], cursection); + err_code |= ERR_ALERT | ERR_FATAL; + out: free(errmsg); return err_code;