mirror of
https://git.haproxy.org/git/haproxy.git/
synced 2025-09-23 14:51:27 +02:00
MEDIUM: acl: automatically detect the type of certain fetches
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.
This commit is contained in:
parent
4f0d919bd4
commit
9987ea9967
25
src/acl.c
25
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;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user