#include <strings.h>
#include "shmlog.h"
+#include "vct.h"
#include "cache.h"
#ifndef HAVE_STRLCPY
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);
}
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)) {
#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)