r2757 - in trunk/varnish-cache: bin/varnishd bin/varnishtest include

phk at projects.linpro.no phk at projects.linpro.no
Sat Jun 21 20:51:29 CEST 2008


Author: phk
Date: 2008-06-21 20:51:29 +0200 (Sat, 21 Jun 2008)
New Revision: 2757

Modified:
   trunk/varnish-cache/bin/varnishd/cache_http.c
   trunk/varnish-cache/bin/varnishd/rfc2616.c
   trunk/varnish-cache/bin/varnishtest/vtc.c
   trunk/varnish-cache/include/vct.h
Log:
Add vct_issepctl()



Modified: trunk/varnish-cache/bin/varnishd/cache_http.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_http.c	2008-06-21 18:37:48 UTC (rev 2756)
+++ trunk/varnish-cache/bin/varnishd/cache_http.c	2008-06-21 18:51:29 UTC (rev 2757)
@@ -43,6 +43,7 @@
 #include <strings.h>
 
 #include "shmlog.h"
+#include "vct.h"
 #include "cache.h"
 
 #ifndef HAVE_STRLCPY
@@ -244,37 +245,48 @@
 	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)) {
+	while (h + fl <= e) {
+		/* Skip leading separators */
+		if (vct_issepctl(*h)) {
 			h++;
 			continue;
 		}
-		if (*h == ',') {
+		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);
+		}
+		while (*h && !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] == '=')
-			*ptr = &h[fl + 1];
-		else
-			*ptr = NULL;
-		return (1);
 	}
 	return (0);
 }

Modified: trunk/varnish-cache/bin/varnishd/rfc2616.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/rfc2616.c	2008-06-21 18:37:48 UTC (rev 2756)
+++ trunk/varnish-cache/bin/varnishd/rfc2616.c	2008-06-21 18:51:29 UTC (rev 2757)
@@ -112,6 +112,7 @@
 	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)) {

Modified: trunk/varnish-cache/bin/varnishtest/vtc.c
===================================================================
--- trunk/varnish-cache/bin/varnishtest/vtc.c	2008-06-21 18:37:48 UTC (rev 2756)
+++ trunk/varnish-cache/bin/varnishtest/vtc.c	2008-06-21 18:51:29 UTC (rev 2757)
@@ -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

Modified: trunk/varnish-cache/include/vct.h
===================================================================
--- trunk/varnish-cache/include/vct.h	2008-06-21 18:37:48 UTC (rev 2756)
+++ trunk/varnish-cache/include/vct.h	2008-06-21 18:51:29 UTC (rev 2757)
@@ -55,6 +55,7 @@
 #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)




More information about the varnish-commit mailing list