From: Willy Tarreau Date: Mon, 16 Apr 2012 15:21:11 +0000 (+0200) Subject: MEDIUM: http/acl: make acl_fetch_hdr_{ip,val} rely on acl_fetch_hdr() X-Git-Tag: v1.5-dev9~66 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d53e2428d162e10ef0ec95a77b59da7db7937adf;p=thirdparty%2Fhaproxy.git MEDIUM: http/acl: make acl_fetch_hdr_{ip,val} rely on acl_fetch_hdr() These two functions will now exploit the return of acl_fetch_hdr() instead of doing the same work again and again. --- diff --git a/src/proto_http.c b/src/proto_http.c index 5503b26ebd..b8b0af6f17 100644 --- a/src/proto_http.c +++ b/src/proto_http.c @@ -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