Skip to content

Commit

Permalink
Remove not needed methods and simplify
Browse files Browse the repository at this point in the history
Motivation:

We shipped a lot of code that come with tcnative when we forked it which we not really need for Netty. We should just remove this and only ship what we care about which will also help to maintain the code better.

Modifications:

- Remove everything we not need in Netty
- Simplify loading of native library as we always need the SSL stuff.
- Bump up version to 2.0.0-SNAPSHOT

Result:

Less code to mantain and easier usage.
  • Loading branch information
normanmaurer committed Sep 6, 2016
1 parent 115289d commit 0929c64
Show file tree
Hide file tree
Showing 29 changed files with 490 additions and 2,964 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,5 @@
# Mac-specific directory that no other operating system needs.
.DS_Store

# Do not include stuff in the static modules as this is generated during the build
*-static/src
29 changes: 29 additions & 0 deletions NOTICE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
The Netty Project
=================

Please visit the Netty web site for more information:

* http://netty.io/

Copyright 2016 The Netty Project

The Netty Project licenses this file to you under the Apache License,
version 2.0 (the "License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at:

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
License for the specific language governing permissions and limitations
under the License.

-------------------------------------------------------------------------------
This product contains a forked and modified version of Tomcat Native

* LICENSE:
* ASL2
* HOMEPAGE:
* http://tomcat.apache.org/native-doc/
* https://svn.apache.org/repos/asf/tomcat/native/
2 changes: 1 addition & 1 deletion boringssl-static/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<parent>
<groupId>io.netty</groupId>
<artifactId>netty-tcnative-parent</artifactId>
<version>1.1.33.Fork18-SNAPSHOT</version>
<version>2.0.0-SNAPSHOT</version>
</parent>
<artifactId>netty-tcnative-boringssl-static</artifactId>
<packaging>jar</packaging>
Expand Down
2 changes: 1 addition & 1 deletion libressl-static/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<parent>
<groupId>io.netty</groupId>
<artifactId>netty-tcnative-parent</artifactId>
<version>1.1.33.Fork18-SNAPSHOT</version>
<version>2.0.0-SNAPSHOT</version>
</parent>
<artifactId>netty-tcnative-libressl-static</artifactId>
<packaging>jar</packaging>
Expand Down
2 changes: 1 addition & 1 deletion openssl-dynamic/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<parent>
<groupId>io.netty</groupId>
<artifactId>netty-tcnative-parent</artifactId>
<version>1.1.33.Fork18-SNAPSHOT</version>
<version>2.0.0-SNAPSHOT</version>
</parent>
<artifactId>netty-tcnative</artifactId>
<packaging>jar</packaging>
Expand Down
37 changes: 15 additions & 22 deletions openssl-dynamic/src/main/c/bb.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
/*
* Copyright 2016 The Netty Project
*
* The Netty Project licenses this file to you under the Apache License,
* version 2.0 (the "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*/
/* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
Expand All @@ -14,30 +29,8 @@
* limitations under the License.
*/

/*
*
* @author Mladen Turk
* @version $Id: bb.c 1442587 2013-02-05 13:49:48Z rjung $
*/

#include "tcn.h"

/**
* DirectByteBuffer utilities
*/
TCN_IMPLEMENT_CALL(void, Buffer, free)(TCN_STDARGS, jobject bb)
{
void *mem;

UNREFERENCED(o);
if ((mem = (*e)->GetDirectBufferAddress(e, bb)) != NULL) {
/* This can cause core dump if address was
* allocated from the APR pool.
*/
free(mem);
}
}

TCN_IMPLEMENT_CALL(jlong, Buffer, address)(TCN_STDARGS, jobject bb)
{
UNREFERENCED(o);
Expand Down
131 changes: 17 additions & 114 deletions openssl-dynamic/src/main/c/error.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
/*
* Copyright 2016 The Netty Project
*
* The Netty Project licenses this file to you under the Apache License,
* version 2.0 (the "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*/
/* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
Expand All @@ -14,27 +29,9 @@
* limitations under the License.
*/

/*
*
* @author Mladen Turk
* @version $Id: error.c 1442587 2013-02-05 13:49:48Z rjung $
*/

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

static const char *tcn_errors[] = {
"Unknown user error",
/* TCN_TIMEUP */ "Operation timed out",
/* TCN_EAGAIN */ "There is no data ready",
/* TCN_EINTR */ "Interrupted system call",
/* TCN_EINPROGRESS */ "Operation in progress",
/* TCN_ETIMEDOUT */ "Connection timed out",
NULL
};

/* Merge IS_ETIMEDOUT with APR_TIMEUP
*/
#define TCN_STATUS_IS_ETIMEDOUT(x) (APR_STATUS_IS_ETIMEDOUT((x)) || ((x) == APR_TIMEUP))
/*
* Convenience function to help throw an java.lang.Exception.
*/
Expand All @@ -52,34 +49,6 @@ void tcn_ThrowException(JNIEnv *env, const char *msg)

}

void tcn_ThrowMemoryException(JNIEnv *env, const char *file, int line, const char *msg)
{
jclass javaExceptionClass;
javaExceptionClass = (*env)->FindClass(env, "java/lang/OutOfMemoryError");
if (javaExceptionClass == NULL) {
fprintf(stderr, "Cannot find java/lang/OutOfMemoryError\n");
return;
}

if (file) {
char fmt[TCN_BUFFER_SZ];
char *f = (char *)(file + strlen(file) - 1);
while (f != file && '\\' != *f && '/' != *f) {
f--;
}
if (f != file) {
f++;
}
sprintf(fmt, "%s for [%04d@%s]", msg, line, f);
(*env)->ThrowNew(env, javaExceptionClass, &fmt[0]);
}
else
(*env)->ThrowNew(env, javaExceptionClass, msg);
(*env)->DeleteLocalRef(env, javaExceptionClass);

}


void tcn_Throw(JNIEnv *env, const char *fmt, ...)
{
char msg[TCN_BUFFER_SZ] = {'\0'};
Expand All @@ -91,76 +60,10 @@ void tcn_Throw(JNIEnv *env, const char *fmt, ...)
va_end(ap);
}

/*
* Convenience function to help throw an APR Exception
* from native error code.
*/
void tcn_ThrowAPRException(JNIEnv *e, apr_status_t err)
{
jclass aprErrorClass;
jmethodID constructorID = 0;
jobject throwObj;
jstring jdescription;
char serr[512] = {0};

aprErrorClass = (*e)->FindClass(e, TCN_ERROR_CLASS);
if (aprErrorClass == NULL) {
fprintf(stderr, "Cannot find " TCN_ERROR_CLASS " class\n");
return;
}

/* Find the constructor ID */
constructorID = (*e)->GetMethodID(e, aprErrorClass,
"<init>",
"(ILjava/lang/String;)V");
if (constructorID == NULL) {
fprintf(stderr,
"Cannot find constructor for " TCN_ERROR_CLASS " class\n");
goto cleanup;
}

apr_strerror(err, serr, 512);
/* Obtain the string objects */
jdescription = AJP_TO_JSTRING(serr);
if (jdescription == NULL) {
fprintf(stderr,
"Cannot allocate description for " TCN_ERROR_CLASS " class\n");
goto cleanup;
}
/* Create the APR Error object */
throwObj = (*e)->NewObject(e, aprErrorClass, constructorID,
(jint)err, jdescription);
if (throwObj == NULL) {
fprintf(stderr,
"Cannot allocate new " TCN_ERROR_CLASS " object\n");
goto cleanup;
}

(*e)->Throw(e, throwObj);
cleanup:
(*e)->DeleteLocalRef(e, aprErrorClass);
}


TCN_IMPLEMENT_CALL(jint, Error, osError)(TCN_STDARGS)
{
UNREFERENCED_STDARGS;
return (jint)apr_get_os_error();
}

TCN_IMPLEMENT_CALL(jstring, Error, strerror)(TCN_STDARGS, jint err)
{
char serr[512] = {0};
jstring jerr;

UNREFERENCED(o);
if (err >= TCN_TIMEUP && err <= TCN_ETIMEDOUT) {
err -= TCN_TIMEUP;
jerr = AJP_TO_JSTRING(tcn_errors[err + 1]);
}
else {
apr_strerror(err, serr, 512);
jerr = AJP_TO_JSTRING(serr);
}
return jerr;
tcn_ThrowException(e, serr);
}
Loading

0 comments on commit 0929c64

Please sign in to comment.