[MEDIUM] modularize the "timeout" keyword configuration parser
The "timeout" keyword already relied on an external parser, let's make use of the new keyword registration mechanism.
This commit is contained in:
parent
39f23b6c7e
commit
9de1bbd004
|
@ -38,8 +38,6 @@ const char *proxy_cap_str(int cap);
|
||||||
const char *proxy_mode_str(int mode);
|
const char *proxy_mode_str(int mode);
|
||||||
struct proxy *findproxy(const char *name, int mode, int cap);
|
struct proxy *findproxy(const char *name, int mode, int cap);
|
||||||
struct server *findserver(const struct proxy *px, const char *name);
|
struct server *findserver(const struct proxy *px, const char *name);
|
||||||
int proxy_parse_timeout(const char **args, struct proxy *proxy,
|
|
||||||
struct proxy *defpx, char *err, int errlen);
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This function returns a string containing the type of the proxy in a format
|
* This function returns a string containing the type of the proxy in a format
|
||||||
|
|
|
@ -1087,27 +1087,6 @@ int cfg_parse_listen(const char *file, int linenum, char **args, int inv)
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (!strcmp(args[0], "contimeout") || !strcmp(args[0], "clitimeout") ||
|
|
||||||
!strcmp(args[0], "srvtimeout") || !strcmp(args[0], "timeout")) {
|
|
||||||
|
|
||||||
/* either we have {con|srv|cli}timeout <value> or we have the
|
|
||||||
* new form: timeout <type> <value>. The parser needs the word
|
|
||||||
* preceeding the value.
|
|
||||||
*/
|
|
||||||
const char **start_arg = (const char **)args;
|
|
||||||
|
|
||||||
if (strcmp(args[0], "timeout") == 0)
|
|
||||||
start_arg++;
|
|
||||||
|
|
||||||
snprintf(trash, sizeof(trash), "error near '%s'", args[0]);
|
|
||||||
rc = proxy_parse_timeout(start_arg, curproxy, &defproxy, trash, sizeof(trash));
|
|
||||||
if (rc < 0) {
|
|
||||||
Alert("parsing [%s:%d] : %s\n", file, linenum, trash);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
if (rc > 0)
|
|
||||||
Warning("parsing [%s:%d] : %s\n", file, linenum, trash);
|
|
||||||
}
|
|
||||||
else if (!strcmp(args[0], "retries")) { /* connection retries */
|
else if (!strcmp(args[0], "retries")) { /* connection retries */
|
||||||
if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
|
if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
|
||||||
return 0;
|
return 0;
|
||||||
|
|
25
src/proxy.c
25
src/proxy.c
|
@ -18,6 +18,7 @@
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
|
|
||||||
#include <common/defaults.h>
|
#include <common/defaults.h>
|
||||||
|
#include <common/cfgparse.h>
|
||||||
#include <common/compat.h>
|
#include <common/compat.h>
|
||||||
#include <common/config.h>
|
#include <common/config.h>
|
||||||
#include <common/errors.h>
|
#include <common/errors.h>
|
||||||
|
@ -80,12 +81,12 @@ const char *proxy_mode_str(int mode) {
|
||||||
* return zero, it may write an error message into the <err> buffer, for at
|
* return zero, it may write an error message into the <err> buffer, for at
|
||||||
* most <errlen> bytes, trailing zero included. The trailing '\n' must not
|
* most <errlen> bytes, trailing zero included. The trailing '\n' must not
|
||||||
* be written. The function must be called with <args> pointing to the first
|
* be written. The function must be called with <args> pointing to the first
|
||||||
* word after "timeout", with <proxy> pointing to the proxy being parsed, and
|
* command line word, with <proxy> pointing to the proxy being parsed, and
|
||||||
* <defpx> to the default proxy or NULL. As a special case for compatibility
|
* <defpx> to the default proxy or NULL. As a special case for compatibility
|
||||||
* with older configs, it also accepts "{cli|srv|con}timeout" in args[0].
|
* with older configs, it also accepts "{cli|srv|con}timeout" in args[0].
|
||||||
*/
|
*/
|
||||||
int proxy_parse_timeout(const char **args, struct proxy *proxy,
|
static int proxy_parse_timeout(char **args, int section, struct proxy *proxy,
|
||||||
struct proxy *defpx, char *err, int errlen)
|
struct proxy *defpx, char *err, int errlen)
|
||||||
{
|
{
|
||||||
unsigned timeout;
|
unsigned timeout;
|
||||||
int retval, cap;
|
int retval, cap;
|
||||||
|
@ -94,6 +95,11 @@ int proxy_parse_timeout(const char **args, struct proxy *proxy,
|
||||||
int *td = NULL;
|
int *td = NULL;
|
||||||
|
|
||||||
retval = 0;
|
retval = 0;
|
||||||
|
|
||||||
|
/* simply skip "timeout" but remain compatible with old form */
|
||||||
|
if (strcmp(args[0], "timeout") == 0)
|
||||||
|
args++;
|
||||||
|
|
||||||
name = args[0];
|
name = args[0];
|
||||||
if (!strcmp(args[0], "client") || !strcmp(args[0], "clitimeout")) {
|
if (!strcmp(args[0], "client") || !strcmp(args[0], "clitimeout")) {
|
||||||
name = "client";
|
name = "client";
|
||||||
|
@ -500,6 +506,19 @@ void listen_proxies(void)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static struct cfg_kw_list cfg_kws = {{ },{
|
||||||
|
{ CFG_LISTEN, "timeout", proxy_parse_timeout },
|
||||||
|
{ CFG_LISTEN, "clitimeout", proxy_parse_timeout },
|
||||||
|
{ CFG_LISTEN, "contimeout", proxy_parse_timeout },
|
||||||
|
{ CFG_LISTEN, "srvtimeout", proxy_parse_timeout },
|
||||||
|
{ 0, NULL, NULL },
|
||||||
|
}};
|
||||||
|
|
||||||
|
__attribute__((constructor))
|
||||||
|
static void __proxy_module_init(void)
|
||||||
|
{
|
||||||
|
cfg_register_keywords(&cfg_kws);
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Local variables:
|
* Local variables:
|
||||||
|
|
Loading…
Reference in New Issue