[PATCH 1/3] Change vmod_debug's PRIV_VCL to point to a struct instead of a single value
Martin Blix Grydeland
martin at varnish-software.com
Thu Feb 26 12:00:22 CET 2015
This is in preparation for being able to use it for storing multiple
values
---
lib/libvmod_debug/vmod_debug.c | 50 ++++++++++++++++++++++++++++++++----------
1 file changed, 39 insertions(+), 11 deletions(-)
diff --git a/lib/libvmod_debug/vmod_debug.c b/lib/libvmod_debug/vmod_debug.c
index b6736fb..72bbbe4 100644
--- a/lib/libvmod_debug/vmod_debug.c
+++ b/lib/libvmod_debug/vmod_debug.c
@@ -36,6 +36,12 @@
#include "vrt.h"
#include "vcc_if.h"
+struct priv_vcl {
+ unsigned magic;
+#define PRIV_VCL_MAGIC 0x8E62FA9D
+ char *foo;
+};
+
VCL_VOID __match_proto__(td_debug_panic)
vmod_panic(VRT_CTX, const char *str, ...)
{
@@ -65,16 +71,6 @@ vmod_author(VRT_CTX, VCL_ENUM id)
WRONG("Illegal VMOD enum");
}
-int
-init_function(struct vmod_priv *priv, const struct VCL_conf *cfg)
-{
- (void)cfg;
-
- priv->priv = strdup("FOO");
- priv->free = free;
- return (0);
-}
-
VCL_VOID __match_proto__(td_debug_test_priv_call)
vmod_test_priv_call(VRT_CTX, struct vmod_priv *priv)
{
@@ -103,9 +99,13 @@ vmod_test_priv_task(VRT_CTX, struct vmod_priv *priv, VCL_STRING s)
VCL_VOID __match_proto__(td_debug_test_priv_vcl)
vmod_test_priv_vcl(VRT_CTX, struct vmod_priv *priv)
{
+ struct priv_vcl *priv_vcl;
CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
- assert(!strcmp(priv->priv, "FOO"));
+ AN(priv);
+ CAST_OBJ_NOTNULL(priv_vcl, priv->priv, PRIV_VCL_MAGIC);
+ AN(priv_vcl->foo);
+ assert(!strcmp(priv_vcl->foo, "FOO"));
}
VCL_BLOB
@@ -175,3 +175,31 @@ vmod_vre_limit(VRT_CTX)
(void)ctx;
return (cache_param->vre_limits.match);
}
+
+static void __match_proto__(vmod_priv_free_f)
+priv_vcl_free(void *priv)
+{
+ struct priv_vcl *priv_vcl;
+
+ CAST_OBJ_NOTNULL(priv_vcl, priv, PRIV_VCL_MAGIC);
+ AN(priv_vcl->foo);
+ free(priv_vcl->foo);
+ FREE_OBJ(priv_vcl);
+ AZ(priv_vcl);
+}
+
+int __match_proto__(vmod_init_f)
+init_function(struct vmod_priv *priv, const struct VCL_conf *cfg)
+{
+ struct priv_vcl *priv_vcl;
+
+ (void)cfg;
+
+ ALLOC_OBJ(priv_vcl, PRIV_VCL_MAGIC);
+ AN(priv_vcl);
+ priv_vcl->foo = strdup("FOO");
+ AN(priv_vcl->foo);
+ priv->priv = priv_vcl;
+ priv->free = priv_vcl_free;
+ return (0);
+}
--
2.1.4
More information about the varnish-dev
mailing list