From: Willy Tarreau Date: Sat, 8 May 2021 17:58:37 +0000 (+0200) Subject: REORG: config: uninline warnifnotcap() and failifnotcap() X-Git-Tag: v2.4-dev19~35 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=08138612a423c8205a4163925a5ad0859211e87e;p=thirdparty%2Fhaproxy.git REORG: config: uninline warnifnotcap() and failifnotcap() These ones are used by virtually every config parser. Not only they provide no benefit in being inlined, but they imply a very deep dependency starting at proxy.h, which results for example in task.c including openssl. Let's move these two functions to cfgparse.c. --- diff --git a/include/haproxy/cfgparse.h b/include/haproxy/cfgparse.h index 310da5e4b2..6963522839 100644 --- a/include/haproxy/cfgparse.h +++ b/include/haproxy/cfgparse.h @@ -27,6 +27,9 @@ #include struct hap_cpuset; +struct proxy; +struct bind_conf; +struct acl_cond; /* configuration sections */ #define CFG_NONE 0 @@ -123,56 +126,8 @@ int parse_process_number(const char *arg, unsigned long *proc, int max, int *aut unsigned long parse_cpu_set(const char **args, struct hap_cpuset *cpu_set, int comma_allowed, char **err); void free_email_alert(struct proxy *p); const char *cfg_find_best_match(const char *word, const struct list *list, int section, const char **extra); - -/* - * Sends a warning if proxy does not have at least one of the - * capabilities in . An optional may be added at the end - * of the warning to help the user. Returns 1 if a warning was emitted - * or 0 if the condition is valid. - */ -static inline int warnifnotcap(struct proxy *proxy, int cap, const char *file, int line, const char *arg, const char *hint) -{ - char *msg; - - switch (cap) { - case PR_CAP_BE: msg = "no backend"; break; - case PR_CAP_FE: msg = "no frontend"; break; - case PR_CAP_BE|PR_CAP_FE: msg = "neither frontend nor backend"; break; - default: msg = "not enough"; break; - } - - if (!(proxy->cap & cap)) { - ha_warning("parsing [%s:%d] : '%s' ignored because %s '%s' has %s capability.%s\n", - file, line, arg, proxy_type_str(proxy), proxy->id, msg, hint ? hint : ""); - return 1; - } - return 0; -} - -/* - * Sends an alert if proxy does not have at least one of the - * capabilities in . An optional may be added at the end - * of the alert to help the user. Returns 1 if an alert was emitted - * or 0 if the condition is valid. - */ -static inline int failifnotcap(struct proxy *proxy, int cap, const char *file, int line, const char *arg, const char *hint) -{ - char *msg; - - switch (cap) { - case PR_CAP_BE: msg = "no backend"; break; - case PR_CAP_FE: msg = "no frontend"; break; - case PR_CAP_BE|PR_CAP_FE: msg = "neither frontend nor backend"; break; - default: msg = "not enough"; break; - } - - if (!(proxy->cap & cap)) { - ha_alert("parsing [%s:%d] : '%s' not allowed because %s '%s' has %s capability.%s\n", - file, line, arg, proxy_type_str(proxy), proxy->id, msg, hint ? hint : ""); - return 1; - } - return 0; -} +int warnifnotcap(struct proxy *proxy, int cap, const char *file, int line, const char *arg, const char *hint); +int failifnotcap(struct proxy *proxy, int cap, const char *file, int line, const char *arg, const char *hint); /* simplified way to define a section parser */ #define REGISTER_CONFIG_SECTION(name, parse, post) \ diff --git a/src/cfgparse.c b/src/cfgparse.c index af727440bd..4b484bcdad 100644 --- a/src/cfgparse.c +++ b/src/cfgparse.c @@ -271,6 +271,56 @@ int str2receiver(char *str, struct proxy *curproxy, struct bind_conf *bind_conf, return 0; } +/* + * Sends a warning if proxy does not have at least one of the + * capabilities in . An optional may be added at the end + * of the warning to help the user. Returns 1 if a warning was emitted + * or 0 if the condition is valid. + */ +int warnifnotcap(struct proxy *proxy, int cap, const char *file, int line, const char *arg, const char *hint) +{ + char *msg; + + switch (cap) { + case PR_CAP_BE: msg = "no backend"; break; + case PR_CAP_FE: msg = "no frontend"; break; + case PR_CAP_BE|PR_CAP_FE: msg = "neither frontend nor backend"; break; + default: msg = "not enough"; break; + } + + if (!(proxy->cap & cap)) { + ha_warning("parsing [%s:%d] : '%s' ignored because %s '%s' has %s capability.%s\n", + file, line, arg, proxy_type_str(proxy), proxy->id, msg, hint ? hint : ""); + return 1; + } + return 0; +} + +/* + * Sends an alert if proxy does not have at least one of the + * capabilities in . An optional may be added at the end + * of the alert to help the user. Returns 1 if an alert was emitted + * or 0 if the condition is valid. + */ +int failifnotcap(struct proxy *proxy, int cap, const char *file, int line, const char *arg, const char *hint) +{ + char *msg; + + switch (cap) { + case PR_CAP_BE: msg = "no backend"; break; + case PR_CAP_FE: msg = "no frontend"; break; + case PR_CAP_BE|PR_CAP_FE: msg = "neither frontend nor backend"; break; + default: msg = "not enough"; break; + } + + if (!(proxy->cap & cap)) { + ha_alert("parsing [%s:%d] : '%s' not allowed because %s '%s' has %s capability.%s\n", + file, line, arg, proxy_type_str(proxy), proxy->id, msg, hint ? hint : ""); + return 1; + } + return 0; +} + /* * Report an error in when there are too many arguments. This version is * intended to be used by keyword parsers so that the message will be included