Commit 8eff7732 authored by Geoff Simmons's avatar Geoff Simmons

implement and test formatters for %U

parent e03aea6d
......@@ -451,28 +451,31 @@ format_T_##dir(tx_t *tx, char *name, enum VSL_tag_e tag, char **s, \
FORMAT_T(client, resp)
FORMAT_T(backend, beresp_body)
#if 0
#define FORMAT_U(dir, dx) \
static void \
format_U_##dir(logline_t *ll, char *name, enum VSL_tag_e tag, \
char **s, size_t *len) \
{ \
char *q = NULL; \
unsigned ulen; \
(void) name; \
(void) tag; \
q = memchr(TAG(ll,SLT_##dx##URL).data, '?', TAG(ll,SLT_##dx##URL).len); \
if (q == NULL) \
ulen = TAG(ll,SLT_##dx##URL).len; \
else \
ulen = q - TAG(ll,SLT_##dx##URL).data; \
*s = TAG(ll,SLT_##dx##URL).data; \
*len = ulen; \
#define FORMAT_U(dir, xurl) \
void \
format_U_##dir(tx_t *tx, char *name, enum VSL_tag_e tag, \
char **s, size_t *len) \
{ \
char *qs = NULL; \
(void) name; \
(void) tag; \
\
logline_t *rec = get_tag(tx, SLT_##xurl); \
get_payload(rec); \
*s = VSB_data(payload); \
qs = memchr(VSB_data(payload), '?', rec->len); \
if (qs == NULL) \
*len = rec->len; \
else { \
*qs = '\0'; \
*len = qs - *s; \
} \
}
FORMAT_U(client, Rx)
FORMAT_U(backend, Tx)
FORMAT_U(client, ReqURL)
FORMAT_U(backend, BereqURL)
#if 0
#define FORMAT_u(dir, hx) \
static void \
......
......@@ -91,3 +91,6 @@ formatter_f format_t;
formatter_f format_T_client;
formatter_f format_T_backend;
formatter_f format_U_client;
formatter_f format_U_backend;
......@@ -856,6 +856,43 @@ static const char
return NULL;
}
static const char
*test_format_U(void)
{
tx_t tx;
logline_t rec;
chunk_t chunk;
char *str;
size_t len;
printf("... testing format_U_*()\n");
init_tx_rec_chunk(&tx, &rec, &chunk);
MAN(chunk.data);
set_record_data(&rec, &chunk, URL_QUERY_PAYLOAD, SLT_ReqURL);
format_U_client(&tx, NULL, SLT__Bogus, &str, &len);
MASSERT(strcmp(str, "/foo") == 0);
MASSERT(len == 4);
rec.tag = SLT_BereqURL;
format_U_backend(&tx, NULL, SLT__Bogus, &str, &len);
MASSERT(strcmp(str, "/foo") == 0);
MASSERT(len == 4);
set_record_data(&rec, &chunk, URL_PAYLOAD, SLT_ReqURL);
format_U_client(&tx, NULL, SLT__Bogus, &str, &len);
MASSERT(strcmp(str, "/foo") == 0);
MASSERT(len == 4);
rec.tag = SLT_BereqURL;
format_U_backend(&tx, NULL, SLT__Bogus, &str, &len);
MASSERT(strcmp(str, "/foo") == 0);
MASSERT(len == 4);
return NULL;
}
static const char
*all_tests(void)
{
......@@ -878,6 +915,7 @@ static const char
mu_run_test(test_format_s);
mu_run_test(test_format_t);
mu_run_test(test_format_T);
mu_run_test(test_format_U);
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