Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
V
varnish-cache
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Commits
Open sidebar
varnishcache
varnish-cache
Commits
9f26fcdd
Commit
9f26fcdd
authored
Oct 22, 2017
by
Poul-Henning Kamp
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Rewrite and simplify VSL_Glob2Tags().
Two static checkers and myself had problems understanding the old code.
parent
23ce17a3
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
45 additions
and
45 deletions
+45
-45
u00006.vtc
bin/varnishtest/tests/u00006.vtc
+6
-0
vsl_arg.c
lib/libvarnishapi/vsl_arg.c
+39
-45
No files found.
bin/varnishtest/tests/u00006.vtc
View file @
9f26fcdd
...
...
@@ -31,10 +31,16 @@ shell -err -expect "-k: Invalid number 'foo'" \
"varnishlog -k foo"
shell -err -expect "-L: Range error" \
"varnishlog -L 0"
shell -err -expect {-i: "foo" matches zero tags} \
"varnishlog -i foo"
shell -err -expect {-i: "Resp" is ambiguous} \
"varnishlog -i Resp"
shell -err -expect {-i: Syntax error in "Re**sp"} \
"varnishlog -i Re**sp"
shell -err -expect {-i: "" matches zero tags} \
"varnishlog -i ''"
shell -err -expect {-I: "foo" matches zero tags} \
"varnishlog -I foo:bar"
shell -err -expect {-I: "Resp" is ambiguous} \
...
...
lib/libvarnishapi/vsl_arg.c
View file @
9f26fcdd
...
...
@@ -83,40 +83,25 @@ VSL_Name2Tag(const char *name, int l)
int
VSL_Glob2Tags
(
const
char
*
glob
,
int
l
,
VSL_tagfind_f
*
func
,
void
*
priv
)
{
int
i
,
r
,
l2
;
int
pre
=
0
;
int
post
=
0
;
char
buf
[
64
]
;
const
char
*
p1
=
NULL
;
const
char
*
p2
=
NULL
;
const
char
*
e
,
*
p
;
int
i
,
l1
=
0
,
l2
=
0
,
r
=
0
;
AN
(
glob
);
if
(
l
<
0
)
l
=
strlen
(
glob
);
if
(
l
==
0
||
l
>
sizeof
buf
-
1
)
return
(
-
1
);
if
(
strchr
(
glob
,
'*'
)
!=
NULL
)
{
if
(
glob
[
0
]
==
'*'
)
{
/* Prefix wildcard */
pre
=
1
;
glob
++
;
l
--
;
}
if
(
l
>
0
&&
glob
[
l
-
1
]
==
'*'
)
{
/* Postfix wildcard */
post
=
1
;
l
--
;
}
}
if
(
pre
&&
post
)
/* Support only post or prefix wildcards */
return
(
-
3
);
memcpy
(
buf
,
glob
,
l
);
buf
[
l
]
=
'\0'
;
if
(
strchr
(
buf
,
'*'
)
!=
NULL
)
/* No multiple wildcards */
return
(
-
3
);
if
(
pre
==
0
&&
post
==
0
)
{
/* No wildcards, use VSL_Name2Tag */
i
=
VSL_Name2Tag
(
buf
,
l
);
if
(
l
>=
0
)
e
=
glob
+
l
;
else
e
=
strchr
(
glob
,
'\0'
);
if
(
glob
==
e
)
return
(
-
1
);
// Empty pattern cannot match
for
(
p
=
glob
;
p
<
e
;
p
++
)
if
(
*
p
==
'*'
)
break
;
if
(
p
==
e
)
{
// No wildcard
i
=
VSL_Name2Tag
(
glob
,
l
);
if
(
i
<
0
)
return
(
i
);
if
(
func
!=
NULL
)
...
...
@@ -124,22 +109,31 @@ VSL_Glob2Tags(const char *glob, int l, VSL_tagfind_f *func, void *priv)
return
(
1
);
}
r
=
0
;
if
(
p
!=
glob
)
{
// Prefix match
p1
=
glob
;
l1
=
p
-
p1
;
}
if
(
p
!=
e
-
1
)
{
// Postfix match
p2
=
p
+
1
;
l2
=
e
-
p2
;
}
for
(
p
++
;
p
<
e
;
p
++
)
if
(
*
p
==
'*'
)
return
(
-
3
);
// More than one wildcard
for
(
i
=
0
;
i
<
SLT__MAX
;
i
++
)
{
if
(
VSL_tags
[
i
]
==
NULL
)
p
=
VSL_tags
[
i
];
if
(
p
==
NULL
)
continue
;
l2
=
strlen
(
VSL_tags
[
i
]);
if
(
l2
<
l
)
e
=
strchr
(
p
,
'\0'
);
if
(
e
-
p
<
l1
+
l2
)
continue
;
if
(
p1
!=
NULL
&&
strncasecmp
(
p
,
p1
,
l1
))
continue
;
if
(
p2
!=
NULL
&&
strncasecmp
(
e
-
l2
,
p2
,
l2
))
continue
;
if
(
pre
)
{
/* Prefix wildcard match */
if
(
strcasecmp
(
buf
,
VSL_tags
[
i
]
+
l2
-
l
))
continue
;
}
else
{
/* Postfix wildcard match */
if
(
strncasecmp
(
buf
,
VSL_tags
[
i
],
l
))
continue
;
}
if
(
func
!=
NULL
)
(
func
)(
i
,
priv
);
r
++
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment