]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: action: Add a functions to check http capture rules
authorChristopher Faulet <cfaulet@haproxy.com>
Mon, 18 Sep 2017 13:26:32 +0000 (15:26 +0200)
committerWilly Tarreau <w@1wt.eu>
Tue, 31 Oct 2017 10:36:12 +0000 (11:36 +0100)
"check_http_req_capture" and "check_http_res_capture" functions have been added
to check validity of "http-request capture" and "http-response capture"
rules. Code for these functions come from cfgparse.c.

src/proto_http.c

index 3c37ade2725a3a4014f98746a1646957cc12f8c2..765146111b0d0dee759be2d7c29e8130784a8640 100644 (file)
@@ -11949,6 +11949,22 @@ enum act_return http_action_req_capture_by_id(struct act_rule *rule, struct prox
        return ACT_RET_CONT;
 }
 
+/* Check an "http-request capture" action.
+ *
+ * The function returns 1 in success case, otherwise, it returns 0 and err is
+ * filled.
+ */
+int check_http_req_capture(struct act_rule *rule, struct proxy *px, char **err)
+{
+       if (rule->arg.capid.idx >= px->nb_req_cap) {
+               memprintf(err, "unable to find capture id '%d' referenced by http-request capture rule",
+                         rule->arg.capid.idx);
+               return 0;
+       }
+
+       return 1;
+}
+
 /* parse an "http-request capture" action. It takes a single argument which is
  * a sample fetch expression. It stores the expression into arg->act.p[0] and
  * the allocated hdr_cap struct or the preallocated "id" into arg->act.p[1].
@@ -12034,6 +12050,7 @@ enum act_parse_ret parse_http_req_capture(const char **args, int *orig_arg, stru
 
                rule->action       = ACT_CUSTOM;
                rule->action_ptr   = http_action_req_capture;
+               rule->check_ptr    = check_http_req_capture;
                rule->arg.cap.expr = expr;
                rule->arg.cap.hdr  = hdr;
        }
@@ -12062,6 +12079,7 @@ enum act_parse_ret parse_http_req_capture(const char **args, int *orig_arg, stru
 
                rule->action       = ACT_CUSTOM;
                rule->action_ptr   = http_action_req_capture_by_id;
+               rule->check_ptr    = check_http_req_capture;
                rule->arg.capid.expr = expr;
                rule->arg.capid.idx  = id;
        }
@@ -12117,6 +12135,22 @@ enum act_return http_action_res_capture_by_id(struct act_rule *rule, struct prox
        return ACT_RET_CONT;
 }
 
+/* Check an "http-response capture" action.
+ *
+ * The function returns 1 in success case, otherwise, it returns 0 and err is
+ * filled.
+ */
+int check_http_res_capture(struct act_rule *rule, struct proxy *px, char **err)
+{
+       if (rule->arg.capid.idx >= px->nb_rsp_cap) {
+               memprintf(err, "unable to find capture id '%d' referenced by http-response capture rule",
+                         rule->arg.capid.idx);
+               return 0;
+       }
+
+       return 1;
+}
+
 /* parse an "http-response capture" action. It takes a single argument which is
  * a sample fetch expression. It stores the expression into arg->act.p[0] and
  * the allocated hdr_cap struct od the preallocated id into arg->act.p[1].
@@ -12185,6 +12219,7 @@ enum act_parse_ret parse_http_res_capture(const char **args, int *orig_arg, stru
 
        rule->action       = ACT_CUSTOM;
        rule->action_ptr   = http_action_res_capture_by_id;
+       rule->check_ptr    = check_http_res_capture;
        rule->arg.capid.expr = expr;
        rule->arg.capid.idx  = id;