From 9de1bbd004d3053b426533e22f6d85ad2d614635 Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Wed, 9 Jul 2008 20:34:27 +0200 Subject: [PATCH] [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. --- include/proto/proxy.h | 2 -- src/cfgparse.c | 21 --------------------- src/proxy.c | 25 ++++++++++++++++++++++--- 3 files changed, 22 insertions(+), 26 deletions(-) diff --git a/include/proto/proxy.h b/include/proto/proxy.h index 78f612053..4707e9acf 100644 --- a/include/proto/proxy.h +++ b/include/proto/proxy.h @@ -38,8 +38,6 @@ const char *proxy_cap_str(int cap); const char *proxy_mode_str(int mode); struct proxy *findproxy(const char *name, int mode, int cap); 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 diff --git a/src/cfgparse.c b/src/cfgparse.c index 91e6c558c..b2af64814 100644 --- a/src/cfgparse.c +++ b/src/cfgparse.c @@ -1087,27 +1087,6 @@ int cfg_parse_listen(const char *file, int linenum, char **args, int inv) 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 or we have the - * new form: timeout . 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 */ if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) return 0; diff --git a/src/proxy.c b/src/proxy.c index e597fc5c4..f9589ecea 100644 --- a/src/proxy.c +++ b/src/proxy.c @@ -18,6 +18,7 @@ #include #include +#include #include #include #include @@ -80,12 +81,12 @@ const char *proxy_mode_str(int mode) { * return zero, it may write an error message into the buffer, for at * most bytes, trailing zero included. The trailing '\n' must not * be written. The function must be called with pointing to the first - * word after "timeout", with pointing to the proxy being parsed, and + * command line word, with pointing to the proxy being parsed, and * 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]. */ -int proxy_parse_timeout(const char **args, struct proxy *proxy, - struct proxy *defpx, char *err, int errlen) +static int proxy_parse_timeout(char **args, int section, struct proxy *proxy, + struct proxy *defpx, char *err, int errlen) { unsigned timeout; int retval, cap; @@ -94,6 +95,11 @@ int proxy_parse_timeout(const char **args, struct proxy *proxy, int *td = NULL; retval = 0; + + /* simply skip "timeout" but remain compatible with old form */ + if (strcmp(args[0], "timeout") == 0) + args++; + name = args[0]; if (!strcmp(args[0], "client") || !strcmp(args[0], "clitimeout")) { 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: