Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
L
libvmod-hoailona
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
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
libvmod-hoailona
Commits
a42d97a0
Commit
a42d97a0
authored
Apr 19, 2017
by
Nils Goroll
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
allow calling .policy multiple times on the cached result
parent
676e2d9d
Pipeline
#183
skipped
Changes
4
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
57 additions
and
18 deletions
+57
-18
README.rst
README.rst
+10
-4
policy_method.vtc
src/tests/policy_method.vtc
+14
-6
vmod_hoailona.c
src/vmod_hoailona.c
+23
-4
vmod_hoailona.vcc
src/vmod_hoailona.vcc
+10
-4
No files found.
README.rst
View file @
a42d97a0
...
...
@@ -449,7 +449,7 @@ hosts.policy
::
INT hosts.policy(PRIV_TASK, STRING host
, STRING path
)
INT hosts.policy(PRIV_TASK, STRING host
=0, STRING path=0
)
Determine the policy type that holds for ``host`` and ``path``. The
return values are:
...
...
@@ -460,9 +460,8 @@ return values are:
* -1 if no matching policy can be found
* -2 if there was an internal error
The ``host`` and ``path`` parameters are required, and must be
non-empty. This method MAY NOT be called in ``vcl_init``. If it is,
then the VCL load fails.
This method MAY NOT be called in ``vcl_init``. If it is, then the VCL
load fails.
The method searches for host names added by the ``.add()`` method that
match ``host``, possibly matching the suffix if the host name in
...
...
@@ -502,6 +501,13 @@ Subsequent calls to the ``.token()``, ``.secret()`` or ``.explain()``
methods refer to the most recent invocation of ``.policy()`` in the
same task scope, that is in the same client or backend transaction.
Likewise, if both the ``host`` and ``path`` parameters are empty,
``.policy()`` returns again the result of the most recent invocation
with parameters.
Calling ``.policy()`` with only one of the ``host`` and ``path``
parameters empty is an error.
.. _func_hosts.token:
hosts.token
...
...
src/tests/policy_method.vtc
View file @
a42d97a0
...
...
@@ -21,9 +21,13 @@ varnish v1 -vcl {
}
sub vcl_synth {
set resp.http.p1 = h.policy("example.com", "/foo/bar");
set resp.http.p2 = h.policy("example.org", "/quux/4711");
set resp.http.p3 = h.policy("example.com", "/bar/foo");
set resp.http.p0 = h.policy();
set resp.http.p1 = h.policy("example.com", "/foo/bar");
set resp.http.p1c = h.policy();
set resp.http.p2 = h.policy("example.org", "/quux/4711");
set resp.http.p2c = h.policy();
set resp.http.p3 = h.policy("example.com", "/bar/foo");
set resp.http.p3c = h.policy();
}
} -start
...
...
@@ -31,9 +35,13 @@ client c1 {
txreq
rxresp
expect resp.status == 200
expect resp.http.p1 == "2"
expect resp.http.p2 == "1"
expect resp.http.p3 == "0"
expect resp.http.p0 == "-2"
expect resp.http.p1 == "2"
expect resp.http.p1c == "2"
expect resp.http.p2 == "1"
expect resp.http.p2c == "1"
expect resp.http.p3 == "0"
expect resp.http.p3c == "0"
} -run
# Examples from Akamai docs
...
...
src/vmod_hoailona.c
View file @
a42d97a0
...
...
@@ -94,6 +94,11 @@ WS_Contains(struct ws * const restrict ws, const void * const restrict ptr,
assert
((
char
*
)
ptr
>=
ws
->
s
&&
(
char
*
)(
ptr
+
len
)
<=
ws
->
e
);
}
static
struct
vmod_hoailona_policy
*
get_policy
(
VRT_CTX
,
const
struct
vmod_priv
*
restrict
const
,
const
char
*
restrict
const
,
const
char
*
restrict
const
);
void
errmsg
(
VRT_CTX
,
const
char
*
fmt
,
...)
{
...
...
@@ -490,10 +495,24 @@ vmod_hosts_policy(VRT_CTX, struct vmod_hoailona_hosts *hosts,
return
-
2
;
}
if
(
hostname
==
NULL
||
hostname
[
0
]
==
'\0'
)
{
VERR
(
ctx
,
"host is empty in %s.policy()"
,
hosts
->
vcl_name
);
return
-
2
;
}
if
(
pathname
==
NULL
||
pathname
[
0
]
==
'\0'
)
{
if
(
!
(
pathname
==
NULL
||
pathname
[
0
]
==
'\0'
))
{
VERR
(
ctx
,
"host is empty in %s.policy()"
,
hosts
->
vcl_name
);
return
-
2
;
}
if
(
priv_task
->
priv
==
NULL
)
{
VERR
(
ctx
,
"%s.policy() no cached result"
,
hosts
->
vcl_name
);
return
-
2
;
}
policy
=
get_policy
(
ctx
,
priv_task
,
hosts
->
vcl_name
,
"policy"
);
if
(
policy
==
NULL
)
return
-
1
;
return
policy
->
type
;
}
else
if
(
pathname
==
NULL
||
pathname
[
0
]
==
'\0'
)
{
VERR
(
ctx
,
"path is empty in %s.policy()"
,
hosts
->
vcl_name
);
return
-
2
;
}
...
...
src/vmod_hoailona.vcc
View file @
a42d97a0
...
...
@@ -399,7 +399,7 @@ Examples::
h.add("evil.org", "deny", description="no access to evil.org");
}
$Method INT .policy(PRIV_TASK, STRING host
, STRING path
)
$Method INT .policy(PRIV_TASK, STRING host
=0, STRING path=0
)
Determine the policy type that holds for ``host`` and ``path``. The
return values are:
...
...
@@ -410,9 +410,8 @@ return values are:
* -1 if no matching policy can be found
* -2 if there was an internal error
The ``host`` and ``path`` parameters are required, and must be
non-empty. This method MAY NOT be called in ``vcl_init``. If it is,
then the VCL load fails.
This method MAY NOT be called in ``vcl_init``. If it is, then the VCL
load fails.
The method searches for host names added by the ``.add()`` method that
match ``host``, possibly matching the suffix if the host name in
...
...
@@ -452,6 +451,13 @@ Subsequent calls to the ``.token()``, ``.secret()`` or ``.explain()``
methods refer to the most recent invocation of ``.policy()`` in the
same task scope, that is in the same client or backend transaction.
Likewise, if both the ``host`` and ``path`` parameters are empty,
``.policy()`` returns again the result of the most recent invocation
with parameters.
Calling ``.policy()`` with only one of the ``host`` and ``path``
parameters empty is an error.
$Method STRING .token(PRIV_TASK, STRING acl=0, DURATION ttl=0, STRING data=0)
If the previous invocation of ``.policy()`` determined policy type
...
...
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