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
4d9878cb
Commit
4d9878cb
authored
Jun 30, 2017
by
Geoff Simmons
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add the info_str() method.
parent
645789a2
Pipeline
#266
skipped
Changes
4
Pipelines
1
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
288 additions
and
41 deletions
+288
-41
README.rst
README.rst
+9
-0
info.c
src/info.c
+110
-0
info.vtc
src/tests/info.vtc
+166
-41
vmod_pcre2.vcc
src/vmod_pcre2.vcc
+3
-0
No files found.
README.rst
View file @
4d9878cb
...
...
@@ -112,6 +112,15 @@ regex.info_int
INT regex.info_int(ENUM {BACKREFMAX,CAPTURECOUNT,JITSIZE,MATCHLIMIT,MAXLOOKBEHIND,MINLENGTH,RECURSIONLIMIT,SIZE})
.. _func_regex.info_str:
regex.info_str
--------------
::
STRING regex.info_str(ENUM {BSR,FIRSTCODEUNIT,FIRSTCODEUNITS,LASTCODEUNIT,NEWLINE}, STRING sep=" ")
.. _func_match:
match
...
...
src/info.c
View file @
4d9878cb
...
...
@@ -25,6 +25,8 @@
*
*/
#include <stdio.h>
#include "vmod_pcre2.h"
#include "vcc_if.h"
...
...
@@ -217,3 +219,111 @@ vmod_regex_info_int(VRT_CTX, struct vmod_pcre2_regex *regex, VCL_ENUM ints)
AZ
(
ret
);
return
where
;
}
VCL_STRING
vmod_regex_info_str
(
VRT_CTX
,
struct
vmod_pcre2_regex
*
regex
,
VCL_ENUM
strs
,
VCL_STRING
sep
)
{
uint32_t
what
,
where
;
int
ret
;
char
*
str
;
CHECK_OBJ_NOTNULL
(
ctx
,
VRT_CTX_MAGIC
);
CHECK_OBJ_NOTNULL
(
regex
,
VMOD_PCRE2_REGEX_MAGIC
);
if
(
sep
==
NULL
)
{
VERR
(
ctx
,
"sep is undefined in %s.info_str()"
,
regex
->
vcl_name
);
return
NULL
;
}
if
(
strcmp
(
strs
,
"BSR"
)
==
0
)
what
=
PCRE2_INFO_BSR
;
else
if
(
strcmp
(
strs
,
"FIRSTCODEUNIT"
)
==
0
)
what
=
PCRE2_INFO_FIRSTCODEUNIT
;
else
if
(
strcmp
(
strs
,
"FIRSTCODEUNITS"
)
==
0
)
what
=
PCRE2_INFO_FIRSTBITMAP
;
else
if
(
strcmp
(
strs
,
"LASTCODEUNIT"
)
==
0
)
what
=
PCRE2_INFO_LASTCODEUNIT
;
else
if
(
strcmp
(
strs
,
"NEWLINE"
)
==
0
)
what
=
PCRE2_INFO_NEWLINE
;
else
WRONG
(
"illegal enum in info_str"
);
if
(
what
==
PCRE2_INFO_FIRSTBITMAP
)
{
unsigned
bytes
;
int
ctr
,
len
;
const
uint8_t
*
map
;
char
*
p
;
ret
=
pcre2_pattern_info
(
regex
->
code
,
what
,
&
map
);
AZ
(
ret
);
if
(
map
==
NULL
)
return
""
;
str
=
WS_Front
(
ctx
->
ws
);
bytes
=
WS_Reserve
(
ctx
->
ws
,
0
);
if
(
bytes
==
0
)
goto
nomem
;
ctr
=
bytes
;
len
=
strlen
(
sep
);
p
=
str
;
for
(
int
i
=
1
;
i
<
256
;
i
++
)
if
(
map
[
i
>>
3
]
&
(
1
<<
(
i
&
7
)))
{
if
(
ctr
-
len
-
2
<
0
)
goto
nomem
;
sprintf
(
p
,
"%c%s"
,
(
uint8_t
)
i
,
sep
);
p
+=
len
+
1
;
ctr
-=
len
+
1
;
}
assert
(
ctr
>=
0
);
assert
((
unsigned
)
ctr
<
bytes
);
*
(
p
-
len
)
=
'\0'
;
WS_Release
(
ctx
->
ws
,
strlen
(
str
)
+
1
);
return
(
VCL_STRING
)
str
;
nomem:
VERRNOMEM
(
ctx
,
"allocating space for first code units in "
"%s.info_str()"
,
regex
->
vcl_name
);
WS_Release
(
ctx
->
ws
,
0
);
return
NULL
;
}
ret
=
pcre2_pattern_info
(
regex
->
code
,
what
,
&
where
);
AZ
(
ret
);
if
(
what
==
PCRE2_INFO_FIRSTCODEUNIT
||
what
==
PCRE2_INFO_LASTCODEUNIT
)
{
if
(
where
==
0
)
return
""
;
if
((
str
=
WS_Printf
(
ctx
->
ws
,
"%c"
,
where
))
==
NULL
)
{
VERRNOMEM
(
ctx
,
"allocating space for return string in "
"%s.info_str()"
,
regex
->
vcl_name
);
return
NULL
;
}
return
(
VCL_STRING
)
str
;
}
if
(
what
==
PCRE2_INFO_BSR
)
switch
(
where
)
{
case
PCRE2_BSR_UNICODE
:
return
(
"UNICODE"
);
case
PCRE2_BSR_ANYCRLF
:
return
(
"ANYCRLF"
);
default:
WRONG
(
"unexpected value returned for BSR"
);
}
assert
(
what
==
PCRE2_INFO_NEWLINE
);
switch
(
where
)
{
case
PCRE2_NEWLINE_CR
:
return
(
"CR"
);
case
PCRE2_NEWLINE_LF
:
return
(
"LF"
);
case
PCRE2_NEWLINE_CRLF
:
return
(
"CRLF"
);
case
PCRE2_NEWLINE_ANY
:
return
(
"ANY"
);
case
PCRE2_NEWLINE_ANYCRLF
:
return
(
"ANYCRLF"
);
default:
WRONG
(
"unexpected value returned for BSR"
);
}
}
src/tests/info.vtc
View file @
4d9878cb
This diff is collapsed.
Click to expand it.
src/vmod_pcre2.vcc
View file @
4d9878cb
...
...
@@ -66,6 +66,9 @@ $Method BOOL .info_bool(ENUM {ALLOW_EMPTY_CLASS, ANCHORED, ALT_BSUX,
$Method INT .info_int(ENUM {BACKREFMAX, CAPTURECOUNT, JITSIZE, MATCHLIMIT,
MAXLOOKBEHIND, MINLENGTH, RECURSIONLIMIT, SIZE})
$Method STRING .info_str(ENUM {BSR, FIRSTCODEUNIT, FIRSTCODEUNITS, LASTCODEUNIT,
NEWLINE}, STRING sep=" ")
$Function BOOL match(PRIV_CALL, PRIV_TASK, STRING pattern, STRING subject,
BOOL allow_empty_class=0, BOOL anchored=0,
ENUM {ANYCRLF, UNICODE} bsr=0, BOOL alt_bsux=0,
...
...
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