Mixe for Privacy and Anonymity in the Internet
CALibProxytest.cpp
Go to the documentation of this file.
1 #include "StdAfx.h"
2 #include "CALibProxytest.hpp"
3 #include "CAMuxSocket.hpp"
4 
5 #ifdef SERVER_MONITORING
6  #include "CAStatusManager.hpp"
7 #endif
10 #if defined _DEBUG && ! defined (ONLY_LOCAL_PROXY)
11  CAThreadList* CALibProxytest::m_pThreadList;
12 #endif
13 
15 #if OPENSSL_VERSION_NUMBER < 0x10100000L
16 void CALibProxytest::openssl_locking_callback(int mode, int type, char * /*file*/, int /*line*/)
17  {
18  if (mode & CRYPTO_LOCK)
19  {
21  }
22  else
23  {
25  }
26  }
27 #endif
28 
31 unsigned long openssl_get_thread_id(void)
32  {
33 #ifndef ONLY_LOCAL_PROXY
34  return CAThread::getSelfID();
35 #else
36  return 1;
37 #endif
38  }
39 
40 
43  {
44 #if !defined MXML_DOM
45  XMLPlatformUtils::Initialize();
46 #endif
47  initDOMParser();
48 #if !defined ONLY_LOCAL_PROXY || defined INLUDE_MIDDLE_MIX
49  #if OPENSSL_VERSION_NUMBER < 0x10100000L
50  SSL_library_init();
51  #else
52  OPENSSL_init_ssl(0, NULL);
53  #endif
54 #endif
55 #if OPENSSL_VERSION_NUMBER < 0x10100000L
56  OpenSSL_add_all_algorithms();
57  //It seems that only older versions of OpenSSL need the thred locking callbacks.
58  //But the mor interesting question is: at which version did the change happen?
59  m_pOpenSSLMutexes=new CAMutex[CRYPTO_num_locks()];
60  CRYPTO_set_locking_callback((void (*)(int,int,const char *,int))openssl_locking_callback);
61  CRYPTO_set_id_callback(openssl_get_thread_id);
62 #endif
63 #if defined _DEBUG && ! defined (ONLY_LOCAL_PROXY)
64  m_pThreadList=new CAThreadList();
65  CAThread::setThreadList(m_pThreadList);
66 #endif
67  CAMsg::init();
71  //startup
72  #ifdef _WIN32
73  int err=0;
74  WSADATA wsadata;
75  err=WSAStartup(0x0202,&wsadata);
76  #endif
77  initRandom();
79  return E_SUCCESS;
80 }
81 
84  {
86  #ifdef _WIN32
87  WSACleanup();
88  #endif
89  delete m_pglobalOptions;
90  m_pglobalOptions=NULL;
91 
92  //OpenSSL Cleanup
93 #if OPENSSL_VERSION_NUMBER < 0x10100000L
94  CRYPTO_set_locking_callback(NULL);
95  delete []m_pOpenSSLMutexes;
96  m_pOpenSSLMutexes=NULL;
97 #endif
98  //XML Cleanup
99  //Note: We have to destroy all XML Objects and all objects that uses XML Objects BEFORE
100  //we terminate the XML lib!
101 #ifdef SERVER_MONITORING
103 #endif
105 #if !defined MXML_DOM
106  XMLPlatformUtils::Terminate();
107 #endif
108 
109 #if defined _DEBUG && ! defined (ONLY_LOCAL_PROXY)
110  if(m_pThreadList != NULL)
111  {
112  int nrOfThreads = m_pThreadList->getSize();
113  CAMsg::printMsg(LOG_INFO,"After cleanup %d threads listed.\n", nrOfThreads);
114  if(nrOfThreads > 0)
115  {
116  m_pThreadList->showAll();
117  }
118  delete m_pThreadList;
119  m_pThreadList = NULL;
120  }
121 #endif
124  CAMsg::cleanup();
125  return E_SUCCESS;
126  }
127 
unsigned long openssl_get_thread_id(void)
Callback used by openssl to identify a thread.
SINT32 initRandom()
Definition: CAUtil.cpp:302
void initDOMParser()
Definition: CAUtil.cpp:656
void releaseDOMParser()
Definition: CAUtil.cpp:694
signed int SINT32
Definition: basetypedefs.h:132
static SINT32 cleanup()
do necessary cleanups of libraries etc.
static CAMutex * m_pOpenSSLMutexes
static CACmdLnOptions * m_pglobalOptions
static void openssl_locking_callback(int mode, int type, char *, int)
Callbackfunction for locking required by OpenSSL <1.1.
static SINT32 init()
do necessary initialisations of libraries etc.
static SINT32 init()
Definition: CAMsg.hpp:69
static SINT32 cleanup()
Definition: CAMsg.hpp:77
static SINT32 printMsg(UINT32 typ, const char *format,...)
Writes a given message to the log.
Definition: CAMsg.cpp:251
SINT32 unlock()
Definition: CAMutex.hpp:52
SINT32 lock()
Definition: CAMutex.hpp:41
static SINT32 init()
static SINT32 cleanup()
static SINT32 cleanup()
static SINT32 init()
static SINT32 cleanup()
Definition: CASocket.hpp:49
static SINT32 init()
Definition: CASocket.hpp:43
static thread_id_t getSelfID()
Definition: CAThread.hpp:201
const SINT32 E_SUCCESS
Definition: errorcodes.hpp:2
void cleanup()
do necessary cleanups of libraries etc.
Definition: proxytest.cpp:151
UINT8 type
Definition: typedefs.hpp:1