| 3 |
* bwf |
* bwf |
| 4 |
* - bad words filter |
* - bad words filter |
| 5 |
* |
* |
| 6 |
* Copyright (C) 2004-2025 Leaflet <leaflet@leafok.com> |
* Copyright (C) 2004-2026 Leaflet <leaflet@leafok.com> |
| 7 |
*/ |
*/ |
| 8 |
|
|
| 9 |
#ifdef HAVE_CONFIG_H |
#ifdef HAVE_CONFIG_H |
| 38 |
|
|
| 39 |
if (filename == NULL) |
if (filename == NULL) |
| 40 |
{ |
{ |
| 41 |
log_error("NULL pointer error\n"); |
log_error("NULL pointer error"); |
| 42 |
return -1; |
return -1; |
| 43 |
} |
} |
| 44 |
|
|
| 45 |
if ((fp = fopen(filename, "r")) == NULL) |
if ((fp = fopen(filename, "r")) == NULL) |
| 46 |
{ |
{ |
| 47 |
log_error("fopen(%s) error: %d\n", filename, errno); |
log_error("fopen(%s) error: %d", filename, errno); |
| 48 |
return -2; |
return -2; |
| 49 |
} |
} |
| 50 |
|
|
| 53 |
len_line = strnlen(line, sizeof(line) - 1); |
len_line = strnlen(line, sizeof(line) - 1); |
| 54 |
if (!feof(fp) && line[len_line - 1] != '\n') |
if (!feof(fp) && line[len_line - 1] != '\n') |
| 55 |
{ |
{ |
| 56 |
log_error("Data line %d (len=%d) is truncated\n", line_id, len_line); |
log_error("Data line %d (len=%d) is truncated", line_id, len_line); |
| 57 |
bwf_pattern_str[0] = '\0'; |
bwf_pattern_str[0] = '\0'; |
| 58 |
return -3; |
return -3; |
| 59 |
} |
} |
| 76 |
|
|
| 77 |
if (len_line + 2 > sizeof(bwf_pattern_str) - 1 - (size_t)(p - bwf_pattern_str)) |
if (len_line + 2 > sizeof(bwf_pattern_str) - 1 - (size_t)(p - bwf_pattern_str)) |
| 78 |
{ |
{ |
| 79 |
log_error("Data in %s exceed length limit %d\n", filename, sizeof(bwf_pattern_str) - 1); |
log_error("Data in %s exceed length limit %d", filename, sizeof(bwf_pattern_str) - 1); |
| 80 |
bwf_pattern_str[0] = '\0'; |
bwf_pattern_str[0] = '\0'; |
| 81 |
return -3; |
return -3; |
| 82 |
} |
} |
| 91 |
|
|
| 92 |
fclose(fp); |
fclose(fp); |
| 93 |
|
|
| 94 |
log_debug("Debug: bwf_pattern_str: %s\n", bwf_pattern_str); |
log_debug("Debug: bwf_pattern_str: %s", bwf_pattern_str); |
| 95 |
|
|
| 96 |
return 0; |
return 0; |
| 97 |
} |
} |
| 134 |
|
|
| 135 |
if (bwf_code == NULL) |
if (bwf_code == NULL) |
| 136 |
{ |
{ |
| 137 |
log_error("BWF not loaded\n"); |
log_error("BWF not loaded"); |
| 138 |
return -1; |
return -1; |
| 139 |
} |
} |
| 140 |
|
|
| 150 |
} |
} |
| 151 |
else if (ret < 0) |
else if (ret < 0) |
| 152 |
{ |
{ |
| 153 |
log_error("pcre2_match() error: %d\n", ret); |
log_error("pcre2_match() error: %d", ret); |
| 154 |
} |
} |
| 155 |
else if (ret == 0) |
else if (ret == 0) |
| 156 |
{ |
{ |
| 157 |
log_error("Vector of offsets is too small\n"); |
log_error("Vector of offsets is too small"); |
| 158 |
} |
} |
| 159 |
else // ret >= 1 |
else // ret >= 1 |
| 160 |
{ |
{ |
| 170 |
} |
} |
| 171 |
else |
else |
| 172 |
{ |
{ |
| 173 |
log_debug("Debug: match pattern #%d of %d at offsets [%d, %d]\n", |
log_debug("Debug: match pattern #%d of %d at offsets [%d, %d]", |
| 174 |
i, match_count, ovector[i * 2], ovector[i * 2 + 1] - ovector[i * 2]); |
i, match_count, ovector[i * 2], ovector[i * 2 + 1] - ovector[i * 2]); |
| 175 |
memset(str + ovector[i * 2], c_mask, ovector[i * 2 + 1] - ovector[i * 2]); |
memset(str + ovector[i * 2], c_mask, ovector[i * 2 + 1] - ovector[i * 2]); |
| 176 |
total_match_count++; |
total_match_count++; |