From: Christopher Faulet Date: Thu, 9 Apr 2020 16:12:08 +0000 (+0200) Subject: MINOR: proxy/checks: Register a keyword to parse external-check rules X-Git-Tag: v2.2-dev7~110 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=e9111b6892b8d8dc7f6e4daed0d7b959923b4e00;p=thirdparty%2Fhaproxy.git MINOR: proxy/checks: Register a keyword to parse external-check rules The keyword 'external-check' is now parsed in a dedicated callback function. Thus the code to parse these rules is now located in checks.c. --- diff --git a/src/cfgparse-listen.c b/src/cfgparse-listen.c index ddc7ba2d35..d5d52ae6f5 100644 --- a/src/cfgparse-listen.c +++ b/src/cfgparse-listen.c @@ -1150,45 +1150,6 @@ int cfg_parse_listen(const char *file, int linenum, char **args, int kwm) /* Indicate that the email_alert is at least partially configured */ curproxy->email_alert.set = 1; }/* end else if (!strcmp(args[0], "email-alert")) */ - else if (!strcmp(args[0], "external-check")) { - if (*(args[1]) == 0) { - ha_alert("parsing [%s:%d] : missing argument after '%s'.\n", - file, linenum, args[0]); - err_code |= ERR_ALERT | ERR_FATAL; - goto out; - } - - if (!strcmp(args[1], "command")) { - if (alertif_too_many_args(2, file, linenum, args, &err_code)) - goto out; - if (*(args[2]) == 0) { - ha_alert("parsing [%s:%d] : missing argument after '%s'.\n", - file, linenum, args[1]); - err_code |= ERR_ALERT | ERR_FATAL; - goto out; - } - free(curproxy->check_command); - curproxy->check_command = strdup(args[2]); - } - else if (!strcmp(args[1], "path")) { - if (alertif_too_many_args(2, file, linenum, args, &err_code)) - goto out; - if (*(args[2]) == 0) { - ha_alert("parsing [%s:%d] : missing argument after '%s'.\n", - file, linenum, args[1]); - err_code |= ERR_ALERT | ERR_FATAL; - goto out; - } - free(curproxy->check_path); - curproxy->check_path = strdup(args[2]); - } - else { - ha_alert("parsing [%s:%d] : external-check: unknown argument '%s'.\n", - file, linenum, args[1]); - err_code |= ERR_ALERT | ERR_FATAL; - goto out; - } - }/* end else if (!strcmp(args[0], "external-check")) */ else if (!strcmp(args[0], "persist")) { /* persist */ if (*(args[1]) == 0) { ha_alert("parsing [%s:%d] : missing persist method.\n", diff --git a/src/checks.c b/src/checks.c index cfe10f8fa8..b9af7706ec 100644 --- a/src/checks.c +++ b/src/checks.c @@ -5265,6 +5265,51 @@ static int proxy_parse_httpcheck(char **args, int section, struct proxy *curpx, return -1; } +/* Parses the "external-check" proxy keyword */ +static int proxy_parse_extcheck(char **args, int section, struct proxy *curpx, + struct proxy *defpx, const char *file, int line, + char **errmsg) +{ + int cur_arg, ret = 0; + + cur_arg = 1; + if (!*(args[cur_arg])) { + memprintf(errmsg, "missing argument after '%s'.\n", args[0]); + goto error; + } + + if (strcmp(args[cur_arg], "command") == 0) { + if (too_many_args(2, args, errmsg, NULL)) + goto error; + if (!*(args[cur_arg+1])) { + memprintf(errmsg, "missing argument after '%s'.", args[cur_arg]); + goto error; + } + free(curpx->check_command); + curpx->check_command = strdup(args[cur_arg+1]); + } + else if (strcmp(args[cur_arg], "path") == 0) { + if (too_many_args(2, args, errmsg, NULL)) + goto error; + if (!*(args[cur_arg+1])) { + memprintf(errmsg, "missing argument after '%s'.", args[cur_arg]); + goto error; + } + free(curpx->check_path); + curpx->check_path = strdup(args[cur_arg+1]); + } + else { + memprintf(errmsg, "'%s' only supports 'command' and 'path'. but got '%s'.", + args[0], args[1]); + goto error; + } + + ret = (*errmsg != NULL); /* Handle warning */ + return ret; + +error: + return -1; +} static struct tcpcheck_ruleset *tcpcheck_ruleset_lookup(const char *name) { @@ -6886,8 +6931,9 @@ static int srv_parse_check_port(char **args, int *cur_arg, struct proxy *curpx, } static struct cfg_kw_list cfg_kws = {ILH, { - { CFG_LISTEN, "tcp-check", proxy_parse_tcpcheck }, - { CFG_LISTEN, "http-check", proxy_parse_httpcheck }, + { CFG_LISTEN, "tcp-check", proxy_parse_tcpcheck }, + { CFG_LISTEN, "http-check", proxy_parse_httpcheck }, + { CFG_LISTEN, "external-check", proxy_parse_extcheck }, { 0, NULL, NULL }, }};