From: Aurelien DARRAGON Date: Wed, 20 Nov 2024 17:07:52 +0000 (+0100) Subject: MINOR: pattern: add pat_ref_gen_find_elt() function X-Git-Tag: v3.2-dev1~93 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a131c542a65e64181ce807311c6a17569dd23da0;p=thirdparty%2Fhaproxy.git MINOR: pattern: add pat_ref_gen_find_elt() function pat_ref_gen_find_elt(ref, gen_id, key) tries to find element belonging to and matching in reference. The goal is to be able to target a single subset from --- diff --git a/include/haproxy/pattern.h b/include/haproxy/pattern.h index 159eca18bb..6b915987c5 100644 --- a/include/haproxy/pattern.h +++ b/include/haproxy/pattern.h @@ -184,6 +184,7 @@ struct pat_ref *pat_ref_lookupid(int unique_id); struct pat_ref *pat_ref_new(const char *reference, const char *display, unsigned int flags); struct pat_ref *pat_ref_newid(int unique_id, const char *display, unsigned int flags); struct pat_ref_elt *pat_ref_find_elt(struct pat_ref *ref, const char *key); +struct pat_ref_elt *pat_ref_gen_find_elt(struct pat_ref *ref, unsigned int gen_id, const char *key); struct pat_ref_elt *pat_ref_append(struct pat_ref *ref, const char *pattern, const char *sample, int line); 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); diff --git a/src/pattern.c b/src/pattern.c index 01f27b669c..cf3bef96fe 100644 --- a/src/pattern.c +++ b/src/pattern.c @@ -1636,6 +1636,28 @@ int pat_ref_delete(struct pat_ref *ref, const char *key) return found; } +/* + * find and return an element belonging to and matching in a + * reference return NULL if not found + */ +struct pat_ref_elt *pat_ref_gen_find_elt(struct pat_ref *ref, unsigned int gen_id, const char *key) +{ + struct ebmb_node *node; + struct pat_ref_elt *elt; + + 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); + } + if (node) + return ebmb_entry(node, struct pat_ref_elt, node); + + return NULL; +} + /* * find and return an element matching in a reference * return NULL if not found