Commit 69a403c5 authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

Mark variables/objects as having a string representation or not

and create a function to figure this out, if present.

Add the req.hash variable and the += operator for it, so we
can put the actual hash contents under vcl control.

The runtime half of this stuff is not done yet.



git-svn-id: http://www.varnish-cache.org/svn/trunk/varnish-cache@1395 d4fa192b-c00b-0410-8231-f00ffab90ce4
parent 20ee7417
...@@ -26,6 +26,8 @@ const char * VRT_r_req_proto(struct sess *); ...@@ -26,6 +26,8 @@ const char * VRT_r_req_proto(struct sess *);
void VRT_l_req_proto(struct sess *, const char *); void VRT_l_req_proto(struct sess *, const char *);
struct backend * VRT_r_req_backend(struct sess *); struct backend * VRT_r_req_backend(struct sess *);
void VRT_l_req_backend(struct sess *, struct backend *); void VRT_l_req_backend(struct sess *, struct backend *);
int VRT_r_req_hash(struct sess *);
void VRT_l_req_hash(struct sess *, int);
double VRT_r_obj_valid(struct sess *); double VRT_r_obj_valid(struct sess *);
void VRT_l_obj_valid(struct sess *, double); void VRT_l_obj_valid(struct sess *, double);
double VRT_r_obj_cacheable(struct sess *); double VRT_r_obj_cacheable(struct sess *);
......
...@@ -37,6 +37,43 @@ ...@@ -37,6 +37,43 @@
#include "vcc_compile.h" #include "vcc_compile.h"
#include "libvarnish.h" #include "libvarnish.h"
/*--------------------------------------------------------------------*/
static void
StringVal(struct tokenlist *tl)
{
struct var *vp;
struct token *vt;
if (tl->t->tok == CSTR) {
EncToken(tl->fb, tl->t);
vcc_NextToken(tl);
return;
}
ExpectErr(tl, VAR);
ERRCHK(tl);
vt = tl->t;
vp = FindVar(tl, tl->t, vcc_vars);
ERRCHK(tl);
if (!vp->has_string) {
vsb_printf(tl->sb,
"No string representation of '%s'\n", vp->name);
vcc_ErrWhere(tl, tl->t);
return;
}
switch (vp->fmt) {
case STRING:
Fb(tl, 0, "%s", vp->rname);
break;
default:
vsb_printf(tl->sb,
"String representation of '%s' not implemented yet.\n",
vp->name);
vcc_ErrWhere(tl, tl->t);
return;
}
vcc_NextToken(tl);
}
/*--------------------------------------------------------------------*/ /*--------------------------------------------------------------------*/
...@@ -182,6 +219,12 @@ parse_set(struct tokenlist *tl) ...@@ -182,6 +219,12 @@ parse_set(struct tokenlist *tl)
" only '=' is legal for backend\n"); " only '=' is legal for backend\n");
vcc_ErrWhere(tl, tl->t); vcc_ErrWhere(tl, tl->t);
return; return;
case HASH:
ExpectErr(tl, T_INCR);
vcc_NextToken(tl);
StringVal(tl);
Fb(tl, 0, ");\n");
return;
default: default:
vsb_printf(tl->sb, vsb_printf(tl->sb,
"Assignments not possible for '%s'\n", vp->name); "Assignments not possible for '%s'\n", vp->name);
......
...@@ -252,6 +252,7 @@ HeaderVar(struct tokenlist *tl, const struct token *t, const struct var *vh) ...@@ -252,6 +252,7 @@ HeaderVar(struct tokenlist *tl, const struct token *t, const struct var *vh)
p[i] = '\0'; p[i] = '\0';
v->name = p; v->name = p;
v->fmt = STRING; v->fmt = STRING;
v->has_string = vh->has_string;
if (!memcmp(vh->name, "req.", 4)) if (!memcmp(vh->name, "req.", 4))
w = 1; w = 1;
else else
......
...@@ -96,6 +96,7 @@ enum var_type { ...@@ -96,6 +96,7 @@ enum var_type {
IP, IP,
HOSTNAME, HOSTNAME,
PORTNAME, PORTNAME,
HASH,
HEADER HEADER
}; };
...@@ -119,6 +120,7 @@ struct var { ...@@ -119,6 +120,7 @@ struct var {
unsigned len; unsigned len;
const char *rname; const char *rname;
const char *lname; const char *lname;
unsigned has_string;
}; };
struct method { struct method {
......
...@@ -32,26 +32,27 @@ ...@@ -32,26 +32,27 @@
# Objects which operate on backends # Objects which operate on backends
set beobj { set beobj {
{ backend.host HOSTNAME } { backend.host HOSTNAME 0 }
{ backend.port PORTNAME } { backend.port PORTNAME 0 }
{ backend.dnsttl TIME } { backend.dnsttl TIME 0 }
} }
# Objects which operate on sessions # Objects which operate on sessions
set spobj { set spobj {
{ client.ip IP } { client.ip IP 1}
{ server.ip IP } { server.ip IP 1}
{ req.request STRING } { req.request STRING 1}
{ req.host STRING } { req.host STRING 1}
{ req.url STRING } { req.url STRING 1}
{ req.proto STRING } { req.proto STRING 1}
{ req.backend BACKEND } { req.backend BACKEND 0}
{ obj.valid BOOL } { req.hash HASH 0}
{ obj.cacheable BOOL } { obj.valid BOOL 0}
{ obj.ttl TIME } { obj.cacheable BOOL 0}
{ req.http. HEADER } { obj.ttl TIME 0}
{ resp.http. HEADER } { req.http. HEADER 1}
{ resp.http. HEADER 1}
} }
set tt(IP) "struct sockaddr *" set tt(IP) "struct sockaddr *"
...@@ -62,6 +63,7 @@ set tt(TIME) "double" ...@@ -62,6 +63,7 @@ set tt(TIME) "double"
set tt(HEADER) "const char *" set tt(HEADER) "const char *"
set tt(HOSTNAME) "const char *" set tt(HOSTNAME) "const char *"
set tt(PORTNAME) "const char *" set tt(PORTNAME) "const char *"
set tt(HASH) "int"
#---------------------------------------------------------------------- #----------------------------------------------------------------------
# Boilerplate warning for all generated files. # Boilerplate warning for all generated files.
...@@ -93,6 +95,7 @@ proc vars {v ty pa} { ...@@ -93,6 +95,7 @@ proc vars {v ty pa} {
puts $fo "\t\{ \"$n\", $t, [string length $n]," puts $fo "\t\{ \"$n\", $t, [string length $n],"
puts $fo "\t \"VRT_r_${m}($pa)\"," puts $fo "\t \"VRT_r_${m}($pa)\","
puts $fo "\t \"VRT_l_${m}($pa, \"," puts $fo "\t \"VRT_l_${m}($pa, \","
puts $fo "\t [lindex $v 2]"
puts $fo "\t\}," puts $fo "\t\},"
puts $fp "$tt($t) VRT_r_${m}($ty);" puts $fp "$tt($t) VRT_r_${m}($ty);"
......
...@@ -13,14 +13,17 @@ struct var vcc_be_vars[] = { ...@@ -13,14 +13,17 @@ struct var vcc_be_vars[] = {
{ "backend.host", HOSTNAME, 12, { "backend.host", HOSTNAME, 12,
"VRT_r_backend_host(backend)", "VRT_r_backend_host(backend)",
"VRT_l_backend_host(backend, ", "VRT_l_backend_host(backend, ",
0
}, },
{ "backend.port", PORTNAME, 12, { "backend.port", PORTNAME, 12,
"VRT_r_backend_port(backend)", "VRT_r_backend_port(backend)",
"VRT_l_backend_port(backend, ", "VRT_l_backend_port(backend, ",
0
}, },
{ "backend.dnsttl", TIME, 14, { "backend.dnsttl", TIME, 14,
"VRT_r_backend_dnsttl(backend)", "VRT_r_backend_dnsttl(backend)",
"VRT_l_backend_dnsttl(backend, ", "VRT_l_backend_dnsttl(backend, ",
0
}, },
{ NULL } { NULL }
}; };
...@@ -29,50 +32,67 @@ struct var vcc_vars[] = { ...@@ -29,50 +32,67 @@ struct var vcc_vars[] = {
{ "client.ip", IP, 9, { "client.ip", IP, 9,
"VRT_r_client_ip(sp)", "VRT_r_client_ip(sp)",
"VRT_l_client_ip(sp, ", "VRT_l_client_ip(sp, ",
1
}, },
{ "server.ip", IP, 9, { "server.ip", IP, 9,
"VRT_r_server_ip(sp)", "VRT_r_server_ip(sp)",
"VRT_l_server_ip(sp, ", "VRT_l_server_ip(sp, ",
1
}, },
{ "req.request", STRING, 11, { "req.request", STRING, 11,
"VRT_r_req_request(sp)", "VRT_r_req_request(sp)",
"VRT_l_req_request(sp, ", "VRT_l_req_request(sp, ",
1
}, },
{ "req.host", STRING, 8, { "req.host", STRING, 8,
"VRT_r_req_host(sp)", "VRT_r_req_host(sp)",
"VRT_l_req_host(sp, ", "VRT_l_req_host(sp, ",
1
}, },
{ "req.url", STRING, 7, { "req.url", STRING, 7,
"VRT_r_req_url(sp)", "VRT_r_req_url(sp)",
"VRT_l_req_url(sp, ", "VRT_l_req_url(sp, ",
1
}, },
{ "req.proto", STRING, 9, { "req.proto", STRING, 9,
"VRT_r_req_proto(sp)", "VRT_r_req_proto(sp)",
"VRT_l_req_proto(sp, ", "VRT_l_req_proto(sp, ",
1
}, },
{ "req.backend", BACKEND, 11, { "req.backend", BACKEND, 11,
"VRT_r_req_backend(sp)", "VRT_r_req_backend(sp)",
"VRT_l_req_backend(sp, ", "VRT_l_req_backend(sp, ",
0
},
{ "req.hash", HASH, 8,
"VRT_r_req_hash(sp)",
"VRT_l_req_hash(sp, ",
0
}, },
{ "obj.valid", BOOL, 9, { "obj.valid", BOOL, 9,
"VRT_r_obj_valid(sp)", "VRT_r_obj_valid(sp)",
"VRT_l_obj_valid(sp, ", "VRT_l_obj_valid(sp, ",
0
}, },
{ "obj.cacheable", BOOL, 13, { "obj.cacheable", BOOL, 13,
"VRT_r_obj_cacheable(sp)", "VRT_r_obj_cacheable(sp)",
"VRT_l_obj_cacheable(sp, ", "VRT_l_obj_cacheable(sp, ",
0
}, },
{ "obj.ttl", TIME, 7, { "obj.ttl", TIME, 7,
"VRT_r_obj_ttl(sp)", "VRT_r_obj_ttl(sp)",
"VRT_l_obj_ttl(sp, ", "VRT_l_obj_ttl(sp, ",
0
}, },
{ "req.http.", HEADER, 9, { "req.http.", HEADER, 9,
"VRT_r_req_http_(sp)", "VRT_r_req_http_(sp)",
"VRT_l_req_http_(sp, ", "VRT_l_req_http_(sp, ",
1
}, },
{ "resp.http.", HEADER, 10, { "resp.http.", HEADER, 10,
"VRT_r_resp_http_(sp)", "VRT_r_resp_http_(sp)",
"VRT_l_resp_http_(sp, ", "VRT_l_resp_http_(sp, ",
1
}, },
{ 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