Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
V
varnish-cache
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Commits
Open sidebar
varnishcache
varnish-cache
Commits
2776c9c7
Commit
2776c9c7
authored
Sep 25, 2018
by
Geoff Simmons
Committed by
Dridi Boukelmoune
Oct 16, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add JSON support for the "ban.list" CLI command.
parent
6758bc02
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
96 additions
and
17 deletions
+96
-17
cache_ban.c
bin/varnishd/cache/cache_ban.c
+85
-16
c00019.vtc
bin/varnishtest/tests/c00019.vtc
+7
-1
c00021.vtc
bin/varnishtest/tests/c00021.vtc
+1
-0
c00022.vtc
bin/varnishtest/tests/c00022.vtc
+1
-0
c00049.vtc
bin/varnishtest/tests/c00049.vtc
+1
-0
c00059.vtc
bin/varnishtest/tests/c00059.vtc
+1
-0
No files found.
bin/varnishd/cache/cache_ban.c
View file @
2776c9c7
...
...
@@ -669,7 +669,7 @@ ccf_ban(struct cli *cli, const char * const *av, void *priv)
}
static
void
ban_render
(
struct
cli
*
cli
,
const
uint8_t
*
bs
)
ban_render
(
struct
cli
*
cli
,
const
uint8_t
*
bs
,
int
quote
)
{
struct
ban_test
bt
;
const
uint8_t
*
be
;
...
...
@@ -704,27 +704,21 @@ ban_render(struct cli *cli, const uint8_t *bs)
default:
WRONG
(
"Wrong BANS_OPER"
);
}
VCLI_Out
(
cli
,
"%s"
,
bt
.
arg2
);
if
(
quote
)
VCLI_Quote
(
cli
,
bt
.
arg2
);
else
VCLI_Out
(
cli
,
"%s"
,
bt
.
arg2
);
if
(
bs
<
be
)
VCLI_Out
(
cli
,
" && "
);
}
}
static
void
v_matchproto_
(
cli_func_t
)
ccf_ban_list
(
struct
cli
*
cli
,
const
char
*
const
*
av
,
void
*
priv
)
static
void
ban_list
(
struct
cli
*
cli
,
struct
ban
*
bl
)
{
struct
ban
*
b
,
*
bl
;
struct
ban
*
b
;
int64_t
o
;
(
void
)
av
;
(
void
)
priv
;
/* Get a reference so we are safe to traverse the list */
Lck_Lock
(
&
ban_mtx
);
bl
=
VTAILQ_LAST
(
&
ban_head
,
banhead_s
);
bl
->
refcount
++
;
Lck_Unlock
(
&
ban_mtx
);
VCLI_Out
(
cli
,
"Present bans:
\n
"
);
VTAILQ_FOREACH
(
b
,
&
ban_head
,
list
)
{
o
=
bl
==
b
?
1
:
0
;
...
...
@@ -738,7 +732,7 @@ ccf_ban_list(struct cli *cli, const char * const *av, void *priv)
b
);
}
VCLI_Out
(
cli
,
" "
);
ban_render
(
cli
,
b
->
spec
);
ban_render
(
cli
,
b
->
spec
,
0
);
VCLI_Out
(
cli
,
"
\n
"
);
if
(
VCLI_Overflow
(
cli
))
break
;
...
...
@@ -750,6 +744,80 @@ ccf_ban_list(struct cli *cli, const char * const *av, void *priv)
Lck_Unlock
(
&
ban_mtx
);
}
}
}
static
void
ban_list_json
(
struct
cli
*
cli
,
const
char
*
const
*
av
,
struct
ban
*
bl
)
{
struct
ban
*
b
;
int64_t
o
;
int
n
=
0
;
int
ocs
;
VCLI_JSON_begin
(
cli
,
2
,
av
);
VCLI_Out
(
cli
,
",
\n
"
);
VTAILQ_FOREACH
(
b
,
&
ban_head
,
list
)
{
o
=
bl
==
b
?
1
:
0
;
VCLI_Out
(
cli
,
"%s"
,
n
?
",
\n
"
:
""
);
n
++
;
VCLI_Out
(
cli
,
"{
\n
"
);
VSB_indent
(
cli
->
sb
,
2
);
VCLI_Out
(
cli
,
"
\"
time
\"
: %.6f,
\n
"
,
ban_time
(
b
->
spec
));
VCLI_Out
(
cli
,
"
\"
refs
\"
: %ju,
\n
"
,
(
intmax_t
)(
b
->
refcount
-
o
));
VCLI_Out
(
cli
,
"
\"
completed
\"
: %s,
\n
"
,
b
->
flags
&
BANS_FLAG_COMPLETED
?
"true"
:
"false"
);
VCLI_Out
(
cli
,
"
\"
spec
\"
:
\"
"
);
ban_render
(
cli
,
b
->
spec
,
1
);
VCLI_Out
(
cli
,
"
\"
"
);
if
(
DO_DEBUG
(
DBG_LURKER
))
{
VCLI_Out
(
cli
,
",
\n
"
);
VCLI_Out
(
cli
,
"
\"
req_tests
\"
: %s,
\n
"
,
b
->
flags
&
BANS_FLAG_REQ
?
"true"
:
"false"
);
VCLI_Out
(
cli
,
"
\"
obj_tests
\"
: %s,
\n
"
,
b
->
flags
&
BANS_FLAG_OBJ
?
"true"
:
"false"
);
VCLI_Out
(
cli
,
"
\"
pointer
\"
:
\"
%p
\"
,
\n
"
,
b
);
if
(
VCLI_Overflow
(
cli
))
break
;
ocs
=
0
;
VCLI_Out
(
cli
,
"
\"
objcores
\"
: [
\n
"
);
VSB_indent
(
cli
->
sb
,
2
);
Lck_Lock
(
&
ban_mtx
);
struct
objcore
*
oc
;
VTAILQ_FOREACH
(
oc
,
&
b
->
objcore
,
ban_list
)
{
if
(
ocs
)
VCLI_Out
(
cli
,
",
\n
"
);
VCLI_Out
(
cli
,
"%p"
,
oc
);
ocs
++
;
}
Lck_Unlock
(
&
ban_mtx
);
VSB_indent
(
cli
->
sb
,
-
2
);
VCLI_Out
(
cli
,
"
\n
]"
);
}
VSB_indent
(
cli
->
sb
,
-
2
);
VCLI_Out
(
cli
,
"
\n
}"
);
}
VCLI_JSON_end
(
cli
);
}
static
void
v_matchproto_
(
cli_func_t
)
ccf_ban_list
(
struct
cli
*
cli
,
const
char
*
const
*
av
,
void
*
priv
)
{
struct
ban
*
bl
;
(
void
)
priv
;
/* Get a reference so we are safe to traverse the list */
Lck_Lock
(
&
ban_mtx
);
bl
=
VTAILQ_LAST
(
&
ban_head
,
banhead_s
);
bl
->
refcount
++
;
Lck_Unlock
(
&
ban_mtx
);
if
(
av
[
2
]
!=
NULL
&&
strcmp
(
av
[
2
],
"-j"
)
==
0
)
ban_list_json
(
cli
,
av
,
bl
);
else
ban_list
(
cli
,
bl
);
Lck_Lock
(
&
ban_mtx
);
bl
->
refcount
--
;
...
...
@@ -759,7 +827,8 @@ ccf_ban_list(struct cli *cli, const char * const *av, void *priv)
static
struct
cli_proto
ban_cmds
[]
=
{
{
CLICMD_BAN
,
""
,
ccf_ban
},
{
CLICMD_BAN_LIST
,
""
,
ccf_ban_list
},
{
CLICMD_BAN_LIST
,
""
,
ccf_ban_list
,
ccf_ban_list
},
{
NULL
}
};
...
...
bin/varnishtest/tests/c00019.vtc
View file @
2776c9c7
...
...
@@ -84,7 +84,13 @@ client c1 {
varnish v1 -expect bans_tested == 2
varnish v1 -expect bans_tests_tested == 2
varnish v1 -cliok "ban.list"
varnish v1 -clijson "ban.list -j"
# Test a bogus regexp
varnish v1 -clierr 106 "ban req.url ~ [[["
# Ban expression with quoting
varnish v1 -cliok {ban req.url ~ "BAR"}
shell {varnishadm -n ${tmpdir}/v1 ban 'obj.http.Host ~ \"Foo\"'}
varnish v1 -cliok "ban.list"
varnish v1 -clijson "ban.list -j"
bin/varnishtest/tests/c00021.vtc
View file @
2776c9c7
...
...
@@ -112,6 +112,7 @@ client c1 {
# header check, no header
varnish v1 -cliok "ban req.url ~ foo && obj.http.bar == barcheck"
varnish v1 -cliok "ban.list"
varnish v1 -clijson "ban.list -j"
client c1 {
txreq -url "/foo"
...
...
bin/varnishtest/tests/c00022.vtc
View file @
2776c9c7
...
...
@@ -149,6 +149,7 @@ client c1 {
expect resp.status == 410
} -run
varnish v1 -cliok "ban.list"
varnish v1 -clijson "ban.list -j"
client c1 {
txreq -url "/foo"
...
...
bin/varnishtest/tests/c00049.vtc
View file @
2776c9c7
...
...
@@ -205,6 +205,7 @@ varnish v1 -cliok "ban.list"
varnish v1 -cliok "param.set ban_lurker_age .1"
delay 3
varnish v1 -clijson "ban.list -j"
varnish v1 -cliok "ban.list"
varnish v1 -expect bans == 1
...
...
bin/varnishtest/tests/c00059.vtc
View file @
2776c9c7
...
...
@@ -18,6 +18,7 @@ client c1 {
varnish v1 -cliok "ban obj.status == 201"
varnish v1 -cliok "ban obj.status == 200"
varnish v1 -cliok "ban.list"
varnish v1 -clijson "ban.list -j"
client c1 {
txreq
...
...
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