Commit 77b337db authored by Tollef Fog Heen's avatar Tollef Fog Heen

Merge r3460: New return syntax

Add support for, and use a new syntax for terminating actions in VCL,
basically "return(action)" instead of just "action".

The previous syntax is still available.



git-svn-id: http://www.varnish-cache.org/svn/branches/2.0@3657 d4fa192b-c00b-0410-8231-f00ffab90ce4
parent b4a28300
...@@ -48,25 +48,25 @@ sub vcl_recv { ...@@ -48,25 +48,25 @@ sub vcl_recv {
req.request != "OPTIONS" && req.request != "OPTIONS" &&
req.request != "DELETE") { req.request != "DELETE") {
/* Non-RFC2616 or CONNECT which is weird. */ /* Non-RFC2616 or CONNECT which is weird. */
pipe; return (pipe);
} }
if (req.request != "GET" && req.request != "HEAD") { if (req.request != "GET" && req.request != "HEAD") {
/* We only deal with GET and HEAD by default */ /* We only deal with GET and HEAD by default */
pass; return (pass);
} }
if (req.http.Authorization || req.http.Cookie) { if (req.http.Authorization || req.http.Cookie) {
/* Not cacheable by default */ /* Not cacheable by default */
pass; return (pass);
} }
lookup; return (lookup);
} }
sub vcl_pipe { sub vcl_pipe {
pipe; return (pipe);
} }
sub vcl_pass { sub vcl_pass {
pass; return (pass);
} }
sub vcl_hash { sub vcl_hash {
...@@ -76,48 +76,48 @@ sub vcl_hash { ...@@ -76,48 +76,48 @@ sub vcl_hash {
} else { } else {
set req.hash += server.ip; set req.hash += server.ip;
} }
hash; return (hash);
} }
sub vcl_hit { sub vcl_hit {
if (!obj.cacheable) { if (!obj.cacheable) {
pass; return (pass);
} }
deliver; return (deliver);
} }
sub vcl_miss { sub vcl_miss {
fetch; return (fetch);
} }
sub vcl_fetch { sub vcl_fetch {
if (!obj.cacheable) { if (!obj.cacheable) {
pass; return (pass);
} }
if (obj.http.Set-Cookie) { if (obj.http.Set-Cookie) {
pass; return (pass);
} }
set obj.prefetch = -30s; set obj.prefetch = -30s;
deliver; return (deliver);
} }
sub vcl_deliver { sub vcl_deliver {
deliver; return (deliver);
} }
sub vcl_discard { sub vcl_discard {
/* XXX: Do not redefine vcl_discard{}, it is not yet supported */ /* XXX: Do not redefine vcl_discard{}, it is not yet supported */
discard; return (discard);
} }
sub vcl_prefetch { sub vcl_prefetch {
/* XXX: Do not redefine vcl_prefetch{}, it is not yet supported */ /* XXX: Do not redefine vcl_prefetch{}, it is not yet supported */
fetch; return (fetch);
} }
sub vcl_timeout { sub vcl_timeout {
/* XXX: Do not redefine vcl_timeout{}, it is not yet supported */ /* XXX: Do not redefine vcl_timeout{}, it is not yet supported */
discard; return (discard);
} }
sub vcl_error { sub vcl_error {
...@@ -141,5 +141,5 @@ sub vcl_error { ...@@ -141,5 +141,5 @@ sub vcl_error {
</body> </body>
</html> </html>
"}; "};
deliver; return (deliver);
} }
...@@ -41,23 +41,37 @@ ...@@ -41,23 +41,37 @@
/*--------------------------------------------------------------------*/ /*--------------------------------------------------------------------*/
#define VCL_RET_MAC(l,u,b,i) \ static void
static void \ parse_action(struct tokenlist *tl)
parse_##l(struct tokenlist *tl) \ {
{ \ int retval = 0;
\
Expect(tl, ID);
#define VCL_RET_MAC(l, u, b, i) \
do { \
if (vcc_IdIs(tl->t, #l)) { \
Fb(tl, 1, "VRT_done(sp, VCL_RET_%s);\n", #u); \ Fb(tl, 1, "VRT_done(sp, VCL_RET_%s);\n", #u); \
vcc_ProcAction(tl->curproc, i, tl->t); \ vcc_ProcAction(tl->curproc, i, tl->t); \
vcc_NextToken(tl); \ retval = 1; \
} } \
} while (0);
#define VCL_RET_MAC_E(l, u, b, i) VCL_RET_MAC(l, u, b, i)
#include "vcl_returns.h" #include "vcl_returns.h"
#undef VCL_RET_MAC #undef VCL_RET_MAC
#undef VCL_RET_MAC_E
if (!retval) {
vsb_printf(tl->sb, "Expected action name.\n");
vcc_ErrWhere(tl, tl->t);
ERRCHK(tl);
}
vcc_NextToken(tl);
}
/*--------------------------------------------------------------------*/ /*--------------------------------------------------------------------*/
static void static void
parse_restart_real(struct tokenlist *tl) parse_restart(struct tokenlist *tl)
{ {
struct token *t1; struct token *t1;
...@@ -70,7 +84,9 @@ parse_restart_real(struct tokenlist *tl) ...@@ -70,7 +84,9 @@ parse_restart_real(struct tokenlist *tl)
vcc_ErrWhere(tl, t1); vcc_ErrWhere(tl, t1);
ERRCHK(tl); ERRCHK(tl);
} }
parse_restart(tl); Fb(tl, 1, "VRT_done(sp, VCL_RET_RESTART);\n");
vcc_ProcAction(tl->curproc, VCL_RET_RESTART, tl->t);
vcc_NextToken(tl);
} }
/*--------------------------------------------------------------------*/ /*--------------------------------------------------------------------*/
...@@ -406,6 +422,22 @@ parse_panic(struct tokenlist *tl) ...@@ -406,6 +422,22 @@ parse_panic(struct tokenlist *tl)
/*--------------------------------------------------------------------*/ /*--------------------------------------------------------------------*/
static void
parse_return(struct tokenlist *tl)
{
vcc_NextToken(tl);
Expect(tl, '(');
vcc_NextToken(tl);
Expect(tl, ID);
parse_action(tl);
ERRCHK(tl);
Expect(tl, ')');
vcc_NextToken(tl);
}
/*--------------------------------------------------------------------*/
static void static void
parse_synthetic(struct tokenlist *tl) parse_synthetic(struct tokenlist *tl)
{ {
...@@ -430,12 +462,11 @@ static struct action_table { ...@@ -430,12 +462,11 @@ static struct action_table {
const char *name; const char *name;
action_f *func; action_f *func;
} action_table[] = { } action_table[] = {
{ "restart", parse_restart_real }, { "restart", parse_restart },
#define VCL_RET_MAC(l, u, b, i) { #l, parse_##l }, { "error", parse_error },
#define VCL_RET_MAC_E(l, u, b, i) VCL_RET_MAC(l, u, b, i) #define VCL_RET_MAC(l, u, b, i) { #l, parse_action },
#include "vcl_returns.h" #include "vcl_returns.h"
#undef VCL_RET_MAC #undef VCL_RET_MAC
#undef VCL_RET_MAC_E
/* Keep list sorted from here */ /* Keep list sorted from here */
{ "call", parse_call }, { "call", parse_call },
...@@ -447,6 +478,7 @@ static struct action_table { ...@@ -447,6 +478,7 @@ static struct action_table {
{ "set", parse_set }, { "set", parse_set },
{ "synthetic", parse_synthetic }, { "synthetic", parse_synthetic },
{ "unset", parse_unset }, { "unset", parse_unset },
{ "return", parse_return },
{ NULL, NULL } { NULL, NULL }
}; };
......
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