/[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.2 - (show annotations)
Tue Nov 11 00:28:05 2025 UTC (4 months ago) by sysadm
Branch: MAIN
Changes since 1.1: +4 -0 lines
Content type: text/x-csrc
Use config.h

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 #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 for (i = 0; i < str_cnt; i++)
59 {
60 strncpy(str, str_in[i], sizeof(str) - 1);
61 str[sizeof(str) - 1] = '\0';
62 printf("Input(len=%ld): %s\n", strlen(str), str);
63
64 ret = check_badwords(str, '*');
65 if (ret < 0)
66 {
67 printf("Error: %d", ret);
68 break;
69 }
70 else if (ret == 0)
71 {
72 printf("=== Unmatched ===\n");
73 }
74 else // ret > 0
75 {
76 printf("Output(len=%ld): %s\n", strlen(str), str);
77 }
78 }
79
80 bwf_unload();
81
82 log_end();
83
84 return 0;
85 }

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