| 56 |
return -3; |
return -3; |
| 57 |
} |
} |
| 58 |
|
|
| 59 |
if (line[len_line - 1] == '\n') |
while (len_line > 0 && (line[len_line - 1] == '\n' || line[len_line - 1] == '\r')) |
| 60 |
{ |
{ |
| 61 |
line[len_line - 1] = '\0'; |
line[len_line - 1] = '\0'; |
| 62 |
|
len_line--; |
| 63 |
|
} |
| 64 |
|
|
| 65 |
|
if (len_line == 0) |
| 66 |
|
{ |
| 67 |
|
continue; |
| 68 |
} |
} |
| 69 |
|
|
| 70 |
if (p > bwf_pattern_str) |
if (p > bwf_pattern_str) |
| 93 |
log_error("Debug: bwf_pattern_str: %s\n", bwf_pattern_str); |
log_error("Debug: bwf_pattern_str: %s\n", bwf_pattern_str); |
| 94 |
#endif |
#endif |
| 95 |
|
|
| 96 |
|
bwf_unload(); |
| 97 |
|
|
| 98 |
bwf_code = pcre2_compile((PCRE2_SPTR)bwf_pattern_str, PCRE2_ZERO_TERMINATED, PCRE2_CASELESS, &errorcode, &erroroffset, NULL); |
bwf_code = pcre2_compile((PCRE2_SPTR)bwf_pattern_str, PCRE2_ZERO_TERMINATED, PCRE2_CASELESS, &errorcode, &erroroffset, NULL); |
| 99 |
if (bwf_code == NULL) |
if (bwf_code == NULL) |
| 100 |
{ |
{ |
| 117 |
int check_badwords(char *str, char c_mask) |
int check_badwords(char *str, char c_mask) |
| 118 |
{ |
{ |
| 119 |
pcre2_match_data *match_data; |
pcre2_match_data *match_data; |
| 120 |
|
PCRE2_SIZE startoffset = 0; |
| 121 |
PCRE2_SIZE *ovector; |
PCRE2_SIZE *ovector; |
| 122 |
|
uint32_t match_count; |
| 123 |
int ret; |
int ret; |
| 124 |
int i; |
int i; |
| 125 |
|
int total_match_count = 0; |
| 126 |
|
|
| 127 |
if (bwf_code == NULL) |
if (bwf_code == NULL) |
| 128 |
{ |
{ |
| 132 |
|
|
| 133 |
match_data = pcre2_match_data_create_from_pattern(bwf_code, NULL); |
match_data = pcre2_match_data_create_from_pattern(bwf_code, NULL); |
| 134 |
|
|
| 135 |
ret = pcre2_match(bwf_code, (PCRE2_SPTR)str, PCRE2_ZERO_TERMINATED, 0, 0, match_data, NULL); |
while (1) |
|
if (ret == PCRE2_ERROR_NOMATCH) |
|
|
{ |
|
|
ret = 0; |
|
|
} |
|
|
else if (ret < 0) |
|
|
{ |
|
|
log_error("pcre2_match() error: %d\n", ret); |
|
|
} |
|
|
else if (ret == 0) |
|
| 136 |
{ |
{ |
| 137 |
log_error("Vector of offsets is too small\n"); |
ret = pcre2_match(bwf_code, (PCRE2_SPTR)str, PCRE2_ZERO_TERMINATED, startoffset, 0, match_data, NULL); |
| 138 |
} |
if (ret == PCRE2_ERROR_NOMATCH) |
| 139 |
else // ret >= 1 |
{ |
| 140 |
{ |
ret = total_match_count; |
| 141 |
ovector = pcre2_get_ovector_pointer(match_data); |
break; |
| 142 |
i = ret - 1; |
} |
| 143 |
|
else if (ret < 0) |
| 144 |
if (ovector[i * 2] == -1 || ovector[i * 2 + 1] == -1) |
{ |
| 145 |
|
log_error("pcre2_match() error: %d\n", ret); |
| 146 |
|
} |
| 147 |
|
else if (ret == 0) |
| 148 |
{ |
{ |
| 149 |
log_error("Bug: match pattern #%d with invalid offsets [%d, %d)", |
log_error("Vector of offsets is too small\n"); |
|
i, ovector[i * 2], ovector[i * 2 + 1]); |
|
|
ret = -2; |
|
| 150 |
} |
} |
| 151 |
else |
else // ret >= 1 |
| 152 |
{ |
{ |
| 153 |
|
ovector = pcre2_get_ovector_pointer(match_data); |
| 154 |
|
match_count = pcre2_get_ovector_count(match_data); |
| 155 |
|
|
| 156 |
|
i = ret - 1; |
| 157 |
|
if (ovector[i * 2] == -1 || ovector[i * 2 + 1] == -1) |
| 158 |
|
{ |
| 159 |
|
log_error("Bug: match pattern #%d of %d with invalid offsets [%d, %d)", |
| 160 |
|
i, match_count, ovector[i * 2], ovector[i * 2 + 1]); |
| 161 |
|
ret = -2; |
| 162 |
|
} |
| 163 |
|
else |
| 164 |
|
{ |
| 165 |
#ifdef _DEBUG |
#ifdef _DEBUG |
| 166 |
log_error("Debug: match pattern #%d at offsets [%d, %d]\n", |
log_error("Debug: match pattern #%d of %d at offsets [%d, %d]\n", |
| 167 |
i, ovector[i * 2], ovector[i * 2 + 1] - ovector[i * 2]); |
i, match_count, ovector[i * 2], ovector[i * 2 + 1] - ovector[i * 2]); |
| 168 |
#endif |
#endif |
| 169 |
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]); |
| 170 |
|
total_match_count++; |
| 171 |
|
startoffset = ovector[i * 2 + 1]; |
| 172 |
|
} |
| 173 |
} |
} |
| 174 |
} |
} |
| 175 |
|
|