MINOR: acl/pattern: use types different from int to clarify who does what.
We now have the following enums and all related functions return them and
consume them :
enum pat_match_res {
PAT_NOMATCH = 0, /* sample didn't match any pattern */
PAT_MATCH = 3, /* sample matched at least one pattern */
};
enum acl_test_res {
ACL_TEST_FAIL = 0, /* test failed */
ACL_TEST_MISS = 1, /* test may pass with more info */
ACL_TEST_PASS = 3, /* test passed */
};
enum acl_cond_pol {
ACL_COND_NONE, /* no polarity set yet */
ACL_COND_IF, /* positive condition (after 'if') */
ACL_COND_UNLESS, /* negative condition (after 'unless') */
};
It's just in order to avoid doubts when reading some code.
diff --git a/src/pattern.c b/src/pattern.c
index e3cb464..b6f7502 100644
--- a/src/pattern.c
+++ b/src/pattern.c
@@ -55,7 +55,7 @@
[PAT_MATCH_REG] = pat_parse_reg,
};
-int (*pat_match_fcts[PAT_MATCH_NUM])(struct sample *, struct pattern *) = {
+enum pat_match_res (*pat_match_fcts[PAT_MATCH_NUM])(struct sample *, struct pattern *) = {
[PAT_MATCH_FOUND] = NULL,
[PAT_MATCH_BOOL] = pat_match_nothing,
[PAT_MATCH_INT] = pat_match_int,
@@ -82,14 +82,14 @@
}
/* always return false */
-int pat_match_nothing(struct sample *smp, struct pattern *pattern)
+enum pat_match_res pat_match_nothing(struct sample *smp, struct pattern *pattern)
{
return PAT_NOMATCH;
}
/* NB: For two strings to be identical, it is required that their lengths match */
-int pat_match_str(struct sample *smp, struct pattern *pattern)
+enum pat_match_res pat_match_str(struct sample *smp, struct pattern *pattern)
{
int icase;
@@ -104,7 +104,7 @@
}
/* NB: For two binaries buf to be identical, it is required that their lengths match */
-int pat_match_bin(struct sample *smp, struct pattern *pattern)
+enum pat_match_res pat_match_bin(struct sample *smp, struct pattern *pattern)
{
if (pattern->len != smp->data.str.len)
return PAT_NOMATCH;
@@ -136,7 +136,7 @@
/* Executes a regex. It temporarily changes the data to add a trailing zero,
* and restores the previous character when leaving.
*/
-int pat_match_reg(struct sample *smp, struct pattern *pattern)
+enum pat_match_res pat_match_reg(struct sample *smp, struct pattern *pattern)
{
if (regex_exec(pattern->ptr.reg, smp->data.str.str, smp->data.str.len) == 0)
return PAT_MATCH;
@@ -144,7 +144,7 @@
}
/* Checks that the pattern matches the beginning of the tested string. */
-int pat_match_beg(struct sample *smp, struct pattern *pattern)
+enum pat_match_res pat_match_beg(struct sample *smp, struct pattern *pattern)
{
int icase;
@@ -159,7 +159,7 @@
}
/* Checks that the pattern matches the end of the tested string. */
-int pat_match_end(struct sample *smp, struct pattern *pattern)
+enum pat_match_res pat_match_end(struct sample *smp, struct pattern *pattern)
{
int icase;
@@ -175,7 +175,7 @@
/* Checks that the pattern is included inside the tested string.
* NB: Suboptimal, should be rewritten using a Boyer-Moore method.
*/
-int pat_match_sub(struct sample *smp, struct pattern *pattern)
+enum pat_match_res pat_match_sub(struct sample *smp, struct pattern *pattern)
{
int icase;
char *end;
@@ -285,7 +285,7 @@
* between the delimiters '?' or '/' or at the beginning or end of the string.
* Delimiters at the beginning or end of the pattern are ignored.
*/
-int pat_match_dir(struct sample *smp, struct pattern *pattern)
+enum pat_match_res pat_match_dir(struct sample *smp, struct pattern *pattern)
{
return match_word(smp, pattern, make_4delim('/', '?', '?', '?'));
}
@@ -294,13 +294,13 @@
* between the delmiters '/', '?', '.' or ":" or at the beginning or end of
* the string. Delimiters at the beginning or end of the pattern are ignored.
*/
-int pat_match_dom(struct sample *smp, struct pattern *pattern)
+enum pat_match_res pat_match_dom(struct sample *smp, struct pattern *pattern)
{
return match_word(smp, pattern, make_4delim('/', '?', '.', ':'));
}
/* Checks that the integer in <test> is included between min and max */
-int pat_match_int(struct sample *smp, struct pattern *pattern)
+enum pat_match_res pat_match_int(struct sample *smp, struct pattern *pattern)
{
if ((!pattern->val.range.min_set || pattern->val.range.min <= smp->data.uint) &&
(!pattern->val.range.max_set || smp->data.uint <= pattern->val.range.max))
@@ -309,7 +309,7 @@
}
/* Checks that the length of the pattern in <test> is included between min and max */
-int pat_match_len(struct sample *smp, struct pattern *pattern)
+enum pat_match_res pat_match_len(struct sample *smp, struct pattern *pattern)
{
if ((!pattern->val.range.min_set || pattern->val.range.min <= smp->data.str.len) &&
(!pattern->val.range.max_set || smp->data.str.len <= pattern->val.range.max))
@@ -317,7 +317,7 @@
return PAT_NOMATCH;
}
-int pat_match_ip(struct sample *smp, struct pattern *pattern)
+enum pat_match_res pat_match_ip(struct sample *smp, struct pattern *pattern)
{
unsigned int v4; /* in network byte order */
struct in6_addr *v6;
@@ -939,10 +939,10 @@
* with the pointer associated with the matching pattern. This function returns
* PAT_NOMATCH or PAT_MATCH.
*/
-inline int 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)
{
- int pat_res = PAT_NOMATCH;
+ enum pat_match_res pat_res = PAT_NOMATCH;
struct pattern *pattern;
struct ebmb_node *node = NULL;
struct pat_idx_elt *elt;