[master] 4135edf Polish the vsl_arg stuff a bit more.
Poul-Henning Kamp
phk at FreeBSD.org
Mon Oct 23 07:05:08 UTC 2017
commit 4135edfe992322419310e9883d335908bd2fd800
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date: Mon Oct 23 07:04:25 2017 +0000
Polish the vsl_arg stuff a bit more.
diff --git a/lib/libvarnishapi/Makefile.am b/lib/libvarnishapi/Makefile.am
index 5ad55d2..41339ed 100644
--- a/lib/libvarnishapi/Makefile.am
+++ b/lib/libvarnishapi/Makefile.am
@@ -100,17 +100,18 @@ vxp_test_SOURCES = \
$(libvarnishapi_la_SOURCES) \
vxp_test.c
-vsl_glob_test_SOURCES = \
- vsl_glob_test.c
vsl_glob_test_LDADD = @PCRE_LIBS@ ${RT_LIBS} ${LIBM} libvarnishapi.la
vsl_glob_test_CFLAGS = -I$(top_srcdir)/include
-TESTS = vjsn_test
+TESTS = vjsn_test vsl_glob_test
noinst_PROGRAMS += ${TESTS}
+vsl_glob_test_SOURCES = vsl_glob_test.c
+vsl_glob_test_LDADD = libvarnishapi.la @SAN_LDFLAGS@
+
vjsn_test_SOURCES = vjsn.c
vjsn_test_CFLAGS = -DVJSN_TEST @SAN_CFLAGS@
vjsn_test_LDADD = libvarnishapi.la @SAN_LDFLAGS@
diff --git a/lib/libvarnishapi/vsl_arg.c b/lib/libvarnishapi/vsl_arg.c
index 6642cab..cd7c2b4 100644
--- a/lib/libvarnishapi/vsl_arg.c
+++ b/lib/libvarnishapi/vsl_arg.c
@@ -146,27 +146,26 @@ VSL_Glob2Tags(const char *glob, int l, VSL_tagfind_f *func, void *priv)
int
VSL_List2Tags(const char *list, int l, VSL_tagfind_f *func, void *priv)
{
- const char *p, *q, *e;
- int r, t;
+ const char *p, *b, *e;
+ int r, t = 0;
- if (l < 0)
- l = strlen(list);
p = list;
- e = p + l;
- t = 0;
+ if (l >= 0)
+ e = p + l;
+ else
+ e = strchr(p, '\0');
while (p < e) {
while (p < e && *p == ',')
p++;
if (p == e)
break;
- q = p;
- while (q < e && *q != ',')
- q++;
- r = VSL_Glob2Tags(p, q - p, func, priv);
+ b = p;
+ while (p < e && *p != ',')
+ p++;
+ r = VSL_Glob2Tags(b, p - b, func, priv);
if (r < 0)
return (r);
t += r;
- p = q;
}
if (t == 0)
return (-1);
diff --git a/lib/libvarnishapi/vsl_glob_test.c b/lib/libvarnishapi/vsl_glob_test.c
index 3ad2ec8..e4f62a9 100644
--- a/lib/libvarnishapi/vsl_glob_test.c
+++ b/lib/libvarnishapi/vsl_glob_test.c
@@ -30,26 +30,55 @@
#ifndef __FLEXELINT__
+#include <fnmatch.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "vapi/vsl.h"
+#include "vdef.h"
+#include "vas.h"
static void
cb(int tag, void *priv)
{
- (void)priv;
-
printf("\t%d (%s)\n", tag, VSL_tags[tag]);
+ if (priv != NULL)
+ assert(!fnmatch(priv, VSL_tags[tag], FNM_CASEFOLD));
+}
+
+static int
+tst_one(const char *p)
+{
+ int i;
+
+ printf("Test <%s>\n", p);
+ i = VSL_Glob2Tags(p, -1, cb, TRUST_ME(p));
+ printf(" -> %d\n", i);
+ return (i);
}
int
main(int argc, char * const *argv)
{
- int i;
+ int i, j;
+ if (argc == 1) {
+ i = tst_one("Req*");
+ assert(i == 10);
+ j = tst_one("reQ*");
+ assert(i == j);
+ assert(tst_one("*Header") > 0);
+ assert(tst_one("Req*eader") == 1);
+ assert(tst_one("*") > 0);
+ assert(tst_one("a*b*c") == -3);
+ assert(tst_one("**") == -3);
+ assert(tst_one("_") == -1);
+ assert(tst_one("") == -1);
+ assert(VSL_Glob2Tags("", 0, cb, NULL) == -1);
+ return (0);
+ }
if (argc != 2) {
fprintf(stderr, "vsl_glob_test <tagname/glob>\n");
exit(1);
More information about the varnish-commit
mailing list