From: phk Date: Sat, 21 Jun 2008 18:51:29 +0000 (+0000) Subject: Add vct_issepctl() X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0ba3bd44a91f439fb76e41711a0b58f220b35a65;p=varnish Add vct_issepctl() git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@2757 d4fa192b-c00b-0410-8231-f00ffab90ce4 --- diff --git a/varnish-cache/bin/varnishd/cache_http.c b/varnish-cache/bin/varnishd/cache_http.c index 3233fbba..5826023f 100644 --- a/varnish-cache/bin/varnishd/cache_http.c +++ b/varnish-cache/bin/varnishd/cache_http.c @@ -43,6 +43,7 @@ #include #include "shmlog.h" +#include "vct.h" #include "cache.h" #ifndef HAVE_STRLCPY @@ -244,37 +245,48 @@ http_GetHdr(const struct http *hp, const char *hdr, char **ptr) return (1); } -/*--------------------------------------------------------------------*/ +/*-------------------------------------------------------------------- + * Find a given headerfield, and if present and wanted, the beginning + * of its value. + */ int http_GetHdrField(const struct http *hp, const char *hdr, const char *field, char **ptr) { - char *h; + char *h, *e; unsigned fl; + if (ptr != NULL) + *ptr = NULL; if (!http_GetHdr(hp, hdr, &h)) return (0); + AN(h); + e = strchr(h, '\0'); fl = strlen(field); - while (*h) { - if (isspace(*h)) { - h++; - continue; - } - if (*h == ',') { + while (h + fl <= e) { + /* Skip leading separators */ + if (vct_issepctl(*h)) { h++; continue; } - if (memcmp(h, field, fl) || - isalpha(h[fl]) || h[fl] == '-') { - while (*h && !(isspace(*h) || *h == ',')) - h++; - continue; + if ((h + fl == e || vct_issepctl(h[fl])) && + !memcmp(h, field, fl)) { + /* got it */ + h += fl; + if (ptr != NULL) { + while (vct_issp(*h)) + h++; + if (*h == '=') { + h++; + while (vct_issp(*h)) + h++; + *ptr = h; + } + } + return (1); } - if (h[fl] == '=') - *ptr = &h[fl + 1]; - else - *ptr = NULL; - return (1); + while (*h && !vct_issepctl(*h)) + h++; } return (0); } diff --git a/varnish-cache/bin/varnishd/rfc2616.c b/varnish-cache/bin/varnishd/rfc2616.c index 51597719..c153c21d 100644 --- a/varnish-cache/bin/varnishd/rfc2616.c +++ b/varnish-cache/bin/varnishd/rfc2616.c @@ -112,6 +112,7 @@ RFC2616_Ttl(const struct sess *sp, const struct http *hp, struct object *obj) u1 = u2 = 0; if (http_GetHdrField(hp, H_Cache_Control, "s-maxage", &p) || http_GetHdrField(hp, H_Cache_Control, "max-age", &p)) { + AN(p); u1 = strtoul(p, NULL, 0); u2 = 0; if (http_GetHdr(hp, H_Age, &p)) { diff --git a/varnish-cache/bin/varnishtest/vtc.c b/varnish-cache/bin/varnishtest/vtc.c index f7cf914e..6b73271f 100644 --- a/varnish-cache/bin/varnishtest/vtc.c +++ b/varnish-cache/bin/varnishtest/vtc.c @@ -40,7 +40,7 @@ #include "vtc.h" #define MAX_FILESIZE (1024 * 1024) -#define MAX_TOKENS 20 +#define MAX_TOKENS 100 /********************************************************************** * Read a file into memory diff --git a/varnish-cache/include/vct.h b/varnish-cache/include/vct.h index fbd53f8d..323c49dc 100644 --- a/varnish-cache/include/vct.h +++ b/varnish-cache/include/vct.h @@ -55,6 +55,7 @@ vct_is(unsigned char x, unsigned char y) #define vct_isctl(x) vct_is(x, VCT_CTL) #define vct_isalpha(x) vct_is(x, VCT_ALPHA) #define vct_issep(x) vct_is(x, VCT_SEPARATOR) +#define vct_issepctl(x) vct_is(x, VCT_SEPARATOR | VCT_CTL) /* NB: VCT always operate in ASCII, don't replace 0x0d with \r etc. */ #define vct_skipcrlf(p) (p[0] == 0x0d && p[1] == 0x0a ? 2 : 1)