aboutsummaryrefslogtreecommitdiffstats
path: root/src/filter.h
blob: 56a70fdf7c56bc1c7991c2be8e105f090b9ec610 (plain)
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
/**
 * @file filter.h
 * Filters logic implemetation
 */

#ifndef RSPAMD_FILTER_H
#define RSPAMD_FILTER_H

#include "config.h"
#include "symbols_cache.h"

struct worker_task;

typedef double (*metric_cons_func)(struct worker_task *task, const char *metric_name, const char *func_name);
typedef void (*filter_func)(struct worker_task *task);

enum filter_type { C_FILTER, PERL_FILTER };

/**
 * Filter structure
 */
struct filter {
	char *func_name;								/**< function name							*/
	enum filter_type type;							/**< filter type (c or perl)				*/
};

/**
 * Rspamd symbol
 */
struct symbol {
	double score;									/**< symbol's score							*/
	GList *options;									/**< list of symbol's options				*/
};

/**
 * Common definition of metric
 */
struct metric {
	char *name;										/**< name of metric							*/
	char *func_name;								/**< name of consolidation function			*/
	metric_cons_func func;							/**< c consolidation function				*/
	double required_score;							/**< required score for this metric			*/
	struct classifier *classifier;					/**< classifier that is used for metric		*/
	struct symbols_cache *cache;					/**< symbols cache for metric 				*/ 
	char *cache_filename;							/**< filename of cache file					*/
};

/**
 * 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  */
};

/**
 * 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
 */
int 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);

/**
 * 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 char *metric_name, const char *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 char *metric_name, const char *unused);

#endif