mirror of
https://git.haproxy.org/git/haproxy.git/
synced 2025-09-21 22:01:31 +02:00
MINOR: pattern: split pat_ref_set()
split pat_ref_set() function in 2 distinct functions. Indeed, since 0844bed7d3 ("MEDIUM: map/acl: Improve pat_ref_set() efficiency (for "set-map", "add-acl" action perfs)"), pat_ref_set() prototype was updated to include an extra <elt> argument. But the logic behind is not explicit because the function will not only try to set <elt>, but also its duplicate (unlike pat_ref_set_elt() which only tries to update <elt>). Thus, to make it clearer and better distinguish between the key-based lookup version and the elt-based one, restotre pat_ref_set() previous prototype and add a dedicated pat_ref_set_elt_duplicate() that takes <elt> as argument and tries to update <elt> and all duplicates.
This commit is contained in:
parent
4d58f521ee
commit
3d250b3be8
@ -188,7 +188,8 @@ struct pat_ref_elt *pat_ref_append(struct pat_ref *ref, const char *pattern, con
|
|||||||
struct pat_ref_elt *pat_ref_load(struct pat_ref *ref, unsigned int gen, const char *pattern, const char *sample, int line, char **err);
|
struct pat_ref_elt *pat_ref_load(struct pat_ref *ref, unsigned int gen, const char *pattern, const char *sample, int line, char **err);
|
||||||
int pat_ref_push(struct pat_ref_elt *elt, struct pattern_expr *expr, int patflags, char **err);
|
int pat_ref_push(struct pat_ref_elt *elt, struct pattern_expr *expr, int patflags, char **err);
|
||||||
int pat_ref_add(struct pat_ref *ref, const char *pattern, const char *sample, char **err);
|
int pat_ref_add(struct pat_ref *ref, const char *pattern, const char *sample, char **err);
|
||||||
int pat_ref_set(struct pat_ref *ref, const char *pattern, const char *sample, char **err, struct pat_ref_elt *elt);
|
int pat_ref_set(struct pat_ref *ref, const char *pattern, const char *sample, char **err);
|
||||||
|
int pat_ref_set_elt_duplicate(struct pat_ref *ref, struct pat_ref_elt *elt, const char *value, char **err);
|
||||||
int pat_ref_set_by_id(struct pat_ref *ref, struct pat_ref_elt *refelt, const char *value, char **err);
|
int pat_ref_set_by_id(struct pat_ref *ref, struct pat_ref_elt *refelt, const char *value, char **err);
|
||||||
int pat_ref_delete(struct pat_ref *ref, const char *key);
|
int pat_ref_delete(struct pat_ref *ref, const char *key);
|
||||||
void pat_ref_delete_by_ptr(struct pat_ref *ref, struct pat_ref_elt *elt);
|
void pat_ref_delete_by_ptr(struct pat_ref *ref, struct pat_ref_elt *elt);
|
||||||
|
@ -2294,7 +2294,7 @@ static int hlua_set_map(lua_State *L)
|
|||||||
HA_RWLOCK_WRLOCK(PATREF_LOCK, &ref->lock);
|
HA_RWLOCK_WRLOCK(PATREF_LOCK, &ref->lock);
|
||||||
elt = pat_ref_find_elt(ref, key);
|
elt = pat_ref_find_elt(ref, key);
|
||||||
if (elt)
|
if (elt)
|
||||||
pat_ref_set(ref, key, value, NULL, elt);
|
pat_ref_set_elt_duplicate(ref, elt, value, NULL);
|
||||||
else
|
else
|
||||||
pat_ref_add(ref, key, value, NULL);
|
pat_ref_add(ref, key, value, NULL);
|
||||||
HA_RWLOCK_WRUNLOCK(PATREF_LOCK, &ref->lock);
|
HA_RWLOCK_WRUNLOCK(PATREF_LOCK, &ref->lock);
|
||||||
|
@ -1848,7 +1848,7 @@ static enum act_return http_action_set_map(struct act_rule *rule, struct proxy *
|
|||||||
elt = pat_ref_find_elt(ref, key->area);
|
elt = pat_ref_find_elt(ref, key->area);
|
||||||
if (elt) {
|
if (elt) {
|
||||||
/* update entry if it exists */
|
/* update entry if it exists */
|
||||||
pat_ref_set(ref, key->area, value->area, NULL, elt);
|
pat_ref_set_elt_duplicate(ref, elt, value->area, NULL);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
/* insert a new entry */
|
/* insert a new entry */
|
||||||
|
@ -808,7 +808,7 @@ static int cli_parse_set_map(char **args, char *payload, struct appctx *appctx,
|
|||||||
*/
|
*/
|
||||||
err = NULL;
|
err = NULL;
|
||||||
HA_RWLOCK_WRLOCK(PATREF_LOCK, &ctx->ref->lock);
|
HA_RWLOCK_WRLOCK(PATREF_LOCK, &ctx->ref->lock);
|
||||||
if (!pat_ref_set(ctx->ref, args[3], args[4], &err, NULL)) {
|
if (!pat_ref_set(ctx->ref, args[3], args[4], &err)) {
|
||||||
HA_RWLOCK_WRUNLOCK(PATREF_LOCK, &ctx->ref->lock);
|
HA_RWLOCK_WRUNLOCK(PATREF_LOCK, &ctx->ref->lock);
|
||||||
if (err)
|
if (err)
|
||||||
return cli_dynerr(appctx, memprintf(&err, "%s.\n", err));
|
return cli_dynerr(appctx, memprintf(&err, "%s.\n", err));
|
||||||
|
@ -1754,21 +1754,10 @@ int pat_ref_set_by_id(struct pat_ref *ref, struct pat_ref_elt *refelt, const cha
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* This function modifies to <value> the sample of all patterns matching <key>
|
static int pat_ref_set_from_node(struct pat_ref *ref, struct ebmb_node *node, const char *value, char **err)
|
||||||
* under <ref>.
|
|
||||||
*/
|
|
||||||
int pat_ref_set(struct pat_ref *ref, const char *key, const char *value, char **err, struct pat_ref_elt *elt)
|
|
||||||
{
|
{
|
||||||
|
struct pat_ref_elt *elt;
|
||||||
int found = 0;
|
int found = 0;
|
||||||
struct ebmb_node *node;
|
|
||||||
|
|
||||||
if (elt) {
|
|
||||||
node = &elt->node;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
/* Look for pattern in the reference. */
|
|
||||||
node = ebst_lookup(&ref->ebmb_root, key);
|
|
||||||
}
|
|
||||||
|
|
||||||
while (node) {
|
while (node) {
|
||||||
char *tmp_err = NULL;
|
char *tmp_err = NULL;
|
||||||
@ -1792,6 +1781,25 @@ int pat_ref_set(struct pat_ref *ref, const char *key, const char *value, char **
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* modifies to <value> the sample for <elt> and all its duplicates */
|
||||||
|
int pat_ref_set_elt_duplicate(struct pat_ref *ref, struct pat_ref_elt *elt, const char *value,
|
||||||
|
char **err)
|
||||||
|
{
|
||||||
|
return pat_ref_set_from_node(ref, &elt->node, value, err);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* This function modifies to <value> the sample of all patterns matching <key>
|
||||||
|
* under <ref>.
|
||||||
|
*/
|
||||||
|
int pat_ref_set(struct pat_ref *ref, const char *key, const char *value, char **err)
|
||||||
|
{
|
||||||
|
struct ebmb_node *node;
|
||||||
|
|
||||||
|
/* Look for pattern in the reference. */
|
||||||
|
node = ebst_lookup(&ref->ebmb_root, key);
|
||||||
|
return pat_ref_set_from_node(ref, node, value, err);
|
||||||
|
}
|
||||||
|
|
||||||
/* helper function to create and initialize a generic pat_ref struct
|
/* helper function to create and initialize a generic pat_ref struct
|
||||||
*
|
*
|
||||||
* Returns the new struct on success and NULL on failure (memory allocation
|
* Returns the new struct on success and NULL on failure (memory allocation
|
||||||
|
Loading…
x
Reference in New Issue
Block a user