Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
L
libvmod-selector
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-selector
Commits
5cea4e6d
Commit
5cea4e6d
authored
Feb 02, 2021
by
Geoff Simmons
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add the .bool() method.
parent
43541478
Changes
6
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
553 additions
and
17 deletions
+553
-17
README.rst
README.rst
+54
-9
associate.c
src/associate.c
+18
-0
bool.vtc
src/tests/bool.vtc
+432
-0
vmod_selector.c
src/vmod_selector.c
+5
-1
vmod_selector.h
src/vmod_selector.h
+2
-0
vmod_selector.vcc
src/vmod_selector.vcc
+42
-7
No files found.
README.rst
View file @
5cea4e6d
...
...
@@ -28,7 +28,7 @@ SYNOPSIS
new <obj> = selector.set([BOOL case_sensitive]
[, BOOL allow_overlaps])
VOID <obj>.add(STRING [, STRING string] [, STRING regex]
[, BACKEND backend] [, INT integer])
[, BACKEND backend] [, INT integer]
[, BOOL bool]
)
VOID <obj>.create_stats()
# Matching
...
...
@@ -43,8 +43,9 @@ SYNOPSIS
# Retrieving objects by index, by string, or after match
STRING <obj>.element([INT n] [, ENUM select])
STRING <obj>.string([INT n] [, STRING element] [, ENUM select])
INT <obj>.integer([INT n] [, STRING element] [, ENUM select])
BACKEND <obj>.backend([INT n] [, STRING element] [, ENUM select])
INT <obj>.integer([INT n] [, STRING element] [, ENUM select])
BOOL <obj>.bool([INT n] [, STRING element] [, ENUM select])
BOOL <obj>.re_match(STRING [, INT n] [, STRING element]
[, ENUM select])
STRING <obj>.sub(STRING text, STRING rewrite [, BOOL all] [, INT n]
...
...
@@ -437,8 +438,8 @@ Examples::
.. _xset.add():
VOID xset.add(STRING, [STRING string], [STRING regex], [BACKEND backend], [INT integer])
----------------------------------------------------------------------------------------
VOID xset.add(STRING, [STRING string], [STRING regex], [BACKEND backend], [INT integer]
, [BOOL bool]
)
----------------------------------------------------------------------------------------
-------------
::
...
...
@@ -447,7 +448,8 @@ VOID xset.add(STRING, [STRING string], [STRING regex], [BACKEND backend], [INT i
[STRING string],
[STRING regex],
[BACKEND backend],
[INT integer]
[INT integer],
[BOOL bool]
)
Add the given string to the set. As indicated above, elements added to
...
...
@@ -455,10 +457,10 @@ the set are implicitly numbered in the order in which they are added
with ``.add()``, starting with 1.
If values are set for the optional parameters ``string``, ``regex``,
``backend``
or ``integer``, then those values are associated with this
element, and can be retrieved with the ``.string()``, ``.backend
()``,
``.
integer()``, ``.re_match()`` or ``.sub()`` methods, as described
below.
``backend``
, ``integer`` or ``bool``, then those values are associated
with this element, and can be retrieved with the ``.string
()``,
``.
backend()``, ``.integer()``, ``.bool()``, ``.re_match()`` or
``.sub()`` methods, as described
below.
A regular expression in the ``regex`` parameter is compiled at VCL load
time. If the compile fails, then the VCL load fails with an error message.
...
...
@@ -895,6 +897,49 @@ Example::
}
}
.. _xset.bool():
BOOL xset.bool(INT n, STRING element, ENUM select)
--------------------------------------------------
::
BOOL xset.bool(
INT n=0,
STRING element=0,
ENUM {UNIQUE, EXACT, FIRST, LAST, SHORTEST, LONGEST} select=UNIQUE
)
Returns the boolean value set by the ``bool`` parameter for the
element of the set indicated by ``n``, ``element`` and ``select``,
according to the rules given above.
``.bool()`` invokes VCL failure if:
* The rules for ``n``, ``element`` and ``select`` indicate failure.
* No boolean was set with the ``bool`` parameter in ``.add()``.
Example::
# Match domains to the Host header, and append "www." where
# necessary.
sub vcl_init {
new domains = selector.set();
domains.add("example.com", bool=true);
domains.add("www.example.net", bool=false);
domains.add("example.org", bool=true);
domains.add("www.example.edu", bool=false)
}
sub vcl_recv {
if (domains.match(req.http.Host)) {
if (domains.bool()) {
set req.http.Host = "www." + req.http.Host;
}
}
}
.. _xset.re_match():
BOOL xset.re_match(STRING subject, INT n, STRING element, ENUM select)
...
...
src/associate.c
View file @
5cea4e6d
...
...
@@ -255,3 +255,21 @@ vmod_set_sub(VRT_CTX, struct vmod_selector_set *set, VCL_STRING str,
return
(
NULL
);
return
(
VRT_regsub
(
ctx
,
all
,
str
,
re
,
sub
));
}
VCL_BOOL
vmod_set_bool
(
VRT_CTX
,
struct
VPFX
(
selector_set
)
*
set
,
VCL_INT
n
,
VCL_STRING
element
,
VCL_ENUM
selects
)
{
unsigned
idx
;
CHECK_OBJ_NOTNULL
(
ctx
,
VRT_CTX_MAGIC
);
CHECK_OBJ_NOTNULL
(
set
,
VMOD_SELECTOR_SET_MAGIC
);
idx
=
get_idx
(
ctx
,
n
,
set
,
"bool"
,
element
,
selects
);
if
(
idx
==
UINT_MAX
)
return
(
0
);
if
(
!
check_added
(
ctx
,
set
,
idx
,
BOOLEAN
,
"bool"
,
"boolean"
))
return
(
0
);
return
(
set
->
table
[
idx
]
->
bool
);
}
src/tests/bool.vtc
0 → 100644
View file @
5cea4e6d
This diff is collapsed.
Click to expand it.
src/vmod_selector.c
View file @
5cea4e6d
...
...
@@ -506,7 +506,7 @@ vmod_set_add(VRT_CTX, struct vmod_selector_set *set,
}
if
(
!
args
->
valid_string
&&
re
==
NULL
&&
!
args
->
valid_backend
&&
!
args
->
valid_integer
)
&&
!
args
->
valid_integer
&&
!
args
->
valid_bool
)
return
;
set
->
table
=
realloc
(
set
->
table
,
n
*
sizeof
(
struct
entry
*
));
...
...
@@ -530,6 +530,10 @@ vmod_set_add(VRT_CTX, struct vmod_selector_set *set,
entry
->
integer
=
args
->
integer
;
set_added
(
set
,
n
-
1
,
INTEGER
);
}
if
(
args
->
valid_bool
)
{
entry
->
bool
=
args
->
bool
;
set_added
(
set
,
n
-
1
,
BOOLEAN
);
}
set
->
table
[
n
-
1
]
=
entry
;
}
...
...
src/vmod_selector.h
View file @
5cea4e6d
...
...
@@ -52,6 +52,7 @@ struct entry {
VCL_BACKEND
backend
;
vre_t
*
re
;
VCL_INT
integer
;
VCL_BOOL
bool
;
};
enum
bitmap_e
{
...
...
@@ -59,6 +60,7 @@ enum bitmap_e {
BACKEND
,
REGEX
,
INTEGER
,
BOOLEAN
,
__MAX_BITMAP
,
};
...
...
src/vmod_selector.vcc
View file @
5cea4e6d
...
...
@@ -24,7 +24,7 @@ SYNOPSIS
new <obj> = selector.set([BOOL case_sensitive]
[, BOOL allow_overlaps])
VOID <obj>.add(STRING [, STRING string] [, STRING regex]
[, BACKEND backend] [, INT integer])
[, BACKEND backend] [, INT integer]
[, BOOL bool]
)
VOID <obj>.create_stats()
# Matching
...
...
@@ -39,8 +39,9 @@ SYNOPSIS
# Retrieving objects by index, by string, or after match
STRING <obj>.element([INT n] [, ENUM select])
STRING <obj>.string([INT n] [, STRING element] [, ENUM select])
INT <obj>.integer([INT n] [, STRING element] [, ENUM select])
BACKEND <obj>.backend([INT n] [, STRING element] [, ENUM select])
INT <obj>.integer([INT n] [, STRING element] [, ENUM select])
BOOL <obj>.bool([INT n] [, STRING element] [, ENUM select])
BOOL <obj>.re_match(STRING [, INT n] [, STRING element]
[, ENUM select])
STRING <obj>.sub(STRING text, STRING rewrite [, BOOL all] [, INT n]
...
...
@@ -422,17 +423,17 @@ Examples::
}
$Method VOID .add(STRING, [STRING string], [STRING regex], [BACKEND backend],
[INT integer])
[INT integer]
, [BOOL bool]
)
Add the given string to the set. As indicated above, elements added to
the set are implicitly numbered in the order in which they are added
with ``.add()``, starting with 1.
If values are set for the optional parameters ``string``, ``regex``,
``backend``
or ``integer``, then those values are associated with this
element, and can be retrieved with the ``.string()``, ``.backend
()``,
``.
integer()``, ``.re_match()`` or ``.sub()`` methods, as described
below.
``backend``
, ``integer`` or ``bool``, then those values are associated
with this element, and can be retrieved with the ``.string
()``,
``.
backend()``, ``.integer()``, ``.bool()``, ``.re_match()`` or
``.sub()`` methods, as described
below.
A regular expression in the ``regex`` parameter is compiled at VCL load
time. If the compile fails, then the VCL load fails with an error message.
...
...
@@ -801,6 +802,40 @@ Example::
}
}
$Method BOOL .bool(INT n=0, STRING element=0,
ENUM {UNIQUE, EXACT, FIRST, LAST, SHORTEST, LONGEST}
select=UNIQUE)
Returns the boolean value set by the ``bool`` parameter for the
element of the set indicated by ``n``, ``element`` and ``select``,
according to the rules given above.
``.bool()`` invokes VCL failure if:
* The rules for ``n``, ``element`` and ``select`` indicate failure.
* No boolean was set with the ``bool`` parameter in ``.add()``.
Example::
# Match domains to the Host header, and append "www." where
# necessary.
sub vcl_init {
new domains = selector.set();
domains.add("example.com", bool=true);
domains.add("www.example.net", bool=false);
domains.add("example.org", bool=true);
domains.add("www.example.edu", bool=false)
}
sub vcl_recv {
if (domains.match(req.http.Host)) {
if (domains.bool()) {
set req.http.Host = "www." + req.http.Host;
}
}
}
$Method BOOL .re_match(STRING subject, INT n=0, STRING element=0,
ENUM {UNIQUE, EXACT, FIRST, LAST, SHORTEST, LONGEST}
select=UNIQUE)
...
...
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