From 9049aee3c1fb02090363a6218ad913b42eb6ed7d Mon Sep 17 00:00:00 2001 From: phk Date: Tue, 26 Jun 2007 10:01:49 +0000 Subject: [PATCH] Markup all VCL variables as RO, WO or RW and generate and check code accordingly. git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@1576 d4fa192b-c00b-0410-8231-f00ffab90ce4 --- varnish-cache/bin/varnishd/cache_vrt.c | 7 -- varnish-cache/include/vrt_obj.h | 16 ---- varnish-cache/lib/libvcl/vcc_action.c | 6 ++ varnish-cache/lib/libvcl/vcc_compile.h | 1 + varnish-cache/lib/libvcl/vcc_gen_obj.tcl | 104 +++++++++++++++++------ varnish-cache/lib/libvcl/vcc_obj.c | 51 ++++++----- varnish-cache/lib/libvcl/vcc_var.c | 2 - 7 files changed, 118 insertions(+), 69 deletions(-) diff --git a/varnish-cache/bin/varnishd/cache_vrt.c b/varnish-cache/bin/varnishd/cache_vrt.c index 8d4623b8..5bbdbc06 100644 --- a/varnish-cache/bin/varnishd/cache_vrt.c +++ b/varnish-cache/bin/varnishd/cache_vrt.c @@ -152,13 +152,6 @@ VRT_l_backend_##onm(struct backend *be, type a) \ CHECK_OBJ_NOTNULL(be, BACKEND_MAGIC); \ be->field = a; \ } \ - \ -type \ -VRT_r_backend_##onm(struct backend *be) \ -{ \ - CHECK_OBJ_NOTNULL(be, BACKEND_MAGIC); \ - return (be->field); \ -} VBACKEND(const char *, host, hostname) VBACKEND(const char *, port, portname) diff --git a/varnish-cache/include/vrt_obj.h b/varnish-cache/include/vrt_obj.h index bd7e84b7..9ca434e3 100644 --- a/varnish-cache/include/vrt_obj.h +++ b/varnish-cache/include/vrt_obj.h @@ -6,29 +6,17 @@ * Edit vcc_gen_obj.tcl instead */ -const char * VRT_r_backend_host(struct backend *); void VRT_l_backend_host(struct backend *, const char *); -const char * VRT_r_backend_port(struct backend *); void VRT_l_backend_port(struct backend *, const char *); -double VRT_r_backend_dnsttl(struct backend *); void VRT_l_backend_dnsttl(struct backend *, double); struct sockaddr * VRT_r_client_ip(struct sess *); -void VRT_l_client_ip(struct sess *, struct sockaddr *); struct sockaddr * VRT_r_server_ip(struct sess *); -void VRT_l_server_ip(struct sess *, struct sockaddr *); const char * VRT_r_req_request(struct sess *); -void VRT_l_req_request(struct sess *, const char *); -const char * VRT_r_req_host(struct sess *); -void VRT_l_req_host(struct sess *, const char *); const char * VRT_r_req_url(struct sess *); -void VRT_l_req_url(struct sess *, const char *); const char * VRT_r_req_proto(struct sess *); -void VRT_l_req_proto(struct sess *, const char *); struct backend * VRT_r_req_backend(struct sess *); void VRT_l_req_backend(struct sess *, struct backend *); const char * VRT_r_req_http_(struct sess *); -void VRT_l_req_http_(struct sess *, const char *); -const char * VRT_r_req_hash(struct sess *); void VRT_l_req_hash(struct sess *, const char *); unsigned VRT_r_obj_valid(struct sess *); void VRT_l_obj_valid(struct sess *, unsigned); @@ -37,10 +25,6 @@ void VRT_l_obj_cacheable(struct sess *, unsigned); double VRT_r_obj_ttl(struct sess *); void VRT_l_obj_ttl(struct sess *, double); const char * VRT_r_resp_proto(struct sess *); -void VRT_l_resp_proto(struct sess *, const char *); int VRT_r_resp_status(struct sess *); -void VRT_l_resp_status(struct sess *, int); const char * VRT_r_resp_response(struct sess *); -void VRT_l_resp_response(struct sess *, const char *); const char * VRT_r_resp_http_(struct sess *); -void VRT_l_resp_http_(struct sess *, const char *); diff --git a/varnish-cache/lib/libvcl/vcc_action.c b/varnish-cache/lib/libvcl/vcc_action.c index 2b5db2cc..54f35613 100644 --- a/varnish-cache/lib/libvcl/vcc_action.c +++ b/varnish-cache/lib/libvcl/vcc_action.c @@ -105,6 +105,12 @@ parse_set(struct tokenlist *tl) vp = vcc_FindVar(tl, tl->t, vcc_vars); ERRCHK(tl); assert(vp != NULL); + if (vp->access != V_RW && vp->access != V_WO) { + vsb_printf(tl->sb, "Variable %.*s cannot be written.\n", + PF(vt)); + vcc_ErrWhere(tl, vt); + return; + } Fb(tl, 1, "%s", vp->lname); vcc_NextToken(tl); switch (vp->fmt) { diff --git a/varnish-cache/lib/libvcl/vcc_compile.h b/varnish-cache/lib/libvcl/vcc_compile.h index 56f9e61f..45e45eb6 100644 --- a/varnish-cache/lib/libvcl/vcc_compile.h +++ b/varnish-cache/lib/libvcl/vcc_compile.h @@ -120,6 +120,7 @@ struct var { unsigned len; const char *rname; const char *lname; + enum {V_RO, V_RW, V_WO} access; unsigned methods; }; diff --git a/varnish-cache/lib/libvcl/vcc_gen_obj.tcl b/varnish-cache/lib/libvcl/vcc_gen_obj.tcl index 12fd7cb8..a718bd0c 100755 --- a/varnish-cache/lib/libvcl/vcc_gen_obj.tcl +++ b/varnish-cache/lib/libvcl/vcc_gen_obj.tcl @@ -32,30 +32,74 @@ # Objects which operate on backends set beobj { - { backend.host HOSTNAME } - { backend.port PORTNAME } - { backend.dnsttl TIME } + { backend.host WO HOSTNAME } + { backend.port WO PORTNAME } + { backend.dnsttl WO TIME } } # Objects which operate on sessions set spobj { - { client.ip IP {recv pipe pass hash miss hit fetch } } - { server.ip IP {recv pipe pass hash miss hit fetch } } - { req.request STRING {recv pipe pass hash miss hit fetch } } - { req.host STRING {recv pipe pass hash miss hit fetch } } - { req.url STRING {recv pipe pass hash miss hit fetch } } - { req.proto STRING {recv pipe pass hash miss hit fetch } } - { req.backend BACKEND {recv pipe pass hash miss hit fetch } } - { req.http. HEADER {recv pipe pass hash miss hit fetch } } - { req.hash HASH { hash } } - { obj.valid BOOL { hit fetch discard timeout} } - { obj.cacheable BOOL { hit fetch discard timeout} } - { obj.ttl TIME { hit fetch discard timeout} } - { resp.proto STRING { fetch } } - { resp.status INT { fetch } } - { resp.response STRING { fetch } } - { resp.http. HEADER { fetch } } + { client.ip + RO IP + {recv pipe pass hash miss hit fetch } + } + { server.ip + RO IP + {recv pipe pass hash miss hit fetch } + } + { req.request + RO STRING + {recv pipe pass hash miss hit fetch } + } + { req.url + RO STRING + {recv pipe pass hash miss hit fetch } + } + { req.proto + RO STRING + {recv pipe pass hash miss hit fetch } + } + { req.backend + RW BACKEND + {recv pipe pass hash miss hit fetch } + } + { req.http. + RO HEADER + {recv pipe pass hash miss hit fetch } + } + { req.hash + WO HASH + { hash } + } + { obj.valid + RW BOOL + { hit fetch discard timeout} + } + { obj.cacheable + RW BOOL + { hit fetch discard timeout} + } + { obj.ttl + RW TIME + { hit fetch discard timeout} + } + { resp.proto + RO STRING + { fetch } + } + { resp.status + RO INT + { fetch } + } + { resp.response + RO STRING + { fetch } + } + { resp.http. + RO HEADER + { fetch } + } } set tt(IP) "struct sockaddr *" @@ -105,15 +149,25 @@ proc vars {v ty pa} { foreach v $v { set n [lindex $v 0] regsub -all {[.]} $n "_" m - set t [lindex $v 1] + set a [lindex $v 1] + set t [lindex $v 2] puts $fo "\t\{ \"$n\", $t, [string length $n]," - puts $fo "\t \"VRT_r_${m}($pa)\"," - puts $fo "\t \"VRT_l_${m}($pa, \"," - puts $fo "\t [method_map [lindex $v 2]]" + if {$a == "RO" || $a == "RW"} { + puts $fo "\t \"VRT_r_${m}($pa)\"," + puts $fp "$tt($t) VRT_r_${m}($ty);" + } else { + puts $fo "\t NULL," + } + if {$a == "WO" || $a == "RW"} { + puts $fo "\t \"VRT_l_${m}($pa, \"," + puts $fp "void VRT_l_${m}($ty, $tt($t));" + } else { + puts $fo "\t NULL," + } + puts $fo "\t V_$a," + puts $fo "\t [method_map [lindex $v 3]]" puts $fo "\t\}," - puts $fp "$tt($t) VRT_r_${m}($ty);" - puts $fp "void VRT_l_${m}($ty, $tt($t));" } puts $fo "\t{ NULL }" } diff --git a/varnish-cache/lib/libvcl/vcc_obj.c b/varnish-cache/lib/libvcl/vcc_obj.c index 9b408c16..da9586b0 100644 --- a/varnish-cache/lib/libvcl/vcc_obj.c +++ b/varnish-cache/lib/libvcl/vcc_obj.c @@ -11,18 +11,21 @@ struct var vcc_be_vars[] = { { "backend.host", HOSTNAME, 12, - "VRT_r_backend_host(backend)", + NULL, "VRT_l_backend_host(backend, ", + V_WO, }, { "backend.port", PORTNAME, 12, - "VRT_r_backend_port(backend)", + NULL, "VRT_l_backend_port(backend, ", + V_WO, }, { "backend.dnsttl", TIME, 14, - "VRT_r_backend_dnsttl(backend)", + NULL, "VRT_l_backend_dnsttl(backend, ", + V_WO, }, { NULL } @@ -31,82 +34,92 @@ struct var vcc_be_vars[] = { struct var vcc_vars[] = { { "client.ip", IP, 9, "VRT_r_client_ip(sp)", - "VRT_l_client_ip(sp, ", + NULL, + V_RO, VCL_MET_RECV | VCL_MET_PIPE | VCL_MET_PASS | VCL_MET_HASH | VCL_MET_MISS | VCL_MET_HIT | VCL_MET_FETCH }, { "server.ip", IP, 9, "VRT_r_server_ip(sp)", - "VRT_l_server_ip(sp, ", + NULL, + V_RO, VCL_MET_RECV | VCL_MET_PIPE | VCL_MET_PASS | VCL_MET_HASH | VCL_MET_MISS | VCL_MET_HIT | VCL_MET_FETCH }, { "req.request", STRING, 11, "VRT_r_req_request(sp)", - "VRT_l_req_request(sp, ", - VCL_MET_RECV | VCL_MET_PIPE | VCL_MET_PASS | VCL_MET_HASH | VCL_MET_MISS | VCL_MET_HIT | VCL_MET_FETCH - }, - { "req.host", STRING, 8, - "VRT_r_req_host(sp)", - "VRT_l_req_host(sp, ", + NULL, + V_RO, VCL_MET_RECV | VCL_MET_PIPE | VCL_MET_PASS | VCL_MET_HASH | VCL_MET_MISS | VCL_MET_HIT | VCL_MET_FETCH }, { "req.url", STRING, 7, "VRT_r_req_url(sp)", - "VRT_l_req_url(sp, ", + NULL, + V_RO, VCL_MET_RECV | VCL_MET_PIPE | VCL_MET_PASS | VCL_MET_HASH | VCL_MET_MISS | VCL_MET_HIT | VCL_MET_FETCH }, { "req.proto", STRING, 9, "VRT_r_req_proto(sp)", - "VRT_l_req_proto(sp, ", + NULL, + V_RO, VCL_MET_RECV | VCL_MET_PIPE | VCL_MET_PASS | VCL_MET_HASH | VCL_MET_MISS | VCL_MET_HIT | VCL_MET_FETCH }, { "req.backend", BACKEND, 11, "VRT_r_req_backend(sp)", "VRT_l_req_backend(sp, ", + V_RW, VCL_MET_RECV | VCL_MET_PIPE | VCL_MET_PASS | VCL_MET_HASH | VCL_MET_MISS | VCL_MET_HIT | VCL_MET_FETCH }, { "req.http.", HEADER, 9, "VRT_r_req_http_(sp)", - "VRT_l_req_http_(sp, ", + NULL, + V_RO, VCL_MET_RECV | VCL_MET_PIPE | VCL_MET_PASS | VCL_MET_HASH | VCL_MET_MISS | VCL_MET_HIT | VCL_MET_FETCH }, { "req.hash", HASH, 8, - "VRT_r_req_hash(sp)", + NULL, "VRT_l_req_hash(sp, ", + V_WO, VCL_MET_HASH }, { "obj.valid", BOOL, 9, "VRT_r_obj_valid(sp)", "VRT_l_obj_valid(sp, ", + V_RW, VCL_MET_HIT | VCL_MET_FETCH | VCL_MET_DISCARD | VCL_MET_TIMEOUT }, { "obj.cacheable", BOOL, 13, "VRT_r_obj_cacheable(sp)", "VRT_l_obj_cacheable(sp, ", + V_RW, VCL_MET_HIT | VCL_MET_FETCH | VCL_MET_DISCARD | VCL_MET_TIMEOUT }, { "obj.ttl", TIME, 7, "VRT_r_obj_ttl(sp)", "VRT_l_obj_ttl(sp, ", + V_RW, VCL_MET_HIT | VCL_MET_FETCH | VCL_MET_DISCARD | VCL_MET_TIMEOUT }, { "resp.proto", STRING, 10, "VRT_r_resp_proto(sp)", - "VRT_l_resp_proto(sp, ", + NULL, + V_RO, VCL_MET_FETCH }, { "resp.status", INT, 11, "VRT_r_resp_status(sp)", - "VRT_l_resp_status(sp, ", + NULL, + V_RO, VCL_MET_FETCH }, { "resp.response", STRING, 13, "VRT_r_resp_response(sp)", - "VRT_l_resp_response(sp, ", + NULL, + V_RO, VCL_MET_FETCH }, { "resp.http.", HEADER, 10, "VRT_r_resp_http_(sp)", - "VRT_l_resp_http_(sp, ", + NULL, + V_RO, VCL_MET_FETCH }, { NULL } diff --git a/varnish-cache/lib/libvcl/vcc_var.c b/varnish-cache/lib/libvcl/vcc_var.c index 96b38eba..eb9a522d 100644 --- a/varnish-cache/lib/libvcl/vcc_var.c +++ b/varnish-cache/lib/libvcl/vcc_var.c @@ -44,7 +44,6 @@ void vcc_StringVal(struct tokenlist *tl) { struct var *vp; - struct token *vt; if (tl->t->tok == CSTR) { EncToken(tl->fb, tl->t); @@ -53,7 +52,6 @@ vcc_StringVal(struct tokenlist *tl) } ExpectErr(tl, VAR); ERRCHK(tl); - vt = tl->t; vp = vcc_FindVar(tl, tl->t, vcc_vars); ERRCHK(tl); switch (vp->fmt) { -- 2.39.5