]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: pattern: add pat_ref_gen_set() function
authorAurelien DARRAGON <adarragon@haproxy.com>
Wed, 20 Nov 2024 16:30:39 +0000 (17:30 +0100)
committerAurelien DARRAGON <adarragon@haproxy.com>
Tue, 26 Nov 2024 15:12:11 +0000 (16:12 +0100)
pat_ref_gen_set(ref, gen_id, value, err) modifies to <value> the sample
of all patterns matching <key> and belonging to <gen_id> (generation id)
under <ref>

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

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

index db0a8a32f3e9a5c88c3f7895ea3a6c5f8e118653..159eca18bb1e6c6fd1aee92a0871bc71fd946cde 100644 (file)
@@ -190,6 +190,7 @@ int pat_ref_push(struct pat_ref_elt *elt, struct pattern_expr *expr, int patflag
 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);
 int pat_ref_set_elt_duplicate(struct pat_ref *ref, struct pat_ref_elt *elt, const char *value, char **err);
+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);
 void pat_ref_delete_by_ptr(struct pat_ref *ref, struct pat_ref_elt *elt);
index e8e995deba15a3bcef10906c52e646ae80e240de..01f27b669cb031c8ea6bc28c4b7c42486d41c21e 100644 (file)
@@ -1788,6 +1788,26 @@ int pat_ref_set_elt_duplicate(struct pat_ref *ref, struct pat_ref_elt *elt, cons
        return pat_ref_set_from_node(ref, &elt->node, value, err);
 }
 
+/* This function modifies to <value> the sample of all patterns matching <key>
+ * and belonging to <gen_id> under <ref>.
+ */
+int pat_ref_gen_set(struct pat_ref *ref, unsigned int gen_id,
+                    const char *key, const char *value, char **err)
+{
+       struct ebmb_node *node;
+       struct pat_ref_elt *elt;
+
+       /* Look for pattern in the reference. */
+       node = ebst_lookup(&ref->ebmb_root, key);
+       while (node) {
+               elt = ebmb_entry(node, struct pat_ref_elt, node);
+               if (elt->gen_id == gen_id)
+                       break;
+               node = ebmb_next_dup(node);
+       }
+       return pat_ref_set_from_node(ref, node, value, err);
+}
+
 /* This function modifies to <value> the sample of all patterns matching <key>
  * under <ref>.
  */