1 /* <@LICENSE> 2 * Licensed to the Apache Software Foundation (ASF) under one or more 3 * contributor license agreements. See the NOTICE file distributed with 4 * this work for additional information regarding copyright ownership. 5 * The ASF licenses this file to you under the Apache License, Version 2.0 6 * (the "License"); you may not use this file except in compliance with 7 * the License. You may obtain a copy of the License at: 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 * </@LICENSE> 17 */ 18 19 #ifndef UTILS_H 20 #define UTILS_H 21 22 #define UNUSED_VARIABLE(v) ((void)(v)) 23 24 #include <stddef.h> 25 26 extern int libspamc_timeout; /* default timeout in seconds */ 27 extern int libspamc_connect_timeout; /* Sep 8, 2008 mrgus: default connect timeout in seconds */ 28 29 #ifdef SPAMC_SSL 30 #include <openssl/crypto.h> 31 #include <openssl/pem.h> 32 #include <openssl/ssl.h> 33 #include <openssl/err.h> 34 #else 35 typedef int SSL; /* fake type to avoid conditional compilation */ 36 typedef int SSL_CTX; 37 typedef int SSL_METHOD; 38 #endif 39 40 #ifdef _WIN32 41 #include <winsock.h> 42 /* 43 * BSD-compatible socket error codes for Win32 44 */ 45 #undef EWOULDBLOCK /* override definition in errno.h */ 46 #define EWOULDBLOCK WSAEWOULDBLOCK 47 #undef EINPROGRESS /* override definition in errno.h */ 48 #define EINPROGRESS WSAEINPROGRESS 49 #undef EALREADY /* override definition in errno.h */ 50 #define EALREADY WSAEALREADY 51 #undef ENOTSOCK /* override definition in errno.h */ 52 #define ENOTSOCK WSAENOTSOCK 53 #undef EDESTADDRREQ /* override definition in errno.h */ 54 #define EDESTADDRREQ WSAEDESTADDRREQ 55 #undef EMSGSIZE /* override definition in errno.h */ 56 #define EMSGSIZE WSAEMSGSIZE 57 #undef EPROTOTYPE /* override definition in errno.h */ 58 #define EPROTOTYPE WSAEPROTOTYPE 59 #undef ENOPROTOOPT /* override definition in errno.h */ 60 #define ENOPROTOOPT WSAENOPROTOOPT 61 #undef EPROTONOSUPPORT /* override definition in errno.h */ 62 #define EPROTONOSUPPORT WSAEPROTONOSUPPORT 63 #undef ESOCKTNOSUPPORT /* override definition in errno.h */ 64 #define ESOCKTNOSUPPORT WSAESOCKTNOSUPPORT 65 #undef EOPNOTSUPP /* override definition in errno.h */ 66 #define EOPNOTSUPP WSAEOPNOTSUPP 67 #undef EPFNOSUPPORT /* override definition in errno.h */ 68 #define EPFNOSUPPORT WSAEPFNOSUPPORT 69 #undef EAFNOSUPPORT /* override definition in errno.h */ 70 #define EAFNOSUPPORT WSAEAFNOSUPPORT 71 #undef EADDRINUSE /* override definition in errno.h */ 72 #define EADDRINUSE WSAEADDRINUSE 73 #undef EADDRNOTAVAIL /* override definition in errno.h */ 74 #define EADDRNOTAVAIL WSAEADDRNOTAVAIL 75 #undef ENETDOWN /* override definition in errno.h */ 76 #define ENETDOWN WSAENETDOWN 77 #undef ENETUNREACH /* override definition in errno.h */ 78 #define ENETUNREACH WSAENETUNREACH 79 #undef ENETRESET /* override definition in errno.h */ 80 #define ENETRESET WSAENETRESET 81 #undef ECONNABORTED /* override definition in errno.h */ 82 #define ECONNABORTED WSAECONNABORTED 83 #undef ECONNRESET /* override definition in errno.h */ 84 #define ECONNRESET WSAECONNRESET 85 #undef ENOBUFS /* override definition in errno.h */ 86 #define ENOBUFS WSAENOBUFS 87 #undef EISCONN /* override definition in errno.h */ 88 #define EISCONN WSAEISCONN 89 #undef ENOTCONN /* override definition in errno.h */ 90 #define ENOTCONN WSAENOTCONN 91 #undef ESHUTDOWN /* override definition in errno.h */ 92 #define ESHUTDOWN WSAESHUTDOWN 93 #undef ETOOMANYREFS /* override definition in errno.h */ 94 #define ETOOMANYREFS WSAETOOMANYREFS 95 #undef ETIMEDOUT /* override definition in errno.h */ 96 #define ETIMEDOUT WSAETIMEDOUT 97 #undef ECONNREFUSED /* override definition in errno.h */ 98 #define ECONNREFUSED WSAECONNREFUSED 99 #undef ELOOP /* override definition in errno.h */ 100 #define ELOOP WSAELOOP 101 /* #define ENAMETOOLONG WSAENAMETOOLONG */ 102 #define EHOSTDOWN WSAEHOSTDOWN 103 #undef EHOSTUNREACH /* override definition in errno.h */ 104 #define EHOSTUNREACH WSAEHOSTUNREACH 105 /* #define ENOTEMPTY WSAENOTEMPTY */ 106 #define EPROCLIM WSAEPROCLIM 107 #define EUSERS WSAEUSERS 108 #define EDQUOT WSAEDQUOT 109 #define ESTALE WSAESTALE 110 #define EREMOTE WSAEREMOTE 111 112 /* NOTE: these are not errno constants in UNIX! */ 113 #define HOST_NOT_FOUND WSAHOST_NOT_FOUND 114 #define TRY_AGAIN WSATRY_AGAIN 115 #define NO_RECOVERY WSANO_RECOVERY 116 #define NO_DATA WSANO_DATA 117 118 #endif 119 120 int fd_timeout_read(int fd, char fdflag, void *, size_t); 121 int ssl_timeout_read(SSL * ssl, void *, int); 122 123 /* uses size_t instead of socket_t because socket_t not defined on some platforms */ 124 int timeout_connect (int sockfd, const struct sockaddr *serv_addr, size_t addrlen); 125 126 /* these are fd-only, no SSL support */ 127 int full_read(int fd, char fdflag, void *buf, int min, int len); 128 int full_read_ssl(SSL * ssl, unsigned char *buf, int min, int len); 129 int full_write(int fd, char fdflag, const void *buf, int len); 130 131 #endif 132