From 4c1027702661412b9828cbb521fc589b2316f9f9 Mon Sep 17 00:00:00 2001 From: phk Date: Fri, 21 Jul 2006 21:13:43 +0000 Subject: [PATCH] More VRT work. 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 | 121 ++++++++++------------- varnish-cache/include/vrt_obj.h | 4 +- varnish-cache/lib/libvcl/vcc_gen_obj.tcl | 1 + varnish-cache/lib/libvcl/vcc_obj.c | 6 ++ 4 files changed, 60 insertions(+), 72 deletions(-) diff --git a/varnish-cache/bin/varnishd/cache_vrt.c b/varnish-cache/bin/varnishd/cache_vrt.c index 0d3596f3..6ed7b92e 100644 --- a/varnish-cache/bin/varnishd/cache_vrt.c +++ b/varnish-cache/bin/varnishd/cache_vrt.c @@ -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) diff --git a/varnish-cache/include/vrt_obj.h b/varnish-cache/include/vrt_obj.h index ad9fb967..98bc72af 100644 --- a/varnish-cache/include/vrt_obj.h +++ b/varnish-cache/include/vrt_obj.h @@ -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 *); diff --git a/varnish-cache/lib/libvcl/vcc_gen_obj.tcl b/varnish-cache/lib/libvcl/vcc_gen_obj.tcl index 41ad6251..963c3e43 100755 --- a/varnish-cache/lib/libvcl/vcc_gen_obj.tcl +++ b/varnish-cache/lib/libvcl/vcc_gen_obj.tcl @@ -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 } diff --git a/varnish-cache/lib/libvcl/vcc_obj.c b/varnish-cache/lib/libvcl/vcc_obj.c index 7ae79854..1a169d18 100644 --- a/varnish-cache/lib/libvcl/vcc_obj.c +++ b/varnish-cache/lib/libvcl/vcc_obj.c @@ -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" -- 2.39.5