Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
L
libvmod-pcre2
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
3
Issues
3
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-pcre2
Commits
9c1a7cdb
Commit
9c1a7cdb
authored
Jun 28, 2017
by
Geoff Simmons
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Consolidate code for setting call-scoped match options in the match and
sub methods.
parent
eb5f62d3
Pipeline
#257
skipped
Changes
1
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
71 additions
and
66 deletions
+71
-66
vmod_pcre2.c
src/vmod_pcre2.c
+71
-66
No files found.
src/vmod_pcre2.c
View file @
9c1a7cdb
...
@@ -131,9 +131,14 @@
...
@@ -131,9 +131,14 @@
VCL_BOOL notempty, VCL_BOOL notempty_atstart, \
VCL_BOOL notempty, VCL_BOOL notempty_atstart, \
VCL_BOOL no_jit, VCL_BOOL no_utf_check
VCL_BOOL no_jit, VCL_BOOL no_utf_check
#define MATCH_SUB_FLAGS_PARAMS \
anchored, notbol, noteol, notempty, notempty_atstart, no_jit, \
no_utf_check, suball, sub_extended, unknown_unset, \
unset_empty \
#define MATCH_FLAGS_PARAMS \
#define MATCH_FLAGS_PARAMS \
anchored, notbol, noteol, notempty, notempty_atstart, no_jit, \
anchored, notbol, noteol, notempty, notempty_atstart, no_jit, \
no_utf_check
no_utf_check
, 0, 0, 0, 0
#define SUB_OPTS \
#define SUB_OPTS \
VCL_BOOL suball, VCL_BOOL sub_extended, VCL_BOOL unknown_unset, \
VCL_BOOL suball, VCL_BOOL sub_extended, VCL_BOOL unknown_unset, \
...
@@ -409,6 +414,61 @@ get_match_context(VRT_CTX, MATCH_CTX_OPTS, const char * restrict const context,
...
@@ -409,6 +414,61 @@ get_match_context(VRT_CTX, MATCH_CTX_OPTS, const char * restrict const context,
return
mctx
;
return
mctx
;
}
}
static
inline
void
set_opt
(
uint32_t
*
options
,
VCL_BOOL
vmod_opt
,
uint32_t
pcre2_opt
)
{
if
(
vmod_opt
)
*
options
|=
pcre2_opt
;
}
static
inline
void
set_match_flags
(
uint32_t
*
options
,
MATCH_FLAGS
,
SUB_OPTS
)
{
set_opt
(
options
,
anchored
,
PCRE2_ANCHORED
);
set_opt
(
options
,
notbol
,
PCRE2_NOTBOL
);
set_opt
(
options
,
noteol
,
PCRE2_NOTEOL
);
set_opt
(
options
,
notempty
,
PCRE2_NOTEMPTY
);
set_opt
(
options
,
notempty_atstart
,
PCRE2_NOTEMPTY_ATSTART
);
set_opt
(
options
,
no_jit
,
PCRE2_NO_JIT
);
set_opt
(
options
,
no_utf_check
,
PCRE2_NO_UTF_CHECK
);
set_opt
(
options
,
suball
,
PCRE2_SUBSTITUTE_GLOBAL
);
set_opt
(
options
,
sub_extended
,
PCRE2_SUBSTITUTE_EXTENDED
);
set_opt
(
options
,
unknown_unset
,
PCRE2_SUBSTITUTE_UNKNOWN_UNSET
);
set_opt
(
options
,
unset_empty
,
PCRE2_SUBSTITUTE_UNSET_EMPTY
);
}
static
inline
struct
match_call
*
get_match_opts
(
VRT_CTX
,
struct
vmod_priv
*
priv
,
MATCH_CTX_OPTS
,
MATCH_FLAGS
,
SUB_OPTS
,
const
char
*
context
,
const
char
*
caller
)
{
struct
match_call
*
match_opts
;
pcre2_match_context
*
mctx
;
if
(
priv
->
priv
!=
NULL
)
{
CAST_OBJ
(
match_opts
,
priv
->
priv
,
VMOD_PCRE2_MATCH_CALL_MAGIC
);
return
match_opts
;
}
if
((
mctx
=
get_match_context
(
ctx
,
MATCH_CTX_PARAMS
,
context
,
caller
))
==
NULL
)
return
NULL
;
ALLOC_OBJ
(
match_opts
,
VMOD_PCRE2_MATCH_CALL_MAGIC
);
if
(
match_opts
==
NULL
)
{
VERRNOMEM
(
ctx
,
"allocating call-scoped match options in %s%s"
,
context
,
caller
);
return
NULL
;
}
match_opts
->
mctx
=
mctx
;
set_match_flags
(
&
match_opts
->
match_options
,
MATCH_SUB_FLAGS_PARAMS
);
priv
->
priv
=
match_opts
;
priv
->
free
=
match_call_free
;
priv
->
len
=
sizeof
(
*
match_opts
);
return
match_opts
;
}
static
inline
struct
task
*
static
inline
struct
task
*
get_task
(
VRT_CTX
,
struct
vmod_priv
*
priv_task
,
get_task
(
VRT_CTX
,
struct
vmod_priv
*
priv_task
,
const
char
*
const
restrict
context
,
const
char
*
const
restrict
context
,
...
@@ -454,13 +514,6 @@ get_task(VRT_CTX, struct vmod_priv *priv_task,
...
@@ -454,13 +514,6 @@ get_task(VRT_CTX, struct vmod_priv *priv_task,
return
match_task
;
return
match_task
;
}
}
static
inline
void
set_opt
(
uint32_t
*
options
,
VCL_BOOL
vmod_opt
,
uint32_t
pcre2_opt
)
{
if
(
vmod_opt
)
*
options
|=
pcre2_opt
;
}
static
inline
void
static
inline
void
set_compile_flags
(
uint32_t
*
options
,
COMPILE_FLAGS
)
set_compile_flags
(
uint32_t
*
options
,
COMPILE_FLAGS
)
{
{
...
@@ -492,18 +545,6 @@ set_compile_flags(uint32_t *options, COMPILE_FLAGS)
...
@@ -492,18 +545,6 @@ set_compile_flags(uint32_t *options, COMPILE_FLAGS)
set_opt
(
options
,
utf
,
PCRE2_UTF
);
set_opt
(
options
,
utf
,
PCRE2_UTF
);
}
}
static
inline
void
set_match_flags
(
uint32_t
*
options
,
MATCH_FLAGS
)
{
set_opt
(
options
,
anchored
,
PCRE2_ANCHORED
);
set_opt
(
options
,
notbol
,
PCRE2_NOTBOL
);
set_opt
(
options
,
noteol
,
PCRE2_NOTEOL
);
set_opt
(
options
,
notempty
,
PCRE2_NOTEMPTY
);
set_opt
(
options
,
notempty_atstart
,
PCRE2_NOTEMPTY_ATSTART
);
set_opt
(
options
,
no_jit
,
PCRE2_NO_JIT
);
set_opt
(
options
,
no_utf_check
,
PCRE2_NO_UTF_CHECK
);
}
static
pcre2_code
*
static
pcre2_code
*
compile
(
VRT_CTX
,
pcre2_compile_context
*
restrict
const
cctx
,
compile
(
VRT_CTX
,
pcre2_compile_context
*
restrict
const
cctx
,
VCL_STRING
const
restrict
pattern
,
uint32_t
options
,
int
do_jit
,
VCL_STRING
const
restrict
pattern
,
uint32_t
options
,
int
do_jit
,
...
@@ -733,26 +774,12 @@ vmod_regex_match(VRT_CTX, struct vmod_pcre2_regex *regex,
...
@@ -733,26 +774,12 @@ vmod_regex_match(VRT_CTX, struct vmod_pcre2_regex *regex,
/* The match context and options are PRIV_CALL-scoped. */
/* The match context and options are PRIV_CALL-scoped. */
/* XXX param to decide whether these should be saved for the call */
/* XXX param to decide whether these should be saved for the call */
if
(
priv_call
->
priv
==
NULL
)
{
match_opts
=
get_match_opts
(
ctx
,
priv_call
,
MATCH_CTX_PARAMS
,
pcre2_match_context
*
mctx
;
MATCH_FLAGS_PARAMS
,
regex
->
vcl_name
,
".match()"
);
if
((
mctx
=
get_match_context
(
ctx
,
MATCH_CTX_PARAMS
,
if
(
match_opts
==
NULL
)
regex
->
vcl_name
,
".match()"
))
==
NULL
)
return
0
;
return
0
;
ALLOC_OBJ
(
match_opts
,
VMOD_PCRE2_MATCH_CALL_MAGIC
);
AN
(
match_opts
);
match_opts
->
mctx
=
mctx
;
priv_call
->
priv
=
match_opts
;
priv_call
->
free
=
match_call_free
;
set_match_flags
(
&
match_opts
->
match_options
,
MATCH_FLAGS_PARAMS
);
}
else
CAST_OBJ
(
match_opts
,
priv_call
->
priv
,
VMOD_PCRE2_MATCH_CALL_MAGIC
);
/* The match data block is task-scoped for this object only. */
/* The match data block is task-scoped for this object only. */
obj_task
=
VRT_priv_task
(
ctx
,
regex
);
obj_task
=
VRT_priv_task
(
ctx
,
regex
);
AN
(
obj_task
);
AN
(
obj_task
);
...
@@ -836,33 +863,11 @@ vmod_regex_sub(VRT_CTX, struct vmod_pcre2_regex *regex,
...
@@ -836,33 +863,11 @@ vmod_regex_sub(VRT_CTX, struct vmod_pcre2_regex *regex,
return
NULL
;
return
NULL
;
}
}
if
(
priv_call
->
priv
==
NULL
)
{
match_opts
=
get_match_opts
(
ctx
,
priv_call
,
MATCH_CTX_PARAMS
,
pcre2_match_context
*
mctx
;
MATCH_SUB_FLAGS_PARAMS
,
regex
->
vcl_name
,
".match()"
);
if
((
mctx
=
get_match_context
(
ctx
,
MATCH_CTX_PARAMS
,
if
(
match_opts
==
NULL
)
regex
->
vcl_name
,
".sub()"
))
return
0
;
==
NULL
)
return
NULL
;
ALLOC_OBJ
(
match_opts
,
VMOD_PCRE2_MATCH_CALL_MAGIC
);
AN
(
match_opts
);
match_opts
->
mctx
=
mctx
;
priv_call
->
priv
=
match_opts
;
priv_call
->
free
=
match_call_free
;
set_match_flags
(
&
match_opts
->
match_options
,
MATCH_FLAGS_PARAMS
);
set_opt
(
&
match_opts
->
match_options
,
suball
,
PCRE2_SUBSTITUTE_GLOBAL
);
set_opt
(
&
match_opts
->
match_options
,
sub_extended
,
PCRE2_SUBSTITUTE_EXTENDED
);
set_opt
(
&
match_opts
->
match_options
,
unknown_unset
,
PCRE2_SUBSTITUTE_UNKNOWN_UNSET
);
set_opt
(
&
match_opts
->
match_options
,
unset_empty
,
PCRE2_SUBSTITUTE_UNSET_EMPTY
);
}
else
CAST_OBJ
(
match_opts
,
priv_call
->
priv
,
VMOD_PCRE2_MATCH_CALL_MAGIC
);
/* XXX mdata in PRIV_CALL? */
/* XXX mdata in PRIV_CALL? */
if
((
match_task
=
get_task
(
ctx
,
priv_task
,
regex
->
vcl_name
,
".sub()"
))
if
((
match_task
=
get_task
(
ctx
,
priv_task
,
regex
->
vcl_name
,
".sub()"
))
...
...
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