1 /* Copyright (c) 2014 Alexander Lamaison <alexander.lamaison@gmail.com>
2 * Copyright (c) 1999-2011 Douglas Gilbert. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms,
5 * with or without modification, are permitted provided
6 * that the following conditions are met:
7 *
8 * Redistributions of source code must retain the above
9 * copyright notice, this list of conditions and the
10 * following disclaimer.
11 *
12 * Redistributions in binary form must reproduce the above
13 * copyright notice, this list of conditions and the following
14 * disclaimer in the documentation and/or other materials
15 * provided with the distribution.
16 *
17 * Neither the name of the copyright holder nor the names
18 * of any other contributors may be used to endorse or
19 * promote products derived from this software without
20 * specific prior written permission.
21 *
22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
23 * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
24 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
25 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
27 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
28 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
29 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
30 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
31 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
32 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
33 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
34 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
35 * OF SUCH DAMAGE.
36 */
37
38 // Note: This file is modified to work with SSH package for U++.
39 // If you get errors during compilation, try modifying the definitons below:
40
41 /* Headers */
42 #define HAVE_INTTYPES_H
43 #define HAVE_STDLIB_H
44 #if defined(flagGCC) || defined(flagCLANG)
45 #define HAVE_ERRNO_H
46 #define HAVE_UNISTD_H
47 #define HAVE_SYS_TIME_H
48 #endif
49 #ifdef flagPOSIX
50 #define HAVE_ARPA_INET_H
51 #define HAVE_MEMORY_H
52 #define HAVE_SYS_SELECT_H
53 #define HAVE_SYS_UIO_H
54 #define HAVE_SYS_SOCKET_H
55 #define HAVE_FCNTL_H
56 #define HAVE_SYS_IOCTL_H
57 #define HAVE_SYS_UN_H
58 #elif flagWIN32
59 #define HAVE_WINDOWS_H
60 #define HAVE_WS2TCPIP_H
61 #define HAVE_WINSOCK2_H
62 #define HAVE_NTDEF_H
63 #define HAVE_NTSTATUS_H
64 #endif
65
66 /* DEBUG */
67 #ifdef flagLIBSSH2TRACE
68 #define LIBSSH2DEBUG
69 #endif
70
71 /*
72 * Z compression requires plugin/z on Windows and for static builds.
73 * Below patch, which applies to libssh2/comp.c, allows using the
74 * Z compression on Upp::SSH Win32 and for static builds.
75 */
76 #if defined(flagWIN32) || defined(flagNOSO)
77 #define UPP_ZLIB_INCLUDE <plugin/z/lib/zlib.h>
78 #else
79 #define UPP_ZLIB_INCLUDE <zlib.h>
80 #endif
81
82 /* Let us enable Z compression. */
83 #define LIBSSH2_HAVE_ZLIB
84
85 /* Upp/SSH package uses OpenSSL by default. */
86 #define LIBSSH2_OPENSSL
87
88 // #undef LIBSSH2_WINCNG
89 // #undef LIBSSH2_MBEDTLS
90
91 /* Types */
92 #define HAVE_LONGLONG
93
94 /* Functions */
95 #ifdef flagPOSIX
96 #define HAVE_POLL
97 #endif
98
99 #if defined(flagGCC) || defined(flagCLANG)
100 #define HAVE_GETTIMEOFDAY
101 #endif
102
103 /*#define HAVE_INET_ADDR*/
104
105 #define HAVE_SELECT
106 #define HAVE_SOCKET
107 #define HAVE_STRTOLL
108 //#define HAVE_STRTOI64
109 #define HAVE_SNPRINTF
110
111 /* OpenSSL functions */
112 #define HAVE_EVP_AES_128_CTR
113 #define LIBSSH2_DH_GEX_NEW
114
115 /* Socket non-blocking support */
116 #ifdef flagPOSIX
117 #define HAVE_O_NONBLOCK
118 #elif flagWIN32
119 #define HAVE_IOCTLSOCKET
120 #endif
121 /* #undef HAVE_FIONBIO */
122 /* #undef HAVE_IOCTLSOCKET_CASE */
123 /* #undef HAVE_SO_NONBLOCK */
124 /* #undef HAVE_DISABLED_NONBLOCKING */
125
126 /* snprintf not in Visual Studio CRT and _snprintf dangerously incompatible.
127 We provide a safe wrapper if snprintf not found */
128 //#ifdef flagMSC
129 //#undef HAVE_SNPRINTF
130 //#endif
131
132 #ifndef HAVE_SNPRINTF
133 #include <stdio.h>
134 #include <stdarg.h>
135 /* Want safe, 'n += snprintf(b + n ...)' like function. If cp_max_len is 1
136 * then assume cp is pointing to a null char and do nothing. Returns number
137 * number of chars placed in cp excluding the trailing null char. So for
138 * cp_max_len > 0 the return value is always < cp_max_len; for cp_max_len
139 * <= 0 the return value is 0 (and no chars are written to cp). */
snprintf(char * cp,int cp_max_len,const char * fmt,...)140 static int snprintf(char * cp, int cp_max_len, const char * fmt, ...)
141 {
142 va_list args;
143 int n;
144
145 if (cp_max_len < 2)
146 return 0;
147 va_start(args, fmt);
148 n = vsnprintf(cp, cp_max_len, fmt, args);
149 va_end(args);
150 return (n < cp_max_len) ? n : (cp_max_len - 1);
151 }
152
153 #define HAVE_SNPRINTF
154 #endif