[master] af71e47 Add an internal API to register/remove a VFP

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


commit af71e4796a6ab513c3d0820abbb575dbe0d7ae25
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Wed Apr 18 20:39:15 2018 +0000

    Add an internal API to register/remove a VFP

diff --git a/bin/varnishd/cache/cache_fetch_proc.c b/bin/varnishd/cache/cache_fetch_proc.c
index 667c713..5c5e94a 100644
--- a/bin/varnishd/cache/cache_fetch_proc.c
+++ b/bin/varnishd/cache/cache_fetch_proc.c
@@ -226,21 +226,52 @@ VFP_Push(struct vfp_ctx *vc, const struct vfp *vfp)
 /*--------------------------------------------------------------------
  */
 
-static const struct vfp *vfplist[] = {
-	&VFP_testgunzip,
-	&VFP_gunzip,
-	&VFP_gzip,
-	&VFP_esi,
-	&VFP_esi_gzip,
-	NULL,
+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 **vp;
-	int l;
+	const struct vfp_filter *vp;
 
 	VSLb(vc->wrk->vsl, SLT_Filters, "%s", fl);
 
@@ -252,23 +283,21 @@ VFP_FilterList(struct vfp_ctx *vc, const char *fl)
 		for (q = p; *q; q++)
 			if (vct_isspace(*q))
 				break;
-		for(vp = vfplist; *vp != NULL; vp++) {
-			l = strlen((*vp)->name);
-			if (l != q - p)
+		VTAILQ_FOREACH(vp, &vfp_filters, list) {
+			if (vp->nlen != q - p)
 				continue;
-			if (!memcmp(p, (*vp)->name, l))
+			if (!memcmp(p, vp->filter->name, vp->nlen))
 				break;
 		}
-		if (*vp == NULL)
+		if (vp == NULL)
 			return (VFP_Error(vc,
 			    "Filter '%.*s' not found", (int)(q-p), p));
-		if (VFP_Push(vc, *vp) == NULL)
+		if (VFP_Push(vc, vp->filter) == NULL)
 			return (-1);
 	}
 	return (0);
 }
 
-
 /*--------------------------------------------------------------------
  * Debugging aids
  */
@@ -295,4 +324,9 @@ 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 789a68c..924782e 100644
--- a/bin/varnishd/cache/cache_filter.h
+++ b/bin/varnishd/cache/cache_filter.h
@@ -89,6 +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 *);
 
 /* Deliver processors ------------------------------------------------*/
 


More information about the varnish-commit mailing list