r2885 - trunk/varnish-cache/lib/libvcl
phk at projects.linpro.no
phk at projects.linpro.no
Mon Jul 7 20:02:07 CEST 2008
Author: phk
Date: 2008-07-07 20:02:06 +0200 (Mon, 07 Jul 2008)
New Revision: 2885
Added:
trunk/varnish-cache/lib/libvcl/vcc_dir_random.c
Modified:
trunk/varnish-cache/lib/libvcl/Makefile.am
trunk/varnish-cache/lib/libvcl/vcc_backend.c
trunk/varnish-cache/lib/libvcl/vcc_priv.h
Log:
Move random director to separate source file.
Modified: trunk/varnish-cache/lib/libvcl/Makefile.am
===================================================================
--- trunk/varnish-cache/lib/libvcl/Makefile.am 2008-07-07 17:42:42 UTC (rev 2884)
+++ trunk/varnish-cache/lib/libvcl/Makefile.am 2008-07-07 18:02:06 UTC (rev 2885)
@@ -13,6 +13,7 @@
vcc_action.c \
vcc_backend.c \
vcc_compile.c \
+ vcc_dir_random.c \
vcc_parse.c \
vcc_fixed_token.c \
vcc_obj.c \
Modified: trunk/varnish-cache/lib/libvcl/vcc_backend.c
===================================================================
--- trunk/varnish-cache/lib/libvcl/vcc_backend.c 2008-07-07 17:42:42 UTC (rev 2884)
+++ trunk/varnish-cache/lib/libvcl/vcc_backend.c 2008-07-07 18:02:06 UTC (rev 2885)
@@ -100,7 +100,7 @@
struct token *found;
};
-static void
+void
vcc_ResetFldSpec(struct fld_spec *f)
{
@@ -108,7 +108,7 @@
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 @@
}
-static void
+void
vcc_IsField(struct tokenlist *tl, struct token **t, struct fld_spec *fs)
{
struct token *t_field;
@@ -172,7 +172,7 @@
return;
}
-static int
+int
vcc_FieldsOk(struct tokenlist *tl, const struct fld_spec *fs)
{
int ok = 1;
@@ -322,7 +322,7 @@
* 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;
@@ -405,94 +405,6 @@
* 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
- */
-
void
vcc_ParseDirector(struct tokenlist *tl)
{
Copied: trunk/varnish-cache/lib/libvcl/vcc_dir_random.c (from rev 2883, trunk/varnish-cache/lib/libvcl/vcc_backend.c)
===================================================================
--- trunk/varnish-cache/lib/libvcl/vcc_dir_random.c (rev 0)
+++ trunk/varnish-cache/lib/libvcl/vcc_dir_random.c 2008-07-07 18:02:06 UTC (rev 2885)
@@ -0,0 +1,134 @@
+/*-
+ * Copyright (c) 2006 Verdens Gang AS
+ * Copyright (c) 2006-2008 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 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));
+}
Property changes on: trunk/varnish-cache/lib/libvcl/vcc_dir_random.c
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:mergeinfo
+
Modified: trunk/varnish-cache/lib/libvcl/vcc_priv.h
===================================================================
--- trunk/varnish-cache/lib/libvcl/vcc_priv.h 2008-07-07 17:42:42 UTC (rev 2884)
+++ trunk/varnish-cache/lib/libvcl/vcc_priv.h 2008-07-07 18:02:06 UTC (rev 2885)
@@ -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_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);
+
More information about the varnish-commit
mailing list