Commit 31e03bf3 authored by Dridi Boukelmoune's avatar Dridi Boukelmoune

Switch VCL symbols from C to Varnish identifiers

This does not include VMOD space, but that is pretty much everything
else.

Refs #2325
parent c0fd77a0
varnishtest "legal symbol names"
varnish v1 -arg "-s my-store=malloc" -vcl {
import directors;
acl my-acl { "127.0.0.1"; }
probe my-pb { }
backend my-be {
.host = "${bad_backend}";
.probe = my-pb;
}
sub vcl_init {
new my-dir = directors.round_robin();
my-dir.add_backend(my-be);
}
sub vcl_recv {
call my-sub;
}
sub my-sub {
if (client.ip ~ my-acl) { }
set req.storage = storage.my-store;
set req.backend_hint = my-dir.backend();
}
} -start
varnish v1 -cli "vcl.label my-label vcl1"
varnish v1 -vcl {
backend dummy { .host = "${bad_backend}"; }
sub vcl_recv {
return (vcl(my-label));
}
}
......@@ -22,11 +22,11 @@ server s4 {
txresp -body "4444"
} -start
varnish v1 -errvcl {Name of VCL object, 'rr1-xx', contains illegal character '-'} {
varnish v1 -errvcl {Name of VCL object, 'rr1.xx', contains illegal character '.'} {
import directors;
backend b1 { .host = "127.0.0.1"; .port = "8080";}
sub vcl_init {
new rr1-xx = directors.round_robin();
new rr1.xx = directors.round_robin();
}
}
......
......@@ -204,12 +204,12 @@ varnish v1 -errvcl {IP + IP not possible.} {
}
}
varnish v1 -errvcl {Name of function, 'foo-bar', contains illegal character '-'} {
varnish v1 -errvcl {Name of function, 'foo.bar', contains illegal character '.'} {
backend b { .host = "127.0.0.1"; }
sub foo-bar {
sub foo.bar {
}
sub vcl_recv {
call foo-bar;
call foo.bar;
}
}
......@@ -238,9 +238,9 @@ varnish v1 -errvcl {'beresp.status': Not available in method 'vcl_recv'.} {
}
}
varnish v1 -errvcl {Name of ACL, 'foo-bar', contains illegal character '-'} {
varnish v1 -errvcl {Name of ACL, 'foo.bar', contains illegal character '.'} {
backend b { .host = "127.0.0.1"; }
acl foo-bar {
acl foo.bar {
}
sub vcl_recv {
if (client.ip ~ foo.bar) {
......
......@@ -484,7 +484,7 @@ vcc_ParseAcl(struct vcc *tl)
vcc_NextToken(tl);
VTAILQ_INIT(&tl->acl);
vcc_ExpectCid(tl, "ACL");
vcc_ExpectVid(tl, "ACL");
ERRCHK(tl);
an = tl->t;
vcc_NextToken(tl);
......
......@@ -255,7 +255,7 @@ vcc_ParseProbe(struct vcc *tl)
vcc_NextToken(tl); /* ID: probe */
vcc_ExpectCid(tl, "backend probe"); /* ID: name */
vcc_ExpectVid(tl, "backend probe"); /* ID: name */
ERRCHK(tl);
t_probe = tl->t;
vcc_NextToken(tl);
......@@ -466,7 +466,7 @@ vcc_ParseBackend(struct vcc *tl)
t_first = tl->t;
vcc_NextToken(tl); /* ID: backend */
vcc_ExpectCid(tl, "backend"); /* ID: name */
vcc_ExpectVid(tl, "backend"); /* ID: name */
ERRCHK(tl);
/* XXX: lift this limit once VSM ident becomes dynamic */
......
......@@ -318,7 +318,7 @@ void vcc_ErrWhere2(struct vcc *, const struct token *, const struct token *);
void vcc__Expect(struct vcc *tl, unsigned tok, unsigned line);
int vcc_IdIs(const struct token *t, const char *p);
void vcc_ExpectCid(struct vcc *tl, const char *what);
void vcc_ExpectVid(struct vcc *tl, const char *what);
void vcc_Lexer(struct vcc *tl, struct source *sp);
void vcc_NextToken(struct vcc *tl);
void vcc__ErrInternal(struct vcc *tl, const char *func,
......
......@@ -471,7 +471,7 @@ vcc_Eval_Handle(struct vcc *tl, struct expr **e, const struct symbol *sym,
*e = vcc_mk_expr(STRING, "\"%s\"", sym->name);
(void)vcc_AddRef(tl, tl->t, sym->kind);
} else {
vcc_ExpectCid(tl, "handle");
vcc_ExpectVid(tl, "handle");
(void)vcc_AddRef(tl, tl->t, sym->kind);
*e = vcc_mk_expr(sym->fmt, "%s", sym->rname);
(*e)->constant = EXPR_VAR; /* XXX ? */
......@@ -1203,7 +1203,7 @@ vcc_expr_cmp(struct vcc *tl, struct expr **e, vcc_type_t fmt)
(tl->t->tok == '~' || tl->t->tok == T_NOMATCH)) {
not = tl->t->tok == '~' ? "" : "!";
vcc_NextToken(tl);
vcc_ExpectCid(tl, "ACL");
vcc_ExpectVid(tl, "ACL");
sym = vcc_AddRef(tl, tl->t, SYM_ACL);
VCC_GlobalSymbol(sym, ACL, ACL_SYMBOL_PREFIX);
bprintf(buf, "%sVRT_acl_match(ctx, %s, \v1)", not, sym->rname);
......
......@@ -213,7 +213,7 @@ vcc_ParseFunction(struct vcc *tl)
int m, i;
vcc_NextToken(tl);
vcc_ExpectCid(tl, "function");
vcc_ExpectVid(tl, "function");
ERRCHK(tl);
m = IsMethod(tl->t);
......
......@@ -291,26 +291,25 @@ vcc_IdIs(const struct token *t, const char *p)
}
/*--------------------------------------------------------------------
* Check that we have a C-identifier
* Check that we have a Varnish identifier
*/
void
vcc_ExpectCid(struct vcc *tl, const char *what)
vcc_ExpectVid(struct vcc *tl, const char *what)
{
const char *q;
const char *bad;
ExpectErr(tl, ID);
ERRCHK(tl);
/* XXX: too soon to use vct_invalid_name() */
for (q = tl->t->b; q < tl->t->e; q++) {
if (!vct_isalnum(*q) && *q != '_') {
VSB_printf(tl->sb, "Name of %s, ", what);
vcc_ErrToken(tl, tl->t);
VSB_printf(tl->sb,
", contains illegal character '%c'\n", *q);
vcc_ErrWhere(tl, tl->t);
return;
}
bad = VCT_invalid_name(tl->t->b, tl->t->e);
if (bad != NULL) {
VSB_printf(tl->sb, "Name of %s, ", what);
vcc_ErrToken(tl, tl->t);
VSB_printf(tl->sb,
", contains illegal character '%c'\n", *bad);
vcc_ErrWhere(tl, tl->t);
return;
}
}
......
......@@ -280,7 +280,7 @@ vcc_ParseNew(struct vcc *tl)
vcc_NextToken(tl);
ExpectErr(tl, ID);
vcc_ExpectCid(tl, "VCL object");
vcc_ExpectVid(tl, "VCL object");
ERRCHK(tl);
sy1 = VCC_HandleSymbol(tl, tl->t, INSTANCE, "vo");
ERRCHK(tl);
......
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