[4.0] 14da184 Add real2time, time2integer and time2real to the std vmod

Federico G. Schwindt fgsch at lodoss.net
Tue Jun 24 11:31:58 CEST 2014


commit 14da1840453b4076ac8b46448c9092a491037d5a
Author: Federico G. Schwindt <fgsch at lodoss.net>
Date:   Tue Jun 24 00:13:55 2014 +0100

    Add real2time, time2integer and time2real to the std vmod
    
    As discussed on the latest VDD.

diff --git a/bin/varnishtest/tests/m00016.vtc b/bin/varnishtest/tests/m00016.vtc
new file mode 100644
index 0000000..ef51f93
--- /dev/null
+++ b/bin/varnishtest/tests/m00016.vtc
@@ -0,0 +1,23 @@
+varnishtest "Test std.real2time, std.time2integer and std.time2real"
+
+server s1 {
+	rxreq
+	txresp
+} -start
+
+varnish v1 -vcl+backend {
+	import ${vmod_std};
+
+	sub vcl_deliver {
+		set resp.http.x-foo = std.integer(req.http.foo, 0);
+		set resp.http.x-bar = std.time2integer(std.real2time(std.real(resp.http.x-foo, 0.0)));
+		set resp.http.x-baz = std.time2real(std.real2time(std.real(resp.http.x-foo, 0.0)));
+	}
+} -start
+
+client c1 {
+	txreq -hdr "foo: 1140618699"
+	rxresp
+	expect resp.http.x-foo == resp.http.x-bar
+	expect resp.http.x-baz == 1140618699.000
+} -run
diff --git a/lib/libvmod_std/vmod.vcc b/lib/libvmod_std/vmod.vcc
index cc3eb43..fbee007 100644
--- a/lib/libvmod_std/vmod.vcc
+++ b/lib/libvmod_std/vmod.vcc
@@ -143,6 +143,27 @@ Description
 Example
 	set req.http.x-real = std.real(req.http.x-foo, 0.0);
 
+$Function TIME real2time(REAL)
+
+Description
+	Converts the real *r* to a time.
+Example
+	set req.http.x-time = std.real2time(1140618699.00);
+
+$Function INT time2integer(TIME)
+
+Description
+	Converts the time *t* to a integer.
+Example
+	set req.http.x-int = std.time2integer(now);
+
+$Function REAL time2real(TIME)
+
+Description
+	Converts the time *t* to a real.
+Example
+	set req.http.x-real = std.time2real(now);
+
 $Function BOOL healthy(BACKEND)
 
 Description
diff --git a/lib/libvmod_std/vmod_std_conversions.c b/lib/libvmod_std/vmod_std_conversions.c
index 589d708..8ca0dd7 100644
--- a/lib/libvmod_std/vmod_std_conversions.c
+++ b/lib/libvmod_std/vmod_std_conversions.c
@@ -195,3 +195,27 @@ vmod_real(const struct vrt_ctx *ctx, VCL_STRING p, VCL_REAL d)
 
 	return (r);
 }
+
+VCL_TIME __match_proto__(td_std_real2time)
+vmod_real2time(const struct vrt_ctx *ctx, VCL_REAL r)
+{
+	CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
+
+	return (r);
+}
+
+VCL_INT __match_proto__(td_std_time2integer)
+vmod_time2integer(const struct vrt_ctx *ctx, VCL_TIME t)
+{
+	CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
+
+	return (t);
+}
+
+VCL_REAL __match_proto__(td_std_time2real)
+vmod_time2real(const struct vrt_ctx *ctx, VCL_TIME t)
+{
+	CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
+
+	return (t);
+}



More information about the varnish-commit mailing list