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/include/proto/acl.h b/include/proto/acl.h
index 2d2a34a..82782d4 100644
--- a/include/proto/acl.h
+++ b/include/proto/acl.h
@@ -33,13 +33,13 @@
/* Negate an acl result. This turns (ACL_MATCH_FAIL, ACL_MATCH_MISS,
* ACL_MATCH_PASS) into (ACL_MATCH_PASS, ACL_MATCH_MISS, ACL_MATCH_FAIL).
*/
-static inline int acl_neg(int res)
+static inline enum acl_test_res acl_neg(enum acl_test_res res)
{
return (3 >> res);
}
/* Convert an acl result to a boolean. Only ACL_MATCH_PASS returns 1. */
-static inline int acl_pass(int res)
+static inline int acl_pass(enum acl_test_res res)
{
return (res >> 1);
}
@@ -79,7 +79,8 @@
* known ACLs passed in <known_acl>. The new condition is returned (or NULL in
* case of low memory). Supports multiple conditions separated by "or".
*/
-struct acl_cond *parse_acl_cond(const char **args, struct list *known_acl, int pol, char **err, struct arg_list *al);
+struct acl_cond *parse_acl_cond(const char **args, struct list *known_acl,
+ enum acl_cond_pol pol, char **err, struct arg_list *al);
/* Builds an ACL condition starting at the if/unless keyword. The complete
* condition is returned. NULL is returned in case of error or if the first
@@ -97,7 +98,7 @@
* function only computes the condition, it does not apply the polarity required
* by IF/UNLESS, it's up to the caller to do this.
*/
-int acl_exec_cond(struct acl_cond *cond, struct proxy *px, struct session *l4, void *l7, unsigned int opt);
+enum acl_test_res acl_exec_cond(struct acl_cond *cond, struct proxy *px, struct session *l4, void *l7, unsigned int opt);
/* Returns a pointer to the first ACL conflicting with usage at place <where>
* which is one of the SMP_VAL_* bits indicating a check place, or NULL if
diff --git a/include/proto/auth.h b/include/proto/auth.h
index ddaf9c1..711b2f8 100644
--- a/include/proto/auth.h
+++ b/include/proto/auth.h
@@ -21,7 +21,7 @@
struct userlist *auth_find_userlist(char *name);
unsigned int auth_resolve_groups(struct userlist *l, char *groups);
void userlist_free(struct userlist *ul);
-int pat_match_auth(struct sample *smp, struct pattern *pattern);
+enum pat_match_res pat_match_auth(struct sample *smp, struct pattern *pattern);
int check_user(struct userlist *ul, unsigned int group_mask, const char *user, const char *pass);
#endif /* _PROTO_AUTH_H */
diff --git a/include/proto/pattern.h b/include/proto/pattern.h
index 6d683f8..ee7518c 100644
--- a/include/proto/pattern.h
+++ b/include/proto/pattern.h
@@ -22,6 +22,10 @@
#ifndef _PROTO_PATTERN_H
#define _PROTO_PATTERN_H
+#include <common/config.h>
+#include <common/standard.h>
+#include <types/pattern.h>
+
/* parse the <text> with <expr> compliant parser. <pattern> is a context for
* the current parsed acl. It must initialized at NULL:
*
@@ -42,7 +46,7 @@
* associated to the matching patterned will be put there. The function returns
* PAT_MATCH or PAT_NOMATCH.
*/
-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);
/*
*
@@ -55,16 +59,16 @@
int pat_parse_nothing(const char **text, struct pattern *pattern, struct sample_storage *smp, int *opaque, char **err);
/* 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);
/* NB: For two binary buffers 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);
/* 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);
/* 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);
/* Parse an integer. It is put both in min and max. */
int pat_parse_int(const char **text, struct pattern *pattern, struct sample_storage *smp, int *opaque, char **err);
@@ -97,36 +101,36 @@
int pat_parse_ip(const char **text, struct pattern *pattern, struct sample_storage *smp, int *opaque, char **err);
/* 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);
/* 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);
/* 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);
/* Checks that the pattern is included inside the tested string. */
-int pat_match_sub(struct sample *smp, struct pattern *pattern);
+enum pat_match_res pat_match_sub(struct sample *smp, struct pattern *pattern);
/* Checks that the pattern is included inside the tested string, but enclosed
* between slashes or at the beginning or end of the string. Slashes 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);
/* Checks that the pattern is included inside the tested string, but enclosed
* between dots or at the beginning or end of the string. Dots 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);
/* Check that the IPv4 address in <test> matches the IP/mask in pattern */
-int pat_match_ip(struct sample *smp, struct pattern *pattern);
+enum pat_match_res pat_match_ip(struct sample *smp, struct pattern *pattern);
/* 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);
int pattern_read_from_file(struct pattern_expr *expr, const char *filename, int patflags, char **err);
void pattern_free(struct pattern *pat);
diff --git a/include/types/acl.h b/include/types/acl.h
index 5358878..e8c3e08 100644
--- a/include/types/acl.h
+++ b/include/types/acl.h
@@ -93,7 +93,7 @@
const char *kw;
char *fetch_kw;
int (*parse)(const char **text, struct pattern *pattern, struct sample_storage *smp, int *opaque, char **err);
- int (*match)(struct sample *smp, struct pattern *pattern);
+ enum pat_match_res (*match)(struct sample *smp, struct pattern *pattern);
/* must be after the config params */
struct sample_fetch *smp; /* the sample fetch we depend on */
};
@@ -148,7 +148,7 @@
struct acl_cond {
struct list list; /* Some specific tests may use multiple conditions */
struct list suites; /* list of acl_term_suites */
- int pol; /* polarity: ACL_COND_IF / ACL_COND_UNLESS */
+ enum acl_cond_pol pol; /* polarity: ACL_COND_IF / ACL_COND_UNLESS */
unsigned int use; /* or'ed bit mask of all suites's SMP_USE_* */
unsigned int val; /* or'ed bit mask of all suites's SMP_VAL_* */
const char *file; /* config file where the condition is declared */
diff --git a/include/types/pattern.h b/include/types/pattern.h
index 02bdff0..3f0a085 100644
--- a/include/types/pattern.h
+++ b/include/types/pattern.h
@@ -56,7 +56,7 @@
* MATCH = 0
* NOMATCH = 3
*/
-enum {
+enum pat_match_res {
PAT_NOMATCH = 0, /* sample didn't match any pattern */
PAT_MATCH = 3, /* sample matched at least one pattern */
};
@@ -152,13 +152,13 @@
*/
struct pattern_expr {
int (*parse)(const char **text, struct pattern *pattern, struct sample_storage *smp, int *opaque, char **err);
- int (*match)(struct sample *smp, struct pattern *pattern);
+ enum pat_match_res (*match)(struct sample *smp, struct pattern *pattern);
struct list patterns; /* list of acl_patterns */
struct eb_root pattern_tree; /* may be used for lookup in large datasets */
};
extern char *pat_match_names[PAT_MATCH_NUM];
extern int (*pat_parse_fcts[PAT_MATCH_NUM])(const char **, struct pattern *, struct sample_storage *, int *, char **);
-extern int (*pat_match_fcts[PAT_MATCH_NUM])(struct sample *, struct pattern *);
+extern enum pat_match_res (*pat_match_fcts[PAT_MATCH_NUM])(struct sample *, struct pattern *);
#endif /* _TYPES_PATTERN_H */