Changeset 588 for trunk/src/sh_log_parse_apache.c
- Timestamp:
- Oct 26, 2025, 12:17:47 PM (16 hours ago)
- File:
-
- 1 edited
-
trunk/src/sh_log_parse_apache.c (modified) (14 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/sh_log_parse_apache.c
r541 r588 28 28 #define FIL__ _("sh_log_parse_apache.c") 29 29 30 /* Debian/Ubuntu: libpcre3-dev */ 31 #ifdef HAVE_PCRE_PCRE_H 32 #include <pcre/pcre.h> 30 /* Debian/Ubuntu: libpcre2-dev */ 31 #define PCRE2_CODE_UNIT_WIDTH 8 32 #ifdef HAVE_PCRE2_PCRE2_H 33 #include <pcre2/pcre2.h> 33 34 #else 34 #include <pcre .h>35 #include <pcre2.h> 35 36 #endif 36 37 … … 44 45 45 46 struct sh_fileinfo_apache { 46 pcre * line_regex;47 int* line_ovector; /* captured substrings */48 int line_ovecnum; /* how many captured */47 pcre2_code * line_regex; 48 PCRE2_SIZE * line_ovector; /* captured substrings */ 49 int line_ovecnum; /* how many captured */ 49 50 50 51 int pos_host; … … 82 83 volatile int p_time = -1; 83 84 char * f_time = NULL; 84 const char *error;85 interroffset;85 int error; 86 size_t erroffset; 86 87 87 88 /* Take the address to keep gcc from putting them into registers. … … 261 262 262 263 result = SH_ALLOC(sizeof(struct sh_fileinfo_apache)); 263 result->line_regex = pcre _compile(sh_string_str(re_string), 0,264 result->line_regex = pcre2_compile((PCRE2_SPTR8)sh_string_str(re_string), sh_string_len(re_string), 0, 264 265 &error, &erroffset, NULL); 265 266 if (!(result->line_regex)) … … 285 286 sh_string_destroy(&re_string); 286 287 287 result->line_ovector = SH_ALLOC(sizeof(int) * (nfields+1) * 3);288 result->line_ovector = NULL; 288 289 result->line_ovecnum = nfields; 289 290 result->pos_host = p_host; … … 304 305 char tstr[128]; 305 306 char sstr[128]; 306 c onst char* hstr;307 char * hstr; 307 308 int res; 308 const char **hstr_addr = (const char **) &hstr; 309 unsigned char **hstr_addr = (unsigned char **) &hstr; 310 size_t hstr_len; 309 311 310 312 struct sh_fileinfo_apache * info = (struct sh_fileinfo_apache *) fileinfo; 311 313 314 pcre2_match_data * match_data = NULL; 315 312 316 if (sh_string_len(logline) > 0 && flag_err_debug == S_TRUE) 313 317 { … … 324 328 } 325 329 326 res = pcre_exec(info->line_regex, NULL, 327 sh_string_str(logline), (int)sh_string_len(logline), 0, 328 0, info->line_ovector, (3*(1+info->line_ovecnum))); 329 330 if (res == (1+info->line_ovecnum)) 330 match_data = pcre2_match_data_create_from_pattern(info->line_regex, NULL); 331 332 res = pcre2_match(info->line_regex, 333 (PCRE2_SPTR8)sh_string_str(logline), (int)sh_string_len(logline), 0, 334 0, match_data, NULL); 335 336 if (res == 1+info->line_ovecnum) /* successful match */ 331 337 { 332 338 struct sh_logrecord * record; 333 339 time_t timestamp = 0; 334 340 size_t size; 341 342 info->line_ovector = pcre2_get_ovector_pointer(match_data); 343 335 344 if (info->pos_time > 0) 336 345 { 337 res = pcre_copy_substring(sh_string_str(logline),338 info->line_ovector, res,339 info->pos_time, tstr, sizeof(tstr));340 if (res <= 0)346 size = sizeof(tstr); 347 res = pcre2_substring_copy_bynumber(match_data, info->pos_time, 348 (PCRE2_UCHAR8 *)tstr, &size); 349 if (res != 0) 341 350 goto corrupt; 342 351 } 343 352 else 344 353 { 345 res = 0;354 res = -1; 346 355 timestamp = 0; 347 356 info->format_time = sh_util_strdup(_("%d/%b/%Y:%T")); … … 349 358 } 350 359 351 if (res >0)360 if (res == 0) 352 361 { 353 362 struct tm btime; … … 371 380 if (info->pos_status > 0) 372 381 { 373 res = pcre_copy_substring(sh_string_str(logline),374 info->line_ovector, res,375 info->pos_status, sstr, sizeof(sstr));376 if (res <= 0)382 size = sizeof(sstr); 383 res = pcre2_substring_copy_bynumber(match_data, info->pos_status, 384 (PCRE2_UCHAR8 *)sstr, &size); 385 if (res != 0) 377 386 goto corrupt; 378 387 } … … 384 393 if (info->pos_host > 0) 385 394 { 386 res = pcre_get_substring(sh_string_str(logline), 387 info->line_ovector, res, 388 info->pos_host, hstr_addr); 389 if (res <= 0) 395 res = pcre2_substring_get_bynumber(match_data, info->pos_host, 396 hstr_addr, &hstr_len); 397 if (res != 0) 390 398 goto corrupt; 391 399 } … … 401 409 402 410 if (hstr) 403 record->host = sh_string_new_from_lchar(hstr, strlen(hstr));411 record->host = sh_string_new_from_lchar(hstr, hstr_len); 404 412 else 405 413 record->host = sh_string_new_from_lchar(sh.host.name, strlen(sh.host.name)); … … 409 417 record->pid = PID_INVALID; 410 418 411 pcre_free_substring(hstr); 419 /* does nothing if hstr == NULL */ 420 pcre2_substring_free((PCRE2_UCHAR8 *)hstr); 421 422 pcre2_match_data_free(match_data); 412 423 return record; 413 424 } … … 415 426 { 416 427 char msg[128]; 417 sl_snprintf(msg, sizeof(msg), _("Incorrect number of captured subexpressions: %d vs %d"), 418 res, info->line_ovecnum); 428 sl_snprintf(msg, sizeof(msg), _("Matching error: %d"), res); 419 429 420 430 SH_MUTEX_LOCK(mutex_thread_nolog); … … 440 450 sh_string_destroy(&msg); 441 451 } 452 pcre2_match_data_free(match_data); 442 453 return NULL; 443 454 }
Note:
See TracChangeset
for help on using the changeset viewer.