Commit c9d1478f authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

Be a bit more helpful with the VCC error messages with the names

which are restricted to valid C language names.

Fixes	#1310
parent 63f7dfa0
......@@ -22,6 +22,13 @@ server s4 {
txresp -body "4444"
} -start
varnish v1 -errvcl {Names of VCL objects cannot contain '-'} {
import directors from "${topbuild}/lib/libvmod_directors/.libs/libvmod_directors.so" ;
backend b1 { .host = "127.0.0.1"; .port = "8080";}
sub vcl_init {
new rr1-xx = directors.round_robin();
}
}
varnish v1 -vcl+backend {
......
......@@ -247,3 +247,31 @@ varnish v1 -vcl {
}
}
}
varnish v1 -errvcl {Names of VCL sub's cannot contain '-'} {
backend b { .host = "127.0.0.1"; }
sub foo-bar {
}
sub vcl_recv {
call foo-bar;
}
}
varnish v1 -errvcl {VCL sub's named 'vcl*' are reserved names.} {
backend b { .host = "127.0.0.1"; }
sub vcl_bar {
}
sub vcl_recv {
call vcl_bar;
}
}
varnish v1 -errvcl {Names of VCL acl's cannot contain '-'} {
backend b { .host = "127.0.0.1"; }
acl foo-bar {
}
sub vcl_recv {
if (client.ip ~ foo.bar) {
}
}
}
......@@ -472,6 +472,12 @@ vcc_Acl(struct vcc *tl)
VTAILQ_INIT(&tl->acl);
ExpectErr(tl, ID);
if (!vcc_isCid(tl->t)) {
VSB_printf(tl->sb,
"Names of VCL acl's cannot contain '-'\n");
vcc_ErrWhere(tl, tl->t);
return;
}
an = tl->t;
vcc_NextToken(tl);
......
......@@ -171,6 +171,12 @@ parse_new(struct vcc *tl)
vcc_NextToken(tl);
ExpectErr(tl, ID);
if (!vcc_isCid(tl->t)) {
VSB_printf(tl->sb,
"Names of VCL objects cannot contain '-'\n");
vcc_ErrWhere(tl, tl->t);
return;
}
sy1 = VCC_FindSymbol(tl, tl->t, SYM_NONE);
XXXAZ(sy1);
......
......@@ -133,6 +133,10 @@ IsMethod(const struct token *t)
if (vcc_IdIs(t, m->name))
return (m - method_tab);
}
if ((t->b[0] == 'v'|| t->b[0] == 'V') &&
(t->b[1] == 'c'|| t->b[1] == 'C') &&
(t->b[2] == 'l'|| t->b[2] == 'L'))
return (-2);
return (-1);
}
......
......@@ -49,10 +49,12 @@
#endif
struct vsb;
struct token;
#define isident1(c) (isalpha(c))
#define isident(c) (isalpha(c) || isdigit(c) || (c) == '_' || (c) == '-')
#define isvar(c) (isident(c) || (c) == '.')
int vcc_isCid(const struct token *t);
unsigned vcl_fixed_token(const char *p, const char **q);
extern const char * const vcl_tnames[256];
void vcl_output_lang_h(struct vsb *sb);
......
......@@ -212,9 +212,23 @@ vcc_Function(struct vcc *tl)
vcc_NextToken(tl);
ExpectErr(tl, ID);
if (!vcc_isCid(tl->t)) {
VSB_printf(tl->sb,
"Names of VCL sub's cannot contain '-'\n");
vcc_ErrWhere(tl, tl->t);
return;
}
m = IsMethod(tl->t);
if (m != -1) {
if (m == -2) {
VSB_printf(tl->sb,
"VCL sub's named 'vcl*' are reserved names.\n");
vcc_ErrWhere(tl, tl->t);
VSB_printf(tl->sb, "Valid vcl_* methods are:\n");
for (i = 0; method_tab[i].name != NULL; i++)
VSB_printf(tl->sb, "\t%s\n", method_tab[i].name);
return;
} else if (m != -1) {
assert(m < VCL_MET_MAX);
tl->fb = tl->fm[m];
if (tl->mprocs[m] == NULL) {
......
......@@ -293,7 +293,7 @@ vcc_IdIs(const struct token *t, const char *p)
* Check that we have a C-identifier
*/
static int
int
vcc_isCid(const struct token *t)
{
const char *q;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment