MEDIUM: acl: Last patch change the output type
This patch remove the compatibility check from the input type and the
match method. Now, it checks if a casts from the input type to output
type exists and the pattern_exec_match() function apply casts before
each pattern matching.
diff --git a/src/pattern.c b/src/pattern.c
index 3f25607..084f73a 100644
--- a/src/pattern.c
+++ b/src/pattern.c
@@ -20,6 +20,7 @@
#include <types/pattern.h>
#include <proto/pattern.h>
+#include <proto/sample.h>
#include <ebsttree.h>
@@ -71,6 +72,23 @@
[PAT_MATCH_REG] = pat_match_reg,
};
+/* Just used for checking configuration compatibility */
+int pat_match_types[PAT_MATCH_NUM] = {
+ [PAT_MATCH_FOUND] = SMP_T_UINT,
+ [PAT_MATCH_BOOL] = SMP_T_UINT,
+ [PAT_MATCH_INT] = SMP_T_UINT,
+ [PAT_MATCH_IP] = SMP_T_ADDR,
+ [PAT_MATCH_BIN] = SMP_T_CBIN,
+ [PAT_MATCH_LEN] = SMP_T_CSTR,
+ [PAT_MATCH_STR] = SMP_T_CSTR,
+ [PAT_MATCH_BEG] = SMP_T_CSTR,
+ [PAT_MATCH_SUB] = SMP_T_CSTR,
+ [PAT_MATCH_DIR] = SMP_T_CSTR,
+ [PAT_MATCH_DOM] = SMP_T_CSTR,
+ [PAT_MATCH_END] = SMP_T_CSTR,
+ [PAT_MATCH_REG] = SMP_T_CSTR,
+};
+
/*
* These functions are exported and may be used by any other component.
*/
@@ -949,10 +967,14 @@
else {
if (!eb_is_empty(&expr->pattern_tree)) {
/* a tree is present, let's check what type it is */
- if (expr->match == pat_match_str)
- node = pat_lookup_str(smp, expr);
- else if (expr->match == pat_match_ip)
- node = pat_lookup_ip(smp, expr);
+ if (expr->match == pat_match_str) {
+ if (sample_convert(smp, SMP_T_STR))
+ node = pat_lookup_str(smp, expr);
+ }
+ else if (expr->match == pat_match_ip) {
+ if (sample_convert(smp, SMP_T_IPV4))
+ node = pat_lookup_ip(smp, expr);
+ }
if (node) {
pat_res |= PAT_MATCH;
elt = ebmb_entry(node, struct pat_idx_elt, node);
@@ -965,7 +987,8 @@
list_for_each_entry(pattern, &expr->patterns, list) {
if (pat_res == PAT_MATCH)
break;
- pat_res |= expr->match(smp, pattern);
+ if (sample_convert(smp, pattern->expect_type))
+ pat_res |= expr->match(smp, pattern);
if (sample)
*sample = pattern->smp;
}