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
c378fa6f
Commit
c378fa6f
authored
Feb 24, 2017
by
Geoff Simmons
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
more reduction of code repetition
parent
2b7b320c
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
67 additions
and
103 deletions
+67
-103
vmod_pcre2.c
src/vmod_pcre2.c
+67
-103
No files found.
src/vmod_pcre2.c
View file @
c378fa6f
...
...
@@ -57,6 +57,23 @@
#define INIT(ctx) (((ctx)->method & VCL_MET_INIT) != 0)
#define SET_OPT(lval, opt, PCRE2_OPT) \
do { if (opt) (lval) |= (PCRE2_OPT); } while(0)
#define SET_CTX_PARAM(ctx, param, type) do { \
if ((param) != 0) AZ(pcre2_set_##param((ctx), (type)(param))); \
} while(0)
#define CHECK_UINT32_RANGE(limit, vcl_name, caller, ret) \
do { \
if ((limit) < 0 || (limit) > UINT32_MAX) { \
VERR(ctx, #limit " (%lld) out of range in %s" \
caller " (must be >= 0 and <= %" PRIu32 ")", \
(long long)(limit), (vcl_name), UINT32_MAX); \
return ret; \
} \
} while(0)
struct
vmod_pcre2_regex
{
unsigned
magic
;
#define VMOD_PCRE2_REGEX_MAGIC 0x3adb2a78
...
...
@@ -156,7 +173,7 @@ vmod_regex__init(VRT_CTX, struct vmod_pcre2_regex **regexp,
VCL_BOOL
alt_verbnames
,
VCL_BOOL
caseless
,
VCL_BOOL
dollar_endonly
,
VCL_BOOL
dotall
,
VCL_BOOL
dupnames
,
VCL_BOOL
extended
,
VCL_BOOL
firstline
,
VCL_STRING
locale
,
VCL_BOOL
match_unset_backref
,
VCL_INT
max_pattern_len
,
VCL_BOOL
match_unset_backref
,
VCL_INT
max_pattern_len
gth
,
VCL_BOOL
multiline
,
VCL_BOOL
never_backslash_c
,
VCL_BOOL
never_ucp
,
VCL_BOOL
never_utf
,
VCL_ENUM
newlines
,
VCL_BOOL
no_auto_capture
,
VCL_BOOL
no_auto_possess
,
...
...
@@ -190,70 +207,42 @@ vmod_regex__init(VRT_CTX, struct vmod_pcre2_regex **regexp,
* to assume that max_pattern_len can never be too large.
*/
assert
(
sizeof
(
VCL_INT
)
<=
sizeof
(
PCRE2_SIZE
));
if
(
max_pattern_len
<
0
)
{
if
(
max_pattern_len
gth
<
0
)
{
VERR
(
ctx
,
"max_pattern_len (%lld) must be >= 0 in %s "
"constructor"
,
(
long
long
)
max_pattern_len
,
vcl_name
);
return
;
}
if
(
parens_nest_limit
<
0
||
parens_nest_limit
>
UINT32_MAX
)
{
VERR
(
ctx
,
"parens_nest_limit (%lld) out of range in %s "
"constructor (must be >= 0 and <= %"
PRIu32
")"
,
(
long
long
)
parens_nest_limit
,
vcl_name
,
UINT32_MAX
);
"constructor"
,
(
long
long
)
max_pattern_length
,
vcl_name
);
return
;
}
CHECK_UINT32_RANGE
(
parens_nest_limit
,
vcl_name
,
" constructor"
,);
/* XXX check illegal combinations such as never_ucp && ucp ... ? */
if
(
anchored
)
options
|=
PCRE2_ANCHORED
;
if
(
allow_empty_class
)
options
|=
PCRE2_ALLOW_EMPTY_CLASS
;
if
(
alt_bsux
)
options
|=
PCRE2_ALT_BSUX
;
if
(
alt_circumflex
)
options
|=
PCRE2_ALT_CIRCUMFLEX
;
if
(
alt_verbnames
)
options
|=
PCRE2_ALT_VERBNAMES
;
if
(
caseless
)
options
|=
PCRE2_CASELESS
;
if
(
dollar_endonly
)
options
|=
PCRE2_DOLLAR_ENDONLY
;
if
(
dotall
)
options
|=
PCRE2_DOTALL
;
if
(
dupnames
)
options
|=
PCRE2_DUPNAMES
;
if
(
extended
)
options
|=
PCRE2_EXTENDED
;
if
(
firstline
)
options
|=
PCRE2_FIRSTLINE
;
if
(
match_unset_backref
)
options
|=
PCRE2_MATCH_UNSET_BACKREF
;
if
(
multiline
)
options
|=
PCRE2_MULTILINE
;
if
(
never_backslash_c
)
options
|=
PCRE2_NEVER_BACKSLASH_C
;
if
(
never_ucp
)
options
|=
PCRE2_NEVER_UCP
;
if
(
never_utf
)
options
|=
PCRE2_NEVER_UTF
;
if
(
no_auto_capture
)
options
|=
PCRE2_NO_AUTO_CAPTURE
;
if
(
no_auto_possess
)
options
|=
PCRE2_NO_AUTO_POSSESS
;
if
(
no_dotstar_anchor
)
options
|=
PCRE2_NO_DOTSTAR_ANCHOR
;
if
(
no_start_optimize
)
options
|=
PCRE2_NO_START_OPTIMIZE
;
if
(
no_utf_check
)
options
|=
PCRE2_NO_UTF_CHECK
;
if
(
ucp
)
options
|=
PCRE2_UCP
;
if
(
ungreedy
)
options
|=
PCRE2_UNGREEDY
;
if
(
use_offset_limit
)
options
|=
PCRE2_USE_OFFSET_LIMIT
;
if
(
utf
)
options
|=
PCRE2_UTF
;
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
);
SET_CTX_PARAM
(
ccontext
,
max_pattern_length
,
PCRE2_SIZE
);
SET_CTX_PARAM
(
ccontext
,
parens_nest_limit
,
uint32_t
);
if
(
bsrs
!=
NULL
)
{
if
(
strcmp
(
"ANYCRLF"
,
bsrs
)
==
0
)
val
=
PCRE2_BSR_ANYCRLF
;
...
...
@@ -284,9 +273,6 @@ vmod_regex__init(VRT_CTX, struct vmod_pcre2_regex **regexp,
AZ
(
pcre2_set_character_tables
(
ccontext
,
tables
));
AN
(
setlocale
(
LC_CTYPE
,
saved_lc
));
}
if
(
max_pattern_len
!=
0
)
AZ
(
pcre2_set_max_pattern_length
(
ccontext
,
(
PCRE2_SIZE
)
max_pattern_len
));
if
(
newlines
!=
NULL
)
{
if
(
strcmp
(
"CR"
,
newlines
)
==
0
)
val
=
PCRE2_NEWLINE_CR
;
...
...
@@ -302,9 +288,6 @@ vmod_regex__init(VRT_CTX, struct vmod_pcre2_regex **regexp,
WRONG
(
"Illegal newline enum value"
);
AZ
(
pcre2_set_newline
(
ccontext
,
val
));
}
if
(
parens_nest_limit
!=
0
)
AZ
(
pcre2_set_parens_nest_limit
(
ccontext
,
(
uint32_t
)
parens_nest_limit
));
/* XXX set the length via parameter */
code
=
pcre2_compile
((
PCRE2_SPTR
)
pattern
,
PCRE2_ZERO_TERMINATED
,
...
...
@@ -434,7 +417,7 @@ vmod_regex_match(VRT_CTX, struct vmod_pcre2_regex *regex,
else
{
/*
* pcre2_general_context is declared as an incomplete
* type, so we can't check if it
'
s full size is allocated.
* type, so we can't check if its full size is allocated.
*/
WS_Assert_Allocated
(
ctx
->
ws
,
gctx_task
->
priv
,
0
);
gctx
=
gctx_task
->
priv
;
...
...
@@ -445,34 +428,21 @@ vmod_regex_match(VRT_CTX, struct vmod_pcre2_regex *regex,
if
(
mctx_call
->
priv
==
NULL
)
{
pcre2_match_context
*
mctx
;
#define CHECK_RANGE(limit) do { \
if ((limit) < 0 || (limit) > UINT32_MAX) { \
VERR(ctx, #limit " (%lld) out of range in " \
"%s.match() (must be >= 0 and <= %" \
PRIu32 ")", (long long)(limit), \
regex->vcl_name, UINT32_MAX); \
return 0; \
} \
} while(0)
CHECK_RANGE
(
match_limit
);
CHECK_RANGE
(
offset_limit
);
CHECK_RANGE
(
recursion_limit
);
#undef CHECK_RANGE
CHECK_UINT32_RANGE
(
match_limit
,
regex
->
vcl_name
,
".match()"
,
0
);
CHECK_UINT32_RANGE
(
offset_limit
,
regex
->
vcl_name
,
".match()"
,
0
);
CHECK_UINT32_RANGE
(
recursion_limit
,
regex
->
vcl_name
,
".match()"
,
0
);
if
((
mctx
=
pcre2_match_context_create
(
NULL
))
==
NULL
)
{
VERRNOMEM
(
ctx
,
"creating match context in %s.match()"
,
regex
->
vcl_name
);
return
0
;
}
if
(
match_limit
!=
0
)
AZ
(
pcre2_set_match_limit
(
mctx
,
(
uint32_t
)
match_limit
));
if
(
offset_limit
!=
0
)
AZ
(
pcre2_set_offset_limit
(
mctx
,
(
uint32_t
)
offset_limit
));
if
(
recursion_limit
!=
0
)
AZ
(
pcre2_set_recursion_limit
(
mctx
,
(
uint32_t
)
recursion_limit
));
SET_CTX_PARAM
(
mctx
,
match_limit
,
uint32_t
);
SET_CTX_PARAM
(
mctx
,
offset_limit
,
uint32_t
);
SET_CTX_PARAM
(
mctx
,
recursion_limit
,
uint32_t
);
ALLOC_OBJ
(
match_opts
,
VMOD_PCRE2_MATCH_CALL_MAGIC
);
AN
(
match_opts
);
...
...
@@ -480,20 +450,14 @@ vmod_regex_match(VRT_CTX, struct vmod_pcre2_regex *regex,
mctx_call
->
priv
=
match_opts
;
mctx_call
->
free
=
match_call_free
;
if
(
anchored
)
match_opts
->
options
|=
PCRE2_ANCHORED
;
if
(
notbol
)
match_opts
->
options
|=
PCRE2_NOTBOL
;
if
(
noteol
)
match_opts
->
options
|=
PCRE2_NOTEOL
;
if
(
notempty
)
match_opts
->
options
|=
PCRE2_NOTEMPTY
;
if
(
notempty_atstart
)
match_opts
->
options
|=
PCRE2_NOTEMPTY_ATSTART
;
if
(
no_jit
)
match_opts
->
options
|=
PCRE2_NO_JIT
;
if
(
no_utf_check
)
match_opts
->
options
|=
PCRE2_NO_UTF_CHECK
;
SET_OPT
(
match_opts
->
options
,
anchored
,
PCRE2_ANCHORED
);
SET_OPT
(
match_opts
->
options
,
notbol
,
PCRE2_NOTBOL
);
SET_OPT
(
match_opts
->
options
,
noteol
,
PCRE2_NOTEOL
);
SET_OPT
(
match_opts
->
options
,
notempty
,
PCRE2_NOTEMPTY
);
SET_OPT
(
match_opts
->
options
,
notempty_atstart
,
PCRE2_NOTEMPTY_ATSTART
);
SET_OPT
(
match_opts
->
options
,
no_jit
,
PCRE2_NO_JIT
);
SET_OPT
(
match_opts
->
options
,
no_utf_check
,
PCRE2_NO_UTF_CHECK
);
if
(
partials
!=
NULL
)
{
VERR
(
ctx
,
...
...
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