@@ -22,13 +22,13 @@ static int doLog(const char * fmt, ...);
22
22
*/
23
23
static int parseLine (char * const line , ConfigBlock * * cur_block ,
24
24
const ConfigBlock * const default_block ,
25
- pcre * const re_newblock , pcre * const re_newstmt ,
26
- pcre * const re_comment , pcre * const re_null )
25
+ pcre2_code * const re_newblock , pcre2_code * const re_newstmt ,
26
+ pcre2_code * const re_comment , pcre2_code * const re_null )
27
27
{
28
- int ovector [ 16 ] ;
29
- pcre * new_regex ;
30
- const char * keyword ;
31
- const char * value ;
28
+ pcre2_match_data * match_data = pcre2_match_data_create ( 16 , NULL ) ;
29
+ pcre2_code * new_regex ;
30
+ char * keyword ;
31
+ char * value ;
32
32
int line_size ;
33
33
int stcount ;
34
34
@@ -41,14 +41,14 @@ static int parseLine(char * const line, ConfigBlock **cur_block,
41
41
}
42
42
line [-- line_size ] = 0 ;
43
43
}
44
- if (pcre_exec (re_null , NULL , line , line_size ,
45
- 0 , 0 , ovector , ARRAY_SIZE ( ovector ) ) >= 0 ||
46
- pcre_exec (re_comment , NULL , line , line_size ,
47
- 0 , 0 , ovector , ARRAY_SIZE ( ovector ) ) >= 0 ) {
44
+ if (pcre2_match (re_null , ( PCRE2_SPTR ) line , ( PCRE2_SIZE ) line_size ,
45
+ 0 , 0 , match_data , NULL ) >= 0 ||
46
+ pcre2_match (re_comment , ( PCRE2_SPTR ) line , ( PCRE2_SIZE ) line_size ,
47
+ 0 , 0 , match_data , NULL ) >= 0 ) {
48
48
return 0 ;
49
49
}
50
- if (pcre_exec (re_newblock , NULL , line , line_size ,
51
- 0 , 0 , ovector , ARRAY_SIZE ( ovector ) ) >= 0 ) {
50
+ if (pcre2_match (re_newblock , ( PCRE2_SPTR ) line , ( PCRE2_SIZE ) line_size ,
51
+ 0 , 0 , match_data , NULL ) >= 0 ) {
52
52
ConfigBlock * previous_block = * cur_block ;
53
53
54
54
if ((* cur_block = wmalloc (sizeof * * cur_block )) == NULL )
@@ -62,10 +62,11 @@ static int parseLine(char * const line, ConfigBlock **cur_block,
62
62
return 0 ;
63
63
}
64
64
if ((stcount =
65
- pcre_exec (re_newstmt , NULL , line , line_size ,
66
- 0 , 0 , ovector , ARRAY_SIZE (ovector ))) >= 3 ) {
67
- pcre_get_substring (line , ovector , stcount , 1 , & keyword );
68
- pcre_get_substring (line , ovector , stcount , 2 , & value );
65
+ pcre2_match (re_newstmt , (PCRE2_SPTR )line , (PCRE2_SIZE )line_size ,
66
+ 0 , 0 , match_data , NULL )) >= 3 ) {
67
+ PCRE2_SIZE len ;
68
+ pcre2_substring_get_bynumber (match_data , 1 , (PCRE2_UCHAR * * )& keyword , & len );
69
+ pcre2_substring_get_bynumber (match_data , 2 , (PCRE2_UCHAR * * )& value , & len );
69
70
if (strcasecmp (keyword , "minimum" ) == 0 ) {
70
71
(* cur_block )-> minimum = atoi (value );
71
72
} else if (strcasecmp (keyword , "maximum" ) == 0 ) {
@@ -112,12 +113,11 @@ static int parseLine(char * const line, ConfigBlock **cur_block,
112
113
return -3 ;
113
114
}
114
115
(* cur_block )-> regexeswithsign = new_regexeswithsign ;
115
- if ((new_regex = wpcre_compile (regex , PCRE_CASELESS )) == NULL ) {
116
+ if ((new_regex = wpcre2_compile (regex , PCRE2_CASELESS )) == NULL ) {
116
117
free (regex );
117
118
return -5 ;
118
119
}
119
120
else {
120
- const char * errptr ;
121
121
RegexWithSign * const this_regex =
122
122
& ((* cur_block )-> regexeswithsign [(* cur_block )-> nb_regexes ]);
123
123
@@ -127,9 +127,7 @@ static int parseLine(char * const line, ConfigBlock **cur_block,
127
127
} else {
128
128
this_regex -> sign = REGEX_SIGN_POSITIVE ;
129
129
}
130
- this_regex -> regex .pcre = new_regex ;
131
- this_regex -> regex .pcre_extra =
132
- pcre_study (new_regex , 0 , & errptr );
130
+ this_regex -> regex = new_regex ;
133
131
}
134
132
(* cur_block )-> nb_regexes ++ ;
135
133
} else if (strcasecmp (keyword , "program_regex" ) == 0 ||
@@ -148,12 +146,11 @@ static int parseLine(char * const line, ConfigBlock **cur_block,
148
146
return -3 ;
149
147
}
150
148
(* cur_block )-> program_regexeswithsign = new_regexeswithsign ;
151
- if ((new_regex = wpcre_compile (regex , PCRE_CASELESS )) == NULL ) {
149
+ if ((new_regex = wpcre2_compile (regex , PCRE2_CASELESS )) == NULL ) {
152
150
free (regex );
153
151
return -5 ;
154
152
}
155
153
else {
156
- const char * errptr ;
157
154
free (regex );
158
155
RegexWithSign * const this_regex =
159
156
& ((* cur_block )-> program_regexeswithsign
@@ -164,9 +161,7 @@ static int parseLine(char * const line, ConfigBlock **cur_block,
164
161
} else {
165
162
this_regex -> sign = REGEX_SIGN_POSITIVE ;
166
163
}
167
- this_regex -> regex .pcre = new_regex ;
168
- this_regex -> regex .pcre_extra =
169
- pcre_study (new_regex , 0 , & errptr );
164
+ this_regex -> regex = new_regex ;
170
165
}
171
166
(* cur_block )-> program_nb_regexes ++ ;
172
167
} else if (strcasecmp (keyword , "maxsize" ) == 0 ) {
@@ -336,18 +331,21 @@ static int parseLine(char * const line, ConfigBlock **cur_block,
336
331
}
337
332
} else
338
333
err ("Unknown keyword '%s'! line: %s" , keyword , line );
334
+ pcre2_substring_free ((PCRE2_UCHAR * )keyword );
335
+ pcre2_substring_free ((PCRE2_UCHAR * )value );
339
336
}
337
+ pcre2_match_data_free (match_data );
340
338
return 0 ;
341
339
}
342
340
343
341
static int configParser (const char * const file )
344
342
{
345
343
char line [LINE_MAX ];
346
344
FILE * fp ;
347
- pcre * re_newblock ;
348
- pcre * re_newstmt ;
349
- pcre * re_comment ;
350
- pcre * re_null ;
345
+ pcre2_code * re_newblock ;
346
+ pcre2_code * re_newstmt ;
347
+ pcre2_code * re_comment ;
348
+ pcre2_code * re_null ;
351
349
int retcode = 0 ;
352
350
ConfigBlock default_block = {
353
351
DEFAULT_MINIMUM , /* minimum */
@@ -381,10 +379,10 @@ static int configParser(const char * const file)
381
379
warnp ("Can't open the configuration file" );
382
380
return -2 ;
383
381
}
384
- re_newblock = wpcre_compile (":\\s*$" , 0 );
385
- re_newstmt = wpcre_compile ("^\\s*(.+?)\\s*=\\s*\"?([^\"]*)\"?\\s*$" , 0 );
386
- re_comment = wpcre_compile ("^\\s*#" , 0 );
387
- re_null = wpcre_compile ("^\\s*$" , 0 );
382
+ re_newblock = wpcre2_compile (":\\s*$" , 0 );
383
+ re_newstmt = wpcre2_compile ("^\\s*(.+?)\\s*=\\s*\"?([^\"]*)\"?\\s*$" , 0 );
384
+ re_comment = wpcre2_compile ("^\\s*#" , 0 );
385
+ re_null = wpcre2_compile ("^\\s*$" , 0 );
388
386
if (!re_newblock || !re_newstmt || !re_comment || !re_null ) {
389
387
retcode = -1 ;
390
388
goto rtn ;
@@ -398,16 +396,16 @@ static int configParser(const char * const file)
398
396
}
399
397
rtn :
400
398
if (re_newblock != NULL ) {
401
- pcre_free (re_newblock );
399
+ pcre2_code_free (re_newblock );
402
400
}
403
401
if (re_newstmt != NULL ) {
404
- pcre_free (re_newstmt );
402
+ pcre2_code_free (re_newstmt );
405
403
}
406
404
if (re_comment != NULL ) {
407
- pcre_free (re_comment );
405
+ pcre2_code_free (re_comment );
408
406
}
409
407
if (re_null != NULL ) {
410
- pcre_free (re_null );
408
+ pcre2_code_free (re_null );
411
409
}
412
410
fclose (fp );
413
411
@@ -1146,7 +1144,7 @@ static int log_stdout(const char * const date,
1146
1144
static int processLogLine (const int logcode ,
1147
1145
const char * const prg , char * const info )
1148
1146
{
1149
- int ovector [ 16 ] ;
1147
+ pcre2_match_data * match_data = pcre2_match_data_create ( 16 , NULL ) ;
1150
1148
ConfigBlock * block = config_blocks ;
1151
1149
RegexWithSign * this_regex ;
1152
1150
const int facility = LOG_FAC (logcode );
@@ -1184,17 +1182,15 @@ static int processLogLine(const int logcode,
1184
1182
this_regex = block -> program_regexeswithsign ;
1185
1183
do {
1186
1184
if (this_regex -> sign == REGEX_SIGN_POSITIVE ) {
1187
- if (pcre_exec (this_regex -> regex .pcre ,
1188
- this_regex -> regex .pcre_extra ,
1189
- prg , prg_len , 0 , 0 , ovector ,
1190
- ARRAY_SIZE (ovector )) >= 0 ) {
1185
+ if (pcre2_match (this_regex -> regex ,
1186
+ (PCRE2_SPTR )prg , (PCRE2_SIZE )prg_len ,
1187
+ 0 , 0 , match_data , NULL ) >= 0 ) {
1191
1188
regex_result = 1 ;
1192
1189
}
1193
1190
} else {
1194
- if (pcre_exec (this_regex -> regex .pcre ,
1195
- this_regex -> regex .pcre_extra ,
1196
- prg , prg_len , 0 , 0 , ovector ,
1197
- ARRAY_SIZE (ovector )) < 0 ) {
1191
+ if (pcre2_match (this_regex -> regex ,
1192
+ (PCRE2_SPTR )prg , (PCRE2_SIZE )prg_len ,
1193
+ 0 , 0 , match_data , NULL ) < 0 ) {
1198
1194
regex_result = 1 ;
1199
1195
}
1200
1196
}
@@ -1213,17 +1209,15 @@ static int processLogLine(const int logcode,
1213
1209
this_regex = block -> regexeswithsign ;
1214
1210
do {
1215
1211
if (this_regex -> sign == REGEX_SIGN_POSITIVE ) {
1216
- if (pcre_exec (this_regex -> regex .pcre ,
1217
- this_regex -> regex .pcre_extra ,
1218
- info , info_len , 0 , 0 , ovector ,
1219
- ARRAY_SIZE (ovector )) >= 0 ) {
1212
+ if (pcre2_match (this_regex -> regex ,
1213
+ (PCRE2_SPTR )info , (PCRE2_SIZE )info_len ,
1214
+ 0 , 0 , match_data , NULL ) >= 0 ) {
1220
1215
regex_result = 1 ;
1221
1216
}
1222
1217
} else {
1223
- if (pcre_exec (this_regex -> regex .pcre ,
1224
- this_regex -> regex .pcre_extra ,
1225
- info , info_len , 0 , 0 , ovector ,
1226
- ARRAY_SIZE (ovector )) < 0 ) {
1218
+ if (pcre2_match (this_regex -> regex ,
1219
+ (PCRE2_SPTR )info , (PCRE2_SIZE )info_len ,
1220
+ 0 , 0 , match_data , NULL ) < 0 ) {
1227
1221
regex_result = 1 ;
1228
1222
}
1229
1223
}
@@ -1274,6 +1268,7 @@ static int processLogLine(const int logcode,
1274
1268
block = block -> next_block ;
1275
1269
}
1276
1270
1271
+ pcre2_match_data_free (match_data );
1277
1272
return 0 ;
1278
1273
}
1279
1274
0 commit comments