Commit daa6c31d authored by Geoff Simmons's avatar Geoff Simmons

implement and test formatters for %O

parent 2905effa
......@@ -268,18 +268,38 @@ format_h_##dir(tx_t *tx, char *name, enum VSL_tag_e tag, char **s, \
FORMAT_h(client, ReqStart, 0)
FORMAT_h(backend, Backend, 2)
static void
format_IO_client(tx_t *tx, int req_fld, int pipe_fld, char **s, size_t *len)
{
int field;
logline_t *rec = get_tag(tx, SLT_ReqAcct);
if (rec != NULL)
field = req_fld;
else {
rec = get_tag(tx, SLT_PipeAcct);
field = pipe_fld;
}
*s = get_rec_fld(rec, field);
*len = strlen(*s);
}
static inline void
format_IO_backend(tx_t *tx, int field, char **s, size_t *len)
{
logline_t *rec = get_tag(tx, SLT_BereqAcct);
*s = get_rec_fld(rec, field);
*len = strlen(*s);
}
void
format_I_client(tx_t *tx, char *name, enum VSL_tag_e tag, char **s,
size_t *len)
size_t *len)
{
(void) name;
(void) tag;
logline_t *rec = get_tag(tx, SLT_ReqAcct);
if (rec == NULL)
rec = get_tag(tx, SLT_PipeAcct);
*s = get_rec_fld(rec, 2);
*len = strlen(*s);
format_IO_client(tx, 2, 2, s, len);
}
void
......@@ -289,14 +309,32 @@ format_I_backend(tx_t *tx, char *name, enum VSL_tag_e tag, char **s,
(void) name;
(void) tag;
logline_t *rec = get_tag(tx, SLT_BereqAcct);
*s = get_rec_fld(rec, 5);
*len = strlen(*s);
format_IO_backend(tx, 5, s, len);
}
FORMAT(client, m, ReqMethod)
FORMAT(backend, m, BereqMethod)
void
format_O_client(tx_t *tx, char *name, enum VSL_tag_e tag, char **s,
size_t *len)
{
(void) name;
(void) tag;
format_IO_client(tx, 5, 3, s, len);
}
void
format_O_backend(tx_t *tx, char *name, enum VSL_tag_e tag, char **s,
size_t *len)
{
(void) name;
(void) tag;
format_IO_backend(tx, 2, s, len);
}
#if 0
#define FORMAT_q(dir, xurl) \
......
......@@ -71,3 +71,6 @@ formatter_f format_I_backend;
formatter_f format_m_client;
formatter_f format_m_backend;
formatter_f format_O_client;
formatter_f format_O_backend;
......@@ -555,6 +555,38 @@ static const char
return NULL;
}
static const char
*test_format_O(void)
{
tx_t tx;
logline_t rec;
chunk_t chunk;
char *str;
size_t len;
printf("... testing format_O_*()\n");
init_tx_rec_chunk(&tx, &rec, &chunk);
MAN(chunk.data);
set_record_data(&rec, &chunk, REQACCT_PAYLOAD, SLT_ReqAcct);
format_O_client(&tx, NULL, SLT__Bogus, &str, &len);
MASSERT(strcmp(str, "283") == 0);
MASSERT(len == 3);
rec.tag = SLT_BereqAcct;
format_O_backend(&tx, NULL, SLT__Bogus, &str, &len);
MASSERT(strcmp(str, "60") == 0);
MASSERT(len == 2);
set_record_data(&rec, &chunk, PIPEACCT_PAYLOAD, SLT_PipeAcct);
format_O_client(&tx, NULL, SLT__Bogus, &str, &len);
MASSERT(strcmp(str, "105") == 0);
MASSERT(len == 3);
return NULL;
}
static const char
*all_tests(void)
{
......@@ -571,6 +603,7 @@ static const char
mu_run_test(test_format_h);
mu_run_test(test_format_I);
mu_run_test(test_format_m);
mu_run_test(test_format_O);
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