Revision 761f2955
| b/lib/Makefile.am | ||
|---|---|---|
| 1 | 1 |
SUBDIRS = filters |
| 2 | 2 |
|
| 3 |
INCLUDES = $(GLIB_CFLAGS) -I$(top_srcdir) -I$(top_srcdir)/lib -I$(includedir) |
|
| 3 |
INCLUDES = $(GLIB_CFLAGS) -I$(top_srcdir) -I$(top_srcdir)/lib -I$(includedir) -I/usr/include/qdbm
|
|
| 4 | 4 |
|
| 5 | 5 |
lib_LTLIBRARIES = libsylfilter.la |
| 6 | 6 |
|
| 7 | 7 |
libsylfilter_la_SOURCES = \ |
| 8 | 8 |
filter.c \ |
| 9 | 9 |
filter-manager.c \ |
| 10 |
filter-utils.c |
|
| 10 |
filter-utils.c \ |
|
| 11 |
filter-kvs.c \ |
|
| 12 |
filter-kvs-qdbm.c |
|
| 11 | 13 |
|
| 12 | 14 |
libsylfilterincludedir=$(includedir)/sylfilter |
| 13 | 15 |
libsylfilterinclude_HEADERS = \ |
| 14 | 16 |
filter.h \ |
| 15 | 17 |
filter-manager.h \ |
| 16 |
filter-utils.h |
|
| 18 |
filter-utils.h \ |
|
| 19 |
filter-kvs.h \ |
|
| 20 |
filter-kvs-qdbm.h |
|
| 17 | 21 |
|
| 18 |
libsylfilter_la_LIBADD = $(GLIB_LIBS) filters/libfilters.la |
|
| 22 |
libsylfilter_la_LIBADD = $(GLIB_LIBS) -lqdbm filters/libfilters.la |
|
| b/lib/Makefile.in | ||
|---|---|---|
| 145 | 145 |
target_alias = @target_alias@ |
| 146 | 146 |
SUBDIRS = filters |
| 147 | 147 |
|
| 148 |
INCLUDES = $(GLIB_CFLAGS) -I$(top_srcdir) -I$(top_srcdir)/lib -I$(includedir) |
|
| 148 |
INCLUDES = $(GLIB_CFLAGS) -I$(top_srcdir) -I$(top_srcdir)/lib -I$(includedir) -I/usr/include/qdbm
|
|
| 149 | 149 |
|
| 150 | 150 |
lib_LTLIBRARIES = libsylfilter.la |
| 151 | 151 |
|
| 152 | 152 |
libsylfilter_la_SOURCES = \ |
| 153 | 153 |
filter.c \ |
| 154 | 154 |
filter-manager.c \ |
| 155 |
filter-utils.c |
|
| 155 |
filter-utils.c \ |
|
| 156 |
filter-kvs.c \ |
|
| 157 |
filter-kvs-qdbm.c |
|
| 156 | 158 |
|
| 157 | 159 |
|
| 158 | 160 |
libsylfilterincludedir = $(includedir)/sylfilter |
| 159 | 161 |
libsylfilterinclude_HEADERS = \ |
| 160 | 162 |
filter.h \ |
| 161 | 163 |
filter-manager.h \ |
| 162 |
filter-utils.h |
|
| 164 |
filter-utils.h \ |
|
| 165 |
filter-kvs.h \ |
|
| 166 |
filter-kvs-qdbm.h |
|
| 163 | 167 |
|
| 164 | 168 |
|
| 165 |
libsylfilter_la_LIBADD = $(GLIB_LIBS) filters/libfilters.la |
|
| 169 |
libsylfilter_la_LIBADD = $(GLIB_LIBS) -lqdbm filters/libfilters.la
|
|
| 166 | 170 |
subdir = lib |
| 167 | 171 |
ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 |
| 168 | 172 |
mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs |
| ... | ... | |
| 172 | 176 |
|
| 173 | 177 |
libsylfilter_la_LDFLAGS = |
| 174 | 178 |
libsylfilter_la_DEPENDENCIES = filters/libfilters.la |
| 175 |
am_libsylfilter_la_OBJECTS = filter.lo filter-manager.lo filter-utils.lo |
|
| 179 |
am_libsylfilter_la_OBJECTS = filter.lo filter-manager.lo filter-utils.lo \ |
|
| 180 |
filter-kvs.lo filter-kvs-qdbm.lo |
|
| 176 | 181 |
libsylfilter_la_OBJECTS = $(am_libsylfilter_la_OBJECTS) |
| 177 | 182 |
|
| 178 | 183 |
DEFAULT_INCLUDES = -I. -I$(srcdir) -I$(top_builddir) |
| 179 | 184 |
depcomp = $(SHELL) $(top_srcdir)/depcomp |
| 180 | 185 |
am__depfiles_maybe = depfiles |
| 181 |
@AMDEP_TRUE@DEP_FILES = ./$(DEPDIR)/filter-manager.Plo \ |
|
| 186 |
@AMDEP_TRUE@DEP_FILES = ./$(DEPDIR)/filter-kvs-qdbm.Plo \ |
|
| 187 |
@AMDEP_TRUE@ ./$(DEPDIR)/filter-kvs.Plo \ |
|
| 188 |
@AMDEP_TRUE@ ./$(DEPDIR)/filter-manager.Plo \ |
|
| 182 | 189 |
@AMDEP_TRUE@ ./$(DEPDIR)/filter-utils.Plo ./$(DEPDIR)/filter.Plo |
| 183 | 190 |
COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \ |
| 184 | 191 |
$(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) |
| ... | ... | |
| 247 | 254 |
distclean-compile: |
| 248 | 255 |
-rm -f *.tab.c |
| 249 | 256 |
|
| 257 |
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/filter-kvs-qdbm.Plo@am__quote@ |
|
| 258 |
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/filter-kvs.Plo@am__quote@ |
|
| 250 | 259 |
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/filter-manager.Plo@am__quote@ |
| 251 | 260 |
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/filter-utils.Plo@am__quote@ |
| 252 | 261 |
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/filter.Plo@am__quote@ |
| b/lib/filter-kvs-qdbm.c | ||
|---|---|---|
| 1 |
#include <depot.h> |
|
| 2 |
#include <stdlib.h> |
|
| 3 |
|
|
| 4 |
#include "filter-kvs.h" |
|
| 5 |
#include "filter-kvs-qdbm.h" |
|
| 6 |
|
|
| 7 |
static XFilterKVS *qdbm_open(const char *dbfile); |
|
| 8 |
static int qdbm_close(XFilterKVS *kvs); |
|
| 9 |
static int qdbm_insert(XFilterKVS *kvs, const char *key, void *value, int size); |
|
| 10 |
static int qdbm_delete(XFilterKVS *kvs, const char *key); |
|
| 11 |
static int qdbm_update(XFilterKVS *kvs, const char *key, void *value, int size); |
|
| 12 |
static int qdbm_fetch(XFilterKVS *kvs, const char *key, void *vbuf, int vsize); |
|
| 13 |
|
|
| 14 |
|
|
| 15 |
int xfilter_kvs_qdbm_set_engine(void) |
|
| 16 |
{
|
|
| 17 |
XFilterKVSEngine engine = {
|
|
| 18 |
qdbm_open, |
|
| 19 |
qdbm_close, |
|
| 20 |
qdbm_insert, |
|
| 21 |
qdbm_delete, |
|
| 22 |
qdbm_update, |
|
| 23 |
qdbm_fetch |
|
| 24 |
}; |
|
| 25 |
|
|
| 26 |
return xfilter_kvs_set_engine(&engine); |
|
| 27 |
} |
|
| 28 |
|
|
| 29 |
static XFilterKVS *qdbm_open(const char *dbfile) |
|
| 30 |
{
|
|
| 31 |
DEPOT *depot; |
|
| 32 |
|
|
| 33 |
depot = dpopen(dbfile, DP_OREADER|DP_OWRITER|DP_OCREAT, 0); |
|
| 34 |
if (!depot) |
|
| 35 |
return NULL; |
|
| 36 |
return xfilter_kvs_new(dbfile, (void *)depot); |
|
| 37 |
} |
|
| 38 |
|
|
| 39 |
static int qdbm_close(XFilterKVS *kvs) |
|
| 40 |
{
|
|
| 41 |
if (!dpclose((DEPOT *)xfilter_kvs_get_handle(kvs))) |
|
| 42 |
return -1; |
|
| 43 |
return 0; |
|
| 44 |
} |
|
| 45 |
|
|
| 46 |
static int qdbm_insert(XFilterKVS *kvs, const char *key, void *value, int size) |
|
| 47 |
{
|
|
| 48 |
DEPOT *depot; |
|
| 49 |
|
|
| 50 |
depot = (DEPOT *)xfilter_kvs_get_handle(kvs); |
|
| 51 |
if (!dpput(depot, key, -1, (const char *)value, size, DP_DKEEP)) |
|
| 52 |
return -1; |
|
| 53 |
return 0; |
|
| 54 |
} |
|
| 55 |
|
|
| 56 |
static int qdbm_delete(XFilterKVS *kvs, const char *key) |
|
| 57 |
{
|
|
| 58 |
DEPOT *depot; |
|
| 59 |
|
|
| 60 |
depot = (DEPOT *)xfilter_kvs_get_handle(kvs); |
|
| 61 |
if (!dpout(depot, key, -1)) |
|
| 62 |
return -1; |
|
| 63 |
|
|
| 64 |
return 0; |
|
| 65 |
} |
|
| 66 |
|
|
| 67 |
static int qdbm_update(XFilterKVS *kvs, const char *key, void *value, int size) |
|
| 68 |
{
|
|
| 69 |
DEPOT *depot; |
|
| 70 |
|
|
| 71 |
depot = (DEPOT *)xfilter_kvs_get_handle(kvs); |
|
| 72 |
if (!dpput(depot, key, -1, (const char *)value, size, DP_DOVER)) |
|
| 73 |
return -1; |
|
| 74 |
|
|
| 75 |
return 0; |
|
| 76 |
} |
|
| 77 |
|
|
| 78 |
static int qdbm_fetch(XFilterKVS *kvs, const char *key, void *vbuf, int vsize) |
|
| 79 |
{
|
|
| 80 |
DEPOT *depot; |
|
| 81 |
int size; |
|
| 82 |
|
|
| 83 |
depot = (DEPOT *)xfilter_kvs_get_handle(kvs); |
|
| 84 |
size = dpgetwb(depot, key, -1, 0, vsize, (char *)vbuf); |
|
| 85 |
if (size < 0) |
|
| 86 |
return -1; |
|
| 87 |
|
|
| 88 |
return size; |
|
| 89 |
} |
|
| b/lib/filter-kvs-qdbm.h | ||
|---|---|---|
| 1 |
#ifndef __FILTER_KVS_QDBM__ |
|
| 2 |
#define __FILTER_KVS_QDBM__ |
|
| 3 |
|
|
| 4 |
int xfilter_kvs_qdbm_set_engine(void); |
|
| 5 |
|
|
| 6 |
#endif /* __FILTER_KVS_QDBM__ */ |
|
| b/lib/filter-kvs.c | ||
|---|---|---|
| 1 |
#include <glib.h> |
|
| 2 |
|
|
| 3 |
#include "filter-kvs.h" |
|
| 4 |
|
|
| 5 |
struct _XFilterKVS |
|
| 6 |
{
|
|
| 7 |
char *dbfile; |
|
| 8 |
void *dbhandle; |
|
| 9 |
}; |
|
| 10 |
|
|
| 11 |
static XFilterKVSEngine ke; |
|
| 12 |
|
|
| 13 |
|
|
| 14 |
int xfilter_kvs_set_engine(XFilterKVSEngine *engine) |
|
| 15 |
{
|
|
| 16 |
g_return_val_if_fail(engine != NULL, -1); |
|
| 17 |
|
|
| 18 |
ke = *engine; |
|
| 19 |
|
|
| 20 |
return 0; |
|
| 21 |
} |
|
| 22 |
|
|
| 23 |
XFilterKVS *xfilter_kvs_new(const char *dbfile, void *dbhandle) |
|
| 24 |
{
|
|
| 25 |
XFilterKVS *kvs; |
|
| 26 |
|
|
| 27 |
kvs = g_new(XFilterKVS, 1); |
|
| 28 |
kvs->dbfile = g_strdup(dbfile); |
|
| 29 |
kvs->dbhandle = dbhandle; |
|
| 30 |
|
|
| 31 |
return kvs; |
|
| 32 |
} |
|
| 33 |
|
|
| 34 |
const char *xfilter_kvs_get_file(XFilterKVS *kvs) |
|
| 35 |
{
|
|
| 36 |
g_return_val_if_fail(kvs != NULL, NULL); |
|
| 37 |
return kvs->dbfile; |
|
| 38 |
} |
|
| 39 |
|
|
| 40 |
void *xfilter_kvs_get_handle(XFilterKVS *kvs) |
|
| 41 |
{
|
|
| 42 |
g_return_val_if_fail(kvs != NULL, NULL); |
|
| 43 |
return kvs->dbhandle; |
|
| 44 |
} |
|
| 45 |
|
|
| 46 |
XFilterKVS *xfilter_kvs_open(const char *dbfile) |
|
| 47 |
{
|
|
| 48 |
g_return_val_if_fail(ke.open != NULL, NULL); |
|
| 49 |
return ke.open(dbfile); |
|
| 50 |
} |
|
| 51 |
|
|
| 52 |
int xfilter_kvs_close(XFilterKVS *kvs) |
|
| 53 |
{
|
|
| 54 |
g_return_val_if_fail(kvs != NULL, -1); |
|
| 55 |
return ke.close(kvs); |
|
| 56 |
} |
|
| 57 |
|
|
| 58 |
int xfilter_kvs_insert(XFilterKVS *kvs, const char *key, void *value, int size) |
|
| 59 |
{
|
|
| 60 |
g_return_val_if_fail(kvs != NULL, -1); |
|
| 61 |
return ke.insert(kvs, key, value, size); |
|
| 62 |
} |
|
| 63 |
|
|
| 64 |
int xfilter_kvs_delete(XFilterKVS *kvs, const char *key) |
|
| 65 |
{
|
|
| 66 |
g_return_val_if_fail(kvs != NULL, -1); |
|
| 67 |
return ke.delete(kvs, key); |
|
| 68 |
} |
|
| 69 |
|
|
| 70 |
int xfilter_kvs_update(XFilterKVS *kvs, const char *key, void *value, int size) |
|
| 71 |
{
|
|
| 72 |
g_return_val_if_fail(kvs != NULL, -1); |
|
| 73 |
return ke.update(kvs, key, value, size); |
|
| 74 |
} |
|
| 75 |
|
|
| 76 |
int xfilter_kvs_fetch(XFilterKVS *kvs, const char *key, void *vbuf, int vsize) |
|
| 77 |
{
|
|
| 78 |
g_return_val_if_fail(kvs != NULL, -1); |
|
| 79 |
return ke.fetch(kvs, key, vbuf, vsize); |
|
| 80 |
} |
|
| 81 |
|
|
| 82 |
int xfilter_kvs_fetch_int(XFilterKVS *kvs, const char *key) |
|
| 83 |
{
|
|
| 84 |
int ival = 0; |
|
| 85 |
int size; |
|
| 86 |
char vbuf[4]; |
|
| 87 |
|
|
| 88 |
g_return_val_if_fail(kvs != NULL, -1); |
|
| 89 |
|
|
| 90 |
size = xfilter_kvs_fetch(kvs, key, vbuf, 4); |
|
| 91 |
if (size == 4) {
|
|
| 92 |
ival = *(int *)vbuf; |
|
| 93 |
return ival; |
|
| 94 |
} |
|
| 95 |
|
|
| 96 |
return 0; |
|
| 97 |
} |
|
| 98 |
|
|
| 99 |
int xfilter_kvs_increment(XFilterKVS *kvs, const char *key, int num) |
|
| 100 |
{
|
|
| 101 |
int ival = 0; |
|
| 102 |
int size; |
|
| 103 |
char vbuf[4]; |
|
| 104 |
|
|
| 105 |
g_return_val_if_fail(kvs != NULL, -1); |
|
| 106 |
|
|
| 107 |
size = xfilter_kvs_fetch(kvs, key, vbuf, 4); |
|
| 108 |
if (size == 4) {
|
|
| 109 |
ival = *(int *)vbuf; |
|
| 110 |
ival += num; |
|
| 111 |
return xfilter_kvs_update(kvs, key, (char *)&ival, 4); |
|
| 112 |
} else if (size <= 0) {
|
|
| 113 |
return xfilter_kvs_insert(kvs, key, (char *)&num, 4); |
|
| 114 |
} |
|
| 115 |
|
|
| 116 |
return -1; |
|
| 117 |
} |
|
| 118 |
|
|
| 119 |
int xfilter_kvs_decrement(XFilterKVS *kvs, const char *key, int num) |
|
| 120 |
{
|
|
| 121 |
int ival = 0; |
|
| 122 |
int size; |
|
| 123 |
char vbuf[4]; |
|
| 124 |
|
|
| 125 |
g_return_val_if_fail(kvs != NULL, -1); |
|
| 126 |
|
|
| 127 |
size = xfilter_kvs_fetch(kvs, key, vbuf, 4); |
|
| 128 |
if (size == 4) {
|
|
| 129 |
ival = *(int *)vbuf; |
|
| 130 |
ival -= num; |
|
| 131 |
if (ival <= 0) |
|
| 132 |
return xfilter_kvs_delete(kvs, key); |
|
| 133 |
else |
|
| 134 |
return xfilter_kvs_update(kvs, key, (char *)&ival, 4); |
|
| 135 |
} |
|
| 136 |
|
|
| 137 |
return -1; |
|
| 138 |
} |
|
| b/lib/filter-kvs.h | ||
|---|---|---|
| 1 |
/* filter-kvs.h */ |
|
| 2 |
|
|
| 3 |
#ifndef __FILTER_KVS_H__ |
|
| 4 |
#define __FILTER_KVS_H__ |
|
| 5 |
|
|
| 6 |
typedef struct _XFilterKVS XFilterKVS; |
|
| 7 |
|
|
| 8 |
typedef struct _XFilterKVSEngine |
|
| 9 |
{
|
|
| 10 |
XFilterKVS * (*open) (const char *dbfile); |
|
| 11 |
int (*close) (XFilterKVS *kvs); |
|
| 12 |
int (*insert) (XFilterKVS *kvs, const char *key, void *value, |
|
| 13 |
int size); |
|
| 14 |
int (*delete) (XFilterKVS *kvs, const char *key); |
|
| 15 |
int (*update) (XFilterKVS *kvs, const char *key, void *value, |
|
| 16 |
int size); |
|
| 17 |
int (*fetch) (XFilterKVS *kvs, const char *key, void *vbuf, int vsize); |
|
| 18 |
} XFilterKVSEngine; |
|
| 19 |
|
|
| 20 |
int xfilter_kvs_set_engine (XFilterKVSEngine *engine); |
|
| 21 |
|
|
| 22 |
XFilterKVS *xfilter_kvs_new (const char *dbfile, void *dbhandle); |
|
| 23 |
const char *xfilter_kvs_get_file(XFilterKVS *kvs); |
|
| 24 |
void *xfilter_kvs_get_handle (XFilterKVS *kvs); |
|
| 25 |
|
|
| 26 |
XFilterKVS *xfilter_kvs_open (const char *dbfile); |
|
| 27 |
int xfilter_kvs_close (XFilterKVS *kvs); |
|
| 28 |
|
|
| 29 |
int xfilter_kvs_insert (XFilterKVS *kvs, const char *key, void *value, |
|
| 30 |
int size); |
|
| 31 |
int xfilter_kvs_delete (XFilterKVS *kvs, const char *key); |
|
| 32 |
int xfilter_kvs_update (XFilterKVS *kvs, const char *key, void *value, |
|
| 33 |
int size); |
|
| 34 |
int xfilter_kvs_fetch (XFilterKVS *kvs, const char *key, void *vbuf, int vsize); |
|
| 35 |
|
|
| 36 |
int xfilter_kvs_fetch_int (XFilterKVS *kvs, const char *key); |
|
| 37 |
|
|
| 38 |
int xfilter_kvs_increment (XFilterKVS *kvs, const char *key, int num); |
|
| 39 |
int xfilter_kvs_decrement (XFilterKVS *kvs, const char *key, int num); |
|
| 40 |
|
|
| 41 |
#endif /* __FILTER_KVS_H__ */ |
|
| b/lib/filters/bayes-filter.c | ||
|---|---|---|
| 1 | 1 |
#include <glib.h> |
| 2 | 2 |
|
| 3 | 3 |
#include "filter.h" |
| 4 |
#include "filter-kvs.h" |
|
| 4 | 5 |
#include "bayes-filter.h" |
| 5 | 6 |
|
| 6 | 7 |
|
| 8 |
static XFilterKVS *bayes_kvs; |
|
| 9 |
|
|
| 7 | 10 |
static GHashTable *xfilter_bayes_word_freq(const char *text) |
| 8 | 11 |
{
|
| 9 | 12 |
GHashTable *table; |
| ... | ... | |
| 30 | 33 |
return table; |
| 31 | 34 |
} |
| 32 | 35 |
|
| 36 |
static void test_walk_func(gpointer key, gpointer val, gpointer data) |
|
| 37 |
{
|
|
| 38 |
int n; |
|
| 39 |
|
|
| 40 |
if ((n = xfilter_kvs_fetch_int(bayes_kvs, (gchar *)key)) < 0) |
|
| 41 |
g_warning("database fetch error");
|
|
| 42 |
g_print("%s: (this: %d) (db: %d)\n", (gchar *)key, GPOINTER_TO_INT(val), n);
|
|
| 43 |
} |
|
| 44 |
|
|
| 33 | 45 |
static XFilterStatus xfilter_bayes_func(XFilter *filter, const XMessageData *data) |
| 34 | 46 |
{
|
| 35 | 47 |
const char *type; |
| ... | ... | |
| 39 | 51 |
if (!type || g_strncasecmp(type, "text/", 5) != 0) |
| 40 | 52 |
return XF_UNSUPPORTED_TYPE; |
| 41 | 53 |
|
| 54 |
if (!bayes_kvs) {
|
|
| 55 |
bayes_kvs = xfilter_kvs_open("filter.db");
|
|
| 56 |
if (!bayes_kvs) {
|
|
| 57 |
g_warning("Cannot open database: filter.db");
|
|
| 58 |
return XF_ERROR; |
|
| 59 |
} |
|
| 60 |
} |
|
| 61 |
|
|
| 42 | 62 |
g_print("bayes-guessing message\n");
|
| 43 | 63 |
table = xfilter_bayes_word_freq(xfilter_message_data_get_content(data)); |
| 64 |
g_hash_table_foreach(table, test_walk_func, NULL); |
|
| 44 | 65 |
g_hash_table_destroy(table); |
| 45 | 66 |
|
| 67 |
xfilter_kvs_close(bayes_kvs); |
|
| 68 |
bayes_kvs = NULL; |
|
| 69 |
|
|
| 46 | 70 |
return XF_NOJUNK; |
| 47 | 71 |
} |
| 48 | 72 |
|
| ... | ... | |
| 57 | 81 |
} |
| 58 | 82 |
|
| 59 | 83 |
|
| 60 |
static void walk_func(gpointer key, gpointer val, gpointer data) |
|
| 84 |
static void learn_walk_func(gpointer key, gpointer val, gpointer data)
|
|
| 61 | 85 |
{
|
| 62 | 86 |
g_print("%s: %d\n", (gchar *)key, GPOINTER_TO_INT(val));
|
| 87 |
if (xfilter_kvs_increment(bayes_kvs, (gchar *)key, GPOINTER_TO_INT(val)) < 0) |
|
| 88 |
g_warning("database update error");
|
|
| 63 | 89 |
} |
| 64 | 90 |
|
| 65 | 91 |
static XFilterStatus xfilter_bayes_learn_func(XFilter *filter, const XMessageData *data, XMessageData **retdata) |
| ... | ... | |
| 73 | 99 |
if (!type || g_strncasecmp(type, "text/", 5) != 0) |
| 74 | 100 |
return XF_UNSUPPORTED_TYPE; |
| 75 | 101 |
|
| 102 |
if (!bayes_kvs) {
|
|
| 103 |
bayes_kvs = xfilter_kvs_open("filter.db");
|
|
| 104 |
if (!bayes_kvs) {
|
|
| 105 |
g_warning("Cannot open database: filter.db");
|
|
| 106 |
return XF_ERROR; |
|
| 107 |
} |
|
| 108 |
} |
|
| 109 |
|
|
| 76 | 110 |
g_print("learning message\n");
|
| 77 | 111 |
table = xfilter_bayes_word_freq(xfilter_message_data_get_content(data)); |
| 78 |
g_hash_table_foreach(table, walk_func, NULL); |
|
| 112 |
g_hash_table_foreach(table, learn_walk_func, NULL);
|
|
| 79 | 113 |
g_hash_table_destroy(table); |
| 80 | 114 |
|
| 115 |
xfilter_kvs_close(bayes_kvs); |
|
| 116 |
bayes_kvs = NULL; |
|
| 117 |
|
|
| 81 | 118 |
return XF_NONE; |
| 82 | 119 |
} |
| 83 | 120 |
|
| b/lib/filters/wordsep-filter.c | ||
|---|---|---|
| 78 | 78 |
{
|
| 79 | 79 |
gchar s[7] = {0};
|
| 80 | 80 |
g_unichar_to_utf8(wc, s); |
| 81 |
g_print("%s: utype=%d word_len=%d\n", s, utype, word_len);
|
|
| 81 |
//g_print("%s: utype=%d word_len=%d\n", s, utype, word_len);
|
|
| 82 | 82 |
} |
| 83 | 83 |
|
| 84 | 84 |
if (p > bp) {
|
| b/src/sylfilter.c | ||
|---|---|---|
| 4 | 4 |
#include "filter.h" |
| 5 | 5 |
#include "filter-manager.h" |
| 6 | 6 |
#include "filter-utils.h" |
| 7 |
#include "filter-kvs.h" |
|
| 8 |
|
|
| 9 |
#define USE_QDBM 1 |
|
| 10 |
#ifdef USE_QDBM |
|
| 11 |
# include "filter-kvs-qdbm.h" |
|
| 12 |
#endif |
|
| 13 |
|
|
| 7 | 14 |
#include "textcontent-filter.h" |
| 8 | 15 |
#include "blacklist-filter.h" |
| 9 | 16 |
#include "whitelist-filter.h" |
| ... | ... | |
| 55 | 62 |
|
| 56 | 63 |
xfilter_init(); |
| 57 | 64 |
|
| 65 |
#ifdef USE_QDBM |
|
| 66 |
xfilter_kvs_qdbm_set_engine(); |
|
| 67 |
#endif |
|
| 68 |
|
|
| 58 | 69 |
// set message files |
| 59 | 70 |
if (argc > 1) |
| 60 | 71 |
rfc822_file = argv[1]; |
Also available in: Unified diff