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
277fa01e
Commit
277fa01e
authored
Jul 10, 2018
by
Geoff Simmons
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Backport for Varnish 4.1.
parent
110aefdd
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
98 additions
and
113 deletions
+98
-113
README.rst
README.rst
+77
-94
configure.ac
configure.ac
+1
-1
case.vtc
src/tests/case.vtc
+1
-1
match.vtc
src/tests/match.vtc
+1
-1
prefix.vtc
src/tests/prefix.vtc
+3
-3
sub.vtc
src/tests/sub.vtc
+2
-2
vmod_selector.c
src/vmod_selector.c
+3
-1
vmod_selector.vcc
src/vmod_selector.vcc
+10
-10
No files found.
README.rst
View file @
277fa01e
...
@@ -12,9 +12,9 @@
...
@@ -12,9 +12,9 @@
vmod_selector
vmod_selector
=============
=============
---------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------
-
Varnish Module for matching strings associated with backends, regexen and other strings
Varnish Module for matching strings associated with backends
, regexen and other strings
---------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------
-
:Manual section: 3
:Manual section: 3
...
@@ -130,7 +130,7 @@ lines. For example::
...
@@ -130,7 +130,7 @@ lines. For example::
}
}
}
}
sub vcl_backend_fetch {
sub vcl_backend_fetch {
# The .hasprefix() method returns true if the URL has a prefix
# The .hasprefix() method returns true if the URL has a prefix
...
@@ -140,7 +140,7 @@ lines. For example::
...
@@ -140,7 +140,7 @@ lines. For example::
# string in the set that was matched as a prefix.
# string in the set that was matched as a prefix.
set bereq.backend = url_prefix.backend();
set bereq.backend = url_prefix.backend();
}
}
}
}
sub vcl_synth {
sub vcl_synth {
...
@@ -154,7 +154,7 @@ lines. For example::
...
@@ -154,7 +154,7 @@ lines. For example::
= "http://other.com" + req.http.X-URL-Prefix + req.url;
= "http://other.com" + req.http.X-URL-Prefix + req.url;
return (deliver);
return (deliver);
}
}
}
}
Matches with the ``.match()`` and ``.hasprefix()`` methods scale well
Matches with the ``.match()`` and ``.hasprefix()`` methods scale well
...
@@ -179,11 +179,12 @@ the VMOD can contribute to better code maintainability.
...
@@ -179,11 +179,12 @@ the VMOD can contribute to better code maintainability.
Matches with ``.match()`` and ``.hasprefix()`` are fixed string
Matches with ``.match()`` and ``.hasprefix()`` are fixed string
matches; characters such as wildcards and regex metacharacters are
matches; characters such as wildcards and regex metacharacters are
matched literally, and have no special meaning. Regex operations
matched literally, and have no special meaning. Regex operations such
such as matching or substitution can be performed after set matches,
as matching or substitution can be performed after set matches, using
using the regex saved with the ``regex`` parameter. But if you need
the regex saved with the ``regex`` parameter. But if you need to match
to match against sets of patterns, consider using the set interface
against sets of patterns, consider using the set interface of VMOD re2
of `VMOD re2`_, which provides techniques similar to the present VMOD.
(see `SEE ALSO`_ below), which provides techniques similar to the
present VMOD.
Selecting matched elements of a set
Selecting matched elements of a set
-----------------------------------
-----------------------------------
...
@@ -309,17 +310,26 @@ or the longest match, and so on::
...
@@ -309,17 +310,26 @@ or the longest match, and so on::
CONTENTS
CONTENTS
========
========
* set(BOOL)
* Object set
* VOID set.add(STRING, STRING, STRING, BACKEND)
* BACKEND set.backend(INT, ENUM)
* STRING set.debug()
* STRING set.element(INT, ENUM)
* BOOL set.hasprefix(STRING)
* BOOL set.match(STRING)
* BOOL set.matched(INT)
* INT set.nmatches()
* BOOL set.re_match(STRING, INT, ENUM)
* STRING set.string(INT, ENUM)
* STRING set.sub(STRING, STRING, BOOL, INT, ENUM)
* INT set.which(ENUM)
* STRING version()
* STRING version()
.. _obj_set:
.. _obj_set:
set
Object set
---
==========
::
new OBJ = set(BOOL case_sensitive=1)
Create a set object. When ``case_sensitive`` is ``false``, matches
Create a set object. When ``case_sensitive`` is ``false``, matches
using the ``.match()`` and ``.hasprefix()`` methods are
using the ``.match()`` and ``.hasprefix()`` methods are
...
@@ -338,12 +348,11 @@ Example::
...
@@ -338,12 +348,11 @@ Example::
.. _func_set.add:
.. _func_set.add:
set.add
VOID set.add(STRING, STRING, STRING, BACKEND)
-------
-------
--------------------------------------
::
Prototype
VOID set.add(STRING, STRING string, STRING regex, BACKEND backend)
VOID set.add(STRING, STRING string=0, STRING regex=0, BACKEND backend=0)
Add the given string to the set. As indicated above, elements added to
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
the set are implicitly numbered in the order in which they are added
...
@@ -384,11 +393,10 @@ Example::
...
@@ -384,11 +393,10 @@ Example::
.. _func_set.match:
.. _func_set.match:
set.match
BOOL set.match(STRING)
---------
----------------------
::
Prototype
BOOL set.match(STRING)
BOOL set.match(STRING)
Returns ``true`` if the given STRING exactly matches one of the
Returns ``true`` if the given STRING exactly matches one of the
...
@@ -412,11 +420,10 @@ Example::
...
@@ -412,11 +420,10 @@ Example::
.. _func_set.hasprefix:
.. _func_set.hasprefix:
set.hasprefix
BOOL set.hasprefix(STRING)
-------------
--------------------------
::
Prototype
BOOL set.hasprefix(STRING)
BOOL set.hasprefix(STRING)
Returns ``true`` if the STRING to be matched has a prefix that is in
Returns ``true`` if the STRING to be matched has a prefix that is in
...
@@ -434,11 +441,10 @@ Example::
...
@@ -434,11 +441,10 @@ Example::
.. _func_set.nmatches:
.. _func_set.nmatches:
set.nmatches
INT set.nmatches()
------------
------------------
::
Prototype
INT set.nmatches()
INT set.nmatches()
Returns the number of elements that were matched by the most recent
Returns the number of elements that were matched by the most recent
...
@@ -471,11 +477,10 @@ Example::
...
@@ -471,11 +477,10 @@ Example::
.. _func_set.matched:
.. _func_set.matched:
set.matched
BOOL set.matched(INT)
-----------
---------------------
::
Prototype
BOOL set.matched(INT)
BOOL set.matched(INT)
After a successful ``.match()`` or ``.hasprefix()`` call for the same
After a successful ``.match()`` or ``.hasprefix()`` call for the same
...
@@ -505,12 +510,11 @@ Example::
...
@@ -505,12 +510,11 @@ Example::
.. _func_set.which:
.. _func_set.which:
set.which
INT set.which(ENUM)
---------
-------------------
::
INT set.which(ENUM {UNIQUE,EXACT,FIRST,LAST,SHORTEST,LONGEST} select="UNIQUE")
Prototype
INT set.which(ENUM select)
After a successful ``.match()`` or ``.hasprefix()`` call for the same
After a successful ``.match()`` or ``.hasprefix()`` call for the same
set object in the same task scope, return the index of the matching
set object in the same task scope, return the index of the matching
...
@@ -543,12 +547,11 @@ Example::
...
@@ -543,12 +547,11 @@ Example::
.. _func_set.element:
.. _func_set.element:
set.element
STRING set.element(INT, ENUM)
-----------
-----------------------------
::
STRING set.element(INT n=0, ENUM {UNIQUE,EXACT,FIRST,LAST,SHORTEST,LONGEST} select="UNIQUE")
Prototype
STRING set.element(INT n, ENUM select)
Returns the element of the set indicated by the ``n`` and ``select``
Returns the element of the set indicated by the ``n`` and ``select``
parameters as described above. Thus if ``n`` >= 1, the ``n``-th
parameters as described above. Thus if ``n`` >= 1, the ``n``-th
...
@@ -581,12 +584,11 @@ Example::
...
@@ -581,12 +584,11 @@ Example::
.. _func_set.backend:
.. _func_set.backend:
set.backend
BACKEND set.backend(INT, ENUM)
-----------
------------------------------
::
BACKEND set.backend(INT n=0, ENUM {UNIQUE,EXACT,FIRST,LAST,SHORTEST,LONGEST} select="UNIQUE")
Prototype
BACKEND set.backend(INT n, ENUM select)
Returns the backend associated with the element of the set indicated
Returns the backend associated with the element of the set indicated
by ``n`` and ``select``, according to the rules given above; that is,
by ``n`` and ``select``, according to the rules given above; that is,
...
@@ -610,12 +612,11 @@ Example::
...
@@ -610,12 +612,11 @@ Example::
.. _func_set.string:
.. _func_set.string:
set.string
STRING set.string(INT, ENUM)
----------
----------------------------
::
STRING set.string(INT n=0, ENUM {UNIQUE,EXACT,FIRST,LAST,SHORTEST,LONGEST} select="UNIQUE")
Prototype
STRING set.string(INT n, ENUM select)
Returns the string set by the ``string`` parameter for the element of
Returns the string set by the ``string`` parameter for the element of
the set indicated by ``n`` and ``select``, according to the rules
the set indicated by ``n`` and ``select``, according to the rules
...
@@ -636,12 +637,11 @@ Example::
...
@@ -636,12 +637,11 @@ Example::
.. _func_set.re_match:
.. _func_set.re_match:
set.re_match
BOOL set.re_match(STRING, INT, ENUM)
------------
------------
------------------------
::
Prototype
BOOL set.re_match(STRING subject, INT n, ENUM select)
BOOL set.re_match(STRING subject, INT n=0, ENUM {UNIQUE,EXACT,FIRST,LAST,SHORTEST,LONGEST} select="UNIQUE")
Using the regular expression set by the ``regex`` parameter for the
Using the regular expression set by the ``regex`` parameter for the
element of the set indicated by ``n`` and ``select``, return the
element of the set indicated by ``n`` and ``select``, return the
...
@@ -680,12 +680,11 @@ Example::
...
@@ -680,12 +680,11 @@ Example::
.. _func_set.sub:
.. _func_set.sub:
set.sub
STRING set.sub(STRING, STRING, BOOL, INT, ENUM)
-------
-----------------------------------------------
::
STRING set.sub(STRING str, STRING sub, BOOL all=0, INT n=0, ENUM {UNIQUE,EXACT,FIRST,LAST,SHORTEST,LONGEST} select="UNIQUE")
Prototype
STRING set.sub(STRING str, STRING sub, BOOL all, INT n, ENUM select)
Using the regular expression set by the ``regex`` parameter for the
Using the regular expression set by the ``regex`` parameter for the
element of the set indicated by ``n`` and ``select``, return the
element of the set indicated by ``n`` and ``select``, return the
...
@@ -734,22 +733,20 @@ Example::
...
@@ -734,22 +733,20 @@ Example::
.. _func_set.debug:
.. _func_set.debug:
set.debug
STRING set.debug()
---------
------------------
::
Prototype
STRING set.debug()
STRING set.debug()
Intentionally not documented.
Intentionally not documented.
.. _func_version:
.. _func_version:
version
STRING version()
-------
----------------
::
Prototype
STRING version()
STRING version()
Return the version string for this VMOD.
Return the version string for this VMOD.
...
@@ -771,8 +768,9 @@ the VMOD's error message as the message for the load failure.
...
@@ -771,8 +768,9 @@ the VMOD's error message as the message for the load failure.
REQUIREMENTS
REQUIREMENTS
============
============
The VMOD requires Varnish 5.0.0. See the VMOD source repository for
The VMOD requires Varnish versions 4.1.7 through 4.1.10. See the VMOD
versions that are compatible with other Varnish versions.
source repository for versions that are compatible with other Varnish
versions.
INSTALLATION
INSTALLATION
============
============
...
@@ -820,20 +818,5 @@ SEE ALSO
...
@@ -820,20 +818,5 @@ SEE ALSO
* varnishd(1)
* varnishd(1)
* vcl(7)
* vcl(7)
* VMOD source repository: https://code.uplex.de/uplex-varnish/libvmod-selector
* VMOD source repository: https://code.uplex.de/uplex-varnish/libvmod-selector
* `VMOD re2`_: https://code.uplex.de/uplex-varnish/libvmod-re2
* VMOD re2: https://code.uplex.de/uplex-varnish/libvmod-re2
COPYRIGHT
=========
::
Copyright (c) 2018 UPLEX Nils Goroll Systemoptimierung
All rights reserved
Author: Geoffrey Simmons <geoffrey.simmons@uplex.de>
See LICENSE
.. _VMOD re2: https://code.uplex.de/uplex-varnish/libvmod-re2
configure.ac
View file @
277fa01e
...
@@ -37,7 +37,7 @@ AM_CONDITIONAL(HAVE_RST2MAN, [test "x$RST2MAN" != "xno"])
...
@@ -37,7 +37,7 @@ AM_CONDITIONAL(HAVE_RST2MAN, [test "x$RST2MAN" != "xno"])
m4_ifndef([VARNISH_PREREQ], AC_MSG_ERROR([Need varnish.m4 -- see README.rst]))
m4_ifndef([VARNISH_PREREQ], AC_MSG_ERROR([Need varnish.m4 -- see README.rst]))
VARNISH_PREREQ([
5.0.0], [5.0.
0])
VARNISH_PREREQ([
4.1.7], [4.1.1
0])
VARNISH_VMODS([selector])
VARNISH_VMODS([selector])
VMOD_TESTS="$(cd $srcdir/src && echo tests/*.vtc)"
VMOD_TESTS="$(cd $srcdir/src && echo tests/*.vtc)"
...
...
src/tests/case.vtc
View file @
277fa01e
...
@@ -294,7 +294,7 @@ varnish v1 -vcl {
...
@@ -294,7 +294,7 @@ varnish v1 -vcl {
set resp.http.Matched-2 = s.matched(2);
set resp.http.Matched-2 = s.matched(2);
set resp.http.Matched-3 = s.matched(3);
set resp.http.Matched-3 = s.matched(3);
set resp.http.Matched-4 = s.matched(4);
set resp.http.Matched-4 = s.matched(4);
s
et resp.body = s.debug(
);
s
ynthetic(s.debug()
);
return (deliver);
return (deliver);
}
}
}
}
...
...
src/tests/match.vtc
View file @
277fa01e
...
@@ -30,7 +30,7 @@ varnish v1 -vcl {
...
@@ -30,7 +30,7 @@ varnish v1 -vcl {
set resp.http.Match-Zab = t.match("zab");
set resp.http.Match-Zab = t.match("zab");
set resp.http.Match-Xuuq = t.match("xuuq");
set resp.http.Match-Xuuq = t.match("xuuq");
set resp.http.Match-Raboof = t.match("raboof");
set resp.http.Match-Raboof = t.match("raboof");
s
et resp.body = t.debug(
);
s
ynthetic( t.debug()
);
return (deliver);
return (deliver);
}
}
} -start
} -start
...
...
src/tests/prefix.vtc
View file @
277fa01e
...
@@ -29,7 +29,7 @@ varnish v1 -vcl {
...
@@ -29,7 +29,7 @@ varnish v1 -vcl {
set resp.http.Matched-2 = s.matched(2);
set resp.http.Matched-2 = s.matched(2);
set resp.http.Matched-3 = s.matched(3);
set resp.http.Matched-3 = s.matched(3);
set resp.http.Matched-4 = s.matched(4);
set resp.http.Matched-4 = s.matched(4);
s
et resp.body = s.debug(
);
s
ynthetic(s.debug()
);
return (deliver);
return (deliver);
}
}
} -start
} -start
...
@@ -168,7 +168,7 @@ varnish v1 -vcl {
...
@@ -168,7 +168,7 @@ varnish v1 -vcl {
set resp.http.Matched-2 = s.matched(2);
set resp.http.Matched-2 = s.matched(2);
set resp.http.Matched-3 = s.matched(3);
set resp.http.Matched-3 = s.matched(3);
set resp.http.Matched-4 = s.matched(4);
set resp.http.Matched-4 = s.matched(4);
s
et resp.body = s.debug(
);
s
ynthetic(s.debug()
);
return (deliver);
return (deliver);
}
}
}
}
...
@@ -345,7 +345,7 @@ varnish v1 -vcl {
...
@@ -345,7 +345,7 @@ varnish v1 -vcl {
set resp.http.Matched-2 = s.matched(2);
set resp.http.Matched-2 = s.matched(2);
set resp.http.Matched-3 = s.matched(3);
set resp.http.Matched-3 = s.matched(3);
set resp.http.Matched-4 = s.matched(4);
set resp.http.Matched-4 = s.matched(4);
s
et resp.body = s.debug(
);
s
ynthetic(s.debug()
);
return (deliver);
return (deliver);
}
}
}
}
...
...
src/tests/sub.vtc
View file @
277fa01e
...
@@ -65,8 +65,8 @@ client c1 {
...
@@ -65,8 +65,8 @@ client c1 {
expect resp.http.N-2-3 == "_f&rap_"
expect resp.http.N-2-3 == "_f&rap_"
expect resp.http.N-2-4 == "_barffra\\p_"
expect resp.http.N-2-4 == "_barffra\\p_"
expect resp.http.N-3 == "XXX"
expect resp.http.N-3 == "XXX"
expect resp.http.N-4 == "
${localhost}
"
expect resp.http.N-4 == "
127.0.0.1
"
expect resp.http.N-5 == "
${localhost}
"
expect resp.http.N-5 == "
127.0.0.1
"
expect resp.http.N-1-1-F == resp.http.N-1-1
expect resp.http.N-1-1-F == resp.http.N-1-1
expect resp.http.N-1-2-F == resp.http.N-1-2
expect resp.http.N-1-2-F == resp.http.N-1-2
...
...
src/vmod_selector.c
View file @
277fa01e
...
@@ -110,12 +110,14 @@ errmsg(VRT_CTX, const char *fmt, ...)
...
@@ -110,12 +110,14 @@ errmsg(VRT_CTX, const char *fmt, ...)
}
}
}
}
#if 0
static inline void
static inline void
WS_Assert_Allocated(const struct ws *ws, const void *ptr, ssize_t len)
WS_Assert_Allocated(const struct ws *ws, const void *ptr, ssize_t len)
{
{
const char *p = ptr;
const char *p = ptr;
assert(p >= ws->s && (p + len) <= ws->f);
assert(p >= ws->s && (p + len) <= ws->f);
}
}
#endif
static
inline
unsigned
static
inline
unsigned
WS_ReserveLumps
(
struct
ws
*
ws
,
size_t
sz
)
WS_ReserveLumps
(
struct
ws
*
ws
,
size_t
sz
)
...
@@ -169,7 +171,7 @@ vmod_set__init(VRT_CTX, struct vmod_selector_set **setp, const char *vcl_name,
...
@@ -169,7 +171,7 @@ vmod_set__init(VRT_CTX, struct vmod_selector_set **setp, const char *vcl_name,
ALLOC_OBJ
(
set
->
bitmaps
,
VMOD_SELECTOR_BITMAPS_MAGIC
);
ALLOC_OBJ
(
set
->
bitmaps
,
VMOD_SELECTOR_BITMAPS_MAGIC
);
AN
(
set
->
bitmaps
);
AN
(
set
->
bitmaps
);
for
(
int
i
=
0
;
i
<
__MAX_BITMAP
;
i
++
)
{
for
(
int
i
=
0
;
i
<
__MAX_BITMAP
;
i
++
)
{
set
->
bitmaps
->
bitmaps
[
i
]
=
vbit_
new
(
0
);
set
->
bitmaps
->
bitmaps
[
i
]
=
vbit_
init
(
0
);
AN
(
set
->
bitmaps
->
bitmaps
[
i
]);
AN
(
set
->
bitmaps
->
bitmaps
[
i
]);
}
}
...
...
src/vmod_selector.vcc
View file @
277fa01e
...
@@ -7,8 +7,6 @@
...
@@ -7,8 +7,6 @@
# See LICENSE
# See LICENSE
#
#
.. _VMOD re2: https://code.uplex.de/uplex-varnish/libvmod-re2
$Module selector 3 Varnish Module for matching strings associated with backends, regexen and other strings
$Module selector 3 Varnish Module for matching strings associated with backends, regexen and other strings
::
::
...
@@ -166,11 +164,12 @@ the VMOD can contribute to better code maintainability.
...
@@ -166,11 +164,12 @@ the VMOD can contribute to better code maintainability.
Matches with ``.match()`` and ``.hasprefix()`` are fixed string
Matches with ``.match()`` and ``.hasprefix()`` are fixed string
matches; characters such as wildcards and regex metacharacters are
matches; characters such as wildcards and regex metacharacters are
matched literally, and have no special meaning. Regex operations
matched literally, and have no special meaning. Regex operations such
such as matching or substitution can be performed after set matches,
as matching or substitution can be performed after set matches, using
using the regex saved with the ``regex`` parameter. But if you need
the regex saved with the ``regex`` parameter. But if you need to match
to match against sets of patterns, consider using the set interface
against sets of patterns, consider using the set interface of VMOD re2
of `VMOD re2`_, which provides techniques similar to the present VMOD.
(see `SEE ALSO`_ below), which provides techniques similar to the
present VMOD.
Selecting matched elements of a set
Selecting matched elements of a set
-----------------------------------
-----------------------------------
...
@@ -665,8 +664,9 @@ the VMOD's error message as the message for the load failure.
...
@@ -665,8 +664,9 @@ the VMOD's error message as the message for the load failure.
REQUIREMENTS
REQUIREMENTS
============
============
The VMOD requires Varnish 5.0.0. See the VMOD source repository for
The VMOD requires Varnish versions 4.1.7 through 4.1.10. See the VMOD
versions that are compatible with other Varnish versions.
source repository for versions that are compatible with other Varnish
versions.
INSTALLATION
INSTALLATION
============
============
...
@@ -714,6 +714,6 @@ SEE ALSO
...
@@ -714,6 +714,6 @@ SEE ALSO
* varnishd(1)
* varnishd(1)
* vcl(7)
* vcl(7)
* VMOD source repository: https://code.uplex.de/uplex-varnish/libvmod-selector
* VMOD source repository: https://code.uplex.de/uplex-varnish/libvmod-selector
*
`VMOD re2`_
: https://code.uplex.de/uplex-varnish/libvmod-re2
*
VMOD re2
: https://code.uplex.de/uplex-varnish/libvmod-re2
$Event event
$Event event
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