[master] 2968fdf Add '<' and '>' operators
Martin Blix Grydeland
martin at varnish-cache.org
Tue Oct 1 14:48:18 CEST 2013
commit 2968fdf2f118ed2dfcacf3d0f3c98ff7fd7569f1
Author: Martin Blix Grydeland <martin at varnish-software.com>
Date: Thu Sep 19 17:00:48 2013 +0200
Add '<' and '>' operators
diff --git a/bin/varnishtest/tests/l00001.vtc b/bin/varnishtest/tests/l00001.vtc
index 5b54b94..2d9e83f 100644
--- a/bin/varnishtest/tests/l00001.vtc
+++ b/bin/varnishtest/tests/l00001.vtc
@@ -57,3 +57,31 @@ logexpect l1 -d 1 -g vxid -q "RespStatus != 503." {
expect * = ReqEnd
expect * = End
} -run
+
+# Test '<' operator on integers
+logexpect l1 -d 1 -g vxid -q "RespStatus < 201" {
+ expect * * Begin req
+ expect * = ReqEnd
+ expect * = End
+} -run
+
+# Test '<' operator on floats
+logexpect l1 -d 1 -g vxid -q "RespStatus < 201." {
+ expect * * Begin req
+ expect * = ReqEnd
+ expect * = End
+} -run
+
+# Test '>' operator on integers
+logexpect l1 -d 1 -g vxid -q "RespStatus > 199" {
+ expect * * Begin req
+ expect * = ReqEnd
+ expect * = End
+} -run
+
+# Test '>' operator on floats
+logexpect l1 -d 1 -g vxid -q "RespStatus > 199." {
+ expect * * Begin req
+ expect * = ReqEnd
+ expect * = End
+} -run
diff --git a/lib/libvarnishapi/vsl_query.c b/lib/libvarnishapi/vsl_query.c
index 74ff646..062be7e 100644
--- a/lib/libvarnishapi/vsl_query.c
+++ b/lib/libvarnishapi/vsl_query.c
@@ -104,11 +104,11 @@ vslq_test_rec(const struct vex *vex, const struct VSLC_ptr *rec)
case T_EQ: /* == */
switch (val->type) {
case VEX_INT:
- if (val->val_int == recint)
+ if (recint == val->val_int)
return (1);
return (0);
case VEX_FLOAT:
- if (val->val_float == recfloat)
+ if (recfloat == val->val_float)
return (1);
return (0);
default:
@@ -117,11 +117,37 @@ vslq_test_rec(const struct vex *vex, const struct VSLC_ptr *rec)
case T_NEQ: /* != */
switch (val->type) {
case VEX_INT:
- if (val->val_int != recint)
+ if (recint != val->val_int)
return (1);
return (0);
case VEX_FLOAT:
- if (val->val_float != recfloat)
+ if (recfloat != val->val_float)
+ return (1);
+ return (0);
+ default:
+ WRONG("Wrong value type");
+ }
+ case '<': /* < */
+ switch (val->type) {
+ case VEX_INT:
+ if (recint < val->val_int)
+ return (1);
+ return (0);
+ case VEX_FLOAT:
+ if (recfloat < val->val_float)
+ return (1);
+ return (0);
+ default:
+ WRONG("Wrong value type");
+ }
+ case '>':
+ switch (val->type) {
+ case VEX_INT:
+ if (recint > val->val_int)
+ return (1);
+ return (0);
+ case VEX_FLOAT:
+ if (recfloat > val->val_float)
return (1);
return (0);
default:
@@ -130,13 +156,13 @@ vslq_test_rec(const struct vex *vex, const struct VSLC_ptr *rec)
case T_SEQ: /* eq */
assert(val->type == VEX_STRING);
if (reclen == val->val_stringlen + 1 &&
- !strncmp(val->val_string, recdata, reclen))
+ !strncmp(recdata, val->val_string, reclen))
return (1);
return (0);
case T_SNEQ: /* ne */
assert(val->type == VEX_STRING);
if (reclen != val->val_stringlen + 1 ||
- strncmp(val->val_string, recdata, reclen))
+ strncmp(recdata, val->val_string, reclen))
return (1);
return (0);
default:
diff --git a/lib/libvarnishapi/vxp_parse.c b/lib/libvarnishapi/vxp_parse.c
index 7ce5093..7e3ed5a 100644
--- a/lib/libvarnishapi/vxp_parse.c
+++ b/lib/libvarnishapi/vxp_parse.c
@@ -199,6 +199,10 @@ vxp_expr_cmp(struct vxp *vxp, struct vex **pvex)
/* Valid operators */
case T_EQ: /* == */
+ case '<': /* < */
+ case '>': /* > */
+ case T_GEQ: /* >= */
+ case T_LEQ: /* <= */
case T_NEQ: /* != */
case T_SEQ: /* eq */
case T_SNEQ: /* ne */
@@ -222,6 +226,8 @@ vxp_expr_cmp(struct vxp *vxp, struct vex **pvex)
case '\0':
WRONG("Missing token");
case T_EQ: /* == */
+ case '<': /* < */
+ case '>': /* > */
case T_GEQ: /* >= */
case T_LEQ: /* <= */
case T_NEQ: /* != */
More information about the varnish-commit
mailing list