File: utils.h

package info (click to toggle)
spamassassin 4.0.2-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 25,732 kB
  • sloc: perl: 89,143; ansic: 5,193; sh: 3,737; javascript: 339; sql: 295; makefile: 209; python: 49
file content (131 lines) | stat: -rw-r--r-- 5,688 bytes parent folder | download | duplicates (15)
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
/* <@LICENSE>
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to you under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at:
 * 
 *     http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * </@LICENSE>
 */

#ifndef UTILS_H
#define UTILS_H

#define UNUSED_VARIABLE(v)	((void)(v))

#include <stddef.h>

extern int libspamc_timeout;	/* default timeout in seconds */
extern int libspamc_connect_timeout;	/* Sep 8, 2008 mrgus: default connect timeout in seconds */

#ifdef SPAMC_SSL
#include <openssl/crypto.h>
#include <openssl/pem.h>
#include <openssl/ssl.h>
#include <openssl/err.h>
#else
typedef int SSL;		/* fake type to avoid conditional compilation */
typedef int SSL_CTX;
typedef int SSL_METHOD;
#endif

#ifdef _WIN32
#include <winsock.h>
/*
 * BSD-compatible socket error codes for Win32
 */
#undef  EWOULDBLOCK      /* override definition in errno.h */
#define EWOULDBLOCK             WSAEWOULDBLOCK
#undef  EINPROGRESS      /* override definition in errno.h */
#define EINPROGRESS             WSAEINPROGRESS
#undef  EALREADY         /* override definition in errno.h */
#define EALREADY                WSAEALREADY
#undef  ENOTSOCK         /* override definition in errno.h */
#define ENOTSOCK                WSAENOTSOCK
#undef  EDESTADDRREQ     /* override definition in errno.h */
#define EDESTADDRREQ            WSAEDESTADDRREQ
#undef  EMSGSIZE         /* override definition in errno.h */
#define EMSGSIZE                WSAEMSGSIZE
#undef  EPROTOTYPE       /* override definition in errno.h */
#define EPROTOTYPE              WSAEPROTOTYPE
#undef  ENOPROTOOPT      /* override definition in errno.h */
#define ENOPROTOOPT             WSAENOPROTOOPT
#undef  EPROTONOSUPPORT  /* override definition in errno.h */
#define EPROTONOSUPPORT         WSAEPROTONOSUPPORT
#undef  ESOCKTNOSUPPORT  /* override definition in errno.h */
#define ESOCKTNOSUPPORT         WSAESOCKTNOSUPPORT
#undef  EOPNOTSUPP       /* override definition in errno.h */
#define EOPNOTSUPP              WSAEOPNOTSUPP
#undef  EPFNOSUPPORT     /* override definition in errno.h */
#define EPFNOSUPPORT            WSAEPFNOSUPPORT
#undef  EAFNOSUPPORT     /* override definition in errno.h */
#define EAFNOSUPPORT            WSAEAFNOSUPPORT
#undef  EADDRINUSE       /* override definition in errno.h */
#define EADDRINUSE              WSAEADDRINUSE
#undef  EADDRNOTAVAIL    /* override definition in errno.h */
#define EADDRNOTAVAIL           WSAEADDRNOTAVAIL
#undef  ENETDOWN         /* override definition in errno.h */
#define ENETDOWN                WSAENETDOWN
#undef  ENETUNREACH      /* override definition in errno.h */
#define ENETUNREACH             WSAENETUNREACH
#undef  ENETRESET        /* override definition in errno.h */
#define ENETRESET               WSAENETRESET
#undef  ECONNABORTED     /* override definition in errno.h */
#define ECONNABORTED            WSAECONNABORTED
#undef  ECONNRESET       /* override definition in errno.h */
#define ECONNRESET              WSAECONNRESET
#undef  ENOBUFS          /* override definition in errno.h */
#define ENOBUFS                 WSAENOBUFS
#undef  EISCONN          /* override definition in errno.h */
#define EISCONN                 WSAEISCONN
#undef  ENOTCONN         /* override definition in errno.h */
#define ENOTCONN                WSAENOTCONN
#undef  ESHUTDOWN        /* override definition in errno.h */
#define ESHUTDOWN               WSAESHUTDOWN
#undef  ETOOMANYREFS     /* override definition in errno.h */
#define ETOOMANYREFS            WSAETOOMANYREFS
#undef  ETIMEDOUT        /* override definition in errno.h */
#define ETIMEDOUT               WSAETIMEDOUT
#undef  ECONNREFUSED     /* override definition in errno.h */
#define ECONNREFUSED            WSAECONNREFUSED
#undef  ELOOP            /* override definition in errno.h */
#define ELOOP                   WSAELOOP
/* #define ENAMETOOLONG            WSAENAMETOOLONG */
#define EHOSTDOWN               WSAEHOSTDOWN
#undef  EHOSTUNREACH     /* override definition in errno.h */
#define EHOSTUNREACH            WSAEHOSTUNREACH
/* #define ENOTEMPTY               WSAENOTEMPTY */
#define EPROCLIM                WSAEPROCLIM
#define EUSERS                  WSAEUSERS
#define EDQUOT                  WSAEDQUOT
#define ESTALE                  WSAESTALE
#define EREMOTE                 WSAEREMOTE

/* NOTE: these are not errno constants in UNIX! */
#define HOST_NOT_FOUND          WSAHOST_NOT_FOUND
#define TRY_AGAIN               WSATRY_AGAIN
#define NO_RECOVERY             WSANO_RECOVERY
#define NO_DATA                 WSANO_DATA

#endif

int fd_timeout_read(int fd, char fdflag, void *, size_t);
int ssl_timeout_read(SSL * ssl, void *, int);

/* uses size_t instead of socket_t because socket_t not defined on some platforms */
int timeout_connect (int sockfd, const struct sockaddr *serv_addr, size_t addrlen);

/* these are fd-only, no SSL support */
int full_read(int fd, char fdflag, void *buf, int min, int len);
int full_read_ssl(SSL * ssl, unsigned char *buf, int min, int len);
int full_write(int fd, char fdflag, const void *buf, int len);

#endif