Skip to content
Commits on Source (11)
# Set the default behavior, in case people don't have core.autocrlf set.
* text=auto
......@@ -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
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/
This product contains the Maven wrapper scripts from 'Maven Wrapper', that provides an easy way to ensure a user has everything necessary to run the Maven build.
* LICENSE:
* license/LICENSE.mvn-wrapper.txt (Apache License 2.0)
* HOMEPAGE:
* https://github.com/takari/maven-wrapper
......@@ -19,7 +19,7 @@
<parent>
<groupId>io.netty</groupId>
<artifactId>netty-tcnative-parent</artifactId>
<version>1.1.33.Fork26</version>
<version>2.0.15.Final</version>
</parent>
<artifactId>netty-tcnative-boringssl-static</artifactId>
<packaging>jar</packaging>
......@@ -141,26 +141,35 @@
<equals arg1="${os.detected.name}" arg2="windows" />
<then>
<!-- On Windows, build with /MT for static linking -->
<exec executable="cmake" failonerror="true" dir="${boringsslBuildDir}" resolveexecutable="true">
<arg value="-DCMAKE_POSITION_INDEPENDENT_CODE=TRUE" />
<arg value="-DCMAKE_BUILD_TYPE=Release" />
<arg value="-DCMAKE_C_FLAGS_RELEASE=/MT" />
<arg value="-DCMAKE_CXX_FLAGS_RELEASE=/MT" />
<arg value="-GNinja" />
<arg value=".." />
</exec>
<property name="cmakeAsmFlags" value="" />
<property name="cmakeCFlags" value="/MT" />
<property name="cmakeCxxFlags" value="/MT" />
</then>
<elseif>
<equals arg1="${os.detected.name}" arg2="linux" />
<then>
<!-- On *nix, add ASM flags to disable executable stack -->
<property name="cmakeAsmFlags" value="-Wa,--noexecstack" />
<property name="cmakeCFlags" value="-std=c99 -O3 -fno-omit-frame-pointer" />
<property name="cmakeCxxFlags" value="-O3 -fno-omit-frame-pointer -Wno-error=maybe-uninitialized" />
</then>
</elseif>
<else>
<!-- On *nix, add ASM flags to disable executable stack -->
<property name="cmakeAsmFlags" value="-Wa,--noexecstack" />
<property name="cmakeCFlags" value="-std=c99 -O3 -fno-omit-frame-pointer" />
<property name="cmakeCxxFlags" value="-O3 -fno-omit-frame-pointer" />
</else>
</if>
<exec executable="cmake" failonerror="true" dir="${boringsslBuildDir}" resolveexecutable="true">
<arg value="-DCMAKE_POSITION_INDEPENDENT_CODE=TRUE" />
<arg value="-DCMAKE_BUILD_TYPE=Release" />
<arg value="-DCMAKE_ASM_FLAGS=-Wa,--noexecstack" />
<arg value="-DCMAKE_ASM_FLAGS=${cmakeAsmFlags}" />
<arg value="-DCMAKE_C_FLAGS_RELEASE=${cmakeCFlags}" />
<arg value="-DCMAKE_CXX_FLAGS_RELEASE=${cmakeCxxFlags}" />
<arg value="-GNinja" />
<arg value=".." />
</exec>
</else>
</if>
<exec executable="ninja" failonerror="true" dir="${boringsslBuildDir}" resolveexecutable="true" />
</target>
</configuration>
......@@ -180,10 +189,14 @@
<!-- Strip on linux. See https://github.com/netty/netty-tcnative/issues/129 -->
<if>
<and>
<equals arg1="${os.detected.name}" arg2="linux" />
<equals arg1="${strip.skip}" arg2="false" />
</and>
<then>
<exec executable="strip" failonerror="true" dir="${nativeLibOnlyDir}/META-INF/native/linux${archBits}/" resolveexecutable="true">
<arg value="libnetty-tcnative.so" />
<arg value="--strip-debug" />
<arg value="libnetty_tcnative.so" />
</exec>
</then>
</if>
......@@ -216,7 +229,7 @@
</goals>
<phase>compile</phase>
<configuration>
<name>netty-tcnative</name>
<name>netty_tcnative</name>
<nativeSourceDirectory>${project.basedir}/src/main/c</nativeSourceDirectory>
<libDirectory>${nativeLibOnlyDir}</libDirectory>
<forceAutogen>${forceAutogen}</forceAutogen>
......@@ -226,6 +239,8 @@
<configureArgs>
<configureArg>--with-ssl=no</configureArg>
<configureArg>--with-apr=${aprHome}</configureArg>
<configureArg>--with-static-libs</configureArg>
<configureArg>CFLAGS=-O3 -Werror -fno-omit-frame-pointer -fvisibility=hidden -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>
</configureArgs>
......@@ -245,24 +260,20 @@
without a classifier).
To build from the top level, run:
mvn clean deploy -pl boringssl-static -P uber -DstagingRepositoryId={repoId}
mvn clean deploy -pl boringssl-static -P uber-staging -DstagingRepositoryId={repoId}
The repoId is necessary to allow the build to download the platform-specific jars from
the nexus staging repository.
-->
<profile>
<id>uber</id>
<activation>
<property>
<name>moduleSelector</name>
<value>uber</value>
</property>
</activation>
<id>uber-staging</id>
<properties>
<unpackDir>${project.build.directory}/unpack</unpackDir>
<libDir>${project.build.directory}/lib</libDir>
<nativeDir>${project.build.outputDirectory}/META-INF/native</nativeDir>
<skipTests>true</skipTests>
<uberArch>${os.detected.arch}</uberArch>
</properties>
<repositories>
......@@ -291,25 +302,25 @@
<groupId>io.netty</groupId>
<artifactId>netty-tcnative-boringssl-static</artifactId>
<version>${project.version}</version>
<classifier>osx-x86_64</classifier>
<classifier>osx-${uberArch}</classifier>
<type>jar</type>
<outputDirectory>${unpackDir}/osx-x86_64</outputDirectory>
<outputDirectory>${unpackDir}/osx-${uberArch}</outputDirectory>
</artifactItem>
<artifactItem>
<groupId>io.netty</groupId>
<artifactId>netty-tcnative-boringssl-static</artifactId>
<version>${project.version}</version>
<classifier>linux-x86_64</classifier>
<classifier>linux-${uberArch}</classifier>
<type>jar</type>
<outputDirectory>${unpackDir}/linux-x86_64</outputDirectory>
<outputDirectory>${unpackDir}/linux-${uberArch}</outputDirectory>
</artifactItem>
<artifactItem>
<groupId>io.netty</groupId>
<artifactId>netty-tcnative-boringssl-static</artifactId>
<version>${project.version}</version>
<classifier>windows-x86_64</classifier>
<classifier>windows-${uberArch}</classifier>
<type>jar</type>
<outputDirectory>${unpackDir}/windows-x86_64</outputDirectory>
<outputDirectory>${unpackDir}/windows-${uberArch}</outputDirectory>
</artifactItem>
<!-- Now unpack all of the Java classes and the original MANIFEST.MF -->
......@@ -340,16 +351,129 @@
<target name="copy-jni-libs">
<mkdir dir="${nativeDir}" />
<copy todir="${nativeDir}" flatten="true">
<fileset dir="${unpackDir}/osx-x86_64/META-INF/native" />
<globmapper from="libnetty-tcnative.*" to="libnetty-tcnative-osx-x86_64.*" />
<fileset dir="${unpackDir}/osx-${uberArch}/META-INF/native" />
<globmapper from="libnetty_tcnative.*" to="libnetty_tcnative_osx_${uberArch}.*" />
</copy>
<copy todir="${nativeDir}" flatten="true">
<fileset dir="${unpackDir}/linux-${uberArch}/META-INF/native" />
<globmapper from="libnetty_tcnative.*" to="libnetty_tcnative_linux_${uberArch}.*" />
</copy>
<copy todir="${nativeDir}" flatten="true">
<fileset dir="${unpackDir}/linux-x86_64/META-INF/native" />
<globmapper from="libnetty-tcnative.*" to="libnetty-tcnative-linux-x86_64.*" />
<fileset dir="${unpackDir}/windows-${uberArch}/META-INF/native" />
<globmapper from="netty_tcnative.*" to="netty_tcnative_windows_${uberArch}.*" />
</copy>
</target>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<executions>
<execution>
<id>generate-manifest</id>
<phase>process-classes</phase>
<goals>
<goal>manifest</goal>
</goals>
<configuration>
<supportedProjectTypes>
<supportedProjectType>jar</supportedProjectType>
</supportedProjectTypes>
<instructions>
<Export-Package>io.netty.internal.tcnative.*</Export-Package>
<Bundle-NativeCode>
META-INF/native/libnetty_tcnative_osx_${uberArch}.jnilib;osname=macos;osname=macosx;processor=${uberArch},
META-INF/native/libnetty_tcnative_linux_${uberArch}.so;osname=linux;processor=${uberArch},
META-INF/native/netty_tcnative_windows_${uberArch}.dll;osname=win32;processor=${uberArch}
</Bundle-NativeCode>
</instructions>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>uber-snapshot</id>
<properties>
<unpackDir>${project.build.directory}/unpack</unpackDir>
<libDir>${project.build.directory}/lib</libDir>
<nativeDir>${project.build.outputDirectory}/META-INF/native</nativeDir>
<skipTests>true</skipTests>
<uberArch>${os.detected.arch}</uberArch>
</properties>
<build>
<plugins>
<plugin>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>unpack</id>
<phase>generate-resources</phase>
<goals>
<goal>unpack</goal>
</goals>
<configuration>
<artifactItems>
<!-- Unpack just the native libraries (windows excluded as we not publish snapshots for it yet) -->
<artifactItem>
<groupId>io.netty</groupId>
<artifactId>netty-tcnative-boringssl-static</artifactId>
<version>${project.version}</version>
<classifier>osx-${uberArch}</classifier>
<type>jar</type>
<outputDirectory>${unpackDir}/osx-${uberArch}</outputDirectory>
</artifactItem>
<artifactItem>
<groupId>io.netty</groupId>
<artifactId>netty-tcnative-boringssl-static</artifactId>
<version>${project.version}</version>
<classifier>linux-${uberArch}</classifier>
<type>jar</type>
<outputDirectory>${unpackDir}/linux-${uberArch}</outputDirectory>
</artifactItem>
<!-- Now unpack all of the Java classes and the original MANIFEST.MF -->
<artifactItem>
<groupId>io.netty</groupId>
<artifactId>netty-tcnative-boringssl-static</artifactId>
<version>${project.version}</version>
<type>jar</type>
<outputDirectory>${project.build.outputDirectory}</outputDirectory>
<includes>**/*.class,**/MANIFEST.MF</includes>
</artifactItem>
</artifactItems>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<id>copy-jni-libs</id>
<phase>generate-resources</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<!-- Windows excluded as we not publish snapshots for it yet -->
<target name="copy-jni-libs">
<mkdir dir="${nativeDir}" />
<copy todir="${nativeDir}" flatten="true">
<fileset dir="${unpackDir}/osx-${uberArch}/META-INF/native" />
<globmapper from="libnetty_tcnative.*" to="libnetty_tcnative_osx_${uberArch}.*" />
</copy>
<copy todir="${nativeDir}" flatten="true">
<fileset dir="${unpackDir}/windows-x86_64/META-INF/native" />
<globmapper from="netty-tcnative.*" to="netty-tcnative-windows-x86_64.*" />
<fileset dir="${unpackDir}/linux-${uberArch}/META-INF/native" />
<globmapper from="libnetty_tcnative.*" to="libnetty_tcnative_linux_${uberArch}.*" />
</copy>
</target>
</configuration>
......@@ -372,11 +496,11 @@
<supportedProjectType>jar</supportedProjectType>
</supportedProjectTypes>
<instructions>
<Export-Package>org.apache.tomcat.jni.*</Export-Package>
<Export-Package>io.netty.internal.tcnative.*</Export-Package>
<Bundle-NativeCode>
META-INF/native/libnetty-tcnative-osx-x86_64.jnilib;osname=macos;osname=macosx;processor=x86_64,
META-INF/native/libnetty-tcnative-linux-x86_64.so;osname=linux;processor=x86_64,
META-INF/native/netty-tcnative-windows-x86_64.dll;osname=win32;processor=x86_64
META-INF/native/libnetty_tcnative_osx_${uberArch}.jnilib;osname=macos;osname=macosx;processor=${uberArch},
META-INF/native/libnetty_tcnative_linux_${uberArch}.so;osname=linux;processor=${uberArch},
META-INF/native/netty_tcnative_windows_${uberArch}.dll;osname=win32;processor=${uberArch}
</Bundle-NativeCode>
</instructions>
</configuration>
......
......@@ -19,7 +19,7 @@
<parent>
<groupId>io.netty</groupId>
<artifactId>netty-tcnative-parent</artifactId>
<version>1.1.33.Fork26</version>
<version>2.0.15.Final</version>
</parent>
<artifactId>netty-tcnative-libressl-static</artifactId>
<packaging>jar</packaging>
......@@ -54,7 +54,7 @@
</goals>
<phase>compile</phase>
<configuration>
<name>netty-tcnative</name>
<name>netty_tcnative</name>
<nativeSourceDirectory>${project.basedir}/src/main/c</nativeSourceDirectory>
<libDirectory>${nativeLibOnlyDir}</libDirectory>
<forceAutogen>${forceAutogen}</forceAutogen>
......@@ -63,6 +63,7 @@
<configureArgs>
<configureArg>--with-ssl=${sslHome}</configureArg>
<configureArg>--with-apr=${aprHome}</configureArg>
<configureArg>--with-static-libs</configureArg>
</configureArgs>
</configuration>
</execution>
......@@ -149,8 +150,9 @@
</plugins>
</build>
</profile>
<profile>
<id>build-libressl-linux-mac</id>
<id>build-libressl-non-windows</id>
<activation>
<os>
<family>!windows</family>
......@@ -163,7 +165,7 @@
<executions>
<!-- Download and build LibreSSL -->
<execution>
<id>build-libressl-linux-mac</id>
<id>build-libressl-non-windows</id>
<phase>generate-sources</phase>
<goals>
<goal>run</goal>
......@@ -178,7 +180,7 @@
</exec>
<mkdir dir="${sslHome}" />
<exec executable="configure" failonerror="true" dir="${libresslCheckoutDir}" resolveexecutable="true">
<arg line="--disable-shared --prefix=${sslHome} CFLAGS=-fPIC" />
<arg line="--disable-shared --prefix=${sslHome} CFLAGS='-O3 -fno-omit-frame-pointer -fPIC'" />
</exec>
<exec executable="make" failonerror="true" dir="${libresslCheckoutDir}" resolveexecutable="true" />
<exec executable="make" failonerror="true" dir="${libresslCheckoutDir}" resolveexecutable="true">
......
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "[]"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright [yyyy] [name of copyright owner]
Licensed 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.
......@@ -19,7 +19,7 @@
<parent>
<groupId>io.netty</groupId>
<artifactId>netty-tcnative-parent</artifactId>
<version>1.1.33.Fork26</version>
<version>2.0.15.Final</version>
</parent>
<artifactId>netty-tcnative</artifactId>
<packaging>jar</packaging>
......@@ -80,7 +80,7 @@
<execution>
<id>build-native-lib</id>
<configuration>
<name>netty-tcnative</name>
<name>netty_tcnative</name>
<nativeSourceDirectory>${project.basedir}/src/main/c</nativeSourceDirectory>
<libDirectory>${nativeLibOnlyDir}</libDirectory>
<forceAutogen>${forceAutogen}</forceAutogen>
......@@ -107,6 +107,10 @@
<family>windows</family>
</os>
</activation>
<properties>
<!-- Skip tests on windows as its not easy to load the openssl library we link against in the tests -->
<skipTests>true</skipTests>
</properties>
<build>
<plugins>
<plugin>
......@@ -158,7 +162,7 @@
<execution>
<id>build-native-lib</id>
<configuration>
<name>netty-tcnative</name>
<name>netty_tcnative</name>
<nativeSourceDirectory>${project.basedir}/src/main/c</nativeSourceDirectory>
<libDirectory>${nativeLibOnlyDir}</libDirectory>
<forceAutogen>${forceAutogen}</forceAutogen>
......
/* 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.
* The ASF 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.
*/
/*
*
* @author Mladen Turk
* @version $Id: address.c 1442587 2013-02-05 13:49:48Z rjung $
*/
#include "tcn.h"
TCN_IMPLEMENT_CALL(jlong, Address, info)(TCN_STDARGS,
jstring hostname,
jint family, jint port,
jint flags, jlong pool)
{
apr_pool_t *p = J2P(pool, apr_pool_t *);
TCN_ALLOC_CSTRING(hostname);
char *sp = NULL;
int scope_id = 0;
apr_sockaddr_t *sa = NULL;
apr_sockaddr_t *sl = NULL;
apr_int32_t f;
UNREFERENCED(o);
GET_S_FAMILY(f, family);
#if APR_HAVE_IPV6
if (hostname) {
/* XXX: This only works for real scope_id's
*/
if ((sp = strchr(J2S(hostname), '%'))) {
*sp++ = '\0';
scope_id = atoi(sp);
}
}
#endif
TCN_THROW_IF_ERR(apr_sockaddr_info_get(&sa,
J2S(hostname), f, (apr_port_t)port,
(apr_int32_t)flags, p), sa);
sl = sa;
/*
* apr_sockaddr_info_get may return several address so this is not
* go to work in some cases (but as least it works for Linux)
* XXX: with AP_ENABLE_V4_MAPPED it is going to work otherwise it won't.
*/
#if APR_HAVE_IPV6
if (hostname == NULL) {
/* Try all address using IPV6 one */
while (sl) {
if (sl->family == APR_INET6)
break; /* Done */
sl = sl->next;
}
/* If we don't find an IPv6 address, use the original one */
if (sl == NULL) {
sl = sa;
}
}
if (sp) {
/* Set the provided scope id
* APR lack the api for setting this directly so lets presume
* the sin6_scope_id is present everywhere
*/
sl->sa.sin6.sin6_scope_id = scope_id;
}
#endif
cleanup:
TCN_FREE_CSTRING(hostname);
return P2J(sl);
}
TCN_IMPLEMENT_CALL(jstring, Address, getnameinfo)(TCN_STDARGS,
jlong sa, jint flags)
{
apr_sockaddr_t *s = J2P(sa, apr_sockaddr_t *);
char *hostname;
UNREFERENCED(o);
if (apr_getnameinfo(&hostname, s, (apr_int32_t)flags) == APR_SUCCESS)
return AJP_TO_JSTRING(hostname);
else
return NULL;
}
TCN_IMPLEMENT_CALL(jstring, Address, getip)(TCN_STDARGS, jlong sa)
{
apr_sockaddr_t *s = J2P(sa, apr_sockaddr_t *);
char *ipaddr;
UNREFERENCED(o);
if (apr_sockaddr_ip_get(&ipaddr, s) == APR_SUCCESS)
return AJP_TO_JSTRING(ipaddr);
else
return NULL;
}
TCN_IMPLEMENT_CALL(jlong, Address, get)(TCN_STDARGS, jint which,
jlong sock)
{
tcn_socket_t *s = J2P(sock, tcn_socket_t *);
apr_sockaddr_t *sa = NULL;
UNREFERENCED(o);
TCN_THROW_IF_ERR(apr_socket_addr_get(&sa,
(apr_interface_e)which, s->sock), sa);
cleanup:
return P2J(sa);
}
TCN_IMPLEMENT_CALL(jboolean, Address, equal)(TCN_STDARGS,
jlong a, jlong b)
{
apr_sockaddr_t *sa = J2P(a, apr_sockaddr_t *);
apr_sockaddr_t *sb = J2P(b, apr_sockaddr_t *);
UNREFERENCED_STDARGS;
return apr_sockaddr_equal(sa, sb) ? JNI_TRUE : JNI_FALSE;
}
TCN_IMPLEMENT_CALL(jint, Address, getservbyname)(TCN_STDARGS,
jlong sa, jstring servname)
{
apr_sockaddr_t *s = J2P(sa, apr_sockaddr_t *);
TCN_ALLOC_CSTRING(servname);
apr_status_t rv;
UNREFERENCED(o);
rv = apr_getservbyname(s, J2S(servname));
TCN_FREE_CSTRING(servname);
return (jint)rv;
}
/*
* 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.
......@@ -14,122 +29,35 @@
* limitations under the License.
*/
/*
*
* @author Mladen Turk
* @version $Id: bb.c 1442587 2013-02-05 13:49:48Z rjung $
*/
#include "tcn.h"
#include "bb.h"
/**
* DirectByteBuffer utilities
*/
TCN_IMPLEMENT_CALL(jobject, Buffer, malloc)(TCN_STDARGS, jint size)
{
void *mem;
size_t sz = (size_t)APR_ALIGN_DEFAULT(size);
UNREFERENCED(o);
if ((mem = malloc(sz)) != NULL) {
jobject rv = (*e)->NewDirectByteBuffer(e, mem, (jlong)sz);
if (rv == NULL)
free(mem);
return rv;
}
else {
return NULL;
}
}
TCN_IMPLEMENT_CALL(jobject, Buffer, calloc)(TCN_STDARGS, jint num, jint size)
{
size_t sz = (size_t)APR_ALIGN_DEFAULT((size * num));
void *mem;
UNREFERENCED(o);
if ((mem = calloc(1, sz)) != NULL) {
jobject rv = (*e)->NewDirectByteBuffer(e, mem, (jlong)sz);
if (rv == NULL)
free(mem);
return rv;
}
else {
return NULL;
}
}
TCN_IMPLEMENT_CALL(jobject, Buffer, palloc)(TCN_STDARGS, jlong pool,
jint size)
TCN_IMPLEMENT_CALL(jlong, Buffer, address)(TCN_STDARGS, jobject bb)
{
apr_pool_t *p = J2P(pool, apr_pool_t *);
apr_size_t sz = (apr_size_t)APR_ALIGN_DEFAULT(size);
void *mem;
UNREFERENCED(o);
TCN_ASSERT(pool != 0);
if ((mem = apr_palloc(p, sz)) != NULL)
return (*e)->NewDirectByteBuffer(e, mem, (jlong)sz);
else
return NULL;
return P2J((*e)->GetDirectBufferAddress(e, bb));
}
TCN_IMPLEMENT_CALL(jobject, Buffer, pcalloc)(TCN_STDARGS, jlong pool,
jint size)
TCN_IMPLEMENT_CALL(jlong, Buffer, size)(TCN_STDARGS, jobject bb)
{
apr_pool_t *p = J2P(pool, apr_pool_t *);
apr_size_t sz = (apr_size_t)APR_ALIGN_DEFAULT(size);
void *mem;
UNREFERENCED(o);
TCN_ASSERT(pool != 0);
if ((mem = apr_pcalloc(p, sz)) != NULL)
return (*e)->NewDirectByteBuffer(e, mem, (jlong)sz);
else
return NULL;
return (*e)->GetDirectBufferCapacity(e, bb);
}
TCN_IMPLEMENT_CALL(jobject, Buffer, create)(TCN_STDARGS, jlong addr,
jint size)
{
void *mem = J2P(addr, void *);
UNREFERENCED(o);
TCN_ASSERT(mem != 0);
TCN_ASSERT(size != 0);
if (mem && size)
return (*e)->NewDirectByteBuffer(e, mem, (jlong)size);
else
return NULL;
}
// JNI Method Registration Table Begin
static const JNINativeMethod method_table[] = {
{ TCN_METHOD_TABLE_ENTRY(address, (Ljava/nio/ByteBuffer;)J, Buffer) },
{ TCN_METHOD_TABLE_ENTRY(size, (Ljava/nio/ByteBuffer;)J, Buffer) }
};
TCN_IMPLEMENT_CALL(void, Buffer, free)(TCN_STDARGS, jobject bb)
{
void *mem;
static const jint method_table_size = sizeof(method_table) / sizeof(method_table[0]);
// JNI Method Registration Table End
UNREFERENCED(o);
if ((mem = (*e)->GetDirectBufferAddress(e, bb)) != NULL) {
/* This can cause core dump if address was
* allocated from the APR pool.
*/
free(mem);
}
jint netty_internal_tcnative_Buffer_JNI_OnLoad(JNIEnv* env, const char* packagePrefix) {
if (netty_internal_tcnative_util_register_natives(env, packagePrefix, "io/netty/internal/tcnative/Buffer", method_table, method_table_size) != 0) {
return JNI_ERR;
}
TCN_IMPLEMENT_CALL(jlong, Buffer, address)(TCN_STDARGS, jobject bb)
{
UNREFERENCED(o);
return P2J((*e)->GetDirectBufferAddress(e, bb));
return TCN_JNI_VERSION;
}
TCN_IMPLEMENT_CALL(jlong, Buffer, size)(TCN_STDARGS, jobject bb)
{
UNREFERENCED(o);
return (*e)->GetDirectBufferCapacity(e, bb);
}
void netty_internal_tcnative_Buffer_JNI_OnUnLoad(JNIEnv* env) { }
/*
* Copyright 2017 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.
*/
#ifndef NETTY_TCNATIVE_BB_H_
#define NETTY_TCNATIVE_BB_H_
// JNI initialization hooks. Users of this file are responsible for calling these in the JNI_OnLoad and JNI_OnUnload methods.
jint netty_internal_tcnative_Buffer_JNI_OnLoad(JNIEnv* env, const char* packagePrefix);
void netty_internal_tcnative_Buffer_JNI_OnUnLoad(JNIEnv* env);
#endif /* NETTY_TCNATIVE_BB_H_ */
/* 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.
* The ASF 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.
*/
/*
*
* @author Mladen Turk
* @version $Id: dir.c 1442587 2013-02-05 13:49:48Z rjung $
*/
#include "tcn.h"
#include "apr_file_io.h"
TCN_IMPLEMENT_CALL(jint, Directory, make)(TCN_STDARGS, jstring path,
jint perm, jlong pool)
{
apr_pool_t *p = J2P(pool, apr_pool_t *);
TCN_ALLOC_CSTRING(path);
apr_status_t rv;
UNREFERENCED(o);
rv = apr_dir_make(J2S(path), (apr_fileperms_t)perm, p);
TCN_FREE_CSTRING(path);
return (jint)rv;
}
TCN_IMPLEMENT_CALL(jint, Directory, makeRecursive)(TCN_STDARGS, jstring path,
jint perm, jlong pool)
{
apr_pool_t *p = J2P(pool, apr_pool_t *);
TCN_ALLOC_CSTRING(path);
apr_status_t rv;
UNREFERENCED(o);
rv = apr_dir_make_recursive(J2S(path), (apr_fileperms_t)perm, p);
TCN_FREE_CSTRING(path);
return (jint)rv;
}
TCN_IMPLEMENT_CALL(jint, Directory, remove)(TCN_STDARGS, jstring path,
jlong pool)
{
apr_pool_t *p = J2P(pool, apr_pool_t *);
TCN_ALLOC_CSTRING(path);
apr_status_t rv;
UNREFERENCED(o);
rv = apr_dir_remove(J2S(path), p);
TCN_FREE_CSTRING(path);
return (jint)rv;
}
TCN_IMPLEMENT_CALL(jstring, Directory, tempGet)(TCN_STDARGS, jlong pool)
{
apr_pool_t *p = J2P(pool, apr_pool_t *);
jstring name = NULL;
const char *tname;
UNREFERENCED(o);
if (apr_temp_dir_get(&tname, p) == APR_SUCCESS)
name = AJP_TO_JSTRING(tname);
return name;
}
TCN_IMPLEMENT_CALL(jlong, Directory, open)(TCN_STDARGS, jstring path,
jlong pool)
{
apr_pool_t *p = J2P(pool, apr_pool_t *);
apr_dir_t *d = NULL;
TCN_ALLOC_CSTRING(path);
UNREFERENCED(o);
TCN_THROW_IF_ERR(apr_dir_open(&d, J2S(path), p), d);
cleanup:
TCN_FREE_CSTRING(path);
return P2J(d);
}
TCN_IMPLEMENT_CALL(jint, Directory, close)(TCN_STDARGS, jlong dir)
{
apr_dir_t *d = J2P(dir, apr_dir_t *);
UNREFERENCED_STDARGS;
return (jint)apr_dir_close(d);
}
TCN_IMPLEMENT_CALL(jint, Directory, rewind)(TCN_STDARGS, jlong dir)
{
apr_dir_t *d = J2P(dir, apr_dir_t *);
UNREFERENCED_STDARGS;
return (jint)apr_dir_rewind(d);
}
/*
* 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.
......@@ -14,72 +29,24 @@
* 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
};
static jclass exceptionClass;
static jclass nullPointerExceptionClass;
/* 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.
*/
void tcn_ThrowException(JNIEnv *env, const char *msg)
{
jclass javaExceptionClass;
javaExceptionClass = (*env)->FindClass(env, "java/lang/Exception");
if (javaExceptionClass == NULL) {
fprintf(stderr, "Cannot find java/lang/Exception class\n");
return;
}
(*env)->ThrowNew(env, javaExceptionClass, msg);
(*env)->DeleteLocalRef(env, javaExceptionClass);
(*env)->ThrowNew(env, exceptionClass, msg);
}
void tcn_ThrowMemoryException(JNIEnv *env, const char *file, int line, const char *msg)
void tcn_ThrowNullPointerException(JNIEnv *env, 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++;
(*env)->ThrowNew(env, nullPointerExceptionClass, msg);
}
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'};
......@@ -91,158 +58,23 @@ 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_ThrowException(e, serr);
}
TCN_IMPLEMENT_CALL(jint, Error, netosError)(TCN_STDARGS)
{
UNREFERENCED_STDARGS;
return (jint)apr_get_netos_error();
}
jint netty_internal_tcnative_Error_JNI_OnLoad(JNIEnv* env, const char* packagePrefix) {
TCN_IMPLEMENT_CALL(jstring, Error, strerror)(TCN_STDARGS, jint err)
{
char serr[512] = {0};
jstring jerr;
TCN_LOAD_CLASS(env, exceptionClass, "java/lang/Exception", JNI_ERR);
TCN_LOAD_CLASS(env, nullPointerExceptionClass, "java/lang/NullPointerException", JNI_ERR);
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 TCN_JNI_VERSION;
}
return jerr;
}
TCN_IMPLEMENT_CALL(jboolean, Status, is)(TCN_STDARGS, jint err, jint idx)
{
#define APR_IS(I, E) case I: if (E(err)) return JNI_TRUE; break
#define APR_ISX(I, E, T) case I: if (E(err) || (err == T)) return JNI_TRUE; break
UNREFERENCED_STDARGS;
switch (idx) {
APR_IS(1, APR_STATUS_IS_ENOSTAT);
APR_IS(2, APR_STATUS_IS_ENOPOOL);
/* empty slot: +3 */
APR_IS(4, APR_STATUS_IS_EBADDATE);
APR_IS(5, APR_STATUS_IS_EINVALSOCK);
APR_IS(6, APR_STATUS_IS_ENOPROC);
APR_IS(7, APR_STATUS_IS_ENOTIME);
APR_IS(8, APR_STATUS_IS_ENODIR);
APR_IS(9, APR_STATUS_IS_ENOLOCK);
APR_IS(10, APR_STATUS_IS_ENOPOLL);
APR_IS(11, APR_STATUS_IS_ENOSOCKET);
APR_IS(12, APR_STATUS_IS_ENOTHREAD);
APR_IS(13, APR_STATUS_IS_ENOTHDKEY);
APR_IS(14, APR_STATUS_IS_EGENERAL);
APR_IS(15, APR_STATUS_IS_ENOSHMAVAIL);
APR_IS(16, APR_STATUS_IS_EBADIP);
APR_IS(17, APR_STATUS_IS_EBADMASK);
/* empty slot: +18 */
APR_IS(19, APR_STATUS_IS_EDSOOPEN);
APR_IS(20, APR_STATUS_IS_EABSOLUTE);
APR_IS(21, APR_STATUS_IS_ERELATIVE);
APR_IS(22, APR_STATUS_IS_EINCOMPLETE);
APR_IS(23, APR_STATUS_IS_EABOVEROOT);
APR_IS(24, APR_STATUS_IS_EBADPATH);
APR_IS(25, APR_STATUS_IS_EPATHWILD);
APR_IS(26, APR_STATUS_IS_ESYMNOTFOUND);
APR_IS(27, APR_STATUS_IS_EPROC_UNKNOWN);
APR_IS(28, APR_STATUS_IS_ENOTENOUGHENTROPY);
/* APR_Error */
APR_IS(51, APR_STATUS_IS_INCHILD);
APR_IS(52, APR_STATUS_IS_INPARENT);
APR_IS(53, APR_STATUS_IS_DETACH);
APR_IS(54, APR_STATUS_IS_NOTDETACH);
APR_IS(55, APR_STATUS_IS_CHILD_DONE);
APR_IS(56, APR_STATUS_IS_CHILD_NOTDONE);
APR_ISX(57, APR_STATUS_IS_TIMEUP, TCN_TIMEUP);
APR_IS(58, APR_STATUS_IS_INCOMPLETE);
/* empty slot: +9 */
/* empty slot: +10 */
/* empty slot: +11 */
APR_IS(62, APR_STATUS_IS_BADCH);
APR_IS(63, APR_STATUS_IS_BADARG);
APR_IS(64, APR_STATUS_IS_EOF);
APR_IS(65, APR_STATUS_IS_NOTFOUND);
/* empty slot: +16 */
/* empty slot: +17 */
/* empty slot: +18 */
APR_IS(69, APR_STATUS_IS_ANONYMOUS);
APR_IS(70, APR_STATUS_IS_FILEBASED);
APR_IS(71, APR_STATUS_IS_KEYBASED);
APR_IS(72, APR_STATUS_IS_EINIT);
APR_IS(73, APR_STATUS_IS_ENOTIMPL);
APR_IS(74, APR_STATUS_IS_EMISMATCH);
APR_IS(75, APR_STATUS_IS_EBUSY);
/* Socket errors */
APR_ISX(90, APR_STATUS_IS_EAGAIN, TCN_EAGAIN);
APR_ISX(91, TCN_STATUS_IS_ETIMEDOUT, TCN_ETIMEDOUT);
APR_IS(92, APR_STATUS_IS_ECONNABORTED);
APR_IS(93, APR_STATUS_IS_ECONNRESET);
APR_ISX(94, APR_STATUS_IS_EINPROGRESS, TCN_EINPROGRESS);
APR_ISX(95, APR_STATUS_IS_EINTR, TCN_EINTR);
APR_IS(96, APR_STATUS_IS_ENOTSOCK);
APR_IS(97, APR_STATUS_IS_EINVAL);
}
return JNI_FALSE;
void netty_internal_tcnative_Error_JNI_OnUnLoad(JNIEnv* env) {
TCN_UNLOAD_CLASS(env, exceptionClass);
TCN_UNLOAD_CLASS(env, nullPointerExceptionClass);
}
/*
* Copyright 2017 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.
*/
#ifndef NETTY_TCNATIVE_ERROR_H_
#define NETTY_TCNATIVE_ERROR_H_
// JNI initialization hooks. Users of this file are responsible for calling these in the JNI_OnLoad and JNI_OnUnload methods.
jint netty_internal_tcnative_Error_JNI_OnLoad(JNIEnv* env, const char* packagePrefix);
void netty_internal_tcnative_Error_JNI_OnUnLoad(JNIEnv* env);
#endif /* NETTY_TCNATIVE_ERROR_H_ */
/* 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.
* The ASF 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.
*/
/*
*
* @author Mladen Turk
* @version $Id: file.c 1442587 2013-02-05 13:49:48Z rjung $
*/
#include "tcn.h"
#include "apr_file_io.h"
TCN_IMPLEMENT_CALL(jint, File, close)(TCN_STDARGS, jlong file)
{
apr_file_t *f = J2P(file, apr_file_t *);
UNREFERENCED_STDARGS;
return (jint)apr_file_close(f);
}
TCN_IMPLEMENT_CALL(jint, File, eof)(TCN_STDARGS, jlong file)
{
apr_file_t *f = J2P(file, apr_file_t *);
UNREFERENCED_STDARGS;
return (jint)apr_file_eof(f);
}
TCN_IMPLEMENT_CALL(jint, File, flush)(TCN_STDARGS, jlong file)
{
apr_file_t *f = J2P(file, apr_file_t *);
UNREFERENCED_STDARGS;
return (jint)apr_file_flush(f);
}
TCN_IMPLEMENT_CALL(jint, File, unlock)(TCN_STDARGS, jlong file)
{
apr_file_t *f = J2P(file, apr_file_t *);
UNREFERENCED_STDARGS;
return (jint)apr_file_unlock(f);
}
TCN_IMPLEMENT_CALL(jint, File, flagsGet)(TCN_STDARGS, jlong file)
{
apr_file_t *f = J2P(file, apr_file_t *);
UNREFERENCED_STDARGS;
return (jint)apr_file_flags_get(f);
}
TCN_IMPLEMENT_CALL(jint, File, lock)(TCN_STDARGS, jlong file, jint flags)
{
apr_file_t *f = J2P(file, apr_file_t *);
UNREFERENCED_STDARGS;
return (jint)apr_file_lock(f, (int)flags);
}
TCN_IMPLEMENT_CALL(jint, File, trunc)(TCN_STDARGS, jlong file, jlong off)
{
apr_file_t *f = J2P(file, apr_file_t *);
UNREFERENCED_STDARGS;
return (jint)apr_file_trunc(f, (apr_off_t)off);
}
TCN_IMPLEMENT_CALL(jlong, File, open)(TCN_STDARGS, jstring fname,
jint flag, jint perm,
jlong pool)
{
apr_pool_t *p = J2P(pool, apr_pool_t *);
apr_file_t *f = NULL;
TCN_ALLOC_CSTRING(fname);
UNREFERENCED(o);
TCN_THROW_IF_ERR(apr_file_open(&f, J2S(fname), (apr_int32_t)flag,
(apr_fileperms_t)perm, p), f);
cleanup:
TCN_FREE_CSTRING(fname);
return P2J(f);
}
TCN_IMPLEMENT_CALL(jlong, File, mktemp)(TCN_STDARGS, jstring templ,
jint flags,
jlong pool)
{
apr_pool_t *p = J2P(pool, apr_pool_t *);
apr_file_t *f = NULL;
char *ctempl = tcn_strdup(e, templ);
UNREFERENCED(o);
if (!ctempl) {
TCN_THROW_OS_ERROR(e);
return 0;
}
TCN_THROW_IF_ERR(apr_file_mktemp(&f, ctempl,
(apr_int32_t)flags, p), f);
cleanup:
free(ctempl);
return P2J(f);
}
TCN_IMPLEMENT_CALL(jint, File, remove)(TCN_STDARGS, jstring path, jlong pool)
{
apr_pool_t *p = J2P(pool, apr_pool_t *);
TCN_ALLOC_CSTRING(path);
apr_status_t rv;
UNREFERENCED(o);
rv = apr_file_remove(J2S(path), p);
TCN_FREE_CSTRING(path);
return (jint)rv;
}
TCN_IMPLEMENT_CALL(jint, File, rename)(TCN_STDARGS, jstring from,
jstring to, jlong pool)
{
apr_pool_t *p = J2P(pool, apr_pool_t *);
TCN_ALLOC_CSTRING(from);
TCN_ALLOC_CSTRING(to);
apr_status_t rv;
UNREFERENCED(o);
rv = apr_file_rename(J2S(from), J2S(to), p);
TCN_FREE_CSTRING(from);
TCN_FREE_CSTRING(to);
return (jint)rv;
}
TCN_IMPLEMENT_CALL(jint, File, copy)(TCN_STDARGS, jstring from,
jstring to, jint perms, jlong pool)
{
apr_pool_t *p = J2P(pool, apr_pool_t *);
TCN_ALLOC_CSTRING(from);
TCN_ALLOC_CSTRING(to);
apr_status_t rv;
UNREFERENCED(o);
rv = apr_file_copy(J2S(from), J2S(to), (apr_fileperms_t)perms, p);
TCN_FREE_CSTRING(from);
TCN_FREE_CSTRING(to);
return (jint)rv;
}
TCN_IMPLEMENT_CALL(jint, File, append)(TCN_STDARGS, jstring from,
jstring to, jint perms, jlong pool)
{
apr_pool_t *p = J2P(pool, apr_pool_t *);
TCN_ALLOC_CSTRING(from);
TCN_ALLOC_CSTRING(to);
apr_status_t rv;
UNREFERENCED(o);
rv = apr_file_append(J2S(from), J2S(to), (apr_fileperms_t)perms, p);
TCN_FREE_CSTRING(from);
TCN_FREE_CSTRING(to);
return (jint)rv;
}
TCN_IMPLEMENT_CALL(jstring, File, nameGet)(TCN_STDARGS, jlong file)
{
apr_file_t *f = J2P(file, apr_file_t *);
jstring name = NULL;
const char *fname;
UNREFERENCED(o);
if (apr_file_name_get(&fname, f) == APR_SUCCESS)
name = AJP_TO_JSTRING(fname);
return name;
}
TCN_IMPLEMENT_CALL(jint, File, permsSet)(TCN_STDARGS, jstring file, jint perms)
{
TCN_ALLOC_CSTRING(file);
apr_status_t rv;
UNREFERENCED(o);
rv = apr_file_perms_set(J2S(file), (apr_fileperms_t)perms);
TCN_FREE_CSTRING(file);
return (jint)rv;
}
TCN_IMPLEMENT_CALL(jint, File, attrsSet)(TCN_STDARGS, jstring file, jint attrs,
jint mask, jlong pool)
{
apr_pool_t *p = J2P(pool, apr_pool_t *);
TCN_ALLOC_CSTRING(file);
apr_status_t rv;
UNREFERENCED(o);
rv = apr_file_attrs_set(J2S(file), (apr_fileattrs_t)attrs,
(apr_fileattrs_t)mask, p);
TCN_FREE_CSTRING(file);
return (jint)rv;
}
TCN_IMPLEMENT_CALL(jint, File, mtimeSet)(TCN_STDARGS, jstring file, jlong mtime,
jlong pool)
{
apr_pool_t *p = J2P(pool, apr_pool_t *);
TCN_ALLOC_CSTRING(file);
apr_status_t rv;
UNREFERENCED(o);
rv = apr_file_mtime_set(J2S(file), J2T(mtime), p);
TCN_FREE_CSTRING(file);
return (jint)rv;
}
TCN_IMPLEMENT_CALL(jlong, File, seek)(TCN_STDARGS, jlong file,
jint where, jlong offset)
{
apr_file_t *f = J2P(file, apr_file_t *);
apr_off_t pos = (apr_off_t)offset;
apr_seek_where_t w;
UNREFERENCED(o);
switch (where) {
case 1:
w = APR_CUR;
break;
case 2:
w = APR_END;
break;
default:
w = APR_SET;
break;
}
TCN_THROW_IF_ERR(apr_file_seek(f, w, &pos), pos);
cleanup:
return (jlong)pos;
}
TCN_IMPLEMENT_CALL(jint, File, putc)(TCN_STDARGS, jbyte c, jlong file)
{
apr_file_t *f = J2P(file, apr_file_t *);
UNREFERENCED_STDARGS;
return (jint)apr_file_putc((char)c, f);
}
TCN_IMPLEMENT_CALL(jint, File, getc)(TCN_STDARGS, jlong file)
{
apr_file_t *f = J2P(file, apr_file_t *);
char ch;
UNREFERENCED_STDARGS;
TCN_THROW_IF_ERR(apr_file_getc(&ch, f), ch);
cleanup:
return (jint)ch;
}
TCN_IMPLEMENT_CALL(jint, File, ungetc)(TCN_STDARGS, jbyte c, jlong file)
{
apr_file_t *f = J2P(file, apr_file_t *);
UNREFERENCED_STDARGS;
return (jint)apr_file_ungetc((char)c, f);
}
TCN_IMPLEMENT_CALL(jint, File, puts)(TCN_STDARGS, jbyteArray str, jlong file)
{
apr_status_t rv = APR_EINVAL;
apr_file_t *f = J2P(file, apr_file_t *);
jbyte *bytes = (*e)->GetPrimitiveArrayCritical(e, str, NULL);
UNREFERENCED(o);
if (bytes) {
rv = apr_file_puts((const char *)bytes, f);
(*e)->ReleasePrimitiveArrayCritical(e, str, bytes, JNI_ABORT);
}
return (jint)rv;
}
TCN_IMPLEMENT_CALL(jint, File, write)(TCN_STDARGS, jlong file,
jbyteArray buf, jint offset, jint towrite)
{
apr_file_t *f = J2P(file, apr_file_t *);
apr_size_t nbytes = (apr_size_t)towrite;
jbyte *bytes = (*e)->GetPrimitiveArrayCritical(e, buf, NULL);
apr_status_t ss;
UNREFERENCED(o);
if (towrite < 0)
towrite = (*e)->GetArrayLength(e, buf);
ss = apr_file_write(f, bytes + offset, &nbytes);
(*e)->ReleasePrimitiveArrayCritical(e, buf, bytes, JNI_ABORT);
if (ss == APR_SUCCESS)
return (jint)nbytes;
else
return -(jint)ss;
}
TCN_IMPLEMENT_CALL(jint, File, writeb)(TCN_STDARGS, jlong file,
jobject buf, jint offset, jint towrite)
{
apr_file_t *f = J2P(file, apr_file_t *);
apr_size_t nbytes = (apr_size_t)towrite;
char *bytes = (char *)(*e)->GetDirectBufferAddress(e, buf);
apr_status_t ss = APR_EINVAL;
UNREFERENCED(o);
if (bytes)
ss = apr_file_write(f, bytes + offset, &nbytes);
if (ss == APR_SUCCESS)
return (jint)nbytes;
else
return -(jint)ss;
}
TCN_IMPLEMENT_CALL(jint, File, writeFull)(TCN_STDARGS, jlong file,
jbyteArray buf, jint offset, jint towrite)
{
apr_file_t *f = J2P(file, apr_file_t *);
apr_size_t nbytes = (apr_size_t)towrite;
apr_size_t written = 0;
apr_status_t ss;
jbyte *bytes = (*e)->GetByteArrayElements(e, buf, NULL);
UNREFERENCED(o);
if (towrite < 0)
towrite = (*e)->GetArrayLength(e, buf);
ss = apr_file_write_full(f, bytes + offset, nbytes, &written);
(*e)->ReleaseByteArrayElements(e, buf, bytes, JNI_ABORT);
if (ss == APR_SUCCESS)
return (jint)written;
else
return -(jint)ss;
}
TCN_IMPLEMENT_CALL(jint, File, writeFullb)(TCN_STDARGS, jlong file,
jobject buf, jint offset, jint towrite)
{
apr_file_t *f = J2P(file, apr_file_t *);
apr_size_t nbytes = (apr_size_t)towrite;
apr_size_t written = 0;
apr_status_t ss = APR_EINVAL;
char *bytes = (char *)(*e)->GetDirectBufferAddress(e, buf);
UNREFERENCED(o);
if (bytes)
ss = apr_file_write_full(f, bytes + offset, nbytes, &written);
if (ss == APR_SUCCESS)
return (jint)written;
else
return -(jint)ss;
}
TCN_IMPLEMENT_CALL(jint, File, writev)(TCN_STDARGS, jlong file,
jobjectArray bufs)
{
apr_file_t *f = J2P(file, apr_file_t *);
jsize nvec = (*e)->GetArrayLength(e, bufs);
jsize i;
struct iovec vec[APR_MAX_IOVEC_SIZE];
jobject ba[APR_MAX_IOVEC_SIZE];
apr_size_t written = 0;
apr_status_t ss;
UNREFERENCED(o);
if (nvec >= APR_MAX_IOVEC_SIZE) {
/* TODO: Throw something here */
return 0;
}
for (i = 0; i < nvec; i++) {
ba[i] = (*e)->GetObjectArrayElement(e, bufs, i);
vec[i].iov_len = (*e)->GetArrayLength(e, ba[i]);
vec[i].iov_base = (void *)((*e)->GetByteArrayElements(e, ba[i], NULL));
}
ss = apr_file_writev(f, vec, nvec, &written);
for (i = 0; i < nvec; i++) {
(*e)->ReleaseByteArrayElements(e, ba[i], (jbyte *)vec[i].iov_base, JNI_ABORT);
}
if (ss == APR_SUCCESS)
return (jint)written;
else
return -(jint)ss;
}
TCN_IMPLEMENT_CALL(jint, File, writevFull)(TCN_STDARGS, jlong file,
jobjectArray bufs)
{
apr_file_t *f = J2P(file, apr_file_t *);
jsize nvec = (*e)->GetArrayLength(e, bufs);
jsize i;
struct iovec vec[APR_MAX_IOVEC_SIZE];
jobject ba[APR_MAX_IOVEC_SIZE];
apr_size_t written = 0;
apr_status_t ss;
UNREFERENCED(o);
if (nvec >= APR_MAX_IOVEC_SIZE) {
/* TODO: Throw something here */
return 0;
}
for (i = 0; i < nvec; i++) {
ba[i] = (*e)->GetObjectArrayElement(e, bufs, i);
vec[i].iov_len = (*e)->GetArrayLength(e, ba[i]);
vec[i].iov_base = (void *)((*e)->GetByteArrayElements(e, ba[i], NULL));
}
#if (APR_VERSION_MAJOR >= 1) && (APR_VERSION_MINOR >= 1)
ss = apr_file_writev_full(f, vec, nvec, &written);
#else
ss = apr_file_writev(f, vec, nvec, &written);
#endif
for (i = 0; i < nvec; i++) {
(*e)->ReleaseByteArrayElements(e, ba[i], (jbyte *)vec[i].iov_base,
JNI_ABORT);
}
if (ss == APR_SUCCESS)
return (jint)written;
else
return -(jint)ss;
}
TCN_IMPLEMENT_CALL(jint, File, read)(TCN_STDARGS, jlong file,
jbyteArray buf, jint offset,
jint toread)
{
apr_file_t *f = J2P(file, apr_file_t *);
apr_size_t nbytes = (apr_size_t)toread;
jbyte *bytes = (*e)->GetByteArrayElements(e, buf, NULL);
apr_status_t ss;
UNREFERENCED(o);
ss = apr_file_read(f, bytes + offset, &nbytes);
(*e)->ReleaseByteArrayElements(e, buf, bytes,
ss == APR_SUCCESS ? 0 : JNI_ABORT);
if (ss == APR_SUCCESS)
return (jint)nbytes;
else
return -(jint)ss;
}
TCN_IMPLEMENT_CALL(jint, File, readb)(TCN_STDARGS, jlong file,
jobject buf, jint offset,
jint toread)
{
apr_file_t *f = J2P(file, apr_file_t *);
apr_size_t nbytes = (apr_size_t)toread;
char *bytes = (char *)(*e)->GetDirectBufferAddress(e, buf);
apr_status_t ss = APR_EINVAL;
UNREFERENCED(o);
if (bytes)
ss = apr_file_read(f, bytes + offset, &nbytes);
if (ss == APR_SUCCESS)
return (jint)nbytes;
else
return -(jint)ss;
}
TCN_IMPLEMENT_CALL(jint, File, readFull)(TCN_STDARGS, jlong file,
jbyteArray buf, jint offset,
jint toread)
{
apr_file_t *f = J2P(file, apr_file_t *);
apr_size_t nbytes = (apr_size_t)toread;
apr_size_t nread = 0;
apr_status_t ss;
jbyte *bytes = (*e)->GetByteArrayElements(e, buf, NULL);
UNREFERENCED(o);
ss = apr_file_read_full(f, bytes + offset, nbytes, &nread);
(*e)->ReleaseByteArrayElements(e, buf, bytes,
ss == APR_SUCCESS ? 0 : JNI_ABORT);
if (ss == APR_SUCCESS)
return (jint)nread;
else
return -(jint)ss;
}
TCN_IMPLEMENT_CALL(jint, File, readFullb)(TCN_STDARGS, jlong file,
jobject buf, jint offset,
jint toread)
{
apr_file_t *f = J2P(file, apr_file_t *);
apr_size_t nbytes = (apr_size_t)toread;
apr_size_t nread = 0;
char *bytes = (char *)(*e)->GetDirectBufferAddress(e, buf);
apr_status_t ss = APR_EINVAL;
UNREFERENCED(o);
if (bytes)
ss = apr_file_read_full(f, bytes + offset, nbytes, &nread);
if (ss == APR_SUCCESS)
return (jint)nread;
else
return -(jint)ss;
}
TCN_IMPLEMENT_CALL(jint, File, gets)(TCN_STDARGS, jbyteArray buf, jint offset,
jlong file)
{
apr_status_t rv;
apr_file_t *f = J2P(file, apr_file_t *);
jsize nbytes = (*e)->GetArrayLength(e, buf);
jbyte *bytes = (*e)->GetByteArrayElements(e, buf, NULL);
UNREFERENCED(o);
rv = apr_file_gets((char*)(bytes + offset),nbytes - offset, f);
(*e)->ReleaseByteArrayElements(e, buf, bytes,
rv == APR_SUCCESS ? 0 : JNI_ABORT);
return (jint)rv;
}
TCN_IMPLEMENT_CALL(jint, File, pipeCreate)(TCN_STDARGS, jlongArray io, jlong pool)
{
apr_status_t rv;
apr_pool_t *p = J2P(pool, apr_pool_t *);
jsize npipes = (*e)->GetArrayLength(e, io);
jlong *pipes = (*e)->GetLongArrayElements(e, io, NULL);
apr_file_t *in;
apr_file_t *out;
UNREFERENCED(o);
if (npipes < 2) {
(*e)->ReleaseLongArrayElements(e, io, pipes, JNI_ABORT);
return APR_EINVAL;
}
rv = apr_file_pipe_create(&in, &out, p);
if (rv == APR_SUCCESS) {
pipes[0] = P2J(in);
pipes[1] = P2J(out);
(*e)->ReleaseLongArrayElements(e, io, pipes, 0);
}
else
(*e)->ReleaseLongArrayElements(e, io, pipes, JNI_ABORT);
return (jint)rv;
}
TCN_IMPLEMENT_CALL(jint, File, pipeTimeoutSet)(TCN_STDARGS, jlong pipe,
jlong timeout)
{
apr_file_t *f = J2P(pipe, apr_file_t *);
UNREFERENCED_STDARGS;
return (jint)apr_file_pipe_timeout_set(f, J2T(timeout));
}
TCN_IMPLEMENT_CALL(jlong, File, pipeTimeoutGet)(TCN_STDARGS, jlong pipe)
{
apr_file_t *f = J2P(pipe, apr_file_t *);
apr_interval_time_t timeout;
UNREFERENCED(o);
TCN_THROW_IF_ERR(apr_file_pipe_timeout_get(f, &timeout), timeout);
cleanup:
return (jlong)timeout;
}
TCN_IMPLEMENT_CALL(jlong, File, dup)(TCN_STDARGS, jlong newf, jlong file,
jlong pool)
{
apr_file_t *f = J2P(file, apr_file_t *);
apr_pool_t *p = J2P(pool, apr_pool_t *);
apr_file_t *d = J2P(newf, apr_file_t *);
UNREFERENCED(o);
TCN_THROW_IF_ERR(apr_file_dup(&d, f, p), d);
cleanup:
return P2J(d);
}
TCN_IMPLEMENT_CALL(jint, File, dup2)(TCN_STDARGS, jlong newf, jlong file,
jlong pool)
{
apr_file_t *f = J2P(file, apr_file_t *);
apr_pool_t *p = J2P(pool, apr_pool_t *);
apr_file_t *d = J2P(newf, apr_file_t *);
UNREFERENCED_STDARGS;
return (jint)apr_file_dup2(d, f, p);
}
/* 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.
* The ASF 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.
*/
/*
*
* @author Mladen Turk
* @version $Id: info.c 1442587 2013-02-05 13:49:48Z rjung $
*/
#include "tcn.h"
#include "apr_file_io.h"
#define DECLARE_FINFO_FIELD(name) static jfieldID _fid##name = NULL
#define FINFO_FIELD(name) _fid##name
#define GET_FINFO_I(N) \
_fid##N = (*e)->GetFieldID(e, finfo, #N, "I"); \
if (_fid##N == NULL) { \
(*e)->ExceptionClear(e); \
goto cleanup; \
} else (void)(0)
#define GET_FINFO_J(N) \
_fid##N = (*e)->GetFieldID(e, finfo, #N, "J"); \
if (_fid##N == NULL) { \
(*e)->ExceptionClear(e); \
goto cleanup; \
} else (void)(0)
#define GET_FINFO_S(N) \
_fid##N = (*e)->GetFieldID(e, finfo, #N, \
"Ljava/lang/String;"); \
if (_fid##N == NULL) { \
(*e)->ExceptionClear(e); \
goto cleanup; \
} else (void)(0)
#define SET_FINFO_I(N, V) \
(*e)->SetIntField(e, obj, _fid##N, (jint)(V))
#define SET_FINFO_J(N, V) \
(*e)->SetLongField(e, obj, _fid##N, (jlong)(V))
#define SET_FINFO_S(N, V) \
(*e)->SetObjectField(e, obj, _fid##N, \
(V) ? AJP_TO_JSTRING((V)) : NULL)
#define DECLARE_AINFO_FIELD(name) static jfieldID _aid##name = NULL
#define AINFO_FIELD(name) _aid##name
#define GET_AINFO_I(N) \
_aid##N = (*e)->GetFieldID(e, ainfo, #N, "I"); \
if (_aid##N == NULL) { \
(*e)->ExceptionClear(e); \
goto cleanup; \
} else (void)(0)
#define GET_AINFO_J(N) \
_aid##N = (*e)->GetFieldID(e, ainfo, #N, "J"); \
if (_aid##N == NULL) { \
(*e)->ExceptionClear(e); \
goto cleanup; \
} else (void)(0)
#define GET_AINFO_S(N) \
_aid##N = (*e)->GetFieldID(e, ainfo, #N, \
"Ljava/lang/String;"); \
if (_aid##N == NULL) { \
(*e)->ExceptionClear(e); \
goto cleanup; \
} else (void)(0)
#define SET_AINFO_I(N, V) \
(*e)->SetIntField(e, obj, _aid##N, (jint)(V))
#define SET_AINFO_J(N, V) \
(*e)->SetLongField(e, obj, _aid##N, (jlong)(V))
#define SET_AINFO_S(N, V) \
(*e)->SetObjectField(e, obj, _aid##N, \
(V) ? AJP_TO_JSTRING((V)) : NULL)
DECLARE_FINFO_FIELD(pool);
DECLARE_FINFO_FIELD(valid);
DECLARE_FINFO_FIELD(protection);
DECLARE_FINFO_FIELD(filetype);
DECLARE_FINFO_FIELD(user);
DECLARE_FINFO_FIELD(group);
DECLARE_FINFO_FIELD(inode);
DECLARE_FINFO_FIELD(device);
DECLARE_FINFO_FIELD(nlink);
DECLARE_FINFO_FIELD(size);
DECLARE_FINFO_FIELD(csize);
DECLARE_FINFO_FIELD(atime);
DECLARE_FINFO_FIELD(mtime);
DECLARE_FINFO_FIELD(ctime);
DECLARE_FINFO_FIELD(fname);
DECLARE_FINFO_FIELD(name);
DECLARE_FINFO_FIELD(filehand);
DECLARE_AINFO_FIELD(pool);
DECLARE_AINFO_FIELD(hostname);
DECLARE_AINFO_FIELD(servname);
DECLARE_AINFO_FIELD(port);
DECLARE_AINFO_FIELD(family);
DECLARE_AINFO_FIELD(next);
static int finfo_class_initialized = 0;
static int ainfo_class_initialized = 0;
static jmethodID finfo_class_init = NULL;
static jmethodID ainfo_class_init = NULL;
static jclass finfo_class = NULL;
static jclass ainfo_class = NULL;
apr_status_t tcn_load_finfo_class(JNIEnv *e, jclass finfo)
{
GET_FINFO_J(pool);
GET_FINFO_I(valid);
GET_FINFO_I(protection);
GET_FINFO_I(filetype);
GET_FINFO_I(user);
GET_FINFO_I(group);
GET_FINFO_I(inode);
GET_FINFO_I(device);
GET_FINFO_I(nlink);
GET_FINFO_J(size);
GET_FINFO_J(csize);
GET_FINFO_J(atime);
GET_FINFO_J(mtime);
GET_FINFO_J(ctime);
GET_FINFO_S(fname);
GET_FINFO_S(name);
GET_FINFO_J(filehand);
finfo_class_init = (*e)->GetMethodID(e, finfo,
"<init>", "()V");
if (finfo_class_init == NULL)
goto cleanup;
finfo_class_initialized = 1;
finfo_class = finfo;
cleanup:
return APR_SUCCESS;
}
apr_status_t tcn_load_ainfo_class(JNIEnv *e, jclass ainfo)
{
GET_AINFO_J(pool);
GET_AINFO_S(hostname);
GET_AINFO_S(servname);
GET_AINFO_I(port);
GET_AINFO_I(family);
GET_AINFO_J(next);
ainfo_class_init = (*e)->GetMethodID(e, ainfo,
"<init>", "()V");
if (ainfo_class_init == NULL)
goto cleanup;
ainfo_class_initialized = 1;
ainfo_class = ainfo;
cleanup:
return APR_SUCCESS;
}
static void fill_finfo(JNIEnv *e, jobject obj, apr_finfo_t *info)
{
SET_FINFO_J(pool, P2J(info->pool));
SET_FINFO_I(valid, info->valid);
SET_FINFO_I(protection, info->protection);
SET_FINFO_I(filetype, info->filetype);
SET_FINFO_I(user, ((jlong)info->user));
SET_FINFO_I(group, ((jlong)info->group));
SET_FINFO_I(inode, info->inode);
SET_FINFO_I(device, info->device);
SET_FINFO_I(nlink, info->nlink);
SET_FINFO_J(size, info->size);
SET_FINFO_J(csize, info->csize);
SET_FINFO_J(atime, info->atime);
SET_FINFO_J(mtime, info->mtime);
SET_FINFO_J(ctime, info->ctime);
SET_FINFO_S(fname, info->fname);
SET_FINFO_S(name, info->name);
SET_FINFO_J(filehand, P2J(info->filehand));
}
static void fill_ainfo(JNIEnv *e, jobject obj, apr_sockaddr_t *info)
{
apr_int32_t f;
if (info->family == APR_UNSPEC) f = 0;
else if (info->family == APR_INET) f = 1;
else if (info->family == APR_INET6) f = 2;
else f = info->family;
SET_AINFO_J(pool, P2J(info->pool));
SET_AINFO_S(hostname, info->hostname);
SET_AINFO_S(servname, info->servname);
SET_AINFO_I(port, info->port);
SET_AINFO_I(family, f);
SET_AINFO_J(next, P2J(info->next));
}
TCN_IMPLEMENT_CALL(jint, File, stat)(TCN_STDARGS, jobject finfo,
jstring fname, jint wanted,
jlong pool)
{
apr_pool_t *p = J2P(pool, apr_pool_t *);
TCN_ALLOC_CSTRING(fname);
apr_status_t rv;
apr_finfo_t info;
UNREFERENCED(o);
if ((rv = apr_stat(&info, J2S(fname), wanted, p)) == APR_SUCCESS) {
jobject io = (*e)->NewLocalRef(e, finfo);
fill_finfo(e, io, &info);
(*e)->DeleteLocalRef(e, io);
}
TCN_FREE_CSTRING(fname);
return (jint)rv;
}
TCN_IMPLEMENT_CALL(jobject, File, getStat)(TCN_STDARGS, jstring fname,
jint wanted, jlong pool)
{
apr_pool_t *p = J2P(pool, apr_pool_t *);
TCN_ALLOC_CSTRING(fname);
apr_status_t rv;
apr_finfo_t info;
jobject finfo = NULL;
UNREFERENCED(o);
if ((rv = apr_stat(&info, J2S(fname), wanted, p)) == APR_SUCCESS) {
finfo = (*e)->NewObject(e, finfo_class, finfo_class_init);
if (finfo == NULL)
goto cleanup;
fill_finfo(e, finfo, &info);
}
else
tcn_ThrowAPRException(e, rv);
cleanup:
TCN_FREE_CSTRING(fname);
return finfo;
}
TCN_IMPLEMENT_CALL(jint, File, infoGet)(TCN_STDARGS, jobject finfo,
jint wanted, jlong file)
{
apr_file_t *f = J2P(file, apr_file_t *);
apr_status_t rv;
apr_finfo_t info;
UNREFERENCED(o);
if ((rv = apr_file_info_get(&info, wanted, f)) == APR_SUCCESS) {
jobject io = (*e)->NewLocalRef(e, finfo);
fill_finfo(e, io, &info);
(*e)->DeleteLocalRef(e, io);
}
return (jint)rv;
}
TCN_IMPLEMENT_CALL(jobject, File, getInfo)(TCN_STDARGS, jint wanted, jlong file)
{
apr_file_t *f = J2P(file, apr_file_t *);
apr_status_t rv;
apr_finfo_t info;
UNREFERENCED(o);
if ((rv = apr_file_info_get(&info, wanted, f)) == APR_SUCCESS) {
jobject finfo;
finfo = (*e)->NewObject(e, finfo_class, finfo_class_init);
if (finfo == NULL)
return NULL;
fill_finfo(e, finfo, &info);
return finfo;
}
else
tcn_ThrowAPRException(e, rv);
return NULL;
}
TCN_IMPLEMENT_CALL(jint, Directory, read)(TCN_STDARGS, jobject finfo,
jint wanted, jlong dir)
{
apr_dir_t *d = J2P(dir, apr_dir_t *);
apr_status_t rv;
apr_finfo_t info;
UNREFERENCED(o);
if ((rv = apr_dir_read(&info, wanted, d)) == APR_SUCCESS) {
jobject io = (*e)->NewLocalRef(e, finfo);
fill_finfo(e, io, &info);
if ((*e)->ExceptionCheck(e)) {
(*e)->ExceptionClear(e);
}
else
rv = APR_EGENERAL;
(*e)->DeleteLocalRef(e, io);
}
return (jint)rv;
}
TCN_IMPLEMENT_CALL(jboolean, Address, fill)(TCN_STDARGS,
jobject addr, jlong info)
{
apr_sockaddr_t *i = J2P(info, apr_sockaddr_t *);
jobject ao;
jboolean rv = JNI_FALSE;
UNREFERENCED(o);
if (i) {
ao = (*e)->NewLocalRef(e, addr);
fill_ainfo(e, ao, i);
if ((*e)->ExceptionCheck(e)) {
(*e)->ExceptionClear(e);
}
else
rv = JNI_TRUE;
(*e)->DeleteLocalRef(e, ao);
}
return rv;
}
TCN_IMPLEMENT_CALL(jobject, Address, getInfo)(TCN_STDARGS, jlong info)
{
apr_sockaddr_t *i = J2P(info, apr_sockaddr_t *);
jobject sockaddrObj = NULL;
UNREFERENCED(o);
/* Create the APR Error object */
sockaddrObj = (*e)->NewObject(e, ainfo_class, ainfo_class_init);
if (sockaddrObj == NULL)
return NULL;
fill_ainfo(e, sockaddrObj, i);
return sockaddrObj;
}
This diff is collapsed.
/* 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.
* The ASF 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.
*/
/*
*
* @author Mladen Turk
* @version $Id: lock.c 1442587 2013-02-05 13:49:48Z rjung $
*/
#include "tcn.h"
#include "apr_proc_mutex.h"
#include "apr_global_mutex.h"
TCN_IMPLEMENT_CALL(jlong, Lock, create)(TCN_STDARGS,
jstring fname,
jint mech, jlong pool)
{
apr_pool_t *p = J2P(pool, apr_pool_t *);
apr_proc_mutex_t *mutex;
TCN_ALLOC_CSTRING(fname);
UNREFERENCED(o);
TCN_THROW_IF_ERR(apr_proc_mutex_create(&mutex, J2S(fname),
(apr_lockmech_e)mech, p), mutex);
cleanup:
TCN_FREE_CSTRING(fname);
return P2J(mutex);
}
TCN_IMPLEMENT_CALL(jlong, Lock, childInit)(TCN_STDARGS,
jstring fname,
jlong pool)
{
apr_pool_t *p = J2P(pool, apr_pool_t *);
apr_proc_mutex_t *mutex;
TCN_ALLOC_CSTRING(fname);
UNREFERENCED(o);
TCN_THROW_IF_ERR(apr_proc_mutex_child_init(&mutex,
J2S(fname), p), mutex);
cleanup:
TCN_FREE_CSTRING(fname);
return P2J(mutex);
}
TCN_IMPLEMENT_CALL(jint, Lock, lock)(TCN_STDARGS, jlong mutex)
{
apr_proc_mutex_t *m = J2P(mutex, apr_proc_mutex_t *);
UNREFERENCED_STDARGS;
return (jint)apr_proc_mutex_lock(m);
}
TCN_IMPLEMENT_CALL(jint, Lock, trylock)(TCN_STDARGS, jlong mutex)
{
apr_proc_mutex_t *m = J2P(mutex, apr_proc_mutex_t *);
UNREFERENCED_STDARGS;
return (jint)apr_proc_mutex_trylock(m);
}
TCN_IMPLEMENT_CALL(jint, Lock, unlock)(TCN_STDARGS, jlong mutex)
{
apr_proc_mutex_t *m = J2P(mutex, apr_proc_mutex_t *);
UNREFERENCED_STDARGS;
return (jint)apr_proc_mutex_unlock(m);
}
TCN_IMPLEMENT_CALL(jint, Lock, destroy)(TCN_STDARGS, jlong mutex)
{
apr_proc_mutex_t *m = J2P(mutex, apr_proc_mutex_t *);
UNREFERENCED_STDARGS;
return (jint)apr_proc_mutex_destroy(m);
}
#if 0
/* There is bug in APR implementing that function */
TCN_IMPLEMENT_CALL(jint, Lock, cleanup)(TCN_STDARGS, jlong mutex)
{
void *m = J2P(mutex, void *);
UNREFERENCED_STDARGS;
return (jint)apr_proc_mutex_cleanup(m);
}
#endif
TCN_IMPLEMENT_CALL(jstring, Lock, lockfile)(TCN_STDARGS, jlong mutex)
{
apr_proc_mutex_t *m = J2P(mutex, apr_proc_mutex_t *);
const char *s = apr_proc_mutex_lockfile(m);
UNREFERENCED_STDARGS;
if (s)
return AJP_TO_JSTRING(s);
else
return NULL;
}
TCN_IMPLEMENT_CALL(jstring, Lock, name)(TCN_STDARGS, jlong mutex)
{
apr_proc_mutex_t *m = J2P(mutex, apr_proc_mutex_t *);
UNREFERENCED(o);
return AJP_TO_JSTRING(apr_proc_mutex_name(m));
}
TCN_IMPLEMENT_CALL(jstring, Lock, defname)(TCN_STDARGS)
{
UNREFERENCED(o);
return AJP_TO_JSTRING(apr_proc_mutex_defname());
}
TCN_IMPLEMENT_CALL(jlong, Global, create)(TCN_STDARGS,
jstring fname,
jint mech, jlong pool)
{
apr_pool_t *p = J2P(pool, apr_pool_t *);
apr_global_mutex_t *mutex;
TCN_ALLOC_CSTRING(fname);
UNREFERENCED(o);
TCN_THROW_IF_ERR(apr_global_mutex_create(&mutex, J2S(fname),
(apr_lockmech_e)mech, p), mutex);
cleanup:
TCN_FREE_CSTRING(fname);
return P2J(mutex);
}
TCN_IMPLEMENT_CALL(jlong, Global, childInit)(TCN_STDARGS,
jstring fname,
jlong pool)
{
apr_pool_t *p = J2P(pool, apr_pool_t *);
apr_global_mutex_t *mutex;
TCN_ALLOC_CSTRING(fname);
UNREFERENCED(o);
TCN_THROW_IF_ERR(apr_global_mutex_child_init(&mutex,
J2S(fname), p), mutex);
cleanup:
TCN_FREE_CSTRING(fname);
return P2J(mutex);
}
TCN_IMPLEMENT_CALL(jint, Global, lock)(TCN_STDARGS, jlong mutex)
{
apr_global_mutex_t *m = J2P(mutex, apr_global_mutex_t *);
UNREFERENCED_STDARGS;
return (jint)apr_global_mutex_lock(m);
}
TCN_IMPLEMENT_CALL(jint, Global, trylock)(TCN_STDARGS, jlong mutex)
{
apr_global_mutex_t *m = J2P(mutex, apr_global_mutex_t *);
UNREFERENCED_STDARGS;
return (jint)apr_global_mutex_trylock(m);
}
TCN_IMPLEMENT_CALL(jint, Global, unlock)(TCN_STDARGS, jlong mutex)
{
apr_global_mutex_t *m = J2P(mutex, apr_global_mutex_t*);
UNREFERENCED_STDARGS;
return (jint)apr_global_mutex_unlock(m);
}
TCN_IMPLEMENT_CALL(jint, Global, destroy)(TCN_STDARGS, jlong mutex)
{
apr_global_mutex_t *m = J2P(mutex, apr_global_mutex_t *);
UNREFERENCED_STDARGS;
return (jint)apr_global_mutex_destroy(m);
}
/* 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.
* The ASF 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.
*/
/*
*
* @author Mladen Turk
* @version $Id: misc.c 1442587 2013-02-05 13:49:48Z rjung $
*/
#include "tcn.h"
#include "apr_time.h"
TCN_IMPLEMENT_CALL(void, Time, sleep)(TCN_STDARGS, jlong t)
{
UNREFERENCED_STDARGS;
apr_sleep((apr_interval_time_t)t);
}
TCN_IMPLEMENT_CALL(jint, OS, random)(TCN_STDARGS, jbyteArray buf,
jint len)
{
#if APR_HAS_RANDOM
apr_status_t rv;
jbyte *b = (*e)->GetPrimitiveArrayCritical(e, buf, NULL);
UNREFERENCED(o);
if ((rv = apr_generate_random_bytes((unsigned char *)b,
(apr_size_t)len)) == APR_SUCCESS)
(*e)->ReleasePrimitiveArrayCritical(e, buf, b, 0);
else
(*e)->ReleasePrimitiveArrayCritical(e, buf, b, JNI_ABORT);
if ((*e)->ExceptionCheck(e)) {
(*e)->ExceptionClear(e);
rv = APR_EGENERAL;
}
return (jint)rv;
#else
return APR_ENOTIMPL;
#endif
}
TCN_IMPLEMENT_CALL(jlong, Time, now)(TCN_STDARGS)
{
UNREFERENCED_STDARGS;
return (jlong)apr_time_now();
}
TCN_IMPLEMENT_CALL(jstring, Time, rfc822)(TCN_STDARGS, jlong t)
{
char ts[APR_RFC822_DATE_LEN];
UNREFERENCED(o);
if (apr_rfc822_date(ts, J2T(t)) == APR_SUCCESS)
return AJP_TO_JSTRING(ts);
else
return NULL;
}
TCN_IMPLEMENT_CALL(jstring, Time, ctime)(TCN_STDARGS, jlong t)
{
char ts[APR_CTIME_LEN];
UNREFERENCED(o);
if (apr_ctime(ts, J2T(t)) == APR_SUCCESS)
return AJP_TO_JSTRING(ts);
else
return NULL;
}
/* 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.
* The ASF 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.
*/
/*
*
* @author Mladen Turk
* @version $Id: mmap.c 1442587 2013-02-05 13:49:48Z rjung $
*/
#include "tcn.h"
#include "apr_mmap.h"
TCN_IMPLEMENT_CALL(jlong, Mmap, create)(TCN_STDARGS, jlong file,
jlong offset, jlong size,
jint flag, jlong pool)
{
#if APR_HAS_MMAP
apr_pool_t *p = J2P(pool, apr_pool_t *);
apr_file_t *f = J2P(file, apr_file_t *);
apr_mmap_t *m = NULL;
UNREFERENCED(o);
TCN_THROW_IF_ERR(apr_mmap_create(&m, f, (apr_off_t)offset,
(apr_size_t)size,
(apr_uint32_t)flag, p), m);
cleanup:
return P2J(m);
#else
UNREFERENCED(o);
tcn_ThrowAPRException(e, APR_ENOTIMPL);
return 0;
#endif
}
TCN_IMPLEMENT_CALL(jlong, Mmap, dup)(TCN_STDARGS, jlong mmap,
jlong pool)
{
#if APR_HAS_MMAP
apr_pool_t *p = J2P(pool, apr_pool_t *);
apr_mmap_t *m = J2P(mmap, apr_mmap_t *);
apr_mmap_t *newm = NULL;
UNREFERENCED(o);
TCN_THROW_IF_ERR(apr_mmap_dup(&newm, m, p), newm);
cleanup:
return P2J(newm);
#else
UNREFERENCED(o);
tcn_ThrowAPRException(e, APR_ENOTIMPL);
return 0;
#endif
}
TCN_IMPLEMENT_CALL(jint, Mmap, delete)(TCN_STDARGS, jlong mmap)
{
#if APR_HAS_MMAP
apr_mmap_t *m = J2P(mmap, apr_mmap_t *);
UNREFERENCED_STDARGS;
return apr_mmap_delete(m);
#else
UNREFERENCED_STDARGS;
UNREFERENCED(mmap);
return APR_ENOTIMPL;
#endif
}
TCN_IMPLEMENT_CALL(jlong, Mmap, offset)(TCN_STDARGS, jlong mmap,
jlong offset)
{
#if APR_HAS_MMAP
apr_mmap_t *m = J2P(mmap, apr_mmap_t *);
void *r;
UNREFERENCED(o);
TCN_THROW_IF_ERR(apr_mmap_offset(&r, m, (apr_off_t)offset), r);
cleanup:
return P2J(r);
#else
UNREFERENCED(o);
tcn_ThrowAPRException(e, APR_ENOTIMPL);
return 0;
#endif
}