Mixe for Privacy and Anonymity in the Internet
StdAfx.h
Go to the documentation of this file.
1  /*
2 Copyright (c) 2000, The JAP-Team
3 All rights reserved.
4 Redistribution and use in source and binary forms, with or without modification,
5 are permitted provided that the following conditions are met:
6 
7  - Redistributions of source code must retain the above copyright notice,
8  this list of conditions and the following disclaimer.
9 
10  - Redistributions in binary form must reproduce the above copyright notice,
11  this list of conditions and the following disclaimer in the documentation and/or
12  other materials provided with the distribution.
13 
14  - Neither the name of the University of Technology Dresden, Germany nor the names of its contributors
15  may be used to endorse or promote products derived from this software without specific
16  prior written permission.
17 
18 
19 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS
20 OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
21 AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS
22 BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
24 OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
25 IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
27 */
28 
29 // stdafx.h : Include-Datei fuer Standard-System-Include-Dateien,
30 // oder projektspezifische Include-Dateien, die haeufig benutzt, aber
31 // in unregelmaessigen Abstaenden geaendert werden.
32 
33 #if !defined(AFX_STDAFX_H__9A5B051F_FF3A_11D3_9F5E_000001037024__INCLUDED_)
34 #define AFX_STDAFX_H__9A5B051F_FF3A_11D3_9F5E_000001037024__INCLUDED_
35 
36 #define MIX_VERSION "00.12.08"
37 
38 // set to "true" if this is a testing/development version which is not meant for prodictive use
39 #define MIX_VERSION_TESTING true
40 
41 #define MIX_VERSION_TESTING_TEXT "This is a testing/development version. Please do not expect it to work in a productive environment, and don't be surprised if you get unpredictive results or segmentation faults. If you don't like experiments, go and get the stable code.\n"
42 
43 #include "doxygen.h"
44 
45 #define STR_HELPER(x) #x
46 #define STR(x) STR_HELPER(x)
47 
48 
49 
50 #if defined(DEBUG)|| defined(_DEBUG)
51  #undef DEBUG
52  #undef _DEBUG
53  #define DEBUG
54  #define _DEBUG
55 #endif
56 
57 //#define LOG_TRAFFIC_PER_USER //Log detail for traffic per user
58 //#define LOG_CHANNEL //Log detail for traffic per channel
59 //#define LOG_PACKET_TIMES //computes statistics about the processing time each packet needs
60 //#define LOG_DIALOG
61 //#define COMPRESSED_LOGS
62 //#define DO_TRACE
63 //#define PSEUDO_LOG
64 //#define DELAY_CHANNELS //to enable max channel bandwidth
65 //#define DELAY_USERS //to enable max per user bandwidth
66 //#define DELAY_CHANNELS_LATENCY //to enable min latency per channel
67 //#define HAVE_EPOLL //define if you have epoll support on your (Linux) system
68 //#define MXML_DOM //define this if you wnat to use the Mix-XML library (www.minixml.org) instead of the default Xerces-C library
69 //#define COUNTRY_STATS //collect stats about countries users come from
70 //#define ONLY_LOCAL_PROXY //define to build only the local proxy (aka JAP)
71 /* LERNGRUPPE: define this to get dynamic mixes */
72 //#define DYNAMIC_MIX
73 //#define SDTFA // specific logic needed by SDTFA, http://www.sdtfa.com
74 //#define USE_OPENSSL_GCM //define if you wnat to use the GCM implementation provided by OpenSSL (>=1.0.1)
75 
76 #define NO_INFOSERVICE_TRHEADS
77 
78 //#define LASTMIX_CHECK_MEMORY // only for internal debugging purpose
79 //#define PRINT_THREAD_STACK_TRACE //Usefull for debugging output of stack trace if mix dies...
80 //#define ENABLE_GPERFTOOLS_CPU_PROFILER //Enables the usage of the Goggle GPerfTools CPU Profiler for profiling the operation of the Mix
81 //#define ENABLE_GPERFTOOLS_HEAP_CHECKER //Enables the usage of the Goggle GPerfTools heap checker for detecting memory leaks
82 
83 //#define DATA_RETENTION_LOG //define if you need to store logs according to German data retention
84 //#define INTEL_IPP_CRYPTO //define if you want to use the crypto routines of the Intel Performance Primitives
85 //#define __UNIT_TEST__ //define if you want to compile the unit tests
86 //#define EXPORT_ASYM_PRIVATE_KEY //define if you want to be able to export/import the private key of an asymmetric key (only used for debugging purposes..)
87 //#define SET_STATIC_MUX_SOCKET_KEY //define if you want to set the MuxSocket keys to all zeros (only used for debugging/testing purposes..)
88 //#define LOG_CRIME
89 //#define PAYMENT //to enable payment support, now use configure --enable-payment..
90 //#define NO_LOOPACCEPTUSER //to disable user accept thread for First Mix
91 
92 //#define USE_POOL
93 //#define NEW_MIX_TYPE // to enable the new 1:x mix protocol
94 //#define WITH_CONTROL_CHANNELS_TEST //enable a Test control Channel
95 #define NEW_FLOW_CONTROL //enable for the new flow control mechanism --> now enabled by default (i.e. can not be disbaled anymore!)
96 #define NEW_CHANNEL_ENCRYPTION //enable the new protcol version which uses RSA-OAEP for key transport and two keys for upstream/downstream channel cryption (--> now enabled by default (i.e. can not be disbaled anymore!)
97 //#define AES_NI // use the AES NI instructions
98 //#define SYM_CHANNEL_CIPHER_CTR //enable CTR mode instead of OFB for symmetric cipher used for channel encryption (this is especially helpfull to increase performance on mobile device clients)
99 //#define WITH_INTEGRITY_CHECK //enable AES-GCM encryption for data channels
100 
101 //define WITH_SGX //should the Intel SGX support be enabled
102 
103 //#define REPLAY_DETECTION // enable to prevent replay of mix packets
104 //#define HAVE_ECC // define if you have (and wnat to use) ECC cryptography
105 //#define SSL_HACK //???
106 
107 //#define ANON_DEBUG_MODE //if defined this Mix operates in AN.ON protocol debug mode, which means that a lot of things are logged which should not be logged in productive mode. So NEVER enable this in productive environments!
108 //#define NO_ENCRYPTION //!!!WARNING!! if defined, no encryption will happen! Only use in BSL-4 laboratory!
109 //#define MUXSOCKET_CIPHER_NO_ENCRYPTION //!!!WARNING!! if defined, no encryption on the MuxSocket will happen! Only use in BSL-4 laboratory!
110 //#define FAST_PROCESSING //make all polling as fast as possible, may lead to very high processor utilisation in case of low traffic/workload; usefull for performance measurements
111 //#define MULTI_THREADED_PACKET_PROCESSING //utilise multiple threads for packet processing, which could lead to a performacne improvement on multi core machines
112 //#define __BUILD_AS_SHADOW_PLUGIN__ //define if you want to compile the Mix as a plugin for the Shadow simulator
113 
114 //#define DO_MIDDLE_MIX_BENCHMARK //define if you want to build a Mix dummy which will only do some benchmarking of a middle Mix
115 
116 #if !defined(PRINT_THREAD_STACK_TRACE) && defined (DEBUG)&& ! defined(ONLY_LOCAL_PROXY)
117  #define PRINT_THREAD_STACK_TRACE
118 #endif
119 
120 #if defined(LOG_DIALOG)
121  #ifndef LOG_CHANNEL
122  #define LOG_CHANNEL
123  #endif
124  #ifndef COUNTRY_STATS
125  #define COUNTRY_STATS
126  #endif
127 #endif
128 #if (defined(LOG_CHANNEL)) && !defined(LOG_TRAFFIC_PER_USER)
129  #define LOG_TRAFFIC_PER_USER
130 #endif
131 
132 #ifdef COUNTRY_STATS
133  #define LOG_COUNTRIES_INTERVALL 6 //how often to log the country stats (multiplied by 10 seconds)
134 #endif
135 
136 #ifdef DELAY_CHANNELS
137  #ifndef DELAY_CHANNEL_TRAFFIC
138  #define DELAY_CHANNEL_TRAFFIC 10000 //Traffic in bytes after which (download direction) the channel is delayed
139  #endif
140  //Delay is at the moment constant and calculate as
141  // 1000/DELAY_BUCKET_GROW_INTERVALL*DELAY_BUCKET_GROW bytes/s
142  #ifndef DELAY_CHANNEL_KBYTE_PER_SECOND
143  #define DELAY_BUCKET_GROW_INTERVALL 100 //Time in ms
144  #define DELAY_BUCKET_GROW PAYLOAD_SIZE //Grow in bytes
145  //so we have around 10 KByte/s at the moment
146  #else
147  #define DELAY_BUCKET_GROW_INTERVALL (1000/DELAY_CHANNEL_KBYTE_PER_SECOND) //Time in ms
148  #define DELAY_BUCKET_GROW PAYLOAD_SIZE //Grow in bytes
149  #endif
150 #endif
151 
152 #ifdef DELAY_USERS
153  #ifndef DELAY_USERS_TRAFFIC
154  #define DELAY_USERS_TRAFFIC 0 //Traffic in packets after which (download direction) the user is delayed
155  #endif
156  //Delay is at the moment constant and calculate as
157  // 1000/DELAY_BUCKET_GROW_INTERVALL*DELAY_BUCKET_GROW bytes/s
158  #ifndef DELAY_USERS_PACKETS_PER_SECOND
159  #define DELAY_USERS_BUCKET_GROW_INTERVALL 100 //Time in ms
160  #define DELAY_USERS_BUCKET_GROW 10 //Grow in packets
161  //so we have around 10 KByte/s at the moment
162  #else
163  #define DELAY_USERS_BUCKET_GROW_INTERVALL 1000 //Time in ms
164  #define DELAY_USERS_BUCKET_GROW DELAY_USERS_PACKETS_PER_SECOND //Grow in bytes
165  #endif
166 #endif
167 
168 #ifndef DELAY_CHANNELS_LATENCY
169  #define DELAY_CHANNEL_LATENCY 0 //min latency defaults to 0 milliseconds
170 #endif
171 
172 #if defined LASTMIX_CHECK_MEMORY && ! defined(QUEUE_SIZE_LOG)
173  #define QUEUE_SIZE_LOG
174 #endif
175 
176 #define REPLAY_TIMESTAMP_PROPAGATION_INTERVALL 1 //How often (in minutes) should the current replay timestamps be propagate
177 
178 #define KEEP_ALIVE_TRAFFIC_RECV_WAIT_TIME 75000 //How long to wait for a Keep-Alive (or any other packet)
179  //before we believe that the connection is broken (in ms)
180 #define KEEP_ALIVE_TRAFFIC_SEND_WAIT_TIME 65000 //How long to wait before we sent a dummy a Keep-Alive-Traffic
181 
182 #ifdef LOG_CRIME //Law Enforcement and AN.ON protocol debuggin cannot be done at the same time...
183  #undef ANON_DEBUG_MODE
184 #endif
185 
186 #if defined(PAYMENT) && ! defined(SSL_HACK)
187  #define SSL_HACK
188 #endif
189 
190 //#define REPLAY_DATABASE_PERFORMANCE_TEST //to perform a performance test of the replay db
191 //Some constants
192 #define MAX_POLLFD 8192 //How many sockets to support at max
193 
194 #define CLIENTS_PER_IP 100 //how many jap connections per IP are allowed?
195 #define CHANNELS_PER_CLIENT 500 //how many channels per jap client are allowed?
196 
197 #define FIRST_MIX_RECEIVE_SYM_KEY_FROM_JAP_TIME_OUT 40000 //Timout in waiting for login information to receive from JAP (10 seconds)
198 #define LAST_MIX_TO_PROXY_CONNECT_TIMEOUT 2000 //Connection timeout for last mix to proxy connections 2 Seconds...
199 #define AI_LOGIN_SO_TIMEOUT (UINT32) 10000 //5 Seconds...
200 #define LAST_MIX_TO_PROXY_SEND_TIMEOUT (UINT32)5000 //5 Seconds...
201 #define MIX_TO_INFOSERVICE_TIMEOUT 30000 //How long to wait when communicating with the InfoService? (ms)
202 #define NUM_LOGIN_WORKER_TRHEADS 10//How many working threads for login *do not change this until you really know that you are doing!* ??
203 #define MAX_LOGIN_QUEUE 500 //how many waiting entries in the login queue *do not change this until you really know that you are doing!*??
204 
205 #if defined(PAYMENT) || defined(MANIOQ)
206  #define MAX_USER_SEND_QUEUE 100000 //How many bytes could be in each User's send queue, before we suspend the belonging channels
207  #define MAX_DATA_PER_CHANNEL 100000
208  #define USER_SEND_BUFFER_RESUME 10000
209 #else
210  //EXPERIMENTAL: reduce user-buffers for free mixes by factor 10
211  #define MAX_USER_SEND_QUEUE 1000000 //How many bytes could be in each User's send queue, before we suspend the belonging channels
212  #define MAX_DATA_PER_CHANNEL 1000000
213  #define USER_SEND_BUFFER_RESUME 100000
214 #endif
215 
216 #define PAYMENT_ACCOUNT_CERT_TIMEOUT 180 //Timeout for receiving the Payment certificate in seconds
217 #define CLEANUP_THREAD_SLEEP_INTERVAL 60 //sleep interval for payment blocked ip list
218 #define BALANCE_REQUEST_TIMEOUT 60 //Timeout for Balance requests
219 
220 #define MAX_SIGNATURE_ELEMENTS 10 // maximum of interpreted XML signature elements
221 
222 #define FLOW_CONTROL_SENDME_HARD_LIMIT 1600000 //last mix stops sending after this unacked packets
223 #define FLOW_CONTROL_SENDME_SOFT_LIMIT 800000 //last mix expect to get a 'SENDME' after this unacked packets
224 
225 #if defined(PAYMENT) || defined(MANIOQ)
226  #define MAX_READ_FROM_PREV_MIX_QUEUE_SIZE 10000000
227  #define MAX_READ_FROM_NEXT_MIX_QUEUE_SIZE 10000000 //How many bytes could be in the incoming queue ??
228  #define MAX_MIXIN_SEND_QUEUE_SIZE 10000000
229  #define MAX_NEXT_MIX_QUEUE_SIZE 10000000
230 #else
231  //EXPERIMENTAL: reduce intermix-buffers for free mixes by factor 10
232  #define MAX_READ_FROM_PREV_MIX_QUEUE_SIZE 10000000000
233  #define MAX_READ_FROM_NEXT_MIX_QUEUE_SIZE 10000000000 //How many bytes could be in the incoming queue ??
234  #define MAX_MIXIN_SEND_QUEUE_SIZE 10000000000
235  #define MAX_NEXT_MIX_QUEUE_SIZE 10000000000
236 #endif
237 //#define FORCED_DELAY
238 //#define MIN_LATENCY 250
239 
240 #define DEFAULT_INFOSERVICE "141.76.45.37"
241 
242 #ifndef MIX_POOL_SIZE
243  #define MIX_POOL_SIZE 10 //packets in the Mix pool
244 #endif
245 #define MIX_POOL_TIMEOUT 200 //home long to wait (in ms) before a dummy is put in the pool
246 #define DUMMY_CHANNEL 0
247 
248 #define FM_PACKET_STATS_LOG_INTERVALL 1 //Intervall in Minutes for loggin packet stats for the first Mix
249 #define LM_PACKET_STATS_LOG_INTERVALL 1 //Intervall in Minutes for loggin packet stats for the last Mix
250 
251 #define MIX_CASCADE_PROTOCOL_VERSION_0_1_2 12 //with integrity check and new channel encryption
252 #define MIX_CASCADE_PROTOCOL_VERSION_0_1_1 11 //with integrity check and new channel encryption --> never worked correctly
253 #define MIX_CASCADE_PROTOCOL_VERSION_0_1_0 10 //with new channel encryption
254 //#define MIX_CASCADE_PROTOCOL_VERSION_0_9 9 //with new payment protocol
255 #define MIX_CASCADE_PROTOCOL_VERSION_0_8 8 //with replay detection + control channels + first mix symmetric
256 #define MIX_CASCADE_PROTOCOL_VERSION_0_7 7 //with replay detection + control channels (obsolete)
257 //#define MIX_CASCADE_PROTOCOL_VERSION_0_6 6 //with new flow control (not used, because flow control is a last Mix only issue)
258 #define MIX_CASCADE_PROTOCOL_VERSION_0_5 5 //with control channels (obsolte - allway with control channels)
259 #define MIX_CASCADE_PROTOCOL_VERSION_0_4 4 //symmetric communication to first mix -> new default protocol
260 #define MIX_CASCADE_PROTOCOL_VERSION_0_3 3 //with reply detection [deprecated - not in use anymore!]
261 #define MIX_CASCADE_PROTOCOL_VERSION_0_2 2 //old normal protocol [deprecated - not in use anymore!]
262 
263 #ifdef REPLAY_DETECTION
264  #define MIX_CASCADE_PROTOCOL_VERSION "0.81"
265 //#elif defined(PAYMENT)
266  //#define MIX_CASCADE_PROTOCOL_VERSION "0.9"
267 #elif defined (WITH_INTEGRITY_CHECK)
268  #define MIX_CASCADE_PROTOCOL_VERSION "0.12"
269 #else
270  #define MIX_CASCADE_PROTOCOL_VERSION "0.10" //"0.10tc"
271 #endif
272 
273 
274 #define PAYMENT_VERSION "2.0"
275 
276 #define INCLUDE_MIDDLE_MIX
277 #ifdef ONLY_MIDDLE_MIX
278  #define ONLY_LOCAL_PROXY
279  #define INCLUDE_MIDDLE_MIX
280  #define INCLUDE_LAST_MIX
281  #define INCLUDE_FIRST_MIX
282 #endif
283 
284 #if defined (_WIN32) &&!defined(__CYGWIN__)
285  //For Visual C++ #if defined(_MSC_VER)
286  //For Borland C++ #if defined(__BCPLUSPLUS__)
287  #define _CRT_SECURE_NO_DEPRECATE
288  #define _CRT_SECURE_NO_WARNINGS
289  #define WIN32_LEAN_AND_MEAN
290  #if _MSC_VER > 1000
291  #pragma once
292  #endif // _MSC_VER > 1000
293  #define _WIN32_WINDOWS 0x0410
294  #include <winsock2.h>
295  #include <Ws2tcpip.h>
296  //#if defined(_MSC_VER) &&defined (_DEBUG)
297  // #include <crtdbg.h>
298  // #define HAVE_CRTDBG
299  //#endif
300  #define socklen_t int
301  #define MSG_NOSIGNAL 0
302  #include <io.h>
303  #include <conio.h>
304  #include <sys/timeb.h>
305  #include <process.h>
306  #include "wepoll/wepoll.h"
307  #ifdef _MSC_VER
308  #define ftime _ftime
309  #define timeb _timeb
310  #define NEED_GMTIME_R_WINDOWS
311  struct tm * gmtime_r(const time_t *timep, struct tm *result);
312 
313  #endif
314  #define HAVE_MALLOC_H
315  #define SET_NET_ERROR(x)
316  #define GET_NET_ERROR (WSAGetLastError())
317  #define GET_NET_ERROR_STR(x) ("Unknown error")
318  #define RESETERROR errno=0;
319  #define GETERROR (errno)
320  #define ERR_INTERN_TIMEDOUT WSAETIMEDOUT
321  #define ERR_INTERN_CONNREFUSED WSAECONNREFUSED
322  #define ERR_INTERN_WOULDBLOCK WSAEWOULDBLOCK
323  #define ERR_INTERN_SOCKET_CLOSED WSAENOTSOCK
324  #define MSG_DONTWAIT 0
325  #define O_NONBLOCK 0
326  #define O_BLOCK 0
327  #define SHUT_RDWR SD_BOTH
328  #define HAVE_VSNPRINTF
329  #define HAVE_SNPRINTF
330  #if _MSC_VER <1500
331  #define vsnprintf _vsnprintf
332  #endif
333  #if _MSC_VER <1900
334  #define snprintf _snprintf
335  #endif
336  #define getpid _getpid
337  #define strncasecmp _strnicmp
338  #define open _open
339  #define myfilewrite _write
340  #define close _close
341  #define read _read
342  #define access _access
343  #define getch _getch
344  #define alloca _alloca
345  #define HAVE_PTHREAD_MUTEX_INIT
346  #define HAVE_PTHREAD_COND_INIT
347  #define HAVE_SEM_INIT
348  #define BYTE_ORDER_LITTLE_ENDIAN
349  #define HAVE_EPOLL
350  #define EPOLL_HANDLE HANDLE
351  #define S_IRUSR _S_IREAD
352  #define S_IWUSR _S_IWRITE
353 #else
354  //__linux is not defined on power pc so we define our own __linux if __linux__ is defined
355  #if defined(__linux__) && !defined(__linux)
356  #define __linux
357  #endif
358  #if defined(CWDEBUG)
359  #include <libcw/sysd.h>
360  #include <libcw/debug.h>
361  #endif
362 
363  #ifdef HAVE_CONFIG_H
364  #include <config.h>
365  #ifndef HAVE_SOCKLEN_T
366  typedef int socklen_t;
367  #endif
368  #else
369  #define HAVE_UNIX_DOMAIN_PROTOCOL
370  #define HAVE_VSNPRINTF
371  #define HAVE_SNPRINTF
372  #define HAVE_POLL
373  #define HAVE_O_SYNC
374  #define HAVE_PTHREAD_MUTEX_INIT
375  #define HAVE_PTHREAD_COND_INIT
376  #define HAVE_SEM_INIT
377  #ifndef __linux
378  #define HAVE_TCP_KEEPALIVE
379  #endif
380  #ifdef __sgi
381  #undef HAVE_TCP_KEEPALIVE
382  #endif
383  #ifdef __FreeBSD__
384  #undef HAVE_TCP_KEEPALIVE
385  #undef HAVE_O_SYNC
386  #define HAVE_O_FSYNC
387  #endif
388  #ifdef __CYGWIN__
389  #undef HAVE_TCP_KEEPALIVE
390  #define MSG_DONTWAIT 0
391  #endif
392  #if !defined(__FreeBSD__)&&!defined(__linux)
393  typedef int socklen_t;
394  #endif
395  #ifndef O_BINARY
396  #define O_BINARY 0
397  #endif
398  #ifndef MAX_PATH
399  #define MAX_PATH 4096
400  #endif
401  #ifdef __sgi
402  #undef HAVE_VSNPRINTF
403  #undef HAVE_SNPRINTF
404  #include <alloca.h>
405  #endif
406  #if !defined( __linux) &&!defined(__CYGWIN__)
407  #include <sys/filio.h>
408  #define MSG_NOSIGNAL 0
409  #endif
410  #endif //Have config.h
411 
412  //Byte order defines
413  #if !defined(BYTE_ORDER_LITTLE_ENDIAN) && ! defined(BYTE_ORDER_BIG_ENDIAN)
414  #ifndef BYTE_ORDER
415  #error "You MUST define either BYTE_ORDER_BIG_ENDIAN or BYTE_ORDER_LITTLE_ENDIAN"
416  #else
417  #if BYTE_ORDER == BIG_ENDIAN
418  #define BYTE_ORDER_BIG_ENDIAN
419  #else
420  #define BYTE_ORDER_LITTLE_ENDIAN
421  #endif
422  #endif // BYTE_ORDER
423  #endif //not byte order given
424 
425  #ifdef HAVE_FILIO
426  #include <sys/filio.h>
427  #endif
428  #ifdef HAVE_POLL
429  #include <poll.h>
430  #endif
431  #ifdef HAVE_EPOLL
432  #include <sys/epoll.h>
433  #define EPOLL_HANDLE SINT32
434  #define epoll_close close
435  #endif
436  #include <sys/ioctl.h>
437  #include <sys/types.h>
438  #include <sys/socket.h>
439  #include <pwd.h>
440  #include <sys/un.h>
441  #include <sys/time.h>
442  #include <netinet/in.h>
443  #include <arpa/inet.h>
444  #include <netdb.h>
445  #include <unistd.h>
446  #include <stdlib.h>
447  #include <strings.h>
448  #include <syslog.h>
449  #include <stdarg.h>
450  #include <memory.h>
451  #include <sys/resource.h>
452  #include <sys/wait.h>
453  #include <termios.h>
454  #include <fnmatch.h>
455  #include <dirent.h>
456  #include <ctype.h>
457 
458  typedef struct sockaddr SOCKADDR;
460  #define SOCKET int
461  typedef struct hostent HOSTENT;
462  #define ioctlsocket(a,b,c) ioctl(a,b,c)
463  #define closesocket(s) close(s)
464  #define SOCKET_ERROR -1
465  #define INVALID_SOCKET -1
466  #define SD_RECEIVE 0
467  #define SD_SEND 1
468  #define SD_BOTH 2
469  #define GET_NET_ERROR (errno)
470  #define SET_NET_ERROR(x) (errno = x)
471  #define GET_NET_ERROR_STR(x) (errno == E_TIMEDOUT ? "Connection timed out." : (errno == E_SOCKETCLOSED ? "Socket is closed." : strerror(x)))
472  #define RESETERROR errno=0;
473  #define GETERROR (errno)
474  #define ERR_INTERN_TIMEDOUT ETIMEDOUT
475  #define ERR_INTERN_CONNREFUSED ECONNREFUSED
476  #define ERR_INTERN_WOULDBLOCK EAGAIN
477  #define ERR_INTERN_SOCKET_CLOSED EBADF
478  #ifndef INADDR_NONE
479  #define INADDR_NONE -1
480  #endif
481  #ifndef AF_LOCAL
482  #define AF_LOCAL AF_UNIX
483  #endif
484  #if !defined(HAVE_MSG_DONTWAIT)&&!defined(MSG_DONTWAIT)
485  #define MSG_DONTWAIT 0
486  #endif
487  #ifndef S_IREAD
488  #define S_IREAD S_IRUSR
489  #endif
490  #ifndef S_IWRITE
491  #define S_IWRITE S_IWUSR
492  #endif
493  #define myfilewrite write
494 #endif //WIn32 ?
495 
496 #include "basetypedefs.h"
497 
498 #ifdef HAVE_MALLOC_H
499  #include <malloc.h>
500 #endif
501 
502 
503 #include <assert.h>
504 
505 #include <pthread.h>
506 //the following definition are just for threading support beside pthread
507 #undef USE_SEMAPHORE //normally we do not need semaphores
508 #ifdef HAVE_PTHREAD_COND_INIT
509  #define HAVE_PTHREAD_CV //normally we use the pthread conditional variables
510 #endif
511 #ifdef HAVE_PTHREAD_MUTEX_INIT
512  #define HAVE_PTHREAD_MUTEXES //normally we use the pthread mutexs
513 #endif
514 
515 #if !defined(HAVE_PTHREAD_CV) || !defined (HAVE_PTHREAD_MUTEXES) //if we do not have pthread mutexes or cvs we emulate them with semphores
516  #define USE_SEMAPHORE
517 #endif
518 
519 #ifdef HAVE_SEM_INIT
520  #define HAVE_PTHREAD_SEMAPHORE //normally we use pthread semaphores
521 #endif
522 
523 #ifdef USE_SEMAPHORE
524  #ifdef HAVE_PTHREAD_SEMAPHORE
525  #include <semaphore.h>
526  #endif
527 #endif
528 
529 #ifdef OS_TUDOS
530  #define Assert
531  #define THREAD_RETURN void
532  #define THREAD_RETURN_ERROR return
533  #define THREAD_RETURN_SUCCESS return
534  #include <l4/thread/thread.h>
535  #include <l4/util/macros.h>
536  #include <l4/env/errno.h>
537  #undef Assert
538  #undef ASSERT
539 #else
540  #define THREAD_RETURN void*
541  #define THREAD_RETURN_ERROR return(NULL)
542  #define THREAD_RETURN_SUCCESS return (NULL)
543 #endif
544 
545 #ifndef DEBUG
546  #define ASSERT(cond,msg)
547 #else
548  #define ASSERT(cond,msg) {if(!(cond)){CAMsg::printMsg(LOG_DEBUG,"ASSERT: %s (File: %s, Line: %u)\n",msg,__FILE__,__LINE__);}}
549 #endif
550 
551 #if defined(HAVE_VSNPRINTF) && defined(HAVE_SNPRINTF)
552 #define WITHOUT_TRIO //we do not need trio, if we have native versions of (v)snprintf
553 #endif
554 
555 
556 //For Google Test Framework Unit Tests
557 #ifdef __GOOGLE_UNIT_TEST__
558 #include <gtest/gtest.h>
559 #endif
560 
561 
562 #include <stdio.h>
563 #include <time.h>
564 #include <sys/types.h>
565 #include <fcntl.h>
566 #include <limits.h>
567 #include <sys/stat.h>
568 #include <signal.h>
569 #include <errno.h>
570 #include "trio/trio.hpp"
571 #include "trio/triostr.hpp"
572 #include "popt/system.h"
573 #include "popt/popt.h"
574 #include <openssl/rsa.h>
575 #include <openssl/aes.h>
576 #include <openssl/rand.h>
577 #include <openssl/evp.h>
578 #ifdef USE_OPENSSL_GCM
579  extern "C"
580  {
581  #include <openssl/modes.h>
582  }
583 #endif
584 #if !defined ONLY_LOCAL_PROXY || defined INCLUDE_MIDDLE_MIX
585  #include <openssl/x509v3.h>
586  #include <openssl/pkcs12.h>
587  #include <openssl/dsa.h>
588 #endif
589 #if !defined ONLY_LOCAL_PROXY || defined INCLUDE_FIRST_MIX
590  #include <openssl/md5.h>
591 #endif
592 #ifndef ONLY_LOCAL_PROXY
593  #include <openssl/asn1.h>
594  #include <openssl/ssl.h>
595  #include <openssl/sha.h>
596  #include <openssl/md5.h>
597 #endif
598 
599 #include "errorcodes.hpp"
600 #include "typedefs.hpp"
601 
602 
603 //For DOM
604 #ifdef MXML_DOM
605  #include <mxml.h>
606  #include "xml/dom/mxml/mxmlDOM.hpp"
607 #else
608 #include <util/XercesDefs.hpp>
609 #include <util/PlatformUtils.hpp>
610 #include <util/XMLString.hpp>
611 #include <util/XMLUniDefs.hpp>
612 #include <framework/XMLFormatter.hpp>
613 #include <util/TranscodingException.hpp>
614 #include <framework/MemBufInputSource.hpp>
615 
616 /*#if (XERCES_VERSION_MAJOR >1)
617  #include <dom/deprecated/DOM.hpp>
618  #include <dom/deprecated/DOMParser.hpp>
619 #else
620  #include <dom/DOM.hpp>
621  #include <parsers/DOMParser.hpp>
622 #endif
623 */
624 #include <dom/DOM.hpp>
625 #include <parsers/XercesDOMParser.hpp>
626 
627 #if (_XERCES_VERSION >= 20200)
628  XERCES_CPP_NAMESPACE_USE
629 #endif
630 
631 #endif //wich DOM-Implementation to use?
632 
633 //For large file support
634 #ifndef O_LARGEFILE
635  #define O_LARGEFILE 0
636 #endif
637 
638 //O_SYNC defined ???
639 #ifndef HAVE_O_SYNC
640  #ifdef HAVE_O_FSYNC
641  #define O_SYNC O_FSYNC
642  #else
643  #define O_SYNC 0
644  #endif
645 #endif
646 
647 //The min() macro
648 #ifndef min
649  #define min(a,b) (( (a) < (b) ) ? (a):(b) )
650 #endif
651 
652 //The max() macro
653 #ifndef max
654  #define max(a,b) (((a) > (b) ) ? (a):(b))
655 #endif
656 
657 //For MySQL
658 #if defined(COUNTRY_STATS)
659  #ifdef HAVE_CONFIG_H
660  #ifdef HAVE_MYSQL_MYSQL_H
661  #include <mysql/mysql.h>
662  #else
663  #include <mysql.h>
664  #endif
665  #else //HAVE_CONFIG_H
666  #include <mysql/mysql.h>
667  #endif
668 #endif
669 
670 //For Payment
671 #ifdef PAYMENT
672  #ifdef HAVE_CONFIG_H
673  #ifdef HAVE_POSTGRESQL_LIBPQ_FE_H
674  #include <postgresql/libpq-fe.h>
675  #elif defined(HAVE_PGSQL_LIBPQ_FE_H)
676  #include <pgsql/libpq-fe.h>
677  #else
678  #include <libpq-fe.h>
679  #endif
680  #elif defined(__FreeBSD__) ||defined (_WIN32)
681  #include <libpq-fe.h>
682  #else
683  #include <postgresql/libpq-fe.h>
684  #endif
685 #endif
686 //Compressed Logs
687 #ifdef COMPRESSED_LOGS
688 #include <zlib.h>
689 #endif
690 
691 
692 
693 //Mix Version Info as multiline String
694 #ifdef XERCES_FULLVERSIONDOT
695  #define MY_XERCES_VERSION XERCES_FULLVERSIONDOT
696 #elif defined(Xerces_DLLVersionStr)
697  #define MY_XERCES_VERSION Xerces_DLLVersionStr
698 #else
699  #define MY_XERCES_VERSION "unknown"
700 #endif
701 
702 #ifdef ENABLE_GPERFTOOLS_CPU_PROFILER
703  #include <gperftools/profiler.h>
704 #endif
705 
706 #ifdef INTEL_IPP_CRYPTO
707  #include <ippcp.h>
708 #endif
709 
710 #ifdef PAYMENT
711  #define PAYMENT_VERSION_INFO " (payment)"
712  #define PAYMENT_COMPATIBILITY "Payment"
713 #else
714  #define PAYMENT_VERSION_INFO
715  #define PAYMENT_COMPATIBILITY
716 #endif
717 
718 #ifdef DATA_RETENTION_LOG
719  #define DATA_RETENTION_LOG_INFO " (with data retention log)"
720 #else
721  #define DATA_RETENTION_LOG_INFO
722 #endif
723 
724 #define NEW_FLOW_CONTROL_INFO " (with new flow control)"
725 #define NEW_FLOW_CONTROL_COMPATIBILITY "NewFlowControl"
726 
727 #define NEW_CHANNEL_ENCRYPTION_INFO " (with enhanced channel encryption)"
728 #define NEW_CHANNEL_ENCRYPTION_COMPATIBILITY "NewChannelEncryption"
729 
730 #ifdef WITH_INTEGRITY_CHECK
731  #define WITH_INTEGRITY_CHECK_INFO " (with integrity check for data channels)"
732  #define WITH_INTEGRITY_CHECK_COMPATIBILITY "WithIntegrityCheck"
733 #else
734  #define WITH_INTEGRITY_CHECK_INFO
735  #define WITH_INTEGRITY_CHECK_COMPATIBILITY
736 #endif
737 
738 #ifdef DELAY_CHANNELS
739  #define WITH_DELAY_CHANNELS_INFO " (with delay channels)"
740 #else
741  #define WITH_DELAY_CHANNELS_INFO
742 #endif
743 
744 #ifdef DELAY_USERS
745  #define WITH_DELAY_USERS_INFO " (with delay users)"
746 #else
747  #define WITH_DELAY_USERS_INFO
748 #endif
749 
750 #ifndef MXML_DOM
751  #define XML_LIB_VERSION "\nUsing Xerces-C: " MY_XERCES_VERSION
752 #else
753  #ifdef MXML_MAJOR_VERSION
754  #define MAKE_A_STRING(x) #x
755  #define TOSTRING(x) MAKE_A_STRING(x)
756  #define XML_LIB_VERSION "\nUsing Mini-XML: " TOSTRING(MXML_MAJOR_VERSION) "." TOSTRING(MXML_MINOR_VERSION)
757  #else
758  #define XML_LIB_VERSION "\nUsing Mini-XML: unknown"
759  #endif
760 #endif
761 #define MIX_VERSION_INFO "Mix-Version: " MIX_VERSION PAYMENT_VERSION_INFO DATA_RETENTION_LOG_INFO NEW_FLOW_CONTROL_INFO NEW_CHANNEL_ENCRYPTION_INFO WITH_INTEGRITY_CHECK_INFO WITH_DELAY_CHANNELS_INFO WITH_DELAY_USERS_INFO "\nUsing: " OPENSSL_VERSION_TEXT XML_LIB_VERSION "\n"
762 #define MIX_VERSION_COMPATIBILITY PAYMENT_COMPATIBILITY " " NEW_FLOW_CONTROL_COMPATIBILITY " " NEW_CHANNEL_ENCRYPTION_COMPATIBILITY " " WITH_INTEGRITY_CHECK_COMPATIBILITY
763 
764 #include "controlchannelids.h"
765 #include "gcm/gcm.h"
766 #ifdef PAYMENT
767  #define MAX_ACCOUNTNUMBER 999999999999ULL
768  #define MIN_ACCOUNTNUMBER 100000000000ULL
769  #define ACCOUNT_NUMBER_SIZE 12
770 #endif
771 
772 //#include <vld.h>
773 #endif // !defined(AFX_STDAFX_H__9A5B051F_FF3A_11D3_9F5E_000001037024__INCLUDED_)
struct hostent HOSTENT
Definition: StdAfx.h:461
SOCKADDR * LPSOCKADDR
Definition: StdAfx.h:459
int socklen_t
Definition: StdAfx.h:393
struct sockaddr SOCKADDR
Definition: StdAfx.h:458