[master] 61367de Simplify the CPP magic involved in HTTP headers, now that we can rely on everybody agreeing about the order of these fields.

Poul-Henning Kamp phk at varnish-cache.org
Thu Mar 22 18:53:04 CET 2012


commit 61367de4084f4c806944c989c021535bb5cf7e16
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Thu Mar 22 14:06:52 2012 +0000

    Simplify the CPP magic involved in HTTP headers, now that we can rely
    on everybody agreeing about the order of these fields.

diff --git a/bin/varnishd/cache/cache.h b/bin/varnishd/cache/cache.h
index 9abf2da..ec385c5 100644
--- a/bin/varnishd/cache/cache.h
+++ b/bin/varnishd/cache/cache.h
@@ -82,13 +82,9 @@ body_status(enum body_status e)
 
 enum {
 	/* Fields from the first line of HTTP proto */
-	HTTP_HDR_REQ,
-	HTTP_HDR_URL,
-	HTTP_HDR_PROTO,
-	HTTP_HDR_STATUS,
-	HTTP_HDR_RESPONSE,
-	/* HTTP header lines */
-	HTTP_HDR_FIRST,
+#define SLTH(aa, bb)	bb,
+#include "tbl/vsl_tags_http.h"
+#undef SLTH
 };
 
 struct SHA256Context;
diff --git a/bin/varnishd/cache/cache_http.c b/bin/varnishd/cache/cache_http.c
index 4d2a9fa..bcde416 100644
--- a/bin/varnishd/cache/cache_http.c
+++ b/bin/varnishd/cache/cache_http.c
@@ -41,24 +41,11 @@
 #include "tbl/http_headers.h"
 #undef HTTPH
 
-/*lint -save -e773 not () */
-#define LOGMTX2(ax, bx, cx)	[bx] = SLT_##ax##cx
-
-#define LOGMTX1(ax) {					\
-	LOGMTX2(ax, HTTP_HDR_REQ,	Request),	\
-	LOGMTX2(ax, HTTP_HDR_RESPONSE,	Response),	\
-	LOGMTX2(ax, HTTP_HDR_STATUS,	Status),	\
-	LOGMTX2(ax, HTTP_HDR_URL,	URL),		\
-	LOGMTX2(ax, HTTP_HDR_PROTO,	Protocol),	\
-	LOGMTX2(ax, HTTP_HDR_FIRST,	Header),	\
-	}
-
-static const enum VSL_tag_e logmtx[][HTTP_HDR_FIRST + 1] = {
-	[HTTP_Rx] = LOGMTX1(Rx),
-	[HTTP_Tx] = LOGMTX1(Tx),
-	[HTTP_Obj] = LOGMTX1(Obj)
+static const enum VSL_tag_e foo[] = {
+	[HTTP_Rx] = SLT_RxRequest,
+	[HTTP_Tx] = SLT_TxRequest,
+	[HTTP_Obj] = SLT_ObjRequest,
 };
-/*lint -restore */
 
 static enum VSL_tag_e
 http2shmlog(const struct http *hp, int t)
@@ -69,7 +56,7 @@ http2shmlog(const struct http *hp, int t)
 		t = HTTP_HDR_FIRST;
 	assert(hp->logtag >= HTTP_Rx && hp->logtag <= HTTP_Obj); /*lint !e685*/
 	assert(t >= HTTP_HDR_REQ && t <= HTTP_HDR_FIRST);
-	return (logmtx[hp->logtag][t]);
+	return ((enum VSL_tag_e)(foo[hp->logtag] + t));
 }
 
 static void



More information about the varnish-commit mailing list