From: Willy Tarreau Date: Mon, 23 Apr 2012 17:25:44 +0000 (+0200) Subject: MEDIUM: get rid of SMP_F_READ_ONLY and SMP_F_MUST_FREE X-Git-Tag: v1.5-dev9~47 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=21e5b0e3cbe6e53acdf4b8a171e029dcd479e985;p=thirdparty%2Fhaproxy.git MEDIUM: get rid of SMP_F_READ_ONLY and SMP_F_MUST_FREE These ones were either unused or improperly used. Some integers were marked read-only, which does not make much sense. Buffers are not read-only, they're "constant" in that they must be kept intact after any possible change. --- diff --git a/include/proto/acl.h b/include/proto/acl.h index e21075fb6b..998ac43620 100644 --- a/include/proto/acl.h +++ b/include/proto/acl.h @@ -205,10 +205,8 @@ int acl_match_dom(struct sample *smp, struct acl_pattern *pattern); /* Check that the IPv4 address in matches the IP/mask in pattern */ int acl_match_ip(struct sample *smp, struct acl_pattern *pattern); -/* Executes a regex. It needs to change the data. If it is marked READ_ONLY - * then it will be allocated and duplicated in place so that others may use - * it later on. Note that this is embarrassing because we always try to avoid - * allocating memory at run time. +/* Executes a regex. It temporarily changes the data to add a trailing zero, + * and restores the previous character when leaving. */ int acl_match_reg(struct sample *smp, struct acl_pattern *pattern); diff --git a/include/types/pattern.h b/include/types/pattern.h index 8fcc5d89c3..c710b207c2 100644 --- a/include/types/pattern.h +++ b/include/types/pattern.h @@ -54,10 +54,6 @@ enum { SMP_F_VOL_TXN = 1 << 5, /* result sensitive to new transaction (eg: HTTP version) */ SMP_F_VOL_SESS = 1 << 6, /* result sensitive to new session (eg: src IP) */ SMP_F_VOLATILE = (1<<2)|(1<<3)|(1<<4)|(1<<5)|(1<<6), /* any volatility condition */ - - SMP_F_READ_ONLY = 1 << 7, /* returned data must not be altered */ - SMP_F_MUST_FREE = 1 << 10, /* migration: this sample must be freed ASAP */ - }; /* pattern fetch direction */ diff --git a/src/acl.c b/src/acl.c index 9c4ce0ca53..5d86a3e1a1 100644 --- a/src/acl.c +++ b/src/acl.c @@ -623,32 +623,14 @@ static void *acl_lookup_str(struct sample *smp, struct acl_expr *expr) return node; } -/* Executes a regex. It needs to change the data. If it is marked READ_ONLY - * then it will be allocated and duplicated in place so that others may use - * it later on. Note that this is embarrassing because we always try to avoid - * allocating memory at run time. +/* Executes a regex. It temporarily changes the data to add a trailing zero, + * and restores the previous character when leaving. */ int acl_match_reg(struct sample *smp, struct acl_pattern *pattern) { char old_char; int ret; - if (unlikely(smp->flags & SMP_F_READ_ONLY)) { - char *new_str; - - new_str = calloc(1, smp->data.str.len + 1); - if (!new_str) - return ACL_PAT_FAIL; - - memcpy(new_str, smp->data.str.str, smp->data.str.len); - new_str[smp->data.str.len] = 0; - if (smp->flags & SMP_F_MUST_FREE) - free(smp->data.str.str); - smp->data.str.str = new_str; - smp->flags |= SMP_F_MUST_FREE; - smp->flags &= ~SMP_F_READ_ONLY; - } - old_char = smp->data.str.str[smp->data.str.len]; smp->data.str.str[smp->data.str.len] = 0; @@ -1903,12 +1885,6 @@ int acl_exec_cond(struct acl_cond *cond, struct proxy *px, struct session *l4, v * */ - /* now we may have some cleanup to do */ - if (smp.flags & SMP_F_MUST_FREE) { - free(smp.data.str.str); - smp.data.str.len = 0; - } - /* we're ORing these terms, so a single PASS is enough */ if (acl_res == ACL_PAT_PASS) break; diff --git a/src/backend.c b/src/backend.c index 4d0d86f14c..fc8f22fa2d 100644 --- a/src/backend.c +++ b/src/backend.c @@ -1456,7 +1456,6 @@ static int acl_fetch_be_id(struct proxy *px, struct session *l4, void *l7, int dir, struct acl_expr *expr, struct sample *smp) { - smp->flags = SMP_F_READ_ONLY; smp->flags = SMP_F_VOL_TXN; smp->type = SMP_T_UINT; smp->data.uint = l4->be->uuid; @@ -1471,7 +1470,6 @@ acl_fetch_srv_id(struct proxy *px, struct session *l4, void *l7, int dir, if (!target_srv(&l4->target)) return 0; - smp->flags = SMP_F_READ_ONLY; smp->type = SMP_T_UINT; smp->data.uint = target_srv(&l4->target)->puid; diff --git a/src/frontend.c b/src/frontend.c index 2e0237a8e1..c44cd920b8 100644 --- a/src/frontend.c +++ b/src/frontend.c @@ -502,7 +502,6 @@ static int acl_fetch_fe_id(struct proxy *px, struct session *l4, void *l7, int dir, struct acl_expr *expr, struct sample *smp) { - smp->flags = SMP_F_READ_ONLY; smp->flags = SMP_F_VOL_SESS; smp->type = SMP_T_UINT; smp->data.uint = l4->fe->uuid; diff --git a/src/proto_http.c b/src/proto_http.c index b6036d56bb..f3db6826b9 100644 --- a/src/proto_http.c +++ b/src/proto_http.c @@ -7665,7 +7665,7 @@ acl_fetch_meth(struct proxy *px, struct session *l4, void *l7, int dir, smp->data.str.len = txn->req.sl.rq.m_l; smp->data.str.str = txn->req.buf->p + txn->req.sol; } - smp->flags = SMP_F_READ_ONLY | SMP_F_VOL_1ST; + smp->flags = SMP_F_VOL_1ST; return 1; } @@ -7730,7 +7730,7 @@ acl_fetch_rqver(struct proxy *px, struct session *l4, void *l7, int dir, smp->data.str.str = ptr; smp->data.str.len = len; - smp->flags = SMP_F_READ_ONLY | SMP_F_VOL_1ST; + smp->flags = SMP_F_VOL_1ST; return 1; } @@ -7755,7 +7755,7 @@ acl_fetch_stver(struct proxy *px, struct session *l4, void *l7, int dir, smp->data.str.str = ptr; smp->data.str.len = len; - smp->flags = SMP_F_READ_ONLY | SMP_F_VOL_1ST; + smp->flags = SMP_F_VOL_1ST; return 1; } @@ -7837,7 +7837,7 @@ acl_fetch_url_port(struct proxy *px, struct session *l4, void *l7, int dir, if (px->options & PR_O_HTTP_PROXY) l4->flags |= SN_ADDR_SET; - smp->flags = SMP_F_READ_ONLY; + smp->flags = 0; return 1; } @@ -7965,8 +7965,6 @@ acl_fetch_path(struct proxy *px, struct session *l4, void *l7, int dir, ptr++; smp->data.str.len = ptr - smp->data.str.str; - - /* we do not need to set READ_ONLY because the data is in a buffer */ smp->flags = SMP_F_VOL_1ST; return 1; } diff --git a/src/protocols.c b/src/protocols.c index 12d719a90b..52ddbcc93d 100644 --- a/src/protocols.c +++ b/src/protocols.c @@ -338,7 +338,6 @@ static int acl_fetch_so_id(struct proxy *px, struct session *l4, void *l7, int dir, struct acl_expr *expr, struct sample *smp) { - smp->flags = SMP_F_READ_ONLY; smp->type = SMP_T_UINT; smp->data.uint = l4->listener->luid; return 1;