Commit e5054a03 authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

Move random director to separate source file.



git-svn-id: http://www.varnish-cache.org/svn/trunk/varnish-cache@2885 d4fa192b-c00b-0410-8231-f00ffab90ce4
parent f0e7b287
......@@ -13,6 +13,7 @@ libvcl_la_SOURCES = \
vcc_action.c \
vcc_backend.c \
vcc_compile.c \
vcc_dir_random.c \
vcc_parse.c \
vcc_fixed_token.c \
vcc_obj.c \
......
......@@ -100,7 +100,7 @@ struct fld_spec {
struct token *found;
};
static void
void
vcc_ResetFldSpec(struct fld_spec *f)
{
......@@ -108,7 +108,7 @@ vcc_ResetFldSpec(struct fld_spec *f)
f->found = NULL;
}
static struct fld_spec *
struct fld_spec *
vcc_FldSpec(struct tokenlist *tl, const char *first, ...)
{
struct fld_spec f[100], *r;
......@@ -136,7 +136,7 @@ vcc_FldSpec(struct tokenlist *tl, const char *first, ...)
}
static void
void
vcc_IsField(struct tokenlist *tl, struct token **t, struct fld_spec *fs)
{
struct token *t_field;
......@@ -172,7 +172,7 @@ vcc_IsField(struct tokenlist *tl, struct token **t, struct fld_spec *fs)
return;
}
static int
int
vcc_FieldsOk(struct tokenlist *tl, const struct fld_spec *fs)
{
int ok = 1;
......@@ -322,7 +322,7 @@ vcc_ParseHostDef(struct tokenlist *tl, int *nbh, const struct token *name, const
* The struct vrt_backend is emitted to Fh().
*/
static void
void
vcc_ParseBackendHost(struct tokenlist *tl, int *nbh, const struct token *name, const char *qual, int serial)
{
struct host *h;
......@@ -401,94 +401,6 @@ vcc_ParseBackend(struct tokenlist *tl)
tl->nbackend++;
}
/*--------------------------------------------------------------------
* Parse directors
*/
static void
vcc_ParseRandomDirector(struct tokenlist *tl, struct token *t_dir)
{
struct token *t_field, *t_be;
int nbh, nelem;
struct fld_spec *fs;
unsigned u;
Fh(tl, 1, "\n#define VGC_backend_%.*s (VCL_conf.director[%d])\n",
PF(t_dir), tl->nbackend);
vcc_AddDef(tl, t_dir, R_BACKEND);
fs = vcc_FldSpec(tl, "!backend", "!weight", NULL);
vcc_NextToken(tl); /* ID: policy (= random) */
ExpectErr(tl, '{');
vcc_NextToken(tl);
Fc(tl, 0,
"\nstatic const struct vrt_dir_random_entry vdre_%.*s[] = {\n",
PF(t_dir));
for (nelem = 0; tl->t->tok != '}'; nelem++) { /* List of members */
t_be = tl->t;
vcc_ResetFldSpec(fs);
nbh = -1;
ExpectErr(tl, '{');
vcc_NextToken(tl);
Fc(tl, 0, "\t{");
while (tl->t->tok != '}') { /* Member fields */
vcc_IsField(tl, &t_field, fs);
ERRCHK(tl);
if (vcc_IdIs(t_field, "backend")) {
vcc_ParseBackendHost(tl, &nbh,
t_dir, "random", nelem);
Fc(tl, 0, " .host = &bh_%d,", nbh);
ERRCHK(tl);
} else if (vcc_IdIs(t_field, "weight")) {
ExpectErr(tl, CNUM);
u = vcc_UintVal(tl);
if (u == 0) {
vsb_printf(tl->sb,
"The .weight must be higher than zero.");
vcc_ErrToken(tl, tl->t);
vsb_printf(tl->sb, " at\n");
vcc_ErrWhere(tl, tl->t);
return;
}
Fc(tl, 0, " .weight = %u", u);
vcc_NextToken(tl);
ExpectErr(tl, ';');
vcc_NextToken(tl);
} else {
ErrInternal(tl);
}
}
if (!vcc_FieldsOk(tl, fs)) {
vsb_printf(tl->sb,
"\nIn member host specfication starting at:\n");
vcc_ErrWhere(tl, t_be);
return;
}
Fc(tl, 0, " },\n");
vcc_NextToken(tl);
}
Fc(tl, 0, "\t{ .host = 0 }\n");
Fc(tl, 0, "};\n");
Fc(tl, 0,
"\nstatic const struct vrt_dir_random vdr_%.*s = {\n",
PF(t_dir));
Fc(tl, 0, "\t.name = \"%.*s\",\n", PF(t_dir));
Fc(tl, 0, "\t.nmember = %d,\n", nelem);
Fc(tl, 0, "\t.members = vdre_%.*s,\n", PF(t_dir));
Fc(tl, 0, "};\n");
vcc_NextToken(tl);
Fi(tl, 0,
"\tVRT_init_dir_random(cli, &VGC_backend_%.*s , &vdr_%.*s);\n",
PF(t_dir), PF(t_dir));
Ff(tl, 0, "\tVRT_fini_dir(cli, VGC_backend_%.*s);\n", PF(t_dir));
}
/*--------------------------------------------------------------------
* Parse directors
*/
......
/*-
* Copyright (c) 2006 Verdens Gang AS
* Copyright (c) 2006-2008 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 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.
*
* $Id$
*/
#include "config.h"
#include <sys/types.h>
#include <sys/socket.h>
#include <netdb.h>
#include <stdio.h>
#include <stdarg.h>
#include <string.h>
#include "vsb.h"
#include "vcc_priv.h"
#include "vcc_compile.h"
#include "libvarnish.h"
/*--------------------------------------------------------------------
* Parse directors
*/
void
vcc_ParseRandomDirector(struct tokenlist *tl, struct token *t_dir)
{
struct token *t_field, *t_be;
int nbh, nelem;
struct fld_spec *fs;
unsigned u;
Fh(tl, 1, "\n#define VGC_backend_%.*s (VCL_conf.director[%d])\n",
PF(t_dir), tl->nbackend);
vcc_AddDef(tl, t_dir, R_BACKEND);
fs = vcc_FldSpec(tl, "!backend", "!weight", NULL);
vcc_NextToken(tl); /* ID: policy (= random) */
ExpectErr(tl, '{');
vcc_NextToken(tl);
Fc(tl, 0,
"\nstatic const struct vrt_dir_random_entry vdre_%.*s[] = {\n",
PF(t_dir));
for (nelem = 0; tl->t->tok != '}'; nelem++) { /* List of members */
t_be = tl->t;
vcc_ResetFldSpec(fs);
nbh = -1;
ExpectErr(tl, '{');
vcc_NextToken(tl);
Fc(tl, 0, "\t{");
while (tl->t->tok != '}') { /* Member fields */
vcc_IsField(tl, &t_field, fs);
ERRCHK(tl);
if (vcc_IdIs(t_field, "backend")) {
vcc_ParseBackendHost(tl, &nbh,
t_dir, "random", nelem);
Fc(tl, 0, " .host = &bh_%d,", nbh);
ERRCHK(tl);
} else if (vcc_IdIs(t_field, "weight")) {
ExpectErr(tl, CNUM);
u = vcc_UintVal(tl);
if (u == 0) {
vsb_printf(tl->sb,
"The .weight must be higher than zero.");
vcc_ErrToken(tl, tl->t);
vsb_printf(tl->sb, " at\n");
vcc_ErrWhere(tl, tl->t);
return;
}
Fc(tl, 0, " .weight = %u", u);
vcc_NextToken(tl);
ExpectErr(tl, ';');
vcc_NextToken(tl);
} else {
ErrInternal(tl);
}
}
if (!vcc_FieldsOk(tl, fs)) {
vsb_printf(tl->sb,
"\nIn member host specfication starting at:\n");
vcc_ErrWhere(tl, t_be);
return;
}
Fc(tl, 0, " },\n");
vcc_NextToken(tl);
}
Fc(tl, 0, "\t{ .host = 0 }\n");
Fc(tl, 0, "};\n");
Fc(tl, 0,
"\nstatic const struct vrt_dir_random vdr_%.*s = {\n",
PF(t_dir));
Fc(tl, 0, "\t.name = \"%.*s\",\n", PF(t_dir));
Fc(tl, 0, "\t.nmember = %d,\n", nelem);
Fc(tl, 0, "\t.members = vdre_%.*s,\n", PF(t_dir));
Fc(tl, 0, "};\n");
vcc_NextToken(tl);
Fi(tl, 0,
"\tVRT_init_dir_random(cli, &VGC_backend_%.*s , &vdr_%.*s);\n",
PF(t_dir), PF(t_dir));
Ff(tl, 0, "\tVRT_fini_dir(cli, VGC_backend_%.*s);\n", PF(t_dir));
}
......@@ -34,6 +34,8 @@
#include "vcc_token_defs.h"
struct vsb;
struct tokenlist;
struct token;
#define isident1(c) (isalpha(c))
#define isident(c) (isalpha(c) || isdigit(c) || (c) == '_' || (c) == '-')
......@@ -44,3 +46,18 @@ void vcl_init_tnames(void);
void vcl_output_lang_h(struct vsb *sb);
#define PF(t) (int)((t)->e - (t)->b), (t)->b
/* vcc_backend.c */
struct fld_spec;
struct fld_spec * vcc_FldSpec(struct tokenlist *tl, const char *first, ...);
void vcc_ResetFldSpec(struct fld_spec *f);
void vcc_IsField(struct tokenlist *tl, struct token **t, struct fld_spec *fs);
int vcc_FieldsOk(struct tokenlist *tl, const struct fld_spec *fs);
void vcc_ParseBackendHost(struct tokenlist *tl, int *nbh, const struct token *name, const char *qual, int serial);
/* vcc_dir_random.c */
void vcc_ParseRandomDirector(struct tokenlist *tl, struct token *t_dir);
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