3131#include <apr_strings.h>
3232#include <math.h>
3333#include <sys/types.h>
34- #ifdef USE_PCRE
34+ #if defined(USE_PCRE2 )
35+ #include <pcre2.h>
36+ #elif defined(USE_PCRE )
3537#include <pcre.h>
3638#else
3739#include <regex.h>
@@ -51,7 +53,9 @@ struct mapcache_dimension_values {
5153struct mapcache_dimension_regex {
5254 mapcache_dimension dimension ;
5355 char * regex_string ;
54- #ifdef USE_PCRE
56+ #if defined(USE_PCRE2 )
57+ pcre2_code * pcregex ;
58+ #elif defined(USE_PCRE )
5559 pcre * pcregex ;
5660#else
5761 regex_t * regex ;
@@ -127,7 +131,13 @@ static apr_array_header_t* _mapcache_dimension_regex_get_entries_for_value(mapca
127131{
128132 mapcache_dimension_regex * dimension = (mapcache_dimension_regex * )dim ;
129133 apr_array_header_t * values = apr_array_make (ctx -> pool ,1 ,sizeof (char * ));
130- #ifdef USE_PCRE
134+ #if defined(USE_PCRE2 )
135+ pcre2_match_data * match_data ;
136+ int rc = pcre2_match (dimension -> pcregex ,(PCRE2_SPTR )value ,strlen (value ),0 ,0 ,match_data ,NULL );
137+ if (rc > 0 ) {
138+ APR_ARRAY_PUSH (values ,char * ) = apr_pstrdup (ctx -> pool ,value );
139+ }
140+ #elif defined(USE_PCRE )
131141 int ovector [30 ];
132142 int rc = pcre_exec (dimension -> pcregex ,NULL ,value ,strlen (value ),0 ,0 ,ovector ,30 );
133143 if (rc > 0 ) {
@@ -168,7 +178,18 @@ static void _mapcache_dimension_regex_parse_xml(mapcache_context *ctx, mapcache_
168178 ctx -> set_error (ctx ,400 ,"failed to parse %s regex: no <regex> child supplied" ,dim -> class_name );
169179 return ;
170180 }
171- #ifdef USE_PCRE
181+ #if defined(USE_PCRE2 )
182+ {
183+ int pcre_err ;
184+ PCRE2_SIZE * pcre_offset ;
185+ dimension -> pcregex = pcre2_compile ((PCRE2_SPTR8 )dimension -> regex_string ,strlen (dimension -> regex_string ), 0 , & pcre_err , pcre_offset , NULL );
186+ if (!dimension -> pcregex ) {
187+ ctx -> set_error (ctx ,400 ,"failed to compile regular expression \"%s\" for %s \"%s\": %d" ,
188+ dimension -> regex_string ,dim -> class_name ,dim -> name ,pcre_err );
189+ return ;
190+ }
191+ }
192+ #elif defined(USE_PCRE )
172193 {
173194 const char * pcre_err ;
174195 int pcre_offset ;
@@ -294,7 +315,7 @@ mapcache_dimension* mapcache_dimension_regex_create(mapcache_context *ctx, apr_p
294315 mapcache_dimension_regex * dimension = apr_pcalloc (pool , sizeof (mapcache_dimension_regex ));
295316 dimension -> dimension .type = MAPCACHE_DIMENSION_REGEX ;
296317 dimension -> dimension .class_name = "dimension" ;
297- #ifndef USE_PCRE
318+ #if !defined( USE_PCRE ) && !defined( USE_PCRE2 )
298319 dimension -> regex = (regex_t * )apr_pcalloc (pool , sizeof (regex_t ));
299320#endif
300321 dimension -> dimension ._get_entries_for_value = _mapcache_dimension_regex_get_entries_for_value ;
0 commit comments