]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: pattern: add pat_ref_gen_delete() function
authorAurelien DARRAGON <adarragon@haproxy.com>
Wed, 20 Nov 2024 17:18:54 +0000 (18:18 +0100)
committerAurelien DARRAGON <adarragon@haproxy.com>
Tue, 26 Nov 2024 15:12:21 +0000 (16:12 +0100)
pat_ref_gen_delete(ref, gen_id, key) tries to delete all samples belonging
to <gen_id> and matching <key> under <ref>

The goal is to be able to target a single subset from <ref>

include/haproxy/pattern.h
src/pattern.c

index 6b915987c5d4a81214594011cff983247ff0dae2..283eb5b0860994b958076f47b900b96682705ecc 100644 (file)
@@ -194,6 +194,7 @@ int pat_ref_set_elt_duplicate(struct pat_ref *ref, struct pat_ref_elt *elt, cons
 int pat_ref_gen_set(struct pat_ref *ref, unsigned int gen_id, const char *key, 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_gen_delete(struct pat_ref *ref, unsigned int gen_id, const char *key);
 void pat_ref_delete_by_ptr(struct pat_ref *ref, struct pat_ref_elt *elt);
 int pat_ref_delete_by_id(struct pat_ref *ref, struct pat_ref_elt *refelt);
 int pat_ref_prune(struct pat_ref *ref);
index cf3bef96fe50b025cd76bb051bbd822a8089bd90..c433c10b202c217d933c2c299b67f1b814482c5c 100644 (file)
@@ -1613,6 +1613,32 @@ int pat_ref_delete_by_id(struct pat_ref *ref, struct pat_ref_elt *refelt)
        return 0;
 }
 
+/* This function removes all elements belonging to <gen_id> and matching <key>
+ * from the reference <ref>.
+ * This function returns 1 if the deletion is done and returns 0 if
+ * the entry is not found.
+ */
+int pat_ref_gen_delete(struct pat_ref *ref, unsigned int gen_id, const char *key)
+{
+       struct ebmb_node *node;
+       int found = 0;
+
+       /* delete pattern from reference */
+       node = ebst_lookup(&ref->ebmb_root, key);
+       while (node) {
+               struct pat_ref_elt *elt;
+
+               elt = ebmb_entry(node, struct pat_ref_elt, node);
+               node = ebmb_next_dup(node);
+               if (elt->gen_id != gen_id)
+                       continue;
+               pat_ref_delete_by_ptr(ref, elt);
+               found = 1;
+       }
+
+       return found;
+}
+
 /* This function removes all patterns matching <key> from the reference
  * and from each expr member of the reference. This function returns 1
  * if the deletion is done and returns 0 is the entry is not found.