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
1f071898
Commit
1f071898
authored
Oct 05, 2020
by
Geoff Simmons
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add the element enum to .re_match().
parent
fabdb68e
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
47 additions
and
8 deletions
+47
-8
README.rst
README.rst
+3
-2
re_match.vtc
src/tests/re_match.vtc
+38
-0
vmod_selector.c
src/vmod_selector.c
+5
-5
vmod_selector.vcc
src/vmod_selector.vcc
+1
-1
No files found.
README.rst
View file @
1f071898
...
...
@@ -818,14 +818,15 @@ Example::
.. _xset.re_match():
BOOL xset.re_match(STRING subject, INT n, ENUM select)
------------------------------------------------------
BOOL xset.re_match(STRING subject, INT n,
STRING element,
ENUM select)
------------------------------------------------------
----------------
::
BOOL xset.re_match(
STRING subject,
INT n=0,
STRING element=0,
ENUM {UNIQUE, EXACT, FIRST, LAST, SHORTEST, LONGEST} select=UNIQUE
)
...
...
src/tests/re_match.vtc
View file @
1f071898
...
...
@@ -62,6 +62,23 @@ varnish v1 -vcl {
set resp.http.Nonmatch-Longest
= s.re_match(req.http.Word, select=LONGEST);
}
if (req.http.Element) {
set resp.http.Element
= s.re_match(req.http.Subject,
element=req.http.Element);
set resp.http.Element-Unique
= s.re_match(req.http.Subject, select=UNIQUE);
set resp.http.Element-Exact
= s.re_match(req.http.Subject, select=EXACT);
set resp.http.Element-First
= s.re_match(req.http.Subject, select=FIRST);
set resp.http.Element-Last
= s.re_match(req.http.Subject, select=LAST);
set resp.http.Element-Shortest
= s.re_match(req.http.Subject, select=SHORTEST);
set resp.http.Element-Longest
= s.re_match(req.http.Subject, select=LONGEST);
}
return (deliver);
}
} -start
...
...
@@ -197,6 +214,17 @@ client c1 {
expect resp.http.Nonmatch-Last == "false"
expect resp.http.Nonmatch-Shortest == "false"
expect resp.http.Nonmatch-Longest == "false"
txreq -hdr "Element: foo" -hdr "Subject: oof"
rxresp
expect resp.status == 200
expect resp.http.Element == "true"
expect resp.http.Element-Unique == resp.http.Element
expect resp.http.Element-Exact == resp.http.Element
expect resp.http.Element-First == "true"
expect resp.http.Element-Last == "true"
expect resp.http.Element-Shortest == "true"
expect resp.http.Element-Longest == "true"
} -run
client c1 {
...
...
@@ -214,6 +242,11 @@ client c1 {
expect_close
} -run
client c1 {
txreq -hdr "Element: oof"
expect_close
} -run
logexpect l1 -v v1 -d 1 -g vxid -q "VCL_Error" {
expect 0 * Begin req
expect * = VCL_Error {^vmod selector failure: s\.re_match\(\) called without prior match$}
...
...
@@ -229,6 +262,11 @@ logexpect l1 -v v1 -d 1 -g vxid -q "VCL_Error" {
expect * = VCL_Error {^vmod selector failure: s\.re_match\(6\): set has 5 elements$}
expect * = VCL_return fail
expect * = End
expect 0 * Begin req
expect * = VCL_Error {^vmod selector failure: s\.re_match\(element="oof"\): no such element$}
expect * = VCL_return fail
expect * = End
} -run
varnish v1 -vcl {
...
...
src/vmod_selector.c
View file @
1f071898
...
...
@@ -813,7 +813,7 @@ vmod_set_integer(VRT_CTX, struct vmod_selector_set * set, VCL_INT n,
static
vre_t
*
get_re
(
VRT_CTX
,
const
struct
vmod_selector_set
*
const
restrict
set
,
VCL_INT
n
,
VCL_ENUM
const
restrict
selects
,
VCL_INT
n
,
VCL_
STRING
element
,
VCL_
ENUM
const
restrict
selects
,
const
char
*
const
restrict
method
)
{
unsigned
idx
;
...
...
@@ -822,7 +822,7 @@ get_re(VRT_CTX, const struct vmod_selector_set * const restrict set,
CHECK_OBJ_NOTNULL
(
ctx
,
VRT_CTX_MAGIC
);
CHECK_OBJ_NOTNULL
(
set
,
VMOD_SELECTOR_SET_MAGIC
);
idx
=
get_idx
(
ctx
,
n
,
set
,
method
,
NULL
,
selects
);
idx
=
get_idx
(
ctx
,
n
,
set
,
method
,
element
,
selects
);
if
(
idx
==
UINT_MAX
)
return
(
NULL
);
if
(
!
check_added
(
ctx
,
set
,
idx
,
REGEX
,
method
,
"regex"
))
...
...
@@ -835,11 +835,11 @@ get_re(VRT_CTX, const struct vmod_selector_set * const restrict set,
VCL_BOOL
vmod_set_re_match
(
VRT_CTX
,
struct
vmod_selector_set
*
set
,
VCL_STRING
subject
,
VCL_INT
n
,
VCL_ENUM
selects
)
VCL_INT
n
,
VCL_
STRING
element
,
VCL_
ENUM
selects
)
{
vre_t
*
re
;
re
=
get_re
(
ctx
,
set
,
n
,
selects
,
"re_match"
);
re
=
get_re
(
ctx
,
set
,
n
,
element
,
selects
,
"re_match"
);
if
(
re
==
NULL
)
return
(
0
);
return
(
VRT_re_match
(
ctx
,
subject
,
re
));
...
...
@@ -851,7 +851,7 @@ vmod_set_sub(VRT_CTX, struct vmod_selector_set *set, VCL_STRING str,
{
vre_t
*
re
;
re
=
get_re
(
ctx
,
set
,
n
,
selects
,
"sub"
);
re
=
get_re
(
ctx
,
set
,
n
,
NULL
,
selects
,
"sub"
);
if
(
re
==
NULL
)
return
(
NULL
);
return
(
VRT_regsub
(
ctx
,
all
,
str
,
re
,
sub
));
...
...
src/vmod_selector.vcc
View file @
1f071898
...
...
@@ -724,7 +724,7 @@ Example::
}
}
$Method BOOL .re_match(STRING subject, INT n=0,
$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