Commit b38ed7c9 authored by Geoff Simmons's avatar Geoff Simmons

implement and test formatter for %t

parent c05ba7e6
......@@ -40,6 +40,7 @@
#include "varnishevent.h"
#include "format.h"
#include "strfTIM.h"
typedef struct arg_t {
char *name;
......@@ -409,28 +410,28 @@ FORMAT_r(backend, Bereq)
FORMAT(client, s, RespStatus)
FORMAT(backend, s, BerespStatus)
#if 0
#define FORMAT_tim(ltr, fmt, extra) \
static void \
format_##ltr(logline_t *ll, char *name, enum VSL_tag_e tag, \
char **s, size_t *len) \
void \
format_##ltr(tx_t *tx, char *name, enum VSL_tag_e tag, \
char **s, size_t *len) \
{ \
struct tm t; \
double t; \
(void) tag; \
extra; \
if (get_tm(ll, &t)) { \
AN(scratch); \
size_t n = strftime(scratch, config.max_reclen, fmt, &t); \
if (n == 0) \
*scratch = '\0'; \
*s = scratch; \
*len = strlen(scratch); \
} \
(extra); \
\
t = get_tm(tx); \
AN(scratch); \
size_t n = strfTIMlocal(scratch, config.max_reclen, fmt, t); \
if (n == 0) \
*scratch = '\0'; \
*s = scratch; \
*len = strlen(scratch); \
}
FORMAT_tim(t, "[%d/%b/%Y:%T %z]", (void) name)
#if 0
#define FORMAT_U(dir, dx) \
static void \
format_U_##dir(logline_t *ll, char *name, enum VSL_tag_e tag, \
......
......@@ -86,3 +86,5 @@ formatter_f format_r_backend;
formatter_f format_s_client;
formatter_f format_s_backend;
formatter_f format_t;
......@@ -21,6 +21,7 @@ test_format_SOURCES = \
test_format_LDADD = \
../config.$(OBJEXT) \
../strfTIM.$(OBJEXT) \
../format.$(OBJEXT) \
@VARNISH_LIBS@ @VARNISH_LIBVARNISH_LIB@ -lm -lvarnish
......
......@@ -794,6 +794,41 @@ static const char
return NULL;
}
static const char
*test_format_t(void)
{
tx_t tx;
logline_t rec;
chunk_t chunk;
char *str;
const char *error;
size_t len;
vre_t *time_re;
int n;
printf("... testing format_t()\n");
#define HTTP_DATA_REGEX \
"^\\[\\d\\d/Mar/2015:\\d\\d:\\d\\d:\\d\\d [+-]\\d{4}\\]$"
time_re = VRE_compile(HTTP_DATA_REGEX, 0, &error, &n);
VMASSERT(time_re != NULL,
"Error compiling '" HTTP_DATA_REGEX "': %s (offset %d)",
error, n);
init_tx_rec_chunk(&tx, &rec, &chunk);
MAN(chunk.data);
set_record_data(&rec, &chunk, T1, SLT_Timestamp);
format_t(&tx, NULL, SLT__Bogus, &str, &len);
n = VRE_exec(time_re, str, strlen(str), 0, 0, NULL, 0, NULL);
VMASSERT(n > 0, "'%s' does not match '" HTTP_DATA_REGEX "', "
"return code = %d", str, n);
MASSERT(len == 28);
return NULL;
}
static const char
*all_tests(void)
{
......@@ -814,6 +849,7 @@ static const char
mu_run_test(test_format_q);
mu_run_test(test_format_r);
mu_run_test(test_format_s);
mu_run_test(test_format_t);
return NULL;
}
......
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