]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: proxy: Register keywords to parse errorfile and errorloc directives
authorChristopher Faulet <cfaulet@haproxy.com>
Thu, 16 Jan 2020 15:16:06 +0000 (16:16 +0100)
committerChristopher Faulet <cfaulet@haproxy.com>
Mon, 20 Jan 2020 14:18:46 +0000 (15:18 +0100)
errorfile and errorloc directives are now pased in dedicated functions in
http_htx.c.

src/cfgparse-listen.c
src/http_htx.c

index 9177181e7ec4d3f73f37014baa7f5186367f431c..61bf7cd829ec69ff9dcc62c300550a0d80b4f881 100644 (file)
@@ -3805,56 +3805,6 @@ stats_error_parsing:
                err_code |= ERR_ALERT | ERR_FATAL;
                goto out;
        }
-       else if (!strcmp(args[0], "errorloc") ||
-                !strcmp(args[0], "errorloc302") ||
-                !strcmp(args[0], "errorloc303")) { /* error location */
-               struct buffer *msg;
-               int errloc, status;
-
-               if (warnifnotcap(curproxy, PR_CAP_FE | PR_CAP_BE, file, linenum, args[0], NULL))
-                       err_code |= ERR_WARN;
-
-               if (*(args[1]) == 0 || *(args[2]) == 0) {
-                       ha_alert("parsing [%s:%d] : <%s> expects <status_code> and <url> as arguments.\n", file, linenum, args[0]);
-                       err_code |= ERR_ALERT | ERR_FATAL;
-                       goto out;
-               }
-
-               status = atol(args[1]);
-               errloc = (!strcmp(args[0], "errorloc303") ? 303 : 302);
-               msg = http_parse_errorloc(errloc, status, args[2], &errmsg);
-               if (!msg) {
-                       ha_alert("parsing [%s:%d] : %s: %s\n", file, linenum, args[0], errmsg);
-                       err_code |= ERR_ALERT | ERR_FATAL;
-                       goto out;
-               }
-               rc = http_get_status_idx(status);
-               curproxy->errmsg[rc] = msg;
-       }
-       else if (!strcmp(args[0], "errorfile")) { /* error message from a file */
-               struct buffer *msg;
-               int status;
-
-               if (warnifnotcap(curproxy, PR_CAP_FE | PR_CAP_BE, file, linenum, args[0], NULL))
-                       err_code |= ERR_WARN;
-
-               if (*(args[1]) == 0 || *(args[2]) == 0) {
-                       ha_alert("parsing [%s:%d] : %s: expects <status_code> and <file> as arguments.\n",
-                                file, linenum, args[0]);
-                       err_code |= ERR_ALERT | ERR_FATAL;
-                       goto out;
-               }
-
-               status = atol(args[1]);
-               msg = http_parse_errorfile(status, args[2], &errmsg);
-               if (!msg) {
-                       ha_alert("parsing [%s:%d] : %s: %s\n", file, linenum, args[0], errmsg);
-                       err_code |= ERR_ALERT | ERR_FATAL;
-                       goto out;
-               }
-               rc = http_get_status_idx(status);
-               curproxy->errmsg[rc] = msg;
-       }
        else {
                struct cfg_kw_list *kwl;
                int index;
index 33edcac800744dcc520ea5e0c88334403221df67..98a62bdc93bec98e591bfce104f2e5e9ce06aefe 100644 (file)
@@ -1050,6 +1050,87 @@ out:
        return buf;
 }
 
+/* Parses the "errorloc[302|303]" proxy keyword */
+static int proxy_parse_errorloc(char **args, int section, struct proxy *curpx,
+                                 struct proxy *defpx, const char *file, int line,
+                                 char **errmsg)
+{
+       struct buffer *msg;
+       int errloc, status, rc, ret = 0;
+
+       if (warnifnotcap(curpx, PR_CAP_FE | PR_CAP_BE, file, line, args[0], NULL)) {
+               ret = 1;
+               goto out;
+       }
+
+       if (*(args[1]) == 0 || *(args[2]) == 0) {
+               memprintf(errmsg, "%s : expects <status_code> and <url> as arguments.\n", args[0]);
+               ret = -1;
+               goto out;
+       }
+
+       status = atol(args[1]);
+       errloc = (!strcmp(args[0], "errorloc303") ? 303 : 302);
+       msg = http_parse_errorloc(errloc, status, args[2], errmsg);
+       if (!msg) {
+               memprintf(errmsg, "%s : %s", args[0], *errmsg);
+               ret = -1;
+               goto out;
+       }
+
+       rc = http_get_status_idx(status);
+       curpx->errmsg[rc] = msg;
+
+  out:
+       return ret;
+}
+
+
+/* Parses the "errorfile" proxy keyword */
+static int proxy_parse_errorfile(char **args, int section, struct proxy *curpx,
+                                struct proxy *defpx, const char *file, int line,
+                                char **errmsg)
+{
+       struct buffer *msg;
+       int status, rc, ret = 0;
+
+       if (warnifnotcap(curpx, PR_CAP_FE | PR_CAP_BE, file, line, args[0], NULL)) {
+               ret = 1;
+               goto out;
+       }
+
+       if (*(args[1]) == 0 || *(args[2]) == 0) {
+               memprintf(errmsg, "%s : expects <status_code> and <file> as arguments.\n", args[0]);
+               ret = -1;
+               goto out;
+       }
+
+       status = atol(args[1]);
+       msg = http_parse_errorfile(status, args[2], errmsg);
+       if (!msg) {
+               memprintf(errmsg, "%s : %s", args[0], *errmsg);
+               ret = -1;
+               goto out;
+       }
+
+       rc = http_get_status_idx(status);
+       curpx->errmsg[rc] = msg;
+
+  out:
+       return ret;
+
+}
+
+static struct cfg_kw_list cfg_kws = {ILH, {
+        { CFG_LISTEN, "errorloc",     proxy_parse_errorloc },
+        { CFG_LISTEN, "errorloc302",  proxy_parse_errorloc },
+        { CFG_LISTEN, "errorloc303",  proxy_parse_errorloc },
+        { CFG_LISTEN, "errorfile",    proxy_parse_errorfile },
+        { 0, NULL, NULL },
+}};
+
+INITCALL1(STG_REGISTER, cfg_register_keywords, &cfg_kws);
+
 /************************************************************************/
 /*                             HTX sample fetches                       */
 /************************************************************************/