]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: pattern: make the pattern matching function return a pointer to the matched...
authorThierry FOURNIER <tfournier@exceliance.fr>
Tue, 10 Dec 2013 14:03:38 +0000 (15:03 +0100)
committerWilly Tarreau <w@1wt.eu>
Thu, 12 Dec 2013 14:44:05 +0000 (15:44 +0100)
This feature will be used by the CLI to look up keys.

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

index ee193929a0dfda754a9467426b88268233b799d9..8c9c1c7025dc7b1eacf1b66fc6129335cc133229 100644 (file)
@@ -58,7 +58,7 @@ static inline int pat_find_match_name(const char *name)
  * associated to the matching patterned will be put there. The function returns
  * PAT_MATCH or PAT_NOMATCH.
  */
-enum pat_match_res pattern_exec_match(struct pattern_expr *expr, struct sample *smp, struct sample_storage **sample);
+enum pat_match_res pattern_exec_match(struct pattern_expr *expr, struct sample *smp, struct sample_storage **sample, struct pattern **pat, struct pat_idx_elt **elt);
 
 /*
  *
index ef6b4a34164b21d366c42ec51c8c6d9e00e6dfef..b033f2afd17ef72f3ef298e091c7fde2bc20acda 100644 (file)
--- a/src/acl.c
+++ b/src/acl.c
@@ -977,7 +977,7 @@ enum acl_test_res acl_exec_cond(struct acl_cond *cond, struct proxy *px, struct
                                        continue;
                                }
 
-                               acl_res |= pat2acl(pattern_exec_match(&expr->pat, &smp, NULL));
+                               acl_res |= pat2acl(pattern_exec_match(&expr->pat, &smp, NULL, NULL, NULL));
                                /*
                                 * OK now acl_res holds the result of this expression
                                 * as one of ACL_TEST_FAIL, ACL_TEST_MISS or ACL_TEST_PASS.
index a13c5b7bdb6283bcb72d400bd1feda6d0bc9150c..b1fa7f672d336a46aec5b1dcf7eaf795a5e1b2bb 100644 (file)
--- a/src/map.c
+++ b/src/map.c
@@ -467,7 +467,7 @@ static int sample_conv_map(const struct arg *arg_p, struct sample *smp)
        desc = arg_p[0].data.map;
 
        /* Execute the match function. */
-       ret = pattern_exec_match(desc->pat, smp, &sample);
+       ret = pattern_exec_match(desc->pat, smp, &sample, NULL, NULL);
        if (ret != PAT_MATCH) {
                if (!desc->def)
                        return 0;
index 43011cd097467d9cabc0e83862b4d9b17d982053..c9e897872457b2b26e9396f99f867ab441339a9b 100644 (file)
@@ -1046,7 +1046,8 @@ int pattern_read_from_file(struct pattern_expr *expr,
  * PAT_NOMATCH or PAT_MATCH.
  */
 enum pat_match_res pattern_exec_match(struct pattern_expr *expr, struct sample *smp,
-                                      struct sample_storage **sample)
+                                      struct sample_storage **sample,
+                                      struct pattern **pat, struct pat_idx_elt **idx_elt)
 {
        enum pat_match_res pat_res = PAT_NOMATCH;
        struct pattern *pattern;
@@ -1079,6 +1080,8 @@ enum pat_match_res pattern_exec_match(struct pattern_expr *expr, struct sample *
                                elt = ebmb_entry(node, struct pat_idx_elt, node);
                                if (sample)
                                        *sample = elt->smp;
+                               if (idx_elt)
+                                       *idx_elt = elt;
                        }
                }
 
@@ -1090,6 +1093,8 @@ enum pat_match_res pattern_exec_match(struct pattern_expr *expr, struct sample *
                                pat_res |= expr->match(smp, pattern);
                        if (sample)
                                *sample = pattern->smp;
+                       if (pat)
+                               *pat = pattern;
                }
        }