]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
[MEDIUM] modularize the "timeout" keyword configuration parser
authorWilly Tarreau <w@1wt.eu>
Wed, 9 Jul 2008 18:34:27 +0000 (20:34 +0200)
committerWilly Tarreau <w@1wt.eu>
Wed, 9 Jul 2008 18:34:27 +0000 (20:34 +0200)
The "timeout" keyword already relied on an external parser, let's
make use of the new keyword registration mechanism.

include/proto/proxy.h
src/cfgparse.c
src/proxy.c

index 78f612053938a939ec285c1b30554c01691330d6..4707e9acfe2f572550e58a8bb10a07433a2db45f 100644 (file)
@@ -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
index 91e6c558c1e631db55800eddbcc39d573c6e0805..b2af64814119f527d6f4230a9e36865e6e60f175 100644 (file)
@@ -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 <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 */
                if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL))
                        return 0;
index e597fc5c4abab28306b067a2e2c8faa2896ff83f..f9589ecea40a2c24323b98c775e426b2a2164a2e 100644 (file)
@@ -18,6 +18,7 @@
 #include <sys/stat.h>
 
 #include <common/defaults.h>
+#include <common/cfgparse.h>
 #include <common/compat.h>
 #include <common/config.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
  * most <errlen> bytes, trailing zero included. The trailing '\n' must not
  * 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
  * 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: