]> err.no Git - varnish/commitdiff
Add vct_issepctl()
authorphk <phk@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Sat, 21 Jun 2008 18:51:29 +0000 (18:51 +0000)
committerphk <phk@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Sat, 21 Jun 2008 18:51:29 +0000 (18:51 +0000)
git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@2757 d4fa192b-c00b-0410-8231-f00ffab90ce4

varnish-cache/bin/varnishd/cache_http.c
varnish-cache/bin/varnishd/rfc2616.c
varnish-cache/bin/varnishtest/vtc.c
varnish-cache/include/vct.h

index 3233fbba0ba027a062cc480e761f5e6ef407cda9..5826023fe7b082d6a6561b2f2d3dbf5f9aa5316b 100644 (file)
@@ -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);
 }
index 515977193c032f8ad75dd850af79c1fa06fb7766..c153c21d9a8252f0d17c00b836b998c9ac5a2f8d 100644 (file)
@@ -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)) {
index f7cf914e21a6377145fea0624c65ccd5853c5986..6b73271fd1c0640c82a8cddf35a5850c67600368 100644 (file)
@@ -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
index fbd53f8d0c40668a552577f36a11d6f5b83d2ccc..323c49dca4f05763311ab7c0a18826dacf9a6c0d 100644 (file)
@@ -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)