---
 lib/libvmod_debug/vmod.vcc     |  4 ++++
 lib/libvmod_debug/vmod_debug.c | 47 ++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 51 insertions(+)

diff --git a/lib/libvmod_debug/vmod.vcc b/lib/libvmod_debug/vmod.vcc
index b5d108c..8e940f4 100644
--- a/lib/libvmod_debug/vmod.vcc
+++ b/lib/libvmod_debug/vmod.vcc
@@ -93,3 +93,7 @@ Encrypt the HTTP header with quad-ROT13 encryption,
 $Function STRING argtest(STRING one, REAL two=2, STRING three="3")
 
 $Function INT vre_limit()
+
+$Function VOID register_exp_callback(PRIV_VCL)
+
+Register the vmod to receive expiry callbacks
diff --git a/lib/libvmod_debug/vmod_debug.c b/lib/libvmod_debug/vmod_debug.c
index 72bbbe4..7d21c16 100644
--- a/lib/libvmod_debug/vmod_debug.c
+++ b/lib/libvmod_debug/vmod_debug.c
@@ -40,6 +40,7 @@ struct priv_vcl {
        unsigned                magic;
 #define PRIV_VCL_MAGIC         0x8E62FA9D
        char                    *foo;
+       struct exp_callback     *exp_cb;
 };
 
 VCL_VOID __match_proto__(td_debug_panic)
@@ -176,6 +177,45 @@ vmod_vre_limit(VRT_CTX)
        return (cache_param->vre_limits.match);
 }
 
+static void __match_proto__(exp_callback_f)
+exp_cb_insert(struct worker *wrk, struct objcore *oc, void *priv)
+{
+       const struct priv_vcl *priv_vcl;
+
+       CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC);
+       CHECK_OBJ_NOTNULL(oc, OBJCORE_MAGIC);
+       CAST_OBJ_NOTNULL(priv_vcl, priv, PRIV_VCL_MAGIC);
+       VSL(SLT_Debug, 0, "exp_cb: insert %p", oc);
+}
+
+static void __match_proto__(exp_callback_f)
+exp_cb_remove(struct worker *wrk, struct objcore *oc, void *priv)
+{
+       const struct priv_vcl *priv_vcl;
+
+       CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC);
+       CHECK_OBJ_NOTNULL(oc, OBJCORE_MAGIC);
+       CAST_OBJ_NOTNULL(priv_vcl, priv, PRIV_VCL_MAGIC);
+       VSL(SLT_Debug, 0, "exp_cb: remove %p", oc);
+}
+
+VCL_VOID
+vmod_register_exp_callback(VRT_CTX, struct vmod_priv *priv)
+{
+       struct priv_vcl *priv_vcl;
+
+       CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
+       CAST_OBJ_NOTNULL(priv_vcl, priv->priv, PRIV_VCL_MAGIC);
+       AZ(priv_vcl->exp_cb);
+       ALLOC_OBJ(priv_vcl->exp_cb, EXP_CALLBACK_MAGIC);
+       AN(priv_vcl->exp_cb);
+       priv_vcl->exp_cb->cb_insert = exp_cb_insert;
+       priv_vcl->exp_cb->cb_remove = exp_cb_remove;
+       priv_vcl->exp_cb->priv = priv_vcl;
+       EXP_Reg_Callback(priv_vcl->exp_cb);
+       VSL(SLT_Debug, 0, "exp_cb: registered");
+}
+
 static void __match_proto__(vmod_priv_free_f)
 priv_vcl_free(void *priv)
 {
@@ -184,6 +224,13 @@ priv_vcl_free(void *priv)
        CAST_OBJ_NOTNULL(priv_vcl, priv, PRIV_VCL_MAGIC);
        AN(priv_vcl->foo);
        free(priv_vcl->foo);
+       if (priv_vcl->exp_cb != NULL) {
+               CHECK_OBJ_NOTNULL(priv_vcl->exp_cb, EXP_CALLBACK_MAGIC);
+               EXP_Dereg_Callback(priv_vcl->exp_cb);
+               FREE_OBJ(priv_vcl->exp_cb);
+               AZ(priv_vcl->exp_cb);
+               VSL(SLT_Debug, 0, "exp_cb: deregistered");
+       }
        FREE_OBJ(priv_vcl);
        AZ(priv_vcl);
 }
-- 
2.1.4


_______________________________________________
varnish-dev mailing list
[email protected]
https://www.varnish-cache.org/lists/mailman/listinfo/varnish-dev

Reply via email to