]> err.no Git - varnish/commitdiff
Use an enum instead of magic '1' and '2' values to VRT_GetHdr.
authorphk <phk@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Mon, 25 Jun 2007 09:10:20 +0000 (09:10 +0000)
committerphk <phk@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Mon, 25 Jun 2007 09:10:20 +0000 (09:10 +0000)
Remove bogus "has_string" variable marking, it can be derived from the type.

Make obj.* variables valid in vcl_timeout() and vcl_discard()

git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@1554 d4fa192b-c00b-0410-8231-f00ffab90ce4

varnish-cache/bin/varnishd/cache_vrt.c
varnish-cache/include/vrt.h
varnish-cache/lib/libvcl/vcc_compile.h
varnish-cache/lib/libvcl/vcc_fixed_token.c
varnish-cache/lib/libvcl/vcc_gen_obj.tcl
varnish-cache/lib/libvcl/vcc_obj.c
varnish-cache/lib/libvcl/vcc_var.c

index 13256f64ad3bdf2b9bf999d91b82be455999d484..10a9cbb0b8f6904ac29165f44f1cac9ccb5e601e 100644 (file)
@@ -71,17 +71,17 @@ VRT_count(struct sess *sp, unsigned u)
 /*--------------------------------------------------------------------*/
 
 char *
-VRT_GetHdr(struct sess *sp, int where, const char *n)
+VRT_GetHdr(struct sess *sp, enum gethdr_e where, const char *n)
 {
        char *p;
        struct http *hp;
 
        CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
        switch (where) {
-       case 1:
+       case HDR_REQ:
                hp = sp->http;
                break;
-       case 2:
+       case HDR_RESP:
                hp = &sp->obj->http;
                break;
        default:
index a0efbd17107a799c272523960eeac02386550504..391212d23d219307fadb38717092b5e222bfacc3 100644 (file)
@@ -74,7 +74,8 @@ int VRT_rewrite(const char *, const char *);
 void VRT_error(struct sess *, unsigned, const char *);
 int VRT_switch_config(const char *);
 
-char *VRT_GetHdr(struct sess *, int where, const char *);
+enum gethdr_e { HDR_REQ, HDR_RESP };
+char *VRT_GetHdr(struct sess *, enum gethdr_e where, const char *);
 void VRT_handling(struct sess *sp, unsigned hand);
 
 /* Backend related */
index 8f89c31d1613630680b88eb94c5f5b3c60198d05..56f9e61fa3fa5a002b8911e95a3696bddc89959f 100644 (file)
@@ -120,7 +120,6 @@ struct var {
        unsigned                len;
        const char              *rname;
        const char              *lname;
-       unsigned                has_string;
        unsigned                methods;
 };
 
index 2aa224c2467cafe8c77d2a29c6e712b93098174d..e2b17b776e6a8d1b79a79b3195af93a264f6b5d0 100644 (file)
@@ -428,7 +428,8 @@ vcl_output_lang_h(struct vsb *sb)
        vsb_cat(sb, "void VRT_error(struct sess *, unsigned, const char *);\n");
        vsb_cat(sb, "int VRT_switch_config(const char *);\n");
        vsb_cat(sb, "\n");
-       vsb_cat(sb, "char *VRT_GetHdr(struct sess *, int where, const char *);\n");
+       vsb_cat(sb, "enum gethdr_e { HDR_REQ, HDR_RESP };\n");
+       vsb_cat(sb, "char *VRT_GetHdr(struct sess *, enum gethdr_e where, const char *);\n");
        vsb_cat(sb, "void VRT_handling(struct sess *sp, unsigned hand);\n");
        vsb_cat(sb, "\n");
        vsb_cat(sb, "/* Backend related */\n");
@@ -471,6 +472,8 @@ vcl_output_lang_h(struct vsb *sb)
        vsb_cat(sb, "void VRT_l_req_proto(struct sess *, const char *);\n");
        vsb_cat(sb, "struct backend * VRT_r_req_backend(struct sess *);\n");
        vsb_cat(sb, "void VRT_l_req_backend(struct sess *, struct backend *);\n");
+       vsb_cat(sb, "const char * VRT_r_req_http_(struct sess *);\n");
+       vsb_cat(sb, "void VRT_l_req_http_(struct sess *, const char *);\n");
        vsb_cat(sb, "const char * VRT_r_req_hash(struct sess *);\n");
        vsb_cat(sb, "void VRT_l_req_hash(struct sess *, const char *);\n");
        vsb_cat(sb, "unsigned VRT_r_obj_valid(struct sess *);\n");
@@ -479,8 +482,6 @@ vcl_output_lang_h(struct vsb *sb)
        vsb_cat(sb, "void VRT_l_obj_cacheable(struct sess *, unsigned);\n");
        vsb_cat(sb, "double VRT_r_obj_ttl(struct sess *);\n");
        vsb_cat(sb, "void VRT_l_obj_ttl(struct sess *, double);\n");
-       vsb_cat(sb, "const char * VRT_r_req_http_(struct sess *);\n");
-       vsb_cat(sb, "void VRT_l_req_http_(struct sess *, const char *);\n");
        vsb_cat(sb, "const char * VRT_r_resp_http_(struct sess *);\n");
        vsb_cat(sb, "void VRT_l_resp_http_(struct sess *, const char *);\n");
 }
index f47bb54f70a895cf734e261deab4ed0efef1d5c2..c504d3c1f4b7d38fc20e75667251c7acf3f8af9d 100755 (executable)
 
 # Objects which operate on backends
 set beobj {
-       { backend.host          HOSTNAME        0 }
-       { backend.port          PORTNAME        0 }
-       { backend.dnsttl        TIME            0 }
+  { backend.host               HOSTNAME }
+  { backend.port               PORTNAME }
+  { backend.dnsttl     TIME     }
 }
 
 # Objects which operate on sessions
 
 set spobj {
-       { client.ip             IP              1
-           {recv pipe pass hash miss hit fetch}
-       }
-       { server.ip             IP              1
-           {recv pipe pass hash miss hit fetch}
-       }
-       { req.request           STRING          1
-           {recv pipe pass hash miss hit fetch}
-       }
-       { req.host              STRING          1
-           {recv pipe pass hash miss hit fetch}
-       }
-        { req.url              STRING          1
-           {recv pipe pass hash miss hit fetch}
-       }
-        { req.proto            STRING          1
-           {recv pipe pass hash miss hit fetch}
-       }
-        { req.backend          BACKEND         0
-           {recv pipe pass hash miss hit fetch}
-       }
-        { req.http.            HEADER          1
-           {recv pipe pass hash miss hit fetch}
-       }
-        { req.hash             HASH            0
-           {hash}
-       }
-        { obj.valid            BOOL            0
-           {hit fetch}
-       }
-        { obj.cacheable                BOOL            0
-           {hit fetch}
-       }
-        { obj.ttl              TIME            0
-           {hit fetch}
-       }
-        { resp.http.           HEADER          1
-           {fetch}
-       }
+  { 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.http.         HEADER  {                             fetch                } }
 }
 
 set tt(IP)     "struct sockaddr *"
@@ -131,8 +105,7 @@ proc vars {v ty pa} {
                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    [lindex $v 2], "
-               puts $fo  "\t    [method_map [lindex $v 3]]"
+               puts $fo  "\t    [method_map [lindex $v 2]]"
                puts $fo "\t\},"
 
                puts $fp  "$tt($t) VRT_r_${m}($ty);"
index 593e5388ebb98ea77d2a5b37713e45a07cca75c9..624950190cb23bbf3acbd3b1eb33f0695ca8c81c 100644 (file)
@@ -13,19 +13,16 @@ struct var vcc_be_vars[] = {
        { "backend.host", HOSTNAME, 12,
            "VRT_r_backend_host(backend)",
            "VRT_l_backend_host(backend, ",
-           0, 
            
        },
        { "backend.port", PORTNAME, 12,
            "VRT_r_backend_port(backend)",
            "VRT_l_backend_port(backend, ",
-           0, 
            
        },
        { "backend.dnsttl", TIME, 14,
            "VRT_r_backend_dnsttl(backend)",
            "VRT_l_backend_dnsttl(backend, ",
-           0, 
            
        },
        { NULL }
@@ -35,79 +32,66 @@ struct var vcc_vars[] = {
        { "client.ip", IP, 9,
            "VRT_r_client_ip(sp)",
            "VRT_l_client_ip(sp, ",
-           1, 
            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, ",
-           1, 
            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, ",
-           1, 
            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, ",
-           1, 
            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, ",
-           1, 
            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, ",
-           1, 
            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, ",
-           0, 
            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, ",
-           1, 
            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)",
            "VRT_l_req_hash(sp, ",
-           0, 
            VCL_MET_HASH
        },
        { "obj.valid", BOOL, 9,
            "VRT_r_obj_valid(sp)",
            "VRT_l_obj_valid(sp, ",
-           0, 
-           VCL_MET_HIT | VCL_MET_FETCH
+           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, ",
-           0, 
-           VCL_MET_HIT | VCL_MET_FETCH
+           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, ",
-           0, 
-           VCL_MET_HIT | VCL_MET_FETCH
+           VCL_MET_HIT | VCL_MET_FETCH | VCL_MET_DISCARD | VCL_MET_TIMEOUT
        },
        { "resp.http.", HEADER, 10,
            "VRT_r_resp_http_(sp)",
            "VRT_l_resp_http_(sp, ",
-           1, 
            VCL_MET_FETCH
        },
        { NULL }
index 9e6749c618c59bb8528ddd069ba144c30a1836a4..96b38eba9d2a916f6c7ecdbc139dc20a285c70b7 100644 (file)
@@ -56,12 +56,6 @@ vcc_StringVal(struct tokenlist *tl)
        vt = tl->t;
        vp = vcc_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);
@@ -82,8 +76,9 @@ static struct var *
 HeaderVar(struct tokenlist *tl, const struct token *t, const struct var *vh)
 {
        char *p;
+       const char *wh;
        struct var *v;
-       int i, w;
+       int i;
 
        (void)tl;
 
@@ -96,12 +91,14 @@ HeaderVar(struct tokenlist *tl, const struct token *t, const struct var *vh)
        p[i] = '\0';
        v->name = p;
        v->fmt = STRING;
-       v->has_string = vh->has_string;
+       v->methods = vh->methods;
        if (!memcmp(vh->name, "req.", 4))
-               w = 1;
+               wh = "HDR_REQ";
+       else if (!memcmp(vh->name, "resp.", 5))
+               wh = "HDR_RESP";
        else
-               w = 2;
-       asprintf(&p, "VRT_GetHdr(sp, %d, \"\\%03o%s:\")", w,
+               assert(0 == 1);
+       asprintf(&p, "VRT_GetHdr(sp, %s, \"\\%03o%s:\")", wh,
            (unsigned)(strlen(v->name + vh->len) + 1), v->name + vh->len);
        assert(p != NULL);
        v->rname = p;