[c5c522c] | 1 | /* $Id: util.h,v 1.20 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 _UTIL_H |
---|
| 23 | # define _UTIL_H |
---|
| 24 | |
---|
| 25 | #ifdef HAVE_CONFIG_H |
---|
| 26 | #include <auto-config.h> |
---|
| 27 | #endif |
---|
| 28 | |
---|
| 29 | #include <sys/types.h> |
---|
| 30 | #include <sys/socket.h> |
---|
| 31 | #include <netinet/in.h> |
---|
| 32 | #include <arpa/inet.h> |
---|
| 33 | |
---|
| 34 | #ifndef _WIN32 |
---|
| 35 | #include <pwd.h> |
---|
| 36 | #endif |
---|
| 37 | |
---|
| 38 | void chomp (char *string); |
---|
| 39 | char * ltrim (char *str); |
---|
| 40 | char * rtrim (char *str); |
---|
| 41 | int lc (char *buff, const char *string); |
---|
| 42 | #ifndef HAVE_STRCASESTR |
---|
| 43 | char * strcasestr (const char *, const char *); |
---|
| 44 | #endif |
---|
| 45 | |
---|
| 46 | #define ALLTRIM(str) ltrim(rtrim(str)) |
---|
| 47 | |
---|
| 48 | #ifndef HAVE_STRSEP |
---|
| 49 | char *strsep (char **stringp, const char *delim); |
---|
| 50 | #endif |
---|
| 51 | |
---|
| 52 | #ifndef HAVE_STRLCPY |
---|
| 53 | size_t strlcpy (char *, const char *, size_t); |
---|
| 54 | size_t strlcat (char *, const char *, size_t); |
---|
| 55 | #endif |
---|
| 56 | |
---|
| 57 | /* |
---|
| 58 | * Specialized Functions |
---|
| 59 | * Utilities specialized for DSPAM functions. |
---|
| 60 | * |
---|
| 61 | * _ds_userdir_path() |
---|
| 62 | * Generates the path for files within DSPAM's filesystem, according to the |
---|
| 63 | * filesystem structure specified at configure time. |
---|
| 64 | * |
---|
| 65 | * _ds_prepare_path_for() |
---|
| 66 | * Creates any necessary subdirectories to support the supplied path |
---|
| 67 | * |
---|
| 68 | * _ds_get_crc64() |
---|
| 69 | * Generates the CRC of the supplied string, using CRC64 |
---|
| 70 | * |
---|
| 71 | * _ds_compute_complexity() |
---|
| 72 | * Calculates the complexity of a token based on its nGram depth |
---|
| 73 | * |
---|
| 74 | * _ds_compute_sparse() |
---|
| 75 | * Calculates the number of sparse skips in a token |
---|
| 76 | * |
---|
| 77 | * _ds_compute_weight() |
---|
| 78 | * Calculates the markovian weight of a token |
---|
| 79 | * |
---|
| 80 | * _ds_compute_weight_osb() |
---|
| 81 | * Calculates the OSB/OSBF/WINNOW weight of a token |
---|
| 82 | */ |
---|
| 83 | |
---|
| 84 | #ifndef HAVE_STRTOK_R |
---|
| 85 | char * strtok_r(char *s1, const char *s2, char **lasts); |
---|
| 86 | #endif |
---|
| 87 | |
---|
| 88 | #ifndef HAVE_INET_NTOA_R |
---|
| 89 | unsigned int i2a |
---|
| 90 | (char* dest,unsigned int x); |
---|
| 91 | char *inet_ntoa_r |
---|
| 92 | (struct in_addr in, char *buf, int len); |
---|
| 93 | #endif |
---|
| 94 | |
---|
| 95 | #ifdef EXT_LOOKUP |
---|
| 96 | int verified_user; |
---|
| 97 | #endif |
---|
| 98 | |
---|
| 99 | const char * _ds_userdir_path ( |
---|
| 100 | char *buff, |
---|
| 101 | const char *home, |
---|
| 102 | const char *filename, |
---|
| 103 | const char *extension); |
---|
| 104 | |
---|
| 105 | int _ds_prepare_path_for (const char *filename); |
---|
| 106 | int _ds_compute_complexity (const char *token); |
---|
| 107 | int _ds_compute_sparse (const char *token); |
---|
| 108 | int _ds_compute_weight (const char *token); |
---|
| 109 | int _ds_compute_weight_osb (const char *token); |
---|
| 110 | char *_ds_truncate_token (const char *token); |
---|
| 111 | |
---|
| 112 | int _ds_extract_address( |
---|
| 113 | char *buf, |
---|
| 114 | const char *address, |
---|
| 115 | size_t len); |
---|
| 116 | |
---|
| 117 | double _ds_gettime(void); |
---|
| 118 | |
---|
| 119 | void timeout(void); |
---|
| 120 | |
---|
| 121 | int _ds_get_fcntl_lock (int fd); |
---|
| 122 | int _ds_free_fcntl_lock (int fd); |
---|
| 123 | |
---|
| 124 | unsigned long long _ds_getcrc64 |
---|
| 125 | (const char *); |
---|
| 126 | int _ds_pow |
---|
| 127 | (int base, unsigned int exp); |
---|
| 128 | int _ds_pow2 |
---|
| 129 | (int exp); |
---|
| 130 | double chi2Q |
---|
| 131 | (double x, int v); |
---|
| 132 | float _ds_round |
---|
| 133 | (float n); |
---|
| 134 | |
---|
| 135 | int _ds_validate_address |
---|
| 136 | (const char *address); |
---|
| 137 | #endif /* _UTIL_H */ |
---|