[c5c522c] | 1 | /* $Id: libdspam.h,v 1.27 2011/06/28 00:13:48 sbajic Exp $ */ |
---|
| 2 | |
---|
| 3 | /* |
---|
| 4 | DSPAM |
---|
| 5 | COPYRIGHT (C) 2002-2012 DSPAM PROJECT |
---|
| 6 | |
---|
| 7 | This program is free software: you can redistribute it and/or modify |
---|
| 8 | it under the terms of the GNU Affero General Public License as |
---|
| 9 | published by the Free Software Foundation, either version 3 of the |
---|
| 10 | License, or (at your option) any later version. |
---|
| 11 | |
---|
| 12 | This program is distributed in the hope that it will be useful, |
---|
| 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 15 | GNU Affero General Public License for more details. |
---|
| 16 | |
---|
| 17 | You should have received a copy of the GNU Affero General Public License |
---|
| 18 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
---|
| 19 | |
---|
| 20 | */ |
---|
| 21 | |
---|
| 22 | #ifdef __cplusplus |
---|
| 23 | extern "C" { |
---|
| 24 | #endif |
---|
| 25 | |
---|
| 26 | #ifdef HAVE_CONFIG_H |
---|
| 27 | #include <auto-config.h> |
---|
| 28 | #endif |
---|
| 29 | |
---|
| 30 | #ifndef _LIBDSPAM_H |
---|
| 31 | # define _LIBDSPAM_H |
---|
| 32 | |
---|
| 33 | #include "diction.h" |
---|
| 34 | #include "nodetree.h" |
---|
| 35 | #include "error.h" |
---|
| 36 | #include "storage_driver.h" |
---|
| 37 | #include "decode.h" |
---|
| 38 | #include "libdspam_objects.h" |
---|
| 39 | #include "heap.h" |
---|
| 40 | #include "tokenizer.h" |
---|
| 41 | |
---|
| 42 | #define LIBDSPAM_VERSION_MAJOR 3 |
---|
| 43 | #define LIBDSPAM_VERSION_MINOR 6 |
---|
| 44 | #define LIBDSPAM_VERSION_PATCH 0 |
---|
| 45 | |
---|
| 46 | #define BNR_SIZE 3 |
---|
| 47 | |
---|
| 48 | /* Public API */ |
---|
| 49 | |
---|
| 50 | int libdspam_init(const char *); |
---|
| 51 | int libdspam_shutdown(void); |
---|
| 52 | |
---|
| 53 | DSPAM_CTX * dspam_init (const char *username, const char *group, |
---|
| 54 | const char *home, int operating_mode, u_int32_t flags); |
---|
| 55 | |
---|
| 56 | DSPAM_CTX * dspam_create (const char *username, const char *group, |
---|
| 57 | const char *home, int operating_mode, u_int32_t flags); |
---|
| 58 | |
---|
| 59 | int dspam_attach (DSPAM_CTX *CTX, void *dbh); |
---|
| 60 | int dspam_detach (DSPAM_CTX *CTX); |
---|
| 61 | int dspam_process (DSPAM_CTX * CTX, const char *message); |
---|
| 62 | |
---|
| 63 | int dspam_getsource (DSPAM_CTX * CTX, char *buf, size_t size); |
---|
| 64 | int dspam_addattribute (DSPAM_CTX * CTX, const char *key, const char *value); |
---|
| 65 | int dspam_clearattributes (DSPAM_CTX * CTX); |
---|
| 66 | |
---|
| 67 | void dspam_destroy (DSPAM_CTX * CTX); |
---|
| 68 | |
---|
| 69 | |
---|
| 70 | /* Private functions */ |
---|
| 71 | |
---|
| 72 | int _ds_calc_stat (DSPAM_CTX * CTX, ds_term_t term, struct _ds_spam_stat *s, |
---|
| 73 | int type, struct _ds_spam_stat *bnr_tot); |
---|
| 74 | int _ds_calc_result (DSPAM_CTX * CTX, ds_heap_t sort, ds_diction_t diction); |
---|
| 75 | int _ds_increment_tokens(DSPAM_CTX *CTX, ds_diction_t diction); |
---|
| 76 | int _ds_operate (DSPAM_CTX * CTX, char *headers, char *body); |
---|
| 77 | int _ds_process_signature (DSPAM_CTX * CTX); |
---|
| 78 | int _ds_factor (struct nt *set, char *token_name, float value); |
---|
| 79 | int _ds_instantiate_bnr (DSPAM_CTX *CTX, ds_diction_t patterns, |
---|
| 80 | struct nt *order, char identifier); |
---|
| 81 | ds_diction_t _ds_apply_bnr (DSPAM_CTX *CTX, ds_diction_t diction); |
---|
| 82 | void _ds_factor_destroy (struct nt *factors); |
---|
| 83 | |
---|
| 84 | |
---|
| 85 | /* Standard Return Codes */ |
---|
| 86 | |
---|
| 87 | #ifndef EINVAL |
---|
| 88 | # define EINVAL -0x01 |
---|
| 89 | /* Invalid call or parms - already initialized or shutdown */ |
---|
| 90 | #endif |
---|
| 91 | #define EUNKNOWN -0x02 /* Unknown/unexpected error */ |
---|
| 92 | #define EFILE -0x03 /* File error */ |
---|
| 93 | #define ELOCK -0x04 /* Lock error */ |
---|
| 94 | #define EFAILURE -0x05 /* Failed to perform operation */ |
---|
| 95 | |
---|
| 96 | #define FALSE_POSITIVE(A) \ |
---|
| 97 | (A->classification == DSR_ISINNOCENT && A->source == DSS_ERROR) |
---|
| 98 | #define SPAM_MISS(A) \ |
---|
| 99 | (A->classification == DSR_ISSPAM && A->source == DSS_ERROR) |
---|
| 100 | #define SIGNATURE_NULL(A) (A->signature == NULL) |
---|
| 101 | |
---|
| 102 | #endif /* _LIBDSPAM_H */ |
---|
| 103 | |
---|
| 104 | #ifdef __cplusplus |
---|
| 105 | } |
---|
| 106 | #endif |
---|