| 87 |
log_error("Debug: bwf_pattern_str: %s\n", bwf_pattern_str); |
log_error("Debug: bwf_pattern_str: %s\n", bwf_pattern_str); |
| 88 |
#endif |
#endif |
| 89 |
|
|
| 90 |
|
bwf_unload(); |
| 91 |
|
|
| 92 |
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); |
| 93 |
if (bwf_code == NULL) |
if (bwf_code == NULL) |
| 94 |
{ |
{ |
| 111 |
int check_badwords(char *str, char c_mask) |
int check_badwords(char *str, char c_mask) |
| 112 |
{ |
{ |
| 113 |
pcre2_match_data *match_data; |
pcre2_match_data *match_data; |
| 114 |
|
PCRE2_SIZE startoffset = 0; |
| 115 |
PCRE2_SIZE *ovector; |
PCRE2_SIZE *ovector; |
| 116 |
|
uint32_t match_count; |
| 117 |
int ret; |
int ret; |
| 118 |
int i; |
int i; |
| 119 |
|
int total_match_count = 0; |
| 120 |
|
|
| 121 |
if (bwf_code == NULL) |
if (bwf_code == NULL) |
| 122 |
{ |
{ |
| 126 |
|
|
| 127 |
match_data = pcre2_match_data_create_from_pattern(bwf_code, NULL); |
match_data = pcre2_match_data_create_from_pattern(bwf_code, NULL); |
| 128 |
|
|
| 129 |
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) |
|
|
{ |
|
|
log_error("Vector of offsets is too small\n"); |
|
|
} |
|
|
else // ret >= 1 |
|
| 130 |
{ |
{ |
| 131 |
ovector = pcre2_get_ovector_pointer(match_data); |
ret = pcre2_match(bwf_code, (PCRE2_SPTR)str, PCRE2_ZERO_TERMINATED, startoffset, 0, match_data, NULL); |
| 132 |
i = ret - 1; |
if (ret == PCRE2_ERROR_NOMATCH) |
| 133 |
|
{ |
| 134 |
if (ovector[i * 2] == -1 || ovector[i * 2 + 1] == -1) |
ret = total_match_count; |
| 135 |
|
break; |
| 136 |
|
} |
| 137 |
|
else if (ret < 0) |
| 138 |
{ |
{ |
| 139 |
log_error("Bug: match pattern #%d with invalid offsets [%d, %d)", |
log_error("pcre2_match() error: %d\n", ret); |
|
i, ovector[i * 2], ovector[i * 2 + 1]); |
|
|
ret = -2; |
|
| 140 |
} |
} |
| 141 |
else |
else if (ret == 0) |
| 142 |
{ |
{ |
| 143 |
|
log_error("Vector of offsets is too small\n"); |
| 144 |
|
} |
| 145 |
|
else // ret >= 1 |
| 146 |
|
{ |
| 147 |
|
ovector = pcre2_get_ovector_pointer(match_data); |
| 148 |
|
match_count = pcre2_get_ovector_count(match_data); |
| 149 |
|
|
| 150 |
|
i = ret - 1; |
| 151 |
|
if (ovector[i * 2] == -1 || ovector[i * 2 + 1] == -1) |
| 152 |
|
{ |
| 153 |
|
log_error("Bug: match pattern #%d of %d with invalid offsets [%d, %d)", |
| 154 |
|
i, match_count, ovector[i * 2], ovector[i * 2 + 1]); |
| 155 |
|
ret = -2; |
| 156 |
|
} |
| 157 |
|
else |
| 158 |
|
{ |
| 159 |
#ifdef _DEBUG |
#ifdef _DEBUG |
| 160 |
log_error("Debug: match pattern #%d at offsets [%d, %d]\n", |
log_error("Debug: match pattern #%d of %d at offsets [%d, %d]\n", |
| 161 |
i, ovector[i * 2], ovector[i * 2 + 1] - ovector[i * 2]); |
i, match_count, ovector[i * 2], ovector[i * 2 + 1] - ovector[i * 2]); |
| 162 |
#endif |
#endif |
| 163 |
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]); |
| 164 |
|
total_match_count++; |
| 165 |
|
startoffset = ovector[i * 2 + 1]; |
| 166 |
|
} |
| 167 |
} |
} |
| 168 |
} |
} |
| 169 |
|
|