1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
|
/**
* @file filter.h
* Filters logic implemetation
*/
#ifndef RSPAMD_FILTER_H
#define RSPAMD_FILTER_H
#include "config.h"
#include "symbols_cache.h"
struct worker_task;
struct rspamd_settings;
struct classifier_config;
typedef double (*metric_cons_func)(struct worker_task *task, const gchar *metric_name, const gchar *func_name);
typedef void (*filter_func)(struct worker_task *task);
enum filter_type { C_FILTER, PERL_FILTER };
/**
* Filter structure
*/
struct filter {
gchar *func_name; /**< function name */
enum filter_type type; /**< filter type (c or perl) */
module_t *module;
};
/**
* Rspamd symbol
*/
struct symbol {
double score; /**< symbol's score */
GList *options; /**< list of symbol's options */
const gchar *name;
};
enum rspamd_metric_action {
METRIC_ACTION_REJECT = 0,
METRIC_ACTION_SOFT_REJECT,
METRIC_ACTION_REWRITE_SUBJECT,
METRIC_ACTION_ADD_HEADER,
METRIC_ACTION_GREYLIST,
METRIC_ACTION_NOACTION
};
struct metric_action {
enum rspamd_metric_action action;
gdouble score;
};
/**
* Common definition of metric
*/
struct metric {
gchar *name; /**< name of metric */
gchar *func_name; /**< name of consolidation function */
metric_cons_func func; /**< c consolidation function */
double grow_factor; /**< grow factor for metric */
double required_score; /**< required score for this metric */
double reject_score; /**< reject score for this metric */
GHashTable *symbols; /**< weights of symbols in metric */
GHashTable *descriptions; /**< descriptions of symbols in metric */
enum rspamd_metric_action action; /**< action to do by this metric by default */
GList *actions; /**< actions that can be performed by this metric */
gchar *subject; /**< subject rewrite string */
};
/**
* Result of metric processing
*/
struct metric_result {
struct metric *metric; /**< pointer to metric structure */
double score; /**< total score */
GHashTable *symbols; /**< symbols of metric */
gboolean checked; /**< whether metric result is consolidated */
double grow_factor; /**< current grow factor */
struct rspamd_settings *user_settings; /**< settings for metric */
struct rspamd_settings *domain_settings; /**< settings for metric */
};
/**
* Composite structure
*/
struct rspamd_composite {
struct expression *expr;
gint id;
};
/**
* Process all filters
* @param task worker's task that present message from user
* @return 0 - if there is non-finished tasks and 1 if processing is completed
*/
gint process_filters (struct worker_task *task);
/**
* Process message with statfiles
* @param task worker's task that present message from user
*/
void process_statfiles (struct worker_task *task);
/**
* Process message with statfiles threaded
* @param data worker's task that present message from user
*/
void process_statfiles_threaded (gpointer data, gpointer user_data);
/**
* Insert a result to task
* @param task worker's task that present message from user
* @param metric_name metric's name to which we need to insert result
* @param symbol symbol to insert
* @param flag numeric weight for symbol
* @param opts list of symbol's options
*/
void insert_result (struct worker_task *task, const gchar *symbol, double flag, GList *opts);
/**
* Insert a single result to task
* @param task worker's task that present message from user
* @param metric_name metric's name to which we need to insert result
* @param symbol symbol to insert
* @param flag numeric weight for symbol
* @param opts list of symbol's options
*/
void insert_result_single (struct worker_task *task, const gchar *symbol, double flag, GList *opts);
/**
* Process all results and form composite metrics from existent metrics as it is defined in config
* @param task worker's task that present message from user
*/
void make_composites (struct worker_task *task);
/**
* Default consolidation function for metric, it get all symbols and multiply symbol
* weight by some factor that is specified in config. Default factor is 1.
* @param task worker's task that present message from user
* @param metric_name name of metric
* @return result metric weight
*/
double factor_consolidation_func (struct worker_task *task, const gchar *metric_name, const gchar *unused);
/*
* Learn specified statfile with message in a task
* @param statfile symbol of statfile
* @param task worker's task object
* @param err pointer to GError
* @return true if learn succeed
*/
gboolean learn_task (const gchar *statfile, struct worker_task *task, GError **err);
/*
* Learn specified statfile with message in a task
* @param statfile symbol of statfile
* @param task worker's task object
* @param err pointer to GError
* @return true if learn succeed
*/
gboolean learn_task_spam (struct classifier_config *cl, struct worker_task *task, gboolean is_spam, GError **err);
/*
* Get action from a string
*/
gboolean check_action_str (const gchar *data, gint *result);
/*
* Return textual representation of action enumeration
*/
const gchar *str_action_metric (enum rspamd_metric_action action);
/*
* Get action for specific metric
*/
gint check_metric_action (double score, double required_score, struct metric *metric);
#endif
|