CHECK_OBJ_NOTNULL(be, BACKEND_MAGIC); \
be->field = a; \
} \
- \
-type \
-VRT_r_backend_##onm(struct backend *be) \
-{ \
- CHECK_OBJ_NOTNULL(be, BACKEND_MAGIC); \
- return (be->field); \
-}
VBACKEND(const char *, host, hostname)
VBACKEND(const char *, port, portname)
* Edit vcc_gen_obj.tcl instead
*/
-const char * VRT_r_backend_host(struct backend *);
void VRT_l_backend_host(struct backend *, const char *);
-const char * VRT_r_backend_port(struct backend *);
void VRT_l_backend_port(struct backend *, const char *);
-double VRT_r_backend_dnsttl(struct backend *);
void VRT_l_backend_dnsttl(struct backend *, double);
struct sockaddr * VRT_r_client_ip(struct sess *);
-void VRT_l_client_ip(struct sess *, struct sockaddr *);
struct sockaddr * VRT_r_server_ip(struct sess *);
-void VRT_l_server_ip(struct sess *, struct sockaddr *);
const char * VRT_r_req_request(struct sess *);
-void VRT_l_req_request(struct sess *, const char *);
-const char * VRT_r_req_host(struct sess *);
-void VRT_l_req_host(struct sess *, const char *);
const char * VRT_r_req_url(struct sess *);
-void VRT_l_req_url(struct sess *, const char *);
const char * VRT_r_req_proto(struct sess *);
-void VRT_l_req_proto(struct sess *, const char *);
struct backend * VRT_r_req_backend(struct sess *);
void VRT_l_req_backend(struct sess *, struct backend *);
const char * VRT_r_req_http_(struct sess *);
-void VRT_l_req_http_(struct sess *, const char *);
-const char * VRT_r_req_hash(struct sess *);
void VRT_l_req_hash(struct sess *, const char *);
unsigned VRT_r_obj_valid(struct sess *);
void VRT_l_obj_valid(struct sess *, unsigned);
double VRT_r_obj_ttl(struct sess *);
void VRT_l_obj_ttl(struct sess *, double);
const char * VRT_r_resp_proto(struct sess *);
-void VRT_l_resp_proto(struct sess *, const char *);
int VRT_r_resp_status(struct sess *);
-void VRT_l_resp_status(struct sess *, int);
const char * VRT_r_resp_response(struct sess *);
-void VRT_l_resp_response(struct sess *, const char *);
const char * VRT_r_resp_http_(struct sess *);
-void VRT_l_resp_http_(struct sess *, const char *);
vp = vcc_FindVar(tl, tl->t, vcc_vars);
ERRCHK(tl);
assert(vp != NULL);
+ if (vp->access != V_RW && vp->access != V_WO) {
+ vsb_printf(tl->sb, "Variable %.*s cannot be written.\n",
+ PF(vt));
+ vcc_ErrWhere(tl, vt);
+ return;
+ }
Fb(tl, 1, "%s", vp->lname);
vcc_NextToken(tl);
switch (vp->fmt) {
unsigned len;
const char *rname;
const char *lname;
+ enum {V_RO, V_RW, V_WO} access;
unsigned methods;
};
# Objects which operate on backends
set beobj {
- { backend.host HOSTNAME }
- { backend.port PORTNAME }
- { backend.dnsttl TIME }
+ { backend.host WO HOSTNAME }
+ { backend.port WO PORTNAME }
+ { backend.dnsttl WO TIME }
}
# Objects which operate on sessions
set spobj {
- { 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.proto STRING { fetch } }
- { resp.status INT { fetch } }
- { resp.response STRING { fetch } }
- { resp.http. HEADER { fetch } }
+ { client.ip
+ RO IP
+ {recv pipe pass hash miss hit fetch }
+ }
+ { server.ip
+ RO IP
+ {recv pipe pass hash miss hit fetch }
+ }
+ { req.request
+ RO STRING
+ {recv pipe pass hash miss hit fetch }
+ }
+ { req.url
+ RO STRING
+ {recv pipe pass hash miss hit fetch }
+ }
+ { req.proto
+ RO STRING
+ {recv pipe pass hash miss hit fetch }
+ }
+ { req.backend
+ RW BACKEND
+ {recv pipe pass hash miss hit fetch }
+ }
+ { req.http.
+ RO HEADER
+ {recv pipe pass hash miss hit fetch }
+ }
+ { req.hash
+ WO HASH
+ { hash }
+ }
+ { obj.valid
+ RW BOOL
+ { hit fetch discard timeout}
+ }
+ { obj.cacheable
+ RW BOOL
+ { hit fetch discard timeout}
+ }
+ { obj.ttl
+ RW TIME
+ { hit fetch discard timeout}
+ }
+ { resp.proto
+ RO STRING
+ { fetch }
+ }
+ { resp.status
+ RO INT
+ { fetch }
+ }
+ { resp.response
+ RO STRING
+ { fetch }
+ }
+ { resp.http.
+ RO HEADER
+ { fetch }
+ }
}
set tt(IP) "struct sockaddr *"
foreach v $v {
set n [lindex $v 0]
regsub -all {[.]} $n "_" m
- set t [lindex $v 1]
+ set a [lindex $v 1]
+ set t [lindex $v 2]
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 [method_map [lindex $v 2]]"
+ if {$a == "RO" || $a == "RW"} {
+ puts $fo "\t \"VRT_r_${m}($pa)\","
+ puts $fp "$tt($t) VRT_r_${m}($ty);"
+ } else {
+ puts $fo "\t NULL,"
+ }
+ if {$a == "WO" || $a == "RW"} {
+ puts $fo "\t \"VRT_l_${m}($pa, \","
+ puts $fp "void VRT_l_${m}($ty, $tt($t));"
+ } else {
+ puts $fo "\t NULL,"
+ }
+ puts $fo "\t V_$a,"
+ puts $fo "\t [method_map [lindex $v 3]]"
puts $fo "\t\},"
- puts $fp "$tt($t) VRT_r_${m}($ty);"
- puts $fp "void VRT_l_${m}($ty, $tt($t));"
}
puts $fo "\t{ NULL }"
}
struct var vcc_be_vars[] = {
{ "backend.host", HOSTNAME, 12,
- "VRT_r_backend_host(backend)",
+ NULL,
"VRT_l_backend_host(backend, ",
+ V_WO,
},
{ "backend.port", PORTNAME, 12,
- "VRT_r_backend_port(backend)",
+ NULL,
"VRT_l_backend_port(backend, ",
+ V_WO,
},
{ "backend.dnsttl", TIME, 14,
- "VRT_r_backend_dnsttl(backend)",
+ NULL,
"VRT_l_backend_dnsttl(backend, ",
+ V_WO,
},
{ NULL }
struct var vcc_vars[] = {
{ "client.ip", IP, 9,
"VRT_r_client_ip(sp)",
- "VRT_l_client_ip(sp, ",
+ NULL,
+ V_RO,
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, ",
+ NULL,
+ V_RO,
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, ",
- 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, ",
+ NULL,
+ V_RO,
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, ",
+ NULL,
+ V_RO,
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, ",
+ NULL,
+ V_RO,
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, ",
+ V_RW,
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, ",
+ NULL,
+ V_RO,
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)",
+ NULL,
"VRT_l_req_hash(sp, ",
+ V_WO,
VCL_MET_HASH
},
{ "obj.valid", BOOL, 9,
"VRT_r_obj_valid(sp)",
"VRT_l_obj_valid(sp, ",
+ V_RW,
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, ",
+ V_RW,
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, ",
+ V_RW,
VCL_MET_HIT | VCL_MET_FETCH | VCL_MET_DISCARD | VCL_MET_TIMEOUT
},
{ "resp.proto", STRING, 10,
"VRT_r_resp_proto(sp)",
- "VRT_l_resp_proto(sp, ",
+ NULL,
+ V_RO,
VCL_MET_FETCH
},
{ "resp.status", INT, 11,
"VRT_r_resp_status(sp)",
- "VRT_l_resp_status(sp, ",
+ NULL,
+ V_RO,
VCL_MET_FETCH
},
{ "resp.response", STRING, 13,
"VRT_r_resp_response(sp)",
- "VRT_l_resp_response(sp, ",
+ NULL,
+ V_RO,
VCL_MET_FETCH
},
{ "resp.http.", HEADER, 10,
"VRT_r_resp_http_(sp)",
- "VRT_l_resp_http_(sp, ",
+ NULL,
+ V_RO,
VCL_MET_FETCH
},
{ NULL }
vcc_StringVal(struct tokenlist *tl)
{
struct var *vp;
- struct token *vt;
if (tl->t->tok == CSTR) {
EncToken(tl->fb, tl->t);
}
ExpectErr(tl, VAR);
ERRCHK(tl);
- vt = tl->t;
vp = vcc_FindVar(tl, tl->t, vcc_vars);
ERRCHK(tl);
switch (vp->fmt) {