[master] b0080ea Enable record prefix filtering for operations
Martin Blix Grydeland
martin at varnish-cache.org
Tue Oct 1 14:48:19 CEST 2013
commit b0080ea4ad92aa54ebfd67b2f2c8846710d67587
Author: Martin Blix Grydeland <martin at varnish-software.com>
Date: Wed Sep 25 15:17:58 2013 +0200
Enable record prefix filtering for operations
diff --git a/bin/varnishtest/tests/l00001.vtc b/bin/varnishtest/tests/l00001.vtc
index f98ebc9..7d22734 100644
--- a/bin/varnishtest/tests/l00001.vtc
+++ b/bin/varnishtest/tests/l00001.vtc
@@ -179,3 +179,10 @@ logexpect l1 -d 1 -g vxid -q "Debug,Resp* == 200" {
expect * = ReqEnd
expect * = End
} -run
+
+# Test record prefix
+logexpect l1 -d 1 -g vxid -q "Resp*:x-test eq '123 321'" {
+ expect 0 * Begin req
+ expect * = ReqEnd
+ expect * = End
+} -run
diff --git a/lib/libvarnishapi/generate.py b/lib/libvarnishapi/generate.py
index 9f3d668..b08e769 100755
--- a/lib/libvarnishapi/generate.py
+++ b/lib/libvarnishapi/generate.py
@@ -63,7 +63,7 @@ tokens = {
"T_NOT": "not",
# Miscellaneous
- None: "<>~[]{}()",
+ None: "<>~[]{}():",
# These have handwritten recognizers
"VAL": None,
diff --git a/lib/libvarnishapi/vsl_query.c b/lib/libvarnishapi/vsl_query.c
index e36d4ba..8a3a441 100644
--- a/lib/libvarnishapi/vsl_query.c
+++ b/lib/libvarnishapi/vsl_query.c
@@ -86,6 +86,18 @@ vslq_test_rec(const struct vex *vex, const struct VSLC_ptr *rec)
b = VSL_CDATA(rec->ptr);
e = b + VSL_LEN(rec->ptr) - 1;
+ /* Prefix */
+ if (vex->lhs->prefix != NULL) {
+ if (strncasecmp(b, vex->lhs->prefix, vex->lhs->prefixlen))
+ return (0);
+ if (b[vex->lhs->prefixlen] != ':')
+ return (0);
+ b += vex->lhs->prefixlen + 1;
+ /* Skip ws */
+ while (*b && isspace(*b))
+ b++;
+ }
+
/* Field */
if (vex->lhs->field > 0) {
for (e = b, i = 0; *e && i < vex->lhs->field; i++) {
diff --git a/lib/libvarnishapi/vxp.h b/lib/libvarnishapi/vxp.h
index 5d653bc..9a285b5 100644
--- a/lib/libvarnishapi/vxp.h
+++ b/lib/libvarnishapi/vxp.h
@@ -83,6 +83,8 @@ struct vex_lhs {
unsigned magic;
#define VEX_LHS_MAGIC 0x1AD3D78D
struct vbitmap *tags;
+ char *prefix;
+ int prefixlen;
int field;
int level_min;
int level_max;
diff --git a/lib/libvarnishapi/vxp_parse.c b/lib/libvarnishapi/vxp_parse.c
index 6847ab2..988fde4 100644
--- a/lib/libvarnishapi/vxp_parse.c
+++ b/lib/libvarnishapi/vxp_parse.c
@@ -85,6 +85,22 @@ vxp_expr_lhs(struct vxp *vxp, struct vex_lhs **plhs)
assert(i > 0);
vxp_NextToken(vxp);
+ if (vxp->t->tok == ':') {
+ /* Record prefix */
+ vxp_NextToken(vxp);
+ if (vxp->t->tok != VAL) {
+ VSB_printf(vxp->sb, "Expected string got '%.*s' ",
+ PF(vxp->t));
+ vxp_ErrWhere(vxp, vxp->t, -1);
+ return;
+ }
+ AN(vxp->t->dec);
+ (*plhs)->prefix = strdup(vxp->t->dec);
+ AN((*plhs)->prefix);
+ (*plhs)->prefixlen = strlen((*plhs)->prefix);
+ vxp_NextToken(vxp);
+ }
+
if (vxp->t->tok == '[') {
/* LHS field [] */
vxp_NextToken(vxp);
@@ -434,6 +450,8 @@ vex_Free(struct vex **pvex)
if ((*pvex)->lhs != NULL) {
if ((*pvex)->lhs->tags != NULL)
vbit_destroy((*pvex)->lhs->tags);
+ if ((*pvex)->lhs->prefix != NULL)
+ free((*pvex)->lhs->prefix);
FREE_OBJ((*pvex)->lhs);
}
if ((*pvex)->rhs != NULL) {
@@ -462,21 +480,22 @@ vex_print_rhs(const struct vex_rhs *rhs)
{
CHECK_OBJ_NOTNULL(rhs, VEX_RHS_MAGIC);
+ fprintf(stderr, "rhs=");
switch (rhs->type) {
case VEX_INT:
- fprintf(stderr, "INT=%jd", (intmax_t)rhs->val_int);
+ fprintf(stderr, "INT(%jd)", (intmax_t)rhs->val_int);
break;
case VEX_FLOAT:
- fprintf(stderr, "FLOAT=%f", rhs->val_float);
+ fprintf(stderr, "FLOAT(%f)", rhs->val_float);
break;
case VEX_STRING:
AN(rhs->val_string);
- fprintf(stderr, "STRING='%s'", rhs->val_string);
+ fprintf(stderr, "STRING(%s)", rhs->val_string);
break;
case VEX_REGEX:
AN(rhs->val_string);
AN(rhs->val_regex);
- fprintf(stderr, "REGEX='%s'", rhs->val_string);
+ fprintf(stderr, "REGEX(%s)", rhs->val_string);
break;
default:
WRONG("rhs type");
@@ -515,6 +534,10 @@ vex_print(const struct vex *vex, int indent)
fprintf(stderr, " lhs=(");
vex_print_tags(vex->lhs->tags);
fprintf(stderr, ")");
+ if (vex->lhs->prefix) {
+ assert(vex->lhs->prefixlen == strlen(vex->lhs->prefix));
+ fprintf(stderr, ":%s", vex->lhs->prefix);
+ }
if (vex->lhs->field >= 0)
fprintf(stderr, "[%d]", vex->lhs->field);
}
More information about the varnish-commit
mailing list