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.
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_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_delete(struct pat_ref *ref, const char *key);
void pat_ref_delete_by_ptr(struct pat_ref *ref, struct pat_ref_elt *elt);
HA_RWLOCK_WRLOCK(PATREF_LOCK, &ref->lock);
elt = pat_ref_find_elt(ref, key);
if (elt)
- pat_ref_set(ref, key, value, NULL, elt);
+ pat_ref_set_elt_duplicate(ref, elt, value, NULL);
else
pat_ref_add(ref, key, value, NULL);
HA_RWLOCK_WRUNLOCK(PATREF_LOCK, &ref->lock);
elt = pat_ref_find_elt(ref, key->area);
if (elt) {
/* 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 {
/* insert a new entry */
*/
err = NULL;
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);
if (err)
return cli_dynerr(appctx, memprintf(&err, "%s.\n", err));
return 0;
}
-/* 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 pat_ref_elt *elt)
+static int pat_ref_set_from_node(struct pat_ref *ref, struct ebmb_node *node, const char *value, char **err)
{
+ struct pat_ref_elt *elt;
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) {
char *tmp_err = NULL;
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
*
* Returns the new struct on success and NULL on failure (memory allocation