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, \ ...@@ -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(client, resp)
FORMAT_T(backend, beresp_body) FORMAT_T(backend, beresp_body)
#if 0 #define FORMAT_U(dir, xurl) \
void \
#define FORMAT_U(dir, dx) \ format_U_##dir(tx_t *tx, char *name, enum VSL_tag_e tag, \
static void \ char **s, size_t *len) \
format_U_##dir(logline_t *ll, char *name, enum VSL_tag_e tag, \ { \
char **s, size_t *len) \ char *qs = NULL; \
{ \ (void) name; \
char *q = NULL; \ (void) tag; \
unsigned ulen; \ \
(void) name; \ logline_t *rec = get_tag(tx, SLT_##xurl); \
(void) tag; \ get_payload(rec); \
q = memchr(TAG(ll,SLT_##dx##URL).data, '?', TAG(ll,SLT_##dx##URL).len); \ *s = VSB_data(payload); \
if (q == NULL) \ qs = memchr(VSB_data(payload), '?', rec->len); \
ulen = TAG(ll,SLT_##dx##URL).len; \ if (qs == NULL) \
else \ *len = rec->len; \
ulen = q - TAG(ll,SLT_##dx##URL).data; \ else { \
*s = TAG(ll,SLT_##dx##URL).data; \ *qs = '\0'; \
*len = ulen; \ *len = qs - *s; \
} \
} }
FORMAT_U(client, Rx) FORMAT_U(client, ReqURL)
FORMAT_U(backend, Tx) FORMAT_U(backend, BereqURL)
#if 0
#define FORMAT_u(dir, hx) \ #define FORMAT_u(dir, hx) \
static void \ static void \
......
...@@ -91,3 +91,6 @@ formatter_f format_t; ...@@ -91,3 +91,6 @@ formatter_f format_t;
formatter_f format_T_client; formatter_f format_T_client;
formatter_f format_T_backend; formatter_f format_T_backend;
formatter_f format_U_client;
formatter_f format_U_backend;
...@@ -856,6 +856,43 @@ static const char ...@@ -856,6 +856,43 @@ static const char
return NULL; 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 static const char
*all_tests(void) *all_tests(void)
{ {
...@@ -878,6 +915,7 @@ static const char ...@@ -878,6 +915,7 @@ static const char
mu_run_test(test_format_s); mu_run_test(test_format_s);
mu_run_test(test_format_t); mu_run_test(test_format_t);
mu_run_test(test_format_T); mu_run_test(test_format_T);
mu_run_test(test_format_U);
return NULL; 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