Commit 18fd375e authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

Move backend parsing into a separate file.

Eliminate a bunch of of unnecessary #includes.



git-svn-id: http://www.varnish-cache.org/svn/trunk/varnish-cache@1300 d4fa192b-c00b-0410-8231-f00ffab90ce4
parent 2cce3866
......@@ -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 \
......
......@@ -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
......
......@@ -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)
{
......
......@@ -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"
/*--------------------------------------------------------------------*/
......
/*-
* 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++;
}
......@@ -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[] = {
......
......@@ -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, ...);
......
......@@ -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,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;
......
......@@ -39,11 +39,8 @@
#include "libvarnish.h"
#include "vcc_priv.h"
#include "vcl_returns.h"
#include "vcc_compile.h"
#include "libvcl.h"
/*--------------------------------------------------------------------*/
void
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment