| 1 | /* $Id: bnr.h,v 1.14 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 | #ifndef __BNR_H |
|---|
| 23 | #define __BNR_H |
|---|
| 24 | |
|---|
| 25 | #include <stdio.h> |
|---|
| 26 | #include <stdlib.h> |
|---|
| 27 | #include <string.h> |
|---|
| 28 | #include <ctype.h> |
|---|
| 29 | #include <math.h> |
|---|
| 30 | #ifdef HAVE_UNISTD_H |
|---|
| 31 | #include <unistd.h> |
|---|
| 32 | #endif |
|---|
| 33 | #include <sys/types.h> |
|---|
| 34 | #include <sys/stat.h> |
|---|
| 35 | |
|---|
| 36 | #include "list.h" |
|---|
| 37 | #include "hash.h" |
|---|
| 38 | |
|---|
| 39 | typedef struct { |
|---|
| 40 | long eliminations; |
|---|
| 41 | struct bnr_list *stream; |
|---|
| 42 | struct bnr_hash *patterns; |
|---|
| 43 | char identifier; |
|---|
| 44 | |
|---|
| 45 | struct bnr_list_c c_stream; |
|---|
| 46 | struct bnr_hash_c c_pattern; |
|---|
| 47 | int stream_iter; |
|---|
| 48 | int pattern_iter; |
|---|
| 49 | int window_size; |
|---|
| 50 | float ex_radius; |
|---|
| 51 | float in_radius; |
|---|
| 52 | } BNR_CTX; |
|---|
| 53 | |
|---|
| 54 | BNR_CTX *bnr_init(int type, char identifier); |
|---|
| 55 | int bnr_destroy(BNR_CTX *BTX); |
|---|
| 56 | |
|---|
| 57 | int bnr_add (BNR_CTX *BTX, void *token, float value); |
|---|
| 58 | int bnr_instantiate (BNR_CTX *BTX); |
|---|
| 59 | int bnr_set_pattern (BNR_CTX *BTX, const char *name, float value); |
|---|
| 60 | int bnr_finalize (BNR_CTX *BTX); |
|---|
| 61 | |
|---|
| 62 | void * bnr_get_token (BNR_CTX *BTX, int *eliminated); |
|---|
| 63 | char * bnr_get_pattern (BNR_CTX *BTX); |
|---|
| 64 | |
|---|
| 65 | float _bnr_round(float n); |
|---|
| 66 | |
|---|
| 67 | /* |
|---|
| 68 | BTX_CHAR Character-Based Context |
|---|
| 69 | Treats the passed token identifier as a const char * and |
|---|
| 70 | creates new storage space for each string (strdup) |
|---|
| 71 | |
|---|
| 72 | BTX_INDEX Pointer-Based Context |
|---|
| 73 | Treats the passed token identifier as a void * to your own |
|---|
| 74 | token structure, whose pointers are used only for indexing |
|---|
| 75 | */ |
|---|
| 76 | |
|---|
| 77 | #define BNR_CHAR 0x00 |
|---|
| 78 | #define BNR_INDEX 0x01 |
|---|
| 79 | |
|---|
| 80 | #ifndef EFAILURE |
|---|
| 81 | #define EFAILURE -0x01 |
|---|
| 82 | #endif |
|---|
| 83 | #endif |
|---|