Hi,
as discussed this afternoon on IRC with Federico, here is a patch for a
std_vmod function for converting from real to int.
we might be interested in pushing this into master.

-- 
Arianna Aondio
Software Developer | Varnish Software AS
Mobile: +47 98062619
We Make Websites Fly
www.varnish-software.com
diff --git a/bin/varnishtest/tests/m00016.vtc b/bin/varnishtest/tests/m00016.vtc
index ef51f93..b9fcf3b 100644
--- a/bin/varnishtest/tests/m00016.vtc
+++ b/bin/varnishtest/tests/m00016.vtc
@@ -11,7 +11,7 @@ varnish v1 -vcl+backend {
 	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)));
+		set resp.http.x-baz = std.real2integer(std.time2real(std.real2time(std.real(resp.http.x-foo, 0.0))));
 	}
 } -start
 
@@ -19,5 +19,5 @@ client c1 {
 	txreq -hdr "foo: 1140618699"
 	rxresp
 	expect resp.http.x-foo == resp.http.x-bar
-	expect resp.http.x-baz == 1140618699.000
+	expect resp.http.x-baz == 1140618699
 } -run
diff --git a/lib/libvmod_std/vmod.vcc b/lib/libvmod_std/vmod.vcc
index 0ad385f..2897fd9 100644
--- a/lib/libvmod_std/vmod.vcc
+++ b/lib/libvmod_std/vmod.vcc
@@ -156,6 +156,13 @@ Example
 	|	...
 	| }
 
+$Function INT real2integer(REAL r)
+
+Description
+	Converts the real *r* to an integer.
+Example
+	set req.http.integer = std.real2integer(1140618699.00);
+
 $Function TIME real2time(REAL r)
 
 Description
diff --git a/lib/libvmod_std/vmod_std_conversions.c b/lib/libvmod_std/vmod_std_conversions.c
index 95bb003..1f0179e 100644
--- a/lib/libvmod_std/vmod_std_conversions.c
+++ b/lib/libvmod_std/vmod_std_conversions.c
@@ -187,6 +187,14 @@ vmod_real(VRT_CTX, VCL_STRING p, VCL_REAL d)
 	return (r);
 }
 
+VCL_INT __match_proto__(td_std_time2real)
+vmod_real2integer(VRT_CTX, VCL_REAL r)
+{
+	CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
+
+	return((long)floor(r));
+}
+
 VCL_TIME __match_proto__(td_std_real2time)
 vmod_real2time(VRT_CTX, VCL_REAL r)
 {
_______________________________________________
varnish-dev mailing list
[email protected]
https://www.varnish-cache.org/lists/mailman/listinfo/varnish-dev

Reply via email to