]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MEDIUM: acl: automatically detect the type of certain fetches
authorWilly Tarreau <w@1wt.eu>
Tue, 11 Jun 2013 19:09:06 +0000 (21:09 +0200)
committerWilly Tarreau <w@1wt.eu>
Tue, 11 Jun 2013 19:09:06 +0000 (21:09 +0200)
Commit bef91e71 added the possibility to automatically use some fetch
functions instead of ACL functions, but for the fetch output type was
never used and setting the match method using -m was always mandatory.

Some fetch types are non-ambiguous and can intuitively be associated
with some ACL types :

    SMP_T_BOOL      -> bool
    SMP_T_UINT/SINT -> int
    SMP_T_IPV4/IPV6 -> ip

So let's have the ACL expression parser detect these ones automatically.

Other types are more ambiguous, especially everything related to strings,
as there are many string matching methods available and none of them is
the obvious standard matching method for any string. These ones will still
have to be specified using -m.

src/acl.c

index 05bb1a50739b797b5a701ff81c53da7f7c8ee0bd..8ba6f6f939f79650d9ff3fb1298511040afff2dd 100644 (file)
--- a/src/acl.c
+++ b/src/acl.c
@@ -1076,6 +1076,27 @@ struct acl_expr *parse_acl_expr(const char **args, char **err, struct arg_list *
        expr->args = empty_arg_list;
        expr->smp = aclkw ? aclkw->smp : smp;
 
+       if (!expr->parse) {
+               /* some types can be automatically converted */
+
+               switch (expr->smp->out_type) {
+               case SMP_T_BOOL:
+                       expr->parse = acl_parse_fcts[ACL_MATCH_BOOL];
+                       expr->match = acl_match_fcts[ACL_MATCH_BOOL];
+                       break;
+               case SMP_T_SINT:
+               case SMP_T_UINT:
+                       expr->parse = acl_parse_fcts[ACL_MATCH_INT];
+                       expr->match = acl_match_fcts[ACL_MATCH_INT];
+                       break;
+               case SMP_T_IPV4:
+               case SMP_T_IPV6:
+                       expr->parse = acl_parse_fcts[ACL_MATCH_IP];
+                       expr->match = acl_match_fcts[ACL_MATCH_IP];
+                       break;
+               }
+       }
+
        arg = strchr(args[0], '(');
        if (expr->smp->arg_mask) {
                int nbargs = 0;
@@ -1171,7 +1192,7 @@ struct acl_expr *parse_acl_expr(const char **args, char **err, struct arg_list *
                        patflags |= ACL_PAT_F_IGNORE_CASE;
                else if ((*args)[1] == 'f') {
                        if (!expr->parse) {
-                               memprintf(err, "matching method must be specified first (using '-m') when using a sample fetch ('%s')", expr->kw);
+                               memprintf(err, "matching method must be specified first (using '-m') when using a sample fetch of this type ('%s')", expr->kw);
                                goto out_free_expr;
                        }
 
@@ -1228,7 +1249,7 @@ struct acl_expr *parse_acl_expr(const char **args, char **err, struct arg_list *
        }
 
        if (!expr->parse) {
-               memprintf(err, "matching method must be specified first (using '-m') when using a sample fetch ('%s')", expr->kw);
+               memprintf(err, "matching method must be specified first (using '-m') when using a sample fetch of this type ('%s')", expr->kw);
                goto out_free_expr;
        }