From c03bd91589ef0cb0763d54fdf15c7a80cae2dd3f Mon Sep 17 00:00:00 2001 From: psychon Date: Wed, 10 Dec 2008 15:53:07 +0000 Subject: [PATCH] Update to latest Csocket and use its new init interface git-svn-id: https://znc.svn.sourceforge.net/svnroot/znc/trunk@1288 726aef4b-f618-498e-8847-2d620e286838 --- Csocket.cpp | 27 ++++++++++++++++++++++++++- Csocket.h | 39 +++++++++++++++------------------------ main.cpp | 4 ---- znc.cpp | 6 ++++++ 4 files changed, 47 insertions(+), 29 deletions(-) diff --git a/Csocket.cpp b/Csocket.cpp index e3d929a9..1d144b1b 100644 --- a/Csocket.cpp +++ b/Csocket.cpp @@ -28,7 +28,7 @@ * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * -* $Revision: 1.89 $ +* $Revision: 1.90 $ */ #include "Csocket.h" @@ -311,6 +311,31 @@ int GetAddrInfo( const CS_STRING & sHostname, Csock *pSock, CSSockAddr & csSockA return( ETIMEDOUT ); } +bool InitCsocket() +{ +#ifdef _WIN32 + WSADATA wsaData; + int iResult = WSAStartup( MAKEWORD( 2, 2 ), &wsaData ); + if( iResult != NO_ERROR ) + return( false ); +#endif /* _WIN32 */ +#ifdef HAVE_LIBSSL + if( !InitSSL() ) + return( false ); +#endif /* HAVE_LIBSSL */ + return( true ); +} + +void ShutdownCsocket() +{ +#ifdef HAVE_LIBSSL + ERR_free_strings(); +#endif /* HAVE_LIBSSL */ +#ifdef _WIN32 + WSACleanup(); +#endif /* _WIN32 */ +} + #ifdef HAVE_LIBSSL bool InitSSL( ECompType eCompressionType ) { diff --git a/Csocket.h b/Csocket.h index 8e004d4b..7d5f5486 100644 --- a/Csocket.h +++ b/Csocket.h @@ -28,7 +28,7 @@ * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * -* $Revision: 1.199 $ +* $Revision: 1.200 $ */ // note to compile with win32 need to link to winsock2, using gcc its -lws2_32 @@ -261,15 +261,27 @@ enum ECompType CT_RLE = 2 }; +void SSLErrors( const char *filename, u_int iLineNum ); + /** - * @brief You HAVE to call this in order to use the SSL library + * @brief You HAVE to call this in order to use the SSL library, calling InitCsocket() also calls this + * so unless you need to call InitSSL for a specific reason call InitCsocket() * @return true on success */ bool InitSSL( ECompType eCompressionType = CT_NONE ); -void SSLErrors( const char *filename, u_int iLineNum ); + #endif /* HAVE_LIBSSL */ +/** + * This does all the csocket initialized inclusing InitSSL() and win32 specific initializations, only needs to be called once + */ +bool InitCsocket(); +/** + * Shutdown and release global allocated memory + */ +void ShutdownCsocket(); + //! @todo need to make this sock specific via getsockopt inline int GetSockError() { @@ -280,27 +292,6 @@ inline int GetSockError() #endif /* _WIN32 */ } -#ifdef _WIN32 -inline bool InitWin32() -{ - WSADATA wsaData; - int iResult = WSAStartup( MAKEWORD( 2, 2 ), &wsaData ); - if( iResult != NO_ERROR ) - return( false ); - - return( true ); -} -inline void ShutdownWin32() -{ - WSACleanup(); -} -#define InitCsocket InitWin32 -#define ShutdownCsocket ShutdownWin32 -#else -#define InitCsocket (void)0 -#define ShutdownCsocket (void)0 -#endif /* _WIN32 */ - //! wrappers for FD_SET and such to work in templates. inline void TFD_ZERO( fd_set *set ) { diff --git a/main.cpp b/main.cpp index 6245e465..01b911fa 100644 --- a/main.cpp +++ b/main.cpp @@ -74,10 +74,6 @@ int main(int argc, char** argv) { srand(time(NULL)); CUtils::SetStdoutIsTTY(isatty(1)); -#ifdef HAVE_LIBSSL - InitSSL(); -#endif /* HAVE_LIBSSL */ - int iArg, iOptIndex = -1; bool bMakeConf = false; bool bMakePass = false; diff --git a/znc.cpp b/znc.cpp index 0bd206bc..fab285f5 100644 --- a/znc.cpp +++ b/znc.cpp @@ -26,6 +26,11 @@ namespace }; CZNC::CZNC() { + if (!InitCsocket()) { + CUtils::PrintError("Failed to initialize Csocket!"); + exit(-1); + } + #ifdef _MODULES m_pModules = new CGlobalModules(); #endif @@ -68,6 +73,7 @@ CZNC::~CZNC() { delete m_pModules; #endif + ShutdownCsocket(); DeletePidFile(); }