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
2e765f31
Commit
2e765f31
authored
Sep 30, 2014
by
Poul-Henning Kamp
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make token name comparison a robust and reusable function
parent
48509ec8
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
37 additions
and
8 deletions
+37
-8
cache_http.c
bin/varnishd/cache/cache_http.c
+37
-8
No files found.
bin/varnishd/cache/cache_http.c
View file @
2e765f31
...
...
@@ -449,6 +449,40 @@ http_split(const char **src, const char *stop, const char *sep,
return
(
1
);
}
/*-----------------------------------------------------------------------------
* Comparison rule for tokens:
* if target string starts with '"', we use memcmp() and expect closing
* double quote as well
* otherwise we use strncascmp()
*
* On match we increment *bp past the token name.
*/
static
int
http_istoken
(
const
char
**
bp
,
const
char
*
e
,
const
char
*
token
)
{
int
fl
=
strlen
(
token
);
const
char
*
b
;
AN
(
bp
);
AN
(
e
);
AN
(
token
);
b
=
*
bp
;
if
(
b
+
fl
+
2
<=
e
&&
*
b
==
'"'
&&
!
memcmp
(
b
+
1
,
token
,
fl
)
&&
b
[
fl
+
1
]
==
'"'
)
{
*
bp
+=
fl
+
2
;
return
(
1
);
}
if
(
b
+
fl
<=
e
&&
!
strncasecmp
(
b
,
token
,
fl
)
&&
(
b
+
fl
==
e
||
!
vct_istchar
(
b
[
fl
])))
{
*
bp
+=
fl
;
return
(
1
);
}
return
(
0
);
}
/*-----------------------------------------------------------------------------
* Find a given data element (token) in a header according to RFC2616's #rule
* (section 2.1, p15)
...
...
@@ -474,7 +508,6 @@ http_GetHdrToken(const struct http *hp, const char *hdr,
const
char
*
token
,
const
char
**
pb
,
const
char
**
pe
)
{
const
char
*
h
,
*
b
,
*
e
;
unsigned
fl
;
if
(
pb
!=
NULL
)
*
pb
=
NULL
;
...
...
@@ -483,18 +516,14 @@ http_GetHdrToken(const struct http *hp, const char *hdr,
if
(
!
http_GetHdr
(
hp
,
hdr
,
&
h
))
return
(
0
);
AN
(
h
);
fl
=
strlen
(
token
);
while
(
http_split
(
&
h
,
NULL
,
","
,
&
b
,
&
e
))
{
if
(
*
b
==
'"'
&&
!
memcmp
(
b
+
1
,
token
,
fl
)
&&
b
[
fl
+
1
]
==
'"'
)
while
(
http_split
(
&
h
,
NULL
,
","
,
&
b
,
&
e
))
if
(
http_istoken
(
&
b
,
e
,
token
)
)
break
;
if
(
!
strncasecmp
(
b
,
token
,
fl
)
&&
!
vct_istchar
(
b
[
fl
]))
break
;
}
if
(
b
==
NULL
)
return
(
0
);
if
(
pb
!=
NULL
)
{
for
(
b
+=
fl
;
vct_islws
(
*
b
);
b
++
)
for
(;
vct_islws
(
*
b
);
b
++
)
continue
;
if
(
b
==
e
)
{
b
=
NULL
;
...
...
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