Commit 07e9348a authored by Tollef Fog Heen's avatar Tollef Fog Heen

Add string representations of TIME and RTIME

Make it possible to get useful string representations of TIME and
RTIME out.  Also change the definition of types that should be RTIME
from TIME.

git-svn-id: http://www.varnish-cache.org/svn/trunk@4428 d4fa192b-c00b-0410-8231-f00ffab90ce4
parent 2425db64
......@@ -840,6 +840,16 @@ VRT_double_string(const struct sess *sp, double num)
return (p);
}
char *
VRT_time_string(const struct sess *sp, double t)
{
char *p;
AN(p = WS_Alloc(sp->http->ws, TIM_FORMAT_SIZE));
TIM_format(t, p);
return p;
}
const char *
VRT_backend_string(struct sess *sp)
{
......
# $Id$
test "Test formatting of timestamps"
server s1 {
rxreq
txresp
} -start
varnish v1 -vcl+backend {
sub vcl_recv {
error 200 req.grace;
}
} -start
client c1 {
txreq
rxresp
expect resp.msg == "10.000"
} -run
......@@ -25,11 +25,6 @@ varnish v1 -vcl {
sub vcl_fetch { error beresp.status req.url; }
}
varnish v1 -badvcl {
backend b { .host = "127.0.0.1"; }
sub vcl_fetch { error 404 req.grace; }
}
varnish v1 -badvcl {
backend b { .host = "127.0.0.1"; }
sub vcl_miss { set server.port = 1000; }
......
......@@ -75,6 +75,7 @@ void TCP_set_read_timeout(int s, double seconds);
#endif
/* from libvarnish/time.c */
#define TIM_FORMAT_SIZE 30
void TIM_format(double t, char *p);
time_t TIM_parse(const char *p);
double TIM_mono(void);
......
......@@ -168,6 +168,7 @@ void VRT_fini_dir(struct cli *, struct director *);
char *VRT_IP_string(const struct sess *sp, const struct sockaddr *sa);
char *VRT_int_string(const struct sess *sp, int);
char *VRT_double_string(const struct sess *sp, double);
char *VRT_time_string(const struct sess *sp, double);
const char *VRT_backend_string(struct sess *sp);
#define VRT_done(sp, hand) \
......
......@@ -107,7 +107,7 @@ TIM_format(double t, char *p)
tt = (time_t) t;
(void)gmtime_r(&tt, &tm);
AN(strftime(p, 30, "%a, %d %b %Y %T GMT", &tm));
AN(strftime(p, TIM_FORMAT_SIZE, "%a, %d %b %Y %T GMT", &tm));
}
/* XXX: add statistics ? */
......
/*
* $Id: vcc_gen_fixed_token.tcl 4376 2009-11-27 11:06:32Z phk $
* $Id$
*
* NB: This file is machine generated, DO NOT EDIT!
*
......@@ -159,10 +159,9 @@ vcl_output_lang_h(struct vsb *sb)
/* ../../include/vcl.h */
vsb_cat(sb, "/*\n * $Id: vcc_gen_fixed_token.tcl 4376 2009-11-27 11");
vsb_cat(sb, ":06:32Z phk $\n *\n * NB: This file is machine genera");
vsb_cat(sb, "ted, DO NOT EDIT!\n *\n * Edit and run vcc_gen_fixed_t");
vsb_cat(sb, "oken.tcl instead\n */\n\nstruct sess;\n");
vsb_cat(sb, "/*\n * $Id$\n *\n * NB: This file is machine generate");
vsb_cat(sb, "d, DO NOT EDIT!\n *\n * Edit and run vcc_gen_fixed_tok");
vsb_cat(sb, "en.tcl instead\n */\n\nstruct sess;\n");
vsb_cat(sb, "struct cli;\n\ntypedef void vcl_init_f(struct cli *);\n");
vsb_cat(sb, "typedef void vcl_fini_f(struct cli *);\n");
vsb_cat(sb, "typedef int vcl_func_f(struct sess *sp);\n");
......@@ -227,16 +226,16 @@ vcl_output_lang_h(struct vsb *sb)
vsb_cat(sb, " * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWI");
vsb_cat(sb, "SE) ARISING IN ANY WAY\n * OUT OF THE USE OF THIS SOFT");
vsb_cat(sb, "WARE, EVEN IF ADVISED OF THE POSSIBILITY OF\n");
vsb_cat(sb, " * SUCH DAMAGE.\n *\n * $Id: vrt.h 4405 2009-12-16 10:");
vsb_cat(sb, "45:39Z phk $\n *\n * Runtime support for compiled VCL ");
vsb_cat(sb, "programs.\n *\n * XXX: When this file is changed, lib/");
vsb_cat(sb, "libvcl/vcc_gen_fixed_token.tcl\n");
vsb_cat(sb, " * XXX: *MUST* be rerun.\n */\n");
vsb_cat(sb, "\nstruct sess;\nstruct vsb;\nstruct cli;\n");
vsb_cat(sb, "struct director;\nstruct VCL_conf;\n");
vsb_cat(sb, "struct sockaddr;\n\n/*\n * A backend probe specificati");
vsb_cat(sb, "on\n */\n\nextern const void * const vrt_magic_string_");
vsb_cat(sb, "end;\n\nstruct vrt_backend_probe {\n");
vsb_cat(sb, " * SUCH DAMAGE.\n *\n * $Id$\n *\n");
vsb_cat(sb, " * Runtime support for compiled VCL programs.\n");
vsb_cat(sb, " *\n * XXX: When this file is changed, lib/libvcl/vcc_");
vsb_cat(sb, "gen_fixed_token.tcl\n * XXX: *MUST* be rerun.\n");
vsb_cat(sb, " */\n\nstruct sess;\nstruct vsb;\n");
vsb_cat(sb, "struct cli;\nstruct director;\n");
vsb_cat(sb, "struct VCL_conf;\nstruct sockaddr;\n");
vsb_cat(sb, "\n/*\n * A backend probe specification\n");
vsb_cat(sb, " */\n\nextern const void * const vrt_magic_string_end;");
vsb_cat(sb, "\n\nstruct vrt_backend_probe {\n");
vsb_cat(sb, "\tconst char\t*url;\n\tconst char\t*request;\n");
vsb_cat(sb, "\tdouble\t\ttimeout;\n\tdouble\t\tinterval;\n");
vsb_cat(sb, "\tunsigned\texp_status;\n\tunsigned\twindow;\n");
......@@ -304,33 +303,33 @@ vcl_output_lang_h(struct vsb *sb)
vsb_cat(sb, "\nchar *VRT_IP_string(const struct sess *sp, const str");
vsb_cat(sb, "uct sockaddr *sa);\nchar *VRT_int_string(const struct ");
vsb_cat(sb, "sess *sp, int);\nchar *VRT_double_string(const struct ");
vsb_cat(sb, "sess *sp, double);\nconst char *VRT_backend_string(str");
vsb_cat(sb, "uct sess *sp);\n\n#define VRT_done(sp, hand)\t\t\t\\\n");
vsb_cat(sb, "sess *sp, double);\nchar *VRT_time_string(const struct");
vsb_cat(sb, " sess *sp, double);\nconst char *VRT_backend_string(st");
vsb_cat(sb, "ruct sess *sp);\n\n#define VRT_done(sp, hand)\t\t\t\\\n");
vsb_cat(sb, "\tdo {\t\t\t\t\t\\\n\t\tVRT_handling(sp, hand);\t\t\\\n");
vsb_cat(sb, "\t\treturn (1);\t\t\t\\\n\t} while (0)\n");
/* ../../include/vrt_obj.h */
vsb_cat(sb, "/*\n * $Id: vcc_gen_fixed_token.tcl 4376 2009-11-27 11");
vsb_cat(sb, ":06:32Z phk $\n *\n * NB: This file is machine genera");
vsb_cat(sb, "ted, DO NOT EDIT!\n *\n * Edit and run vcc_gen_fixed_t");
vsb_cat(sb, "oken.tcl instead\n */\n\nstruct sockaddr * VRT_r_clien");
vsb_cat(sb, "t_ip(const struct sess *);\nstruct sockaddr * VRT_r_se");
vsb_cat(sb, "rver_ip(struct sess *);\nconst char * VRT_r_server_hos");
vsb_cat(sb, "tname(struct sess *);\nconst char * VRT_r_server_ident");
vsb_cat(sb, "ity(struct sess *);\nint VRT_r_server_port(struct sess");
vsb_cat(sb, " *);\nconst char * VRT_r_req_request(const struct sess");
vsb_cat(sb, " *);\nvoid VRT_l_req_request(const struct sess *, cons");
vsb_cat(sb, "t char *, ...);\nconst char * VRT_r_req_url(const stru");
vsb_cat(sb, "ct sess *);\nvoid VRT_l_req_url(const struct sess *, c");
vsb_cat(sb, "onst char *, ...);\nconst char * VRT_r_req_proto(const");
vsb_cat(sb, " struct sess *);\nvoid VRT_l_req_proto(const struct se");
vsb_cat(sb, "ss *, const char *, ...);\nvoid VRT_l_req_hash(struct ");
vsb_cat(sb, "sess *, const char *);\nstruct director * VRT_r_req_ba");
vsb_cat(sb, "ckend(struct sess *);\nvoid VRT_l_req_backend(struct s");
vsb_cat(sb, "ess *, struct director *);\nint VRT_r_req_restarts(con");
vsb_cat(sb, "st struct sess *);\ndouble VRT_r_req_grace(struct sess");
vsb_cat(sb, " *);\nvoid VRT_l_req_grace(struct sess *, double);\n");
vsb_cat(sb, "/*\n * $Id$\n *\n * NB: This file is machine generate");
vsb_cat(sb, "d, DO NOT EDIT!\n *\n * Edit and run vcc_gen_fixed_tok");
vsb_cat(sb, "en.tcl instead\n */\n\nstruct sockaddr * VRT_r_client_");
vsb_cat(sb, "ip(const struct sess *);\nstruct sockaddr * VRT_r_serv");
vsb_cat(sb, "er_ip(struct sess *);\nconst char * VRT_r_server_hostn");
vsb_cat(sb, "ame(struct sess *);\nconst char * VRT_r_server_identit");
vsb_cat(sb, "y(struct sess *);\nint VRT_r_server_port(struct sess *");
vsb_cat(sb, ");\nconst char * VRT_r_req_request(const struct sess *");
vsb_cat(sb, ");\nvoid VRT_l_req_request(const struct sess *, const ");
vsb_cat(sb, "char *, ...);\nconst char * VRT_r_req_url(const struct");
vsb_cat(sb, " sess *);\nvoid VRT_l_req_url(const struct sess *, con");
vsb_cat(sb, "st char *, ...);\nconst char * VRT_r_req_proto(const s");
vsb_cat(sb, "truct sess *);\nvoid VRT_l_req_proto(const struct sess");
vsb_cat(sb, " *, const char *, ...);\nvoid VRT_l_req_hash(struct se");
vsb_cat(sb, "ss *, const char *);\nstruct director * VRT_r_req_back");
vsb_cat(sb, "end(struct sess *);\nvoid VRT_l_req_backend(struct ses");
vsb_cat(sb, "s *, struct director *);\nint VRT_r_req_restarts(const");
vsb_cat(sb, " struct sess *);\ndouble VRT_r_req_grace(struct sess *");
vsb_cat(sb, ");\nvoid VRT_l_req_grace(struct sess *, double);\n");
vsb_cat(sb, "const char * VRT_r_req_xid(struct sess *);\n");
vsb_cat(sb, "unsigned VRT_r_req_esi(struct sess *);\n");
vsb_cat(sb, "void VRT_l_req_esi(struct sess *, unsigned);\n");
......
......@@ -150,7 +150,7 @@ set spobj {
all
"const struct sess *"
}
{ req.grace TIME
{ req.grace RTIME
RW
all
"struct sess *"
......@@ -196,17 +196,17 @@ set spobj {
{ pipe pass miss fetch }
"const struct sess *"
}
{ bereq.connect_timeout TIME
{ bereq.connect_timeout RTIME
RW
{ pass miss }
"struct sess *"
}
{ bereq.first_byte_timeout TIME
{ bereq.first_byte_timeout RTIME
RW
{ pass miss }
"struct sess *"
}
{ bereq.between_bytes_timeout TIME
{ bereq.between_bytes_timeout RTIME
RW
{ pass miss }
"struct sess *"
......@@ -219,7 +219,7 @@ set spobj {
{ fetch }
"const struct sess *"
}
{ beresp.saintmode TIME
{ beresp.saintmode RTIME
WO
{ fetch }
"const struct sess *"
......@@ -244,12 +244,12 @@ set spobj {
{ fetch }
"const struct sess *"
}
{ beresp.ttl TIME
{ beresp.ttl RTIME
RW
{ fetch }
"const struct sess *"
}
{ beresp.grace TIME
{ beresp.grace RTIME
RW
{ fetch }
"const struct sess *"
......@@ -288,17 +288,17 @@ set spobj {
{ hit }
"const struct sess *"
}
{ obj.ttl TIME
{ obj.ttl RTIME
RW
{ hit error }
"const struct sess *"
}
{ obj.grace TIME
{ obj.grace RTIME
RW
{ hit error }
"const struct sess *"
}
{ obj.lastuse TIME
{ obj.lastuse RTIME
RO
{ hit deliver error }
"const struct sess *"
......
/*
* $Id: vcc_gen_fixed_token.tcl 4376 2009-11-27 11:06:32Z phk $
* $Id$
*
* NB: This file is machine generated, DO NOT EDIT!
*
......@@ -105,7 +105,7 @@ struct var vcc_vars[] = {
| VCL_MET_MISS | VCL_MET_HIT | VCL_MET_FETCH | VCL_MET_DELIVER
| VCL_MET_ERROR
},
{ "req.grace", TIME, 9,
{ "req.grace", RTIME, 9,
"VRT_r_req_grace(sp)",
"VRT_l_req_grace(sp, ",
V_RW, 0,
......@@ -159,19 +159,19 @@ struct var vcc_vars[] = {
V_RW, "HDR_BEREQ",
VCL_MET_PIPE | VCL_MET_PASS | VCL_MET_MISS | VCL_MET_FETCH
},
{ "bereq.connect_timeout", TIME, 21,
{ "bereq.connect_timeout", RTIME, 21,
"VRT_r_bereq_connect_timeout(sp)",
"VRT_l_bereq_connect_timeout(sp, ",
V_RW, 0,
VCL_MET_PASS | VCL_MET_MISS
},
{ "bereq.first_byte_timeout", TIME, 24,
{ "bereq.first_byte_timeout", RTIME, 24,
"VRT_r_bereq_first_byte_timeout(sp)",
"VRT_l_bereq_first_byte_timeout(sp, ",
V_RW, 0,
VCL_MET_PASS | VCL_MET_MISS
},
{ "bereq.between_bytes_timeout", TIME, 27,
{ "bereq.between_bytes_timeout", RTIME, 27,
"VRT_r_bereq_between_bytes_timeout(sp)",
"VRT_l_bereq_between_bytes_timeout(sp, ",
V_RW, 0,
......@@ -183,7 +183,7 @@ struct var vcc_vars[] = {
V_RW, 0,
VCL_MET_FETCH
},
{ "beresp.saintmode", TIME, 16,
{ "beresp.saintmode", RTIME, 16,
NULL,
"VRT_l_beresp_saintmode(sp, ",
V_WO, 0,
......@@ -213,13 +213,13 @@ struct var vcc_vars[] = {
V_RW, 0,
VCL_MET_FETCH
},
{ "beresp.ttl", TIME, 10,
{ "beresp.ttl", RTIME, 10,
"VRT_r_beresp_ttl(sp)",
"VRT_l_beresp_ttl(sp, ",
V_RW, 0,
VCL_MET_FETCH
},
{ "beresp.grace", TIME, 12,
{ "beresp.grace", RTIME, 12,
"VRT_r_beresp_grace(sp)",
"VRT_l_beresp_grace(sp, ",
V_RW, 0,
......@@ -261,19 +261,19 @@ struct var vcc_vars[] = {
V_RW, 0,
VCL_MET_HIT
},
{ "obj.ttl", TIME, 7,
{ "obj.ttl", RTIME, 7,
"VRT_r_obj_ttl(sp)",
"VRT_l_obj_ttl(sp, ",
V_RW, 0,
VCL_MET_HIT | VCL_MET_ERROR
},
{ "obj.grace", TIME, 9,
{ "obj.grace", RTIME, 9,
"VRT_r_obj_grace(sp)",
"VRT_l_obj_grace(sp, ",
V_RW, 0,
VCL_MET_HIT | VCL_MET_ERROR
},
{ "obj.lastuse", TIME, 11,
{ "obj.lastuse", RTIME, 11,
"VRT_r_obj_lastuse(sp)",
NULL,
V_RO, 0,
......
......@@ -265,6 +265,9 @@ Cond_Int(const struct var *vp, struct tokenlist *tl)
case TIME:
vcc_TimeVal(tl);
break;
case RTIME:
vcc_RTimeVal(tl);
break;
case INT:
ExpectErr(tl, CNUM);
Fb(tl, 0, "%.*s ", PF(tl->t));
......@@ -355,6 +358,7 @@ Cond_2(struct tokenlist *tl)
case IP: L(tl, vcc_Cond_Ip(vp, tl)); break;
case STRING: L(tl, Cond_String(vp, tl)); break;
case TIME: L(tl, Cond_Int(vp, tl)); break;
case RTIME: L(tl, Cond_Int(vp, tl)); break;
case BACKEND: L(tl, Cond_Backend(vp, tl)); break;
default:
vsb_printf(tl->sb,
......
......@@ -171,6 +171,12 @@ vcc_StringVal(struct tokenlist *tl)
case FLOAT:
Fb(tl, 0, "VRT_double_string(sp, %s)", vp->rname);
break;
case TIME:
Fb(tl, 0, "VRT_time_string(sp, %s)", vp->rname);
break;
case RTIME:
Fb(tl, 0, "VRT_double_string(sp, %s)", vp->rname);
break;
case BACKEND:
Fb(tl, 0, "VRT_backend_string(sp)");
break;
......
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