| 1 |
/* SPDX-License-Identifier: GPL-3.0-or-later */
|
| 2 |
/*
|
| 3 |
* test_bwf
|
| 4 |
* - tester for bad words filter
|
| 5 |
*
|
| 6 |
* Copyright (C) 2004-2026 Leaflet <leaflet@leafok.com>
|
| 7 |
*/
|
| 8 |
|
| 9 |
#ifdef HAVE_CONFIG_H
|
| 10 |
#include "config.h"
|
| 11 |
#endif
|
| 12 |
|
| 13 |
#include "bwf.h"
|
| 14 |
#include "log.h"
|
| 15 |
#include <stdio.h>
|
| 16 |
#include <string.h>
|
| 17 |
#include <unistd.h>
|
| 18 |
|
| 19 |
const char *str_in[] = {
|
| 20 |
"fuck",
|
| 21 |
"fuck ",
|
| 22 |
" fUck ",
|
| 23 |
"f u c k",
|
| 24 |
"法轮",
|
| 25 |
"法 轮",
|
| 26 |
" 法 轮 ",
|
| 27 |
"大法轮",
|
| 28 |
"法轮小",
|
| 29 |
"大法轮小",
|
| 30 |
"法\n轮",
|
| 31 |
"fuckrape",
|
| 32 |
"1 rApe \n FuCK 2",
|
| 33 |
};
|
| 34 |
|
| 35 |
const int str_cnt = sizeof(str_in) / sizeof(const char *);
|
| 36 |
|
| 37 |
int main(int argc, char *argv[])
|
| 38 |
{
|
| 39 |
char str[256];
|
| 40 |
int i;
|
| 41 |
int ret;
|
| 42 |
|
| 43 |
if (log_begin("../log/bbsd.log", "../log/error.log") < 0)
|
| 44 |
{
|
| 45 |
printf("Open log error\n");
|
| 46 |
return -1;
|
| 47 |
}
|
| 48 |
|
| 49 |
log_common_redir(STDOUT_FILENO);
|
| 50 |
log_error_redir(STDERR_FILENO);
|
| 51 |
|
| 52 |
// Load BWF config
|
| 53 |
if (bwf_load("../conf/badwords.conf.default") < 0)
|
| 54 |
{
|
| 55 |
return -2;
|
| 56 |
}
|
| 57 |
|
| 58 |
if (bwf_compile() < 0)
|
| 59 |
{
|
| 60 |
return -2;
|
| 61 |
}
|
| 62 |
|
| 63 |
for (i = 0; i < str_cnt; i++)
|
| 64 |
{
|
| 65 |
strncpy(str, str_in[i], sizeof(str) - 1);
|
| 66 |
str[sizeof(str) - 1] = '\0';
|
| 67 |
printf("Input(len=%ld): %s\n", strlen(str), str);
|
| 68 |
|
| 69 |
ret = check_badwords(str, '*');
|
| 70 |
if (ret < 0)
|
| 71 |
{
|
| 72 |
printf("Error: %d", ret);
|
| 73 |
break;
|
| 74 |
}
|
| 75 |
else if (ret == 0)
|
| 76 |
{
|
| 77 |
printf("=== Unmatched ===\n");
|
| 78 |
}
|
| 79 |
else // ret > 0
|
| 80 |
{
|
| 81 |
printf("Output(len=%ld): %s\n", strlen(str), str);
|
| 82 |
}
|
| 83 |
}
|
| 84 |
|
| 85 |
bwf_cleanup();
|
| 86 |
|
| 87 |
log_end();
|
| 88 |
|
| 89 |
return 0;
|
| 90 |
}
|