From: Willy Tarreau Date: Wed, 30 Mar 2022 09:21:32 +0000 (+0200) Subject: MINOR: config: alphanumerically sort config keywords output X-Git-Tag: v2.6-dev5~105 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=d90582600005305284798518ea335e6031bd506c;p=thirdparty%2Fhaproxy.git MINOR: config: alphanumerically sort config keywords output The output produced by dump_registered_keywords() really deserves to be sorted in order to ease comparisons. The function now implements a tiny sorting mechanism that's suitable for each two-level list, and makes use of dump_act_rules() to dump rulesets. The code is not significantly more complicated and some parts (e.g options) could even be factored. The output is much more exploitable to detect differences now. --- diff --git a/src/cfgparse.c b/src/cfgparse.c index 6dd8210676..14980b36dd 100644 --- a/src/cfgparse.c +++ b/src/cfgparse.c @@ -4250,12 +4250,20 @@ void cfg_dump_registered_keywords() for (section = 1; sect_names[section]; section++) { struct cfg_kw_list *kwl; + const struct cfg_keyword *kwp, *kwn; printf("%s\n", sect_names[section]); - list_for_each_entry(kwl, &cfg_keywords.list, list) { - for (index = 0; kwl->kw[index].kw != NULL; index++) - if (kwl->kw[index].section == section) - printf("\t%s\n", kwl->kw[index].kw); + + for (kwn = kwp = NULL;; kwp = kwn) { + list_for_each_entry(kwl, &cfg_keywords.list, list) { + for (index = 0; kwl->kw[index].kw != NULL; index++) + if (kwl->kw[index].section == section && + strordered(kwp ? kwp->kw : NULL, kwl->kw[index].kw, kwn != kwp ? kwn->kw : NULL)) + kwn = &kwl->kw[index]; + } + if (kwn == kwp) + break; + printf("\t%s\n", kwn->kw); } if (section == CFG_LISTEN) { @@ -4265,100 +4273,96 @@ void cfg_dump_registered_keywords() extern struct bind_kw_list bind_keywords; extern struct ssl_bind_kw ssl_bind_kws[] __maybe_unused; extern struct srv_kw_list srv_keywords; - struct action_kw_list *akwl; struct bind_kw_list *bkwl; struct srv_kw_list *skwl; - - list_for_each_entry(bkwl, &bind_keywords.list, list) { - for (index = 0; bkwl->kw[index].kw != NULL; index++) { - if (!bkwl->kw[index].skip) - printf("\tbind %s\n", bkwl->kw[index].kw); - else - printf("\tbind %s +%d\n", bkwl->kw[index].kw, bkwl->kw[index].skip); + const struct bind_kw *bkwp, *bkwn; + const struct srv_kw *skwp, *skwn; + const struct ssl_bind_kw *sbkwp __maybe_unused, *sbkwn __maybe_unused; + const struct cfg_opt *coptp, *coptn; + + for (bkwn = bkwp = NULL;; bkwp = bkwn) { + list_for_each_entry(bkwl, &bind_keywords.list, list) { + for (index = 0; bkwl->kw[index].kw != NULL; index++) + if (strordered(bkwp ? bkwp->kw : NULL, + bkwl->kw[index].kw, + bkwn != bkwp ? bkwn->kw : NULL)) + bkwn = &bkwl->kw[index]; } + if (bkwn == bkwp) + break; + + if (!bkwn->skip) + printf("\tbind %s\n", bkwn->kw); + else + printf("\tbind %s +%d\n", bkwn->kw, bkwn->skip); } #if defined(USE_OPENSSL) - for (index = 0; ssl_bind_kws[index].kw != NULL; index++) { - if (!ssl_bind_kws[index].skip) - printf("\tbind ssl %s\n", ssl_bind_kws[index].kw); + for (sbkwn = sbkwp = NULL;; sbkwp = sbkwn) { + for (index = 0; ssl_bind_kws[index].kw != NULL; index++) { + if (strordered(sbkwp ? sbkwp->kw : NULL, + ssl_bind_kws[index].kw, + sbkwn != sbkwp ? sbkwn->kw : NULL)) + sbkwn = &ssl_bind_kws[index]; + } + if (sbkwn == sbkwp) + break; + if (!sbkwn->skip) + printf("\tbind ssl %s\n", sbkwn->kw); else - printf("\tbind ssl %s +%d\n", ssl_bind_kws[index].kw, ssl_bind_kws[index].skip); + printf("\tbind ssl %s +%d\n", sbkwn->kw, sbkwn->skip); } #endif - list_for_each_entry(skwl, &srv_keywords.list, list) { - for (index = 0; skwl->kw[index].kw != NULL; index++) { - if (!skwl->kw[index].skip) - printf("\tserver %s\n", skwl->kw[index].kw); - else - printf("\tserver %s +%d\n", skwl->kw[index].kw, skwl->kw[index].skip); + for (skwn = skwp = NULL;; skwp = skwn) { + list_for_each_entry(skwl, &srv_keywords.list, list) { + for (index = 0; skwl->kw[index].kw != NULL; index++) + if (strordered(skwp ? skwp->kw : NULL, + skwl->kw[index].kw, + skwn != skwp ? skwn->kw : NULL)) + skwn = &skwl->kw[index]; } - } + if (skwn == skwp) + break; - for (index = 0; cfg_opts[index].name; index++) { - printf("\toption %s [ ", cfg_opts[index].name); - if (cfg_opts[index].cap & PR_CAP_FE) - printf("FE "); - if (cfg_opts[index].cap & PR_CAP_BE) - printf("BE "); - if (cfg_opts[index].mode == PR_MODE_HTTP) - printf("HTTP "); - printf("]\n"); - } + if (!skwn->skip) + printf("\tserver %s\n", skwn->kw); + else + printf("\tserver %s +%d\n", skwn->kw, skwn->skip); + } + + for (coptn = coptp = NULL;; coptp = coptn) { + for (index = 0; cfg_opts[index].name; index++) + if (strordered(coptp ? coptp->name : NULL, + cfg_opts[index].name, + coptn != coptp ? coptn->name : NULL)) + coptn = &cfg_opts[index]; + + for (index = 0; cfg_opts2[index].name; index++) + if (strordered(coptp ? coptp->name : NULL, + cfg_opts2[index].name, + coptn != coptp ? coptn->name : NULL)) + coptn = &cfg_opts2[index]; + if (coptn == coptp) + break; - for (index = 0; cfg_opts2[index].name; index++) { - printf("\toption %s [ ", cfg_opts2[index].name); - if (cfg_opts2[index].cap & PR_CAP_FE) + printf("\toption %s [ ", coptn->name); + if (coptn->cap & PR_CAP_FE) printf("FE "); - if (cfg_opts2[index].cap & PR_CAP_BE) + if (coptn->cap & PR_CAP_BE) printf("BE "); - if (cfg_opts2[index].mode == PR_MODE_HTTP) + if (coptn->mode == PR_MODE_HTTP) printf("HTTP "); printf("]\n"); } - list_for_each_entry(akwl, &tcp_req_conn_keywords, list) { - for (index = 0; akwl->kw[index].kw != NULL; index++) - printf("\ttcp-request connection %s%s\n", akwl->kw[index].kw, - (akwl->kw[index].flags & KWF_MATCH_PREFIX) ? "*" : ""); - } - - list_for_each_entry(akwl, &tcp_req_sess_keywords, list) { - for (index = 0; akwl->kw[index].kw != NULL; index++) - printf("\ttcp-request session %s%s\n", akwl->kw[index].kw, - (akwl->kw[index].flags & KWF_MATCH_PREFIX) ? "*" : ""); - } - - list_for_each_entry(akwl, &tcp_req_cont_keywords, list) { - for (index = 0; akwl->kw[index].kw != NULL; index++) - printf("\ttcp-request content %s%s\n", akwl->kw[index].kw, - (akwl->kw[index].flags & KWF_MATCH_PREFIX) ? "*" : ""); - } - - list_for_each_entry(akwl, &tcp_res_cont_keywords, list) { - for (index = 0; akwl->kw[index].kw != NULL; index++) - printf("\ttcp-response content %s%s\n", akwl->kw[index].kw, - (akwl->kw[index].flags & KWF_MATCH_PREFIX) ? "*" : ""); - } - - list_for_each_entry(akwl, &http_req_keywords.list, list) { - for (index = 0; akwl->kw[index].kw != NULL; index++) - printf("\thttp-request %s%s\n", akwl->kw[index].kw, - (akwl->kw[index].flags & KWF_MATCH_PREFIX) ? "*" : ""); - } - - list_for_each_entry(akwl, &http_res_keywords.list, list) { - for (index = 0; akwl->kw[index].kw != NULL; index++) - printf("\thttp-response %s%s\n", akwl->kw[index].kw, - (akwl->kw[index].flags & KWF_MATCH_PREFIX) ? "*" : ""); - } - - list_for_each_entry(akwl, &http_after_res_keywords.list, list) { - for (index = 0; akwl->kw[index].kw != NULL; index++) - printf("\thttp-after-response %s%s\n", akwl->kw[index].kw, - (akwl->kw[index].flags & KWF_MATCH_PREFIX) ? "*" : ""); - } + dump_act_rules(&tcp_req_conn_keywords, "\ttcp-request connection "); + dump_act_rules(&tcp_req_sess_keywords, "\ttcp-request session "); + dump_act_rules(&tcp_req_cont_keywords, "\ttcp-request content "); + dump_act_rules(&tcp_res_cont_keywords, "\ttcp-response content "); + dump_act_rules(&http_req_keywords.list, "\thttp-request "); + dump_act_rules(&http_res_keywords.list, "\thttp-response "); + dump_act_rules(&http_after_res_keywords.list, "\thttp-after-response "); } } }