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