pax_global_header 0000666 0000000 0000000 00000000064 13440241474 0014515 g ustar 00root root 0000000 0000000 52 comment=32f974d68f12c007ef84caa7983641886e922a94
libvmod-re-master-32f974d68f12c007ef84caa7983641886e922a94/ 0000775 0000000 0000000 00000000000 13440241474 0021603 5 ustar 00root root 0000000 0000000 libvmod-re-master-32f974d68f12c007ef84caa7983641886e922a94/.dir-locals.el 0000664 0000000 0000000 00000000111 13440241474 0024225 0 ustar 00root root 0000000 0000000 ((nil . ((indent-tabs-mode . t)))
(c-mode . ((c-file-style . "BSD"))))
libvmod-re-master-32f974d68f12c007ef84caa7983641886e922a94/.gitignore 0000664 0000000 0000000 00000000736 13440241474 0023601 0 ustar 00root root 0000000 0000000 CONFIGURE
Makefile
Makefile.in
aclocal.m4
autom4te.cache/
compile
config.guess
config.h
config.h.in
config.log
config.status
config.sub
configure
depcomp
install-sh
libtool
ltmain.sh
m4/libtool.m4
m4/ltoptions.m4
m4/ltsugar.m4
m4/ltversion.m4
m4/lt~obsolete.m4
missing
src/.deps/
src/.libs/
src/Makefile
src/Makefile.in
src/libvmod_re.la
src/vcc_if.c
src/vcc_if.h
src/vcc_if.lo
src/vcc_if.o
src/vmod_re.lo
src/vmod_re.o
src/vmod_re.man.rst
src/vmod_re.rst
stamp-h1
vmod_re.3
*~
libvmod-re-master-32f974d68f12c007ef84caa7983641886e922a94/COPYING 0000664 0000000 0000000 00000000315 13440241474 0022635 0 ustar 00root root 0000000 0000000 Copyright (c) 2013-2014 UPLEX Nils Goroll Systemoptimierung
...
See LICENSE for details.
You're free to use and distribute this under terms in the
LICENSE. Please add your relevant copyright statements.
libvmod-re-master-32f974d68f12c007ef84caa7983641886e922a94/INSTALL.rst 0000664 0000000 0000000 00000004210 13440241474 0023440 0 ustar 00root root 0000000 0000000 INSTALLATION
============
RPMs
~~~~
Binary, debuginfo and source RPMs for VMOD re are available at
packagecloud:
https://packagecloud.io/uplex/varnish
The packages are built for Enterprise Linux 7 (el7), and hence will
run on compatible distros (such as RHEL7, Fedora, CentOS 7 and Amazon
Linux).
To set up your YUM repository for the RPMs, follow these instructions:
https://packagecloud.io/uplex/varnish/install#manual-rpm
You will also need these additional repositories:
* EPEL7
* ``yum install https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm``
* Official Varnish packages from packagecloud (since version 6.0.0)
* Follow the instructions at: https://packagecloud.io/varnishcache/varnish60/install#manual-rpm
If you have problems or questions concerning the RPMs, post an issue
to one of the source repository web sites, or contact
.
Building from source
~~~~~~~~~~~~~~~~~~~~
The VMOD is built on a system where an instance of Varnish is
installed, and the auto-tools will attempt to locate the Varnish
instance, and then pull in libraries and other support files from
there.
Quick start
-----------
This sequence should be enough in typical setups:
1. ``./autogen.sh`` (for git-installation)
2. ``./configure``
3. ``make``
4. ``make check`` (regression tests)
5. ``make install`` (may require root: sudo make install)
Alternative configs
-------------------
If you have installed Varnish to a non-standard directory, call
``autogen.sh`` and ``configure`` with ``PKG_CONFIG_PATH`` pointing to
the appropriate path. For example, when varnishd configure was called
with ``--prefix=$PREFIX``, use::
PKG_CONFIG_PATH=${PREFIX}/lib/pkgconfig
export PKG_CONFIG_PATH
For developers
--------------
As with Varnish, you can use these ``configure`` options for stricter
compiling:
* ``--enable-developer-warnings``
* ``--enable-extra-developer-warnings`` (for GCC 4)
* ``--enable-werror``
The VMOD must always build successfully with these options enabled.
Also as with Varnish, you can add ``--enable-debugging-symbols``, so
that the VMOD's symbols are available to debuggers, in core dumps and
so forth.
libvmod-re-master-32f974d68f12c007ef84caa7983641886e922a94/LICENSE 0000664 0000000 0000000 00000002423 13440241474 0022611 0 ustar 00root root 0000000 0000000 Copyright 2013-2018 UPLEX Nils Goroll Systemoptimierung
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
libvmod-re-master-32f974d68f12c007ef84caa7983641886e922a94/Makefile.am 0000664 0000000 0000000 00000001244 13440241474 0023640 0 ustar 00root root 0000000 0000000 ACLOCAL_AMFLAGS = -I m4 -I ${LIBVARNISHAPI_DATAROOTDIR}/aclocal
SUBDIRS = src
DISTCHECK_CONFIGURE_FLAGS = \
VMOD_DIR='$${libdir}/varnish/vmods'
EXTRA_DIST = README.rst LICENSE COPYING
doc_DATA = README.rst LICENSE COPYING
dist_man_MANS = vmod_re.3
MAINTAINERCLEANFILES = $(dist_man_MANS)
vmod_re.3: README.rst
README.rst: src/vmod_re.man.rst
cp src/vmod_re.man.rst README.rst
src/vmod_re.man.rst:
make -C src vmod_re.man.rst
%.1 %.2 %.3 %.4 %.5 %.6 %.7 %.8 %.9:
if HAVE_RST2MAN
${RST2MAN} $< $@
else
@echo "========================================"
@echo "You need rst2man installed to make dist"
@echo "========================================"
@false
endif
libvmod-re-master-32f974d68f12c007ef84caa7983641886e922a94/README.rst 0000664 0000000 0000000 00000024531 13440241474 0023277 0 ustar 00root root 0000000 0000000 ..
.. NB: This file is machine generated, DO NOT EDIT!
..
.. Edit vmod.vcc and run make instead
..
.. role:: ref(emphasis)
=======
VMOD re
=======
-------------------------------------------------------------------------
Varnish Module for Regular Expression Matching with Subexpression Capture
-------------------------------------------------------------------------
:Manual section: 3
SYNOPSIS
========
::
import re;
# object interface
new = re.regex(STRING, [, INT limit] [, INT limit_recursion])
BOOL .match(STRING, [, INT limit] [, INT limit_recursion])
STRING .backref(INT [, STRING fallback])
# function interface
BOOL re.match_dyn(STRING, [, INT limit] [, INT limit_recursion])
STRING re.backref_dyn(INT [, STRING fallback])
STRING re.version()
DESCRIPTION
===========
Varnish Module (VMOD) for matching strings against regular expressions,
and for extracting captured substrings after matches.
Regular expression matching as implemented by the VMOD is equivalent
to VCL's infix operator ``~``. The VMOD is motivated by the fact that
backreference capture in standard VCL requires verbose and suboptimal
use of the ``regsub`` or ``regsuball`` functions. For example, this
common idiom in VCL captures a string of digits following the
substring ``"bar"`` from one request header into another::
sub vcl_recv {
if (req.http.Foo ~ "bar\d+")) {
set req.http.Baz = regsub(req.http.Foo,
"^.*bar(\d+).*$", "\1");
}
}
It requires two regex executions when a match is found, the second one
less efficient than the first (since it must match the entire string
to be replaced while capturing a substring), and is just cumbersome.
The equivalent solution with the VMOD looks like this::
import re;
sub vcl_init {
new myregex = re.regex("bar(\d+)");
}
sub vcl_recv {
if (myregex.match(req.http.Foo)) {
set req.http.Baz = myregex.backref(1);
}
}
The object is created at VCL initialization with the regex containing
the capture expression, only describing the substring to be
matched. When a match with the ``match`` method succeeds, then a
captured string can be obtained from the ``backref`` method.
Calls to the ``backref`` method refer back to the most recent
successful call to ``match`` for the same object in the same task
scope; that is, in the same client or backend context. For example if
``match`` is called for an object in one of the ``vcl_backend_*``
subroutines and returns ``true``, then subsequent calls to ``backref``
in the same backend scope extract substrings from the matched
substring.
The VMOD also supports dynamic regex matching with the ``match_dyn``
and ``backref_dyn`` functions::
import re;
sub vcl_backend_response {
if (re.match_dyn(beresp.http.Bar + "(\d+)",
req.http.Foo)) {
set beresp.http.Baz = re.backref_dyn(1);
}
}
In ``match_dyn``, the regex in the first argument is compiled when it
is called, and matched against the string in the second
argument. Subsequent calls to ``backref_dyn`` extract substrings from
the matched string for the most recent successful call to
``match_dyn`` in the same task scope.
As with the constructor, the regex argument to ``match_dyn`` should
contain any capturing expressions needed for calls to ``backref_dyn``.
``match_dyn`` makes it possible to construct regexen whose contents
are not fully known until runtime, but ``match`` is more efficient,
since it re-uses the compiled expression obtained at VCL
initialization. So if you are matching against a fixed pattern that
never changes during the lifetime of VCL, use ``match``.
.. _vmod_re.regex:
new xregex = re.regex(STRING, INT limit, INT limit_recursion)
-------------------------------------------------------------
::
new xregex = re.regex(
STRING,
INT limit=1000,
INT limit_recursion=1000
)
Description
Create a regex object with the given regular expression. The
expression is compiled when the constructor is called. It
should include any capturing parentheses that will be needed
for extracting backreferences.
If the regular expression fails to compile, then the VCL
load fails with an error message describing the problem.
The optional parameters ``limit`` and ``limit_recursion`` are
per-object defaults for the respective parameters of the
`vmod_re.regex.match`_ method.
Example
``new myregex = re.regex("\bmax-age\s*=\s*(\d+)");``
.. _vmod_re.regex.match:
BOOL xregex.match(STRING, INT limit, INT limit_recursion)
---------------------------------------------------------
::
BOOL xregex.match(STRING, INT limit=0, INT limit_recursion=0)
Description
Determines whether the given string matches the regex compiled
by the constructor; functionally equivalent to VCL's infix
operator ``~``.
The optional parameter ``limit`` restricts the number of
internal matching function calls in a ``pcre_exec()``
execution, analogous to the varnishd ``pcre_match_limit``
parameter. For the default value 0, the ``limit`` given to the
constructor `vmod_re.regex`_ is used.
The optional parameter ``limit_recursion`` restricts the
number of internal matching function recursions in a
``pcre_exec()`` execution, analogous to the varnishd
``pcre_match_limit_recursion`` parameter. For the default
value 0, the ``limit_recursion`` given to the constructor
`vmod_re.regex`_ is used.
Example
``if (myregex.match(beresp.http.Surrogate-Control)) { # ...``
.. _vmod_re.regex.backref:
STRING xregex.backref(INT, STRING fallback)
-------------------------------------------
::
STRING xregex.backref(
INT,
STRING fallback="**BACKREF METHOD FAILED**"
)
Description
Extracts the `nth` subexpression of the most recent successful
call of the ``match`` method for this object in the same task
scope (client or backend context), or a fallback string in
case the extraction fails. Backref 0 indicates the entire
matched string. Thus this function behaves like the ``\n``
symbols in ``regsub`` and ``regsuball``, and the ``$1``,
``$2`` ... variables in Perl.
After unsuccessful matches, the ``fallback`` string is returned
for any call to ``backref``. The default value of ``fallback``
is ``"**BACKREF METHOD FAILED**"``.
The VCL infix operators ``~`` and ``!~`` do not affect this
method, nor do the functions ``regsub`` or ``regsuball``.
If ``backref`` is called without any prior call to ``match``
for this object in the same task scope, then an error message
is emitted to the Varnish log using the ``VCL_Error`` tag, and
the fallback string is returned.
Example
``set beresp.ttl = std.duration(myregex.backref(1, "120"), 120s);``
.. _vmod_re.match_dyn:
BOOL match_dyn(STRING, STRING, INT limit, INT limit_recursion)
--------------------------------------------------------------
::
BOOL match_dyn(
STRING,
STRING,
INT limit=1000,
INT limit_recursion=1000
)
Description
Compiles the regular expression given in the first argument,
and determines whether it matches the string in the second
argument.
If the regular expression fails to compile, then an error
message describing the problem is emitted to the Varnish log
with the tag ``VCL_Error``, and ``match_dyn`` returns
``false``.
For parameters ``limit`` and ``limit_recursion`` see
`vmod_re.regex.match`_, except that there is no object to inherit
defaults from.
Example
``if (re.match_dyn(req.http.Foo + "(\d+)", beresp.http.Bar)) { # ...``
.. _vmod_re.backref_dyn:
STRING backref_dyn(INT, STRING fallback)
----------------------------------------
::
STRING backref_dyn(
INT,
STRING fallback="**BACKREF FUNCTION FAILED**"
)
Description
Similar to the ``backref`` method, this function extracts the
`nth` subexpression of the most recent successful call of the
``match_dyn`` function in the same task scope, or a fallback
string in case the extraction fails.
After unsuccessful matches, the ``fallback`` string is returned
for any call to ``backref_dyn``. The default value of ``fallback``
is ``"**BACKREF FUNCTION FAILED**"``.
If ``backref_dyn`` is called without any prior call to ``match_dyn``
in the same task scope, then a ``VCL_Error`` message is logged, and
the fallback string is returned.
.. _vmod_re.version:
STRING version()
----------------
Description
Returns the version string for this vmod.
Example
``set resp.http.X-re-version = re.version();``
REQUIREMENTS
============
The VMOD requires the Varnish since version 6.0.0 or the master
branch. See the project repository for versions that are compatible
with other versions of Varnish.
INSTALLATION
============
See `INSTALL.rst `_ in the project source repository.
LIMITATIONS
===========
The VMOD allocates memory for captured subexpressions from Varnish
workspaces, whose sizes are determined by the runtime parameters
``workspace_backend``, for calls within the ``vcl_backend_*``
subroutines, and ``workspace_client``, for the other VCL subs. The
VMOD copies the string to be matched into the workspace, if it's not
already in the workspace, and also uses workspace to save data about
backreferences.
For typical usage, the default workspace sizes are probably enough;
but if you are matching against many, long strings in each client or
backend context, you might need to increase the Varnish parameters for
workspace sizes. If the VMOD cannot allocate enough workspace, then a
``VCL_error`` message is emitted, and the match methods as well as
``backref`` will fail. (If you're just using the regexen for matching
and not to capture backrefs, then you might as well just use the
standard VCL operators ``~`` and ``!~``, and save the workspace.)
``backref`` can extract up to 10 subexpressions, in addition to the
full expression indicated by backref 0. If a ``match`` or
``match_dyn`` operation would have resulted in more than 11 captures
(10 substrings and the full string), then a ``VCL_Error`` message is
emitted to the Varnish log, and the captures are limited to 11.
SEE ALSO
========
* varnishd(1)
* vcl(7)
* pcre(3)
* source repository: https://code.uplex.de/uplex-varnish/libvmod-re
COPYRIGHT
=========
::
Copyright 2014-2018 UPLEX Nils Goroll Systemoptimierung
All rights reserved
This document is licensed under the same conditions as the libvmod-re
project. See LICENSE for details.
Authors: Geoffrey Simmons
Nils Goroll
libvmod-re-master-32f974d68f12c007ef84caa7983641886e922a94/autogen.sh 0000775 0000000 0000000 00000002072 13440241474 0023605 0 ustar 00root root 0000000 0000000 #!/bin/sh
warn() {
echo "WARNING: $@" 1>&2
}
case `uname -s` in
Darwin)
LIBTOOLIZE=glibtoolize
;;
FreeBSD)
LIBTOOLIZE=libtoolize
;;
Linux)
LIBTOOLIZE=libtoolize
;;
SunOS)
LIBTOOLIZE=libtoolize
;;
*)
warn "unrecognized platform:" `uname -s`
LIBTOOLIZE=libtoolize
esac
automake_version=`automake --version | tr ' ' '\n' | egrep '^[0-9]\.[0-9a-z.-]+'`
if [ -z "$automake_version" ] ; then
warn "unable to determine automake version"
else
case $automake_version in
0.*|1.[0-8]|1.[0-8][.-]*)
warn "automake ($automake_version) detected; 1.9 or newer recommended"
;;
*)
;;
esac
fi
# check for varnishapi.m4 in custom paths
dataroot=`pkg-config --variable=datarootdir varnishapi 2>/dev/null`
if [ -z "$dataroot" ] ; then
cat >&2 <