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

Move the variable set from being an argument to FindVar to being

a property of the VCC instance.



git-svn-id: http://www.varnish-cache.org/svn/trunk/varnish-cache@5011 d4fa192b-c00b-0410-8231-f00ffab90ce4
parent 549a56b2
......@@ -732,7 +732,7 @@ fo.write("""
#include <stdio.h>
#include "vcc_compile.h"
struct var vcc_vars[] = {
const struct var vcc_vars[] = {
""")
for i in sp_variables:
......
......@@ -65,11 +65,11 @@ parse_call(struct vcc *tl)
static void
parse_error(struct vcc *tl)
{
struct var *vp;
const struct var *vp;
vcc_NextToken(tl);
if (tl->t->tok == ID) {
vp = vcc_FindVar(tl, tl->t, vcc_vars, 0, "cannot be read");
vp = vcc_FindVar(tl, tl->t, 0, "cannot be read");
ERRCHK(tl);
assert(vp != NULL);
if (vp->fmt == INT) {
......@@ -114,13 +114,13 @@ illegal_assignment(const struct vcc *tl, const char *type)
static void
parse_set(struct vcc *tl)
{
struct var *vp;
const struct var *vp;
struct token *at, *vt;
vcc_NextToken(tl);
ExpectErr(tl, ID);
vt = tl->t;
vp = vcc_FindVar(tl, tl->t, vcc_vars, 1, "cannot be set");
vp = vcc_FindVar(tl, tl->t, 1, "cannot be set");
ERRCHK(tl);
assert(vp != NULL);
Fb(tl, 1, "%s", vp->lname);
......@@ -237,11 +237,11 @@ parse_set(struct vcc *tl)
static void
parse_unset(struct vcc *tl)
{
struct var *vp;
const struct var *vp;
vcc_NextToken(tl);
ExpectErr(tl, ID);
vp = vcc_FindVar(tl, tl->t, vcc_vars, 1, "cannot be unset");
vp = vcc_FindVar(tl, tl->t, 1, "cannot be unset");
ERRCHK(tl);
assert(vp != NULL);
if (vp->fmt != STRING || vp->hdr == NULL) {
......
......@@ -461,6 +461,7 @@ vcc_NewVcc(const struct vcc *tl0)
if (tl0 != NULL) {
REPLACE(tl->default_vcl, tl0->default_vcl);
REPLACE(tl->vcl_dir, tl0->vcl_dir);
tl->vars = tl0->vars;
}
VTAILQ_INIT(&tl->hosts);
VTAILQ_INIT(&tl->membits);
......@@ -684,6 +685,7 @@ VCC_New(void)
struct vcc *tl;
tl = vcc_NewVcc(NULL);
tl->vars = vcc_vars;
return (tl);
}
......
......@@ -73,6 +73,8 @@ struct vcc {
char *vcl_dir;
char *vmod_dir;
const struct var *vars;
/* Instance section */
struct tokenhead tokens;
VTAILQ_HEAD(, source) sources;
......@@ -208,7 +210,7 @@ parsedirector_f vcc_ParseRandomDirector;
parsedirector_f vcc_ParseRoundRobinDirector;
/* vcc_obj.c */
extern struct var vcc_vars[];
extern const struct var vcc_vars[];
/* vcc_parse.c */
void vcc_Parse(struct vcc *tl);
......@@ -240,8 +242,8 @@ void vcc_AddToken(struct vcc *tl, unsigned tok, const char *b,
const char *e);
/* vcc_var.c */
struct var *vcc_FindVar(struct vcc *tl, const struct token *t,
struct var *vl, int wr_access, const char *use);
const struct var *vcc_FindVar(struct vcc *tl, const struct token *t,
int wr_access, const char *use);
void vcc_VarVal(struct vcc *tl, const struct var *vp,
const struct token *vt);
......
......@@ -160,10 +160,11 @@ vcl_output_lang_h(struct vsb *sb)
/* ../../include/vcl.h */
vsb_cat(sb, "\n/*\n * $Id$\n *\n * NB: This file is machine "
"generated, DO NOT EDIT!\n *\n * Edit and run generate.py instead"
"\n */\n\nstruct sess;\nstruct cli;\n\ntypedef void vcl_init_f(st"
"ruct cli *);\ntypedef void vcl_fini_f(struct cli *);\n"
vsb_cat(sb, "\n/*\n * $Id: vcl.h 5007 2010-07-05 09:37:53Z "
"phk $\n *\n * NB: This file is machine generated, DO NOT "
"EDIT!\n *\n * Edit and run generate.py instead\n */\n"
"\nstruct sess;\nstruct cli;\n\ntypedef void vcl_init_f(struct "
"cli *);\ntypedef void vcl_fini_f(struct cli *);\n"
"typedef int vcl_func_f(struct sess *sp);\n\n/* VCL Methods "
"*/\n#define VCL_MET_RECV\t\t(1U << 0)\n#define VCL_MET_PIPE\t"
"\t(1U << 1)\n#define VCL_MET_PASS\t\t(1U << 2)\n#define VCL_MET_"
......
......@@ -11,7 +11,7 @@
#include <stdio.h>
#include "vcc_compile.h"
struct var vcc_vars[] = {
const struct var vcc_vars[] = {
{ "client.ip", IP, 9,
"VRT_r_client_ip(sp)",
VCL_MET_RECV | VCL_MET_PIPE | VCL_MET_PASS | VCL_MET_HASH
......
......@@ -326,7 +326,7 @@ vcc_Cond_Backend(const struct var *vp, struct vcc *tl)
static void
vcc_Cond_2(struct vcc *tl)
{
struct var *vp;
const struct var *vp;
C(tl, ",");
if (tl->t->tok == '!') {
......@@ -340,7 +340,7 @@ vcc_Cond_2(struct vcc *tl)
vcc_Cond_0(tl);
SkipToken(tl, ')');
} else if (tl->t->tok == ID) {
vp = vcc_FindVar(tl, tl->t, vcc_vars, 0, "cannot be read");
vp = vcc_FindVar(tl, tl->t, 0, "cannot be read");
ERRCHK(tl);
assert(vp != NULL);
vcc_NextToken(tl);
......
......@@ -142,7 +142,7 @@ vcc_regsub(struct vcc *tl, int all)
int
vcc_StringVal(struct vcc *tl)
{
struct var *vp;
const struct var *vp;
if (tl->t->tok == CSTR) {
EncToken(tl->fb, tl->t);
......@@ -159,7 +159,7 @@ vcc_StringVal(struct vcc *tl)
return 1;
}
if (tl->t->tok == ID) {
vp = vcc_FindVar(tl, tl->t, vcc_vars, 0, "cannot be read");
vp = vcc_FindVar(tl, tl->t, 0, "cannot be read");
if (tl->err)
return (0);
assert(vp != NULL);
......
......@@ -86,13 +86,14 @@ HeaderVar(struct vcc *tl, const struct token *t, const struct var *vh)
/*--------------------------------------------------------------------*/
struct var *
vcc_FindVar(struct vcc *tl, const struct token *t, struct var *vl,
int wr_access, const char *use)
const struct var *
vcc_FindVar(struct vcc *tl, const struct token *t, int wr_access,
const char *use)
{
struct var *v;
const struct var *v;
for (v = vl; v->name != NULL; v++) {
AN(tl->vars);
for (v = tl->vars; v->name != NULL; v++) {
if (v->fmt == HEADER && (t->e - t->b) <= v->len)
continue;
if (v->fmt != HEADER && t->e - t->b != v->len)
......
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