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
a403707a
Commit
a403707a
authored
Jun 29, 2017
by
Geoff Simmons
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Set up compile contexts and options flags in a single function.
parent
7ea83d5c
Pipeline
#260
skipped
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
55 additions
and
52 deletions
+55
-52
vmod_pcre2.c
src/vmod_pcre2.c
+55
-52
No files found.
src/vmod_pcre2.c
View file @
a403707a
...
...
@@ -316,10 +316,48 @@ match_call_free(void *priv)
FREE_OBJ
(
match_call
);
}
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_compile_flags
(
uint32_t
*
options
,
COMPILE_FLAGS
)
{
/* XXX check illegal combinations such as never_ucp && ucp ... ? */
set_opt
(
options
,
anchored
,
PCRE2_ANCHORED
);
set_opt
(
options
,
allow_empty_class
,
PCRE2_ALLOW_EMPTY_CLASS
);
set_opt
(
options
,
alt_bsux
,
PCRE2_ALT_BSUX
);
set_opt
(
options
,
alt_circumflex
,
PCRE2_ALT_CIRCUMFLEX
);
set_opt
(
options
,
alt_verbnames
,
PCRE2_ALT_VERBNAMES
);
set_opt
(
options
,
caseless
,
PCRE2_CASELESS
);
set_opt
(
options
,
dollar_endonly
,
PCRE2_DOLLAR_ENDONLY
);
set_opt
(
options
,
dotall
,
PCRE2_DOTALL
);
set_opt
(
options
,
dupnames
,
PCRE2_DUPNAMES
);
set_opt
(
options
,
extended
,
PCRE2_EXTENDED
);
set_opt
(
options
,
firstline
,
PCRE2_FIRSTLINE
);
set_opt
(
options
,
match_unset_backref
,
PCRE2_MATCH_UNSET_BACKREF
);
set_opt
(
options
,
multiline
,
PCRE2_MULTILINE
);
set_opt
(
options
,
never_backslash_c
,
PCRE2_NEVER_BACKSLASH_C
);
set_opt
(
options
,
never_ucp
,
PCRE2_NEVER_UCP
);
set_opt
(
options
,
never_utf
,
PCRE2_NEVER_UTF
);
set_opt
(
options
,
no_auto_capture
,
PCRE2_NO_AUTO_CAPTURE
);
set_opt
(
options
,
no_auto_possess
,
PCRE2_NO_AUTO_POSSESS
);
set_opt
(
options
,
no_dotstar_anchor
,
PCRE2_NO_DOTSTAR_ANCHOR
);
set_opt
(
options
,
no_start_optimize
,
PCRE2_NO_START_OPTIMIZE
);
set_opt
(
options
,
no_utf_check
,
PCRE2_NO_UTF_CHECK
);
set_opt
(
options
,
ucp
,
PCRE2_UCP
);
set_opt
(
options
,
ungreedy
,
PCRE2_UNGREEDY
);
set_opt
(
options
,
use_offset_limit
,
PCRE2_USE_OFFSET_LIMIT
);
set_opt
(
options
,
utf
,
PCRE2_UTF
);
}
static
pcre2_compile_context
*
get_compile_
context
(
VRT_CTX
,
COMPILE_CTX_OPTS
,
const
char
*
restrict
const
context
,
const
char
*
restrict
const
caller
)
get_compile_
opts
(
VRT_CTX
,
COMPILE_CTX_OPTS
,
COMPILE_FLAGS
,
uint32_t
*
options
,
const
char
*
restrict
const
context
,
const
char
*
restrict
const
caller
)
{
pcre2_compile_context
*
ccontext
;
uint32_t
val
;
...
...
@@ -384,6 +422,7 @@ get_compile_context(VRT_CTX, COMPILE_CTX_OPTS,
WRONG
(
"Illegal newline enum value"
);
AZ
(
pcre2_set_newline
(
ccontext
,
val
));
}
set_compile_flags
(
options
,
COMPILE_FLAGS_PARAMS
);
return
ccontext
;
}
...
...
@@ -414,13 +453,6 @@ get_match_context(VRT_CTX, MATCH_CTX_OPTS, const char * restrict const context,
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
)
{
...
...
@@ -514,37 +546,6 @@ get_task(VRT_CTX, struct vmod_priv *priv_task,
return
match_task
;
}
static
inline
void
set_compile_flags
(
uint32_t
*
options
,
COMPILE_FLAGS
)
{
/* XXX check illegal combinations such as never_ucp && ucp ... ? */
set_opt
(
options
,
anchored
,
PCRE2_ANCHORED
);
set_opt
(
options
,
allow_empty_class
,
PCRE2_ALLOW_EMPTY_CLASS
);
set_opt
(
options
,
alt_bsux
,
PCRE2_ALT_BSUX
);
set_opt
(
options
,
alt_circumflex
,
PCRE2_ALT_CIRCUMFLEX
);
set_opt
(
options
,
alt_verbnames
,
PCRE2_ALT_VERBNAMES
);
set_opt
(
options
,
caseless
,
PCRE2_CASELESS
);
set_opt
(
options
,
dollar_endonly
,
PCRE2_DOLLAR_ENDONLY
);
set_opt
(
options
,
dotall
,
PCRE2_DOTALL
);
set_opt
(
options
,
dupnames
,
PCRE2_DUPNAMES
);
set_opt
(
options
,
extended
,
PCRE2_EXTENDED
);
set_opt
(
options
,
firstline
,
PCRE2_FIRSTLINE
);
set_opt
(
options
,
match_unset_backref
,
PCRE2_MATCH_UNSET_BACKREF
);
set_opt
(
options
,
multiline
,
PCRE2_MULTILINE
);
set_opt
(
options
,
never_backslash_c
,
PCRE2_NEVER_BACKSLASH_C
);
set_opt
(
options
,
never_ucp
,
PCRE2_NEVER_UCP
);
set_opt
(
options
,
never_utf
,
PCRE2_NEVER_UTF
);
set_opt
(
options
,
no_auto_capture
,
PCRE2_NO_AUTO_CAPTURE
);
set_opt
(
options
,
no_auto_possess
,
PCRE2_NO_AUTO_POSSESS
);
set_opt
(
options
,
no_dotstar_anchor
,
PCRE2_NO_DOTSTAR_ANCHOR
);
set_opt
(
options
,
no_start_optimize
,
PCRE2_NO_START_OPTIMIZE
);
set_opt
(
options
,
no_utf_check
,
PCRE2_NO_UTF_CHECK
);
set_opt
(
options
,
ucp
,
PCRE2_UCP
);
set_opt
(
options
,
ungreedy
,
PCRE2_UNGREEDY
);
set_opt
(
options
,
use_offset_limit
,
PCRE2_USE_OFFSET_LIMIT
);
set_opt
(
options
,
utf
,
PCRE2_UTF
);
}
static
pcre2_code
*
compile
(
VRT_CTX
,
pcre2_compile_context
*
restrict
const
cctx
,
VCL_STRING
const
restrict
pattern
,
uint32_t
options
,
int
do_jit
,
...
...
@@ -782,10 +783,10 @@ vmod_regex__init(VRT_CTX, struct vmod_pcre2_regex **regexp,
VERR
(
ctx
,
"pattern is NULL in %s constructor"
,
vcl_name
);
return
;
}
if
((
ccontext
=
get_compile_context
(
ctx
,
COMPILE_CTX_PARAMS
,
vcl_name
,
" constructor"
))
==
NULL
)
if
((
ccontext
=
get_compile_opts
(
ctx
,
COMPILE_CTX_PARAMS
,
COMPILE_FLAGS_PARAMS
,
&
options
,
vcl_name
,
" constructor"
))
==
NULL
)
return
;
set_compile_flags
(
&
options
,
COMPILE_FLAGS_PARAMS
);
if
((
code
=
compile
(
ctx
,
ccontext
,
pattern
,
options
,
have_jit
,
vcl_name
,
" constructor"
))
==
NULL
)
...
...
@@ -954,12 +955,13 @@ vmod_match(VRT_CTX, struct vmod_priv *call, struct vmod_priv *task,
if
(
match_call
==
NULL
)
return
0
;
if
(
match_call
->
cctx
==
NULL
)
{
match_call
->
cctx
=
get_compile_context
(
ctx
,
COMPILE_CTX_PARAMS
,
"pcre2"
,
".match()"
);
match_call
->
cctx
=
get_compile_opts
(
ctx
,
COMPILE_CTX_PARAMS
,
COMPILE_FLAGS_PARAMS
,
&
match_call
->
compile_options
,
"pcre2"
,
".match()"
);
if
(
match_call
->
cctx
==
NULL
)
return
0
;
set_compile_flags
(
&
match_call
->
compile_options
,
COMPILE_FLAGS_PARAMS
);
}
if
((
code
=
compile
(
ctx
,
match_call
->
cctx
,
pattern
,
...
...
@@ -1058,12 +1060,13 @@ vmod_sub(VRT_CTX, struct vmod_priv *priv_call, struct vmod_priv *priv_task,
if
(
match_opts
==
NULL
)
return
0
;
if
(
match_opts
->
cctx
==
NULL
)
{
match_opts
->
cctx
=
get_compile_context
(
ctx
,
COMPILE_CTX_PARAMS
,
"pcre2"
,
".sub()"
);
match_opts
->
cctx
=
get_compile_opts
(
ctx
,
COMPILE_CTX_PARAMS
,
COMPILE_FLAGS_PARAMS
,
&
match_opts
->
compile_options
,
"pcre2"
,
".sub()"
);
if
(
match_opts
->
cctx
==
NULL
)
return
0
;
set_compile_flags
(
&
match_opts
->
compile_options
,
COMPILE_FLAGS_PARAMS
);
}
if
((
code
=
compile
(
ctx
,
match_opts
->
cctx
,
pattern
,
...
...
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