Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
V
varnishevent
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
1
Issues
1
List
Board
Labels
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
uplex-varnish
varnishevent
Commits
ec0c8a2c
Commit
ec0c8a2c
authored
Mar 31, 2015
by
Geoff Simmons
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
implement and test %r formatters
parent
0a92f869
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
197 additions
and
47 deletions
+197
-47
format.c
src/format.c
+49
-44
format.h
src/format.h
+6
-0
test_format.c
src/test/test_format.c
+142
-3
No files found.
src/format.c
View file @
ec0c8a2c
...
...
@@ -356,52 +356,57 @@ format_q_##dir(tx_t *tx, char *name, enum VSL_tag_e tag, \
FORMAT_q
(
client
,
ReqURL
)
FORMAT_q
(
backend
,
BereqURL
)
#if 0
#define FORMAT_r(dir, dx, hx) \
static void \
format_r_##dir(logline_t *ll, char *name, enum VSL_tag_e tag, \
char **s, size_t *len) \
{ \
(void) name; \
(void) tag; \
\
record_t *rec; \
\
rec = &TAG(ll, SLT_##dx##Request); \
if (rec->len) \
snprintf(scratch, rec->len+1, "%s", rec->data); \
else \
strcpy(scratch, "-"); \
strcat(scratch, " "); \
\
if ((rec = GET_HDR(ll, hx, "Host")) != NULL) { \
if (strncmp(rec->data, "http://", 7) != 0) \
strcat(scratch, "http://"); \
strncat(scratch, rec->data+6, rec->len-6); \
} \
else \
strcat(scratch, "http://localhost"); \
\
rec = &TAG(ll, SLT_##dx##URL); \
if (rec->len) \
strncat(scratch, rec->data, rec->len); \
else \
strcat(scratch, "-"); \
\
strcat(scratch, " "); \
rec = &TAG(ll, SLT_##dx##Protocol); \
if (rec->len) \
strncat(scratch, rec->data, rec->len); \
else \
strcat(scratch, "HTTP/1.0"); \
\
*s = scratch; \
*len = strlen(scratch); \
#define FORMAT_r(dir, dx) \
void \
format_r_##dir(tx_t *tx, char *name, enum VSL_tag_e tag, \
char **s, size_t *len) \
{ \
char *str; \
(void) name; \
(void) tag; \
\
logline_t *rec = get_tag(tx, SLT_##dx##Method); \
if (rec != NULL) { \
get_payload(rec); \
sprintf(scratch, VSB_data(payload)); \
} \
else \
strcpy(scratch, "-"); \
strcat(scratch, " "); \
\
if ((str = get_hdr(tx, SLT_##dx##Header, host_re)) != NULL) { \
if (strncmp(str, "http://", 7) != 0) \
strcat(scratch, "http://"); \
strcat(scratch, str); \
} \
else \
strcat(scratch, "http://localhost"); \
\
rec = get_tag(tx, SLT_##dx##URL); \
if (rec->len) { \
get_payload(rec); \
strcat(scratch, VSB_data(payload)); \
} \
else \
strcat(scratch, "-"); \
\
strcat(scratch, " "); \
rec = get_tag(tx, SLT_##dx##Protocol); \
if (rec->len) { \
get_payload(rec); \
strcat(scratch, VSB_data(payload)); \
} \
else \
strcat(scratch, "HTTP/1.0"); \
\
*s = scratch; \
*len = strlen(scratch); \
}
FORMAT_r(client, Rx, rx)
FORMAT_r(backend, Tx, tx)
FORMAT_r
(
client
,
Req
)
FORMAT_r
(
backend
,
Bereq
)
#if 0
FORMAT(client, s, TxStatus)
FORMAT(backend, s, RxStatus)
...
...
src/format.h
View file @
ec0c8a2c
...
...
@@ -44,6 +44,9 @@ vre_t *time_resp_re;
#define TS_BERESP_BODY_REGEX "^\\s*BerespBody\\s*:\\s*(.+)$"
vre_t
*
time_beresp_body_re
;
#define HOST_REGEX "^\\s*Host\\s*:\\s*(.+)$"
vre_t
*
host_re
;
typedef
void
formatter_f
(
tx_t
*
tx
,
char
*
name
,
enum
VSL_tag_e
tag
,
char
**
s
,
size_t
*
len
);
...
...
@@ -77,3 +80,6 @@ formatter_f format_O_backend;
formatter_f
format_q_client
;
formatter_f
format_q_backend
;
formatter_f
format_r_client
;
formatter_f
format_r_backend
;
src/test/test_format.c
View file @
ec0c8a2c
...
...
@@ -44,10 +44,8 @@
int
tests_run
=
0
;
static
void
init_tx
_rec_chunk
(
tx_t
*
tx
,
logline_t
*
rec
,
chunk_t
*
chunk
)
add
_rec_chunk
(
tx_t
*
tx
,
logline_t
*
rec
,
chunk_t
*
chunk
)
{
tx
->
magic
=
TX_MAGIC
;
VSTAILQ_INIT
(
&
tx
->
lines
);
VSTAILQ_INSERT_TAIL
(
&
tx
->
lines
,
rec
,
linelist
);
rec
->
magic
=
LOGLINE_MAGIC
;
VSTAILQ_INIT
(
&
rec
->
chunks
);
...
...
@@ -56,6 +54,14 @@ init_tx_rec_chunk(tx_t *tx, logline_t *rec, chunk_t *chunk)
chunk
->
data
=
(
char
*
)
calloc
(
1
,
config
.
chunk_size
);
}
static
void
init_tx_rec_chunk
(
tx_t
*
tx
,
logline_t
*
rec
,
chunk_t
*
chunk
)
{
tx
->
magic
=
TX_MAGIC
;
VSTAILQ_INIT
(
&
tx
->
lines
);
add_rec_chunk
(
tx
,
rec
,
chunk
);
}
static
void
set_record_data
(
logline_t
*
rec
,
chunk_t
*
chunk
,
const
char
*
data
,
enum
VSL_tag_e
tag
)
...
...
@@ -98,6 +104,10 @@ static const char
"Error compiling "
TS_BERESP_BODY_REGEX
": %s (offset %d)"
,
error
,
erroroffset
);
host_re
=
VRE_compile
(
HOST_REGEX
,
VRE_CASELESS
,
&
error
,
&
erroroffset
);
VMASSERT
(
host_re
!=
NULL
,
"Error compiling "
HOST_REGEX
": %s (offset %d)"
,
error
,
erroroffset
);
return
NULL
;
}
...
...
@@ -628,6 +638,134 @@ static const char
return
NULL
;
}
static
const
char
*
test_format_r
(
void
)
{
tx_t
tx
;
logline_t
rec_method
,
rec_host
,
rec_url
,
rec_proto
;
chunk_t
chunk_method
,
chunk_host
,
chunk_url
,
chunk_proto
;
char
*
str
;
size_t
len
;
printf
(
"... testing format_r_*()
\n
"
);
init_tx_rec_chunk
(
&
tx
,
&
rec_method
,
&
chunk_method
);
MAN
(
chunk_method
.
data
);
add_rec_chunk
(
&
tx
,
&
rec_host
,
&
chunk_host
);
MAN
(
chunk_host
.
data
);
add_rec_chunk
(
&
tx
,
&
rec_url
,
&
chunk_url
);
MAN
(
chunk_url
.
data
);
add_rec_chunk
(
&
tx
,
&
rec_proto
,
&
chunk_proto
);
MAN
(
chunk_proto
.
data
);
set_record_data
(
&
rec_method
,
&
chunk_method
,
"GET"
,
SLT_ReqMethod
);
set_record_data
(
&
rec_host
,
&
chunk_host
,
"Host: www.foobar.com"
,
SLT_ReqHeader
);
set_record_data
(
&
rec_url
,
&
chunk_url
,
URL_PAYLOAD
,
SLT_ReqURL
);
set_record_data
(
&
rec_proto
,
&
chunk_proto
,
PROTOCOL_PAYLOAD
,
SLT_ReqProtocol
);
format_r_client
(
&
tx
,
NULL
,
SLT__Bogus
,
&
str
,
&
len
);
MASSERT
(
strcmp
(
str
,
"GET http://www.foobar.com/foo HTTP/1.1"
)
==
0
);
MASSERT
(
len
==
38
);
rec_method
.
tag
=
SLT_BereqMethod
;
rec_host
.
tag
=
SLT_BereqHeader
;
rec_url
.
tag
=
SLT_BereqURL
;
rec_proto
.
tag
=
SLT_BereqProtocol
;
format_r_backend
(
&
tx
,
NULL
,
SLT__Bogus
,
&
str
,
&
len
);
MASSERT
(
strcmp
(
str
,
"GET http://www.foobar.com/foo HTTP/1.1"
)
==
0
);
MASSERT
(
len
==
38
);
/* No method record */
rec_method
.
tag
=
SLT__Bogus
;
rec_host
.
tag
=
SLT_ReqHeader
;
rec_url
.
tag
=
SLT_ReqURL
;
rec_proto
.
tag
=
SLT_ReqProtocol
;
format_r_client
(
&
tx
,
NULL
,
SLT__Bogus
,
&
str
,
&
len
);
MASSERT
(
strcmp
(
str
,
"- http://www.foobar.com/foo HTTP/1.1"
)
==
0
);
MASSERT
(
len
==
36
);
rec_host
.
tag
=
SLT_BereqHeader
;
rec_url
.
tag
=
SLT_BereqURL
;
rec_proto
.
tag
=
SLT_BereqProtocol
;
format_r_backend
(
&
tx
,
NULL
,
SLT__Bogus
,
&
str
,
&
len
);
MASSERT
(
strcmp
(
str
,
"- http://www.foobar.com/foo HTTP/1.1"
)
==
0
);
MASSERT
(
len
==
36
);
/* No host header */
rec_method
.
tag
=
SLT_ReqMethod
;
set_record_data
(
&
rec_host
,
&
chunk_host
,
"Foo: bar"
,
SLT_ReqHeader
);
rec_url
.
tag
=
SLT_ReqURL
;
rec_proto
.
tag
=
SLT_ReqProtocol
;
format_r_client
(
&
tx
,
NULL
,
SLT__Bogus
,
&
str
,
&
len
);
MASSERT
(
strcmp
(
str
,
"GET http://localhost/foo HTTP/1.1"
)
==
0
);
MASSERT
(
len
==
33
);
rec_method
.
tag
=
SLT_BereqMethod
;
rec_host
.
tag
=
SLT_BereqHeader
;
rec_url
.
tag
=
SLT_BereqURL
;
rec_proto
.
tag
=
SLT_BereqProtocol
;
format_r_backend
(
&
tx
,
NULL
,
SLT__Bogus
,
&
str
,
&
len
);
MASSERT
(
strcmp
(
str
,
"GET http://localhost/foo HTTP/1.1"
)
==
0
);
MASSERT
(
len
==
33
);
/* No header record */
rec_method
.
tag
=
SLT_ReqMethod
;
rec_host
.
tag
=
SLT__Bogus
;
rec_url
.
tag
=
SLT_ReqURL
;
rec_proto
.
tag
=
SLT_ReqProtocol
;
format_r_client
(
&
tx
,
NULL
,
SLT__Bogus
,
&
str
,
&
len
);
MASSERT
(
strcmp
(
str
,
"GET http://localhost/foo HTTP/1.1"
)
==
0
);
MASSERT
(
len
==
33
);
rec_method
.
tag
=
SLT_BereqMethod
;
rec_url
.
tag
=
SLT_BereqURL
;
rec_proto
.
tag
=
SLT_BereqProtocol
;
format_r_backend
(
&
tx
,
NULL
,
SLT__Bogus
,
&
str
,
&
len
);
MASSERT
(
strcmp
(
str
,
"GET http://localhost/foo HTTP/1.1"
)
==
0
);
MASSERT
(
len
==
33
);
/* URL record empty */
set_record_data
(
&
rec_host
,
&
chunk_host
,
"Host: www.foobar.com"
,
SLT_ReqHeader
);
rec_method
.
tag
=
SLT_ReqMethod
;
rec_url
.
tag
=
SLT_ReqURL
;
rec_url
.
len
=
0
;
rec_proto
.
tag
=
SLT_ReqProtocol
;
format_r_client
(
&
tx
,
NULL
,
SLT__Bogus
,
&
str
,
&
len
);
MASSERT
(
strcmp
(
str
,
"GET http://www.foobar.com- HTTP/1.1"
)
==
0
);
MASSERT
(
len
==
35
);
rec_method
.
tag
=
SLT_BereqMethod
;
rec_host
.
tag
=
SLT_BereqHeader
;
rec_url
.
tag
=
SLT_BereqURL
;
rec_proto
.
tag
=
SLT_BereqProtocol
;
format_r_backend
(
&
tx
,
NULL
,
SLT__Bogus
,
&
str
,
&
len
);
MASSERT
(
strcmp
(
str
,
"GET http://www.foobar.com- HTTP/1.1"
)
==
0
);
MASSERT
(
len
==
35
);
/* Proto record empty */
rec_method
.
tag
=
SLT_ReqMethod
;
rec_host
.
tag
=
SLT_ReqHeader
;
rec_url
.
tag
=
SLT_ReqURL
;
rec_url
.
len
=
strlen
(
URL_PAYLOAD
);
rec_proto
.
tag
=
SLT_ReqProtocol
;
rec_proto
.
len
=
0
;
format_r_client
(
&
tx
,
NULL
,
SLT__Bogus
,
&
str
,
&
len
);
MASSERT
(
strcmp
(
str
,
"GET http://www.foobar.com/foo HTTP/1.0"
)
==
0
);
MASSERT
(
len
==
38
);
rec_method
.
tag
=
SLT_BereqMethod
;
rec_host
.
tag
=
SLT_BereqHeader
;
rec_url
.
tag
=
SLT_BereqURL
;
rec_proto
.
tag
=
SLT_BereqProtocol
;
format_r_backend
(
&
tx
,
NULL
,
SLT__Bogus
,
&
str
,
&
len
);
MASSERT
(
strcmp
(
str
,
"GET http://www.foobar.com/foo HTTP/1.0"
)
==
0
);
MASSERT
(
len
==
38
);
return
NULL
;
}
static
const
char
*
all_tests
(
void
)
{
...
...
@@ -646,6 +784,7 @@ static const char
mu_run_test
(
test_format_m
);
mu_run_test
(
test_format_O
);
mu_run_test
(
test_format_q
);
mu_run_test
(
test_format_r
);
return
NULL
;
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment