File: util.h

package info (click to toggle)
dspam 3.10.1+dfsg-11
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 6,656 kB
  • sloc: ansic: 26,034; sh: 12,546; perl: 5,469; makefile: 690; sql: 379
file content (137 lines) | stat: -rw-r--r-- 3,332 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
/* $Id: util.h,v 1.20 2011/06/28 00:13:48 sbajic Exp $ */

/*
 DSPAM
 COPYRIGHT (C) 2002-2011 DSPAM PROJECT

 This program is free software: you can redistribute it and/or modify
 it under the terms of the GNU Affero General Public License as
 published by the Free Software Foundation, either version 3 of the
 License, or (at your option) any later version.

 This program is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU Affero General Public License for more details.

 You should have received a copy of the GNU Affero General Public License
 along with this program.  If not, see <http://www.gnu.org/licenses/>.

*/

#ifndef _UTIL_H
#  define _UTIL_H

#ifdef HAVE_CONFIG_H
#include <auto-config.h>
#endif

#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>

#ifndef _WIN32
#include <pwd.h>
#endif

void	chomp	(char *string);
char *	ltrim	(char *str);
char *	rtrim	(char *str);
int	lc	(char *buff, const char *string);
#ifndef HAVE_STRCASESTR
char *  strcasestr (const char *, const char *);
#endif

#define ALLTRIM(str)  ltrim(rtrim(str))

#ifndef HAVE_STRSEP
char *strsep (char **stringp, const char *delim);
#endif

#ifndef HAVE_STRLCPY
size_t strlcpy (char *, const char *, size_t);
size_t strlcat (char *, const char *, size_t);
#endif

/*
 * Specialized Functions
 * Utilities specialized for DSPAM functions.
 *
 *  _ds_userdir_path()
 *    Generates the path for files within DSPAM's filesystem, according to the
 *    filesystem structure specified at configure time.
 *
 *  _ds_prepare_path_for()
 *    Creates any necessary subdirectories to support the supplied path
 *
 *  _ds_get_crc64()
 *    Generates the CRC of the supplied string, using CRC64
 *
 *  _ds_compute_complexity()
 *    Calculates the complexity of a token based on its nGram depth
 *
 *  _ds_compute_sparse()
 *    Calculates the number of sparse skips in a token
 *
 *  _ds_compute_weight()
 *    Calculates the markovian weight of a token
 *
 *  _ds_compute_weight_osb()
 *    Calculates the OSB/OSBF/WINNOW weight of a token
 */

#ifndef HAVE_STRTOK_R
char * strtok_r(char *s1, const char *s2, char **lasts);
#endif

#ifndef HAVE_INET_NTOA_R
unsigned int i2a
  (char* dest,unsigned int x);
char *inet_ntoa_r
  (struct in_addr in, char *buf, int len);
#endif

#ifdef EXT_LOOKUP
  int verified_user;
#endif

const char *	_ds_userdir_path (
  char *buff,
  const char *home,
  const char *filename,
  const char *extension);

int _ds_prepare_path_for   (const char *filename);
int _ds_compute_complexity (const char *token);
int _ds_compute_sparse     (const char *token);
int _ds_compute_weight     (const char *token);
int _ds_compute_weight_osb (const char *token);
char *_ds_truncate_token   (const char *token);

int	_ds_extract_address(
  char *buf, 
  const char *address, 
  size_t len);

double	_ds_gettime(void);

void timeout(void);

int _ds_get_fcntl_lock  (int fd);
int _ds_free_fcntl_lock (int fd);

unsigned long long _ds_getcrc64
  (const char *);
int _ds_pow
  (int base, unsigned int exp);
int _ds_pow2
  (int exp);
double chi2Q
  (double x, int v);
float _ds_round
  (float n);

int _ds_validate_address
  (const char *address);
#endif /* _UTIL_H */