[cvs] bogofilter/src wordlists.c,1.21,1.22 wordlists.h,1.5,1.6 bogoutil.c,1.42,1.43
Fast Bayesian spam filter along lines suggested by Paul Graham
Brought to you by:
m-a
From: <re...@us...> - 2003-07-20 19:05:59
|
Update of /cvsroot/bogofilter/bogofilter/src In directory sc8-pr-cvs1:/tmp/cvs-serv18930 Modified Files: wordlists.c wordlists.h bogoutil.c Log Message: Rewrite check for wordlist mode. Index: wordlists.c =================================================================== RCS file: /cvsroot/bogofilter/bogofilter/src/wordlists.c,v retrieving revision 1.21 retrieving revision 1.22 diff -u -d -r1.21 -r1.22 --- wordlists.c 20 Jul 2003 01:13:32 -0000 1.21 +++ wordlists.c 20 Jul 2003 19:05:53 -0000 1.22 @@ -186,33 +186,6 @@ return; } -void set_wordlist_mode(void **dbhp, const char *filepath, dbmode_t dbmode) -{ - if (wl_mode == WL_M_UNKNOWN) { - void *dbh; - - wl_mode = wl_default; - - dbh = db_open(filepath, cCombined, aCombined, dbmode); - if (dbh != NULL) - wl_mode = WL_M_COMBINED; - - if (dbh == NULL) { - dbh = db_open(filepath, cSeparate, aSeparate, dbmode); - if (dbh != NULL) - wl_mode = WL_M_SEPARATE; - } - - if (dbhp != NULL) /* If non-null, handle is wanted */ - *dbhp = dbh; - else /* else not wanted - close file */ - if (dbh != NULL) - db_close(dbh, true); - } - - return; -} - void open_wordlists(dbmode_t mode) { wordlist_t *list; @@ -221,6 +194,8 @@ do { retry = 0; for (list = word_lists; list != NULL; list = list->next) { + if (wl_mode == WL_M_UNKNOWN) + set_wordlist_mode(list->filepath); switch (wl_mode) { case WL_M_COMBINED: list->dbh = db_open(list->filepath, cCombined, aCombined, mode); @@ -229,8 +204,8 @@ list->dbh = db_open(list->filepath, cSeparate, aSeparate, mode); break; case WL_M_UNKNOWN: - set_wordlist_mode(&list->dbh, list->filepath, mode); - break; + fprintf(stderr, "Invalid wordlist mode.\n"); + exit(2); } if (list->dbh == NULL) { int err = errno; @@ -296,14 +271,44 @@ break; case WL_M_SEPARATE: count = 2; - ok = (build_path(filepaths[0], sizeof(FILEPATH), path, WORDLIST) == 0 && - build_path(filepaths[1], sizeof(FILEPATH), path, WORDLIST) == 0); + ok = (build_path(filepaths[0], sizeof(FILEPATH), path, SPAMFILE) == 0 && + build_path(filepaths[1], sizeof(FILEPATH), path, GOODFILE) == 0); break; case WL_M_UNKNOWN: fprintf(stderr, "Invalid wordlist mode.\n"); exit(2); } return count; +} + +static bool check_wordlist_paths(const char *path, size_t count, const char **names) +{ + size_t i; + for (i = 0; i < count ; i += 1) { + char filepath[PATH_LEN]; + struct stat statbuf; + const char *name = names[i]; + build_path(filepath, sizeof(filepath), path, name); + memset(&statbuf, 0, sizeof(statbuf)); + if (stat(filepath, &statbuf) != 0) + return false; + } + return true; +} + +void set_wordlist_mode(const char *filepath) +{ + if (wl_mode != WL_M_UNKNOWN) + return; + + wl_mode = wl_default; + if (check_wordlist_paths(filepath, cCombined, aCombined)) + wl_mode = WL_M_COMBINED; + else + if (check_wordlist_paths(filepath, cSeparate, aSeparate)) + wl_mode = WL_M_SEPARATE; + + return; } void set_good_weight(double weight) Index: wordlists.h =================================================================== RCS file: /cvsroot/bogofilter/bogofilter/src/wordlists.h,v retrieving revision 1.5 retrieving revision 1.6 diff -u -d -r1.5 -r1.6 --- wordlists.h 19 Jul 2003 19:12:22 -0000 1.5 +++ wordlists.h 20 Jul 2003 19:05:53 -0000 1.6 @@ -40,7 +40,7 @@ extern wordlist_t *word_lists; void incr_wordlist_mode(void); -void set_wordlist_mode(void **dbh, const char *filepath, dbmode_t dbmode); +void set_wordlist_mode(const char *filepath); size_t build_wordlist_paths(char **filepaths, const char *path); int setup_wordlists(const char* dir, priority_t precedence); Index: bogoutil.c =================================================================== RCS file: /cvsroot/bogofilter/bogofilter/src/bogoutil.c,v retrieving revision 1.42 retrieving revision 1.43 diff -u -d -r1.42 -r1.43 --- bogoutil.c 20 Jul 2003 02:45:10 -0000 1.42 +++ bogoutil.c 20 Jul 2003 19:05:53 -0000 1.43 @@ -374,7 +374,7 @@ void *dbh; - set_wordlist_mode(NULL, dir, DB_READ); + set_wordlist_mode(dir); count = build_wordlist_paths(filepaths, dir); /* XXX FIXME: deadlock possible */ |