Commit 4478944b authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

Make all the VCL variables controlled by generate.py use vrt_ctx.

parent af675ec6
......@@ -295,9 +295,10 @@ VRT_hashdata(struct req *req, const char *str, ...)
/*--------------------------------------------------------------------*/
double
VRT_r_now()
VRT_r_now(const struct vrt_ctx *ctx)
{
(void)ctx;
return (VTIM_real());
}
......
......@@ -150,26 +150,30 @@ VBERESP(beresp, unsigned, uncacheable, do_pass)
/*--------------------------------------------------------------------*/
const char *
VRT_r_client_identity(const struct req *req)
VRT_r_client_identity(const struct vrt_ctx *ctx)
{
CHECK_OBJ_NOTNULL(req, REQ_MAGIC);
if (req->client_identity != NULL)
return (req->client_identity);
CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
CHECK_OBJ_NOTNULL(ctx->req, REQ_MAGIC);
if (ctx->req->client_identity != NULL)
return (ctx->req->client_identity);
else
return (req->sp->addr);
return (ctx->req->sp->addr);
}
void
VRT_l_client_identity(struct req *req, const char *str, ...)
VRT_l_client_identity(const struct vrt_ctx *ctx, const char *str, ...)
{
va_list ap;
char *b;
CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
CHECK_OBJ_NOTNULL(ctx->req, REQ_MAGIC);
va_start(ap, str);
b = VRT_String(req->http->ws, NULL, str, ap);
// XXX ?
b = VRT_String(ctx->req->http->ws, NULL, str, ap);
va_end(ap);
req->client_identity = b;
ctx->req->client_identity = b;
}
/*--------------------------------------------------------------------*/
......@@ -257,33 +261,37 @@ VRT_l_beresp_storage(const struct vrt_ctx *ctx, const char *str, ...)
/*--------------------------------------------------------------------*/
void
VRT_l_req_backend(struct req *req, struct director *be)
VRT_l_req_backend(const struct vrt_ctx *ctx, struct director *be)
{
CHECK_OBJ_NOTNULL(req, REQ_MAGIC);
req->director = be;
CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
CHECK_OBJ_NOTNULL(ctx->req, REQ_MAGIC);
ctx->req->director = be;
}
struct director *
VRT_r_req_backend(const struct req *req)
VRT_r_req_backend(const struct vrt_ctx *ctx)
{
CHECK_OBJ_NOTNULL(req, REQ_MAGIC);
return (req->director);
CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
CHECK_OBJ_NOTNULL(ctx->req, REQ_MAGIC);
return (ctx->req->director);
}
unsigned
VRT_r_req_backend_healthy(const struct req *req)
VRT_r_req_backend_healthy(const struct vrt_ctx *ctx)
{
CHECK_OBJ_NOTNULL(req, REQ_MAGIC);
CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
CHECK_OBJ_NOTNULL(ctx->req, REQ_MAGIC);
/*
* XXX: Not optimal, but we do not have a backend in vcl_deliver
* XXX: and we have to return something.
*/
if (req->director == NULL)
if (ctx->req->director == NULL)
return (0);
CHECK_OBJ_NOTNULL(req->director, DIRECTOR_MAGIC);
return (VDI_Healthy(req->director, req->digest));
CHECK_OBJ_NOTNULL(ctx->req->director, DIRECTOR_MAGIC);
return (VDI_Healthy(ctx->req->director, ctx->req->digest));
}
/*--------------------------------------------------------------------*/
......@@ -321,51 +329,58 @@ VRT_r_bereq_backend_healthy(const struct vrt_ctx *ctx)
/*--------------------------------------------------------------------*/
void
VRT_l_req_esi(struct req *req, unsigned process_esi)
VRT_l_req_esi(const struct vrt_ctx *ctx, unsigned process_esi)
{
CHECK_OBJ_NOTNULL(req, REQ_MAGIC);
CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
CHECK_OBJ_NOTNULL(ctx->req, REQ_MAGIC);
/*
* Only allow you to turn of esi in the main request
* else everything gets confused
*/
if(req->esi_level == 0)
req->disable_esi = !process_esi;
if(ctx->req->esi_level == 0)
ctx->req->disable_esi = !process_esi;
}
unsigned
VRT_r_req_esi(const struct req *req)
VRT_r_req_esi(const struct vrt_ctx *ctx)
{
CHECK_OBJ_NOTNULL(req, REQ_MAGIC);
return (!req->disable_esi);
CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
CHECK_OBJ_NOTNULL(ctx->req, REQ_MAGIC);
return (!ctx->req->disable_esi);
}
long
VRT_r_req_esi_level(const struct req *req)
VRT_r_req_esi_level(const struct vrt_ctx *ctx)
{
CHECK_OBJ_NOTNULL(req, REQ_MAGIC);
return(req->esi_level);
CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
CHECK_OBJ_NOTNULL(ctx->req, REQ_MAGIC);
return(ctx->req->esi_level);
}
/*--------------------------------------------------------------------*/
unsigned
VRT_r_req_can_gzip(const struct req *req)
VRT_r_req_can_gzip(const struct vrt_ctx *ctx)
{
CHECK_OBJ_NOTNULL(req, REQ_MAGIC);
return (RFC2616_Req_Gzip(req->http));
CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
CHECK_OBJ_NOTNULL(ctx->req, REQ_MAGIC);
return (RFC2616_Req_Gzip(ctx->req->http)); // XXX ?
}
/*--------------------------------------------------------------------*/
long
VRT_r_req_restarts(const struct req *req)
VRT_r_req_restarts(const struct vrt_ctx *ctx)
{
CHECK_OBJ_NOTNULL(req, REQ_MAGIC);
return (req->restarts);
CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
CHECK_OBJ_NOTNULL(ctx->req, REQ_MAGIC);
return (ctx->req->restarts);
}
/*--------------------------------------------------------------------
......@@ -437,15 +452,17 @@ VRT_DO_EXP(beresp, ctx->bo->exp, keep, 0,
*/
const char *
VRT_r_req_xid(const struct req *req)
VRT_r_req_xid(const struct vrt_ctx *ctx)
{
char *p;
int size;
CHECK_OBJ_NOTNULL(req, REQ_MAGIC);
CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
CHECK_OBJ_NOTNULL(ctx->req, REQ_MAGIC);
size = snprintf(NULL, 0, "%u", req->vsl->wid & VSL_IDENTMASK) + 1;
AN(p = WS_Alloc(req->http->ws, size));
assert(snprintf(p, size, "%u", req->vsl->wid & VSL_IDENTMASK) < size);
// XXX ?
size = snprintf(NULL, 0, "%u", ctx->req->vsl->wid & VSL_IDENTMASK) + 1;
AN(p = WS_Alloc(ctx->req->http->ws, size));
assert(snprintf(p, size, "%u", ctx->req->vsl->wid & VSL_IDENTMASK) < size);
return (p);
}
......@@ -453,19 +470,21 @@ VRT_r_req_xid(const struct req *req)
#define REQ_BOOL(hash_var) \
void \
VRT_l_req_##hash_var(struct req *req, unsigned val) \
VRT_l_req_##hash_var(const struct vrt_ctx *ctx, unsigned val) \
{ \
\
CHECK_OBJ_NOTNULL(req, REQ_MAGIC); \
req->hash_var = val ? 1 : 0; \
CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC); \
CHECK_OBJ_NOTNULL(ctx->req, REQ_MAGIC); \
ctx->req->hash_var = val ? 1 : 0; \
} \
\
unsigned \
VRT_r_req_##hash_var(const struct req *req) \
VRT_r_req_##hash_var(const struct vrt_ctx *ctx) \
{ \
\
CHECK_OBJ_NOTNULL(req, REQ_MAGIC); \
return(req->hash_var); \
CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC); \
CHECK_OBJ_NOTNULL(ctx->req, REQ_MAGIC); \
return(ctx->req->hash_var); \
}
REQ_BOOL(hash_ignore_busy)
......@@ -474,33 +493,36 @@ REQ_BOOL(hash_always_miss)
/*--------------------------------------------------------------------*/
struct sockaddr_storage *
VRT_r_client_ip(const struct req *req)
VRT_r_client_ip(const struct vrt_ctx *ctx)
{
CHECK_OBJ_NOTNULL(req, REQ_MAGIC);
return (&req->sp->sockaddr);
CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
CHECK_OBJ_NOTNULL(ctx->req, REQ_MAGIC);
return (&ctx->req->sp->sockaddr);
}
struct sockaddr_storage *
VRT_r_server_ip(const struct req *req)
VRT_r_server_ip(const struct vrt_ctx *ctx)
{
int i;
CHECK_OBJ_NOTNULL(req, REQ_MAGIC);
if (req->sp->mysockaddr.ss_family == AF_UNSPEC) {
i = getsockname(req->sp->fd,
(void*)&req->sp->mysockaddr, &req->sp->mysockaddrlen);
CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
CHECK_OBJ_NOTNULL(ctx->req, REQ_MAGIC);
if (ctx->req->sp->mysockaddr.ss_family == AF_UNSPEC) {
i = getsockname(ctx->req->sp->fd,
(void*)&ctx->req->sp->mysockaddr,
&ctx->req->sp->mysockaddrlen);
assert(VTCP_Check(i));
}
return (&req->sp->mysockaddr);
return (&ctx->req->sp->mysockaddr);
}
const char*
VRT_r_server_identity(const struct req *req)
VRT_r_server_identity(const struct vrt_ctx *ctx)
{
CHECK_OBJ_NOTNULL(req, REQ_MAGIC);
CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
if (heritage.identity[0] != '\0')
return (heritage.identity);
else
......@@ -508,10 +530,10 @@ VRT_r_server_identity(const struct req *req)
}
const char*
VRT_r_server_hostname(const struct req *req)
VRT_r_server_hostname(const struct vrt_ctx *ctx)
{
CHECK_OBJ_NOTNULL(req, REQ_MAGIC);
CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
if (vrt_hostname[0] == '\0')
AZ(gethostname(vrt_hostname, sizeof(vrt_hostname)));
return (vrt_hostname);
......@@ -522,43 +544,49 @@ VRT_r_server_hostname(const struct req *req)
*/
long
VRT_r_server_port(const struct req *req)
VRT_r_server_port(const struct vrt_ctx *ctx)
{
int i;
CHECK_OBJ_NOTNULL(req, REQ_MAGIC);
if (req->sp->mysockaddr.ss_family == AF_UNSPEC) {
i = getsockname(req->sp->fd,
(void*)&req->sp->mysockaddr, &req->sp->mysockaddrlen);
CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
CHECK_OBJ_NOTNULL(ctx->req, REQ_MAGIC);
if (ctx->req->sp->mysockaddr.ss_family == AF_UNSPEC) {
i = getsockname(ctx->req->sp->fd,
(void*)&ctx->req->sp->mysockaddr,
&ctx->req->sp->mysockaddrlen);
assert(VTCP_Check(i));
}
return (VTCP_port(&req->sp->mysockaddr));
return (VTCP_port(&ctx->req->sp->mysockaddr));
}
/*--------------------------------------------------------------------*/
long
VRT_r_obj_hits(const struct req *req)
VRT_r_obj_hits(const struct vrt_ctx *ctx)
{
CHECK_OBJ_NOTNULL(req, REQ_MAGIC);
CHECK_OBJ_NOTNULL(req->obj, OBJECT_MAGIC); /* XXX */
return (req->obj->hits);
CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
CHECK_OBJ_NOTNULL(ctx->req, REQ_MAGIC);
CHECK_OBJ_NOTNULL(ctx->req->obj, OBJECT_MAGIC); /* XXX */
return (ctx->req->obj->hits);
}
double
VRT_r_obj_lastuse(const struct req *req)
VRT_r_obj_lastuse(const struct vrt_ctx *ctx)
{
CHECK_OBJ_NOTNULL(req, REQ_MAGIC);
CHECK_OBJ_NOTNULL(req->obj, OBJECT_MAGIC); /* XXX */
return (VTIM_real() - req->obj->last_use);
CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
CHECK_OBJ_NOTNULL(ctx->req, REQ_MAGIC);
CHECK_OBJ_NOTNULL(ctx->req->obj, OBJECT_MAGIC); /* XXX */
return (VTIM_real() - ctx->req->obj->last_use);
}
unsigned
VRT_r_obj_uncacheable(const struct req *req)
VRT_r_obj_uncacheable(const struct vrt_ctx *ctx)
{
CHECK_OBJ_NOTNULL(req, REQ_MAGIC);
CHECK_OBJ_NOTNULL(req->obj, OBJECT_MAGIC);
return (req->obj->objcore->flags & OC_F_PASS ? 1 : 0);
CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
CHECK_OBJ_NOTNULL(ctx->req, REQ_MAGIC);
CHECK_OBJ_NOTNULL(ctx->req->obj, OBJECT_MAGIC);
return (ctx->req->obj->objcore->flags & OC_F_PASS ? 1 : 0);
}
......@@ -105,397 +105,331 @@ sp_variables = (
'IP',
( 'both',),
( ),
'R'
),
('client.identity',
'STRING',
( 'both',),
( 'both',),
'R'
),
('server.ip',
'IP',
( 'client',),
( ),
'R'
),
('server.hostname',
'STRING',
( 'client',),
( ),
'R'
),
('server.identity',
'STRING',
( 'client',),
( ),
'R'
),
('server.port',
'INT',
( 'client',),
( ),
'R'
),
('req.method',
'STRING',
( 'client',),
( 'client',),
'C'
),
('req.request',
'STRING',
( 'client',),
( 'client',),
'C'
),
('req.url',
'STRING',
( 'client',),
( 'client',),
'C'
),
('req.proto',
'STRING',
( 'client',),
( 'client',),
'C'
),
('req.http.',
'HEADER',
( 'client',),
( 'client',),
'C'
),
('req.restarts',
'INT',
( 'client',),
( ),
'cR'
),
('req.esi_level',
'INT',
( 'client',),
( ),
'cR'
),
('req.ttl',
'DURATION',
( 'client',),
( 'client',),
'C'
),
('req.grace',
'DURATION',
( 'client',),
( 'client',),
'C'
),
('req.keep',
'DURATION',
( 'client',),
( 'client',),
'C'
),
('req.xid',
'STRING',
( 'client',),
( ),
'R'
),
('req.esi',
'BOOL',
( 'recv', 'backend_response', 'deliver', 'error',),
( 'recv', 'backend_response', 'deliver', 'error',),
'R'
),
('req.can_gzip',
'BOOL',
( 'client',),
( ),
'R'
),
('req.backend',
'BACKEND',
( 'client',),
( 'client',),
'R'
),
('req.backend.healthy',
'BOOL',
( 'client',),
( ),
'R'
),
('req.hash_ignore_busy',
'BOOL',
( 'recv',),
( 'recv',),
'R'
),
('req.hash_always_miss',
'BOOL',
( 'recv',),
( 'recv',),
'R'
),
('bereq.backend',
'BACKEND',
( 'backend', ),
( 'backend', ),
'C'
),
('bereq.backend.healthy',
'BOOL',
( 'backend', ),
( ),
'C'
),
('bereq.method',
'STRING',
( 'pipe', 'backend_fetch', 'pass', 'miss', 'backend_response',),
( 'pipe', 'backend_fetch', 'pass', 'miss', 'backend_response',),
'C'
),
('bereq.request',
'STRING',
( 'pipe', 'backend_fetch', 'pass', 'miss', 'backend_response',),
( 'pipe', 'backend_fetch', 'pass', 'miss', 'backend_response',),
'C'
),
('bereq.url',
'STRING',
( 'pipe', 'backend_fetch', 'pass', 'miss', 'backend_response',),
( 'pipe', 'backend_fetch', 'pass', 'miss', 'backend_response',),
'C'
),
('bereq.proto',
'STRING',
( 'pipe', 'backend_fetch', 'pass', 'miss', 'backend_response',),
( 'pipe', 'backend_fetch', 'pass', 'miss', 'backend_response',),
'C'
),
('bereq.http.',
'HEADER',
( 'pipe', 'backend_fetch', 'pass', 'miss', 'backend_response',),
( 'pipe', 'backend_fetch', 'pass', 'miss', 'backend_response',),
'C'
),
('bereq.connect_timeout',
'DURATION',
( 'pipe', 'backend_fetch', 'pass', 'miss',),
( 'pipe', 'backend_fetch', 'pass', 'miss',),
'C'
),
('bereq.first_byte_timeout',
'DURATION',
( 'backend_fetch', 'pass', 'miss',),
( 'backend_fetch', 'pass', 'miss',),
'C'
),
('bereq.between_bytes_timeout',
'DURATION',
( 'backend_fetch', 'pass', 'miss',),
( 'backend_fetch', 'pass', 'miss',),
'C'
),
('beresp.proto',
'STRING',
( 'backend_response',),
( 'backend_response',),
'C'
),
('beresp.saintmode',
'DURATION',
( ),
( 'backend_response',),
'C'
),
('beresp.status',
'INT',
( 'backend_response',),
( 'backend_response',),
'C'
),
('beresp.response',
'STRING',
( 'backend_response',),
( 'backend_response',),
'C'
),
('beresp.http.',
'HEADER',
( 'backend_response',),
( 'backend_response',),
'C'
),
('beresp.do_esi',
'BOOL',
( 'backend_response',),
( 'backend_response',),
'C'
),
('beresp.do_stream',
'BOOL',
( 'backend_response',),
( 'backend_response',),
'C'
),
('beresp.do_gzip',
'BOOL',
( 'backend_response',),
( 'backend_response',),
'C'
),
('beresp.do_gunzip',
'BOOL',
( 'backend_response',),
( 'backend_response',),
'C'
),
('beresp.do_pass',
'BOOL',
( 'backend_response',),
( 'backend_response',),
'C'
),
('beresp.uncacheable',
'BOOL',
( 'backend_response',),
( 'backend_response',),
'C'
),
('beresp.ttl',
'DURATION',
( 'backend_response',),
( 'backend_response',),
'C'
),
('beresp.grace',
'DURATION',
( 'backend_response',),
( 'backend_response',),
'C'
),
('beresp.keep',
'DURATION',
( 'backend_response',),
( 'backend_response',),
'C'
),
('beresp.backend.name',
'STRING',
( 'backend_response',),
( ),
'C'
),
('beresp.backend.ip',
'IP',
( 'backend_response',),
( ),
'C'
),
('beresp.backend.port',
'INT',
( 'backend_response',),
( ),
'C'
),
('beresp.storage',
'STRING',
( 'backend_response',),
( 'backend_response',),
'C'
),
('obj.proto',
'STRING',
( 'lookup', 'error',),
( 'lookup', 'error',),
'C'
),
('obj.status',
'INT',
( 'error',),
( 'error',),
'C'
),
('obj.response',
'STRING',
( 'error',),
( 'error',),
'C'
),
('obj.hits',
'INT',
( 'lookup', 'deliver',),
( ),
'cR'
),
('obj.http.',
'HEADER',
( 'lookup', 'error',),
( 'error',), # XXX ?
'C'
),
('obj.ttl',
'DURATION',
( 'lookup', 'error',),
( 'lookup', 'error',),
'C'
),
('obj.grace',
'DURATION',
( 'lookup', 'error',),
( 'lookup', 'error',),
'C'
),
('obj.keep',
'DURATION',
( 'lookup', 'error',),
( 'lookup', 'error',),
'C'
),
('obj.lastuse',
'DURATION',
( 'lookup', 'deliver', 'error',),
( ),
'cR'
),
('obj.uncacheable',
'BOOL',
( 'lookup', 'deliver', 'error',),
( ),
'cR'
),
('resp.proto',
'STRING',
( 'deliver',),
( 'deliver',),
'C'
),
('resp.status',
'INT',
( 'deliver',),
( 'deliver',),
'C'
),
('resp.response',
'STRING',
( 'deliver',),
( 'deliver',),
'C'
),
('resp.http.',
'HEADER',
( 'deliver',),
( 'deliver',),
'C'
),
('now',
'TIME',
( 'all',),
( ),
''
),
)
......@@ -875,45 +809,6 @@ fo.write("""
const struct var vcc_vars[] = {
""")
def mk_proto(c, r=False):
if c == "":
return "void"
s = ""
for i in c:
if i == "c" and not r:
s += " const"
elif i == "c":
pass
elif i == "C":
s += " const struct vrt_ctx *"
elif i == "R":
if r:
s += " const"
s += " struct req *"
else:
print("Unknown args-spec char '%s'" % i)
exit(1)
return s[1:]
def mk_args(c, r=False):
if c == "":
return ""
s = ""
for i in c:
if i == "c":
continue;
elif i == "R":
s += "req"
elif i == "C":
s += "ctx"
else:
print("Unknown args-spec char '%s'" % i)
exit(1)
if s != "" and not r:
s += ","
return s
for i in sp_variables:
typ = i[1]
cnam = i[0].replace(".", "_")
......@@ -928,10 +823,8 @@ for i in sp_variables:
fo.write(i[0].split(".")[0].upper())
fo.write('",\n')
else:
fo.write('\t "VRT_r_%s(%s)",\n' %
(cnam, mk_args(i[4], True)))
fh.write(ctyp + " VRT_r_%s(%s);\n" %
(cnam, mk_proto(i[4], True)))
fo.write('\t "VRT_r_%s(ctx)",\n' % cnam)
fh.write(ctyp + " VRT_r_%s(const struct vrt_ctx *);\n" % cnam )
restrict(fo, i[2])
if len(i[3]) == 0:
......@@ -941,9 +834,8 @@ for i in sp_variables:
fo.write(i[0].split(".")[0].upper())
fo.write('",\n')
else:
fo.write('\t "VRT_l_%s(%s",\n' %
(cnam, mk_args(i[4], False)))
fh.write("void VRT_l_%s(%s, " % (cnam, mk_proto(i[4], False)))
fo.write('\t "VRT_l_%s(ctx, ",\n' % cnam)
fh.write("void VRT_l_%s(const struct vrt_ctx *, " % cnam)
if typ != "STRING":
fh.write(ctyp + ");\n")
else:
......
......@@ -695,7 +695,7 @@ vcc_CompileSource(const struct vcc *tl0, struct vsb *sb, struct source *sp)
Fc(tl, 1,
"VGC_function_%s(const struct vrt_ctx *ctx,"
" struct worker *wrk,"
" struct req *req, struct busyobj *bo)\n",
" struct req *req)\n",
method_tab[i].name);
AZ(VSB_finish(tl->fm[i]));
Fc(tl, 1, "{\n");
......
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