Commit bb1b526e authored by Geoff Simmons's avatar Geoff Simmons

Add the LOCAL,UTC options to dump_keys().

Also change the date outputs to include time zones.
parent 12c05ea6
......@@ -612,10 +612,10 @@ KEY_Updated(VRT_CTX, uint8_t *id, uint8_t idlen)
return (key_time(ctx, id, idlen, UPDATED));
}
#define TIMSZ (sizeof("YYYY-mm-ddTHH:MM:SS"))
#define TIMSZ (sizeof("YYYY-mm-ddTHH:MM:SS+hh:mm"))
void
KEY_Dump(VRT_CTX)
KEY_Dump(VRT_CTX, enum tz tz)
{
struct key_tree *tree_h;
struct key *key;
......@@ -625,6 +625,8 @@ KEY_Dump(VRT_CTX)
char tim_buf[TIMSZ];
const char *p[0];
struct strands strands = { 1, p };
struct tm *(*time_r[2])(const time_t *, struct tm *) =
{localtime_r, gmtime_r};
CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
......@@ -641,13 +643,13 @@ KEY_Dump(VRT_CTX)
VSB_bcat(vsb, key->id, key->idlen);
tim = (time_t)key->added;
localtime_r(&tim, &tm);
strftime(tim_buf, TIMSZ, "%Y-%m-%dT%T", &tm);
(time_r[tz])(&tim, &tm);
strftime(tim_buf, TIMSZ, "%FT%T%z", &tm);
VSB_printf(vsb, ",%s,", tim_buf);
tim = (time_t)key->updated;
localtime_r(&tim, &tm);
strftime(tim_buf, TIMSZ, "%Y-%m-%dT%T", &tm);
(time_r[tz])(&tim, &tm);
strftime(tim_buf, TIMSZ, "%FT%T%z", &tm);
VSB_printf(vsb, "%s\n", tim_buf);
}
KEY_Unlock(i);
......
......@@ -32,6 +32,11 @@
#include "vrt.h"
#endif
enum tz {
LOCAL = 0,
UTC,
};
int KEY_Init(VRT_CTX);
void KEY_Fini(void);
void KEY_Rdlock(uint8_t idlen);
......@@ -45,4 +50,4 @@ int KEY_Delete(VRT_CTX, uint8_t *id, uint8_t idlen);
VCL_BOOL KEY_Exists(uint8_t *id, uint8_t idlen);
VCL_TIME KEY_Added(VRT_CTX, uint8_t *id, uint8_t idlen);
VCL_TIME KEY_Updated(VRT_CTX, uint8_t *id, uint8_t idlen);
void KEY_Dump(VRT_CTX);
void KEY_Dump(VRT_CTX, enum tz tz);
......@@ -238,7 +238,12 @@ varnish v1 -vcl {
sub vcl_synth {
set resp.http.Content-Type = "text/csv";
ece.dump_keys();
if (req.url == "/3") {
ece.dump_keys(UTC);
}
else {
ece.dump_keys();
}
return (deliver);
}
}
......@@ -255,10 +260,20 @@ client c1 {
expect resp.status == 200
expect resp.http.Content-Type == "text/csv"
expect resp.body ~ "^id,added,updated"
expect resp.body ~ {(?m)^foo,(\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2},?){2}$}
expect resp.body ~ {(?m)^bar,(\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2},?){2}$}
expect resp.body ~ {(?m)^baz,(\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2},?){2}$}
expect resp.body ~ {(?m)^quux,(\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2},?){2}$}
expect resp.body ~ {(?m)^foo,(\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}[+-]\d{2}:?\d{2},?){2}$}
expect resp.body ~ {(?m)^bar,(\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}[+-]\d{2}:?\d{2},?){2}$}
expect resp.body ~ {(?m)^baz,(\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}[+-]\d{2}:?\d{2},?){2}$}
expect resp.body ~ {(?m)^quux,(\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}[+-]\d{2}:?\d{2},?){2}$}
txreq -url /3
rxresp
expect resp.status == 200
expect resp.http.Content-Type == "text/csv"
expect resp.body ~ "^id,added,updated"
expect resp.body ~ {(?m)^foo,(\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}[+-]\d{2}:?\d{2},?){2}$}
expect resp.body ~ {(?m)^bar,(\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}[+-]\d{2}:?\d{2},?){2}$}
expect resp.body ~ {(?m)^baz,(\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}[+-]\d{2}:?\d{2},?){2}$}
expect resp.body ~ {(?m)^quux,(\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}[+-]\d{2}:?\d{2},?){2}$}
} -run
varnish v1 -vcl {
......
......@@ -189,8 +189,10 @@ vmod_key_updated(VRT_CTX, VCL_STRING id)
}
VCL_VOID
vmod_dump_keys(VRT_CTX)
vmod_dump_keys(VRT_CTX, VCL_ENUM zone)
{
enum tz tz = LOCAL;
CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
if ((ctx->method & VCL_MET_SYNTH) == 0) {
......@@ -198,7 +200,9 @@ vmod_dump_keys(VRT_CTX)
return;
}
KEY_Dump(ctx);
if (zone == VENUM(UTC))
tz = UTC;
KEY_Dump(ctx, tz);
}
VCL_STRING
......
......@@ -104,7 +104,7 @@ last updated.
XXX ...
$Function VOID dump_keys()
$Function VOID dump_keys(ENUM {LOCAL, UTC} tz=LOCAL)
Generate a synthetic client response body with information in CSV
format (comma-separated values) about all of the keys that are
......
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