浏览代码

OPENSSL_API_COMPAT

ithewei 5 年之前
父节点
当前提交
61edd9c7eb
共有 2 个文件被更改,包括 21 次插入21 次删除
  1. 0 21
      base/RAII.cpp
  2. 21 0
      base/hssl.c

+ 0 - 21
base/RAII.cpp

@@ -64,24 +64,3 @@ public:
 };
 static CurlRAII s_curl;
 #endif
-
-#ifdef WITH_OPENSSL
-#include "openssl/ssl.h"
-#include "openssl/err.h"
-#ifdef _MSC_VER
-//#pragma comment(lib, "libssl.a")
-//#pragma comment(lib, "libcrypto.a")
-#endif
-class OpensslRAII {
-public:
-    OpensslRAII() {
-        //OPENSSL_init_ssl(OPENSSL_INIT_SSL_DEFAULT, NULL);
-        SSL_load_error_strings();
-        SSL_library_init();
-    }
-
-    ~OpensslRAII() {
-    }
-};
-static OpensslRAII s_openssl;
-#endif

+ 21 - 0
base/hssl.c

@@ -1,6 +1,7 @@
 #include "hssl.h"
 
 static hssl_ctx_t s_ssl_ctx = 0;
+
 hssl_ctx_t hssl_ctx_instance() {
     return s_ssl_ctx;
 }
@@ -8,9 +9,29 @@ hssl_ctx_t hssl_ctx_instance() {
 #ifdef WITH_OPENSSL
 
 #include "openssl/ssl.h"
+#include "openssl/err.h"
+#ifdef _MSC_VER
+//#pragma comment(lib, "libssl.a")
+//#pragma comment(lib, "libcrypto.a")
+#endif
 
 hssl_ctx_t hssl_ctx_init(hssl_ctx_init_param_t* param) {
+    static int s_initialized = 0;
+    if (s_initialized == 0) {
+#if OPENSSL_VERSION_NUMBER < 0x10100000L
+        SSL_library_init();
+        SSL_load_error_strings();
+#else
+        OPENSSL_init_ssl(OPENSSL_INIT_SSL_DEFAULT, NULL);
+#endif
+        s_initialized = 1;
+    }
+
+#if OPENSSL_VERSION_NUMBER < 0x10100000L
+    SSL_CTX* ctx = SSL_CTX_new(SSLv23_method());
+#else
     SSL_CTX* ctx = SSL_CTX_new(TLS_method());
+#endif
     if (ctx == NULL) return NULL;
     int mode = SSL_VERIFY_NONE;
     if (param) {