[master] a1726ad Use VSL_List2Tags in -IX option processing.
Martin Blix Grydeland
martin at varnish-cache.org
Tue Oct 1 14:48:18 CEST 2013
commit a1726adcdaf8439a25b42e89bf585df1e12f8476
Author: Martin Blix Grydeland <martin at varnish-software.com>
Date: Tue Sep 24 17:07:14 2013 +0200
Use VSL_List2Tags in -IX option processing.
Use VSL_List2Tags in -IX option processing so that the filters can be
applied to a list of tags.
diff --git a/include/vapi/vapi_options.h b/include/vapi/vapi_options.h
index 6eceaf6..c9e6e02 100644
--- a/include/vapi/vapi_options.h
+++ b/include/vapi/vapi_options.h
@@ -75,10 +75,10 @@
)
#define VSL_OPT_I \
- VOPT("I:", "[-I <[tag:]regex>]", "Include by regex", \
+ VOPT("I:", "[-I <[taglist:]regex>]", "Include by regex", \
"Include by regex matching. Output only records matching" \
- " tag and regular expression. Applies to any tag if tag" \
- " is * or empty.\n" \
+ " taglist and regular expression. Applies to any tag if" \
+ " taglist is absent.\n" \
"\n" \
VSL_iI_PS \
)
@@ -117,8 +117,8 @@
)
#define VSL_OPT_X \
- VOPT("X:", "[-X <[tag:]regex>]", "Exclude by regex", \
+ VOPT("X:", "[-X <[taglist:]regex>]", "Exclude by regex", \
"Exclude by regex matching. Do not output records matching" \
- " tag and regular expression. Applies to any tag if tag" \
- " is * or empty." \
+ " taglist and regular expression. Applies to any tag if" \
+ " taglist is absent." \
)
diff --git a/lib/libvarnishapi/vsl.c b/lib/libvarnishapi/vsl.c
index 0889f54..cfb424a 100644
--- a/lib/libvarnishapi/vsl.c
+++ b/lib/libvarnishapi/vsl.c
@@ -108,6 +108,8 @@ vsl_IX_free(vslf_list *list)
vslf = VTAILQ_FIRST(list);
CHECK_OBJ_NOTNULL(vslf, VSLF_MAGIC);
VTAILQ_REMOVE(list, vslf, list);
+ if (vslf->tags)
+ vbit_destroy(vslf->tags);
AN(vslf->vre);
VRE_free(&vslf->vre);
AZ(vslf->vre);
@@ -167,7 +169,7 @@ vsl_match_IX(struct VSL_data *vsl, const vslf_list *list, const struct VSL_curso
VTAILQ_FOREACH(vslf, list, list) {
CHECK_OBJ_NOTNULL(vslf, VSLF_MAGIC);
- if (vslf->tag >= 0 && vslf->tag != tag)
+ if (vslf->tags != NULL && !vbit_test(vslf->tags, tag))
continue;
if (VRE_exec(vslf->vre, cdata, len, 0, 0, NULL, 0, NULL) >= 0)
return (1);
diff --git a/lib/libvarnishapi/vsl_api.h b/lib/libvarnishapi/vsl_api.h
index 5b7307c..7094fec 100644
--- a/lib/libvarnishapi/vsl_api.h
+++ b/lib/libvarnishapi/vsl_api.h
@@ -63,7 +63,7 @@ struct vslf {
#define VSLF_MAGIC 0x08650B39
VTAILQ_ENTRY(vslf) list;
- int tag;
+ struct vbitmap *tags;
vre_t *vre;
};
diff --git a/lib/libvarnishapi/vsl_arg.c b/lib/libvarnishapi/vsl_arg.c
index b32a470..dc58a66 100644
--- a/lib/libvarnishapi/vsl_arg.c
+++ b/lib/libvarnishapi/vsl_arg.c
@@ -256,47 +256,46 @@ vsl_IX_arg(struct VSL_data *vsl, int opt, const char *arg)
const char *b, *e, *err;
vre_t *vre;
struct vslf *vslf;
+ struct vbitmap *tags = NULL;
CHECK_OBJ_NOTNULL(vsl, VSL_MAGIC);
vsl->flags |= F_SEEN_ixIX;
- l = 0;
b = arg;
e = strchr(b, ':');
if (e) {
- while (isspace(*b))
- b++;
+ tags = vbit_init(SLT__MAX);
+ AN(tags);
l = e - b;
- while (l > 0 && isspace(b[l - 1]))
- l--;
- }
- if (l > 0 && strncmp(b, "*", l))
- i = VSL_Name2Tag(b, l);
- else
- i = -3;
- if (i == -2)
- return (vsl_diag(vsl,
- "-%c: \"%*.*s\" matches multiple tags\n",
- (char)opt, l, l, b));
- else if (i == -1)
- return (vsl_diag(vsl,
- "-%c: Could not match \"%*.*s\" to any tag\n",
- (char)opt, l, l, b));
- assert(i >= -3);
-
- if (e)
+ i = VSL_List2Tags(b, l, vsl_vbm_bitset, tags);
+ if (i < 0)
+ vbit_destroy(tags);
+ if (i == -1)
+ return (vsl_diag(vsl,
+ "-%c: \"%*.*s\" matches zero tags",
+ (char)opt, l, l, b));
+ else if (i == -2)
+ return (vsl_diag(vsl,
+ "-%c: \"%*.*s\" is ambiguous",
+ (char)opt, l, l, b));
+ else if (i == 3)
+ return (vsl_diag(vsl,
+ "-%c: Syntax error in \"%*.*s\"",
+ (char)opt, l, l, b));
b = e + 1;
+ }
+
vre = VRE_compile(b, 0, &err, &off);
- if (vre == NULL)
+ if (vre == NULL) {
+ if (tags)
+ vbit_destroy(tags);
return (vsl_diag(vsl, "-%c: Regex error at position %d (%s)\n",
(char)opt, off, err));
+ }
ALLOC_OBJ(vslf, VSLF_MAGIC);
- if (vslf == NULL) {
- VRE_free(&vre);
- return (vsl_diag(vsl, "Out of memory"));
- }
- vslf->tag = i;
+ AN(vslf);
+ vslf->tags = tags;
vslf->vre = vre;
if (opt == 'I')
More information about the varnish-commit
mailing list