[master] 980cce7 Rename httpconn to http1_proto, for increased clarity in a more complex future world.

Poul-Henning Kamp phk at varnish-cache.org
Wed Jan 23 14:32:57 CET 2013


commit 980cce7fa6fc209efec2f5b2f840e212f4ba8c4c
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Wed Jan 23 13:32:32 2013 +0000

    Rename httpconn to http1_proto, for increased clarity in a more
    complex future world.

diff --git a/bin/varnishd/Makefile.am b/bin/varnishd/Makefile.am
index 7d2077b..f5ef9ba 100644
--- a/bin/varnishd/Makefile.am
+++ b/bin/varnishd/Makefile.am
@@ -31,7 +31,7 @@ varnishd_SOURCES = \
 	cache/cache_hash.c \
 	cache/cache_http.c \
 	cache/cache_http1_fsm.c \
-	cache/cache_httpconn.c \
+	cache/cache_http1_proto.c \
 	cache/cache_lck.c \
 	cache/cache_main.c \
 	cache/cache_mempool.c \
diff --git a/bin/varnishd/cache/cache_http1_proto.c b/bin/varnishd/cache/cache_http1_proto.c
new file mode 100644
index 0000000..8b331af
--- /dev/null
+++ b/bin/varnishd/cache/cache_http1_proto.c
@@ -0,0 +1,211 @@
+/*-
+ * Copyright (c) 2006 Verdens Gang AS
+ * Copyright (c) 2006-2011 Varnish Software AS
+ * All rights reserved.
+ *
+ * Author: Poul-Henning Kamp <phk at phk.freebsd.dk>
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * HTTP protocol requests
+ *
+ * The trouble with the "until magic sequence" design of HTTP protocol messages
+ * is that either you have to read a single character at a time, which is
+ * inefficient, or you risk reading too much, and pre-read some of the object,
+ * or even the next pipelined request, which follows the one you want.
+ *
+ * HTC reads a HTTP protocol header into a workspace, subject to limits,
+ * and stops when we see the magic marker (double [CR]NL), and if we overshoot,
+ * it keeps track of the "pipelined" data.
+ *
+ * We use this both for client and backend connections.
+ */
+
+#include "config.h"
+
+#include "cache.h"
+
+#include "vct.h"
+
+
+/*--------------------------------------------------------------------*/
+
+void
+HTC_Init(struct http_conn *htc, struct ws *ws, int fd, struct vsl_log *vsl,
+    unsigned maxbytes, unsigned maxhdr)
+{
+
+	htc->magic = HTTP_CONN_MAGIC;
+	htc->ws = ws;
+	htc->fd = fd;
+	htc->vsl = vsl;
+	htc->maxbytes = maxbytes;
+	htc->maxhdr = maxhdr;
+
+	(void)WS_Reserve(htc->ws, htc->maxbytes);
+	htc->rxbuf.b = ws->f;
+	htc->rxbuf.e = ws->f;
+	*htc->rxbuf.e = '\0';
+	htc->pipeline.b = NULL;
+	htc->pipeline.e = NULL;
+}
+
+/*--------------------------------------------------------------------
+ * Start over, and recycle any pipelined input.
+ * The WS_Reset is safe, even though the pipelined input is stored in
+ * the ws somewhere, because WS_Reset only fiddles pointers.
+ */
+
+enum htc_status_e
+HTC_Reinit(struct http_conn *htc)
+{
+	unsigned l;
+
+	CHECK_OBJ_NOTNULL(htc, HTTP_CONN_MAGIC);
+	(void)WS_Reserve(htc->ws, htc->maxbytes);
+	htc->rxbuf.b = htc->ws->f;
+	htc->rxbuf.e = htc->ws->f;
+	if (htc->pipeline.b != NULL) {
+		l = Tlen(htc->pipeline);
+		memmove(htc->rxbuf.b, htc->pipeline.b, l);
+		htc->rxbuf.e += l;
+		htc->pipeline.b = NULL;
+		htc->pipeline.e = NULL;
+	}
+	*htc->rxbuf.e = '\0';
+	return (HTC_Complete(htc));
+}
+
+/*--------------------------------------------------------------------
+ * Check if we have a complete HTTP request or response yet
+ *
+ */
+
+enum htc_status_e
+HTC_Complete(struct http_conn *htc)
+{
+	int i;
+	const char *p;
+	txt *t;
+
+	CHECK_OBJ_NOTNULL(htc, HTTP_CONN_MAGIC);
+
+	t = &htc->rxbuf;
+	Tcheck(*t);
+	assert(*t->e == '\0');
+
+	/* Skip any leading white space */
+	for (p = t->b ; vct_islws(*p); p++)
+		continue;
+	if (p == t->e) {
+		/* All white space */
+		t->e = t->b;
+		*t->e = '\0';
+		return (HTC_ALL_WHITESPACE);
+	}
+	while (1) {
+		p = strchr(p, '\n');
+		if (p == NULL)
+			return (HTC_NEED_MORE);
+		p++;
+		if (*p == '\r')
+			p++;
+		if (*p == '\n')
+			break;
+	}
+	p++;
+	i = p - t->b;
+	WS_ReleaseP(htc->ws, htc->rxbuf.e);
+	AZ(htc->pipeline.b);
+	AZ(htc->pipeline.e);
+	if (htc->rxbuf.b + i < htc->rxbuf.e) {
+		htc->pipeline.b = htc->rxbuf.b + i;
+		htc->pipeline.e = htc->rxbuf.e;
+		htc->rxbuf.e = htc->pipeline.b;
+	}
+	return (HTC_COMPLETE);
+}
+
+/*--------------------------------------------------------------------
+ * Receive more HTTP protocol bytes
+ */
+
+enum htc_status_e
+HTC_Rx(struct http_conn *htc)
+{
+	int i;
+
+	CHECK_OBJ_NOTNULL(htc, HTTP_CONN_MAGIC);
+	AN(htc->ws->r);
+	i = (htc->ws->r - htc->rxbuf.e) - 1;	/* space for NUL */
+	if (i <= 0) {
+		WS_ReleaseP(htc->ws, htc->rxbuf.b);
+		return (HTC_OVERFLOW);
+	}
+	i = read(htc->fd, htc->rxbuf.e, i);
+	if (i <= 0) {
+		/*
+		 * We wouldn't come here if we had a complete HTTP header
+		 * so consequently an EOF can not be OK
+		 */
+		WS_ReleaseP(htc->ws, htc->rxbuf.b);
+		return (HTC_ERROR_EOF);
+	}
+	htc->rxbuf.e += i;
+	*htc->rxbuf.e = '\0';
+	return (HTC_Complete(htc));
+}
+
+/*--------------------------------------------------------------------
+ * Read up to len bytes, returning pipelined data first.
+ */
+
+ssize_t
+HTC_Read(struct http_conn *htc, void *d, size_t len)
+{
+	size_t l;
+	unsigned char *p;
+	ssize_t i;
+
+	CHECK_OBJ_NOTNULL(htc, HTTP_CONN_MAGIC);
+	l = 0;
+	p = d;
+	if (htc->pipeline.b) {
+		l = Tlen(htc->pipeline);
+		if (l > len)
+			l = len;
+		memcpy(p, htc->pipeline.b, l);
+		p += l;
+		len -= l;
+		htc->pipeline.b += l;
+		if (htc->pipeline.b == htc->pipeline.e)
+			htc->pipeline.b = htc->pipeline.e = NULL;
+	}
+	if (len == 0)
+		return (l);
+	i = read(htc->fd, p, len);
+	if (i < 0) {
+		VSLb(htc->vsl, SLT_FetchError, "%s", strerror(errno));
+		return (i);
+	}
+	return (i + l);
+}
diff --git a/bin/varnishd/cache/cache_httpconn.c b/bin/varnishd/cache/cache_httpconn.c
deleted file mode 100644
index 8b331af..0000000
--- a/bin/varnishd/cache/cache_httpconn.c
+++ /dev/null
@@ -1,211 +0,0 @@
-/*-
- * Copyright (c) 2006 Verdens Gang AS
- * Copyright (c) 2006-2011 Varnish Software AS
- * All rights reserved.
- *
- * Author: Poul-Henning Kamp <phk at phk.freebsd.dk>
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * HTTP protocol requests
- *
- * The trouble with the "until magic sequence" design of HTTP protocol messages
- * is that either you have to read a single character at a time, which is
- * inefficient, or you risk reading too much, and pre-read some of the object,
- * or even the next pipelined request, which follows the one you want.
- *
- * HTC reads a HTTP protocol header into a workspace, subject to limits,
- * and stops when we see the magic marker (double [CR]NL), and if we overshoot,
- * it keeps track of the "pipelined" data.
- *
- * We use this both for client and backend connections.
- */
-
-#include "config.h"
-
-#include "cache.h"
-
-#include "vct.h"
-
-
-/*--------------------------------------------------------------------*/
-
-void
-HTC_Init(struct http_conn *htc, struct ws *ws, int fd, struct vsl_log *vsl,
-    unsigned maxbytes, unsigned maxhdr)
-{
-
-	htc->magic = HTTP_CONN_MAGIC;
-	htc->ws = ws;
-	htc->fd = fd;
-	htc->vsl = vsl;
-	htc->maxbytes = maxbytes;
-	htc->maxhdr = maxhdr;
-
-	(void)WS_Reserve(htc->ws, htc->maxbytes);
-	htc->rxbuf.b = ws->f;
-	htc->rxbuf.e = ws->f;
-	*htc->rxbuf.e = '\0';
-	htc->pipeline.b = NULL;
-	htc->pipeline.e = NULL;
-}
-
-/*--------------------------------------------------------------------
- * Start over, and recycle any pipelined input.
- * The WS_Reset is safe, even though the pipelined input is stored in
- * the ws somewhere, because WS_Reset only fiddles pointers.
- */
-
-enum htc_status_e
-HTC_Reinit(struct http_conn *htc)
-{
-	unsigned l;
-
-	CHECK_OBJ_NOTNULL(htc, HTTP_CONN_MAGIC);
-	(void)WS_Reserve(htc->ws, htc->maxbytes);
-	htc->rxbuf.b = htc->ws->f;
-	htc->rxbuf.e = htc->ws->f;
-	if (htc->pipeline.b != NULL) {
-		l = Tlen(htc->pipeline);
-		memmove(htc->rxbuf.b, htc->pipeline.b, l);
-		htc->rxbuf.e += l;
-		htc->pipeline.b = NULL;
-		htc->pipeline.e = NULL;
-	}
-	*htc->rxbuf.e = '\0';
-	return (HTC_Complete(htc));
-}
-
-/*--------------------------------------------------------------------
- * Check if we have a complete HTTP request or response yet
- *
- */
-
-enum htc_status_e
-HTC_Complete(struct http_conn *htc)
-{
-	int i;
-	const char *p;
-	txt *t;
-
-	CHECK_OBJ_NOTNULL(htc, HTTP_CONN_MAGIC);
-
-	t = &htc->rxbuf;
-	Tcheck(*t);
-	assert(*t->e == '\0');
-
-	/* Skip any leading white space */
-	for (p = t->b ; vct_islws(*p); p++)
-		continue;
-	if (p == t->e) {
-		/* All white space */
-		t->e = t->b;
-		*t->e = '\0';
-		return (HTC_ALL_WHITESPACE);
-	}
-	while (1) {
-		p = strchr(p, '\n');
-		if (p == NULL)
-			return (HTC_NEED_MORE);
-		p++;
-		if (*p == '\r')
-			p++;
-		if (*p == '\n')
-			break;
-	}
-	p++;
-	i = p - t->b;
-	WS_ReleaseP(htc->ws, htc->rxbuf.e);
-	AZ(htc->pipeline.b);
-	AZ(htc->pipeline.e);
-	if (htc->rxbuf.b + i < htc->rxbuf.e) {
-		htc->pipeline.b = htc->rxbuf.b + i;
-		htc->pipeline.e = htc->rxbuf.e;
-		htc->rxbuf.e = htc->pipeline.b;
-	}
-	return (HTC_COMPLETE);
-}
-
-/*--------------------------------------------------------------------
- * Receive more HTTP protocol bytes
- */
-
-enum htc_status_e
-HTC_Rx(struct http_conn *htc)
-{
-	int i;
-
-	CHECK_OBJ_NOTNULL(htc, HTTP_CONN_MAGIC);
-	AN(htc->ws->r);
-	i = (htc->ws->r - htc->rxbuf.e) - 1;	/* space for NUL */
-	if (i <= 0) {
-		WS_ReleaseP(htc->ws, htc->rxbuf.b);
-		return (HTC_OVERFLOW);
-	}
-	i = read(htc->fd, htc->rxbuf.e, i);
-	if (i <= 0) {
-		/*
-		 * We wouldn't come here if we had a complete HTTP header
-		 * so consequently an EOF can not be OK
-		 */
-		WS_ReleaseP(htc->ws, htc->rxbuf.b);
-		return (HTC_ERROR_EOF);
-	}
-	htc->rxbuf.e += i;
-	*htc->rxbuf.e = '\0';
-	return (HTC_Complete(htc));
-}
-
-/*--------------------------------------------------------------------
- * Read up to len bytes, returning pipelined data first.
- */
-
-ssize_t
-HTC_Read(struct http_conn *htc, void *d, size_t len)
-{
-	size_t l;
-	unsigned char *p;
-	ssize_t i;
-
-	CHECK_OBJ_NOTNULL(htc, HTTP_CONN_MAGIC);
-	l = 0;
-	p = d;
-	if (htc->pipeline.b) {
-		l = Tlen(htc->pipeline);
-		if (l > len)
-			l = len;
-		memcpy(p, htc->pipeline.b, l);
-		p += l;
-		len -= l;
-		htc->pipeline.b += l;
-		if (htc->pipeline.b == htc->pipeline.e)
-			htc->pipeline.b = htc->pipeline.e = NULL;
-	}
-	if (len == 0)
-		return (l);
-	i = read(htc->fd, p, len);
-	if (i < 0) {
-		VSLb(htc->vsl, SLT_FetchError, "%s", strerror(errno));
-		return (i);
-	}
-	return (i + l);
-}



More information about the varnish-commit mailing list