[master] a9d4a49 Wrap a structure around fetch filters, and move the filter API to a separate #include file.

Poul-Henning Kamp phk at FreeBSD.org
Wed Jul 2 23:04:22 CEST 2014


commit a9d4a4978a2bf7fe42b75d13d63b7a2da9faf0ac
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Wed Jul 2 21:03:50 2014 +0000

    Wrap a structure around fetch filters, and move the filter
    API to a separate #include file.

diff --git a/bin/varnishd/Makefile.am b/bin/varnishd/Makefile.am
index 402cd0d..bcfe989 100644
--- a/bin/varnishd/Makefile.am
+++ b/bin/varnishd/Makefile.am
@@ -103,6 +103,7 @@ noinst_HEADERS = \
 pkgdataincludedir = $(pkgdatadir)/include
 nobase_pkgdatainclude_HEADERS = \
 	cache/cache.h \
+	cache/cache_filter.h \
 	cache/cache_backend.h \
 	common/common.h \
 	common/params.h
diff --git a/bin/varnishd/cache/cache.h b/bin/varnishd/cache/cache.h
index 038510d..b9e13fa 100644
--- a/bin/varnishd/cache/cache.h
+++ b/bin/varnishd/cache/cache.h
@@ -36,6 +36,7 @@
 
 #include "common/common.h"
 
+#include "cache/cache_filter.h"
 #include "vapi/vsl_int.h"
 
 #include <sys/socket.h>
@@ -253,32 +254,6 @@ struct dstat {
 #undef L0
 #undef L1
 
-/* Fetch processors --------------------------------------------------*/
-
-enum vfp_status {
-	VFP_ERROR = -1,
-	VFP_OK = 0,
-	VFP_END = 1,
-};
-typedef enum vfp_status
-    vfp_pull_f(struct busyobj *bo, void *p, ssize_t *len, intptr_t *priv);
-
-extern vfp_pull_f vfp_gunzip_pull;
-extern vfp_pull_f vfp_gzip_pull;
-extern vfp_pull_f vfp_testgunzip_pull;
-extern vfp_pull_f vfp_esi_pull;
-extern vfp_pull_f vfp_esi_gzip_pull;
-
-/* Deliver processors ------------------------------------------------*/
-
-enum vdp_action {
-	VDP_NULL,
-	VDP_FLUSH,
-	VDP_FINISH,
-};
-typedef int vdp_bytes(struct req *, enum vdp_action, const void *ptr,
-    ssize_t len);
-
 /*--------------------------------------------------------------------*/
 
 struct exp {
@@ -487,7 +462,7 @@ struct busyobj {
 	uint8_t			*vary;
 
 #define N_VFPS			5
-	vfp_pull_f		*vfps[N_VFPS];
+	const struct vfp	*vfps[N_VFPS];
 	intptr_t		vfps_priv[N_VFPS];
 	int			vfp_nxt;
 
@@ -901,7 +876,7 @@ enum vfp_status VFP_Error(struct busyobj *, const char *fmt, ...)
     __printflike(2, 3);
 void VFP_Init(void);
 void VFP_Fetch_Body(struct busyobj *bo, ssize_t est);
-void VFP_Push(struct busyobj *, vfp_pull_f *func, intptr_t priv);
+void VFP_Push(struct busyobj *, const struct vfp *, intptr_t priv);
 enum vfp_status VFP_Suck(struct busyobj *, void *p, ssize_t *lp);
 extern char vfp_init[];
 extern char vfp_fini[];
diff --git a/bin/varnishd/cache/cache_esi_fetch.c b/bin/varnishd/cache/cache_esi_fetch.c
index 41bea3b..9424399 100644
--- a/bin/varnishd/cache/cache_esi_fetch.c
+++ b/bin/varnishd/cache/cache_esi_fetch.c
@@ -141,7 +141,7 @@ vfp_esi_end(struct busyobj *bo, struct vef_priv *vef, enum vfp_status retval)
 	return (retval);
 }
 
-enum vfp_status __match_proto__(vfp_pull_f)
+static enum vfp_status __match_proto__(vfp_pull_f)
 vfp_esi_gzip_pull(struct busyobj *bo, void *p, ssize_t *lp, intptr_t *priv)
 {
 	enum vfp_status vp;
@@ -202,7 +202,7 @@ vfp_esi_gzip_pull(struct busyobj *bo, void *p, ssize_t *lp, intptr_t *priv)
 	return (vp);
 }
 
-enum vfp_status __match_proto__(vfp_pull_f)
+static enum vfp_status __match_proto__(vfp_pull_f)
 vfp_esi_pull(struct busyobj *bo, void *p, ssize_t *lp, intptr_t *priv)
 {
 	enum vfp_status vp;
@@ -241,3 +241,11 @@ vfp_esi_pull(struct busyobj *bo, void *p, ssize_t *lp, intptr_t *priv)
 	}
 	return (vp);
 }
+
+const struct vfp vfp_esi = {
+	.pull = vfp_esi_pull,
+};
+
+const struct vfp vfp_esi_gzip = {
+	.pull = vfp_esi_gzip_pull,
+};
diff --git a/bin/varnishd/cache/cache_fetch.c b/bin/varnishd/cache/cache_fetch.c
index 0980c64..b2665e2 100644
--- a/bin/varnishd/cache/cache_fetch.c
+++ b/bin/varnishd/cache/cache_fetch.c
@@ -468,22 +468,22 @@ vbf_stp_fetch(struct worker *wrk, struct busyobj *bo)
 
 	if (bo->do_gunzip || (bo->is_gzip && bo->do_esi)) {
 		RFC2616_Weaken_Etag(bo->beresp);
-		VFP_Push(bo, vfp_gunzip_pull, 0);
+		VFP_Push(bo, &vfp_gunzip, 0);
 	}
 
 	if (bo->do_esi && bo->do_gzip) {
-		VFP_Push(bo, vfp_esi_gzip_pull, 0);
+		VFP_Push(bo, &vfp_esi_gzip, 0);
 		RFC2616_Weaken_Etag(bo->beresp);
 	} else if (bo->do_esi && bo->is_gzip && !bo->do_gunzip) {
-		VFP_Push(bo, vfp_esi_gzip_pull, 0);
+		VFP_Push(bo, &vfp_esi_gzip, 0);
 		RFC2616_Weaken_Etag(bo->beresp);
 	} else if (bo->do_esi) {
-		VFP_Push(bo, vfp_esi_pull, 0);
+		VFP_Push(bo, &vfp_esi, 0);
 	} else if (bo->do_gzip) {
-		VFP_Push(bo, vfp_gzip_pull, 0);
+		VFP_Push(bo, &vfp_gzip, 0);
 		RFC2616_Weaken_Etag(bo->beresp);
 	} else if (bo->is_gzip && !bo->do_gunzip) {
-		VFP_Push(bo, vfp_testgunzip_pull, 0);
+		VFP_Push(bo, &vfp_testgunzip, 0);
 	}
 
 	if (bo->fetch_objcore->flags & OC_F_PRIVATE)
diff --git a/bin/varnishd/cache/cache_fetch_proc.c b/bin/varnishd/cache/cache_fetch_proc.c
index 0666c45..7e1b30b 100644
--- a/bin/varnishd/cache/cache_fetch_proc.c
+++ b/bin/varnishd/cache/cache_fetch_proc.c
@@ -114,8 +114,8 @@ VFP_GetStorage(struct busyobj *bo, ssize_t sz)
 static enum vfp_status
 vfp_call(struct busyobj *bo, int nbr, void *p, ssize_t *lp)
 {
-	AN(bo->vfps[nbr]);
-	return (bo->vfps[nbr](bo, p, lp, &bo->vfps_priv[nbr]));
+	AN(bo->vfps[nbr]->pull);
+	return (bo->vfps[nbr]->pull(bo, p, lp, &bo->vfps_priv[nbr]));
 }
 
 static void
@@ -250,12 +250,12 @@ VFP_Fetch_Body(struct busyobj *bo, ssize_t est)
 }
 
 void
-VFP_Push(struct busyobj *bo, vfp_pull_f *func, intptr_t priv)
+VFP_Push(struct busyobj *bo, const struct vfp *vfp, intptr_t priv)
 {
 
 	CHECK_OBJ_NOTNULL(bo, BUSYOBJ_MAGIC);
 	bo->vfps_priv[bo->vfp_nxt] = priv;
-	bo->vfps[bo->vfp_nxt] = func;
+	bo->vfps[bo->vfp_nxt] = vfp;
 	bo->vfp_nxt++;
 }
 
diff --git a/bin/varnishd/cache/cache_filter.h b/bin/varnishd/cache/cache_filter.h
new file mode 100644
index 0000000..d2b0cf1
--- /dev/null
+++ b/bin/varnishd/cache/cache_filter.h
@@ -0,0 +1,62 @@
+/*-
+ * Copyright (c) 2013-2014 Varnish Software AS
+ * All rights reserved.
+ *
+ * Author: Poul-Henning Kamp <phk at phk.freebsd.dk>
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ */
+
+struct busyobj;
+struct req;
+
+/* Fetch processors --------------------------------------------------*/
+
+enum vfp_status {
+	VFP_ERROR = -1,
+	VFP_OK = 0,
+	VFP_END = 1,
+};
+typedef enum vfp_status
+    vfp_pull_f(struct busyobj *bo, void *p, ssize_t *len, intptr_t *priv);
+
+struct vfp {
+	vfp_pull_f	*pull;
+};
+
+extern const struct vfp vfp_gunzip;
+extern const struct vfp vfp_gzip;
+extern const struct vfp vfp_testgunzip;
+extern const struct vfp vfp_esi;
+extern const struct vfp vfp_esi_gzip;
+
+
+/* Deliver processors ------------------------------------------------*/
+
+enum vdp_action {
+	VDP_NULL,
+	VDP_FLUSH,
+	VDP_FINISH,
+};
+typedef int vdp_bytes(struct req *, enum vdp_action, const void *ptr,
+    ssize_t len);
diff --git a/bin/varnishd/cache/cache_gzip.c b/bin/varnishd/cache/cache_gzip.c
index bdbf229..2e3528b 100644
--- a/bin/varnishd/cache/cache_gzip.c
+++ b/bin/varnishd/cache/cache_gzip.c
@@ -450,7 +450,7 @@ VGZ_Destroy(struct vgz **vgp)
  * A VFP for gunzip'ing an object as we receive it from the backend
  */
 
-enum vfp_status __match_proto__(vfp_pull_f)
+static enum vfp_status __match_proto__(vfp_pull_f)
 vfp_gunzip_pull(struct busyobj *bo, void *p, ssize_t *lp, intptr_t *priv)
 {
         ssize_t l;
@@ -513,13 +513,18 @@ vfp_gunzip_pull(struct busyobj *bo, void *p, ssize_t *lp, intptr_t *priv)
 	return (vp);
 }
 
+const struct vfp vfp_gunzip = {
+	.pull = vfp_gunzip_pull,
+};
+
+
 /*--------------------------------------------------------------------
  * VFP_GZIP
  *
  * A VFP for gzip'ing an object as we receive it from the backend
  */
 
-enum vfp_status __match_proto__(vfp_pull_f)
+static enum vfp_status __match_proto__(vfp_pull_f)
 vfp_gzip_pull(struct busyobj *bo, void *p, ssize_t *lp, intptr_t *priv)
 {
         ssize_t l;
@@ -583,6 +588,10 @@ vfp_gzip_pull(struct busyobj *bo, void *p, ssize_t *lp, intptr_t *priv)
 	return (VFP_END);
 }
 
+const struct vfp vfp_gzip = {
+	.pull = vfp_gzip_pull,
+};
+
 /*--------------------------------------------------------------------
  * VFP_TESTGZIP
  *
@@ -590,7 +599,7 @@ vfp_gzip_pull(struct busyobj *bo, void *p, ssize_t *lp, intptr_t *priv)
  * collecting the magic bits while we're at it.
  */
 
-enum vfp_status __match_proto__(vfp_pull_f)
+static enum vfp_status __match_proto__(vfp_pull_f)
 vfp_testgunzip_pull(struct busyobj *bo, void *p, ssize_t *lp, intptr_t *priv)
 {
 	struct vgz *vg;
@@ -641,3 +650,7 @@ vfp_testgunzip_pull(struct busyobj *bo, void *p, ssize_t *lp, intptr_t *priv)
 	}
 	return (vp);
 }
+
+const struct vfp vfp_testgunzip = {
+	.pull = vfp_testgunzip_pull,
+};
diff --git a/bin/varnishd/cache/cache_http1_fetch.c b/bin/varnishd/cache/cache_http1_fetch.c
index b6d72dd..65c2591 100644
--- a/bin/varnishd/cache/cache_http1_fetch.c
+++ b/bin/varnishd/cache/cache_http1_fetch.c
@@ -100,6 +100,10 @@ v1f_pull_straight(struct busyobj *bo, void *p, ssize_t *lp, intptr_t *priv)
 	return (VFP_OK);
 }
 
+static const struct vfp v1f_straight = {
+	.pull = v1f_pull_straight,
+};
+
 /*--------------------------------------------------------------------
  * Read a chunked HTTP object.
  *
@@ -133,6 +137,10 @@ v1f_pull_chunked(struct busyobj *bo, void *p, ssize_t *lp, intptr_t *priv)
 	}
 }
 
+static const struct vfp v1f_chunked = {
+	.pull = v1f_pull_chunked,
+};
+
 /*--------------------------------------------------------------------*/
 
 static enum vfp_status __match_proto__(vfp_pull_f)
@@ -160,6 +168,11 @@ v1f_pull_eof(struct busyobj *bo, void *p, ssize_t *lp, intptr_t *priv)
 	return (VFP_OK);
 }
 
+static const struct vfp v1f_eof = {
+	.pull = v1f_pull_eof,
+};
+
+
 /*--------------------------------------------------------------------
  */
 
@@ -176,14 +189,14 @@ V1F_Setup_Fetch(struct busyobj *bo)
 
 	switch(htc->body_status) {
 	case BS_EOF:
-		VFP_Push(bo, v1f_pull_eof, 0);
+		VFP_Push(bo, &v1f_eof, 0);
 		return(-1);
 	case BS_LENGTH:
 		cl = vbf_fetch_number(bo->h_content_length, 10);
-		VFP_Push(bo, v1f_pull_straight, cl);
+		VFP_Push(bo, &v1f_straight, cl);
 		return (cl);
 	case BS_CHUNKED:
-		VFP_Push(bo, v1f_pull_chunked, -1);
+		VFP_Push(bo, &v1f_chunked, -1);
 		return (-1);
 	default:
 		break;



More information about the varnish-commit mailing list