Mixe for Privacy and Anonymity in the Internet
CALibProxytest.cpp
Go to the documentation of this file.
00001 #include "StdAfx.h"
00002 #include "CALibProxytest.hpp"
00003 #ifdef SERVER_MONITORING
00004   #include "CAStatusManager.hpp"
00005 #endif
00006 CACmdLnOptions* CALibProxytest::m_pglobalOptions;
00007 CAMutex* CALibProxytest::m_pOpenSSLMutexes;
00008 #if defined _DEBUG && ! defined (ONLY_LOCAL_PROXY)
00009   CAThreadList* CALibProxytest::m_pThreadList;
00010 #endif
00011 
00013 void CALibProxytest::openssl_locking_callback(int mode, int type, char * /*file*/, int /*line*/)
00014   {
00015     if (mode & CRYPTO_LOCK)
00016       {
00017         m_pOpenSSLMutexes[type].lock();
00018       }
00019     else
00020       {
00021         m_pOpenSSLMutexes[type].unlock();
00022       }
00023   }
00024 
00026 
00027 unsigned long openssl_get_thread_id(void)
00028   {
00029     return CAThread::getSelfID();
00030   }
00031 
00032 
00034 SINT32 CALibProxytest::init()
00035   {
00036 #ifndef ONLY_LOCAL_PROXY
00037     XMLPlatformUtils::Initialize();
00038     initDOMParser();
00039 #endif
00040 #ifndef ONLY_LOCAL_PROXY
00041     SSL_library_init();
00042 #endif
00043     OpenSSL_add_all_algorithms();
00044     m_pOpenSSLMutexes=new CAMutex[CRYPTO_num_locks()];
00045     CRYPTO_set_locking_callback((void (*)(int,int,const char *,int))openssl_locking_callback);
00046     CRYPTO_set_id_callback(openssl_get_thread_id);
00047 #if defined _DEBUG && ! defined (ONLY_LOCAL_PROXY)
00048     m_pThreadList=new CAThreadList();
00049     CAThread::setThreadList(m_pThreadList);
00050 #endif
00051     CAMsg::init();
00052     CASocketAddrINet::init();
00053     //startup
00054     #ifdef _WIN32
00055       int err=0;
00056       WSADATA wsadata;
00057       err=WSAStartup(0x0202,&wsadata);
00058     #endif
00059     initRandom();
00060     m_pglobalOptions=new CACmdLnOptions();
00061     return E_SUCCESS;
00062 }
00063 
00065 SINT32 CALibProxytest::cleanup()
00066   {
00067     CASocketAddrINet::cleanup();
00068     #ifdef _WIN32
00069       WSACleanup();
00070     #endif
00071     delete m_pglobalOptions;
00072     m_pglobalOptions=NULL;
00073 
00074   //OpenSSL Cleanup
00075     CRYPTO_set_locking_callback(NULL);
00076     delete []m_pOpenSSLMutexes;
00077     m_pOpenSSLMutexes=NULL;
00078     //XML Cleanup
00079     //Note: We have to destroy all XML Objects and all objects that uses XML Objects BEFORE
00080     //we terminate the XML lib!
00081 #ifdef SERVER_MONITORING
00082     CAStatusManager::cleanup();
00083 #endif
00084     releaseDOMParser();
00085 #ifndef ONLY_LOCAL_PROXY
00086     XMLPlatformUtils::Terminate();
00087 #endif
00088 
00089 #if defined _DEBUG && ! defined (ONLY_LOCAL_PROXY)
00090       if(m_pThreadList != NULL)
00091       {
00092         int nrOfThreads = m_pThreadList->getSize();
00093         CAMsg::printMsg(LOG_INFO,"After cleanup %d threads listed.\n", nrOfThreads);
00094         if(nrOfThreads > 0)
00095         {
00096           m_pThreadList->showAll();
00097         }
00098         delete m_pThreadList;
00099         m_pThreadList = NULL;
00100       }
00101 #endif
00102     CAMsg::cleanup();
00103     return E_SUCCESS;
00104   }
00105