]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: sample: add function for browsing samples.
authorThierry FOURNIER <tfournier@haproxy.com>
Mon, 8 Dec 2014 13:49:19 +0000 (14:49 +0100)
committerWilly Tarreau <w@1wt.eu>
Sat, 28 Feb 2015 22:12:32 +0000 (23:12 +0100)
This function is useful with the incoming lua functions.

include/proto/sample.h
src/sample.c

index 6b76662589c781bc8feaf602b3107ec22037d13c..19b9f02bc43c0b776035aa9bc24c9e147b79c2a5 100644 (file)
@@ -40,6 +40,7 @@ void sample_register_convs(struct sample_conv_kw_list *psl);
 const char *sample_src_names(unsigned int use);
 const char *sample_ckp_names(unsigned int use);
 struct sample_fetch *find_sample_fetch(const char *kw, int len);
+struct sample_fetch *sample_fetch_getnext(struct sample_fetch *current, int *idx);
 int smp_resolve_args(struct proxy *p);
 int smp_expr_output_type(struct sample_expr *expr);
 int c_none(struct sample *smp);
index 4c0d303cdbd7b4b1af58c2dd09b41cd87d0e8c99..896f6897abd1c7d793963f23b83e05c4a6a1b6e1 100644 (file)
@@ -384,6 +384,49 @@ struct sample_fetch *find_sample_fetch(const char *kw, int len)
        return NULL;
 }
 
+/* This fucntion browse the list of available saple fetch. <current> is
+ * the last used sample fetch. If it is the first call, it must set to NULL.
+ * <idx> is the index of the next sampleèfetch entry. It is used as private
+ * value. It is useles to initiate it.
+ *
+ * It returns always the newt fetch_sample entry, and NULL when the end of
+ * the list is reached.
+ */
+struct sample_fetch *sample_fetch_getnext(struct sample_fetch *current, int *idx)
+{
+       struct sample_fetch_kw_list *kwl;
+       struct sample_fetch *base;
+
+       if (!current) {
+               /* Get first kwl entry. */
+               kwl = LIST_NEXT(&sample_fetches.list, struct sample_fetch_kw_list *, list);
+               (*idx) = 0;
+       } else {
+               /* Get kwl corresponding to the curret entry. */
+               base = current + 1 - (*idx);
+               kwl = container_of(base, struct sample_fetch_kw_list, kw);
+       }
+
+       while (1) {
+
+               /* Check if kwl is the last entry. */
+               if (&kwl->list == &sample_fetches.list)
+                       return NULL;
+
+               /* idx contain the next keyword. If it is available, return it. */
+               if (kwl->kw[*idx].kw) {
+                       (*idx)++;
+                       return &kwl->kw[(*idx)-1];
+               }
+
+               /* get next entry in the main list, and return NULL if the end is reached. */
+               kwl = LIST_NEXT(&kwl->list, struct sample_fetch_kw_list *, list);
+
+               /* Set index to 0, ans do one other loop. */
+               (*idx) = 0;
+       }
+}
+
 /*
  * Returns the pointer on sample format conversion keyword structure identified by
  * string of <len> in buffer <kw>.