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

Use an enum instead of magic '1' and '2' values to VRT_GetHdr.

Remove bogus "has_string" variable marking, it can be derived from the type.

Make obj.* variables valid in vcl_timeout() and vcl_discard()



git-svn-id: http://www.varnish-cache.org/svn/trunk/varnish-cache@1554 d4fa192b-c00b-0410-8231-f00ffab90ce4
parent 177be95c
......@@ -71,17 +71,17 @@ VRT_count(struct sess *sp, unsigned u)
/*--------------------------------------------------------------------*/
char *
VRT_GetHdr(struct sess *sp, int where, const char *n)
VRT_GetHdr(struct sess *sp, enum gethdr_e where, const char *n)
{
char *p;
struct http *hp;
CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
switch (where) {
case 1:
case HDR_REQ:
hp = sp->http;
break;
case 2:
case HDR_RESP:
hp = &sp->obj->http;
break;
default:
......
......@@ -74,7 +74,8 @@ int VRT_rewrite(const char *, const char *);
void VRT_error(struct sess *, unsigned, const char *);
int VRT_switch_config(const char *);
char *VRT_GetHdr(struct sess *, int where, const char *);
enum gethdr_e { HDR_REQ, HDR_RESP };
char *VRT_GetHdr(struct sess *, enum gethdr_e where, const char *);
void VRT_handling(struct sess *sp, unsigned hand);
/* Backend related */
......
......@@ -120,7 +120,6 @@ struct var {
unsigned len;
const char *rname;
const char *lname;
unsigned has_string;
unsigned methods;
};
......
......@@ -428,7 +428,8 @@ vcl_output_lang_h(struct vsb *sb)
vsb_cat(sb, "void VRT_error(struct sess *, unsigned, const char *);\n");
vsb_cat(sb, "int VRT_switch_config(const char *);\n");
vsb_cat(sb, "\n");
vsb_cat(sb, "char *VRT_GetHdr(struct sess *, int where, const char *);\n");
vsb_cat(sb, "enum gethdr_e { HDR_REQ, HDR_RESP };\n");
vsb_cat(sb, "char *VRT_GetHdr(struct sess *, enum gethdr_e where, const char *);\n");
vsb_cat(sb, "void VRT_handling(struct sess *sp, unsigned hand);\n");
vsb_cat(sb, "\n");
vsb_cat(sb, "/* Backend related */\n");
......@@ -471,6 +472,8 @@ vcl_output_lang_h(struct vsb *sb)
vsb_cat(sb, "void VRT_l_req_proto(struct sess *, const char *);\n");
vsb_cat(sb, "struct backend * VRT_r_req_backend(struct sess *);\n");
vsb_cat(sb, "void VRT_l_req_backend(struct sess *, struct backend *);\n");
vsb_cat(sb, "const char * VRT_r_req_http_(struct sess *);\n");
vsb_cat(sb, "void VRT_l_req_http_(struct sess *, const char *);\n");
vsb_cat(sb, "const char * VRT_r_req_hash(struct sess *);\n");
vsb_cat(sb, "void VRT_l_req_hash(struct sess *, const char *);\n");
vsb_cat(sb, "unsigned VRT_r_obj_valid(struct sess *);\n");
......@@ -479,8 +482,6 @@ vcl_output_lang_h(struct vsb *sb)
vsb_cat(sb, "void VRT_l_obj_cacheable(struct sess *, unsigned);\n");
vsb_cat(sb, "double VRT_r_obj_ttl(struct sess *);\n");
vsb_cat(sb, "void VRT_l_obj_ttl(struct sess *, double);\n");
vsb_cat(sb, "const char * VRT_r_req_http_(struct sess *);\n");
vsb_cat(sb, "void VRT_l_req_http_(struct sess *, const char *);\n");
vsb_cat(sb, "const char * VRT_r_resp_http_(struct sess *);\n");
vsb_cat(sb, "void VRT_l_resp_http_(struct sess *, const char *);\n");
}
......@@ -32,53 +32,27 @@
# Objects which operate on backends
set beobj {
{ backend.host HOSTNAME 0 }
{ backend.port PORTNAME 0 }
{ backend.dnsttl TIME 0 }
{ backend.host HOSTNAME }
{ backend.port PORTNAME }
{ backend.dnsttl TIME }
}
# Objects which operate on sessions
set spobj {
{ client.ip IP 1
{recv pipe pass hash miss hit fetch}
}
{ server.ip IP 1
{recv pipe pass hash miss hit fetch}
}
{ req.request STRING 1
{recv pipe pass hash miss hit fetch}
}
{ req.host STRING 1
{recv pipe pass hash miss hit fetch}
}
{ req.url STRING 1
{recv pipe pass hash miss hit fetch}
}
{ req.proto STRING 1
{recv pipe pass hash miss hit fetch}
}
{ req.backend BACKEND 0
{recv pipe pass hash miss hit fetch}
}
{ req.http. HEADER 1
{recv pipe pass hash miss hit fetch}
}
{ req.hash HASH 0
{hash}
}
{ obj.valid BOOL 0
{hit fetch}
}
{ obj.cacheable BOOL 0
{hit fetch}
}
{ obj.ttl TIME 0
{hit fetch}
}
{ resp.http. HEADER 1
{fetch}
}
{ client.ip IP {recv pipe pass hash miss hit fetch } }
{ server.ip IP {recv pipe pass hash miss hit fetch } }
{ req.request STRING {recv pipe pass hash miss hit fetch } }
{ req.host STRING {recv pipe pass hash miss hit fetch } }
{ req.url STRING {recv pipe pass hash miss hit fetch } }
{ req.proto STRING {recv pipe pass hash miss hit fetch } }
{ req.backend BACKEND {recv pipe pass hash miss hit fetch } }
{ req.http. HEADER {recv pipe pass hash miss hit fetch } }
{ req.hash HASH { hash } }
{ obj.valid BOOL { hit fetch discard timeout} }
{ obj.cacheable BOOL { hit fetch discard timeout} }
{ obj.ttl TIME { hit fetch discard timeout} }
{ resp.http. HEADER { fetch } }
}
set tt(IP) "struct sockaddr *"
......@@ -131,8 +105,7 @@ proc vars {v ty pa} {
puts $fo "\t\{ \"$n\", $t, [string length $n],"
puts $fo "\t \"VRT_r_${m}($pa)\","
puts $fo "\t \"VRT_l_${m}($pa, \","
puts $fo "\t [lindex $v 2], "
puts $fo "\t [method_map [lindex $v 3]]"
puts $fo "\t [method_map [lindex $v 2]]"
puts $fo "\t\},"
puts $fp "$tt($t) VRT_r_${m}($ty);"
......
......@@ -13,19 +13,16 @@ struct var vcc_be_vars[] = {
{ "backend.host", HOSTNAME, 12,
"VRT_r_backend_host(backend)",
"VRT_l_backend_host(backend, ",
0,
},
{ "backend.port", PORTNAME, 12,
"VRT_r_backend_port(backend)",
"VRT_l_backend_port(backend, ",
0,
},
{ "backend.dnsttl", TIME, 14,
"VRT_r_backend_dnsttl(backend)",
"VRT_l_backend_dnsttl(backend, ",
0,
},
{ NULL }
......@@ -35,79 +32,66 @@ struct var vcc_vars[] = {
{ "client.ip", IP, 9,
"VRT_r_client_ip(sp)",
"VRT_l_client_ip(sp, ",
1,
VCL_MET_RECV | VCL_MET_PIPE | VCL_MET_PASS | VCL_MET_HASH | VCL_MET_MISS | VCL_MET_HIT | VCL_MET_FETCH
},
{ "server.ip", IP, 9,
"VRT_r_server_ip(sp)",
"VRT_l_server_ip(sp, ",
1,
VCL_MET_RECV | VCL_MET_PIPE | VCL_MET_PASS | VCL_MET_HASH | VCL_MET_MISS | VCL_MET_HIT | VCL_MET_FETCH
},
{ "req.request", STRING, 11,
"VRT_r_req_request(sp)",
"VRT_l_req_request(sp, ",
1,
VCL_MET_RECV | VCL_MET_PIPE | VCL_MET_PASS | VCL_MET_HASH | VCL_MET_MISS | VCL_MET_HIT | VCL_MET_FETCH
},
{ "req.host", STRING, 8,
"VRT_r_req_host(sp)",
"VRT_l_req_host(sp, ",
1,
VCL_MET_RECV | VCL_MET_PIPE | VCL_MET_PASS | VCL_MET_HASH | VCL_MET_MISS | VCL_MET_HIT | VCL_MET_FETCH
},
{ "req.url", STRING, 7,
"VRT_r_req_url(sp)",
"VRT_l_req_url(sp, ",
1,
VCL_MET_RECV | VCL_MET_PIPE | VCL_MET_PASS | VCL_MET_HASH | VCL_MET_MISS | VCL_MET_HIT | VCL_MET_FETCH
},
{ "req.proto", STRING, 9,
"VRT_r_req_proto(sp)",
"VRT_l_req_proto(sp, ",
1,
VCL_MET_RECV | VCL_MET_PIPE | VCL_MET_PASS | VCL_MET_HASH | VCL_MET_MISS | VCL_MET_HIT | VCL_MET_FETCH
},
{ "req.backend", BACKEND, 11,
"VRT_r_req_backend(sp)",
"VRT_l_req_backend(sp, ",
0,
VCL_MET_RECV | VCL_MET_PIPE | VCL_MET_PASS | VCL_MET_HASH | VCL_MET_MISS | VCL_MET_HIT | VCL_MET_FETCH
},
{ "req.http.", HEADER, 9,
"VRT_r_req_http_(sp)",
"VRT_l_req_http_(sp, ",
1,
VCL_MET_RECV | VCL_MET_PIPE | VCL_MET_PASS | VCL_MET_HASH | VCL_MET_MISS | VCL_MET_HIT | VCL_MET_FETCH
},
{ "req.hash", HASH, 8,
"VRT_r_req_hash(sp)",
"VRT_l_req_hash(sp, ",
0,
VCL_MET_HASH
},
{ "obj.valid", BOOL, 9,
"VRT_r_obj_valid(sp)",
"VRT_l_obj_valid(sp, ",
0,
VCL_MET_HIT | VCL_MET_FETCH
VCL_MET_HIT | VCL_MET_FETCH | VCL_MET_DISCARD | VCL_MET_TIMEOUT
},
{ "obj.cacheable", BOOL, 13,
"VRT_r_obj_cacheable(sp)",
"VRT_l_obj_cacheable(sp, ",
0,
VCL_MET_HIT | VCL_MET_FETCH
VCL_MET_HIT | VCL_MET_FETCH | VCL_MET_DISCARD | VCL_MET_TIMEOUT
},
{ "obj.ttl", TIME, 7,
"VRT_r_obj_ttl(sp)",
"VRT_l_obj_ttl(sp, ",
0,
VCL_MET_HIT | VCL_MET_FETCH
VCL_MET_HIT | VCL_MET_FETCH | VCL_MET_DISCARD | VCL_MET_TIMEOUT
},
{ "resp.http.", HEADER, 10,
"VRT_r_resp_http_(sp)",
"VRT_l_resp_http_(sp, ",
1,
VCL_MET_FETCH
},
{ NULL }
......
......@@ -56,12 +56,6 @@ vcc_StringVal(struct tokenlist *tl)
vt = tl->t;
vp = vcc_FindVar(tl, tl->t, vcc_vars);
ERRCHK(tl);
if (!vp->has_string) {
vsb_printf(tl->sb,
"No string representation of '%s'\n", vp->name);
vcc_ErrWhere(tl, tl->t);
return;
}
switch (vp->fmt) {
case STRING:
Fb(tl, 0, "%s", vp->rname);
......@@ -82,8 +76,9 @@ static struct var *
HeaderVar(struct tokenlist *tl, const struct token *t, const struct var *vh)
{
char *p;
const char *wh;
struct var *v;
int i, w;
int i;
(void)tl;
......@@ -96,12 +91,14 @@ HeaderVar(struct tokenlist *tl, const struct token *t, const struct var *vh)
p[i] = '\0';
v->name = p;
v->fmt = STRING;
v->has_string = vh->has_string;
v->methods = vh->methods;
if (!memcmp(vh->name, "req.", 4))
w = 1;
wh = "HDR_REQ";
else if (!memcmp(vh->name, "resp.", 5))
wh = "HDR_RESP";
else
w = 2;
asprintf(&p, "VRT_GetHdr(sp, %d, \"\\%03o%s:\")", w,
assert(0 == 1);
asprintf(&p, "VRT_GetHdr(sp, %s, \"\\%03o%s:\")", wh,
(unsigned)(strlen(v->name + vh->len) + 1), v->name + vh->len);
assert(p != NULL);
v->rname = p;
......
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