]> err.no Git - varnish/commitdiff
Move backend parsing into a separate file.
authorphk <phk@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Sun, 1 Apr 2007 09:34:28 +0000 (09:34 +0000)
committerphk <phk@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Sun, 1 Apr 2007 09:34:28 +0000 (09:34 +0000)
Eliminate a bunch of of unnecessary #includes.

git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@1300 d4fa192b-c00b-0410-8231-f00ffab90ce4

varnish-cache/lib/libvcl/Makefile.am
varnish-cache/lib/libvcl/flint.lnt
varnish-cache/lib/libvcl/vcc_acl.c
varnish-cache/lib/libvcl/vcc_action.c
varnish-cache/lib/libvcl/vcc_backend.c [new file with mode: 0644]
varnish-cache/lib/libvcl/vcc_compile.c
varnish-cache/lib/libvcl/vcc_compile.h
varnish-cache/lib/libvcl/vcc_parse.c
varnish-cache/lib/libvcl/vcc_token.c

index 263156f607c2aac59d33086d019ed0af97faa572..ecf716986e24b3799d818e6237ee1eef3d1fe42d 100644 (file)
@@ -11,6 +11,7 @@ libvcl_la_SOURCES = \
        \
        vcc_acl.c \
        vcc_action.c \
+       vcc_backend.c \
        vcc_compile.c \
        vcc_parse.c \
        vcc_fixed_token.c \
index 94b2c7b219b99166da1b6705628235ff7de847ce..35910f423834282b8aba430996401f7ecb73566a 100644 (file)
@@ -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
 
index b743ce5ac1b66df671de1d1eb61c3565115a77a0..5c2c02d8bb0182d24d59d40348d09e151e6b7e11 100644 (file)
  * $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)
 {
index d3a5a008df01402b80df14ab486eef5e1bf6255b..bf1acc67435b1bc712c419fe90715152d3b4b628 100644 (file)
  * $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"
 
 /*--------------------------------------------------------------------*/
 
diff --git a/varnish-cache/lib/libvcl/vcc_backend.c b/varnish-cache/lib/libvcl/vcc_backend.c
new file mode 100644 (file)
index 0000000..b73385c
--- /dev/null
@@ -0,0 +1,186 @@
+/*-
+ * Copyright (c) 2006 Verdens Gang AS
+ * Copyright (c) 2006 Linpro AS
+ * All rights reserved.
+ *
+ * Author: Poul-Henning Kamp <phk@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++;
+}
index 425b125789bd252c5f2c7b0890d7b816b2dd3edd..7505e397ff547137d69725b68b686fead49d7ebe 100644 (file)
  *     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>
 #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[] = {
index feb5d3e99a033cffd9bcbc94c6337781f7c69036..4a54a047ba30082e677a074ad78c40991979f4e7 100644 (file)
@@ -135,6 +135,9 @@ void vcc_Cond_Ip(struct var *vp, struct tokenlist *tl);
 /* 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, ...);
index b01052b67c58339b6b30c7d8cf2d593ff0136baa..6b485b8eadb3186e32345a27f49e0372f0cfd22e 100644 (file)
  * $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,150 +504,6 @@ Compound(struct tokenlist *tl)
 
 /*--------------------------------------------------------------------*/
 
-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)
 {
@@ -720,7 +562,7 @@ vcc_Parse(struct tokenlist *tl)
                        Function(tl);
                        break;
                case T_BACKEND:
-                       Backend(tl);
+                       vcc_ParseBackend(tl);
                        break;
                case EOI:
                        break;
index ca47c8e2b2ec47c6bcb36f11f557be1137a8fe95..00ff0429888c03e84a90c83871d9ce7fcd3ae274 100644 (file)
 
 #include "libvarnish.h"
 #include "vcc_priv.h"
-#include "vcl_returns.h"
 #include "vcc_compile.h"
 
-#include "libvcl.h"
-
 /*--------------------------------------------------------------------*/
 
 void