MEDIUM: acl: have a pointer to the keyword name in acl_expr

The acl_expr struct used to hold a pointer to the ACL keyword. But since
we now have all the relevant pointers, we don't need that anymore, we just
need the pointer to the keyword as a string in order to return warnings
and error messages.

So let's change this in order to remove the dependency on the acl_keyword
struct from acl_expr.

During this change, acl_cond_kw_conflicts() used to return a pointer to an
ACL keyword but had to be changed to return a const char* for the same reason.
This commit is contained in:
Willy Tarreau 2013-03-31 22:59:32 +02:00
parent acca90d8e5
commit 93fddf1dbc
5 changed files with 40 additions and 40 deletions

View File

@ -110,7 +110,7 @@ const struct acl *acl_cond_conflicts(const struct acl_cond *cond, unsigned int w
* null), or false if not conflict is found. The first useless keyword is * null), or false if not conflict is found. The first useless keyword is
* returned. * returned.
*/ */
int acl_cond_kw_conflicts(const struct acl_cond *cond, unsigned int where, struct acl const **acl, struct acl_keyword const **kw); int acl_cond_kw_conflicts(const struct acl_cond *cond, unsigned int where, struct acl const **acl, char const **kw);
/* /*
* Find targets for userlist and groups in acl. Function returns the number * Find targets for userlist and groups in acl. Function returns the number

View File

@ -197,7 +197,7 @@ struct acl_expr {
struct list patterns; /* list of acl_patterns */ struct list patterns; /* list of acl_patterns */
struct eb_root pattern_tree; /* may be used for lookup in large datasets */ struct eb_root pattern_tree; /* may be used for lookup in large datasets */
struct list list; /* chaining */ struct list list; /* chaining */
struct acl_keyword *kw; /* back-reference to the keyword */ const char *kw; /* points to the ACL kw's name or fetch's name (must not free) */
}; };
/* The acl will be linked to from the proxy where it is declared */ /* The acl will be linked to from the proxy where it is declared */

View File

@ -1050,7 +1050,7 @@ struct acl_expr *parse_acl_expr(const char **args, char **err)
goto out_return; goto out_return;
} }
expr->kw = aclkw; expr->kw = aclkw->kw;
LIST_INIT(&expr->patterns); LIST_INIT(&expr->patterns);
expr->pattern_tree = EB_ROOT_UNIQUE; expr->pattern_tree = EB_ROOT_UNIQUE;
expr->parse = aclkw->parse; expr->parse = aclkw->parse;
@ -1068,7 +1068,7 @@ struct acl_expr *parse_acl_expr(const char **args, char **err)
arg++; arg++;
end = strchr(arg, ')'); end = strchr(arg, ')');
if (!end) { if (!end) {
memprintf(err, "missing closing ')' after arguments to ACL keyword '%s'", expr->kw->kw); memprintf(err, "missing closing ')' after arguments to ACL keyword '%s'", expr->kw);
goto out_free_expr; goto out_free_expr;
} }
@ -1081,7 +1081,7 @@ struct acl_expr *parse_acl_expr(const char **args, char **err)
err, NULL, NULL); err, NULL, NULL);
if (nbargs < 0) { if (nbargs < 0) {
/* note that make_arg_list will have set <err> here */ /* note that make_arg_list will have set <err> here */
memprintf(err, "in argument to '%s', %s", expr->kw->kw, *err); memprintf(err, "in argument to '%s', %s", expr->kw, *err);
goto out_free_expr; goto out_free_expr;
} }
@ -1092,7 +1092,7 @@ struct acl_expr *parse_acl_expr(const char **args, char **err)
/* invalid keyword argument, error must have been /* invalid keyword argument, error must have been
* set by val_args(). * set by val_args().
*/ */
memprintf(err, "in argument to '%s', %s", expr->kw->kw, *err); memprintf(err, "in argument to '%s', %s", expr->kw, *err);
goto out_free_expr; goto out_free_expr;
} }
} }
@ -1104,7 +1104,7 @@ struct acl_expr *parse_acl_expr(const char **args, char **err)
* the current one later. * the current one later.
*/ */
if (type != ARGT_FE && type != ARGT_BE && type != ARGT_TAB) { if (type != ARGT_FE && type != ARGT_BE && type != ARGT_TAB) {
memprintf(err, "ACL keyword '%s' expects %d arguments", expr->kw->kw, ARGM(expr->smp->arg_mask)); memprintf(err, "ACL keyword '%s' expects %d arguments", expr->kw, ARGM(expr->smp->arg_mask));
goto out_free_expr; goto out_free_expr;
} }
@ -1121,14 +1121,14 @@ struct acl_expr *parse_acl_expr(const char **args, char **err)
} }
else if (ARGM(expr->smp->arg_mask)) { else if (ARGM(expr->smp->arg_mask)) {
/* there were some mandatory arguments */ /* there were some mandatory arguments */
memprintf(err, "ACL keyword '%s' expects %d arguments", expr->kw->kw, ARGM(expr->smp->arg_mask)); memprintf(err, "ACL keyword '%s' expects %d arguments", expr->kw, ARGM(expr->smp->arg_mask));
goto out_free_expr; goto out_free_expr;
} }
} }
else { else {
if (arg) { if (arg) {
/* no argument expected */ /* no argument expected */
memprintf(err, "ACL keyword '%s' takes no argument", expr->kw->kw); memprintf(err, "ACL keyword '%s' takes no argument", expr->kw);
goto out_free_expr; goto out_free_expr;
} }
} }
@ -1184,7 +1184,7 @@ struct acl_expr *parse_acl_expr(const char **args, char **err)
expr->match = acl_match_fcts[idx]; expr->match = acl_match_fcts[idx];
} }
else { else {
memprintf(err, "matching method '%s' cannot be used with fetch keyword '%s'", args[1], expr->kw->kw); memprintf(err, "matching method '%s' cannot be used with fetch keyword '%s'", args[1], expr->kw);
goto out_free_expr; goto out_free_expr;
} }
args++; args++;
@ -1791,7 +1791,7 @@ const struct acl *acl_cond_conflicts(const struct acl_cond *cond, unsigned int w
* null), or false if not conflict is found. The first useless keyword is * null), or false if not conflict is found. The first useless keyword is
* returned. * returned.
*/ */
int acl_cond_kw_conflicts(const struct acl_cond *cond, unsigned int where, struct acl const **acl, struct acl_keyword const **kw) int acl_cond_kw_conflicts(const struct acl_cond *cond, unsigned int where, struct acl const **acl, char const **kw)
{ {
struct acl_term_suite *suite; struct acl_term_suite *suite;
struct acl_term *term; struct acl_term *term;
@ -1840,7 +1840,7 @@ acl_find_targets(struct proxy *p)
if (!arg->data.str.len) { if (!arg->data.str.len) {
Alert("proxy %s: acl '%s' %s(): missing server name.\n", Alert("proxy %s: acl '%s' %s(): missing server name.\n",
p->id, acl->name, expr->kw->kw); p->id, acl->name, expr->kw);
cfgerr++; cfgerr++;
continue; continue;
} }
@ -1860,7 +1860,7 @@ acl_find_targets(struct proxy *p)
px = findproxy(pname, PR_CAP_BE); px = findproxy(pname, PR_CAP_BE);
if (!px) { if (!px) {
Alert("proxy %s: acl '%s' %s(): unable to find proxy '%s'.\n", Alert("proxy %s: acl '%s' %s(): unable to find proxy '%s'.\n",
p->id, acl->name, expr->kw->kw, pname); p->id, acl->name, expr->kw, pname);
cfgerr++; cfgerr++;
continue; continue;
} }
@ -1869,7 +1869,7 @@ acl_find_targets(struct proxy *p)
srv = findserver(px, sname); srv = findserver(px, sname);
if (!srv) { if (!srv) {
Alert("proxy %s: acl '%s' %s(): unable to find server '%s'.\n", Alert("proxy %s: acl '%s' %s(): unable to find server '%s'.\n",
p->id, acl->name, expr->kw->kw, sname); p->id, acl->name, expr->kw, sname);
cfgerr++; cfgerr++;
continue; continue;
} }
@ -1890,14 +1890,14 @@ acl_find_targets(struct proxy *p)
if (!prx) { if (!prx) {
Alert("proxy %s: acl '%s' %s(): unable to find frontend '%s'.\n", Alert("proxy %s: acl '%s' %s(): unable to find frontend '%s'.\n",
p->id, acl->name, expr->kw->kw, pname); p->id, acl->name, expr->kw, pname);
cfgerr++; cfgerr++;
continue; continue;
} }
if (!(prx->cap & PR_CAP_FE)) { if (!(prx->cap & PR_CAP_FE)) {
Alert("proxy %s: acl '%s' %s(): proxy '%s' has no frontend capability.\n", Alert("proxy %s: acl '%s' %s(): proxy '%s' has no frontend capability.\n",
p->id, acl->name, expr->kw->kw, pname); p->id, acl->name, expr->kw, pname);
cfgerr++; cfgerr++;
continue; continue;
} }
@ -1918,14 +1918,14 @@ acl_find_targets(struct proxy *p)
if (!prx) { if (!prx) {
Alert("proxy %s: acl '%s' %s(): unable to find backend '%s'.\n", Alert("proxy %s: acl '%s' %s(): unable to find backend '%s'.\n",
p->id, acl->name, expr->kw->kw, pname); p->id, acl->name, expr->kw, pname);
cfgerr++; cfgerr++;
continue; continue;
} }
if (!(prx->cap & PR_CAP_BE)) { if (!(prx->cap & PR_CAP_BE)) {
Alert("proxy %s: acl '%s' %s(): proxy '%s' has no backend capability.\n", Alert("proxy %s: acl '%s' %s(): proxy '%s' has no backend capability.\n",
p->id, acl->name, expr->kw->kw, pname); p->id, acl->name, expr->kw, pname);
cfgerr++; cfgerr++;
continue; continue;
} }
@ -1946,7 +1946,7 @@ acl_find_targets(struct proxy *p)
if (!prx) { if (!prx) {
Alert("proxy %s: acl '%s' %s(): unable to find table '%s'.\n", Alert("proxy %s: acl '%s' %s(): unable to find table '%s'.\n",
p->id, acl->name, expr->kw->kw, pname); p->id, acl->name, expr->kw, pname);
cfgerr++; cfgerr++;
continue; continue;
} }
@ -1954,7 +1954,7 @@ acl_find_targets(struct proxy *p)
if (!prx->table.size) { if (!prx->table.size) {
Alert("proxy %s: acl '%s' %s(): no table in proxy '%s'.\n", Alert("proxy %s: acl '%s' %s(): no table in proxy '%s'.\n",
p->id, acl->name, expr->kw->kw, pname); p->id, acl->name, expr->kw, pname);
cfgerr++; cfgerr++;
continue; continue;
} }
@ -1967,7 +1967,7 @@ acl_find_targets(struct proxy *p)
else if (arg->type == ARGT_USR) { else if (arg->type == ARGT_USR) {
if (!arg->data.str.len) { if (!arg->data.str.len) {
Alert("proxy %s: acl '%s' %s(): missing userlist name.\n", Alert("proxy %s: acl '%s' %s(): missing userlist name.\n",
p->id, acl->name, expr->kw->kw); p->id, acl->name, expr->kw);
cfgerr++; cfgerr++;
continue; continue;
} }
@ -1980,7 +1980,7 @@ acl_find_targets(struct proxy *p)
if (!ul) { if (!ul) {
Alert("proxy %s: acl '%s' %s(%s): unable to find userlist.\n", Alert("proxy %s: acl '%s' %s(%s): unable to find userlist.\n",
p->id, acl->name, expr->kw->kw, arg->data.str.str); p->id, acl->name, expr->kw, arg->data.str.str);
cfgerr++; cfgerr++;
continue; continue;
} }
@ -1998,12 +1998,12 @@ acl_find_targets(struct proxy *p)
if (cfgerr) if (cfgerr)
break; break;
if (!strcmp(expr->kw->kw, "http_auth_group")) { if (!strcmp(expr->kw, "http_auth_group")) {
/* note: argument resolved above thanks to ARGT_USR */ /* note: argument resolved above thanks to ARGT_USR */
if (LIST_ISEMPTY(&expr->patterns)) { if (LIST_ISEMPTY(&expr->patterns)) {
Alert("proxy %s: acl %s %s(): no groups specified.\n", Alert("proxy %s: acl %s %s(): no groups specified.\n",
p->id, acl->name, expr->kw->kw); p->id, acl->name, expr->kw);
cfgerr++; cfgerr++;
continue; continue;
} }
@ -2018,7 +2018,7 @@ acl_find_targets(struct proxy *p)
if (!pattern->val.group_mask) { if (!pattern->val.group_mask) {
Alert("proxy %s: acl %s %s(): invalid group(s).\n", Alert("proxy %s: acl %s %s(): invalid group(s).\n",
p->id, acl->name, expr->kw->kw); p->id, acl->name, expr->kw);
cfgerr++; cfgerr++;
continue; continue;
} }

View File

@ -422,7 +422,7 @@ int warnif_misplaced_reqadd(struct proxy *proxy, const char *file, int line, con
static int warnif_cond_conflicts(const struct acl_cond *cond, unsigned int where, const char *file, int line) static int warnif_cond_conflicts(const struct acl_cond *cond, unsigned int where, const char *file, int line)
{ {
const struct acl *acl; const struct acl *acl;
const struct acl_keyword *kw; const char *kw;
if (!cond) if (!cond)
return 0; return 0;
@ -434,7 +434,7 @@ static int warnif_cond_conflicts(const struct acl_cond *cond, unsigned int where
file, line, acl->name, sample_ckp_names(where)); file, line, acl->name, sample_ckp_names(where));
else else
Warning("parsing [%s:%d] : anonymous acl will never match because it uses keyword '%s' which is incompatible with '%s'\n", Warning("parsing [%s:%d] : anonymous acl will never match because it uses keyword '%s' which is incompatible with '%s'\n",
file, line, LIST_ELEM(acl->expr.n, struct acl_expr *, list)->kw->kw, sample_ckp_names(where)); file, line, LIST_ELEM(acl->expr.n, struct acl_expr *, list)->kw, sample_ckp_names(where));
return ERR_WARN; return ERR_WARN;
} }
if (!acl_cond_kw_conflicts(cond, where, &acl, &kw)) if (!acl_cond_kw_conflicts(cond, where, &acl, &kw))
@ -442,10 +442,10 @@ static int warnif_cond_conflicts(const struct acl_cond *cond, unsigned int where
if (acl->name && *acl->name) if (acl->name && *acl->name)
Warning("parsing [%s:%d] : acl '%s' involves keywords '%s' which is incompatible with '%s'\n", Warning("parsing [%s:%d] : acl '%s' involves keywords '%s' which is incompatible with '%s'\n",
file, line, acl->name, kw->kw, sample_ckp_names(where)); file, line, acl->name, kw, sample_ckp_names(where));
else else
Warning("parsing [%s:%d] : anonymous acl involves keyword '%s' which is incompatible with '%s'\n", Warning("parsing [%s:%d] : anonymous acl involves keyword '%s' which is incompatible with '%s'\n",
file, line, kw->kw, sample_ckp_names(where)); file, line, kw, sample_ckp_names(where));
return ERR_WARN; return ERR_WARN;
} }

View File

@ -1190,7 +1190,7 @@ static int tcp_parse_tcp_rep(char **args, int section_type, struct proxy *curpx,
struct tcp_rule *rule; struct tcp_rule *rule;
unsigned int where; unsigned int where;
const struct acl *acl; const struct acl *acl;
const struct acl_keyword *kw; const char *kw;
if (!*args[1]) { if (!*args[1]) {
memprintf(err, "missing argument for '%s' in %s '%s'", memprintf(err, "missing argument for '%s' in %s '%s'",
@ -1249,7 +1249,7 @@ static int tcp_parse_tcp_rep(char **args, int section_type, struct proxy *curpx,
memprintf(err, memprintf(err,
"anonymous acl will never match in '%s %s' because it uses keyword '%s' which is incompatible with '%s'", "anonymous acl will never match in '%s %s' because it uses keyword '%s' which is incompatible with '%s'",
args[0], args[1], args[0], args[1],
LIST_ELEM(acl->expr.n, struct acl_expr *, list)->kw->kw, LIST_ELEM(acl->expr.n, struct acl_expr *, list)->kw,
sample_ckp_names(where)); sample_ckp_names(where));
warn++; warn++;
@ -1258,11 +1258,11 @@ static int tcp_parse_tcp_rep(char **args, int section_type, struct proxy *curpx,
if (acl->name && *acl->name) if (acl->name && *acl->name)
memprintf(err, memprintf(err,
"acl '%s' involves keyword '%s' which is incompatible with '%s'", "acl '%s' involves keyword '%s' which is incompatible with '%s'",
acl->name, kw->kw, sample_ckp_names(where)); acl->name, kw, sample_ckp_names(where));
else else
memprintf(err, memprintf(err,
"anonymous acl involves keyword '%s' which is incompatible with '%s'", "anonymous acl involves keyword '%s' which is incompatible with '%s'",
kw->kw, sample_ckp_names(where)); kw, sample_ckp_names(where));
warn++; warn++;
} }
@ -1296,7 +1296,7 @@ static int tcp_parse_tcp_req(char **args, int section_type, struct proxy *curpx,
struct tcp_rule *rule; struct tcp_rule *rule;
unsigned int where; unsigned int where;
const struct acl *acl; const struct acl *acl;
const struct acl_keyword *kw; const char *kw;
if (!*args[1]) { if (!*args[1]) {
if (curpx == defpx) if (curpx == defpx)
@ -1358,7 +1358,7 @@ static int tcp_parse_tcp_req(char **args, int section_type, struct proxy *curpx,
memprintf(err, memprintf(err,
"anonymous acl will never match in '%s %s' because it uses keyword '%s' which is incompatible with '%s'", "anonymous acl will never match in '%s %s' because it uses keyword '%s' which is incompatible with '%s'",
args[0], args[1], args[0], args[1],
LIST_ELEM(acl->expr.n, struct acl_expr *, list)->kw->kw, LIST_ELEM(acl->expr.n, struct acl_expr *, list)->kw,
sample_ckp_names(where)); sample_ckp_names(where));
warn++; warn++;
@ -1367,11 +1367,11 @@ static int tcp_parse_tcp_req(char **args, int section_type, struct proxy *curpx,
if (acl->name && *acl->name) if (acl->name && *acl->name)
memprintf(err, memprintf(err,
"acl '%s' involves keyword '%s' which is incompatible with '%s'", "acl '%s' involves keyword '%s' which is incompatible with '%s'",
acl->name, kw->kw, sample_ckp_names(where)); acl->name, kw, sample_ckp_names(where));
else else
memprintf(err, memprintf(err,
"anonymous acl involves keyword '%s' which is incompatible with '%s'", "anonymous acl involves keyword '%s' which is incompatible with '%s'",
kw->kw, sample_ckp_names(where)); kw, sample_ckp_names(where));
warn++; warn++;
} }
@ -1401,7 +1401,7 @@ static int tcp_parse_tcp_req(char **args, int section_type, struct proxy *curpx,
memprintf(err, memprintf(err,
"anonymous acl will never match in '%s %s' because it uses keyword '%s' which is incompatible with '%s'", "anonymous acl will never match in '%s %s' because it uses keyword '%s' which is incompatible with '%s'",
args[0], args[1], args[0], args[1],
LIST_ELEM(acl->expr.n, struct acl_expr *, list)->kw->kw, LIST_ELEM(acl->expr.n, struct acl_expr *, list)->kw,
sample_ckp_names(where)); sample_ckp_names(where));
warn++; warn++;
@ -1410,11 +1410,11 @@ static int tcp_parse_tcp_req(char **args, int section_type, struct proxy *curpx,
if (acl->name && *acl->name) if (acl->name && *acl->name)
memprintf(err, memprintf(err,
"acl '%s' involves keyword '%s' which is incompatible with '%s'", "acl '%s' involves keyword '%s' which is incompatible with '%s'",
acl->name, kw->kw, sample_ckp_names(where)); acl->name, kw, sample_ckp_names(where));
else else
memprintf(err, memprintf(err,
"anonymous acl involves keyword '%s' which is incompatible with '%s'", "anonymous acl involves keyword '%s' which is incompatible with '%s'",
kw->kw, sample_ckp_names(where)); kw, sample_ckp_names(where));
warn++; warn++;
} }