forked from Wind4/vlmcsd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtypes.h
395 lines (319 loc) · 8.83 KB
/
types.h
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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
#ifndef __types_h
#define __types_h
#ifndef _GNU_SOURCE
#define _GNU_SOURCE
#endif
#ifndef _CRT_SECURE_NO_WARNINGS
#define _CRT_SECURE_NO_WARNINGS
#endif
#ifndef CONFIG
#define CONFIG "config.h"
#endif // CONFIG
#include CONFIG
#if defined(NO_INTERNAL_DATA) && defined(NO_EXTERNAL_DATA)
#error NO_INTERAL_DATA and NO_EXTERNAL_DATA cannot be used together
#endif
#if defined(_WIN32)
//#ifndef USE_MSRPC
#include <winsock2.h>
//#include <ws2tcpip.h>
//#endif // USE_MSRPC
#endif // defined(_WIN32)
#define ANDROID_API_LEVEL ANDROID_HELPER1(__ANDROID_API__)
#define ANDROID_HELPER1(s) ANDROID_HELPER2(s)
#define ANDROID_HELPER2(s) #s
#if !_WIN32 && !__CYGWIN__
#if !__minix__
#include <pthread.h>
#endif // !__minix__
#define __declspec(x) __attribute__((__visibility__("default")))
#endif
#if !defined(EXTERNAL)
#define EXTERNAL dllimport
#endif
#ifdef __cplusplus
#define EXTERNC extern "C"
#else
#define EXTERNC
#endif
#include <stdlib.h>
//#include <limits.h>
#include <stdint.h>
#ifdef __ANDROID__
#include <android/api-level.h>
#endif // __ANDROID__
#ifndef _WIN32
#include <unistd.h>
#include <netinet/in.h>
#endif // _WIN32
#if __linux__ // Some versions of uclibc do not define IP_FREEBIND in the correct header file
#ifndef IP_FREEBIND
#define IP_FREEBIND 15
#endif // IP_FREEBIND
#endif // __linux__
#ifdef NO_EXTERNAL_DATA
#ifndef UNSAFE_DATA_LOAD
#define UNSAFE_DATA_LOAD
#endif // UNSAFE_DATA_LOAD
#endif // NO_EXTERNAL_DATA
#if (IP_BINDANY || IP_FREEBIND || IPV6_BINDANY || IP_NONLOCALOK) && !defined(NO_FREEBIND) && !defined(USE_MSRPC) && !defined(SIMPLE_SOCKETS)
#define HAVE_FREEBIND 1
#endif
#if !defined(NO_GETIFADDRS) && !defined(USE_MSRPC) && !defined(SIMPLE_SOCKETS) && !defined(NO_SOCKETS) && !defined(NO_PRIVATE_IP_DETECT)
#define HAVE_GETIFADDR 1
#endif
//#if (__minix__ || defined(NO_SOCKETS)) && !defined(NO_STRICT_MODES)
//#define NO_STRICT_MODES
//#endif // __minix__ && !defined(NO_STRICT_MODES)
#if (defined(NO_STRICT_MODES) || defined(NO_SOCKETS)) && !defined(NO_CLIENT_LIST)
#define NO_CLIENT_LIST
#endif // defined(NO_STRICT_MODES) || defined(NO_SOCKETS) && !defined(NO_CLIENT_LIST)
#if !_WIN32 && !__CYGWIN__
#if !defined(_POSIX_THREADS) || (!defined(_POSIX_THREAD_PROCESS_SHARED) && !defined(USE_THREADS) && !__ANDROID__)
#ifndef NO_CLIENT_LIST
#define NO_CLIENT_LIST
#endif // !NO_CLIENT_LIST
#endif // !defined(_POSIX_THREADS) || (!defined(_POSIX_THREAD_PROCESS_SHARED) && !defined(USE_THREADS))
#if !defined(_POSIX_THREADS) && !defined(NO_LIMIT)
#define NO_LIMIT
#endif // !defined(POSIX_THREADS) && !defined(NO_LIMIT)
#endif // !_WIN32 && !__CYGWIN__
#ifndef alloca
#ifdef __GNUC__
#define alloca(x) __builtin_alloca(x)
#endif // __GNUC__
#endif // alloca
#ifndef alloca
#ifdef __has_builtin // clang feature test
#if __has_builtin(__builtin_alloca)
#define alloca(x) __builtin_alloca(x)
#endif // __has_builtin(__builtin_alloca)
#endif // __has_builtin
#endif // alloca
#ifndef alloca
#if !_MSC_VER
#include <alloca.h>
#else
#include <malloc.h>
//#define alloca _malloca
#endif
//#define alloca _malloca
//#endif // _MSC_VER
#endif // alloca
#ifndef __packed
#if _MSC_VER
#define __packed
#else // !_MSC_VER
#define __packed __attribute__((packed))
#endif // !_MSC_VER
#endif
#ifndef __pure
#if _MSC_VER
#define __pure
#else
#define __pure __attribute__((pure))
#endif
#endif
#ifndef __noreturn
#if _MSC_VER
#define __noreturn __declspec(noreturn)
#else
#define __noreturn __attribute__((noreturn))
#endif
#endif
#define restrict __restrict
typedef struct __packed
{
uint16_t val[0];
} PACKED16;
typedef struct __packed
{
uint32_t val[0];
} PACKED32;
typedef struct __packed
{
uint64_t val[0];
} PACKED64;
// Deal with Mingw32-w64 C++ header which defines a _countof that is incompatible with vlmcsd
#define vlmcsd_countof(x) ( sizeof(x) / sizeof(x[0]) )
// PATH_MAX is optional in Posix. We use a default of 260 here
#ifndef PATH_MAX
#ifdef _WIN32
#define PATH_MAX MAX_PATH
#else
#define PATH_MAX 260
#endif // _WIN32
#endif // !PATH_MAX
#if PATH_MAX > 260
#define VLMCSD_PATH_MAX 260
#else
#define VLMCSD_PATH_MAX PATH_MAX
#endif
// Synchronization Objects
// Mutexes
#ifdef USE_THREADS
#if !defined(_WIN32) && !defined(__CYGWIN__)
#define lock_mutex(x) pthread_mutex_lock(x)
#define unlock_mutex(x) pthread_mutex_unlock(x)
#else
#define lock_mutex(x) EnterCriticalSection(x)
#define unlock_mutex(x) LeaveCriticalSection(x)
#endif
#else // !USE_THREADS
//defines to nothing
#define lock_mutex(x)
#define unlock_mutex(x)
#endif // !USE_THREADS
// Semaphores
#ifndef _WIN32
#define semaphore_wait(x) sem_wait(x)
#define semaphore_post(x) sem_post(x)
#else // _WIN32
#define semaphore_wait(x) WaitForSingleObject(x, INFINITE)
#define semaphore_post(x) ReleaseSemaphore(x, 1, NULL)
#endif // _WIN32
// Stupid MingW just uses rand() from msvcrt.dll which uses RAND_MAX of 0x7fff
#if RAND_MAX < 0x7fffffff
#define rand32() ((uint32_t)((rand() << 17) | (rand() << 2) | (rand() & 3)))
#elif RAND_MAX < 0xffffffff
#define rand32(x) ((uint32_t)((rand(x) << 1) | (rand(x) & 1)))
#else
#define rand32(x) (uint32_t)rand(x)
#endif
#if (defined(_WIN32) || defined(__CYGWIN__)) && !defined(NO_SOCKETS)
#define _NTSERVICE
#else
#ifndef NO_TAP
#define NO_TAP
#endif
#endif
#if (defined(__CYGWIN__) || defined(_WIN32) || defined(NO_SOCKETS)) && !defined(NO_SIGHUP)
#define NO_SIGHUP
#endif // (defined(__CYGWIN__) || defined(_WIN32) || defined(NO_SOCKETS)) && !defined(NO_SIGHUP)
#ifdef _WIN32
#ifndef USE_THREADS
#define USE_THREADS
#endif
#endif
#if defined(USE_THREADS)
#define _TLS __thread
#else
#define _TLS
#endif
#define GUID_STRING_LENGTH 36
#if defined(_WIN32)
#include <windows.h>
//#include <VersionHelpers.h>
typedef char* sockopt_t;
/* Unknown Winsock error codes */
#define WSAENODEV -1
// Map VLMCSD error codes to WSAGetLastError() and GetLastError() codes
// Add more if you need them
#define SOCKET_EADDRINUSE WSAEADDRINUSE
#define SOCKET_ENODEV WSAENODEV
#define SOCKET_EADDRNOTAVAIL WSAEADDRNOTAVAIL
#define SOCKET_EACCES WSAEACCES
#define SOCKET_EINVAL WSAEINVAL
#define SOCKET_ENOTSOCK WSAENOTSOCK
#define SOCKET_EINTR WSAEINTR
#define SOCKET_EINPROGRESS WSAEINPROGRESS
#define SOCKET_ECONNABORTED WSAECONNABORTED
#define SOCKET_EALREADY WSAEALREADY
#define VLMCSD_EACCES ERROR_ACCESS_DENIED
#define VLMCSD_EINVAL ERROR_INVALID_PARAMETER
#define VLMCSD_ENOMEM ERROR_OUTOFMEMORY
#define VLMCSD_EPERM ERROR_CAN_NOT_COMPLETE
#define socket_errno WSAGetLastError()
#define socketclose(x) (closesocket(x))
#define vlmcsd_strerror(x) win_strerror(x)
#define VLMCSD_SHUT_RD SD_RECEIVE
#define VLMCSD_SHUT_WR SD_SEND
#define VLMCSD_SHUT_RDWR SD_BOTH
#elif defined(__CYGWIN__)
#include <windows.h>
// Resolve conflicts between OpenSSL and MS Crypto API
#ifdef _CRYPTO_OPENSSL
#undef OCSP_RESPONSE
#undef X509_NAME
#endif
#else
typedef uint32_t DWORD;
typedef uint16_t WORD;
typedef uint8_t BYTE;
typedef uint16_t WCHAR;
typedef int32_t BOOL;
typedef int32_t HRESULT;
#define SUCCEEDED(hr) (((HRESULT)(hr)) >= 0)
#define FAILED(hr) (((HRESULT)(hr)) < 0)
#define S_OK ((HRESULT)0)
#define FALSE 0
#define TRUE !0
typedef struct {
DWORD Data1;
WORD Data2;
WORD Data3;
BYTE Data4[8];
} /*__packed*/ GUID;
typedef struct {
DWORD dwLowDateTime;
DWORD dwHighDateTime;
} /*__packed*/ FILETIME;
#endif // defined(__CYGWIN__)
#ifndef _WIN32
// Map VLMCSD error codes to POSIX codes
// Add more if you need them
#define SOCKET_EADDRINUSE EADDRINUSE
#define SOCKET_ENODEV ENODEV
#define SOCKET_EADDRNOTAVAIL EADDRNOTAVAIL
#define SOCKET_EACCES EACCES
#define SOCKET_EINVAL EINVAL
#define SOCKET_ENOTSOCK ENOTSOCK
#define SOCKET_EINTR EINTR
#define SOCKET_EINPROGRESS EINPROGRESS
#define SOCKET_ECONNABORTED ECONNABORTED
#define SOCKET_EALREADY EALREADY
#define VLMCSD_EACCES EACCES
#define VLMCSD_EINVAL EINVAL
#define VLMCSD_EINTR EINTR
#define VLMCSD_ENOMEM ENOMEM
#define VLMCSD_EPERM EPERM
typedef void* sockopt_t;
#define _countof(x) ( sizeof(x) / sizeof(x[0]) )
#define SOCKET int
#define INVALID_SOCKET -1
#define socket_errno errno
#define socketclose(x) (close(x))
#define vlmcsd_strerror strerror
#define VLMCSD_SHUT_RD SHUT_RD
#define VLMCSD_SHUT_WR SHUT_WR
#define VLMCSD_SHUT_RDWR SHUT_RDWR
#endif // __MINGW__
#define INVALID_UID ((uid_t)~0)
#define INVALID_GID ((gid_t)~0)
#undef IsEqualGUID
#define IsEqualGUID(a, b) ( !memcmp(a, b, sizeof(GUID)) )
#if !defined(__stdcall) && !_MSC_VER
#define __stdcall
#endif
#if !defined(__cdecl) && !_MSC_VER
#define __cdecl
#endif
typedef const char *const * CARGV;
typedef struct {
SOCKET socket;
DWORD RpcAssocGroup;
} CLDATA, *const PCLDATA;
#ifdef _MSC_VER
#define strcasecmp _stricmp
#define strncasecmp _strnicmp
#define vlmcsd_snprintf _snprintf
#define vlmcsd_vsnprintf _vsnprintf
#define vlmcsd_unlink DeleteFile
#define vlmcsd_strtoll _strtoi64
#else // !_MSC_VER
#define vlmcsd_snprintf snprintf
#define vlmcsd_vsnprintf vsnprintf
#define vlmcsd_strtoll strtoll
#define vlmcsd_unlink unlink
#endif // !_MSC_VER
#endif // __types_h