/[LeafOK_CVS]/lbbs/src/test_bwf.c
ViewVC logotype

Contents of /lbbs/src/test_bwf.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1 - (show annotations)
Fri Nov 7 13:56:49 2025 UTC (4 months, 1 week ago) by sysadm
Branch: MAIN
Content type: text/x-csrc
Add BWF - bad word filter

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

webmaster@leafok.com
ViewVC Help
Powered by ViewVC 1.3.0-beta1