...
 
Commits (6)
......@@ -113,7 +113,7 @@ 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:
.. _re.regex():
new xregex = re.regex(STRING, INT limit, INT limit_recursion)
-------------------------------------------------------------
......@@ -137,12 +137,12 @@ Description
The optional parameters ``limit`` and ``limit_recursion`` are
per-object defaults for the respective parameters of the
`vmod_re.regex.match`_ method.
`xregex.match()`_ method.
Example
``new myregex = re.regex("\bmax-age\s*=\s*(\d+)");``
.. _vmod_re.regex.match:
.. _xregex.match():
BOOL xregex.match(STRING, INT limit, INT limit_recursion)
---------------------------------------------------------
......@@ -160,19 +160,19 @@ Description
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.
constructor `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.
`re.regex()`_ is used.
Example
``if (myregex.match(beresp.http.Surrogate-Control)) { # ...``
.. _vmod_re.regex.backref:
.. _xregex.backref():
STRING xregex.backref(INT, STRING fallback)
-------------------------------------------
......@@ -208,7 +208,7 @@ Description
Example
``set beresp.ttl = std.duration(myregex.backref(1, "120"), 120s);``
.. _vmod_re.match_dyn:
.. _re.match_dyn():
BOOL match_dyn(STRING, STRING, INT limit, INT limit_recursion)
--------------------------------------------------------------
......@@ -233,13 +233,13 @@ Description
``false``.
For parameters ``limit`` and ``limit_recursion`` see
`vmod_re.regex.match`_, except that there is no object to inherit
`xregex.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:
.. _re.backref_dyn():
STRING backref_dyn(INT, STRING fallback)
----------------------------------------
......@@ -265,7 +265,7 @@ Description
in the same task scope, then a ``VCL_Error`` message is logged, and
the fallback string is returned.
.. _vmod_re.version:
.. _re.version():
STRING version()
----------------
......
......@@ -186,14 +186,8 @@ match(VRT_CTX, vre_t *vre, VCL_STRING subject, struct vmod_priv *task,
}
task->len = sizeof(*ov);
if (WS_Inside(ctx->ws, subject, subject + len))
ov->subject = subject;
else if ((ov->subject = WS_Copy(ctx->ws, (const void *) subject, len))
== NULL) {
VSLb(ctx->vsl, SLT_VCL_Error,
"vmod re: insufficient workspace");
return 0;
}
ov->subject = subject;
memset(ov->ovector, -1, sizeof(ov->ovector));
cp = s * 2 * sizeof(*nov);
assert(cp <= sizeof(nov));
......@@ -205,7 +199,7 @@ static VCL_STRING
backref(VRT_CTX, VCL_INT refnum, VCL_STRING fallback, struct vmod_priv *task)
{
ov_t *ov;
char *substr;
const char *substr, *start;
int len;
CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
......@@ -234,11 +228,13 @@ backref(VRT_CTX, VCL_INT refnum, VCL_STRING fallback, struct vmod_priv *task)
if (ov->ovector[refnum] == -1)
return fallback;
start = ov->subject + ov->ovector[refnum];
len = ov->ovector[refnum+1] - ov->ovector[refnum];
assert(len <= ov->ovector[1] - ov->ovector[0]);
WS_Assert_Allocated(ctx->ws, ov->subject + ov->ovector[refnum], len);
substr = WS_Printf(ctx->ws, "%.*s", len,
ov->subject + ov->ovector[refnum]);
if (start[len] == '\0')
substr = start;
else
substr = WS_Printf(ctx->ws, "%.*s", len, start);
if (substr == NULL) {
VSLb(ctx->vsl, SLT_VCL_Error,
"vmod re: insufficient workspace");
......
......@@ -122,7 +122,7 @@ Description
The optional parameters ``limit`` and ``limit_recursion`` are
per-object defaults for the respective parameters of the
`vmod_re.regex.match`_ method.
`xregex.match()`_ method.
Example
``new myregex = re.regex("\bmax-age\s*=\s*(\d+)");``
......@@ -138,14 +138,14 @@ Description
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.
constructor `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.
`re.regex()`_ is used.
Example
``if (myregex.match(beresp.http.Surrogate-Control)) { # ...``
......@@ -190,7 +190,7 @@ Description
``false``.
For parameters ``limit`` and ``limit_recursion`` see
`vmod_re.regex.match`_, except that there is no object to inherit
`xregex.match()`_, except that there is no object to inherit
defaults from.
Example
......