From 8a78c0e9cdde55b76fab798ffab69d9bf356278f Mon Sep 17 00:00:00 2001 From: Tollef Fog Heen Date: Wed, 12 Nov 2008 13:06:20 +0100 Subject: [PATCH] Temporary commit --- varnish-cache/bin/varnishd/cache_vrt.c | 21 ++++++++++ varnish-cache/lib/libvcl/vcc_action.c | 27 ++++++++++++ varnish-cache/lib/libvcl/vcc_fixed_token.c | 10 +++++ .../lib/libvcl/vcc_gen_fixed_token.tcl | 7 ++++ varnish-cache/lib/libvcl/vcc_string.c | 5 +++ varnish-cache/lib/libvcl/vcc_token_defs.h | 41 ++++++++++--------- 6 files changed, 91 insertions(+), 20 deletions(-) diff --git a/varnish-cache/bin/varnishd/cache_vrt.c b/varnish-cache/bin/varnishd/cache_vrt.c index 0e5bb163..c4c36d40 100644 --- a/varnish-cache/bin/varnishd/cache_vrt.c +++ b/varnish-cache/bin/varnishd/cache_vrt.c @@ -44,6 +44,7 @@ #include #include #include +#include #include "shmlog.h" #include "vrt.h" @@ -563,6 +564,26 @@ VRT_l_req_hash(struct sess *sp, const char *str) /*--------------------------------------------------------------------*/ +char * +VRT_r_strftime(struct sess *sp, const char *format, double timestamp) +{ + char *s; + unsigned length; + size_t r; + struct tm tm; + time_t time; + + CHECK_OBJ_NOTNULL(sp, SESS_MAGIC); + + time = timestamp; + AN(length = WS_Reserve(sp->http->ws, 0)); + AN(gmtime_r(&time, &tm)); + r = strftime(sp->http->ws->f, length, format, &tm); + s = sp->http->ws->f; + WS_Release(sp->http->ws, r + 1); + return s; +} + double VRT_r_now(const struct sess *sp) { diff --git a/varnish-cache/lib/libvcl/vcc_action.c b/varnish-cache/lib/libvcl/vcc_action.c index fc42f9c1..0f9cc560 100644 --- a/varnish-cache/lib/libvcl/vcc_action.c +++ b/varnish-cache/lib/libvcl/vcc_action.c @@ -131,6 +131,33 @@ parse_error(struct tokenlist *tl) /*--------------------------------------------------------------------*/ +void +parse_format_time(struct tokenlist *tl) +{ + vcc_NextToken(tl); + + Expect(tl, '('); + vcc_NextToken(tl); + Fb(tl, 1, "VRT_strftime(sp, "); + + if (!vcc_StringVal(tl)) { + ERRCHK(tl); + vcc_ExpectedStringval(tl); + return; + } + Fb(tl, 0, ", "); + + Expect(tl, ','); + vcc_NextToken(tl); + + vcc_RTimeVal(tl); + Fb(tl, 0, ");"); + Expect(tl, ')'); + vcc_NextToken(tl); +} + +/*--------------------------------------------------------------------*/ + static void illegal_assignment(const struct tokenlist *tl, const char *type) { diff --git a/varnish-cache/lib/libvcl/vcc_fixed_token.c b/varnish-cache/lib/libvcl/vcc_fixed_token.c index e4648edd..3353803c 100644 --- a/varnish-cache/lib/libvcl/vcc_fixed_token.c +++ b/varnish-cache/lib/libvcl/vcc_fixed_token.c @@ -81,6 +81,15 @@ vcl_fixed_token(const char *p, const char **q) return (T_ELSE); } return (0); + case 'f': + if (p[1] == 'o' && p[2] == 'r' && p[3] == 'm' && + p[4] == 'a' && p[5] == 't' && p[6] == '_' && + p[7] == 't' && p[8] == 'i' && p[9] == 'm' && + p[10] == 'e' && !isvar(p[11])) { + *q = p + 11; + return (T_FORMAT_TIME); + } + return (0); case 'i': if (p[1] == 'n' && p[2] == 'c' && p[3] == 'l' && p[4] == 'u' && p[5] == 'd' && p[6] == 'e' @@ -138,6 +147,7 @@ const char * const vcl_tnames[256] = { [T_ELSEIF] = "elseif", [T_ELSIF] = "elsif", [T_EQ] = "==", + [T_FORMAT_TIME] = "format_time", [T_GEQ] = ">=", [T_IF] = "if", [T_INC] = "++", diff --git a/varnish-cache/lib/libvcl/vcc_gen_fixed_token.tcl b/varnish-cache/lib/libvcl/vcc_gen_fixed_token.tcl index eef6334f..dd0b1526 100755 --- a/varnish-cache/lib/libvcl/vcc_gen_fixed_token.tcl +++ b/varnish-cache/lib/libvcl/vcc_gen_fixed_token.tcl @@ -71,6 +71,12 @@ set keywords { if else elseif elsif } +# Functions +# +set functions { + format_time +} + # Non-word tokens # set magic { @@ -239,6 +245,7 @@ proc mk_token {tok str alpha} { } foreach k $keywords { mk_token $k $k 1 } +foreach k $functions { mk_token $k $k 1 } foreach k $magic { mk_token [lindex $k 1] [lindex $k 0] 0 } foreach k $extras { set t [string toupper $k] diff --git a/varnish-cache/lib/libvcl/vcc_string.c b/varnish-cache/lib/libvcl/vcc_string.c index 37fc1e0f..ca5bbbea 100644 --- a/varnish-cache/lib/libvcl/vcc_string.c +++ b/varnish-cache/lib/libvcl/vcc_string.c @@ -132,6 +132,7 @@ vcc_StringVal(struct tokenlist *tl) { struct var *vp; + fprintf(stderr, "foo\n"); if (tl->t->tok == CSTR) { EncToken(tl->fb, tl->t); vcc_NextToken(tl); @@ -146,6 +147,10 @@ vcc_StringVal(struct tokenlist *tl) vcc_NextToken(tl); return (1); } + if (tl->t->tok == ID && vcc_IdIs(tl->t, "format_string")) { + parse_format_time(tl); + return (1); + } if (tl->t->tok == VAR) { vp = vcc_FindVar(tl, tl->t, vcc_vars); if (tl->err) diff --git a/varnish-cache/lib/libvcl/vcc_token_defs.h b/varnish-cache/lib/libvcl/vcc_token_defs.h index d417655a..b73c3661 100644 --- a/varnish-cache/lib/libvcl/vcc_token_defs.h +++ b/varnish-cache/lib/libvcl/vcc_token_defs.h @@ -12,23 +12,24 @@ #define T_ELSE 130 #define T_ELSEIF 131 #define T_ELSIF 132 -#define T_INC 133 -#define T_DEC 134 -#define T_CAND 135 -#define T_COR 136 -#define T_LEQ 137 -#define T_EQ 138 -#define T_NEQ 139 -#define T_GEQ 140 -#define T_SHR 141 -#define T_SHL 142 -#define T_INCR 143 -#define T_DECR 144 -#define T_MUL 145 -#define T_DIV 146 -#define ID 147 -#define VAR 148 -#define CNUM 149 -#define CSTR 150 -#define EOI 151 -#define CSRC 152 +#define T_FORMAT_TIME 133 +#define T_INC 134 +#define T_DEC 135 +#define T_CAND 136 +#define T_COR 137 +#define T_LEQ 138 +#define T_EQ 139 +#define T_NEQ 140 +#define T_GEQ 141 +#define T_SHR 142 +#define T_SHL 143 +#define T_INCR 144 +#define T_DECR 145 +#define T_MUL 146 +#define T_DIV 147 +#define ID 148 +#define VAR 149 +#define CNUM 150 +#define CSTR 151 +#define EOI 152 +#define CSRC 153 -- 2.39.5