[master] 9bcf907 Add support for floats

Martin Blix Grydeland martin at varnish-cache.org
Tue Oct 1 14:48:18 CEST 2013


commit 9bcf907cf28db63693ed872403192b66a269462e
Author: Martin Blix Grydeland <martin at varnish-software.com>
Date:   Thu Sep 19 16:31:43 2013 +0200

    Add support for floats

diff --git a/bin/varnishtest/tests/l00001.vtc b/bin/varnishtest/tests/l00001.vtc
index e9f7503..5b54b94 100644
--- a/bin/varnishtest/tests/l00001.vtc
+++ b/bin/varnishtest/tests/l00001.vtc
@@ -30,16 +30,30 @@ logexpect l1 -d 1 -g vxid -q "ReqProtocol ne 'HTTP/1.0'" {
 	expect * =	End
 } -run
 
-# Test '==' operator
+# Test '==' operator on integers
 logexpect l1 -d 1 -g vxid -q "RespStatus == 200" {
 	expect * *	Begin	req
 	expect * =	ReqEnd
 	expect * =	End
 } -run
 
-# Test '!=' operator
+# Test '==' operator on floats
+logexpect l1 -d 1 -g vxid -q "RespStatus == 200." {
+	expect * *	Begin	req
+	expect * =	ReqEnd
+	expect * =	End
+} -run
+
+# Test '!=' operator on integers
 logexpect l1 -d 1 -g vxid -q "RespStatus != 503" {
 	expect * *	Begin	req
 	expect * =	ReqEnd
 	expect * =	End
 } -run
+
+# Test '!=' operator on floats
+logexpect l1 -d 1 -g vxid -q "RespStatus != 503." {
+	expect * *	Begin	req
+	expect * =	ReqEnd
+	expect * =	End
+} -run
diff --git a/lib/libvarnishapi/vsl_query.c b/lib/libvarnishapi/vsl_query.c
index 2d4abf1..74ff646 100644
--- a/lib/libvarnishapi/vsl_query.c
+++ b/lib/libvarnishapi/vsl_query.c
@@ -60,6 +60,7 @@ vslq_test_rec(const struct vex *vex, const struct VSLC_ptr *rec)
 	int reclen;
 	const char *recdata;
 	long long recint;
+	double recfloat;
 	char *endptr;
 
 	AN(vex);
@@ -86,6 +87,12 @@ vslq_test_rec(const struct vex *vex, const struct VSLC_ptr *rec)
 				break;
 			/* Can't parse - no match */
 			return (0);
+		case VEX_FLOAT:
+			recfloat = strtod(recdata, &endptr);
+			if (*endptr == '\0' || isspace(*endptr))
+				break;
+			/* Can't parse - no match */
+			return (0);
 		default:
 			INCOMPL();
 		}
@@ -100,8 +107,12 @@ vslq_test_rec(const struct vex *vex, const struct VSLC_ptr *rec)
 			if (val->val_int == recint)
 				return (1);
 			return (0);
+		case VEX_FLOAT:
+			if (val->val_float == recfloat)
+				return (1);
+			return (0);
 		default:
-			INCOMPL();
+			WRONG("Wrong value type");
 		}
 	case T_NEQ:		/* != */
 		switch (val->type) {
@@ -109,8 +120,12 @@ vslq_test_rec(const struct vex *vex, const struct VSLC_ptr *rec)
 			if (val->val_int != recint)
 				return (1);
 			return (0);
+		case VEX_FLOAT:
+			if (val->val_float != recfloat)
+				return (1);
+			return (0);
 		default:
-			INCOMPL();
+			WRONG("Wrong value type");
 		}
 	case T_SEQ:		/* eq */
 		assert(val->type == VEX_STRING);



More information about the varnish-commit mailing list