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
fe7ffa86
Commit
fe7ffa86
authored
Apr 01, 2015
by
Geoff Simmons
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
implement and test formatters for %u
parent
8eff7732
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
89 additions
and
13 deletions
+89
-13
format.c
src/format.c
+12
-13
format.h
src/format.h
+6
-0
Makefile.am
src/test/Makefile.am
+1
-0
test_format.c
src/test/test_format.c
+70
-0
No files found.
src/format.c
View file @
fe7ffa86
...
...
@@ -475,23 +475,20 @@ format_U_##dir(tx_t *tx, char *name, enum VSL_tag_e tag, \
FORMAT_U
(
client
,
ReqURL
)
FORMAT_U
(
backend
,
BereqURL
)
#if 0
#define FORMAT_u(dir, hx) \
static void
\
format_u_##dir(
logline_t *ll, char *name, enum VSL_tag_e tag,
\
void
\
format_u_##dir(
tx_t *tx, char *name, enum VSL_tag_e tag,
\
char **s, size_t *len) \
{ \
(void) name; \
(void) tag; \
record_t *rec;
\
char *hdr;
\
\
if ((rec = GET_HDR(ll, hx, "Authorization")) != NULL \
&& strncasecmp(rec->data + strlen("Authorization: "), "Basic", \
strlen("Basic")) == 0) { \
char *c, *auth = get_fld(rec, 3); \
if ((hdr = get_hdr(tx, SLT_##hx, auth_re)) != NULL \
&& strcasecmp(get_fld(hdr, 0), "Basic") == 0) { \
char *c, *auth = get_fld(hdr, 1); \
VB64_init(); \
VB64_decode(scratch, config.max_reclen, auth
);
\
VB64_decode(scratch, config.max_reclen, auth
, auth + strlen(auth));
\
c = strchr(scratch, ':'); \
if (c != NULL) \
*c = '\0'; \
...
...
@@ -505,8 +502,10 @@ format_u_##dir(logline_t *ll, char *name, enum VSL_tag_e tag, \
} \
}
FORMAT_u(client, rx)
FORMAT_u(backend, tx)
FORMAT_u
(
client
,
ReqHeader
)
FORMAT_u
(
backend
,
BereqHeader
)
#if 0
#define FORMAT_Xio(dir, io, hx) \
static void \
...
...
src/format.h
View file @
fe7ffa86
...
...
@@ -47,6 +47,9 @@ vre_t *time_beresp_body_re;
#define HOST_REGEX "^\\s*Host\\s*:\\s*(.+)$"
vre_t
*
host_re
;
#define AUTH_REGEX "^\\s*Authorization\\s*:\\s*(.+)$"
vre_t
*
auth_re
;
typedef
void
formatter_f
(
tx_t
*
tx
,
char
*
name
,
enum
VSL_tag_e
tag
,
char
**
s
,
size_t
*
len
);
...
...
@@ -94,3 +97,6 @@ formatter_f format_T_backend;
formatter_f
format_U_client
;
formatter_f
format_U_backend
;
formatter_f
format_u_client
;
formatter_f
format_u_backend
;
src/test/Makefile.am
View file @
fe7ffa86
...
...
@@ -22,6 +22,7 @@ test_format_SOURCES = \
test_format_LDADD
=
\
../config.
$(OBJEXT)
\
../strfTIM.
$(OBJEXT)
\
../base64.
$(OBJEXT)
\
../format.
$(OBJEXT)
\
@VARNISH_LIBS@ @VARNISH_LIBVARNISH_LIB@
-lm
-lvarnish
...
...
src/test/test_format.c
View file @
fe7ffa86
...
...
@@ -108,6 +108,10 @@ static const char
VMASSERT
(
host_re
!=
NULL
,
"Error compiling "
HOST_REGEX
": %s (offset %d)"
,
error
,
erroroffset
);
auth_re
=
VRE_compile
(
AUTH_REGEX
,
VRE_CASELESS
,
&
error
,
&
erroroffset
);
VMASSERT
(
auth_re
!=
NULL
,
"Error compiling "
AUTH_REGEX
": %s (offset %d)"
,
error
,
erroroffset
);
return
NULL
;
}
...
...
@@ -893,6 +897,71 @@ 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
);
#define BASIC_AUTH_PAYLOAD "Authorization: Basic dmFybmlzaDo0ZXZlcg=="
set_record_data
(
&
rec
,
&
chunk
,
BASIC_AUTH_PAYLOAD
,
SLT_ReqHeader
);
format_u_client
(
&
tx
,
NULL
,
SLT__Bogus
,
&
str
,
&
len
);
MASSERT
(
strcmp
(
str
,
"varnish"
)
==
0
);
MASSERT
(
len
==
7
);
rec
.
tag
=
SLT_BereqHeader
;
format_u_backend
(
&
tx
,
NULL
,
SLT__Bogus
,
&
str
,
&
len
);
MASSERT
(
strcmp
(
str
,
"varnish"
)
==
0
);
MASSERT
(
len
==
7
);
/* No header record */
rec
.
tag
=
SLT__Bogus
;
format_u_client
(
&
tx
,
NULL
,
SLT__Bogus
,
&
str
,
&
len
);
MASSERT
(
strcmp
(
str
,
"-"
)
==
0
);
MASSERT
(
len
==
1
);
format_u_backend
(
&
tx
,
NULL
,
SLT__Bogus
,
&
str
,
&
len
);
MASSERT
(
strcmp
(
str
,
"-"
)
==
0
);
MASSERT
(
len
==
1
);
/* No auth header */
rec
.
tag
=
SLT_ReqHeader
;
rec
.
len
=
0
;
format_u_client
(
&
tx
,
NULL
,
SLT__Bogus
,
&
str
,
&
len
);
MASSERT
(
strcmp
(
str
,
"-"
)
==
0
);
MASSERT
(
len
==
1
);
rec
.
tag
=
SLT_BereqHeader
;
format_u_backend
(
&
tx
,
NULL
,
SLT__Bogus
,
&
str
,
&
len
);
MASSERT
(
strcmp
(
str
,
"-"
)
==
0
);
MASSERT
(
len
==
1
);
/* No basic auth header
* Not a real example of a digest auth header, but kept short, so
* that we can test with only one chunk.
*/
#define DIGEST_AUTH_PAYLOAD "Authorization: Digest username=\"Mufasa\", realm=\"realm@host.com\""
set_record_data
(
&
rec
,
&
chunk
,
DIGEST_AUTH_PAYLOAD
,
SLT_ReqHeader
);
format_u_client
(
&
tx
,
NULL
,
SLT__Bogus
,
&
str
,
&
len
);
MASSERT
(
strcmp
(
str
,
"-"
)
==
0
);
MASSERT
(
len
==
1
);
rec
.
tag
=
SLT_BereqHeader
;
format_u_backend
(
&
tx
,
NULL
,
SLT__Bogus
,
&
str
,
&
len
);
MASSERT
(
strcmp
(
str
,
"-"
)
==
0
);
MASSERT
(
len
==
1
);
return
NULL
;
}
static
const
char
*
all_tests
(
void
)
{
...
...
@@ -916,6 +985,7 @@ static const char
mu_run_test
(
test_format_t
);
mu_run_test
(
test_format_T
);
mu_run_test
(
test_format_U
);
mu_run_test
(
test_format_u
);
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