1 /* Copyright (C) 2016-2019 Shengyu Zhang <i@silverrainz.me>
2  *
3  * This file is part of Srain.
4  *
5  * Srain is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 /**
20  * @file filter.h
21  * @brief This header provides a modular mechanism for filering SrnMessage.
22  * @author Shengyu Zhang <i@silverrainz.me>
23  * @version
24  * @date 2019-05-16
25  */
26 
27 #ifndef __FILTER_H
28 #define __FILTER_H
29 
30 #include "core/core.h"
31 
32 typedef int SrnFilterFlags;
33 
34 #define SRN_FILTER_FLAG_USER        1 << 0
35 #define SRN_FILTER_FLAG_PATTERN     1 << 1
36 #define SRN_FILTER_FLAG_LOG         1 << 2
37 
38 void srn_filter_init(void);
39 void srn_filter_finalize(void);
40 
41 /**
42  * @brief srn_render_message filters a SrnMessage according to the given flags.
43  * Fields of SrnMessage MUST not be changed after filtering.
44  *
45  * @param msg is a SrnMessage instance.
46  * @param flags indicates which filter modueles to use.
47  *
48  * @return FALSE if the given message should be filtered.
49  */
50 bool srn_filter_message(const SrnMessage *msg, SrnFilterFlags flags);
51 
52 SrnRet srn_filter_attach_pattern(SrnExtraData *extra_data, const char *pattern);
53 SrnRet srn_filter_detach_pattern(SrnExtraData *extra_data, const char *pattern);
54 
55 #endif /* __FILTER_H */
56