r1300 - trunk/varnish-cache/lib/libvcl

phk at projects.linpro.no phk at projects.linpro.no
Sun Apr 1 11:34:28 CEST 2007


Author: phk
Date: 2007-04-01 11:34:28 +0200 (Sun, 01 Apr 2007)
New Revision: 1300

Added:
   trunk/varnish-cache/lib/libvcl/vcc_backend.c
Modified:
   trunk/varnish-cache/lib/libvcl/Makefile.am
   trunk/varnish-cache/lib/libvcl/flint.lnt
   trunk/varnish-cache/lib/libvcl/vcc_acl.c
   trunk/varnish-cache/lib/libvcl/vcc_action.c
   trunk/varnish-cache/lib/libvcl/vcc_compile.c
   trunk/varnish-cache/lib/libvcl/vcc_compile.h
   trunk/varnish-cache/lib/libvcl/vcc_parse.c
   trunk/varnish-cache/lib/libvcl/vcc_token.c
Log:
Move backend parsing into a separate file.
Eliminate a bunch of of unnecessary #includes.



Modified: trunk/varnish-cache/lib/libvcl/Makefile.am
===================================================================
--- trunk/varnish-cache/lib/libvcl/Makefile.am	2007-04-01 09:17:52 UTC (rev 1299)
+++ trunk/varnish-cache/lib/libvcl/Makefile.am	2007-04-01 09:34:28 UTC (rev 1300)
@@ -11,6 +11,7 @@
 	\
 	vcc_acl.c \
 	vcc_action.c \
+	vcc_backend.c \
 	vcc_compile.c \
 	vcc_parse.c \
 	vcc_fixed_token.c \

Modified: trunk/varnish-cache/lib/libvcl/flint.lnt
===================================================================
--- trunk/varnish-cache/lib/libvcl/flint.lnt	2007-04-01 09:17:52 UTC (rev 1299)
+++ trunk/varnish-cache/lib/libvcl/flint.lnt	2007-04-01 09:34:28 UTC (rev 1300)
@@ -42,7 +42,7 @@
 
 -e785	// Too few initializers for aggregate 
 
--e766	//  Header file '../../include/libvarnish.h' not used in module
+// -e766	//  Header file '../../include/libvarnish.h' not used in module
 
 -e773	// Expression-like macro 'VCL_FARGS' not parenthesized
 

Modified: trunk/varnish-cache/lib/libvcl/vcc_acl.c
===================================================================
--- trunk/varnish-cache/lib/libvcl/vcc_acl.c	2007-04-01 09:17:52 UTC (rev 1299)
+++ trunk/varnish-cache/lib/libvcl/vcc_acl.c	2007-04-01 09:34:28 UTC (rev 1300)
@@ -29,27 +29,13 @@
  * $Id$
  */
 
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <sys/stat.h>
-
-#include <assert.h>
-#include <ctype.h>
-#include <errno.h>
-#include <netdb.h>
 #include <stdio.h>
-#include <stdarg.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
 
 #include "vsb.h"
 
 #include "vcc_priv.h"
 #include "vcc_compile.h"
 
-#include "libvcl.h"
-
 void
 vcc_Cond_Ip(struct var *vp, struct tokenlist *tl)
 {

Modified: trunk/varnish-cache/lib/libvcl/vcc_action.c
===================================================================
--- trunk/varnish-cache/lib/libvcl/vcc_action.c	2007-04-01 09:17:52 UTC (rev 1299)
+++ trunk/varnish-cache/lib/libvcl/vcc_action.c	2007-04-01 09:34:28 UTC (rev 1300)
@@ -29,30 +29,14 @@
  * $Id$
  */
 
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <sys/stat.h>
-
 #include <assert.h>
-#include <ctype.h>
-#include <errno.h>
-#include <fcntl.h>
-#include <netdb.h>
 #include <stdio.h>
-#include <stdarg.h>
-#include <stdlib.h>
-#include <string.h>
-#include <queue.h>
-#include <unistd.h>
 
-#include "compat/asprintf.h"
 #include "vsb.h"
 
 #include "vcc_priv.h"
 #include "vcc_compile.h"
 
-#include "vrt.h"
-#include "libvcl.h"
 
 /*--------------------------------------------------------------------*/
 

Copied: trunk/varnish-cache/lib/libvcl/vcc_backend.c (from rev 1297, trunk/varnish-cache/lib/libvcl/vcc_parse.c)
===================================================================
--- trunk/varnish-cache/lib/libvcl/vcc_parse.c	2007-04-01 08:48:08 UTC (rev 1297)
+++ trunk/varnish-cache/lib/libvcl/vcc_backend.c	2007-04-01 09:34:28 UTC (rev 1300)
@@ -0,0 +1,186 @@
+/*-
+ * Copyright (c) 2006 Verdens Gang AS
+ * Copyright (c) 2006 Linpro 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 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.
+ *
+ * $Id$
+ */
+
+#include <sys/types.h>
+#include <sys/socket.h>
+
+#include <assert.h>
+#include <netdb.h>
+#include <stdio.h>
+#include <string.h>
+
+#include "vsb.h"
+
+#include "vcc_priv.h"
+#include "vcc_compile.h"
+
+
+static const char *
+CheckHostPort(const char *host, const char *port)
+{
+	struct addrinfo *res, hint;
+	int error;
+
+	memset(&hint, 0, sizeof hint);
+	hint.ai_family = PF_UNSPEC;
+	hint.ai_socktype = SOCK_STREAM;
+	error = getaddrinfo(host, port, &hint, &res);
+	if (error)
+		return (gai_strerror(error));
+	freeaddrinfo(res);
+	return (NULL);
+}
+
+void
+vcc_ParseBackend(struct tokenlist *tl)
+{
+	unsigned a;
+	struct var *vp;
+	struct token *t_be = NULL;
+	struct token *t_host = NULL;
+	struct token *t_port = NULL;
+	const char *ep;
+
+	vcc_NextToken(tl);
+	ExpectErr(tl, ID);
+	t_be = tl->t;
+	vcc_AddDef(tl, tl->t, R_BACKEND);
+	if (tl->nbackend == 0)
+		vcc_AddRef(tl, tl->t, R_BACKEND);
+	Fh(tl, 1, "#define VGC_backend_%.*s (VCL_conf.backend[%d])\n",
+	    PF(tl->t), tl->nbackend);
+	Fc(tl, 0, "\n");
+	Fc(tl, 0, "static void\n");
+	Fc(tl, 1, "VGC_init_backend_%.*s (void)\n", PF(tl->t));
+	Fc(tl, 1, "{\n");
+	Fc(tl, 1, "\tstruct backend *backend = VGC_backend_%.*s;\n", PF(tl->t));
+	Fc(tl, 1, "\n");
+	Fc(tl, 1, "\tVRT_set_backend_name(backend, \"%.*s\");\n", PF(tl->t));
+	vcc_NextToken(tl);
+	ExpectErr(tl, '{');
+	vcc_NextToken(tl);
+	while (1) {
+		if (tl->t->tok == '}')
+			break;
+		ExpectErr(tl, ID);
+		if (!vcc_IdIs(tl->t, "set")) {
+			vsb_printf(tl->sb,
+			    "Expected 'set', found ");
+			vcc_ErrToken(tl, tl->t);
+			vsb_printf(tl->sb, " at\n");
+			vcc_ErrWhere(tl, tl->t);
+			return;
+		}
+		vcc_NextToken(tl);
+		ExpectErr(tl, VAR);
+		vp = FindVar(tl, tl->t, vcc_be_vars);
+		ERRCHK(tl);
+		assert(vp != NULL);
+		vcc_NextToken(tl);
+		ExpectErr(tl, '=');
+		vcc_NextToken(tl);
+		switch (vp->fmt) {
+		case HOSTNAME:
+			ExpectErr(tl, CSTR);
+			t_host = tl->t;
+			Fc(tl, 1, "\t%s ", vp->lname);
+			EncToken(tl->fc, t_host);
+			Fc(tl, 0, ");\n");
+			vcc_NextToken(tl);
+			break;
+		case PORTNAME:
+			ExpectErr(tl, CSTR);
+			t_port = tl->t;
+			Fc(tl, 1, "\t%s ", vp->lname);
+			EncToken(tl->fc, t_port);
+			Fc(tl, 0, ");\n");
+			vcc_NextToken(tl);
+			break;
+#if 0
+		case INT:
+		case SIZE:
+		case RATE:
+		case FLOAT:
+#endif
+		case TIME:
+			Fc(tl, 1, "\t%s ", vp->lname);
+			a = tl->t->tok;
+			if (a == T_MUL || a == T_DIV)
+				Fc(tl, 0, "%g", vcc_DoubleVal(tl));
+			else if (vp->fmt == TIME)
+				vcc_TimeVal(tl);
+			else if (vp->fmt == SIZE)
+				vcc_SizeVal(tl);
+			else if (vp->fmt == RATE)
+				vcc_RateVal(tl);
+			else
+				Fc(tl, 0, "%g", vcc_DoubleVal(tl));
+			Fc(tl, 0, ");\n");
+			break;
+		default:
+			vsb_printf(tl->sb,
+			    "Assignments not possible for '%s'\n", vp->name);
+			vcc_ErrWhere(tl, tl->t);
+			return;
+		}
+		ExpectErr(tl, ';');
+		vcc_NextToken(tl);
+	}
+	ExpectErr(tl, '}');
+	if (t_host == NULL) {
+		vsb_printf(tl->sb, "Backend '%.*s' has no hostname\n",
+		    PF(t_be));
+		vcc_ErrWhere(tl, tl->t);
+		return;
+	}
+	ep = CheckHostPort(t_host->dec, "80");
+	if (ep != NULL) {
+		vsb_printf(tl->sb, "Backend '%.*s': %s\n", PF(t_be), ep);
+		vcc_ErrWhere(tl, t_host);
+		return;
+	}
+	if (t_port != NULL) {
+		ep = CheckHostPort(t_host->dec, t_port->dec);
+		if (ep != NULL) {
+			vsb_printf(tl->sb,
+			    "Backend '%.*s': %s\n", PF(t_be), ep);
+			vcc_ErrWhere(tl, t_port);
+			return;
+		}
+	}
+
+	vcc_NextToken(tl);
+	Fc(tl, 1, "}\n");
+	Fc(tl, 0, "\n");
+	Fi(tl, 0, "\tVGC_init_backend_%.*s();\n", PF(t_be));
+	Ff(tl, 0, "\tVRT_fini_backend(VGC_backend_%.*s);\n", PF(t_be));
+	tl->nbackend++;
+}

Modified: trunk/varnish-cache/lib/libvcl/vcc_compile.c
===================================================================
--- trunk/varnish-cache/lib/libvcl/vcc_compile.c	2007-04-01 09:17:52 UTC (rev 1299)
+++ trunk/varnish-cache/lib/libvcl/vcc_compile.c	2007-04-01 09:34:28 UTC (rev 1300)
@@ -60,15 +60,10 @@
  *	and all the rest...
  */
 
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <sys/stat.h>
-
 #include <assert.h>
 #include <ctype.h>
 #include <errno.h>
 #include <fcntl.h>
-#include <netdb.h>
 #include <stdio.h>
 #include <stdarg.h>
 #include <stdlib.h>
@@ -76,13 +71,13 @@
 #include <queue.h>
 #include <unistd.h>
 
-#include "compat/asprintf.h"
+#include <sys/stat.h>
+
 #include "vsb.h"
 
 #include "vcc_priv.h"
 #include "vcc_compile.h"
 
-#include "vrt.h"
 #include "libvcl.h"
 
 struct method method_tab[] = {

Modified: trunk/varnish-cache/lib/libvcl/vcc_compile.h
===================================================================
--- trunk/varnish-cache/lib/libvcl/vcc_compile.h	2007-04-01 09:17:52 UTC (rev 1299)
+++ trunk/varnish-cache/lib/libvcl/vcc_compile.h	2007-04-01 09:34:28 UTC (rev 1300)
@@ -135,6 +135,9 @@
 /* vcc_action.c */
 void vcc_ParseAction(struct tokenlist *tl);
 
+/* vcc_backend.c */
+void vcc_ParseBackend(struct tokenlist *tl);
+
 /* vcc_compile.c */
 extern struct method method_tab[];
 void Fh(struct tokenlist *tl, int indent, const char *fmt, ...);

Modified: trunk/varnish-cache/lib/libvcl/vcc_parse.c
===================================================================
--- trunk/varnish-cache/lib/libvcl/vcc_parse.c	2007-04-01 09:17:52 UTC (rev 1299)
+++ trunk/varnish-cache/lib/libvcl/vcc_parse.c	2007-04-01 09:34:28 UTC (rev 1300)
@@ -29,30 +29,16 @@
  * $Id$
  */
 
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <sys/stat.h>
-
 #include <assert.h>
-#include <ctype.h>
-#include <errno.h>
-#include <fcntl.h>
-#include <netdb.h>
 #include <stdio.h>
-#include <stdarg.h>
-#include <stdlib.h>
 #include <string.h>
-#include <queue.h>
-#include <unistd.h>
 
-#include "compat/asprintf.h"
 #include "vsb.h"
 
 #include "vcc_priv.h"
 #include "vcc_compile.h"
 
 #include "vrt.h"
-#include "libvcl.h"
 
 /*--------------------------------------------------------------------*/
 
@@ -518,151 +504,7 @@
 
 /*--------------------------------------------------------------------*/
 
-static const char *
-CheckHostPort(const char *host, const char *port)
-{
-	struct addrinfo *res, hint;
-	int error;
-
-	memset(&hint, 0, sizeof hint);
-	hint.ai_family = PF_UNSPEC;
-	hint.ai_socktype = SOCK_STREAM;
-	error = getaddrinfo(host, port, &hint, &res);
-	if (error)
-		return (gai_strerror(error));
-	freeaddrinfo(res);
-	return (NULL);
-}
-
 static void
-Backend(struct tokenlist *tl)
-{
-	unsigned a;
-	struct var *vp;
-	struct token *t_be = NULL;
-	struct token *t_host = NULL;
-	struct token *t_port = NULL;
-	const char *ep;
-
-	vcc_NextToken(tl);
-	ExpectErr(tl, ID);
-	t_be = tl->t;
-	vcc_AddDef(tl, tl->t, R_BACKEND);
-	if (tl->nbackend == 0)
-		vcc_AddRef(tl, tl->t, R_BACKEND);
-	Fh(tl, 1, "#define VGC_backend_%.*s (VCL_conf.backend[%d])\n",
-	    PF(tl->t), tl->nbackend);
-	Fc(tl, 0, "\n");
-	Fc(tl, 0, "static void\n");
-	Fc(tl, 1, "VGC_init_backend_%.*s (void)\n", PF(tl->t));
-	Fc(tl, 1, "{\n");
-	Fc(tl, 1, "\tstruct backend *backend = VGC_backend_%.*s;\n", PF(tl->t));
-	Fc(tl, 1, "\n");
-	Fc(tl, 1, "\tVRT_set_backend_name(backend, \"%.*s\");\n", PF(tl->t));
-	vcc_NextToken(tl);
-	ExpectErr(tl, '{');
-	vcc_NextToken(tl);
-	while (1) {
-		if (tl->t->tok == '}')
-			break;
-		ExpectErr(tl, ID);
-		if (!vcc_IdIs(tl->t, "set")) {
-			vsb_printf(tl->sb,
-			    "Expected 'set', found ");
-			vcc_ErrToken(tl, tl->t);
-			vsb_printf(tl->sb, " at\n");
-			vcc_ErrWhere(tl, tl->t);
-			return;
-		}
-		vcc_NextToken(tl);
-		ExpectErr(tl, VAR);
-		vp = FindVar(tl, tl->t, vcc_be_vars);
-		ERRCHK(tl);
-		assert(vp != NULL);
-		vcc_NextToken(tl);
-		ExpectErr(tl, '=');
-		vcc_NextToken(tl);
-		switch (vp->fmt) {
-		case HOSTNAME:
-			ExpectErr(tl, CSTR);
-			t_host = tl->t;
-			Fc(tl, 1, "\t%s ", vp->lname);
-			EncToken(tl->fc, t_host);
-			Fc(tl, 0, ");\n");
-			vcc_NextToken(tl);
-			break;
-		case PORTNAME:
-			ExpectErr(tl, CSTR);
-			t_port = tl->t;
-			Fc(tl, 1, "\t%s ", vp->lname);
-			EncToken(tl->fc, t_port);
-			Fc(tl, 0, ");\n");
-			vcc_NextToken(tl);
-			break;
-#if 0
-		case INT:
-		case SIZE:
-		case RATE:
-		case FLOAT:
-#endif
-		case TIME:
-			Fc(tl, 1, "\t%s ", vp->lname);
-			a = tl->t->tok;
-			if (a == T_MUL || a == T_DIV)
-				Fc(tl, 0, "%g", vcc_DoubleVal(tl));
-			else if (vp->fmt == TIME)
-				vcc_TimeVal(tl);
-			else if (vp->fmt == SIZE)
-				vcc_SizeVal(tl);
-			else if (vp->fmt == RATE)
-				vcc_RateVal(tl);
-			else
-				Fc(tl, 0, "%g", vcc_DoubleVal(tl));
-			Fc(tl, 0, ");\n");
-			break;
-		default:
-			vsb_printf(tl->sb,
-			    "Assignments not possible for '%s'\n", vp->name);
-			vcc_ErrWhere(tl, tl->t);
-			return;
-		}
-		ExpectErr(tl, ';');
-		vcc_NextToken(tl);
-	}
-	ExpectErr(tl, '}');
-	if (t_host == NULL) {
-		vsb_printf(tl->sb, "Backend '%.*s' has no hostname\n",
-		    PF(t_be));
-		vcc_ErrWhere(tl, tl->t);
-		return;
-	}
-	ep = CheckHostPort(t_host->dec, "80");
-	if (ep != NULL) {
-		vsb_printf(tl->sb, "Backend '%.*s': %s\n", PF(t_be), ep);
-		vcc_ErrWhere(tl, t_host);
-		return;
-	}
-	if (t_port != NULL) {
-		ep = CheckHostPort(t_host->dec, t_port->dec);
-		if (ep != NULL) {
-			vsb_printf(tl->sb,
-			    "Backend '%.*s': %s\n", PF(t_be), ep);
-			vcc_ErrWhere(tl, t_port);
-			return;
-		}
-	}
-
-	vcc_NextToken(tl);
-	Fc(tl, 1, "}\n");
-	Fc(tl, 0, "\n");
-	Fi(tl, 0, "\tVGC_init_backend_%.*s();\n", PF(t_be));
-	Ff(tl, 0, "\tVRT_fini_backend(VGC_backend_%.*s);\n", PF(t_be));
-	tl->nbackend++;
-}
-
-/*--------------------------------------------------------------------*/
-
-static void
 Function(struct tokenlist *tl)
 {
 	int m;
@@ -720,7 +562,7 @@
 			Function(tl);
 			break;
 		case T_BACKEND:
-			Backend(tl);
+			vcc_ParseBackend(tl);
 			break;
 		case EOI:
 			break;

Modified: trunk/varnish-cache/lib/libvcl/vcc_token.c
===================================================================
--- trunk/varnish-cache/lib/libvcl/vcc_token.c	2007-04-01 09:17:52 UTC (rev 1299)
+++ trunk/varnish-cache/lib/libvcl/vcc_token.c	2007-04-01 09:34:28 UTC (rev 1300)
@@ -39,11 +39,8 @@
 
 #include "libvarnish.h"
 #include "vcc_priv.h"
-#include "vcl_returns.h"
 #include "vcc_compile.h"
 
-#include "libvcl.h"
-
 /*--------------------------------------------------------------------*/
 
 void




More information about the varnish-commit mailing list