]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MEDIUM: http/acl: make acl_fetch_hdr_{ip,val} rely on acl_fetch_hdr()
authorWilly Tarreau <w@1wt.eu>
Mon, 16 Apr 2012 15:21:11 +0000 (17:21 +0200)
committerWilly Tarreau <w@1wt.eu>
Tue, 8 May 2012 18:57:10 +0000 (20:57 +0200)
These two functions will now exploit the return of acl_fetch_hdr() instead
of doing the same work again and again.

src/proto_http.c

index 5503b26ebdd6e49ba1ce695f860a00635c1d0c4e..b8b0af6f17c4e1491982c2e2d4b36396c9dd9f55 100644 (file)
@@ -7897,27 +7897,12 @@ static int
 acl_fetch_hdr_val(struct proxy *px, struct session *l4, void *l7, int dir,
                   struct acl_expr *expr, struct acl_test *test)
 {
-       struct http_txn *txn = l7;
-       struct hdr_idx *idx = &txn->hdr_idx;
-       struct hdr_ctx *ctx = (struct hdr_ctx *)test->ctx.a;
-       const struct http_msg *msg = ((dir & ACL_DIR_MASK) == ACL_DIR_REQ) ? &txn->req : &txn->rsp;
-
-       CHECK_HTTP_MESSAGE_FIRST();
-
-       if (!(test->flags & ACL_TEST_F_FETCH_MORE))
-               /* search for header from the beginning */
-               ctx->idx = 0;
+       int ret = acl_fetch_hdr(px, l4, l7, dir, expr, test);
 
-       if (http_find_header2(expr->arg.str, expr->arg_len, msg->buf->p + msg->sol, idx, ctx)) {
-               test->flags |= ACL_TEST_F_FETCH_MORE;
-               test->flags |= ACL_TEST_F_VOL_HDR;
-               temp_pattern.data.integer = strl2ic((char *)ctx->line + ctx->val, ctx->vlen);
-               return 1;
-       }
+       if (ret > 0)
+               temp_pattern.data.integer = strl2ic(temp_pattern.data.str.str, temp_pattern.data.str.len);
 
-       test->flags &= ~ACL_TEST_F_FETCH_MORE;
-       test->flags |= ACL_TEST_F_VOL_HDR;
-       return 0;
+       return ret;
 }
 
 /* 7. Check on HTTP header's IPv4 address value. The IPv4 address is returned.
@@ -7926,30 +7911,15 @@ static int
 acl_fetch_hdr_ip(struct proxy *px, struct session *l4, void *l7, int dir,
                   struct acl_expr *expr, struct acl_test *test)
 {
-       struct http_txn *txn = l7;
-       struct hdr_idx *idx = &txn->hdr_idx;
-       struct hdr_ctx *ctx = (struct hdr_ctx *)test->ctx.a;
-       const struct http_msg *msg = ((dir & ACL_DIR_MASK) == ACL_DIR_REQ) ? &txn->req : &txn->rsp;
-
-       CHECK_HTTP_MESSAGE_FIRST();
-
-       if (!(test->flags & ACL_TEST_F_FETCH_MORE))
-               /* search for header from the beginning */
-               ctx->idx = 0;
+       int ret;
 
-       while (http_find_header2(expr->arg.str, expr->arg_len, msg->buf->p + msg->sol, idx, ctx)) {
-               test->flags |= ACL_TEST_F_FETCH_MORE;
-               test->flags |= ACL_TEST_F_VOL_HDR;
-               /* Same optimization as url_ip */
+       while ((ret = acl_fetch_hdr(px, l4, l7, dir, expr, test)) > 0) {
                temp_pattern.type = PATTERN_TYPE_IP;
-               if (url2ipv4((char *)ctx->line + ctx->val, &temp_pattern.data.ip))
-                       return 1;
-               /* Dods not look like an IP address, let's fetch next one */
+               if (url2ipv4((char *)temp_pattern.data.str.str, &temp_pattern.data.ip))
+                       break;
+               /* if the header doesn't match an IP address, fetch next one */
        }
-
-       test->flags &= ~ACL_TEST_F_FETCH_MORE;
-       test->flags |= ACL_TEST_F_VOL_HDR;
-       return 0;
+       return ret;
 }
 
 /* 8. Check on URI PATH. A pointer to the PATH is stored. The path starts at