Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove dependency on apr by using c++11 / c++14 features #255

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions boringssl-static/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@
<artifactId>maven-bundle-plugin</artifactId>
<configuration>
<instructions>
<Apr-Version>${aprVersion}</Apr-Version>
<BoringSSL-Revision>${boringsslBuildNumber}</BoringSSL-Revision>
<BoringSSL-Branch>${boringsslBranch}</BoringSSL-Branch>
</instructions>
Expand Down Expand Up @@ -230,7 +229,6 @@
<!-- <verbose>true</verbose> -->
<configureArgs>
<configureArg>--with-ssl=no</configureArg>
<configureArg>--with-apr=${aprHome}</configureArg>
<configureArg>CFLAGS=-O3 -Werror -fno-omit-frame-pointer -Wunused-variable</configureArg>
<configureArg>CPPFLAGS=-DHAVE_OPENSSL -I${boringsslCheckoutDir}/include</configureArg>
<configureArg>LDFLAGS=-L${boringsslBuildDir}/ssl -L${boringsslBuildDir}/crypto -L${boringsslBuildDir}/decrepit -ldecrepit -lssl -lcrypto</configureArg>
Expand Down
2 changes: 0 additions & 2 deletions libressl-static/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@
<windowsBuildTool>msbuild</windowsBuildTool>
<configureArgs>
<configureArg>--with-ssl=${sslHome}</configureArg>
<configureArg>--with-apr=${aprHome}</configureArg>
</configureArgs>
</configuration>
</execution>
Expand All @@ -75,7 +74,6 @@
<artifactId>maven-bundle-plugin</artifactId>
<configuration>
<instructions>
<Apr-Version>${aprVersion}</Apr-Version>
<LibreSSL-Version>${libresslVersion}</LibreSSL-Version>
</instructions>
</configuration>
Expand Down
3 changes: 0 additions & 3 deletions openssl-dynamic/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -167,9 +167,6 @@
<libDirectory>${nativeLibOnlyDir}</libDirectory>
<forceAutogen>${forceAutogen}</forceAutogen>
<forceConfigure>${forceConfigure}</forceConfigure>
<configureArgs>
<configureArg>--with-apr=/usr/local/opt/apr/libexec/</configureArg>
</configureArgs>
</configuration>
<goals>
<goal>generate</goal>
Expand Down
13 changes: 3 additions & 10 deletions openssl-dynamic/src/main/c/error.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
*/

#include "tcn.h"
#include "apr_strings.h"

static jclass exceptionClass;
static jclass nullPointerExceptionClass;
Expand All @@ -47,25 +46,18 @@ void tcn_ThrowNullPointerException(JNIEnv *env, const char *msg)
{
(*env)->ThrowNew(env, nullPointerExceptionClass, msg);
}

void tcn_Throw(JNIEnv *env, const char *fmt, ...)
{
char msg[TCN_BUFFER_SZ] = {'\0'};
va_list ap;

va_start(ap, fmt);
apr_vsnprintf(msg, TCN_BUFFER_SZ, fmt, ap);
vsnprintf(msg, TCN_BUFFER_SZ, fmt, ap);
tcn_ThrowException(env, msg);
va_end(ap);
}

void tcn_ThrowAPRException(JNIEnv *e, apr_status_t err)
{
char serr[512] = {0};

apr_strerror(err, serr, 512);
tcn_ThrowException(e, serr);
}

jint netty_internal_tcnative_Error_JNI_OnLoad(JNIEnv* env, const char* packagePrefix) {

TCN_LOAD_CLASS(env, exceptionClass, "java/lang/Exception", JNI_ERR);
Expand All @@ -78,3 +70,4 @@ void netty_internal_tcnative_Error_JNI_OnUnLoad(JNIEnv* env) {
TCN_UNLOAD_CLASS(env, exceptionClass);
TCN_UNLOAD_CLASS(env, nullPointerExceptionClass);
}

80 changes: 2 additions & 78 deletions openssl-dynamic/src/main/c/jnilib.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,20 +38,17 @@
#endif

#include "tcn.h"
#include "apr_version.h"
#include "apr_atomic.h"
#include "apr_strings.h"
#include "bb.h"
#include "native_constants.h"
#include "ssl.h"
#include "sslcontext.h"
#include "error.h"
#include <string.h>

#ifndef TCN_JNI_VERSION
#define TCN_JNI_VERSION JNI_VERSION_1_6
#endif

apr_pool_t *tcn_global_pool = NULL;
static JavaVM *tcn_global_vm = NULL;

static jclass jString_class;
Expand Down Expand Up @@ -90,45 +87,6 @@ jstring tcn_new_string(JNIEnv *env, const char *str)
return (*env)->NewStringUTF(env, str);
}

TCN_IMPLEMENT_CALL(jboolean, Library, initialize0)(TCN_STDARGS)
{

UNREFERENCED_STDARGS;
if (!tcn_global_pool) {
apr_initialize();
if (apr_pool_create(&tcn_global_pool, NULL) != APR_SUCCESS) {
return JNI_FALSE;
}
apr_atomic_init(tcn_global_pool);
}
return JNI_TRUE;
}

TCN_IMPLEMENT_CALL(jint, Library, aprMajorVersion)(TCN_STDARGS)
{
apr_version_t apv;

UNREFERENCED_STDARGS;
apr_version(&apv);
return apv.major;
}

TCN_IMPLEMENT_CALL(jstring, Library, aprVersionString)(TCN_STDARGS)
{
UNREFERENCED(o);
return AJP_TO_JSTRING(apr_version_string());
}

TCN_IMPLEMENT_CALL(jboolean, Library, aprHasThreads)(TCN_STDARGS)
{
UNREFERENCED_STDARGS;
#if APR_HAS_THREADS
return JNI_TRUE;
#else
return JNI_FALSE;
#endif
}

jclass tcn_get_string_class()
{
return jString_class;
Expand Down Expand Up @@ -288,22 +246,7 @@ static char* parsePackagePrefix(const char* libraryPathName, jint* status) {

#endif /* TCN_NOT_DYNAMIC */

// JNI Method Registration Table Begin
static const JNINativeMethod method_table[] = {
{ TCN_METHOD_TABLE_ENTRY(initialize0, ()Z, Library) },
{ TCN_METHOD_TABLE_ENTRY(aprMajorVersion, ()I, Library) },
{ TCN_METHOD_TABLE_ENTRY(aprVersionString, ()Ljava/lang/String;, Library) },
{ TCN_METHOD_TABLE_ENTRY(aprHasThreads, ()Z, Library) },
};

static const jint method_table_size = sizeof(method_table) / sizeof(method_table[0]);
// JNI Method Registration Table End

jint netty_internal_tcnative_Library_JNI_OnLoad(JNIEnv* env, const char* packagePrefix) {
if (netty_internal_tcnative_util_register_natives(env, packagePrefix, "io/netty/internal/tcnative/Library", method_table, method_table_size) != 0) {
return JNI_ERR;
}

// Load all c modules that we depend upon
if (netty_internal_tcnative_Error_JNI_OnLoad(env, packagePrefix) == JNI_ERR) {
return JNI_ERR;
Expand All @@ -322,21 +265,6 @@ jint netty_internal_tcnative_Library_JNI_OnLoad(JNIEnv* env, const char* package
return JNI_ERR;
}

apr_version_t apv;
int apvn;

/* Before doing anything else check if we have a valid
* APR version.
*/
apr_version(&apv);
apvn = apv.major * 1000 + apv.minor * 100 + apv.patch;
if (apvn < 1201) {
tcn_Throw(env, "Unsupported APR version (%s)",
apr_version_string());
return JNI_ERR;
}


/* Initialize global java.lang.String class */
TCN_LOAD_CLASS(env, jString_class, "java/lang/String", JNI_ERR);

Expand Down Expand Up @@ -365,11 +293,7 @@ jint netty_internal_tcnative_Library_JNI_OnLoad(JNIEnv* env, const char* package
}

void netty_internal_tcnative_Library_JNI_OnUnLoad(JNIEnv* env) {
if (tcn_global_pool != NULL) {
TCN_UNLOAD_CLASS(env, jString_class);
apr_terminate();
}

TCN_UNLOAD_CLASS(env, jString_class);
TCN_UNLOAD_CLASS(env, byteArrayClass);
TCN_UNLOAD_CLASS(env, keyMaterialClass);

Expand Down
Loading