@@ -187,58 +187,73 @@ const
187187 BIO_C_DO_STATE_MACHINE = 101
188188 BIO_C_GET_SSL = 110
189189
190- # Here we're trying to stay compatible with openssl 1.0.* and 1.1.*. Some
191- # symbols are loaded dynamically and we don't use them if not found.
192- proc thisModule (): LibHandle {.inline .} =
193- var thisMod {.global .}: LibHandle
194- if thisMod.isNil: thisMod = loadLib ()
195- result = thisMod
196-
197- proc sslModule (): LibHandle {.inline .} =
198- var sslMod {.global .}: LibHandle
199- if sslMod.isNil: sslMod = loadLibPattern (DLLSSLName )
200- result = sslMod
201-
202- proc sslSym (name: string ): pointer =
203- var dl = thisModule ()
204- if not dl.isNil:
205- result = symAddr (dl, name)
206- if result .isNil:
207- dl = sslModule ()
208- if not dl.isNil:
209- result = symAddr (dl, name)
210-
211- proc SSL_library_init * (): cint {.discardable .} =
212- let theProc = cast [proc (): cint {.cdecl .}](sslSym (" SSL_library_init" ))
213- if not theProc.isNil: result = theProc ()
214-
215- proc SSL_load_error_strings * () =
216- let theProc = cast [proc () {.cdecl .}](sslSym (" SSL_load_error_strings" ))
217- if not theProc.isNil: theProc ()
218-
219- proc ERR_load_BIO_strings * (){.cdecl , dynlib : DLLUtilName , importc .}
220-
221190proc TLSv1_method * (): PSSL_METHOD {.cdecl , dynlib : DLLSSLName , importc .}
222191
223- proc SSLv23_client_method * (): PSSL_METHOD {. deprecated .} =
224- let theProc = cast [ proc (): PSSL_METHOD {.cdecl , gcsafe .}]( sslSym ( " SSLv23_client_method " ))
225- if not theProc.isNil: result = theProc ()
226- else : result = TLSv1_method ()
192+ when compileOption ( " dynlibOverride " , " ssl " ):
193+ proc SSL_library_init * (): cint {.cdecl , dynlib : DLLSSLName , importc , discardable .}
194+ proc SSL_load_error_strings * () {. cdecl , dynlib : DLLSSLName , importc .}
195+ proc SSLv23_client_method * (): PSSL_METHOD {. cdecl , dynlib : DLLSSLName , importc .}
227196
228- proc SSLv23_method * (): PSSL_METHOD {.deprecated .} =
229- let theProc = cast [proc (): PSSL_METHOD {.cdecl , gcsafe .}](sslSym (" SSLv23_method" ))
230- if not theProc.isNil: result = theProc ()
231- else : result = TLSv1_method ()
197+ proc SSLv23_method * (): PSSL_METHOD {.cdecl , dynlib : DLLSSLName , importc .}
198+ proc SSLv2_method * (): PSSL_METHOD {.cdecl , dynlib : DLLSSLName , importc .}
199+ proc SSLv3_method * (): PSSL_METHOD {.cdecl , dynlib : DLLSSLName , importc .}
232200
233- proc SSLv2_method * (): PSSL_METHOD {.deprecated .} =
234- let theProc = cast [proc (): PSSL_METHOD {.cdecl , gcsafe .}](sslSym (" SSLv2_method" ))
235- if not theProc.isNil: result = theProc ()
236- else : result = TLSv1_method ()
201+ template OpenSSL_add_all_algorithms * () = discard
202+ else :
203+ # Here we're trying to stay compatible with openssl 1.0.* and 1.1.*. Some
204+ # symbols are loaded dynamically and we don't use them if not found.
205+ proc thisModule (): LibHandle {.inline .} =
206+ var thisMod {.global .}: LibHandle
207+ if thisMod.isNil: thisMod = loadLib ()
208+ result = thisMod
209+
210+ proc sslModule (): LibHandle {.inline .} =
211+ var sslMod {.global .}: LibHandle
212+ if sslMod.isNil: sslMod = loadLibPattern (DLLSSLName )
213+ result = sslMod
214+
215+ proc sslSym (name: string ): pointer =
216+ var dl = thisModule ()
217+ if not dl.isNil:
218+ result = symAddr (dl, name)
219+ if result .isNil:
220+ dl = sslModule ()
221+ if not dl.isNil:
222+ result = symAddr (dl, name)
223+
224+ proc SSL_library_init * (): cint {.discardable .} =
225+ let theProc = cast [proc (): cint {.cdecl .}](sslSym (" SSL_library_init" ))
226+ if not theProc.isNil: result = theProc ()
227+
228+ proc SSL_load_error_strings * () =
229+ let theProc = cast [proc () {.cdecl .}](sslSym (" SSL_load_error_strings" ))
230+ if not theProc.isNil: theProc ()
231+
232+ proc SSLv23_client_method * (): PSSL_METHOD =
233+ let theProc = cast [proc (): PSSL_METHOD {.cdecl , gcsafe .}](sslSym (" SSLv23_client_method" ))
234+ if not theProc.isNil: result = theProc ()
235+ else : result = TLSv1_method ()
236+
237+ proc SSLv23_method * (): PSSL_METHOD =
238+ let theProc = cast [proc (): PSSL_METHOD {.cdecl , gcsafe .}](sslSym (" SSLv23_method" ))
239+ if not theProc.isNil: result = theProc ()
240+ else : result = TLSv1_method ()
241+
242+ proc SSLv2_method * (): PSSL_METHOD =
243+ let theProc = cast [proc (): PSSL_METHOD {.cdecl , gcsafe .}](sslSym (" SSLv2_method" ))
244+ if not theProc.isNil: result = theProc ()
245+ else : result = TLSv1_method ()
246+
247+ proc SSLv3_method * (): PSSL_METHOD =
248+ let theProc = cast [proc (): PSSL_METHOD {.cdecl , gcsafe .}](sslSym (" SSLv3_method" ))
249+ if not theProc.isNil: result = theProc ()
250+ else : result = TLSv1_method ()
251+
252+ proc OpenSSL_add_all_algorithms * () =
253+ let theProc = cast [proc () {.cdecl .}](sslSym (" OPENSSL_add_all_algorithms_conf" ))
254+ if not theProc.isNil: theProc ()
237255
238- proc SSLv3_method * (): PSSL_METHOD {.deprecated .} =
239- let theProc = cast [proc (): PSSL_METHOD {.cdecl , gcsafe .}](sslSym (" SSLv3_method" ))
240- if not theProc.isNil: result = theProc ()
241- else : result = TLSv1_method ()
256+ proc ERR_load_BIO_strings * (){.cdecl , dynlib : DLLUtilName , importc .}
242257
243258proc SSL_new * (context: SslCtx ): SslPtr {.cdecl , dynlib : DLLSSLName , importc .}
244259proc SSL_free * (ssl: SslPtr ){.cdecl , dynlib : DLLSSLName , importc .}
@@ -306,10 +321,6 @@ proc ERR_error_string*(e: cInt, buf: cstring): cstring{.cdecl,
306321proc ERR_get_error * (): cInt{.cdecl , dynlib : DLLUtilName , importc .}
307322proc ERR_peek_last_error * (): cInt{.cdecl , dynlib : DLLUtilName , importc .}
308323
309- proc OpenSSL_add_all_algorithms * () =
310- let theProc = cast [proc () {.cdecl .}](sslSym (" OPENSSL_add_all_algorithms_conf" ))
311- if not theProc.isNil: theProc ()
312-
313324proc OPENSSL_config * (configName: cstring ){.cdecl , dynlib : DLLSSLName , importc .}
314325
315326when not useWinVersion and not defined (macosx) and not defined (android):
0 commit comments