Commit 901d2e06 authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

Push the new expressions into all other actions.

Get precedence of the implicit cast to STRING right.



git-svn-id: http://www.varnish-cache.org/svn/trunk/varnish-cache@5133 d4fa192b-c00b-0410-8231-f00ffab90ce4
parent 8bd29a1e
......@@ -126,13 +126,13 @@ sub vcl_error {
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<title>"} obj.status " " obj.response {"</title>
<title>"} + obj.status + " " + obj.response + {"</title>
</head>
<body>
<h1>Error "} obj.status " " obj.response {"</h1>
<p>"} obj.response {"</p>
<h1>Error "} + obj.status + " " + obj.response + {"</h1>
<p>"} + obj.response + {"</p>
<h3>Guru Meditation:</h3>
<p>XID: "} req.xid {"</p>
<p>XID: "} + req.xid + {"</p>
<hr>
<p>Varnish cache server</p>
</body>
......
......@@ -73,6 +73,7 @@
-efile(451, "http_headers.h") // No include guard
-efile(451, "stat_field.h") // No include guard
-efile(451, "acct_fields.h") // No include guard
-efile(451, "vcc_types.h") // No include guard
-efile(451, "config.h") // No include guard
//////////////
// -e458 // unprotected access
......
......@@ -27,7 +27,7 @@ varnish v1 -vcl+backend {
error 410;
}
if (req.request == "PURGESTR") {
purge ("" req.http.purge);
purge ("" + req.http.purge);
error 410;
}
}
......
......@@ -17,7 +17,7 @@ varnish v1 -storage "-smalloc,1m" -vcl+backend {
sub vcl_fetch {
if (beresp.http.panic) {
panic "Had Panic header: " beresp.http.panic;
panic "Had Panic header: " + beresp.http.panic;
}
}
} -start
......
......@@ -15,8 +15,8 @@ varnish v1 -vcl {
varnish v1 -vcl {
backend b { .host = "127.0.0.1"; }
sub vcl_miss { error req.url ; }
sub vcl_pass { error "the butter please" ; }
sub vcl_miss { error 100 req.url ; }
sub vcl_pass { error 100 "the butter please" ; }
sub vcl_fetch { error beresp.status req.url; }
}
......
......@@ -65,24 +65,27 @@ parse_call(struct vcc *tl)
static void
parse_error(struct vcc *tl)
{
int paran = 0;
vcc_NextToken(tl);
if (tl->t->tok == '(') {
paran = 1;
vcc_NextToken(tl);
}
Fb(tl, 1, "VRT_error(sp,\n");
vcc_Expr(tl, INT);
if (tl->t->tok == ',') {
Fb(tl, 1, ",\n");
if (tl->t->tok == '(') {
vcc_NextToken(tl);
vcc_Expr(tl, STRING);
vcc_Expr(tl, INT);
if (tl->t->tok == ',') {
Fb(tl, 1, ",\n");
vcc_NextToken(tl);
vcc_Expr(tl, STRING);
} else
Fb(tl, 1, ", 0\n");
SkipToken(tl, ')');
} else {
Fb(tl, 1, ", 0\n");
vcc_Expr(tl, INT);
if (tl->t->tok != ';') {
Fb(tl, 1, ",\n");
vcc_Expr(tl, STRING);
} else
Fb(tl, 1, ", 0\n");
}
if (paran)
SkipToken(tl, ')');
Fb(tl, 1, ");\n");
Fb(tl, 1, "VRT_done(sp, VCL_RET_ERROR);\n");
}
......@@ -235,10 +238,8 @@ parse_purge(struct vcc *tl)
}
vcc_NextToken(tl);
Fb(tl, 1, " ");
if (!vcc_StringVal(tl)) {
vcc_ExpectedStringval(tl);
return;
}
vcc_Expr(tl, STRING);
ERRCHK(tl);
Fb(tl, 0, ",\n");
if (tl->t->tok == ')')
break;
......@@ -250,13 +251,9 @@ parse_purge(struct vcc *tl)
tl->indent -= INDENT;
} else {
Fb(tl, 1, "VRT_ban_string(sp, ");
if (!vcc_StringVal(tl)) {
vcc_ExpectedStringval(tl);
return;
}
do
Fb(tl, 0, ", ");
while (vcc_StringVal(tl));
vcc_Expr(tl, STRING);
ERRCHK(tl);
Fb(tl, 0, ", ");
Fb(tl, 0, "vrt_magic_string_end);\n");
}
......@@ -275,10 +272,8 @@ parse_purge_url(struct vcc *tl)
vcc_NextToken(tl);
Fb(tl, 1, "VRT_ban(sp, \"req.url\", \"~\", ");
if (!vcc_StringVal(tl)) {
vcc_ExpectedStringval(tl);
return;
}
vcc_Expr(tl, STRING);
ERRCHK(tl);
ExpectErr(tl, ')');
vcc_NextToken(tl);
Fb(tl, 0, ", 0);\n");
......@@ -314,14 +309,9 @@ parse_hash_data(struct vcc *tl)
SkipToken(tl, '(');
Fb(tl, 1, "VRT_hashdata(sp, ");
if (!vcc_StringVal(tl)) {
vcc_ExpectedStringval(tl);
return;
}
do
Fb(tl, 0, ", ");
while (vcc_StringVal(tl));
Fb(tl, 0, " vrt_magic_string_end);\n");
vcc_Expr(tl, STRING);
ERRCHK(tl);
Fb(tl, 0, ", vrt_magic_string_end);\n");
SkipToken(tl, ')');
}
......@@ -333,14 +323,9 @@ parse_panic(struct vcc *tl)
vcc_NextToken(tl);
Fb(tl, 1, "VRT_panic(sp, ");
if (!vcc_StringVal(tl)) {
vcc_ExpectedStringval(tl);
return;
}
do
Fb(tl, 0, ", ");
while (vcc_StringVal(tl));
Fb(tl, 0, " vrt_magic_string_end);\n");
vcc_Expr(tl, STRING);
ERRCHK(tl);
Fb(tl, 0, ", vrt_magic_string_end);\n");
}
/*--------------------------------------------------------------------*/
......@@ -393,14 +378,9 @@ parse_synthetic(struct vcc *tl)
vcc_NextToken(tl);
Fb(tl, 1, "VRT_synth_page(sp, 0, ");
if (!vcc_StringVal(tl)) {
vcc_ExpectedStringval(tl);
return;
}
do
Fb(tl, 0, ", ");
while (vcc_StringVal(tl));
Fb(tl, 0, " vrt_magic_string_end);\n");
vcc_Expr(tl, STRING);
ERRCHK(tl);
Fb(tl, 0, ", vrt_magic_string_end);\n");
}
/*--------------------------------------------------------------------*/
......@@ -410,14 +390,9 @@ parse_log(struct vcc *tl)
vcc_NextToken(tl);
Fb(tl, 1, "VRT_log(sp, ");
if (!vcc_StringVal(tl)) {
vcc_ExpectedStringval(tl);
return;
}
do
Fb(tl, 0, ", ");
while (vcc_StringVal(tl));
Fb(tl, 0, " vrt_magic_string_end);\n");
vcc_Expr(tl, STRING);
ERRCHK(tl);
Fb(tl, 0, ", vrt_magic_string_end);\n");
}
/*--------------------------------------------------------------------*/
......
......@@ -359,14 +359,14 @@ hack_regsub(struct vcc *tl, struct expr **e, int all)
/*--------------------------------------------------------------------
* SYNTAX:
* Expr4:
* Expr5:
* '(' Expr0 ')'
* CNUM
* CSTR
*/
static void
vcc_expr4(struct vcc *tl, struct expr **e, enum var_type fmt)
vcc_expr5(struct vcc *tl, struct expr **e, enum var_type fmt)
{
struct expr *e1, *e2;
const struct symbol *sym;
......@@ -469,6 +469,34 @@ vcc_expr4(struct vcc *tl, struct expr **e, enum var_type fmt)
*e = e1;
}
/*--------------------------------------------------------------------
*/
static void
vcc_expr4(struct vcc *tl, struct expr **e, enum var_type fmt)
{
const char *p;
*e = NULL;
vcc_expr5(tl, e, fmt);
ERRCHK(tl);
if (fmt == STRING) {
p = NULL;
switch((*e)->fmt) {
case BACKEND: p = "VRT_backend_string(sp, \v1)"; break;
case INT: p = "VRT_int_string(sp, \v1)"; break;
case IP: p = "VRT_IP_string(sp, \v1)"; break;
case TIME: p = "VRT_time_string(sp, \v1)"; break;
case DURATION: p = "VRT_double_string(sp, \v1)"; break;
/* XXX: should have "s" suffix ? */
default: break;
}
if (p != NULL) {
*e = vcc_expr_edit(STRING, p, *e, NULL);
return;
}
}
}
/*--------------------------------------------------------------------
* SYNTAX:
* Expr3:
......@@ -497,6 +525,7 @@ vcc_expr_mul(struct vcc *tl, struct expr **e, enum var_type fmt)
tk = tl->t;
vcc_NextToken(tl);
vcc_expr4(tl, &e2, f2);
assert(e2->fmt == f2);
ERRCHK(tl);
if (tk->tok == '+')
*e = vcc_expr_edit(f3, "(\v1+\v2)", *e, e2);
......@@ -526,9 +555,9 @@ vcc_expr_add(struct vcc *tl, struct expr **e, enum var_type fmt)
*e = vcc_expr_edit(STRING, "\v+VRT_String(sp,\n\v1", *e, NULL);
while (tl->t->tok == '+') {
vcc_NextToken(tl);
vcc_expr0(tl, &e2, STRING);
vcc_expr_mul(tl, &e2, STRING);
assert(e2->fmt == STRING);
*e = vcc_expr_edit(STRING, "\v1, \v2", *e, e2);
*e = vcc_expr_edit(STRING, "\v1,\n\v2", *e, e2);
}
*e = vcc_expr_edit(STRING, "\v1, vrt_magic_string_end)",
*e, NULL);
......@@ -546,6 +575,7 @@ vcc_expr_add(struct vcc *tl, struct expr **e, enum var_type fmt)
while (tl->t->tok == '+' || tl->t->tok == '-') {
vcc_NextToken(tl);
vcc_expr_mul(tl, &e2, f2);
assert(e2->fmt == f2);
ERRCHK(tl);
if (tl->t->tok == '+')
*e = vcc_expr_edit(f2, "(\v1+\v2)", *e, e2);
......@@ -598,7 +628,6 @@ vcc_expr_cmp(struct vcc *tl, struct expr **e, enum var_type fmt)
char buf[256];
char *re;
const char *not;
const char *p;
struct token *tk;
*e = NULL;
......@@ -684,20 +713,6 @@ vcc_expr_cmp(struct vcc *tl, struct expr **e, enum var_type fmt)
break;
}
}
if (fmt == STRING) {
p = NULL;
switch((*e)->fmt) {
case BACKEND: p = "VRT_backend_string(sp, \v1)"; break;
case INT: p = "VRT_int_string(sp, \v1)"; break;
case IP: p = "VRT_IP_string(sp, \v1)"; break;
case TIME: p = "VRT_time_string(sp, \v1)"; break;
default: break;
}
if (p != NULL) {
*e = vcc_expr_edit(STRING, p, *e, NULL);
return;
}
}
if (fmt == VOID || fmt != (*e)->fmt) {
vsb_printf(tl->sb, "WANT: %s has %s next %.*s (%s)\n",
vcc_Type(fmt), vcc_Type((*e)->fmt),
......
......@@ -77,134 +77,3 @@ vcc_regexp(struct vcc *tl)
Ff(tl, 0, "\tVRT_re_fini(%s);\n", buf);
return (p);
}
/*--------------------------------------------------------------------*/
static int
vcc_regsub(struct vcc *tl, int all)
{
char *p;
vcc_NextToken(tl);
Fb(tl, 0, "VRT_regsub(sp, %d, ", all);
Expect(tl, '(');
if (tl->err)
return (0);
vcc_NextToken(tl);
if (!vcc_StringVal(tl)) {
vcc_ExpectedStringval(tl);
return (0);
}
Expect(tl, ',');
if (tl->err)
return (0);
vcc_NextToken(tl);
Expect(tl, CSTR);
if (tl->err)
return (0);
p = vcc_regexp(tl);
vcc_NextToken(tl);
Fb(tl, 0, ", %s, ", p);
Expect(tl, ',');
if (tl->err)
return (0);
vcc_NextToken(tl);
if (!vcc_StringVal(tl)) {
vcc_ExpectedStringval(tl);
return (0);
}
Expect(tl, ')');
if (tl->err)
return (0);
vcc_NextToken(tl);
Fb(tl, 0, ")");
return (1);
}
/*--------------------------------------------------------------------
* Parse a string value and emit something that results in a usable
* "const char *".
* There are three possible outcomes:
* tl->err != 0 means something bad happened and a message is emitted.
* return (0) means "could not use this token"
* return (1) means "done"
*/
int
vcc_StringVal(struct vcc *tl)
{
const struct var *vp;
if (tl->t->tok == CSTR) {
EncToken(tl->fb, tl->t);
vcc_NextToken(tl);
return (1);
}
if (tl->t->tok == ID && vcc_IdIs(tl->t, "regsub"))
return (vcc_regsub(tl, 0));
if (tl->t->tok == ID && vcc_IdIs(tl->t, "regsuball"))
return (vcc_regsub(tl, 1));
if (tl->t->tok == ID && vcc_IdIs(tl->t, "now")) {
Fb(tl, 0, "VRT_time_string(sp, VRT_r_now(sp))");
vcc_NextToken(tl);
return 1;
}
if (tl->t->tok == ID) {
vp = vcc_FindVar(tl, tl->t, 0, "cannot be read");
if (tl->err)
return (0);
assert(vp != NULL);
switch (vp->fmt) {
case STRING:
Fb(tl, 0, "%s", vp->rname);
break;
case IP:
Fb(tl, 0, "VRT_IP_string(sp, %s)", vp->rname);
break;
case INT:
Fb(tl, 0, "VRT_int_string(sp, %s)", vp->rname);
break;
#if 0
case FLOAT:
Fb(tl, 0, "VRT_double_string(sp, %s)", vp->rname);
break;
#endif
case TIME:
Fb(tl, 0, "VRT_time_string(sp, %s)", vp->rname);
break;
case DURATION:
Fb(tl, 0, "VRT_double_string(sp, %s)", vp->rname);
break;
case BACKEND:
Fb(tl, 0, "VRT_backend_string(sp, NULL)");
break;
default:
vsb_printf(tl->sb, "String representation of '%s'"
" not implemented yet.\n", vp->name);
vcc_ErrWhere(tl, tl->t);
return (0);
}
vcc_NextToken(tl);
return (1);
}
return (0);
}
void
vcc_ExpectedStringval(struct vcc *tl)
{
if (!tl->err) {
vsb_printf(tl->sb, "Expected string variable or constant\n");
vcc_ErrWhere(tl, tl->t);
}
}
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