]> err.no Git - varnish/commitdiff
Mark variables/objects as having a string representation or not
authorphk <phk@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Wed, 9 May 2007 11:07:59 +0000 (11:07 +0000)
committerphk <phk@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Wed, 9 May 2007 11:07:59 +0000 (11:07 +0000)
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: svn+ssh://projects.linpro.no/svn/varnish/trunk@1395 d4fa192b-c00b-0410-8231-f00ffab90ce4

varnish-cache/include/vrt_obj.h
varnish-cache/lib/libvcl/vcc_action.c
varnish-cache/lib/libvcl/vcc_compile.c
varnish-cache/lib/libvcl/vcc_compile.h
varnish-cache/lib/libvcl/vcc_gen_obj.tcl
varnish-cache/lib/libvcl/vcc_obj.c

index 9eba3c0d5cffddf52fb83353daecf0c55b82e391..f11e783270cfb71249b99e543a5639514d1bf32d 100644 (file)
@@ -26,6 +26,8 @@ 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 *);
+int VRT_r_req_hash(struct sess *);
+void VRT_l_req_hash(struct sess *, int);
 double VRT_r_obj_valid(struct sess *);
 void VRT_l_obj_valid(struct sess *, double);
 double VRT_r_obj_cacheable(struct sess *);
index 1990fe7302d8448e341c3d74e2c083efe1477f87..0ef6f01bdfa3bebdc6f1e9fcd93c77778b930861 100644 (file)
 #include "vcc_compile.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)
                    " only '=' is legal for backend\n");
                vcc_ErrWhere(tl, tl->t);
                return;
+       case HASH:
+               ExpectErr(tl, T_INCR);
+               vcc_NextToken(tl);
+               StringVal(tl);
+               Fb(tl, 0, ");\n");
+               return;
        default:
                vsb_printf(tl->sb,
                    "Assignments not possible for '%s'\n", vp->name);
index f012e098c278031e034f68729173f442eac972e7..fe03689435956144c6c7962e83e03fc417dcab50 100644 (file)
@@ -252,6 +252,7 @@ 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;
        if (!memcmp(vh->name, "req.", 4))
                w = 1;
        else
index 563b351c1a7a2148fe4cf4cbb457bebbc4f3d0d6..a43287f85873d7fddfdb62324fa4e1b5b53bbea1 100644 (file)
@@ -96,6 +96,7 @@ enum var_type {
        IP,
        HOSTNAME,
        PORTNAME,
+       HASH,
        HEADER
 };
 
@@ -119,6 +120,7 @@ struct var {
        unsigned                len;
        const char              *rname;
        const char              *lname;
+       unsigned                has_string;
 };
 
 struct method {
index b25116949bfc3d80218d05a5c479c29b96a8cfb4..4a84a86b6104614496aa0ac54461bf9908547c99 100755 (executable)
 
 # Objects which operate on backends
 set beobj {
-       { backend.host          HOSTNAME }
-       { backend.port          PORTNAME }
-       { backend.dnsttl        TIME }
+       { backend.host          HOSTNAME        0 }
+       { backend.port          PORTNAME        0 }
+       { backend.dnsttl        TIME            0 }
 }
 
 # Objects which operate on sessions
 
 set spobj {
-       { client.ip             IP }
-       { server.ip             IP }
-       { req.request           STRING }
-       { req.host              STRING }
-        { req.url              STRING }
-        { req.proto            STRING }
-        { req.backend          BACKEND }
-        { obj.valid            BOOL }
-        { obj.cacheable                BOOL }
-        { obj.ttl              TIME }
-        { req.http.            HEADER }
-        { resp.http.           HEADER }
+       { client.ip             IP              1}
+       { server.ip             IP              1}
+       { req.request           STRING          1}
+       { req.host              STRING          1}
+        { req.url              STRING          1}
+        { req.proto            STRING          1}
+        { req.backend          BACKEND         0}
+        { req.hash             HASH            0}
+        { obj.valid            BOOL            0}
+        { obj.cacheable                BOOL            0}
+        { obj.ttl              TIME            0}
+        { req.http.            HEADER          1}
+        { resp.http.           HEADER          1}
 }
 
 set tt(IP)     "struct sockaddr *"
@@ -62,6 +63,7 @@ set tt(TIME)  "double"
 set tt(HEADER) "const char *"
 set tt(HOSTNAME) "const char *"
 set tt(PORTNAME) "const char *"
+set tt(HASH)   "int"
 
 #----------------------------------------------------------------------
 # Boilerplate warning for all generated files.
@@ -93,6 +95,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\},"
 
                puts $fp  "$tt($t) VRT_r_${m}($ty);"
index ce244d32b8ce7c51069a0f82b1faba9f4b2d7e11..d5a74953cd778829b40bad705afaafca8c629e54 100644 (file)
@@ -13,14 +13,17 @@ 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 }
 };
@@ -29,50 +32,67 @@ struct var vcc_vars[] = {
        { "client.ip", IP, 9,
            "VRT_r_client_ip(sp)",
            "VRT_l_client_ip(sp, ",
+           1
        },
        { "server.ip", IP, 9,
            "VRT_r_server_ip(sp)",
            "VRT_l_server_ip(sp, ",
+           1
        },
        { "req.request", STRING, 11,
            "VRT_r_req_request(sp)",
            "VRT_l_req_request(sp, ",
+           1
        },
        { "req.host", STRING, 8,
            "VRT_r_req_host(sp)",
            "VRT_l_req_host(sp, ",
+           1
        },
        { "req.url", STRING, 7,
            "VRT_r_req_url(sp)",
            "VRT_l_req_url(sp, ",
+           1
        },
        { "req.proto", STRING, 9,
            "VRT_r_req_proto(sp)",
            "VRT_l_req_proto(sp, ",
+           1
        },
        { "req.backend", BACKEND, 11,
            "VRT_r_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,
            "VRT_r_obj_valid(sp)",
            "VRT_l_obj_valid(sp, ",
+           0
        },
        { "obj.cacheable", BOOL, 13,
            "VRT_r_obj_cacheable(sp)",
            "VRT_l_obj_cacheable(sp, ",
+           0
        },
        { "obj.ttl", TIME, 7,
            "VRT_r_obj_ttl(sp)",
            "VRT_l_obj_ttl(sp, ",
+           0
        },
        { "req.http.", HEADER, 9,
            "VRT_r_req_http_(sp)",
            "VRT_l_req_http_(sp, ",
+           1
        },
        { "resp.http.", HEADER, 10,
            "VRT_r_resp_http_(sp)",
            "VRT_l_resp_http_(sp, ",
+           1
        },
        { NULL }
 };