changeset 2099:bcbc9137a535

refactoring
author Sebastien Jodogne <s.jodogne@gmail.com>
date Fri, 07 Oct 2016 11:13:41 +0200
parents 7d184e11043e
children 0b6464320aac
files Core/HttpClient.cpp Core/HttpClient.h OrthancServer/OrthancInitialization.cpp
diffstat 3 files changed, 46 insertions(+), 30 deletions(-) [+]
line wrap: on
line diff
--- a/Core/HttpClient.cpp	Thu Oct 06 17:28:43 2016 +0200
+++ b/Core/HttpClient.cpp	Fri Oct 07 11:13:41 2016 +0200
@@ -44,6 +44,16 @@
 #include <boost/thread/mutex.hpp>
 
 
+#if ORTHANC_SSL_ENABLED == 1
+// For OpenSSL initialization and finalization
+#  include <openssl/conf.h>
+#  include <openssl/engine.h>
+#  include <openssl/err.h>
+#  include <openssl/evp.h>
+#  include <openssl/ssl.h>
+#endif
+
+
 #if ORTHANC_PKCS11_ENABLED == 1
 #  include "Pkcs11.h"
 #endif
@@ -784,4 +794,32 @@
     throw OrthancException(ErrorCode_InternalError);
 #endif
   }
+
+
+  void HttpClient::InitializeOpenSsl()
+  {
+#if ORTHANC_SSL_ENABLED == 1
+    // https://wiki.openssl.org/index.php/Library_Initialization
+    SSL_library_init();
+    SSL_load_error_strings();
+    OpenSSL_add_all_algorithms();
+    ERR_load_crypto_strings();
+#endif
+  }
+
+
+  void HttpClient::FinalizeOpenSsl()
+  {
+ #if ORTHANC_SSL_ENABLED == 1
+    // Finalize OpenSSL
+    // https://wiki.openssl.org/index.php/Library_Initialization#Cleanup
+    FIPS_mode_set(0);
+    ENGINE_cleanup();
+    CONF_modules_unload(1);
+    EVP_cleanup();
+    CRYPTO_cleanup_all_ex_data();
+    ERR_remove_state(0);
+    ERR_free_strings();
+#endif
+  }
 }
--- a/Core/HttpClient.h	Thu Oct 06 17:28:43 2016 +0200
+++ b/Core/HttpClient.h	Fri Oct 07 11:13:41 2016 +0200
@@ -247,6 +247,10 @@
   
     static void GlobalFinalize();
 
+    static void InitializeOpenSsl();
+
+    static void FinalizeOpenSsl();
+
     static void InitializePkcs11(const std::string& module,
                                  const std::string& pin,
                                  bool verbose);
--- a/OrthancServer/OrthancInitialization.cpp	Thu Oct 06 17:28:43 2016 +0200
+++ b/OrthancServer/OrthancInitialization.cpp	Fri Oct 07 11:13:41 2016 +0200
@@ -50,23 +50,13 @@
 #include <boost/thread.hpp>
 
 
-#if ORTHANC_SSL_ENABLED == 1
-// For OpenSSL initialization and finalization
-#include <openssl/conf.h>
-#include <openssl/engine.h>
-#include <openssl/err.h>
-#include <openssl/evp.h>
-#include <openssl/ssl.h>
-#endif
-
-
 #if ORTHANC_JPEG_ENABLED == 1
-#include <dcmtk/dcmjpeg/djdecode.h>
+#  include <dcmtk/dcmjpeg/djdecode.h>
 #endif
 
 
 #if ORTHANC_JPEG_LOSSLESS_ENABLED == 1
-#include <dcmtk/dcmjpls/djdecode.h>
+#  include <dcmtk/dcmjpls/djdecode.h>
 #endif
 
 
@@ -471,13 +461,7 @@
   {
     boost::recursive_mutex::scoped_lock lock(globalMutex_);
 
-#if ORTHANC_SSL_ENABLED == 1
-    // https://wiki.openssl.org/index.php/Library_Initialization
-    SSL_library_init();
-    SSL_load_error_strings();
-    OpenSSL_add_all_algorithms();
-    ERR_load_crypto_strings();
-#endif
+    HttpClient::InitializeOpenSsl();
 
     InitializeServerEnumerations();
 
@@ -531,17 +515,7 @@
     DJDecoderRegistration::cleanup();
 #endif
 
-#if ORTHANC_SSL_ENABLED == 1
-    // Finalize OpenSSL
-    // https://wiki.openssl.org/index.php/Library_Initialization#Cleanup
-    FIPS_mode_set(0);
-    ENGINE_cleanup();
-    CONF_modules_unload(1);
-    EVP_cleanup();
-    CRYPTO_cleanup_all_ex_data();
-    ERR_remove_state(0);
-    ERR_free_strings();
-#endif
+    HttpClient::FinalizeOpenSsl();
   }