]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: pattern: find element in a reference
authorBaptiste Assmann <bedis9@gmail.com>
Fri, 25 Apr 2014 14:57:03 +0000 (16:57 +0200)
committerWilly Tarreau <w@1wt.eu>
Fri, 25 Apr 2014 15:31:13 +0000 (17:31 +0200)
This function can be used to look for an entry in either an ACL or a
MAP.

include/proto/pattern.h
src/pattern.c

index fdf9598280e6a759bd4eab5abd32efb30e8799ed..e6ceba8ed36f20f0529cf5e6eb80d26629ccfb64 100644 (file)
@@ -181,6 +181,7 @@ struct pat_ref *pat_ref_lookup(const char *reference);
 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);
 int pat_ref_append(struct pat_ref *ref, char *pattern, char *sample, int line);
 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);
index 3238fbb43fb86ed4bd21218025869c3fdee3c2f5..16aa09fbb7e67330b9b4c926075010e84d10da25 100644 (file)
@@ -1408,6 +1408,23 @@ int pat_ref_delete(struct pat_ref *ref, const char *key)
        return 1;
 }
 
+/*
+ * find and return an element <elt> matching <key> in a reference <ref>
+ * return NULL if not found
+ */
+struct pat_ref_elt *pat_ref_find_elt(struct pat_ref *ref, const char *key)
+{
+       struct pat_ref_elt *elt;
+
+       list_for_each_entry(elt, &ref->head, list) {
+               if (strcmp(key, elt->pattern) == 0)
+                       return elt;
+       }
+
+       return NULL;
+}
+
+
   /* This function modify the sample of the first pattern that match the <key>. */
 static inline int pat_ref_set_elt(struct pat_ref *ref, struct pat_ref_elt *elt,
                                   const char *value, char **err)