[master] 716a307 We will have to maintain the filter list per VCL, so move the stuff there.

Poul-Henning Kamp phk at FreeBSD.org
Thu Apr 19 12:45:19 UTC 2018


commit 716a307a750b3c2297984187b3ed1094ff94d50a
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Thu Apr 19 11:47:12 2018 +0000

    We will have to maintain the filter list per VCL, so move the
    stuff there.

diff --git a/bin/varnishd/cache/cache_fetch_proc.c b/bin/varnishd/cache/cache_fetch_proc.c
index 5c5e94a..78f6055 100644
--- a/bin/varnishd/cache/cache_fetch_proc.c
+++ b/bin/varnishd/cache/cache_fetch_proc.c
@@ -224,81 +224,6 @@ VFP_Push(struct vfp_ctx *vc, const struct vfp *vfp)
 }
 
 /*--------------------------------------------------------------------
- */
-
-struct vfp_filter {
-	unsigned			magic;
-#define VFP_FILTER_MAGIC		0xd40894e9
-	const struct vfp		*filter;
-	int				nlen;
-	VTAILQ_ENTRY(vfp_filter)	list;
-};
-
-static VTAILQ_HEAD(,vfp_filter) vfp_filters =
-    VTAILQ_HEAD_INITIALIZER(vfp_filters);
-
-void
-VFP_AddFilter(const struct vfp *filter)
-{
-	struct vfp_filter *vp;
-
-	VTAILQ_FOREACH(vp, &vfp_filters, list) {
-		assert(vp->filter != filter);
-		assert(strcasecmp(vp->filter->name, filter->name));
-	}
-	ALLOC_OBJ(vp, VFP_FILTER_MAGIC);
-	AN(vp);
-	vp->filter = filter;
-	vp->nlen = strlen(filter->name);
-	VTAILQ_INSERT_TAIL(&vfp_filters, vp, list);
-}
-
-void
-VFP_RemoveFilter(const struct vfp *filter)
-{
-	struct vfp_filter *vp;
-
-	VTAILQ_FOREACH(vp, &vfp_filters, list) {
-		if (vp->filter == filter)
-			break;
-	}
-	AN(vp);
-	VTAILQ_REMOVE(&vfp_filters, vp, list);
-	FREE_OBJ(vp);
-}
-
-int
-VFP_FilterList(struct vfp_ctx *vc, const char *fl)
-{
-	const char *p, *q;
-	const struct vfp_filter *vp;
-
-	VSLb(vc->wrk->vsl, SLT_Filters, "%s", fl);
-
-	for (p = fl; *p; p = q) {
-		if (vct_isspace(*p)) {
-			q = p + 1;
-			continue;
-		}
-		for (q = p; *q; q++)
-			if (vct_isspace(*q))
-				break;
-		VTAILQ_FOREACH(vp, &vfp_filters, list) {
-			if (vp->nlen != q - p)
-				continue;
-			if (!memcmp(p, vp->filter->name, vp->nlen))
-				break;
-		}
-		if (vp == NULL)
-			return (VFP_Error(vc,
-			    "Filter '%.*s' not found", (int)(q-p), p));
-		if (VFP_Push(vc, vp->filter) == NULL)
-			return (-1);
-	}
-	return (0);
-}
-
-/*--------------------------------------------------------------------
  * Debugging aids
  */
 
@@ -324,9 +249,4 @@ VFP_Init(void)
 {
 
 	CLI_AddFuncs(debug_cmds);
-	VFP_AddFilter(&VFP_testgunzip);
-	VFP_AddFilter(&VFP_gunzip);
-	VFP_AddFilter(&VFP_gzip);
-	VFP_AddFilter(&VFP_esi);
-	VFP_AddFilter(&VFP_esi_gzip);
 }
diff --git a/bin/varnishd/cache/cache_filter.h b/bin/varnishd/cache/cache_filter.h
index 924782e..65a0e65 100644
--- a/bin/varnishd/cache/cache_filter.h
+++ b/bin/varnishd/cache/cache_filter.h
@@ -89,8 +89,8 @@ enum vfp_status VFP_Suck(struct vfp_ctx *, void *p, ssize_t *lp);
 enum vfp_status VFP_Error(struct vfp_ctx *, const char *fmt, ...)
     v_printflike_(2, 3);
 int VFP_FilterList(struct vfp_ctx *, const char *);
-void VFP_AddFilter(const struct vfp *);
-void VFP_RemoveFilter(const struct vfp *);
+void VFP_AddFilter(struct vcl *, const struct vfp *);
+void VFP_RemoveFilter(struct vcl *, const struct vfp *);
 
 /* Deliver processors ------------------------------------------------*/
 
diff --git a/bin/varnishd/cache/cache_main.c b/bin/varnishd/cache/cache_main.c
index c77cca9..bfc76b4 100644
--- a/bin/varnishd/cache/cache_main.c
+++ b/bin/varnishd/cache/cache_main.c
@@ -351,6 +351,7 @@ child_main(int sigmagic, size_t altstksz)
 	ObjInit();
 
 	VCL_Init();
+	VCL_VRT_Init();
 
 	HTTP_Init();
 
diff --git a/bin/varnishd/cache/cache_varnishd.h b/bin/varnishd/cache/cache_varnishd.h
index 397703a..072c526 100644
--- a/bin/varnishd/cache/cache_varnishd.h
+++ b/bin/varnishd/cache/cache_varnishd.h
@@ -405,6 +405,9 @@ typedef int vcl_be_func(struct cli *, struct director *, void *);
 
 int VCL_IterDirector(struct cli *, const char *, vcl_be_func *, void *);
 
+/* cache_vcl_vrt.c */
+void VCL_VRT_Init(void);
+
 /* cache_vrt.c */
 void VRTPRIV_init(struct vrt_privs *privs);
 void VRTPRIV_dynamic_kill(struct vrt_privs *privs, uintptr_t id);
diff --git a/bin/varnishd/cache/cache_vcl.c b/bin/varnishd/cache/cache_vcl.c
index abc519f..c4d9ae1 100644
--- a/bin/varnishd/cache/cache_vcl.c
+++ b/bin/varnishd/cache/cache_vcl.c
@@ -526,6 +526,7 @@ vcl_load(struct cli *cli, struct vrt_ctx *ctx,
 	XXXAN(vcl->loaded_name);
 	VTAILQ_INIT(&vcl->director_list);
 	VTAILQ_INIT(&vcl->ref_list);
+	VTAILQ_INIT(&vcl->vfps);
 
 	vcl->temp = VCL_TEMP_INIT;
 
diff --git a/bin/varnishd/cache/cache_vcl.h b/bin/varnishd/cache/cache_vcl.h
index 87433af..f0789a8 100644
--- a/bin/varnishd/cache/cache_vcl.h
+++ b/bin/varnishd/cache/cache_vcl.h
@@ -26,8 +26,15 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
+ * NB: This is a private .h file for cache_vcl*.c
+ * NB: No other code should include this file.
+ *
  */
 
+struct vfp_filter;
+
+VTAILQ_HEAD(vfp_filter_head, vfp_filter);
+
 struct vcl {
 	unsigned		magic;
 #define VCL_MAGIC		0x214188f2
@@ -45,6 +52,7 @@ struct vcl {
 	int			nrefs;
 	struct vcl		*label;
 	int			nlabels;
+	struct vfp_filter_head	vfps;
 };
 
 struct vclref {
diff --git a/bin/varnishd/cache/cache_vcl_vrt.c b/bin/varnishd/cache/cache_vcl_vrt.c
index 484c14b..9c8e823 100644
--- a/bin/varnishd/cache/cache_vcl_vrt.c
+++ b/bin/varnishd/cache/cache_vcl_vrt.c
@@ -37,9 +37,11 @@
 #include "cache_varnishd.h"
 
 #include "vcl.h"
+#include "vct.h"
 
 #include "cache_director.h"
 #include "cache_vcl.h"
+#include "cache_filter.h"
 
 /*--------------------------------------------------------------------*/
 
@@ -413,3 +415,98 @@ VCL_##func##_method(struct vcl *vcl, struct worker *wrk,		\
 }
 
 #include "tbl/vcl_returns.h"
+
+/*--------------------------------------------------------------------
+ */
+
+struct vfp_filter {
+	unsigned			magic;
+#define VFP_FILTER_MAGIC		0xd40894e9
+	const struct vfp		*filter;
+	int				nlen;
+	VTAILQ_ENTRY(vfp_filter)	list;
+};
+
+static struct vfp_filter_head vfp_filters =
+    VTAILQ_HEAD_INITIALIZER(vfp_filters);
+
+void
+VFP_AddFilter(struct vcl *vcl, const struct vfp *filter)
+{
+	struct vfp_filter *vp;
+	struct vfp_filter_head *hd = &vfp_filters;
+
+	VTAILQ_FOREACH(vp, hd, list) {
+		xxxassert(vp->filter != filter);
+		xxxassert(strcasecmp(vp->filter->name, filter->name));
+	}
+	if (vcl != NULL) {
+		hd = &vcl->vfps;
+		VTAILQ_FOREACH(vp, hd, list) {
+			xxxassert(vp->filter != filter);
+			xxxassert(strcasecmp(vp->filter->name, filter->name));
+		}
+	}
+	ALLOC_OBJ(vp, VFP_FILTER_MAGIC);
+	AN(vp);
+	vp->filter = filter;
+	vp->nlen = strlen(filter->name);
+	VTAILQ_INSERT_TAIL(hd, vp, list);
+}
+
+void
+VFP_RemoveFilter(struct vcl *vcl, const struct vfp *filter)
+{
+	struct vfp_filter *vp;
+	struct vfp_filter_head *hd = &vcl->vfps;
+
+	AN(vcl);
+	VTAILQ_FOREACH(vp, hd, list) {
+		if (vp->filter == filter)
+			break;
+	}
+	XXXAN(vp);
+	VTAILQ_REMOVE(hd, vp, list);
+	FREE_OBJ(vp);
+}
+
+int
+VFP_FilterList(struct vfp_ctx *vc, const char *fl)
+{
+	const char *p, *q;
+	const struct vfp_filter *vp;
+
+	VSLb(vc->wrk->vsl, SLT_Filters, "%s", fl);
+
+	for (p = fl; *p; p = q) {
+		if (vct_isspace(*p)) {
+			q = p + 1;
+			continue;
+		}
+		for (q = p; *q; q++)
+			if (vct_isspace(*q))
+				break;
+		VTAILQ_FOREACH(vp, &vfp_filters, list) {
+			if (vp->nlen != q - p)
+				continue;
+			if (!memcmp(p, vp->filter->name, vp->nlen))
+				break;
+		}
+		if (vp == NULL)
+			return (VFP_Error(vc,
+			    "Filter '%.*s' not found", (int)(q-p), p));
+		if (VFP_Push(vc, vp->filter) == NULL)
+			return (-1);
+	}
+	return (0);
+}
+
+void
+VCL_VRT_Init(void)
+{
+	VFP_AddFilter(NULL, &VFP_testgunzip);
+	VFP_AddFilter(NULL, &VFP_gunzip);
+	VFP_AddFilter(NULL, &VFP_gzip);
+	VFP_AddFilter(NULL, &VFP_esi);
+	VFP_AddFilter(NULL, &VFP_esi_gzip);
+}


More information about the varnish-commit mailing list