summary refs log tree commit diff stats
path: root/lib
diff options
context:
space:
mode:
authorLeorize <leorize+oss@disroot.org>2020-06-04 09:22:41 -0500
committerAndreas Rumpf <rumpf_a@web.de>2020-06-06 21:11:53 +0200
commitd406f588d89fcf4a19c3e556ca57def9644a8a57 (patch)
treece48c7c442aa8400238ceb92f8c908d23753b711 /lib
parent0ca069b4f8ff4e4f6d85178247818857970ce591 (diff)
downloadNim-d406f588d89fcf4a19c3e556ca57def9644a8a57.tar.gz
wrappers/openssl: the version number comes from the utility library
Previously we loaded the SSL library for this, but that's not where the
symbol resides.
Diffstat (limited to 'lib')
-rw-r--r--lib/wrappers/openssl.nim29
1 files changed, 20 insertions, 9 deletions
diff --git a/lib/wrappers/openssl.nim b/lib/wrappers/openssl.nim
index c2f0250c0..8a80a554c 100644
--- a/lib/wrappers/openssl.nim
+++ b/lib/wrappers/openssl.nim
@@ -264,7 +264,7 @@ when compileOption("dynlibOverride", "ssl") or defined(noOpenSSLHacks):
     proc SSL_library_init*(): cint {.cdecl, dynlib: DLLSSLName, importc, discardable.}
     proc SSL_load_error_strings*() {.cdecl, dynlib: DLLSSLName, importc.}
     proc SSLv23_method*(): PSSL_METHOD {.cdecl, dynlib: DLLSSLName, importc.}
-    proc SSLeay(): culong {.cdecl, dynlib: DLLSSLName, importc.}
+    proc SSLeay(): culong {.cdecl, dynlib: DLLUtilName, importc.}
 
     proc getOpenSSLVersion*(): culong =
       SSLeay()
@@ -278,7 +278,7 @@ when compileOption("dynlibOverride", "ssl") or defined(noOpenSSLHacks):
     proc SSLv23_method*(): PSSL_METHOD =
       TLS_method()
 
-    proc OpenSSL_version_num(): culong {.cdecl, dynlib: DLLSSLName, importc.}
+    proc OpenSSL_version_num(): culong {.cdecl, dynlib: DLLUtilName, importc.}
 
     proc getOpenSSLVersion*(): culong =
       ## Return OpenSSL version as unsigned long
@@ -318,13 +318,18 @@ else:
 
     result = sslMod
 
-  proc sslSymNullable(name: string, alternativeName = ""): pointer =
+  proc utilModule(): LibHandle {.inline.} =
+    var utilMod {.global.}: LibHandle
+    if utilMod.isNil: utilMod = loadLibPattern(DLLUtilName)
+
+    result = utilMod
+
+  proc symNullable(dll: LibHandle, name: string, alternativeName = ""): pointer =
     # Load from DLL.
-    var sslDynlib = sslModule()
-    if not sslDynlib.isNil:
-      result = symAddr(sslDynlib, name)
+    if not dll.isNil:
+      result = symAddr(dll, name)
       if result.isNil and alternativeName.len > 0:
-        result = symAddr(sslDynlib, alternativeName)
+        result = symAddr(dll, alternativeName)
 
     # Attempt to load from current exe.
     if result.isNil:
@@ -332,12 +337,18 @@ else:
       if thisDynlib.isNil: return nil
       result = symAddr(thisDynlib, name)
       if result.isNil and alternativeName.len > 0:
-        result = symAddr(sslDynlib, alternativeName)
+        result = symAddr(thisDynlib, alternativeName)
+
+  proc sslSymNullable(name: string, alternativeName = ""): pointer =
+    sslModule().symNullable(name, alternativeName)
 
   proc sslSymThrows(name: string, alternativeName = ""): pointer =
     result = sslSymNullable(name, alternativeName)
     if result.isNil: raiseInvalidLibrary(name)
 
+  proc utilSymNullable(name: string, alternativeName = ""): pointer =
+    utilModule().symNullable(name, alternativeName)
+
   proc loadPSSLMethod(method1, method2: string): PSSL_METHOD =
     ## Load <method1> from OpenSSL if available, otherwise <method2>
     ##
@@ -392,7 +403,7 @@ else:
 
   proc getOpenSSLVersion*(): culong =
     ## Return OpenSSL version as unsigned long or 0 if not available
-    let theProc = cast[proc(): culong {.cdecl.}](sslSymNullable("OpenSSL_version_num", "SSLeay"))
+    let theProc = cast[proc(): culong {.cdecl.}](utilSymNullable("OpenSSL_version_num", "SSLeay"))
     {.gcsafe.}:
       result =
         if theProc.isNil: 0.culong