1 /***************************************************************************** 2 3 NAME: 4 common.h -- common definitions and prototypes for bogofilter 5 6 ******************************************************************************/ 7 8 #ifndef COMMON_H 9 #define COMMON_H 10 11 #include "system.h" 12 13 #ifdef HAVE_STDARG_H 14 #include <stdarg.h> 15 #endif 16 #include <stdio.h> 17 18 #include "debug.h" 19 20 #include "bftypes.h" 21 22 #ifdef ENABLE_MEMDEBUG 23 #include "memdebug.h" 24 #else 25 #define MEMDISPLAY do { } while(0) 26 #endif 27 28 /* for easier debugging - can be disabled */ 29 #if 0 30 #define D 0 /* size adjustment */ 31 #define Z(n) /* mark end of string */ 32 #else 33 #define D 1 /* size adjustment */ 34 #define Z(n) n=(byte)'\0' /* mark end of string */ 35 #endif 36 37 /* length of token between these values */ 38 #define MIN_TOKEN_LEN 3 /* default value of min-token-len */ 39 #define MAX_TOKEN_LEN 30 /* default value of max-token-len */ 40 #define MAX_MULTI_TOKEN_LEN 30 /* default value of max-multi-token-len */ 41 #define MAX_PREFIX_LEN 5 /* maximum length of prefix */ 42 #define MUL_TOKEN_CNT 1 /* default value of multi-token-count */ 43 44 typedef enum sh_e { IX_SPAM = 0, /* index for SPAM */ 45 IX_GOOD = 1, /* index for GOOD */ 46 IX_SIZE = 2, /* array size */ 47 IX_UNDF = 3 /* ... undefined */ 48 } sh_t; 49 50 #define max(x, y) (((x) > (y)) ? (x) : (y)) 51 #define min(x, y) (((x) < (y)) ? (x) : (y)) 52 53 #define NL "\n" 54 #define CRLF "\r\n" 55 56 #if defined(PATH_MAX) 57 #define PATH_LEN PATH_MAX 58 #elif defined(MAXPATHLEN) 59 #define PATH_LEN MAXPATHLEN 60 #else 61 #define PATH_LEN 1024 62 #endif 63 64 /** Default database file mode */ 65 #define DS_MODE (mode_t) 0664 66 67 /** Default directory */ 68 #define DIR_MODE (mode_t) 0775 69 70 #define COUNTOF(array) ((sizeof(array)/sizeof(array[0]))) 71 #define MEMBERSIZE(struc, memb) (sizeof ((struc *)0) -> memb) 72 73 typedef unsigned char byte; 74 75 enum dbmode_e { DS_READ = 1, DS_WRITE = 2, DS_LOAD = 8 }; 76 typedef enum dbmode_e dbmode_t; 77 78 #define BIT(n) (1 << n) 79 80 typedef enum rc_e { RC_SPAM = 0, 81 RC_HAM = 1, 82 RC_UNSURE = 2, 83 RC_OK, 84 RC_MORE } rc_t; 85 86 typedef enum ex_e { EX_SPAM = RC_SPAM, 87 EX_HAM = RC_HAM, 88 EX_UNSURE = RC_UNSURE, 89 EX_OK = 0, 90 EX_ERROR = 3 } ex_t; 91 92 typedef enum run_e { 93 RUN_UNKNOWN= 0, 94 RUN_NORMAL = BIT(0), 95 RUN_UPDATE = BIT(1), 96 REG_SPAM = BIT(2), 97 REG_GOOD = BIT(3), 98 UNREG_SPAM = BIT(4), 99 UNREG_GOOD = BIT(5) 100 } run_t; 101 extern run_t run_type; 102 extern bool run_classify; 103 extern bool run_register; 104 105 typedef struct { 106 double mant; 107 int exp; 108 } FLOAT; 109 110 typedef enum priority_e { 111 PR_NONE, /* 0 */ 112 PR_ENV_HOME, /* 1 */ 113 PR_CFG_SITE, /* 2 */ 114 PR_CFG_USER, /* 3 */ 115 PR_CFG_UPDATE, /* 4 */ 116 PR_ENV_BOGO, /* 5 */ 117 PR_COMMAND /* 6 */ 118 } priority_t; 119 120 typedef enum bulk_e { 121 B_NORMAL, 122 B_CMDLINE, 123 B_STDIN 124 } bulk_t; 125 126 /* for transaction flag */ 127 128 typedef enum { 129 T_ERROR = -1, /* -1 for error */ 130 T_DISABLED = 0, /* 0 for no transactions - 0 must mean T_DISABLE 131 for compatibility with dummy functions */ 132 T_ENABLED = 1, /* 1 for transactions */ 133 T_DEFAULT_OFF = 2, /* 2 for off, unless explicity specified */ 134 T_DEFAULT_ON = 3, /* 3 for on, unless explicity specified */ 135 T_DONT_KNOW /* 4 for don't know */ 136 } e_txn; 137 138 /* for encoding (unicode) flag */ 139 140 typedef enum { 141 E_UNKNOWN = 0, /* 0 for not set */ 142 E_RAW = 1, /* 1 for raw text */ 143 E_UNICODE = 2, /* 2 for unicode */ 144 #ifdef ENABLE_UNICODE 145 E_DEFAULT = E_UNICODE 146 #else 147 E_DEFAULT = E_RAW 148 #endif 149 } e_enc; 150 151 #include "globals.h" 152 153 /* Represents the secondary data for a word key */ 154 typedef struct { 155 u_int32_t good; 156 u_int32_t bad; 157 u_int32_t msgs_good; 158 u_int32_t msgs_bad; 159 } wordcnts_t; 160 161 typedef struct { 162 wordcnts_t cnts; 163 double prob; 164 int freq; 165 bool used; 166 } wordprop_t; 167 168 extern void bf_exit(void); 169 170 #define internal_error do { fprintf(stderr, "Internal error in %s:%lu\n", __FILE__, (unsigned long)__LINE__); abort(); } while(0) 171 172 typedef enum e_wordlist_version { 173 ORIGINAL_VERSION = 0, 174 IP_PREFIX = 20040500 /* when IP prefixes were added */ 175 } t_wordlist_version; 176 177 #define CURRENT_VERSION IP_PREFIX 178 179 /* for bogoutil.c and datastore_db_trans.c */ 180 181 typedef enum { M_NONE, M_DUMP, M_LOAD, M_WORD, M_MAINTAIN, M_ROBX, M_HIST, 182 M_LIST_LOGFILES, M_LEAFPAGES, 183 M_RECOVER, M_CRECOVER, M_PURGELOGS, M_VERIFY, M_REMOVEENV, M_CHECKPOINT, 184 M_PAGESIZE } 185 cmd_t; 186 187 #endif 188