mirror of
http://git.haproxy.org/git/haproxy.git/
synced 2025-01-02 10:12:03 +00:00
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.
This commit is contained in:
parent
197e10aaae
commit
21e5b0e3cb
@ -205,10 +205,8 @@ int acl_match_dom(struct sample *smp, struct acl_pattern *pattern);
|
||||
/* Check that the IPv4 address in <test> 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);
|
||||
|
||||
|
@ -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 */
|
||||
|
28
src/acl.c
28
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;
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user