Commit 53b98814 authored by Geoff Simmons's avatar Geoff Simmons

implement and test formatters for %H conversion

parent 964a9b46
...@@ -41,8 +41,8 @@ ...@@ -41,8 +41,8 @@
#include "varnishevent.h" #include "varnishevent.h"
#include "format.h" #include "format.h"
typedef void formatter_f(logline_t *ll, char *name, enum VSL_tag_e tag, typedef void formatter_f(tx_t *tx, char *name, enum VSL_tag_e tag,
char **s, size_t *len); char **s, size_t *len);
typedef struct arg_t { typedef struct arg_t {
char *name; char *name;
...@@ -196,19 +196,25 @@ get_tm(tx_t *tx) ...@@ -196,19 +196,25 @@ get_tm(tx_t *tx)
return epocht; return epocht;
} }
#if 0 #define FORMAT(dir, ltr, slt) \
void \
#define FORMAT(dir, ltr, slt) \ format_##ltr##_##dir(tx_t *tx, char *name, enum VSL_tag_e tag, char **s, \
static void \ size_t *len) \
format_##ltr##_##dir(logline_t *ll, char *name, enum VSL_tag_e tag, \ { \
char **s, size_t *len) \ (void) name; \
{ \ (void) tag; \
(void) name; \ \
(void) tag; \ logline_t *rec = get_tag(tx, SLT_##slt); \
if (TAG(ll,SLT_##slt).len) \ get_payload(rec); \
RETURN_REC(TAG(ll,SLT_##slt), s, len); \ *s = VSB_data(payload); \
*len = VSB_len(payload); \
} }
FORMAT(client, H, ReqProtocol)
FORMAT(backend, H, BereqProtocol)
#if 0
#define FORMAT_b(dir, hx) \ #define FORMAT_b(dir, hx) \
static void \ static void \
format_b_##dir(logline_t *ll, char *name, enum VSL_tag_e tag, \ format_b_##dir(logline_t *ll, char *name, enum VSL_tag_e tag, \
...@@ -226,9 +232,6 @@ format_b_##dir(logline_t *ll, char *name, enum VSL_tag_e tag, \ ...@@ -226,9 +232,6 @@ format_b_##dir(logline_t *ll, char *name, enum VSL_tag_e tag, \
FORMAT_b(client, tx) FORMAT_b(client, tx)
FORMAT_b(backend, rx) FORMAT_b(backend, rx)
FORMAT(client, H, RxProtocol)
FORMAT(backend, H, TxProtocol)
static void static void
format_h_client(logline_t *ll, char *name, enum VSL_tag_e tag, format_h_client(logline_t *ll, char *name, enum VSL_tag_e tag,
char **s, size_t *len) char **s, size_t *len)
......
...@@ -38,9 +38,15 @@ struct vsb *payload; ...@@ -38,9 +38,15 @@ struct vsb *payload;
#define TS_START_REGEX "^\\s*Start\\s*:\\s*(.+)$" #define TS_START_REGEX "^\\s*Start\\s*:\\s*(.+)$"
vre_t *time_start_re; vre_t *time_start_re;
typedef void formatter_f(tx_t *tx, char *name, enum VSL_tag_e tag,
char **s, size_t *len);
void get_payload(logline_t *rec); void get_payload(logline_t *rec);
logline_t *get_tag(tx_t *tx, enum VSL_tag_e tag); logline_t *get_tag(tx_t *tx, enum VSL_tag_e tag);
char *get_hdr(tx_t *tx, enum VSL_tag_e tag, vre_t *hdr_re); char *get_hdr(tx_t *tx, enum VSL_tag_e tag, vre_t *hdr_re);
char *get_fld(const char *str, int n); char *get_fld(const char *str, int n);
char *get_rec_fld(logline_t *rec, int n); char *get_rec_fld(logline_t *rec, int n);
double get_tm(tx_t *tx); double get_tm(tx_t *tx);
formatter_f format_H_client;
formatter_f format_H_backend;
...@@ -345,6 +345,44 @@ static const char ...@@ -345,6 +345,44 @@ static const char
return NULL; return NULL;
} }
static const char
*test_format_H(void)
{
tx_t tx;
logline_t rec;
chunk_t chunk;
char *str;
size_t len;
printf("... testing format_H_*()\n");
tx.magic = TX_MAGIC;
tx.t = TX_TIME;
VSTAILQ_INIT(&tx.lines);
VSTAILQ_INSERT_TAIL(&tx.lines, &rec, linelist);
rec.magic = LOGLINE_MAGIC;
VSTAILQ_INIT(&rec.chunks);
VSTAILQ_INSERT_TAIL(&rec.chunks, &chunk, chunklist);
chunk.magic = CHUNK_MAGIC;
chunk.data = (char *) calloc(1, config.chunk_size);
MAN(chunk.data);
rec.len = strlen("HTTP/1.1");
rec.tag = SLT_ReqProtocol;
strcpy(chunk.data, "HTTP/1.1");
VSTAILQ_INSERT_TAIL(&rec.chunks, &chunk, chunklist);
format_H_client(&tx, NULL, SLT__Bogus, &str, &len);
MASSERT(strcmp(str, "HTTP/1.1") == 0);
MASSERT(len == strlen("HTTP/1.1"));
rec.tag = SLT_BereqProtocol;
format_H_backend(&tx, NULL, SLT__Bogus, &str, &len);
MASSERT(strcmp(str, "HTTP/1.1") == 0);
MASSERT(len == strlen("HTTP/1.1"));
return NULL;
}
static const char static const char
*all_tests(void) *all_tests(void)
{ {
...@@ -355,6 +393,7 @@ static const char ...@@ -355,6 +393,7 @@ static const char
mu_run_test(test_format_get_fld); mu_run_test(test_format_get_fld);
mu_run_test(test_format_get_rec_fld); mu_run_test(test_format_get_rec_fld);
mu_run_test(test_format_get_tm); mu_run_test(test_format_get_tm);
mu_run_test(test_format_H);
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