]> err.no Git - varnish/commitdiff
More VRT work.
authorphk <phk@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Fri, 21 Jul 2006 21:13:43 +0000 (21:13 +0000)
committerphk <phk@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Fri, 21 Jul 2006 21:13:43 +0000 (21:13 +0000)
Use macros for trivial objects which are just a field in a struct.

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

varnish-cache/bin/varnishd/cache_vrt.c
varnish-cache/include/vrt_obj.h
varnish-cache/lib/libvcl/vcc_gen_obj.tcl
varnish-cache/lib/libvcl/vcc_obj.c

index 0d3596f3736cb3cd8ed2bf2a3fabdc864df734d6..6ed7b92e190c064fc6cfc8bbcedd5d6bdb26882b 100644 (file)
@@ -54,18 +54,6 @@ VRT_GetHdr(struct sess *sp, const char *n)
 
 /*--------------------------------------------------------------------*/
 
-char *
-VRT_GetReq(struct sess *sp)
-{
-
-       CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
-       assert(sp != NULL);
-       assert(sp->http != NULL);
-       return (sp->http->hd[HTTP_HDR_REQ].b);
-}
-
-/*--------------------------------------------------------------------*/
-
 void
 VRT_handling(struct sess *sp, unsigned hand)
 {
@@ -77,34 +65,6 @@ VRT_handling(struct sess *sp, unsigned hand)
 
 /*--------------------------------------------------------------------*/
 
-void
-VRT_l_backend_host(struct backend *be, const char *h)
-{
-       CHECK_OBJ_NOTNULL(be, BACKEND_MAGIC);
-       be->hostname = h;
-}
-
-const char *
-VRT_r_backend_host(struct backend *be)
-{
-       CHECK_OBJ_NOTNULL(be, BACKEND_MAGIC);
-       return (be->hostname);
-}
-
-void
-VRT_l_backend_port(struct backend *be, const char *p)
-{
-       CHECK_OBJ_NOTNULL(be, BACKEND_MAGIC);
-       be->portname = p;
-}
-
-const char *
-VRT_r_backend_port(struct backend *be)
-{
-       CHECK_OBJ_NOTNULL(be, BACKEND_MAGIC);
-       return (be->portname);
-}
-
 void
 VRT_set_backend_name(struct backend *be, const char *p)
 {
@@ -128,6 +88,26 @@ VRT_alloc_backends(struct VCL_conf *cp)
 
 /*--------------------------------------------------------------------*/
 
+#define VBACKEND(type,onm,field)                       \
+void                                                   \
+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)
+
+/*--------------------------------------------------------------------*/
+
 void
 VRT_l_obj_ttl(struct sess *sp, double a)
 {
@@ -144,40 +124,39 @@ VRT_r_obj_ttl(struct sess *sp)
        return (sp->obj->ttl - sp->t_req);
 }
 
-
-double
-VRT_r_obj_valid(struct sess *sp)
-{
-       CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
-       CHECK_OBJ_NOTNULL(sp->obj, OBJECT_MAGIC);       /* XXX */
-       return (sp->obj->valid);
-}
-
-
-double
-VRT_r_obj_cacheable(struct sess *sp)
-{
-       CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
-       CHECK_OBJ_NOTNULL(sp->obj, OBJECT_MAGIC);       /* XXX */
-       return (sp->obj->cacheable);
-}
-
 /*--------------------------------------------------------------------*/
 
-const char *
-VRT_r_req_request(struct sess *sp)
-{
-       CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
-       CHECK_OBJ_NOTNULL(sp->http, HTTP_MAGIC);
-       return (sp->http->hd[HTTP_HDR_REQ].b);
-}
+#define VOBJ(type,onm,field)                                           \
+void                                                                   \
+VRT_l_obj_##onm(struct sess *sp, type a)                               \
+{                                                                      \
+       CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);                              \
+       CHECK_OBJ_NOTNULL(sp->obj, OBJECT_MAGIC);       /* XXX */       \
+       sp->obj->field = a;                                             \
+}                                                                      \
+                                                                       \
+type                                                                   \
+VRT_r_obj_##onm(struct sess *sp)                                       \
+{                                                                      \
+       CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);                              \
+       CHECK_OBJ_NOTNULL(sp->obj, OBJECT_MAGIC);       /* XXX */       \
+       return (sp->obj->field);                                        \
+}
+
+VOBJ(double, valid, valid)
+VOBJ(double, cacheable, cacheable)
 
+/*--------------------------------------------------------------------*/
 
-const char *
-VRT_r_req_url(struct sess *sp)
-{
-       CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
-       CHECK_OBJ_NOTNULL(sp->http, HTTP_MAGIC);
-       return (sp->http->hd[HTTP_HDR_URL].b);
+#define  VREQ(n1, n2)                                  \
+const char *                                           \
+VRT_r_req_##n1(struct sess *sp)                                \
+{                                                      \
+       CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);              \
+       CHECK_OBJ_NOTNULL(sp->http, HTTP_MAGIC);        \
+       return (sp->http->hd[n2].b);                    \
 }
 
+VREQ(request, HTTP_HDR_REQ)
+VREQ(url, HTTP_HDR_URL)
+VREQ(proto, HTTP_HDR_PROTO)
index ad9fb96702e78b176ccb7311210914a22cc40cdf..98bc72afec1589e41c8705c2d84152a9fbebcb0e 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $Id: vcc_gen_obj.tcl 545 2006-07-21 20:43:56Z phk $
+ * $Id: vcc_gen_obj.tcl 548 2006-07-21 20:51:24Z phk $
  *
  * NB:  This file is machine generated, DO NOT EDIT!
  *
@@ -14,6 +14,8 @@ const char * VRT_r_req_request(struct sess *);
 void VRT_l_req_request(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 *);
 double VRT_r_obj_valid(struct sess *);
 void VRT_l_obj_valid(struct sess *, double);
 double VRT_r_obj_cacheable(struct sess *);
index 41ad625117c0f8391381719c2b884f93bba2ef73..963c3e43f0aa5773fa08045746a51a0829a57a25 100755 (executable)
@@ -14,6 +14,7 @@ set beobj {
 set spobj {
        { req.request   STRING }
         { req.url      STRING }
+        { req.proto    STRING }
         { obj.valid    BOOL }
         { obj.cacheable        BOOL }
         { obj.backend  BACKEND }
index 7ae798544b800b356e10644e1f277258712fdf20..1a169d18dbceaba853bf5b30746510413aff3518 100644 (file)
@@ -30,6 +30,10 @@ struct var vcc_vars[] = {
            "VRT_r_req_url(sp)",
            "VRT_l_req_url(sp, ",
        },
+       { "req.proto", STRING, 9,
+           "VRT_r_req_proto(sp)",
+           "VRT_l_req_proto(sp, ",
+       },
        { "obj.valid", BOOL, 9,
            "VRT_r_obj_valid(sp)",
            "VRT_l_obj_valid(sp, ",
@@ -70,6 +74,8 @@ const char *vrt_obj_h =
        "void VRT_l_req_request(struct sess *, const char *);\n"
        "const char * VRT_r_req_url(struct sess *);\n"
        "void VRT_l_req_url(struct sess *, const char *);\n"
+       "const char * VRT_r_req_proto(struct sess *);\n"
+       "void VRT_l_req_proto(struct sess *, const char *);\n"
        "double VRT_r_obj_valid(struct sess *);\n"
        "void VRT_l_obj_valid(struct sess *, double);\n"
        "double VRT_r_obj_cacheable(struct sess *);\n"