--- lbbs/src/bwf.c 2025/11/07 06:32:50 1.3 +++ lbbs/src/bwf.c 2025/12/18 02:56:00 1.7 @@ -6,6 +6,10 @@ * Copyright (C) 2004-2025 Leaflet */ +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + #define PCRE2_CODE_UNIT_WIDTH 8 #include "bwf.h" @@ -31,8 +35,6 @@ int bwf_load(const char *filename) size_t len_line; char *p = bwf_pattern_str; int line_id = 0; - int errorcode; - PCRE2_SIZE erroroffset; if (filename == NULL) { @@ -56,9 +58,15 @@ int bwf_load(const char *filename) return -3; } - if (line[len_line - 1] == '\n') + while (len_line > 0 && (line[len_line - 1] == '\n' || line[len_line - 1] == '\r')) { line[len_line - 1] = '\0'; + len_line--; + } + + if (len_line == 0) + { + continue; } if (p > bwf_pattern_str) @@ -83,23 +91,29 @@ int bwf_load(const char *filename) fclose(fp); -#ifdef _DEBUG - log_error("Debug: bwf_pattern_str: %s\n", bwf_pattern_str); -#endif + log_debug("Debug: bwf_pattern_str: %s\n", bwf_pattern_str); - bwf_unload(); + return 0; +} + +int bwf_compile(void) +{ + int errorcode; + PCRE2_SIZE erroroffset; + + bwf_cleanup(); bwf_code = pcre2_compile((PCRE2_SPTR)bwf_pattern_str, PCRE2_ZERO_TERMINATED, PCRE2_CASELESS, &errorcode, &erroroffset, NULL); if (bwf_code == NULL) { log_error("pcre2_compile() error: %d", errorcode); - return -4; + return -1; } return 0; } -void bwf_unload(void) +void bwf_cleanup(void) { if (bwf_code != NULL) { @@ -156,10 +170,8 @@ int check_badwords(char *str, char c_mas } else { -#ifdef _DEBUG - log_error("Debug: match pattern #%d of %d at offsets [%d, %d]\n", + log_debug("Debug: match pattern #%d of %d at offsets [%d, %d]\n", i, match_count, ovector[i * 2], ovector[i * 2 + 1] - ovector[i * 2]); -#endif memset(str + ovector[i * 2], c_mask, ovector[i * 2 + 1] - ovector[i * 2]); total_match_count++; startoffset = ovector[i * 2 + 1];