From 29730ba570f17790193ede6dbf9edb259b434f3b Mon Sep 17 00:00:00 2001 From: Christopher Faulet Date: Mon, 18 Sep 2017 15:26:32 +0200 Subject: [PATCH] MINOR: action: Add a functions to check http capture rules "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 | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/src/proto_http.c b/src/proto_http.c index 3c37ade272..765146111b 100644 --- a/src/proto_http.c +++ b/src/proto_http.c @@ -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;