Commit 4f343c25 authored by Geoff Simmons's avatar Geoff Simmons

implement and test the formatter for %{tag:X}x

parent 1d6f8f85
......@@ -636,18 +636,21 @@ format_VCL_Log(tx_t *tx, char *name, enum VSL_tag_e tag, char **s, size_t *len)
*len = strlen(l);
}
#if 0
static void
format_SLT(logline_t *ll, char *name, enum VSL_tag_e tag,
char **s, size_t *len)
void
format_SLT(tx_t *tx, char *name, enum VSL_tag_e tag, char **s, size_t *len)
{
(void) name;
if (TAG(ll,tag).len)
RETURN_REC(TAG(ll,tag), s, len);
logline_t *rec = get_tag(tx, tag);
if (rec != NULL) {
get_payload(rec);
*s = VSB_data(payload);
*len = VSB_len(payload);
}
}
#if 0
static void
format_incomplete(logline_t *ll, char *name, enum VSL_tag_e tag,
char **s, size_t *len)
......
......@@ -98,3 +98,5 @@ formatter_f format_Xttfb_backend;
formatter_f format_VCL_disp;
formatter_f format_VCL_Log;
formatter_f format_SLT;
......@@ -1212,6 +1212,44 @@ static const char
return NULL;
}
static const char
*test_format_SLT(void)
{
tx_t tx;
logline_t rec;
chunk_t chunk;
char *str;
size_t len;
printf("... testing format_SLT()\n");
init_tx_rec_chunk(&tx, &rec, &chunk);
MAN(chunk.data);
set_record_data(&rec, &chunk, "no backend connection", SLT_FetchError);
format_SLT(&tx, NULL, SLT_FetchError, &str, &len);
MASSERT(strcmp(str, "no backend connection") == 0);
MASSERT(len == 21);
/* record not found */
str = NULL;
len = 0;
rec.tag = SLT_BereqHeader;
format_SLT(&tx, NULL, SLT_FetchError, &str, &len);
MAZ(str);
MAZ(len);
/* Binary tag with non-printables in the payload */
memcpy(chunk.data, "foo\0\xFF bar", 9);
rec.len = 9;
rec.tag = SLT_Debug;
format_SLT(&tx, NULL, SLT_Debug, &str, &len);
MASSERT(strcmp(str, "foo\0\xFF bar") == 0);
MASSERT(len == 9);
return NULL;
}
static const char
*all_tests(void)
{
......@@ -1242,6 +1280,7 @@ static const char
mu_run_test(test_format_Xttfb);
mu_run_test(test_format_VCL_disp);
mu_run_test(test_format_VCL_Log);
mu_run_test(test_format_SLT);
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