Commit a8cb329f authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

Add vct_issepctl()



git-svn-id: http://www.varnish-cache.org/svn/trunk/varnish-cache@2757 d4fa192b-c00b-0410-8231-f00ffab90ce4
parent 72a9884a
......@@ -43,6 +43,7 @@
#include <strings.h>
#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);
}
......
......@@ -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)) {
......
......@@ -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
......
......@@ -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)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment