Commit 277fa01e authored by Geoff Simmons's avatar Geoff Simmons

Backport for Varnish 4.1.

parent 110aefdd
......@@ -12,9 +12,9 @@
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
......@@ -130,7 +130,7 @@ lines. For example::
}
}
sub vcl_backend_fetch {
# The .hasprefix() method returns true if the URL has a prefix
......@@ -140,7 +140,7 @@ lines. For example::
# string in the set that was matched as a prefix.
set bereq.backend = url_prefix.backend();
}
}
sub vcl_synth {
......@@ -154,7 +154,7 @@ lines. For example::
= "http://other.com" + req.http.X-URL-Prefix + req.url;
return (deliver);
}
}
Matches with the ``.match()`` and ``.hasprefix()`` methods scale well
......@@ -179,11 +179,12 @@ the VMOD can contribute to better code maintainability.
Matches with ``.match()`` and ``.hasprefix()`` are fixed string
matches; characters such as wildcards and regex metacharacters are
matched literally, and have no special meaning. Regex operations
such as matching or substitution can be performed after set matches,
using the regex saved with the ``regex`` parameter. But if you need
to match against sets of patterns, consider using the set interface
of `VMOD re2`_, which provides techniques similar to the present VMOD.
matched literally, and have no special meaning. Regex operations such
as matching or substitution can be performed after set matches, using
the regex saved with the ``regex`` parameter. But if you need to match
against sets of patterns, consider using the set interface of VMOD re2
(see `SEE ALSO`_ below), which provides techniques similar to the
present VMOD.
Selecting matched elements of a set
-----------------------------------
......@@ -309,17 +310,26 @@ or the longest match, and so on::
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()
.. _obj_set:
set
---
::
Object set
==========
new OBJ = set(BOOL case_sensitive=1)
Create a set object. When ``case_sensitive`` is ``false``, matches
using the ``.match()`` and ``.hasprefix()`` methods are
......@@ -338,12 +348,11 @@ Example::
.. _func_set.add:
set.add
-------
VOID set.add(STRING, STRING, STRING, BACKEND)
---------------------------------------------
::
VOID set.add(STRING, STRING string=0, STRING regex=0, BACKEND backend=0)
Prototype
VOID set.add(STRING, STRING string, STRING regex, BACKEND backend)
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
......@@ -384,11 +393,10 @@ Example::
.. _func_set.match:
set.match
---------
::
BOOL set.match(STRING)
----------------------
Prototype
BOOL set.match(STRING)
Returns ``true`` if the given STRING exactly matches one of the
......@@ -412,11 +420,10 @@ Example::
.. _func_set.hasprefix:
set.hasprefix
-------------
::
BOOL set.hasprefix(STRING)
--------------------------
Prototype
BOOL set.hasprefix(STRING)
Returns ``true`` if the STRING to be matched has a prefix that is in
......@@ -434,11 +441,10 @@ Example::
.. _func_set.nmatches:
set.nmatches
------------
::
INT set.nmatches()
------------------
Prototype
INT set.nmatches()
Returns the number of elements that were matched by the most recent
......@@ -471,11 +477,10 @@ Example::
.. _func_set.matched:
set.matched
-----------
::
BOOL set.matched(INT)
---------------------
Prototype
BOOL set.matched(INT)
After a successful ``.match()`` or ``.hasprefix()`` call for the same
......@@ -505,12 +510,11 @@ Example::
.. _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
set object in the same task scope, return the index of the matching
......@@ -543,12 +547,11 @@ Example::
.. _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``
parameters as described above. Thus if ``n`` >= 1, the ``n``-th
......@@ -581,12 +584,11 @@ Example::
.. _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
by ``n`` and ``select``, according to the rules given above; that is,
......@@ -610,12 +612,11 @@ Example::
.. _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
the set indicated by ``n`` and ``select``, according to the rules
......@@ -636,12 +637,11 @@ Example::
.. _func_set.re_match:
set.re_match
------------
BOOL set.re_match(STRING, INT, ENUM)
------------------------------------
::
BOOL set.re_match(STRING subject, INT n=0, ENUM {UNIQUE,EXACT,FIRST,LAST,SHORTEST,LONGEST} select="UNIQUE")
Prototype
BOOL set.re_match(STRING subject, INT n, ENUM select)
Using the regular expression set by the ``regex`` parameter for the
element of the set indicated by ``n`` and ``select``, return the
......@@ -680,12 +680,11 @@ Example::
.. _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
element of the set indicated by ``n`` and ``select``, return the
......@@ -734,22 +733,20 @@ Example::
.. _func_set.debug:
set.debug
---------
::
STRING set.debug()
------------------
Prototype
STRING set.debug()
Intentionally not documented.
.. _func_version:
version
-------
::
STRING version()
----------------
Prototype
STRING version()
Return the version string for this VMOD.
......@@ -771,8 +768,9 @@ the VMOD's error message as the message for the load failure.
REQUIREMENTS
============
The VMOD requires Varnish 5.0.0. See the VMOD source repository for
versions that are compatible with other Varnish versions.
The VMOD requires Varnish versions 4.1.7 through 4.1.10. See the VMOD
source repository for versions that are compatible with other Varnish
versions.
INSTALLATION
============
......@@ -820,20 +818,5 @@ SEE ALSO
* varnishd(1)
* vcl(7)
* VMOD source repository: https://code.uplex.de/uplex-varnish/libvmod-selector
* `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
* VMOD re2: https://code.uplex.de/uplex-varnish/libvmod-re2
......@@ -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]))
VARNISH_PREREQ([5.0.0], [5.0.0])
VARNISH_PREREQ([4.1.7], [4.1.10])
VARNISH_VMODS([selector])
VMOD_TESTS="$(cd $srcdir/src && echo tests/*.vtc)"
......
......@@ -294,7 +294,7 @@ varnish v1 -vcl {
set resp.http.Matched-2 = s.matched(2);
set resp.http.Matched-3 = s.matched(3);
set resp.http.Matched-4 = s.matched(4);
set resp.body = s.debug();
synthetic(s.debug());
return (deliver);
}
}
......
......@@ -30,7 +30,7 @@ varnish v1 -vcl {
set resp.http.Match-Zab = t.match("zab");
set resp.http.Match-Xuuq = t.match("xuuq");
set resp.http.Match-Raboof = t.match("raboof");
set resp.body = t.debug();
synthetic( t.debug() );
return (deliver);
}
} -start
......
......@@ -29,7 +29,7 @@ varnish v1 -vcl {
set resp.http.Matched-2 = s.matched(2);
set resp.http.Matched-3 = s.matched(3);
set resp.http.Matched-4 = s.matched(4);
set resp.body = s.debug();
synthetic(s.debug());
return (deliver);
}
} -start
......@@ -168,7 +168,7 @@ varnish v1 -vcl {
set resp.http.Matched-2 = s.matched(2);
set resp.http.Matched-3 = s.matched(3);
set resp.http.Matched-4 = s.matched(4);
set resp.body = s.debug();
synthetic(s.debug());
return (deliver);
}
}
......@@ -345,7 +345,7 @@ varnish v1 -vcl {
set resp.http.Matched-2 = s.matched(2);
set resp.http.Matched-3 = s.matched(3);
set resp.http.Matched-4 = s.matched(4);
set resp.body = s.debug();
synthetic(s.debug());
return (deliver);
}
}
......
......@@ -65,8 +65,8 @@ client c1 {
expect resp.http.N-2-3 == "_f&rap_"
expect resp.http.N-2-4 == "_barffra\\p_"
expect resp.http.N-3 == "XXX"
expect resp.http.N-4 == "${localhost}"
expect resp.http.N-5 == "${localhost}"
expect resp.http.N-4 == "127.0.0.1"
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-2-F == resp.http.N-1-2
......
......@@ -110,12 +110,14 @@ errmsg(VRT_CTX, const char *fmt, ...)
}
}
#if 0
static inline void
WS_Assert_Allocated(const struct ws *ws, const void *ptr, ssize_t len)
{
const char *p = ptr;
assert(p >= ws->s && (p + len) <= ws->f);
}
#endif
static inline unsigned
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,
ALLOC_OBJ(set->bitmaps, VMOD_SELECTOR_BITMAPS_MAGIC);
AN(set->bitmaps);
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]);
}
......
......@@ -7,8 +7,6 @@
# 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
::
......@@ -166,11 +164,12 @@ the VMOD can contribute to better code maintainability.
Matches with ``.match()`` and ``.hasprefix()`` are fixed string
matches; characters such as wildcards and regex metacharacters are
matched literally, and have no special meaning. Regex operations
such as matching or substitution can be performed after set matches,
using the regex saved with the ``regex`` parameter. But if you need
to match against sets of patterns, consider using the set interface
of `VMOD re2`_, which provides techniques similar to the present VMOD.
matched literally, and have no special meaning. Regex operations such
as matching or substitution can be performed after set matches, using
the regex saved with the ``regex`` parameter. But if you need to match
against sets of patterns, consider using the set interface of VMOD re2
(see `SEE ALSO`_ below), which provides techniques similar to the
present VMOD.
Selecting matched elements of a set
-----------------------------------
......@@ -665,8 +664,9 @@ the VMOD's error message as the message for the load failure.
REQUIREMENTS
============
The VMOD requires Varnish 5.0.0. See the VMOD source repository for
versions that are compatible with other Varnish versions.
The VMOD requires Varnish versions 4.1.7 through 4.1.10. See the VMOD
source repository for versions that are compatible with other Varnish
versions.
INSTALLATION
============
......@@ -714,6 +714,6 @@ SEE ALSO
* varnishd(1)
* vcl(7)
* 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
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment