]> err.no Git - varnish/commitdiff
Markup all VCL variables as RO, WO or RW and generate and check code
authorphk <phk@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Tue, 26 Jun 2007 10:01:49 +0000 (10:01 +0000)
committerphk <phk@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Tue, 26 Jun 2007 10:01:49 +0000 (10:01 +0000)
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
varnish-cache/include/vrt_obj.h
varnish-cache/lib/libvcl/vcc_action.c
varnish-cache/lib/libvcl/vcc_compile.h
varnish-cache/lib/libvcl/vcc_gen_obj.tcl
varnish-cache/lib/libvcl/vcc_obj.c
varnish-cache/lib/libvcl/vcc_var.c

index 8d4623b8c14a9b31df0923c5f77fc928772e68fc..5bbdbc0603741a7117cc2c55347280e35820fa31 100644 (file)
@@ -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)
index bd7e84b732f57c346b160ffcea0fd1c99c9f692c..9ca434e331e51395e5f01136a4e64093b1e7cf21 100644 (file)
@@ -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 *);
index 2b5db2cc5e739a4b959feb5034a07ef44a41b23b..54f35613a5dd51c7273c85e57c161ebf3448c431 100644 (file)
@@ -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) {
index 56f9e61fa3fa5a002b8911e95a3696bddc89959f..45e45eb62dd58c227ac4559d87b7be77e34b52fb 100644 (file)
@@ -120,6 +120,7 @@ struct var {
        unsigned                len;
        const char              *rname;
        const char              *lname;
+       enum {V_RO, V_RW, V_WO} access;
        unsigned                methods;
 };
 
index 12fd7cb80b2d069070bfb6f80676ba5f94cd4be2..a718bd0cd74a76664099d96d30ffab72e694fc9c 100755 (executable)
 
 # 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 }"
 }
index 9b408c1637c4d8b87b4110584fcad0140953791f..da9586b0a159315b509b9d1021b55ad9a2cf27a0 100644 (file)
 
 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 }
index 96b38eba9d2a916f6c7ecdbc139dc20a285c70b7..eb9a522d04f2190d01f9d852d2f722ebcc3a8fb2 100644 (file)
@@ -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) {