ze-filter  (ze-filter-0.8.0-develop-180218)
ze-bfilter.h
Go to the documentation of this file.
1 /*
2  *
3  * ze-filter - Mail Server Filter for sendmail
4  *
5  * Copyright (c) 2001-2018 - Jose-Marcio Martins da Cruz
6  *
7  * Auteur : Jose Marcio Martins da Cruz
8  * jose.marcio.mc@gmail.org
9  *
10  * Historique :
11  * Creation : Thu Jun 15 13:41:01 CEST 2006
12  *
13  * This program is free software, but with restricted license :
14  *
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
19  *
20  * More details about ze-filter license can be found at ze-filter
21  * web site : http://foss.jose-marcio.org
22  */
23 
24 
25 #ifndef __ZE_BFILTER_H
26 
27 
32 #define BFLAG_TRFTOK 2
33 
34 #define BFLAG_DEFAULT (BFLAG_TRFTOK)
35 
36 #define BFHISTODIM 21
37 
38 typedef struct
39 {
41  bool ok;
42 
43  pthread_mutex_t mutex;
45  char *dbname;
46  size_t cachesize;
47 
48  long nbMsgsSpam;
49  long nbMsgsHam;
50 
51  double kms;
52  double kmh;
53 
56 
57  double kts;
58  double kth;
59 
62 
63  double kfs;
64  double kfh;
65 
66  long nbFeatures;
67 
68  double rhs;
69  double ut_prob;
70 
71  int nbt;
72 
73  int crypt;
74 
76 
77  size_t maxMsgSize;
78  size_t maxPartSize;
79 
80  bool logit;
81 
82  bool segRecurse;
83  bool segDouble;
84 
85  int clType;
86  int clFSel;
87 
88  int histo[BFHISTODIM];
89 } bfilter_T;
90 
91 
92 #define CL_TYPE_NP 0
93 #define CL_TYPE_NB 1
94 
95 #define CL_FS_EP 0
96 #define CL_FS_MI 1
97 #define CF_FS_TFIDF 2
98 
99 
100 #define BFILTER_INITIALIZER \
101  { \
102  SIGNATURE, \
103  FALSE, \
104  PTHREAD_MUTEX_INITIALIZER, \
105  ZEDB_INITIALIZER, \
106  NULL, 0, \
107  0, 0, 0., 0., \
108  0, 0, 0., 0., \
109  0, 0, 0., 0., 0, \
110  1.0, \
111  UT_PROB, \
112  64, \
113  HASH_PLAIN, \
114  BFLAG_DEFAULT, \
115  400000, \
116  40000, \
117  FALSE, \
118  TRUE, \
119  TRUE, \
120  CL_TYPE_NP, \
121  CL_FS_EP, \
122  0 \
123  }
124 
126 
127 bool bfilter_init(char *dbname);
128 
129 bool bfilter_db_open();
130 
131 bool bfilter_db_reopen();
132 
133 bool bfilter_close();
134 
135 bool bfilter_ok();
136 
138 
139 bool set_bfilter_logit(bool enable);
140 
141 bool set_bfilter_ham_spam_ratio(double ratio);
142 bool set_bfilter_unknown_token_prob(double prob);
143 bool set_bfilter_nb_tokens(int nbt);
144 bool set_bfilter_max_sizes(size_t msg, size_t mime);
145 bool set_bfilter_db_crypt(int crypt);
146 
151 size_t get_bfilter_max_sizes();
153 
154 typedef struct sfilter_token_T
155 {
156  char token[128];
157  int nb;
158  double prob;
159 
160  double nts;
161  double nth;
162 
163  /* XXX int version needed by learning phase */
164  int nbs;
165  int nbh;
166 
167  double value;
168 
169  bool ok;
171 
172 typedef int (*btsm_browse_F) (void *, void *);
173 
174 typedef int (*smodel_db_browse_F) (void *, void *, void *);
175 
176 bool smodel_db_check_token(char *key, sfilter_token_T * token);
177 void smodel_db_info(char *prefix, smodel_db_browse_F func,
178  void *arg);
179 
180 void set_tokconf_active(char *tag, bool active);
181 
182 bool bfilter_handle_message(char *id, char *fname,
183  btsm_browse_F func, void *arg);
184 
185 /* ****************************************************************************
186  * *
187  * *
188  **************************************************************************** */
189 
190 #define UT_PROB 0.5
191 
194 # define __ZE_BFILTER_H 1
195 #endif /* __ZE_BFILTER_H */
size_t cachesize
Definition: ze-bfilter.h:46
bool bfilter_db_reopen()
Definition: ze-bfilter.c:614
int(* smodel_db_browse_F)(void *, void *, void *)
Definition: ze-bfilter.h:174
bool set_bfilter_nb_tokens(int nbt)
Definition: ze-bfilter.c:470
long nbTokensSpam
Definition: ze-bfilter.h:54
bool set_bfilter_max_sizes(size_t msg, size_t mime)
Definition: ze-bfilter.c:486
bfilter_T * bfilter_ptr()
Definition: ze-bfilter.c:60
uint32_t get_bfilter_flags()
Definition: ze-bfilter.c:524
bool logit
Definition: ze-bfilter.h:80
bool segDouble
Definition: ze-bfilter.h:83
double get_bfilter_ham_spam_ratio()
Definition: ze-bfilter.c:538
bool smodel_db_check_token(char *key, sfilter_token_T *token)
Definition: ze-bfilter.c:723
Definition: zeDb.h:47
size_t maxPartSize
Definition: ze-bfilter.h:78
void set_tokconf_active(char *tag, bool active)
bool set_bfilter_unknown_token_prob(double prob)
Definition: ze-bfilter.c:454
uint32_t flags
Definition: ze-bfilter.h:75
int crypt
Definition: ze-bfilter.h:73
long nbFeatures
Definition: ze-bfilter.h:66
bool bfilter_init(char *dbname)
Definition: ze-bfilter.c:200
double kms
Definition: ze-bfilter.h:51
size_t get_bfilter_max_sizes()
Definition: ze-bfilter.c:580
bool bfilter_close()
Definition: ze-bfilter.c:651
double rhs
Definition: ze-bfilter.h:68
long nbMsgsSpam
Definition: ze-bfilter.h:48
struct sfilter_token_T sfilter_token_T
int clFSel
Definition: ze-bfilter.h:86
uint32_t signature
Definition: ze-bfilter.h:40
double kts
Definition: ze-bfilter.h:57
int get_bfilter_nb_tokens()
Definition: ze-bfilter.c:566
int clType
Definition: ze-bfilter.h:85
#define BFHISTODIM
Definition: ze-bfilter.h:36
bool bfilter_ok()
Definition: ze-bfilter.c:676
bool set_bfilter_ham_spam_ratio(double ratio)
Definition: ze-bfilter.c:438
double get_bfilter_unknown_token_prob()
Definition: ze-bfilter.c:552
double ut_prob
Definition: ze-bfilter.h:69
long nbFeaturesSpam
Definition: ze-bfilter.h:60
long nbMsgsHam
Definition: ze-bfilter.h:49
long nbFeaturesHam
Definition: ze-bfilter.h:61
bool set_bfilter_logit(bool enable)
Definition: ze-bfilter.c:404
void smodel_db_info(char *prefix, smodel_db_browse_F func, void *arg)
Definition: ze-bfilter.c:846
double kmh
Definition: ze-bfilter.h:52
long nbTokensHam
Definition: ze-bfilter.h:55
double kth
Definition: ze-bfilter.h:58
int(* btsm_browse_F)(void *, void *)
Definition: ze-bfilter.h:172
char * dbname
Definition: ze-bfilter.h:45
ZEDB_T bdb
Definition: ze-bfilter.h:44
bool set_bfilter_db_crypt(int crypt)
Definition: ze-bfilter.c:507
uint32_t set_bfilter_flags(uint32_t flags)
Definition: ze-bfilter.c:421
bool ok
Definition: ze-bfilter.h:41
double kfs
Definition: ze-bfilter.h:63
bool segRecurse
Definition: ze-bfilter.h:82
pthread_mutex_t mutex
Definition: ze-bfilter.h:43
long uint32_t
Definition: ze-sys.h:489
size_t maxMsgSize
Definition: ze-bfilter.h:77
int msg[MAX_SCORE+2]
Definition: ze-stats.c:41
char token[128]
Definition: ze-bfilter.h:156
bool bfilter_db_open()
int get_bfilter_db_crypt()
Definition: ze-bfilter.c:600
bool bfilter_handle_message(char *id, char *fname, btsm_browse_F func, void *arg)
double kfh
Definition: ze-bfilter.h:64