vanzin commented on a change in pull request #91: run time support is added for
openssl 1.0 and 1.1 for UNIX
URL: https://github.com/apache/commons-crypto/pull/91#discussion_r255249458
##########
File path: src/main/native/org/apache/commons/crypto/OpenSslInfoNative.c
##########
@@ -75,38 +84,61 @@ static int load_library(JNIEnv *env)
{
char msg[100];
#ifdef UNIX
- openssl = dlopen(COMMONS_CRYPTO_OPENSSL_LIBRARY, RTLD_LAZY | RTLD_GLOBAL);
+ openssl_new = dlopen(COMMONS_CRYPTO_OPENSSL_LIBRARY_1, RTLD_LAZY |
RTLD_GLOBAL);
+ if (!openssl_new) {
+ snprintf(msg, sizeof(msg), "Cannot load %s (%s)!",
COMMONS_CRYPTO_OPENSSL_LIBRARY_1, \
+ dlerror());
+ } else {
+ openssl_1 = 1;
+ get_methods(env, openssl_new);
+ }
+ openssl_old = dlopen(COMMONS_CRYPTO_OPENSSL_LIBRARY, RTLD_LAZY |
RTLD_GLOBAL);
+ if (!openssl_old) {
+ snprintf(msg, sizeof(msg), "Cannot load %s (%s)!",
COMMONS_CRYPTO_OPENSSL_LIBRARY, \
+ dlerror());
+ } else {
+ openssl_0 = 1;
+ get_methods(env, openssl_old);
+ }
+ if (!openssl_0 && !openssl_1) {
+ THROW(env, "java/lang/UnsatisfiedLinkError", msg);
+ return 0;
+ }
#endif
-
#ifdef WINDOWS
openssl = LoadLibrary(TEXT(COMMONS_CRYPTO_OPENSSL_LIBRARY));
-#endif
-
if (!openssl) {
-#ifdef UNIX
- snprintf(msg, sizeof(msg), "Cannot load %s (%s)!",
COMMONS_CRYPTO_OPENSSL_LIBRARY, \
- dlerror());
-#endif
-#ifdef WINDOWS
snprintf(msg, sizeof(msg), "Cannot load %s (%d)!",
COMMONS_CRYPTO_OPENSSL_LIBRARY, \
- GetLastError());
-#endif
+ GetLastError());
THROW(env, "java/lang/UnsatisfiedLinkError", msg);
return 0;
+ } else {
+ get_methods(env, openssl);
}
- get_methods(env, openssl);
+#endif
+
return 1;
}
JNIEXPORT jstring JNICALL
Java_org_apache_commons_crypto_OpenSslInfoNative_SSLeayVersion
(JNIEnv *env, jclass clazz, jint type)
{
+ jstring answer = NULL;
if (!load_library(env)) {
return NULL;
}
-
- jstring answer = (*env)->NewStringUTF(env,dlsym_SSLeay_version(type));
- return answer;
+#ifdef UNIX
+ if (openssl_0) {
Review comment:
Indentation is all wonky, here and in other places too. Use 2 spaces for
indentations everywhere in the C files (Java seems to be using 4 spaces).
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]