[tomcat-native] 01/03: Imported Upstream version 1.1.30
Tony Mancill
tmancill at moszumanska.debian.org
Sat Jun 14 14:37:28 UTC 2014
This is an automated email from the git hooks/post-receive script.
tmancill pushed a commit to branch master
in repository tomcat-native.
commit 0d027eb582762b5d8bc812a6068fcef92eee1cc7
Author: tony mancill <tmancill at debian.org>
Date: Sat Jun 14 07:35:50 2014 -0700
Imported Upstream version 1.1.30
---
CHANGELOG.txt | 166 +
LICENSE | 201 +
NOTICE | 5 +
README.txt | 101 +
TODO.txt | 98 +
jni/build.properties.default | 53 +
jni/build.xml | 403 ++
jni/docs/images/add.gif | Bin 0 -> 1037 bytes
jni/docs/images/asf-feather.png | Bin 0 -> 40042 bytes
jni/docs/images/code.gif | Bin 0 -> 394 bytes
jni/docs/images/design.gif | Bin 0 -> 608 bytes
jni/docs/images/docs-stylesheet.css | 293 ++
jni/docs/images/docs.gif | Bin 0 -> 261 bytes
jni/docs/images/fix.gif | Bin 0 -> 345 bytes
jni/docs/images/printer.gif | Bin 0 -> 438 bytes
jni/docs/images/style.css | 23 +
jni/docs/images/tomcat.gif | Bin 0 -> 2066 bytes
jni/docs/images/tomcat.png | Bin 0 -> 8410 bytes
jni/docs/images/update.gif | Bin 0 -> 627 bytes
jni/docs/images/void.gif | Bin 0 -> 43 bytes
jni/docs/index.html | 188 +
jni/docs/miscellaneous/changelog.html | 287 ++
jni/docs/news/2008.html | 28 +
jni/docs/news/2009.html | 12 +
jni/docs/news/2010.html | 17 +
jni/docs/news/2011.html | 13 +
jni/docs/news/2012.html | 23 +
jni/docs/news/2013.html | 26 +
jni/docs/news/2014.html | 5 +
jni/examples/mkcerts | 216 +
jni/examples/org/apache/tomcat/jni/Echo.java | 340 ++
jni/examples/org/apache/tomcat/jni/Echo.properties | 17 +
.../org/apache/tomcat/jni/Local.properties | 23 +
.../org/apache/tomcat/jni/LocalServer.java | 184 +
jni/examples/org/apache/tomcat/jni/SSL.properties | 22 +
jni/examples/org/apache/tomcat/jni/SSLServer.java | 239 +
jni/java/org/apache/tomcat/Apr.java | 41 +
jni/java/org/apache/tomcat/apr.properties | 16 +
jni/java/org/apache/tomcat/jni/Address.java | 112 +
jni/java/org/apache/tomcat/jni/BIOCallback.java | 54 +
jni/java/org/apache/tomcat/jni/Buffer.java | 89 +
jni/java/org/apache/tomcat/jni/Directory.java | 95 +
jni/java/org/apache/tomcat/jni/Error.java | 96 +
jni/java/org/apache/tomcat/jni/File.java | 721 +++
jni/java/org/apache/tomcat/jni/FileInfo.java | 65 +
jni/java/org/apache/tomcat/jni/Global.java | 94 +
jni/java/org/apache/tomcat/jni/Library.java | 223 +
jni/java/org/apache/tomcat/jni/Local.java | 73 +
jni/java/org/apache/tomcat/jni/Lock.java | 121 +
jni/java/org/apache/tomcat/jni/Mmap.java | 71 +
jni/java/org/apache/tomcat/jni/Multicast.java | 76 +
jni/java/org/apache/tomcat/jni/OS.java | 128 +
.../org/apache/tomcat/jni/PasswordCallback.java | 32 +
jni/java/org/apache/tomcat/jni/Poll.java | 183 +
jni/java/org/apache/tomcat/jni/Pool.java | 162 +
jni/java/org/apache/tomcat/jni/PoolCallback.java | 31 +
jni/java/org/apache/tomcat/jni/Proc.java | 208 +
.../org/apache/tomcat/jni/ProcErrorCallback.java | 36 +
jni/java/org/apache/tomcat/jni/Procattr.java | 170 +
jni/java/org/apache/tomcat/jni/Registry.java | 233 +
jni/java/org/apache/tomcat/jni/SSL.java | 354 ++
jni/java/org/apache/tomcat/jni/SSLContext.java | 289 ++
jni/java/org/apache/tomcat/jni/SSLExt.java | 159 +
jni/java/org/apache/tomcat/jni/SSLSocket.java | 110 +
jni/java/org/apache/tomcat/jni/Shm.java | 122 +
jni/java/org/apache/tomcat/jni/Sockaddr.java | 40 +
jni/java/org/apache/tomcat/jni/Socket.java | 584 +++
jni/java/org/apache/tomcat/jni/Status.java | 263 ++
jni/java/org/apache/tomcat/jni/Stdlib.java | 88 +
jni/java/org/apache/tomcat/jni/Thread.java | 31 +
jni/java/org/apache/tomcat/jni/Time.java | 72 +
jni/java/org/apache/tomcat/jni/User.java | 125 +
.../org/apache/tomcat/jni/socket/AprSocket.java | 922 ++++
.../apache/tomcat/jni/socket/AprSocketContext.java | 1347 ++++++
.../org/apache/tomcat/jni/socket/HostInfo.java | 84 +
jni/java/overview.html | 30 +
jni/jnirelease.sh | 251 +
jni/native/BUILDING | 100 +
jni/native/Makefile.in | 82 +
jni/native/NMAKEmakefile | 152 +
jni/native/NMAKEmakefile.inc | 347 ++
jni/native/build-outputs.mk | 62 +
jni/native/build.conf | 36 +
jni/native/build/apr_common.m4 | 985 ++++
jni/native/build/buildcheck.sh | 82 +
jni/native/build/config.guess | 1420 ++++++
jni/native/build/config.sub | 1793 +++++++
jni/native/build/find_apr.m4 | 202 +
jni/native/build/get-version.sh | 53 +
jni/native/build/install.sh | 112 +
jni/native/build/lineends.pl | 165 +
jni/native/build/mkdir.sh | 52 +
jni/native/build/rpm/tcnative.spec.in | 97 +
jni/native/build/tcnative.m4 | 413 ++
jni/native/buildconf | 96 +
jni/native/config.layout | 265 ++
jni/native/configure | 4944 ++++++++++++++++++++
jni/native/configure.in | 277 ++
jni/native/include/ssl_private.h | 321 ++
jni/native/include/tcn.h | 317 ++
jni/native/include/tcn_api.h | 65 +
jni/native/include/tcn_version.h | 100 +
jni/native/libtcnative.dsp | 231 +
jni/native/libtcnative.dsw | 71 +
jni/native/os/netware/system.c | 45 +
jni/native/os/unix/system.c | 446 ++
jni/native/os/unix/uxpipe.c | 355 ++
jni/native/os/win32/apache.ico | Bin 0 -> 1078 bytes
jni/native/os/win32/libtcnative.rc | 71 +
jni/native/os/win32/logmessages.bin | Bin 0 -> 224 bytes
jni/native/os/win32/logmessages.mc | 41 +
jni/native/os/win32/ntpipe.c | 506 ++
jni/native/os/win32/registry.c | 792 ++++
jni/native/os/win32/system.c | 468 ++
jni/native/src/address.c | 146 +
jni/native/src/bb.c | 135 +
jni/native/src/dir.c | 105 +
jni/native/src/error.c | 248 +
jni/native/src/file.c | 601 +++
jni/native/src/info.c | 357 ++
jni/native/src/jnilib.c | 484 ++
jni/native/src/lock.c | 202 +
jni/native/src/misc.c | 81 +
jni/native/src/mmap.c | 102 +
jni/native/src/multicast.c | 75 +
jni/native/src/network.c | 1446 ++++++
jni/native/src/os.c | 40 +
jni/native/src/poll.c | 481 ++
jni/native/src/pool.c | 250 +
jni/native/src/proc.c | 453 ++
jni/native/src/shm.c | 127 +
jni/native/src/ssl.c | 1222 +++++
jni/native/src/sslcontext.c | 812 ++++
jni/native/src/sslinfo.c | 589 +++
jni/native/src/sslnetwork.c | 733 +++
jni/native/src/sslutils.c | 1244 +++++
jni/native/src/stdlib.c | 120 +
jni/native/src/thread.c | 29 +
jni/native/src/user.c | 163 +
jni/native/srclib/BUILDING | 42 +
jni/native/srclib/VERSIONS | 4 +
jni/native/srclib/apr/NMAKEmakefile | 234 +
jni/native/srclib/apr/apr-enable-ipv6.patch | 20 +
jni/native/srclib/openssl/openssl-msvcrt.patch | 28 +
jni/native/tcnative.dsp | 231 +
jni/native/tcnative.pc.in | 30 +
jni/native/tcnative.spec | 97 +
jni/test/org/apache/tomcat/jni/FileTestSuite.java | 43 +
.../apache/tomcat/jni/SocketServerTestBind.java | 132 +
.../apache/tomcat/jni/SocketServerTestSuite.java | 206 +
jni/xdocs/build.xml | 137 +
jni/xdocs/images/add.gif | Bin 0 -> 1037 bytes
jni/xdocs/images/asf-feather.png | Bin 0 -> 40042 bytes
jni/xdocs/images/code.gif | Bin 0 -> 394 bytes
jni/xdocs/images/design.gif | Bin 0 -> 608 bytes
jni/xdocs/images/docs-stylesheet.css | 293 ++
jni/xdocs/images/docs.gif | Bin 0 -> 261 bytes
jni/xdocs/images/fix.gif | Bin 0 -> 345 bytes
jni/xdocs/images/printer.gif | Bin 0 -> 438 bytes
jni/xdocs/images/style.css | 23 +
jni/xdocs/images/tomcat.gif | Bin 0 -> 2066 bytes
jni/xdocs/images/tomcat.png | Bin 0 -> 8410 bytes
jni/xdocs/images/update.gif | Bin 0 -> 627 bytes
jni/xdocs/images/void.gif | Bin 0 -> 43 bytes
jni/xdocs/index.xml | 231 +
jni/xdocs/miscellaneous/changelog.xml | 339 ++
jni/xdocs/miscellaneous/project.xml | 47 +
jni/xdocs/news/2008.xml | 58 +
jni/xdocs/news/2009.xml | 42 +
jni/xdocs/news/2010.xml | 47 +
jni/xdocs/news/2011.xml | 43 +
jni/xdocs/news/2012.xml | 53 +
jni/xdocs/news/2013.xml | 56 +
jni/xdocs/news/2014.xml | 35 +
jni/xdocs/news/project.xml | 47 +
jni/xdocs/project.xml | 47 +
jni/xdocs/style.xsl | 361 ++
177 files changed, 39719 insertions(+)
diff --git a/CHANGELOG.txt b/CHANGELOG.txt
new file mode 100644
index 0000000..04189f0
--- /dev/null
+++ b/CHANGELOG.txt
@@ -0,0 +1,166 @@
+ This is the Changelog for Tomcat Native. This changelog does not contain
+ all updates and fixes to the Tomcat Native (yet). It should contain fixes
+ made only after December 19th 2007, when the new documentation project for
+ Tomcat Native was started.
+
+ Changes between 1.1.29 and 1.1.30
+
+ * Fix: 56363: Use OpenSSL 1.0.1g with Windows binaries. (mturk)
+ * Fix: 55915: Apply Mike Noordermeer's patch for ECDHE support. (mturk)
+ * Fix: 55663: Minor correction to the wording of the NOTICE file to
+ align it with the requirements for NOTICE files. (kkolinko)
+ * Fix: 56027: Partial fix includes new fipsModeGet function to get the
+ current state of OpenSSL FIPS mode.
+
+ Changes between 1.1.28 and 1.1.29
+
+ * Fix: Change return code when removing a socket from a poller, that was
+ actually not in the poller from APR_SUCCESS to APR_NOTFOUND. (rjung)
+
+ Changes between 1.1.27 and 1.1.28
+
+ * Update: Java classes in package org.apache.tomcat.jni are now taken
+ from Tomcat trunk using svn:externals. (rjung)
+ * Update: Minimum supported APR version is now again 1.2.1. Version
+ 1.3.0 of APR improves performance. (rjung)
+ * Fix: 29422: Fixed double-free in ssl_ocsp_request. Patch provided by
+ Aristotelis. (schultz)
+ * Fix: 51655: Added a decent description of what tcnative actually is.
+ (schultz)
+ * Fix: 51813: Add NULL-checking for s->net to avoid SIGSEGV in
+ situations where it appears a socket has been recycled. (schultz)
+
+ Changes between 1.1.26 and 1.1.27
+
+ * Fix: 54513: Fix regression in pollset return value. (mturk)
+ * Fix: Switch CPU information on Solaris from milliseconds to
+ microseconds. Make consistent with OS.java and Linux impl. (rjung)
+
+ Changes between 1.1.25 and 1.1.26 (not released)
+
+ * Fix: 54468: Fix FIPS mode for listeners when using OpenSSL 1.0.1c and
+ later; resolves 'Low level API call to digest MD5 forbidden in FIPS
+ mode!' errors. (wrowe)
+ * Update: Add clearOptions function to allow access to OpenSSL's
+ SSL_CTX_clear_options function. (schultz)
+
+ Changes between 1.1.24 and 1.1.25 (not released)
+
+ * Update: Minimum supported APR version is now 1.3.0. (mturk)
+ * Fix: 52856: Fix high CPU usage when client changes IP address or has
+ high latency. (mturk)
+ * Update: Add CPU information to OS info for Linux. This was already
+ available under Windows and Solaris. (rjung)
+ * Fix: 53969: ssl.c::hasOp could only check for
+ SSL_OP_ALLOW_UNSAFE_LEGACY_RENEGOTIATION. Now it can check for any
+ SSL_OP_* available at compile-time. (schultz)
+
+ Changes between 1.1.23 and 1.1.24
+
+ * Update: Add support for per-socket timeouts inside poller. (markt,
+ mturk)
+
+ Changes between 1.1.22 and 1.1.23
+
+ * Update: 45392: Add support for OCSP verification. Based upon a patch
+ from Aristotelis. (mturk)
+ * Fix: 52119: Autodetect Diablo JDK on FreeBSD and Java7+. Based upon a
+ patch from Michael Osipov. (mturk)
+ * Fix: 52717: Set scope_id for IPv6 addresses if provided. (mturk)
+ * Update: 50570: Allow explicit use of FIPS mode in APR lifecycle
+ listener (native support only in this update; Java support to follow).
+ Based upon a patch from Chris Beckey. (schultz)
+
+ Changes between 1.1.21 and 1.1.22
+
+ * Fix: Arrange release packaging script. (jfclere).
+ * Fix: Fix typos in the changelog. (markt).
+
+ Changes between 1.1.20 and 1.1.21 (not released)
+
+ * Fix: 50394: InternalAprInputBuffer.fill() doesn't deal correctly with
+ EOF. (jfclere)
+ * Fix: Support arbitrary protocol combinations of SSLv2, SSLv3 and
+ TLSv1. (rjung)
+ * Fix: 51437: Try loading certificate in DER format if PEM was invalid.
+ (mturk)
+ * Fix: 49557: index error in the loop to get the env info in the
+ proc.create function. (kkolinko, jfclere)
+ * Fix: 49851: JNI Registry.deleteKey and Registry.deleteValue corrupt
+ Windows registry. (jfclere)
+ * Fix: 48253: adding dynamic locking callbacks for openssl engines.
+ (jfclere)
+ * Update: Make the non blocking write really no blocking. (jfclere)
+ * Update: Add support for unsafe legacy renegotiation. (mturk)
+
+ Changes between 1.1.19 and 1.1.20
+
+ * Fix: 48584: Prevent crashing JVM on shutdown. (mturk)
+
+ Changes between 1.1.18 and 1.1.19
+
+ * Fix: Update windows resource files to correct version. (mturk)
+ * Fix: 48129: Fix build with OpenSSL 1.0.0-beta3. Patch provided by
+ Tomas Mraz. (mturk, rjung)
+ * Update: Add detection of the Mac OS X JVM. (rjung)
+
+ Changes between 1.1.17 and 1.1.18
+
+ * Fix: Fix CVE-2009-3555 SSL-Man-In-The-Middle attack. (mturk)
+
+ Changes between 1.1.16 and 1.1.17
+
+ * Update: Arrange build after svn reorganisation (rjung)
+ * Fix: 47852: Fix some Javadoc errors. Patch provided by Sebb. (rjung)
+ * Fix: 46950: Fix SSL renegotiation in combination with client
+ certificates. The complete solution also needs a fix in Tomcat's Java
+ code. (markt)
+ * Fix: Align method names and signatures of native C code and java code.
+ (markt, rjung)
+ * Fix: 42728: Remove memory leak. (markt)
+ * Fix: 46457: Fix use of multicast. (markt)
+ * Fix: Fix API name for recvfrom (mturk)
+ * Fix: Allow building against APR 1.3 (mturk)
+ * Fix: Improve fix for 43327 with better handling for IPv6 addresses
+ (markt)
+
+ Changes between 1.1.15 and 1.1.16
+
+ * Fix: Fix API name for recvfrom (mturk)
+ * Fix: Allow building against APR 1.3 (mturk)
+ * Fix: Improve fix for 43327 with better handling for IPv6 addresses
+ (markt)
+
+ Changes between 1.1.14 and 1.1.15
+
+ * Fix: 43327: Socket bind fail because mixing IPv4/IPv6 (markt, jfclere)
+ * Fix: 44864: Use additional check for SSL verify like with mod_ssl for
+ SSLVerifyClient=optionalNoCA. (mturk)
+
+ Changes between 1.1.13 and 1.1.14
+
+ * Fix: 45071: Reset ttl when Poll.pool remove is false. Additional patch
+ was provided by Alex Barclay. (mturk)
+ * Fix: Fix optGet that was always throwing exceptions. (jfclere)
+ * Fix: Fix optSet don't throw exception as JAVA prototype doesn't.
+ (jfclere)
+
+ Changes between 1.1.12 and 1.1.13
+
+ * Fix: IFS problem in native/build/tcnative.m4 (rjung)
+ * Fix: Wrong gcc link flag in native/build/tcnative.m4 (rjung)
+
+ Changes between 1.1.11 and 1.1.12
+
+ * Update: Add support of J9VM based JVM. (jfclere)
+ * Update: Arrange licence in source files. (markt)
+ * Update: Add two new 'immediate' methods for sending the data. It is
+ the responsibility of the Java callee to deal with the returned values
+ and retry if the error was non-fatal. (mturk)
+ * Fix: Arrange the check of openssl version. It was failing on Linux.
+ (jfclere)
+ * Fix: Prevent returning APR_SUCCESS when there is something wrong in
+ ssl layer. (jfclere)
+ * Fix: 44087: Fix it. (jfclere)
+
+ Copyright � 2008-2014, The Apache Software Foundation
diff --git a/LICENSE b/LICENSE
new file mode 100644
index 0000000..261eeb9
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,201 @@
+ 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.
diff --git a/NOTICE b/NOTICE
new file mode 100644
index 0000000..c2c34d0
--- /dev/null
+++ b/NOTICE
@@ -0,0 +1,5 @@
+Apache Tomcat Native Library
+Copyright 2002-2014 The Apache Software Foundation
+
+This product includes software developed at
+The Apache Software Foundation (http://www.apache.org/).
diff --git a/README.txt b/README.txt
new file mode 100644
index 0000000..cea204a
--- /dev/null
+++ b/README.txt
@@ -0,0 +1,101 @@
+
+ Apache Tomcat Native Library
+
+
+What is it?
+-----------
+
+The Apache Tomcat Native Library provides portable API for features
+not found in contemporary JDK's. It uses Apache Portable Runtime as
+operating system abstraction layer and OpenSSL for SSL networking and
+allows optimal performance in production environments.
+
+
+Licensing
+---------
+
+Please see the file called LICENSE.
+
+The Latest Version
+------------------
+
+Details of the latest version can be found on the Apache Tomcat
+project page under http://tomcat.apache.org/.
+
+Documentation
+-------------
+
+The documentation available as of the date of this release is
+included in HTML format in the jni/docs directory.
+The most up-to-date documentation can be found at
+http://tomcat.apache.org/native-doc/
+
+Documentation about the Tomcat APR connector which is based
+on this library can be found at
+http://tomcat.apache.org/tomcat-7.0-doc/apr.html.
+
+
+Building
+--------
+
+To build the Java API. Note that Java 1.7 is required to build the Java API.
+> ant
+
+To build the native part see jni/native/BUILDING (or native/BUILDING if you have a working copy of svn).
+
+
+Running the tests
+-----------------
+
+First run "ant download" to retrieve junit. It will be placed
+in the directory given by "base.path". The path can be changed
+by adjusting "base.path" in the file build.properties.default
+or overwrite it in a new file build.properties.
+
+Now run "ant test".
+
+
+Running the examples
+--------------------
+
+Before running the examples you may have to set LD_LIBRARY_PATH, something like
+LD_LIBRARY_PATH=/opt/SMAWoIS/openssl/lib; export LD_LIBRARY_PATH
+
+1) echo example:
+ - Choose some free port in
+ dist/classes/examples/org/apache/tomcat/jni/Echo.properties
+ - run: ant run-echo
+
+2) ssl server example:
+ - Change parameters in dist/classes/examples/org/apache/tomcat/jni/SSL.properties
+ according to your needs. The certificate and key should be in
+ dist/classes/examples.
+ - run: ant run-ssl-server
+
+
+Cryptographic Software Notice
+-----------------------------
+
+This distribution may include software that has been designed for use
+with cryptographic software. The country in which you currently reside
+may have restrictions on the import, possession, use, and/or re-export
+to another country, of encryption software. BEFORE using any encryption
+software, please check your country's laws, regulations and policies
+concerning the import, possession, or use, and re-export of encryption
+software, to see if this is permitted. See <http://www.wassenaar.org/>
+for more information.
+
+The U.S. Government Department of Commerce, Bureau of Industry and
+Security (BIS), has classified this software as Export Commodity
+Control Number (ECCN) 5D002.C.1, which includes information security
+software using or performing cryptographic functions with asymmetric
+algorithms. The form and manner of this Apache Software Foundation
+distribution makes it eligible for export under the License Exception
+ENC Technology Software Unrestricted (TSU) exception (see the BIS
+Export Administration Regulations, Section 740.13) for both object
+code and source code.
+
+Apache Tomcat Native uses cryptographic software for configuring and
+listening to connections over SSL encrypted network sockets by
+performing calls to a general-purpose encryption library, such as
+OpenSSL or the operating system's platform-specific SSL facilities.
diff --git a/TODO.txt b/TODO.txt
new file mode 100644
index 0000000..401545d
--- /dev/null
+++ b/TODO.txt
@@ -0,0 +1,98 @@
+================================================================================
+ 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.
+================================================================================
+
+
+ Apache Tomcat Native Library
+
+ TODO
+
+
+SSL Renegotiation
+-----------------
+
+It is unclear to me, what the current state is. It looks like we support
+the unsafe legacy reneg whenever the OpenSSL used during build time
+supports it. There is no configuration option to switch it off during
+runtime. Right?
+
+Is it correct, that client initiated reneg is not supported and thus the
+known attacks will not work even with old OpenSSL?
+
+Should we add a remark about this topic to the docs?
+
+
+Java Tests and Examples
+-----------------------
+
+- "ant run-echo": what is the expected behaviour of this example.
+ I couldn't get it to do something understandable.
+ Document the example in the README.txt.
+
+- "ant run-ssl-server": Could't we include a test certificate in the
+ distribution?
+
+- "ant run-ssl-server": What should the test produce, if run successfully?
+ Document the example in the README.txt.
+
+- "ant run-local-server": Creates a unix socket "\\.\PIPE\test" in the
+ examples directory, then waits. How is the test expected to work?
+ And the file name doesn't seem to be appropriate for Unix.
+ Document the example in the README.txt.
+
+
+Java Classes Source Distribution
+--------------------------------
+
+Check on how to handle the test and examples classes.
+I think they have no other home.
+
+Furthermore some of the Java files do not exist inside TC:
+- Apr.java, apr.properties, jni/Buffer.java and jni/Thread.java
+I don't know their purpose and whether we can delete them.
+
+
+Releasing
+---------
+
+- Document how to release.
+
+- Add info about updating config.guess and config.sub from
+
+http://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=config.guess;hb=HEAD
+http://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=config.sub;hb=HEAD
+
+- ZIP download seems to have group write permissions set
+ (at least after I extract it on Solaris).
+ It's a bit strange that permissions differ between the
+ tar and zip archives.
+
+- OCSP enabled Windows binary
+ - Document build
+ - Use consistent naming
+ (1.1.22 used ...win32-ocsp..., 1.1.24 used ...ocsp-win32...)
+
+
+Trunk
+-----
+
+Trunk isn't really maintained. A lot of merges
+need to be done. AFAIK the trunk native classes
+contain some additions, so we can't simply remove trunk.
+
+Change release layout when releasing trunk: don't insert
+the additional "jni" directory, instead keep layout in sync
+between svn and source distribution.
diff --git a/jni/build.properties.default b/jni/build.properties.default
new file mode 100644
index 0000000..412d688
--- /dev/null
+++ b/jni/build.properties.default
@@ -0,0 +1,53 @@
+#
+# 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.
+#
+
+# ----- Version Control Flags -----
+version.major=1
+version.minor=1
+version.build=30
+version.patch=0
+#version.suffix=-dev
+version.suffix=
+
+# ----- Default Base Path for Dependent Packages -----
+# Please note this path must be absolute, not relative,
+# as it is referenced with different working directory
+# contexts by the various build scripts.
+base.path=/usr/share/java
+#base.path=C:/path/to/the/repository
+#base.path=/usr/local
+
+compile.source=1.7
+compile.target=1.7
+compile.debug=off
+compile.deprecation=on
+compile.optimize=on
+
+base-tomcat.loc=http://archive.apache.org/dist/tomcat
+base-sf.loc=http://downloads.sourceforge.net
+
+# ----- JUnit Unit Test Suite, version 3.8 or later -----
+# The JUnit version we will use
+junit.version=3.8.2
+# The directory containing your binary distribution of JUnit
+# It will be automatically downloaded if it doesn't exist
+junit.home=${base.path}/junit${junit.version}
+#junit.home = /usr/local/java/junit3.8.1
+# The pathname of the "junit.jar" JAR file
+junit.jar=${junit.home}/junit.jar
+# The URL used to download JUnit if needed
+junit.loc=${base-sf.loc}/junit/junit${junit.version}.zip
diff --git a/jni/build.xml b/jni/build.xml
new file mode 100644
index 0000000..1c2abc6
--- /dev/null
+++ b/jni/build.xml
@@ -0,0 +1,403 @@
+<?xml version="1.0"?>
+<!--
+ 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.
+-->
+<!-- Build file for Tomcat Native -->
+<project name="Tomcat Native" default="compile" basedir=".">
+ <!-- Give user a chance to override without editing this file
+ (and without typing -D each time it compiles it
+ -->
+ <property file="${user.home}/.ant.properties" />
+ <property file="${user.home}/build.properties" />
+ <property file=".ant.properties" />
+ <property file="build.properties" />
+ <property file="build.properties.default"/>
+
+ <!-- Initialization properties -->
+ <property name="project" value="tomcat-native" />
+ <property name="name" value="Tomcat Native" />
+ <property name="title" value="Tomcat Native Library"/>
+ <property name="year" value="2014" />
+ <property name="version.major" value="1" />
+ <property name="version.minor" value="1" />
+ <property name="version.build" value="30" />
+ <property name="version.patch" value="0" />
+ <property name="version.suffix" value="" />
+
+ <property name="junit.home" value="/usr/local/junit3.8"/>
+ <property name="junit.jar" value="${junit.home}/junit.jar"/>
+ <property name="test.runner" value="junit.textui.TestRunner"/>
+
+ <property name="version" value="${version.major}.${version.minor}.${version.build}${version.suffix}" />
+ <property name="version.number" value="${version.major}.${version.minor}.${version.build}.${version.patch}" />
+ <property name="version.major.minor" value="${version.major}.${version.minor}" />
+
+ <property name="final.name" value="${project}-${version}" />
+
+ <property name="build.dir" value="./dist"/>
+ <property name="build.src" value="${build.dir}/src"/>
+ <property name="build.dest" value="${build.dir}/classes"/>
+ <property name="src.dir" value="."/>
+ <property name="dist.root" value="./dist"/>
+ <property name="ant.home" value="."/>
+
+ <property name="compile.source" value="1.7"/>
+ <property name="compile.target" value="1.7"/>
+ <property name="compile.debug" value="off"/>
+ <property name="compile.optimize" value="on"/>
+ <property name="compile.deprecation" value="on"/>
+
+ <property name="docs.src" value="./xdocs"/>
+ <property name="docs.dest" value="${dist.root}/doc"/>
+ <property name="docs.dest.print" value="${dist.root}/doc/printable"/>
+ <property name="test.dir" value="${build.dest}/test"/>
+ <property name="examples.dir" value="${build.dest}/examples"/>
+
+ <property name="tc.library.path" value="${basedir}/native/.libs"/>
+
+ <!-- The base directory for component sources -->
+ <property name="source.home" value="java"/>
+
+ <!-- Build classpath -->
+ <path id="classpath">
+ <pathelement location="${build.dest}/java"/>
+ </path>
+
+ <!-- Test classpath -->
+ <path id="test.classpath">
+ <pathelement location="${build.dest}/java"/>
+ <pathelement location="${build.dest}/test"/>
+ <pathelement location="${junit.jar}"/>
+ </path>
+
+ <!-- Examples classpath -->
+ <path id="examples.classpath">
+ <pathelement location="${build.dest}/java"/>
+ <pathelement location="${build.dest}/examples"/>
+ </path>
+
+ <!-- =================================================================== -->
+ <!-- prints the environment -->
+ <!-- =================================================================== -->
+ <target name="env">
+ <echo message="java.home = ${java.home}"/>
+ <echo message="user.home = ${user.home}"/>
+ <!--
+ <echo message="java.class.path = ${java.class.path}"/>
+ -->
+ <echo message="tc.library.path = ${tc.library.path}"/>
+ <echo message=""/>
+ </target>
+
+ <target name="prepare" depends="env">
+ <mkdir dir="${build.dir}"/>
+ </target>
+
+ <!-- Download and dependency building -->
+ <target name="proxyflags">
+ <!-- check proxy parameters. -->
+ <condition property="useproxy">
+ <equals arg1="${proxy.use}" arg2="on" />
+ </condition>
+ </target>
+
+ <target name="setproxy" depends="proxyflags" if="useproxy">
+ <taskdef name="setproxy"
+ classname="org.apache.tools.ant.taskdefs.optional.net.SetProxy" />
+ <setproxy proxyhost="${proxy.host}" proxyport="${proxy.port}"
+ proxyuser="${proxy.user}" proxypassword="${proxy.password}" />
+ <echo message="Using ${proxy.host}:${proxy.port} to download ${sourcefile}"/>
+ </target>
+
+ <target name="testexist">
+ <echo message="Testing for ${destfile}"/>
+ <available file="${destfile}" property="exist"/>
+ </target>
+
+ <target name="downloadgz" unless="exist" depends="setproxy,testexist">
+ <!-- Download and extract the package -->
+ <get src="${sourcefile}" dest="${base.path}/file.tar.gz" />
+ <gunzip src="${base.path}/file.tar.gz" dest="${base.path}/file.tar"/>
+ <untar src="${base.path}/file.tar" dest="${base.path}"/>
+ <delete file="${base.path}/file.tar"/>
+ <delete file="${base.path}/file.tar.gz"/>
+ </target>
+
+ <target name="downloadzip" unless="exist" depends="setproxy,testexist">
+ <!-- Download and extract the package -->
+ <get src="${sourcefile}" dest="${base.path}/file.zip" />
+ <mkdir dir="${destdir}" />
+ <unzip src="${base.path}/file.zip" dest="${destdir}"/>
+ <delete file="${base.path}/file.zip"/>
+ </target>
+
+ <target name="downloadfile" unless="exist" depends="setproxy,testexist">
+ <!-- Download extract the file -->
+ <mkdir dir="${destdir}" />
+ <get src="${sourcefile}" dest="${destfile}" />
+ </target>
+
+ <target name="download" description="Download needed dependencies">
+
+ <mkdir dir="${base.path}"/>
+
+ <antcall target="downloadzip">
+ <param name="sourcefile" value="${junit.loc}"/>
+ <param name="destfile" value="${junit.jar}"/>
+ <param name="destdir" value="${base.path}"/>
+ </antcall>
+ </target>
+
+ <!-- =================================================================== -->
+ <!-- Creates the API documentation -->
+ <!-- =================================================================== -->
+ <target name="javadocs" description="Java documentation">
+ <mkdir dir="${docs.dest}"/>
+ <mkdir dir="${docs.dest}/api"/>
+ <javadoc sourcepath="${build.src}/java"
+ destdir="${docs.dest}/api"
+ author="true"
+ version="true"
+ overview="${src.dir}/java/overview.html"
+ packagenames="org.apache.tomcat.*"
+ windowtitle="${title} (Version ${version})"
+ doctitle="<h1>${title} (Version ${version})</h1>"
+ bottom="Copyright 2002-2014 The Apache Software Foundation.<!--
+
+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.-->">
+ <classpath refid="classpath"/>
+ </javadoc>
+ </target>
+
+ <!-- =================================================================== -->
+ <!-- Cleans up the build directory -->
+ <!-- =================================================================== -->
+ <target name="clean" description="Clean build directory">
+ <delete dir="${build.dir}"/>
+ </target>
+
+ <!-- =================================================================== -->
+ <!-- Compiles the source directory -->
+ <!-- =================================================================== -->
+ <target name="compile" depends="prepare" description="Compile Java sources">
+ <mkdir dir="${build.dest}"/>
+ <mkdir dir="${build.dest}/java"/>
+ <mkdir dir="${build.src}"/>
+ <mkdir dir="${build.src}/java"/>
+ <tstamp>
+ <format property="TODAY" pattern="MMM d yyyy" locale="en"/>
+ <format property="TSTAMP" pattern="hh:mm:ss"/>
+ </tstamp>
+ <!-- Copy static resource files -->
+ <filter token="VERSION" value="${version}"/>
+ <filter token="VERSION_NUMBER" value="${version.number}"/>
+ <filter token="VERSION_BUILT" value="${TODAY} ${TSTAMP}"/>
+ <copy todir="${build.src}/java" filtering="yes" encoding="ISO-8859-1">
+ <fileset dir="${src.dir}/java">
+ <include name="**/*.java"/>
+ <include name="**/*.xml"/>
+ <include name="**/*.properties"/>
+ </fileset>
+ </copy>
+
+ <javac srcdir="${build.src}/java"
+ destdir="${build.dest}/java"
+ source="${compile.source}"
+ target="${compile.target}"
+ debug="${compile.debug}"
+ deprecation="${compile.deprecation}"
+ optimize="${compile.optimize}"
+ encoding="ISO-8859-1">
+ <classpath refid="classpath"/>
+ </javac>
+
+ <copy todir="${build.dest}/java" filtering="yes" encoding="ISO-8859-1">
+ <fileset dir="${build.src}/java">
+ <include name="**/*.xml"/>
+ <include name="**/*.properties"/>
+ </fileset>
+ </copy>
+ </target>
+
+ <!-- ================================================================== -->
+ <!-- Make Tomcat Native jar -->
+ <!-- ================================================================== -->
+ <target name="jar" depends="compile" description="Generates the Jar file">
+ <jar
+ destfile="${build.dir}/${final.name}.jar"
+ basedir="${build.dir}/classes/java"
+ excludes="**/*.java">
+ <manifest>
+ <section name="org/apache/tomcat/jni">
+ <attribute name="Specification-Title" value="Tomcat Native"/>
+ <attribute name="Specification-Version" value="${version}"/>
+ <attribute name="Specification-Vendor" value="Apache Software Foundation"/>
+ <attribute name="Implementation-Title" value="org.apache.tomcat.jni"/>
+ <attribute name="Implementation-Vendor" value="Apache Software Foundation"/>
+ <attribute name="Implementation-Vendor-Id" value="org.apache"/>
+ <attribute name="Implementation-Version" value="${version} (build ${DSTAMP} ${TSTAMP})"/>
+ </section>
+ </manifest>
+ </jar>
+ </target>
+
+ <!-- =================================================================== -->
+ <!-- Compiles the test directory -->
+ <!-- =================================================================== -->
+ <target name="compile-tests" depends="compile" description="Compile Java test classes">
+ <mkdir dir="${build.dest}"/>
+ <mkdir dir="${build.dest}/test"/>
+ <mkdir dir="${build.src}"/>
+ <mkdir dir="${build.src}/test"/>
+ <tstamp>
+ <format property="TODAY" pattern="MMM d yyyy" locale="en"/>
+ <format property="TSTAMP" pattern="hh:mm:ss"/>
+ </tstamp>
+ <!-- Copy static resource files -->
+ <filter token="VERSION" value="${version}"/>
+ <filter token="VERSION_NUMBER" value="${version.number}"/>
+ <filter token="VERSION_BUILT" value="${TODAY} ${TSTAMP}"/>
+ <copy todir="${build.src}/test" filtering="yes" encoding="ISO-8859-1">
+ <fileset dir="${src.dir}/test">
+ <include name="**/*.java"/>
+ <include name="**/*.xml"/>
+ <include name="**/*.properties"/>
+ </fileset>
+ </copy>
+ <javac srcdir="${build.src}/test"
+ destdir="${build.dest}/test"
+ source="${compile.source}"
+ target="${compile.target}"
+ debug="on"
+ deprecation="${compile.deprecation}"
+ optimize="${compile.optimize}"
+ encoding="ISO-8859-1">
+ <classpath refid="test.classpath"/>
+ </javac>
+ <copy todir="${build.dest}/test" filtering="yes" encoding="ISO-8859-1">
+ <fileset dir="${build.src}/test">
+ <include name="**/*.xml"/>
+ <include name="**/*.properties"/>
+ </fileset>
+ </copy>
+ </target>
+
+ <!-- =================================================================== -->
+ <!-- Junit tests -->
+ <!-- =================================================================== -->
+ <target name="test" depends="compile-tests" description="Run the tests">
+ <echo message="Running Tomcat Native package tests ..."/>
+ <java dir="${test.dir}" classname="${test.runner}" fork="yes" failonerror="${test.failonerror}">
+ <arg value="org.apache.tomcat.jni.FileTestSuite"/>
+ <classpath refid="test.classpath"/>
+ <env key="PATH" path="${tc.library.path}:${java.library.path}"/>
+ <env key="Path" path="${tc.library.path}:${java.library.path}"/>
+ <jvmarg value="-Djava.library.path=${tc.library.path}"/>
+ </java>
+ <java dir="${test.dir}" classname="${test.runner}" fork="yes" failonerror="${test.failonerror}">
+ <arg value="org.apache.tomcat.jni.SocketServerTestSuite"/>
+ <classpath refid="test.classpath"/>
+ <env key="PATH" path="${tc.library.path}:${java.library.path}"/>
+ <env key="Path" path="${tc.library.path}:${java.library.path}"/>
+ <jvmarg value="-Djava.library.path=${tc.library.path}"/>
+ </java>
+ </target>
+
+ <!-- =================================================================== -->
+ <!-- Compiles the examples directory -->
+ <!-- =================================================================== -->
+ <target name="compile-examples" depends="compile" description="Compile example Java classes">
+ <mkdir dir="${build.dest}"/>
+ <mkdir dir="${build.dest}/examples"/>
+ <mkdir dir="${build.src}"/>
+ <mkdir dir="${build.src}/examples"/>
+ <tstamp>
+ <format property="TODAY" pattern="MMM d yyyy" locale="en"/>
+ <format property="TSTAMP" pattern="hh:mm:ss"/>
+ </tstamp>
+ <!-- Copy static resource files -->
+ <filter token="VERSION" value="${version}"/>
+ <filter token="VERSION_NUMBER" value="${version.number}"/>
+ <filter token="VERSION_BUILT" value="${TODAY} ${TSTAMP}"/>
+ <copy todir="${build.src}/examples" filtering="yes" encoding="ISO-8859-1">
+ <fileset dir="${src.dir}/examples">
+ <include name="**/*.java"/>
+ <include name="**/*.xml"/>
+ <include name="**/*.properties"/>
+ </fileset>
+ </copy>
+ <javac srcdir="${build.src}/examples"
+ destdir="${build.dest}/examples"
+ source="${compile.source}"
+ target="${compile.target}"
+ debug="${compile.debug}"
+ deprecation="${compile.deprecation}"
+ optimize="${compile.optimize}"
+ encoding="ISO-8859-1">
+ <classpath refid="examples.classpath"/>
+ </javac>
+ <copy todir="${build.dest}/examples" filtering="yes" encoding="ISO-8859-1">
+ <fileset dir="${build.src}/examples">
+ <include name="**/*.xml"/>
+ <include name="**/*.properties"/>
+ </fileset>
+ </copy>
+ </target>
+
+ <!-- =================================================================== -->
+ <!-- executes the examples -->
+ <!-- =================================================================== -->
+ <target name="run-echo" depends="compile-examples" description="Run the Echo example">
+ <echo message="Running Tomcat Native Echo example ..."/>
+ <java dir="${examples.dir}" classname="org.apache.tomcat.jni.Echo"
+ fork="yes" failonerror="${test.failonerror}">
+ <classpath refid="examples.classpath"/>
+ <env key="PATH" path="${tc.library.path}:${java.library.path}"/>
+ <env key="Path" path="${tc.library.path}:${java.library.path}"/>
+ <jvmarg value="-Djava.library.path=${tc.library.path}"/>
+ </java>
+ </target>
+ <target name="run-ssl-server" depends="compile-examples" description="Run the SSL Server example">
+ <echo message="Running Tomcat Native SSL Server example ..."/>
+ <java dir="${examples.dir}" classname="org.apache.tomcat.jni.SSLServer"
+ fork="yes" failonerror="${test.failonerror}">
+ <env key="PATH" path="${tc.library.path}:${java.library.path}"/>
+ <env key="Path" path="${tc.library.path}:${java.library.path}"/>
+ <classpath refid="examples.classpath"/>
+ <jvmarg value="-Djava.library.path=${tc.library.path}"/>
+ </java>
+ </target>
+ <target name="run-local-server" depends="compile-examples" description="Run the Local Server example">
+ <echo message="Running Tomcat Native Local Server example ..."/>
+ <java dir="${examples.dir}" classname="org.apache.tomcat.jni.LocalServer"
+ fork="yes" failonerror="${test.failonerror}">
+ <classpath refid="examples.classpath"/>
+ <env key="PATH" path="${tc.library.path}:${java.library.path}"/>
+ <env key="Path" path="${tc.library.path}:${java.library.path}"/>
+ <jvmarg value="-Djava.library.path=${tc.library.path}"/>
+ </java>
+ </target>
+</project>
diff --git a/jni/docs/images/add.gif b/jni/docs/images/add.gif
new file mode 100644
index 0000000..0774d07
Binary files /dev/null and b/jni/docs/images/add.gif differ
diff --git a/jni/docs/images/asf-feather.png b/jni/docs/images/asf-feather.png
new file mode 100644
index 0000000..7b596e6
Binary files /dev/null and b/jni/docs/images/asf-feather.png differ
diff --git a/jni/docs/images/code.gif b/jni/docs/images/code.gif
new file mode 100644
index 0000000..d27307b
Binary files /dev/null and b/jni/docs/images/code.gif differ
diff --git a/jni/docs/images/design.gif b/jni/docs/images/design.gif
new file mode 100644
index 0000000..f5db0a9
Binary files /dev/null and b/jni/docs/images/design.gif differ
diff --git a/jni/docs/images/docs-stylesheet.css b/jni/docs/images/docs-stylesheet.css
new file mode 100644
index 0000000..3269df5
--- /dev/null
+++ b/jni/docs/images/docs-stylesheet.css
@@ -0,0 +1,293 @@
+ at charset "utf-8";
+/*
+ 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.
+*/
+
+
+/* General style */
+
+body {
+ margin: 0;
+}
+
+body, input {
+ font-family: 'Lucida Sans Unicode', Arial, Helvetica, sans-serif;
+ font-size: 10.5pt;
+}
+
+code, pre {
+ font-family: Consolas, monospace;
+}
+
+img {
+ border: 0;
+}
+
+table {
+ border-collapse: collapse;
+ text-align: left;
+}
+table *:not(table) {
+ /* Prevent border-collapsing for table child elements like <div> */
+ border-collapse: separate;
+}
+
+main {
+ /* Remove this once all IEs support <main> element */
+ display: block;
+}
+
+
+/* Layout */
+
+#wrapper {
+ min-width: 400px;
+}
+
+#header {
+ border-bottom: 1px solid #bbb;
+}
+
+ at media not print {
+ #header {
+ box-shadow: 0 0 7px #aaa;
+ }
+}
+
+#header > div {
+ padding-left: 15px;
+ padding-right: 15px;
+
+ /* Work-around for old browsers: */
+ background-color: #F8F3E4;
+ background: linear-gradient(to bottom, #ffffff -10%, #F8F3E4 100%);
+ position: relative;
+}
+
+#header .logo {
+ float: left;
+ padding-top: 10px;
+ min-width: 190px;
+}
+
+#header .logo img{
+ /* To avoid that the Font Descender being added to the parent div's height */
+ vertical-align: middle;
+}
+
+#header .asfLogo {
+ float: right;
+ position: relative;
+ top: 8px;
+}
+
+#header h1 {
+ margin-top: 0.6em;
+ margin-bottom: 0;
+}
+
+#header .versionInfo {
+ font-size: 13pt;
+ margin-bottom: 1em;
+}
+
+#middle {
+ display: table;
+ table-layout: fixed;
+ margin: 0;
+ width: 100%;
+}
+#middle > div { display: table-row; }
+#middle > div > div { display: table-cell; vertical-align: top; }
+
+
+
+#mainLeft {
+ width: 190px;
+}
+
+#mainLeft > div {
+ margin-top: -1px; /* to overwrite border of element above */
+ padding-left: 16px;
+ padding-right: 14px;
+ padding-top: 6px;
+ padding-bottom: 15px;
+ background-color: #F8F3E4;
+ border-right: 1px solid #bbb;
+ border-bottom: 1px solid #bbb;
+ font-size: 10pt;
+ border-bottom-right-radius: 20px;
+ box-shadow: 0 0 5px #aaa;
+}
+
+#mainLeft h2 {
+ margin-bottom: 0.2em;
+ font-size: 1.2em;
+}
+
+#mainLeft ul {
+ padding: 0;
+ margin: 0;
+ list-style-type: none;
+}
+
+#mainLeft ul a {
+ text-indent: -0.6em;
+ padding-left: 1.4em;
+ display: block;
+ text-decoration: none;
+ color: #444;
+}
+#mainLeft ul a:hover {
+ color: #000;
+ background-color: #D1c9b9;
+}
+
+#mainRight {
+ padding-left: 14px;
+ padding-right: 20px;
+
+}
+
+#footer {
+ margin-top: 30px;
+ padding-top: 20px;
+ padding-bottom: 20px;
+ padding-left: 20px;
+ padding-right: 20px;
+ border-top: 1px solid #ccc;
+ color: #444;
+ text-align: center;
+ /* font-style: italic; */
+ font-size: 9pt;
+}
+
+
+/* Content */
+
+#content div.text {
+ padding-left: 1em;
+ padding-left: 1em;
+}
+
+#content h3, #content h4, #content h5, #content h6 {
+ padding-left: 5px;
+ padding-right: 5px;
+ background-color: #eaeaea;
+}
+
+ at media not print {
+ #content h3, #content h4, #content h5, #content h6 {
+ border: 1px solid #ccc;
+ border-radius: 4px;
+ }
+}
+
+#content h4, #content h5, #content h6 {
+ background-color: #f6f6f6;
+}
+
+code {
+ background-color: rgb(224,255,255);
+}
+
+div.codeBox pre code, code.attributeName, code.propertyName, code.noHighlight, .noHighlight code {
+ background-color: transparent;
+}
+div.codeBox {
+ overflow: auto;
+ margin: 1em 0;
+}
+div.codeBox pre {
+ margin: 0;
+ padding: 4px;
+ border: 1px solid #999;
+ border-radius: 5px;
+ background-color: #eff8ff;
+ display: table; /* To prevent <pre>s from taking the complete available width. */
+ /*
+ When it is officially supported, use the following CSS instead of display: table
+ to prevent big <pre>s from exceeding the browser window:
+ max-width: available;
+ width: min-content;
+ */
+}
+
+div.codeBox pre.wrap {
+ white-space: pre-wrap;
+}
+
+
+table.defaultTable tr, table.detail-table tr {
+ border: 1px solid #CCC;
+}
+
+table.defaultTable tr:nth-child(even), table.detail-table tr:nth-child(even) {
+ background-color: #FAFBFF;
+}
+
+table.defaultTable tr:nth-child(odd), table.detail-table tr:nth-child(odd) {
+ background-color: #EEEFFF;
+}
+
+table.defaultTable th, table.detail-table th {
+ background-color: #88b;
+ color: #fff;
+}
+
+table.defaultTable th, table.defaultTable td, table.detail-table th, table.detail-table td {
+ padding: 5px 8px;
+}
+
+
+p.notice {
+ border: 1px solid rgb(255, 0, 0);
+ background-color: rgb(238, 238, 238);
+ color: rgb(0, 51, 102);
+ padding: 0.5em;
+ margin: 1em 2em 1em 1em;
+}
+
+
+/* Changelog-Styles */
+
+ul.changelog {
+ padding-left: 1em;
+ list-style-type: none;
+}
+
+ul.changelog li{
+ padding-top: 5px;
+ padding-bottom: 5px;
+}
+
+ul.changelog img {
+ vertical-align: middle
+}
+
+
+/* Printer-only Styles */
+ at media print {
+ .noPrint { display: none; }
+ #middle > div > div#mainLeft { display: none; }
+ a { color: inherit; text-decoration: none; }
+}
+
+/* Fix for Comments section which contains a <h4> */
+#comments_thread h1, #comments_thread h2, #comments_thread h3, #comments_thread h4, #comments_thread h5, #comments_thread h6 {
+ border: none;
+ background-color: transparent;
+}
\ No newline at end of file
diff --git a/jni/docs/images/docs.gif b/jni/docs/images/docs.gif
new file mode 100644
index 0000000..d64a4a1
Binary files /dev/null and b/jni/docs/images/docs.gif differ
diff --git a/jni/docs/images/fix.gif b/jni/docs/images/fix.gif
new file mode 100644
index 0000000..d59ad64
Binary files /dev/null and b/jni/docs/images/fix.gif differ
diff --git a/jni/docs/images/printer.gif b/jni/docs/images/printer.gif
new file mode 100644
index 0000000..5021187
Binary files /dev/null and b/jni/docs/images/printer.gif differ
diff --git a/jni/docs/images/style.css b/jni/docs/images/style.css
new file mode 100644
index 0000000..89c3066
--- /dev/null
+++ b/jni/docs/images/style.css
@@ -0,0 +1,23 @@
+/*
+ * 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.
+ */
+
+p.todo {
+ margin-left: 20px;
+ margin-right: 10px;
+ text-align: justify;
+ font-size: smaller;
+}
diff --git a/jni/docs/images/tomcat.gif b/jni/docs/images/tomcat.gif
new file mode 100644
index 0000000..f2aa6f8
Binary files /dev/null and b/jni/docs/images/tomcat.gif differ
diff --git a/jni/docs/images/tomcat.png b/jni/docs/images/tomcat.png
new file mode 100644
index 0000000..f40a9de
Binary files /dev/null and b/jni/docs/images/tomcat.png differ
diff --git a/jni/docs/images/update.gif b/jni/docs/images/update.gif
new file mode 100644
index 0000000..31e22ab
Binary files /dev/null and b/jni/docs/images/update.gif differ
diff --git a/jni/docs/images/void.gif b/jni/docs/images/void.gif
new file mode 100644
index 0000000..e565824
Binary files /dev/null and b/jni/docs/images/void.gif differ
diff --git a/jni/docs/index.html b/jni/docs/index.html
new file mode 100644
index 0000000..64c693f
--- /dev/null
+++ b/jni/docs/index.html
@@ -0,0 +1,188 @@
+<!DOCTYPE html SYSTEM "about:legacy-compat">
+<html lang="en"><head><META http-equiv="Content-Type" content="text/html; charset=UTF-8"><link href="./images/docs-stylesheet.css" rel="stylesheet" type="text/css"><link href="./images/style.css" rel="stylesheet" type="text/css"><title>Apache Tomcat Native Library - Documentation Index</title><meta name="author" content="Jean-Frederic Clere"></head><body><div id="wrapper"><header><div id="header"><div><div><div class="logo noPrint"><a href="http://tomcat.apache.org/"><img alt="Tomcat Hom [...]
+
+ <p>
+ The Apache Tomcat Native Library is an optional component for use with
+ Apache Tomcat that allows Tomcat to use certain native resources
+ for performance, compatibility, etc.
+ </p>
+
+ <p>
+ Specifically, the Apache Tomcat Native Library gives Tomcat access to
+ the Apache Portable Runtime (APR) library's network connection (socket)
+ implementation and random-number generator.
+ See the Apache Tomcat documentation for more information on how to
+ configure Tomcat to use the APR connector.
+ </p>
+
+ <p>
+ Features of the APR connector:
+ </p>
+ <ul>
+ <li>Non-blocking I/O for Keep-Alive requests (between requests)</li>
+ <li>Uses OpenSSL for TLS/SSL capabilities (if supported by linked APR library)</li>
+ <li>FIPS 140-2 support for TLS/SSL (if supported by linked OpenSSL library)</li>
+ </ul>
+
+
+<p>Select one of the links from the navigation menu (to the left) to drill
+down to the more detailed documentation that is available. Each available
+manual is described in more detail below.</p>
+
+</div><h3 id="Headlines">Headlines</h3><div class="text">
+<ul>
+
+<li><a href="news/2013.html#20131015.1">15 October 2013 - <b>TC-Native-1.1.29 released</b></a>
+<p>The Apache Tomcat team is proud to announce the immediate availability of Tomcat Native 1.1.29 Stable.
+</p>
+<p>
+ The sources and the binaries for selected platforms are available from the
+ <a href="../download-native.cgi">Download page</a>.
+</p>
+<p>
+ Please see the <a href="miscellaneous/changelog.html">ChangeLog</a> for a full list of changes.
+</p>
+</li>
+</ul>
+</div><h3 id="Building">Building</h3><div class="text">
+<div class="subsection"><h4 id="Requirements">Requirements</h4><div class="text">
+ <p>
+ Build tc-native requires three components to be installed:
+ </p>
+ <ul>
+ <li>APR library</li>
+ <li>OpenSSL libraries</li>
+ <li>Java SE Development Kit (JDK)</li>
+ </ul>
+
+ <p>
+ In debian based Linux those dependencies could be installed by something like:
+ </p>
+ <div class="codeBox"><pre><code>apt-get install libapr1.0-dev libssl-dev</code></pre></div>
+ <p>
+ In rpm based Linux those dependencies could be installed by something like:
+ </p>
+ <div class="codeBox"><pre><code>yum install apr-devel openssl-devel</code></pre></div>
+</div></div>
+
+<div class="subsection"><h4 id="Building/UNIX">UNIX</h4><div class="text">
+ <p>
+ On all the POSIX systems (Linux, Solaris, HP-UX, AIX etc...) a well-known
+ configure and make is used to build tc-native.<br>
+ In the jni/native runs:
+ </p>
+ <div class="codeBox"><pre><code>./configure --help</code></pre></div>
+ <p>to read the description of all the parameters.</p>
+ <div class="codeBox"><pre><code>./configure --with-apr=$HOME/APR \
+ --with-java-home=$JAVA_HOME \
+ --with-ssl=$HOME/OPENSSL \
+ --prefix=$CATALINA_HOME</code></pre></div>
+ <p>
+ to create the includes and makefiles to be able to build tc-native.<br>
+ Where:<br>
+ <code>$HOME/APR</code> is something like /usr/bin/apr-1-config or the path where apr is
+ installed.<br>
+ <code>$JAVA_HOME</code> is something /home/jfclere/JAVA/jdk1.5.0_09 path to a JDK
+ installation. Any JDK should work but it is advisable to use the same
+ JVM version the JVM you use with Tomcat.<br>
+ <code>$HOME/OPENSSL</code> is the path where OpenSSL is installed.<br>
+ <code>$CATALINA_HOME</code> is the path where the produced libraries will be
+ installed. Something like $HOME/apache-tomcat-6.0.16/<br>
+ <br>
+ The configure is able to guess most of OpenSSL standard installations.
+ So most of the time the following will be enough:
+ </p>
+ <div class="codeBox"><pre><code>./configure --with-apr=/usr/bin/apr-1-config \
+ --with-java-home=/home/jfclere/JAVA/jdk1.5.0_09/ \
+ --with-ssl=yes \
+ --prefix=$CATALINA_HOME</code></pre></div>
+ <p>
+ To build the libraries and install them:
+ </p>
+ <div class="codeBox"><pre><code>make && make install</code></pre></div>
+ <p>
+ The libraries will be found in $CATALINA_HOME/lib
+ </p>
+</div></div>
+
+<div class="subsection"><h4 id="Building/Windows">Windows</h4><div class="text">
+ <p>
+ Download the windows sources of tc-native and extract them.
+ </p>
+ <p>
+ Download OpenSSL sources (See <a href="http://www.openssl.org/related/binaries.html"><b>Binary Distributions</b></a>)
+ OpenSSL is a crypto software so check if you are allowed to download it. If not you can still use tc-native without SSL.
+ </p>
+ <p>
+ Download APR sources for Windows. (See <a href="http://apr.apache.org/download.cgi"><b>Download</b></a>)
+ Extract them in jni and rename the apr-1.x.y directory to apr.
+ </p>
+ <p>
+ Use MS Visual Studio to open the workspace of the APR sources and build the library (libapr).
+ </p>
+ <p>
+ Use MS Visual Studio to open the workspace of the tc-native sources, adjust the OpenSSL includes and libraries location
+ change the name of the libraries libeay32 and libssleay to libeay32MT and libssleayMT and build the tcn-native library.
+ That should create a tcnative-1.dll.
+ </p>
+</div></div>
+
+</div><h3 id="Install_and_tests">Install and tests</h3><div class="text">
+ <div class="subsection"><h4 id="Configuring_Tomcat">Configuring Tomcat</h4><div class="text">
+ <p>
+ Apache Tomcat comes with the <code>AprLifecycleListener</code> enabled
+ by default. Still, you should check your <code>conf/server.xml</code>
+ to ensure that something like the following is present, and uncommented:
+ </p>
+
+ <div class="codeBox"><pre class="wrap"><code><Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="on" /></code></pre></div>
+ <p>
+ Please see the Apache Tomcat documentation for configuration specifics.
+ </p>
+ </div></div>
+
+<div class="subsection"><h4 id="Install_and_tests/UNIX">UNIX</h4><div class="text">
+ <p>
+ Edit $CATALINA_HOME/bin/setenv.sh (creating the file if necessary) and add
+ the path to the tc-native libraries to LD_LIBRARY_PATH. Something like:
+ </p>
+ <div class="codeBox"><pre><code>LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$CATALINA_HOME/lib
+export LD_LIBRARY_PATH</code></pre></div>
+ <p>
+ Start tomcat and check for the messages like this ones:
+ </p>
+ <div class="codeBox"><pre class="wrap"><code>Feb 8, 2008 12:27:41 PM org.apache.catalina.core.AprLifecycleListener init
+INFO: Loaded APR based Apache Tomcat Native library 1.x.y.
+Feb 8, 2008 12:27:41 PM org.apache.catalina.core.AprLifecycleListener init
+INFO: APR capabilities: IPv6 [true], sendfile [true], accept filters [false], random [true].
+Feb 8, 2008 12:27:41 PM org.apache.coyote.http11.Http11AprProtocol init
+INFO: Initializing Coyote HTTP/1.1 on http-8080</code></pre></div>
+ <p>
+ Refer to the tomcat documentation to configure the connectors
+ (See <a href="http://tomcat.apache.org/tomcat-6.0-doc/apr.html">Tomcat6.0.x</a>
+ and <a href="http://tomcat.apache.org/tomcat-5.5-doc/apr.html">Tomcat5.5.x</a>)
+ </p>
+</div></div>
+
+<div class="subsection"><h4 id="Install_and_tests/Windows">Windows</h4><div class="text">
+ <p>
+ Edit $CATALINA_BASE\bin\setenv.bat (creating the file if necessary) and add
+ the path to the tc-native libraries, apr and OpenSSL to PATH. For example:
+ </p>
+
+ <div class="codeBox"><pre class="wrap"><code>set PATH=%PATH;C:\cygwin\home\support\tomcat-native-current-win32-src\jni\native\Debug;C:\cygwin\home\support\tomcat-native-current-win32-src\jni\apr\Debug;C:\OpenSSL\lib\VC</code></pre></div>
+ <p>
+ Start tomcat and check for the messages like this ones:
+ </p>
+ <div class="codeBox"><pre class="wrap"><code>Feb 8, 2008 2:48:17 PM org.apache.catalina.core.AprLifecycleListener init
+INFO: Loaded APR based Apache Tomcat Native library 1.x.y.
+Feb 8, 2008 2:48:17 PM org.apache.catalina.core.AprLifecycleListener init
+INFO: APR capabilities: IPv6 [false], sendfile [true], accept filters [false], random [true].
+Feb 8, 2008 2:48:18 PM org.apache.coyote.http11.Http11AprProtocol init
+INFO: Initializing Coyote HTTP/1.1 on http-8080</code></pre></div>
+
+</div></div>
+
+</div></div></div></div></div><footer><div id="footer">
+ Copyright © 2008-2014, The Apache Software Foundation
+ </div></footer></div></body></html>
\ No newline at end of file
diff --git a/jni/docs/miscellaneous/changelog.html b/jni/docs/miscellaneous/changelog.html
new file mode 100644
index 0000000..57aec21
--- /dev/null
+++ b/jni/docs/miscellaneous/changelog.html
@@ -0,0 +1,287 @@
+<!DOCTYPE html SYSTEM "about:legacy-compat">
+<html lang="en"><head><META http-equiv="Content-Type" content="text/html; charset=UTF-8"><link href="../images/docs-stylesheet.css" rel="stylesheet" type="text/css"><link href="../images/style.css" rel="stylesheet" type="text/css"><title>The Apache Tomcat Native - Miscellaneous Documentation - </title><meta name="author" content="Jean-Frederic Clere"></head><body><div id="wrapper"><header><div id="header"><div><div><div class="logo noPrint"><a href="http://tomcat.apache.org/"><img alt="T [...]
+ <p>
+ This is the Changelog for Tomcat Native. This changelog
+ does not contain all updates and fixes to the Tomcat Native (yet).
+ It should contain fixes made only after December 19th 2007, when the
+ new documentation project for Tomcat Native was started.
+ </p>
+</div><h3 id="Changes_between_1.1.29_and_1.1.30">Changes between 1.1.29 and 1.1.30</h3><div class="text">
+ <ul class="changelog">
+ <li><img alt="Fix: " class="icon" src="../images/fix.gif">
+ <a href="http://issues.apache.org/bugzilla/show_bug.cgi?id=56363">56363</a>: Use OpenSSL 1.0.1g with Windows binaries. (mturk)
+ </li>
+ <li><img alt="Fix: " class="icon" src="../images/fix.gif">
+ <a href="http://issues.apache.org/bugzilla/show_bug.cgi?id=55915">55915</a>: Apply Mike Noordermeer's patch for ECDHE support. (mturk)
+ </li>
+ <li><img alt="Fix: " class="icon" src="../images/fix.gif">
+ <a href="http://issues.apache.org/bugzilla/show_bug.cgi?id=55663">55663</a>: Minor correction to the wording of the NOTICE file
+ to align it with the <a href="http://www.apache.org/legal/src-headers.html#notice">requirements
+ for NOTICE files</a>. (kkolinko)
+ </li>
+ <li><img alt="Fix: " class="icon" src="../images/fix.gif">
+ <a href="http://issues.apache.org/bugzilla/show_bug.cgi?id=56027">56027</a>: Partial fix includes new <code>fipsModeGet</code>
+ function to get the current state of OpenSSL FIPS mode.
+ </li>
+ </ul>
+</div><h3 id="Changes_between_1.1.28_and_1.1.29">Changes between 1.1.28 and 1.1.29</h3><div class="text">
+ <ul class="changelog">
+ <li><img alt="Fix: " class="icon" src="../images/fix.gif">
+ Change return code when removing a socket from a poller, that was
+ actually not in the poller from APR_SUCCESS to APR_NOTFOUND. (rjung)
+ </li>
+ </ul>
+</div><h3 id="Changes_between_1.1.27_and_1.1.28">Changes between 1.1.27 and 1.1.28</h3><div class="text">
+ <ul class="changelog">
+ <li><img alt="Update: " class="icon" src="../images/update.gif">
+ Java classes in package org.apache.tomcat.jni are now taken
+ from Tomcat trunk using svn:externals. (rjung)
+ </li>
+ <li><img alt="Update: " class="icon" src="../images/update.gif">
+ Minimum supported APR version is now again 1.2.1. Version 1.3.0
+ of APR improves performance. (rjung)
+ </li>
+ <li><img alt="Fix: " class="icon" src="../images/fix.gif">
+ <a href="http://issues.apache.org/bugzilla/show_bug.cgi?id=29422">29422</a>: Fixed double-free in <code>ssl_ocsp_request</code>.
+ Patch provided by Aristotelis. (schultz)
+ </li>
+ <li><img alt="Fix: " class="icon" src="../images/fix.gif">
+ <a href="http://issues.apache.org/bugzilla/show_bug.cgi?id=51655">51655</a>: Added a decent description of what tcnative actually is.
+ (schultz)
+ </li>
+ <li><img alt="Fix: " class="icon" src="../images/fix.gif">
+ <a href="http://issues.apache.org/bugzilla/show_bug.cgi?id=51813">51813</a>: Add NULL-checking for <code>s->net</code> to
+ avoid SIGSEGV in situations where it appears a socket has been recycled.
+ (schultz)
+ </li>
+ </ul>
+</div><h3 id="Changes_between_1.1.26_and_1.1.27">Changes between 1.1.26 and 1.1.27</h3><div class="text">
+ <ul class="changelog">
+ <li><img alt="Fix: " class="icon" src="../images/fix.gif">
+ <a href="http://issues.apache.org/bugzilla/show_bug.cgi?id=54513">54513</a>: Fix regression in pollset return value. (mturk)
+ </li>
+ <li><img alt="Fix: " class="icon" src="../images/fix.gif">
+ Switch CPU information on Solaris from milliseconds to
+ microseconds. Make consistent with OS.java and Linux impl. (rjung)
+ </li>
+ </ul>
+</div><h3 id="Changes_between_1.1.25_and_1.1.26_(not_released)">Changes between 1.1.25 and 1.1.26 (not released)</h3><div class="text">
+ <ul class="changelog">
+ <li><img alt="Fix: " class="icon" src="../images/fix.gif">
+ <a href="http://issues.apache.org/bugzilla/show_bug.cgi?id=54468">54468</a>: Fix FIPS mode for listeners when using OpenSSL 1.0.1c
+ and later; resolves 'Low level API call to digest MD5 forbidden in FIPS
+ mode!' errors. (wrowe)
+ </li>
+ <li><img alt="Update: " class="icon" src="../images/update.gif">
+ Add clearOptions function to allow access to OpenSSL's
+ SSL_CTX_clear_options function. (schultz)
+ </li>
+ </ul>
+</div><h3 id="Changes_between_1.1.24_and_1.1.25_(not_released)">Changes between 1.1.24 and 1.1.25 (not released)</h3><div class="text">
+ <ul class="changelog">
+ <li><img alt="Update: " class="icon" src="../images/update.gif">
+ Minimum supported APR version is now 1.3.0. (mturk)
+ </li>
+ <li><img alt="Fix: " class="icon" src="../images/fix.gif">
+ <a href="http://issues.apache.org/bugzilla/show_bug.cgi?id=52856">52856</a>: Fix high CPU usage when client changes IP address or
+ has high latency. (mturk)
+ </li>
+ <li><img alt="Update: " class="icon" src="../images/update.gif">
+ Add CPU information to OS info for Linux.
+ This was already available under Windows and Solaris. (rjung)
+ </li>
+ <li><img alt="Fix: " class="icon" src="../images/fix.gif">
+ <a href="http://issues.apache.org/bugzilla/show_bug.cgi?id=53969">53969</a>: ssl.c::hasOp could only check for
+ SSL_OP_ALLOW_UNSAFE_LEGACY_RENEGOTIATION. Now it can check
+ for any SSL_OP_* available at compile-time. (schultz)
+ </li>
+ </ul>
+</div><h3 id="Changes_between_1.1.23_and_1.1.24">Changes between 1.1.23 and 1.1.24</h3><div class="text">
+ <ul class="changelog">
+ <li><img alt="Update: " class="icon" src="../images/update.gif">
+ Add support for per-socket timeouts inside poller. (markt, mturk)
+ </li>
+ </ul>
+</div><h3 id="Changes_between_1.1.22_and_1.1.23">Changes between 1.1.22 and 1.1.23</h3><div class="text">
+ <ul class="changelog">
+ <li><img alt="Update: " class="icon" src="../images/update.gif">
+ <a href="http://issues.apache.org/bugzilla/show_bug.cgi?id=45392">45392</a>: Add support for OCSP verification. Based upon a patch
+ from Aristotelis. (mturk)
+ </li>
+ <li><img alt="Fix: " class="icon" src="../images/fix.gif">
+ <a href="http://issues.apache.org/bugzilla/show_bug.cgi?id=52119">52119</a>: Autodetect Diablo JDK on FreeBSD and Java7+. Based upon a patch
+ from Michael Osipov. (mturk)
+ </li>
+ <li><img alt="Fix: " class="icon" src="../images/fix.gif">
+ <a href="http://issues.apache.org/bugzilla/show_bug.cgi?id=52717">52717</a>: Set scope_id for IPv6 addresses if provided. (mturk)
+ </li>
+ <li><img alt="Update: " class="icon" src="../images/update.gif">
+ <a href="http://issues.apache.org/bugzilla/show_bug.cgi?id=50570">50570</a>: Allow explicit use of FIPS mode in APR lifecycle
+ listener (native support only in this update; Java support to follow).
+ Based upon a patch from Chris Beckey. (schultz)
+ </li>
+ </ul>
+</div><h3 id="Changes_between_1.1.21_and_1.1.22">Changes between 1.1.21 and 1.1.22</h3><div class="text">
+ <ul class="changelog">
+ <li><img alt="Fix: " class="icon" src="../images/fix.gif">
+ Arrange release packaging script. (jfclere).
+ </li>
+ <li><img alt="Fix: " class="icon" src="../images/fix.gif">
+ Fix typos in the changelog. (markt).
+ </li>
+ </ul>
+</div><h3 id="Changes_between_1.1.20_and_1.1.21_(not_released)">Changes between 1.1.20 and 1.1.21 (not released)</h3><div class="text">
+ <ul class="changelog">
+ <li><img alt="Fix: " class="icon" src="../images/fix.gif">
+ <a href="http://issues.apache.org/bugzilla/show_bug.cgi?id=50394">50394</a>: InternalAprInputBuffer.fill() doesn't deal correctly with EOF. (jfclere)
+ </li>
+ <li><img alt="Fix: " class="icon" src="../images/fix.gif">
+ Support arbitrary protocol combinations of SSLv2, SSLv3 and TLSv1. (rjung)
+ </li>
+ <li><img alt="Fix: " class="icon" src="../images/fix.gif">
+ <a href="http://issues.apache.org/bugzilla/show_bug.cgi?id=51437">51437</a>: Try loading certificate in DER format if PEM was invalid. (mturk)
+ </li>
+ <li><img alt="Fix: " class="icon" src="../images/fix.gif">
+ <a href="http://issues.apache.org/bugzilla/show_bug.cgi?id=49557">49557</a>: index error in the loop to get the env info in the proc.create function. (kkolinko, jfclere)
+ </li>
+ <li><img alt="Fix: " class="icon" src="../images/fix.gif">
+ <a href="http://issues.apache.org/bugzilla/show_bug.cgi?id=49851">49851</a>: JNI Registry.deleteKey and Registry.deleteValue corrupt Windows registry. (jfclere)
+ </li>
+ <li><img alt="Fix: " class="icon" src="../images/fix.gif">
+ <a href="http://issues.apache.org/bugzilla/show_bug.cgi?id=48253">48253</a>: adding dynamic locking callbacks for openssl engines. (jfclere)
+ </li>
+ <li><img alt="Update: " class="icon" src="../images/update.gif">
+ Make the non blocking write really no blocking. (jfclere)
+ </li>
+ <li><img alt="Update: " class="icon" src="../images/update.gif">
+ Add support for unsafe legacy renegotiation. (mturk)
+ </li>
+ </ul>
+</div><h3 id="Changes_between_1.1.19_and_1.1.20">Changes between 1.1.19 and 1.1.20</h3><div class="text">
+ <ul class="changelog">
+ <li><img alt="Fix: " class="icon" src="../images/fix.gif">
+ <a href="http://issues.apache.org/bugzilla/show_bug.cgi?id=48584">48584</a>: Prevent crashing JVM on shutdown. (mturk)
+ </li>
+ </ul>
+</div><h3 id="Changes_between_1.1.18_and_1.1.19">Changes between 1.1.18 and 1.1.19</h3><div class="text">
+ <ul class="changelog">
+ <li><img alt="Fix: " class="icon" src="../images/fix.gif">
+ Update windows resource files to correct version. (mturk)
+ </li>
+ <li><img alt="Fix: " class="icon" src="../images/fix.gif">
+ <a href="http://issues.apache.org/bugzilla/show_bug.cgi?id=48129">48129</a>: Fix build with OpenSSL 1.0.0-beta3.
+ Patch provided by Tomas Mraz. (mturk, rjung)
+ </li>
+ <li><img alt="Update: " class="icon" src="../images/update.gif">
+ Add detection of the Mac OS X JVM. (rjung)
+ </li>
+ </ul>
+</div><h3 id="Changes_between_1.1.17_and_1.1.18">Changes between 1.1.17 and 1.1.18</h3><div class="text">
+ <ul class="changelog">
+ <li><img alt="Fix: " class="icon" src="../images/fix.gif">
+ Fix CVE-2009-3555 SSL-Man-In-The-Middle attack. (mturk)
+ </li>
+ </ul>
+</div><h3 id="Changes_between_1.1.16_and_1.1.17">Changes between 1.1.16 and 1.1.17</h3><div class="text">
+ <ul class="changelog">
+ <li><img alt="Update: " class="icon" src="../images/update.gif">
+ Arrange build after svn reorganisation (rjung)
+ </li>
+ <li><img alt="Fix: " class="icon" src="../images/fix.gif">
+ <a href="http://issues.apache.org/bugzilla/show_bug.cgi?id=47852">47852</a>: Fix some Javadoc errors. Patch provided by Sebb. (rjung)
+ </li>
+ <li><img alt="Fix: " class="icon" src="../images/fix.gif">
+ <a href="http://issues.apache.org/bugzilla/show_bug.cgi?id=46950">46950</a>: Fix SSL renegotiation in combination with client
+ certificates. The complete solution also needs a fix in Tomcat's Java code. (markt)
+ </li>
+ <li><img alt="Fix: " class="icon" src="../images/fix.gif">
+ Align method names and signatures of native C code and java code. (markt, rjung)
+ </li>
+ <li><img alt="Fix: " class="icon" src="../images/fix.gif">
+ <a href="http://issues.apache.org/bugzilla/show_bug.cgi?id=42728">42728</a>: Remove memory leak. (markt)
+ </li>
+ <li><img alt="Fix: " class="icon" src="../images/fix.gif">
+ <a href="http://issues.apache.org/bugzilla/show_bug.cgi?id=46457">46457</a>: Fix use of multicast. (markt)
+ </li>
+ <li><img alt="Fix: " class="icon" src="../images/fix.gif">
+ Fix API name for recvfrom (mturk)
+ </li>
+ <li><img alt="Fix: " class="icon" src="../images/fix.gif">
+ Allow building against APR 1.3 (mturk)
+ </li>
+ <li><img alt="Fix: " class="icon" src="../images/fix.gif">
+ Improve fix for <a href="http://issues.apache.org/bugzilla/show_bug.cgi?id=43327">43327</a> with better handling for IPv6
+ addresses (markt)
+ </li>
+ </ul>
+</div><h3 id="Changes_between_1.1.15_and_1.1.16">Changes between 1.1.15 and 1.1.16</h3><div class="text">
+ <ul class="changelog">
+ <li><img alt="Fix: " class="icon" src="../images/fix.gif">
+ Fix API name for recvfrom (mturk)
+ </li>
+ <li><img alt="Fix: " class="icon" src="../images/fix.gif">
+ Allow building against APR 1.3 (mturk)
+ </li>
+ <li><img alt="Fix: " class="icon" src="../images/fix.gif">
+ Improve fix for <a href="http://issues.apache.org/bugzilla/show_bug.cgi?id=43327">43327</a> with better handling for IPv6
+ addresses (markt)
+ </li>
+ </ul>
+</div><h3 id="Changes_between_1.1.14_and_1.1.15">Changes between 1.1.14 and 1.1.15</h3><div class="text">
+ <ul class="changelog">
+ <li><img alt="Fix: " class="icon" src="../images/fix.gif">
+ <a href="http://issues.apache.org/bugzilla/show_bug.cgi?id=43327">43327</a>: Socket bind fail because mixing IPv4/IPv6 (markt, jfclere)
+ </li>
+ <li><img alt="Fix: " class="icon" src="../images/fix.gif">
+ <a href="http://issues.apache.org/bugzilla/show_bug.cgi?id=44864">44864</a>: Use additional check for SSL verify like
+ with mod_ssl for SSLVerifyClient=optionalNoCA. (mturk)
+ </li>
+ </ul>
+</div><h3 id="Changes_between_1.1.13_and_1.1.14">Changes between 1.1.13 and 1.1.14</h3><div class="text">
+ <ul class="changelog">
+ <li><img alt="Fix: " class="icon" src="../images/fix.gif">
+ <a href="http://issues.apache.org/bugzilla/show_bug.cgi?id=45071">45071</a>: Reset ttl when Poll.pool remove is false.
+ Additional patch was provided by Alex Barclay. (mturk)
+ </li>
+ <li><img alt="Fix: " class="icon" src="../images/fix.gif">
+ Fix optGet that was always throwing exceptions. (jfclere)
+ </li>
+ <li><img alt="Fix: " class="icon" src="../images/fix.gif">
+ Fix optSet don't throw exception as JAVA prototype doesn't. (jfclere)
+ </li>
+ </ul>
+</div><h3 id="Changes_between_1.1.12_and_1.1.13">Changes between 1.1.12 and 1.1.13</h3><div class="text">
+ <ul class="changelog">
+ <li><img alt="Fix: " class="icon" src="../images/fix.gif">
+ IFS problem in native/build/tcnative.m4 (rjung)
+ </li>
+ <li><img alt="Fix: " class="icon" src="../images/fix.gif">
+ Wrong gcc link flag in native/build/tcnative.m4 (rjung)
+ </li>
+ </ul>
+</div><h3 id="Changes_between_1.1.11_and_1.1.12">Changes between 1.1.11 and 1.1.12</h3><div class="text">
+ <ul class="changelog">
+ <li><img alt="Update: " class="icon" src="../images/update.gif">
+ Add support of J9VM based JVM. (jfclere)
+ </li>
+ <li><img alt="Update: " class="icon" src="../images/update.gif">
+ Arrange licence in source files. (markt)
+ </li>
+ <li><img alt="Update: " class="icon" src="../images/update.gif">
+ Add two new 'immediate' methods for sending the data.
+ It is the responsibility of the Java callee to deal with
+ the returned values and retry if the error was non-fatal. (mturk)
+ </li>
+ <li><img alt="Fix: " class="icon" src="../images/fix.gif">
+ Arrange the check of openssl version. It was failing on Linux. (jfclere)
+ </li>
+ <li><img alt="Fix: " class="icon" src="../images/fix.gif">
+ Prevent returning APR_SUCCESS when there is something wrong in ssl layer. (jfclere)
+ </li>
+ <li><img alt="Fix: " class="icon" src="../images/fix.gif">
+ <a href="http://issues.apache.org/bugzilla/show_bug.cgi?id=44087">44087</a>: Fix it. (jfclere)
+ </li>
+ </ul>
+</div></div></div></div></div><footer><div id="footer">
+ Copyright © 2008-2014, The Apache Software Foundation
+ </div></footer></div></body></html>
\ No newline at end of file
diff --git a/jni/docs/news/2008.html b/jni/docs/news/2008.html
new file mode 100644
index 0000000..3783363
--- /dev/null
+++ b/jni/docs/news/2008.html
@@ -0,0 +1,28 @@
+<!DOCTYPE html SYSTEM "about:legacy-compat">
+<html lang="en"><head><META http-equiv="Content-Type" content="text/html; charset=UTF-8"><link href="../images/docs-stylesheet.css" rel="stylesheet" type="text/css"><link href="../images/style.css" rel="stylesheet" type="text/css"><title>The Apache Tomcat Native - News - 2008 News and Status</title><meta name="author" content="Apache Tomcat Native Project"></head><body><div id="wrapper"><header><div id="header"><div><div><div class="logo noPrint"><a href="http://tomcat.apache.org/"><img [...]
+<div class="subsection"><h4 id="20081118.1">18 November - TC-Native-1.1.16 released</h4><div class="text">
+<p>The Apache Tomcat team is proud to announce the immediate availability
+of Tomcat Native 1.1.16. This is a stable release adding some bug fixes.
+</p>
+</div></div>
+<div class="subsection"><h4 id="20080911.1">11 September - TC-Native-1.1.15 released</h4><div class="text">
+<p>The Apache Tomcat team is proud to announce the immediate availability
+of Tomcat Native 1.1.15. This is a stable release adding some bug fixes.
+</p>
+</div></div>
+<div class="subsection"><h4 id="20080704.1">4 July - TC-Native-1.1.14 released</h4><div class="text">
+<p>The Apache Tomcat team is proud to announce the immediate availability
+of Tomcat Native 1.1.14. This is a stable release adding some bug fixes.
+</p>
+</div></div>
+<div class="subsection"><h4 id="20080115.1">15 February - TC-Native-1.1.13 released</h4><div class="text">
+<p>The Apache Tomcat team is proud to announce the immediate availability
+of Tomcat Native 1.1.13. This is a stable release adding few new features
+and some bug fixes.
+</p><p>
+ Please see the <a href="../miscellaneous/changelog.html">ChangeLog</a> for a full list of changes.
+</p>
+</div></div>
+</div></div></div></div></div><footer><div id="footer">
+ Copyright © 2008-2014, The Apache Software Foundation
+ </div></footer></div></body></html>
\ No newline at end of file
diff --git a/jni/docs/news/2009.html b/jni/docs/news/2009.html
new file mode 100644
index 0000000..f7ad75b
--- /dev/null
+++ b/jni/docs/news/2009.html
@@ -0,0 +1,12 @@
+<!DOCTYPE html SYSTEM "about:legacy-compat">
+<html lang="en"><head><META http-equiv="Content-Type" content="text/html; charset=UTF-8"><link href="../images/docs-stylesheet.css" rel="stylesheet" type="text/css"><link href="../images/style.css" rel="stylesheet" type="text/css"><title>The Apache Tomcat Native - News - 2009 News and Status</title><meta name="author" content="Apache Tomcat Native Project"></head><body><div id="wrapper"><header><div id="header"><div><div><div class="logo noPrint"><a href="http://tomcat.apache.org/"><img [...]
+<div class="subsection"><h4 id="20091123.1">23 November - TC-Native-1.1.18 released</h4><div class="text">
+<p>The Apache Tomcat team is proud to announce the immediate availability
+of Tomcat Native 1.1.18. This is a stable release adding some bug fixes.
+</p><p>
+ Please see the <a href="../miscellaneous/changelog.html">ChangeLog</a> for a full list of changes.
+</p>
+</div></div>
+</div></div></div></div></div><footer><div id="footer">
+ Copyright © 2008-2014, The Apache Software Foundation
+ </div></footer></div></body></html>
\ No newline at end of file
diff --git a/jni/docs/news/2010.html b/jni/docs/news/2010.html
new file mode 100644
index 0000000..8608f4a
--- /dev/null
+++ b/jni/docs/news/2010.html
@@ -0,0 +1,17 @@
+<!DOCTYPE html SYSTEM "about:legacy-compat">
+<html lang="en"><head><META http-equiv="Content-Type" content="text/html; charset=UTF-8"><link href="../images/docs-stylesheet.css" rel="stylesheet" type="text/css"><link href="../images/style.css" rel="stylesheet" type="text/css"><title>The Apache Tomcat Native - News - 2010 News and Status</title><meta name="author" content="Apache Tomcat Native Project"></head><body><div id="wrapper"><header><div id="header"><div><div><div class="logo noPrint"><a href="http://tomcat.apache.org/"><img [...]
+<div class="subsection"><h4 id="20100217.1">17 February - TC-Native-1.1.20 released</h4><div class="text">
+<p>The Apache Tomcat team is proud to announce the immediate availability
+of Tomcat Native 1.1.20. This is a stable release adding some bug fixes.
+</p>
+</div></div>
+<div class="subsection"><h4 id="20100108.1">8 January - TC-Native-1.1.19 released</h4><div class="text">
+<p>The Apache Tomcat team is proud to announce the immediate availability
+of Tomcat Native 1.1.19. This is a stable release adding some bug fixes.
+</p><p>
+ Please see the <a href="../miscellaneous/changelog.html">ChangeLog</a> for a full list of changes.
+</p>
+</div></div>
+</div></div></div></div></div><footer><div id="footer">
+ Copyright © 2008-2014, The Apache Software Foundation
+ </div></footer></div></body></html>
\ No newline at end of file
diff --git a/jni/docs/news/2011.html b/jni/docs/news/2011.html
new file mode 100644
index 0000000..ab3aa99
--- /dev/null
+++ b/jni/docs/news/2011.html
@@ -0,0 +1,13 @@
+<!DOCTYPE html SYSTEM "about:legacy-compat">
+<html lang="en"><head><META http-equiv="Content-Type" content="text/html; charset=UTF-8"><link href="../images/docs-stylesheet.css" rel="stylesheet" type="text/css"><link href="../images/style.css" rel="stylesheet" type="text/css"><title>The Apache Tomcat Native - News - 2011 News and Status</title><meta name="author" content="Apache Tomcat Native Project"></head><body><div id="wrapper"><header><div id="header"><div><div><div class="logo noPrint"><a href="http://tomcat.apache.org/"><img [...]
+<div class="subsection"><h4 id="20110808.1">08 August - TC-Native-1.1.22 released</h4><div class="text">
+<p>The Apache Tomcat team is proud to announce the immediate availability
+of Tomcat Native 1.1.22. This is a stable release adding some bug fixes.
+</p>
+<p>
+ Please see the <a href="../miscellaneous/changelog.html">ChangeLog</a> for a full list of changes.
+</p>
+</div></div>
+</div></div></div></div></div><footer><div id="footer">
+ Copyright © 2008-2014, The Apache Software Foundation
+ </div></footer></div></body></html>
\ No newline at end of file
diff --git a/jni/docs/news/2012.html b/jni/docs/news/2012.html
new file mode 100644
index 0000000..49182e3
--- /dev/null
+++ b/jni/docs/news/2012.html
@@ -0,0 +1,23 @@
+<!DOCTYPE html SYSTEM "about:legacy-compat">
+<html lang="en"><head><META http-equiv="Content-Type" content="text/html; charset=UTF-8"><link href="../images/docs-stylesheet.css" rel="stylesheet" type="text/css"><link href="../images/style.css" rel="stylesheet" type="text/css"><title>The Apache Tomcat Native - News - 2012 News and Status</title><meta name="author" content="Apache Tomcat Native Project"></head><body><div id="wrapper"><header><div id="header"><div><div><div class="logo noPrint"><a href="http://tomcat.apache.org/"><img [...]
+<div class="subsection"><h4 id="20120613.1">13 June - TC-Native-1.1.24 released</h4><div class="text">
+<p>The Apache Tomcat team is proud to announce the immediate availability
+of Tomcat Native 1.1.24. This is a feature-add release adding support for
+per-socket Poller timeouts.
+</p>
+<p>
+ Please see the <a href="../miscellaneous/changelog.html">ChangeLog</a> for a full list of changes.
+</p>
+</div></div>
+<div class="subsection"><h4 id="20120302.1">02 March - TC-Native-1.1.23 released</h4><div class="text">
+<p>The Apache Tomcat team is proud to announce the immediate availability
+of Tomcat Native 1.1.23. This is a stable release adding some bug fixes and
+experimental support for OCSP and PKCS12 certificates.
+</p>
+<p>
+ Please see the <a href="../miscellaneous/changelog.html">ChangeLog</a> for a full list of changes.
+</p>
+</div></div>
+</div></div></div></div></div><footer><div id="footer">
+ Copyright © 2008-2014, The Apache Software Foundation
+ </div></footer></div></body></html>
\ No newline at end of file
diff --git a/jni/docs/news/2013.html b/jni/docs/news/2013.html
new file mode 100644
index 0000000..190ae08
--- /dev/null
+++ b/jni/docs/news/2013.html
@@ -0,0 +1,26 @@
+<!DOCTYPE html SYSTEM "about:legacy-compat">
+<html lang="en"><head><META http-equiv="Content-Type" content="text/html; charset=UTF-8"><link href="../images/docs-stylesheet.css" rel="stylesheet" type="text/css"><link href="../images/style.css" rel="stylesheet" type="text/css"><title>The Apache Tomcat Native - News - 2013 News and Status</title><meta name="author" content="Apache Tomcat Native Project"></head><body><div id="wrapper"><header><div id="header"><div><div><div class="logo noPrint"><a href="http://tomcat.apache.org/"><img [...]
+<div class="subsection"><h4 id="20131015.1">15 October - TC-Native-1.1.29 released</h4><div class="text">
+<p>The Apache Tomcat team is proud to announce the immediate availability
+of Tomcat Native 1.1.29. This is a bug fixing release.
+</p>
+</div></div>
+<div class="subsection"><h4 id="20130916.1">16 September - TC-Native-1.1.28 released</h4><div class="text">
+<p>The Apache Tomcat team is proud to announce the immediate availability
+of Tomcat Native 1.1.28. This is a bug fixing release.
+</p>
+<p>
+ Please see the <a href="../miscellaneous/changelog.html">ChangeLog</a> for a full list of changes.
+</p>
+</div></div>
+<div class="subsection"><h4 id="20130212.1">12 February - TC-Native-1.1.27 released</h4><div class="text">
+<p>The Apache Tomcat team is proud to announce the immediate availability
+of Tomcat Native 1.1.27. This is a bug fixing release.
+</p>
+<p>
+ Please see the <a href="../miscellaneous/changelog.html">ChangeLog</a> for a full list of changes.
+</p>
+</div></div>
+</div></div></div></div></div><footer><div id="footer">
+ Copyright © 2008-2014, The Apache Software Foundation
+ </div></footer></div></body></html>
\ No newline at end of file
diff --git a/jni/docs/news/2014.html b/jni/docs/news/2014.html
new file mode 100644
index 0000000..a81deff
--- /dev/null
+++ b/jni/docs/news/2014.html
@@ -0,0 +1,5 @@
+<!DOCTYPE html SYSTEM "about:legacy-compat">
+<html lang="en"><head><META http-equiv="Content-Type" content="text/html; charset=UTF-8"><link href="../images/docs-stylesheet.css" rel="stylesheet" type="text/css"><link href="../images/style.css" rel="stylesheet" type="text/css"><title>The Apache Tomcat Native - News - 2013 News and Status</title><meta name="author" content="Apache Tomcat Native Project"></head><body><div id="wrapper"><header><div id="header"><div><div><div class="logo noPrint"><a href="http://tomcat.apache.org/"><img [...]
+</div></div></div></div></div><footer><div id="footer">
+ Copyright © 2008-2014, The Apache Software Foundation
+ </div></footer></div></body></html>
\ No newline at end of file
diff --git a/jni/examples/mkcerts b/jni/examples/mkcerts
new file mode 100644
index 0000000..a611ca9
--- /dev/null
+++ b/jni/examples/mkcerts
@@ -0,0 +1,216 @@
+#!/bin/sh
+#
+# 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.
+#
+#
+# This is the configuration file to treate the CA certificate of the
+# _DEMONSTRATION ONLY_ 'Coyote' Certificate Authority.
+# This CA is used to sign the localhost.crt and user.crt
+# because self-signed server certificates are not accepted by all browsers.
+# NEVER USE THIS CA YOURSELF FOR REAL LIFE! INSTEAD EITHER USE A PUBLICALLY
+# KNOWN CA OR CREATE YOUR OWN CA!
+
+if [ -z "$OPENSSL" ]; then OPENSSL=openssl; fi
+
+PASSPHRASE="pass:secret"
+# Encrypt all keys
+GENRSA="$OPENSSL genrsa -des3"
+# Uncomment for no key encryption
+# GENRSA="$OPENSSL genrsa"
+REQ="$OPENSSL req -new"
+CA="$OPENSSL ca"
+X509="$OPENSSL x509"
+
+$OPENSSL rand -out .rnd 8192
+$GENRSA -passout $PASSPHRASE -out ca.key -rand .rnd 1024
+
+cat >ca.cfg <<EOT
+[ ca ]
+default_ca = default_db
+[ default_db ]
+dir = .
+certs = .
+new_certs_dir = ca.certs
+database = ca.index
+serial = ca.serial
+RANDFILE = .rnd
+certificate = ca.crt
+private_key = ca.key
+default_days = 365
+default_crl_days = 30
+default_md = md5
+preserve = no
+name_opt = ca_default
+cert_opt = ca_default
+unique_subject = no
+[ server_policy ]
+countryName = supplied
+stateOrProvinceName = supplied
+localityName = supplied
+organizationName = supplied
+organizationalUnitName = supplied
+commonName = supplied
+emailAddress = supplied
+[ server_cert ]
+subjectKeyIdentifier = hash
+authorityKeyIdentifier = keyid:always
+extendedKeyUsage = serverAuth,clientAuth,msSGC,nsSGC
+basicConstraints = critical,CA:false
+[ user_policy ]
+commonName = supplied
+emailAddress = supplied
+[ user_cert ]
+subjectAltName = email:copy
+basicConstraints = critical,CA:false
+authorityKeyIdentifier = keyid:always
+extendedKeyUsage = clientAuth,emailProtection
+
+[ req ]
+default_bits = 1024
+default_keyfile = ca.key
+distinguished_name = default_ca
+x509_extensions = extensions
+string_mask = nombstr
+req_extensions = req_extensions
+input_password = secret
+output_password = secret
+[ default_ca ]
+countryName = Country Code
+countryName_value = US
+countryName_min = 2
+countryName_max = 2
+stateOrProvinceName = State Name
+stateOrProvinceName_value = Delaware
+localityName = Locality Name
+localityName_value = Wilmington
+organizationName = Organization Name
+organizationName_value = Apache Software Foundation
+organizationalUnitName = Organizational Unit Name
+organizationalUnitName_value = Apache Tomcat
+commonName = Common Name
+commonName_value = Apache Tomcat demo root CA
+commonName_max = 64
+emailAddress = Email Address
+emailAddress_value = coyote at tomcat.apache.org
+emailAddress_max = 40
+[ extensions ]
+subjectKeyIdentifier = hash
+authorityKeyIdentifier = keyid:always
+basicConstraints = critical,CA:true
+[ req_extensions ]
+nsCertType = objsign,email,server
+EOT
+
+$REQ -x509 -days 3650 -batch -config ca.cfg -key ca.key -out ca.crt
+
+# Create cabundle.crt that can be used for CAfile
+cat >cabundle.crt <<EOT
+Tomcat Demo Root CA
+=========================================
+`$X509 -noout -fingerprint -in ca.crt`
+PEM Data:
+`$X509 -in ca.crt`
+`$X509 -noout -text -in ca.crt`
+EOT
+
+$GENRSA -passout $PASSPHRASE -out localhost.key -rand .rnd 1024
+
+cat >localhost.cfg <<EOT
+[ req ]
+default_bits = 1024
+distinguished_name = localhost
+string_mask = nombstr
+req_extensions = extensions
+input_password = secret
+output_password = secret
+[ localhost ]
+countryName = Country Code
+countryName_value = US
+countryName_min = 2
+countryName_max = 2
+stateOrProvinceName = State Name
+stateOrProvinceName_value = Delaware
+localityName = Locality Name
+localityName_value = Wilmington
+organizationName = Organization Name
+organizationName_value = Apache Software Foundation
+organizationalUnitName = Organizational Unit Name
+organizationalUnitName_value = Apache Tomcat
+commonName = Common Name
+commonName_value = Apache Tomcat localhost secure demo server
+commonName_max = 64
+emailAddress = Email Address
+emailAddress_value = tomcat at localhost.edu
+emailAddress_max = 40
+[ extensions ]
+nsCertType = server
+basicConstraints = critical,CA:false
+EOT
+
+$REQ -passin $PASSPHRASE -batch -config localhost.cfg -key localhost.key -out localhost.csr
+rm -f localhost.cfg
+
+# make sure environment exists
+if [ ! -d ca.certs ]; then
+ mkdir ca.certs
+ echo '01' >ca.serial
+ cp /dev/null ca.index
+fi
+
+$CA -passin $PASSPHRASE -batch -config ca.cfg -extensions server_cert -policy server_policy -out x.crt -infiles localhost.csr
+$X509 -in x.crt -out localhost.crt
+rm -f x.crt
+# Create PKCS12 localhost certificate
+$OPENSSL pkcs12 -export -passout $PASSPHRASE -passin $PASSPHRASE -in localhost.crt -inkey localhost.key -certfile ca.crt -out localhost.p12
+
+$GENRSA -passout $PASSPHRASE -out user.key -rand .rnd 1024
+
+cat >user.cfg <<EOT
+[ req ]
+default_bits = 1024
+distinguished_name = admin
+string_mask = nombstr
+req_extensions = extensions
+input_password = secret
+output_password = secret
+[ admin ]
+commonName = User Name
+commonName_value = Localhost Administrator
+commonName_max = 64
+emailAddress = Email Address
+emailAddress_value = admin at localhost.edu
+emailAddress_max = 40
+[ extensions ]
+nsCertType = client,email
+basicConstraints = critical,CA:false
+EOT
+
+$REQ -passin $PASSPHRASE -batch -config user.cfg -key user.key -out user.csr
+rm -f user.cfg
+$CA -passin $PASSPHRASE -batch -config ca.cfg -extensions user_cert -policy user_policy -out x.crt -infiles user.csr
+$X509 -in x.crt -out user.crt
+rm -f x.crt
+
+# $OPENSSL verify -CAfile ca.crt localhost.crt
+# $OPENSSL verify -CAfile ca.crt user.crt
+
+# Create PKCS12 user certificate
+$OPENSSL pkcs12 -export -passout $PASSPHRASE -passin $PASSPHRASE -in user.crt -inkey user.key -certfile ca.crt -out user.p12
+
+rm -f ca.cfg
+rm -f *.old
+rm -f ca.index.attr
+rm -f .rnd
diff --git a/jni/examples/org/apache/tomcat/jni/Echo.java b/jni/examples/org/apache/tomcat/jni/Echo.java
new file mode 100644
index 0000000..20e008a
--- /dev/null
+++ b/jni/examples/org/apache/tomcat/jni/Echo.java
@@ -0,0 +1,340 @@
+/*
+ * 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.
+ */
+
+package org.apache.tomcat.jni;
+
+import java.io.InputStream;
+import java.util.Properties;
+
+/** Echo server example
+ *
+ * @author Mladen Turk
+ * @version $Id: Echo.java 1442587 2013-02-05 13:49:48Z rjung $
+ */
+
+public class Echo {
+
+ public static String echoEcho = null;
+ public static String echoAddr = null;
+ public static int echoPort = 0;
+ public static int echoNmax = 0;
+ public static int echoNrun = 0;
+ public static long echoPool = 0;
+
+ private static Poller echoPoller = null;
+ private static Acceptor echoAcceptor = null;
+
+ private static Object threadLock = new Object();
+
+ static {
+
+ try {
+ InputStream is = Echo.class.getResourceAsStream
+ ("/org/apache/tomcat/jni/Echo.properties");
+ Properties props = new Properties();
+ props.load(is);
+ is.close();
+ echoAddr = props.getProperty("echo.ip", "127.0.0.1");
+ echoPort = Integer.decode(props.getProperty("echo.port", "8023")).intValue();
+ echoNmax = Integer.decode(props.getProperty("echo.max", "1")).intValue();
+ }
+ catch (Throwable t) {
+ ; // Nothing
+ }
+ }
+
+ /* Acceptor thread. Listens for new connections */
+ private class Acceptor extends java.lang.Thread {
+ private long serverSock = 0;
+ private long inetAddress = 0;
+ private long pool = 0;
+ public Acceptor() throws Exception {
+ try {
+
+ pool = Pool.create(Echo.echoPool);
+ System.out.println("Accepting: " + Echo.echoAddr + ":" +
+ Echo.echoPort);
+ inetAddress = Address.info(Echo.echoAddr, Socket.APR_INET,
+ Echo.echoPort, 0,
+ pool);
+ serverSock = Socket.create(Socket.APR_INET, Socket.SOCK_STREAM,
+ Socket.APR_PROTO_TCP, pool);
+ long sa = Address.get(Socket.APR_LOCAL, serverSock);
+ Sockaddr addr = new Sockaddr();
+ if (Address.fill(addr, sa)) {
+ System.out.println("Host: " + addr.hostname);
+ System.out.println("Server: " + addr.servname);
+ System.out.println("IP: " + Address.getip(sa) +
+ ":" + addr.port);
+ }
+ int rc = Socket.bind(serverSock, inetAddress);
+ if (rc != 0) {
+ throw(new Exception("Can't create Acceptor: bind: " + Error.strerror(rc)));
+ }
+ Socket.listen(serverSock, 5);
+ }
+ catch( Exception ex ) {
+ ex.printStackTrace();
+ throw(new Exception("Can't create Acceptor"));
+ }
+ }
+
+ public void run() {
+ int i = 0;
+ try {
+ while (true) {
+ long clientSock = Socket.accept(serverSock);
+ System.out.println("Accepted id: " + i);
+
+ try {
+ long sa = Address.get(Socket.APR_REMOTE, clientSock);
+ Sockaddr raddr = new Sockaddr();
+ if (Address.fill(raddr, sa)) {
+ System.out.println("Remote Host: " + Address.getnameinfo(sa, 0));
+ System.out.println("Remote IP: " + Address.getip(sa) +
+ ":" + raddr.port);
+ }
+ sa = Address.get(Socket.APR_LOCAL, clientSock);
+ Sockaddr laddr = new Sockaddr();
+ if (Address.fill(laddr, sa)) {
+ System.out.println("Local Host: " + laddr.hostname);
+ System.out.println("Local Server: " + Address.getnameinfo(sa, 0));
+ System.out.println("Local IP: " + Address.getip(sa) +
+ ":" + laddr.port);
+ }
+
+ } catch (Exception e) {
+ // Ignore
+ e.printStackTrace();
+ }
+
+ Socket.timeoutSet(clientSock, 10000000);
+ Worker worker = new Worker(clientSock, i++,
+ this.getClass().getName());
+ Echo.incThreads();
+ worker.start();
+ }
+ }
+ catch( Exception ex ) {
+ ex.printStackTrace();
+ }
+ }
+ }
+
+ /* Poller thread. Listens for new recycled connections */
+ private class Poller extends java.lang.Thread {
+ private long serverPollset = 0;
+ private long pool = 0;
+ private int nsocks = 0;
+ public Poller() {
+ try {
+
+ pool = Pool.create(Echo.echoPool);
+ serverPollset = Poll.create(16, pool, 0, 10000000);
+ }
+ catch( Exception ex ) {
+ ex.printStackTrace();
+ }
+ }
+
+ public void add(long socket) {
+ int rv = Poll.add(serverPollset, socket,
+ Poll.APR_POLLIN);
+ if (rv == Status.APR_SUCCESS) {
+ System.out.println("Added worker to pollset");
+ nsocks++;
+ }
+ }
+
+ public void remove(long socket) {
+ int rv = Poll.remove(serverPollset, socket);
+ if (rv == Status.APR_SUCCESS) {
+ nsocks--;
+ System.out.println("Removed worker from pollset");
+ }
+ else {
+ System.out.println("Failed removing worker from pollset");
+ }
+ }
+
+ public void run() {
+ while (true) {
+ try {
+ if (nsocks < 1) {
+ java.lang.Thread.sleep(1);
+ continue;
+ }
+ /* Two times size then created pollset */
+ long [] desc = new long[64];
+ /* USe 1 second poll timeout */
+ int rv = Poll.poll(serverPollset, 1000000, desc, false);
+ if (rv > 0) {
+ for (int n = 0; n < rv; n++) {
+ long clientSock = desc[n*2+1];
+ System.out.println("Poll flags " + desc[n*2]);
+ remove(clientSock);
+ Worker worker = new Worker(clientSock, n,
+ this.getClass().getName());
+ Echo.incThreads();
+ worker.start();
+ }
+ }
+ else {
+ if (Status.APR_STATUS_IS_TIMEUP(-rv))
+ System.out.println("Timeup");
+ else {
+ System.out.println("Error " + (-rv));
+ }
+ }
+ }
+ /* XXX: JFC quick hack
+ catch(Error err ) {
+ if (Status.APR_STATUS_IS_TIMEUP(err.getError())) {
+ /0 TODO: deal with timeout 0/
+ }
+ else {
+ err.printStackTrace();
+ break;
+ }
+ }
+ */
+ catch( Exception ex ) {
+ ex.printStackTrace();
+ break;
+ }
+ }
+ }
+ }
+
+ private class Worker extends java.lang.Thread {
+ private int workerId = 0;
+ private long clientSock = 0;
+ private byte [] wellcomeMsg = null;
+ public Worker(long clientSocket, int workerId, String from) {
+ this.clientSock = clientSocket;
+ this.workerId = workerId;
+ wellcomeMsg = ("Echo server id: " + this.workerId + " from " +
+ from + "\r\n").getBytes();
+ }
+
+ public void run() {
+ boolean doClose = false;
+ try {
+ Socket.send(clientSock, wellcomeMsg, 0, wellcomeMsg.length);
+ /* Do a blocking read byte at a time */
+ byte [] buf = new byte[1];
+ while (Socket.recv(clientSock, buf, 0, 1) == 1) {
+ if (buf[0] == '\n')
+ break;
+ else if (buf[0] == '!') {
+ doClose = true;
+ break;
+ }
+ }
+ if (doClose) {
+ try {
+ byte [] msg = ("Bye from worker: " + workerId + "\r\n").getBytes();
+ Socket.send(clientSock, msg, 0, msg.length);
+ } catch(Exception e) { }
+
+ Socket.close(clientSock);
+ }
+ else {
+ try {
+ byte [] msg = ("Recycling worker: " + workerId + "\r\n").getBytes();
+ Socket.send(clientSock, msg, 0, msg.length);
+ } catch(Exception e) { }
+ /* Put the socket to the keep-alive poll */
+ Echo.echoPoller.add(clientSock);
+ }
+ } catch (Exception e) {
+ Socket.close(clientSock);
+ e.printStackTrace();
+ }
+ Echo.decThreads();
+ System.out.println("Worker: " + workerId + " finished");
+ }
+ }
+
+ public Echo()
+ {
+ echoPool = Pool.create(0);
+ try {
+ echoAcceptor = new Acceptor();
+ echoAcceptor.start();
+ echoPoller = new Poller();
+ echoPoller.start();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+
+ }
+
+ public static void incThreads() {
+ synchronized(threadLock) {
+ echoNrun++;
+ }
+ }
+
+ public static void decThreads() {
+ synchronized(threadLock) {
+ echoNrun--;
+ }
+ }
+
+ public static void main(String [] args) {
+ try {
+ Library.initialize(null);
+ long [] inf = new long[16];
+ System.out.println("Info ...");
+ System.out.println(" Native " + Library.versionString());
+ System.out.println(" APR " + Library.aprVersionString());
+ OS.info(inf);
+ System.out.println("OS Info ...");
+ System.out.println(" Physical " + inf[0]);
+ System.out.println(" Avail " + inf[1]);
+ System.out.println(" Swap " + inf[2]);
+ System.out.println(" Swap free " + inf[3]);
+ System.out.println(" Shared " + inf[4]);
+ System.out.println(" Buffers size " + inf[5]);
+ System.out.println(" Load " + inf[6]);
+
+ System.out.println(" Idle " + inf[7]);
+ System.out.println(" Kernel " + inf[8]);
+ System.out.println(" User " + inf[9]);
+
+ System.out.println(" Proc creation " + inf[10]);
+ System.out.println(" Proc kernel " + inf[11]);
+ System.out.println(" Proc user " + inf[12]);
+ System.out.println(" Curr working " + inf[13]);
+ System.out.println(" Peak working " + inf[14]);
+ System.out.println(" Page faults " + inf[15]);
+
+ SSL.initialize(null);
+ System.out.println("OpenSSL ...");
+ System.out.println(" version " + SSL.versionString());
+ System.out.println(" number " + SSL.version());
+
+ System.out.println("Starting Native Echo server example on port " +
+ echoAddr + ":" + echoPort);
+ Echo echo = new Echo();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+
+ }
+}
diff --git a/jni/examples/org/apache/tomcat/jni/Echo.properties b/jni/examples/org/apache/tomcat/jni/Echo.properties
new file mode 100644
index 0000000..34d7727
--- /dev/null
+++ b/jni/examples/org/apache/tomcat/jni/Echo.properties
@@ -0,0 +1,17 @@
+# 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.
+
+# Test port used for echo server
+echo.port=8023
diff --git a/jni/examples/org/apache/tomcat/jni/Local.properties b/jni/examples/org/apache/tomcat/jni/Local.properties
new file mode 100644
index 0000000..0551f98
--- /dev/null
+++ b/jni/examples/org/apache/tomcat/jni/Local.properties
@@ -0,0 +1,23 @@
+# 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.
+
+# Local properties
+local.max=10
+
+# For NT Pipes use something like
+local.path=\\\\.\\PIPE\\test
+
+# For Unix Sockets use
+# local.path=/tmp/testsock
diff --git a/jni/examples/org/apache/tomcat/jni/LocalServer.java b/jni/examples/org/apache/tomcat/jni/LocalServer.java
new file mode 100644
index 0000000..f9f80f5
--- /dev/null
+++ b/jni/examples/org/apache/tomcat/jni/LocalServer.java
@@ -0,0 +1,184 @@
+/*
+ * 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.
+ */
+package org.apache.tomcat.jni;
+
+import java.io.InputStream;
+import java.util.Properties;
+
+/** Local Socket server example
+ *
+ * @author Mladen Turk
+ * @version $Id: LocalServer.java 1442587 2013-02-05 13:49:48Z rjung $
+ */
+
+public class LocalServer {
+
+ public static String serverAddr = null;
+ public static int serverNmax = 0;
+ public static int serverNrun = 0;
+ public static long serverPool = 0;
+
+ private static Acceptor serverAcceptor = null;
+
+ private static Object threadLock = new Object();
+
+ static {
+
+ try {
+ InputStream is = LocalServer.class.getResourceAsStream
+ ("/org/apache/tomcat/jni/Local.properties");
+ Properties props = new Properties();
+ props.load(is);
+ is.close();
+ serverAddr = props.getProperty("local.path", null);
+ serverNmax = Integer.decode(props.getProperty("local.max", "0")).intValue();
+ }
+ catch (Throwable t) {
+ ; // Nothing
+ }
+ }
+
+ public LocalServer()
+ {
+ serverPool = Pool.create(0);
+ try {
+ serverAcceptor = new Acceptor();
+ serverAcceptor.start();
+
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+
+ }
+ public static void incThreads() {
+ synchronized(threadLock) {
+ serverNrun++;
+ }
+ }
+
+ public static void decThreads() {
+ synchronized(threadLock) {
+ serverNrun--;
+ }
+ }
+
+ /* Acceptor thread. Listens for new connections */
+ private class Acceptor extends java.lang.Thread {
+ private long serverSock = 0;
+ private long inetAddress = 0;
+ private long pool = 0;
+ public Acceptor() throws Exception {
+ try {
+
+ pool = Pool.create(LocalServer.serverPool);
+ System.out.println("Accepting: " + LocalServer.serverAddr);
+ serverSock = Local.create(LocalServer.serverAddr, pool);
+ int rc = Local.bind(serverSock, inetAddress);
+ if (rc != 0) {
+ throw(new Exception("Can't create Acceptor: bind: " + Error.strerror(rc)));
+ }
+ Local.listen(serverSock, LocalServer.serverNmax);
+ }
+ catch( Exception ex ) {
+ ex.printStackTrace();
+ throw(new Exception("Can't create Acceptor"));
+ }
+ }
+
+ public void run() {
+ int i = 0;
+ try {
+ while (true) {
+ long clientSock = Local.accept(serverSock);
+ System.out.println("Accepted id: " + i);
+
+ Socket.timeoutSet(clientSock, 10000000);
+ Worker worker = new Worker(clientSock, i++,
+ this.getClass().getName());
+ LocalServer.incThreads();
+ worker.start();
+ }
+ }
+ catch( Exception ex ) {
+ ex.printStackTrace();
+ }
+ }
+ }
+
+ private class Worker extends java.lang.Thread {
+ private int workerId = 0;
+ private long clientSock = 0;
+ private byte [] wellcomeMsg = null;
+
+ public Worker(long clientSocket, int workerId, String from) {
+ this.clientSock = clientSocket;
+ this.workerId = workerId;
+ wellcomeMsg = ("LocalServer server id: " + this.workerId + " from " +
+ from).getBytes();
+ }
+
+ public void run() {
+ boolean doClose = false;
+ try {
+ Socket.send(clientSock, wellcomeMsg, 0, wellcomeMsg.length);
+ while (!doClose) {
+ /* Do a blocking read byte at a time */
+ byte [] buf = new byte[1];
+ byte [] msg = new byte[256];
+ int p = 0;
+ while (Socket.recv(clientSock, buf, 0, 1) == 1) {
+ if (buf[0] == '\n')
+ break;
+ else if (buf[0] == '!') {
+ doClose = true;
+ break;
+ }
+ if (p > 250)
+ break;
+ msg[p++] = buf[0];
+ }
+ if (doClose) {
+ try {
+ byte [] snd = ("Bye from worker: " + workerId).getBytes();
+ Socket.send(clientSock, snd, 0, snd.length);
+ } catch(Exception e) { }
+
+ Socket.close(clientSock);
+ }
+ else
+ Socket.send(clientSock, msg, 0, p);
+ }
+ } catch (Exception e) {
+ Socket.destroy(clientSock);
+ e.printStackTrace();
+ }
+ LocalServer.decThreads();
+ System.out.println("Worker: " + workerId + " finished");
+ }
+ }
+
+
+ public static void main(String [] args) {
+ try {
+ Library.initialize(null);
+
+ LocalServer server = new LocalServer();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+ }
diff --git a/jni/examples/org/apache/tomcat/jni/SSL.properties b/jni/examples/org/apache/tomcat/jni/SSL.properties
new file mode 100644
index 0000000..1ecf411
--- /dev/null
+++ b/jni/examples/org/apache/tomcat/jni/SSL.properties
@@ -0,0 +1,22 @@
+# 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.
+
+# SSL Server and client properties
+server.port=4443
+server.cert=localhost.crt
+server.key=localhost.key
+server.password=secret
+server.ciphers=ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP:+eNULL
+server.verify=none
\ No newline at end of file
diff --git a/jni/examples/org/apache/tomcat/jni/SSLServer.java b/jni/examples/org/apache/tomcat/jni/SSLServer.java
new file mode 100644
index 0000000..5adbf10
--- /dev/null
+++ b/jni/examples/org/apache/tomcat/jni/SSLServer.java
@@ -0,0 +1,239 @@
+/*
+ * 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.
+ */
+package org.apache.tomcat.jni;
+
+import java.io.InputStream;
+import java.util.Properties;
+
+/** SSL Server server example
+ *
+ * @author Mladen Turk
+ * @version $Id: SSLServer.java 1442587 2013-02-05 13:49:48Z rjung $
+ */
+
+public class SSLServer {
+
+ public static String serverAddr = null;
+ public static int serverPort = 0;
+ public static int serverNmax = 0;
+ public static int serverNrun = 0;
+ public static long serverCtx = 0;
+ public static long serverPool = 0;
+ public static String serverCert = null;
+ public static String serverKey = null;
+ public static String serverCiphers = null;
+ public static String serverPassword = null;
+ public static String serverCAFile = null;
+
+ private static Acceptor serverAcceptor = null;
+
+ private static Object threadLock = new Object();
+
+ static {
+
+ try {
+ InputStream is = SSLServer.class.getResourceAsStream
+ ("/org/apache/tomcat/jni/SSL.properties");
+ Properties props = new Properties();
+ props.load(is);
+ is.close();
+ serverAddr = props.getProperty("server.ip", "127.0.0.1");
+ serverPort = Integer.decode(props.getProperty("server.port", "4443")).intValue();
+ serverNmax = Integer.decode(props.getProperty("server.max", "1")).intValue();
+ serverCert = props.getProperty("server.cert", "server.pem");
+ serverKey = props.getProperty("server.key", null);
+ serverCAFile = props.getProperty("server.cacertificate", null);
+ serverCiphers = props.getProperty("server.ciphers", "ALL");
+ serverPassword = props.getProperty("server.password", null);
+ }
+ catch (Throwable t) {
+ ; // Nothing
+ }
+ }
+
+ public SSLServer()
+ {
+ serverPool = Pool.create(0);
+ try {
+ /* Create SSL Context, one for each Virtual Host */
+ serverCtx = SSLContext.make(serverPool, SSL.SSL_PROTOCOL_SSLV2 | SSL.SSL_PROTOCOL_SSLV3, SSL.SSL_MODE_SERVER);
+ /* List the ciphers that the client is permitted to negotiate. */
+ SSLContext.setCipherSuite(serverCtx, serverCiphers);
+ /* Load Server key and certificate */
+ SSLContext.setCertificate(serverCtx, serverCert, serverKey, serverPassword, SSL.SSL_AIDX_RSA);
+ SSLContext.setVerify(serverCtx, SSL.SSL_CVERIFY_NONE, 10);
+ serverAcceptor = new Acceptor();
+ serverAcceptor.start();
+
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+
+ }
+ public static void incThreads() {
+ synchronized(threadLock) {
+ serverNrun++;
+ }
+ }
+
+ public static void decThreads() {
+ synchronized(threadLock) {
+ serverNrun--;
+ }
+ }
+
+ /* Acceptor thread. Listens for new connections */
+ private class Acceptor extends java.lang.Thread {
+ private long serverSock = 0;
+ private long inetAddress = 0;
+ private long pool = 0;
+ public Acceptor() throws Exception {
+ try {
+
+ pool = Pool.create(SSLServer.serverPool);
+ System.out.println("Accepting: " + SSLServer.serverAddr + ":" +
+ SSLServer.serverPort);
+ inetAddress = Address.info(SSLServer.serverAddr, Socket.APR_INET,
+ SSLServer.serverPort, 0,
+ pool);
+ serverSock = Socket.create(Socket.APR_INET, Socket.SOCK_STREAM,
+ Socket.APR_PROTO_TCP, pool);
+ int rc = Socket.bind(serverSock, inetAddress);
+ if (rc != 0) {
+ throw(new Exception("Can't create Acceptor: bind: " + Error.strerror(rc)));
+ }
+ Socket.listen(serverSock, 5);
+ }
+ catch( Exception ex ) {
+ ex.printStackTrace();
+ throw(new Exception("Can't create Acceptor"));
+ }
+ }
+
+ public void run() {
+ int i = 0;
+ try {
+ while (true) {
+ long clientSock = Socket.accept(serverSock);
+ System.out.println("Accepted id: " + i);
+
+ try {
+ long sa = Address.get(Socket.APR_REMOTE, clientSock);
+ Sockaddr raddr = new Sockaddr();
+ if (Address.fill(raddr, sa)) {
+ System.out.println("Remote Host: " + Address.getnameinfo(sa, 0));
+ System.out.println("Remote IP: " + Address.getip(sa) +
+ ":" + raddr.port);
+ }
+ sa = Address.get(Socket.APR_LOCAL, clientSock);
+ Sockaddr laddr = new Sockaddr();
+ if (Address.fill(laddr, sa)) {
+ System.out.println("Local Host: " + laddr.hostname);
+ System.out.println("Local Server: " + Address.getnameinfo(sa, 0));
+ System.out.println("Local IP: " + Address.getip(sa) +
+ ":" + laddr.port);
+ }
+
+ } catch (Exception e) {
+ // Ignore
+ e.printStackTrace();
+ }
+
+ Socket.timeoutSet(clientSock, 10000000);
+ SSLSocket.attach(SSLServer.serverCtx, clientSock);
+ i = SSLSocket.handshake(clientSock);
+ if (i == 0) {
+
+ Worker worker = new Worker(clientSock, i++,
+ this.getClass().getName());
+ SSLServer.incThreads();
+ worker.start();
+
+ }
+ else {
+ System.out.println("Handshake error: " + SSL.getLastError());
+ Socket.destroy(clientSock);
+ }
+ }
+ }
+ catch( Exception ex ) {
+ ex.printStackTrace();
+ }
+ }
+ }
+
+ private class Worker extends java.lang.Thread {
+ private int workerId = 0;
+ private long clientSock = 0;
+ private byte [] wellcomeMsg = null;
+
+ public Worker(long clientSocket, int workerId, String from) {
+ this.clientSock = clientSocket;
+ this.workerId = workerId;
+ wellcomeMsg = ("SSLServer server id: " + this.workerId + " from " +
+ from + "\r\n").getBytes();
+ }
+
+ public void run() {
+ boolean doClose = false;
+ try {
+ Socket.send(clientSock, wellcomeMsg, 0, wellcomeMsg.length);
+ while (!doClose) {
+ /* Do a blocking read byte at a time */
+ byte [] buf = new byte[1];
+ int ret;
+ ret = Socket.recv(clientSock, buf, 0, 1);
+ if (ret != 1)
+ throw(new Exception("Socket.recv failed"));
+
+ if (buf[0] == '\n')
+ continue;
+ else if (buf[0] == '!') {
+ doClose = true;
+ }
+ Socket.send(clientSock, buf, 0, 1);
+
+ if (doClose) {
+ try {
+ byte [] msg = ("Bye from worker: " + workerId + "\r\n").getBytes();
+ Socket.send(clientSock, msg, 0, msg.length);
+ } catch(Exception e) { }
+
+ Socket.close(clientSock);
+ }
+ }
+ } catch (Exception e) {
+ Socket.destroy(clientSock);
+ e.printStackTrace();
+ }
+ Echo.decThreads();
+ System.out.println("Worker: " + workerId + " finished");
+ }
+ }
+
+
+ public static void main(String [] args) {
+ try {
+ Library.initialize(null);
+ SSL.initialize(null);
+
+ SSLServer server = new SSLServer();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+ }
diff --git a/jni/java/org/apache/tomcat/Apr.java b/jni/java/org/apache/tomcat/Apr.java
new file mode 100644
index 0000000..53d5d06
--- /dev/null
+++ b/jni/java/org/apache/tomcat/Apr.java
@@ -0,0 +1,41 @@
+/*
+ * 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.
+ */
+
+
+package org.apache.tomcat;
+
+import java.io.InputStream;
+import java.util.Properties;
+
+public class Apr {
+ private static String aprInfo = null;
+
+ static {
+
+ try {
+ InputStream is = Apr.class.getResourceAsStream
+ ("/org/apache/tomcat/apr.properties");
+ Properties props = new Properties();
+ props.load(is);
+ is.close();
+ aprInfo = props.getProperty("tcn.info");
+ }
+ catch (Throwable t) {
+ ; // Nothing
+ }
+ }
+}
diff --git a/jni/java/org/apache/tomcat/apr.properties b/jni/java/org/apache/tomcat/apr.properties
new file mode 100644
index 0000000..4ac8c44
--- /dev/null
+++ b/jni/java/org/apache/tomcat/apr.properties
@@ -0,0 +1,16 @@
+# 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.
+
+tcn.info=Tomcat Native/@VERSION@
diff --git a/jni/java/org/apache/tomcat/jni/Address.java b/jni/java/org/apache/tomcat/jni/Address.java
new file mode 100644
index 0000000..d04be3b
--- /dev/null
+++ b/jni/java/org/apache/tomcat/jni/Address.java
@@ -0,0 +1,112 @@
+/*
+ * 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.
+ */
+
+package org.apache.tomcat.jni;
+
+/** Address
+ *
+ * @author Mladen Turk
+ */
+public class Address {
+
+ public static final String APR_ANYADDR = "0.0.0.0";
+ /**
+ * Fill the Sockaddr class from apr_sockaddr_t
+ * @param info Sockaddr class to fill
+ * @param sa Structure pointer
+ */
+ public static native boolean fill(Sockaddr info, long sa);
+
+ /**
+ * Create the Sockaddr object from apr_sockaddr_t
+ * @param sa Structure pointer
+ */
+ public static native Sockaddr getInfo(long sa);
+
+ /**
+ * Create apr_sockaddr_t from hostname, address family, and port.
+ * @param hostname The hostname or numeric address string to resolve/parse, or
+ * NULL to build an address that corresponds to 0.0.0.0 or ::
+ * @param family The address family to use, or APR_UNSPEC if the system should
+ * decide.
+ * @param port The port number.
+ * @param flags Special processing flags:
+ * <PRE>
+ * APR_IPV4_ADDR_OK first query for IPv4 addresses; only look
+ * for IPv6 addresses if the first query failed;
+ * only valid if family is APR_UNSPEC and hostname
+ * isn't NULL; mutually exclusive with
+ * APR_IPV6_ADDR_OK
+ * APR_IPV6_ADDR_OK first query for IPv6 addresses; only look
+ * for IPv4 addresses if the first query failed;
+ * only valid if family is APR_UNSPEC and hostname
+ * isn't NULL and APR_HAVE_IPV6; mutually exclusive
+ * with APR_IPV4_ADDR_OK
+ * </PRE>
+ * @param p The pool for the apr_sockaddr_t and associated storage.
+ * @return The new apr_sockaddr_t.
+ */
+ public static native long info(String hostname, int family,
+ int port, int flags, long p)
+ throws Exception;
+ /**
+ * Look up the host name from an apr_sockaddr_t.
+ * @param sa The apr_sockaddr_t.
+ * @param flags Special processing flags.
+ * @return The hostname.
+ */
+ public static native String getnameinfo(long sa, int flags);
+
+ /**
+ * Return the IP address (in numeric address string format) in
+ * an APR socket address. APR will allocate storage for the IP address
+ * string from the pool of the apr_sockaddr_t.
+ * @param sa The socket address to reference.
+ * @return The IP address.
+ */
+ public static native String getip(long sa);
+
+ /**
+ * Given an apr_sockaddr_t and a service name, set the port for the service
+ * @param sockaddr The apr_sockaddr_t that will have its port set
+ * @param servname The name of the service you wish to use
+ * @return APR status code.
+ */
+ public static native int getservbyname(long sockaddr, String servname);
+
+ /**
+ * Return an apr_sockaddr_t from an apr_socket_t
+ * @param which Which interface do we want the apr_sockaddr_t for?
+ * @param sock The socket to use
+ * @return The returned apr_sockaddr_t.
+ */
+ public static native long get(int which, long sock)
+ throws Exception;
+
+ /**
+ * See if the IP addresses in two APR socket addresses are
+ * equivalent. Appropriate logic is present for comparing
+ * IPv4-mapped IPv6 addresses with IPv4 addresses.
+ *
+ * @param a One of the APR socket addresses.
+ * @param b The other APR socket address.
+ * The return value will be True if the addresses
+ * are equivalent.
+ */
+ public static native boolean equal(long a, long b);
+
+}
diff --git a/jni/java/org/apache/tomcat/jni/BIOCallback.java b/jni/java/org/apache/tomcat/jni/BIOCallback.java
new file mode 100644
index 0000000..ee13c70
--- /dev/null
+++ b/jni/java/org/apache/tomcat/jni/BIOCallback.java
@@ -0,0 +1,54 @@
+/*
+ * 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.
+ */
+
+package org.apache.tomcat.jni;
+
+/** Open SSL BIO Callback Interface
+ *
+ * @author Mladen Turk
+ */
+public interface BIOCallback {
+
+ /**
+ * Write data
+ * @param buf containing the bytes to write.
+ * @return Number of characters written.
+ */
+ public int write(byte [] buf);
+
+ /**
+ * Read data
+ * @param buf buffer to store the read bytes.
+ * @return number of bytes read.
+ */
+ public int read(byte [] buf);
+
+ /**
+ * Puts string
+ * @param data String to write
+ * @return Number of characters written
+ */
+ public int puts(String data);
+
+ /**
+ * Read string up to the len or CLRLF
+ * @param len Maximum number of characters to read
+ * @return String with up to len bytes read
+ */
+ public String gets(int len);
+
+}
diff --git a/jni/java/org/apache/tomcat/jni/Buffer.java b/jni/java/org/apache/tomcat/jni/Buffer.java
new file mode 100644
index 0000000..3a26d5f
--- /dev/null
+++ b/jni/java/org/apache/tomcat/jni/Buffer.java
@@ -0,0 +1,89 @@
+/*
+ * 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.
+ */
+
+package org.apache.tomcat.jni;
+
+import java.nio.ByteBuffer;
+
+/** Buffer
+ *
+ * @author Mladen Turk
+ */
+public class Buffer {
+
+ /**
+ * Allocate a new ByteBuffer from memory
+ * @param size The amount of memory to allocate
+ * @return The ByteBuffer with allocated memory
+ */
+ public static native ByteBuffer malloc(int size);
+
+ /**
+ * Allocate a new ByteBuffer from memory and set all of the memory to 0
+ * @param num Number of elements.
+ * @param size Length in bytes of each element.
+ * @return The ByteBuffer with allocated memory
+ */
+ public static native ByteBuffer calloc(int num, int size);
+
+ /**
+ * Allocate a new ByteBuffer from a pool
+ * @param p The pool to allocate from
+ * @param size The amount of memory to allocate
+ * @return The ByteBuffer with allocated memory
+ */
+ public static native ByteBuffer palloc(long p, int size);
+
+ /**
+ * Allocate a new ByteBuffer from a pool and set all of the memory to 0
+ * @param p The pool to allocate from
+ * @param size The amount of memory to allocate
+ * @return The ByteBuffer with allocated memory
+ */
+ public static native ByteBuffer pcalloc(long p, int size);
+
+ /**
+ * Allocate a new ByteBuffer from already allocated memory.
+ * <br />Allocated memory must be provided from call to the
+ * Stdlib.alloc or Stdlib.calloc methods.
+ * @param mem The memory to use
+ * @param size The amount of memory to use
+ * @return The ByteBuffer with attached memory
+ */
+ public static native ByteBuffer create(long mem, int size);
+
+ /**
+ * Deallocates or frees a memory block used by ByteBuffer
+ * <br /><b>Warning :</b> Call this method only on ByteBuffers
+ * that were created by calling Buffer.alloc or Buffer.calloc.
+ * @param buf Previously allocated ByteBuffer to be freed.
+ */
+ public static native void free(ByteBuffer buf);
+
+ /**
+ * Returns the memory address of the ByteBuffer.
+ * @param buf Previously allocated ByteBuffer.
+ */
+ public static native long address(ByteBuffer buf);
+
+ /**
+ * Returns the allocated memory size of the ByteBuffer.
+ * @param buf Previously allocated ByteBuffer.
+ */
+ public static native long size(ByteBuffer buf);
+
+}
diff --git a/jni/java/org/apache/tomcat/jni/Directory.java b/jni/java/org/apache/tomcat/jni/Directory.java
new file mode 100644
index 0000000..7c2de6e
--- /dev/null
+++ b/jni/java/org/apache/tomcat/jni/Directory.java
@@ -0,0 +1,95 @@
+/*
+ * 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.
+ */
+
+package org.apache.tomcat.jni;
+
+/** Directory
+ *
+ * @author Mladen Turk
+ */
+public class Directory {
+
+ /**
+ * Create a new directory on the file system.
+ * @param path the path for the directory to be created. (use / on all systems)
+ * @param perm Permissions for the new directory.
+ * @param pool the pool to use.
+ */
+ public static native int make(String path, int perm, long pool);
+
+ /** Creates a new directory on the file system, but behaves like
+ * 'mkdir -p'. Creates intermediate directories as required. No error
+ * will be reported if PATH already exists.
+ * @param path the path for the directory to be created. (use / on all systems)
+ * @param perm Permissions for the new directory.
+ * @param pool the pool to use.
+ */
+ public static native int makeRecursive(String path, int perm, long pool);
+
+ /**
+ * Remove directory from the file system.
+ * @param path the path for the directory to be removed. (use / on all systems)
+ * @param pool the pool to use.
+ */
+ public static native int remove(String path, long pool);
+
+ /**
+ * Find an existing directory suitable as a temporary storage location.
+ * @param pool The pool to use for any necessary allocations.
+ * @return The temp directory.
+ *
+ * This function uses an algorithm to search for a directory that an
+ * an application can use for temporary storage. Once such a
+ * directory is found, that location is cached by the library. Thus,
+ * callers only pay the cost of this algorithm once if that one time
+ * is successful.
+ *
+ */
+ public static native String tempGet(long pool);
+
+ /**
+ * Open the specified directory.
+ * @param dirname The full path to the directory (use / on all systems)
+ * @param pool The pool to use.
+ * @return The opened directory descriptor.
+ */
+ public static native long open(String dirname, long pool)
+ throws Error;
+
+ /**
+ * close the specified directory.
+ * @param thedir the directory descriptor to close.
+ */
+ public static native int close(long thedir);
+
+ /**
+ * Rewind the directory to the first entry.
+ * @param thedir the directory descriptor to rewind.
+ */
+ public static native int rewind(long thedir);
+
+
+ /**
+ * Read the next entry from the specified directory.
+ * @param finfo the file info structure and filled in by apr_dir_read
+ * @param wanted The desired apr_finfo_t fields, as a bit flag of APR_FINFO_ values
+ * @param thedir the directory descriptor returned from apr_dir_open
+ * No ordering is guaranteed for the entries read.
+ */
+ public static native int read(FileInfo finfo, int wanted, long thedir);
+
+}
diff --git a/jni/java/org/apache/tomcat/jni/Error.java b/jni/java/org/apache/tomcat/jni/Error.java
new file mode 100644
index 0000000..d543258
--- /dev/null
+++ b/jni/java/org/apache/tomcat/jni/Error.java
@@ -0,0 +1,96 @@
+/*
+ * 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.
+ */
+
+package org.apache.tomcat.jni;
+
+/** Error
+ *
+ * @author Mladen Turk
+ */
+public class Error extends Exception {
+
+ private static final long serialVersionUID = 1L;
+
+ /**
+ * APR error type.
+ */
+ private final int error;
+
+ /**
+ * A description of the problem.
+ */
+ private final String description;
+
+ /**
+ * Construct an APRException.
+ *
+ * @param error one of the value in Error
+ * @param description error message
+ */
+ private Error(int error, String description)
+ {
+ super(error + ": " + description);
+ this.error = error;
+ this.description = description;
+ }
+
+ /**
+ * Get the APR error code of the exception.
+ *
+ * @return error of the Exception
+ */
+ public int getError()
+ {
+ return error;
+ }
+
+ /**
+ * Get the APR description of the exception.
+ *
+ * @return description of the Exception
+ */
+ public String getDescription()
+ {
+ return description;
+ }
+
+ /**
+ * Get the last platform error.
+ * @return apr_status_t the last platform error, folded into apr_status_t, on most platforms
+ * This retrieves errno, or calls a GetLastError() style function, and
+ * folds it with APR_FROM_OS_ERROR. Some platforms (such as OS2) have no
+ * such mechanism, so this call may be unsupported. Do NOT use this
+ * call for socket errors from socket, send, recv etc!
+ */
+ public static native int osError();
+
+ /**
+ * Get the last platform socket error.
+ * @return the last socket error, folded into apr_status_t, on all platforms
+ * This retrieves errno or calls a GetLastSocketError() style function,
+ * and folds it with APR_FROM_OS_ERROR.
+ */
+ public static native int netosError();
+
+ /**
+ * Return a human readable string describing the specified error.
+ * @param statcode The error code the get a string for.
+ * @return The error string.
+ */
+ public static native String strerror(int statcode);
+
+}
diff --git a/jni/java/org/apache/tomcat/jni/File.java b/jni/java/org/apache/tomcat/jni/File.java
new file mode 100644
index 0000000..eacf6b2
--- /dev/null
+++ b/jni/java/org/apache/tomcat/jni/File.java
@@ -0,0 +1,721 @@
+/*
+ * 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.
+ */
+
+package org.apache.tomcat.jni;
+/* Import needed classes */
+import java.nio.ByteBuffer;
+
+/** File
+ *
+ * @author Mladen Turk
+ */
+public class File {
+
+ /** Open the file for reading */
+ public static final int APR_FOPEN_READ = 0x00001;
+ /** Open the file for writing */
+ public static final int APR_FOPEN_WRITE = 0x00002;
+ /** Create the file if not there */
+ public static final int APR_FOPEN_CREATE = 0x00004;
+ /** Append to the end of the file */
+ public static final int APR_FOPEN_APPEND = 0x00008;
+ /** Open the file and truncate to 0 length */
+ public static final int APR_FOPEN_TRUNCATE = 0x00010;
+ /** Open the file in binary mode */
+ public static final int APR_FOPEN_BINARY = 0x00020;
+ /** Open should fail if APR_CREATE and file exists. */
+ public static final int APR_FOPEN_EXCL = 0x00040;
+ /** Open the file for buffered I/O */
+ public static final int APR_FOPEN_BUFFERED = 0x00080;
+ /** Delete the file after close */
+ public static final int APR_FOPEN_DELONCLOSE = 0x00100;
+ /** Platform dependent tag to open the file for
+ * use across multiple threads
+ */
+ public static final int APR_FOPEN_XTHREAD = 0x00200;
+ /** Platform dependent support for higher level locked read/write
+ * access to support writes across process/machines
+ */
+ public static final int APR_FOPEN_SHARELOCK = 0x00400;
+ /** Do not register a cleanup when the file is opened */
+ public static final int APR_FOPEN_NOCLEANUP = 0x00800;
+ /** Advisory flag that this file should support
+ * apr_socket_sendfile operation
+ */
+ public static final int APR_FOPEN_SENDFILE_ENABLED = 0x01000;
+ /** Platform dependent flag to enable large file support;
+ * <br /><b>Warning :</b> The APR_LARGEFILE flag only has effect on some platforms
+ * where sizeof(apr_off_t) == 4. Where implemented, it allows opening
+ * and writing to a file which exceeds the size which can be
+ * represented by apr_off_t (2 gigabytes). When a file's size does
+ * exceed 2Gb, apr_file_info_get() will fail with an error on the
+ * descriptor, likewise apr_stat()/apr_lstat() will fail on the
+ * filename. apr_dir_read() will fail with APR_INCOMPLETE on a
+ * directory entry for a large file depending on the particular
+ * APR_FINFO_* flags. Generally, it is not recommended to use this
+ * flag.
+ */
+ public static final int APR_FOPEN_LARGEFILE = 0x04000;
+
+ /** Set the file position */
+ public static final int APR_SET = 0;
+ /** Current */
+ public static final int APR_CUR = 1;
+ /** Go to end of file */
+ public static final int APR_END = 2;
+
+ /* flags for apr_file_attrs_set */
+
+ /** File is read-only */
+ public static final int APR_FILE_ATTR_READONLY = 0x01;
+ /** File is executable */
+ public static final int APR_FILE_ATTR_EXECUTABLE = 0x02;
+ /** File is hidden */
+ public static final int APR_FILE_ATTR_HIDDEN = 0x04;
+
+
+ /* File lock types/flags */
+
+ /** Shared lock. More than one process or thread can hold a shared lock
+ * at any given time. Essentially, this is a "read lock", preventing
+ * writers from establishing an exclusive lock.
+ */
+ public static final int APR_FLOCK_SHARED = 1;
+
+ /** Exclusive lock. Only one process may hold an exclusive lock at any
+ * given time. This is analogous to a "write lock".
+ */
+ public static final int APR_FLOCK_EXCLUSIVE = 2;
+ /** mask to extract lock type */
+ public static final int APR_FLOCK_TYPEMASK = 0x000F;
+ /** do not block while acquiring the file lock */
+ public static final int APR_FLOCK_NONBLOCK = 0x0010;
+
+ /* apr_filetype_e values for the filetype member of the
+ * apr_file_info_t structure
+ * <br /><b>Warning :</b>: Not all of the filetypes below can be determined.
+ * For example, a given platform might not correctly report
+ * a socket descriptor as APR_SOCK if that type isn't
+ * well-identified on that platform. In such cases where
+ * a filetype exists but cannot be described by the recognized
+ * flags below, the filetype will be APR_UNKFILE. If the
+ * filetype member is not determined, the type will be APR_NOFILE.
+ */
+
+ /** no file type determined */
+ public static final int APR_NOFILE = 0;
+ /** a regular file */
+ public static final int APR_REG = 1;
+ /** a directory */
+ public static final int APR_DIR = 2;
+ /** a character device */
+ public static final int APR_CHR = 3;
+ /** a block device */
+ public static final int APR_BLK = 4;
+ /** a FIFO / pipe */
+ public static final int APR_PIPE = 5;
+ /** a symbolic link */
+ public static final int APR_LNK = 6;
+ /** a [unix domain] socket */
+ public static final int APR_SOCK = 7;
+ /** a file of some other unknown type */
+ public static final int APR_UNKFILE = 127;
+
+
+ /*
+ * apr_file_permissions File Permissions flags
+ */
+
+ public static final int APR_FPROT_USETID = 0x8000; /** Set user id */
+ public static final int APR_FPROT_UREAD = 0x0400; /** Read by user */
+ public static final int APR_FPROT_UWRITE = 0x0200; /** Write by user */
+ public static final int APR_FPROT_UEXECUTE = 0x0100; /** Execute by user */
+
+ public static final int APR_FPROT_GSETID = 0x4000; /** Set group id */
+ public static final int APR_FPROT_GREAD = 0x0040; /** Read by group */
+ public static final int APR_FPROT_GWRITE = 0x0020; /** Write by group */
+ public static final int APR_FPROT_GEXECUTE = 0x0010; /** Execute by group */
+
+ public static final int APR_FPROT_WSTICKY = 0x2000; /** Sticky bit */
+ public static final int APR_FPROT_WREAD = 0x0004; /** Read by others */
+ public static final int APR_FPROT_WWRITE = 0x0002; /** Write by others */
+ public static final int APR_FPROT_WEXECUTE = 0x0001; /** Execute by others */
+ public static final int APR_FPROT_OS_DEFAULT = 0x0FFF; /** use OS's default permissions */
+
+
+ public static final int APR_FINFO_LINK = 0x00000001; /** Stat the link not the file itself if it is a link */
+ public static final int APR_FINFO_MTIME = 0x00000010; /** Modification Time */
+ public static final int APR_FINFO_CTIME = 0x00000020; /** Creation or inode-changed time */
+ public static final int APR_FINFO_ATIME = 0x00000040; /** Access Time */
+ public static final int APR_FINFO_SIZE = 0x00000100; /** Size of the file */
+ public static final int APR_FINFO_CSIZE = 0x00000200; /** Storage size consumed by the file */
+ public static final int APR_FINFO_DEV = 0x00001000; /** Device */
+ public static final int APR_FINFO_INODE = 0x00002000; /** Inode */
+ public static final int APR_FINFO_NLINK = 0x00004000; /** Number of links */
+ public static final int APR_FINFO_TYPE = 0x00008000; /** Type */
+ public static final int APR_FINFO_USER = 0x00010000; /** User */
+ public static final int APR_FINFO_GROUP = 0x00020000; /** Group */
+ public static final int APR_FINFO_UPROT = 0x00100000; /** User protection bits */
+ public static final int APR_FINFO_GPROT = 0x00200000; /** Group protection bits */
+ public static final int APR_FINFO_WPROT = 0x00400000; /** World protection bits */
+ public static final int APR_FINFO_ICASE = 0x01000000; /** if dev is case insensitive */
+ public static final int APR_FINFO_NAME = 0x02000000; /** ->name in proper case */
+
+ public static final int APR_FINFO_MIN = 0x00008170; /** type, mtime, ctime, atime, size */
+ public static final int APR_FINFO_IDENT = 0x00003000; /** dev and inode */
+ public static final int APR_FINFO_OWNER = 0x00030000; /** user and group */
+ public static final int APR_FINFO_PROT = 0x00700000; /** all protections */
+ public static final int APR_FINFO_NORM = 0x0073b170; /** an atomic unix apr_stat() */
+ public static final int APR_FINFO_DIRENT = 0x02000000; /** an atomic unix apr_dir_read() */
+
+
+
+ /**
+ * Open the specified file.
+ * @param fname The full path to the file (using / on all systems)
+ * @param flag Or'ed value of:
+ * <PRE>
+ * APR_FOPEN_READ open for reading
+ * APR_FOPEN_WRITE open for writing
+ * APR_FOPEN_CREATE create the file if not there
+ * APR_FOPEN_APPEND file ptr is set to end prior to all writes
+ * APR_FOPEN_TRUNCATE set length to zero if file exists
+ * APR_FOPEN_BINARY not a text file (This flag is ignored on
+ * UNIX because it has no meaning)
+ * APR_FOPEN_BUFFERED buffer the data. Default is non-buffered
+ * APR_FOPEN_EXCL return error if APR_CREATE and file exists
+ * APR_FOPEN_DELONCLOSE delete the file after closing.
+ * APR_FOPEN_XTHREAD Platform dependent tag to open the file
+ * for use across multiple threads
+ * APR_FOPEN_SHARELOCK Platform dependent support for higher
+ * level locked read/write access to support
+ * writes across process/machines
+ * APR_FOPEN_NOCLEANUP Do not register a cleanup with the pool
+ * passed in on the <EM>pool</EM> argument (see below).
+ * The apr_os_file_t handle in apr_file_t will not
+ * be closed when the pool is destroyed.
+ * APR_FOPEN_SENDFILE_ENABLED Open with appropriate platform semantics
+ * for sendfile operations. Advisory only,
+ * apr_socket_sendfile does not check this flag.
+ * </PRE>
+ * @param perm Access permissions for file.
+ * @param pool The pool to use.
+ * If perm is APR_OS_DEFAULT and the file is being created,
+ * appropriate default permissions will be used.
+ * @return The opened file descriptor.
+ */
+ public static native long open(String fname, int flag, int perm, long pool)
+ throws Error;
+
+ /**
+ * Close the specified file.
+ * @param file The file descriptor to close.
+ */
+ public static native int close(long file);
+
+ /**
+ * Flush the file's buffer.
+ * @param thefile The file descriptor to flush
+ */
+ public static native int flush(long thefile);
+
+ /**
+ * Open a temporary file
+ * @param templ The template to use when creating a temp file.
+ * @param flags The flags to open the file with. If this is zero,
+ * the file is opened with
+ * APR_CREATE | APR_READ | APR_WRITE | APR_EXCL | APR_DELONCLOSE
+ * @param pool The pool to allocate the file out of.
+ * @return The apr file to use as a temporary file.
+ *
+ * This function generates a unique temporary file name from template.
+ * The last six characters of template must be XXXXXX and these are replaced
+ * with a string that makes the filename unique. Since it will be modified,
+ * template must not be a string constant, but should be declared as a character
+ * array.
+ *
+ */
+ public static native long mktemp(String templ, int flags, long pool)
+ throws Error;
+
+ /**
+ * Delete the specified file.
+ * @param path The full path to the file (using / on all systems)
+ * @param pool The pool to use.
+ * If the file is open, it won't be removed until all
+ * instances are closed.
+ */
+ public static native int remove(String path, long pool);
+
+ /**
+ * Rename the specified file.
+ * <br /><b>Warning :</b> If a file exists at the new location, then it will be
+ * overwritten. Moving files or directories across devices may not be
+ * possible.
+ * @param fromPath The full path to the original file (using / on all systems)
+ * @param toPath The full path to the new file (using / on all systems)
+ * @param pool The pool to use.
+ */
+ public static native int rename(String fromPath, String toPath, long pool);
+
+ /**
+ * Copy the specified file to another file.
+ * The new file does not need to exist, it will be created if required.
+ * <br /><b>Warning :</b> If the new file already exists, its contents will be overwritten.
+ * @param fromPath The full path to the original file (using / on all systems)
+ * @param toPath The full path to the new file (using / on all systems)
+ * @param perms Access permissions for the new file if it is created.
+ * In place of the usual or'd combination of file permissions, the
+ * value APR_FILE_SOURCE_PERMS may be given, in which case the source
+ * file's permissions are copied.
+ * @param pool The pool to use.
+ */
+ public static native int copy(String fromPath, String toPath, int perms, long pool);
+
+ /**
+ * Append the specified file to another file.
+ * The new file does not need to exist, it will be created if required.
+ * @param fromPath The full path to the source file (use / on all systems)
+ * @param toPath The full path to the destination file (use / on all systems)
+ * @param perms Access permissions for the destination file if it is created.
+ * In place of the usual or'd combination of file permissions, the
+ * value APR_FILE_SOURCE_PERMS may be given, in which case the source
+ * file's permissions are copied.
+ * @param pool The pool to use.
+ */
+ public static native int append(String fromPath, String toPath, int perms, long pool);
+
+ /**
+ * Write the string into the specified file.
+ * @param str The string to write. Must be NUL terminated!
+ * @param thefile The file descriptor to write to
+ */
+ public static native int puts(byte [] str, long thefile);
+
+ /**
+ * Move the read/write file offset to a specified byte within a file.
+ * @param thefile The file descriptor
+ * @param where How to move the pointer, one of:
+ * <PRE>
+ * APR_SET -- set the offset to offset
+ * APR_CUR -- add the offset to the current position
+ * APR_END -- add the offset to the current file size
+ * </PRE>
+ * @param offset The offset to move the pointer to.
+ * @return Offset the pointer was actually moved to.
+ */
+ public static native long seek(long thefile, int where, long offset)
+ throws Error;
+
+ /**
+ * Write a character into the specified file.
+ * @param ch The character to write.
+ * @param thefile The file descriptor to write to
+ */
+ public static native int putc(byte ch, long thefile);
+
+ /**
+ * Put a character back onto a specified stream.
+ * @param ch The character to write.
+ * @param thefile The file descriptor to write to
+ */
+ public static native int ungetc(byte ch, long thefile);
+
+ /**
+ * Write data to the specified file.
+ *
+ * Write will write up to the specified number of
+ * bytes, but never more. If the OS cannot write that many bytes, it
+ * will write as many as it can. The third argument is modified to
+ * reflect the * number of bytes written.
+ *
+ * It is possible for both bytes to be written and an error to
+ * be returned. APR_EINTR is never returned.
+ * @param thefile The file descriptor to write to.
+ * @param buf The buffer which contains the data.
+ * @param offset Start offset in buf
+ * @param nbytes The number of bytes to write; (-1) for full array.
+ * @return The number of bytes written.
+ */
+ public static native int write(long thefile, byte[] buf, int offset, int nbytes);
+
+ /**
+ * Write data to the specified file.
+ *
+ * Write will write up to the specified number of
+ * bytes, but never more. If the OS cannot write that many bytes, it
+ * will write as many as it can. The third argument is modified to
+ * reflect the * number of bytes written.
+ *
+ * It is possible for both bytes to be written and an error to
+ * be returned. APR_EINTR is never returned.
+ * @param thefile The file descriptor to write to.
+ * @param buf The direct Byte buffer which contains the data.
+ * @param offset Start offset in buf
+ * @param nbytes The number of bytes to write
+ * @return The number of bytes written.
+ */
+ public static native int writeb(long thefile, ByteBuffer buf, int offset, int nbytes);
+
+ /**
+ * Write data to the specified file, ensuring that all of the data is
+ * written before returning.
+ *
+ * Write will write up to the specified number of
+ * bytes, but never more. If the OS cannot write that many bytes, the
+ * process/thread will block until they can be written. Exceptional
+ * error such as "out of space" or "pipe closed" will terminate with
+ * an error.
+ *
+ * It is possible for both bytes to be written and an error to
+ * be returned. And if *bytes_written is less than nbytes, an
+ * accompanying error is _always_ returned.
+ *
+ * APR_EINTR is never returned.
+ * @param thefile The file descriptor to write to.
+ * @param buf The buffer which contains the data.
+ * @param offset Start offset in buf
+ * @param nbytes The number of bytes to write; (-1) for full array.
+ * @return The number of bytes written.
+ */
+ public static native int writeFull(long thefile, byte[] buf, int offset, int nbytes);
+
+ /**
+ * Write data to the specified file, ensuring that all of the data is
+ * written before returning.
+ *
+ * Write will write up to the specified number of
+ * bytes, but never more. If the OS cannot write that many bytes, the
+ * process/thread will block until they can be written. Exceptional
+ * error such as "out of space" or "pipe closed" will terminate with
+ * an error.
+ *
+ * It is possible for both bytes to be written and an error to
+ * be returned. And if *bytes_written is less than nbytes, an
+ * accompanying error is _always_ returned.
+ *
+ * APR_EINTR is never returned.
+ * @param thefile The file descriptor to write to.
+ * @param buf The direct ByteBuffer which contains the data.
+ * @param offset Start offset in buf
+ * @param nbytes The number of bytes to write.
+ * @return The number of bytes written.
+ */
+ public static native int writeFullb(long thefile, ByteBuffer buf, int offset, int nbytes);
+
+ /**
+ * Write data from array of byte arrays to the specified file.
+ *
+ * It is possible for both bytes to be written and an error to
+ * be returned. APR_EINTR is never returned.
+ *
+ * apr_file_writev is available even if the underlying
+ * operating system doesn't provide writev().
+ * @param thefile The file descriptor to write to.
+ * @param vec The array from which to get the data to write to the file.
+ * @return The number of bytes written.
+ */
+ public static native int writev(long thefile, byte[][] vec);
+
+ /**
+ * Write data from array of byte arrays to the specified file,
+ * ensuring that all of the data is written before returning.
+ *
+ * writevFull is available even if the underlying
+ * operating system doesn't provide writev().
+ * @param thefile The file descriptor to write to.
+ * @param vec The array from which to get the data to write to the file.
+ * @return The number of bytes written.
+ */
+ public static native int writevFull(long thefile, byte[][] vec);
+
+ /**
+ * Read data from the specified file.
+ *
+ * apr_file_read will read up to the specified number of
+ * bytes, but never more. If there isn't enough data to fill that
+ * number of bytes, all of the available data is read. The third
+ * argument is modified to reflect the number of bytes read. If a
+ * char was put back into the stream via ungetc, it will be the first
+ * character returned.
+ *
+ * It is not possible for both bytes to be read and an APR_EOF
+ * or other error to be returned. APR_EINTR is never returned.
+ * @param thefile The file descriptor to read from.
+ * @param buf The buffer to store the data to.
+ * @param offset Start offset in buf
+ * @param nbytes The number of bytes to read (-1) for full array.
+ * @return the number of bytes read.
+ */
+ public static native int read(long thefile, byte[] buf, int offset, int nbytes);
+
+ /**
+ * Read data from the specified file.
+ *
+ * apr_file_read will read up to the specified number of
+ * bytes, but never more. If there isn't enough data to fill that
+ * number of bytes, all of the available data is read. The third
+ * argument is modified to reflect the number of bytes read. If a
+ * char was put back into the stream via ungetc, it will be the first
+ * character returned.
+ *
+ * It is not possible for both bytes to be read and an APR_EOF
+ * or other error to be returned. APR_EINTR is never returned.
+ * @param thefile The file descriptor to read from.
+ * @param buf The direct Byte buffer to store the data to.
+ * @param offset Start offset in buf
+ * @param nbytes The number of bytes to read.
+ * @return the number of bytes read.
+ */
+ public static native int readb(long thefile, ByteBuffer buf, int offset, int nbytes);
+
+ /**
+ * Read data from the specified file, ensuring that the buffer is filled
+ * before returning.
+ *
+ * Read will read up to the specified number of
+ * bytes, but never more. If there isn't enough data to fill that
+ * number of bytes, then the process/thread will block until it is
+ * available or EOF is reached. If a char was put back into the
+ * stream via ungetc, it will be the first character returned.
+ *
+ * It is possible for both bytes to be read and an error to be
+ * returned. And if *bytes_read is less than nbytes, an accompanying
+ * error is _always_ returned.
+ *
+ * APR_EINTR is never returned.
+ * @param thefile The file descriptor to read from.
+ * @param buf The buffer to store the data to.
+ * @param offset Start offset in buf
+ * @param nbytes The number of bytes to read (-1) for full array.
+ * @return the number of bytes read.
+ */
+ public static native int readFull(long thefile, byte[] buf, int offset, int nbytes);
+
+ /**
+ * Read data from the specified file, ensuring that the buffer is filled
+ * before returning.
+ *
+ * Read will read up to the specified number of
+ * bytes, but never more. If there isn't enough data to fill that
+ * number of bytes, then the process/thread will block until it is
+ * available or EOF is reached. If a char was put back into the
+ * stream via ungetc, it will be the first character returned.
+ *
+ * It is possible for both bytes to be read and an error to be
+ * returned. And if *bytes_read is less than nbytes, an accompanying
+ * error is _always_ returned.
+ *
+ * APR_EINTR is never returned.
+ * @param thefile The file descriptor to read from.
+ * @param buf The direct ByteBuffer to store the data to.
+ * @param offset Start offset in buf
+ * @param nbytes The number of bytes to read.
+ * @return the number of bytes read.
+ */
+ public static native int readFullb(long thefile, ByteBuffer buf, int offset, int nbytes);
+
+ /**
+ * Read a string from the specified file.
+ * The buffer will be NUL-terminated if any characters are stored.
+ * @param buf The buffer to store the string in.
+ * @param offset Start offset in buf
+ * @param thefile The file descriptor to read from
+ */
+ public static native int gets(byte[] buf, int offset, long thefile);
+
+
+ /**
+ * Read a character from the specified file.
+ * @param thefile The file descriptor to read from
+ * @return The read character
+ */
+ public static native int getc(long thefile)
+ throws Error;
+
+ /**
+ * Are we at the end of the file
+ * @param fptr The apr file we are testing.
+ * @return Returns APR_EOF if we are at the end of file, APR_SUCCESS otherwise.
+ */
+ public static native int eof(long fptr);
+
+ /**
+ * return the file name of the current file.
+ * @param thefile The currently open file.
+ */
+ public static native String nameGet(long thefile);
+
+ /**
+ * Set the specified file's permission bits.
+ * <br /><b>Warning :</b> Some platforms may not be able to apply all of the
+ * available permission bits; APR_INCOMPLETE will be returned if some
+ * permissions are specified which could not be set.
+ * <br /><b>Warning :</b> Platforms which do not implement this feature will return
+ * APR_ENOTIMPL.
+ * @param fname The file (name) to apply the permissions to.
+ * @param perms The permission bits to apply to the file.
+ *
+ */
+ public static native int permsSet(String fname, int perms);
+
+ /**
+ * Set attributes of the specified file.
+ * This function should be used in preference to explicit manipulation
+ * of the file permissions, because the operations to provide these
+ * attributes are platform specific and may involve more than simply
+ * setting permission bits.
+ * <br /><b>Warning :</b> Platforms which do not implement this feature will return
+ * APR_ENOTIMPL.
+ * @param fname The full path to the file (using / on all systems)
+ * @param attributes Or'd combination of
+ * <PRE>
+ * APR_FILE_ATTR_READONLY - make the file readonly
+ * APR_FILE_ATTR_EXECUTABLE - make the file executable
+ * APR_FILE_ATTR_HIDDEN - make the file hidden
+ * </PRE>
+ * @param mask Mask of valid bits in attributes.
+ * @param pool the pool to use.
+ */
+ public static native int attrsSet(String fname, int attributes, int mask, long pool);
+
+ /**
+ * Set the mtime of the specified file.
+ * <br /><b>Warning :</b> Platforms which do not implement this feature will return
+ * APR_ENOTIMPL.
+ * @param fname The full path to the file (using / on all systems)
+ * @param mtime The mtime to apply to the file in microseconds
+ * @param pool The pool to use.
+ */
+ public static native int mtimeSet(String fname, long mtime, long pool);
+
+ /**
+ * Establish a lock on the specified, open file. The lock may be advisory
+ * or mandatory, at the discretion of the platform. The lock applies to
+ * the file as a whole, rather than a specific range. Locks are established
+ * on a per-thread/process basis; a second lock by the same thread will not
+ * block.
+ * @param thefile The file to lock.
+ * @param type The type of lock to establish on the file.
+ */
+ public static native int lock(long thefile, int type);
+
+ /**
+ * Remove any outstanding locks on the file.
+ * @param thefile The file to unlock.
+ */
+ public static native int unlock(long thefile);
+
+ /**
+ * Retrieve the flags that were passed into apr_file_open()
+ * when the file was opened.
+ * @param file The file to retrieve flags.
+ * @return the flags
+ */
+ public static native int flagsGet(long file);
+
+ /**
+ * Truncate the file's length to the specified offset
+ * @param fp The file to truncate
+ * @param offset The offset to truncate to.
+ */
+ public static native int trunc(long fp, long offset);
+
+ /**
+ * Create an anonymous pipe.
+ * @param io io[0] The file descriptors to use as input to the pipe.
+ * io[1] The file descriptor to use as output from the pipe.
+ * @param pool The pool to operate on.
+ */
+ public static native int pipeCreate(long [] io, long pool);
+
+ /**
+ * Get the timeout value for a pipe or manipulate the blocking state.
+ * @param thepipe The pipe we are getting a timeout for.
+ * @return The current timeout value in microseconds.
+ */
+ public static native long pipeTimeoutGet(long thepipe)
+ throws Error;
+
+ /**
+ * Set the timeout value for a pipe or manipulate the blocking state.
+ * @param thepipe The pipe we are setting a timeout on.
+ * @param timeout The timeout value in microseconds. Values < 0 mean wait
+ * forever, 0 means do not wait at all.
+ */
+ public static native int pipeTimeoutSet(long thepipe, long timeout);
+
+ /**
+ * Duplicate the specified file descriptor.
+ * @param newFile The file to duplicate.
+ * newFile must point to a valid apr_file_t, or point to NULL.
+ * @param oldFile The file to duplicate.
+ * @param pool The pool to use for the new file.
+ * @return Duplicated file structure.
+ */
+ public static native long dup(long newFile, long oldFile, long pool)
+ throws Error;
+
+ /**
+ * Duplicate the specified file descriptor and close the original.
+ * @param newFile The old file that is to be closed and reused.
+ * newFile MUST point at a valid apr_file_t. It cannot be NULL.
+ * @param oldFile The file to duplicate.
+ * @param pool The pool to use for the new file.
+ * @return Status code.
+ */
+ public static native int dup2(long newFile, long oldFile, long pool);
+
+ /**
+ * Get the specified file's stats. The file is specified by filename,
+ * instead of using a pre-opened file.
+ * @param finfo Where to store the information about the file, which is
+ * never touched if the call fails.
+ * @param fname The name of the file to stat.
+ * @param wanted The desired apr_finfo_t fields, as a bit flag of APR_FINFO_ values
+ * @param pool the pool to use to allocate the new file.
+ */
+ public static native int stat(FileInfo finfo, String fname, int wanted, long pool);
+
+ /**
+ * Get the specified file's stats. The file is specified by filename,
+ * instead of using a pre-opened file.
+ * @param fname The name of the file to stat.
+ * @param wanted The desired apr_finfo_t fields, as a bit flag of APR_FINFO_ values
+ * @param pool the pool to use to allocate the new file.
+ * @return FileInfo object.
+ */
+ public static native FileInfo getStat(String fname, int wanted, long pool);
+
+ /**
+ * Get the specified file's stats.
+ * @param finfo Where to store the information about the file.
+ * @param wanted The desired apr_finfo_t fields, as a bit flag of APR_FINFO_ values
+ * @param thefile The file to get information about.
+ */
+ public static native int infoGet(FileInfo finfo, int wanted, long thefile);
+
+
+ /**
+ * Get the specified file's stats.
+ * @param wanted The desired apr_finfo_t fields, as a bit flag of APR_FINFO_ values
+ * @param thefile The file to get information about.
+ * @return FileInfo object.
+ */
+ public static native FileInfo getInfo(int wanted, long thefile);
+
+}
diff --git a/jni/java/org/apache/tomcat/jni/FileInfo.java b/jni/java/org/apache/tomcat/jni/FileInfo.java
new file mode 100644
index 0000000..9fb6bd3
--- /dev/null
+++ b/jni/java/org/apache/tomcat/jni/FileInfo.java
@@ -0,0 +1,65 @@
+/*
+ * 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.
+ */
+
+package org.apache.tomcat.jni;
+
+/** Fileinfo
+ *
+ * @author Mladen Turk
+ */
+public class FileInfo {
+
+ /** Allocates memory and closes lingering handles in the specified pool */
+ public long pool;
+ /** The bitmask describing valid fields of this apr_finfo_t structure
+ * including all available 'wanted' fields and potentially more */
+ public int valid;
+ /** The access permissions of the file. Mimics Unix access rights. */
+ public int protection;
+ /** The type of file. One of APR_REG, APR_DIR, APR_CHR, APR_BLK, APR_PIPE,
+ * APR_LNK or APR_SOCK. If the type is undetermined, the value is APR_NOFILE.
+ * If the type cannot be determined, the value is APR_UNKFILE.
+ */
+ public int filetype;
+ /** The user id that owns the file */
+ public int user;
+ /** The group id that owns the file */
+ public int group;
+ /** The inode of the file. */
+ public int inode;
+ /** The id of the device the file is on. */
+ public int device;
+ /** The number of hard links to the file. */
+ public int nlink;
+ /** The size of the file */
+ public long size;
+ /** The storage size consumed by the file */
+ public long csize;
+ /** The time the file was last accessed */
+ public long atime;
+ /** The time the file was last modified */
+ public long mtime;
+ /** The time the file was created, or the inode was last changed */
+ public long ctime;
+ /** The pathname of the file (possibly unrooted) */
+ public String fname;
+ /** The file's name (no path) in filesystem case */
+ public String name;
+ /** The file's handle, if accessed (can be submitted to apr_duphandle) */
+ public long filehand;
+
+}
diff --git a/jni/java/org/apache/tomcat/jni/Global.java b/jni/java/org/apache/tomcat/jni/Global.java
new file mode 100644
index 0000000..af13fbf
--- /dev/null
+++ b/jni/java/org/apache/tomcat/jni/Global.java
@@ -0,0 +1,94 @@
+/*
+ * 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.
+ */
+
+package org.apache.tomcat.jni;
+
+/** Global
+ *
+ * @author Mladen Turk
+ */
+public class Global {
+
+ /**
+ * Create and initialize a mutex that can be used to synchronize both
+ * processes and threads. Note: There is considerable overhead in using
+ * this API if only cross-process or cross-thread mutual exclusion is
+ * required. See apr_proc_mutex.h and apr_thread_mutex.h for more
+ * specialized lock routines.
+ * <br /><b>Warning :</b> Check APR_HAS_foo_SERIALIZE defines to see if the platform supports
+ * APR_LOCK_foo. Only APR_LOCK_DEFAULT is portable.
+ * @param fname A file name to use if the lock mechanism requires one. This
+ * argument should always be provided. The lock code itself will
+ * determine if it should be used.
+ * @param mech The mechanism to use for the interprocess lock, if any; one of
+ * <PRE>
+ * APR_LOCK_FCNTL
+ * APR_LOCK_FLOCK
+ * APR_LOCK_SYSVSEM
+ * APR_LOCK_POSIXSEM
+ * APR_LOCK_PROC_PTHREAD
+ * APR_LOCK_DEFAULT pick the default mechanism for the platform
+ * </PRE>
+ * @param pool the pool from which to allocate the mutex.
+ * @return Newly created mutex.
+ */
+ public static native long create(String fname, int mech, long pool)
+ throws Error;
+
+ /**
+ * Re-open a mutex in a child process.
+ * @param fname A file name to use if the mutex mechanism requires one. This
+ * argument should always be provided. The mutex code itself will
+ * determine if it should be used. This filename should be the
+ * same one that was passed to apr_proc_mutex_create().
+ * @param pool The pool to operate on.
+ * This function must be called to maintain portability, even
+ * if the underlying lock mechanism does not require it.
+ * @return Newly opened mutex.
+ */
+ public static native long childInit(String fname, long pool)
+ throws Error;
+
+ /**
+ * Acquire the lock for the given mutex. If the mutex is already locked,
+ * the current thread will be put to sleep until the lock becomes available.
+ * @param mutex the mutex on which to acquire the lock.
+ */
+ public static native int lock(long mutex);
+
+ /**
+ * Attempt to acquire the lock for the given mutex. If the mutex has already
+ * been acquired, the call returns immediately with APR_EBUSY. Note: it
+ * is important that the APR_STATUS_IS_EBUSY(s) macro be used to determine
+ * if the return value was APR_EBUSY, for portability reasons.
+ * @param mutex the mutex on which to attempt the lock acquiring.
+ */
+ public static native int trylock(long mutex);
+
+ /**
+ * Release the lock for the given mutex.
+ * @param mutex the mutex from which to release the lock.
+ */
+ public static native int unlock(long mutex);
+
+ /**
+ * Destroy the mutex and free the memory associated with the lock.
+ * @param mutex the mutex to destroy.
+ */
+ public static native int destroy(long mutex);
+
+}
diff --git a/jni/java/org/apache/tomcat/jni/Library.java b/jni/java/org/apache/tomcat/jni/Library.java
new file mode 100644
index 0000000..8923131
--- /dev/null
+++ b/jni/java/org/apache/tomcat/jni/Library.java
@@ -0,0 +1,223 @@
+/*
+ * 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.
+ */
+
+package org.apache.tomcat.jni;
+
+/** Library
+ *
+ * @author Mladen Turk
+ */
+public final class Library {
+
+ /* Default library names */
+ private static final String [] NAMES = {"tcnative-1", "libtcnative-1"};
+ /*
+ * A handle to the unique Library singleton instance.
+ */
+ private static Library _instance = null;
+
+ private Library()
+ throws Exception
+ {
+ boolean loaded = false;
+ StringBuilder err = new StringBuilder();
+ for (int i = 0; i < NAMES.length; i++) {
+ try {
+ System.loadLibrary(NAMES[i]);
+ loaded = true;
+ }
+ catch (Throwable t) {
+ if (t instanceof ThreadDeath) {
+ throw (ThreadDeath) t;
+ }
+ if (t instanceof VirtualMachineError) {
+ throw (VirtualMachineError) t;
+ }
+ String name = System.mapLibraryName(NAMES[i]);
+ String path = System.getProperty("java.library.path");
+ String sep = System.getProperty("path.separator");
+ String [] paths = path.split(sep);
+ for (int j=0; j<paths.length; j++) {
+ java.io.File fd = new java.io.File(paths[j] , name);
+ if (fd.exists()) {
+ t.printStackTrace();
+ }
+ }
+ if ( i > 0)
+ err.append(", ");
+ err.append(t.getMessage());
+ }
+ if (loaded)
+ break;
+ }
+ if (!loaded) {
+ err.append('(');
+ err.append(System.getProperty("java.library.path"));
+ err.append(')');
+ throw new UnsatisfiedLinkError(err.toString());
+ }
+ }
+
+ private Library(String libraryName)
+ {
+ System.loadLibrary(libraryName);
+ }
+
+ /* create global TCN's APR pool
+ * This has to be the first call to TCN library.
+ */
+ private static native boolean initialize();
+ /* destroy global TCN's APR pool
+ * This has to be the last call to TCN library.
+ */
+ public static native void terminate();
+ /* Internal function for loading APR Features */
+ private static native boolean has(int what);
+ /* Internal function for loading APR Features */
+ private static native int version(int what);
+ /* Internal function for loading APR sizes */
+ private static native int size(int what);
+
+ /* TCN_MAJOR_VERSION */
+ public static int TCN_MAJOR_VERSION = 0;
+ /* TCN_MINOR_VERSION */
+ public static int TCN_MINOR_VERSION = 0;
+ /* TCN_PATCH_VERSION */
+ public static int TCN_PATCH_VERSION = 0;
+ /* TCN_IS_DEV_VERSION */
+ public static int TCN_IS_DEV_VERSION = 0;
+ /* APR_MAJOR_VERSION */
+ public static int APR_MAJOR_VERSION = 0;
+ /* APR_MINOR_VERSION */
+ public static int APR_MINOR_VERSION = 0;
+ /* APR_PATCH_VERSION */
+ public static int APR_PATCH_VERSION = 0;
+ /* APR_IS_DEV_VERSION */
+ public static int APR_IS_DEV_VERSION = 0;
+
+ /* TCN_VERSION_STRING */
+ public static native String versionString();
+ /* APR_VERSION_STRING */
+ public static native String aprVersionString();
+
+ /* APR Feature Macros */
+ public static boolean APR_HAVE_IPV6 = false;
+ public static boolean APR_HAS_SHARED_MEMORY = false;
+ public static boolean APR_HAS_THREADS = false;
+ public static boolean APR_HAS_SENDFILE = false;
+ public static boolean APR_HAS_MMAP = false;
+ public static boolean APR_HAS_FORK = false;
+ public static boolean APR_HAS_RANDOM = false;
+ public static boolean APR_HAS_OTHER_CHILD = false;
+ public static boolean APR_HAS_DSO = false;
+ public static boolean APR_HAS_SO_ACCEPTFILTER = false;
+ public static boolean APR_HAS_UNICODE_FS = false;
+ public static boolean APR_HAS_PROC_INVOKED = false;
+ public static boolean APR_HAS_USER = false;
+ public static boolean APR_HAS_LARGE_FILES = false;
+ public static boolean APR_HAS_XTHREAD_FILES = false;
+ public static boolean APR_HAS_OS_UUID = false;
+ /* Are we big endian? */
+ public static boolean APR_IS_BIGENDIAN = false;
+ /* APR sets APR_FILES_AS_SOCKETS to 1 on systems where it is possible
+ * to poll on files/pipes.
+ */
+ public static boolean APR_FILES_AS_SOCKETS = false;
+ /* This macro indicates whether or not EBCDIC is the native character set.
+ */
+ public static boolean APR_CHARSET_EBCDIC = false;
+ /* Is the TCP_NODELAY socket option inherited from listening sockets?
+ */
+ public static boolean APR_TCP_NODELAY_INHERITED = false;
+ /* Is the O_NONBLOCK flag inherited from listening sockets?
+ */
+ public static boolean APR_O_NONBLOCK_INHERITED = false;
+
+
+ public static int APR_SIZEOF_VOIDP;
+ public static int APR_PATH_MAX;
+ public static int APRMAXHOSTLEN;
+ public static int APR_MAX_IOVEC_SIZE;
+ public static int APR_MAX_SECS_TO_LINGER;
+ public static int APR_MMAP_THRESHOLD;
+ public static int APR_MMAP_LIMIT;
+
+ /* return global TCN's APR pool */
+ public static native long globalPool();
+
+ /**
+ * Setup any APR internal data structures. This MUST be the first function
+ * called for any APR library.
+ * @param libraryName the name of the library to load
+ */
+ public static boolean initialize(String libraryName)
+ throws Exception
+ {
+ if (_instance == null) {
+ if (libraryName == null)
+ _instance = new Library();
+ else
+ _instance = new Library(libraryName);
+ TCN_MAJOR_VERSION = version(0x01);
+ TCN_MINOR_VERSION = version(0x02);
+ TCN_PATCH_VERSION = version(0x03);
+ TCN_IS_DEV_VERSION = version(0x04);
+ APR_MAJOR_VERSION = version(0x11);
+ APR_MINOR_VERSION = version(0x12);
+ APR_PATCH_VERSION = version(0x13);
+ APR_IS_DEV_VERSION = version(0x14);
+
+ APR_SIZEOF_VOIDP = size(1);
+ APR_PATH_MAX = size(2);
+ APRMAXHOSTLEN = size(3);
+ APR_MAX_IOVEC_SIZE = size(4);
+ APR_MAX_SECS_TO_LINGER = size(5);
+ APR_MMAP_THRESHOLD = size(6);
+ APR_MMAP_LIMIT = size(7);
+
+ APR_HAVE_IPV6 = has(0);
+ APR_HAS_SHARED_MEMORY = has(1);
+ APR_HAS_THREADS = has(2);
+ APR_HAS_SENDFILE = has(3);
+ APR_HAS_MMAP = has(4);
+ APR_HAS_FORK = has(5);
+ APR_HAS_RANDOM = has(6);
+ APR_HAS_OTHER_CHILD = has(7);
+ APR_HAS_DSO = has(8);
+ APR_HAS_SO_ACCEPTFILTER = has(9);
+ APR_HAS_UNICODE_FS = has(10);
+ APR_HAS_PROC_INVOKED = has(11);
+ APR_HAS_USER = has(12);
+ APR_HAS_LARGE_FILES = has(13);
+ APR_HAS_XTHREAD_FILES = has(14);
+ APR_HAS_OS_UUID = has(15);
+ APR_IS_BIGENDIAN = has(16);
+ APR_FILES_AS_SOCKETS = has(17);
+ APR_CHARSET_EBCDIC = has(18);
+ APR_TCP_NODELAY_INHERITED = has(19);
+ APR_O_NONBLOCK_INHERITED = has(20);
+ if (APR_MAJOR_VERSION < 1) {
+ throw new UnsatisfiedLinkError("Unsupported APR Version (" +
+ aprVersionString() + ")");
+ }
+ if (!APR_HAS_THREADS) {
+ throw new UnsatisfiedLinkError("Missing APR_HAS_THREADS");
+ }
+ }
+ return initialize();
+ }
+}
diff --git a/jni/java/org/apache/tomcat/jni/Local.java b/jni/java/org/apache/tomcat/jni/Local.java
new file mode 100644
index 0000000..256af62
--- /dev/null
+++ b/jni/java/org/apache/tomcat/jni/Local.java
@@ -0,0 +1,73 @@
+/*
+ * 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.
+ */
+
+package org.apache.tomcat.jni;
+
+/** Local socket
+ *
+ * @author Mladen Turk
+ */
+public class Local {
+
+ /**
+ * Create a socket.
+ * @param path The address of the new socket.
+ * @param cont The parent pool to use
+ * @return The new socket that has been set up.
+ */
+ public static native long create(String path, long cont)
+ throws Exception;
+
+ /**
+ * Bind the socket to its associated port
+ * @param sock The socket to bind
+ * @param sa The socket address to bind to
+ * This may be where we will find out if there is any other process
+ * using the selected port.
+ */
+ public static native int bind(long sock, long sa);
+
+ /**
+ * Listen to a bound socket for connections.
+ * @param sock The socket to listen on
+ * @param backlog The number of outstanding connections allowed in the sockets
+ * listen queue. If this value is less than zero, for NT pipes
+ * the number of instances is unlimited.
+ *
+ */
+ public static native int listen(long sock, int backlog);
+
+ /**
+ * Accept a new connection request
+ * @param sock The socket we are listening on.
+ * @return A copy of the socket that is connected to the socket that
+ * made the connection request. This is the socket which should
+ * be used for all future communication.
+ */
+ public static native long accept(long sock)
+ throws Exception;
+
+ /**
+ * Issue a connection request to a socket either on the same machine
+ * or a different one.
+ * @param sock The socket we wish to use for our side of the connection
+ * @param sa The address of the machine we wish to connect to.
+ * Unused for NT Pipes.
+ */
+ public static native int connect(long sock, long sa);
+
+}
diff --git a/jni/java/org/apache/tomcat/jni/Lock.java b/jni/java/org/apache/tomcat/jni/Lock.java
new file mode 100644
index 0000000..209e056
--- /dev/null
+++ b/jni/java/org/apache/tomcat/jni/Lock.java
@@ -0,0 +1,121 @@
+/*
+ * 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.
+ */
+
+package org.apache.tomcat.jni;
+
+/** Lock
+ *
+ * @author Mladen Turk
+ */
+public class Lock {
+
+ /**
+ * Enumerated potential types for APR process locking methods
+ * <br /><b>Warning :</b> Check APR_HAS_foo_SERIALIZE defines to see if the platform supports
+ * APR_LOCK_foo. Only APR_LOCK_DEFAULT is portable.
+ */
+
+ public static final int APR_LOCK_FCNTL = 0; /** fcntl() */
+ public static final int APR_LOCK_FLOCK = 1; /** flock() */
+ public static final int APR_LOCK_SYSVSEM = 2; /** System V Semaphores */
+ public static final int APR_LOCK_PROC_PTHREAD = 3; /** POSIX pthread process-based locking */
+ public static final int APR_LOCK_POSIXSEM = 4; /** POSIX semaphore process-based locking */
+ public static final int APR_LOCK_DEFAULT = 5; /** Use the default process lock */
+
+ /**
+ * Create and initialize a mutex that can be used to synchronize processes.
+ * <br /><b>Warning :</b> Check APR_HAS_foo_SERIALIZE defines to see if the platform supports
+ * APR_LOCK_foo. Only APR_LOCK_DEFAULT is portable.
+ * @param fname A file name to use if the lock mechanism requires one. This
+ * argument should always be provided. The lock code itself will
+ * determine if it should be used.
+ * @param mech The mechanism to use for the interprocess lock, if any; one of
+ * <PRE>
+ * APR_LOCK_FCNTL
+ * APR_LOCK_FLOCK
+ * APR_LOCK_SYSVSEM
+ * APR_LOCK_POSIXSEM
+ * APR_LOCK_PROC_PTHREAD
+ * APR_LOCK_DEFAULT pick the default mechanism for the platform
+ * </PRE>
+ * @param pool the pool from which to allocate the mutex.
+ * @return Newly created mutex.
+ */
+ public static native long create(String fname, int mech, long pool)
+ throws Error;
+
+ /**
+ * Re-open a mutex in a child process.
+ * This function must be called to maintain portability, even
+ * if the underlying lock mechanism does not require it.
+ * @param fname A file name to use if the mutex mechanism requires one. This
+ * argument should always be provided. The mutex code itself will
+ * determine if it should be used. This filename should be the
+ * same one that was passed to apr_proc_mutex_create().
+ * @param pool The pool to operate on.
+ * @return Newly opened mutex.
+ */
+ public static native long childInit(String fname, long pool)
+ throws Error;
+
+ /**
+ * Acquire the lock for the given mutex. If the mutex is already locked,
+ * the current thread will be put to sleep until the lock becomes available.
+ * @param mutex the mutex on which to acquire the lock.
+ */
+ public static native int lock(long mutex);
+
+ /**
+ * Attempt to acquire the lock for the given mutex. If the mutex has already
+ * been acquired, the call returns immediately with APR_EBUSY. Note: it
+ * is important that the APR_STATUS_IS_EBUSY(s) macro be used to determine
+ * if the return value was APR_EBUSY, for portability reasons.
+ * @param mutex the mutex on which to attempt the lock acquiring.
+ */
+ public static native int trylock(long mutex);
+
+ /**
+ * Release the lock for the given mutex.
+ * @param mutex the mutex from which to release the lock.
+ */
+ public static native int unlock(long mutex);
+
+ /**
+ * Destroy the mutex and free the memory associated with the lock.
+ * @param mutex the mutex to destroy.
+ */
+ public static native int destroy(long mutex);
+
+ /**
+ * Return the name of the lockfile for the mutex, or NULL
+ * if the mutex doesn't use a lock file
+ */
+ public static native String lockfile(long mutex);
+
+ /**
+ * Display the name of the mutex, as it relates to the actual method used.
+ * This matches the valid options for Apache's AcceptMutex directive
+ * @param mutex the name of the mutex
+ */
+ public static native String name(long mutex);
+
+ /**
+ * Display the name of the default mutex: APR_LOCK_DEFAULT
+ */
+ public static native String defname();
+
+}
diff --git a/jni/java/org/apache/tomcat/jni/Mmap.java b/jni/java/org/apache/tomcat/jni/Mmap.java
new file mode 100644
index 0000000..92d7687
--- /dev/null
+++ b/jni/java/org/apache/tomcat/jni/Mmap.java
@@ -0,0 +1,71 @@
+/*
+ * 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.
+ */
+
+package org.apache.tomcat.jni;
+
+/** Mmap
+ *
+ * @author Mladen Turk
+ */
+public class Mmap {
+ /** MMap opened for reading */
+ public static final int APR_MMAP_READ = 1;
+ /** MMap opened for writing */
+ public static final int APR_MMAP_WRITE = 2;
+
+
+ /**
+ * Create a new mmap'ed file out of an existing APR file.
+ * @param file The file turn into an mmap.
+ * @param offset The offset into the file to start the data pointer at.
+ * @param size The size of the file
+ * @param flag bit-wise or of:
+ * <PRE>
+ * APR_MMAP_READ MMap opened for reading
+ * APR_MMAP_WRITE MMap opened for writing
+ * </PRE>
+ * @param pool The pool to use when creating the mmap.
+ * @return The newly created mmap'ed file.
+ */
+ public static native long create(long file, long offset, long size, int flag, long pool)
+ throws Error;
+
+ /**
+ * Duplicate the specified MMAP.
+ * @param mmap The mmap to duplicate.
+ * @param pool The pool to use for new_mmap.
+ * @return Duplicated mmap'ed file.
+ */
+ public static native long dup(long mmap, long pool)
+ throws Error;
+
+ /**
+ * Remove a mmap'ed.
+ * @param mm The mmap'ed file.
+ */
+ public static native int delete(long mm);
+
+ /**
+ * Move the pointer into the mmap'ed file to the specified offset.
+ * @param mm The mmap'ed file.
+ * @param offset The offset to move to.
+ * @return The pointer to the offset specified.
+ */
+ public static native long offset(long mm, long offset)
+ throws Error;
+
+}
diff --git a/jni/java/org/apache/tomcat/jni/Multicast.java b/jni/java/org/apache/tomcat/jni/Multicast.java
new file mode 100644
index 0000000..579a161
--- /dev/null
+++ b/jni/java/org/apache/tomcat/jni/Multicast.java
@@ -0,0 +1,76 @@
+/*
+ * 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.
+ */
+
+package org.apache.tomcat.jni;
+
+/** Multicast
+ *
+ * @author Mladen Turk
+ */
+public class Multicast {
+
+ /**
+ * Join a Multicast Group
+ * @param sock The socket to join a multicast group
+ * @param join The address of the multicast group to join
+ * @param iface Address of the interface to use. If NULL is passed, the
+ * default multicast interface will be used. (OS Dependent)
+ * @param source Source Address to accept transmissions from (non-NULL
+ * implies Source-Specific Multicast)
+ */
+ public static native int join(long sock, long join,
+ long iface, long source);
+
+ /**
+ * Leave a Multicast Group. All arguments must be the same as
+ * apr_mcast_join.
+ * @param sock The socket to leave a multicast group
+ * @param addr The address of the multicast group to leave
+ * @param iface Address of the interface to use. If NULL is passed, the
+ * default multicast interface will be used. (OS Dependent)
+ * @param source Source Address to accept transmissions from (non-NULL
+ * implies Source-Specific Multicast)
+ */
+ public static native int leave(long sock, long addr,
+ long iface, long source);
+
+ /**
+ * Set the Multicast Time to Live (ttl) for a multicast transmission.
+ * @param sock The socket to set the multicast ttl
+ * @param ttl Time to live to Assign. 0-255, default=1
+ * <br /><b>Remark :</b> If the TTL is 0, packets will only be seen
+ * by sockets on the local machine,
+ * and only when multicast loopback is enabled.
+ */
+ public static native int hops(long sock, int ttl);
+
+ /**
+ * Toggle IP Multicast Loopback
+ * @param sock The socket to set multicast loopback
+ * @param opt false=disable, true=enable
+ */
+ public static native int loopback(long sock, boolean opt);
+
+
+ /**
+ * Set the Interface to be used for outgoing Multicast Transmissions.
+ * @param sock The socket to set the multicast interface on
+ * @param iface Address of the interface to use for Multicast
+ */
+ public static native int ointerface(long sock, long iface);
+
+}
diff --git a/jni/java/org/apache/tomcat/jni/OS.java b/jni/java/org/apache/tomcat/jni/OS.java
new file mode 100644
index 0000000..e7791af
--- /dev/null
+++ b/jni/java/org/apache/tomcat/jni/OS.java
@@ -0,0 +1,128 @@
+/*
+ * 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.
+ */
+
+package org.apache.tomcat.jni;
+
+/** OS
+ *
+ * @author Mladen Turk
+ */
+public class OS {
+
+ /* OS Enums */
+ private static final int UNIX = 1;
+ private static final int NETWARE = 2;
+ private static final int WIN32 = 3;
+ private static final int WIN64 = 4;
+ private static final int LINUX = 5;
+ private static final int SOLARIS = 6;
+ private static final int BSD = 7;
+ private static final int MACOSX = 8;
+
+ public static final int LOG_EMERG = 1;
+ public static final int LOG_ERROR = 2;
+ public static final int LOG_NOTICE = 3;
+ public static final int LOG_WARN = 4;
+ public static final int LOG_INFO = 5;
+ public static final int LOG_DEBUG = 6;
+
+ /**
+ * Check for OS type.
+ * @param type OS type to test.
+ */
+ private static native boolean is(int type);
+
+ public static final boolean IS_UNIX = is(UNIX);
+ public static final boolean IS_NETWARE = is(NETWARE);
+ public static final boolean IS_WIN32 = is(WIN32);
+ public static final boolean IS_WIN64 = is(WIN64);
+ public static final boolean IS_LINUX = is(LINUX);
+ public static final boolean IS_SOLARIS = is(SOLARIS);
+ public static final boolean IS_BSD = is(BSD);
+ public static final boolean IS_MACOSX = is(MACOSX);
+
+ /**
+ * Get the name of the system default character set.
+ * @param pool the pool to allocate the name from, if needed
+ */
+ public static native String defaultEncoding(long pool);
+
+ /**
+ * Get the name of the current locale character set.
+ * Defers to apr_os_default_encoding if the current locale's
+ * data can't be retrieved on this system.
+ * @param pool the pool to allocate the name from, if needed
+ */
+ public static native String localeEncoding(long pool);
+
+ /**
+ * Generate random bytes.
+ * @param buf Buffer to fill with random bytes
+ * @param len Length of buffer in bytes
+ */
+ public static native int random(byte [] buf, int len);
+
+ /**
+ * Gather system info.
+ * <PRE>
+ * On exit the inf array will be filled with:
+ * inf[0] - Total usable main memory size
+ * inf[1] - Available memory size
+ * inf[2] - Total page file/swap space size
+ * inf[3] - Page file/swap space still available
+ * inf[4] - Amount of shared memory
+ * inf[5] - Memory used by buffers
+ * inf[6] - Memory Load
+ *
+ * inf[7] - Idle Time in microseconds
+ * inf[8] - Kernel Time in microseconds
+ * inf[9] - User Time in microseconds
+ *
+ * inf[10] - Process creation time (apr_time_t)
+ * inf[11] - Process Kernel Time in microseconds
+ * inf[12] - Process User Time in microseconds
+ *
+ * inf[13] - Current working set size.
+ * inf[14] - Peak working set size.
+ * inf[15] - Number of page faults.
+ * </PRE>
+ * @param inf array that will be filled with system information.
+ * Array length must be at least 16.
+ */
+ public static native int info(long [] inf);
+
+ /**
+ * Expand environment variables.
+ * @param str String to expand
+ * @return Expanded string with replaced environment variables.
+ */
+ public static native String expand(String str);
+
+ /**
+ * Initialize system logging.
+ * @param domain String that will be prepended to every message
+ */
+ public static native void sysloginit(String domain);
+
+ /**
+ * Log message.
+ * @param level Log message severity. See LOG_XXX enums.
+ * @param message Message to log
+ */
+ public static native void syslog(int level, String message);
+
+}
diff --git a/jni/java/org/apache/tomcat/jni/PasswordCallback.java b/jni/java/org/apache/tomcat/jni/PasswordCallback.java
new file mode 100644
index 0000000..13f5d9a
--- /dev/null
+++ b/jni/java/org/apache/tomcat/jni/PasswordCallback.java
@@ -0,0 +1,32 @@
+/*
+ * 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.
+ */
+
+package org.apache.tomcat.jni;
+
+/** PasswordCallback Interface
+ *
+ * @author Mladen Turk
+ */
+public interface PasswordCallback {
+
+ /**
+ * Called when the password is required
+ * @param prompt Password prompt
+ * @return Valid password or null
+ */
+ public String callback(String prompt);
+}
diff --git a/jni/java/org/apache/tomcat/jni/Poll.java b/jni/java/org/apache/tomcat/jni/Poll.java
new file mode 100644
index 0000000..a9b26fd
--- /dev/null
+++ b/jni/java/org/apache/tomcat/jni/Poll.java
@@ -0,0 +1,183 @@
+/*
+ * 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.
+ */
+package org.apache.tomcat.jni;
+
+/** Poll
+ *
+ * @author Mladen Turk
+ */
+public class Poll {
+
+ /**
+ * Poll return values
+ */
+ /** Can read without blocking */
+ public static final int APR_POLLIN = 0x001;
+ /** Priority data available */
+ public static final int APR_POLLPRI = 0x002;
+ /** Can write without blocking */
+ public static final int APR_POLLOUT = 0x004;
+ /** Pending error */
+ public static final int APR_POLLERR = 0x010;
+ /** Hangup occurred */
+ public static final int APR_POLLHUP = 0x020;
+ /** Descriptor invalid */
+ public static final int APR_POLLNVAL = 0x040;
+
+ /**
+ * Pollset Flags
+ */
+ /** Adding or Removing a Descriptor is thread safe */
+ public static final int APR_POLLSET_THREADSAFE = 0x001;
+
+
+ /** Used in apr_pollfd_t to determine what the apr_descriptor is
+ * apr_datatype_e enum
+ */
+ public static final int APR_NO_DESC = 0; /** nothing here */
+ public static final int APR_POLL_SOCKET = 1; /** descriptor refers to a socket */
+ public static final int APR_POLL_FILE = 2; /** descriptor refers to a file */
+ public static final int APR_POLL_LASTDESC = 3; /** descriptor is the last one in the list */
+
+ /**
+ * Setup a pollset object.
+ * If flags equals APR_POLLSET_THREADSAFE, then a pollset is
+ * created on which it is safe to make concurrent calls to
+ * apr_pollset_add(), apr_pollset_remove() and apr_pollset_poll() from
+ * separate threads. This feature is only supported on some
+ * platforms; the apr_pollset_create() call will fail with
+ * APR_ENOTIMPL on platforms where it is not supported.
+ * @param size The maximum number of descriptors that this pollset can hold
+ * @param p The pool from which to allocate the pollset
+ * @param flags Optional flags to modify the operation of the pollset.
+ * @param ttl Maximum time to live for a particular socket.
+ * @return The pointer in which to return the newly created object
+ */
+ public static native long create(int size, long p, int flags, long ttl)
+ throws Error;
+ /**
+ * Destroy a pollset object
+ * @param pollset The pollset to destroy
+ */
+ public static native int destroy(long pollset);
+
+ /**
+ * Add a socket to a pollset with the default timeout.
+ * @param pollset The pollset to which to add the socket
+ * @param sock The sockets to add
+ * @param reqevents requested events
+ */
+ public static native int add(long pollset, long sock,
+ int reqevents);
+
+ /**
+ * Add a socket to a pollset with a specific timeout.
+ * @param pollset The pollset to which to add the socket
+ * @param sock The sockets to add
+ * @param reqevents requested events
+ * @param timeout requested timeout in microseconds (-1 for infinite)
+ */
+ public static native int addWithTimeout(long pollset, long sock,
+ int reqevents, long timeout);
+
+ /**
+ * Remove a descriptor from a pollset
+ * @param pollset The pollset from which to remove the descriptor
+ * @param sock The socket to remove
+ */
+ public static native int remove(long pollset, long sock);
+
+ /**
+ * Block for activity on the descriptor(s) in a pollset
+ * @param pollset The pollset to use
+ * @param timeout Timeout in microseconds
+ * @param descriptors Array of signaled descriptors (output parameter)
+ * The descriptor array must be two times the size of pollset.
+ * and are populated as follows:
+ * <PRE>
+ * descriptors[2n + 0] -> returned events
+ * descriptors[2n + 1] -> socket
+ * </PRE>
+ * @param remove Remove signaled descriptors from pollset
+ * @return Number of signaled descriptors (output parameter)
+ * or negative APR error code.
+ */
+ public static native int poll(long pollset, long timeout,
+ long [] descriptors, boolean remove);
+
+ /**
+ * Maintain on the descriptor(s) in a pollset
+ * @param pollset The pollset to use
+ * @param descriptors Array of signaled descriptors (output parameter)
+ * The descriptor array must be the size of pollset.
+ * and are populated as follows:
+ * <PRE>
+ * descriptors[n] -> socket
+ * </PRE>
+ * @param remove Remove signaled descriptors from pollset
+ * @return Number of signaled descriptors (output parameter)
+ * or negative APR error code.
+ */
+ public static native int maintain(long pollset, long [] descriptors,
+ boolean remove);
+
+ /**
+ * Set the socket time to live.
+ * @param pollset The pollset to use
+ * @param ttl Timeout in microseconds
+ */
+ public static native void setTtl(long pollset, long ttl);
+
+ /**
+ * Get the socket time to live.
+ * @param pollset The pollset to use
+ * @return Timeout in microseconds
+ */
+ public static native long getTtl(long pollset);
+
+ /**
+ * Return all descriptor(s) in a pollset
+ * @param pollset The pollset to use
+ * @param descriptors Array of descriptors (output parameter)
+ * The descriptor array must be two times the size of pollset.
+ * and are populated as follows:
+ * <PRE>
+ * descriptors[2n + 0] -> returned events
+ * descriptors[2n + 1] -> socket
+ * </PRE>
+ * @return Number of descriptors (output parameter) in the Poll
+ * or negative APR error code.
+ */
+ public static native int pollset(long pollset, long [] descriptors);
+
+ /**
+ * Make poll() return.
+ *
+ * @param pollset
+ * @return Negative APR error code
+ */
+ public static native int interrupt(long pollset);
+
+ /**
+ * Check if interrupt() is allowed.
+ *
+ * @param pollset
+ * @return <code>true</true> if {@link #interrupt(long)} is allowed, else
+ * <code>false</code>
+ */
+ public static native boolean wakeable(long pollset);
+}
diff --git a/jni/java/org/apache/tomcat/jni/Pool.java b/jni/java/org/apache/tomcat/jni/Pool.java
new file mode 100644
index 0000000..b036e9c
--- /dev/null
+++ b/jni/java/org/apache/tomcat/jni/Pool.java
@@ -0,0 +1,162 @@
+/*
+ * 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.
+ */
+
+package org.apache.tomcat.jni;
+
+import java.nio.ByteBuffer;
+
+/** Pool
+ *
+ * @author Mladen Turk
+ */
+public class Pool {
+
+ /**
+ * Create a new pool.
+ * @param parent The parent pool. If this is 0, the new pool is a root
+ * pool. If it is non-zero, the new pool will inherit all
+ * of its parent pool's attributes, except the apr_pool_t will
+ * be a sub-pool.
+ * @return The pool we have just created.
+ */
+ public static native long create(long parent);
+
+ /**
+ * Clear all memory in the pool and run all the cleanups. This also destroys all
+ * subpools.
+ * @param pool The pool to clear
+ * This does not actually free the memory, it just allows the pool
+ * to re-use this memory for the next allocation.
+ */
+ public static native void clear(long pool);
+
+ /**
+ * Destroy the pool. This takes similar action as apr_pool_clear() and then
+ * frees all the memory.
+ * This will actually free the memory
+ * @param pool The pool to destroy
+ */
+ public static native void destroy(long pool);
+
+ /**
+ * Get the parent pool of the specified pool.
+ * @param pool The pool for retrieving the parent pool.
+ * @return The parent of the given pool.
+ */
+ public static native long parentGet(long pool);
+
+ /**
+ * Determine if pool a is an ancestor of pool b
+ * @param a The pool to search
+ * @param b The pool to search for
+ * @return True if a is an ancestor of b, NULL is considered an ancestor
+ * of all pools.
+ */
+ public static native boolean isAncestor(long a, long b);
+
+
+ /*
+ * Cleanup
+ *
+ * Cleanups are performed in the reverse order they were registered. That is:
+ * Last In, First Out. A cleanup function can safely allocate memory from
+ * the pool that is being cleaned up. It can also safely register additional
+ * cleanups which will be run LIFO, directly after the current cleanup
+ * terminates. Cleanups have to take caution in calling functions that
+ * create subpools. Subpools, created during cleanup will NOT automatically
+ * be cleaned up. In other words, cleanups are to clean up after themselves.
+ */
+
+ /**
+ * Register a function to be called when a pool is cleared or destroyed
+ * @param pool The pool register the cleanup with
+ * @param o The object to call when the pool is cleared
+ * or destroyed
+ * @return The cleanup handler.
+ */
+ public static native long cleanupRegister(long pool, Object o);
+
+ /**
+ * Remove a previously registered cleanup function
+ * @param pool The pool remove the cleanup from
+ * @param data The cleanup handler to remove from cleanup
+ */
+ public static native void cleanupKill(long pool, long data);
+
+ /**
+ * Register a process to be killed when a pool dies.
+ * @param a The pool to use to define the processes lifetime
+ * @param proc The process to register
+ * @param how How to kill the process, one of:
+ * <PRE>
+ * APR_KILL_NEVER -- process is never sent any signals
+ * APR_KILL_ALWAYS -- process is sent SIGKILL on apr_pool_t cleanup
+ * APR_KILL_AFTER_TIMEOUT -- SIGTERM, wait 3 seconds, SIGKILL
+ * APR_JUST_WAIT -- wait forever for the process to complete
+ * APR_KILL_ONLY_ONCE -- send SIGTERM and then wait
+ * </PRE>
+ */
+ public static native void noteSubprocess(long a, long proc, int how);
+
+ /**
+ * Allocate a block of memory from a pool
+ * @param p The pool to allocate from
+ * @param size The amount of memory to allocate
+ * @return The ByteBuffer with allocated memory
+ */
+ public static native ByteBuffer alloc(long p, int size);
+
+ /**
+ * Allocate a block of memory from a pool and set all of the memory to 0
+ * @param p The pool to allocate from
+ * @param size The amount of memory to allocate
+ * @return The ByteBuffer with allocated memory
+ */
+ public static native ByteBuffer calloc(long p, int size);
+
+ /*
+ * User data management
+ */
+
+ /**
+ * Set the data associated with the current pool
+ * @param data The user data associated with the pool.
+ * @param key The key to use for association
+ * @param pool The current pool
+ * <br /><b>Warning :</b>
+ * The data to be attached to the pool should have a life span
+ * at least as long as the pool it is being attached to.
+ * Object attached to the pool will be globally referenced
+ * until the pool is cleared or dataSet is called with the null data.
+ * @return APR Status code.
+ */
+ public static native int dataSet(long pool, String key, Object data);
+
+ /**
+ * Return the data associated with the current pool.
+ * @param key The key for the data to retrieve
+ * @param pool The current pool.
+ */
+ public static native Object dataGet(long pool, String key);
+
+ /**
+ * Run all of the child_cleanups, so that any unnecessary files are
+ * closed because we are about to exec a new program
+ */
+ public static native void cleanupForExec();
+
+}
diff --git a/jni/java/org/apache/tomcat/jni/PoolCallback.java b/jni/java/org/apache/tomcat/jni/PoolCallback.java
new file mode 100644
index 0000000..5075a3e
--- /dev/null
+++ b/jni/java/org/apache/tomcat/jni/PoolCallback.java
@@ -0,0 +1,31 @@
+/*
+ * 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.
+ */
+
+package org.apache.tomcat.jni;
+
+/** PoolCallback Interface
+ *
+ * @author Mladen Turk
+ */
+public interface PoolCallback {
+
+ /**
+ * Called when the pool is destroyed or cleared
+ * @return Function must return APR_SUCCESS
+ */
+ public int callback();
+}
diff --git a/jni/java/org/apache/tomcat/jni/Proc.java b/jni/java/org/apache/tomcat/jni/Proc.java
new file mode 100644
index 0000000..c4c3c43
--- /dev/null
+++ b/jni/java/org/apache/tomcat/jni/Proc.java
@@ -0,0 +1,208 @@
+/*
+ * 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.
+ */
+
+package org.apache.tomcat.jni;
+
+/** Proc
+ *
+ * @author Mladen Turk
+ */
+public class Proc {
+
+ /*
+ * apr_cmdtype_e enum
+ */
+ public static final int APR_SHELLCM = 0; /** use the shell to invoke the program */
+ public static final int APR_PROGRAM = 1; /** invoke the program directly, no copied env */
+ public static final int APR_PROGRAM_ENV = 2; /** invoke the program, replicating our environment */
+ public static final int APR_PROGRAM_PATH = 3; /** find program on PATH, use our environment */
+ public static final int APR_SHELLCMD_ENV = 4; /** use the shell to invoke the program,
+ * replicating our environment
+ */
+
+ /*
+ * apr_wait_how_e enum
+ */
+ public static final int APR_WAIT = 0; /** wait for the specified process to finish */
+ public static final int APR_NOWAIT = 1; /** do not wait -- just see if it has finished */
+
+ /*
+ * apr_exit_why_e enum
+ */
+ public static final int APR_PROC_EXIT = 1; /** process exited normally */
+ public static final int APR_PROC_SIGNAL = 2; /** process exited due to a signal */
+ public static final int APR_PROC_SIGNAL_CORE = 4; /** process exited and dumped a core file */
+
+ public static final int APR_NO_PIPE = 0;
+ public static final int APR_FULL_BLOCK = 1;
+ public static final int APR_FULL_NONBLOCK = 2;
+ public static final int APR_PARENT_BLOCK = 3;
+ public static final int APR_CHILD_BLOCK = 4;
+
+ public static final int APR_LIMIT_CPU = 0;
+ public static final int APR_LIMIT_MEM = 1;
+ public static final int APR_LIMIT_NPROC = 2;
+ public static final int APR_LIMIT_NOFILE = 3;
+
+
+ /** child has died, caller must call unregister still */
+ public static final int APR_OC_REASON_DEATH = 0;
+ /** write_fd is unwritable */
+ public static final int APR_OC_REASON_UNWRITABLE = 1;
+ /** a restart is occurring, perform any necessary cleanup (including
+ * sending a special signal to child)
+ */
+ public static final int APR_OC_REASON_RESTART = 2;
+ /** unregister has been called, do whatever is necessary (including
+ * kill the child)
+ */
+ public static final int APR_OC_REASON_UNREGISTER = 3;
+ /** somehow the child exited without us knowing ... buggy os? */
+ public static final int APR_OC_REASON_LOST = 4;
+ /** a health check is occurring, for most maintenance functions
+ * this is a no-op.
+ */
+ public static final int APR_OC_REASON_RUNNING = 5;
+
+ /* apr_kill_conditions_e enumeration */
+ /** process is never sent any signals */
+ public static final int APR_KILL_NEVER = 0;
+ /** process is sent SIGKILL on apr_pool_t cleanup */
+ public static final int APR_KILL_ALWAYS = 1;
+ /** SIGTERM, wait 3 seconds, SIGKILL */
+ public static final int APR_KILL_AFTER_TIMEOUT = 2;
+ /** wait forever for the process to complete */
+ public static final int APR_JUST_WAIT = 3;
+ /** send SIGTERM and then wait */
+ public static final int APR_KILL_ONLY_ONCE = 4;
+
+ public static final int APR_PROC_DETACH_FOREGROUND = 0; /** Do not detach */
+ public static final int APR_PROC_DETACH_DAEMONIZE = 1; /** Detach */
+
+ /* Maximum number of arguments for create process call */
+ public static final int MAX_ARGS_SIZE = 1024;
+ /* Maximum number of environment variables for create process call */
+ public static final int MAX_ENV_SIZE = 1024;
+
+ /**
+ * Allocate apr_proc_t structure from pool
+ * This is not an apr function.
+ * @param cont The pool to use.
+ */
+ public static native long alloc(long cont);
+
+ /**
+ * This is currently the only non-portable call in APR. This executes
+ * a standard unix fork.
+ * @param proc The resulting process handle.
+ * @param cont The pool to use.
+ * @return APR_INCHILD for the child, and APR_INPARENT for the parent
+ * or an error.
+ */
+ public static native int fork(long [] proc, long cont);
+
+ /**
+ * Create a new process and execute a new program within that process.
+ * This function returns without waiting for the new process to terminate;
+ * use apr_proc_wait for that.
+ * @param progname The program to run
+ * @param args The arguments to pass to the new program. The first
+ * one should be the program name.
+ * @param env The new environment table for the new process. This
+ * should be a list of NULL-terminated strings. This argument
+ * is ignored for APR_PROGRAM_ENV, APR_PROGRAM_PATH, and
+ * APR_SHELLCMD_ENV types of commands.
+ * @param attr The procattr we should use to determine how to create the new
+ * process
+ * @param pool The pool to use.
+ * @return The resulting process handle.
+ */
+ public static native int create(long proc, String progname,
+ String [] args, String [] env,
+ long attr, long pool);
+
+ /**
+ * Wait for a child process to die
+ * @param proc The process handle that corresponds to the desired child process
+ * @param exit exit[0] The returned exit status of the child, if a child process
+ * dies, or the signal that caused the child to die.
+ * On platforms that don't support obtaining this information,
+ * the status parameter will be returned as APR_ENOTIMPL.
+ * exit[1] Why the child died, the bitwise or of:
+ * <PRE>
+ * APR_PROC_EXIT -- process terminated normally
+ * APR_PROC_SIGNAL -- process was killed by a signal
+ * APR_PROC_SIGNAL_CORE -- process was killed by a signal, and
+ * generated a core dump.
+ * </PRE>
+ * @param waithow How should we wait. One of:
+ * <PRE>
+ * APR_WAIT -- block until the child process dies.
+ * APR_NOWAIT -- return immediately regardless of if the
+ * child is dead or not.
+ * </PRE>
+ * @return The childs status is in the return code to this process. It is one of:
+ * <PRE>
+ * APR_CHILD_DONE -- child is no longer running.
+ * APR_CHILD_NOTDONE -- child is still running.
+ * </PRE>
+ */
+ public static native int wait(long proc, int [] exit, int waithow);
+
+ /**
+ * Wait for any current child process to die and return information
+ * about that child.
+ * @param proc Pointer to NULL on entry, will be filled out with child's
+ * information
+ * @param exit exit[0] The returned exit status of the child, if a child process
+ * dies, or the signal that caused the child to die.
+ * On platforms that don't support obtaining this information,
+ * the status parameter will be returned as APR_ENOTIMPL.
+ * exit[1] Why the child died, the bitwise or of:
+ * <PRE>
+ * APR_PROC_EXIT -- process terminated normally
+ * APR_PROC_SIGNAL -- process was killed by a signal
+ * APR_PROC_SIGNAL_CORE -- process was killed by a signal, and
+ * generated a core dump.
+ * </PRE>
+ * @param waithow How should we wait. One of:
+ * <PRE>
+ * APR_WAIT -- block until the child process dies.
+ * APR_NOWAIT -- return immediately regardless of if the
+ * child is dead or not.
+ * </PRE>
+ * @param pool Pool to allocate child information out of.
+ */
+ public static native int waitAllProcs(long proc, int [] exit,
+ int waithow, long pool);
+
+ /**
+ * Detach the process from the controlling terminal.
+ * @param daemonize set to non-zero if the process should daemonize
+ * and become a background process, else it will
+ * stay in the foreground.
+ */
+ public static native int detach(int daemonize);
+
+ /**
+ * Terminate a process.
+ * @param proc The process to terminate.
+ * @param sig How to kill the process.
+ */
+ public static native int kill(long proc, int sig);
+
+}
diff --git a/jni/java/org/apache/tomcat/jni/ProcErrorCallback.java b/jni/java/org/apache/tomcat/jni/ProcErrorCallback.java
new file mode 100644
index 0000000..60f53c8
--- /dev/null
+++ b/jni/java/org/apache/tomcat/jni/ProcErrorCallback.java
@@ -0,0 +1,36 @@
+/*
+ * 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.
+ */
+
+package org.apache.tomcat.jni;
+
+/** ProcErrorCallback Interface
+ *
+ * @author Mladen Turk
+ */
+public interface ProcErrorCallback {
+
+ /**
+ * Called in the child process if APR encounters an error
+ * in the child prior to running the specified program.
+ * @param pool Pool associated with the apr_proc_t. If your child
+ * error function needs user data, associate it with this
+ * pool.
+ * @param err APR error code describing the error
+ * @param description Text description of type of processing which failed
+ */
+ public void callback(long pool, int err, String description);
+}
diff --git a/jni/java/org/apache/tomcat/jni/Procattr.java b/jni/java/org/apache/tomcat/jni/Procattr.java
new file mode 100644
index 0000000..e522ca6
--- /dev/null
+++ b/jni/java/org/apache/tomcat/jni/Procattr.java
@@ -0,0 +1,170 @@
+/*
+ * 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.
+ */
+
+package org.apache.tomcat.jni;
+
+/** Procattr
+ *
+ * @author Mladen Turk
+ */
+public class Procattr {
+
+ /**
+ * Create and initialize a new procattr variable
+ * @param cont The pool to use
+ * @return The newly created procattr.
+ */
+ public static native long create(long cont)
+ throws Error;
+
+ /**
+ * Determine if any of stdin, stdout, or stderr should be linked to pipes
+ * when starting a child process.
+ * @param attr The procattr we care about.
+ * @param in Should stdin be a pipe back to the parent?
+ * @param out Should stdout be a pipe back to the parent?
+ * @param err Should stderr be a pipe back to the parent?
+ */
+ public static native int ioSet(long attr, int in, int out, int err);
+ /**
+ * Set the child_in and/or parent_in values to existing apr_file_t values.
+ * <br />
+ * This is NOT a required initializer function. This is
+ * useful if you have already opened a pipe (or multiple files)
+ * that you wish to use, perhaps persistently across multiple
+ * process invocations - such as a log file. You can save some
+ * extra function calls by not creating your own pipe since this
+ * creates one in the process space for you.
+ * @param attr The procattr we care about.
+ * @param in apr_file_t value to use as child_in. Must be a valid file.
+ * @param parent apr_file_t value to use as parent_in. Must be a valid file.
+ */
+ public static native int childInSet(long attr, long in, long parent);
+
+ /**
+ * Set the child_out and parent_out values to existing apr_file_t values.
+ * <br />
+ * This is NOT a required initializer function. This is
+ * useful if you have already opened a pipe (or multiple files)
+ * that you wish to use, perhaps persistently across multiple
+ * process invocations - such as a log file.
+ * @param attr The procattr we care about.
+ * @param out apr_file_t value to use as child_out. Must be a valid file.
+ * @param parent apr_file_t value to use as parent_out. Must be a valid file.
+ */
+ public static native int childOutSet(long attr, long out, long parent);
+
+ /**
+ * Set the child_err and parent_err values to existing apr_file_t values.
+ * <br />
+ * This is NOT a required initializer function. This is
+ * useful if you have already opened a pipe (or multiple files)
+ * that you wish to use, perhaps persistently across multiple
+ * process invocations - such as a log file.
+ * @param attr The procattr we care about.
+ * @param err apr_file_t value to use as child_err. Must be a valid file.
+ * @param parent apr_file_t value to use as parent_err. Must be a valid file.
+ */
+ public static native int childErrSet(long attr, long err, long parent);
+
+ /**
+ * Set which directory the child process should start executing in.
+ * @param attr The procattr we care about.
+ * @param dir Which dir to start in. By default, this is the same dir as
+ * the parent currently resides in, when the createprocess call
+ * is made.
+ */
+ public static native int dirSet(long attr, String dir);
+
+ /**
+ * Set what type of command the child process will call.
+ * @param attr The procattr we care about.
+ * @param cmd The type of command. One of:
+ * <PRE>
+ * APR_SHELLCMD -- Anything that the shell can handle
+ * APR_PROGRAM -- Executable program (default)
+ * APR_PROGRAM_ENV -- Executable program, copy environment
+ * APR_PROGRAM_PATH -- Executable program on PATH, copy env
+ * </PRE>
+ */
+ public static native int cmdtypeSet(long attr, int cmd);
+
+ /**
+ * Determine if the child should start in detached state.
+ * @param attr The procattr we care about.
+ * @param detach Should the child start in detached state? Default is no.
+ */
+ public static native int detachSet(long attr, int detach);
+
+ /**
+ * Specify that apr_proc_create() should do whatever it can to report
+ * failures to the caller of apr_proc_create(), rather than find out in
+ * the child.
+ * @param attr The procattr describing the child process to be created.
+ * @param chk Flag to indicate whether or not extra work should be done
+ * to try to report failures to the caller.
+ * <br />
+ * This flag only affects apr_proc_create() on platforms where
+ * fork() is used. This leads to extra overhead in the calling
+ * process, but that may help the application handle such
+ * errors more gracefully.
+ */
+ public static native int errorCheckSet(long attr, int chk);
+
+ /**
+ * Determine if the child should start in its own address space or using the
+ * current one from its parent
+ * @param attr The procattr we care about.
+ * @param addrspace Should the child start in its own address space? Default
+ * is no on NetWare and yes on other platforms.
+ */
+ public static native int addrspaceSet(long attr, int addrspace);
+
+ /**
+ * Specify an error function to be called in the child process if APR
+ * encounters an error in the child prior to running the specified program.
+ * @param attr The procattr describing the child process to be created.
+ * @param pool The the pool to use.
+ * @param o The Object to call in the child process.
+ * <br />
+ * At the present time, it will only be called from apr_proc_create()
+ * on platforms where fork() is used. It will never be called on other
+ * platforms, on those platforms apr_proc_create() will return the error
+ * in the parent process rather than invoke the callback in the now-forked
+ * child process.
+ */
+ public static native void errfnSet(long attr, long pool, Object o);
+
+ /**
+ * Set the username used for running process
+ * @param attr The procattr we care about.
+ * @param username The username used
+ * @param password User password if needed. Password is needed on WIN32
+ * or any other platform having
+ * APR_PROCATTR_USER_SET_REQUIRES_PASSWORD set.
+ */
+ public static native int userSet(long attr, String username, String password);
+
+ /**
+ * Set the group used for running process
+ * @param attr The procattr we care about.
+ * @param groupname The group name used
+ */
+ public static native int groupSet(long attr, String groupname);
+
+
+}
diff --git a/jni/java/org/apache/tomcat/jni/Registry.java b/jni/java/org/apache/tomcat/jni/Registry.java
new file mode 100644
index 0000000..9c493e7
--- /dev/null
+++ b/jni/java/org/apache/tomcat/jni/Registry.java
@@ -0,0 +1,233 @@
+/*
+ * 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.
+ */
+
+package org.apache.tomcat.jni;
+
+/** Windows Registy support
+ *
+ * @author Mladen Turk
+ */
+public class Registry {
+
+ /* Registry Enums */
+ public static final int HKEY_CLASSES_ROOT = 1;
+ public static final int HKEY_CURRENT_CONFIG = 2;
+ public static final int HKEY_CURRENT_USER = 3;
+ public static final int HKEY_LOCAL_MACHINE = 4;
+ public static final int HKEY_USERS = 5;
+
+ public static final int KEY_ALL_ACCESS = 0x0001;
+ public static final int KEY_CREATE_LINK = 0x0002;
+ public static final int KEY_CREATE_SUB_KEY = 0x0004;
+ public static final int KEY_ENUMERATE_SUB_KEYS = 0x0008;
+ public static final int KEY_EXECUTE = 0x0010;
+ public static final int KEY_NOTIFY = 0x0020;
+ public static final int KEY_QUERY_VALUE = 0x0040;
+ public static final int KEY_READ = 0x0080;
+ public static final int KEY_SET_VALUE = 0x0100;
+ public static final int KEY_WOW64_64KEY = 0x0200;
+ public static final int KEY_WOW64_32KEY = 0x0400;
+ public static final int KEY_WRITE = 0x0800;
+
+ public static final int REG_BINARY = 1;
+ public static final int REG_DWORD = 2;
+ public static final int REG_EXPAND_SZ = 3;
+ public static final int REG_MULTI_SZ = 4;
+ public static final int REG_QWORD = 5;
+ public static final int REG_SZ = 6;
+
+ /**
+ * Create or open a Registry Key.
+ * @param name Registry Subkey to open
+ * @param root Root key, one of HKEY_*
+ * @param sam Access mask that specifies the access rights for the key.
+ * @param pool Pool used for native memory allocation
+ * @return Opened Registry key
+ */
+ public static native long create(int root, String name, int sam, long pool)
+ throws Error;
+
+ /**
+ * Opens the specified Registry Key.
+ * @param name Registry Subkey to open
+ * @param root Root key, one of HKEY_*
+ * @param sam Access mask that specifies the access rights for the key.
+ * @param pool Pool used for native memory allocation
+ * @return Opened Registry key
+ */
+ public static native long open(int root, String name, int sam, long pool)
+ throws Error;
+
+ /**
+ * Close the specified Registry key.
+ * @param key The Registry key descriptor to close.
+ */
+ public static native int close(long key);
+
+ /**
+ * Get the Registry key type.
+ * @param key The Registry key descriptor to use.
+ * @param name The name of the value to query
+ * @return Value type or negative error value
+ */
+ public static native int getType(long key, String name);
+
+ /**
+ * Get the Registry value for REG_DWORD
+ * @param key The Registry key descriptor to use.
+ * @param name The name of the value to query
+ * @return Registry key value
+ */
+ public static native int getValueI(long key, String name)
+ throws Error;
+
+ /**
+ * Get the Registry value for REG_QWORD or REG_DWORD
+ * @param key The Registry key descriptor to use.
+ * @param name The name of the value to query
+ * @return Registry key value
+ */
+ public static native long getValueJ(long key, String name)
+ throws Error;
+
+ /**
+ * Get the Registry key length.
+ * @param key The Registry key descriptor to use.
+ * @param name The name of the value to query
+ * @return Value size or negative error value
+ */
+ public static native int getSize(long key, String name);
+
+ /**
+ * Get the Registry value for REG_SZ or REG_EXPAND_SZ
+ * @param key The Registry key descriptor to use.
+ * @param name The name of the value to query
+ * @return Registry key value
+ */
+ public static native String getValueS(long key, String name)
+ throws Error;
+
+ /**
+ * Get the Registry value for REG_MULTI_SZ
+ * @param key The Registry key descriptor to use.
+ * @param name The name of the value to query
+ * @return Registry key value
+ */
+ public static native String[] getValueA(long key, String name)
+ throws Error;
+
+ /**
+ * Get the Registry value for REG_BINARY
+ * @param key The Registry key descriptor to use.
+ * @param name The name of the value to query
+ * @return Registry key value
+ */
+ public static native byte[] getValueB(long key, String name)
+ throws Error;
+
+
+ /**
+ * Set the Registry value for REG_DWORD
+ * @param key The Registry key descriptor to use.
+ * @param name The name of the value to set
+ * @param val The the value to set
+ * @return If the function succeeds, the return value is 0
+ */
+ public static native int setValueI(long key, String name, int val);
+
+ /**
+ * Set the Registry value for REG_QWORD
+ * @param key The Registry key descriptor to use.
+ * @param name The name of the value to set
+ * @param val The the value to set
+ * @return If the function succeeds, the return value is 0
+ */
+ public static native int setValueJ(long key, String name, long val);
+
+ /**
+ * Set the Registry value for REG_SZ
+ * @param key The Registry key descriptor to use.
+ * @param name The name of the value to set
+ * @param val The the value to set
+ * @return If the function succeeds, the return value is 0
+ */
+ public static native int setValueS(long key, String name, String val);
+
+ /**
+ * Set the Registry value for REG_EXPAND_SZ
+ * @param key The Registry key descriptor to use.
+ * @param name The name of the value to set
+ * @param val The the value to set
+ * @return If the function succeeds, the return value is 0
+ */
+ public static native int setValueE(long key, String name, String val);
+
+ /**
+ * Set the Registry value for REG_MULTI_SZ
+ * @param key The Registry key descriptor to use.
+ * @param name The name of the value to set
+ * @param val The the value to set
+ * @return If the function succeeds, the return value is 0
+ */
+ public static native int setValueA(long key, String name, String[] val);
+
+ /**
+ * Set the Registry value for REG_BINARY
+ * @param key The Registry key descriptor to use.
+ * @param name The name of the value to set
+ * @param val The the value to set
+ * @return If the function succeeds, the return value is 0
+ */
+ public static native int setValueB(long key, String name, byte[] val);
+
+ /**
+ * Enumerate the Registry subkeys
+ * @param key The Registry key descriptor to use.
+ * @return Array of all subkey names
+ */
+ public static native String[] enumKeys(long key)
+ throws Error;
+
+ /**
+ * Enumerate the Registry values
+ * @param key The Registry key descriptor to use.
+ * @return Array of all value names
+ */
+ public static native String[] enumValues(long key)
+ throws Error;
+
+ /**
+ * Delete the Registry value
+ * @param key The Registry key descriptor to use.
+ * @param name The name of the value to delete
+ * @return If the function succeeds, the return value is 0
+ */
+ public static native int deleteValue(long key, String name);
+
+ /**
+ * Delete the Registry subkey
+ * @param root Root key, one of HKEY_*
+ * @param name Subkey to delete
+ * @param onlyIfEmpty If true will not delete a key if
+ * it contains any subkeys or values
+ * @return If the function succeeds, the return value is 0
+ */
+ public static native int deleteKey(int root, String name,
+ boolean onlyIfEmpty);
+
+
+}
diff --git a/jni/java/org/apache/tomcat/jni/SSL.java b/jni/java/org/apache/tomcat/jni/SSL.java
new file mode 100644
index 0000000..d2b5257
--- /dev/null
+++ b/jni/java/org/apache/tomcat/jni/SSL.java
@@ -0,0 +1,354 @@
+/*
+ * 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.
+ */
+package org.apache.tomcat.jni;
+
+/** SSL
+ *
+ * @author Mladen Turk
+ */
+public final class SSL {
+
+ /*
+ * Type definitions mostly from mod_ssl
+ */
+ public static final int UNSET = -1;
+ /*
+ * Define the certificate algorithm types
+ */
+ public static final int SSL_ALGO_UNKNOWN = 0;
+ public static final int SSL_ALGO_RSA = (1<<0);
+ public static final int SSL_ALGO_DSA = (1<<1);
+ public static final int SSL_ALGO_ALL = (SSL_ALGO_RSA|SSL_ALGO_DSA);
+
+ public static final int SSL_AIDX_RSA = 0;
+ public static final int SSL_AIDX_DSA = 1;
+ public static final int SSL_AIDX_MAX = 2;
+ /*
+ * Define IDs for the temporary RSA keys and DH params
+ */
+
+ public static final int SSL_TMP_KEY_RSA_512 = 0;
+ public static final int SSL_TMP_KEY_RSA_1024 = 1;
+ public static final int SSL_TMP_KEY_RSA_2048 = 2;
+ public static final int SSL_TMP_KEY_RSA_4096 = 3;
+ public static final int SSL_TMP_KEY_DH_512 = 4;
+ public static final int SSL_TMP_KEY_DH_1024 = 5;
+ public static final int SSL_TMP_KEY_DH_2048 = 6;
+ public static final int SSL_TMP_KEY_DH_4096 = 7;
+ public static final int SSL_TMP_KEY_MAX = 8;
+
+ /*
+ * Define the SSL options
+ */
+ public static final int SSL_OPT_NONE = 0;
+ public static final int SSL_OPT_RELSET = (1<<0);
+ public static final int SSL_OPT_STDENVVARS = (1<<1);
+ public static final int SSL_OPT_EXPORTCERTDATA = (1<<3);
+ public static final int SSL_OPT_FAKEBASICAUTH = (1<<4);
+ public static final int SSL_OPT_STRICTREQUIRE = (1<<5);
+ public static final int SSL_OPT_OPTRENEGOTIATE = (1<<6);
+ public static final int SSL_OPT_ALL = (SSL_OPT_STDENVVARS|SSL_OPT_EXPORTCERTDATA|SSL_OPT_FAKEBASICAUTH|SSL_OPT_STRICTREQUIRE|SSL_OPT_OPTRENEGOTIATE);
+
+ /*
+ * Define the SSL Protocol options
+ */
+ public static final int SSL_PROTOCOL_NONE = 0;
+ public static final int SSL_PROTOCOL_SSLV2 = (1<<0);
+ public static final int SSL_PROTOCOL_SSLV3 = (1<<1);
+ public static final int SSL_PROTOCOL_TLSV1 = (1<<2);
+ public static final int SSL_PROTOCOL_ALL = (SSL_PROTOCOL_SSLV3|SSL_PROTOCOL_TLSV1);
+
+ /*
+ * Define the SSL verify levels
+ */
+ public static final int SSL_CVERIFY_UNSET = UNSET;
+ public static final int SSL_CVERIFY_NONE = 0;
+ public static final int SSL_CVERIFY_OPTIONAL = 1;
+ public static final int SSL_CVERIFY_REQUIRE = 2;
+ public static final int SSL_CVERIFY_OPTIONAL_NO_CA = 3;
+
+ /* Use either SSL_VERIFY_NONE or SSL_VERIFY_PEER, the last 2 options
+ * are 'ored' with SSL_VERIFY_PEER if they are desired
+ */
+ public static final int SSL_VERIFY_NONE = 0;
+ public static final int SSL_VERIFY_PEER = 1;
+ public static final int SSL_VERIFY_FAIL_IF_NO_PEER_CERT = 2;
+ public static final int SSL_VERIFY_CLIENT_ONCE = 4;
+ public static final int SSL_VERIFY_PEER_STRICT = (SSL_VERIFY_PEER|SSL_VERIFY_FAIL_IF_NO_PEER_CERT);
+
+ public static final int SSL_OP_MICROSOFT_SESS_ID_BUG = 0x00000001;
+ public static final int SSL_OP_NETSCAPE_CHALLENGE_BUG = 0x00000002;
+ public static final int SSL_OP_NETSCAPE_REUSE_CIPHER_CHANGE_BUG = 0x00000008;
+ public static final int SSL_OP_SSLREF2_REUSE_CERT_TYPE_BUG = 0x00000010;
+ public static final int SSL_OP_MICROSOFT_BIG_SSLV3_BUFFER = 0x00000020;
+ public static final int SSL_OP_MSIE_SSLV2_RSA_PADDING = 0x00000040;
+ public static final int SSL_OP_SSLEAY_080_CLIENT_DH_BUG = 0x00000080;
+ public static final int SSL_OP_TLS_D5_BUG = 0x00000100;
+ public static final int SSL_OP_TLS_BLOCK_PADDING_BUG = 0x00000200;
+
+ /* Disable SSL 3.0/TLS 1.0 CBC vulnerability workaround that was added
+ * in OpenSSL 0.9.6d. Usually (depending on the application protocol)
+ * the workaround is not needed. Unfortunately some broken SSL/TLS
+ * implementations cannot handle it at all, which is why we include
+ * it in SSL_OP_ALL. */
+ public static final int SSL_OP_DONT_INSERT_EMPTY_FRAGMENTS = 0x00000800;
+
+ /* SSL_OP_ALL: various bug workarounds that should be rather harmless.
+ * This used to be 0x000FFFFFL before 0.9.7. */
+ public static final int SSL_OP_ALL = 0x00000FFF;
+ /* As server, disallow session resumption on renegotiation */
+ public static final int SSL_OP_NO_SESSION_RESUMPTION_ON_RENEGOTIATION = 0x00010000;
+ /* Don't use compression even if supported */
+ public static final int SSL_OP_NO_COMPRESSION = 0x00020000;
+ /* Permit unsafe legacy renegotiation */
+ public static final int SSL_OP_ALLOW_UNSAFE_LEGACY_RENEGOTIATION = 0x00040000;
+ /* If set, always create a new key when using tmp_eddh parameters */
+ public static final int SSL_OP_SINGLE_ECDH_USE = 0x00080000;
+ /* If set, always create a new key when using tmp_dh parameters */
+ public static final int SSL_OP_SINGLE_DH_USE = 0x00100000;
+ /* Set to always use the tmp_rsa key when doing RSA operations,
+ * even when this violates protocol specs */
+ public static final int SSL_OP_EPHEMERAL_RSA = 0x00200000;
+ /* Set on servers to choose the cipher according to the server's
+ * preferences */
+ public static final int SSL_OP_CIPHER_SERVER_PREFERENCE = 0x00400000;
+ /* If set, a server will allow a client to issue a SSLv3.0 version number
+ * as latest version supported in the premaster secret, even when TLSv1.0
+ * (version 3.1) was announced in the client hello. Normally this is
+ * forbidden to prevent version rollback attacks. */
+ public static final int SSL_OP_TLS_ROLLBACK_BUG = 0x00800000;
+
+ public static final int SSL_OP_NO_SSLv2 = 0x01000000;
+ public static final int SSL_OP_NO_SSLv3 = 0x02000000;
+ public static final int SSL_OP_NO_TLSv1 = 0x04000000;
+ public static final int SSL_OP_NO_TICKET = 0x00004000;
+
+ /* The next flag deliberately changes the ciphertest, this is a check
+ * for the PKCS#1 attack */
+ public static final int SSL_OP_PKCS1_CHECK_1 = 0x08000000;
+ public static final int SSL_OP_PKCS1_CHECK_2 = 0x10000000;
+ public static final int SSL_OP_NETSCAPE_CA_DN_BUG = 0x20000000;
+ public static final int SSL_OP_NETSCAPE_DEMO_CIPHER_CHANGE_BUG = 0x40000000;
+
+ public static final int SSL_CRT_FORMAT_UNDEF = 0;
+ public static final int SSL_CRT_FORMAT_ASN1 = 1;
+ public static final int SSL_CRT_FORMAT_TEXT = 2;
+ public static final int SSL_CRT_FORMAT_PEM = 3;
+ public static final int SSL_CRT_FORMAT_NETSCAPE = 4;
+ public static final int SSL_CRT_FORMAT_PKCS12 = 5;
+ public static final int SSL_CRT_FORMAT_SMIME = 6;
+ public static final int SSL_CRT_FORMAT_ENGINE = 7;
+
+ public static final int SSL_MODE_CLIENT = 0;
+ public static final int SSL_MODE_SERVER = 1;
+ public static final int SSL_MODE_COMBINED = 2;
+
+ public static final int SSL_SHUTDOWN_TYPE_UNSET = 0;
+ public static final int SSL_SHUTDOWN_TYPE_STANDARD = 1;
+ public static final int SSL_SHUTDOWN_TYPE_UNCLEAN = 2;
+ public static final int SSL_SHUTDOWN_TYPE_ACCURATE = 3;
+
+ public static final int SSL_INFO_SESSION_ID = 0x0001;
+ public static final int SSL_INFO_CIPHER = 0x0002;
+ public static final int SSL_INFO_CIPHER_USEKEYSIZE = 0x0003;
+ public static final int SSL_INFO_CIPHER_ALGKEYSIZE = 0x0004;
+ public static final int SSL_INFO_CIPHER_VERSION = 0x0005;
+ public static final int SSL_INFO_CIPHER_DESCRIPTION = 0x0006;
+ public static final int SSL_INFO_PROTOCOL = 0x0007;
+
+ /* To obtain the CountryName of the Client Certificate Issuer
+ * use the SSL_INFO_CLIENT_I_DN + SSL_INFO_DN_COUNTRYNAME
+ */
+ public static final int SSL_INFO_CLIENT_S_DN = 0x0010;
+ public static final int SSL_INFO_CLIENT_I_DN = 0x0020;
+ public static final int SSL_INFO_SERVER_S_DN = 0x0040;
+ public static final int SSL_INFO_SERVER_I_DN = 0x0080;
+
+ public static final int SSL_INFO_DN_COUNTRYNAME = 0x0001;
+ public static final int SSL_INFO_DN_STATEORPROVINCENAME = 0x0002;
+ public static final int SSL_INFO_DN_LOCALITYNAME = 0x0003;
+ public static final int SSL_INFO_DN_ORGANIZATIONNAME = 0x0004;
+ public static final int SSL_INFO_DN_ORGANIZATIONALUNITNAME = 0x0005;
+ public static final int SSL_INFO_DN_COMMONNAME = 0x0006;
+ public static final int SSL_INFO_DN_TITLE = 0x0007;
+ public static final int SSL_INFO_DN_INITIALS = 0x0008;
+ public static final int SSL_INFO_DN_GIVENNAME = 0x0009;
+ public static final int SSL_INFO_DN_SURNAME = 0x000A;
+ public static final int SSL_INFO_DN_DESCRIPTION = 0x000B;
+ public static final int SSL_INFO_DN_UNIQUEIDENTIFIER = 0x000C;
+ public static final int SSL_INFO_DN_EMAILADDRESS = 0x000D;
+
+ public static final int SSL_INFO_CLIENT_M_VERSION = 0x0101;
+ public static final int SSL_INFO_CLIENT_M_SERIAL = 0x0102;
+ public static final int SSL_INFO_CLIENT_V_START = 0x0103;
+ public static final int SSL_INFO_CLIENT_V_END = 0x0104;
+ public static final int SSL_INFO_CLIENT_A_SIG = 0x0105;
+ public static final int SSL_INFO_CLIENT_A_KEY = 0x0106;
+ public static final int SSL_INFO_CLIENT_CERT = 0x0107;
+ public static final int SSL_INFO_CLIENT_V_REMAIN = 0x0108;
+
+ public static final int SSL_INFO_SERVER_M_VERSION = 0x0201;
+ public static final int SSL_INFO_SERVER_M_SERIAL = 0x0202;
+ public static final int SSL_INFO_SERVER_V_START = 0x0203;
+ public static final int SSL_INFO_SERVER_V_END = 0x0204;
+ public static final int SSL_INFO_SERVER_A_SIG = 0x0205;
+ public static final int SSL_INFO_SERVER_A_KEY = 0x0206;
+ public static final int SSL_INFO_SERVER_CERT = 0x0207;
+ /* Return client certificate chain.
+ * Add certificate chain number to that flag (0 ... verify depth)
+ */
+ public static final int SSL_INFO_CLIENT_CERT_CHAIN = 0x0400;
+ /* Return OpenSSL version number */
+ public static native int version();
+
+ /* Return OpenSSL version string */
+ public static native String versionString();
+
+ /**
+ * Initialize OpenSSL support.
+ * This function needs to be called once for the
+ * lifetime of JVM. Library.init() has to be called before.
+ * @param engine Support for external a Crypto Device ("engine"),
+ * usually
+ * a hardware accelerator card for crypto operations.
+ * @return APR status code
+ */
+ public static native int initialize(String engine);
+
+ /**
+ * Enable/Disable FIPS Mode.
+ *
+ * @param mode 1 - enable, 0 - disable
+ *
+ * @return FIPS_mode_set return code
+ */
+ public static native int fipsModeSet(int mode);
+
+ /**
+ * Add content of the file to the PRNG
+ * @param filename Filename containing random data.
+ * If null the default file will be tested.
+ * The seed file is $RANDFILE if that environment variable is
+ * set, $HOME/.rnd otherwise.
+ * In case both files are unavailable builtin
+ * random seed generator is used.
+ */
+ public static native boolean randLoad(String filename);
+
+ /**
+ * Writes a number of random bytes (currently 1024) to
+ * file <code>filename</code> which can be used to initialize the PRNG
+ * by calling randLoad in a later session.
+ * @param filename Filename to save the data
+ */
+ public static native boolean randSave(String filename);
+
+ /**
+ * Creates random data to filename
+ * @param filename Filename to save the data
+ * @param len The length of random sequence in bytes
+ * @param base64 Output the data in Base64 encoded format
+ */
+ public static native boolean randMake(String filename, int len,
+ boolean base64);
+
+ /**
+ * Sets global random filename.
+ * @param filename Filename to use.
+ * If set it will be used for SSL initialization
+ * and all contexts where explicitly not set.
+ */
+ public static native void randSet(String filename);
+
+ /**
+ * Initialize new BIO
+ * @param pool The pool to use.
+ * @param callback BIOCallback to use
+ * @return New BIO handle
+ */
+ public static native long newBIO(long pool, BIOCallback callback)
+ throws Exception;
+
+ /**
+ * Close BIO and dereference callback object
+ * @param bio BIO to close and destroy.
+ * @return APR Status code
+ */
+ public static native int closeBIO(long bio);
+
+ /**
+ * Set global Password callback for obtaining passwords.
+ * @param callback PasswordCallback implementation to use.
+ */
+ public static native void setPasswordCallback(PasswordCallback callback);
+
+ /**
+ * Set global Password for decrypting certificates and keys.
+ * @param password Password to use.
+ */
+ public static native void setPassword(String password);
+
+ /**
+ * Generate temporary RSA key.
+ * <br />
+ * Index can be one of:
+ * <PRE>
+ * SSL_TMP_KEY_RSA_512
+ * SSL_TMP_KEY_RSA_1024
+ * SSL_TMP_KEY_RSA_2048
+ * SSL_TMP_KEY_RSA_4096
+ * </PRE>
+ * By default 512 and 1024 keys are generated on startup.
+ * You can use a low priority thread to generate them on the fly.
+ * @param idx temporary key index.
+ */
+ public static native boolean generateRSATempKey(int idx);
+
+ /**
+ * Load temporary DSA key from file
+ * <br />
+ * Index can be one of:
+ * <PRE>
+ * SSL_TMP_KEY_DH_512
+ * SSL_TMP_KEY_DH_1024
+ * SSL_TMP_KEY_DH_2048
+ * SSL_TMP_KEY_DH_4096
+ * </PRE>
+ * @param idx temporary key index.
+ * @param file File containing DH params.
+ */
+ public static native boolean loadDSATempKey(int idx, String file);
+
+ /**
+ * Return last SSL error string
+ */
+ public static native String getLastError();
+
+ /**
+ * Return true if all the requested SSL_OP_* are supported by OpenSSL.
+ *
+ * <i>Note that for versions of tcnative < 1.1.25, this method will
+ * return <code>true</code> if and only if <code>op</code>=
+ * {@link #SSL_OP_ALLOW_UNSAFE_LEGACY_RENEGOTIATION} and tcnative
+ * supports that flag.</i>
+ *
+ * @param op Bitwise-OR of all SSL_OP_* to test.
+ *
+ * @return true if all SSL_OP_* are supported by OpenSSL library.
+ */
+ public static native boolean hasOp(int op);
+}
diff --git a/jni/java/org/apache/tomcat/jni/SSLContext.java b/jni/java/org/apache/tomcat/jni/SSLContext.java
new file mode 100644
index 0000000..c97790f
--- /dev/null
+++ b/jni/java/org/apache/tomcat/jni/SSLContext.java
@@ -0,0 +1,289 @@
+/*
+ * 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.
+ */
+
+package org.apache.tomcat.jni;
+
+/** SSL Context
+ *
+ * @author Mladen Turk
+ */
+public final class SSLContext {
+
+
+ /**
+ * Initialize new SSL context
+ * @param pool The pool to use.
+ * @param protocol The SSL protocol to use. It can be one of:
+ * <PRE>
+ * SSL_PROTOCOL_SSLV2
+ * SSL_PROTOCOL_SSLV3
+ * SSL_PROTOCOL_SSLV2 | SSL_PROTOCOL_SSLV3
+ * SSL_PROTOCOL_TLSV1
+ * SSL_PROTOCOL_ALL
+ * </PRE>
+ * @param mode SSL mode to use
+ * <PRE>
+ * SSL_MODE_CLIENT
+ * SSL_MODE_SERVER
+ * SSL_MODE_COMBINED
+ * </PRE>
+ */
+ public static native long make(long pool, int protocol, int mode)
+ throws Exception;
+
+ /**
+ * Free the resources used by the Context
+ * @param ctx Server or Client context to free.
+ * @return APR Status code.
+ */
+ public static native int free(long ctx);
+
+ /**
+ * Set Session context id. Usually host:port combination.
+ * @param ctx Context to use.
+ * @param id String that uniquely identifies this context.
+ */
+ public static native void setContextId(long ctx, String id);
+
+ /**
+ * Associate BIOCallback for input or output data capture.
+ * <br />
+ * First word in the output string will contain error
+ * level in the form:
+ * <PRE>
+ * [ERROR] -- Critical error messages
+ * [WARN] -- Warning messages
+ * [INFO] -- Informational messages
+ * [DEBUG] -- Debugging messaged
+ * </PRE>
+ * Callback can use that word to determine application logging level
+ * by intercepting <b>write</b> call.
+ * If the <b>bio</b> is set to 0 no error messages will be displayed.
+ * Default is to use the stderr output stream.
+ * @param ctx Server or Client context to use.
+ * @param bio BIO handle to use, created with SSL.newBIO
+ * @param dir BIO direction (1 for input 0 for output).
+ */
+ public static native void setBIO(long ctx, long bio, int dir);
+
+ /**
+ * Set OpenSSL Option.
+ * @param ctx Server or Client context to use.
+ * @param options See SSL.SSL_OP_* for option flags.
+ */
+ public static native void setOptions(long ctx, int options);
+
+ /**
+ * Clears OpenSSL Options.
+ * @param ctx Server or Client context to use.
+ * @param options See SSL.SSL_OP_* for option flags.
+ */
+ public static native void clearOptions(long ctx, int options);
+
+ /**
+ * Sets the "quiet shutdown" flag for <b>ctx</b> to be
+ * <b>mode</b>. SSL objects created from <b>ctx</b> inherit the
+ * <b>mode</b> valid at the time and may be 0 or 1.
+ * <br />
+ * Normally when a SSL connection is finished, the parties must send out
+ * "close notify" alert messages using L<SSL_shutdown(3)|SSL_shutdown(3)>
+ * for a clean shutdown.
+ * <br />
+ * When setting the "quiet shutdown" flag to 1, <b>SSL.shutdown</b>
+ * will set the internal flags to SSL_SENT_SHUTDOWN|SSL_RECEIVED_SHUTDOWN.
+ * (<b>SSL_shutdown</b> then behaves like called with
+ * SSL_SENT_SHUTDOWN|SSL_RECEIVED_SHUTDOWN.)
+ * The session is thus considered to be shutdown, but no "close notify" alert
+ * is sent to the peer. This behaviour violates the TLS standard.
+ * The default is normal shutdown behaviour as described by the TLS standard.
+ * @param ctx Server or Client context to use.
+ * @param mode True to set the quiet shutdown.
+ */
+ public static native void setQuietShutdown(long ctx, boolean mode);
+
+ /**
+ * Cipher Suite available for negotiation in SSL handshake.
+ * <br />
+ * This complex directive uses a colon-separated cipher-spec string consisting
+ * of OpenSSL cipher specifications to configure the Cipher Suite the client
+ * is permitted to negotiate in the SSL handshake phase. Notice that this
+ * directive can be used both in per-server and per-directory context.
+ * In per-server context it applies to the standard SSL handshake when a
+ * connection is established. In per-directory context it forces a SSL
+ * renegotiation with the reconfigured Cipher Suite after the HTTP request
+ * was read but before the HTTP response is sent.
+ * @param ctx Server or Client context to use.
+ * @param ciphers An SSL cipher specification.
+ */
+ public static native boolean setCipherSuite(long ctx, String ciphers)
+ throws Exception;
+
+ /**
+ * Set File of concatenated PEM-encoded CA CRLs or
+ * directory of PEM-encoded CA Certificates for Client Auth
+ * <br />
+ * This directive sets the all-in-one file where you can assemble the
+ * Certificate Revocation Lists (CRL) of Certification Authorities (CA)
+ * whose clients you deal with. These are used for Client Authentication.
+ * Such a file is simply the concatenation of the various PEM-encoded CRL
+ * files, in order of preference.
+ * <br />
+ * The files in this directory have to be PEM-encoded and are accessed through
+ * hash filenames. So usually you can't just place the Certificate files there:
+ * you also have to create symbolic links named hash-value.N. And you should
+ * always make sure this directory contains the appropriate symbolic links.
+ * Use the Makefile which comes with mod_ssl to accomplish this task.
+ * @param ctx Server or Client context to use.
+ * @param file File of concatenated PEM-encoded CA CRLs for Client Auth.
+ * @param path Directory of PEM-encoded CA Certificates for Client Auth.
+ */
+ public static native boolean setCARevocation(long ctx, String file,
+ String path)
+ throws Exception;
+
+ /**
+ * Set File of PEM-encoded Server CA Certificates
+ * <br />
+ * This directive sets the optional all-in-one file where you can assemble the
+ * certificates of Certification Authorities (CA) which form the certificate
+ * chain of the server certificate. This starts with the issuing CA certificate
+ * of of the server certificate and can range up to the root CA certificate.
+ * Such a file is simply the concatenation of the various PEM-encoded CA
+ * Certificate files, usually in certificate chain order.
+ * <br />
+ * But be careful: Providing the certificate chain works only if you are using
+ * a single (either RSA or DSA) based server certificate. If you are using a
+ * coupled RSA+DSA certificate pair, this will work only if actually both
+ * certificates use the same certificate chain. Else the browsers will be
+ * confused in this situation.
+ * @param ctx Server or Client context to use.
+ * @param file File of PEM-encoded Server CA Certificates.
+ * @param skipfirst Skip first certificate if chain file is inside
+ * certificate file.
+ */
+ public static native boolean setCertificateChainFile(long ctx, String file,
+ boolean skipfirst);
+
+ /**
+ * Set Certificate
+ * <br />
+ * Point setCertificateFile at a PEM encoded certificate. If
+ * the certificate is encrypted, then you will be prompted for a
+ * pass phrase. Note that a kill -HUP will prompt again. A test
+ * certificate can be generated with `make certificate' under
+ * built time. Keep in mind that if you've both a RSA and a DSA
+ * certificate you can configure both in parallel (to also allow
+ * the use of DSA ciphers, etc.)
+ * <br />
+ * If the key is not combined with the certificate, use key param
+ * to point at the key file. Keep in mind that if
+ * you've both a RSA and a DSA private key you can configure
+ * both in parallel (to also allow the use of DSA ciphers, etc.)
+ * @param ctx Server or Client context to use.
+ * @param cert Certificate file.
+ * @param key Private Key file to use if not in cert.
+ * @param password Certificate password. If null and certificate
+ * is encrypted, password prompt will be displayed.
+ * @param idx Certificate index SSL_AIDX_RSA or SSL_AIDX_DSA.
+ */
+ public static native boolean setCertificate(long ctx, String cert,
+ String key, String password,
+ int idx)
+ throws Exception;
+
+ /**
+ * Set File and Directory of concatenated PEM-encoded CA Certificates
+ * for Client Auth
+ * <br />
+ * This directive sets the all-in-one file where you can assemble the
+ * Certificates of Certification Authorities (CA) whose clients you deal with.
+ * These are used for Client Authentication. Such a file is simply the
+ * concatenation of the various PEM-encoded Certificate files, in order of
+ * preference. This can be used alternatively and/or additionally to
+ * path.
+ * <br />
+ * The files in this directory have to be PEM-encoded and are accessed through
+ * hash filenames. So usually you can't just place the Certificate files there:
+ * you also have to create symbolic links named hash-value.N. And you should
+ * always make sure this directory contains the appropriate symbolic links.
+ * Use the Makefile which comes with mod_ssl to accomplish this task.
+ * @param ctx Server or Client context to use.
+ * @param file File of concatenated PEM-encoded CA Certificates for
+ * Client Auth.
+ * @param path Directory of PEM-encoded CA Certificates for Client Auth.
+ */
+ public static native boolean setCACertificate(long ctx, String file,
+ String path)
+ throws Exception;
+
+ /**
+ * Set file for randomness
+ * @param ctx Server or Client context to use.
+ * @param file random file.
+ */
+ public static native void setRandom(long ctx, String file);
+
+ /**
+ * Set SSL connection shutdown type
+ * <br />
+ * The following levels are available for level:
+ * <PRE>
+ * SSL_SHUTDOWN_TYPE_STANDARD
+ * SSL_SHUTDOWN_TYPE_UNCLEAN
+ * SSL_SHUTDOWN_TYPE_ACCURATE
+ * </PRE>
+ * @param ctx Server or Client context to use.
+ * @param type Shutdown type to use.
+ */
+ public static native void setShutdownType(long ctx, int type);
+
+ /**
+ * Set Type of Client Certificate verification and Maximum depth of CA Certificates
+ * in Client Certificate verification.
+ * <br />
+ * This directive sets the Certificate verification level for the Client
+ * Authentication. Notice that this directive can be used both in per-server
+ * and per-directory context. In per-server context it applies to the client
+ * authentication process used in the standard SSL handshake when a connection
+ * is established. In per-directory context it forces a SSL renegotiation with
+ * the reconfigured client verification level after the HTTP request was read
+ * but before the HTTP response is sent.
+ * <br />
+ * The following levels are available for level:
+ * <PRE>
+ * SSL_CVERIFY_NONE - No client Certificate is required at all
+ * SSL_CVERIFY_OPTIONAL - The client may present a valid Certificate
+ * SSL_CVERIFY_REQUIRE - The client has to present a valid Certificate
+ * SSL_CVERIFY_OPTIONAL_NO_CA - The client may present a valid Certificate
+ * but it need not to be (successfully) verifiable
+ * </PRE>
+ * <br />
+ * The depth actually is the maximum number of intermediate certificate issuers,
+ * i.e. the number of CA certificates which are max allowed to be followed while
+ * verifying the client certificate. A depth of 0 means that self-signed client
+ * certificates are accepted only, the default depth of 1 means the client
+ * certificate can be self-signed or has to be signed by a CA which is directly
+ * known to the server (i.e. the CA's certificate is under
+ * <code>setCACertificatePath</code>), etc.
+ * @param ctx Server or Client context to use.
+ * @param level Type of Client Certificate verification.
+ * @param depth Maximum depth of CA Certificates in Client Certificate
+ * verification.
+ */
+ public static native void setVerify(long ctx, int level, int depth);
+
+}
diff --git a/jni/java/org/apache/tomcat/jni/SSLExt.java b/jni/java/org/apache/tomcat/jni/SSLExt.java
new file mode 100644
index 0000000..e794de0
--- /dev/null
+++ b/jni/java/org/apache/tomcat/jni/SSLExt.java
@@ -0,0 +1,159 @@
+/*
+ * 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.
+ */
+package org.apache.tomcat.jni;
+
+/**
+ * Support TLS extensions and extra methods.
+ *
+ * The methods are separated to make it easier for java code to
+ * support existing native library - it can check if this class can
+ * be loaded in order to use the exensions.
+ *
+ * @author Costin Manolache
+ */
+public final class SSLExt {
+
+
+ /**
+ * Set advertised NPN protocol.
+ * This is only available for recent or patched openssl.
+ *
+ * Example: "\x06spdy/2"
+ *
+ * Works with TLS1, doesn't with SSL2/SSL3
+ *
+ * Servers sends list in ServerHelo, client selects it and
+ * sends it back after ChangeChipher
+ *
+ * Not supported in 1.0.0, seems to be in 1.0.1 and after
+ */
+ public static native int setNPN(long tcctx, byte[] proto, int len);
+
+ /**
+ * Get other side's advertised protocols.
+ * Only works after handshake.
+ */
+ public static native int getNPN(long tcsock, byte[] proto);
+
+ /**
+ * Enabling dump/debugging on the socket. Both raw and decrypted
+ * packets will be logged.
+ */
+ public static native int debug(long tcsock);
+
+ /**
+ * Server: Extract the session data associated with the socket.
+ * Must be saved, keyed by session ID.
+ */
+ public static native byte[] getSessionData(long tcsock);
+
+ /**
+ * Server: Set the session data for a socket.
+ */
+ public static native int setSessionData(long tcsock, byte[] data, int len);
+
+
+ /**
+ * Client: get the ticket received from server, if tickets are supported.
+ */
+ public static native int getTicket(long tcsock, byte[] resBuf);
+
+ /**
+ * Client: set the previously received ticket.
+ */
+ public static native int setTicket(long tcsock, byte[] data, int len);
+
+ /**
+ * Set the key used by server to generate tickets.
+ * Key must be 48 bytes.
+ */
+ public static native int setTicketKeys(long ctx, byte[] data, int len);
+
+ /**
+ * For client side calls. Data should be a \0 terminated string
+ */
+ public static native int setSNI(long tcsock, byte[] data, int len);
+
+ /**
+ * Return the last openssl error
+ */
+ public static native String sslErrReasonErrorString();
+
+ public static native long sslCtxSetMode(long ctx, long mode);
+
+ /* Allow SSL_write(..., n) to return r with 0 < r < n (i.e. report success
+ * when just a single record has been written): */
+ public static final int SSL_MODE_ENABLE_PARTIAL_WRITE = 0x1;
+
+ /* Make it possible to retry SSL_write() with changed buffer location
+ * (buffer contents must stay the same!); this is not the default to avoid
+ * the misconception that non-blocking SSL_write() behaves like
+ * non-blocking write(): */
+ public static final int SSL_MODE_ACCEPT_MOVING_WRITE_BUFFER = 0x2;
+
+ /* Don't attempt to automatically build certificate chain */
+ static final int SSL_MODE_NO_AUTO_CHAIN = 0x8;
+
+ /* Save RAM by releasing read and write buffers when they're empty. (SSL3 and
+ * TLS only.) "Released" buffers are put onto a free-list in the context
+ * or just freed (depending on the context's setting for freelist_max_len). */
+ public static final int SSL_MODE_RELEASE_BUFFERS = 0x10;
+
+ // 1.1
+ //static final int SSL_MODE_HANDSHAKE_CUTTHROUGH = ..;
+
+ /**
+ * SSL_set_mode
+ */
+ public static native long sslSetMode(long tcsock, long mode);
+
+ public static int setNPN(long sslContext, byte[] spdyNPN) {
+ try {
+ return SSLExt.setNPN(sslContext, spdyNPN, spdyNPN.length);
+ } catch (Throwable t) {
+ t.printStackTrace();
+ return -1;
+ }
+ }
+
+ /**
+ * Higher level method, checking if the specified protocol has been
+ * negotiated.
+ */
+ public static boolean checkNPN(long tcsocket, byte[] expected) {
+ byte[] npn = new byte[expected.length + 1];
+ int npnLen = 0;
+ try {
+ npnLen = SSLExt.getNPN(tcsocket, npn);
+ if (npnLen != expected.length) {
+ return false;
+ }
+ } catch (Throwable t) {
+ // ignore
+ return false;
+ }
+ for (int i = 0; i < expected.length; i++) {
+ if (expected[i] != npn[i]) {
+ return false;
+ }
+ }
+ return true;
+ }
+
+
+
+}
diff --git a/jni/java/org/apache/tomcat/jni/SSLSocket.java b/jni/java/org/apache/tomcat/jni/SSLSocket.java
new file mode 100644
index 0000000..bc7c2a7
--- /dev/null
+++ b/jni/java/org/apache/tomcat/jni/SSLSocket.java
@@ -0,0 +1,110 @@
+/*
+ * 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.
+ */
+
+package org.apache.tomcat.jni;
+
+/** SSL Socket
+ *
+ * @author Mladen Turk
+ */
+public class SSLSocket {
+
+ /**
+ * Attach APR socket on a SSL connection.
+ * @param ctx SSLContext to use.
+ * @param sock APR Socket that already did physical connect or accept.
+ * @return APR_STATUS code.
+ */
+ public static native int attach(long ctx, long sock)
+ throws Exception;
+
+ /**
+ * Do a SSL handshake.
+ * @param thesocket The socket to use
+ */
+ public static native int handshake(long thesocket);
+
+ /**
+ * Do a SSL renegotiation.
+ * SSL supports per-directory re-configuration of SSL parameters.
+ * This is implemented by performing an SSL renegotiation of the
+ * re-configured parameters after the request is read, but before the
+ * response is sent. In more detail: the renegotiation happens after the
+ * request line and MIME headers were read, but _before_ the attached
+ * request body is read. The reason simply is that in the HTTP protocol
+ * usually there is no acknowledgment step between the headers and the
+ * body (there is the 100-continue feature and the chunking facility
+ * only), so Apache has no API hook for this step.
+ *
+ * @param thesocket The socket to use
+ */
+ public static native int renegotiate(long thesocket);
+
+ /**
+ * Set Type of Client Certificate verification and Maximum depth of CA
+ * Certificates in Client Certificate verification.
+ * <br />
+ * This is used to change the verification level for a connection prior to
+ * starting a re-negotiation.
+ * <br />
+ * The following levels are available for level:
+ * <PRE>
+ * SSL_CVERIFY_NONE - No client Certificate is required at all
+ * SSL_CVERIFY_OPTIONAL - The client may present a valid Certificate
+ * SSL_CVERIFY_REQUIRE - The client has to present a valid
+ * Certificate
+ * SSL_CVERIFY_OPTIONAL_NO_CA - The client may present a valid Certificate
+ * but it need not to be (successfully)
+ * verifiable
+ * </PRE>
+ * <br />
+ * @param sock The socket to change.
+ * @param level Type of Client Certificate verification.
+ */
+ public static native void setVerify(long sock, int level, int depth);
+
+ /**
+ * Return SSL Info parameter as byte array.
+ *
+ * @param sock The socket to read the data from.
+ * @param id Parameter id.
+ * @return Byte array containing info id value.
+ */
+ public static native byte[] getInfoB(long sock, int id)
+ throws Exception;
+
+ /**
+ * Return SSL Info parameter as String.
+ *
+ * @param sock The socket to read the data from.
+ * @param id Parameter id.
+ * @return String containing info id value.
+ */
+ public static native String getInfoS(long sock, int id)
+ throws Exception;
+
+ /**
+ * Return SSL Info parameter as integer.
+ *
+ * @param sock The socket to read the data from.
+ * @param id Parameter id.
+ * @return Integer containing info id value or -1 on error.
+ */
+ public static native int getInfoI(long sock, int id)
+ throws Exception;
+
+}
diff --git a/jni/java/org/apache/tomcat/jni/Shm.java b/jni/java/org/apache/tomcat/jni/Shm.java
new file mode 100644
index 0000000..c8df841
--- /dev/null
+++ b/jni/java/org/apache/tomcat/jni/Shm.java
@@ -0,0 +1,122 @@
+/*
+ * 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.
+ */
+
+package org.apache.tomcat.jni;
+
+import java.nio.ByteBuffer;
+
+/** Shm
+ *
+ * @author Mladen Turk
+ */
+public class Shm {
+
+ /**
+ * Create and make accessible a shared memory segment.
+ * <br />
+ * A note about Anonymous vs. Named shared memory segments:<br />
+ * Not all platforms support anonymous shared memory segments, but in
+ * some cases it is preferred over other types of shared memory
+ * implementations. Passing a NULL 'file' parameter to this function
+ * will cause the subsystem to use anonymous shared memory segments.
+ * If such a system is not available, APR_ENOTIMPL is returned.
+ * <br />
+ * A note about allocation sizes:<br />
+ * On some platforms it is necessary to store some metainformation
+ * about the segment within the actual segment. In order to supply
+ * the caller with the requested size it may be necessary for the
+ * implementation to request a slightly greater segment length
+ * from the subsystem. In all cases, the apr_shm_baseaddr_get()
+ * function will return the first usable byte of memory.
+ * @param reqsize The desired size of the segment.
+ * @param filename The file to use for shared memory on platforms that
+ * require it.
+ * @param pool the pool from which to allocate the shared memory
+ * structure.
+ * @return The created shared memory structure.
+ *
+ */
+ public static native long create(long reqsize, String filename, long pool)
+ throws Error;
+
+ /**
+ * Remove shared memory segment associated with a filename.
+ * <br />
+ * This function is only supported on platforms which support
+ * name-based shared memory segments, and will return APR_ENOTIMPL on
+ * platforms without such support.
+ * @param filename The filename associated with shared-memory segment which
+ * needs to be removed
+ * @param pool The pool used for file operations
+ */
+ public static native int remove(String filename, long pool);
+
+ /**
+ * Destroy a shared memory segment and associated memory.
+ * @param m The shared memory segment structure to destroy.
+ */
+ public static native int destroy(long m);
+
+ /**
+ * Attach to a shared memory segment that was created
+ * by another process.
+ * @param filename The file used to create the original segment.
+ * (This MUST match the original filename.)
+ * @param pool the pool from which to allocate the shared memory
+ * structure for this process.
+ * @return The created shared memory structure.
+ */
+ public static native long attach(String filename, long pool)
+ throws Error;
+
+ /**
+ * Detach from a shared memory segment without destroying it.
+ * @param m The shared memory structure representing the segment
+ * to detach from.
+ */
+ public static native int detach(long m);
+
+ /**
+ * Retrieve the base address of the shared memory segment.
+ * NOTE: This address is only usable within the callers address
+ * space, since this API does not guarantee that other attaching
+ * processes will maintain the same address mapping.
+ * @param m The shared memory segment from which to retrieve
+ * the base address.
+ * @return address, aligned by APR_ALIGN_DEFAULT.
+ */
+ public static native long baseaddr(long m);
+
+ /**
+ * Retrieve the length of a shared memory segment in bytes.
+ * @param m The shared memory segment from which to retrieve
+ * the segment length.
+ */
+ public static native long size(long m);
+
+ /**
+ * Retrieve new ByteBuffer base address of the shared memory segment.
+ * NOTE: This address is only usable within the callers address
+ * space, since this API does not guarantee that other attaching
+ * processes will maintain the same address mapping.
+ * @param m The shared memory segment from which to retrieve
+ * the base address.
+ * @return address, aligned by APR_ALIGN_DEFAULT.
+ */
+ public static native ByteBuffer buffer(long m);
+
+}
diff --git a/jni/java/org/apache/tomcat/jni/Sockaddr.java b/jni/java/org/apache/tomcat/jni/Sockaddr.java
new file mode 100644
index 0000000..f5262a7
--- /dev/null
+++ b/jni/java/org/apache/tomcat/jni/Sockaddr.java
@@ -0,0 +1,40 @@
+/*
+ * 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.
+ */
+
+package org.apache.tomcat.jni;
+
+/** Sockaddr
+ *
+ * @author Mladen Turk
+ */
+public class Sockaddr {
+
+ /** The pool to use... */
+ public long pool;
+ /** The hostname */
+ public String hostname;
+ /** Either a string of the port number or the service name for the port */
+ public String servname;
+ /** The numeric port */
+ public int port;
+ /** The family */
+ public int family;
+ /** If multiple addresses were found by apr_sockaddr_info_get(), this
+ * points to a representation of the next address. */
+ public long next;
+
+}
diff --git a/jni/java/org/apache/tomcat/jni/Socket.java b/jni/java/org/apache/tomcat/jni/Socket.java
new file mode 100644
index 0000000..1a220a2
--- /dev/null
+++ b/jni/java/org/apache/tomcat/jni/Socket.java
@@ -0,0 +1,584 @@
+/*
+ * 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.
+ */
+
+package org.apache.tomcat.jni;
+
+/* Import needed classes */
+import java.nio.ByteBuffer;
+
+/** Socket
+ *
+ * @author Mladen Turk
+ */
+public class Socket {
+
+ /* Standard socket defines */
+ public static final int SOCK_STREAM = 0;
+ public static final int SOCK_DGRAM = 1;
+ /*
+ * apr_sockopt Socket option definitions
+ */
+ public static final int APR_SO_LINGER = 1; /** Linger */
+ public static final int APR_SO_KEEPALIVE = 2; /** Keepalive */
+ public static final int APR_SO_DEBUG = 4; /** Debug */
+ public static final int APR_SO_NONBLOCK = 8; /** Non-blocking IO */
+ public static final int APR_SO_REUSEADDR = 16; /** Reuse addresses */
+ public static final int APR_SO_SNDBUF = 64; /** Send buffer */
+ public static final int APR_SO_RCVBUF = 128; /** Receive buffer */
+ public static final int APR_SO_DISCONNECTED = 256; /** Disconnected */
+ /** For SCTP sockets, this is mapped to STCP_NODELAY internally. */
+ public static final int APR_TCP_NODELAY = 512;
+ public static final int APR_TCP_NOPUSH = 1024; /** No push */
+ /** This flag is ONLY set internally when we set APR_TCP_NOPUSH with
+ * APR_TCP_NODELAY set to tell us that APR_TCP_NODELAY should be turned on
+ * again when NOPUSH is turned off
+ */
+ public static final int APR_RESET_NODELAY = 2048;
+ /** Set on non-blocking sockets (timeout != 0) on which the
+ * previous read() did not fill a buffer completely. the next
+ * apr_socket_recv() will first call select()/poll() rather than
+ * going straight into read(). (Can also be set by an application to
+ * force a select()/poll() call before the next read, in cases where
+ * the app expects that an immediate read would fail.)
+ */
+ public static final int APR_INCOMPLETE_READ = 4096;
+ /** like APR_INCOMPLETE_READ, but for write
+ */
+ public static final int APR_INCOMPLETE_WRITE = 8192;
+ /** Don't accept IPv4 connections on an IPv6 listening socket.
+ */
+ public static final int APR_IPV6_V6ONLY = 16384;
+ /** Delay accepting of new connections until data is available.
+ */
+ public static final int APR_TCP_DEFER_ACCEPT = 32768;
+
+ /** Define what type of socket shutdown should occur.
+ * apr_shutdown_how_e enum
+ */
+ public static final int APR_SHUTDOWN_READ = 0; /** no longer allow read request */
+ public static final int APR_SHUTDOWN_WRITE = 1; /** no longer allow write requests */
+ public static final int APR_SHUTDOWN_READWRITE = 2; /** no longer allow read or write requests */
+
+ public static final int APR_IPV4_ADDR_OK = 0x01;
+ public static final int APR_IPV6_ADDR_OK = 0x02;
+
+ /* TODO: Missing:
+ * APR_INET
+ * APR_UNSPEC
+ * APR_INET6
+ */
+ public static final int APR_UNSPEC = 0;
+ public static final int APR_INET = 1;
+ public static final int APR_INET6 = 2;
+
+ public static final int APR_PROTO_TCP = 6; /** TCP */
+ public static final int APR_PROTO_UDP = 17; /** UDP */
+ public static final int APR_PROTO_SCTP = 132; /** SCTP */
+
+ /**
+ * Enum to tell us if we're interested in remote or local socket
+ * apr_interface_e
+ */
+ public static final int APR_LOCAL = 0;
+ public static final int APR_REMOTE = 1;
+
+ /* Socket.get types */
+ public static final int SOCKET_GET_POOL = 0;
+ public static final int SOCKET_GET_IMPL = 1;
+ public static final int SOCKET_GET_APRS = 2;
+ public static final int SOCKET_GET_TYPE = 3;
+
+ /**
+ * Create a socket.
+ * @param family The address family of the socket (e.g., APR_INET).
+ * @param type The type of the socket (e.g., SOCK_STREAM).
+ * @param protocol The protocol of the socket (e.g., APR_PROTO_TCP).
+ * @param cont The parent pool to use
+ * @return The new socket that has been set up.
+ */
+ public static native long create(int family, int type,
+ int protocol, long cont)
+ throws Exception;
+
+
+ /**
+ * Shutdown either reading, writing, or both sides of a socket.
+ * <br />
+ * This does not actually close the socket descriptor, it just
+ * controls which calls are still valid on the socket.
+ * @param thesocket The socket to close
+ * @param how How to shutdown the socket. One of:
+ * <PRE>
+ * APR_SHUTDOWN_READ no longer allow read requests
+ * APR_SHUTDOWN_WRITE no longer allow write requests
+ * APR_SHUTDOWN_READWRITE no longer allow read or write requests
+ * </PRE>
+ */
+ public static native int shutdown(long thesocket, int how);
+
+ /**
+ * Close a socket.
+ * @param thesocket The socket to close
+ */
+ public static native int close(long thesocket);
+
+ /**
+ * Destroy a pool associated with socket
+ * @param thesocket The destroy
+ */
+ public static native void destroy(long thesocket);
+
+ /**
+ * Bind the socket to its associated port
+ * @param sock The socket to bind
+ * @param sa The socket address to bind to
+ * This may be where we will find out if there is any other process
+ * using the selected port.
+ */
+ public static native int bind(long sock, long sa);
+
+ /**
+ * Listen to a bound socket for connections.
+ * @param sock The socket to listen on
+ * @param backlog The number of outstanding connections allowed in the sockets
+ * listen queue. If this value is less than zero, the listen
+ * queue size is set to zero.
+ */
+ public static native int listen(long sock, int backlog);
+
+ /**
+ * Accept a new connection request
+ * @param sock The socket we are listening on.
+ * @param pool The pool for the new socket.
+ * @return A copy of the socket that is connected to the socket that
+ * made the connection request. This is the socket which should
+ * be used for all future communication.
+ */
+ public static native long acceptx(long sock, long pool)
+ throws Exception;
+
+ /**
+ * Accept a new connection request
+ * @param sock The socket we are listening on.
+ * @return A copy of the socket that is connected to the socket that
+ * made the connection request. This is the socket which should
+ * be used for all future communication.
+ */
+ public static native long accept(long sock)
+ throws Exception;
+
+ /**
+ * Set an OS level accept filter.
+ * @param sock The socket to put the accept filter on.
+ * @param name The accept filter
+ * @param args Any extra args to the accept filter. Passing NULL here removes
+ * the accept filter.
+ */
+ public static native int acceptfilter(long sock, String name, String args);
+
+ /**
+ * Query the specified socket if at the OOB/Urgent data mark
+ * @param sock The socket to query
+ * @return True if socket is at the OOB/urgent mark,
+ * otherwise return false.
+ */
+ public static native boolean atmark(long sock);
+
+ /**
+ * Issue a connection request to a socket either on the same machine
+ * or a different one.
+ * @param sock The socket we wish to use for our side of the connection
+ * @param sa The address of the machine we wish to connect to.
+ */
+ public static native int connect(long sock, long sa);
+
+ /**
+ * Send data over a network.
+ * <PRE>
+ * This functions acts like a blocking write by default. To change
+ * this behavior, use apr_socket_timeout_set() or the APR_SO_NONBLOCK
+ * socket option.
+ *
+ * It is possible for both bytes to be sent and an error to be returned.
+ *
+ * APR_EINTR is never returned.
+ * </PRE>
+ * @param sock The socket to send the data over.
+ * @param buf The buffer which contains the data to be sent.
+ * @param offset Offset in the byte buffer.
+ * @param len The number of bytes to write; (-1) for full array.
+ * @return The number of bytes send.
+ *
+ */
+ public static native int send(long sock, byte[] buf, int offset, int len);
+
+ /**
+ * Send data over a network.
+ * <PRE>
+ * This functions acts like a blocking write by default. To change
+ * this behavior, use apr_socket_timeout_set() or the APR_SO_NONBLOCK
+ * socket option.
+ *
+ * It is possible for both bytes to be sent and an error to be returned.
+ *
+ * APR_EINTR is never returned.
+ * </PRE>
+ * @param sock The socket to send the data over.
+ * @param buf The Byte buffer which contains the data to be sent.
+ * @param offset The offset within the buffer array of the first buffer from
+ * which bytes are to be retrieved; must be non-negative
+ * and no larger than buf.length
+ * @param len The maximum number of buffers to be accessed; must be non-negative
+ * and no larger than buf.length - offset
+ * @return The number of bytes send.
+ *
+ */
+ public static native int sendb(long sock, ByteBuffer buf,
+ int offset, int len);
+
+ /**
+ * Send data over a network without retry
+ * <PRE>
+ * This functions acts like a blocking write by default. To change
+ * this behavior, use apr_socket_timeout_set() or the APR_SO_NONBLOCK
+ * socket option.
+ *
+ * It is possible for both bytes to be sent and an error to be returned.
+ *
+ * </PRE>
+ * @param sock The socket to send the data over.
+ * @param buf The Byte buffer which contains the data to be sent.
+ * @param offset The offset within the buffer array of the first buffer from
+ * which bytes are to be retrieved; must be non-negative
+ * and no larger than buf.length
+ * @param len The maximum number of buffers to be accessed; must be non-negative
+ * and no larger than buf.length - offset
+ * @return The number of bytes send.
+ *
+ */
+ public static native int sendib(long sock, ByteBuffer buf,
+ int offset, int len);
+
+ /**
+ * Send data over a network using internally set ByteBuffer
+ */
+ public static native int sendbb(long sock,
+ int offset, int len);
+
+ /**
+ * Send data over a network using internally set ByteBuffer
+ * without internal retry.
+ */
+ public static native int sendibb(long sock,
+ int offset, int len);
+
+ /**
+ * Send multiple packets of data over a network.
+ * <PRE>
+ * This functions acts like a blocking write by default. To change
+ * this behavior, use apr_socket_timeout_set() or the APR_SO_NONBLOCK
+ * socket option.
+ * The number of bytes actually sent is stored in argument 3.
+ *
+ * It is possible for both bytes to be sent and an error to be returned.
+ *
+ * APR_EINTR is never returned.
+ * </PRE>
+ * @param sock The socket to send the data over.
+ * @param vec The array from which to get the data to send.
+ *
+ */
+ public static native int sendv(long sock, byte[][] vec);
+
+ /**
+ * @param sock The socket to send from
+ * @param where The apr_sockaddr_t describing where to send the data
+ * @param flags The flags to use
+ * @param buf The data to send
+ * @param offset Offset in the byte buffer.
+ * @param len The length of the data to send
+ */
+ public static native int sendto(long sock, long where, int flags,
+ byte[] buf, int offset, int len);
+
+ /**
+ * Read data from a network.
+ *
+ * <PRE>
+ * This functions acts like a blocking read by default. To change
+ * this behavior, use apr_socket_timeout_set() or the APR_SO_NONBLOCK
+ * socket option.
+ * The number of bytes actually received is stored in argument 3.
+ *
+ * It is possible for both bytes to be received and an APR_EOF or
+ * other error to be returned.
+ *
+ * APR_EINTR is never returned.
+ * </PRE>
+ * @param sock The socket to read the data from.
+ * @param buf The buffer to store the data in.
+ * @param offset Offset in the byte buffer.
+ * @param nbytes The number of bytes to read (-1) for full array.
+ * @return the number of bytes received.
+ */
+ public static native int recv(long sock, byte[] buf, int offset, int nbytes);
+
+ /**
+ * Read data from a network with timeout.
+ *
+ * <PRE>
+ * This functions acts like a blocking read by default. To change
+ * this behavior, use apr_socket_timeout_set() or the APR_SO_NONBLOCK
+ * socket option.
+ * The number of bytes actually received is stored in argument 3.
+ *
+ * It is possible for both bytes to be received and an APR_EOF or
+ * other error to be returned.
+ *
+ * APR_EINTR is never returned.
+ * </PRE>
+ * @param sock The socket to read the data from.
+ * @param buf The buffer to store the data in.
+ * @param offset Offset in the byte buffer.
+ * @param nbytes The number of bytes to read (-1) for full array.
+ * @param timeout The socket timeout in microseconds.
+ * @return the number of bytes received.
+ */
+ public static native int recvt(long sock, byte[] buf, int offset,
+ int nbytes, long timeout);
+
+ /**
+ * Read data from a network.
+ *
+ * <PRE>
+ * This functions acts like a blocking read by default. To change
+ * this behavior, use apr_socket_timeout_set() or the APR_SO_NONBLOCK
+ * socket option.
+ * The number of bytes actually received is stored in argument 3.
+ *
+ * It is possible for both bytes to be received and an APR_EOF or
+ * other error to be returned.
+ *
+ * APR_EINTR is never returned.
+ * </PRE>
+ * @param sock The socket to read the data from.
+ * @param buf The buffer to store the data in.
+ * @param offset Offset in the byte buffer.
+ * @param nbytes The number of bytes to read (-1) for full array.
+ * @return the number of bytes received.
+ */
+ public static native int recvb(long sock, ByteBuffer buf,
+ int offset, int nbytes);
+ /**
+ * Read data from a network using internally set ByteBuffer
+ */
+ public static native int recvbb(long sock,
+ int offset, int nbytes);
+ /**
+ * Read data from a network with timeout.
+ *
+ * <PRE>
+ * This functions acts like a blocking read by default. To change
+ * this behavior, use apr_socket_timeout_set() or the APR_SO_NONBLOCK
+ * socket option.
+ * The number of bytes actually received is stored in argument 3.
+ *
+ * It is possible for both bytes to be received and an APR_EOF or
+ * other error to be returned.
+ *
+ * APR_EINTR is never returned.
+ * </PRE>
+ * @param sock The socket to read the data from.
+ * @param buf The buffer to store the data in.
+ * @param offset Offset in the byte buffer.
+ * @param nbytes The number of bytes to read (-1) for full array.
+ * @param timeout The socket timeout in microseconds.
+ * @return the number of bytes received.
+ */
+ public static native int recvbt(long sock, ByteBuffer buf,
+ int offset, int nbytes, long timeout);
+ /**
+ * Read data from a network with timeout using internally set ByteBuffer
+ */
+ public static native int recvbbt(long sock,
+ int offset, int nbytes, long timeout);
+
+ /**
+ * @param from The apr_sockaddr_t to fill in the recipient info
+ * @param sock The socket to use
+ * @param flags The flags to use
+ * @param buf The buffer to use
+ * @param offset Offset in the byte buffer.
+ * @param nbytes The number of bytes to read (-1) for full array.
+ * @return the number of bytes received.
+ */
+ public static native int recvfrom(long from, long sock, int flags,
+ byte[] buf, int offset, int nbytes);
+
+ /**
+ * Setup socket options for the specified socket
+ * @param sock The socket to set up.
+ * @param opt The option we would like to configure. One of:
+ * <PRE>
+ * APR_SO_DEBUG -- turn on debugging information
+ * APR_SO_KEEPALIVE -- keep connections active
+ * APR_SO_LINGER -- lingers on close if data is present
+ * APR_SO_NONBLOCK -- Turns blocking on/off for socket
+ * When this option is enabled, use
+ * the APR_STATUS_IS_EAGAIN() macro to
+ * see if a send or receive function
+ * could not transfer data without
+ * blocking.
+ * APR_SO_REUSEADDR -- The rules used in validating addresses
+ * supplied to bind should allow reuse
+ * of local addresses.
+ * APR_SO_SNDBUF -- Set the SendBufferSize
+ * APR_SO_RCVBUF -- Set the ReceiveBufferSize
+ * </PRE>
+ * @param on Value for the option.
+ */
+ public static native int optSet(long sock, int opt, int on);
+
+ /**
+ * Query socket options for the specified socket
+ * @param sock The socket to query
+ * @param opt The option we would like to query. One of:
+ * <PRE>
+ * APR_SO_DEBUG -- turn on debugging information
+ * APR_SO_KEEPALIVE -- keep connections active
+ * APR_SO_LINGER -- lingers on close if data is present
+ * APR_SO_NONBLOCK -- Turns blocking on/off for socket
+ * APR_SO_REUSEADDR -- The rules used in validating addresses
+ * supplied to bind should allow reuse
+ * of local addresses.
+ * APR_SO_SNDBUF -- Set the SendBufferSize
+ * APR_SO_RCVBUF -- Set the ReceiveBufferSize
+ * APR_SO_DISCONNECTED -- Query the disconnected state of the socket.
+ * (Currently only used on Windows)
+ * </PRE>
+ * @return Socket option returned on the call.
+ */
+ public static native int optGet(long sock, int opt)
+ throws Exception;
+
+ /**
+ * Setup socket timeout for the specified socket
+ * @param sock The socket to set up.
+ * @param t Value for the timeout in microseconds.
+ * <PRE>
+ * t > 0 -- read and write calls return APR_TIMEUP if specified time
+ * elapses with no data read or written
+ * t == 0 -- read and write calls never block
+ * t < 0 -- read and write calls block
+ * </PRE>
+ */
+ public static native int timeoutSet(long sock, long t);
+
+ /**
+ * Query socket timeout for the specified socket
+ * @param sock The socket to query
+ * @return Socket timeout returned from the query.
+ */
+ public static native long timeoutGet(long sock)
+ throws Exception;
+
+ /**
+ * Send a file from an open file descriptor to a socket, along with
+ * optional headers and trailers.
+ * <br />
+ * This functions acts like a blocking write by default. To change
+ * this behavior, use apr_socket_timeout_set() or the
+ * APR_SO_NONBLOCK socket option.
+ * The number of bytes actually sent is stored in the len parameter.
+ * The offset parameter is passed by reference for no reason; its
+ * value will never be modified by the apr_socket_sendfile() function.
+ * @param sock The socket to which we're writing
+ * @param file The open file from which to read
+ * @param headers Array containing the headers to send
+ * @param trailers Array containing the trailers to send
+ * @param offset Offset into the file where we should begin writing
+ * @param len Number of bytes to send from the file
+ * @param flags APR flags that are mapped to OS specific flags
+ * @return Number of bytes actually sent, including headers,
+ * file, and trailers
+ *
+ */
+ public static native long sendfile(long sock, long file, byte [][] headers,
+ byte[][] trailers, long offset,
+ long len, int flags);
+
+ /**
+ * Send a file without header and trailer arrays.
+ */
+ public static native long sendfilen(long sock, long file, long offset,
+ long len, int flags);
+
+ /**
+ * Create a child pool from associated socket pool.
+ * @param thesocket The socket to use
+ */
+ public static native long pool(long thesocket)
+ throws Exception;
+
+ /**
+ * Private method for getting the socket struct members
+ * @param socket The socket to use
+ * @param what Struct member to obtain
+ * <PRE>
+ * SOCKET_GET_POOL - The socket pool
+ * SOCKET_GET_IMPL - The socket implementation object
+ * SOCKET_GET_APRS - APR socket
+ * SOCKET_GET_TYPE - Socket type
+ * </PRE>
+ * @return The structure member address
+ */
+ private static native long get(long socket, int what);
+
+ /**
+ * Set internal send ByteBuffer.
+ * This function will preset internal Java ByteBuffer for
+ * consecutive sendbb calls.
+ * @param sock The socket to use
+ * @param buf The ByteBuffer
+ */
+ public static native void setsbb(long sock, ByteBuffer buf);
+
+ /**
+ * Set internal receive ByteBuffer.
+ * This function will preset internal Java ByteBuffer for
+ * consecutive revcvbb/recvbbt calls.
+ * @param sock The socket to use
+ * @param buf The ByteBuffer
+ */
+ public static native void setrbb(long sock, ByteBuffer buf);
+
+ /**
+ * Set the data associated with the current socket.
+ * @param sock The currently open socket.
+ * @param data The user data to associate with the socket.
+ * @param key The key to associate with the data.
+ */
+ public static native int dataSet(long sock, String key, Object data);
+
+ /**
+ * Return the data associated with the current socket
+ * @param key The key to associate with the user data.
+ * @param sock The currently open socket.
+ * @return Data or null in case of error.
+ */
+ public static native Object dataGet(long sock, String key);
+}
diff --git a/jni/java/org/apache/tomcat/jni/Status.java b/jni/java/org/apache/tomcat/jni/Status.java
new file mode 100644
index 0000000..6b69471
--- /dev/null
+++ b/jni/java/org/apache/tomcat/jni/Status.java
@@ -0,0 +1,263 @@
+/*
+ * 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.
+ */
+
+package org.apache.tomcat.jni;
+
+/** Status
+ *
+ * @author Mladen Turk
+ */
+public class Status {
+
+ /**
+ * APR_OS_START_ERROR is where the APR specific error values start.
+ */
+ public static final int APR_OS_START_ERROR = 20000;
+ /**
+ * APR_OS_ERRSPACE_SIZE is the maximum number of errors you can fit
+ * into one of the error/status ranges below -- except for
+ * APR_OS_START_USERERR, which see.
+ */
+ public static final int APR_OS_ERRSPACE_SIZE = 50000;
+ /**
+ * APR_OS_START_STATUS is where the APR specific status codes start.
+ */
+ public static final int APR_OS_START_STATUS = (APR_OS_START_ERROR + APR_OS_ERRSPACE_SIZE);
+
+ /**
+ * APR_OS_START_USERERR are reserved for applications that use APR that
+ * layer their own error codes along with APR's. Note that the
+ * error immediately following this one is set ten times farther
+ * away than usual, so that users of apr have a lot of room in
+ * which to declare custom error codes.
+ */
+ public static final int APR_OS_START_USERERR = (APR_OS_START_STATUS + APR_OS_ERRSPACE_SIZE);
+ /**
+ * APR_OS_START_USEERR is obsolete, defined for compatibility only.
+ * Use APR_OS_START_USERERR instead.
+ */
+ public static final int APR_OS_START_USEERR = APR_OS_START_USERERR;
+ /**
+ * APR_OS_START_CANONERR is where APR versions of errno values are defined
+ * on systems which don't have the corresponding errno.
+ */
+ public static final int APR_OS_START_CANONERR = (APR_OS_START_USERERR + (APR_OS_ERRSPACE_SIZE * 10));
+
+ /**
+ * APR_OS_START_EAIERR folds EAI_ error codes from getaddrinfo() into
+ * apr_status_t values.
+ */
+ public static final int APR_OS_START_EAIERR = (APR_OS_START_CANONERR + APR_OS_ERRSPACE_SIZE);
+ /**
+ * APR_OS_START_SYSERR folds platform-specific system error values into
+ * apr_status_t values.
+ */
+ public static final int APR_OS_START_SYSERR = (APR_OS_START_EAIERR + APR_OS_ERRSPACE_SIZE);
+
+ /** no error. */
+ public static final int APR_SUCCESS = 0;
+
+ /**
+ * APR Error Values
+ * <PRE>
+ * <b>APR ERROR VALUES</b>
+ * APR_ENOSTAT APR was unable to perform a stat on the file
+ * APR_ENOPOOL APR was not provided a pool with which to allocate memory
+ * APR_EBADDATE APR was given an invalid date
+ * APR_EINVALSOCK APR was given an invalid socket
+ * APR_ENOPROC APR was not given a process structure
+ * APR_ENOTIME APR was not given a time structure
+ * APR_ENODIR APR was not given a directory structure
+ * APR_ENOLOCK APR was not given a lock structure
+ * APR_ENOPOLL APR was not given a poll structure
+ * APR_ENOSOCKET APR was not given a socket
+ * APR_ENOTHREAD APR was not given a thread structure
+ * APR_ENOTHDKEY APR was not given a thread key structure
+ * APR_ENOSHMAVAIL There is no more shared memory available
+ * APR_EDSOOPEN APR was unable to open the dso object. For more
+ * information call apr_dso_error().
+ * APR_EGENERAL General failure (specific information not available)
+ * APR_EBADIP The specified IP address is invalid
+ * APR_EBADMASK The specified netmask is invalid
+ * APR_ESYMNOTFOUND Could not find the requested symbol
+ * </PRE>
+ *
+ */
+ public static final int APR_ENOSTAT = (APR_OS_START_ERROR + 1);
+ public static final int APR_ENOPOOL = (APR_OS_START_ERROR + 2);
+ public static final int APR_EBADDATE = (APR_OS_START_ERROR + 4);
+ public static final int APR_EINVALSOCK = (APR_OS_START_ERROR + 5);
+ public static final int APR_ENOPROC = (APR_OS_START_ERROR + 6);
+ public static final int APR_ENOTIME = (APR_OS_START_ERROR + 7);
+ public static final int APR_ENODIR = (APR_OS_START_ERROR + 8);
+ public static final int APR_ENOLOCK = (APR_OS_START_ERROR + 9);
+ public static final int APR_ENOPOLL = (APR_OS_START_ERROR + 10);
+ public static final int APR_ENOSOCKET = (APR_OS_START_ERROR + 11);
+ public static final int APR_ENOTHREAD = (APR_OS_START_ERROR + 12);
+ public static final int APR_ENOTHDKEY = (APR_OS_START_ERROR + 13);
+ public static final int APR_EGENERAL = (APR_OS_START_ERROR + 14);
+ public static final int APR_ENOSHMAVAIL = (APR_OS_START_ERROR + 15);
+ public static final int APR_EBADIP = (APR_OS_START_ERROR + 16);
+ public static final int APR_EBADMASK = (APR_OS_START_ERROR + 17);
+ public static final int APR_EDSOOPEN = (APR_OS_START_ERROR + 19);
+ public static final int APR_EABSOLUTE = (APR_OS_START_ERROR + 20);
+ public static final int APR_ERELATIVE = (APR_OS_START_ERROR + 21);
+ public static final int APR_EINCOMPLETE = (APR_OS_START_ERROR + 22);
+ public static final int APR_EABOVEROOT = (APR_OS_START_ERROR + 23);
+ public static final int APR_EBADPATH = (APR_OS_START_ERROR + 24);
+ public static final int APR_EPATHWILD = (APR_OS_START_ERROR + 25);
+ public static final int APR_ESYMNOTFOUND = (APR_OS_START_ERROR + 26);
+ public static final int APR_EPROC_UNKNOWN = (APR_OS_START_ERROR + 27);
+ public static final int APR_ENOTENOUGHENTROPY = (APR_OS_START_ERROR + 28);
+
+ /** APR Status Values
+ * <PRE>
+ * <b>APR STATUS VALUES</b>
+ * APR_INCHILD Program is currently executing in the child
+ * APR_INPARENT Program is currently executing in the parent
+ * APR_DETACH The thread is detached
+ * APR_NOTDETACH The thread is not detached
+ * APR_CHILD_DONE The child has finished executing
+ * APR_CHILD_NOTDONE The child has not finished executing
+ * APR_TIMEUP The operation did not finish before the timeout
+ * APR_INCOMPLETE The operation was incomplete although some processing
+ * was performed and the results are partially valid
+ * APR_BADCH Getopt found an option not in the option string
+ * APR_BADARG Getopt found an option that is missing an argument
+ * and an argument was specified in the option string
+ * APR_EOF APR has encountered the end of the file
+ * APR_NOTFOUND APR was unable to find the socket in the poll structure
+ * APR_ANONYMOUS APR is using anonymous shared memory
+ * APR_FILEBASED APR is using a file name as the key to the shared memory
+ * APR_KEYBASED APR is using a shared key as the key to the shared memory
+ * APR_EINIT Ininitalizer value. If no option has been found, but
+ * the status variable requires a value, this should be used
+ * APR_ENOTIMPL The APR function has not been implemented on this
+ * platform, either because nobody has gotten to it yet,
+ * or the function is impossible on this platform.
+ * APR_EMISMATCH Two passwords do not match.
+ * APR_EBUSY The given lock was busy.
+ * </PRE>
+ *
+ */
+ public static final int APR_INCHILD = (APR_OS_START_STATUS + 1);
+ public static final int APR_INPARENT = (APR_OS_START_STATUS + 2);
+ public static final int APR_DETACH = (APR_OS_START_STATUS + 3);
+ public static final int APR_NOTDETACH = (APR_OS_START_STATUS + 4);
+ public static final int APR_CHILD_DONE = (APR_OS_START_STATUS + 5);
+ public static final int APR_CHILD_NOTDONE = (APR_OS_START_STATUS + 6);
+ public static final int APR_TIMEUP = (APR_OS_START_STATUS + 7);
+ public static final int APR_INCOMPLETE = (APR_OS_START_STATUS + 8);
+ public static final int APR_BADCH = (APR_OS_START_STATUS + 12);
+ public static final int APR_BADARG = (APR_OS_START_STATUS + 13);
+ public static final int APR_EOF = (APR_OS_START_STATUS + 14);
+ public static final int APR_NOTFOUND = (APR_OS_START_STATUS + 15);
+ public static final int APR_ANONYMOUS = (APR_OS_START_STATUS + 19);
+ public static final int APR_FILEBASED = (APR_OS_START_STATUS + 20);
+ public static final int APR_KEYBASED = (APR_OS_START_STATUS + 21);
+ public static final int APR_EINIT = (APR_OS_START_STATUS + 22);
+ public static final int APR_ENOTIMPL = (APR_OS_START_STATUS + 23);
+ public static final int APR_EMISMATCH = (APR_OS_START_STATUS + 24);
+ public static final int APR_EBUSY = (APR_OS_START_STATUS + 25);
+
+ public static final int TIMEUP = (APR_OS_START_USERERR + 1);
+ public static final int EAGAIN = (APR_OS_START_USERERR + 2);
+ public static final int EINTR = (APR_OS_START_USERERR + 3);
+ public static final int EINPROGRESS = (APR_OS_START_USERERR + 4);
+ public static final int ETIMEDOUT = (APR_OS_START_USERERR + 5);
+
+ private static native boolean is(int err, int idx);
+ /**
+ * APR_STATUS_IS Status Value Tests
+ * <br /><b>Warning :</b> For any particular error condition, more than one of these tests
+ * may match. This is because platform-specific error codes may not
+ * always match the semantics of the POSIX codes these tests (and the
+ * corresponding APR error codes) are named after. A notable example
+ * are the APR_STATUS_IS_ENOENT and APR_STATUS_IS_ENOTDIR tests on
+ * Win32 platforms. The programmer should always be aware of this and
+ * adjust the order of the tests accordingly.
+ *
+ */
+ public static final boolean APR_STATUS_IS_ENOSTAT(int s) { return is(s, 1); }
+ public static final boolean APR_STATUS_IS_ENOPOOL(int s) { return is(s, 2); }
+ /* empty slot: +3 */
+ public static final boolean APR_STATUS_IS_EBADDATE(int s) { return is(s, 4); }
+ public static final boolean APR_STATUS_IS_EINVALSOCK(int s) { return is(s, 5); }
+ public static final boolean APR_STATUS_IS_ENOPROC(int s) { return is(s, 6); }
+ public static final boolean APR_STATUS_IS_ENOTIME(int s) { return is(s, 7); }
+ public static final boolean APR_STATUS_IS_ENODIR(int s) { return is(s, 8); }
+ public static final boolean APR_STATUS_IS_ENOLOCK(int s) { return is(s, 9); }
+ public static final boolean APR_STATUS_IS_ENOPOLL(int s) { return is(s, 10); }
+ public static final boolean APR_STATUS_IS_ENOSOCKET(int s) { return is(s, 11); }
+ public static final boolean APR_STATUS_IS_ENOTHREAD(int s) { return is(s, 12); }
+ public static final boolean APR_STATUS_IS_ENOTHDKEY(int s) { return is(s, 13); }
+ public static final boolean APR_STATUS_IS_EGENERAL(int s) { return is(s, 14); }
+ public static final boolean APR_STATUS_IS_ENOSHMAVAIL(int s){ return is(s, 15); }
+ public static final boolean APR_STATUS_IS_EBADIP(int s) { return is(s, 16); }
+ public static final boolean APR_STATUS_IS_EBADMASK(int s) { return is(s, 17); }
+ /* empty slot: +18 */
+ public static final boolean APR_STATUS_IS_EDSOPEN(int s) { return is(s, 19); }
+ public static final boolean APR_STATUS_IS_EABSOLUTE(int s) { return is(s, 20); }
+ public static final boolean APR_STATUS_IS_ERELATIVE(int s) { return is(s, 21); }
+ public static final boolean APR_STATUS_IS_EINCOMPLETE(int s){ return is(s, 22); }
+ public static final boolean APR_STATUS_IS_EABOVEROOT(int s) { return is(s, 23); }
+ public static final boolean APR_STATUS_IS_EBADPATH(int s) { return is(s, 24); }
+ public static final boolean APR_STATUS_IS_EPATHWILD(int s) { return is(s, 25); }
+ public static final boolean APR_STATUS_IS_ESYMNOTFOUND(int s) { return is(s, 26); }
+ public static final boolean APR_STATUS_IS_EPROC_UNKNOWN(int s) { return is(s, 27); }
+ public static final boolean APR_STATUS_IS_ENOTENOUGHENTROPY(int s) { return is(s, 28); }
+
+ /*
+ * APR_Error
+ */
+ public static final boolean APR_STATUS_IS_INCHILD(int s) { return is(s, 51); }
+ public static final boolean APR_STATUS_IS_INPARENT(int s) { return is(s, 52); }
+ public static final boolean APR_STATUS_IS_DETACH(int s) { return is(s, 53); }
+ public static final boolean APR_STATUS_IS_NOTDETACH(int s) { return is(s, 54); }
+ public static final boolean APR_STATUS_IS_CHILD_DONE(int s) { return is(s, 55); }
+ public static final boolean APR_STATUS_IS_CHILD_NOTDONE(int s) { return is(s, 56); }
+ public static final boolean APR_STATUS_IS_TIMEUP(int s) { return is(s, 57); }
+ public static final boolean APR_STATUS_IS_INCOMPLETE(int s) { return is(s, 58); }
+ /* empty slot: +9 */
+ /* empty slot: +10 */
+ /* empty slot: +11 */
+ public static final boolean APR_STATUS_IS_BADCH(int s) { return is(s, 62); }
+ public static final boolean APR_STATUS_IS_BADARG(int s) { return is(s, 63); }
+ public static final boolean APR_STATUS_IS_EOF(int s) { return is(s, 64); }
+ public static final boolean APR_STATUS_IS_NOTFOUND(int s) { return is(s, 65); }
+ /* empty slot: +16 */
+ /* empty slot: +17 */
+ /* empty slot: +18 */
+ public static final boolean APR_STATUS_IS_ANONYMOUS(int s) { return is(s, 69); }
+ public static final boolean APR_STATUS_IS_FILEBASED(int s) { return is(s, 70); }
+ public static final boolean APR_STATUS_IS_KEYBASED(int s) { return is(s, 71); }
+ public static final boolean APR_STATUS_IS_EINIT(int s) { return is(s, 72); }
+ public static final boolean APR_STATUS_IS_ENOTIMPL(int s) { return is(s, 73); }
+ public static final boolean APR_STATUS_IS_EMISMATCH(int s) { return is(s, 74); }
+ public static final boolean APR_STATUS_IS_EBUSY(int s) { return is(s, 75); }
+
+ /* Socket errors */
+ public static final boolean APR_STATUS_IS_EAGAIN(int s) { return is(s, 90); }
+ public static final boolean APR_STATUS_IS_ETIMEDOUT(int s) { return is(s, 91); }
+ public static final boolean APR_STATUS_IS_ECONNABORTED(int s) { return is(s, 92); }
+ public static final boolean APR_STATUS_IS_ECONNRESET(int s) { return is(s, 93); }
+ public static final boolean APR_STATUS_IS_EINPROGRESS(int s) { return is(s, 94); }
+ public static final boolean APR_STATUS_IS_EINTR(int s) { return is(s, 95); }
+ public static final boolean APR_STATUS_IS_ENOTSOCK(int s) { return is(s, 96); }
+ public static final boolean APR_STATUS_IS_EINVAL(int s) { return is(s, 97); }
+
+}
diff --git a/jni/java/org/apache/tomcat/jni/Stdlib.java b/jni/java/org/apache/tomcat/jni/Stdlib.java
new file mode 100644
index 0000000..58b281c
--- /dev/null
+++ b/jni/java/org/apache/tomcat/jni/Stdlib.java
@@ -0,0 +1,88 @@
+/*
+ * 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.
+ */
+
+package org.apache.tomcat.jni;
+
+/** Stdlib
+ *
+ * @author Mladen Turk
+ */
+public class Stdlib {
+
+ /**
+ * Read from plain memory
+ * @param dst Destination byte array
+ * @param src Source memory address
+ * @param sz Number of bytes to copy.
+ */
+ public static native boolean memread(byte [] dst, long src, int sz);
+
+ /**
+ * Write to plain memory
+ * @param dst Destination memory address
+ * @param src Source byte array
+ * @param sz Number of bytes to copy.
+ */
+ public static native boolean memwrite(long dst, byte [] src, int sz);
+
+ /**
+ * Sets buffers to a specified character
+ * @param dst Destination memory address
+ * @param c Character to set.
+ * @param sz Number of characters.
+ */
+ public static native boolean memset(long dst, int c, int sz);
+
+ /**
+ * Allocates memory blocks.
+ * @param sz Bytes to allocate.
+ */
+ public static native long malloc(int sz);
+
+ /**
+ * Reallocate memory blocks.
+ * @param mem Pointer to previously allocated memory block.
+ * @param sz New size in bytes.
+ */
+ public static native long realloc(long mem, int sz);
+
+ /**
+ * Allocates an array in memory with elements initialized to 0.
+ * @param num Number of elements.
+ * @param sz Length in bytes of each element.
+ */
+ public static native long calloc(int num, int sz);
+
+ /**
+ * Deallocates or frees a memory block.
+ * @param mem Previously allocated memory block to be freed.
+ */
+ public static native void free(long mem);
+
+ /**
+ * Get current process pid.
+ * @return current pid or < 1 in case of error.
+ */
+ public static native int getpid();
+
+ /**
+ * Get current process parent pid.
+ * @return parent pid or < 1 in case of error.
+ */
+ public static native int getppid();
+
+}
diff --git a/jni/java/org/apache/tomcat/jni/Thread.java b/jni/java/org/apache/tomcat/jni/Thread.java
new file mode 100644
index 0000000..e7fc920
--- /dev/null
+++ b/jni/java/org/apache/tomcat/jni/Thread.java
@@ -0,0 +1,31 @@
+/*
+ * 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.
+ */
+
+package org.apache.tomcat.jni;
+
+/** Thread
+ *
+ * @author Mladen Turk
+ */
+public class Thread {
+
+ /**
+ * Get the current thread ID handle.
+ */
+ public static native long current();
+
+}
diff --git a/jni/java/org/apache/tomcat/jni/Time.java b/jni/java/org/apache/tomcat/jni/Time.java
new file mode 100644
index 0000000..2eceb65
--- /dev/null
+++ b/jni/java/org/apache/tomcat/jni/Time.java
@@ -0,0 +1,72 @@
+/*
+ * 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.
+ */
+
+package org.apache.tomcat.jni;
+
+/** Time
+ *
+ * @author Mladen Turk
+ */
+public class Time {
+
+ /** number of microseconds per second */
+ public static final long APR_USEC_PER_SEC = 1000000L;
+ /** number of milliseconds per microsecond */
+ public static final long APR_MSEC_PER_USEC = 1000L;
+
+ /** @return apr_time_t as a second */
+ public static long sec(long t)
+ {
+ return t / APR_USEC_PER_SEC;
+ }
+
+ /** @return apr_time_t as a msec */
+ public static long msec(long t)
+ {
+ return t / APR_MSEC_PER_USEC;
+ }
+
+ /**
+ * number of microseconds since 00:00:00 January 1, 1970 UTC
+ * @return the current time
+ */
+ public static native long now();
+
+ /**
+ * Formats dates in the RFC822
+ * format in an efficient manner.
+ * @param t the time to convert
+ */
+ public static native String rfc822(long t);
+
+ /**
+ * Formats dates in the ctime() format
+ * in an efficient manner.
+ * Unlike ANSI/ISO C ctime(), apr_ctime() does not include
+ * a \n at the end of the string.
+ * @param t the time to convert
+ */
+ public static native String ctime(long t);
+
+ /**
+ * Sleep for the specified number of micro-seconds.
+ * <br /><b>Warning :</b> May sleep for longer than the specified time.
+ * @param t desired amount of time to sleep.
+ */
+ public static native void sleep(long t);
+
+}
diff --git a/jni/java/org/apache/tomcat/jni/User.java b/jni/java/org/apache/tomcat/jni/User.java
new file mode 100644
index 0000000..0af7283
--- /dev/null
+++ b/jni/java/org/apache/tomcat/jni/User.java
@@ -0,0 +1,125 @@
+/*
+ * 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.
+ */
+
+package org.apache.tomcat.jni;
+
+/** User
+ *
+ * @author Mladen Turk
+ */
+public class User {
+
+ /**
+ * Get the userid (and groupid) of the calling process
+ * This function is available only if APR_HAS_USER is defined.
+ * @param p The pool from which to allocate working space
+ * @return Returns the user id
+ */
+ public static native long uidCurrent(long p)
+ throws Error;
+
+ /**
+ * Get the groupid of the calling process
+ * This function is available only if APR_HAS_USER is defined.
+ * @param p The pool from which to allocate working space
+ * @return Returns the group id
+ */
+ public static native long gidCurrent(long p)
+ throws Error;
+
+
+ /**
+ * Get the userid for the specified username
+ * This function is available only if APR_HAS_USER is defined.
+ * @param username The username to lookup
+ * @param p The pool from which to allocate working space
+ * @return Returns the user id
+ */
+ public static native long uid(String username, long p)
+ throws Error;
+
+ /**
+ * Get the groupid for the specified username
+ * This function is available only if APR_HAS_USER is defined.
+ * @param username The username to lookup
+ * @param p The pool from which to allocate working space
+ * @return Returns the user's group id
+ */
+ public static native long usergid(String username, long p)
+ throws Error;
+
+ /**
+ * Get the groupid for a specified group name
+ * This function is available only if APR_HAS_USER is defined.
+ * @param groupname The group name to look up
+ * @param p The pool from which to allocate working space
+ * @return Returns the user's group id
+ */
+ public static native long gid(String groupname, long p)
+ throws Error;
+
+ /**
+ * Get the user name for a specified userid
+ * This function is available only if APR_HAS_USER is defined.
+ * @param userid The userid
+ * @param p The pool from which to allocate the string
+ * @return New string containing user name
+ */
+ public static native String username(long userid, long p)
+ throws Error;
+
+ /**
+ * Get the group name for a specified groupid
+ * This function is available only if APR_HAS_USER is defined.
+ * @param groupid The groupid
+ * @param p The pool from which to allocate the string
+ * @return New string containing group name
+ */
+ public static native String groupname(long groupid, long p)
+ throws Error;
+
+ /**
+ * Compare two user identifiers for equality.
+ * This function is available only if APR_HAS_USER is defined.
+ * @param left One uid to test
+ * @param right Another uid to test
+ * @return APR_SUCCESS if the apr_uid_t structures identify the same user,
+ * APR_EMISMATCH if not, APR_BADARG if an apr_uid_t is invalid.
+ */
+ public static native int uidcompare(long left, long right);
+
+ /**
+ * Compare two group identifiers for equality.
+ * This function is available only if APR_HAS_USER is defined.
+ * @param left One gid to test
+ * @param right Another gid to test
+ * @return APR_SUCCESS if the apr_gid_t structures identify the same group,
+ * APR_EMISMATCH if not, APR_BADARG if an apr_gid_t is invalid.
+ */
+ public static native int gidcompare(long left, long right);
+
+ /**
+ * Get the home directory for the named user
+ * This function is available only if APR_HAS_USER is defined.
+ * @param username The named user
+ * @param p The pool from which to allocate the string
+ * @return New string containing directory name
+ */
+ public static native String homepath(String username, long p)
+ throws Error;
+
+}
diff --git a/jni/java/org/apache/tomcat/jni/socket/AprSocket.java b/jni/java/org/apache/tomcat/jni/socket/AprSocket.java
new file mode 100644
index 0000000..1800bab
--- /dev/null
+++ b/jni/java/org/apache/tomcat/jni/socket/AprSocket.java
@@ -0,0 +1,922 @@
+/*
+ * 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.
+ */
+package org.apache.tomcat.jni.socket;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.security.cert.CertificateException;
+import java.security.cert.CertificateFactory;
+import java.security.cert.X509Certificate;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import org.apache.tomcat.jni.Address;
+import org.apache.tomcat.jni.Error;
+import org.apache.tomcat.jni.Poll;
+import org.apache.tomcat.jni.SSL;
+import org.apache.tomcat.jni.SSLExt;
+import org.apache.tomcat.jni.SSLSocket;
+import org.apache.tomcat.jni.Sockaddr;
+import org.apache.tomcat.jni.Socket;
+import org.apache.tomcat.jni.Status;
+import org.apache.tomcat.jni.socket.AprSocketContext.AprPoller;
+import org.apache.tomcat.jni.socket.AprSocketContext.BlockingPollHandler;
+
+/**
+ * Native socket, using JNI + APR + openssl.
+ *
+ * The socket is non-blocking - you can register either a blocking or non
+ * blocking callback.
+ *
+ * There is no explicit method to register/unregister poll interest -
+ * it is done automatically, when read/write methods return 0.
+ *
+ * To keep the socket polling you must read all the available data, until
+ * read() returns 0. If you want to pause - don't read all input. To resume -
+ * read again until it returns 0.
+ *
+ * Same for write - when write() returns 0 the socket is registered for
+ * write interest.
+ *
+ * You can also use the blocking read/write methods.
+ */
+public class AprSocket implements Runnable {
+
+ private static final Logger log =
+ Logger.getLogger("org.apache.tomcat.jni.socket.AprSocket");
+
+ private static final byte[][] NO_CERTS = new byte[0][];
+
+ static final int CONNECTING = 0x1;
+ static final int CONNECTED = 0x2;
+
+ // Current ( real ) poll status
+ static final int POLLIN_ACTIVE = 0x4;
+ static final int POLLOUT_ACTIVE = 0x8;
+
+ static final int POLL = 0x10;
+
+ static final int SSL_ATTACHED = 0x40;
+
+ // Requested poll status. Set by read/write when needed.
+ // Cleared when polled
+ static final int POLLIN = 0x80;
+ static final int POLLOUT = 0x100;
+
+ static final int ACCEPTED = 0x200;
+ static final int ERROR = 0x400;
+ static final int CLOSED = 0x800;
+
+ static final int READING = 0x1000;
+ static final int WRITING = 0x2000;
+
+ // Not null
+ private final AprSocketContext context;
+
+ // only one - to save per/socket memory - context has similar callbacks.
+ BlockingPollHandler handler;
+
+ // Set while it's associated with a poller - it'll stay associated after
+ // connect until close. Destroy will happen in the poller.
+ // POLL bit indicates if the socket is actually polling.
+ AprPoller poller;
+
+ // Bit field indicating the status and socket should only be accessed with
+ // socketLock protection
+ private int status;
+
+ long socket;
+
+ //long to = 10000;
+
+ // Persistent info about the peer ( SSL, etc )
+ private HostInfo hostInfo;
+
+ AprSocket(AprSocketContext context) {
+ this.context = context;
+ }
+
+ public void recycle() {
+ status = 0;
+ hostInfo = null;
+ handler = null;
+ socket = 0;
+ poller = null;
+ }
+
+ @Override
+ public String toString() {
+ return (context.isServer() ? "AprSrv-" : "AprCli-") +
+ Long.toHexString(socket) + " " + Integer.toHexString(status);
+ }
+
+ public void setHandler(BlockingPollHandler l) {
+ handler = l;
+ }
+
+ private void setNonBlocking() {
+ if (socket != 0 && context.running) {
+ Socket.optSet(socket, Socket.APR_SO_NONBLOCK, 1);
+ Socket.timeoutSet(socket, 0);
+ }
+ }
+
+ /**
+ * Check if the socket is currently registered with a poller.
+ */
+ public boolean isPolling() {
+ synchronized (this) {
+ return (status & POLL) != 0;
+ }
+ }
+
+ public BlockingPollHandler getHandler() {
+ return handler;
+ }
+
+ public AprSocketContext getContext() {
+ return context;
+ }
+
+ AprSocket setHost(HostInfo hi) {
+ hostInfo = hi;
+ return this;
+ }
+
+ /**
+ */
+ public void connect() throws IOException {
+ if (isBlocking()) {
+ // will call handleConnected() at the end.
+ context.connectBlocking(this);
+ } else {
+ synchronized(this) {
+ if ((status & CONNECTING) != 0) {
+ return;
+ }
+ status |= CONNECTING;
+ }
+ context.connectExecutor.execute(this);
+ }
+ }
+
+
+ // after connection is done, called from a thread pool ( not IO thread )
+ // may block for handshake.
+ void afterConnect() throws IOException {
+ if (hostInfo.secure) {
+ blockingStartTLS();
+ }
+
+ setNonBlocking(); // call again, to set the bits ( connect was blocking )
+
+ setStatus(CONNECTED);
+ clearStatus(CONNECTING);
+
+ notifyConnected(false);
+ }
+
+ public HostInfo getHost() {
+ return hostInfo;
+ }
+
+ /**
+ * Write as much data as possible to the socket.
+ *
+ * @param data
+ * @param off
+ * @param len
+ * @return For both blocking and non-blocking, returns the number of bytes
+ * written. If no data can be written (e.g. if the buffers are
+ * full) 0 will be returned.
+ * @throws IOException
+ */
+ public int write(byte[] data, int off, int len, long to) throws IOException {
+ long max = System.currentTimeMillis() + to;
+
+ while (true) {
+ int rc = writeInternal(data, off, len);
+ if (rc < 0) {
+ throw new IOException("Write error " + rc);
+ } else if (rc == 0) {
+ // need poll out - do we need to update polling ?
+ context.findPollerAndAdd(this);
+ } else {
+ return rc;
+ }
+
+ try {
+ long waitTime = max - System.currentTimeMillis();
+ if (waitTime <= 0) {
+ return 0;
+ }
+ wait(waitTime);
+ } catch (InterruptedException e) {
+ return 0;
+ }
+ }
+ }
+
+ public int write(byte[] data, int off, int len) throws IOException {
+ // In SSL mode, read/write can't be called at the same time.
+ int rc = writeInternal(data, off, len);
+ if (rc < 0) {
+ throw new IOException("Write error " + rc);
+ } else if (rc == 0) {
+ // need poll out - do we need to update polling ?
+ synchronized (this) {
+ context.findPollerAndAdd(this);
+ }
+ }
+ return rc;
+ }
+
+ private int writeInternal(byte[] data, int off, int len) throws IOException {
+ int rt = 0;
+ int sent = 0;
+ synchronized(this) {
+ if ((status & CLOSED) != 0
+ || socket == 0
+ || !context.running) {
+ throw new IOException("Closed");
+ }
+ if ((status & WRITING) != 0) {
+ throw new IOException("Write from 2 threads not allowed");
+ }
+ status |= WRITING;
+
+ while (len > 0) {
+ sent = Socket.send(socket, data, off, len);
+ if (sent <= 0) {
+ break;
+ }
+ off += sent;
+ len -= sent;
+ }
+
+ status &= ~WRITING;
+ }
+
+ if (context.rawDataHandler != null) {
+ context.rawData(this, false, data, off, sent, len, false);
+ }
+
+ if (sent <= 0) {
+ if (sent == -Status.TIMEUP || sent == -Status.EAGAIN || sent == 0) {
+ setStatus(POLLOUT);
+ updatePolling();
+ return rt;
+ }
+ log.warning("apr.send(): Failed to send, closing " + sent);
+ reset();
+ throw new IOException("Error sending " + sent + " " + Error.strerror(-sent));
+ } else {
+ off += sent;
+ len -= sent;
+ rt += sent;
+ return sent;
+ }
+ }
+
+ public int read(byte[] data, int off, int len, long to) throws IOException {
+ int rd = readNB(data, off, len);
+ if (rd == 0) {
+ synchronized(this) {
+ try {
+ wait(to);
+ } catch (InterruptedException e) {
+ return 0;
+ }
+ }
+ rd = readNB(data, off, len);
+ }
+ return processReadResult(data, off, len, rd);
+ }
+
+ public int read(byte[] data, int off, int len) throws IOException {
+ return readNB(data, off, len);
+ }
+
+ private int processReadResult(byte[] data, int off, int len, int read)
+ throws IOException {
+ if (context.rawDataHandler != null) {
+ context.rawData(this, true, data, off, read, len, false);
+ }
+
+ if (read > 0) {
+ return read;
+ }
+
+ if (read == 0 || read == -Status.TIMEUP || read == -Status.ETIMEDOUT
+ || read == -Status.EAGAIN) {
+ read = 0;
+ setStatus(POLLIN);
+ updatePolling();
+ return 0;
+ }
+
+ if (read == -Status.APR_EOF || read == -1) {
+ close();
+ return -1;
+ }
+ // abrupt close
+ reset();
+ throw new IOException("apr.read(): " + read + " " + Error.strerror(-read));
+ }
+
+ public int readNB(byte[] data, int off, int len) throws IOException {
+ int read;
+ synchronized(this) {
+ if ((status & CLOSED) != 0
+ || socket == 0
+ || !context.running) {
+ return -1;
+ }
+ if ((status & READING) != 0) {
+ throw new IOException("Read from 2 threads not allowed");
+ }
+ status |= READING;
+
+ read = Socket.recv(socket, data, off, len);
+ status &= ~READING;
+ }
+ return processReadResult(data, off, len, read);
+ }
+
+ /*
+ No support for shutdownOutput: SSL is quite tricky.
+ Use close() instead - no read/write will be allowed after.
+
+ */
+
+ public void close() {
+ synchronized (this) {
+ if ((status & CLOSED) != 0 || socket == 0) {
+ return;
+ }
+ status |= CLOSED;
+ status &= ~POLLIN;
+ status &= ~POLLOUT;
+ }
+ if (context.rawDataHandler != null) {
+ context.rawDataHandler.rawData(this, false, null, 0, 0, 0, true);
+ }
+ Socket.close(socket);
+ if (poller == null) {
+ maybeDestroy();
+ } else {
+ try {
+ poller.requestUpdate(this);
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+ }
+
+ void maybeDestroy() {
+ synchronized(this) {
+ if (socket == 0 ||
+ (status & CONNECTING) != 0 || !context.running) {
+ // closed or operation in progress
+ // if context stopped, pool will be destroyed and close
+ // all sockets automatically.
+ return;
+ }
+ if ((status & CLOSED) == 0) {
+ return; // not closed
+ }
+ if ((status & (WRITING | READING)) != 0) {
+ return; // not closed
+ }
+
+ if (context.rawDataHandler != null) {
+ context.rawDataHandler.rawData(this, false, null, -1, -1, -1, true);
+ }
+ if (log.isLoggable(Level.FINE)) {
+ log.info("closing: context.open=" + context.open.get() + " " + this);
+ }
+
+ context.open.decrementAndGet();
+
+ if (socket != 0 && (status & CLOSED) == 0) {
+ Socket.close(socket);
+ status |= CLOSED;
+ }
+
+ if (handler != null) {
+ if (isBlocking()) {
+ context.getExecutor().execute(this);
+ } else {
+ handler.closed(this);
+ }
+ }
+
+ context.destroySocket(this);
+ }
+ }
+
+
+
+ /**
+ * Close input and output, potentially sending RST, than close the socket.
+ *
+ * The proper way to close when gracefully done is by calling writeEnd() and
+ * reading all remaining input until -1 (EOF) is received.
+ *
+ * If EOF is received, the proper way to close is send whatever is remaining and
+ * call writeEnd();
+ */
+ public void reset() {
+ setStatus(ERROR);
+ close();
+ }
+
+
+ /**
+ */
+ public boolean isClosed() {
+ synchronized(this) {
+ if ((status & CLOSED) != 0 || socket == 0 || !context.running) {
+ return true;
+ }
+ return false;
+ }
+ }
+
+ public long getIOTimeout() throws IOException {
+ if (socket != 0 && context.running) {
+ try {
+ return Socket.timeoutGet(socket) / 1000;
+ } catch (Exception e) {
+ throw new IOException(e);
+ }
+ } else {
+ throw new IOException("Socket is closed");
+ }
+ }
+
+ // Cert is in DER format
+ // Called after handshake
+ public byte[][] getPeerCert(boolean check) throws IOException {
+ getHost();
+ if (hostInfo.certs != null && hostInfo.certs != NO_CERTS && !check) {
+ return hostInfo.certs;
+ }
+ if (!checkBitAndSocket(SSL_ATTACHED)) {
+ return NO_CERTS;
+ }
+ try {
+ int certLength = SSLSocket.getInfoI(socket,
+ SSL.SSL_INFO_CLIENT_CERT_CHAIN);
+ // TODO: if resumed, old certs are good.
+ // If not - warn if certs changed, remember first cert, etc.
+ if (certLength <= 0) {
+ // Can also happen on session resume - keep the old
+ if (hostInfo.certs == null) {
+ hostInfo.certs = NO_CERTS;
+ }
+ return hostInfo.certs;
+ }
+ hostInfo.certs = new byte[certLength + 1][];
+
+ hostInfo.certs[0] = SSLSocket.getInfoB(socket,
+ SSL.SSL_INFO_CLIENT_CERT);
+ for (int i = 0; i < certLength; i++) {
+ hostInfo.certs[i + 1] = SSLSocket.getInfoB(socket,
+ SSL.SSL_INFO_CLIENT_CERT_CHAIN + i);
+ }
+ return hostInfo.certs;
+ } catch (Exception e) {
+ throw new IOException(e);
+ }
+ }
+
+ public X509Certificate[] getPeerX509Cert() throws IOException {
+ byte[][] certs = getPeerCert(false);
+ X509Certificate[] xcerts = new X509Certificate[certs.length];
+ if (certs.length == 0) {
+ return xcerts;
+ }
+ try {
+ CertificateFactory cf = CertificateFactory.getInstance("X.509");
+ for (int i = 0; i < certs.length; i++) {
+ if (certs[i] != null) {
+ ByteArrayInputStream bis = new ByteArrayInputStream(
+ certs[i]);
+ xcerts[i] = (X509Certificate) cf.generateCertificate(bis);
+ bis.close();
+ }
+ }
+ } catch (CertificateException ex) {
+ throw new IOException(ex);
+ }
+ return xcerts;
+ }
+
+ public String getCipherSuite() throws IOException {
+ if (checkBitAndSocket(SSL_ATTACHED)) {
+ return null;
+ }
+ try {
+ return SSLSocket.getInfoS(socket, SSL.SSL_INFO_CIPHER);
+ } catch (Exception e) {
+ throw new IOException(e);
+ }
+ }
+
+ public int getKeySize() throws IOException {
+ if (checkBitAndSocket(SSL_ATTACHED)) {
+ return -1;
+ }
+ try {
+ return SSLSocket.getInfoI(socket, SSL.SSL_INFO_CIPHER_USEKEYSIZE);
+ } catch (Exception e) {
+ throw new IOException(e);
+ }
+ }
+
+ public int getRemotePort() throws IOException {
+ if (socket != 0 && context.running) {
+ try {
+ long sa = Address.get(Socket.APR_REMOTE, socket);
+ Sockaddr addr = Address.getInfo(sa);
+ return addr.port;
+ } catch (Exception ex) {
+ throw new IOException(ex);
+ }
+ }
+ throw new IOException("Socket closed");
+ }
+
+ public String getRemoteAddress() throws IOException {
+ if (socket != 0 && context.running) {
+ try {
+ long sa = Address.get(Socket.APR_REMOTE, socket);
+ return Address.getip(sa);
+ } catch (Exception ex) {
+ throw new IOException(ex);
+ }
+ }
+ throw new IOException("Socket closed");
+ }
+
+ public String getRemoteHostname() throws IOException {
+ if (socket != 0 && context.running) {
+ try {
+ long sa = Address.get(Socket.APR_REMOTE, socket);
+ String remoteHost = Address.getnameinfo(sa, 0);
+ if (remoteHost == null) {
+ remoteHost = Address.getip(sa);
+ }
+ return remoteHost;
+ } catch (Exception ex) {
+ throw new IOException(ex);
+ }
+ }
+ throw new IOException("Socket closed");
+ }
+
+ public int getLocalPort() throws IOException {
+ if (socket != 0 && context.running) {
+ try {
+ long sa = Address.get(Socket.APR_LOCAL, socket);
+ Sockaddr addr = Address.getInfo(sa);
+ return addr.port;
+ } catch (Exception ex) {
+ throw new IOException(ex);
+ }
+ }
+ throw new IOException("Socket closed");
+ }
+
+ public String getLocalAddress() throws IOException {
+ if (socket != 0 && context.running) {
+ try {
+ long sa = Address.get(Socket.APR_LOCAL, socket);
+ return Address.getip(sa);
+ } catch (Exception ex) {
+ throw new IOException(ex);
+ }
+ }
+ throw new IOException("Socket closed");
+ }
+
+ public String getLocalHostname() throws IOException {
+ if (socket != 0 && context.running) {
+ try {
+ long sa = Address.get(Socket.APR_LOCAL, socket);
+ return Address.getnameinfo(sa, 0);
+ } catch (Exception ex) {
+ throw new IOException(ex);
+ }
+ }
+ throw new IOException("Socket closed");
+ }
+
+ public boolean isBlocking() {
+ return ! (handler instanceof AprSocketContext.NonBlockingPollHandler);
+ }
+
+ public boolean isError() {
+ return checkPreConnect(ERROR);
+ }
+
+ void notifyError(Throwable err, boolean needsThread) {
+ if (handler instanceof AprSocketContext.NonBlockingPollHandler) {
+ if (err != null) {
+ ((AprSocketContext.NonBlockingPollHandler) handler).error(this, err);
+ }
+ } else {
+ // poller destroyed, etc
+ if (needsThread) {
+ context.getExecutor().execute(this);
+ } else {
+ try {
+ notifyIO();
+ } catch (IOException e) {
+ log.log(Level.SEVERE, this + " error ", e);
+ }
+ }
+ }
+ }
+
+ // Called after connect and from poller.
+ void notifyIO() throws IOException {
+ long t0 = System.currentTimeMillis();
+ try {
+ if (handler != null) {
+ handler.process(this, true, false, false);
+ }
+ } catch (Throwable t) {
+ throw new IOException(t);
+ } finally {
+ long t1 = System.currentTimeMillis();
+ t1 -= t0;
+ if (t1 > context.maxHandlerTime.get()) {
+ context.maxHandlerTime.set(t1);
+ }
+ context.totalHandlerTime.addAndGet(t1);
+ context.handlerCount.incrementAndGet();
+ }
+ }
+
+ private void notifyConnected(boolean server) throws IOException {
+ // Will set the handler on the channel for accepted
+ context.onSocket(this);
+
+ if (handler instanceof AprSocketContext.NonBlockingPollHandler) {
+ ((AprSocketContext.NonBlockingPollHandler) handler).connected(this);
+
+ ((AprSocketContext.NonBlockingPollHandler) handler).process(this, true, true, false);
+ // Now register for polling - unless process() set suspendRead and
+ // doesn't need out notifications
+ updatePolling();
+ } else {
+ if (server) {
+ // client will block in connect().
+ // Server: call process();
+ notifyIO();
+ }
+ }
+ }
+
+ private void updatePolling() throws IOException {
+ synchronized (this) {
+ if ((status & CLOSED) != 0) {
+ maybeDestroy();
+ return;
+ }
+ }
+ context.findPollerAndAdd(this);
+ }
+
+ @Override
+ public void run() {
+ if (!context.running) {
+ return;
+ }
+ if (checkPreConnect(CLOSED)) {
+ if (handler != null) {
+ handler.closed(this);
+ }
+ return;
+ }
+ if (!checkPreConnect(CONNECTED)) {
+ if (checkBitAndSocket(ACCEPTED)) {
+ try {
+ context.open.incrementAndGet();
+
+ if (log.isLoggable(Level.FINE)) {
+ log.info("Accept: " + context.open.get() + " " + this + " " +
+ getRemotePort());
+ }
+ if (context.tcpNoDelay) {
+ Socket.optSet(socket, Socket.APR_TCP_NODELAY, 1);
+ }
+
+ setStatus(CONNECTED);
+ if (context.sslMode) {
+ Socket.timeoutSet(socket,
+ context.connectTimeout * 1000L);
+ blockingStartTLS();
+ }
+ setNonBlocking(); // call again, to set the bits ( connect was blocking )
+
+ notifyConnected(true);
+ return;
+ } catch (Throwable t) {
+ t.printStackTrace(); // no error handler yet
+ reset();
+ notifyError(t, false);
+ return;
+ }
+ }
+ if (checkPreConnect(CONNECTING)) {
+ // Non-blocking connect - will call 'afterConnection' at the end.
+ try {
+ context.connectBlocking(this);
+ } catch (IOException t) {
+ reset(); // also sets status ERROR
+ if (handler instanceof AprSocketContext.NonBlockingPollHandler) {
+ ((AprSocketContext.NonBlockingPollHandler) handler).process(this, false, false, true);
+ }
+ notifyError(t, false);
+ }
+ }
+ } else {
+ if (handler != null) {
+ try {
+ notifyIO();
+ } catch (Throwable e) {
+ log.log(Level.SEVERE, this + " error ", e);
+ reset();
+ // no notifyIO - just did it.
+ }
+ }
+ }
+ }
+
+ /**
+ * This is a blocking call ! ( can be made non-blocking, but too complex )
+ *
+ * Will be called automatically after connect() or accept if 'secure' is
+ * true.
+ *
+ * Can be called manually to upgrade the channel
+ * @throws IOException
+ */
+ public void blockingStartTLS() throws IOException {
+ synchronized(this) {
+ if (socket == 0 || !context.running) {
+ return;
+ }
+ if ((status & SSL_ATTACHED) != 0) {
+ return;
+ }
+ status |= SSL_ATTACHED;
+ }
+
+ try {
+ if (log.isLoggable(Level.FINE)) {
+ log.info(this + " StartSSL");
+ }
+
+ AprSocketContext aprCon = context;
+ SSLSocket.attach(aprCon.getSslCtx(), socket);
+
+ if (context.debugSSL) {
+ SSLExt.debug(socket);
+ }
+ if (!getContext().isServer()) {
+ if (context.USE_TICKETS && hostInfo.ticketLen > 0) {
+ SSLExt.setTicket(socket, hostInfo.ticket,
+ hostInfo.ticketLen);
+ } else if (hostInfo.sessDer != null) {
+ SSLExt.setSessionData(socket, hostInfo.sessDer,
+ hostInfo.sessDer.length);
+ }
+ }
+ SSLExt.sslSetMode(socket, SSLExt.SSL_MODE_ENABLE_PARTIAL_WRITE |
+ SSLExt.SSL_MODE_ACCEPT_MOVING_WRITE_BUFFER);
+
+ int rc = SSLSocket.handshake(socket);
+
+ // At this point we have the session ID, remote certs, etc
+ // we can lookup host info
+ if (hostInfo == null) {
+ hostInfo = new HostInfo();
+ }
+
+ if (rc != Status.APR_SUCCESS) {
+ throw new IOException(this + " Handshake failed " + rc + " "
+ + Error.strerror(rc) + " SSLL "
+ + SSL.getLastError());
+ } else { // SUCCESS
+ handshakeDone();
+ }
+ } catch (IOException e) {
+ throw e;
+ } catch (Exception e) {
+ throw new IOException(e);
+ }
+ }
+
+ private void handshakeDone() throws IOException {
+ getHost();
+ if (socket == 0 || !context.running) {
+ throw new IOException("Socket closed");
+ }
+ if (context.USE_TICKETS && ! context.isServer()) {
+ if (hostInfo.ticket == null) {
+ hostInfo.ticket = new byte[2048];
+ }
+ int ticketLen = SSLExt.getTicket(socket, hostInfo.ticket);
+ if (ticketLen > 0) {
+ hostInfo.ticketLen = ticketLen;
+ if (log.isLoggable(Level.FINE)) {
+ log.info("Received ticket: " + ticketLen);
+ }
+ }
+ }
+
+ // TODO: if the ticket, session id or session changed - callback to
+ // save the session again
+ try {
+ hostInfo.sessDer = SSLExt.getSessionData(socket);
+ getPeerCert(true);
+ hostInfo.sessionId = SSLSocket.getInfoS(socket,
+ SSL.SSL_INFO_SESSION_ID);
+ } catch (Exception e) {
+ throw new IOException(e);
+ }
+
+ hostInfo.npn = new byte[32];
+ hostInfo.npnLen = SSLExt.getNPN(socket, hostInfo.npn);
+
+ // If custom verification is used - should check the certificates
+ if (context.tlsCertVerifier != null) {
+ context.tlsCertVerifier.handshakeDone(this);
+ }
+ }
+
+ int requestedPolling() {
+ synchronized(this) {
+ if (socket == 0 || ((status & CLOSED) != 0)) {
+ return 0;
+ }
+ // Implicit:
+ //Poll.APR_POLLNVAL | Poll.APR_POLLHUP | Poll.APR_POLLERR |
+ int res = 0;
+ if ((status & POLLIN) != 0) {
+ res = Poll.APR_POLLIN;
+ }
+ if ((status & POLLOUT) != 0) {
+ res |= Poll.APR_POLLOUT;
+ }
+ return res;
+ }
+ }
+
+ boolean checkBitAndSocket(int bit) {
+ synchronized (this) {
+ return ((status & bit) != 0 && socket != 0 &&
+ (status & CLOSED) == 0 && context.running);
+ }
+ }
+
+ boolean checkPreConnect(int bit) {
+ synchronized (this) {
+ return ((status & bit) != 0);
+ }
+ }
+
+ void clearStatus(int bit) {
+ synchronized (this) {
+ status &= ~bit;
+ }
+ }
+
+ boolean setStatus(int bit) {
+ synchronized (this) {
+ int old = status & bit;
+ status |= bit;
+ return old != 0;
+ }
+ }
+
+
+}
\ No newline at end of file
diff --git a/jni/java/org/apache/tomcat/jni/socket/AprSocketContext.java b/jni/java/org/apache/tomcat/jni/socket/AprSocketContext.java
new file mode 100644
index 0000000..b6b9536
--- /dev/null
+++ b/jni/java/org/apache/tomcat/jni/socket/AprSocketContext.java
@@ -0,0 +1,1347 @@
+/*
+ * 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.
+ */
+package org.apache.tomcat.jni.socket;
+
+import java.io.IOException;
+import java.net.InetSocketAddress;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.BlockingQueue;
+import java.util.concurrent.Executor;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.LinkedBlockingQueue;
+import java.util.concurrent.RejectedExecutionHandler;
+import java.util.concurrent.ThreadFactory;
+import java.util.concurrent.ThreadPoolExecutor;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.concurrent.atomic.AtomicInteger;
+import java.util.concurrent.atomic.AtomicLong;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import org.apache.tomcat.jni.Address;
+import org.apache.tomcat.jni.Error;
+import org.apache.tomcat.jni.Library;
+import org.apache.tomcat.jni.OS;
+import org.apache.tomcat.jni.Poll;
+import org.apache.tomcat.jni.Pool;
+import org.apache.tomcat.jni.SSL;
+import org.apache.tomcat.jni.SSLContext;
+import org.apache.tomcat.jni.SSLExt;
+import org.apache.tomcat.jni.Socket;
+import org.apache.tomcat.jni.Status;
+
+public class AprSocketContext {
+ /**
+ * Called when a chunk of data is sent or received. This is very low
+ * level, used mostly for debugging or stats.
+ */
+ public static interface RawDataHandler {
+ public void rawData(AprSocket ch, boolean input, byte[] data, int pos,
+ int len, int requested, boolean closed);
+ }
+
+ /**
+ * Called in SSL mode after the handshake is completed.
+ *
+ * @see AprSocketContext#customVerification(TlsCertVerifier)
+ */
+ public static interface TlsCertVerifier {
+ public void handshakeDone(AprSocket ch);
+ }
+
+ /**
+ * Delegates loading of persistent info about a host - public certs,
+ * tickets, config, persistent info etc.
+ */
+ public static interface HostInfoLoader {
+ public HostInfo getHostInfo(String name, int port, boolean ssl);
+ }
+
+ private static final Logger log = Logger.getLogger("AprSocketCtx");
+
+ // If interrupt() or thread-safe poll update are not supported - the
+ // poll updates will happen after the poll() timeout.
+ // The poll timeout with interrupt/thread safe updates can be much higher/
+ private static final int FALLBACK_POLL_TIME = 2000;
+
+ // It seems to send the ticket, get server helo / ChangeCipherSpec, but than
+ // SSL3_GET_RECORD:decryption failed or bad record mac in s3_pkt.c:480:
+ // Either bug in openssl, or some combination of ciphers - needs more debugging.
+ // ( this can save a roundtrip and CPU on TLS handshake )
+ boolean USE_TICKETS = false;
+
+ private final AprSocket END = new AprSocket(this);
+
+ private static final AtomicInteger contextNumber = new AtomicInteger();
+ private int contextId;
+
+ private final AtomicInteger threadNumber = new AtomicInteger();
+
+ /**
+ * For now - single acceptor thread per connector.
+ */
+ private AcceptorThread acceptor;
+ private AcceptorDispatchThread acceptorDispatch;
+
+ // APR/JNI is thread safe
+ private boolean threadSafe = true;
+
+ /**
+ * Pollers.
+ */
+ private final List<AprPoller> pollers = new ArrayList<>();
+
+ // Set on all accepted or connected sockets.
+ // TODO: add the other properties
+ boolean tcpNoDelay = true;
+
+ protected boolean running = true;
+
+ protected boolean sslMode;
+
+ // onSocket() will be called in accept thread.
+ // If false: use executor ( but that may choke the acceptor thread )
+ private boolean nonBlockingAccept = false;
+
+ private final BlockingQueue<AprSocket> acceptedQueue =
+ new LinkedBlockingQueue<>();
+
+ /**
+ * Root APR memory pool.
+ */
+ private long rootPool = 0;
+
+ /**
+ * SSL context.
+ */
+ private long sslCtx = 0;
+
+ TlsCertVerifier tlsCertVerifier;
+
+ //
+ final int connectTimeout = 20000;
+ final int defaultTimeout = 100000;
+ // TODO: Use this
+ final int keepAliveTimeout = 20000;
+
+ final AtomicInteger open = new AtomicInteger();
+
+ /**
+ * Poll interval, in microseconds. If the platform doesn't support
+ * poll interrupt - it'll take this time to stop the poller.
+ *
+ */
+ private int pollTime = 5 * 1000000;
+
+ private HostInfoLoader hostInfoLoader;
+
+ final RawDataHandler rawDataHandler = null;
+
+ // TODO: do we need this here ?
+ private final Map<String, HostInfo> hosts = new HashMap<>();
+
+ private String certFile;
+ private String keyFile;
+
+ private byte[] spdyNPN;
+
+ private byte[] ticketKey;
+
+ // For resolving DNS ( i.e. connect ), callbacks
+ private ExecutorService threadPool;
+
+ // Separate executor for connect/handshakes
+ final ExecutorService connectExecutor;
+
+ final boolean debugSSL = false;
+ private boolean debugPoll = false;
+
+ private boolean deferAccept = false;
+
+ private int backlog = 100;
+
+ private boolean useSendfile;
+
+ private int sslProtocol = SSL.SSL_PROTOCOL_TLSV1 | SSL.SSL_PROTOCOL_SSLV3;
+
+ /**
+ * Max time spent in a callback ( will be longer for blocking )
+ */
+ final AtomicLong maxHandlerTime = new AtomicLong();
+ final AtomicLong totalHandlerTime = new AtomicLong();
+ final AtomicLong handlerCount = new AtomicLong();
+
+ /**
+ * Total connections handled ( accepted or connected ).
+ */
+ private final AtomicInteger connectionsCount = new AtomicInteger();
+
+
+ public AprSocketContext() {
+ connectExecutor =new ThreadPoolExecutor(0, 64, 5, TimeUnit.SECONDS,
+ new LinkedBlockingQueue<Runnable>(), new RejectedExecutionHandler() {
+ @Override
+ public void rejectedExecution(Runnable r,
+ java.util.concurrent.ThreadPoolExecutor executor) {
+ AprSocket s = (AprSocket) r;
+ log.severe("Rejecting " + s);
+ s.reset();
+ }
+ });
+ contextId = contextNumber.incrementAndGet();
+ }
+
+ /**
+ * Poller thread count.
+ */
+ private int pollerThreadCount = 4;
+ public void setPollerThreadCount(int pollerThreadCount) { this.pollerThreadCount = pollerThreadCount; }
+ public int getPollerThreadCount() { return pollerThreadCount; }
+
+ // to test the limits - default should be lower
+ private int maxConnections = 64 * 1024;
+ public void setMaxconnections(int maxCon) {
+ this.maxConnections = maxCon;
+ }
+
+ public void setBacklog(int backlog) { if (backlog > 0) this.backlog = backlog; }
+ public int getBacklog() { return backlog; }
+
+ /**
+ * Defer accept.
+ */
+ public void setDeferAccept(boolean deferAccept) { this.deferAccept = deferAccept; }
+ public boolean getDeferAccept() { return deferAccept; }
+
+ /**
+ * For client:
+ * - ClientHello will include the npn extension ( the ID == 0x3374)
+ * - if ServerHello includes a list of protocols - select one
+ * - send it after ChangeCipherSpec and before Finish
+ *
+ * For server:
+ * - if ClientHello includes the npn extension
+ * -- will send this string as list of supported protocols in ServerHello
+ * - read the selection before Finish.
+ * @param npn
+ */
+ public void setNpn(String npn) {
+ byte[] data = npn.getBytes();
+ byte[] npnB = new byte[data.length + 2];
+
+ System.arraycopy(data, 0, npnB, 1, data.length);
+ npnB[0] = (byte) data.length;
+ npnB[npnB.length - 1] = 0;
+ spdyNPN = npnB;
+
+ }
+
+ public void setNpn(byte[] data) {
+ spdyNPN = data;
+ }
+
+ public void setHostLoader(HostInfoLoader handler) {
+ this.hostInfoLoader = handler;
+ }
+
+ public boolean isServer() {
+ return acceptor != null;
+ }
+
+ protected Executor getExecutor() {
+ if (threadPool == null) {
+ threadPool = Executors.newCachedThreadPool(new ThreadFactory( ) {
+ @Override
+ public Thread newThread(Runnable r) {
+ Thread t = new Thread(r, "AprThread-" + contextId + "-" +
+ threadNumber.incrementAndGet());
+ t.setDaemon(true);
+ return t;
+ }
+ });
+ }
+ return threadPool;
+ }
+
+ /**
+ * All accepted/connected sockets will start handshake automatically.
+ */
+ public AprSocketContext setTls() {
+ this.sslMode = true;
+ return this;
+ }
+
+ public void setTcpNoDelay(boolean b) {
+ tcpNoDelay = b;
+ }
+
+ public void setSslProtocol(String protocol) {
+ protocol = protocol.trim();
+ if ("SSLv2".equalsIgnoreCase(protocol)) {
+ sslProtocol = SSL.SSL_PROTOCOL_SSLV2;
+ } else if ("SSLv3".equalsIgnoreCase(protocol)) {
+ sslProtocol = SSL.SSL_PROTOCOL_SSLV3;
+ } else if ("TLSv1".equalsIgnoreCase(protocol)) {
+ sslProtocol = SSL.SSL_PROTOCOL_TLSV1;
+ } else if ("all".equalsIgnoreCase(protocol)) {
+ sslProtocol = SSL.SSL_PROTOCOL_ALL;
+ }
+ }
+
+ public void setTicketKey(byte[] key48Bytes) {
+ if(key48Bytes.length != 48) {
+ throw new RuntimeException("Key must be 48 bytes");
+ }
+ this.ticketKey = key48Bytes;
+ }
+
+ public void customVerification(TlsCertVerifier verifier) {
+ tlsCertVerifier = verifier;
+ }
+
+ // TODO: should have a separate method for switching to tls later.
+ /**
+ * Set certificate, will also enable TLS mode.
+ */
+ public AprSocketContext setKeys(String certPemFile, String keyDerFile) {
+ this.sslMode = true;
+ setTls();
+ certFile = certPemFile;
+ keyFile = keyDerFile;
+ return this;
+ }
+
+ /**
+ * SSL cipher suite.
+ */
+ private String SSLCipherSuite = "ALL";
+ public String getSSLCipherSuite() { return SSLCipherSuite; }
+ public void setSSLCipherSuite(String SSLCipherSuite) { this.SSLCipherSuite = SSLCipherSuite; }
+
+ /**
+ * Override or use hostInfoLoader to implement persistent/memcache storage.
+ */
+ public HostInfo getHostInfo(String host, int port, boolean ssl) {
+ if (hostInfoLoader != null) {
+ return hostInfoLoader.getHostInfo(host, port, ssl);
+ }
+ // Use local cache
+ String key = host + ":" + port;
+ HostInfo pi = hosts.get(key);
+ if (pi != null) {
+ return pi;
+ }
+ pi = new HostInfo(host, port, ssl);
+ hosts.put(key, pi);
+ return pi;
+ }
+
+ protected void rawData(AprSocket ch, boolean inp, byte[] data, int pos,
+ int len, int requested, boolean closed) {
+ if (rawDataHandler != null) {
+ rawDataHandler.rawData(ch, inp, data, pos, len, requested, closed);
+ }
+ }
+
+ public void listen(final int port) throws IOException {
+ if (acceptor != null) {
+ throw new IOException("Already accepting on " + acceptor.port);
+ }
+ if (sslMode && certFile == null) {
+ throw new IOException("Missing certificates for server");
+ }
+ if (sslMode || !nonBlockingAccept) {
+ acceptorDispatch = new AcceptorDispatchThread();
+ acceptorDispatch.setName("AprAcceptorDispatch-" + port);
+ acceptorDispatch.start();
+ }
+
+ acceptor = new AcceptorThread(port);
+ acceptor.prepare();
+ acceptor.setName("AprAcceptor-" + port);
+ acceptor.start();
+
+
+ }
+
+ /**
+ * Get a socket for connectiong to host:port.
+ */
+ public AprSocket socket(String host, int port, boolean ssl) {
+ HostInfo hi = getHostInfo(host, port, ssl);
+ return socket(hi);
+ }
+
+ public AprSocket socket(HostInfo hi) {
+ AprSocket sock = newSocket(this);
+ sock.setHost(hi);
+ return sock;
+ }
+
+ public AprSocket socket(long socket) {
+ AprSocket sock = newSocket(this);
+ // Tomcat doesn't set this
+ SSLExt.sslSetMode(socket, SSLExt.SSL_MODE_ENABLE_PARTIAL_WRITE |
+ SSLExt.SSL_MODE_ACCEPT_MOVING_WRITE_BUFFER);
+ sock.setStatus(AprSocket.ACCEPTED);
+ sock.socket = socket;
+ return sock;
+ }
+
+
+ void destroySocket(AprSocket socket) {
+ // TODO: does it need to be done in io thread ?
+ synchronized (socket) {
+ if (socket.socket != 0) {
+ long s = socket.socket;
+ socket.socket = 0;
+ log.info("DESTROY: " + Long.toHexString(s));
+ Socket.destroy(s);
+ }
+ }
+ }
+
+ protected void connectBlocking(AprSocket apr) throws IOException {
+ try {
+ if (!running) {
+ throw new IOException("Stopped");
+ }
+ HostInfo hi = apr.getHost();
+
+ long clientSockP;
+ synchronized (pollers) {
+ long socketpool = Pool.create(getRootPool());
+
+ int family = Socket.APR_INET;
+
+ clientSockP = Socket.create(family,
+ Socket.SOCK_STREAM,
+ Socket.APR_PROTO_TCP, socketpool); // or rootPool ?
+ }
+ Socket.timeoutSet(clientSockP, connectTimeout * 1000);
+ if (OS.IS_UNIX) {
+ Socket.optSet(clientSockP, Socket.APR_SO_REUSEADDR, 1);
+ }
+
+ Socket.optSet(clientSockP, Socket.APR_SO_KEEPALIVE, 1);
+
+ // Blocking
+ // TODO: use socket pool
+ // TODO: cache it ( and TTL ) in hi
+ long inetAddress = Address.info(hi.host, Socket.APR_INET,
+ hi.port, 0, rootPool);
+ // this may take a long time - stop/destroy must wait
+ // at least connect timeout
+ int rc = Socket.connect(clientSockP, inetAddress);
+
+ if (rc != 0) {
+ synchronized (pollers) {
+ Socket.close(clientSockP);
+ Socket.destroy(clientSockP);
+ }
+ /////Pool.destroy(socketpool);
+ throw new IOException("Socket.connect(): " + rc + " " + Error.strerror(rc) + " " + connectTimeout);
+ }
+ if (!running) {
+ throw new IOException("Stopped");
+ }
+
+ connectionsCount.incrementAndGet();
+ if (tcpNoDelay) {
+ Socket.optSet(clientSockP, Socket.APR_TCP_NODELAY, 1);
+ }
+
+ Socket.timeoutSet(clientSockP, defaultTimeout * 1000);
+
+ apr.socket = clientSockP;
+
+ apr.afterConnect();
+ } catch (IOException e) {
+ apr.reset();
+ throw e;
+ } catch (Throwable e) {
+ apr.reset();
+ e.printStackTrace();
+ throw new IOException(e);
+ }
+ }
+
+ AprSocket newSocket(AprSocketContext context) {
+ return new AprSocket(context);
+ }
+
+ /**
+ * To clean the pools - we could track if all channels are
+ * closed, but this seems simpler and safer.
+ */
+ @Override
+ protected void finalize() {
+ if (rootPool != 0) {
+ log.warning(this + " GC without stop()");
+ try {
+ stop();
+ } catch (Exception e) {
+ //TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+ }
+
+
+ public void stop() {
+ synchronized (pollers) {
+ if (!running) {
+ return;
+ }
+ running = false;
+ }
+
+ if (rootPool != 0) {
+ if (acceptor != null) {
+ try {
+ acceptor.unblock();
+ acceptor.join();
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+ }
+ if (acceptorDispatch != null) {
+ acceptedQueue.add(END);
+ try {
+ acceptorDispatch.join();
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+ }
+ if (threadPool != null) {
+ threadPool.shutdownNow();
+ }
+
+ log.info("Stopping pollers " + contextId);
+
+ while (true) {
+ AprPoller a;
+ synchronized (pollers) {
+ if (pollers.size() == 0) {
+ break;
+ }
+ a = pollers.remove(0);
+ }
+ a.interruptPoll();
+ try {
+ a.join();
+ log.info("Poller " + a.id + " done ");
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+ }
+ }
+ }
+
+
+ // Called when the last poller has been destroyed.
+ void destroy() {
+ synchronized (pollers) {
+ if (pollers.size() != 0) {
+ return;
+ }
+
+ if (rootPool == 0) {
+ return;
+ }
+ log.info("Destroy root pool " + rootPool);
+ //Pool.destroy(rootPool);
+ //rootPool = 0;
+ }
+ }
+
+ private static IOException noApr;
+ static {
+
+ try {
+ Library.initialize(null);
+ SSL.initialize(null);
+ } catch (Exception e) {
+ noApr = new IOException("APR not present", e);
+ }
+
+ }
+
+ private long getRootPool() throws IOException {
+ if (rootPool == 0) {
+ if (noApr != null) {
+ throw noApr;
+ }
+ // Create the root APR memory pool
+ rootPool = Pool.create(0);
+
+ // Adjust poller sizes
+ if ((OS.IS_WIN32 || OS.IS_WIN64) && (maxConnections > 1024)) {
+ // The maximum per poller to get reasonable performance is 1024
+ pollerThreadCount = maxConnections / 1024;
+ // Adjust poller size so that it won't reach the limit
+ maxConnections = maxConnections - (maxConnections % 1024);
+ }
+ }
+ return rootPool;
+ }
+
+ long getSslCtx() throws Exception {
+ if (sslCtx == 0) {
+ synchronized (AprSocketContext.class) {
+
+ boolean serverMode = acceptor != null;
+ sslCtx = SSLContext.make(getRootPool(),
+ sslProtocol,
+ serverMode ? SSL.SSL_MODE_SERVER : SSL.SSL_MODE_CLIENT);
+
+
+ // SSL.SSL_OP_NO_SSLv3
+ int opts = SSL.SSL_OP_NO_SSLv2 |
+ SSL.SSL_OP_SINGLE_DH_USE;
+
+ if (!USE_TICKETS || serverMode && ticketKey == null) {
+ opts |= SSL.SSL_OP_NO_TICKET;
+ }
+
+ SSLContext.setOptions(sslCtx, opts);
+ // Set revocation
+ // SSLContext.setCARevocation(sslContext, SSLCARevocationFile, SSLCARevocationPath);
+
+ // Client certificate verification - maybe make it option
+ try {
+ SSLContext.setCipherSuite(sslCtx, SSLCipherSuite);
+
+
+ if (serverMode) {
+ if (ticketKey != null) {
+ //SSLExt.setTicketKeys(sslCtx, ticketKey, ticketKey.length);
+ }
+ if (certFile != null) {
+ boolean rc = SSLContext.setCertificate(sslCtx,
+ certFile,
+ keyFile, null, SSL.SSL_AIDX_DSA);
+ if (!rc) {
+ throw new IOException("Can't set keys");
+ }
+ }
+ SSLContext.setVerify(sslCtx, SSL.SSL_CVERIFY_NONE, 10);
+
+ if (spdyNPN != null) {
+ SSLExt.setNPN(sslCtx, spdyNPN, spdyNPN.length);
+ }
+ } else {
+ if (tlsCertVerifier != null) {
+ // NONE ?
+ SSLContext.setVerify(sslCtx,
+ SSL.SSL_CVERIFY_NONE, 10);
+ } else {
+ SSLContext.setCACertificate(sslCtx,
+ "/etc/ssl/certs/ca-certificates.crt",
+ "/etc/ssl/certs");
+ SSLContext.setVerify(sslCtx,
+ SSL.SSL_CVERIFY_REQUIRE, 10);
+ }
+
+ if (spdyNPN != null) {
+ SSLExt.setNPN(sslCtx, spdyNPN, spdyNPN.length);
+ }
+ }
+ } catch (IOException e) {
+ throw e;
+ } catch (Exception e) {
+ throw new IOException(e);
+ }
+
+ // TODO: try release buffers
+ }
+ }
+ return sslCtx;
+ }
+
+ void findPollerAndAdd(AprSocket ch) throws IOException {
+ if (ch.poller != null) {
+ ch.poller.requestUpdate(ch);
+ return;
+ }
+ assignPoller(ch);
+ }
+
+ void assignPoller(AprSocket ch) throws IOException {
+ AprPoller target = null;
+ synchronized (pollers) {
+ // Make sure we have min number of pollers
+ int needPollers = pollerThreadCount - pollers.size();
+ if (needPollers > 0) {
+ for (int i = needPollers; i > 0; i--) {
+ pollers.add(allocatePoller());
+ }
+ }
+ int max = 0;
+ for (AprPoller poller: pollers) {
+ int rem = poller.remaining();
+ if (rem > max) {
+ target = poller;
+ max = rem;
+ }
+ }
+ }
+ if (target != null && target.add(ch)) {
+ return;
+ }
+
+ // can't be added - add a new poller
+ synchronized (pollers) {
+ AprPoller poller = allocatePoller();
+ poller.add(ch);
+ pollers.add(poller);
+ }
+ }
+
+ /**
+ * Called on each accepted socket (for servers) or after connection (client)
+ * after handshake.
+ */
+ protected void onSocket(@SuppressWarnings("unused") AprSocket s) {
+ // Defaults to NO-OP. Parameter is used by sub-classes.
+ }
+
+ private class AcceptorThread extends Thread {
+ private final int port;
+ private long serverSockPool = 0;
+ private long serverSock = 0;
+
+ private long inetAddress;
+
+ AcceptorThread(int port) {
+ this.port = port;
+ setDaemon(true);
+ }
+
+ void prepare() throws IOException {
+ try {
+ // Create the pool for the server socket
+ serverSockPool = Pool.create(getRootPool());
+
+ int family = Socket.APR_INET;
+ inetAddress =
+ Address.info(null, family, port, 0, serverSockPool);
+
+ // Create the APR server socket
+ serverSock = Socket.create(family,
+ Socket.SOCK_STREAM,
+ Socket.APR_PROTO_TCP, serverSockPool);
+
+ if (OS.IS_UNIX) {
+ Socket.optSet(serverSock, Socket.APR_SO_REUSEADDR, 1);
+ }
+ // Deal with the firewalls that tend to drop the inactive sockets
+ Socket.optSet(serverSock, Socket.APR_SO_KEEPALIVE, 1);
+ // Bind the server socket
+ int ret = Socket.bind(serverSock, inetAddress);
+ if (ret != 0) {
+ throw new IOException("Socket.bind " + ret + " " +
+ Error.strerror(ret) + " port=" + port);
+ }
+ // Start listening on the server socket
+ ret = Socket.listen(serverSock, backlog );
+ if (ret != 0) {
+ throw new IOException("endpoint.init.listen"
+ + ret + " " + Error.strerror(ret));
+ }
+ if (OS.IS_WIN32 || OS.IS_WIN64) {
+ // On Windows set the reuseaddr flag after the bind/listen
+ Socket.optSet(serverSock, Socket.APR_SO_REUSEADDR, 1);
+ }
+
+ // Sendfile usage on systems which don't support it cause major problems
+ if (useSendfile && !Library.APR_HAS_SENDFILE) {
+ useSendfile = false;
+ }
+
+ // Delay accepting of new connections until data is available
+ // Only Linux kernels 2.4 + have that implemented
+ // on other platforms this call is noop and will return APR_ENOTIMPL.
+ if (deferAccept) {
+ if (Socket.optSet(serverSock, Socket.APR_TCP_DEFER_ACCEPT, 1) == Status.APR_ENOTIMPL) {
+ deferAccept = false;
+ }
+ }
+ } catch (Throwable t) {
+ throw new IOException(t);
+ }
+ }
+
+ void unblock() {
+ try (java.net.Socket sock = new java.net.Socket()) {
+ // Easiest ( maybe safest ) way to interrupt accept
+ // we could have it in non-blocking mode, etc
+ sock.connect(new InetSocketAddress("127.0.0.1", port));
+ } catch (Exception ex) {
+ // ignore - the acceptor may have shut down by itself.
+ }
+ }
+
+ @Override
+ public void run() {
+ while (running) {
+ try {
+ // each socket has a pool.
+ final AprSocket ch = newSocket(AprSocketContext.this);
+ ch.setStatus(AprSocket.ACCEPTED);
+
+ ch.socket = Socket.accept(serverSock);
+ if (!running) {
+ break;
+ }
+ connectionsCount.incrementAndGet();
+ if (connectionsCount.get() % 1000 == 0) {
+ System.err.println("Accepted: " + connectionsCount.get());
+ }
+
+ if (nonBlockingAccept && !sslMode) {
+ ch.setStatus(AprSocket.CONNECTED);
+ // TODO: SSL really needs a thread.
+ onSocket(ch);
+ } else {
+ acceptedQueue.add(ch);
+ }
+ } catch (Throwable e) {
+ e.printStackTrace();
+ }
+ }
+ Socket.close(serverSock);
+ }
+ }
+
+ private class AcceptorDispatchThread extends Thread {
+
+ AcceptorDispatchThread() {
+ setDaemon(true);
+ }
+
+ @Override
+ public void run() {
+ while(running) {
+ try {
+ AprSocket ch = acceptedQueue.take();
+ if (ch == END) {
+ return;
+ }
+ connectExecutor.execute(ch);
+ } catch (InterruptedException e) {
+ }
+ }
+ }
+ }
+
+ /**
+ * Create the poller. With some versions of APR, the maximum poller size will
+ * be 62 (recompiling APR is necessary to remove this limitation).
+ * @throws IOException
+ */
+ AprPoller allocatePoller() throws IOException {
+ long pool = Pool.create(getRootPool());
+ int size = maxConnections / pollerThreadCount;
+
+ long serverPollset = allocatePoller(size, pool);
+
+ if (serverPollset == 0 && size > 1024) {
+ log.severe("Falling back to 1024-sized poll, won't scale");
+ size = 1024;
+ serverPollset = allocatePoller(size, pool);
+ }
+ if (serverPollset == 0) {
+ log.severe("Falling back to 62-sized poll, won't scale");
+ size = 62;
+ serverPollset = allocatePoller(size, pool);
+ }
+
+ AprPoller res = new AprPoller();
+ res.pool = pool;
+ res.serverPollset = serverPollset;
+ res.desc = new long[size * 2];
+ res.size = size;
+ res.id = contextId++;
+ res.setDaemon(true);
+ res.setName("AprPoller-" + res.id);
+ res.start();
+ if (debugPoll && !sizeLogged) {
+ sizeLogged = true;
+ log.info("Poller size " + (res.desc.length / 2));
+ }
+ return res;
+ }
+
+ // Removed the 'thread safe' updates for now, to simplify the code
+ // last test shows a small improvement, can switch later.
+ private static boolean sizeLogged = false;
+
+ protected long allocatePoller(int size, long pool) {
+ int flag = threadSafe ? Poll.APR_POLLSET_THREADSAFE: 0;
+ for (int i = 0; i < 2; i++) {
+ try {
+ // timeout must be -1 - or ttl will take effect, strange results.
+ return Poll.create(size, pool, flag, -1);
+ } catch (Error e) {
+ e.printStackTrace();
+ if (Status.APR_STATUS_IS_EINVAL(e.getError())) {
+ log.info(" endpoint.poll.limitedpollsize " + size);
+ return 0;
+ } else if (Status.APR_STATUS_IS_ENOTIMPL(e.getError())) {
+ // thread safe not supported
+ log.severe("THREAD SAFE NOT SUPPORTED" + e);
+ threadSafe = false;
+ // try again without the flags
+ continue;
+ } else {
+ log.severe("endpoint.poll.initfail" + e);
+ return 0;
+ }
+ }
+ }
+ log.severe("Unexpected ENOTIMPL with flag==0");
+ return 0;
+ }
+
+ class AprPoller extends Thread {
+
+ private int id;
+ private int size;
+ private long serverPollset = 0;
+ private long pool = 0;
+ private long[] desc;
+
+ private long lastPoll;
+ private long lastPollTime;
+ private final AtomicBoolean inPoll = new AtomicBoolean(false);
+
+ // Should be replaced with socket data.
+ // used only to lookup by socket
+ private final Map<Long, AprSocket> channels = new HashMap<>();
+
+ // Active + pending, must be < desc.length / 2
+ // The channel will also have poller=this when active or pending
+ // How many sockets have poller == this
+ private final AtomicInteger keepAliveCount = new AtomicInteger();
+ // Tracks desc, how many sockets are actively polled
+ private final AtomicInteger polledCount = new AtomicInteger();
+
+ private final AtomicInteger pollCount = new AtomicInteger();
+
+ private final List<AprSocket> updates = new ArrayList<>();
+
+ @Override
+ public void run() {
+ if (!running) {
+ return;
+ }
+ if (debugPoll) {
+ log.info("Starting poller " + id + " " + (isServer() ? "SRV ": "CLI "));
+ }
+ long t0 = System.currentTimeMillis();
+ while (running) {
+ try {
+ updates();
+
+ // Pool for the specified interval. Remove signaled sockets
+ synchronized (this) {
+ inPoll.set(true);
+ }
+ // if updates are added after updates and poll - interrupt will have still
+ // work
+
+ int rv = Poll.poll(serverPollset, pollTime, desc, true);
+ synchronized (this) {
+ inPoll.set(false);
+ if (!running) {
+ break;
+ }
+ }
+
+ pollCount.incrementAndGet();
+ lastPoll = System.currentTimeMillis();
+ lastPollTime = lastPoll - t0;
+
+ if (rv > 0) {
+ if (debugPoll) {
+ log.info(" Poll() id=" + id + " rv=" + rv + " keepAliveCount=" + keepAliveCount +
+ " polled = " + polledCount.get()
+ + " time=" + lastPollTime);
+ }
+ polledCount.addAndGet(-rv);
+ for (int pollIdx = 0; pollIdx < rv; pollIdx++) {
+ long sock = desc[pollIdx * 2 + 1];
+ AprSocket ch;
+ boolean blocking = false;
+
+ synchronized (channels) {
+ ch = channels.get(Long.valueOf(sock));
+ if (ch != null) {
+ blocking = ch.isBlocking();
+ } else {
+ log.severe("Polled socket not found !!!!!" + Long.toHexString(sock));
+ // TODO: destroy/close the raw socket
+ continue;
+ }
+ }
+ // was removed from polling
+ ch.clearStatus(AprSocket.POLL);
+
+ // We just removed it ( see last param to poll()).
+ // Check for failed sockets and hand this socket off to a worker
+ long mask = desc[pollIdx * 2];
+
+ boolean err = ((mask & Poll.APR_POLLERR) == Poll.APR_POLLERR);
+ boolean nval = ((mask & Poll.APR_POLLNVAL) != 0);
+ if (err || nval) {
+ System.err.println("ERR " + err + " NVAL " + nval);
+ }
+
+ boolean out = (mask & Poll.APR_POLLOUT) == Poll.APR_POLLOUT;
+ boolean in = (mask & Poll.APR_POLLIN) == Poll.APR_POLLIN;
+ if (debugPoll) {
+ log.info(" Poll channel: " + Long.toHexString(mask) +
+ (out ? " OUT" :"") +
+ (in ? " IN": "") +
+ (err ? " ERR" : "") +
+ " Ch: " + ch);
+ }
+
+ // will be set again in process(), if all read/write is done
+ ch.clearStatus(AprSocket.POLLOUT);
+ ch.clearStatus(AprSocket.POLLIN);
+
+ // try to send if needed
+ if (blocking) {
+ synchronized (ch) {
+ ch.notifyAll();
+ }
+ getExecutor().execute(ch);
+ } else {
+ ((AprSocketContext.NonBlockingPollHandler) ch.handler).process(ch, in, out, false);
+
+ // Update polling for the channel (in IO thread, safe)
+ updateIOThread(ch);
+ }
+ }
+ } else if (rv < 0) {
+ int errn = -rv;
+ if (errn == Status.TIMEUP) {
+ // to or interrupt
+// if (debugPoll) {
+// log.info(" Poll() timeup" + " keepAliveCount=" + keepAliveCount +
+// " polled = " + polledCount.get()
+// + " time=" + lastPollTime);
+// }
+ } else if (errn == Status.EINTR) {
+ // interrupt - no need to log
+ } else {
+ if (debugPoll) {
+ log.info(" Poll() rv=" + rv + " keepAliveCount=" + keepAliveCount +
+ " polled = " + polledCount.get()
+ + " time=" + lastPollTime);
+ }
+ /* Any non timeup or interrupted error is critical */
+ if (errn > Status.APR_OS_START_USERERR) {
+ errn -= Status.APR_OS_START_USERERR;
+ }
+ log.severe("endpoint.poll.fail " + errn + " " + Error.strerror(errn));
+ // Handle poll critical failure
+ synchronized (this) {
+ destroyPoller(); // will close all sockets
+ }
+ continue;
+ }
+ }
+ // TODO: timeouts
+ } catch (Throwable t) {
+ log.log(Level.SEVERE, "endpoint.poll.error", t);
+ }
+
+ }
+ if (!running) {
+ destroyPoller();
+ }
+ }
+
+ /**
+ * Destroy the poller.
+ */
+ protected void destroyPoller() {
+ synchronized (pollers) {
+ pollers.remove(this);
+ }
+ log.info("Poller stopped after cnt=" +
+ pollCount.get() +
+ " sockets=" + channels.size() +
+ " lastPoll=" + lastPoll);
+
+ // Close all sockets
+ synchronized (this) {
+ if (serverPollset == 0) {
+ return;
+ }
+
+// for (AprSocket ch: channels.values()) {
+// ch.poller = null;
+// ch.reset();
+// }
+ keepAliveCount.set(0);
+ log.warning("Destroy pollset");
+ //serverPollset = 0;
+ }
+ Pool.destroy(pool);
+ pool = 0;
+ synchronized (pollers) {
+ // Now we can destroy the root pool
+ if (pollers.size() == 0 && !running) {
+ log.info("Destroy server context");
+// AprSocketContext.this.destroy();
+ }
+ }
+ }
+
+ /**
+ * Called only in poller thread, only used if not thread safe
+ * @throws IOException
+ */
+ protected void updates() throws IOException {
+ synchronized (this) {
+ for (AprSocket up: updates) {
+ updateIOThread(up);
+ }
+ updates.clear();
+ }
+ }
+
+ void interruptPoll() {
+ try {
+ int rc = Status.APR_SUCCESS;
+ synchronized (this) {
+ if (serverPollset != 0) {
+ rc = Poll.interrupt(serverPollset);
+ } else {
+ log.severe("Interrupt with closed pollset");
+ }
+ }
+ if (rc != Status.APR_SUCCESS) {
+ log.severe("Failed interrupt and not thread safe");
+ }
+ } catch (Throwable t) {
+ t.printStackTrace();
+ if (pollTime > FALLBACK_POLL_TIME) {
+ pollTime = FALLBACK_POLL_TIME;
+ }
+ }
+ }
+
+
+ int remaining() {
+ synchronized (channels) {
+ return (desc.length - channels.size() * 2);
+ }
+ }
+
+
+
+ /**
+ * Called from any thread, return true if we could add it
+ * to pending.
+ */
+ boolean add(AprSocket ch) throws IOException {
+ synchronized (this) {
+ if (!running) {
+ return false;
+ }
+ if (keepAliveCount.get() >= size) {
+ return false;
+ }
+ keepAliveCount.incrementAndGet();
+ ch.poller = this;
+ }
+
+ requestUpdate(ch);
+
+ return true;
+ }
+
+ /**
+ * May be called outside of IOThread.
+ */
+ protected void requestUpdate(AprSocket ch) throws IOException {
+ synchronized (this) {
+ if (!running) {
+ return;
+ }
+ }
+ if (isPollerThread()) {
+ updateIOThread(ch);
+ } else {
+ synchronized (this) {
+ if (!updates.contains(ch)) {
+ updates.add(ch);
+ }
+ interruptPoll();
+ }
+ if (debugPoll) {
+ log.info("Poll: requestUpdate " + id + " " + ch);
+ }
+ }
+ }
+
+ private void updateIOThread(AprSocket ch) throws IOException {
+ if (!running || ch.socket == 0) {
+ return;
+ }
+ // called from IO thread, either in 'updates' or after
+ // poll.
+ //synchronized (ch)
+ boolean polling = ch.checkPreConnect(AprSocket.POLL);
+
+ int requested = ch.requestedPolling();
+ if (requested == 0) {
+ if (polling) {
+ removeSafe(ch);
+ }
+ if (ch.isClosed()) {
+ synchronized (channels) {
+ ch.poller = null;
+ channels.remove(Long.valueOf(ch.socket));
+ }
+ keepAliveCount.decrementAndGet();
+ ch.reset();
+ }
+ } else {
+ if (polling) {
+ removeSafe(ch);
+ }
+ // will close if error
+ pollAdd(ch, requested);
+ }
+ if (debugPoll) {
+ log.info("Poll: updated=" + id + " " + ch);
+ }
+ }
+
+ /**
+ * Called only from IO thread
+ */
+ private void pollAdd(AprSocket up, int req) throws IOException {
+ boolean failed = false;
+ int rv;
+ synchronized (channels) {
+ if (up.isClosed()) {
+ return;
+ }
+ rv = Poll.add(serverPollset, up.socket, req);
+ if (rv != Status.APR_SUCCESS) {
+ up.poller = null;
+ keepAliveCount.decrementAndGet();
+ failed = true;
+ } else {
+ polledCount.incrementAndGet();
+ channels.put(Long.valueOf(up.socket), up);
+ up.setStatus(AprSocket.POLL);
+ }
+ }
+ if (failed) {
+ up.reset();
+ throw new IOException("poll add error " + rv + " " + up + " " + Error.strerror(rv));
+ }
+ }
+
+ /**
+ * Called only from IO thread. Remove from Poll and channels,
+ * set POLL bit to false.
+ */
+ private void removeSafe(AprSocket up) {
+ int rv = Status.APR_EGENERAL;
+ if (running && serverPollset != 0 && up.socket != 0
+ && !up.isClosed()) {
+ rv = Poll.remove(serverPollset, up.socket);
+ }
+ up.clearStatus(AprSocket.POLL);
+
+ if (rv != Status.APR_SUCCESS) {
+ log.severe("poll remove error " + Error.strerror(rv) + " " + up);
+ } else {
+ polledCount.decrementAndGet();
+ }
+ }
+
+
+ public boolean isPollerThread() {
+ return Thread.currentThread() == this;
+ }
+
+ }
+
+ /**
+ * Callback for poll events, will be invoked in a thread pool.
+ *
+ */
+ public static interface BlockingPollHandler {
+
+ /**
+ * Called when the socket has been polled for in, out or closed.
+ *
+ *
+ */
+ public void process(AprSocket ch, boolean in, boolean out, boolean close);
+
+
+ /**
+ * Called just before the socket is destroyed
+ */
+ public void closed(AprSocket ch);
+ }
+
+ /**
+ * Additional callbacks for non-blocking.
+ * This can be much faster - but it's harder to code, should be used only
+ * for low-level protocol implementation, proxies, etc.
+ *
+ * The model is restricted in many ways to avoid complexity and bugs:
+ *
+ * - read can only happen in the IO thread associated with the poller
+ * - user doesn't control poll interest - it is set automatically based
+ * on read/write results
+ * - it is only possible to suspend read, for TCP flow control - also
+ * only from the IO thread. Resume can happen from any thread.
+ * - it is also possible to call write() from any thread
+ */
+ public static interface NonBlockingPollHandler extends BlockingPollHandler {
+
+ /**
+ * Called after connection is established, in a thread pool.
+ * Process will be called next.
+ */
+ public void connected(AprSocket ch);
+
+ /**
+ * Before close, if an exception happens.
+ */
+ public void error(AprSocket ch, Throwable t);
+ }
+
+}
diff --git a/jni/java/org/apache/tomcat/jni/socket/HostInfo.java b/jni/java/org/apache/tomcat/jni/socket/HostInfo.java
new file mode 100644
index 0000000..4262910
--- /dev/null
+++ b/jni/java/org/apache/tomcat/jni/socket/HostInfo.java
@@ -0,0 +1,84 @@
+/*
+ * 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.
+ */
+package org.apache.tomcat.jni.socket;
+
+import java.io.Serializable;
+
+/**
+ * Information about the remote host. Persisting this in memcache or similar
+ * storage can improve performance on future TLS connections by skipping roundtrips
+ * and reducing CPU use in handshake.
+ *
+ * This class is used in both server and client mode.
+ *
+ * AprSocketContextLitener.getPeer(name) can be used to read from an external storage.
+ *
+ * TODO: also save the SPDY persistent settings here.
+ * TODO: fix tickets, don't seem to work anymore.
+ */
+public class HostInfo implements Serializable {
+
+ private static final long serialVersionUID = 1L;
+
+ public String host;
+
+ public int port;
+
+ public boolean secure;
+
+ /**
+ * Raw cert data (x.509 format).
+ * This is retrieved when a full handshake happens - if session reuse or tickets
+ * are used you'll not receive the certs again.
+ */
+ public byte[][] certs;
+
+ public byte[] ticket;
+ public int ticketLen;
+
+ public String sessionId;
+
+ /**
+ * DER-encoded session data.
+ */
+ public byte[] sessDer;
+
+ /**
+ * Negotiated NPN.
+ */
+ byte[] npn;
+ int npnLen;
+
+ public HostInfo() {
+ }
+
+ public HostInfo(String host, int port, boolean secure) {
+ this.host = host;
+ this.port = port;
+ this.secure = secure;
+ }
+
+ public String getNpn() {
+ return new String(npn, 0, npnLen);
+ }
+
+ public void setNpn(String npn) {
+ if (npn == null) {
+ npnLen = 0;
+ }
+ }
+}
\ No newline at end of file
diff --git a/jni/java/overview.html b/jni/java/overview.html
new file mode 100644
index 0000000..56f30bb
--- /dev/null
+++ b/jni/java/overview.html
@@ -0,0 +1,30 @@
+<!--
+
+ 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.
+
+-->
+
+<html>
+<head>
+<title>Overview Documentation for Tomcat Native</title>
+</head>
+<body bgcolor="white">
+<p>The <em>Tomcat Native Library</em> component of the Apache Tomcat
+Connectors project offers JNI wrappers around APR and various other
+system libraries.</p>
+
+</body>
+</html>
diff --git a/jni/jnirelease.sh b/jni/jnirelease.sh
new file mode 100755
index 0000000..56f8c1b
--- /dev/null
+++ b/jni/jnirelease.sh
@@ -0,0 +1,251 @@
+#!/bin/sh
+#
+# 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.
+#
+
+#
+# BEFORE releasing don't forget to edit and commit
+# native/include/tcn_version.h
+# native/os/win32/libtcnative.rc
+
+# Default place to look for apr source. Can be overridden with
+# --with-apr=[directory]
+apr_src_dir=`pwd`/srclib/apr
+JKJNIEXT=""
+JKJNIVER=""
+SVNBASE=https://svn.apache.org/repos/asf/tomcat/native
+TCTRUNK_SVNBASE=https://svn.apache.org/repos/asf/tomcat/trunk
+
+for o
+do
+ case "$o" in
+ -*=*) a=`echo "$o" | sed 's/^[-_a-zA-Z0-9]*=//'` ;;
+ *) a='' ;;
+ esac
+ case "$o" in
+ --ver*=* )
+ JKJNIEXT="$a"
+ shift
+ ;;
+ --with-apr=* )
+ apr_src_dir="$a" ;
+ shift ;;
+ * )
+ echo ""
+ echo "Usage: jnirelease.sh [options]"
+ echo " --ver[sion]=<version> Tomcat Native version"
+ echo " --with-apr=<directory> APR sources directory"
+ echo ""
+ exit 1
+ ;;
+ esac
+done
+
+
+if [ -d "$apr_src_dir" ]; then
+ echo ""
+ echo "Using apr source from: \`$apr_src_dir'"
+else
+ echo ""
+ echo "Problem finding apr source in: \`$apr_src_dir'"
+ echo "Use:"
+ echo " --with-apr=<directory>"
+ echo ""
+ exit 1
+fi
+
+if [ "x$JKJNIEXT" = "x" ]; then
+ echo ""
+ echo "Unknown SVN version"
+ echo "Use:"
+ echo " --ver=<tagged-version>|trunk"
+ echo ""
+ exit 1
+fi
+
+# Check for links, elinks or w3m
+w3m_opts="-dump -cols 80 -t 4 -S -O iso-8859-1 -T text/html"
+elinks_opts="-dump -dump-width 80 -dump-charset iso-8859-1 -no-numbering -no-references -no-home"
+links_opts="-dump -width 80 -codepage iso-8859-1 -no-g -html-numbered-links 0"
+EXPTOOL=""
+EXPOPTS=""
+for i in w3m elinks links
+do
+ EXPTOOL="`which $i 2>/dev/null || type $i 2>&1`"
+ if [ -x "$EXPTOOL" ]; then
+ case ${i} in
+ w3m)
+ EXPOPTS="${w3m_opts}"
+ ;;
+ elinks)
+ EXPOPTS="${elinks_opts}"
+ ;;
+ links)
+ EXPOPTS="${links_opts}"
+ ;;
+ esac
+ echo "Using: ${EXPTOOL} ${EXPOPTS} ..."
+ break
+ fi
+done
+if [ ! -x "$EXPTOOL" ]; then
+ echo ""
+ echo "Cannot find html export tool"
+ echo "Make sure you have either w3m elinks or links in the PATH"
+ echo ""
+ exit 1
+fi
+PERL="`which perl 2>/dev/null || type perl 2>&1`"
+if [ -x "$PERL" ]; then
+ echo "Using $PERL"
+else
+ echo ""
+ echo "Cannot find perl"
+ echo "Make sure you have perl in the PATH"
+ echo ""
+ exit 1
+fi
+
+JKJNISVN=$SVNBASE/${JKJNIEXT}
+if [ "x$JKJNIEXT" = "xtrunk" ]; then
+ i="`svn info`"
+ JKJNIVER=`echo "$i" | awk '$1 == "Revision:" {print $2}'`
+ JKJNISVN=`echo "$i" | awk '$1 == "URL:" {print $2}'`
+else
+ JKJNIVER=$JKJNIEXT
+ JKJNISVN="${SVNBASE}/tags/TOMCAT_NATIVE_`echo $JKJNIVER | sed 's/\./_/g'`"
+fi
+echo "Using SVN repo : \`${JKJNISVN}'"
+echo "Using version : \`${JKJNIVER}'"
+
+# Checking for recentness of svn:externals
+externals_path=java/org/apache/tomcat
+jni_externals=`svn propget svn:externals $JKJNISVN/$externals_path | \
+ grep $externals_path/jni | \
+ sed -e 's#.*@##' -e 's# .*##'`
+jni_last_changed=`svn info --xml $TCTRUNK_SVNBASE/$externals_path/jni | \
+ tr "\n" " " | \
+ sed -e 's#.*commit *revision="##' -e 's#".*##'`
+if [ "x$jni_externals" != "x$jni_last_changed" ]; then
+ echo "WARNING: svn:externals for jni in $externals_path is '$jni_externals',"
+ echo " last changed revision in TC trunk is '$jni_last_changed'."
+ echo " If you want to correct, cancel script now and run"
+ echo " 'svn propedit svn:externals' on $externals_path to fix"
+ echo " the revision number."
+ sleep 3
+ exit 1
+fi
+
+JKJNIDIST=tomcat-native-${JKJNIVER}-src
+
+rm -rf ${JKJNIDIST}
+mkdir -p ${JKJNIDIST}/jni
+for i in native java xdocs examples test build.xml build.properties.default jnirelease.sh
+do
+ svn export ${JKJNISVN}/${i} ${JKJNIDIST}/jni/${i}
+ if [ $? -ne 0 ]; then
+ echo ""
+ echo "svn export ${i} failed"
+ echo ""
+ fi
+done
+
+# check the release if release.
+if [ "x$JKJNIEXT" = "xtrunk" ]; then
+ echo "Not a release"
+else
+ grep TCN_IS_DEV_VERSION ${JKJNIDIST}/jni/native/include/tcn_version.h | grep 0
+ if [ $? -ne 0 ]; then
+ echo "Check: ${JKJNIDIST}/jni/native/include/tcn_version.h it says -dev"
+ exit 1
+ fi
+ WIN_VERSION=`grep TCN_VERSION ${JKJNIDIST}/jni/native/os/win32/libtcnative.rc | grep define | awk ' { print $3 } '`
+ if [ "x\"$JKJNIVER\"" != "x$WIN_VERSION" ]; then
+ echo "Check: ${JKJNIDIST}/jni/native/os/win32/libtcnative.rc says $WIN_VERSION (FILEVERSION, PRODUCTVERSION, TCN_VERSION"
+ exit 1
+ fi
+fi
+
+top="`pwd`"
+cd ${JKJNIDIST}/jni/xdocs
+ant
+$EXPTOOL $EXPOPTS ../build/docs/miscellaneous/changelog.html > ../../CHANGELOG.txt 2>/dev/null
+if [ $? -ne 0 ]; then
+ echo ""
+ echo "$EXPTOOL $EXPOPTS ../build/docs/miscellaneous/changelog.html failed"
+ echo ""
+ exit 1
+fi
+# Remove first 25 lines from converted file which contains
+# page navagation data.
+# Remember to increase the lines when new file is added to news.
+sed -i '1,25d' ../../CHANGELOG.txt
+cd "$top"
+mv ${JKJNIDIST}/jni/build/docs ${JKJNIDIST}/jni/docs
+rm -rf ${JKJNIDIST}/jni/build
+for i in LICENSE NOTICE README.txt TODO.txt
+do
+ svn cat ${JKJNISVN}/${i} > ${JKJNIDIST}/${i}
+ if [ $? -ne 0 ]; then
+ echo ""
+ echo "svn cat ${JKJNISVN}/${i} failed"
+ echo ""
+ exit 1
+ fi
+done
+#
+# Prebuild
+cd ${JKJNIDIST}/jni/native
+./buildconf --with-apr=$apr_src_dir || exit 1
+cd "$top"
+# Create source distribution
+tar -cf - ${JKJNIDIST} | gzip -c9 > ${JKJNIDIST}.tar.gz || exit 1
+#
+# Create Win32 source distribution
+JKWINDIST=tomcat-native-${JKJNIVER}-win32-src
+rm -rf ${JKWINDIST}
+mkdir -p ${JKWINDIST}/jni
+for i in native java xdocs examples test build.xml build.properties.default jnirelease.sh
+do
+ svn export --native-eol CRLF ${JKJNISVN}/${i} ${JKWINDIST}/jni/${i}
+ if [ $? -ne 0 ]; then
+ echo ""
+ echo "svn export ${i} failed"
+ echo ""
+ exit 1
+ fi
+done
+top="`pwd`"
+cd ${JKWINDIST}/jni/xdocs
+ant
+if [ $? -ne 0 ]; then
+ echo ""
+ echo "ant (building docs failed)"
+ echo ""
+ exit 1
+fi
+cd "$top"
+cp ${JKJNIDIST}/CHANGELOG.txt ${JKWINDIST}
+
+mv ${JKWINDIST}/jni/build/docs ${JKWINDIST}/jni/docs
+rm -rf ${JKWINDIST}/jni/build
+for i in LICENSE NOTICE README.txt TODO.txt
+do
+ svn cat ${JKJNISVN}/${i} > ${JKWINDIST}/${i}
+ $PERL ${JKWINDIST}/jni/native/build/lineends.pl --cr ${JKWINDIST}/${i}
+done
+$PERL ${JKWINDIST}/jni/native/build/lineends.pl --cr ${JKWINDIST}/CHANGELOG.txt
+zip -9rqyo ${JKWINDIST}.zip ${JKWINDIST}
diff --git a/jni/native/BUILDING b/jni/native/BUILDING
new file mode 100644
index 0000000..9bbab7f
--- /dev/null
+++ b/jni/native/BUILDING
@@ -0,0 +1,100 @@
+================================================================================
+ 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.
+================================================================================
+
+Building from source package
+-----------------------------
+
+> configure --with-apr=apr_install_location --with-ssl=openssl_install_location
+> make
+
+Building from the svn tree
+--------------------------
+
+> sh buildconf --with-apr=apr_source_location.
+> configure --with-apr=apr_install_location --with-ssl=openssl_install_location
+> make
+
+Testing the build
+-----------------
+
+The make should produce a .so file named libtcnative-1.so.
+Build the jar containing the examples by
+
+> cd ..
+> ant jar
+ Run one of the example (the echo one):
+> ant run-echo
+
+Using it in Tomcat
+------------------
+
+1. In <Connector> use of conf/server.xml:
+ protocol="org.apache.coyote.http11.Http11AprProtocol"
+2. In bin/setenv.sh add the following:
+ CATALINA_OPTS="$CATALINA_OPTS -Djava.library.path=tclib_location"
+ In my machine I am using:
+ /home/jfclere/native/native/.libs for tclib_location
+
+NOTES
+-----
+ - configure --disable-openssl: Configure without ssl support.
+ - To use it in Tomcat you may have to add in bin/setenv.sh:
+ LD_LIBRARY_PATH=openssl_install_location/lib; export LD_LIBRARY_PATH
+ (use ldd ./.libs/libtcnative-1.so to check it).
+ - quick testing: openssl s_client -connect localhost:8443
+ - For MAC OS X you must manually add a link
+ cd ${tcnative installdir}
+ ln -d libtcnative-1.dylib libtcnative-1.jnilib
+
+
+Building statically linked library on Unixes
+--------------------------------------------
+
+To statically link apr and openssl dependencies use the following
+procedure.
+
+You will need to build static version of openssl library.
+
+> ./config --prefix=~/natives/openssl no-shared -fPIC
+> make
+> make install_sw
+
+Note that for Solaris platform you should use -KPIC instead -fPIC
+so that library is compiled with position independent code.
+
+Apr by default builds both static and dynamic libraries.
+
+> ./configure --prefix=~/natives/apr
+> make
+> make install
+
+After that edit the ~/natives/apr/lib/libapr-1.la file
+and comment or delete the following sections:
+dlname='...' and library_names='...'
+This is needed so that libtool picks the static version of the library.
+
+Build Tomcat native by executing
+
+> ./configure --with-apr=~/natives/apr --with-ssl=~/natives/openssl --prefix=~/natives/tomcat
+> make
+> make install
+
+That's it. You have just build libtcnative-1.so with statically linked
+apr and openssl.
+
+
+
diff --git a/jni/native/Makefile.in b/jni/native/Makefile.in
new file mode 100644
index 0000000..fc84eb0
--- /dev/null
+++ b/jni/native/Makefile.in
@@ -0,0 +1,82 @@
+#
+# 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.
+#
+
+#
+# Top-level Makefile for TCNATIVE
+#
+
+CFLAGS = @CFLAGS@
+CPPFLAGS = @CPPFLAGS@
+
+# gets substituted into some targets
+TCNATIVE_MAJOR_VERSION=@TCNATIVE_MAJOR_VERSION@
+TCNATIVE_DOTTED_VERSION=@TCNATIVE_DOTTED_VERSION@
+TCNATIVE_LIBTOOL_VERSION=@TCNATIVE_LIBTOOL_VERSION@
+
+srcdir = @srcdir@
+VPATH = @srcdir@
+
+# this sucks, but it's the only way to add extra flags to the LT_COMPILE
+INCLUDES = @CFLAGS@ @CPPFLAGS@ @TCNATIVE_INCLUDES@ @TCNATIVE_PRIV_INCLUDES@ @APR_INCLUDES@
+TCNATIVE_LDFLAGS = @TCNATIVE_LDFLAGS@
+TCNATIVE_LIBS = @TCNATIVE_LIBS@
+
+TARGET_LIB = lib at TCNATIVE_LIBNAME@.la
+EXTRA_OS_LINK=@EXTRA_OS_LINK@
+TCNATIVE_PCFILE = tcnative-$(TCNATIVE_MAJOR_VERSION).pc
+INSTALL = @INSTALL@
+INSTALL_DATA = @INSTALL_DATA@
+
+TARGETS = $(TARGET_LIB)
+
+# bring in rules.mk for standard functionality
+ at INCLUDE_RULES@
+ at INCLUDE_OUTPUTS@
+
+LINK = $(LIBTOOL) $(LTFLAGS) --mode=link $(LT_LDFLAGS) $(COMPILE) -version-info $(TCNATIVE_LIBTOOL_VERSION) $(ALL_LDFLAGS) -o $@
+CLEAN_SUBDIRS = test
+
+CLEAN_TARGETS = .make.dirs
+DISTCLEAN_TARGETS = config.cache config.log config.status libtool \
+ build/rules.mk tcnative.pc
+EXTRACLEAN_TARGETS = configure aclocal.m4 build-outputs.mk \
+ build/apr_common.m4 build/find_apr.m4 build/install.sh \
+ build/config.guess build/config.sub tcnative.spec
+
+prefix=@prefix@
+exec_prefix=@exec_prefix@
+bindir=@bindir@
+libdir=@libdir@
+includedir=@includedir@
+top_srcdir=@abs_srcdir@
+top_blddir=@abs_builddir@
+
+
+install: $(TARGET_LIB)
+ $(APR_MKDIR) $(DESTDIR)$(includedir) $(DESTDIR)$(libdir)/pkgconfig \
+ $(DESTDIR)$(libdir) $(DESTDIR)$(bindir)
+ $(INSTALL_DATA) tcnative.pc $(DESTDIR)$(libdir)/pkgconfig/$(TCNATIVE_PCFILE)
+ list='$(INSTALL_SUBDIRS)'; for i in $$list; do \
+ ( cd $$i ; $(MAKE) DESTDIR=$(DESTDIR) install ); \
+ done
+ $(LIBTOOL) --mode=install $(INSTALL) -m 755 $(TARGET_LIB) $(DESTDIR)$(libdir)
+
+$(TARGET_LIB): $(OBJECTS)
+ $(LINK) @lib_target@ @TCNATIVE_LDFLAGS@ @TCNATIVE_LIBS@
+
+check: $(TARGET_LIB)
+ (cd test && $(MAKE) check)
diff --git a/jni/native/NMAKEmakefile b/jni/native/NMAKEmakefile
new file mode 100644
index 0000000..48c41b4
--- /dev/null
+++ b/jni/native/NMAKEmakefile
@@ -0,0 +1,152 @@
+# 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.
+#
+# ====================================================================
+#
+# NMAKEmakefile Master Tomcat Native makefile.
+# Usage:
+# APR_DECLARE_STATIC=1 Use static version of the APR
+# ENABLE_OCSP=1 Enable OpenSSL OCSP code
+# DEBUG=1 Build DEBUG version of TCN
+#
+# Originally contributed by Mladen Turk <mturk redhat.com>
+#
+# ====================================================================
+#
+
+!IF !DEFINED(APR_DECLARE_STATIC) || "$(APR_DECLARE_STATIC)" == ""
+PROJECT = libtcnative-1
+!ELSE
+PROJECT = tcnative-1
+!ENDIF
+TARGET = DLL
+
+!include <NMAKEmakefile.inc>
+
+!IF !DEFINED(APR_DECLARE_STATIC) || "$(APR_DECLARE_STATIC)" == ""
+APR_LIB = libapr-1.lib
+!ELSE
+CFLAGS = $(CFLAGS) -DAPR_DECLARE_STATIC
+APR_LIB = apr-1.lib
+!ENDIF
+!IF DEFINED(ENABLE_OCSP)
+CFLAGS = $(CFLAGS) -DHAVE_OPENSSL_OCSP
+!ENDIF
+
+!IF !DEFINED(SRCDIR) || "$(SRCDIR)" == ""
+SRCDIR = .
+!ENDIF
+
+INCLUDES = -I$(SRCDIR)\include $(JAVA_INCLUDES)
+
+!IFNDEF WITH_APR
+WITH_APR = $(SRCDIR)\srclib\apr
+LDIRS = /libpath:"$(WITH_APR)\$(WORKDIR)"
+!ELSE
+LDIRS = /libpath:"$(WITH_APR)\lib"
+!ENDIF
+
+INCLUDES = $(INCLUDES) -I$(WITH_APR)\include -I$(WITH_APR)\include\arch\win32
+!IF DEFINED(WITH_OPENSSL)
+INCLUDES = $(INCLUDES) -I$(WITH_OPENSSL)\include
+LDIRS = $(LDIRS) /libpath:"$(WITH_OPENSSL)\lib"
+!ELSE
+WITH_OPENSSL = $(SRCDIR)\srclib\openssl
+INCLUDES = $(INCLUDES) $(WITH_OPENSSL)\inc32
+LDIRS = $(LDIRS) /libpath:"$(WITH_OPENSSL)\out32"
+!ENDIF
+
+LFLAGS = $(LFLAGS) /version:1.1
+LFLAGS = $(LFLAGS) user32.lib psapi.lib gdi32.lib shlwapi.lib wldap32.lib ole32.lib
+LFLAGS = $(LFLAGS) $(APR_LIB)
+LFLAGS = $(LFLAGS) libeay32.lib ssleay32.lib
+
+CFLAGS = $(CFLAGS) -DZLIB_WINAPI -DNO_IDEA -DNO_RC5 -DNO_MDC2 -DOPENSSL_NO_IDEA \
+ -DOPENSSL_NO_RC5 -DOPENSSL_NO_MDC2 -DHAVE_OPENSSL -DHAVE_SSL_SET_STATE=1
+
+
+PDBFLAGS = -Fo$(WORKDIR)\ -Fd$(WORKDIR)\$(PROJECT)-src
+OBJECTS = \
+ $(WORKDIR)\address.obj \
+ $(WORKDIR)\bb.obj \
+ $(WORKDIR)\dir.obj \
+ $(WORKDIR)\error.obj \
+ $(WORKDIR)\file.obj \
+ $(WORKDIR)\info.obj \
+ $(WORKDIR)\jnilib.obj \
+ $(WORKDIR)\lock.obj \
+ $(WORKDIR)\misc.obj \
+ $(WORKDIR)\mmap.obj \
+ $(WORKDIR)\multicast.obj \
+ $(WORKDIR)\network.obj \
+ $(WORKDIR)\os.obj \
+ $(WORKDIR)\poll.obj \
+ $(WORKDIR)\pool.obj \
+ $(WORKDIR)\proc.obj \
+ $(WORKDIR)\shm.obj \
+ $(WORKDIR)\ssl.obj \
+ $(WORKDIR)\sslcontext.obj \
+ $(WORKDIR)\sslinfo.obj \
+ $(WORKDIR)\sslnetwork.obj \
+ $(WORKDIR)\sslutils.obj \
+ $(WORKDIR)\stdlib.obj \
+ $(WORKDIR)\user.obj \
+ $(WORKDIR)\thread.obj \
+ $(WORKDIR)\ntpipe.obj \
+ $(WORKDIR)\registry.obj \
+ $(WORKDIR)\system.obj
+
+HEADERS = \
+ $(SRCDIR)\include\tcn.h \
+ $(SRCDIR)\include\tcn_api.h \
+ $(SRCDIR)\include\tcn_version.h \
+ $(SRCDIR)\include\ssl_private.h
+
+BUILDLIB = $(PREFIX)\lib
+BUILDBIN = $(WORKDIR)\$(PROJECT).dll
+BUILDPDB = $(WORKDIR)\$(PROJECT).pdb
+BUILDRES = $(WORKDIR)\$(PROJECT).res
+BUILDMAN = $(BUILDBIN).manifest
+
+all : $(WORKDIR) $(BUILDBIN)
+
+$(BUILDLIB) :
+ @if not exist "$(BUILDLIB)\$(NULL)" mkdir "$(BUILDLIB)"
+
+$(WORKDIR) :
+ @$(MAKEWORKDIR)
+
+{$(SRCDIR)\src}.c{$(WORKDIR)}.obj:
+ $(CC) $(CFLAGS) $(INCLUDES) $(PDBFLAGS) $<
+
+{$(SRCDIR)\os\win32}.c{$(WORKDIR)}.obj:
+ $(CC) $(CFLAGS) $(INCLUDES) $(PDBFLAGS) $<
+
+$(OBJECTS): $(HEADERS)
+
+$(BUILDRES): $(SRCDIR)\os\win32\libtcnative.rc $(HEADERS)
+ $(RC) $(RCFLAGS) /i "$(SRCDIR)\include" /fo $(BUILDRES) $(SRCDIR)\os\win32\libtcnative.rc
+
+$(BUILDBIN): $(WORKDIR) $(OBJECTS) $(BUILDRES)
+ $(LINK) $(LFLAGS) $(OBJECTS) $(BUILDRES) $(LIBS) $(LDIRS) /pdb:$(BUILDPDB) /out:$(BUILDBIN)
+ IF EXIST $(BUILDMAN) \
+ mt -nologo -manifest $(BUILDMAN) -outputresource:$(BUILDBIN);2
+
+clean:
+ @$(CLEANTARGET)
+
+install: $(BUILDLIB) $(WORKDIR) $(BUILDBIN)
+ @xcopy "$(WORKDIR)\*.lib" "$(BUILDLIB)" /Y /Q
+ @xcopy "$(WORKDIR)\*.dll" "$(BUILDLIB)" /Y /Q
diff --git a/jni/native/NMAKEmakefile.inc b/jni/native/NMAKEmakefile.inc
new file mode 100644
index 0000000..d250fc7
--- /dev/null
+++ b/jni/native/NMAKEmakefile.inc
@@ -0,0 +1,347 @@
+# 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
+#
+#
+# ====================================================================
+#
+# Makefile.inc Master makefile definitions.
+# This file defines CPU architecture and basic compiler
+# and linker parameters.
+# Common params:
+# CPU Compile for specified CPU. Supported CPU's are:
+# X86 (Common x86 architecture)
+# X64 (AMD64/EMT64 architecture)
+# I64 (Intel IA64 architecture)
+# If not specified it will default to the
+# PROCESSOR_ARCHITECTURE environment variable
+# or to the X86 if not specified.
+# WINVER Compile for specified Windows version
+# WINNT for Windows 2000 and up(default)
+# WINXP for Windows XP and up
+# WIN2003 for Windows 2003 and up
+# VSITA for Windows Vista and up
+# Deprecated targets (may not even compile):
+# NT4 for Windows NT4 and up
+# WIN9X for Windows 95, 98 and Me
+# BUILD Build version
+# RETAIL or RELEASE (default)
+# DEBUG
+# TARGET Build application target
+# EXE Console executable (default)
+# GUI Windows GUI executable
+# DLL Dynamic Link Library
+# LIB Static library
+# UNICODE Build unicode version
+# If definded and not empty -D_UNICODE is added
+# to CFLAGS; -D_MBCS is added otherwise
+# Environment variables used:
+# EXTRA_CFLAGS Added to the common CFLAGS
+# EXTRA_CXXFLAGS Added to the common CXXFLAGS
+# EXTRA_LIBS Added to the common LIBS
+# EXTRA_LFLAGS Added to the common LFLAGS
+# EXTRA_RCFLAGS Added to the common RCFLAGS
+#
+# Compiler tools environment variables:
+# CC C compiler (defaults to cl.exe)
+# CXX C++ compiler (defaults to $CC -TP)
+# CPP C preprocessor (defaults to $CC -EP)
+# LINK Linker (defaults to link.exe)
+# RC Resource compiler (defaults to rc.exe)
+# MT Manifest toolkit (defaults to mt.exe)
+# ML Assembler (defaults to ml.exe or ml64.exe)
+#
+# Originally contributed by Mladen Turk <mturk jboss.com>
+#
+# ====================================================================
+#
+
+# C/C++ compiler
+!IF !DEFINED(CC) || "$(CC)" == ""
+CC = cl.exe
+!ENDIF
+!IF !DEFINED(CXX) || "$(CXX)" == ""
+CXX = $(CC) -TP
+!ENDIF
+!IF !DEFINED(CPP) || "$(CPP)" == ""
+CPP = $(CC) -EP
+!ENDIF
+# Linker
+!IF !DEFINED(LINK) || "$(LINK)" == ""
+LINK = link.exe
+!ENDIF
+# Resource Compiler
+!IF !DEFINED(RC) || "$(RC)" == ""
+RC = rc.exe
+!ENDIF
+# Manifest toolkit
+!IF !DEFINED(MT) || "$(MT)" == ""
+MT = mt.exe
+!ENDIF
+
+# Use BUILD_CPU if CPU was not set
+!IF !DEFINED(CPU) || "$(CPU)" == ""
+!IF "$(BUILD_CPU)" == "i386" || "$(BUILD_CPU)" == "x86" || "$(BUILD_CPU)" == "i686"
+CPU=X86
+!ENDIF
+!IF "$(BUILD_CPU)" == "amd64" || "$(BUILD_CPU)" == "x86_64" || "$(BUILD_CPU)" == "x64"
+CPU=X64
+!ENDIF
+!IF "$(BUILD_CPU)" == "ia64" || "$(BUILD_CPU)" == "i64"
+CPU=I64
+!ENDIF
+!ENDIF
+# Figure out CPU from the current host
+!IF !DEFINED(CPU) || "$(CPU)" == ""
+!IF "$(PROCESSOR_ARCHITECTURE)" == ""
+!IF "$(PROCESSOR_ARCHITEW6432)" == ""
+CPU=X86
+!ELSE
+CPU=$(PROCESSOR_ARCHITEW6432)
+!ENDIF
+!ELSE
+CPU=$(PROCESSOR_ARCHITECTURE)
+!ENDIF
+!ENDIF
+
+!IF "$(CPU)" != "X86"
+!IF "$(CPU)" != "X64"
+!IF "$(CPU)" != "I64"
+!ERROR Must specify CPU environment variable (X86, X64, I64) $(CPU)
+!ENDIF
+!ENDIF
+!ENDIF
+
+!IF !DEFINED(TARGET) || "$(TARGET)" == ""
+TARGET=EXE
+!ENDIF
+
+!IF "$(TARGET)" != "EXE"
+!IF "$(TARGET)" != "GUI"
+!IF "$(TARGET)" != "DLL"
+!IF "$(TARGET)" != "LIB"
+!ERROR Must specify TARGET environment variable (EXE, GUI, DLL, LIB)
+!ENDIF
+!ENDIF
+!ENDIF
+!ENDIF
+
+!IF !DEFINED(WINVER) || "$(WINVER)" == ""
+WINVER=WINXP
+!ENDIF
+
+
+!IF "$(WINVER)" != "WINNT"
+!IF "$(WINVER)" != "WINXP"
+!IF "$(WINVER)" != "WIN2003"
+!IF "$(WINVER)" != "VISTA"
+!IF "$(WINVER)" != "WIN7"
+!ERROR Must specify WINVER environment variable (WINNT, WINXP, WIN2003, VISTA, WIN7)
+!ENDIF
+!ENDIF
+!ENDIF
+!ENDIF
+!ENDIF
+
+!IF "$(WINVER)" == "WINNT"
+NMAKE_WINVER = 0x0500
+_WIN32_IE = 0x0500
+!ELSEIF "$(WINVER)" == "WINXP"
+NMAKE_WINVER = 0x0501
+_WIN32_IE = 0x0600
+!ELSEIF "$(WINVER)" == "WIN2003"
+NMAKE_WINVER = 0x0502
+_WIN32_IE = 0x0600
+!ELSEIF "$(WINVER)" == "VISTA"
+NMAKE_WINVER = 0x0600
+_WIN32_IE = 0x0700
+!ELSEIF "$(WINVER)" == "WIN7"
+NMAKE_WINVER = 0x0700
+_WIN32_IE = 0x0800
+!ELSE
+!ERROR Must specify WINVER environment variable (WINNT, WINXP, WIN2003, VISTA, WIN7)
+!ENDIF
+
+NMAKE_WINNT = -DWINNT -D_WINNT -D_WIN32_WINNT=$(NMAKE_WINVER) -DWINVER=$(NMAKE_WINVER) -D_WIN32_IE=$(_WIN32_IE)
+
+!IF !DEFINED(BUILD) || "$(BUILD)" == ""
+BUILD=RELEASE
+!ENDIF
+!IFDEF RELEASE
+BUILD=RELEASE
+!ENDIF
+!IFDEF DEBUG
+BUILD=DEBUG
+!ENDIF
+!IFDEF NODEBUG
+BUILD=RELEASE
+!ENDIF
+
+!IF "$(BUILD)" != "RELEASE"
+!IF "$(BUILD)" != "DEBUG"
+!ERROR Must specify BUILD environment variable (RELEASE, DEBUG)
+!ENDIF
+!ENDIF
+
+# Common flags for all platforms
+CMN_CFLAGS = -c -nologo -DWIN32 -D_WIN32 -D_WINDOWS $(NMAKE_WINNT) -W3
+!IF "$(TARGET)" == "EXE"
+CMN_CFLAGS = $(CMN_CFLAGS) -D_CONSOLE
+!ENDIF
+# Mark that extern C newer throws C++ exception
+CMN_CFLAGS = $(CMN_CFLAGS) -EHsc
+
+!IF !DEFINED(UNICODE) || "$(UNICODE)" == ""
+CMN_CFLAGS = $(CMN_CFLAGS) -D_MBCS -DMBCS
+!ELSE
+CMN_CFLAGS = $(CMN_CFLAGS) -D_UNICODE -DUNICODE
+!ENDIF
+
+!IF "$(CPU)" == "X86"
+CPU_CFLAGS = -D_X86_=1
+MACHINE=X86
+MACHINE_LC=i386
+!ELSEIF "$(CPU)" == "X64"
+CPU_CFLAGS = -D_AMD64_=1 -DWIN64 -D_WIN64
+MACHINE=AMD64
+MACHINE_LC=amd64
+!ELSEIF "$(CPU)" == "I64"
+CPU_CFLAGS = -D_IA64_=1 -DWIN64 -D_WIN64
+MACHINE=IA64
+MACHINE_LC=ia64
+!ENDIF
+
+!IF "$(BUILD)" == "RELEASE"
+!IF "$(CPU)" == "X86"
+OPT_CFLAGS = -O2 -Ob2 -Oy- -Zi -DNDEBUG
+!ELSE
+OPT_CFLAGS = -O2 -Ob2 -Zi -DNDEBUG
+!ENDIF
+!ELSE
+OPT_CFLAGS = -Od -Zi -DDEBUG -D_DEBUG
+!ENDIF
+
+!IF DEFINED(STATIC_CRT)
+CRT_CFLAGS = -D_MT -MT
+!ELSE
+CRT_CFLAGS = -D_MT -MD
+!ENDIF
+
+!IF "$(BUILD)" == "DEBUG"
+CRT_CFLAGS = $(CRT_CFLAGS)d
+!ENDIF
+
+CFLAGS = $(CMN_CFLAGS) $(CPU_CFLAGS) $(OPT_CFLAGS) $(CRT_CFLAGS)
+
+!IF DEFINED(EXTRA_CFLAGS)
+CFLAGS = $(CFLAGS) $(EXTRA_CFLAGS)
+!ENDIF
+
+# Cleanup CXXFLAGS
+CXXFLAGS =
+!IF DEFINED(EXTRA_CXXFLAGS)
+CXXFLAGS = $(EXTRA_CXXFLAGS)
+!ENDIF
+
+# Linker section
+LIBS = kernel32.lib advapi32.lib ws2_32.lib mswsock.lib ole32.lib shell32.lib rpcrt4.lib
+# Extra libs from command line or env
+!IF DEFINED(EXTRA_LIBS)
+LIBS = $(LIBS) $(EXTRA_LIBS)
+!ENDIF
+
+# Run-Time Error Checks
+!IF "$(BUILD)" == "DEBUG"
+!IF DEFINED(RTC_CHECK)
+LIBS = $(LIBS) RunTmChk.lib
+CFLAGS = $(CFLAGS) -RTC1
+!ENDIF
+!ENDIF
+
+COMMON_LFLAGS = /NOLOGO
+
+# Always add debugging to the linker
+OPT_LFLAGS = /INCREMENTAL:NO /DEBUG
+!IF "$(BUILD)" == "RELEASE"
+OPT_LFLAGS = /OPT:REF
+!ENDIF
+
+!IF "$(TARGET)" == "EXE"
+LFLAGS = $(COMMON_LFLAGS) /SUBSYSTEM:CONSOLE /MACHINE:$(MACHINE)
+!ELSEIF "$(TARGET)" == "GUI"
+LFLAGS = $(COMMON_LFLAGS) /SUBSYSTEM:WINDOWS /MACHINE:$(MACHINE)
+!ELSEIF "$(TARGET)" == "DLL"
+LFLAGS = $(COMMON_LFLAGS) /DLL /SUBSYSTEM:WINDOWS /MACHINE:$(MACHINE)
+!ELSEIF "$(TARGET)" == "LIB"
+LFLAGS = -lib $(COMMON_LFLAGS)
+!ENDIF
+
+!IF DEFINED(EXTRA_LFLAGS)
+LFLAGS = $(LFLAGS) $(EXTRA_LFLAGS)
+!ENDIF
+
+!IF "$(TARGET)" != "LIB"
+LFLAGS = $(LFLAGS) $(OPT_LFLAGS)
+!ENDIF
+
+# Resource compiler flags
+
+RCFLAGS=/l 0x409
+!IF "$(BUILD)" == "RELEASE"
+RCFLAGS = $(RCFLAGS) /d "NDEBUG"
+!ELSE
+RCFLAGS = $(RCFLAGS) /d "_DEBUG" /d "DEBUG"
+!ENDIF
+RCFLAGS = $(RCFLAGS)
+!IF DEFINED(EXTRA_RCFLAGS)
+RCFLAGS = $(RCFLAGS) $(EXTRA_RCFLAGS)
+!ENDIF
+
+
+# Build Target dir e.g. WINNT_I386_RELEASE_DLL
+!IF !DEFINED(WORKDIR) || "$(WORKDIR)" == ""
+!IF !DEFINED(WORKDIR_EXT) || "$(WORKDIR_EXT)" == ""
+WORKDIR = $(WINVER)_$(CPU)_$(TARGET)_$(BUILD)
+WORKDIR_DLL = $(WINVER)_$(CPU)_DLL_$(BUILD)
+WORKDIR_LIB = $(WINVER)_$(CPU)_LIB_$(BUILD)
+WORKDIR_EXE = $(WINVER)_$(CPU)_EXE_$(BUILD)
+!ELSE
+WORKDIR = $(WINVER)_$(CPU)_$(BUILDIR_EXT)_$(BUILD)
+!ENDIF
+!ENDIF
+
+CLEANTARGET=if exist "$(WORKDIR)\$(NULL)" rd /s /q $(WORKDIR)
+MAKEWORKDIR=if not exist "$(WORKDIR)\$(NULL)" mkdir $(WORKDIR)
+MAKEINSTALL=if not exist "$(INSTALLLOC)\$(NULL)" mkdir $(INSTALLLOC)
+
+!IF DEFINED(JAVA_HOME) && "$(JAVA_HOME)" != ""
+JAVA_INCLUDES=-I "$(JAVA_HOME)\include" -I "$(JAVA_HOME)\include\win32"
+!ENDIF
+
+# Assembler Section
+!IF !DEFINED(ML) || "$(ML)" == ""
+!IF "$(CPU)" == "X86"
+ML = ml.exe
+AFLAGS = /coff /Zi /c
+!ELSEIF "$(CPU)" == "X64"
+ML = ml64.exe
+AFLAGS = /Zi /c
+!ELSEIF "$(CPU)" == "I64"
+ML = ml64.exe
+AFLAGS = /coff /Zi /c
+!ENDIF
+!ENDIF
+
diff --git a/jni/native/build-outputs.mk b/jni/native/build-outputs.mk
new file mode 100644
index 0000000..5865ebd
--- /dev/null
+++ b/jni/native/build-outputs.mk
@@ -0,0 +1,62 @@
+# DO NOT EDIT. AUTOMATICALLY GENERATED.
+
+src/address.lo: src/address.c .make.dirs include/tcn.h include/tcn_api.h
+src/bb.lo: src/bb.c .make.dirs include/tcn.h include/tcn_api.h
+src/dir.lo: src/dir.c .make.dirs include/tcn.h include/tcn_api.h
+src/error.lo: src/error.c .make.dirs include/tcn.h include/tcn_api.h
+src/file.lo: src/file.c .make.dirs include/tcn.h include/tcn_api.h
+src/info.lo: src/info.c .make.dirs include/tcn.h include/tcn_api.h
+src/jnilib.lo: src/jnilib.c .make.dirs include/tcn.h include/tcn_api.h include/tcn_version.h
+src/lock.lo: src/lock.c .make.dirs include/tcn.h include/tcn_api.h
+src/misc.lo: src/misc.c .make.dirs include/tcn.h include/tcn_api.h
+src/mmap.lo: src/mmap.c .make.dirs include/tcn.h include/tcn_api.h
+src/multicast.lo: src/multicast.c .make.dirs include/tcn.h include/tcn_api.h
+src/network.lo: src/network.c .make.dirs include/tcn.h include/tcn_api.h
+src/os.lo: src/os.c .make.dirs include/tcn.h include/tcn_api.h
+src/poll.lo: src/poll.c .make.dirs include/tcn.h include/tcn_api.h
+src/pool.lo: src/pool.c .make.dirs include/tcn.h include/tcn_api.h
+src/proc.lo: src/proc.c .make.dirs include/tcn.h include/tcn_api.h
+src/shm.lo: src/shm.c .make.dirs include/tcn.h include/tcn_api.h
+src/ssl.lo: src/ssl.c .make.dirs include/ssl_private.h include/tcn.h include/tcn_api.h
+src/sslcontext.lo: src/sslcontext.c .make.dirs include/ssl_private.h include/tcn.h include/tcn_api.h
+src/sslinfo.lo: src/sslinfo.c .make.dirs include/ssl_private.h include/tcn.h include/tcn_api.h
+src/sslnetwork.lo: src/sslnetwork.c .make.dirs include/ssl_private.h include/tcn.h include/tcn_api.h
+src/sslutils.lo: src/sslutils.c .make.dirs include/ssl_private.h include/tcn.h include/tcn_api.h
+src/stdlib.lo: src/stdlib.c .make.dirs include/tcn.h include/tcn_api.h
+src/thread.lo: src/thread.c .make.dirs include/tcn.h include/tcn_api.h
+src/user.lo: src/user.c .make.dirs include/tcn.h include/tcn_api.h
+
+OBJECTS_all = src/address.lo src/bb.lo src/dir.lo src/error.lo src/file.lo src/info.lo src/jnilib.lo src/lock.lo src/misc.lo src/mmap.lo src/multicast.lo src/network.lo src/os.lo src/poll.lo src/pool.lo src/proc.lo src/shm.lo src/ssl.lo src/sslcontext.lo src/sslinfo.lo src/sslnetwork.lo src/sslutils.lo src/stdlib.lo src/thread.lo src/user.lo
+
+os/unix/system.lo: os/unix/system.c .make.dirs include/tcn.h include/tcn_api.h
+os/unix/uxpipe.lo: os/unix/uxpipe.c .make.dirs include/tcn.h include/tcn_api.h
+
+OBJECTS_os_unix = os/unix/system.lo os/unix/uxpipe.lo
+
+OBJECTS_unix = $(OBJECTS_all) $(OBJECTS_os_unix)
+
+OBJECTS_aix = $(OBJECTS_all) $(OBJECTS_os_unix)
+
+OBJECTS_beos = $(OBJECTS_all) $(OBJECTS_os_unix)
+
+OBJECTS_os2 = $(OBJECTS_all) $(OBJECTS_os_unix)
+
+OBJECTS_os390 = $(OBJECTS_all) $(OBJECTS_os_unix)
+
+os/win32/ntpipe.lo: os/win32/ntpipe.c .make.dirs include/tcn.h include/tcn_api.h
+os/win32/registry.lo: os/win32/registry.c .make.dirs include/tcn.h include/tcn_api.h
+os/win32/system.lo: os/win32/system.c .make.dirs include/ssl_private.h include/tcn.h include/tcn_api.h
+
+OBJECTS_os_win32 = os/win32/ntpipe.lo os/win32/registry.lo os/win32/system.lo
+
+OBJECTS_win32 = $(OBJECTS_all) $(OBJECTS_os_win32)
+
+HEADERS = $(top_srcdir)/include/ssl_private.h $(top_srcdir)/include/tcn.h $(top_srcdir)/include/tcn_api.h $(top_srcdir)/include/tcn_version.h
+
+SOURCE_DIRS = src os/unix os/win32 $(EXTRA_SOURCE_DIRS)
+
+BUILD_DIRS = os os/unix os/win32 src
+
+.make.dirs: $(srcdir)/build-outputs.mk
+ @for d in $(BUILD_DIRS); do test -d $$d || mkdir $$d; done
+ @echo timestamp > $@
diff --git a/jni/native/build.conf b/jni/native/build.conf
new file mode 100644
index 0000000..dece39a
--- /dev/null
+++ b/jni/native/build.conf
@@ -0,0 +1,36 @@
+#
+# 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.
+#
+
+#
+# Configuration file for APRJAVA. Used by APR/build/gen-build.py
+#
+
+[options]
+
+# the platform-independent .c files
+paths =
+ src/*.c
+
+# we have no platform-specific subdirs
+platform_dirs =
+ os
+
+# the public headers
+headers = include/*.h
+
+# we have a recursive makefile for the test files (for now)
+# test/*.c
diff --git a/jni/native/build/apr_common.m4 b/jni/native/build/apr_common.m4
new file mode 100644
index 0000000..50dbfac
--- /dev/null
+++ b/jni/native/build/apr_common.m4
@@ -0,0 +1,985 @@
+dnl -------------------------------------------------------- -*- autoconf -*-
+dnl Licensed to the Apache Software Foundation (ASF) under one or more
+dnl contributor license agreements. See the NOTICE file distributed with
+dnl this work for additional information regarding copyright ownership.
+dnl The ASF licenses this file to You under the Apache License, Version 2.0
+dnl (the "License"); you may not use this file except in compliance with
+dnl the License. You may obtain a copy of the License at
+dnl
+dnl http://www.apache.org/licenses/LICENSE-2.0
+dnl
+dnl Unless required by applicable law or agreed to in writing, software
+dnl distributed under the License is distributed on an "AS IS" BASIS,
+dnl WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+dnl See the License for the specific language governing permissions and
+dnl limitations under the License.
+
+dnl
+dnl apr_common.m4: APR's general-purpose autoconf macros
+dnl
+
+dnl
+dnl APR_CONFIG_NICE(filename)
+dnl
+dnl Saves a snapshot of the configure command-line for later reuse
+dnl
+AC_DEFUN([APR_CONFIG_NICE], [
+ rm -f $1
+ cat >$1<<EOF
+#! /bin/sh
+#
+# Created by configure
+
+EOF
+ if test -n "$CC"; then
+ echo "CC=\"$CC\"; export CC" >> $1
+ fi
+ if test -n "$CFLAGS"; then
+ echo "CFLAGS=\"$CFLAGS\"; export CFLAGS" >> $1
+ fi
+ if test -n "$CPPFLAGS"; then
+ echo "CPPFLAGS=\"$CPPFLAGS\"; export CPPFLAGS" >> $1
+ fi
+ if test -n "$LDFLAGS"; then
+ echo "LDFLAGS=\"$LDFLAGS\"; export LDFLAGS" >> $1
+ fi
+ if test -n "$LTFLAGS"; then
+ echo "LTFLAGS=\"$LTFLAGS\"; export LTFLAGS" >> $1
+ fi
+ if test -n "$LIBS"; then
+ echo "LIBS=\"$LIBS\"; export LIBS" >> $1
+ fi
+ if test -n "$INCLUDES"; then
+ echo "INCLUDES=\"$INCLUDES\"; export INCLUDES" >> $1
+ fi
+ if test -n "$NOTEST_CFLAGS"; then
+ echo "NOTEST_CFLAGS=\"$NOTEST_CFLAGS\"; export NOTEST_CFLAGS" >> $1
+ fi
+ if test -n "$NOTEST_CPPFLAGS"; then
+ echo "NOTEST_CPPFLAGS=\"$NOTEST_CPPFLAGS\"; export NOTEST_CPPFLAGS" >> $1
+ fi
+ if test -n "$NOTEST_LDFLAGS"; then
+ echo "NOTEST_LDFLAGS=\"$NOTEST_LDFLAGS\"; export NOTEST_LDFLAGS" >> $1
+ fi
+ if test -n "$NOTEST_LIBS"; then
+ echo "NOTEST_LIBS=\"$NOTEST_LIBS\"; export NOTEST_LIBS" >> $1
+ fi
+
+ # Retrieve command-line arguments.
+ eval "set x $[0] $ac_configure_args"
+ shift
+
+ for arg
+ do
+ APR_EXPAND_VAR(arg, $arg)
+ echo "\"[$]arg\" \\" >> $1
+ done
+ echo '"[$]@"' >> $1
+ chmod +x $1
+])dnl
+
+dnl APR_MKDIR_P_CHECK(fallback-mkdir-p)
+dnl checks whether mkdir -p works
+AC_DEFUN([APR_MKDIR_P_CHECK], [
+ AC_CACHE_CHECK(for working mkdir -p, ac_cv_mkdir_p,[
+ test -d conftestdir && rm -rf conftestdir
+ mkdir -p conftestdir/somedir >/dev/null 2>&1
+ if test -d conftestdir/somedir; then
+ ac_cv_mkdir_p=yes
+ else
+ ac_cv_mkdir_p=no
+ fi
+ rm -rf conftestdir
+ ])
+ if test "$ac_cv_mkdir_p" = "yes"; then
+ mkdir_p="mkdir -p"
+ else
+ mkdir_p="$1"
+ fi
+])
+
+dnl
+dnl APR_SUBDIR_CONFIG(dir [, sub-package-cmdline-args, args-to-drop])
+dnl
+dnl dir: directory to find configure in
+dnl sub-package-cmdline-args: arguments to add to the invocation (optional)
+dnl args-to-drop: arguments to drop from the invocation (optional)
+dnl
+dnl Note: This macro relies on ac_configure_args being set properly.
+dnl
+dnl The args-to-drop argument is shoved into a case statement, so
+dnl multiple arguments can be separated with a |.
+dnl
+dnl Note: Older versions of autoconf do not single-quote args, while 2.54+
+dnl places quotes around every argument. So, if you want to drop the
+dnl argument called --enable-layout, you must pass the third argument as:
+dnl [--enable-layout=*|\'--enable-layout=*]
+dnl
+dnl Trying to optimize this is left as an exercise to the reader who wants
+dnl to put up with more autoconf craziness. I give up.
+dnl
+AC_DEFUN([APR_SUBDIR_CONFIG], [
+ # save our work to this point; this allows the sub-package to use it
+ AC_CACHE_SAVE
+
+ echo "configuring package in $1 now"
+ ac_popdir=`pwd`
+ apr_config_subdirs="$1"
+ test -d $1 || $mkdir_p $1
+ ac_abs_srcdir=`(cd $srcdir/$1 && pwd)`
+ cd $1
+
+changequote(, )dnl
+ # A "../" for each directory in /$config_subdirs.
+ ac_dots=`echo $apr_config_subdirs|sed -e 's%^\./%%' -e 's%[^/]$%&/%' -e 's%[^/]*/%../%g'`
+changequote([, ])dnl
+
+ # Make the cache file pathname absolute for the subdirs
+ # required to correctly handle subdirs that might actually
+ # be symlinks
+ case "$cache_file" in
+ /*) # already absolute
+ ac_sub_cache_file=$cache_file ;;
+ *) # Was relative path.
+ ac_sub_cache_file="$ac_popdir/$cache_file" ;;
+ esac
+
+ ifelse($3, [], [apr_configure_args=$ac_configure_args],[
+ apr_configure_args=
+ apr_sep=
+ for apr_configure_arg in $ac_configure_args
+ do
+ case "$apr_configure_arg" in
+ $3)
+ continue ;;
+ esac
+ apr_configure_args="$apr_configure_args$apr_sep'$apr_configure_arg'"
+ apr_sep=" "
+ done
+ ])
+
+ dnl autoconf doesn't add --silent to ac_configure_args; explicitly pass it
+ test "x$silent" = "xyes" && apr_configure_args="$apr_configure_args --silent"
+
+ dnl AC_CONFIG_SUBDIRS silences option warnings, emulate this for 2.62
+ apr_configure_args="--disable-option-checking $apr_configure_args"
+
+ dnl The eval makes quoting arguments work - specifically the second argument
+ dnl where the quoting mechanisms used is "" rather than [].
+ dnl
+ dnl We need to execute another shell because some autoconf/shell combinations
+ dnl will choke after doing repeated APR_SUBDIR_CONFIG()s. (Namely Solaris
+ dnl and autoconf-2.54+)
+ if eval $SHELL $ac_abs_srcdir/configure $apr_configure_args --cache-file=$ac_sub_cache_file --srcdir=$ac_abs_srcdir $2
+ then :
+ echo "$1 configured properly"
+ else
+ echo "configure failed for $1"
+ exit 1
+ fi
+
+ cd $ac_popdir
+
+ # grab any updates from the sub-package
+ AC_CACHE_LOAD
+])dnl
+
+dnl
+dnl APR_SAVE_THE_ENVIRONMENT(variable_name)
+dnl
+dnl Stores the variable (usually a Makefile macro) for later restoration
+dnl
+AC_DEFUN([APR_SAVE_THE_ENVIRONMENT], [
+ apr_ste_save_$1="$$1"
+])dnl
+
+dnl
+dnl APR_RESTORE_THE_ENVIRONMENT(variable_name, prefix_)
+dnl
+dnl Uses the previously saved variable content to figure out what configure
+dnl has added to the variable, moving the new bits to prefix_variable_name
+dnl and restoring the original variable contents. This makes it possible
+dnl for a user to override configure when it does something stupid.
+dnl
+AC_DEFUN([APR_RESTORE_THE_ENVIRONMENT], [
+dnl Check whether $apr_ste_save_$1 is empty or
+dnl only whitespace. The verbatim "X" is token number 1,
+dnl the following whitespace will be ignored.
+set X $apr_ste_save_$1
+if test ${#} -eq 1; then
+ $2$1="$$1"
+ $1=
+else
+ if test "x$apr_ste_save_$1" = "x$$1"; then
+ $2$1=
+ else
+ $2$1=`echo "$$1" | sed -e "s%${apr_ste_save_$1}%%"`
+ $1="$apr_ste_save_$1"
+ fi
+fi
+if test "x$silent" != "xyes"; then
+ echo " restoring $1 to \"$$1\""
+ echo " setting $2$1 to \"$$2$1\""
+fi
+AC_SUBST($2$1)
+])dnl
+
+dnl
+dnl APR_SETIFNULL(variable, value)
+dnl
+dnl Set variable iff it's currently null
+dnl
+AC_DEFUN([APR_SETIFNULL], [
+ if test -z "$$1"; then
+ test "x$silent" != "xyes" && echo " setting $1 to \"$2\""
+ $1="$2"
+ fi
+])dnl
+
+dnl
+dnl APR_SETVAR(variable, value)
+dnl
+dnl Set variable no matter what
+dnl
+AC_DEFUN([APR_SETVAR], [
+ test "x$silent" != "xyes" && echo " forcing $1 to \"$2\""
+ $1="$2"
+])dnl
+
+dnl
+dnl APR_ADDTO(variable, value)
+dnl
+dnl Add value to variable
+dnl
+AC_DEFUN([APR_ADDTO], [
+ if test "x$$1" = "x"; then
+ test "x$silent" != "xyes" && echo " setting $1 to \"$2\""
+ $1="$2"
+ else
+ apr_addto_bugger="$2"
+ for i in $apr_addto_bugger; do
+ apr_addto_duplicate="0"
+ for j in $$1; do
+ if test "x$i" = "x$j"; then
+ apr_addto_duplicate="1"
+ break
+ fi
+ done
+ if test $apr_addto_duplicate = "0"; then
+ test "x$silent" != "xyes" && echo " adding \"$i\" to $1"
+ $1="$$1 $i"
+ fi
+ done
+ fi
+])dnl
+
+dnl
+dnl APR_REMOVEFROM(variable, value)
+dnl
+dnl Remove a value from a variable
+dnl
+AC_DEFUN([APR_REMOVEFROM], [
+ if test "x$$1" = "x$2"; then
+ test "x$silent" != "xyes" && echo " nulling $1"
+ $1=""
+ else
+ apr_new_bugger=""
+ apr_removed=0
+ for i in $$1; do
+ if test "x$i" != "x$2"; then
+ apr_new_bugger="$apr_new_bugger $i"
+ else
+ apr_removed=1
+ fi
+ done
+ if test $apr_removed = "1"; then
+ test "x$silent" != "xyes" && echo " removed \"$2\" from $1"
+ $1=$apr_new_bugger
+ fi
+ fi
+]) dnl
+
+dnl
+dnl APR_CHECK_DEFINE_FILES( symbol, header_file [header_file ...] )
+dnl
+AC_DEFUN([APR_CHECK_DEFINE_FILES], [
+ AC_CACHE_CHECK([for $1 in $2],ac_cv_define_$1,[
+ ac_cv_define_$1=no
+ for curhdr in $2
+ do
+ AC_EGREP_CPP(YES_IS_DEFINED, [
+#include <$curhdr>
+#ifdef $1
+YES_IS_DEFINED
+#endif
+ ], ac_cv_define_$1=yes)
+ done
+ ])
+ if test "$ac_cv_define_$1" = "yes"; then
+ AC_DEFINE(HAVE_$1, 1, [Define if $1 is defined])
+ fi
+])
+
+
+dnl
+dnl APR_CHECK_DEFINE(symbol, header_file)
+dnl
+AC_DEFUN([APR_CHECK_DEFINE], [
+ AC_CACHE_CHECK([for $1 in $2],ac_cv_define_$1,[
+ AC_EGREP_CPP(YES_IS_DEFINED, [
+#include <$2>
+#ifdef $1
+YES_IS_DEFINED
+#endif
+ ], ac_cv_define_$1=yes, ac_cv_define_$1=no)
+ ])
+ if test "$ac_cv_define_$1" = "yes"; then
+ AC_DEFINE(HAVE_$1, 1, [Define if $1 is defined in $2])
+ fi
+])
+
+dnl
+dnl APR_CHECK_APR_DEFINE( symbol )
+dnl
+AC_DEFUN([APR_CHECK_APR_DEFINE], [
+apr_old_cppflags=$CPPFLAGS
+CPPFLAGS="$CPPFLAGS $INCLUDES"
+AC_EGREP_CPP(YES_IS_DEFINED, [
+#include <apr.h>
+#if $1
+YES_IS_DEFINED
+#endif
+], ac_cv_define_$1=yes, ac_cv_define_$1=no)
+CPPFLAGS=$apr_old_cppflags
+])
+
+dnl APR_CHECK_FILE(filename); set ac_cv_file_filename to
+dnl "yes" if 'filename' is readable, else "no".
+dnl @deprecated! - use AC_CHECK_FILE instead
+AC_DEFUN([APR_CHECK_FILE], [
+dnl Pick a safe variable name
+define([apr_cvname], ac_cv_file_[]translit([$1], [./+-], [__p_]))
+AC_CACHE_CHECK([for $1], [apr_cvname],
+[if test -r $1; then
+ apr_cvname=yes
+ else
+ apr_cvname=no
+ fi])
+])
+
+define(APR_IFALLYES,[dnl
+ac_rc=yes
+for ac_spec in $1; do
+ ac_type=`echo "$ac_spec" | sed -e 's/:.*$//'`
+ ac_item=`echo "$ac_spec" | sed -e 's/^.*://'`
+ case $ac_type in
+ header )
+ ac_item=`echo "$ac_item" | sed 'y%./+-%__p_%'`
+ ac_var="ac_cv_header_$ac_item"
+ ;;
+ file )
+ ac_item=`echo "$ac_item" | sed 'y%./+-%__p_%'`
+ ac_var="ac_cv_file_$ac_item"
+ ;;
+ func ) ac_var="ac_cv_func_$ac_item" ;;
+ struct ) ac_var="ac_cv_struct_$ac_item" ;;
+ define ) ac_var="ac_cv_define_$ac_item" ;;
+ custom ) ac_var="$ac_item" ;;
+ esac
+ eval "ac_val=\$$ac_var"
+ if test ".$ac_val" != .yes; then
+ ac_rc=no
+ break
+ fi
+done
+if test ".$ac_rc" = .yes; then
+ :
+ $2
+else
+ :
+ $3
+fi
+])
+
+
+define(APR_BEGIN_DECISION,[dnl
+ac_decision_item='$1'
+ac_decision_msg='FAILED'
+ac_decision=''
+])
+
+
+AC_DEFUN([APR_DECIDE],[dnl
+dnl Define the flag (or not) in apr_private.h via autoheader
+AH_TEMPLATE($1, [Define if $2 will be used])
+ac_decision='$1'
+ac_decision_msg='$2'
+ac_decision_$1=yes
+ac_decision_$1_msg='$2'
+])
+
+
+define(APR_DECISION_OVERRIDE,[dnl
+ ac_decision=''
+ for ac_item in $1; do
+ eval "ac_decision_this=\$ac_decision_${ac_item}"
+ if test ".$ac_decision_this" = .yes; then
+ ac_decision=$ac_item
+ eval "ac_decision_msg=\$ac_decision_${ac_item}_msg"
+ fi
+ done
+])
+
+
+define(APR_DECISION_FORCE,[dnl
+ac_decision="$1"
+eval "ac_decision_msg=\"\$ac_decision_${ac_decision}_msg\""
+])
+
+
+define(APR_END_DECISION,[dnl
+if test ".$ac_decision" = .; then
+ echo "[$]0:Error: decision on $ac_decision_item failed" 1>&2
+ exit 1
+else
+ if test ".$ac_decision_msg" = .; then
+ ac_decision_msg="$ac_decision"
+ fi
+ AC_DEFINE_UNQUOTED(${ac_decision_item})
+ AC_MSG_RESULT([decision on $ac_decision_item... $ac_decision_msg])
+fi
+])
+
+
+dnl
+dnl APR_CHECK_SIZEOF_EXTENDED(INCLUDES, TYPE [, CROSS_SIZE])
+dnl
+dnl A variant of AC_CHECK_SIZEOF which allows the checking of
+dnl sizes of non-builtin types
+dnl
+AC_DEFUN([APR_CHECK_SIZEOF_EXTENDED],
+[changequote(<<, >>)dnl
+dnl The name to #define.
+define(<<AC_TYPE_NAME>>, translit(sizeof_$2, [a-z *], [A-Z_P]))dnl
+dnl The cache variable name.
+define(<<AC_CV_NAME>>, translit(ac_cv_sizeof_$2, [ *], [_p]))dnl
+changequote([, ])dnl
+AC_MSG_CHECKING(size of $2)
+AC_CACHE_VAL(AC_CV_NAME,
+[AC_TRY_RUN([#include <stdio.h>
+$1
+main()
+{
+ FILE *f=fopen("conftestval", "w");
+ if (!f) exit(1);
+ fprintf(f, "%d\n", sizeof($2));
+ exit(0);
+}], AC_CV_NAME=`cat conftestval`, AC_CV_NAME=0, ifelse([$3],,,
+AC_CV_NAME=$3))])dnl
+AC_MSG_RESULT($AC_CV_NAME)
+AC_DEFINE_UNQUOTED(AC_TYPE_NAME, $AC_CV_NAME, [The size of ]$2)
+undefine([AC_TYPE_NAME])dnl
+undefine([AC_CV_NAME])dnl
+])
+
+
+dnl
+dnl APR_TRY_COMPILE_NO_WARNING(INCLUDES, FUNCTION-BODY,
+dnl [ACTIONS-IF-NO-WARNINGS], [ACTIONS-IF-WARNINGS])
+dnl
+dnl Tries a compile test with warnings activated so that the result
+dnl is false if the code doesn't compile cleanly. For compilers
+dnl where it is not known how to activate a "fail-on-error" mode,
+dnl it is undefined which of the sets of actions will be run.
+dnl
+AC_DEFUN([APR_TRY_COMPILE_NO_WARNING],
+[apr_save_CFLAGS=$CFLAGS
+ CFLAGS="$CFLAGS $CFLAGS_WARN"
+ if test "$ac_cv_prog_gcc" = "yes"; then
+ CFLAGS="$CFLAGS -Werror"
+ fi
+ AC_COMPILE_IFELSE(
+ [AC_LANG_SOURCE(
+ [#include "confdefs.h"
+ ]
+ [[$1]]
+ [int main(int argc, const char *const *argv) {]
+ [[$2]]
+ [ return 0; }]
+ )],
+ [$3], [$4])
+ CFLAGS=$apr_save_CFLAGS
+])
+
+dnl
+dnl APR_CHECK_STRERROR_R_RC
+dnl
+dnl Decide which style of retcode is used by this system's
+dnl strerror_r(). It either returns int (0 for success, -1
+dnl for failure), or it returns a pointer to the error
+dnl string.
+dnl
+dnl
+AC_DEFUN([APR_CHECK_STRERROR_R_RC], [
+AC_MSG_CHECKING(for type of return code from strerror_r)
+AC_TRY_RUN([
+#include <errno.h>
+#include <string.h>
+#include <stdio.h>
+main()
+{
+ char buf[1024];
+ if (strerror_r(ERANGE, buf, sizeof buf) < 1) {
+ exit(0);
+ }
+ else {
+ exit(1);
+ }
+}], [
+ ac_cv_strerror_r_rc_int=yes ], [
+ ac_cv_strerror_r_rc_int=no ], [
+ ac_cv_strerror_r_rc_int=no ] )
+if test "x$ac_cv_strerror_r_rc_int" = xyes; then
+ AC_DEFINE(STRERROR_R_RC_INT, 1, [Define if strerror returns int])
+ msg="int"
+else
+ msg="pointer"
+fi
+AC_MSG_RESULT([$msg])
+] )
+
+dnl
+dnl APR_CHECK_DIRENT_INODE
+dnl
+dnl Decide if d_fileno or d_ino are available in the dirent
+dnl structure on this platform. Single UNIX Spec says d_ino,
+dnl BSD uses d_fileno. Undef to find the real beast.
+dnl
+AC_DEFUN([APR_CHECK_DIRENT_INODE], [
+AC_CACHE_CHECK([for inode member of struct dirent], apr_cv_dirent_inode, [
+apr_cv_dirent_inode=no
+AC_TRY_COMPILE([
+#include <sys/types.h>
+#include <dirent.h>
+],[
+#ifdef d_ino
+#undef d_ino
+#endif
+struct dirent de; de.d_fileno;
+], apr_cv_dirent_inode=d_fileno)
+if test "$apr_cv_dirent_inode" = "no"; then
+AC_TRY_COMPILE([
+#include <sys/types.h>
+#include <dirent.h>
+],[
+#ifdef d_fileno
+#undef d_fileno
+#endif
+struct dirent de; de.d_ino;
+], apr_cv_dirent_inode=d_ino)
+fi
+])
+if test "$apr_cv_dirent_inode" != "no"; then
+ AC_DEFINE_UNQUOTED(DIRENT_INODE, $apr_cv_dirent_inode,
+ [Define if struct dirent has an inode member])
+fi
+])
+
+dnl
+dnl APR_CHECK_DIRENT_TYPE
+dnl
+dnl Decide if d_type is available in the dirent structure
+dnl on this platform. Not part of the Single UNIX Spec.
+dnl Note that this is worthless without DT_xxx macros, so
+dnl look for one while we are at it.
+dnl
+AC_DEFUN([APR_CHECK_DIRENT_TYPE], [
+AC_CACHE_CHECK([for file type member of struct dirent], apr_cv_dirent_type,[
+apr_cv_dirent_type=no
+AC_TRY_COMPILE([
+#include <sys/types.h>
+#include <dirent.h>
+],[
+struct dirent de; de.d_type = DT_REG;
+], apr_cv_dirent_type=d_type)
+])
+if test "$apr_cv_dirent_type" != "no"; then
+ AC_DEFINE_UNQUOTED(DIRENT_TYPE, $apr_cv_dirent_type,
+ [Define if struct dirent has a d_type member])
+fi
+])
+
+dnl the following is a newline, a space, a tab, and a backslash (the
+dnl backslash is used by the shell to skip newlines, but m4 sees it;
+dnl treat it like whitespace).
+dnl WARNING: don't reindent these lines, or the space/tab will be lost!
+define([apr_whitespace],[
+ \])
+
+dnl
+dnl APR_COMMA_ARGS(ARG1 ...)
+dnl convert the whitespace-separated arguments into comman-separated
+dnl arguments.
+dnl
+dnl APR_FOREACH(CODE-BLOCK, ARG1, ARG2, ...)
+dnl subsitute CODE-BLOCK for each ARG[i]. "eachval" will be set to ARG[i]
+dnl within each iteration.
+dnl
+changequote({,})
+define({APR_COMMA_ARGS},{patsubst([$}{1],[[}apr_whitespace{]+],[,])})
+define({APR_FOREACH},
+ {ifelse($}{2,,,
+ [define([eachval],
+ $}{2)$}{1[]APR_FOREACH([$}{1],
+ builtin([shift],
+ builtin([shift], $}{@)))])})
+changequote([,])
+
+dnl APR_FLAG_HEADERS(HEADER-FILE ... [, FLAG-TO-SET ] [, "yes" ])
+dnl we set FLAG-TO-SET to 1 if we find HEADER-FILE, otherwise we set to 0
+dnl if FLAG-TO-SET is null, we automagically determine it's name
+dnl by changing all "/" to "_" in the HEADER-FILE and dropping
+dnl all "." and "-" chars. If the 3rd parameter is "yes" then instead of
+dnl setting to 1 or 0, we set FLAG-TO-SET to yes or no.
+dnl
+AC_DEFUN([APR_FLAG_HEADERS], [
+AC_CHECK_HEADERS($1)
+for aprt_i in $1
+do
+ ac_safe=`echo "$aprt_i" | sed 'y%./+-%__p_%'`
+ aprt_2=`echo "$aprt_i" | sed -e 's%/%_%g' -e 's/\.//g' -e 's/-//g'`
+ if eval "test \"`echo '$ac_cv_header_'$ac_safe`\" = yes"; then
+ eval "ifelse($2,,$aprt_2,$2)=ifelse($3,yes,yes,1)"
+ else
+ eval "ifelse($2,,$aprt_2,$2)=ifelse($3,yes,no,0)"
+ fi
+done
+])
+
+dnl APR_FLAG_FUNCS(FUNC ... [, FLAG-TO-SET] [, "yes" ])
+dnl if FLAG-TO-SET is null, we automagically determine it's name
+dnl prepending "have_" to the function name in FUNC, otherwise
+dnl we use what's provided as FLAG-TO-SET. If the 3rd parameter
+dnl is "yes" then instead of setting to 1 or 0, we set FLAG-TO-SET
+dnl to yes or no.
+dnl
+AC_DEFUN([APR_FLAG_FUNCS], [
+AC_CHECK_FUNCS($1)
+for aprt_j in $1
+do
+ aprt_3="have_$aprt_j"
+ if eval "test \"`echo '$ac_cv_func_'$aprt_j`\" = yes"; then
+ eval "ifelse($2,,$aprt_3,$2)=ifelse($3,yes,yes,1)"
+ else
+ eval "ifelse($2,,$aprt_3,$2)=ifelse($3,yes,no,0)"
+ fi
+done
+])
+
+dnl Iteratively interpolate the contents of the second argument
+dnl until interpolation offers no new result. Then assign the
+dnl final result to $1.
+dnl
+dnl Example:
+dnl
+dnl foo=1
+dnl bar='${foo}/2'
+dnl baz='${bar}/3'
+dnl APR_EXPAND_VAR(fraz, $baz)
+dnl $fraz is now "1/2/3"
+dnl
+AC_DEFUN([APR_EXPAND_VAR], [
+ap_last=
+ap_cur="$2"
+while test "x${ap_cur}" != "x${ap_last}";
+do
+ ap_last="${ap_cur}"
+ ap_cur=`eval "echo ${ap_cur}"`
+done
+$1="${ap_cur}"
+])
+
+dnl
+dnl Removes the value of $3 from the string in $2, strips of any leading
+dnl slashes, and returns the value in $1.
+dnl
+dnl Example:
+dnl orig_path="${prefix}/bar"
+dnl APR_PATH_RELATIVE(final_path, $orig_path, $prefix)
+dnl $final_path now contains "bar"
+AC_DEFUN([APR_PATH_RELATIVE], [
+ap_stripped=`echo $2 | sed -e "s#^$3##"`
+# check if the stripping was successful
+if test "x$2" != "x${ap_stripped}"; then
+ # it was, so strip of any leading slashes
+ $1="`echo ${ap_stripped} | sed -e 's#^/*##'`"
+else
+ # it wasn't so return the original
+ $1="$2"
+fi
+])
+
+dnl APR_HELP_STRING(LHS, RHS)
+dnl Autoconf 2.50 can not handle substr correctly. It does have
+dnl AC_HELP_STRING, so let's try to call it if we can.
+dnl Note: this define must be on one line so that it can be properly returned
+dnl as the help string. When using this macro with a multi-line RHS, ensure
+dnl that you surround the macro invocation with []s
+AC_DEFUN([APR_HELP_STRING], [ifelse(regexp(AC_ACVERSION, 2\.1), -1, AC_HELP_STRING([$1],[$2]),[ ][$1] substr([ ],len($1))[$2])])
+
+dnl
+dnl APR_LAYOUT(configlayout, layoutname [, extravars])
+dnl
+AC_DEFUN([APR_LAYOUT], [
+ if test ! -f $srcdir/config.layout; then
+ echo "** Error: Layout file $srcdir/config.layout not found"
+ echo "** Error: Cannot use undefined layout '$LAYOUT'"
+ exit 1
+ fi
+ # Catch layout names including a slash which will otherwise
+ # confuse the heck out of the sed script.
+ case $2 in
+ */*)
+ echo "** Error: $2 is not a valid layout name"
+ exit 1 ;;
+ esac
+ pldconf=./config.pld
+ changequote({,})
+ sed -e "1s/[ ]*<[lL]ayout[ ]*$2[ ]*>[ ]*//;1t" \
+ -e "1,/[ ]*<[lL]ayout[ ]*$2[ ]*>[ ]*/d" \
+ -e '/[ ]*<\/Layout>[ ]*/,$d' \
+ -e "s/^[ ]*//g" \
+ -e "s/:[ ]*/=\'/g" \
+ -e "s/[ ]*$/'/g" \
+ $1 > $pldconf
+ layout_name=$2
+ if test ! -s $pldconf; then
+ echo "** Error: unable to find layout $layout_name"
+ exit 1
+ fi
+ . $pldconf
+ rm $pldconf
+ for var in prefix exec_prefix bindir sbindir libexecdir mandir \
+ sysconfdir datadir includedir localstatedir runtimedir \
+ logfiledir libdir installbuilddir libsuffix $3; do
+ eval "val=\"\$$var\""
+ case $val in
+ *+)
+ val=`echo $val | sed -e 's;\+$;;'`
+ eval "$var=\"\$val\""
+ autosuffix=yes
+ ;;
+ *)
+ autosuffix=no
+ ;;
+ esac
+ val=`echo $val | sed -e 's:\(.\)/*$:\1:'`
+ val=`echo $val | sed -e 's:[\$]\([a-z_]*\):${\1}:g'`
+ if test "$autosuffix" = "yes"; then
+ if echo $val | grep apache >/dev/null; then
+ addtarget=no
+ else
+ addtarget=yes
+ fi
+ if test "$addtarget" = "yes"; then
+ val="$val/apache2"
+ fi
+ fi
+ eval "$var='$val'"
+ done
+ changequote([,])
+])dnl
+
+dnl
+dnl APR_ENABLE_LAYOUT(default layout name [, extra vars])
+dnl
+AC_DEFUN([APR_ENABLE_LAYOUT], [
+AC_ARG_ENABLE(layout,
+[ --enable-layout=LAYOUT],[
+ LAYOUT=$enableval
+])
+
+if test -z "$LAYOUT"; then
+ LAYOUT="$1"
+fi
+APR_LAYOUT($srcdir/config.layout, $LAYOUT, $2)
+
+AC_MSG_CHECKING(for chosen layout)
+AC_MSG_RESULT($layout_name)
+])
+
+
+dnl
+dnl APR_PARSE_ARGUMENTS
+dnl a reimplementation of autoconf's argument parser,
+dnl used here to allow us to co-exist layouts and argument based
+dnl set ups.
+AC_DEFUN([APR_PARSE_ARGUMENTS], [
+ac_prev=
+# Retrieve the command-line arguments. The eval is needed because
+# the arguments are quoted to preserve accuracy.
+eval "set x $ac_configure_args"
+shift
+for ac_option
+do
+ # If the previous option needs an argument, assign it.
+ if test -n "$ac_prev"; then
+ eval "$ac_prev=\$ac_option"
+ ac_prev=
+ continue
+ fi
+
+ ac_optarg=`expr "x$ac_option" : 'x[[^=]]*=\(.*\)'`
+
+ case $ac_option in
+
+ -bindir | --bindir | --bindi | --bind | --bin | --bi)
+ ac_prev=bindir ;;
+ -bindir=* | --bindir=* | --bindi=* | --bind=* | --bin=* | --bi=*)
+ bindir="$ac_optarg" ;;
+
+ -datadir | --datadir | --datadi | --datad | --data | --dat | --da)
+ ac_prev=datadir ;;
+ -datadir=* | --datadir=* | --datadi=* | --datad=* | --data=* | --dat=* \
+ | --da=*)
+ datadir="$ac_optarg" ;;
+
+ -exec-prefix | --exec_prefix | --exec-prefix | --exec-prefi \
+ | --exec-pref | --exec-pre | --exec-pr | --exec-p | --exec- \
+ | --exec | --exe | --ex)
+ ac_prev=exec_prefix ;;
+ -exec-prefix=* | --exec_prefix=* | --exec-prefix=* | --exec-prefi=* \
+ | --exec-pref=* | --exec-pre=* | --exec-pr=* | --exec-p=* | --exec-=* \
+ | --exec=* | --exe=* | --ex=*)
+ exec_prefix="$ac_optarg" ;;
+
+ -includedir | --includedir | --includedi | --included | --include \
+ | --includ | --inclu | --incl | --inc)
+ ac_prev=includedir ;;
+ -includedir=* | --includedir=* | --includedi=* | --included=* | --include=* \
+ | --includ=* | --inclu=* | --incl=* | --inc=*)
+ includedir="$ac_optarg" ;;
+
+ -infodir | --infodir | --infodi | --infod | --info | --inf)
+ ac_prev=infodir ;;
+ -infodir=* | --infodir=* | --infodi=* | --infod=* | --info=* | --inf=*)
+ infodir="$ac_optarg" ;;
+
+ -libdir | --libdir | --libdi | --libd)
+ ac_prev=libdir ;;
+ -libdir=* | --libdir=* | --libdi=* | --libd=*)
+ libdir="$ac_optarg" ;;
+
+ -libexecdir | --libexecdir | --libexecdi | --libexecd | --libexec \
+ | --libexe | --libex | --libe)
+ ac_prev=libexecdir ;;
+ -libexecdir=* | --libexecdir=* | --libexecdi=* | --libexecd=* | --libexec=* \
+ | --libexe=* | --libex=* | --libe=*)
+ libexecdir="$ac_optarg" ;;
+
+ -localstatedir | --localstatedir | --localstatedi | --localstated \
+ | --localstate | --localstat | --localsta | --localst \
+ | --locals | --local | --loca | --loc | --lo)
+ ac_prev=localstatedir ;;
+ -localstatedir=* | --localstatedir=* | --localstatedi=* | --localstated=* \
+ | --localstate=* | --localstat=* | --localsta=* | --localst=* \
+ | --locals=* | --local=* | --loca=* | --loc=* | --lo=*)
+ localstatedir="$ac_optarg" ;;
+
+ -mandir | --mandir | --mandi | --mand | --man | --ma | --m)
+ ac_prev=mandir ;;
+ -mandir=* | --mandir=* | --mandi=* | --mand=* | --man=* | --ma=* | --m=*)
+ mandir="$ac_optarg" ;;
+
+ -prefix | --prefix | --prefi | --pref | --pre | --pr | --p)
+ ac_prev=prefix ;;
+ -prefix=* | --prefix=* | --prefi=* | --pref=* | --pre=* | --pr=* | --p=*)
+ prefix="$ac_optarg" ;;
+
+ -sbindir | --sbindir | --sbindi | --sbind | --sbin | --sbi | --sb)
+ ac_prev=sbindir ;;
+ -sbindir=* | --sbindir=* | --sbindi=* | --sbind=* | --sbin=* \
+ | --sbi=* | --sb=*)
+ sbindir="$ac_optarg" ;;
+
+ -sharedstatedir | --sharedstatedir | --sharedstatedi \
+ | --sharedstated | --sharedstate | --sharedstat | --sharedsta \
+ | --sharedst | --shareds | --shared | --share | --shar \
+ | --sha | --sh)
+ ac_prev=sharedstatedir ;;
+ -sharedstatedir=* | --sharedstatedir=* | --sharedstatedi=* \
+ | --sharedstated=* | --sharedstate=* | --sharedstat=* | --sharedsta=* \
+ | --sharedst=* | --shareds=* | --shared=* | --share=* | --shar=* \
+ | --sha=* | --sh=*)
+ sharedstatedir="$ac_optarg" ;;
+
+ -sysconfdir | --sysconfdir | --sysconfdi | --sysconfd | --sysconf \
+ | --syscon | --sysco | --sysc | --sys | --sy)
+ ac_prev=sysconfdir ;;
+ -sysconfdir=* | --sysconfdir=* | --sysconfdi=* | --sysconfd=* | --sysconf=* \
+ | --syscon=* | --sysco=* | --sysc=* | --sys=* | --sy=*)
+ sysconfdir="$ac_optarg" ;;
+
+ esac
+done
+
+# Be sure to have absolute paths.
+for ac_var in exec_prefix prefix
+do
+ eval ac_val=$`echo $ac_var`
+ case $ac_val in
+ [[\\/$]]* | ?:[[\\/]]* | NONE | '' ) ;;
+ *) AC_MSG_ERROR([expected an absolute path for --$ac_var: $ac_val]);;
+ esac
+done
+
+])dnl
+
+dnl
+dnl APR_CHECK_DEPEND
+dnl
+dnl Determine what program we can use to generate .deps-style dependencies
+dnl
+AC_DEFUN([APR_CHECK_DEPEND], [
+dnl Try to determine what depend program we can use
+dnl All GCC-variants should have -MM.
+dnl If not, then we can check on those, too.
+if test "$GCC" = "yes"; then
+ MKDEP='$(CC) -MM'
+else
+ rm -f conftest.c
+dnl <sys/types.h> should be available everywhere!
+ cat > conftest.c <<EOF
+#include <sys/types.h>
+ int main() { return 0; }
+EOF
+ MKDEP="true"
+ for i in "$CC -MM" "$CC -M" "$CPP -MM" "$CPP -M" "cpp -M"; do
+ AC_MSG_CHECKING([if $i can create proper make dependencies])
+ if $i conftest.c 2>/dev/null | grep 'conftest.o: conftest.c' >/dev/null; then
+ MKDEP=$i
+ AC_MSG_RESULT(yes)
+ break;
+ fi
+ AC_MSG_RESULT(no)
+ done
+ rm -f conftest.c
+fi
+
+AC_SUBST(MKDEP)
+])
+
+dnl
+dnl APR_CHECK_TYPES_COMPATIBLE(TYPE-1, TYPE-2, [ACTION-IF-TRUE])
+dnl
+dnl Try to determine whether two types are the same. Only works
+dnl for gcc and icc.
+dnl
+AC_DEFUN([APR_CHECK_TYPES_COMPATIBLE], [
+define([apr_cvname], apr_cv_typematch_[]translit([$1], [ ], [_])_[]translit([$2], [ ], [_]))
+AC_CACHE_CHECK([whether $1 and $2 are the same], apr_cvname, [
+AC_TRY_COMPILE(AC_INCLUDES_DEFAULT, [
+ int foo[0 - !__builtin_types_compatible_p($1, $2)];
+], [apr_cvname=yes
+$3], [apr_cvname=no])])
+])
diff --git a/jni/native/build/buildcheck.sh b/jni/native/build/buildcheck.sh
new file mode 100755
index 0000000..d35be6d
--- /dev/null
+++ b/jni/native/build/buildcheck.sh
@@ -0,0 +1,82 @@
+#! /bin/sh
+
+# 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.
+
+
+echo "buildconf: checking installation..."
+
+# any python
+python=`build/PrintPath python`
+if test -z "$python"; then
+echo "buildconf: python not found."
+echo " You need python installed"
+echo " to build Tomcat Native from SVN."
+exit 1
+else
+py_version=`python -c 'import sys; print sys.version' 2>&1|sed 's/ .*//;q'`
+echo "buildconf: python version $py_version (ok)"
+fi
+
+# autoconf 2.50 or newer
+ac_version=`${AUTOCONF:-autoconf} --version 2>/dev/null|sed -e 's/^[^0-9]*//;s/[a-z]* *$//;q'`
+if test -z "$ac_version"; then
+echo "buildconf: autoconf not found."
+echo " You need autoconf version 2.50 or newer installed"
+echo " to build Tomcat Native from SVN."
+exit 1
+fi
+IFS=.; set $ac_version; IFS=' '
+if test "$1" = "2" -a "$2" -lt "50" || test "$1" -lt "2"; then
+echo "buildconf: autoconf version $ac_version found."
+echo " You need autoconf version 2.50 or newer installed"
+echo " to build Tomcat Native from SVN."
+exit 1
+else
+echo "buildconf: autoconf version $ac_version (ok)"
+fi
+
+# Sample libtool --version outputs:
+# ltmain.sh (GNU libtool) 1.3.3 (1.385.2.181 1999/07/02 15:49:11)
+# ltmain.sh (GNU libtool 1.1361 2004/01/02 23:10:52) 1.5a
+# output is multiline from 1.5 onwards
+
+# Require libtool 1.4 or newer
+libtool=`build/PrintPath glibtool libtool libtool15 libtool14`
+lt_pversion=`$libtool --version 2>/dev/null|sed -e 's/([^)]*)//g;s/^[^0-9]*//;s/[- ].*//g;q'`
+if test -z "$lt_pversion"; then
+echo "buildconf: libtool not found."
+echo " You need libtool version 1.4 or newer installed"
+echo " to build Tomcat Native from SVN."
+exit 1
+fi
+lt_version=`echo $lt_pversion|sed -e 's/\([a-z]*\)$/.\1/'`
+IFS=.; set $lt_version; IFS=' '
+lt_status="good"
+if test "$1" = "1"; then
+ if test "$2" -lt "4"; then
+ lt_status="bad"
+ fi
+fi
+if test $lt_status = "good"; then
+ echo "buildconf: libtool version $lt_pversion (ok)"
+ exit 0
+fi
+
+echo "buildconf: libtool version $lt_pversion found."
+echo " You need libtool version 1.4 or newer installed"
+echo " to build Tomcat Native from SVN."
+
+exit 1
diff --git a/jni/native/build/config.guess b/jni/native/build/config.guess
new file mode 100755
index 0000000..72625d4
--- /dev/null
+++ b/jni/native/build/config.guess
@@ -0,0 +1,1420 @@
+#! /bin/sh
+# Attempt to guess a canonical system name.
+# Copyright 1992-2014 Free Software Foundation, Inc.
+
+timestamp='2014-02-12'
+
+# This file is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, see <http://www.gnu.org/licenses/>.
+#
+# As a special exception to the GNU General Public License, if you
+# distribute this file as part of a program that contains a
+# configuration script generated by Autoconf, you may include it under
+# the same distribution terms that you use for the rest of that
+# program. This Exception is an additional permission under section 7
+# of the GNU General Public License, version 3 ("GPLv3").
+#
+# Originally written by Per Bothner.
+#
+# You can get the latest version of this script from:
+# http://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=config.guess;hb=HEAD
+#
+# Please send patches with a ChangeLog entry to config-patches at gnu.org.
+
+
+me=`echo "$0" | sed -e 's,.*/,,'`
+
+usage="\
+Usage: $0 [OPTION]
+
+Output the configuration name of the system \`$me' is run on.
+
+Operation modes:
+ -h, --help print this help, then exit
+ -t, --time-stamp print date of last modification, then exit
+ -v, --version print version number, then exit
+
+Report bugs and patches to <config-patches at gnu.org>."
+
+version="\
+GNU config.guess ($timestamp)
+
+Originally written by Per Bothner.
+Copyright 1992-2014 Free Software Foundation, Inc.
+
+This is free software; see the source for copying conditions. There is NO
+warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE."
+
+help="
+Try \`$me --help' for more information."
+
+# Parse command line
+while test $# -gt 0 ; do
+ case $1 in
+ --time-stamp | --time* | -t )
+ echo "$timestamp" ; exit ;;
+ --version | -v )
+ echo "$version" ; exit ;;
+ --help | --h* | -h )
+ echo "$usage"; exit ;;
+ -- ) # Stop option processing
+ shift; break ;;
+ - ) # Use stdin as input.
+ break ;;
+ -* )
+ echo "$me: invalid option $1$help" >&2
+ exit 1 ;;
+ * )
+ break ;;
+ esac
+done
+
+if test $# != 0; then
+ echo "$me: too many arguments$help" >&2
+ exit 1
+fi
+
+trap 'exit 1' 1 2 15
+
+# CC_FOR_BUILD -- compiler used by this script. Note that the use of a
+# compiler to aid in system detection is discouraged as it requires
+# temporary files to be created and, as you can see below, it is a
+# headache to deal with in a portable fashion.
+
+# Historically, `CC_FOR_BUILD' used to be named `HOST_CC'. We still
+# use `HOST_CC' if defined, but it is deprecated.
+
+# Portable tmp directory creation inspired by the Autoconf team.
+
+set_cc_for_build='
+trap "exitcode=\$?; (rm -f \$tmpfiles 2>/dev/null; rmdir \$tmp 2>/dev/null) && exit \$exitcode" 0 ;
+trap "rm -f \$tmpfiles 2>/dev/null; rmdir \$tmp 2>/dev/null; exit 1" 1 2 13 15 ;
+: ${TMPDIR=/tmp} ;
+ { tmp=`(umask 077 && mktemp -d "$TMPDIR/cgXXXXXX") 2>/dev/null` && test -n "$tmp" && test -d "$tmp" ; } ||
+ { test -n "$RANDOM" && tmp=$TMPDIR/cg$$-$RANDOM && (umask 077 && mkdir $tmp) ; } ||
+ { tmp=$TMPDIR/cg-$$ && (umask 077 && mkdir $tmp) && echo "Warning: creating insecure temp directory" >&2 ; } ||
+ { echo "$me: cannot create a temporary directory in $TMPDIR" >&2 ; exit 1 ; } ;
+dummy=$tmp/dummy ;
+tmpfiles="$dummy.c $dummy.o $dummy.rel $dummy" ;
+case $CC_FOR_BUILD,$HOST_CC,$CC in
+ ,,) echo "int x;" > $dummy.c ;
+ for c in cc gcc c89 c99 ; do
+ if ($c -c -o $dummy.o $dummy.c) >/dev/null 2>&1 ; then
+ CC_FOR_BUILD="$c"; break ;
+ fi ;
+ done ;
+ if test x"$CC_FOR_BUILD" = x ; then
+ CC_FOR_BUILD=no_compiler_found ;
+ fi
+ ;;
+ ,,*) CC_FOR_BUILD=$CC ;;
+ ,*,*) CC_FOR_BUILD=$HOST_CC ;;
+esac ; set_cc_for_build= ;'
+
+# This is needed to find uname on a Pyramid OSx when run in the BSD universe.
+# (ghazi at noc.rutgers.edu 1994-08-24)
+if (test -f /.attbin/uname) >/dev/null 2>&1 ; then
+ PATH=$PATH:/.attbin ; export PATH
+fi
+
+UNAME_MACHINE=`(uname -m) 2>/dev/null` || UNAME_MACHINE=unknown
+UNAME_RELEASE=`(uname -r) 2>/dev/null` || UNAME_RELEASE=unknown
+UNAME_SYSTEM=`(uname -s) 2>/dev/null` || UNAME_SYSTEM=unknown
+UNAME_VERSION=`(uname -v) 2>/dev/null` || UNAME_VERSION=unknown
+
+case "${UNAME_SYSTEM}" in
+Linux|GNU|GNU/*)
+ # If the system lacks a compiler, then just pick glibc.
+ # We could probably try harder.
+ LIBC=gnu
+
+ eval $set_cc_for_build
+ cat <<-EOF > $dummy.c
+ #include <features.h>
+ #if defined(__UCLIBC__)
+ LIBC=uclibc
+ #elif defined(__dietlibc__)
+ LIBC=dietlibc
+ #else
+ LIBC=gnu
+ #endif
+ EOF
+ eval `$CC_FOR_BUILD -E $dummy.c 2>/dev/null | grep '^LIBC' | sed 's, ,,g'`
+ ;;
+esac
+
+# Note: order is significant - the case branches are not exclusive.
+
+case "${UNAME_MACHINE}:${UNAME_SYSTEM}:${UNAME_RELEASE}:${UNAME_VERSION}" in
+ *:NetBSD:*:*)
+ # NetBSD (nbsd) targets should (where applicable) match one or
+ # more of the tuples: *-*-netbsdelf*, *-*-netbsdaout*,
+ # *-*-netbsdecoff* and *-*-netbsd*. For targets that recently
+ # switched to ELF, *-*-netbsd* would select the old
+ # object file format. This provides both forward
+ # compatibility and a consistent mechanism for selecting the
+ # object file format.
+ #
+ # Note: NetBSD doesn't particularly care about the vendor
+ # portion of the name. We always set it to "unknown".
+ sysctl="sysctl -n hw.machine_arch"
+ UNAME_MACHINE_ARCH=`(/sbin/$sysctl 2>/dev/null || \
+ /usr/sbin/$sysctl 2>/dev/null || echo unknown)`
+ case "${UNAME_MACHINE_ARCH}" in
+ armeb) machine=armeb-unknown ;;
+ arm*) machine=arm-unknown ;;
+ sh3el) machine=shl-unknown ;;
+ sh3eb) machine=sh-unknown ;;
+ sh5el) machine=sh5le-unknown ;;
+ *) machine=${UNAME_MACHINE_ARCH}-unknown ;;
+ esac
+ # The Operating System including object format, if it has switched
+ # to ELF recently, or will in the future.
+ case "${UNAME_MACHINE_ARCH}" in
+ arm*|i386|m68k|ns32k|sh3*|sparc|vax)
+ eval $set_cc_for_build
+ if echo __ELF__ | $CC_FOR_BUILD -E - 2>/dev/null \
+ | grep -q __ELF__
+ then
+ # Once all utilities can be ECOFF (netbsdecoff) or a.out (netbsdaout).
+ # Return netbsd for either. FIX?
+ os=netbsd
+ else
+ os=netbsdelf
+ fi
+ ;;
+ *)
+ os=netbsd
+ ;;
+ esac
+ # The OS release
+ # Debian GNU/NetBSD machines have a different userland, and
+ # thus, need a distinct triplet. However, they do not need
+ # kernel version information, so it can be replaced with a
+ # suitable tag, in the style of linux-gnu.
+ case "${UNAME_VERSION}" in
+ Debian*)
+ release='-gnu'
+ ;;
+ *)
+ release=`echo ${UNAME_RELEASE}|sed -e 's/[-_].*/\./'`
+ ;;
+ esac
+ # Since CPU_TYPE-MANUFACTURER-KERNEL-OPERATING_SYSTEM:
+ # contains redundant information, the shorter form:
+ # CPU_TYPE-MANUFACTURER-OPERATING_SYSTEM is used.
+ echo "${machine}-${os}${release}"
+ exit ;;
+ *:Bitrig:*:*)
+ UNAME_MACHINE_ARCH=`arch | sed 's/Bitrig.//'`
+ echo ${UNAME_MACHINE_ARCH}-unknown-bitrig${UNAME_RELEASE}
+ exit ;;
+ *:OpenBSD:*:*)
+ UNAME_MACHINE_ARCH=`arch | sed 's/OpenBSD.//'`
+ echo ${UNAME_MACHINE_ARCH}-unknown-openbsd${UNAME_RELEASE}
+ exit ;;
+ *:ekkoBSD:*:*)
+ echo ${UNAME_MACHINE}-unknown-ekkobsd${UNAME_RELEASE}
+ exit ;;
+ *:SolidBSD:*:*)
+ echo ${UNAME_MACHINE}-unknown-solidbsd${UNAME_RELEASE}
+ exit ;;
+ macppc:MirBSD:*:*)
+ echo powerpc-unknown-mirbsd${UNAME_RELEASE}
+ exit ;;
+ *:MirBSD:*:*)
+ echo ${UNAME_MACHINE}-unknown-mirbsd${UNAME_RELEASE}
+ exit ;;
+ alpha:OSF1:*:*)
+ case $UNAME_RELEASE in
+ *4.0)
+ UNAME_RELEASE=`/usr/sbin/sizer -v | awk '{print $3}'`
+ ;;
+ *5.*)
+ UNAME_RELEASE=`/usr/sbin/sizer -v | awk '{print $4}'`
+ ;;
+ esac
+ # According to Compaq, /usr/sbin/psrinfo has been available on
+ # OSF/1 and Tru64 systems produced since 1995. I hope that
+ # covers most systems running today. This code pipes the CPU
+ # types through head -n 1, so we only detect the type of CPU 0.
+ ALPHA_CPU_TYPE=`/usr/sbin/psrinfo -v | sed -n -e 's/^ The alpha \(.*\) processor.*$/\1/p' | head -n 1`
+ case "$ALPHA_CPU_TYPE" in
+ "EV4 (21064)")
+ UNAME_MACHINE="alpha" ;;
+ "EV4.5 (21064)")
+ UNAME_MACHINE="alpha" ;;
+ "LCA4 (21066/21068)")
+ UNAME_MACHINE="alpha" ;;
+ "EV5 (21164)")
+ UNAME_MACHINE="alphaev5" ;;
+ "EV5.6 (21164A)")
+ UNAME_MACHINE="alphaev56" ;;
+ "EV5.6 (21164PC)")
+ UNAME_MACHINE="alphapca56" ;;
+ "EV5.7 (21164PC)")
+ UNAME_MACHINE="alphapca57" ;;
+ "EV6 (21264)")
+ UNAME_MACHINE="alphaev6" ;;
+ "EV6.7 (21264A)")
+ UNAME_MACHINE="alphaev67" ;;
+ "EV6.8CB (21264C)")
+ UNAME_MACHINE="alphaev68" ;;
+ "EV6.8AL (21264B)")
+ UNAME_MACHINE="alphaev68" ;;
+ "EV6.8CX (21264D)")
+ UNAME_MACHINE="alphaev68" ;;
+ "EV6.9A (21264/EV69A)")
+ UNAME_MACHINE="alphaev69" ;;
+ "EV7 (21364)")
+ UNAME_MACHINE="alphaev7" ;;
+ "EV7.9 (21364A)")
+ UNAME_MACHINE="alphaev79" ;;
+ esac
+ # A Pn.n version is a patched version.
+ # A Vn.n version is a released version.
+ # A Tn.n version is a released field test version.
+ # A Xn.n version is an unreleased experimental baselevel.
+ # 1.2 uses "1.2" for uname -r.
+ echo ${UNAME_MACHINE}-dec-osf`echo ${UNAME_RELEASE} | sed -e 's/^[PVTX]//' | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz'`
+ # Reset EXIT trap before exiting to avoid spurious non-zero exit code.
+ exitcode=$?
+ trap '' 0
+ exit $exitcode ;;
+ Alpha\ *:Windows_NT*:*)
+ # How do we know it's Interix rather than the generic POSIX subsystem?
+ # Should we change UNAME_MACHINE based on the output of uname instead
+ # of the specific Alpha model?
+ echo alpha-pc-interix
+ exit ;;
+ 21064:Windows_NT:50:3)
+ echo alpha-dec-winnt3.5
+ exit ;;
+ Amiga*:UNIX_System_V:4.0:*)
+ echo m68k-unknown-sysv4
+ exit ;;
+ *:[Aa]miga[Oo][Ss]:*:*)
+ echo ${UNAME_MACHINE}-unknown-amigaos
+ exit ;;
+ *:[Mm]orph[Oo][Ss]:*:*)
+ echo ${UNAME_MACHINE}-unknown-morphos
+ exit ;;
+ *:OS/390:*:*)
+ echo i370-ibm-openedition
+ exit ;;
+ *:z/VM:*:*)
+ echo s390-ibm-zvmoe
+ exit ;;
+ *:OS400:*:*)
+ echo powerpc-ibm-os400
+ exit ;;
+ arm:RISC*:1.[012]*:*|arm:riscix:1.[012]*:*)
+ echo arm-acorn-riscix${UNAME_RELEASE}
+ exit ;;
+ arm*:riscos:*:*|arm*:RISCOS:*:*)
+ echo arm-unknown-riscos
+ exit ;;
+ SR2?01:HI-UX/MPP:*:* | SR8000:HI-UX/MPP:*:*)
+ echo hppa1.1-hitachi-hiuxmpp
+ exit ;;
+ Pyramid*:OSx*:*:* | MIS*:OSx*:*:* | MIS*:SMP_DC-OSx*:*:*)
+ # akee at wpdis03.wpafb.af.mil (Earle F. Ake) contributed MIS and NILE.
+ if test "`(/bin/universe) 2>/dev/null`" = att ; then
+ echo pyramid-pyramid-sysv3
+ else
+ echo pyramid-pyramid-bsd
+ fi
+ exit ;;
+ NILE*:*:*:dcosx)
+ echo pyramid-pyramid-svr4
+ exit ;;
+ DRS?6000:unix:4.0:6*)
+ echo sparc-icl-nx6
+ exit ;;
+ DRS?6000:UNIX_SV:4.2*:7* | DRS?6000:isis:4.2*:7*)
+ case `/usr/bin/uname -p` in
+ sparc) echo sparc-icl-nx7; exit ;;
+ esac ;;
+ s390x:SunOS:*:*)
+ echo ${UNAME_MACHINE}-ibm-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'`
+ exit ;;
+ sun4H:SunOS:5.*:*)
+ echo sparc-hal-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'`
+ exit ;;
+ sun4*:SunOS:5.*:* | tadpole*:SunOS:5.*:*)
+ echo sparc-sun-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'`
+ exit ;;
+ i86pc:AuroraUX:5.*:* | i86xen:AuroraUX:5.*:*)
+ echo i386-pc-auroraux${UNAME_RELEASE}
+ exit ;;
+ i86pc:SunOS:5.*:* | i86xen:SunOS:5.*:*)
+ eval $set_cc_for_build
+ SUN_ARCH="i386"
+ # If there is a compiler, see if it is configured for 64-bit objects.
+ # Note that the Sun cc does not turn __LP64__ into 1 like gcc does.
+ # This test works for both compilers.
+ if [ "$CC_FOR_BUILD" != 'no_compiler_found' ]; then
+ if (echo '#ifdef __amd64'; echo IS_64BIT_ARCH; echo '#endif') | \
+ (CCOPTS= $CC_FOR_BUILD -E - 2>/dev/null) | \
+ grep IS_64BIT_ARCH >/dev/null
+ then
+ SUN_ARCH="x86_64"
+ fi
+ fi
+ echo ${SUN_ARCH}-pc-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'`
+ exit ;;
+ sun4*:SunOS:6*:*)
+ # According to config.sub, this is the proper way to canonicalize
+ # SunOS6. Hard to guess exactly what SunOS6 will be like, but
+ # it's likely to be more like Solaris than SunOS4.
+ echo sparc-sun-solaris3`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'`
+ exit ;;
+ sun4*:SunOS:*:*)
+ case "`/usr/bin/arch -k`" in
+ Series*|S4*)
+ UNAME_RELEASE=`uname -v`
+ ;;
+ esac
+ # Japanese Language versions have a version number like `4.1.3-JL'.
+ echo sparc-sun-sunos`echo ${UNAME_RELEASE}|sed -e 's/-/_/'`
+ exit ;;
+ sun3*:SunOS:*:*)
+ echo m68k-sun-sunos${UNAME_RELEASE}
+ exit ;;
+ sun*:*:4.2BSD:*)
+ UNAME_RELEASE=`(sed 1q /etc/motd | awk '{print substr($5,1,3)}') 2>/dev/null`
+ test "x${UNAME_RELEASE}" = "x" && UNAME_RELEASE=3
+ case "`/bin/arch`" in
+ sun3)
+ echo m68k-sun-sunos${UNAME_RELEASE}
+ ;;
+ sun4)
+ echo sparc-sun-sunos${UNAME_RELEASE}
+ ;;
+ esac
+ exit ;;
+ aushp:SunOS:*:*)
+ echo sparc-auspex-sunos${UNAME_RELEASE}
+ exit ;;
+ # The situation for MiNT is a little confusing. The machine name
+ # can be virtually everything (everything which is not
+ # "atarist" or "atariste" at least should have a processor
+ # > m68000). The system name ranges from "MiNT" over "FreeMiNT"
+ # to the lowercase version "mint" (or "freemint"). Finally
+ # the system name "TOS" denotes a system which is actually not
+ # MiNT. But MiNT is downward compatible to TOS, so this should
+ # be no problem.
+ atarist[e]:*MiNT:*:* | atarist[e]:*mint:*:* | atarist[e]:*TOS:*:*)
+ echo m68k-atari-mint${UNAME_RELEASE}
+ exit ;;
+ atari*:*MiNT:*:* | atari*:*mint:*:* | atarist[e]:*TOS:*:*)
+ echo m68k-atari-mint${UNAME_RELEASE}
+ exit ;;
+ *falcon*:*MiNT:*:* | *falcon*:*mint:*:* | *falcon*:*TOS:*:*)
+ echo m68k-atari-mint${UNAME_RELEASE}
+ exit ;;
+ milan*:*MiNT:*:* | milan*:*mint:*:* | *milan*:*TOS:*:*)
+ echo m68k-milan-mint${UNAME_RELEASE}
+ exit ;;
+ hades*:*MiNT:*:* | hades*:*mint:*:* | *hades*:*TOS:*:*)
+ echo m68k-hades-mint${UNAME_RELEASE}
+ exit ;;
+ *:*MiNT:*:* | *:*mint:*:* | *:*TOS:*:*)
+ echo m68k-unknown-mint${UNAME_RELEASE}
+ exit ;;
+ m68k:machten:*:*)
+ echo m68k-apple-machten${UNAME_RELEASE}
+ exit ;;
+ powerpc:machten:*:*)
+ echo powerpc-apple-machten${UNAME_RELEASE}
+ exit ;;
+ RISC*:Mach:*:*)
+ echo mips-dec-mach_bsd4.3
+ exit ;;
+ RISC*:ULTRIX:*:*)
+ echo mips-dec-ultrix${UNAME_RELEASE}
+ exit ;;
+ VAX*:ULTRIX*:*:*)
+ echo vax-dec-ultrix${UNAME_RELEASE}
+ exit ;;
+ 2020:CLIX:*:* | 2430:CLIX:*:*)
+ echo clipper-intergraph-clix${UNAME_RELEASE}
+ exit ;;
+ mips:*:*:UMIPS | mips:*:*:RISCos)
+ eval $set_cc_for_build
+ sed 's/^ //' << EOF >$dummy.c
+#ifdef __cplusplus
+#include <stdio.h> /* for printf() prototype */
+ int main (int argc, char *argv[]) {
+#else
+ int main (argc, argv) int argc; char *argv[]; {
+#endif
+ #if defined (host_mips) && defined (MIPSEB)
+ #if defined (SYSTYPE_SYSV)
+ printf ("mips-mips-riscos%ssysv\n", argv[1]); exit (0);
+ #endif
+ #if defined (SYSTYPE_SVR4)
+ printf ("mips-mips-riscos%ssvr4\n", argv[1]); exit (0);
+ #endif
+ #if defined (SYSTYPE_BSD43) || defined(SYSTYPE_BSD)
+ printf ("mips-mips-riscos%sbsd\n", argv[1]); exit (0);
+ #endif
+ #endif
+ exit (-1);
+ }
+EOF
+ $CC_FOR_BUILD -o $dummy $dummy.c &&
+ dummyarg=`echo "${UNAME_RELEASE}" | sed -n 's/\([0-9]*\).*/\1/p'` &&
+ SYSTEM_NAME=`$dummy $dummyarg` &&
+ { echo "$SYSTEM_NAME"; exit; }
+ echo mips-mips-riscos${UNAME_RELEASE}
+ exit ;;
+ Motorola:PowerMAX_OS:*:*)
+ echo powerpc-motorola-powermax
+ exit ;;
+ Motorola:*:4.3:PL8-*)
+ echo powerpc-harris-powermax
+ exit ;;
+ Night_Hawk:*:*:PowerMAX_OS | Synergy:PowerMAX_OS:*:*)
+ echo powerpc-harris-powermax
+ exit ;;
+ Night_Hawk:Power_UNIX:*:*)
+ echo powerpc-harris-powerunix
+ exit ;;
+ m88k:CX/UX:7*:*)
+ echo m88k-harris-cxux7
+ exit ;;
+ m88k:*:4*:R4*)
+ echo m88k-motorola-sysv4
+ exit ;;
+ m88k:*:3*:R3*)
+ echo m88k-motorola-sysv3
+ exit ;;
+ AViiON:dgux:*:*)
+ # DG/UX returns AViiON for all architectures
+ UNAME_PROCESSOR=`/usr/bin/uname -p`
+ if [ $UNAME_PROCESSOR = mc88100 ] || [ $UNAME_PROCESSOR = mc88110 ]
+ then
+ if [ ${TARGET_BINARY_INTERFACE}x = m88kdguxelfx ] || \
+ [ ${TARGET_BINARY_INTERFACE}x = x ]
+ then
+ echo m88k-dg-dgux${UNAME_RELEASE}
+ else
+ echo m88k-dg-dguxbcs${UNAME_RELEASE}
+ fi
+ else
+ echo i586-dg-dgux${UNAME_RELEASE}
+ fi
+ exit ;;
+ M88*:DolphinOS:*:*) # DolphinOS (SVR3)
+ echo m88k-dolphin-sysv3
+ exit ;;
+ M88*:*:R3*:*)
+ # Delta 88k system running SVR3
+ echo m88k-motorola-sysv3
+ exit ;;
+ XD88*:*:*:*) # Tektronix XD88 system running UTekV (SVR3)
+ echo m88k-tektronix-sysv3
+ exit ;;
+ Tek43[0-9][0-9]:UTek:*:*) # Tektronix 4300 system running UTek (BSD)
+ echo m68k-tektronix-bsd
+ exit ;;
+ *:IRIX*:*:*)
+ echo mips-sgi-irix`echo ${UNAME_RELEASE}|sed -e 's/-/_/g'`
+ exit ;;
+ ????????:AIX?:[12].1:2) # AIX 2.2.1 or AIX 2.1.1 is RT/PC AIX.
+ echo romp-ibm-aix # uname -m gives an 8 hex-code CPU id
+ exit ;; # Note that: echo "'`uname -s`'" gives 'AIX '
+ i*86:AIX:*:*)
+ echo i386-ibm-aix
+ exit ;;
+ ia64:AIX:*:*)
+ if [ -x /usr/bin/oslevel ] ; then
+ IBM_REV=`/usr/bin/oslevel`
+ else
+ IBM_REV=${UNAME_VERSION}.${UNAME_RELEASE}
+ fi
+ echo ${UNAME_MACHINE}-ibm-aix${IBM_REV}
+ exit ;;
+ *:AIX:2:3)
+ if grep bos325 /usr/include/stdio.h >/dev/null 2>&1; then
+ eval $set_cc_for_build
+ sed 's/^ //' << EOF >$dummy.c
+ #include <sys/systemcfg.h>
+
+ main()
+ {
+ if (!__power_pc())
+ exit(1);
+ puts("powerpc-ibm-aix3.2.5");
+ exit(0);
+ }
+EOF
+ if $CC_FOR_BUILD -o $dummy $dummy.c && SYSTEM_NAME=`$dummy`
+ then
+ echo "$SYSTEM_NAME"
+ else
+ echo rs6000-ibm-aix3.2.5
+ fi
+ elif grep bos324 /usr/include/stdio.h >/dev/null 2>&1; then
+ echo rs6000-ibm-aix3.2.4
+ else
+ echo rs6000-ibm-aix3.2
+ fi
+ exit ;;
+ *:AIX:*:[4567])
+ IBM_CPU_ID=`/usr/sbin/lsdev -C -c processor -S available | sed 1q | awk '{ print $1 }'`
+ if /usr/sbin/lsattr -El ${IBM_CPU_ID} | grep ' POWER' >/dev/null 2>&1; then
+ IBM_ARCH=rs6000
+ else
+ IBM_ARCH=powerpc
+ fi
+ if [ -x /usr/bin/oslevel ] ; then
+ IBM_REV=`/usr/bin/oslevel`
+ else
+ IBM_REV=${UNAME_VERSION}.${UNAME_RELEASE}
+ fi
+ echo ${IBM_ARCH}-ibm-aix${IBM_REV}
+ exit ;;
+ *:AIX:*:*)
+ echo rs6000-ibm-aix
+ exit ;;
+ ibmrt:4.4BSD:*|romp-ibm:BSD:*)
+ echo romp-ibm-bsd4.4
+ exit ;;
+ ibmrt:*BSD:*|romp-ibm:BSD:*) # covers RT/PC BSD and
+ echo romp-ibm-bsd${UNAME_RELEASE} # 4.3 with uname added to
+ exit ;; # report: romp-ibm BSD 4.3
+ *:BOSX:*:*)
+ echo rs6000-bull-bosx
+ exit ;;
+ DPX/2?00:B.O.S.:*:*)
+ echo m68k-bull-sysv3
+ exit ;;
+ 9000/[34]??:4.3bsd:1.*:*)
+ echo m68k-hp-bsd
+ exit ;;
+ hp300:4.4BSD:*:* | 9000/[34]??:4.3bsd:2.*:*)
+ echo m68k-hp-bsd4.4
+ exit ;;
+ 9000/[34678]??:HP-UX:*:*)
+ HPUX_REV=`echo ${UNAME_RELEASE}|sed -e 's/[^.]*.[0B]*//'`
+ case "${UNAME_MACHINE}" in
+ 9000/31? ) HP_ARCH=m68000 ;;
+ 9000/[34]?? ) HP_ARCH=m68k ;;
+ 9000/[678][0-9][0-9])
+ if [ -x /usr/bin/getconf ]; then
+ sc_cpu_version=`/usr/bin/getconf SC_CPU_VERSION 2>/dev/null`
+ sc_kernel_bits=`/usr/bin/getconf SC_KERNEL_BITS 2>/dev/null`
+ case "${sc_cpu_version}" in
+ 523) HP_ARCH="hppa1.0" ;; # CPU_PA_RISC1_0
+ 528) HP_ARCH="hppa1.1" ;; # CPU_PA_RISC1_1
+ 532) # CPU_PA_RISC2_0
+ case "${sc_kernel_bits}" in
+ 32) HP_ARCH="hppa2.0n" ;;
+ 64) HP_ARCH="hppa2.0w" ;;
+ '') HP_ARCH="hppa2.0" ;; # HP-UX 10.20
+ esac ;;
+ esac
+ fi
+ if [ "${HP_ARCH}" = "" ]; then
+ eval $set_cc_for_build
+ sed 's/^ //' << EOF >$dummy.c
+
+ #define _HPUX_SOURCE
+ #include <stdlib.h>
+ #include <unistd.h>
+
+ int main ()
+ {
+ #if defined(_SC_KERNEL_BITS)
+ long bits = sysconf(_SC_KERNEL_BITS);
+ #endif
+ long cpu = sysconf (_SC_CPU_VERSION);
+
+ switch (cpu)
+ {
+ case CPU_PA_RISC1_0: puts ("hppa1.0"); break;
+ case CPU_PA_RISC1_1: puts ("hppa1.1"); break;
+ case CPU_PA_RISC2_0:
+ #if defined(_SC_KERNEL_BITS)
+ switch (bits)
+ {
+ case 64: puts ("hppa2.0w"); break;
+ case 32: puts ("hppa2.0n"); break;
+ default: puts ("hppa2.0"); break;
+ } break;
+ #else /* !defined(_SC_KERNEL_BITS) */
+ puts ("hppa2.0"); break;
+ #endif
+ default: puts ("hppa1.0"); break;
+ }
+ exit (0);
+ }
+EOF
+ (CCOPTS= $CC_FOR_BUILD -o $dummy $dummy.c 2>/dev/null) && HP_ARCH=`$dummy`
+ test -z "$HP_ARCH" && HP_ARCH=hppa
+ fi ;;
+ esac
+ if [ ${HP_ARCH} = "hppa2.0w" ]
+ then
+ eval $set_cc_for_build
+
+ # hppa2.0w-hp-hpux* has a 64-bit kernel and a compiler generating
+ # 32-bit code. hppa64-hp-hpux* has the same kernel and a compiler
+ # generating 64-bit code. GNU and HP use different nomenclature:
+ #
+ # $ CC_FOR_BUILD=cc ./config.guess
+ # => hppa2.0w-hp-hpux11.23
+ # $ CC_FOR_BUILD="cc +DA2.0w" ./config.guess
+ # => hppa64-hp-hpux11.23
+
+ if echo __LP64__ | (CCOPTS= $CC_FOR_BUILD -E - 2>/dev/null) |
+ grep -q __LP64__
+ then
+ HP_ARCH="hppa2.0w"
+ else
+ HP_ARCH="hppa64"
+ fi
+ fi
+ echo ${HP_ARCH}-hp-hpux${HPUX_REV}
+ exit ;;
+ ia64:HP-UX:*:*)
+ HPUX_REV=`echo ${UNAME_RELEASE}|sed -e 's/[^.]*.[0B]*//'`
+ echo ia64-hp-hpux${HPUX_REV}
+ exit ;;
+ 3050*:HI-UX:*:*)
+ eval $set_cc_for_build
+ sed 's/^ //' << EOF >$dummy.c
+ #include <unistd.h>
+ int
+ main ()
+ {
+ long cpu = sysconf (_SC_CPU_VERSION);
+ /* The order matters, because CPU_IS_HP_MC68K erroneously returns
+ true for CPU_PA_RISC1_0. CPU_IS_PA_RISC returns correct
+ results, however. */
+ if (CPU_IS_PA_RISC (cpu))
+ {
+ switch (cpu)
+ {
+ case CPU_PA_RISC1_0: puts ("hppa1.0-hitachi-hiuxwe2"); break;
+ case CPU_PA_RISC1_1: puts ("hppa1.1-hitachi-hiuxwe2"); break;
+ case CPU_PA_RISC2_0: puts ("hppa2.0-hitachi-hiuxwe2"); break;
+ default: puts ("hppa-hitachi-hiuxwe2"); break;
+ }
+ }
+ else if (CPU_IS_HP_MC68K (cpu))
+ puts ("m68k-hitachi-hiuxwe2");
+ else puts ("unknown-hitachi-hiuxwe2");
+ exit (0);
+ }
+EOF
+ $CC_FOR_BUILD -o $dummy $dummy.c && SYSTEM_NAME=`$dummy` &&
+ { echo "$SYSTEM_NAME"; exit; }
+ echo unknown-hitachi-hiuxwe2
+ exit ;;
+ 9000/7??:4.3bsd:*:* | 9000/8?[79]:4.3bsd:*:* )
+ echo hppa1.1-hp-bsd
+ exit ;;
+ 9000/8??:4.3bsd:*:*)
+ echo hppa1.0-hp-bsd
+ exit ;;
+ *9??*:MPE/iX:*:* | *3000*:MPE/iX:*:*)
+ echo hppa1.0-hp-mpeix
+ exit ;;
+ hp7??:OSF1:*:* | hp8?[79]:OSF1:*:* )
+ echo hppa1.1-hp-osf
+ exit ;;
+ hp8??:OSF1:*:*)
+ echo hppa1.0-hp-osf
+ exit ;;
+ i*86:OSF1:*:*)
+ if [ -x /usr/sbin/sysversion ] ; then
+ echo ${UNAME_MACHINE}-unknown-osf1mk
+ else
+ echo ${UNAME_MACHINE}-unknown-osf1
+ fi
+ exit ;;
+ parisc*:Lites*:*:*)
+ echo hppa1.1-hp-lites
+ exit ;;
+ C1*:ConvexOS:*:* | convex:ConvexOS:C1*:*)
+ echo c1-convex-bsd
+ exit ;;
+ C2*:ConvexOS:*:* | convex:ConvexOS:C2*:*)
+ if getsysinfo -f scalar_acc
+ then echo c32-convex-bsd
+ else echo c2-convex-bsd
+ fi
+ exit ;;
+ C34*:ConvexOS:*:* | convex:ConvexOS:C34*:*)
+ echo c34-convex-bsd
+ exit ;;
+ C38*:ConvexOS:*:* | convex:ConvexOS:C38*:*)
+ echo c38-convex-bsd
+ exit ;;
+ C4*:ConvexOS:*:* | convex:ConvexOS:C4*:*)
+ echo c4-convex-bsd
+ exit ;;
+ CRAY*Y-MP:*:*:*)
+ echo ymp-cray-unicos${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/'
+ exit ;;
+ CRAY*[A-Z]90:*:*:*)
+ echo ${UNAME_MACHINE}-cray-unicos${UNAME_RELEASE} \
+ | sed -e 's/CRAY.*\([A-Z]90\)/\1/' \
+ -e y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/ \
+ -e 's/\.[^.]*$/.X/'
+ exit ;;
+ CRAY*TS:*:*:*)
+ echo t90-cray-unicos${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/'
+ exit ;;
+ CRAY*T3E:*:*:*)
+ echo alphaev5-cray-unicosmk${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/'
+ exit ;;
+ CRAY*SV1:*:*:*)
+ echo sv1-cray-unicos${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/'
+ exit ;;
+ *:UNICOS/mp:*:*)
+ echo craynv-cray-unicosmp${UNAME_RELEASE} | sed -e 's/\.[^.]*$/.X/'
+ exit ;;
+ F30[01]:UNIX_System_V:*:* | F700:UNIX_System_V:*:*)
+ FUJITSU_PROC=`uname -m | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz'`
+ FUJITSU_SYS=`uname -p | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz' | sed -e 's/\///'`
+ FUJITSU_REL=`echo ${UNAME_RELEASE} | sed -e 's/ /_/'`
+ echo "${FUJITSU_PROC}-fujitsu-${FUJITSU_SYS}${FUJITSU_REL}"
+ exit ;;
+ 5000:UNIX_System_V:4.*:*)
+ FUJITSU_SYS=`uname -p | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz' | sed -e 's/\///'`
+ FUJITSU_REL=`echo ${UNAME_RELEASE} | tr 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' 'abcdefghijklmnopqrstuvwxyz' | sed -e 's/ /_/'`
+ echo "sparc-fujitsu-${FUJITSU_SYS}${FUJITSU_REL}"
+ exit ;;
+ i*86:BSD/386:*:* | i*86:BSD/OS:*:* | *:Ascend\ Embedded/OS:*:*)
+ echo ${UNAME_MACHINE}-pc-bsdi${UNAME_RELEASE}
+ exit ;;
+ sparc*:BSD/OS:*:*)
+ echo sparc-unknown-bsdi${UNAME_RELEASE}
+ exit ;;
+ *:BSD/OS:*:*)
+ echo ${UNAME_MACHINE}-unknown-bsdi${UNAME_RELEASE}
+ exit ;;
+ *:FreeBSD:*:*)
+ UNAME_PROCESSOR=`/usr/bin/uname -p`
+ case ${UNAME_PROCESSOR} in
+ amd64)
+ echo x86_64-unknown-freebsd`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'` ;;
+ *)
+ echo ${UNAME_PROCESSOR}-unknown-freebsd`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'` ;;
+ esac
+ exit ;;
+ i*:CYGWIN*:*)
+ echo ${UNAME_MACHINE}-pc-cygwin
+ exit ;;
+ *:MINGW64*:*)
+ echo ${UNAME_MACHINE}-pc-mingw64
+ exit ;;
+ *:MINGW*:*)
+ echo ${UNAME_MACHINE}-pc-mingw32
+ exit ;;
+ i*:MSYS*:*)
+ echo ${UNAME_MACHINE}-pc-msys
+ exit ;;
+ i*:windows32*:*)
+ # uname -m includes "-pc" on this system.
+ echo ${UNAME_MACHINE}-mingw32
+ exit ;;
+ i*:PW*:*)
+ echo ${UNAME_MACHINE}-pc-pw32
+ exit ;;
+ *:Interix*:*)
+ case ${UNAME_MACHINE} in
+ x86)
+ echo i586-pc-interix${UNAME_RELEASE}
+ exit ;;
+ authenticamd | genuineintel | EM64T)
+ echo x86_64-unknown-interix${UNAME_RELEASE}
+ exit ;;
+ IA64)
+ echo ia64-unknown-interix${UNAME_RELEASE}
+ exit ;;
+ esac ;;
+ [345]86:Windows_95:* | [345]86:Windows_98:* | [345]86:Windows_NT:*)
+ echo i${UNAME_MACHINE}-pc-mks
+ exit ;;
+ 8664:Windows_NT:*)
+ echo x86_64-pc-mks
+ exit ;;
+ i*:Windows_NT*:* | Pentium*:Windows_NT*:*)
+ # How do we know it's Interix rather than the generic POSIX subsystem?
+ # It also conflicts with pre-2.0 versions of AT&T UWIN. Should we
+ # UNAME_MACHINE based on the output of uname instead of i386?
+ echo i586-pc-interix
+ exit ;;
+ i*:UWIN*:*)
+ echo ${UNAME_MACHINE}-pc-uwin
+ exit ;;
+ amd64:CYGWIN*:*:* | x86_64:CYGWIN*:*:*)
+ echo x86_64-unknown-cygwin
+ exit ;;
+ p*:CYGWIN*:*)
+ echo powerpcle-unknown-cygwin
+ exit ;;
+ prep*:SunOS:5.*:*)
+ echo powerpcle-unknown-solaris2`echo ${UNAME_RELEASE}|sed -e 's/[^.]*//'`
+ exit ;;
+ *:GNU:*:*)
+ # the GNU system
+ echo `echo ${UNAME_MACHINE}|sed -e 's,[-/].*$,,'`-unknown-${LIBC}`echo ${UNAME_RELEASE}|sed -e 's,/.*$,,'`
+ exit ;;
+ *:GNU/*:*:*)
+ # other systems with GNU libc and userland
+ echo ${UNAME_MACHINE}-unknown-`echo ${UNAME_SYSTEM} | sed 's,^[^/]*/,,' | tr '[A-Z]' '[a-z]'``echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'`-${LIBC}
+ exit ;;
+ i*86:Minix:*:*)
+ echo ${UNAME_MACHINE}-pc-minix
+ exit ;;
+ aarch64:Linux:*:*)
+ echo ${UNAME_MACHINE}-unknown-linux-${LIBC}
+ exit ;;
+ aarch64_be:Linux:*:*)
+ UNAME_MACHINE=aarch64_be
+ echo ${UNAME_MACHINE}-unknown-linux-${LIBC}
+ exit ;;
+ alpha:Linux:*:*)
+ case `sed -n '/^cpu model/s/^.*: \(.*\)/\1/p' < /proc/cpuinfo` in
+ EV5) UNAME_MACHINE=alphaev5 ;;
+ EV56) UNAME_MACHINE=alphaev56 ;;
+ PCA56) UNAME_MACHINE=alphapca56 ;;
+ PCA57) UNAME_MACHINE=alphapca56 ;;
+ EV6) UNAME_MACHINE=alphaev6 ;;
+ EV67) UNAME_MACHINE=alphaev67 ;;
+ EV68*) UNAME_MACHINE=alphaev68 ;;
+ esac
+ objdump --private-headers /bin/sh | grep -q ld.so.1
+ if test "$?" = 0 ; then LIBC="gnulibc1" ; fi
+ echo ${UNAME_MACHINE}-unknown-linux-${LIBC}
+ exit ;;
+ arc:Linux:*:* | arceb:Linux:*:*)
+ echo ${UNAME_MACHINE}-unknown-linux-${LIBC}
+ exit ;;
+ arm*:Linux:*:*)
+ eval $set_cc_for_build
+ if echo __ARM_EABI__ | $CC_FOR_BUILD -E - 2>/dev/null \
+ | grep -q __ARM_EABI__
+ then
+ echo ${UNAME_MACHINE}-unknown-linux-${LIBC}
+ else
+ if echo __ARM_PCS_VFP | $CC_FOR_BUILD -E - 2>/dev/null \
+ | grep -q __ARM_PCS_VFP
+ then
+ echo ${UNAME_MACHINE}-unknown-linux-${LIBC}eabi
+ else
+ echo ${UNAME_MACHINE}-unknown-linux-${LIBC}eabihf
+ fi
+ fi
+ exit ;;
+ avr32*:Linux:*:*)
+ echo ${UNAME_MACHINE}-unknown-linux-${LIBC}
+ exit ;;
+ cris:Linux:*:*)
+ echo ${UNAME_MACHINE}-axis-linux-${LIBC}
+ exit ;;
+ crisv32:Linux:*:*)
+ echo ${UNAME_MACHINE}-axis-linux-${LIBC}
+ exit ;;
+ frv:Linux:*:*)
+ echo ${UNAME_MACHINE}-unknown-linux-${LIBC}
+ exit ;;
+ hexagon:Linux:*:*)
+ echo ${UNAME_MACHINE}-unknown-linux-${LIBC}
+ exit ;;
+ i*86:Linux:*:*)
+ echo ${UNAME_MACHINE}-pc-linux-${LIBC}
+ exit ;;
+ ia64:Linux:*:*)
+ echo ${UNAME_MACHINE}-unknown-linux-${LIBC}
+ exit ;;
+ m32r*:Linux:*:*)
+ echo ${UNAME_MACHINE}-unknown-linux-${LIBC}
+ exit ;;
+ m68*:Linux:*:*)
+ echo ${UNAME_MACHINE}-unknown-linux-${LIBC}
+ exit ;;
+ mips:Linux:*:* | mips64:Linux:*:*)
+ eval $set_cc_for_build
+ sed 's/^ //' << EOF >$dummy.c
+ #undef CPU
+ #undef ${UNAME_MACHINE}
+ #undef ${UNAME_MACHINE}el
+ #if defined(__MIPSEL__) || defined(__MIPSEL) || defined(_MIPSEL) || defined(MIPSEL)
+ CPU=${UNAME_MACHINE}el
+ #else
+ #if defined(__MIPSEB__) || defined(__MIPSEB) || defined(_MIPSEB) || defined(MIPSEB)
+ CPU=${UNAME_MACHINE}
+ #else
+ CPU=
+ #endif
+ #endif
+EOF
+ eval `$CC_FOR_BUILD -E $dummy.c 2>/dev/null | grep '^CPU'`
+ test x"${CPU}" != x && { echo "${CPU}-unknown-linux-${LIBC}"; exit; }
+ ;;
+ or1k:Linux:*:*)
+ echo ${UNAME_MACHINE}-unknown-linux-${LIBC}
+ exit ;;
+ or32:Linux:*:*)
+ echo ${UNAME_MACHINE}-unknown-linux-${LIBC}
+ exit ;;
+ padre:Linux:*:*)
+ echo sparc-unknown-linux-${LIBC}
+ exit ;;
+ parisc64:Linux:*:* | hppa64:Linux:*:*)
+ echo hppa64-unknown-linux-${LIBC}
+ exit ;;
+ parisc:Linux:*:* | hppa:Linux:*:*)
+ # Look for CPU level
+ case `grep '^cpu[^a-z]*:' /proc/cpuinfo 2>/dev/null | cut -d' ' -f2` in
+ PA7*) echo hppa1.1-unknown-linux-${LIBC} ;;
+ PA8*) echo hppa2.0-unknown-linux-${LIBC} ;;
+ *) echo hppa-unknown-linux-${LIBC} ;;
+ esac
+ exit ;;
+ ppc64:Linux:*:*)
+ echo powerpc64-unknown-linux-${LIBC}
+ exit ;;
+ ppc:Linux:*:*)
+ echo powerpc-unknown-linux-${LIBC}
+ exit ;;
+ ppc64le:Linux:*:*)
+ echo powerpc64le-unknown-linux-${LIBC}
+ exit ;;
+ ppcle:Linux:*:*)
+ echo powerpcle-unknown-linux-${LIBC}
+ exit ;;
+ s390:Linux:*:* | s390x:Linux:*:*)
+ echo ${UNAME_MACHINE}-ibm-linux-${LIBC}
+ exit ;;
+ sh64*:Linux:*:*)
+ echo ${UNAME_MACHINE}-unknown-linux-${LIBC}
+ exit ;;
+ sh*:Linux:*:*)
+ echo ${UNAME_MACHINE}-unknown-linux-${LIBC}
+ exit ;;
+ sparc:Linux:*:* | sparc64:Linux:*:*)
+ echo ${UNAME_MACHINE}-unknown-linux-${LIBC}
+ exit ;;
+ tile*:Linux:*:*)
+ echo ${UNAME_MACHINE}-unknown-linux-${LIBC}
+ exit ;;
+ vax:Linux:*:*)
+ echo ${UNAME_MACHINE}-dec-linux-${LIBC}
+ exit ;;
+ x86_64:Linux:*:*)
+ echo ${UNAME_MACHINE}-unknown-linux-${LIBC}
+ exit ;;
+ xtensa*:Linux:*:*)
+ echo ${UNAME_MACHINE}-unknown-linux-${LIBC}
+ exit ;;
+ i*86:DYNIX/ptx:4*:*)
+ # ptx 4.0 does uname -s correctly, with DYNIX/ptx in there.
+ # earlier versions are messed up and put the nodename in both
+ # sysname and nodename.
+ echo i386-sequent-sysv4
+ exit ;;
+ i*86:UNIX_SV:4.2MP:2.*)
+ # Unixware is an offshoot of SVR4, but it has its own version
+ # number series starting with 2...
+ # I am not positive that other SVR4 systems won't match this,
+ # I just have to hope. -- rms.
+ # Use sysv4.2uw... so that sysv4* matches it.
+ echo ${UNAME_MACHINE}-pc-sysv4.2uw${UNAME_VERSION}
+ exit ;;
+ i*86:OS/2:*:*)
+ # If we were able to find `uname', then EMX Unix compatibility
+ # is probably installed.
+ echo ${UNAME_MACHINE}-pc-os2-emx
+ exit ;;
+ i*86:XTS-300:*:STOP)
+ echo ${UNAME_MACHINE}-unknown-stop
+ exit ;;
+ i*86:atheos:*:*)
+ echo ${UNAME_MACHINE}-unknown-atheos
+ exit ;;
+ i*86:syllable:*:*)
+ echo ${UNAME_MACHINE}-pc-syllable
+ exit ;;
+ i*86:LynxOS:2.*:* | i*86:LynxOS:3.[01]*:* | i*86:LynxOS:4.[02]*:*)
+ echo i386-unknown-lynxos${UNAME_RELEASE}
+ exit ;;
+ i*86:*DOS:*:*)
+ echo ${UNAME_MACHINE}-pc-msdosdjgpp
+ exit ;;
+ i*86:*:4.*:* | i*86:SYSTEM_V:4.*:*)
+ UNAME_REL=`echo ${UNAME_RELEASE} | sed 's/\/MP$//'`
+ if grep Novell /usr/include/link.h >/dev/null 2>/dev/null; then
+ echo ${UNAME_MACHINE}-univel-sysv${UNAME_REL}
+ else
+ echo ${UNAME_MACHINE}-pc-sysv${UNAME_REL}
+ fi
+ exit ;;
+ i*86:*:5:[678]*)
+ # UnixWare 7.x, OpenUNIX and OpenServer 6.
+ case `/bin/uname -X | grep "^Machine"` in
+ *486*) UNAME_MACHINE=i486 ;;
+ *Pentium) UNAME_MACHINE=i586 ;;
+ *Pent*|*Celeron) UNAME_MACHINE=i686 ;;
+ esac
+ echo ${UNAME_MACHINE}-unknown-sysv${UNAME_RELEASE}${UNAME_SYSTEM}${UNAME_VERSION}
+ exit ;;
+ i*86:*:3.2:*)
+ if test -f /usr/options/cb.name; then
+ UNAME_REL=`sed -n 's/.*Version //p' </usr/options/cb.name`
+ echo ${UNAME_MACHINE}-pc-isc$UNAME_REL
+ elif /bin/uname -X 2>/dev/null >/dev/null ; then
+ UNAME_REL=`(/bin/uname -X|grep Release|sed -e 's/.*= //')`
+ (/bin/uname -X|grep i80486 >/dev/null) && UNAME_MACHINE=i486
+ (/bin/uname -X|grep '^Machine.*Pentium' >/dev/null) \
+ && UNAME_MACHINE=i586
+ (/bin/uname -X|grep '^Machine.*Pent *II' >/dev/null) \
+ && UNAME_MACHINE=i686
+ (/bin/uname -X|grep '^Machine.*Pentium Pro' >/dev/null) \
+ && UNAME_MACHINE=i686
+ echo ${UNAME_MACHINE}-pc-sco$UNAME_REL
+ else
+ echo ${UNAME_MACHINE}-pc-sysv32
+ fi
+ exit ;;
+ pc:*:*:*)
+ # Left here for compatibility:
+ # uname -m prints for DJGPP always 'pc', but it prints nothing about
+ # the processor, so we play safe by assuming i586.
+ # Note: whatever this is, it MUST be the same as what config.sub
+ # prints for the "djgpp" host, or else GDB configury will decide that
+ # this is a cross-build.
+ echo i586-pc-msdosdjgpp
+ exit ;;
+ Intel:Mach:3*:*)
+ echo i386-pc-mach3
+ exit ;;
+ paragon:*:*:*)
+ echo i860-intel-osf1
+ exit ;;
+ i860:*:4.*:*) # i860-SVR4
+ if grep Stardent /usr/include/sys/uadmin.h >/dev/null 2>&1 ; then
+ echo i860-stardent-sysv${UNAME_RELEASE} # Stardent Vistra i860-SVR4
+ else # Add other i860-SVR4 vendors below as they are discovered.
+ echo i860-unknown-sysv${UNAME_RELEASE} # Unknown i860-SVR4
+ fi
+ exit ;;
+ mini*:CTIX:SYS*5:*)
+ # "miniframe"
+ echo m68010-convergent-sysv
+ exit ;;
+ mc68k:UNIX:SYSTEM5:3.51m)
+ echo m68k-convergent-sysv
+ exit ;;
+ M680?0:D-NIX:5.3:*)
+ echo m68k-diab-dnix
+ exit ;;
+ M68*:*:R3V[5678]*:*)
+ test -r /sysV68 && { echo 'm68k-motorola-sysv'; exit; } ;;
+ 3[345]??:*:4.0:3.0 | 3[34]??A:*:4.0:3.0 | 3[34]??,*:*:4.0:3.0 | 3[34]??/*:*:4.0:3.0 | 4400:*:4.0:3.0 | 4850:*:4.0:3.0 | SKA40:*:4.0:3.0 | SDS2:*:4.0:3.0 | SHG2:*:4.0:3.0 | S7501*:*:4.0:3.0)
+ OS_REL=''
+ test -r /etc/.relid \
+ && OS_REL=.`sed -n 's/[^ ]* [^ ]* \([0-9][0-9]\).*/\1/p' < /etc/.relid`
+ /bin/uname -p 2>/dev/null | grep 86 >/dev/null \
+ && { echo i486-ncr-sysv4.3${OS_REL}; exit; }
+ /bin/uname -p 2>/dev/null | /bin/grep entium >/dev/null \
+ && { echo i586-ncr-sysv4.3${OS_REL}; exit; } ;;
+ 3[34]??:*:4.0:* | 3[34]??,*:*:4.0:*)
+ /bin/uname -p 2>/dev/null | grep 86 >/dev/null \
+ && { echo i486-ncr-sysv4; exit; } ;;
+ NCR*:*:4.2:* | MPRAS*:*:4.2:*)
+ OS_REL='.3'
+ test -r /etc/.relid \
+ && OS_REL=.`sed -n 's/[^ ]* [^ ]* \([0-9][0-9]\).*/\1/p' < /etc/.relid`
+ /bin/uname -p 2>/dev/null | grep 86 >/dev/null \
+ && { echo i486-ncr-sysv4.3${OS_REL}; exit; }
+ /bin/uname -p 2>/dev/null | /bin/grep entium >/dev/null \
+ && { echo i586-ncr-sysv4.3${OS_REL}; exit; }
+ /bin/uname -p 2>/dev/null | /bin/grep pteron >/dev/null \
+ && { echo i586-ncr-sysv4.3${OS_REL}; exit; } ;;
+ m68*:LynxOS:2.*:* | m68*:LynxOS:3.0*:*)
+ echo m68k-unknown-lynxos${UNAME_RELEASE}
+ exit ;;
+ mc68030:UNIX_System_V:4.*:*)
+ echo m68k-atari-sysv4
+ exit ;;
+ TSUNAMI:LynxOS:2.*:*)
+ echo sparc-unknown-lynxos${UNAME_RELEASE}
+ exit ;;
+ rs6000:LynxOS:2.*:*)
+ echo rs6000-unknown-lynxos${UNAME_RELEASE}
+ exit ;;
+ PowerPC:LynxOS:2.*:* | PowerPC:LynxOS:3.[01]*:* | PowerPC:LynxOS:4.[02]*:*)
+ echo powerpc-unknown-lynxos${UNAME_RELEASE}
+ exit ;;
+ SM[BE]S:UNIX_SV:*:*)
+ echo mips-dde-sysv${UNAME_RELEASE}
+ exit ;;
+ RM*:ReliantUNIX-*:*:*)
+ echo mips-sni-sysv4
+ exit ;;
+ RM*:SINIX-*:*:*)
+ echo mips-sni-sysv4
+ exit ;;
+ *:SINIX-*:*:*)
+ if uname -p 2>/dev/null >/dev/null ; then
+ UNAME_MACHINE=`(uname -p) 2>/dev/null`
+ echo ${UNAME_MACHINE}-sni-sysv4
+ else
+ echo ns32k-sni-sysv
+ fi
+ exit ;;
+ PENTIUM:*:4.0*:*) # Unisys `ClearPath HMP IX 4000' SVR4/MP effort
+ # says <Richard.M.Bartel at ccMail.Census.GOV>
+ echo i586-unisys-sysv4
+ exit ;;
+ *:UNIX_System_V:4*:FTX*)
+ # From Gerald Hewes <hewes at openmarket.com>.
+ # How about differentiating between stratus architectures? -djm
+ echo hppa1.1-stratus-sysv4
+ exit ;;
+ *:*:*:FTX*)
+ # From seanf at swdc.stratus.com.
+ echo i860-stratus-sysv4
+ exit ;;
+ i*86:VOS:*:*)
+ # From Paul.Green at stratus.com.
+ echo ${UNAME_MACHINE}-stratus-vos
+ exit ;;
+ *:VOS:*:*)
+ # From Paul.Green at stratus.com.
+ echo hppa1.1-stratus-vos
+ exit ;;
+ mc68*:A/UX:*:*)
+ echo m68k-apple-aux${UNAME_RELEASE}
+ exit ;;
+ news*:NEWS-OS:6*:*)
+ echo mips-sony-newsos6
+ exit ;;
+ R[34]000:*System_V*:*:* | R4000:UNIX_SYSV:*:* | R*000:UNIX_SV:*:*)
+ if [ -d /usr/nec ]; then
+ echo mips-nec-sysv${UNAME_RELEASE}
+ else
+ echo mips-unknown-sysv${UNAME_RELEASE}
+ fi
+ exit ;;
+ BeBox:BeOS:*:*) # BeOS running on hardware made by Be, PPC only.
+ echo powerpc-be-beos
+ exit ;;
+ BeMac:BeOS:*:*) # BeOS running on Mac or Mac clone, PPC only.
+ echo powerpc-apple-beos
+ exit ;;
+ BePC:BeOS:*:*) # BeOS running on Intel PC compatible.
+ echo i586-pc-beos
+ exit ;;
+ BePC:Haiku:*:*) # Haiku running on Intel PC compatible.
+ echo i586-pc-haiku
+ exit ;;
+ x86_64:Haiku:*:*)
+ echo x86_64-unknown-haiku
+ exit ;;
+ SX-4:SUPER-UX:*:*)
+ echo sx4-nec-superux${UNAME_RELEASE}
+ exit ;;
+ SX-5:SUPER-UX:*:*)
+ echo sx5-nec-superux${UNAME_RELEASE}
+ exit ;;
+ SX-6:SUPER-UX:*:*)
+ echo sx6-nec-superux${UNAME_RELEASE}
+ exit ;;
+ SX-7:SUPER-UX:*:*)
+ echo sx7-nec-superux${UNAME_RELEASE}
+ exit ;;
+ SX-8:SUPER-UX:*:*)
+ echo sx8-nec-superux${UNAME_RELEASE}
+ exit ;;
+ SX-8R:SUPER-UX:*:*)
+ echo sx8r-nec-superux${UNAME_RELEASE}
+ exit ;;
+ Power*:Rhapsody:*:*)
+ echo powerpc-apple-rhapsody${UNAME_RELEASE}
+ exit ;;
+ *:Rhapsody:*:*)
+ echo ${UNAME_MACHINE}-apple-rhapsody${UNAME_RELEASE}
+ exit ;;
+ *:Darwin:*:*)
+ UNAME_PROCESSOR=`uname -p` || UNAME_PROCESSOR=unknown
+ eval $set_cc_for_build
+ if test "$UNAME_PROCESSOR" = unknown ; then
+ UNAME_PROCESSOR=powerpc
+ fi
+ if test `echo "$UNAME_RELEASE" | sed -e 's/\..*//'` -le 10 ; then
+ if [ "$CC_FOR_BUILD" != 'no_compiler_found' ]; then
+ if (echo '#ifdef __LP64__'; echo IS_64BIT_ARCH; echo '#endif') | \
+ (CCOPTS= $CC_FOR_BUILD -E - 2>/dev/null) | \
+ grep IS_64BIT_ARCH >/dev/null
+ then
+ case $UNAME_PROCESSOR in
+ i386) UNAME_PROCESSOR=x86_64 ;;
+ powerpc) UNAME_PROCESSOR=powerpc64 ;;
+ esac
+ fi
+ fi
+ elif test "$UNAME_PROCESSOR" = i386 ; then
+ # Avoid executing cc on OS X 10.9, as it ships with a stub
+ # that puts up a graphical alert prompting to install
+ # developer tools. Any system running Mac OS X 10.7 or
+ # later (Darwin 11 and later) is required to have a 64-bit
+ # processor. This is not true of the ARM version of Darwin
+ # that Apple uses in portable devices.
+ UNAME_PROCESSOR=x86_64
+ fi
+ echo ${UNAME_PROCESSOR}-apple-darwin${UNAME_RELEASE}
+ exit ;;
+ *:procnto*:*:* | *:QNX:[0123456789]*:*)
+ UNAME_PROCESSOR=`uname -p`
+ if test "$UNAME_PROCESSOR" = "x86"; then
+ UNAME_PROCESSOR=i386
+ UNAME_MACHINE=pc
+ fi
+ echo ${UNAME_PROCESSOR}-${UNAME_MACHINE}-nto-qnx${UNAME_RELEASE}
+ exit ;;
+ *:QNX:*:4*)
+ echo i386-pc-qnx
+ exit ;;
+ NEO-?:NONSTOP_KERNEL:*:*)
+ echo neo-tandem-nsk${UNAME_RELEASE}
+ exit ;;
+ NSE-*:NONSTOP_KERNEL:*:*)
+ echo nse-tandem-nsk${UNAME_RELEASE}
+ exit ;;
+ NSR-?:NONSTOP_KERNEL:*:*)
+ echo nsr-tandem-nsk${UNAME_RELEASE}
+ exit ;;
+ *:NonStop-UX:*:*)
+ echo mips-compaq-nonstopux
+ exit ;;
+ BS2000:POSIX*:*:*)
+ echo bs2000-siemens-sysv
+ exit ;;
+ DS/*:UNIX_System_V:*:*)
+ echo ${UNAME_MACHINE}-${UNAME_SYSTEM}-${UNAME_RELEASE}
+ exit ;;
+ *:Plan9:*:*)
+ # "uname -m" is not consistent, so use $cputype instead. 386
+ # is converted to i386 for consistency with other x86
+ # operating systems.
+ if test "$cputype" = "386"; then
+ UNAME_MACHINE=i386
+ else
+ UNAME_MACHINE="$cputype"
+ fi
+ echo ${UNAME_MACHINE}-unknown-plan9
+ exit ;;
+ *:TOPS-10:*:*)
+ echo pdp10-unknown-tops10
+ exit ;;
+ *:TENEX:*:*)
+ echo pdp10-unknown-tenex
+ exit ;;
+ KS10:TOPS-20:*:* | KL10:TOPS-20:*:* | TYPE4:TOPS-20:*:*)
+ echo pdp10-dec-tops20
+ exit ;;
+ XKL-1:TOPS-20:*:* | TYPE5:TOPS-20:*:*)
+ echo pdp10-xkl-tops20
+ exit ;;
+ *:TOPS-20:*:*)
+ echo pdp10-unknown-tops20
+ exit ;;
+ *:ITS:*:*)
+ echo pdp10-unknown-its
+ exit ;;
+ SEI:*:*:SEIUX)
+ echo mips-sei-seiux${UNAME_RELEASE}
+ exit ;;
+ *:DragonFly:*:*)
+ echo ${UNAME_MACHINE}-unknown-dragonfly`echo ${UNAME_RELEASE}|sed -e 's/[-(].*//'`
+ exit ;;
+ *:*VMS:*:*)
+ UNAME_MACHINE=`(uname -p) 2>/dev/null`
+ case "${UNAME_MACHINE}" in
+ A*) echo alpha-dec-vms ; exit ;;
+ I*) echo ia64-dec-vms ; exit ;;
+ V*) echo vax-dec-vms ; exit ;;
+ esac ;;
+ *:XENIX:*:SysV)
+ echo i386-pc-xenix
+ exit ;;
+ i*86:skyos:*:*)
+ echo ${UNAME_MACHINE}-pc-skyos`echo ${UNAME_RELEASE}` | sed -e 's/ .*$//'
+ exit ;;
+ i*86:rdos:*:*)
+ echo ${UNAME_MACHINE}-pc-rdos
+ exit ;;
+ i*86:AROS:*:*)
+ echo ${UNAME_MACHINE}-pc-aros
+ exit ;;
+ x86_64:VMkernel:*:*)
+ echo ${UNAME_MACHINE}-unknown-esx
+ exit ;;
+esac
+
+cat >&2 <<EOF
+$0: unable to guess system type
+
+This script, last modified $timestamp, has failed to recognize
+the operating system you are using. It is advised that you
+download the most up to date version of the config scripts from
+
+ http://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=config.guess;hb=HEAD
+and
+ http://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=config.sub;hb=HEAD
+
+If the version you run ($0) is already up to date, please
+send the following data and any information you think might be
+pertinent to <config-patches at gnu.org> in order to provide the needed
+information to handle your system.
+
+config.guess timestamp = $timestamp
+
+uname -m = `(uname -m) 2>/dev/null || echo unknown`
+uname -r = `(uname -r) 2>/dev/null || echo unknown`
+uname -s = `(uname -s) 2>/dev/null || echo unknown`
+uname -v = `(uname -v) 2>/dev/null || echo unknown`
+
+/usr/bin/uname -p = `(/usr/bin/uname -p) 2>/dev/null`
+/bin/uname -X = `(/bin/uname -X) 2>/dev/null`
+
+hostinfo = `(hostinfo) 2>/dev/null`
+/bin/universe = `(/bin/universe) 2>/dev/null`
+/usr/bin/arch -k = `(/usr/bin/arch -k) 2>/dev/null`
+/bin/arch = `(/bin/arch) 2>/dev/null`
+/usr/bin/oslevel = `(/usr/bin/oslevel) 2>/dev/null`
+/usr/convex/getsysinfo = `(/usr/convex/getsysinfo) 2>/dev/null`
+
+UNAME_MACHINE = ${UNAME_MACHINE}
+UNAME_RELEASE = ${UNAME_RELEASE}
+UNAME_SYSTEM = ${UNAME_SYSTEM}
+UNAME_VERSION = ${UNAME_VERSION}
+EOF
+
+exit 1
+
+# Local variables:
+# eval: (add-hook 'write-file-hooks 'time-stamp)
+# time-stamp-start: "timestamp='"
+# time-stamp-format: "%:y-%02m-%02d"
+# time-stamp-end: "'"
+# End:
diff --git a/jni/native/build/config.sub b/jni/native/build/config.sub
new file mode 100755
index 0000000..092cff0
--- /dev/null
+++ b/jni/native/build/config.sub
@@ -0,0 +1,1793 @@
+#! /bin/sh
+# Configuration validation subroutine script.
+# Copyright 1992-2014 Free Software Foundation, Inc.
+
+timestamp='2014-01-01'
+
+# This file is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, see <http://www.gnu.org/licenses/>.
+#
+# As a special exception to the GNU General Public License, if you
+# distribute this file as part of a program that contains a
+# configuration script generated by Autoconf, you may include it under
+# the same distribution terms that you use for the rest of that
+# program. This Exception is an additional permission under section 7
+# of the GNU General Public License, version 3 ("GPLv3").
+
+
+# Please send patches with a ChangeLog entry to config-patches at gnu.org.
+#
+# Configuration subroutine to validate and canonicalize a configuration type.
+# Supply the specified configuration type as an argument.
+# If it is invalid, we print an error message on stderr and exit with code 1.
+# Otherwise, we print the canonical config type on stdout and succeed.
+
+# You can get the latest version of this script from:
+# http://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=config.sub;hb=HEAD
+
+# This file is supposed to be the same for all GNU packages
+# and recognize all the CPU types, system types and aliases
+# that are meaningful with *any* GNU software.
+# Each package is responsible for reporting which valid configurations
+# it does not support. The user should be able to distinguish
+# a failure to support a valid configuration from a meaningless
+# configuration.
+
+# The goal of this file is to map all the various variations of a given
+# machine specification into a single specification in the form:
+# CPU_TYPE-MANUFACTURER-OPERATING_SYSTEM
+# or in some cases, the newer four-part form:
+# CPU_TYPE-MANUFACTURER-KERNEL-OPERATING_SYSTEM
+# It is wrong to echo any other type of specification.
+
+me=`echo "$0" | sed -e 's,.*/,,'`
+
+usage="\
+Usage: $0 [OPTION] CPU-MFR-OPSYS
+ $0 [OPTION] ALIAS
+
+Canonicalize a configuration name.
+
+Operation modes:
+ -h, --help print this help, then exit
+ -t, --time-stamp print date of last modification, then exit
+ -v, --version print version number, then exit
+
+Report bugs and patches to <config-patches at gnu.org>."
+
+version="\
+GNU config.sub ($timestamp)
+
+Copyright 1992-2014 Free Software Foundation, Inc.
+
+This is free software; see the source for copying conditions. There is NO
+warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE."
+
+help="
+Try \`$me --help' for more information."
+
+# Parse command line
+while test $# -gt 0 ; do
+ case $1 in
+ --time-stamp | --time* | -t )
+ echo "$timestamp" ; exit ;;
+ --version | -v )
+ echo "$version" ; exit ;;
+ --help | --h* | -h )
+ echo "$usage"; exit ;;
+ -- ) # Stop option processing
+ shift; break ;;
+ - ) # Use stdin as input.
+ break ;;
+ -* )
+ echo "$me: invalid option $1$help"
+ exit 1 ;;
+
+ *local*)
+ # First pass through any local machine types.
+ echo $1
+ exit ;;
+
+ * )
+ break ;;
+ esac
+done
+
+case $# in
+ 0) echo "$me: missing argument$help" >&2
+ exit 1;;
+ 1) ;;
+ *) echo "$me: too many arguments$help" >&2
+ exit 1;;
+esac
+
+# Separate what the user gave into CPU-COMPANY and OS or KERNEL-OS (if any).
+# Here we must recognize all the valid KERNEL-OS combinations.
+maybe_os=`echo $1 | sed 's/^\(.*\)-\([^-]*-[^-]*\)$/\2/'`
+case $maybe_os in
+ nto-qnx* | linux-gnu* | linux-android* | linux-dietlibc | linux-newlib* | \
+ linux-musl* | linux-uclibc* | uclinux-uclibc* | uclinux-gnu* | kfreebsd*-gnu* | \
+ knetbsd*-gnu* | netbsd*-gnu* | \
+ kopensolaris*-gnu* | \
+ storm-chaos* | os2-emx* | rtmk-nova*)
+ os=-$maybe_os
+ basic_machine=`echo $1 | sed 's/^\(.*\)-\([^-]*-[^-]*\)$/\1/'`
+ ;;
+ android-linux)
+ os=-linux-android
+ basic_machine=`echo $1 | sed 's/^\(.*\)-\([^-]*-[^-]*\)$/\1/'`-unknown
+ ;;
+ *)
+ basic_machine=`echo $1 | sed 's/-[^-]*$//'`
+ if [ $basic_machine != $1 ]
+ then os=`echo $1 | sed 's/.*-/-/'`
+ else os=; fi
+ ;;
+esac
+
+### Let's recognize common machines as not being operating systems so
+### that things like config.sub decstation-3100 work. We also
+### recognize some manufacturers as not being operating systems, so we
+### can provide default operating systems below.
+case $os in
+ -sun*os*)
+ # Prevent following clause from handling this invalid input.
+ ;;
+ -dec* | -mips* | -sequent* | -encore* | -pc532* | -sgi* | -sony* | \
+ -att* | -7300* | -3300* | -delta* | -motorola* | -sun[234]* | \
+ -unicom* | -ibm* | -next | -hp | -isi* | -apollo | -altos* | \
+ -convergent* | -ncr* | -news | -32* | -3600* | -3100* | -hitachi* |\
+ -c[123]* | -convex* | -sun | -crds | -omron* | -dg | -ultra | -tti* | \
+ -harris | -dolphin | -highlevel | -gould | -cbm | -ns | -masscomp | \
+ -apple | -axis | -knuth | -cray | -microblaze*)
+ os=
+ basic_machine=$1
+ ;;
+ -bluegene*)
+ os=-cnk
+ ;;
+ -sim | -cisco | -oki | -wec | -winbond)
+ os=
+ basic_machine=$1
+ ;;
+ -scout)
+ ;;
+ -wrs)
+ os=-vxworks
+ basic_machine=$1
+ ;;
+ -chorusos*)
+ os=-chorusos
+ basic_machine=$1
+ ;;
+ -chorusrdb)
+ os=-chorusrdb
+ basic_machine=$1
+ ;;
+ -hiux*)
+ os=-hiuxwe2
+ ;;
+ -sco6)
+ os=-sco5v6
+ basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'`
+ ;;
+ -sco5)
+ os=-sco3.2v5
+ basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'`
+ ;;
+ -sco4)
+ os=-sco3.2v4
+ basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'`
+ ;;
+ -sco3.2.[4-9]*)
+ os=`echo $os | sed -e 's/sco3.2./sco3.2v/'`
+ basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'`
+ ;;
+ -sco3.2v[4-9]*)
+ # Don't forget version if it is 3.2v4 or newer.
+ basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'`
+ ;;
+ -sco5v6*)
+ # Don't forget version if it is 3.2v4 or newer.
+ basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'`
+ ;;
+ -sco*)
+ os=-sco3.2v2
+ basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'`
+ ;;
+ -udk*)
+ basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'`
+ ;;
+ -isc)
+ os=-isc2.2
+ basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'`
+ ;;
+ -clix*)
+ basic_machine=clipper-intergraph
+ ;;
+ -isc*)
+ basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'`
+ ;;
+ -lynx*178)
+ os=-lynxos178
+ ;;
+ -lynx*5)
+ os=-lynxos5
+ ;;
+ -lynx*)
+ os=-lynxos
+ ;;
+ -ptx*)
+ basic_machine=`echo $1 | sed -e 's/86-.*/86-sequent/'`
+ ;;
+ -windowsnt*)
+ os=`echo $os | sed -e 's/windowsnt/winnt/'`
+ ;;
+ -psos*)
+ os=-psos
+ ;;
+ -mint | -mint[0-9]*)
+ basic_machine=m68k-atari
+ os=-mint
+ ;;
+esac
+
+# Decode aliases for certain CPU-COMPANY combinations.
+case $basic_machine in
+ # Recognize the basic CPU types without company name.
+ # Some are omitted here because they have special meanings below.
+ 1750a | 580 \
+ | a29k \
+ | aarch64 | aarch64_be \
+ | alpha | alphaev[4-8] | alphaev56 | alphaev6[78] | alphapca5[67] \
+ | alpha64 | alpha64ev[4-8] | alpha64ev56 | alpha64ev6[78] | alpha64pca5[67] \
+ | am33_2.0 \
+ | arc | arceb \
+ | arm | arm[bl]e | arme[lb] | armv[2-8] | armv[3-8][lb] | armv7[arm] \
+ | avr | avr32 \
+ | be32 | be64 \
+ | bfin \
+ | c4x | c8051 | clipper \
+ | d10v | d30v | dlx | dsp16xx \
+ | epiphany \
+ | fido | fr30 | frv \
+ | h8300 | h8500 | hppa | hppa1.[01] | hppa2.0 | hppa2.0[nw] | hppa64 \
+ | hexagon \
+ | i370 | i860 | i960 | ia64 \
+ | ip2k | iq2000 \
+ | k1om \
+ | le32 | le64 \
+ | lm32 \
+ | m32c | m32r | m32rle | m68000 | m68k | m88k \
+ | maxq | mb | microblaze | microblazeel | mcore | mep | metag \
+ | mips | mipsbe | mipseb | mipsel | mipsle \
+ | mips16 \
+ | mips64 | mips64el \
+ | mips64octeon | mips64octeonel \
+ | mips64orion | mips64orionel \
+ | mips64r5900 | mips64r5900el \
+ | mips64vr | mips64vrel \
+ | mips64vr4100 | mips64vr4100el \
+ | mips64vr4300 | mips64vr4300el \
+ | mips64vr5000 | mips64vr5000el \
+ | mips64vr5900 | mips64vr5900el \
+ | mipsisa32 | mipsisa32el \
+ | mipsisa32r2 | mipsisa32r2el \
+ | mipsisa64 | mipsisa64el \
+ | mipsisa64r2 | mipsisa64r2el \
+ | mipsisa64sb1 | mipsisa64sb1el \
+ | mipsisa64sr71k | mipsisa64sr71kel \
+ | mipsr5900 | mipsr5900el \
+ | mipstx39 | mipstx39el \
+ | mn10200 | mn10300 \
+ | moxie \
+ | mt \
+ | msp430 \
+ | nds32 | nds32le | nds32be \
+ | nios | nios2 | nios2eb | nios2el \
+ | ns16k | ns32k \
+ | open8 \
+ | or1k | or32 \
+ | pdp10 | pdp11 | pj | pjl \
+ | powerpc | powerpc64 | powerpc64le | powerpcle \
+ | pyramid \
+ | rl78 | rx \
+ | score \
+ | sh | sh[1234] | sh[24]a | sh[24]aeb | sh[23]e | sh[34]eb | sheb | shbe | shle | sh[1234]le | sh3ele \
+ | sh64 | sh64le \
+ | sparc | sparc64 | sparc64b | sparc64v | sparc86x | sparclet | sparclite \
+ | sparcv8 | sparcv9 | sparcv9b | sparcv9v \
+ | spu \
+ | tahoe | tic4x | tic54x | tic55x | tic6x | tic80 | tron \
+ | ubicom32 \
+ | v850 | v850e | v850e1 | v850e2 | v850es | v850e2v3 \
+ | we32k \
+ | x86 | xc16x | xstormy16 | xtensa \
+ | z8k | z80)
+ basic_machine=$basic_machine-unknown
+ ;;
+ c54x)
+ basic_machine=tic54x-unknown
+ ;;
+ c55x)
+ basic_machine=tic55x-unknown
+ ;;
+ c6x)
+ basic_machine=tic6x-unknown
+ ;;
+ m6811 | m68hc11 | m6812 | m68hc12 | m68hcs12x | nvptx | picochip)
+ basic_machine=$basic_machine-unknown
+ os=-none
+ ;;
+ m88110 | m680[12346]0 | m683?2 | m68360 | m5200 | v70 | w65 | z8k)
+ ;;
+ ms1)
+ basic_machine=mt-unknown
+ ;;
+
+ strongarm | thumb | xscale)
+ basic_machine=arm-unknown
+ ;;
+ xgate)
+ basic_machine=$basic_machine-unknown
+ os=-none
+ ;;
+ xscaleeb)
+ basic_machine=armeb-unknown
+ ;;
+
+ xscaleel)
+ basic_machine=armel-unknown
+ ;;
+
+ # We use `pc' rather than `unknown'
+ # because (1) that's what they normally are, and
+ # (2) the word "unknown" tends to confuse beginning users.
+ i*86 | x86_64)
+ basic_machine=$basic_machine-pc
+ ;;
+ # Object if more than one company name word.
+ *-*-*)
+ echo Invalid configuration \`$1\': machine \`$basic_machine\' not recognized 1>&2
+ exit 1
+ ;;
+ # Recognize the basic CPU types with company name.
+ 580-* \
+ | a29k-* \
+ | aarch64-* | aarch64_be-* \
+ | alpha-* | alphaev[4-8]-* | alphaev56-* | alphaev6[78]-* \
+ | alpha64-* | alpha64ev[4-8]-* | alpha64ev56-* | alpha64ev6[78]-* \
+ | alphapca5[67]-* | alpha64pca5[67]-* | arc-* | arceb-* \
+ | arm-* | armbe-* | armle-* | armeb-* | armv*-* \
+ | avr-* | avr32-* \
+ | be32-* | be64-* \
+ | bfin-* | bs2000-* \
+ | c[123]* | c30-* | [cjt]90-* | c4x-* \
+ | c8051-* | clipper-* | craynv-* | cydra-* \
+ | d10v-* | d30v-* | dlx-* \
+ | elxsi-* \
+ | f30[01]-* | f700-* | fido-* | fr30-* | frv-* | fx80-* \
+ | h8300-* | h8500-* \
+ | hppa-* | hppa1.[01]-* | hppa2.0-* | hppa2.0[nw]-* | hppa64-* \
+ | hexagon-* \
+ | i*86-* | i860-* | i960-* | ia64-* \
+ | ip2k-* | iq2000-* \
+ | k1om-* \
+ | le32-* | le64-* \
+ | lm32-* \
+ | m32c-* | m32r-* | m32rle-* \
+ | m68000-* | m680[012346]0-* | m68360-* | m683?2-* | m68k-* \
+ | m88110-* | m88k-* | maxq-* | mcore-* | metag-* \
+ | microblaze-* | microblazeel-* \
+ | mips-* | mipsbe-* | mipseb-* | mipsel-* | mipsle-* \
+ | mips16-* \
+ | mips64-* | mips64el-* \
+ | mips64octeon-* | mips64octeonel-* \
+ | mips64orion-* | mips64orionel-* \
+ | mips64r5900-* | mips64r5900el-* \
+ | mips64vr-* | mips64vrel-* \
+ | mips64vr4100-* | mips64vr4100el-* \
+ | mips64vr4300-* | mips64vr4300el-* \
+ | mips64vr5000-* | mips64vr5000el-* \
+ | mips64vr5900-* | mips64vr5900el-* \
+ | mipsisa32-* | mipsisa32el-* \
+ | mipsisa32r2-* | mipsisa32r2el-* \
+ | mipsisa64-* | mipsisa64el-* \
+ | mipsisa64r2-* | mipsisa64r2el-* \
+ | mipsisa64sb1-* | mipsisa64sb1el-* \
+ | mipsisa64sr71k-* | mipsisa64sr71kel-* \
+ | mipsr5900-* | mipsr5900el-* \
+ | mipstx39-* | mipstx39el-* \
+ | mmix-* \
+ | mt-* \
+ | msp430-* \
+ | nds32-* | nds32le-* | nds32be-* \
+ | nios-* | nios2-* | nios2eb-* | nios2el-* \
+ | none-* | np1-* | ns16k-* | ns32k-* \
+ | open8-* \
+ | orion-* \
+ | pdp10-* | pdp11-* | pj-* | pjl-* | pn-* | power-* \
+ | powerpc-* | powerpc64-* | powerpc64le-* | powerpcle-* \
+ | pyramid-* \
+ | rl78-* | romp-* | rs6000-* | rx-* \
+ | sh-* | sh[1234]-* | sh[24]a-* | sh[24]aeb-* | sh[23]e-* | sh[34]eb-* | sheb-* | shbe-* \
+ | shle-* | sh[1234]le-* | sh3ele-* | sh64-* | sh64le-* \
+ | sparc-* | sparc64-* | sparc64b-* | sparc64v-* | sparc86x-* | sparclet-* \
+ | sparclite-* \
+ | sparcv8-* | sparcv9-* | sparcv9b-* | sparcv9v-* | sv1-* | sx?-* \
+ | tahoe-* \
+ | tic30-* | tic4x-* | tic54x-* | tic55x-* | tic6x-* | tic80-* \
+ | tile*-* \
+ | tron-* \
+ | ubicom32-* \
+ | v850-* | v850e-* | v850e1-* | v850es-* | v850e2-* | v850e2v3-* \
+ | vax-* \
+ | we32k-* \
+ | x86-* | x86_64-* | xc16x-* | xps100-* \
+ | xstormy16-* | xtensa*-* \
+ | ymp-* \
+ | z8k-* | z80-*)
+ ;;
+ # Recognize the basic CPU types without company name, with glob match.
+ xtensa*)
+ basic_machine=$basic_machine-unknown
+ ;;
+ # Recognize the various machine names and aliases which stand
+ # for a CPU type and a company and sometimes even an OS.
+ 386bsd)
+ basic_machine=i386-unknown
+ os=-bsd
+ ;;
+ 3b1 | 7300 | 7300-att | att-7300 | pc7300 | safari | unixpc)
+ basic_machine=m68000-att
+ ;;
+ 3b*)
+ basic_machine=we32k-att
+ ;;
+ a29khif)
+ basic_machine=a29k-amd
+ os=-udi
+ ;;
+ abacus)
+ basic_machine=abacus-unknown
+ ;;
+ adobe68k)
+ basic_machine=m68010-adobe
+ os=-scout
+ ;;
+ alliant | fx80)
+ basic_machine=fx80-alliant
+ ;;
+ altos | altos3068)
+ basic_machine=m68k-altos
+ ;;
+ am29k)
+ basic_machine=a29k-none
+ os=-bsd
+ ;;
+ amd64)
+ basic_machine=x86_64-pc
+ ;;
+ amd64-*)
+ basic_machine=x86_64-`echo $basic_machine | sed 's/^[^-]*-//'`
+ ;;
+ amdahl)
+ basic_machine=580-amdahl
+ os=-sysv
+ ;;
+ amiga | amiga-*)
+ basic_machine=m68k-unknown
+ ;;
+ amigaos | amigados)
+ basic_machine=m68k-unknown
+ os=-amigaos
+ ;;
+ amigaunix | amix)
+ basic_machine=m68k-unknown
+ os=-sysv4
+ ;;
+ apollo68)
+ basic_machine=m68k-apollo
+ os=-sysv
+ ;;
+ apollo68bsd)
+ basic_machine=m68k-apollo
+ os=-bsd
+ ;;
+ aros)
+ basic_machine=i386-pc
+ os=-aros
+ ;;
+ aux)
+ basic_machine=m68k-apple
+ os=-aux
+ ;;
+ balance)
+ basic_machine=ns32k-sequent
+ os=-dynix
+ ;;
+ blackfin)
+ basic_machine=bfin-unknown
+ os=-linux
+ ;;
+ blackfin-*)
+ basic_machine=bfin-`echo $basic_machine | sed 's/^[^-]*-//'`
+ os=-linux
+ ;;
+ bluegene*)
+ basic_machine=powerpc-ibm
+ os=-cnk
+ ;;
+ c54x-*)
+ basic_machine=tic54x-`echo $basic_machine | sed 's/^[^-]*-//'`
+ ;;
+ c55x-*)
+ basic_machine=tic55x-`echo $basic_machine | sed 's/^[^-]*-//'`
+ ;;
+ c6x-*)
+ basic_machine=tic6x-`echo $basic_machine | sed 's/^[^-]*-//'`
+ ;;
+ c90)
+ basic_machine=c90-cray
+ os=-unicos
+ ;;
+ cegcc)
+ basic_machine=arm-unknown
+ os=-cegcc
+ ;;
+ convex-c1)
+ basic_machine=c1-convex
+ os=-bsd
+ ;;
+ convex-c2)
+ basic_machine=c2-convex
+ os=-bsd
+ ;;
+ convex-c32)
+ basic_machine=c32-convex
+ os=-bsd
+ ;;
+ convex-c34)
+ basic_machine=c34-convex
+ os=-bsd
+ ;;
+ convex-c38)
+ basic_machine=c38-convex
+ os=-bsd
+ ;;
+ cray | j90)
+ basic_machine=j90-cray
+ os=-unicos
+ ;;
+ craynv)
+ basic_machine=craynv-cray
+ os=-unicosmp
+ ;;
+ cr16 | cr16-*)
+ basic_machine=cr16-unknown
+ os=-elf
+ ;;
+ crds | unos)
+ basic_machine=m68k-crds
+ ;;
+ crisv32 | crisv32-* | etraxfs*)
+ basic_machine=crisv32-axis
+ ;;
+ cris | cris-* | etrax*)
+ basic_machine=cris-axis
+ ;;
+ crx)
+ basic_machine=crx-unknown
+ os=-elf
+ ;;
+ da30 | da30-*)
+ basic_machine=m68k-da30
+ ;;
+ decstation | decstation-3100 | pmax | pmax-* | pmin | dec3100 | decstatn)
+ basic_machine=mips-dec
+ ;;
+ decsystem10* | dec10*)
+ basic_machine=pdp10-dec
+ os=-tops10
+ ;;
+ decsystem20* | dec20*)
+ basic_machine=pdp10-dec
+ os=-tops20
+ ;;
+ delta | 3300 | motorola-3300 | motorola-delta \
+ | 3300-motorola | delta-motorola)
+ basic_machine=m68k-motorola
+ ;;
+ delta88)
+ basic_machine=m88k-motorola
+ os=-sysv3
+ ;;
+ dicos)
+ basic_machine=i686-pc
+ os=-dicos
+ ;;
+ djgpp)
+ basic_machine=i586-pc
+ os=-msdosdjgpp
+ ;;
+ dpx20 | dpx20-*)
+ basic_machine=rs6000-bull
+ os=-bosx
+ ;;
+ dpx2* | dpx2*-bull)
+ basic_machine=m68k-bull
+ os=-sysv3
+ ;;
+ ebmon29k)
+ basic_machine=a29k-amd
+ os=-ebmon
+ ;;
+ elxsi)
+ basic_machine=elxsi-elxsi
+ os=-bsd
+ ;;
+ encore | umax | mmax)
+ basic_machine=ns32k-encore
+ ;;
+ es1800 | OSE68k | ose68k | ose | OSE)
+ basic_machine=m68k-ericsson
+ os=-ose
+ ;;
+ fx2800)
+ basic_machine=i860-alliant
+ ;;
+ genix)
+ basic_machine=ns32k-ns
+ ;;
+ gmicro)
+ basic_machine=tron-gmicro
+ os=-sysv
+ ;;
+ go32)
+ basic_machine=i386-pc
+ os=-go32
+ ;;
+ h3050r* | hiux*)
+ basic_machine=hppa1.1-hitachi
+ os=-hiuxwe2
+ ;;
+ h8300hms)
+ basic_machine=h8300-hitachi
+ os=-hms
+ ;;
+ h8300xray)
+ basic_machine=h8300-hitachi
+ os=-xray
+ ;;
+ h8500hms)
+ basic_machine=h8500-hitachi
+ os=-hms
+ ;;
+ harris)
+ basic_machine=m88k-harris
+ os=-sysv3
+ ;;
+ hp300-*)
+ basic_machine=m68k-hp
+ ;;
+ hp300bsd)
+ basic_machine=m68k-hp
+ os=-bsd
+ ;;
+ hp300hpux)
+ basic_machine=m68k-hp
+ os=-hpux
+ ;;
+ hp3k9[0-9][0-9] | hp9[0-9][0-9])
+ basic_machine=hppa1.0-hp
+ ;;
+ hp9k2[0-9][0-9] | hp9k31[0-9])
+ basic_machine=m68000-hp
+ ;;
+ hp9k3[2-9][0-9])
+ basic_machine=m68k-hp
+ ;;
+ hp9k6[0-9][0-9] | hp6[0-9][0-9])
+ basic_machine=hppa1.0-hp
+ ;;
+ hp9k7[0-79][0-9] | hp7[0-79][0-9])
+ basic_machine=hppa1.1-hp
+ ;;
+ hp9k78[0-9] | hp78[0-9])
+ # FIXME: really hppa2.0-hp
+ basic_machine=hppa1.1-hp
+ ;;
+ hp9k8[67]1 | hp8[67]1 | hp9k80[24] | hp80[24] | hp9k8[78]9 | hp8[78]9 | hp9k893 | hp893)
+ # FIXME: really hppa2.0-hp
+ basic_machine=hppa1.1-hp
+ ;;
+ hp9k8[0-9][13679] | hp8[0-9][13679])
+ basic_machine=hppa1.1-hp
+ ;;
+ hp9k8[0-9][0-9] | hp8[0-9][0-9])
+ basic_machine=hppa1.0-hp
+ ;;
+ hppa-next)
+ os=-nextstep3
+ ;;
+ hppaosf)
+ basic_machine=hppa1.1-hp
+ os=-osf
+ ;;
+ hppro)
+ basic_machine=hppa1.1-hp
+ os=-proelf
+ ;;
+ i370-ibm* | ibm*)
+ basic_machine=i370-ibm
+ ;;
+ i*86v32)
+ basic_machine=`echo $1 | sed -e 's/86.*/86-pc/'`
+ os=-sysv32
+ ;;
+ i*86v4*)
+ basic_machine=`echo $1 | sed -e 's/86.*/86-pc/'`
+ os=-sysv4
+ ;;
+ i*86v)
+ basic_machine=`echo $1 | sed -e 's/86.*/86-pc/'`
+ os=-sysv
+ ;;
+ i*86sol2)
+ basic_machine=`echo $1 | sed -e 's/86.*/86-pc/'`
+ os=-solaris2
+ ;;
+ i386mach)
+ basic_machine=i386-mach
+ os=-mach
+ ;;
+ i386-vsta | vsta)
+ basic_machine=i386-unknown
+ os=-vsta
+ ;;
+ iris | iris4d)
+ basic_machine=mips-sgi
+ case $os in
+ -irix*)
+ ;;
+ *)
+ os=-irix4
+ ;;
+ esac
+ ;;
+ isi68 | isi)
+ basic_machine=m68k-isi
+ os=-sysv
+ ;;
+ m68knommu)
+ basic_machine=m68k-unknown
+ os=-linux
+ ;;
+ m68knommu-*)
+ basic_machine=m68k-`echo $basic_machine | sed 's/^[^-]*-//'`
+ os=-linux
+ ;;
+ m88k-omron*)
+ basic_machine=m88k-omron
+ ;;
+ magnum | m3230)
+ basic_machine=mips-mips
+ os=-sysv
+ ;;
+ merlin)
+ basic_machine=ns32k-utek
+ os=-sysv
+ ;;
+ microblaze*)
+ basic_machine=microblaze-xilinx
+ ;;
+ mingw64)
+ basic_machine=x86_64-pc
+ os=-mingw64
+ ;;
+ mingw32)
+ basic_machine=i686-pc
+ os=-mingw32
+ ;;
+ mingw32ce)
+ basic_machine=arm-unknown
+ os=-mingw32ce
+ ;;
+ miniframe)
+ basic_machine=m68000-convergent
+ ;;
+ *mint | -mint[0-9]* | *MiNT | *MiNT[0-9]*)
+ basic_machine=m68k-atari
+ os=-mint
+ ;;
+ mips3*-*)
+ basic_machine=`echo $basic_machine | sed -e 's/mips3/mips64/'`
+ ;;
+ mips3*)
+ basic_machine=`echo $basic_machine | sed -e 's/mips3/mips64/'`-unknown
+ ;;
+ monitor)
+ basic_machine=m68k-rom68k
+ os=-coff
+ ;;
+ morphos)
+ basic_machine=powerpc-unknown
+ os=-morphos
+ ;;
+ msdos)
+ basic_machine=i386-pc
+ os=-msdos
+ ;;
+ ms1-*)
+ basic_machine=`echo $basic_machine | sed -e 's/ms1-/mt-/'`
+ ;;
+ msys)
+ basic_machine=i686-pc
+ os=-msys
+ ;;
+ mvs)
+ basic_machine=i370-ibm
+ os=-mvs
+ ;;
+ nacl)
+ basic_machine=le32-unknown
+ os=-nacl
+ ;;
+ ncr3000)
+ basic_machine=i486-ncr
+ os=-sysv4
+ ;;
+ netbsd386)
+ basic_machine=i386-unknown
+ os=-netbsd
+ ;;
+ netwinder)
+ basic_machine=armv4l-rebel
+ os=-linux
+ ;;
+ news | news700 | news800 | news900)
+ basic_machine=m68k-sony
+ os=-newsos
+ ;;
+ news1000)
+ basic_machine=m68030-sony
+ os=-newsos
+ ;;
+ news-3600 | risc-news)
+ basic_machine=mips-sony
+ os=-newsos
+ ;;
+ necv70)
+ basic_machine=v70-nec
+ os=-sysv
+ ;;
+ next | m*-next )
+ basic_machine=m68k-next
+ case $os in
+ -nextstep* )
+ ;;
+ -ns2*)
+ os=-nextstep2
+ ;;
+ *)
+ os=-nextstep3
+ ;;
+ esac
+ ;;
+ nh3000)
+ basic_machine=m68k-harris
+ os=-cxux
+ ;;
+ nh[45]000)
+ basic_machine=m88k-harris
+ os=-cxux
+ ;;
+ nindy960)
+ basic_machine=i960-intel
+ os=-nindy
+ ;;
+ mon960)
+ basic_machine=i960-intel
+ os=-mon960
+ ;;
+ nonstopux)
+ basic_machine=mips-compaq
+ os=-nonstopux
+ ;;
+ np1)
+ basic_machine=np1-gould
+ ;;
+ neo-tandem)
+ basic_machine=neo-tandem
+ ;;
+ nse-tandem)
+ basic_machine=nse-tandem
+ ;;
+ nsr-tandem)
+ basic_machine=nsr-tandem
+ ;;
+ op50n-* | op60c-*)
+ basic_machine=hppa1.1-oki
+ os=-proelf
+ ;;
+ openrisc | openrisc-*)
+ basic_machine=or32-unknown
+ ;;
+ os400)
+ basic_machine=powerpc-ibm
+ os=-os400
+ ;;
+ OSE68000 | ose68000)
+ basic_machine=m68000-ericsson
+ os=-ose
+ ;;
+ os68k)
+ basic_machine=m68k-none
+ os=-os68k
+ ;;
+ pa-hitachi)
+ basic_machine=hppa1.1-hitachi
+ os=-hiuxwe2
+ ;;
+ paragon)
+ basic_machine=i860-intel
+ os=-osf
+ ;;
+ parisc)
+ basic_machine=hppa-unknown
+ os=-linux
+ ;;
+ parisc-*)
+ basic_machine=hppa-`echo $basic_machine | sed 's/^[^-]*-//'`
+ os=-linux
+ ;;
+ pbd)
+ basic_machine=sparc-tti
+ ;;
+ pbb)
+ basic_machine=m68k-tti
+ ;;
+ pc532 | pc532-*)
+ basic_machine=ns32k-pc532
+ ;;
+ pc98)
+ basic_machine=i386-pc
+ ;;
+ pc98-*)
+ basic_machine=i386-`echo $basic_machine | sed 's/^[^-]*-//'`
+ ;;
+ pentium | p5 | k5 | k6 | nexgen | viac3)
+ basic_machine=i586-pc
+ ;;
+ pentiumpro | p6 | 6x86 | athlon | athlon_*)
+ basic_machine=i686-pc
+ ;;
+ pentiumii | pentium2 | pentiumiii | pentium3)
+ basic_machine=i686-pc
+ ;;
+ pentium4)
+ basic_machine=i786-pc
+ ;;
+ pentium-* | p5-* | k5-* | k6-* | nexgen-* | viac3-*)
+ basic_machine=i586-`echo $basic_machine | sed 's/^[^-]*-//'`
+ ;;
+ pentiumpro-* | p6-* | 6x86-* | athlon-*)
+ basic_machine=i686-`echo $basic_machine | sed 's/^[^-]*-//'`
+ ;;
+ pentiumii-* | pentium2-* | pentiumiii-* | pentium3-*)
+ basic_machine=i686-`echo $basic_machine | sed 's/^[^-]*-//'`
+ ;;
+ pentium4-*)
+ basic_machine=i786-`echo $basic_machine | sed 's/^[^-]*-//'`
+ ;;
+ pn)
+ basic_machine=pn-gould
+ ;;
+ power) basic_machine=power-ibm
+ ;;
+ ppc | ppcbe) basic_machine=powerpc-unknown
+ ;;
+ ppc-* | ppcbe-*)
+ basic_machine=powerpc-`echo $basic_machine | sed 's/^[^-]*-//'`
+ ;;
+ ppcle | powerpclittle | ppc-le | powerpc-little)
+ basic_machine=powerpcle-unknown
+ ;;
+ ppcle-* | powerpclittle-*)
+ basic_machine=powerpcle-`echo $basic_machine | sed 's/^[^-]*-//'`
+ ;;
+ ppc64) basic_machine=powerpc64-unknown
+ ;;
+ ppc64-*) basic_machine=powerpc64-`echo $basic_machine | sed 's/^[^-]*-//'`
+ ;;
+ ppc64le | powerpc64little | ppc64-le | powerpc64-little)
+ basic_machine=powerpc64le-unknown
+ ;;
+ ppc64le-* | powerpc64little-*)
+ basic_machine=powerpc64le-`echo $basic_machine | sed 's/^[^-]*-//'`
+ ;;
+ ps2)
+ basic_machine=i386-ibm
+ ;;
+ pw32)
+ basic_machine=i586-unknown
+ os=-pw32
+ ;;
+ rdos | rdos64)
+ basic_machine=x86_64-pc
+ os=-rdos
+ ;;
+ rdos32)
+ basic_machine=i386-pc
+ os=-rdos
+ ;;
+ rom68k)
+ basic_machine=m68k-rom68k
+ os=-coff
+ ;;
+ rm[46]00)
+ basic_machine=mips-siemens
+ ;;
+ rtpc | rtpc-*)
+ basic_machine=romp-ibm
+ ;;
+ s390 | s390-*)
+ basic_machine=s390-ibm
+ ;;
+ s390x | s390x-*)
+ basic_machine=s390x-ibm
+ ;;
+ sa29200)
+ basic_machine=a29k-amd
+ os=-udi
+ ;;
+ sb1)
+ basic_machine=mipsisa64sb1-unknown
+ ;;
+ sb1el)
+ basic_machine=mipsisa64sb1el-unknown
+ ;;
+ sde)
+ basic_machine=mipsisa32-sde
+ os=-elf
+ ;;
+ sei)
+ basic_machine=mips-sei
+ os=-seiux
+ ;;
+ sequent)
+ basic_machine=i386-sequent
+ ;;
+ sh)
+ basic_machine=sh-hitachi
+ os=-hms
+ ;;
+ sh5el)
+ basic_machine=sh5le-unknown
+ ;;
+ sh64)
+ basic_machine=sh64-unknown
+ ;;
+ sparclite-wrs | simso-wrs)
+ basic_machine=sparclite-wrs
+ os=-vxworks
+ ;;
+ sps7)
+ basic_machine=m68k-bull
+ os=-sysv2
+ ;;
+ spur)
+ basic_machine=spur-unknown
+ ;;
+ st2000)
+ basic_machine=m68k-tandem
+ ;;
+ stratus)
+ basic_machine=i860-stratus
+ os=-sysv4
+ ;;
+ strongarm-* | thumb-*)
+ basic_machine=arm-`echo $basic_machine | sed 's/^[^-]*-//'`
+ ;;
+ sun2)
+ basic_machine=m68000-sun
+ ;;
+ sun2os3)
+ basic_machine=m68000-sun
+ os=-sunos3
+ ;;
+ sun2os4)
+ basic_machine=m68000-sun
+ os=-sunos4
+ ;;
+ sun3os3)
+ basic_machine=m68k-sun
+ os=-sunos3
+ ;;
+ sun3os4)
+ basic_machine=m68k-sun
+ os=-sunos4
+ ;;
+ sun4os3)
+ basic_machine=sparc-sun
+ os=-sunos3
+ ;;
+ sun4os4)
+ basic_machine=sparc-sun
+ os=-sunos4
+ ;;
+ sun4sol2)
+ basic_machine=sparc-sun
+ os=-solaris2
+ ;;
+ sun3 | sun3-*)
+ basic_machine=m68k-sun
+ ;;
+ sun4)
+ basic_machine=sparc-sun
+ ;;
+ sun386 | sun386i | roadrunner)
+ basic_machine=i386-sun
+ ;;
+ sv1)
+ basic_machine=sv1-cray
+ os=-unicos
+ ;;
+ symmetry)
+ basic_machine=i386-sequent
+ os=-dynix
+ ;;
+ t3e)
+ basic_machine=alphaev5-cray
+ os=-unicos
+ ;;
+ t90)
+ basic_machine=t90-cray
+ os=-unicos
+ ;;
+ tile*)
+ basic_machine=$basic_machine-unknown
+ os=-linux-gnu
+ ;;
+ tx39)
+ basic_machine=mipstx39-unknown
+ ;;
+ tx39el)
+ basic_machine=mipstx39el-unknown
+ ;;
+ toad1)
+ basic_machine=pdp10-xkl
+ os=-tops20
+ ;;
+ tower | tower-32)
+ basic_machine=m68k-ncr
+ ;;
+ tpf)
+ basic_machine=s390x-ibm
+ os=-tpf
+ ;;
+ udi29k)
+ basic_machine=a29k-amd
+ os=-udi
+ ;;
+ ultra3)
+ basic_machine=a29k-nyu
+ os=-sym1
+ ;;
+ v810 | necv810)
+ basic_machine=v810-nec
+ os=-none
+ ;;
+ vaxv)
+ basic_machine=vax-dec
+ os=-sysv
+ ;;
+ vms)
+ basic_machine=vax-dec
+ os=-vms
+ ;;
+ vpp*|vx|vx-*)
+ basic_machine=f301-fujitsu
+ ;;
+ vxworks960)
+ basic_machine=i960-wrs
+ os=-vxworks
+ ;;
+ vxworks68)
+ basic_machine=m68k-wrs
+ os=-vxworks
+ ;;
+ vxworks29k)
+ basic_machine=a29k-wrs
+ os=-vxworks
+ ;;
+ w65*)
+ basic_machine=w65-wdc
+ os=-none
+ ;;
+ w89k-*)
+ basic_machine=hppa1.1-winbond
+ os=-proelf
+ ;;
+ xbox)
+ basic_machine=i686-pc
+ os=-mingw32
+ ;;
+ xps | xps100)
+ basic_machine=xps100-honeywell
+ ;;
+ xscale-* | xscalee[bl]-*)
+ basic_machine=`echo $basic_machine | sed 's/^xscale/arm/'`
+ ;;
+ ymp)
+ basic_machine=ymp-cray
+ os=-unicos
+ ;;
+ z8k-*-coff)
+ basic_machine=z8k-unknown
+ os=-sim
+ ;;
+ z80-*-coff)
+ basic_machine=z80-unknown
+ os=-sim
+ ;;
+ none)
+ basic_machine=none-none
+ os=-none
+ ;;
+
+# Here we handle the default manufacturer of certain CPU types. It is in
+# some cases the only manufacturer, in others, it is the most popular.
+ w89k)
+ basic_machine=hppa1.1-winbond
+ ;;
+ op50n)
+ basic_machine=hppa1.1-oki
+ ;;
+ op60c)
+ basic_machine=hppa1.1-oki
+ ;;
+ romp)
+ basic_machine=romp-ibm
+ ;;
+ mmix)
+ basic_machine=mmix-knuth
+ ;;
+ rs6000)
+ basic_machine=rs6000-ibm
+ ;;
+ vax)
+ basic_machine=vax-dec
+ ;;
+ pdp10)
+ # there are many clones, so DEC is not a safe bet
+ basic_machine=pdp10-unknown
+ ;;
+ pdp11)
+ basic_machine=pdp11-dec
+ ;;
+ we32k)
+ basic_machine=we32k-att
+ ;;
+ sh[1234] | sh[24]a | sh[24]aeb | sh[34]eb | sh[1234]le | sh[23]ele)
+ basic_machine=sh-unknown
+ ;;
+ sparc | sparcv8 | sparcv9 | sparcv9b | sparcv9v)
+ basic_machine=sparc-sun
+ ;;
+ cydra)
+ basic_machine=cydra-cydrome
+ ;;
+ orion)
+ basic_machine=orion-highlevel
+ ;;
+ orion105)
+ basic_machine=clipper-highlevel
+ ;;
+ mac | mpw | mac-mpw)
+ basic_machine=m68k-apple
+ ;;
+ pmac | pmac-mpw)
+ basic_machine=powerpc-apple
+ ;;
+ *-unknown)
+ # Make sure to match an already-canonicalized machine name.
+ ;;
+ *)
+ echo Invalid configuration \`$1\': machine \`$basic_machine\' not recognized 1>&2
+ exit 1
+ ;;
+esac
+
+# Here we canonicalize certain aliases for manufacturers.
+case $basic_machine in
+ *-digital*)
+ basic_machine=`echo $basic_machine | sed 's/digital.*/dec/'`
+ ;;
+ *-commodore*)
+ basic_machine=`echo $basic_machine | sed 's/commodore.*/cbm/'`
+ ;;
+ *)
+ ;;
+esac
+
+# Decode manufacturer-specific aliases for certain operating systems.
+
+if [ x"$os" != x"" ]
+then
+case $os in
+ # First match some system type aliases
+ # that might get confused with valid system types.
+ # -solaris* is a basic system type, with this one exception.
+ -auroraux)
+ os=-auroraux
+ ;;
+ -solaris1 | -solaris1.*)
+ os=`echo $os | sed -e 's|solaris1|sunos4|'`
+ ;;
+ -solaris)
+ os=-solaris2
+ ;;
+ -svr4*)
+ os=-sysv4
+ ;;
+ -unixware*)
+ os=-sysv4.2uw
+ ;;
+ -gnu/linux*)
+ os=`echo $os | sed -e 's|gnu/linux|linux-gnu|'`
+ ;;
+ # First accept the basic system types.
+ # The portable systems comes first.
+ # Each alternative MUST END IN A *, to match a version number.
+ # -sysv* is not here because it comes later, after sysvr4.
+ -gnu* | -bsd* | -mach* | -minix* | -genix* | -ultrix* | -irix* \
+ | -*vms* | -sco* | -esix* | -isc* | -aix* | -cnk* | -sunos | -sunos[34]*\
+ | -hpux* | -unos* | -osf* | -luna* | -dgux* | -auroraux* | -solaris* \
+ | -sym* | -kopensolaris* | -plan9* \
+ | -amigaos* | -amigados* | -msdos* | -newsos* | -unicos* | -aof* \
+ | -aos* | -aros* \
+ | -nindy* | -vxsim* | -vxworks* | -ebmon* | -hms* | -mvs* \
+ | -clix* | -riscos* | -uniplus* | -iris* | -rtu* | -xenix* \
+ | -hiux* | -386bsd* | -knetbsd* | -mirbsd* | -netbsd* \
+ | -bitrig* | -openbsd* | -solidbsd* \
+ | -ekkobsd* | -kfreebsd* | -freebsd* | -riscix* | -lynxos* \
+ | -bosx* | -nextstep* | -cxux* | -aout* | -elf* | -oabi* \
+ | -ptx* | -coff* | -ecoff* | -winnt* | -domain* | -vsta* \
+ | -udi* | -eabi* | -lites* | -ieee* | -go32* | -aux* \
+ | -chorusos* | -chorusrdb* | -cegcc* \
+ | -cygwin* | -msys* | -pe* | -psos* | -moss* | -proelf* | -rtems* \
+ | -mingw32* | -mingw64* | -linux-gnu* | -linux-android* \
+ | -linux-newlib* | -linux-musl* | -linux-uclibc* \
+ | -uxpv* | -beos* | -mpeix* | -udk* \
+ | -interix* | -uwin* | -mks* | -rhapsody* | -darwin* | -opened* \
+ | -openstep* | -oskit* | -conix* | -pw32* | -nonstopux* \
+ | -storm-chaos* | -tops10* | -tenex* | -tops20* | -its* \
+ | -os2* | -vos* | -palmos* | -uclinux* | -nucleus* \
+ | -morphos* | -superux* | -rtmk* | -rtmk-nova* | -windiss* \
+ | -powermax* | -dnix* | -nx6 | -nx7 | -sei* | -dragonfly* \
+ | -skyos* | -haiku* | -rdos* | -toppers* | -drops* | -es*)
+ # Remember, each alternative MUST END IN *, to match a version number.
+ ;;
+ -qnx*)
+ case $basic_machine in
+ x86-* | i*86-*)
+ ;;
+ *)
+ os=-nto$os
+ ;;
+ esac
+ ;;
+ -nto-qnx*)
+ ;;
+ -nto*)
+ os=`echo $os | sed -e 's|nto|nto-qnx|'`
+ ;;
+ -sim | -es1800* | -hms* | -xray | -os68k* | -none* | -v88r* \
+ | -windows* | -osx | -abug | -netware* | -os9* | -beos* | -haiku* \
+ | -macos* | -mpw* | -magic* | -mmixware* | -mon960* | -lnews*)
+ ;;
+ -mac*)
+ os=`echo $os | sed -e 's|mac|macos|'`
+ ;;
+ -linux-dietlibc)
+ os=-linux-dietlibc
+ ;;
+ -linux*)
+ os=`echo $os | sed -e 's|linux|linux-gnu|'`
+ ;;
+ -sunos5*)
+ os=`echo $os | sed -e 's|sunos5|solaris2|'`
+ ;;
+ -sunos6*)
+ os=`echo $os | sed -e 's|sunos6|solaris3|'`
+ ;;
+ -opened*)
+ os=-openedition
+ ;;
+ -os400*)
+ os=-os400
+ ;;
+ -wince*)
+ os=-wince
+ ;;
+ -osfrose*)
+ os=-osfrose
+ ;;
+ -osf*)
+ os=-osf
+ ;;
+ -utek*)
+ os=-bsd
+ ;;
+ -dynix*)
+ os=-bsd
+ ;;
+ -acis*)
+ os=-aos
+ ;;
+ -atheos*)
+ os=-atheos
+ ;;
+ -syllable*)
+ os=-syllable
+ ;;
+ -386bsd)
+ os=-bsd
+ ;;
+ -ctix* | -uts*)
+ os=-sysv
+ ;;
+ -nova*)
+ os=-rtmk-nova
+ ;;
+ -ns2 )
+ os=-nextstep2
+ ;;
+ -nsk*)
+ os=-nsk
+ ;;
+ # Preserve the version number of sinix5.
+ -sinix5.*)
+ os=`echo $os | sed -e 's|sinix|sysv|'`
+ ;;
+ -sinix*)
+ os=-sysv4
+ ;;
+ -tpf*)
+ os=-tpf
+ ;;
+ -triton*)
+ os=-sysv3
+ ;;
+ -oss*)
+ os=-sysv3
+ ;;
+ -svr4)
+ os=-sysv4
+ ;;
+ -svr3)
+ os=-sysv3
+ ;;
+ -sysvr4)
+ os=-sysv4
+ ;;
+ # This must come after -sysvr4.
+ -sysv*)
+ ;;
+ -ose*)
+ os=-ose
+ ;;
+ -es1800*)
+ os=-ose
+ ;;
+ -xenix)
+ os=-xenix
+ ;;
+ -*mint | -mint[0-9]* | -*MiNT | -MiNT[0-9]*)
+ os=-mint
+ ;;
+ -aros*)
+ os=-aros
+ ;;
+ -zvmoe)
+ os=-zvmoe
+ ;;
+ -dicos*)
+ os=-dicos
+ ;;
+ -nacl*)
+ ;;
+ -none)
+ ;;
+ *)
+ # Get rid of the `-' at the beginning of $os.
+ os=`echo $os | sed 's/[^-]*-//'`
+ echo Invalid configuration \`$1\': system \`$os\' not recognized 1>&2
+ exit 1
+ ;;
+esac
+else
+
+# Here we handle the default operating systems that come with various machines.
+# The value should be what the vendor currently ships out the door with their
+# machine or put another way, the most popular os provided with the machine.
+
+# Note that if you're going to try to match "-MANUFACTURER" here (say,
+# "-sun"), then you have to tell the case statement up towards the top
+# that MANUFACTURER isn't an operating system. Otherwise, code above
+# will signal an error saying that MANUFACTURER isn't an operating
+# system, and we'll never get to this point.
+
+case $basic_machine in
+ score-*)
+ os=-elf
+ ;;
+ spu-*)
+ os=-elf
+ ;;
+ *-acorn)
+ os=-riscix1.2
+ ;;
+ arm*-rebel)
+ os=-linux
+ ;;
+ arm*-semi)
+ os=-aout
+ ;;
+ c4x-* | tic4x-*)
+ os=-coff
+ ;;
+ c8051-*)
+ os=-elf
+ ;;
+ hexagon-*)
+ os=-elf
+ ;;
+ tic54x-*)
+ os=-coff
+ ;;
+ tic55x-*)
+ os=-coff
+ ;;
+ tic6x-*)
+ os=-coff
+ ;;
+ # This must come before the *-dec entry.
+ pdp10-*)
+ os=-tops20
+ ;;
+ pdp11-*)
+ os=-none
+ ;;
+ *-dec | vax-*)
+ os=-ultrix4.2
+ ;;
+ m68*-apollo)
+ os=-domain
+ ;;
+ i386-sun)
+ os=-sunos4.0.2
+ ;;
+ m68000-sun)
+ os=-sunos3
+ ;;
+ m68*-cisco)
+ os=-aout
+ ;;
+ mep-*)
+ os=-elf
+ ;;
+ mips*-cisco)
+ os=-elf
+ ;;
+ mips*-*)
+ os=-elf
+ ;;
+ or1k-*)
+ os=-elf
+ ;;
+ or32-*)
+ os=-coff
+ ;;
+ *-tti) # must be before sparc entry or we get the wrong os.
+ os=-sysv3
+ ;;
+ sparc-* | *-sun)
+ os=-sunos4.1.1
+ ;;
+ *-be)
+ os=-beos
+ ;;
+ *-haiku)
+ os=-haiku
+ ;;
+ *-ibm)
+ os=-aix
+ ;;
+ *-knuth)
+ os=-mmixware
+ ;;
+ *-wec)
+ os=-proelf
+ ;;
+ *-winbond)
+ os=-proelf
+ ;;
+ *-oki)
+ os=-proelf
+ ;;
+ *-hp)
+ os=-hpux
+ ;;
+ *-hitachi)
+ os=-hiux
+ ;;
+ i860-* | *-att | *-ncr | *-altos | *-motorola | *-convergent)
+ os=-sysv
+ ;;
+ *-cbm)
+ os=-amigaos
+ ;;
+ *-dg)
+ os=-dgux
+ ;;
+ *-dolphin)
+ os=-sysv3
+ ;;
+ m68k-ccur)
+ os=-rtu
+ ;;
+ m88k-omron*)
+ os=-luna
+ ;;
+ *-next )
+ os=-nextstep
+ ;;
+ *-sequent)
+ os=-ptx
+ ;;
+ *-crds)
+ os=-unos
+ ;;
+ *-ns)
+ os=-genix
+ ;;
+ i370-*)
+ os=-mvs
+ ;;
+ *-next)
+ os=-nextstep3
+ ;;
+ *-gould)
+ os=-sysv
+ ;;
+ *-highlevel)
+ os=-bsd
+ ;;
+ *-encore)
+ os=-bsd
+ ;;
+ *-sgi)
+ os=-irix
+ ;;
+ *-siemens)
+ os=-sysv4
+ ;;
+ *-masscomp)
+ os=-rtu
+ ;;
+ f30[01]-fujitsu | f700-fujitsu)
+ os=-uxpv
+ ;;
+ *-rom68k)
+ os=-coff
+ ;;
+ *-*bug)
+ os=-coff
+ ;;
+ *-apple)
+ os=-macos
+ ;;
+ *-atari*)
+ os=-mint
+ ;;
+ *)
+ os=-none
+ ;;
+esac
+fi
+
+# Here we handle the case where we know the os, and the CPU type, but not the
+# manufacturer. We pick the logical manufacturer.
+vendor=unknown
+case $basic_machine in
+ *-unknown)
+ case $os in
+ -riscix*)
+ vendor=acorn
+ ;;
+ -sunos*)
+ vendor=sun
+ ;;
+ -cnk*|-aix*)
+ vendor=ibm
+ ;;
+ -beos*)
+ vendor=be
+ ;;
+ -hpux*)
+ vendor=hp
+ ;;
+ -mpeix*)
+ vendor=hp
+ ;;
+ -hiux*)
+ vendor=hitachi
+ ;;
+ -unos*)
+ vendor=crds
+ ;;
+ -dgux*)
+ vendor=dg
+ ;;
+ -luna*)
+ vendor=omron
+ ;;
+ -genix*)
+ vendor=ns
+ ;;
+ -mvs* | -opened*)
+ vendor=ibm
+ ;;
+ -os400*)
+ vendor=ibm
+ ;;
+ -ptx*)
+ vendor=sequent
+ ;;
+ -tpf*)
+ vendor=ibm
+ ;;
+ -vxsim* | -vxworks* | -windiss*)
+ vendor=wrs
+ ;;
+ -aux*)
+ vendor=apple
+ ;;
+ -hms*)
+ vendor=hitachi
+ ;;
+ -mpw* | -macos*)
+ vendor=apple
+ ;;
+ -*mint | -mint[0-9]* | -*MiNT | -MiNT[0-9]*)
+ vendor=atari
+ ;;
+ -vos*)
+ vendor=stratus
+ ;;
+ esac
+ basic_machine=`echo $basic_machine | sed "s/unknown/$vendor/"`
+ ;;
+esac
+
+echo $basic_machine$os
+exit
+
+# Local variables:
+# eval: (add-hook 'write-file-hooks 'time-stamp)
+# time-stamp-start: "timestamp='"
+# time-stamp-format: "%:y-%02m-%02d"
+# time-stamp-end: "'"
+# End:
diff --git a/jni/native/build/find_apr.m4 b/jni/native/build/find_apr.m4
new file mode 100644
index 0000000..925e523
--- /dev/null
+++ b/jni/native/build/find_apr.m4
@@ -0,0 +1,202 @@
+dnl -------------------------------------------------------- -*- autoconf -*-
+dnl Licensed to the Apache Software Foundation (ASF) under one or more
+dnl contributor license agreements. See the NOTICE file distributed with
+dnl this work for additional information regarding copyright ownership.
+dnl The ASF licenses this file to You under the Apache License, Version 2.0
+dnl (the "License"); you may not use this file except in compliance with
+dnl the License. You may obtain a copy of the License at
+dnl
+dnl http://www.apache.org/licenses/LICENSE-2.0
+dnl
+dnl Unless required by applicable law or agreed to in writing, software
+dnl distributed under the License is distributed on an "AS IS" BASIS,
+dnl WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+dnl See the License for the specific language governing permissions and
+dnl limitations under the License.
+
+dnl
+dnl find_apr.m4 : locate the APR include files and libraries
+dnl
+dnl This macro file can be used by applications to find and use the APR
+dnl library. It provides a standardized mechanism for using APR. It supports
+dnl embedding APR into the application source, or locating an installed
+dnl copy of APR.
+dnl
+dnl APR_FIND_APR(srcdir, builddir, implicit-install-check, acceptable-majors,
+dnl detailed-check)
+dnl
+dnl where srcdir is the location of the bundled APR source directory, or
+dnl empty if source is not bundled.
+dnl
+dnl where builddir is the location where the bundled APR will will be built,
+dnl or empty if the build will occur in the srcdir.
+dnl
+dnl where implicit-install-check set to 1 indicates if there is no
+dnl --with-apr option specified, we will look for installed copies.
+dnl
+dnl where acceptable-majors is a space separated list of acceptable major
+dnl version numbers. Often only a single major version will be acceptable.
+dnl If multiple versions are specified, and --with-apr=PREFIX or the
+dnl implicit installed search are used, then the first (leftmost) version
+dnl in the list that is found will be used. Currently defaults to [0 1].
+dnl
+dnl where detailed-check is an M4 macro which sets the apr_acceptable to
+dnl either "yes" or "no". The macro will be invoked for each installed
+dnl copy of APR found, with the apr_config variable set appropriately.
+dnl Only installed copies of APR which are considered acceptable by
+dnl this macro will be considered found. If no installed copies are
+dnl considered acceptable by this macro, apr_found will be set to either
+dnl either "no" or "reconfig".
+dnl
+dnl Sets the following variables on exit:
+dnl
+dnl apr_found : "yes", "no", "reconfig"
+dnl
+dnl apr_config : If the apr-config tool exists, this refers to it. If
+dnl apr_found is "reconfig", then the bundled directory
+dnl should be reconfigured *before* using apr_config.
+dnl
+dnl Note: this macro file assumes that apr-config has been installed; it
+dnl is normally considered a required part of an APR installation.
+dnl
+dnl If a bundled source directory is available and needs to be (re)configured,
+dnl then apr_found is set to "reconfig". The caller should reconfigure the
+dnl (passed-in) source directory, placing the result in the build directory,
+dnl as appropriate.
+dnl
+dnl If apr_found is "yes" or "reconfig", then the caller should use the
+dnl value of apr_config to fetch any necessary build/link information.
+dnl
+
+AC_DEFUN([APR_FIND_APR], [
+ apr_found="no"
+
+ if test "$target_os" = "os2-emx"; then
+ # Scripts don't pass test -x on OS/2
+ TEST_X="test -f"
+ else
+ TEST_X="test -x"
+ fi
+
+ ifelse([$4], [], [
+ ifdef(AC_WARNING,AC_WARNING([$0: missing argument 4 (acceptable-majors): Defaulting to APR 0.x then APR 1.x]))
+ acceptable_majors="0 1"],
+ [acceptable_majors="$4"])
+
+ apr_temp_acceptable_apr_config=""
+ for apr_temp_major in $acceptable_majors
+ do
+ case $apr_temp_major in
+ 0)
+ apr_temp_acceptable_apr_config="$apr_temp_acceptable_apr_config apr-config"
+ ;;
+ *)
+ apr_temp_acceptable_apr_config="$apr_temp_acceptable_apr_config apr-$apr_temp_major-config"
+ ;;
+ esac
+ done
+
+ AC_MSG_CHECKING(for APR)
+ AC_ARG_WITH(apr,
+ [ --with-apr=PATH prefix for installed APR or the full path to
+ apr-config],
+ [
+ if test "$withval" = "no" || test "$withval" = "yes"; then
+ AC_MSG_ERROR([--with-apr requires a directory or file to be provided])
+ fi
+
+ for apr_temp_apr_config_file in $apr_temp_acceptable_apr_config
+ do
+ for lookdir in "$withval/bin" "$withval"
+ do
+ if $TEST_X "$lookdir/$apr_temp_apr_config_file"; then
+ apr_config="$lookdir/$apr_temp_apr_config_file"
+ ifelse([$5], [], [], [
+ apr_acceptable="yes"
+ $5
+ if test "$apr_acceptable" != "yes"; then
+ AC_MSG_WARN([Found APR in $apr_config, but we think it is considered unacceptable])
+ continue
+ fi])
+ apr_found="yes"
+ break 2
+ fi
+ done
+ done
+
+ if test "$apr_found" != "yes" && $TEST_X "$withval" && $withval --help > /dev/null 2>&1 ; then
+ apr_config="$withval"
+ ifelse([$5], [], [apr_found="yes"], [
+ apr_acceptable="yes"
+ $5
+ if test "$apr_acceptable" = "yes"; then
+ apr_found="yes"
+ fi])
+ fi
+
+ dnl if --with-apr is used, it is a fatal error for its argument
+ dnl to be invalid
+ if test "$apr_found" != "yes"; then
+ AC_MSG_ERROR([the --with-apr parameter is incorrect. It must specify an install prefix, a build directory, or an apr-config file.])
+ fi
+ ],[
+ dnl If we allow installed copies, check those before using bundled copy.
+ if test -n "$3" && test "$3" = "1"; then
+ for apr_temp_apr_config_file in $apr_temp_acceptable_apr_config
+ do
+ if $apr_temp_apr_config_file --help > /dev/null 2>&1 ; then
+ apr_config="$apr_temp_apr_config_file"
+ ifelse([$5], [], [], [
+ apr_acceptable="yes"
+ $5
+ if test "$apr_acceptable" != "yes"; then
+ AC_MSG_WARN([skipped APR at $apr_config, version not acceptable])
+ continue
+ fi])
+ apr_found="yes"
+ break
+ else
+ dnl look in some standard places
+ for lookdir in /usr /usr/local /usr/local/apr /opt/apr; do
+ if $TEST_X "$lookdir/bin/$apr_temp_apr_config_file"; then
+ apr_config="$lookdir/bin/$apr_temp_apr_config_file"
+ ifelse([$5], [], [], [
+ apr_acceptable="yes"
+ $5
+ if test "$apr_acceptable" != "yes"; then
+ AC_MSG_WARN([skipped APR at $apr_config, version not acceptable])
+ continue
+ fi])
+ apr_found="yes"
+ break 2
+ fi
+ done
+ fi
+ done
+ fi
+ dnl if we have not found anything yet and have bundled source, use that
+ if test "$apr_found" = "no" && test -d "$1"; then
+ apr_temp_abs_srcdir="`cd \"$1\" && pwd`"
+ apr_found="reconfig"
+ apr_bundled_major="`sed -n '/#define.*APR_MAJOR_VERSION/s/^[^0-9]*\([0-9]*\).*$/\1/p' \"$1/include/apr_version.h\"`"
+ case $apr_bundled_major in
+ "")
+ AC_MSG_ERROR([failed to find major version of bundled APR])
+ ;;
+ 0)
+ apr_temp_apr_config_file="apr-config"
+ ;;
+ *)
+ apr_temp_apr_config_file="apr-$apr_bundled_major-config"
+ ;;
+ esac
+ if test -n "$2"; then
+ apr_config="$2/$apr_temp_apr_config_file"
+ else
+ apr_config="$1/$apr_temp_apr_config_file"
+ fi
+ fi
+ ])
+
+ AC_MSG_RESULT($apr_found)
+])
diff --git a/jni/native/build/get-version.sh b/jni/native/build/get-version.sh
new file mode 100755
index 0000000..6d45ce0
--- /dev/null
+++ b/jni/native/build/get-version.sh
@@ -0,0 +1,53 @@
+#!/bin/sh
+
+# 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.
+
+#
+# extract version numbers from a header file
+#
+# USAGE: get-version.sh CMD VERSION_HEADER PREFIX
+# where CMD is one of: all, major, libtool
+# where PREFIX is the prefix to {MAJOR|MINOR|PATCH}_VERSION defines
+#
+# get-version.sh all returns a dotted version number
+# get-version.sh major returns just the major version number
+# get-version.sh libtool returns a version "libtool -version-info" format
+#
+
+if test $# != 3; then
+ echo "USAGE: $0 CMD VERSION_HEADER PREFIX"
+ echo " where CMD is one of: all, major, libtool"
+ exit 1
+fi
+
+major_sed="/#define.*$3_MAJOR_VERSION/s/^[^0-9]*\([0-9]*\).*$/\1/p"
+minor_sed="/#define.*$3_MINOR_VERSION/s/^[^0-9]*\([0-9]*\).*$/\1/p"
+patch_sed="/#define.*$3_PATCH_VERSION/s/^[^0-9]*\([0-9]*\).*$/\1/p"
+major="`sed -n $major_sed $2`"
+minor="`sed -n $minor_sed $2`"
+patch="`sed -n $patch_sed $2`"
+
+if test "$1" = "all"; then
+ echo ${major}.${minor}.${patch}
+elif test "$1" = "major"; then
+ echo ${major}
+elif test "$1" = "libtool"; then
+ # Yes, ${minor}:${patch}:${minor} is correct due to libtool idiocy.
+ echo ${minor}:${patch}:${minor}
+else
+ echo "ERROR: unknown version CMD ($1)"
+ exit 1
+fi
diff --git a/jni/native/build/install.sh b/jni/native/build/install.sh
new file mode 100755
index 0000000..9a8821f
--- /dev/null
+++ b/jni/native/build/install.sh
@@ -0,0 +1,112 @@
+#!/bin/sh
+##
+## install.sh -- install a program, script or datafile
+##
+## Based on `install-sh' from the X Consortium's X11R5 distribution
+## as of 89/12/18 which is freely available.
+## Cleaned up for Apache's Autoconf-style Interface (APACI)
+## by Ralf S. Engelschall <rse at apache.org>
+##
+#
+# This script falls under the Apache License.
+# See http://www.apache.org/docs/LICENSE
+
+
+#
+# put in absolute paths if you don't have them in your path;
+# or use env. vars.
+#
+mvprog="${MVPROG-mv}"
+cpprog="${CPPROG-cp}"
+chmodprog="${CHMODPROG-chmod}"
+chownprog="${CHOWNPROG-chown}"
+chgrpprog="${CHGRPPROG-chgrp}"
+stripprog="${STRIPPROG-strip}"
+rmprog="${RMPROG-rm}"
+
+#
+# parse argument line
+#
+instcmd="$mvprog"
+chmodcmd=""
+chowncmd=""
+chgrpcmd=""
+stripcmd=""
+rmcmd="$rmprog -f"
+mvcmd="$mvprog"
+ext=""
+src=""
+dst=""
+while [ "x$1" != "x" ]; do
+ case $1 in
+ -c) instcmd="$cpprog"
+ shift; continue
+ ;;
+ -m) chmodcmd="$chmodprog $2"
+ shift; shift; continue
+ ;;
+ -o) chowncmd="$chownprog $2"
+ shift; shift; continue
+ ;;
+ -g) chgrpcmd="$chgrpprog $2"
+ shift; shift; continue
+ ;;
+ -s) stripcmd="$stripprog"
+ shift; continue
+ ;;
+ -S) stripcmd="$stripprog $2"
+ shift; shift; continue
+ ;;
+ -e) ext="$2"
+ shift; shift; continue
+ ;;
+ *) if [ "x$src" = "x" ]; then
+ src=$1
+ else
+ dst=$1
+ fi
+ shift; continue
+ ;;
+ esac
+done
+if [ "x$src" = "x" ]; then
+ echo "install.sh: no input file specified"
+ exit 1
+fi
+if [ "x$dst" = "x" ]; then
+ echo "install.sh: no destination specified"
+ exit 1
+fi
+
+#
+# If destination is a directory, append the input filename; if
+# your system does not like double slashes in filenames, you may
+# need to add some logic
+#
+if [ -d $dst ]; then
+ dst="$dst/`basename $src`"
+fi
+
+# Add a possible extension (such as ".exe") to src and dst
+src="$src$ext"
+dst="$dst$ext"
+
+# Make a temp file name in the proper directory.
+dstdir=`dirname $dst`
+dsttmp=$dstdir/#inst.$$#
+
+# Move or copy the file name to the temp name
+$instcmd $src $dsttmp
+
+# And set any options; do chmod last to preserve setuid bits
+if [ "x$chowncmd" != "x" ]; then $chowncmd $dsttmp; fi
+if [ "x$chgrpcmd" != "x" ]; then $chgrpcmd $dsttmp; fi
+if [ "x$stripcmd" != "x" ]; then $stripcmd $dsttmp; fi
+if [ "x$chmodcmd" != "x" ]; then $chmodcmd $dsttmp; fi
+
+# Now rename the file to the real destination.
+$rmcmd $dst
+$mvcmd $dsttmp $dst
+
+exit 0
+
diff --git a/jni/native/build/lineends.pl b/jni/native/build/lineends.pl
new file mode 100755
index 0000000..f61fa64
--- /dev/null
+++ b/jni/native/build/lineends.pl
@@ -0,0 +1,165 @@
+#!/usr/local/bin/perl
+
+# 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.
+
+#
+# Heuristically converts line endings to the current OS's preferred format
+#
+# All existing line endings must be identical (e.g. lf's only, or even
+# the accedental cr.cr.lf sequence.) If some lines end lf, and others as
+# cr.lf, the file is presumed binary. If the cr character appears anywhere
+# except prefixed to an lf, the file is presumed binary. If there is no
+# change in the resulting file size, or the file is binary, the conversion
+# is discarded.
+#
+# Todo: Handle NULL stdin characters gracefully.
+#
+
+use IO::File;
+use File::Find;
+
+# The ignore list is '-' separated, with this leading hyphen and
+# trailing hyphens in ever concatinated list below.
+$ignore = "-";
+
+# Image formats
+$ignore .= "gif-jpg-jpeg-png-ico-bmp-";
+
+# Archive formats
+$ignore .= "tar-gz-z-zip-jar-war-bz2-tgz-";
+
+# Many document formats
+$ignore .= "eps-psd-pdf-ai-";
+
+# Some encodings
+$ignore .= "ucs2-ucs4-";
+
+# Some binary objects
+$ignore .= "class-so-dll-exe-obj-a-o-lo-slo-sl-dylib-";
+
+# Some build env files
+$ignore .= "mcp-xdc-ncb-opt-pdb-ilk-sbr-";
+
+$preservedate = 1;
+
+$forceending = 0;
+
+$givenpaths = 0;
+
+$notnative = 0;
+
+while (defined @ARGV[0]) {
+ if (@ARGV[0] eq '--touch') {
+ $preservedate = 0;
+ }
+ elsif (@ARGV[0] eq '--nocr') {
+ $notnative = -1;
+ }
+ elsif (@ARGV[0] eq '--cr') {
+ $notnative = 1;
+ }
+ elsif (@ARGV[0] eq '--force') {
+ $forceending = 1;
+ }
+ elsif (@ARGV[0] eq '--FORCE') {
+ $forceending = 2;
+ }
+ elsif (@ARGV[0] =~ m/^-/) {
+ die "What is " . @ARGV[0] . " supposed to mean?\n\n"
+ . "Syntax:\t$0 [option()s] [path(s)]\n\n" . <<'OUTCH'
+Where: paths specifies the top level directory to convert (default of '.')
+ options are;
+
+ --cr keep/add one ^M
+ --nocr remove ^M's
+ --touch the datestamp (default: keeps date/attribs)
+ --force mismatched corrections (unbalanced ^M's)
+ --FORCE all files regardless of file name!
+
+OUTCH
+ }
+ else {
+ find(\&totxt, @ARGV[0]);
+ print "scanned " . @ARGV[0] . "\n";
+ $givenpaths = 1;
+ }
+ shift @ARGV;
+}
+
+if (!$givenpaths) {
+ find(\&totxt, '.');
+ print "did .\n";
+}
+
+sub totxt {
+ $oname = $_;
+ $tname = '.#' . $_;
+ if (!-f) {
+ return;
+ }
+ @exts = split /\./;
+ if ($forceending < 2) {
+ while ($#exts && ($ext = pop(@exts))) {
+ if ($ignore =~ m|-$ext-|i) {
+ return;
+ }
+ }
+ }
+ @ostat = stat($oname);
+ $srcfl = new IO::File $oname, "r" or die;
+ $dstfl = new IO::File $tname, "w" or die;
+ binmode $srcfl;
+ if ($notnative) {
+ binmode $dstfl;
+ }
+ undef $t;
+ while (<$srcfl>) {
+ if (s/(\r*)\n$/\n/) {
+ $n = length $1;
+ if (!defined $t) {
+ $t = $n;
+ }
+ if (!$forceending && (($n != $t) || m/\r/)) {
+ print "mismatch in " .$oname. ":" .$n. " expected " .$t. "\n";
+ undef $t;
+ last;
+ }
+ elsif ($notnative > 0) {
+ s/\n$/\r\n/;
+ }
+ }
+ print $dstfl $_;
+ }
+ if (defined $t && (tell $srcfl == tell $dstfl)) {
+ undef $t;
+ }
+ undef $srcfl;
+ undef $dstfl;
+ if (defined $t) {
+ unlink $oname or die;
+ rename $tname, $oname or die;
+ @anames = ($oname);
+ if ($preservedate) {
+ utime $ostat[9], $ostat[9], @anames;
+ }
+ chmod $ostat[2] & 07777, @anames;
+ chown $ostat[5], $ostat[6], @anames;
+ print "Converted file " . $oname . " to text in " . $File::Find::dir . "\n";
+ }
+ else {
+ unlink $tname or die;
+ }
+}
diff --git a/jni/native/build/mkdir.sh b/jni/native/build/mkdir.sh
new file mode 100755
index 0000000..eb6b51e
--- /dev/null
+++ b/jni/native/build/mkdir.sh
@@ -0,0 +1,52 @@
+#!/bin/sh
+
+#
+# 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.
+#
+
+##
+## mkdir.sh -- make directory hierarchy
+##
+## Based on `mkinstalldirs' from Noah Friedman <friedman at prep.ai.mit.edu>
+## as of 1994-03-25, which was placed in the Public Domain.
+## Cleaned up for Apache's Autoconf-style Interface (APACI)
+## by Ralf S. Engelschall <rse at apache.org>
+##
+
+
+umask 022
+errstatus=0
+for file in ${1+"$@"} ; do
+ set fnord `echo ":$file" |\
+ sed -e 's/^:\//%/' -e 's/^://' -e 's/\// /g' -e 's/^%/\//'`
+ shift
+ pathcomp=
+ for d in ${1+"$@"}; do
+ pathcomp="$pathcomp$d"
+ case "$pathcomp" in
+ -* ) pathcomp=./$pathcomp ;;
+ ?: ) pathcomp="$pathcomp/"
+ continue ;;
+ esac
+ if test ! -d "$pathcomp"; then
+ echo "mkdir $pathcomp" 1>&2
+ mkdir "$pathcomp" || errstatus=$?
+ fi
+ pathcomp="$pathcomp/"
+ done
+done
+exit $errstatus
+
diff --git a/jni/native/build/rpm/tcnative.spec.in b/jni/native/build/rpm/tcnative.spec.in
new file mode 100644
index 0000000..8f1d4b5
--- /dev/null
+++ b/jni/native/build/rpm/tcnative.spec.in
@@ -0,0 +1,97 @@
+#
+# 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.
+#
+
+%define tcnver 1
+%define aprver 1
+
+Summary: Tomcat Native Java library
+Name: tcnative
+Version: TCN_VERSION
+Release: TCN_RELEASE
+License: Apache Software License
+Group: System Environment/Libraries
+URL: http://apr.apache.org/
+Source0: %{name}-%{version}.tar.gz
+BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-buildroot
+BuildPrereq: autoconf, libtool, doxygen, apr-devel >= 0:{version}-{release}, openssl >= 0.9.7
+
+%description
+The mission of the Tomcat Native Library (TCN) is to provide a
+free library of C data structures and routines. This library
+contains additional utility interfaces for Java.
+
+%package devel
+Group: Development/Libraries
+Summary: Tomcat Native development kit
+Requires: tcnative = %{version}-%{release}, apr-devel >= 0:{version}-{release}, openssl-devel >= 0.9.7
+
+%description devel
+The mission of the Tomcat Native Library (TCN) is to provide a
+free library of C data structures and routines. This library
+contains additional utility interfaces for Java.
+
+%prep
+%setup -q
+
+%build
+%configure --with-apr=%{_prefix} \
+ --includedir=%{_includedir}/apr-%{aprver}
+make %{?_smp_mflags} && make dox
+
+%check
+# Run non-interactive tests
+pushd test
+make %{?_smp_mflags} testall CFLAGS=-fno-strict-aliasing
+./testall -v || exit 1
+popd
+
+%install
+rm -rf $RPM_BUILD_ROOT
+make install DESTDIR=$RPM_BUILD_ROOT
+
+# Documentation
+mv docs/dox/html html
+
+# Unpackaged files
+rm -f $RPM_BUILD_ROOT%{_libdir}/tcnative.exp
+
+%clean
+rm -rf $RPM_BUILD_ROOT
+
+%post -p /sbin/ldconfig
+
+%postun -p /sbin/ldconfig
+
+%files
+%defattr(-,root,root,-)
+%doc CHANGES LICENSE NOTICE
+%{_libdir}/libtcnative-%{tcnver}.so.*
+
+%files devel
+%defattr(-,root,root,-)
+%{_libdir}/libtcnative-%{tcnver}.*a
+%{_libdir}/libtcnative-%{tcnver}.so
+%{_libdir}/pkgconfig/tcnative-%{tcnver}.pc
+%{_includedir}/apr-%{aprver}/*.h
+%doc --parents html
+
+%changelog
+* Mon Jan 04 2010 Rainer Jung <rjung at apache.org> 1.0.0-2
+- Decouple apr major lib version form tcnative lib version
+* Tue Jun 22 2004 Mladen Turk <mturk at jboss.com> 1.0.0-1
+- update to support v1.0.2 of APR
+
diff --git a/jni/native/build/tcnative.m4 b/jni/native/build/tcnative.m4
new file mode 100644
index 0000000..17d8bec
--- /dev/null
+++ b/jni/native/build/tcnative.m4
@@ -0,0 +1,413 @@
+#
+# 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.
+#
+
+dnl
+dnl TCN_FIND_APR: figure out where APR is located
+dnl
+AC_DEFUN(TCN_FIND_APR,[
+
+ dnl use the find_apr.m4 script to locate APR. sets apr_found and apr_config
+ APR_FIND_APR(,,,[1])
+ if test "$apr_found" = "no"; then
+ AC_MSG_ERROR(APR could not be located. Please use the --with-apr option.)
+ fi
+
+ sapr_pversion="`$apr_config --version`"
+ if test -z "$sapr_pversion"; then
+ AC_MSG_ERROR(APR config could not be located. Please use the --with-apr option.)
+ fi
+ sapr_version="`echo $sapr_pversion|sed -e 's/\([a-z]*\)$/.\1/'`"
+ tc_save_IFS=$IFS; IFS=.; set $sapr_version; IFS=$tc_save_IFS
+ if test "${1}" -lt "1"; then
+ AC_MSG_ERROR(You need APR version 1.2.1 or newer installed. For optimal performance version 1.3.0 or newer is needed.)
+ else
+ if test "${2}" -lt "2"; then
+ AC_MSG_ERROR(You need APR version 1.2.1 or newer installed. For optimal performance version 1.3.0 or newer is needed.)
+ elif test "${2}" -lt "3"; then
+ AC_MSG_WARN(For optimal performance you need APR version 1.3.0 or newer installed.)
+ fi
+ fi
+
+ APR_BUILD_DIR="`$apr_config --installbuilddir`"
+
+ dnl make APR_BUILD_DIR an absolute directory (we'll need it in the
+ dnl sub-projects in some cases)
+ APR_BUILD_DIR="`cd $APR_BUILD_DIR && pwd`"
+
+ APR_INCLUDES="`$apr_config --includes`"
+ APR_LIBS="`$apr_config --link-libtool --libs`"
+ APR_SO_EXT="`$apr_config --apr-so-ext`"
+ APR_LIB_TARGET="`$apr_config --apr-lib-target`"
+
+ AC_SUBST(APR_INCLUDES)
+ AC_SUBST(APR_LIBS)
+ AC_SUBST(APR_BUILD_DIR)
+])
+
+dnl --------------------------------------------------------------------------
+dnl TCN_JDK
+dnl
+dnl Detection of JDK location and Java Platform (1.2, 1.3, 1.4, 1.5, 1.6)
+dnl result goes in JAVA_HOME / JAVA_PLATFORM (2 -> 1.2 and higher)
+dnl
+dnl --------------------------------------------------------------------------
+AC_DEFUN(
+ [TCN_FIND_JDK],
+ [
+ tempval=""
+ AC_MSG_CHECKING([for JDK location (please wait)])
+ if test -n "${JAVA_HOME}" ; then
+ JAVA_HOME_ENV="${JAVA_HOME}"
+ else
+ JAVA_HOME_ENV=""
+ fi
+
+ JAVA_HOME=""
+ JAVA_PLATFORM=""
+
+ AC_ARG_WITH(
+ [java-home],
+ [ --with-java-home=DIR Location of JDK directory.],
+ [
+
+ # This stuff works if the command line parameter --with-java-home was
+ # specified, so it takes priority rightfully.
+
+ tempval=${withval}
+
+ if test ! -d "${tempval}" ; then
+ AC_MSG_ERROR(Not a directory: ${tempval})
+ fi
+
+ JAVA_HOME=${tempval}
+ AC_MSG_RESULT(${JAVA_HOME})
+ ],
+ [
+ # This works if the parameter was NOT specified, so it's a good time
+ # to see what the environment says.
+ # Since Sun uses JAVA_HOME a lot, we check it first and ignore the
+ # JAVA_HOME, otherwise just use whatever JAVA_HOME was specified.
+
+ if test -n "${JAVA_HOME_ENV}" ; then
+ JAVA_HOME=${JAVA_HOME_ENV}
+ AC_MSG_RESULT(${JAVA_HOME_ENV} from environment)
+ fi
+ ])
+
+ if test -z "${JAVA_HOME}" ; then
+
+ # Oh well, nobody set neither JAVA_HOME nor JAVA_HOME, have to guess
+ # The following code is based on the code submitted by Henner Zeller
+ # for ${srcdir}/src/scripts/package/rpm/ApacheJServ.spec
+ # Two variables will be set as a result:
+ #
+ # JAVA_HOME
+ # JAVA_PLATFORM
+ AC_MSG_CHECKING([Try to guess JDK location])
+
+ for JAVA_PREFIX in /usr/local /usr/local/lib /usr /usr/lib /opt /usr/java /System/Library/Frameworks/JavaVM.framework/Versions
+ do
+ for JAVA_PLATFORM in 8 7 6 5 4 3 2
+ do
+ for subversion in .9 .8 .7 .6 .5 .4 .3 .2 .1 .0 ""
+ do
+ for VARIANT in IBMJava2- diablo-jdk java java- jdk jdk- ""
+ do
+ GUESS="${JAVA_PREFIX}/${VARIANT}1.${JAVA_PLATFORM}${subversion}"
+ if test -d "${GUESS}/bin" & test -d "${GUESS}/include"
+ then
+ JAVA_HOME="${GUESS}"
+ AC_MSG_RESULT([${GUESS}])
+ break
+ fi
+ if test -d "${GUESS}/Commands" & test -d "${GUESS}/Headers"
+ then
+ JAVA_HOME="${GUESS}"
+ AC_MSG_RESULT([${GUESS}])
+ break
+ fi
+
+ done
+
+ if test -n "${JAVA_HOME}" ; then
+ break;
+ fi
+
+ done
+
+ if test -n "${JAVA_HOME}" ; then
+ break;
+ fi
+
+ done
+
+ if test -n "${JAVA_HOME}" ; then
+ break;
+ fi
+
+ done
+
+ if test ! -n "${JAVA_HOME}" ; then
+ AC_MSG_ERROR(can't locate a valid JDK location)
+ fi
+
+ fi
+
+ if test -n "${JAVA_PLATFORM}"; then
+ AC_MSG_RESULT(Java Platform detected - 1.${JAVA_PLATFORM})
+ else
+ AC_MSG_CHECKING(Java platform)
+ fi
+
+ AC_ARG_WITH(java-platform,
+ [ --with-java-platform[=2] Force the Java platform
+ (value is 1 for 1.1.x or 2 for 1.2.x or greater)],
+ [
+ case "${withval}" in
+ "1"|"2")
+ JAVA_PLATFORM=${withval}
+ ;;
+ *)
+ AC_MSG_ERROR(invalid java platform provided)
+ ;;
+ esac
+ ],
+ [
+ if test -n "${JAVA_PLATFORM}"; then
+ AC_MSG_RESULT(Java Platform detected - 1.${JAVA_PLATFORM})
+ else
+ AC_MSG_CHECKING(Java platform)
+ fi
+ ])
+
+ AC_MSG_RESULT(${JAVA_PLATFORM})
+
+ unset tempval
+ ])
+
+
+AC_DEFUN(
+ [TCN_FIND_JDK_OS],
+ [
+ tempval=""
+ JAVA_OS=""
+ AC_ARG_WITH(os-type,
+ [ --with-os-type[=SUBDIR] Location of JDK os-type subdirectory.],
+ [
+ tempval=${withval}
+
+ if test ! -d "${JAVA_HOME}/${tempval}" ; then
+ AC_MSG_ERROR(Not a directory: ${JAVA_HOME}/${tempval})
+ fi
+
+ JAVA_OS = ${tempval}
+ ],
+ [
+ AC_MSG_CHECKING(os_type directory)
+ JAVA_OS=NONE
+ if test -f ${JAVA_HOME}/${JAVA_INC}/jni_md.h; then
+ JAVA_OS=""
+ else
+ for f in ${JAVA_HOME}/${JAVA_INC}/*/jni_md.h; do
+ if test -f $f; then
+ JAVA_OS=`dirname ${f}`
+ JAVA_OS=`basename ${JAVA_OS}`
+ echo " ${JAVA_OS}"
+ fi
+ done
+ if test "${JAVA_OS}" = "NONE"; then
+ AC_MSG_RESULT(Cannot find jni_md.h in ${JAVA_HOME}/${OS})
+ AC_MSG_ERROR(You should retry --with-os-type=SUBDIR)
+ fi
+ fi
+ ])
+ ])
+
+dnl check for sableVM
+dnl (copied from daemon/src/native/unix/support/apjava.m4)
+AC_DEFUN(
+ [TCN_SABLEVM],
+ [
+ if test x"$JAVA_HOME" != x
+ then
+ AC_PATH_PROG(SABLEVM,sablevm,NONE,$JAVA_HOME/bin)
+ if test "$SABLEVM" != "NONE"
+ then
+ AC_MSG_RESULT([Using sableVM: $SABLEVM])
+ CFLAGS="$CFLAGS -DHAVE_SABLEVM"
+ NEED_JNI_MD=no
+ fi
+ fi
+ ])
+dnl check for IBM J9VM
+AC_DEFUN(
+ [TCN_J9VM],
+ [
+ if test x"$JAVA_HOME" != x
+ then
+ J9VM=`$JAVA_HOME/bin/java -version 2>&1 | grep J9VM`
+ if test x"$J9VM" != x
+ then
+ AC_MSG_RESULT([Using J9VM: $J9VM])
+ NEED_JNI_MD=no
+ fi
+ fi
+ ])
+
+dnl TCN_HELP_STRING(LHS, RHS)
+dnl Autoconf 2.50 can not handle substr correctly. It does have
+dnl AC_HELP_STRING, so let's try to call it if we can.
+dnl Note: this define must be on one line so that it can be properly returned
+dnl as the help string.
+AC_DEFUN(TCN_HELP_STRING,[ifelse(regexp(AC_ACVERSION, 2\.1), -1, AC_HELP_STRING($1,$2),[ ]$1 substr([ ],len($1))$2)])dnl
+
+dnl
+dnl TCN_CHECK_SSL_TOOLKIT
+dnl
+dnl Configure for the detected openssl toolkit installation, giving
+dnl preference to "--with-ssl=<path>" if it was specified.
+dnl
+AC_DEFUN(TCN_CHECK_SSL_TOOLKIT,[
+OPENSSL_WARNING=
+AC_MSG_CHECKING(for OpenSSL library)
+AC_ARG_WITH(ssl,
+[ --with-ssl[=PATH] Build with OpenSSL [yes|no|path]],
+ use_openssl="$withval", use_openssl="auto")
+
+openssldirs="/usr /usr/local /usr/local/ssl /usr/pkg /usr/sfw"
+if test "$use_openssl" = "auto"
+then
+ for d in $openssldirs
+ do
+ if test -f $d/include/openssl/opensslv.h
+ then
+ use_openssl=$d
+ break
+ fi
+ done
+fi
+case "$use_openssl" in
+ no)
+ AC_MSG_RESULT(no)
+ TCN_OPENSSL_INC=""
+ USE_OPENSSL=""
+ ;;
+ auto)
+ TCN_OPENSSL_INC=""
+ USE_OPENSSL=""
+ AC_MSG_RESULT(not found)
+ ;;
+ *)
+ if test "$use_openssl" = "yes"
+ then
+ # User did not specify a path - guess it
+ for d in $openssldirs
+ do
+ if test -f $d/include/openssl/opensslv.h
+ then
+ use_openssl=$d
+ break
+ fi
+ done
+ if test "$use_openssl" = "yes"
+ then
+ AC_MSG_RESULT(not found)
+ AC_MSG_ERROR(
+[OpenSSL was not found in any of $openssldirs; use --with-ssl=/path])
+ fi
+ fi
+ USE_OPENSSL='-DOPENSSL'
+
+ if test "$use_openssl" = "/usr"
+ then
+ TCN_OPENSSL_INC=""
+ TCN_OPENSSL_LIBS="-lssl -lcrypto"
+ else
+ TCN_OPENSSL_INC="-I$use_openssl/include"
+ case $host in
+ *-solaris*)
+ TCN_OPENSSL_LIBS="-L$use_openssl/lib -R$use_openssl/lib -lssl -lcrypto"
+ ;;
+ *-hp-hpux*)
+ TCN_OPENSSL_LIBS="-L$use_openssl/lib -Wl,+b: -lssl -lcrypto"
+ ;;
+ *linux*)
+ TCN_OPENSSL_LIBS="-L$use_openssl/lib -Wl,-rpath,$use_openssl/lib -lssl -lcrypto"
+ ;;
+ *)
+ TCN_OPENSSL_LIBS="-L$use_openssl/lib -lssl -lcrypto"
+ ;;
+ esac
+ fi
+ AC_MSG_RESULT(using openssl from $use_openssl/lib and $use_openssl/include)
+
+ saved_cflags="$CFLAGS"
+ saved_libs="$LIBS"
+ CFLAGS="$CFLAGS $TCN_OPENSSL_INC"
+ LIBS="$LIBS $TCN_OPENSSL_LIBS"
+
+AC_ARG_ENABLE(openssl-version-check,
+[AC_HELP_STRING([--enable-openssl-version-check],
+ [Check OpenSSL Version @<:@default=yes@:>@])])
+case "$enable_openssl_version_check" in
+yes|'')
+ AC_MSG_CHECKING(OpenSSL library version)
+ AC_TRY_RUN([
+#include <stdio.h>
+#include <openssl/opensslv.h>
+int main() {
+ if ((OPENSSL_VERSION_NUMBER >= 0x0090701fL &&
+ OPENSSL_VERSION_NUMBER < 0x00908000L) ||
+ OPENSSL_VERSION_NUMBER >= 0x0090801fL)
+ return (0);
+ printf("\n\nFound OPENSSL_VERSION_NUMBER %#010x\n",
+ OPENSSL_VERSION_NUMBER);
+ printf("Require OPENSSL_VERSION_NUMBER 0x0090701f or greater (0.9.7a)\n"
+ "Require OPENSSL_VERSION_NUMBER 0x0090801f or greater (0.9.8a)\n\n");
+ return (1);
+}
+ ],
+ [AC_MSG_RESULT(ok)],
+ [AC_MSG_RESULT(not compatible)
+ OPENSSL_WARNING=yes
+ ],
+ [AC_MSG_RESULT(assuming target platform has compatible version)])
+;;
+no)
+ AC_MSG_RESULT(Skipped OpenSSL version check)
+;;
+esac
+
+ AC_MSG_CHECKING(for OpenSSL DSA support)
+ if test -f $use_openssl/include/openssl/dsa.h
+ then
+ AC_DEFINE(HAVE_OPENSSL_DSA)
+ AC_MSG_RESULT(yes)
+ else
+ AC_MSG_RESULT(no)
+ fi
+ CFLAGS="$saved_cflags"
+ LIBS="$saved_libs"
+ ;;
+esac
+if test "x$USE_OPENSSL" != "x"
+then
+ APR_ADDTO(TCNATIVE_PRIV_INCLUDES, [$TCN_OPENSSL_INC])
+ APR_ADDTO(TCNATIVE_LDFLAGS, [$TCN_OPENSSL_LIBS])
+ APR_ADDTO(CFLAGS, [-DHAVE_OPENSSL])
+fi
+])
diff --git a/jni/native/buildconf b/jni/native/buildconf
new file mode 100755
index 0000000..169ffa4
--- /dev/null
+++ b/jni/native/buildconf
@@ -0,0 +1,96 @@
+#!/bin/sh
+#
+# 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.
+#
+#
+
+# Default place to look for apr source. Can be overridden with
+# --with-apr=[directory]
+apr_src_dir=`pwd`/srclib/apr-1.3.9
+
+while test $# -gt 0
+do
+ # Normalize
+ case "$1" in
+ -*=*) optarg=`echo "$1" | sed 's/[-_a-zA-Z0-9]*=//'` ;;
+ *) optarg= ;;
+ esac
+
+ case "$1" in
+ --with-apr=*)
+ apr_src_dir=$optarg
+ ;;
+ esac
+
+ shift
+done
+
+if test -d "$apr_src_dir"
+then
+ echo ""
+ echo "Looking for apr source in $apr_src_dir"
+else
+ echo ""
+ echo "Problem finding apr source in $apr_src_dir."
+ echo "Use:"
+ echo " --with-apr=[directory]"
+ exit 1
+fi
+
+# Remove some files, then copy them from apr source tree
+rm -f build/apr_common.m4 build/find_apr.m4 build/install.sh \
+ build/config.guess build/config.sub
+cp $apr_src_dir/build/apr_common.m4 $apr_src_dir/build/find_apr.m4 \
+ $apr_src_dir/build/install.sh $apr_src_dir/build/config.guess \
+ $apr_src_dir/build/config.sub build
+
+# Remove aclocal.m4 as it'll break some builds...
+rm -rf aclocal.m4 autom4te*.cache
+
+echo "Creating configure ..."
+### do some work to toss config.cache?
+if ${AUTOCONF:-autoconf}; then
+ :
+else
+ echo "autoconf failed"
+ exit 1
+fi
+
+#
+# Generate build-outputs.mk for the build systme
+#
+echo "Generating 'make' outputs ..."
+$apr_src_dir/build/gen-build.py make
+
+# Remove autoconf cache again
+rm -rf autom4te*.cache
+
+# Create RPM Spec file
+if [ -f `which cut` ]; then
+ echo rebuilding rpm spec file
+ ( REVISION=`build/get-version.sh all include/tcn_version.h TCN`
+ VERSION=`echo $REVISION | cut -d- -s -f1`
+ RELEASE=`echo $REVISION | cut -d- -s -f2`
+ if [ "x$VERSION" = "x" ]; then
+ VERSION=$REVISION
+ RELEASE=1
+ fi
+ cat ./build/rpm/tcnative.spec.in | \
+ sed -e "s/TCN_VERSION/$VERSION/" \
+ -e "s/TCN_RELEASE/$RELEASE/" \
+ > tcnative.spec )
+fi
+
diff --git a/jni/native/config.layout b/jni/native/config.layout
new file mode 100644
index 0000000..788f62f
--- /dev/null
+++ b/jni/native/config.layout
@@ -0,0 +1,265 @@
+#
+# 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.
+#
+
+##
+## config.layout -- Pre-defined Installation Path Layouts
+##
+## Hints:
+## - layouts can be loaded with configure's --enable-layout=ID option
+## - when no --enable-layout option is given, the default layout is `apr'
+## - a trailing plus character (`+') on paths is replaced with a
+## `/<target>' suffix where <target> is currently hardcoded to 'apr'.
+## (This may become a configurable parameter at some point.)
+##
+
+# Generic path layout that needs --prefix=/some/path
+<Layout generic>
+ exec_prefix: ${prefix}
+ bindir: ${exec_prefix}/bin
+ sbindir: ${exec_prefix}/bin
+ libdir: ${exec_prefix}/lib
+ libexecdir: ${exec_prefix}/modules
+ mandir: ${prefix}/man
+ sysconfdir: ${prefix}/conf
+ datadir: ${prefix}
+ installbuilddir: ${datadir}/build
+ includedir: ${prefix}/include/apr-${TCNATIVE_MAJOR_VERSION}
+ localstatedir: ${prefix}
+ libsuffix: -${TCNATIVE_MAJOR_VERSION}
+</Layout>
+
+# Classical Tomcat Native path layout designed for parallel installs.
+<Layout tcnative>
+ prefix: /usr/local/apr
+ exec_prefix: ${prefix}
+ bindir: ${exec_prefix}/bin
+ sbindir: ${exec_prefix}/bin
+ libdir: ${exec_prefix}/lib
+ libexecdir: ${exec_prefix}/modules
+ mandir: ${prefix}/man
+ sysconfdir: ${prefix}/conf
+ datadir: ${prefix}
+ installbuilddir: ${datadir}/build
+ includedir: ${prefix}/include/apr-${TCNATIVE_MAJOR_VERSION}
+ localstatedir: ${prefix}
+ libsuffix: -${TCNATIVE_MAJOR_VERSION}
+</Layout>
+
+# Classical single-installation APR path layout.
+<Layout classic>
+ prefix: /usr/local/apr
+ exec_prefix: ${prefix}
+ bindir: ${exec_prefix}/bin
+ sbindir: ${exec_prefix}/bin
+ libdir: ${exec_prefix}/lib
+ libexecdir: ${exec_prefix}/modules
+ mandir: ${prefix}/man
+ sysconfdir: ${prefix}/conf
+ datadir: ${prefix}
+ installbuilddir: ${datadir}/build
+ includedir: ${prefix}/include
+ localstatedir: ${prefix}
+</Layout>
+
+# GNU standards conforming path layout.
+# See FSF's GNU project `make-stds' document for details.
+<Layout GNU>
+ prefix: /usr/local
+ exec_prefix: ${prefix}
+ bindir: ${exec_prefix}/bin
+ sbindir: ${exec_prefix}/sbin
+ libdir: ${exec_prefix}/lib
+ libexecdir: ${exec_prefix}/libexec
+ mandir: ${prefix}/man
+ sysconfdir: ${prefix}/etc+
+ datadir: ${prefix}/share+
+ installbuilddir: ${datadir}/build
+ includedir: ${prefix}/include+
+ localstatedir: ${prefix}/var+
+ runtimedir: ${localstatedir}/run
+</Layout>
+
+# Mac OS X Server (Rhapsody)
+<Layout Mac OS X Server>
+ prefix: /Local/Library/WebServer
+ exec_prefix: /usr
+ bindir: ${exec_prefix}/bin
+ sbindir: ${exec_prefix}/sbin
+ libdir: ${exec_prefix}/lib
+ libexecdir: /System/Library/apr/Modules
+ mandir: ${exec_prefix}/share/man
+ sysconfdir: ${prefix}/Configuration
+ datadir: ${prefix}
+ installbuilddir: /System/Library/apr/Build
+ includedir: /System/Library/Frameworks/apr.framework/Versions/2.0/Headers
+ localstatedir: /var
+ runtimedir: ${prefix}/Logs
+</Layout>
+
+# Darwin/Mac OS Layout
+<Layout Darwin>
+ prefix: /usr
+ exec_prefix: ${prefix}
+ bindir: ${exec_prefix}/bin
+ sbindir: ${exec_prefix}/sbin
+ libdir: ${exec_prefix}/lib
+ libexecdir: ${exec_prefix}/libexec+
+ mandir: ${prefix}/share/man
+ datadir: /Library/WebServer
+ sysconfdir: /etc+
+ installbuilddir: ${prefix}/share/httpd/build
+ includedir: ${prefix}/include+
+ localstatedir: /var
+ runtimedir: ${localstatedir}/run
+</Layout>
+
+# Red Hat Linux 7.x layout
+<Layout RedHat>
+ prefix: /usr
+ exec_prefix: ${prefix}
+ bindir: ${prefix}/bin
+ sbindir: ${prefix}/sbin
+ libdir: ${prefix}/lib
+ libexecdir: ${prefix}/lib/apr
+ mandir: ${prefix}/man
+ sysconfdir: /etc/httpd/conf
+ datadir: /var/www
+ installbuilddir: ${datadir}/build
+ includedir: ${prefix}/include/apr
+ localstatedir: /var
+ runtimedir: ${localstatedir}/run
+</Layout>
+
+# According to the /opt filesystem conventions
+<Layout opt>
+ prefix: /opt/apr
+ exec_prefix: ${prefix}
+ bindir: ${exec_prefix}/bin
+ sbindir: ${exec_prefix}/sbin
+ libdir: ${exec_prefix}/lib
+ libexecdir: ${exec_prefix}/libexec
+ mandir: ${prefix}/man
+ sysconfdir: /etc${prefix}
+ datadir: ${prefix}/share
+ installbuilddir: ${datadir}/build
+ includedir: ${prefix}/include
+ localstatedir: /var${prefix}
+ runtimedir: ${localstatedir}/run
+</Layout>
+
+# BeOS layout...
+<Layout beos>
+ prefix: /boot/home/apr
+ exec_prefix: ${prefix}
+ bindir: ${exec_prefix}/bin
+ sbindir: ${exec_prefix}/bin
+ libdir: ${exec_prefix}/lib
+ libexecdir: ${exec_prefix}/libexec
+ mandir: ${prefix}/man
+ sysconfdir: ${prefix}/conf
+ datadir: ${prefix}
+ installbuilddir: ${datadir}/build
+ includedir: ${prefix}/include
+ localstatedir: ${prefix}
+ runtimedir: ${localstatedir}/logs
+</Layout>
+
+# SuSE 6.x layout
+<Layout SuSE>
+ prefix: /usr
+ exec_prefix: ${prefix}
+ bindir: ${prefix}/bin
+ sbindir: ${prefix}/sbin
+ libdir: ${prefix}/lib
+ libexecdir: ${prefix}/lib/apr
+ mandir: ${prefix}/share/man
+ sysconfdir: /etc/httpd
+ datadir: /usr/local/httpd
+ installbuilddir: ${datadir}/build
+ includedir: ${prefix}/include/apr
+ localstatedir: /var/lib/httpd
+ runtimedir: /var/run
+</Layout>
+
+# BSD/OS layout
+<Layout BSDI>
+ prefix: /var/www
+ exec_prefix: /usr/contrib
+ bindir: ${exec_prefix}/bin
+ sbindir: ${exec_prefix}/bin
+ libdir: ${exec_prefix}/lib
+ libexecdir: ${exec_prefix}/libexec/apr
+ mandir: ${exec_prefix}/man
+ sysconfdir: ${prefix}/conf
+ datadir: ${prefix}
+ installbuilddir: ${datadir}/build
+ includedir: ${exec_prefix}/include/apr
+ localstatedir: /var
+ runtimedir: ${localstatedir}/run
+</Layout>
+
+# Solaris 8 Layout
+<Layout Solaris>
+ prefix: /usr/apr
+ exec_prefix: ${prefix}
+ bindir: ${exec_prefix}/bin
+ sbindir: ${exec_prefix}/bin
+ libdir: ${exec_prefix}/lib
+ libexecdir: ${exec_prefix}/libexec
+ mandir: ${exec_prefix}/man
+ sysconfdir: /etc/apr
+ datadir: /var/apr
+ installbuilddir: ${datadir}/build
+ includedir: ${exec_prefix}/include
+ localstatedir: ${prefix}
+ runtimedir: /var/run
+</Layout>
+
+# OpenBSD Layout
+<Layout OpenBSD>
+ prefix: /var/www
+ exec_prefix: /usr
+ bindir: ${exec_prefix}/bin
+ sbindir: ${exec_prefix}/sbin
+ libdir: ${exec_prefix}/lib
+ libexecdir: ${exec_prefix}/lib/apr/modules
+ mandir: ${exec_prefix}/share/man
+ sysconfdir: ${prefix}/conf
+ datadir: ${prefix}
+ installbuilddir: ${prefix}/build
+ includedir: ${exec_prefix}/lib/apr/include
+ localstatedir: ${prefix}
+ runtimedir: ${prefix}/logs
+</Layout>
+
+# Debian layout
+<Layout Debian>
+ prefix:
+ exec_prefix: ${prefix}/usr
+ bindir: ${exec_prefix}/bin
+ sbindir: ${exec_prefix}/sbin
+ libdir: ${exec_prefix}/lib
+ libexecdir: ${exec_prefix}/lib/apr/modules
+ mandir: ${exec_prefix}/share/man
+ datadir: ${exec_prefix}/share/apr
+ includedir: ${exec_prefix}/include/apr-${TCNATIVE_MAJOR_VERSION}
+ localstatedir: ${prefix}/var/run
+ runtimedir: ${prefix}/var/run
+ infodir: ${exec_prefix}/share/info
+ libsuffix -${TCNATIVE_MAJOR_VERSION}
+ installbuilddir: ${prefix}/usr/share/apache2/build
+</Layout>
diff --git a/jni/native/configure b/jni/native/configure
new file mode 100755
index 0000000..41b7ca3
--- /dev/null
+++ b/jni/native/configure
@@ -0,0 +1,4944 @@
+#! /bin/sh
+# Guess values for system-dependent variables and create Makefiles.
+# Generated by GNU Autoconf 2.59.
+#
+# Copyright (C) 2003 Free Software Foundation, Inc.
+# This configure script is free software; the Free Software Foundation
+# gives unlimited permission to copy, distribute and modify it.
+## --------------------- ##
+## M4sh Initialization. ##
+## --------------------- ##
+
+# Be Bourne compatible
+if test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then
+ emulate sh
+ NULLCMD=:
+ # Zsh 3.x and 4.x performs word splitting on ${1+"$@"}, which
+ # is contrary to our usage. Disable this feature.
+ alias -g '${1+"$@"}'='"$@"'
+elif test -n "${BASH_VERSION+set}" && (set -o posix) >/dev/null 2>&1; then
+ set -o posix
+fi
+DUALCASE=1; export DUALCASE # for MKS sh
+
+# Support unset when possible.
+if ( (MAIL=60; unset MAIL) || exit) >/dev/null 2>&1; then
+ as_unset=unset
+else
+ as_unset=false
+fi
+
+
+# Work around bugs in pre-3.0 UWIN ksh.
+$as_unset ENV MAIL MAILPATH
+PS1='$ '
+PS2='> '
+PS4='+ '
+
+# NLS nuisances.
+for as_var in \
+ LANG LANGUAGE LC_ADDRESS LC_ALL LC_COLLATE LC_CTYPE LC_IDENTIFICATION \
+ LC_MEASUREMENT LC_MESSAGES LC_MONETARY LC_NAME LC_NUMERIC LC_PAPER \
+ LC_TELEPHONE LC_TIME
+do
+ if (set +x; test -z "`(eval $as_var=C; export $as_var) 2>&1`"); then
+ eval $as_var=C; export $as_var
+ else
+ $as_unset $as_var
+ fi
+done
+
+# Required to use basename.
+if expr a : '\(a\)' >/dev/null 2>&1; then
+ as_expr=expr
+else
+ as_expr=false
+fi
+
+if (basename /) >/dev/null 2>&1 && test "X`basename / 2>&1`" = "X/"; then
+ as_basename=basename
+else
+ as_basename=false
+fi
+
+
+# Name of the executable.
+as_me=`$as_basename "$0" ||
+$as_expr X/"$0" : '.*/\([^/][^/]*\)/*$' \| \
+ X"$0" : 'X\(//\)$' \| \
+ X"$0" : 'X\(/\)$' \| \
+ . : '\(.\)' 2>/dev/null ||
+echo X/"$0" |
+ sed '/^.*\/\([^/][^/]*\)\/*$/{ s//\1/; q; }
+ /^X\/\(\/\/\)$/{ s//\1/; q; }
+ /^X\/\(\/\).*/{ s//\1/; q; }
+ s/.*/./; q'`
+
+
+# PATH needs CR, and LINENO needs CR and PATH.
+# Avoid depending upon Character Ranges.
+as_cr_letters='abcdefghijklmnopqrstuvwxyz'
+as_cr_LETTERS='ABCDEFGHIJKLMNOPQRSTUVWXYZ'
+as_cr_Letters=$as_cr_letters$as_cr_LETTERS
+as_cr_digits='0123456789'
+as_cr_alnum=$as_cr_Letters$as_cr_digits
+
+# The user is always right.
+if test "${PATH_SEPARATOR+set}" != set; then
+ echo "#! /bin/sh" >conf$$.sh
+ echo "exit 0" >>conf$$.sh
+ chmod +x conf$$.sh
+ if (PATH="/nonexistent;."; conf$$.sh) >/dev/null 2>&1; then
+ PATH_SEPARATOR=';'
+ else
+ PATH_SEPARATOR=:
+ fi
+ rm -f conf$$.sh
+fi
+
+
+ as_lineno_1=$LINENO
+ as_lineno_2=$LINENO
+ as_lineno_3=`(expr $as_lineno_1 + 1) 2>/dev/null`
+ test "x$as_lineno_1" != "x$as_lineno_2" &&
+ test "x$as_lineno_3" = "x$as_lineno_2" || {
+ # Find who we are. Look in the path if we contain no path at all
+ # relative or not.
+ case $0 in
+ *[\\/]* ) as_myself=$0 ;;
+ *) as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+ IFS=$as_save_IFS
+ test -z "$as_dir" && as_dir=.
+ test -r "$as_dir/$0" && as_myself=$as_dir/$0 && break
+done
+
+ ;;
+ esac
+ # We did not find ourselves, most probably we were run as `sh COMMAND'
+ # in which case we are not to be found in the path.
+ if test "x$as_myself" = x; then
+ as_myself=$0
+ fi
+ if test ! -f "$as_myself"; then
+ { echo "$as_me: error: cannot find myself; rerun with an absolute path" >&2
+ { (exit 1); exit 1; }; }
+ fi
+ case $CONFIG_SHELL in
+ '')
+ as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in /bin$PATH_SEPARATOR/usr/bin$PATH_SEPARATOR$PATH
+do
+ IFS=$as_save_IFS
+ test -z "$as_dir" && as_dir=.
+ for as_base in sh bash ksh sh5; do
+ case $as_dir in
+ /*)
+ if ("$as_dir/$as_base" -c '
+ as_lineno_1=$LINENO
+ as_lineno_2=$LINENO
+ as_lineno_3=`(expr $as_lineno_1 + 1) 2>/dev/null`
+ test "x$as_lineno_1" != "x$as_lineno_2" &&
+ test "x$as_lineno_3" = "x$as_lineno_2" ') 2>/dev/null; then
+ $as_unset BASH_ENV || test "${BASH_ENV+set}" != set || { BASH_ENV=; export BASH_ENV; }
+ $as_unset ENV || test "${ENV+set}" != set || { ENV=; export ENV; }
+ CONFIG_SHELL=$as_dir/$as_base
+ export CONFIG_SHELL
+ exec "$CONFIG_SHELL" "$0" ${1+"$@"}
+ fi;;
+ esac
+ done
+done
+;;
+ esac
+
+ # Create $as_me.lineno as a copy of $as_myself, but with $LINENO
+ # uniformly replaced by the line number. The first 'sed' inserts a
+ # line-number line before each line; the second 'sed' does the real
+ # work. The second script uses 'N' to pair each line-number line
+ # with the numbered line, and appends trailing '-' during
+ # substitution so that $LINENO is not a special case at line end.
+ # (Raja R Harinath suggested sed '=', and Paul Eggert wrote the
+ # second 'sed' script. Blame Lee E. McMahon for sed's syntax. :-)
+ sed '=' <$as_myself |
+ sed '
+ N
+ s,$,-,
+ : loop
+ s,^\(['$as_cr_digits']*\)\(.*\)[$]LINENO\([^'$as_cr_alnum'_]\),\1\2\1\3,
+ t loop
+ s,-$,,
+ s,^['$as_cr_digits']*\n,,
+ ' >$as_me.lineno &&
+ chmod +x $as_me.lineno ||
+ { echo "$as_me: error: cannot create $as_me.lineno; rerun with a POSIX shell" >&2
+ { (exit 1); exit 1; }; }
+
+ # Don't try to exec as it changes $[0], causing all sort of problems
+ # (the dirname of $[0] is not the place where we might find the
+ # original and so on. Autoconf is especially sensible to this).
+ . ./$as_me.lineno
+ # Exit status is that of the last command.
+ exit
+}
+
+
+case `echo "testing\c"; echo 1,2,3`,`echo -n testing; echo 1,2,3` in
+ *c*,-n*) ECHO_N= ECHO_C='
+' ECHO_T=' ' ;;
+ *c*,* ) ECHO_N=-n ECHO_C= ECHO_T= ;;
+ *) ECHO_N= ECHO_C='\c' ECHO_T= ;;
+esac
+
+if expr a : '\(a\)' >/dev/null 2>&1; then
+ as_expr=expr
+else
+ as_expr=false
+fi
+
+rm -f conf$$ conf$$.exe conf$$.file
+echo >conf$$.file
+if ln -s conf$$.file conf$$ 2>/dev/null; then
+ # We could just check for DJGPP; but this test a) works b) is more generic
+ # and c) will remain valid once DJGPP supports symlinks (DJGPP 2.04).
+ if test -f conf$$.exe; then
+ # Don't use ln at all; we don't have any links
+ as_ln_s='cp -p'
+ else
+ as_ln_s='ln -s'
+ fi
+elif ln conf$$.file conf$$ 2>/dev/null; then
+ as_ln_s=ln
+else
+ as_ln_s='cp -p'
+fi
+rm -f conf$$ conf$$.exe conf$$.file
+
+if mkdir -p . 2>/dev/null; then
+ as_mkdir_p=:
+else
+ test -d ./-p && rmdir ./-p
+ as_mkdir_p=false
+fi
+
+as_executable_p="test -f"
+
+# Sed expression to map a string onto a valid CPP name.
+as_tr_cpp="eval sed 'y%*$as_cr_letters%P$as_cr_LETTERS%;s%[^_$as_cr_alnum]%_%g'"
+
+# Sed expression to map a string onto a valid variable name.
+as_tr_sh="eval sed 'y%*+%pp%;s%[^_$as_cr_alnum]%_%g'"
+
+
+# IFS
+# We need space, tab and new line, in precisely that order.
+as_nl='
+'
+IFS=" $as_nl"
+
+# CDPATH.
+$as_unset CDPATH
+
+
+# Name of the host.
+# hostname on some systems (SVR3.2, Linux) returns a bogus exit status,
+# so uname gets run too.
+ac_hostname=`(hostname || uname -n) 2>/dev/null | sed 1q`
+
+exec 6>&1
+
+#
+# Initializations.
+#
+ac_default_prefix=/usr/local
+ac_config_libobj_dir=.
+cross_compiling=no
+subdirs=
+MFLAGS=
+MAKEFLAGS=
+SHELL=${CONFIG_SHELL-/bin/sh}
+
+# Maximum number of lines to put in a shell here document.
+# This variable seems obsolete. It should probably be removed, and
+# only ac_max_sed_lines should be used.
+: ${ac_max_here_lines=38}
+
+# Identity of this package.
+PACKAGE_NAME=
+PACKAGE_TARNAME=
+PACKAGE_VERSION=
+PACKAGE_STRING=
+PACKAGE_BUGREPORT=
+
+ac_unique_file="configure.in"
+ac_subst_vars='SHELL PATH_SEPARATOR PACKAGE_NAME PACKAGE_TARNAME PACKAGE_VERSION PACKAGE_STRING PACKAGE_BUGREPORT exec_prefix prefix program_transform_name bindir sbindir libexecdir datadir sysconfdir sharedstatedir localstatedir libdir includedir oldincludedir infodir mandir build_alias host_alias target_alias DEFS ECHO_C ECHO_N ECHO_T LIBS TCN_CONFIG_LOCATION build build_cpu build_vendor build_os host host_cpu host_vendor host_os target target_cpu target_vendor target_os INSTALL_PROGRA [...]
+ac_subst_files=''
+
+# Initialize some variables set by options.
+ac_init_help=
+ac_init_version=false
+# The variables have the same names as the options, with
+# dashes changed to underlines.
+cache_file=/dev/null
+exec_prefix=NONE
+no_create=
+no_recursion=
+prefix=NONE
+program_prefix=NONE
+program_suffix=NONE
+program_transform_name=s,x,x,
+silent=
+site=
+srcdir=
+verbose=
+x_includes=NONE
+x_libraries=NONE
+
+# Installation directory options.
+# These are left unexpanded so users can "make install exec_prefix=/foo"
+# and all the variables that are supposed to be based on exec_prefix
+# by default will actually change.
+# Use braces instead of parens because sh, perl, etc. also accept them.
+bindir='${exec_prefix}/bin'
+sbindir='${exec_prefix}/sbin'
+libexecdir='${exec_prefix}/libexec'
+datadir='${prefix}/share'
+sysconfdir='${prefix}/etc'
+sharedstatedir='${prefix}/com'
+localstatedir='${prefix}/var'
+libdir='${exec_prefix}/lib'
+includedir='${prefix}/include'
+oldincludedir='/usr/include'
+infodir='${prefix}/info'
+mandir='${prefix}/man'
+
+ac_prev=
+for ac_option
+do
+ # If the previous option needs an argument, assign it.
+ if test -n "$ac_prev"; then
+ eval "$ac_prev=\$ac_option"
+ ac_prev=
+ continue
+ fi
+
+ ac_optarg=`expr "x$ac_option" : 'x[^=]*=\(.*\)'`
+
+ # Accept the important Cygnus configure options, so we can diagnose typos.
+
+ case $ac_option in
+
+ -bindir | --bindir | --bindi | --bind | --bin | --bi)
+ ac_prev=bindir ;;
+ -bindir=* | --bindir=* | --bindi=* | --bind=* | --bin=* | --bi=*)
+ bindir=$ac_optarg ;;
+
+ -build | --build | --buil | --bui | --bu)
+ ac_prev=build_alias ;;
+ -build=* | --build=* | --buil=* | --bui=* | --bu=*)
+ build_alias=$ac_optarg ;;
+
+ -cache-file | --cache-file | --cache-fil | --cache-fi \
+ | --cache-f | --cache- | --cache | --cach | --cac | --ca | --c)
+ ac_prev=cache_file ;;
+ -cache-file=* | --cache-file=* | --cache-fil=* | --cache-fi=* \
+ | --cache-f=* | --cache-=* | --cache=* | --cach=* | --cac=* | --ca=* | --c=*)
+ cache_file=$ac_optarg ;;
+
+ --config-cache | -C)
+ cache_file=config.cache ;;
+
+ -datadir | --datadir | --datadi | --datad | --data | --dat | --da)
+ ac_prev=datadir ;;
+ -datadir=* | --datadir=* | --datadi=* | --datad=* | --data=* | --dat=* \
+ | --da=*)
+ datadir=$ac_optarg ;;
+
+ -disable-* | --disable-*)
+ ac_feature=`expr "x$ac_option" : 'x-*disable-\(.*\)'`
+ # Reject names that are not valid shell variable names.
+ expr "x$ac_feature" : ".*[^-_$as_cr_alnum]" >/dev/null &&
+ { echo "$as_me: error: invalid feature name: $ac_feature" >&2
+ { (exit 1); exit 1; }; }
+ ac_feature=`echo $ac_feature | sed 's/-/_/g'`
+ eval "enable_$ac_feature=no" ;;
+
+ -enable-* | --enable-*)
+ ac_feature=`expr "x$ac_option" : 'x-*enable-\([^=]*\)'`
+ # Reject names that are not valid shell variable names.
+ expr "x$ac_feature" : ".*[^-_$as_cr_alnum]" >/dev/null &&
+ { echo "$as_me: error: invalid feature name: $ac_feature" >&2
+ { (exit 1); exit 1; }; }
+ ac_feature=`echo $ac_feature | sed 's/-/_/g'`
+ case $ac_option in
+ *=*) ac_optarg=`echo "$ac_optarg" | sed "s/'/'\\\\\\\\''/g"`;;
+ *) ac_optarg=yes ;;
+ esac
+ eval "enable_$ac_feature='$ac_optarg'" ;;
+
+ -exec-prefix | --exec_prefix | --exec-prefix | --exec-prefi \
+ | --exec-pref | --exec-pre | --exec-pr | --exec-p | --exec- \
+ | --exec | --exe | --ex)
+ ac_prev=exec_prefix ;;
+ -exec-prefix=* | --exec_prefix=* | --exec-prefix=* | --exec-prefi=* \
+ | --exec-pref=* | --exec-pre=* | --exec-pr=* | --exec-p=* | --exec-=* \
+ | --exec=* | --exe=* | --ex=*)
+ exec_prefix=$ac_optarg ;;
+
+ -gas | --gas | --ga | --g)
+ # Obsolete; use --with-gas.
+ with_gas=yes ;;
+
+ -help | --help | --hel | --he | -h)
+ ac_init_help=long ;;
+ -help=r* | --help=r* | --hel=r* | --he=r* | -hr*)
+ ac_init_help=recursive ;;
+ -help=s* | --help=s* | --hel=s* | --he=s* | -hs*)
+ ac_init_help=short ;;
+
+ -host | --host | --hos | --ho)
+ ac_prev=host_alias ;;
+ -host=* | --host=* | --hos=* | --ho=*)
+ host_alias=$ac_optarg ;;
+
+ -includedir | --includedir | --includedi | --included | --include \
+ | --includ | --inclu | --incl | --inc)
+ ac_prev=includedir ;;
+ -includedir=* | --includedir=* | --includedi=* | --included=* | --include=* \
+ | --includ=* | --inclu=* | --incl=* | --inc=*)
+ includedir=$ac_optarg ;;
+
+ -infodir | --infodir | --infodi | --infod | --info | --inf)
+ ac_prev=infodir ;;
+ -infodir=* | --infodir=* | --infodi=* | --infod=* | --info=* | --inf=*)
+ infodir=$ac_optarg ;;
+
+ -libdir | --libdir | --libdi | --libd)
+ ac_prev=libdir ;;
+ -libdir=* | --libdir=* | --libdi=* | --libd=*)
+ libdir=$ac_optarg ;;
+
+ -libexecdir | --libexecdir | --libexecdi | --libexecd | --libexec \
+ | --libexe | --libex | --libe)
+ ac_prev=libexecdir ;;
+ -libexecdir=* | --libexecdir=* | --libexecdi=* | --libexecd=* | --libexec=* \
+ | --libexe=* | --libex=* | --libe=*)
+ libexecdir=$ac_optarg ;;
+
+ -localstatedir | --localstatedir | --localstatedi | --localstated \
+ | --localstate | --localstat | --localsta | --localst \
+ | --locals | --local | --loca | --loc | --lo)
+ ac_prev=localstatedir ;;
+ -localstatedir=* | --localstatedir=* | --localstatedi=* | --localstated=* \
+ | --localstate=* | --localstat=* | --localsta=* | --localst=* \
+ | --locals=* | --local=* | --loca=* | --loc=* | --lo=*)
+ localstatedir=$ac_optarg ;;
+
+ -mandir | --mandir | --mandi | --mand | --man | --ma | --m)
+ ac_prev=mandir ;;
+ -mandir=* | --mandir=* | --mandi=* | --mand=* | --man=* | --ma=* | --m=*)
+ mandir=$ac_optarg ;;
+
+ -nfp | --nfp | --nf)
+ # Obsolete; use --without-fp.
+ with_fp=no ;;
+
+ -no-create | --no-create | --no-creat | --no-crea | --no-cre \
+ | --no-cr | --no-c | -n)
+ no_create=yes ;;
+
+ -no-recursion | --no-recursion | --no-recursio | --no-recursi \
+ | --no-recurs | --no-recur | --no-recu | --no-rec | --no-re | --no-r)
+ no_recursion=yes ;;
+
+ -oldincludedir | --oldincludedir | --oldincludedi | --oldincluded \
+ | --oldinclude | --oldinclud | --oldinclu | --oldincl | --oldinc \
+ | --oldin | --oldi | --old | --ol | --o)
+ ac_prev=oldincludedir ;;
+ -oldincludedir=* | --oldincludedir=* | --oldincludedi=* | --oldincluded=* \
+ | --oldinclude=* | --oldinclud=* | --oldinclu=* | --oldincl=* | --oldinc=* \
+ | --oldin=* | --oldi=* | --old=* | --ol=* | --o=*)
+ oldincludedir=$ac_optarg ;;
+
+ -prefix | --prefix | --prefi | --pref | --pre | --pr | --p)
+ ac_prev=prefix ;;
+ -prefix=* | --prefix=* | --prefi=* | --pref=* | --pre=* | --pr=* | --p=*)
+ prefix=$ac_optarg ;;
+
+ -program-prefix | --program-prefix | --program-prefi | --program-pref \
+ | --program-pre | --program-pr | --program-p)
+ ac_prev=program_prefix ;;
+ -program-prefix=* | --program-prefix=* | --program-prefi=* \
+ | --program-pref=* | --program-pre=* | --program-pr=* | --program-p=*)
+ program_prefix=$ac_optarg ;;
+
+ -program-suffix | --program-suffix | --program-suffi | --program-suff \
+ | --program-suf | --program-su | --program-s)
+ ac_prev=program_suffix ;;
+ -program-suffix=* | --program-suffix=* | --program-suffi=* \
+ | --program-suff=* | --program-suf=* | --program-su=* | --program-s=*)
+ program_suffix=$ac_optarg ;;
+
+ -program-transform-name | --program-transform-name \
+ | --program-transform-nam | --program-transform-na \
+ | --program-transform-n | --program-transform- \
+ | --program-transform | --program-transfor \
+ | --program-transfo | --program-transf \
+ | --program-trans | --program-tran \
+ | --progr-tra | --program-tr | --program-t)
+ ac_prev=program_transform_name ;;
+ -program-transform-name=* | --program-transform-name=* \
+ | --program-transform-nam=* | --program-transform-na=* \
+ | --program-transform-n=* | --program-transform-=* \
+ | --program-transform=* | --program-transfor=* \
+ | --program-transfo=* | --program-transf=* \
+ | --program-trans=* | --program-tran=* \
+ | --progr-tra=* | --program-tr=* | --program-t=*)
+ program_transform_name=$ac_optarg ;;
+
+ -q | -quiet | --quiet | --quie | --qui | --qu | --q \
+ | -silent | --silent | --silen | --sile | --sil)
+ silent=yes ;;
+
+ -sbindir | --sbindir | --sbindi | --sbind | --sbin | --sbi | --sb)
+ ac_prev=sbindir ;;
+ -sbindir=* | --sbindir=* | --sbindi=* | --sbind=* | --sbin=* \
+ | --sbi=* | --sb=*)
+ sbindir=$ac_optarg ;;
+
+ -sharedstatedir | --sharedstatedir | --sharedstatedi \
+ | --sharedstated | --sharedstate | --sharedstat | --sharedsta \
+ | --sharedst | --shareds | --shared | --share | --shar \
+ | --sha | --sh)
+ ac_prev=sharedstatedir ;;
+ -sharedstatedir=* | --sharedstatedir=* | --sharedstatedi=* \
+ | --sharedstated=* | --sharedstate=* | --sharedstat=* | --sharedsta=* \
+ | --sharedst=* | --shareds=* | --shared=* | --share=* | --shar=* \
+ | --sha=* | --sh=*)
+ sharedstatedir=$ac_optarg ;;
+
+ -site | --site | --sit)
+ ac_prev=site ;;
+ -site=* | --site=* | --sit=*)
+ site=$ac_optarg ;;
+
+ -srcdir | --srcdir | --srcdi | --srcd | --src | --sr)
+ ac_prev=srcdir ;;
+ -srcdir=* | --srcdir=* | --srcdi=* | --srcd=* | --src=* | --sr=*)
+ srcdir=$ac_optarg ;;
+
+ -sysconfdir | --sysconfdir | --sysconfdi | --sysconfd | --sysconf \
+ | --syscon | --sysco | --sysc | --sys | --sy)
+ ac_prev=sysconfdir ;;
+ -sysconfdir=* | --sysconfdir=* | --sysconfdi=* | --sysconfd=* | --sysconf=* \
+ | --syscon=* | --sysco=* | --sysc=* | --sys=* | --sy=*)
+ sysconfdir=$ac_optarg ;;
+
+ -target | --target | --targe | --targ | --tar | --ta | --t)
+ ac_prev=target_alias ;;
+ -target=* | --target=* | --targe=* | --targ=* | --tar=* | --ta=* | --t=*)
+ target_alias=$ac_optarg ;;
+
+ -v | -verbose | --verbose | --verbos | --verbo | --verb)
+ verbose=yes ;;
+
+ -version | --version | --versio | --versi | --vers | -V)
+ ac_init_version=: ;;
+
+ -with-* | --with-*)
+ ac_package=`expr "x$ac_option" : 'x-*with-\([^=]*\)'`
+ # Reject names that are not valid shell variable names.
+ expr "x$ac_package" : ".*[^-_$as_cr_alnum]" >/dev/null &&
+ { echo "$as_me: error: invalid package name: $ac_package" >&2
+ { (exit 1); exit 1; }; }
+ ac_package=`echo $ac_package| sed 's/-/_/g'`
+ case $ac_option in
+ *=*) ac_optarg=`echo "$ac_optarg" | sed "s/'/'\\\\\\\\''/g"`;;
+ *) ac_optarg=yes ;;
+ esac
+ eval "with_$ac_package='$ac_optarg'" ;;
+
+ -without-* | --without-*)
+ ac_package=`expr "x$ac_option" : 'x-*without-\(.*\)'`
+ # Reject names that are not valid shell variable names.
+ expr "x$ac_package" : ".*[^-_$as_cr_alnum]" >/dev/null &&
+ { echo "$as_me: error: invalid package name: $ac_package" >&2
+ { (exit 1); exit 1; }; }
+ ac_package=`echo $ac_package | sed 's/-/_/g'`
+ eval "with_$ac_package=no" ;;
+
+ --x)
+ # Obsolete; use --with-x.
+ with_x=yes ;;
+
+ -x-includes | --x-includes | --x-include | --x-includ | --x-inclu \
+ | --x-incl | --x-inc | --x-in | --x-i)
+ ac_prev=x_includes ;;
+ -x-includes=* | --x-includes=* | --x-include=* | --x-includ=* | --x-inclu=* \
+ | --x-incl=* | --x-inc=* | --x-in=* | --x-i=*)
+ x_includes=$ac_optarg ;;
+
+ -x-libraries | --x-libraries | --x-librarie | --x-librari \
+ | --x-librar | --x-libra | --x-libr | --x-lib | --x-li | --x-l)
+ ac_prev=x_libraries ;;
+ -x-libraries=* | --x-libraries=* | --x-librarie=* | --x-librari=* \
+ | --x-librar=* | --x-libra=* | --x-libr=* | --x-lib=* | --x-li=* | --x-l=*)
+ x_libraries=$ac_optarg ;;
+
+ -*) { echo "$as_me: error: unrecognized option: $ac_option
+Try \`$0 --help' for more information." >&2
+ { (exit 1); exit 1; }; }
+ ;;
+
+ *=*)
+ ac_envvar=`expr "x$ac_option" : 'x\([^=]*\)='`
+ # Reject names that are not valid shell variable names.
+ expr "x$ac_envvar" : ".*[^_$as_cr_alnum]" >/dev/null &&
+ { echo "$as_me: error: invalid variable name: $ac_envvar" >&2
+ { (exit 1); exit 1; }; }
+ ac_optarg=`echo "$ac_optarg" | sed "s/'/'\\\\\\\\''/g"`
+ eval "$ac_envvar='$ac_optarg'"
+ export $ac_envvar ;;
+
+ *)
+ # FIXME: should be removed in autoconf 3.0.
+ echo "$as_me: WARNING: you should use --build, --host, --target" >&2
+ expr "x$ac_option" : ".*[^-._$as_cr_alnum]" >/dev/null &&
+ echo "$as_me: WARNING: invalid host type: $ac_option" >&2
+ : ${build_alias=$ac_option} ${host_alias=$ac_option} ${target_alias=$ac_option}
+ ;;
+
+ esac
+done
+
+if test -n "$ac_prev"; then
+ ac_option=--`echo $ac_prev | sed 's/_/-/g'`
+ { echo "$as_me: error: missing argument to $ac_option" >&2
+ { (exit 1); exit 1; }; }
+fi
+
+# Be sure to have absolute paths.
+for ac_var in exec_prefix prefix
+do
+ eval ac_val=$`echo $ac_var`
+ case $ac_val in
+ [\\/$]* | ?:[\\/]* | NONE | '' ) ;;
+ *) { echo "$as_me: error: expected an absolute directory name for --$ac_var: $ac_val" >&2
+ { (exit 1); exit 1; }; };;
+ esac
+done
+
+# Be sure to have absolute paths.
+for ac_var in bindir sbindir libexecdir datadir sysconfdir sharedstatedir \
+ localstatedir libdir includedir oldincludedir infodir mandir
+do
+ eval ac_val=$`echo $ac_var`
+ case $ac_val in
+ [\\/$]* | ?:[\\/]* ) ;;
+ *) { echo "$as_me: error: expected an absolute directory name for --$ac_var: $ac_val" >&2
+ { (exit 1); exit 1; }; };;
+ esac
+done
+
+# There might be people who depend on the old broken behavior: `$host'
+# used to hold the argument of --host etc.
+# FIXME: To remove some day.
+build=$build_alias
+host=$host_alias
+target=$target_alias
+
+# FIXME: To remove some day.
+if test "x$host_alias" != x; then
+ if test "x$build_alias" = x; then
+ cross_compiling=maybe
+ echo "$as_me: WARNING: If you wanted to set the --build type, don't use --host.
+ If a cross compiler is detected then cross compile mode will be used." >&2
+ elif test "x$build_alias" != "x$host_alias"; then
+ cross_compiling=yes
+ fi
+fi
+
+ac_tool_prefix=
+test -n "$host_alias" && ac_tool_prefix=$host_alias-
+
+test "$silent" = yes && exec 6>/dev/null
+
+
+# Find the source files, if location was not specified.
+if test -z "$srcdir"; then
+ ac_srcdir_defaulted=yes
+ # Try the directory containing this script, then its parent.
+ ac_confdir=`(dirname "$0") 2>/dev/null ||
+$as_expr X"$0" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \
+ X"$0" : 'X\(//\)[^/]' \| \
+ X"$0" : 'X\(//\)$' \| \
+ X"$0" : 'X\(/\)' \| \
+ . : '\(.\)' 2>/dev/null ||
+echo X"$0" |
+ sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ s//\1/; q; }
+ /^X\(\/\/\)[^/].*/{ s//\1/; q; }
+ /^X\(\/\/\)$/{ s//\1/; q; }
+ /^X\(\/\).*/{ s//\1/; q; }
+ s/.*/./; q'`
+ srcdir=$ac_confdir
+ if test ! -r $srcdir/$ac_unique_file; then
+ srcdir=..
+ fi
+else
+ ac_srcdir_defaulted=no
+fi
+if test ! -r $srcdir/$ac_unique_file; then
+ if test "$ac_srcdir_defaulted" = yes; then
+ { echo "$as_me: error: cannot find sources ($ac_unique_file) in $ac_confdir or .." >&2
+ { (exit 1); exit 1; }; }
+ else
+ { echo "$as_me: error: cannot find sources ($ac_unique_file) in $srcdir" >&2
+ { (exit 1); exit 1; }; }
+ fi
+fi
+(cd $srcdir && test -r ./$ac_unique_file) 2>/dev/null ||
+ { echo "$as_me: error: sources are in $srcdir, but \`cd $srcdir' does not work" >&2
+ { (exit 1); exit 1; }; }
+srcdir=`echo "$srcdir" | sed 's%\([^\\/]\)[\\/]*$%\1%'`
+ac_env_build_alias_set=${build_alias+set}
+ac_env_build_alias_value=$build_alias
+ac_cv_env_build_alias_set=${build_alias+set}
+ac_cv_env_build_alias_value=$build_alias
+ac_env_host_alias_set=${host_alias+set}
+ac_env_host_alias_value=$host_alias
+ac_cv_env_host_alias_set=${host_alias+set}
+ac_cv_env_host_alias_value=$host_alias
+ac_env_target_alias_set=${target_alias+set}
+ac_env_target_alias_value=$target_alias
+ac_cv_env_target_alias_set=${target_alias+set}
+ac_cv_env_target_alias_value=$target_alias
+ac_env_CC_set=${CC+set}
+ac_env_CC_value=$CC
+ac_cv_env_CC_set=${CC+set}
+ac_cv_env_CC_value=$CC
+ac_env_CFLAGS_set=${CFLAGS+set}
+ac_env_CFLAGS_value=$CFLAGS
+ac_cv_env_CFLAGS_set=${CFLAGS+set}
+ac_cv_env_CFLAGS_value=$CFLAGS
+ac_env_LDFLAGS_set=${LDFLAGS+set}
+ac_env_LDFLAGS_value=$LDFLAGS
+ac_cv_env_LDFLAGS_set=${LDFLAGS+set}
+ac_cv_env_LDFLAGS_value=$LDFLAGS
+ac_env_CPPFLAGS_set=${CPPFLAGS+set}
+ac_env_CPPFLAGS_value=$CPPFLAGS
+ac_cv_env_CPPFLAGS_set=${CPPFLAGS+set}
+ac_cv_env_CPPFLAGS_value=$CPPFLAGS
+
+#
+# Report the --help message.
+#
+if test "$ac_init_help" = "long"; then
+ # Omit some internal or obsolete options to make the list less imposing.
+ # This message is too long to be a string in the A/UX 3.1 sh.
+ cat <<_ACEOF
+\`configure' configures this package to adapt to many kinds of systems.
+
+Usage: $0 [OPTION]... [VAR=VALUE]...
+
+To assign environment variables (e.g., CC, CFLAGS...), specify them as
+VAR=VALUE. See below for descriptions of some of the useful variables.
+
+Defaults for the options are specified in brackets.
+
+Configuration:
+ -h, --help display this help and exit
+ --help=short display options specific to this package
+ --help=recursive display the short help of all the included packages
+ -V, --version display version information and exit
+ -q, --quiet, --silent do not print \`checking...' messages
+ --cache-file=FILE cache test results in FILE [disabled]
+ -C, --config-cache alias for \`--cache-file=config.cache'
+ -n, --no-create do not create output files
+ --srcdir=DIR find the sources in DIR [configure dir or \`..']
+
+_ACEOF
+
+ cat <<_ACEOF
+Installation directories:
+ --prefix=PREFIX install architecture-independent files in PREFIX
+ [$ac_default_prefix]
+ --exec-prefix=EPREFIX install architecture-dependent files in EPREFIX
+ [PREFIX]
+
+By default, \`make install' will install all the files in
+\`$ac_default_prefix/bin', \`$ac_default_prefix/lib' etc. You can specify
+an installation prefix other than \`$ac_default_prefix' using \`--prefix',
+for instance \`--prefix=\$HOME'.
+
+For better control, use the options below.
+
+Fine tuning of the installation directories:
+ --bindir=DIR user executables [EPREFIX/bin]
+ --sbindir=DIR system admin executables [EPREFIX/sbin]
+ --libexecdir=DIR program executables [EPREFIX/libexec]
+ --datadir=DIR read-only architecture-independent data [PREFIX/share]
+ --sysconfdir=DIR read-only single-machine data [PREFIX/etc]
+ --sharedstatedir=DIR modifiable architecture-independent data [PREFIX/com]
+ --localstatedir=DIR modifiable single-machine data [PREFIX/var]
+ --libdir=DIR object code libraries [EPREFIX/lib]
+ --includedir=DIR C header files [PREFIX/include]
+ --oldincludedir=DIR C header files for non-gcc [/usr/include]
+ --infodir=DIR info documentation [PREFIX/info]
+ --mandir=DIR man documentation [PREFIX/man]
+_ACEOF
+
+ cat <<\_ACEOF
+
+System types:
+ --build=BUILD configure for building on BUILD [guessed]
+ --host=HOST cross-compile to build programs to run on HOST [BUILD]
+ --target=TARGET configure for building compilers for TARGET [HOST]
+_ACEOF
+fi
+
+if test -n "$ac_init_help"; then
+
+ cat <<\_ACEOF
+
+Optional Features:
+ --disable-FEATURE do not include FEATURE (same as --enable-FEATURE=no)
+ --enable-FEATURE[=ARG] include FEATURE [ARG=yes]
+ --enable-layout=LAYOUT
+ --disable-openssl avoid using OpenSSL toolkit
+ --enable-ocsp Turn on OpenSSL OCSP verification support
+ --enable-openssl-version-check
+ Check OpenSSL Version [default=yes]
+ --enable-maintainer-mode Turn on debugging and compile time warnings
+
+Optional Packages:
+ --with-PACKAGE[=ARG] use PACKAGE [ARG=yes]
+ --without-PACKAGE do not use PACKAGE (same as --with-PACKAGE=no)
+ --with-apr=PATH prefix for installed APR or the full path to
+ apr-config
+ --with-java-home=DIR Location of JDK directory.
+ --with-java-platform=2 Force the Java platform
+ (value is 1 for 1.1.x or 2 for 1.2.x or greater)
+ --with-os-type=SUBDIR Location of JDK os-type subdirectory.
+ --with-ssl=PATH Build with OpenSSL yes|no|path
+
+Some influential environment variables:
+ CC C compiler command
+ CFLAGS C compiler flags
+ LDFLAGS linker flags, e.g. -L<lib dir> if you have libraries in a
+ nonstandard directory <lib dir>
+ CPPFLAGS C/C++ preprocessor flags, e.g. -I<include dir> if you have
+ headers in a nonstandard directory <include dir>
+
+Use these variables to override the choices made by `configure' or to help
+it to find libraries and programs with nonstandard names/locations.
+
+_ACEOF
+fi
+
+if test "$ac_init_help" = "recursive"; then
+ # If there are subdirs, report their specific --help.
+ ac_popdir=`pwd`
+ for ac_dir in : $ac_subdirs_all; do test "x$ac_dir" = x: && continue
+ test -d $ac_dir || continue
+ ac_builddir=.
+
+if test "$ac_dir" != .; then
+ ac_dir_suffix=/`echo "$ac_dir" | sed 's,^\.[\\/],,'`
+ # A "../" for each directory in $ac_dir_suffix.
+ ac_top_builddir=`echo "$ac_dir_suffix" | sed 's,/[^\\/]*,../,g'`
+else
+ ac_dir_suffix= ac_top_builddir=
+fi
+
+case $srcdir in
+ .) # No --srcdir option. We are building in place.
+ ac_srcdir=.
+ if test -z "$ac_top_builddir"; then
+ ac_top_srcdir=.
+ else
+ ac_top_srcdir=`echo $ac_top_builddir | sed 's,/$,,'`
+ fi ;;
+ [\\/]* | ?:[\\/]* ) # Absolute path.
+ ac_srcdir=$srcdir$ac_dir_suffix;
+ ac_top_srcdir=$srcdir ;;
+ *) # Relative path.
+ ac_srcdir=$ac_top_builddir$srcdir$ac_dir_suffix
+ ac_top_srcdir=$ac_top_builddir$srcdir ;;
+esac
+
+# Do not use `cd foo && pwd` to compute absolute paths, because
+# the directories may not exist.
+case `pwd` in
+.) ac_abs_builddir="$ac_dir";;
+*)
+ case "$ac_dir" in
+ .) ac_abs_builddir=`pwd`;;
+ [\\/]* | ?:[\\/]* ) ac_abs_builddir="$ac_dir";;
+ *) ac_abs_builddir=`pwd`/"$ac_dir";;
+ esac;;
+esac
+case $ac_abs_builddir in
+.) ac_abs_top_builddir=${ac_top_builddir}.;;
+*)
+ case ${ac_top_builddir}. in
+ .) ac_abs_top_builddir=$ac_abs_builddir;;
+ [\\/]* | ?:[\\/]* ) ac_abs_top_builddir=${ac_top_builddir}.;;
+ *) ac_abs_top_builddir=$ac_abs_builddir/${ac_top_builddir}.;;
+ esac;;
+esac
+case $ac_abs_builddir in
+.) ac_abs_srcdir=$ac_srcdir;;
+*)
+ case $ac_srcdir in
+ .) ac_abs_srcdir=$ac_abs_builddir;;
+ [\\/]* | ?:[\\/]* ) ac_abs_srcdir=$ac_srcdir;;
+ *) ac_abs_srcdir=$ac_abs_builddir/$ac_srcdir;;
+ esac;;
+esac
+case $ac_abs_builddir in
+.) ac_abs_top_srcdir=$ac_top_srcdir;;
+*)
+ case $ac_top_srcdir in
+ .) ac_abs_top_srcdir=$ac_abs_builddir;;
+ [\\/]* | ?:[\\/]* ) ac_abs_top_srcdir=$ac_top_srcdir;;
+ *) ac_abs_top_srcdir=$ac_abs_builddir/$ac_top_srcdir;;
+ esac;;
+esac
+
+ cd $ac_dir
+ # Check for guested configure; otherwise get Cygnus style configure.
+ if test -f $ac_srcdir/configure.gnu; then
+ echo
+ $SHELL $ac_srcdir/configure.gnu --help=recursive
+ elif test -f $ac_srcdir/configure; then
+ echo
+ $SHELL $ac_srcdir/configure --help=recursive
+ elif test -f $ac_srcdir/configure.ac ||
+ test -f $ac_srcdir/configure.in; then
+ echo
+ $ac_configure --help
+ else
+ echo "$as_me: WARNING: no configuration information is in $ac_dir" >&2
+ fi
+ cd $ac_popdir
+ done
+fi
+
+test -n "$ac_init_help" && exit 0
+if $ac_init_version; then
+ cat <<\_ACEOF
+
+Copyright (C) 2003 Free Software Foundation, Inc.
+This configure script is free software; the Free Software Foundation
+gives unlimited permission to copy, distribute and modify it.
+_ACEOF
+ exit 0
+fi
+exec 5>config.log
+cat >&5 <<_ACEOF
+This file contains any messages produced by compilers while
+running configure, to aid debugging if configure makes a mistake.
+
+It was created by $as_me, which was
+generated by GNU Autoconf 2.59. Invocation command line was
+
+ $ $0 $@
+
+_ACEOF
+{
+cat <<_ASUNAME
+## --------- ##
+## Platform. ##
+## --------- ##
+
+hostname = `(hostname || uname -n) 2>/dev/null | sed 1q`
+uname -m = `(uname -m) 2>/dev/null || echo unknown`
+uname -r = `(uname -r) 2>/dev/null || echo unknown`
+uname -s = `(uname -s) 2>/dev/null || echo unknown`
+uname -v = `(uname -v) 2>/dev/null || echo unknown`
+
+/usr/bin/uname -p = `(/usr/bin/uname -p) 2>/dev/null || echo unknown`
+/bin/uname -X = `(/bin/uname -X) 2>/dev/null || echo unknown`
+
+/bin/arch = `(/bin/arch) 2>/dev/null || echo unknown`
+/usr/bin/arch -k = `(/usr/bin/arch -k) 2>/dev/null || echo unknown`
+/usr/convex/getsysinfo = `(/usr/convex/getsysinfo) 2>/dev/null || echo unknown`
+hostinfo = `(hostinfo) 2>/dev/null || echo unknown`
+/bin/machine = `(/bin/machine) 2>/dev/null || echo unknown`
+/usr/bin/oslevel = `(/usr/bin/oslevel) 2>/dev/null || echo unknown`
+/bin/universe = `(/bin/universe) 2>/dev/null || echo unknown`
+
+_ASUNAME
+
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+ IFS=$as_save_IFS
+ test -z "$as_dir" && as_dir=.
+ echo "PATH: $as_dir"
+done
+
+} >&5
+
+cat >&5 <<_ACEOF
+
+
+## ----------- ##
+## Core tests. ##
+## ----------- ##
+
+_ACEOF
+
+
+# Keep a trace of the command line.
+# Strip out --no-create and --no-recursion so they do not pile up.
+# Strip out --silent because we don't want to record it for future runs.
+# Also quote any args containing shell meta-characters.
+# Make two passes to allow for proper duplicate-argument suppression.
+ac_configure_args=
+ac_configure_args0=
+ac_configure_args1=
+ac_sep=
+ac_must_keep_next=false
+for ac_pass in 1 2
+do
+ for ac_arg
+ do
+ case $ac_arg in
+ -no-create | --no-c* | -n | -no-recursion | --no-r*) continue ;;
+ -q | -quiet | --quiet | --quie | --qui | --qu | --q \
+ | -silent | --silent | --silen | --sile | --sil)
+ continue ;;
+ *" "*|*" "*|*[\[\]\~\#\$\^\&\*\(\)\{\}\\\|\;\<\>\?\"\']*)
+ ac_arg=`echo "$ac_arg" | sed "s/'/'\\\\\\\\''/g"` ;;
+ esac
+ case $ac_pass in
+ 1) ac_configure_args0="$ac_configure_args0 '$ac_arg'" ;;
+ 2)
+ ac_configure_args1="$ac_configure_args1 '$ac_arg'"
+ if test $ac_must_keep_next = true; then
+ ac_must_keep_next=false # Got value, back to normal.
+ else
+ case $ac_arg in
+ *=* | --config-cache | -C | -disable-* | --disable-* \
+ | -enable-* | --enable-* | -gas | --g* | -nfp | --nf* \
+ | -q | -quiet | --q* | -silent | --sil* | -v | -verb* \
+ | -with-* | --with-* | -without-* | --without-* | --x)
+ case "$ac_configure_args0 " in
+ "$ac_configure_args1"*" '$ac_arg' "* ) continue ;;
+ esac
+ ;;
+ -* ) ac_must_keep_next=true ;;
+ esac
+ fi
+ ac_configure_args="$ac_configure_args$ac_sep'$ac_arg'"
+ # Get rid of the leading space.
+ ac_sep=" "
+ ;;
+ esac
+ done
+done
+$as_unset ac_configure_args0 || test "${ac_configure_args0+set}" != set || { ac_configure_args0=; export ac_configure_args0; }
+$as_unset ac_configure_args1 || test "${ac_configure_args1+set}" != set || { ac_configure_args1=; export ac_configure_args1; }
+
+# When interrupted or exit'd, cleanup temporary files, and complete
+# config.log. We remove comments because anyway the quotes in there
+# would cause problems or look ugly.
+# WARNING: Be sure not to use single quotes in there, as some shells,
+# such as our DU 5.0 friend, will then `close' the trap.
+trap 'exit_status=$?
+ # Save into config.log some information that might help in debugging.
+ {
+ echo
+
+ cat <<\_ASBOX
+## ---------------- ##
+## Cache variables. ##
+## ---------------- ##
+_ASBOX
+ echo
+ # The following way of writing the cache mishandles newlines in values,
+{
+ (set) 2>&1 |
+ case `(ac_space='"'"' '"'"'; set | grep ac_space) 2>&1` in
+ *ac_space=\ *)
+ sed -n \
+ "s/'"'"'/'"'"'\\\\'"'"''"'"'/g;
+ s/^\\([_$as_cr_alnum]*_cv_[_$as_cr_alnum]*\\)=\\(.*\\)/\\1='"'"'\\2'"'"'/p"
+ ;;
+ *)
+ sed -n \
+ "s/^\\([_$as_cr_alnum]*_cv_[_$as_cr_alnum]*\\)=\\(.*\\)/\\1=\\2/p"
+ ;;
+ esac;
+}
+ echo
+
+ cat <<\_ASBOX
+## ----------------- ##
+## Output variables. ##
+## ----------------- ##
+_ASBOX
+ echo
+ for ac_var in $ac_subst_vars
+ do
+ eval ac_val=$`echo $ac_var`
+ echo "$ac_var='"'"'$ac_val'"'"'"
+ done | sort
+ echo
+
+ if test -n "$ac_subst_files"; then
+ cat <<\_ASBOX
+## ------------- ##
+## Output files. ##
+## ------------- ##
+_ASBOX
+ echo
+ for ac_var in $ac_subst_files
+ do
+ eval ac_val=$`echo $ac_var`
+ echo "$ac_var='"'"'$ac_val'"'"'"
+ done | sort
+ echo
+ fi
+
+ if test -s confdefs.h; then
+ cat <<\_ASBOX
+## ----------- ##
+## confdefs.h. ##
+## ----------- ##
+_ASBOX
+ echo
+ sed "/^$/d" confdefs.h | sort
+ echo
+ fi
+ test "$ac_signal" != 0 &&
+ echo "$as_me: caught signal $ac_signal"
+ echo "$as_me: exit $exit_status"
+ } >&5
+ rm -f core *.core &&
+ rm -rf conftest* confdefs* conf$$* $ac_clean_files &&
+ exit $exit_status
+ ' 0
+for ac_signal in 1 2 13 15; do
+ trap 'ac_signal='$ac_signal'; { (exit 1); exit 1; }' $ac_signal
+done
+ac_signal=0
+
+# confdefs.h avoids OS command line length limits that DEFS can exceed.
+rm -rf conftest* confdefs.h
+# AIX cpp loses on an empty file, so make sure it contains at least a newline.
+echo >confdefs.h
+
+# Predefined preprocessor variables.
+
+cat >>confdefs.h <<_ACEOF
+#define PACKAGE_NAME "$PACKAGE_NAME"
+_ACEOF
+
+
+cat >>confdefs.h <<_ACEOF
+#define PACKAGE_TARNAME "$PACKAGE_TARNAME"
+_ACEOF
+
+
+cat >>confdefs.h <<_ACEOF
+#define PACKAGE_VERSION "$PACKAGE_VERSION"
+_ACEOF
+
+
+cat >>confdefs.h <<_ACEOF
+#define PACKAGE_STRING "$PACKAGE_STRING"
+_ACEOF
+
+
+cat >>confdefs.h <<_ACEOF
+#define PACKAGE_BUGREPORT "$PACKAGE_BUGREPORT"
+_ACEOF
+
+
+# Let the site file select an alternate cache file if it wants to.
+# Prefer explicitly selected file to automatically selected ones.
+if test -z "$CONFIG_SITE"; then
+ if test "x$prefix" != xNONE; then
+ CONFIG_SITE="$prefix/share/config.site $prefix/etc/config.site"
+ else
+ CONFIG_SITE="$ac_default_prefix/share/config.site $ac_default_prefix/etc/config.site"
+ fi
+fi
+for ac_site_file in $CONFIG_SITE; do
+ if test -r "$ac_site_file"; then
+ { echo "$as_me:$LINENO: loading site script $ac_site_file" >&5
+echo "$as_me: loading site script $ac_site_file" >&6;}
+ sed 's/^/| /' "$ac_site_file" >&5
+ . "$ac_site_file"
+ fi
+done
+
+if test -r "$cache_file"; then
+ # Some versions of bash will fail to source /dev/null (special
+ # files actually), so we avoid doing that.
+ if test -f "$cache_file"; then
+ { echo "$as_me:$LINENO: loading cache $cache_file" >&5
+echo "$as_me: loading cache $cache_file" >&6;}
+ case $cache_file in
+ [\\/]* | ?:[\\/]* ) . $cache_file;;
+ *) . ./$cache_file;;
+ esac
+ fi
+else
+ { echo "$as_me:$LINENO: creating cache $cache_file" >&5
+echo "$as_me: creating cache $cache_file" >&6;}
+ >$cache_file
+fi
+
+# Check that the precious variables saved in the cache have kept the same
+# value.
+ac_cache_corrupted=false
+for ac_var in `(set) 2>&1 |
+ sed -n 's/^ac_env_\([a-zA-Z_0-9]*\)_set=.*/\1/p'`; do
+ eval ac_old_set=\$ac_cv_env_${ac_var}_set
+ eval ac_new_set=\$ac_env_${ac_var}_set
+ eval ac_old_val="\$ac_cv_env_${ac_var}_value"
+ eval ac_new_val="\$ac_env_${ac_var}_value"
+ case $ac_old_set,$ac_new_set in
+ set,)
+ { echo "$as_me:$LINENO: error: \`$ac_var' was set to \`$ac_old_val' in the previous run" >&5
+echo "$as_me: error: \`$ac_var' was set to \`$ac_old_val' in the previous run" >&2;}
+ ac_cache_corrupted=: ;;
+ ,set)
+ { echo "$as_me:$LINENO: error: \`$ac_var' was not set in the previous run" >&5
+echo "$as_me: error: \`$ac_var' was not set in the previous run" >&2;}
+ ac_cache_corrupted=: ;;
+ ,);;
+ *)
+ if test "x$ac_old_val" != "x$ac_new_val"; then
+ { echo "$as_me:$LINENO: error: \`$ac_var' has changed since the previous run:" >&5
+echo "$as_me: error: \`$ac_var' has changed since the previous run:" >&2;}
+ { echo "$as_me:$LINENO: former value: $ac_old_val" >&5
+echo "$as_me: former value: $ac_old_val" >&2;}
+ { echo "$as_me:$LINENO: current value: $ac_new_val" >&5
+echo "$as_me: current value: $ac_new_val" >&2;}
+ ac_cache_corrupted=:
+ fi;;
+ esac
+ # Pass precious variables to config.status.
+ if test "$ac_new_set" = set; then
+ case $ac_new_val in
+ *" "*|*" "*|*[\[\]\~\#\$\^\&\*\(\)\{\}\\\|\;\<\>\?\"\']*)
+ ac_arg=$ac_var=`echo "$ac_new_val" | sed "s/'/'\\\\\\\\''/g"` ;;
+ *) ac_arg=$ac_var=$ac_new_val ;;
+ esac
+ case " $ac_configure_args " in
+ *" '$ac_arg' "*) ;; # Avoid dups. Use of quotes ensures accuracy.
+ *) ac_configure_args="$ac_configure_args '$ac_arg'" ;;
+ esac
+ fi
+done
+if $ac_cache_corrupted; then
+ { echo "$as_me:$LINENO: error: changes in the environment can compromise the build" >&5
+echo "$as_me: error: changes in the environment can compromise the build" >&2;}
+ { { echo "$as_me:$LINENO: error: run \`make distclean' and/or \`rm $cache_file' and start over" >&5
+echo "$as_me: error: run \`make distclean' and/or \`rm $cache_file' and start over" >&2;}
+ { (exit 1); exit 1; }; }
+fi
+
+ac_ext=c
+ac_cpp='$CPP $CPPFLAGS'
+ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
+ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
+ac_compiler_gnu=$ac_cv_c_compiler_gnu
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ac_aux_dir=
+for ac_dir in build $srcdir/build; do
+ if test -f $ac_dir/install-sh; then
+ ac_aux_dir=$ac_dir
+ ac_install_sh="$ac_aux_dir/install-sh -c"
+ break
+ elif test -f $ac_dir/install.sh; then
+ ac_aux_dir=$ac_dir
+ ac_install_sh="$ac_aux_dir/install.sh -c"
+ break
+ elif test -f $ac_dir/shtool; then
+ ac_aux_dir=$ac_dir
+ ac_install_sh="$ac_aux_dir/shtool install -c"
+ break
+ fi
+done
+if test -z "$ac_aux_dir"; then
+ { { echo "$as_me:$LINENO: error: cannot find install-sh or install.sh in build $srcdir/build" >&5
+echo "$as_me: error: cannot find install-sh or install.sh in build $srcdir/build" >&2;}
+ { (exit 1); exit 1; }; }
+fi
+ac_config_guess="$SHELL $ac_aux_dir/config.guess"
+ac_config_sub="$SHELL $ac_aux_dir/config.sub"
+ac_configure="$SHELL $ac_aux_dir/configure" # This should be Cygnus configure.
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#
+# 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.
+#
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ rm -f config.nice
+ cat >config.nice<<EOF
+#! /bin/sh
+#
+# Created by configure
+
+EOF
+ if test -n "$CC"; then
+ echo "CC=\"$CC\"; export CC" >> config.nice
+ fi
+ if test -n "$CFLAGS"; then
+ echo "CFLAGS=\"$CFLAGS\"; export CFLAGS" >> config.nice
+ fi
+ if test -n "$CPPFLAGS"; then
+ echo "CPPFLAGS=\"$CPPFLAGS\"; export CPPFLAGS" >> config.nice
+ fi
+ if test -n "$LDFLAGS"; then
+ echo "LDFLAGS=\"$LDFLAGS\"; export LDFLAGS" >> config.nice
+ fi
+ if test -n "$LTFLAGS"; then
+ echo "LTFLAGS=\"$LTFLAGS\"; export LTFLAGS" >> config.nice
+ fi
+ if test -n "$LIBS"; then
+ echo "LIBS=\"$LIBS\"; export LIBS" >> config.nice
+ fi
+ if test -n "$INCLUDES"; then
+ echo "INCLUDES=\"$INCLUDES\"; export INCLUDES" >> config.nice
+ fi
+ if test -n "$NOTEST_CFLAGS"; then
+ echo "NOTEST_CFLAGS=\"$NOTEST_CFLAGS\"; export NOTEST_CFLAGS" >> config.nice
+ fi
+ if test -n "$NOTEST_CPPFLAGS"; then
+ echo "NOTEST_CPPFLAGS=\"$NOTEST_CPPFLAGS\"; export NOTEST_CPPFLAGS" >> config.nice
+ fi
+ if test -n "$NOTEST_LDFLAGS"; then
+ echo "NOTEST_LDFLAGS=\"$NOTEST_LDFLAGS\"; export NOTEST_LDFLAGS" >> config.nice
+ fi
+ if test -n "$NOTEST_LIBS"; then
+ echo "NOTEST_LIBS=\"$NOTEST_LIBS\"; export NOTEST_LIBS" >> config.nice
+ fi
+
+ # Retrieve command-line arguments.
+ eval "set x $0 $ac_configure_args"
+ shift
+
+ for arg
+ do
+
+ap_last=
+ap_cur="$arg"
+while test "x${ap_cur}" != "x${ap_last}";
+do
+ ap_last="${ap_cur}"
+ ap_cur=`eval "echo ${ap_cur}"`
+done
+arg="${ap_cur}"
+
+ echo "\"$arg\" \\" >> config.nice
+ done
+ echo '"$@"' >> config.nice
+ chmod +x config.nice
+
+
+
+abs_srcdir=`(cd $srcdir && pwd)`
+abs_builddir=`pwd`
+
+if test "$abs_builddir" != "$abs_srcdir"; then
+ USE_VPATH=1
+ TCN_CONFIG_LOCATION=build
+else
+ TCN_CONFIG_LOCATION=source
+fi
+
+
+# Make sure we can run config.sub.
+$ac_config_sub sun4 >/dev/null 2>&1 ||
+ { { echo "$as_me:$LINENO: error: cannot run $ac_config_sub" >&5
+echo "$as_me: error: cannot run $ac_config_sub" >&2;}
+ { (exit 1); exit 1; }; }
+
+echo "$as_me:$LINENO: checking build system type" >&5
+echo $ECHO_N "checking build system type... $ECHO_C" >&6
+if test "${ac_cv_build+set}" = set; then
+ echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+ ac_cv_build_alias=$build_alias
+test -z "$ac_cv_build_alias" &&
+ ac_cv_build_alias=`$ac_config_guess`
+test -z "$ac_cv_build_alias" &&
+ { { echo "$as_me:$LINENO: error: cannot guess build type; you must specify one" >&5
+echo "$as_me: error: cannot guess build type; you must specify one" >&2;}
+ { (exit 1); exit 1; }; }
+ac_cv_build=`$ac_config_sub $ac_cv_build_alias` ||
+ { { echo "$as_me:$LINENO: error: $ac_config_sub $ac_cv_build_alias failed" >&5
+echo "$as_me: error: $ac_config_sub $ac_cv_build_alias failed" >&2;}
+ { (exit 1); exit 1; }; }
+
+fi
+echo "$as_me:$LINENO: result: $ac_cv_build" >&5
+echo "${ECHO_T}$ac_cv_build" >&6
+build=$ac_cv_build
+build_cpu=`echo $ac_cv_build | sed 's/^\([^-]*\)-\([^-]*\)-\(.*\)$/\1/'`
+build_vendor=`echo $ac_cv_build | sed 's/^\([^-]*\)-\([^-]*\)-\(.*\)$/\2/'`
+build_os=`echo $ac_cv_build | sed 's/^\([^-]*\)-\([^-]*\)-\(.*\)$/\3/'`
+
+
+echo "$as_me:$LINENO: checking host system type" >&5
+echo $ECHO_N "checking host system type... $ECHO_C" >&6
+if test "${ac_cv_host+set}" = set; then
+ echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+ ac_cv_host_alias=$host_alias
+test -z "$ac_cv_host_alias" &&
+ ac_cv_host_alias=$ac_cv_build_alias
+ac_cv_host=`$ac_config_sub $ac_cv_host_alias` ||
+ { { echo "$as_me:$LINENO: error: $ac_config_sub $ac_cv_host_alias failed" >&5
+echo "$as_me: error: $ac_config_sub $ac_cv_host_alias failed" >&2;}
+ { (exit 1); exit 1; }; }
+
+fi
+echo "$as_me:$LINENO: result: $ac_cv_host" >&5
+echo "${ECHO_T}$ac_cv_host" >&6
+host=$ac_cv_host
+host_cpu=`echo $ac_cv_host | sed 's/^\([^-]*\)-\([^-]*\)-\(.*\)$/\1/'`
+host_vendor=`echo $ac_cv_host | sed 's/^\([^-]*\)-\([^-]*\)-\(.*\)$/\2/'`
+host_os=`echo $ac_cv_host | sed 's/^\([^-]*\)-\([^-]*\)-\(.*\)$/\3/'`
+
+
+echo "$as_me:$LINENO: checking target system type" >&5
+echo $ECHO_N "checking target system type... $ECHO_C" >&6
+if test "${ac_cv_target+set}" = set; then
+ echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+ ac_cv_target_alias=$target_alias
+test "x$ac_cv_target_alias" = "x" &&
+ ac_cv_target_alias=$ac_cv_host_alias
+ac_cv_target=`$ac_config_sub $ac_cv_target_alias` ||
+ { { echo "$as_me:$LINENO: error: $ac_config_sub $ac_cv_target_alias failed" >&5
+echo "$as_me: error: $ac_config_sub $ac_cv_target_alias failed" >&2;}
+ { (exit 1); exit 1; }; }
+
+fi
+echo "$as_me:$LINENO: result: $ac_cv_target" >&5
+echo "${ECHO_T}$ac_cv_target" >&6
+target=$ac_cv_target
+target_cpu=`echo $ac_cv_target | sed 's/^\([^-]*\)-\([^-]*\)-\(.*\)$/\1/'`
+target_vendor=`echo $ac_cv_target | sed 's/^\([^-]*\)-\([^-]*\)-\(.*\)$/\2/'`
+target_os=`echo $ac_cv_target | sed 's/^\([^-]*\)-\([^-]*\)-\(.*\)$/\3/'`
+
+
+# The aliases save the names the user supplied, while $host etc.
+# will get canonicalized.
+test -n "$target_alias" &&
+ test "$program_prefix$program_suffix$program_transform_name" = \
+ NONENONEs,x,x, &&
+ program_prefix=${target_alias}-
+# Find a good install program. We prefer a C program (faster),
+# so one script is as good as another. But avoid the broken or
+# incompatible versions:
+# SysV /etc/install, /usr/sbin/install
+# SunOS /usr/etc/install
+# IRIX /sbin/install
+# AIX /bin/install
+# AmigaOS /C/install, which installs bootblocks on floppy discs
+# AIX 4 /usr/bin/installbsd, which doesn't work without a -g flag
+# AFS /usr/afsws/bin/install, which mishandles nonexistent args
+# SVR4 /usr/ucb/install, which tries to use the nonexistent group "staff"
+# OS/2's system install, which has a completely different semantic
+# ./install, which can be erroneously created by make from ./install.sh.
+echo "$as_me:$LINENO: checking for a BSD-compatible install" >&5
+echo $ECHO_N "checking for a BSD-compatible install... $ECHO_C" >&6
+if test -z "$INSTALL"; then
+if test "${ac_cv_path_install+set}" = set; then
+ echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+ as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+ IFS=$as_save_IFS
+ test -z "$as_dir" && as_dir=.
+ # Account for people who put trailing slashes in PATH elements.
+case $as_dir/ in
+ ./ | .// | /cC/* | \
+ /etc/* | /usr/sbin/* | /usr/etc/* | /sbin/* | /usr/afsws/bin/* | \
+ ?:\\/os2\\/install\\/* | ?:\\/OS2\\/INSTALL\\/* | \
+ /usr/ucb/* ) ;;
+ *)
+ # OSF1 and SCO ODT 3.0 have their own names for install.
+ # Don't use installbsd from OSF since it installs stuff as root
+ # by default.
+ for ac_prog in ginstall scoinst install; do
+ for ac_exec_ext in '' $ac_executable_extensions; do
+ if $as_executable_p "$as_dir/$ac_prog$ac_exec_ext"; then
+ if test $ac_prog = install &&
+ grep dspmsg "$as_dir/$ac_prog$ac_exec_ext" >/dev/null 2>&1; then
+ # AIX install. It has an incompatible calling convention.
+ :
+ elif test $ac_prog = install &&
+ grep pwplus "$as_dir/$ac_prog$ac_exec_ext" >/dev/null 2>&1; then
+ # program-specific install script used by HP pwplus--don't use.
+ :
+ else
+ ac_cv_path_install="$as_dir/$ac_prog$ac_exec_ext -c"
+ break 3
+ fi
+ fi
+ done
+ done
+ ;;
+esac
+done
+
+
+fi
+ if test "${ac_cv_path_install+set}" = set; then
+ INSTALL=$ac_cv_path_install
+ else
+ # As a last resort, use the slow shell script. We don't cache a
+ # path for INSTALL within a source directory, because that will
+ # break other packages using the cache if that directory is
+ # removed, or if the path is relative.
+ INSTALL=$ac_install_sh
+ fi
+fi
+echo "$as_me:$LINENO: result: $INSTALL" >&5
+echo "${ECHO_T}$INSTALL" >&6
+
+# Use test -z because SunOS4 sh mishandles braces in ${var-val}.
+# It thinks the first close brace ends the variable substitution.
+test -z "$INSTALL_PROGRAM" && INSTALL_PROGRAM='${INSTALL}'
+
+test -z "$INSTALL_SCRIPT" && INSTALL_SCRIPT='${INSTALL}'
+
+test -z "$INSTALL_DATA" && INSTALL_DATA='${INSTALL} -m 644'
+
+
+top_builddir="$abs_builddir"
+
+
+
+
+
+ echo "$as_me:$LINENO: checking for working mkdir -p" >&5
+echo $ECHO_N "checking for working mkdir -p... $ECHO_C" >&6
+if test "${ac_cv_mkdir_p+set}" = set; then
+ echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+
+ test -d conftestdir && rm -rf conftestdir
+ mkdir -p conftestdir/somedir >/dev/null 2>&1
+ if test -d conftestdir/somedir; then
+ ac_cv_mkdir_p=yes
+ else
+ ac_cv_mkdir_p=no
+ fi
+ rm -rf conftestdir
+
+fi
+echo "$as_me:$LINENO: result: $ac_cv_mkdir_p" >&5
+echo "${ECHO_T}$ac_cv_mkdir_p" >&6
+ if test "$ac_cv_mkdir_p" = "yes"; then
+ mkdir_p="mkdir -p"
+ else
+ mkdir_p="$abs_srcdir/build/mkdir.sh"
+ fi
+
+
+get_version="$abs_srcdir/build/get-version.sh"
+version_hdr="$abs_srcdir/include/tcn_version.h"
+TCNATIVE_MAJOR_VERSION="`$get_version major $version_hdr TCN`"
+TCNATIVE_DOTTED_VERSION="`$get_version all $version_hdr TCN`"
+TCNATIVE_LIBTOOL_VERSION="`$get_version libtool $version_hdr TCN`"
+
+
+
+
+
+echo "Tomcat Native Version: ${TCNATIVE_DOTTED_VERSION}"
+
+
+# Check whether --enable-layout or --disable-layout was given.
+if test "${enable_layout+set}" = set; then
+ enableval="$enable_layout"
+
+ LAYOUT=$enableval
+
+fi;
+
+if test -z "$LAYOUT"; then
+ LAYOUT="tcnative"
+fi
+
+ if test ! -f $srcdir/config.layout; then
+ echo "** Error: Layout file $srcdir/config.layout not found"
+ echo "** Error: Cannot use undefined layout '$LAYOUT'"
+ exit 1
+ fi
+ # Catch layout names including a slash which will otherwise
+ # confuse the heck out of the sed script.
+ case $LAYOUT in
+ */*)
+ echo "** Error: $LAYOUT is not a valid layout name"
+ exit 1 ;;
+ esac
+ pldconf=./config.pld
+
+ sed -e "1s/[ ]*<[lL]ayout[ ]*$LAYOUT[ ]*>[ ]*//;1t" \
+ -e "1,/[ ]*<[lL]ayout[ ]*$LAYOUT[ ]*>[ ]*/d" \
+ -e '/[ ]*<\/Layout>[ ]*/,$d' \
+ -e "s/^[ ]*//g" \
+ -e "s/:[ ]*/=\'/g" \
+ -e "s/[ ]*$/'/g" \
+ $srcdir/config.layout > $pldconf
+ layout_name=$LAYOUT
+ if test ! -s $pldconf; then
+ echo "** Error: unable to find layout $layout_name"
+ exit 1
+ fi
+ . $pldconf
+ rm $pldconf
+ for var in prefix exec_prefix bindir sbindir libexecdir mandir \
+ sysconfdir datadir includedir localstatedir runtimedir \
+ logfiledir libdir installbuilddir libsuffix ; do
+ eval "val=\"\$$var\""
+ case $val in
+ *+)
+ val=`echo $val | sed -e 's;\+$;;'`
+ eval "$var=\"\$val\""
+ autosuffix=yes
+ ;;
+ *)
+ autosuffix=no
+ ;;
+ esac
+ val=`echo $val | sed -e 's:\(.\)/*$:\1:'`
+ val=`echo $val | sed -e 's:[\$]\([a-z_]*\):$\1:g'`
+ if test "$autosuffix" = "yes"; then
+ if echo $val | grep apache >/dev/null; then
+ addtarget=no
+ else
+ addtarget=yes
+ fi
+ if test "$addtarget" = "yes"; then
+ val="$val/apache2"
+ fi
+ fi
+ eval "$var='$val'"
+ done
+
+
+
+echo "$as_me:$LINENO: checking for chosen layout" >&5
+echo $ECHO_N "checking for chosen layout... $ECHO_C" >&6
+echo "$as_me:$LINENO: result: $layout_name" >&5
+echo "${ECHO_T}$layout_name" >&6
+
+
+ac_prev=
+# Retrieve the command-line arguments. The eval is needed because
+# the arguments are quoted to preserve accuracy.
+eval "set x $ac_configure_args"
+shift
+for ac_option
+do
+ # If the previous option needs an argument, assign it.
+ if test -n "$ac_prev"; then
+ eval "$ac_prev=\$ac_option"
+ ac_prev=
+ continue
+ fi
+
+ ac_optarg=`expr "x$ac_option" : 'x[^=]*=\(.*\)'`
+
+ case $ac_option in
+
+ -bindir | --bindir | --bindi | --bind | --bin | --bi)
+ ac_prev=bindir ;;
+ -bindir=* | --bindir=* | --bindi=* | --bind=* | --bin=* | --bi=*)
+ bindir="$ac_optarg" ;;
+
+ -datadir | --datadir | --datadi | --datad | --data | --dat | --da)
+ ac_prev=datadir ;;
+ -datadir=* | --datadir=* | --datadi=* | --datad=* | --data=* | --dat=* \
+ | --da=*)
+ datadir="$ac_optarg" ;;
+
+ -exec-prefix | --exec_prefix | --exec-prefix | --exec-prefi \
+ | --exec-pref | --exec-pre | --exec-pr | --exec-p | --exec- \
+ | --exec | --exe | --ex)
+ ac_prev=exec_prefix ;;
+ -exec-prefix=* | --exec_prefix=* | --exec-prefix=* | --exec-prefi=* \
+ | --exec-pref=* | --exec-pre=* | --exec-pr=* | --exec-p=* | --exec-=* \
+ | --exec=* | --exe=* | --ex=*)
+ exec_prefix="$ac_optarg" ;;
+
+ -includedir | --includedir | --includedi | --included | --include \
+ | --includ | --inclu | --incl | --inc)
+ ac_prev=includedir ;;
+ -includedir=* | --includedir=* | --includedi=* | --included=* | --include=* \
+ | --includ=* | --inclu=* | --incl=* | --inc=*)
+ includedir="$ac_optarg" ;;
+
+ -infodir | --infodir | --infodi | --infod | --info | --inf)
+ ac_prev=infodir ;;
+ -infodir=* | --infodir=* | --infodi=* | --infod=* | --info=* | --inf=*)
+ infodir="$ac_optarg" ;;
+
+ -libdir | --libdir | --libdi | --libd)
+ ac_prev=libdir ;;
+ -libdir=* | --libdir=* | --libdi=* | --libd=*)
+ libdir="$ac_optarg" ;;
+
+ -libexecdir | --libexecdir | --libexecdi | --libexecd | --libexec \
+ | --libexe | --libex | --libe)
+ ac_prev=libexecdir ;;
+ -libexecdir=* | --libexecdir=* | --libexecdi=* | --libexecd=* | --libexec=* \
+ | --libexe=* | --libex=* | --libe=*)
+ libexecdir="$ac_optarg" ;;
+
+ -localstatedir | --localstatedir | --localstatedi | --localstated \
+ | --localstate | --localstat | --localsta | --localst \
+ | --locals | --local | --loca | --loc | --lo)
+ ac_prev=localstatedir ;;
+ -localstatedir=* | --localstatedir=* | --localstatedi=* | --localstated=* \
+ | --localstate=* | --localstat=* | --localsta=* | --localst=* \
+ | --locals=* | --local=* | --loca=* | --loc=* | --lo=*)
+ localstatedir="$ac_optarg" ;;
+
+ -mandir | --mandir | --mandi | --mand | --man | --ma | --m)
+ ac_prev=mandir ;;
+ -mandir=* | --mandir=* | --mandi=* | --mand=* | --man=* | --ma=* | --m=*)
+ mandir="$ac_optarg" ;;
+
+ -prefix | --prefix | --prefi | --pref | --pre | --pr | --p)
+ ac_prev=prefix ;;
+ -prefix=* | --prefix=* | --prefi=* | --pref=* | --pre=* | --pr=* | --p=*)
+ prefix="$ac_optarg" ;;
+
+ -sbindir | --sbindir | --sbindi | --sbind | --sbin | --sbi | --sb)
+ ac_prev=sbindir ;;
+ -sbindir=* | --sbindir=* | --sbindi=* | --sbind=* | --sbin=* \
+ | --sbi=* | --sb=*)
+ sbindir="$ac_optarg" ;;
+
+ -sharedstatedir | --sharedstatedir | --sharedstatedi \
+ | --sharedstated | --sharedstate | --sharedstat | --sharedsta \
+ | --sharedst | --shareds | --shared | --share | --shar \
+ | --sha | --sh)
+ ac_prev=sharedstatedir ;;
+ -sharedstatedir=* | --sharedstatedir=* | --sharedstatedi=* \
+ | --sharedstated=* | --sharedstate=* | --sharedstat=* | --sharedsta=* \
+ | --sharedst=* | --shareds=* | --shared=* | --share=* | --shar=* \
+ | --sha=* | --sh=*)
+ sharedstatedir="$ac_optarg" ;;
+
+ -sysconfdir | --sysconfdir | --sysconfdi | --sysconfd | --sysconf \
+ | --syscon | --sysco | --sysc | --sys | --sy)
+ ac_prev=sysconfdir ;;
+ -sysconfdir=* | --sysconfdir=* | --sysconfdi=* | --sysconfd=* | --sysconf=* \
+ | --syscon=* | --sysco=* | --sysc=* | --sys=* | --sy=*)
+ sysconfdir="$ac_optarg" ;;
+
+ esac
+done
+
+# Be sure to have absolute paths.
+for ac_var in exec_prefix prefix
+do
+ eval ac_val=$`echo $ac_var`
+ case $ac_val in
+ [\\/$]* | ?:[\\/]* | NONE | '' ) ;;
+ *) { { echo "$as_me:$LINENO: error: expected an absolute path for --$ac_var: $ac_val" >&5
+echo "$as_me: error: expected an absolute path for --$ac_var: $ac_val" >&2;}
+ { (exit 1); exit 1; }; };;
+ esac
+done
+
+
+
+
+TCNATIVE_INCLUDES=""
+TCNATIVE_PRIV_INCLUDES="-I$top_builddir/include"
+
+
+
+
+ apr_found="no"
+
+ if test "$target_os" = "os2-emx"; then
+ # Scripts don't pass test -x on OS/2
+ TEST_X="test -f"
+ else
+ TEST_X="test -x"
+ fi
+
+ acceptable_majors="1"
+
+ apr_temp_acceptable_apr_config=""
+ for apr_temp_major in $acceptable_majors
+ do
+ case $apr_temp_major in
+ 0)
+ apr_temp_acceptable_apr_config="$apr_temp_acceptable_apr_config apr-config"
+ ;;
+ *)
+ apr_temp_acceptable_apr_config="$apr_temp_acceptable_apr_config apr-$apr_temp_major-config"
+ ;;
+ esac
+ done
+
+ echo "$as_me:$LINENO: checking for APR" >&5
+echo $ECHO_N "checking for APR... $ECHO_C" >&6
+
+# Check whether --with-apr or --without-apr was given.
+if test "${with_apr+set}" = set; then
+ withval="$with_apr"
+
+ if test "$withval" = "no" || test "$withval" = "yes"; then
+ { { echo "$as_me:$LINENO: error: --with-apr requires a directory or file to be provided" >&5
+echo "$as_me: error: --with-apr requires a directory or file to be provided" >&2;}
+ { (exit 1); exit 1; }; }
+ fi
+
+ for apr_temp_apr_config_file in $apr_temp_acceptable_apr_config
+ do
+ for lookdir in "$withval/bin" "$withval"
+ do
+ if $TEST_X "$lookdir/$apr_temp_apr_config_file"; then
+ apr_config="$lookdir/$apr_temp_apr_config_file"
+
+ apr_found="yes"
+ break 2
+ fi
+ done
+ done
+
+ if test "$apr_found" != "yes" && $TEST_X "$withval" && $withval --help > /dev/null 2>&1 ; then
+ apr_config="$withval"
+ apr_found="yes"
+ fi
+
+ if test "$apr_found" != "yes"; then
+ { { echo "$as_me:$LINENO: error: the --with-apr parameter is incorrect. It must specify an install prefix, a build directory, or an apr-config file." >&5
+echo "$as_me: error: the --with-apr parameter is incorrect. It must specify an install prefix, a build directory, or an apr-config file." >&2;}
+ { (exit 1); exit 1; }; }
+ fi
+
+else
+
+ if test -n "" && test "" = "1"; then
+ for apr_temp_apr_config_file in $apr_temp_acceptable_apr_config
+ do
+ if $apr_temp_apr_config_file --help > /dev/null 2>&1 ; then
+ apr_config="$apr_temp_apr_config_file"
+
+ apr_found="yes"
+ break
+ else
+ for lookdir in /usr /usr/local /usr/local/apr /opt/apr; do
+ if $TEST_X "$lookdir/bin/$apr_temp_apr_config_file"; then
+ apr_config="$lookdir/bin/$apr_temp_apr_config_file"
+
+ apr_found="yes"
+ break 2
+ fi
+ done
+ fi
+ done
+ fi
+ if test "$apr_found" = "no" && test -d ""; then
+ apr_temp_abs_srcdir="`cd \"\" && pwd`"
+ apr_found="reconfig"
+ apr_bundled_major="`sed -n '/#define.*APR_MAJOR_VERSION/s/^[^0-9]*\([0-9]*\).*$/\1/p' \"/include/apr_version.h\"`"
+ case $apr_bundled_major in
+ "")
+ { { echo "$as_me:$LINENO: error: failed to find major version of bundled APR" >&5
+echo "$as_me: error: failed to find major version of bundled APR" >&2;}
+ { (exit 1); exit 1; }; }
+ ;;
+ 0)
+ apr_temp_apr_config_file="apr-config"
+ ;;
+ *)
+ apr_temp_apr_config_file="apr-$apr_bundled_major-config"
+ ;;
+ esac
+ if test -n ""; then
+ apr_config="/$apr_temp_apr_config_file"
+ else
+ apr_config="/$apr_temp_apr_config_file"
+ fi
+ fi
+
+fi;
+
+ echo "$as_me:$LINENO: result: $apr_found" >&5
+echo "${ECHO_T}$apr_found" >&6
+
+ if test "$apr_found" = "no"; then
+ { { echo "$as_me:$LINENO: error: APR could not be located. Please use the --with-apr option." >&5
+echo "$as_me: error: APR could not be located. Please use the --with-apr option." >&2;}
+ { (exit 1); exit 1; }; }
+ fi
+
+ sapr_pversion="`$apr_config --version`"
+ if test -z "$sapr_pversion"; then
+ { { echo "$as_me:$LINENO: error: APR config could not be located. Please use the --with-apr option." >&5
+echo "$as_me: error: APR config could not be located. Please use the --with-apr option." >&2;}
+ { (exit 1); exit 1; }; }
+ fi
+ sapr_version="`echo $sapr_pversion|sed -e 's/\(a-z*\)$/.\1/'`"
+ tc_save_IFS=$IFS; IFS=.; set $sapr_version; IFS=$tc_save_IFS
+ if test "${1}" -lt "1"; then
+ { { echo "$as_me:$LINENO: error: You need APR version 1.2.1 or newer installed. For optimal performance version 1.3.0 or newer is needed." >&5
+echo "$as_me: error: You need APR version 1.2.1 or newer installed. For optimal performance version 1.3.0 or newer is needed." >&2;}
+ { (exit 1); exit 1; }; }
+ else
+ if test "${2}" -lt "2"; then
+ { { echo "$as_me:$LINENO: error: You need APR version 1.2.1 or newer installed. For optimal performance version 1.3.0 or newer is needed." >&5
+echo "$as_me: error: You need APR version 1.2.1 or newer installed. For optimal performance version 1.3.0 or newer is needed." >&2;}
+ { (exit 1); exit 1; }; }
+ elif test "${2}" -lt "3"; then
+ { echo "$as_me:$LINENO: WARNING: For optimal performance you need APR version 1.3.0 or newer installed." >&5
+echo "$as_me: WARNING: For optimal performance you need APR version 1.3.0 or newer installed." >&2;}
+ fi
+ fi
+
+ APR_BUILD_DIR="`$apr_config --installbuilddir`"
+
+ APR_BUILD_DIR="`cd $APR_BUILD_DIR && pwd`"
+
+ APR_INCLUDES="`$apr_config --includes`"
+ APR_LIBS="`$apr_config --link-libtool --libs`"
+ APR_SO_EXT="`$apr_config --apr-so-ext`"
+ APR_LIB_TARGET="`$apr_config --apr-lib-target`"
+
+
+
+
+
+
+
+ if test -z "$CC"; then
+ test "x$silent" != "xyes" && echo " setting CC to \"`$apr_config --cc`\""
+ CC="`$apr_config --cc`"
+ fi
+
+
+ if test -z "$CPP"; then
+ test "x$silent" != "xyes" && echo " setting CPP to \"`$apr_config --cpp`\""
+ CPP="`$apr_config --cpp`"
+ fi
+
+
+# Find a good install program. We prefer a C program (faster),
+# so one script is as good as another. But avoid the broken or
+# incompatible versions:
+# SysV /etc/install, /usr/sbin/install
+# SunOS /usr/etc/install
+# IRIX /sbin/install
+# AIX /bin/install
+# AmigaOS /C/install, which installs bootblocks on floppy discs
+# AIX 4 /usr/bin/installbsd, which doesn't work without a -g flag
+# AFS /usr/afsws/bin/install, which mishandles nonexistent args
+# SVR4 /usr/ucb/install, which tries to use the nonexistent group "staff"
+# OS/2's system install, which has a completely different semantic
+# ./install, which can be erroneously created by make from ./install.sh.
+echo "$as_me:$LINENO: checking for a BSD-compatible install" >&5
+echo $ECHO_N "checking for a BSD-compatible install... $ECHO_C" >&6
+if test -z "$INSTALL"; then
+if test "${ac_cv_path_install+set}" = set; then
+ echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+ as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+ IFS=$as_save_IFS
+ test -z "$as_dir" && as_dir=.
+ # Account for people who put trailing slashes in PATH elements.
+case $as_dir/ in
+ ./ | .// | /cC/* | \
+ /etc/* | /usr/sbin/* | /usr/etc/* | /sbin/* | /usr/afsws/bin/* | \
+ ?:\\/os2\\/install\\/* | ?:\\/OS2\\/INSTALL\\/* | \
+ /usr/ucb/* ) ;;
+ *)
+ # OSF1 and SCO ODT 3.0 have their own names for install.
+ # Don't use installbsd from OSF since it installs stuff as root
+ # by default.
+ for ac_prog in ginstall scoinst install; do
+ for ac_exec_ext in '' $ac_executable_extensions; do
+ if $as_executable_p "$as_dir/$ac_prog$ac_exec_ext"; then
+ if test $ac_prog = install &&
+ grep dspmsg "$as_dir/$ac_prog$ac_exec_ext" >/dev/null 2>&1; then
+ # AIX install. It has an incompatible calling convention.
+ :
+ elif test $ac_prog = install &&
+ grep pwplus "$as_dir/$ac_prog$ac_exec_ext" >/dev/null 2>&1; then
+ # program-specific install script used by HP pwplus--don't use.
+ :
+ else
+ ac_cv_path_install="$as_dir/$ac_prog$ac_exec_ext -c"
+ break 3
+ fi
+ fi
+ done
+ done
+ ;;
+esac
+done
+
+
+fi
+ if test "${ac_cv_path_install+set}" = set; then
+ INSTALL=$ac_cv_path_install
+ else
+ # As a last resort, use the slow shell script. We don't cache a
+ # path for INSTALL within a source directory, because that will
+ # break other packages using the cache if that directory is
+ # removed, or if the path is relative.
+ INSTALL=$ac_install_sh
+ fi
+fi
+echo "$as_me:$LINENO: result: $INSTALL" >&5
+echo "${ECHO_T}$INSTALL" >&6
+
+# Use test -z because SunOS4 sh mishandles braces in ${var-val}.
+# It thinks the first close brace ends the variable substitution.
+test -z "$INSTALL_PROGRAM" && INSTALL_PROGRAM='${INSTALL}'
+
+test -z "$INSTALL_SCRIPT" && INSTALL_SCRIPT='${INSTALL}'
+
+test -z "$INSTALL_DATA" && INSTALL_DATA='${INSTALL} -m 644'
+
+
+NEED_JNI_MD=yes
+
+ tempval=""
+ echo "$as_me:$LINENO: checking for JDK location (please wait)" >&5
+echo $ECHO_N "checking for JDK location (please wait)... $ECHO_C" >&6
+ if test -n "${JAVA_HOME}" ; then
+ JAVA_HOME_ENV="${JAVA_HOME}"
+ else
+ JAVA_HOME_ENV=""
+ fi
+
+ JAVA_HOME=""
+ JAVA_PLATFORM=""
+
+
+# Check whether --with-java-home or --without-java-home was given.
+if test "${with_java_home+set}" = set; then
+ withval="$with_java_home"
+
+
+ # This stuff works if the command line parameter --with-java-home was
+ # specified, so it takes priority rightfully.
+
+ tempval=${withval}
+
+ if test ! -d "${tempval}" ; then
+ { { echo "$as_me:$LINENO: error: Not a directory: ${tempval}" >&5
+echo "$as_me: error: Not a directory: ${tempval}" >&2;}
+ { (exit 1); exit 1; }; }
+ fi
+
+ JAVA_HOME=${tempval}
+ echo "$as_me:$LINENO: result: ${JAVA_HOME}" >&5
+echo "${ECHO_T}${JAVA_HOME}" >&6
+
+else
+
+ # This works if the parameter was NOT specified, so it's a good time
+ # to see what the environment says.
+ # Since Sun uses JAVA_HOME a lot, we check it first and ignore the
+ # JAVA_HOME, otherwise just use whatever JAVA_HOME was specified.
+
+ if test -n "${JAVA_HOME_ENV}" ; then
+ JAVA_HOME=${JAVA_HOME_ENV}
+ echo "$as_me:$LINENO: result: ${JAVA_HOME_ENV} from environment" >&5
+echo "${ECHO_T}${JAVA_HOME_ENV} from environment" >&6
+ fi
+
+fi;
+
+ if test -z "${JAVA_HOME}" ; then
+
+ # Oh well, nobody set neither JAVA_HOME nor JAVA_HOME, have to guess
+ # The following code is based on the code submitted by Henner Zeller
+ # for ${srcdir}/src/scripts/package/rpm/ApacheJServ.spec
+ # Two variables will be set as a result:
+ #
+ # JAVA_HOME
+ # JAVA_PLATFORM
+ echo "$as_me:$LINENO: checking Try to guess JDK location" >&5
+echo $ECHO_N "checking Try to guess JDK location... $ECHO_C" >&6
+
+ for JAVA_PREFIX in /usr/local /usr/local/lib /usr /usr/lib /opt /usr/java /System/Library/Frameworks/JavaVM.framework/Versions
+ do
+ for JAVA_PLATFORM in 8 7 6 5 4 3 2
+ do
+ for subversion in .9 .8 .7 .6 .5 .4 .3 .2 .1 .0 ""
+ do
+ for VARIANT in IBMJava2- diablo-jdk java java- jdk jdk- ""
+ do
+ GUESS="${JAVA_PREFIX}/${VARIANT}1.${JAVA_PLATFORM}${subversion}"
+ if test -d "${GUESS}/bin" & test -d "${GUESS}/include"
+ then
+ JAVA_HOME="${GUESS}"
+ echo "$as_me:$LINENO: result: ${GUESS}" >&5
+echo "${ECHO_T}${GUESS}" >&6
+ break
+ fi
+ if test -d "${GUESS}/Commands" & test -d "${GUESS}/Headers"
+ then
+ JAVA_HOME="${GUESS}"
+ echo "$as_me:$LINENO: result: ${GUESS}" >&5
+echo "${ECHO_T}${GUESS}" >&6
+ break
+ fi
+
+ done
+
+ if test -n "${JAVA_HOME}" ; then
+ break;
+ fi
+
+ done
+
+ if test -n "${JAVA_HOME}" ; then
+ break;
+ fi
+
+ done
+
+ if test -n "${JAVA_HOME}" ; then
+ break;
+ fi
+
+ done
+
+ if test ! -n "${JAVA_HOME}" ; then
+ { { echo "$as_me:$LINENO: error: can't locate a valid JDK location" >&5
+echo "$as_me: error: can't locate a valid JDK location" >&2;}
+ { (exit 1); exit 1; }; }
+ fi
+
+ fi
+
+ if test -n "${JAVA_PLATFORM}"; then
+ echo "$as_me:$LINENO: result: Java Platform detected - 1.${JAVA_PLATFORM}" >&5
+echo "${ECHO_T}Java Platform detected - 1.${JAVA_PLATFORM}" >&6
+ else
+ echo "$as_me:$LINENO: checking Java platform" >&5
+echo $ECHO_N "checking Java platform... $ECHO_C" >&6
+ fi
+
+
+# Check whether --with-java-platform or --without-java-platform was given.
+if test "${with_java_platform+set}" = set; then
+ withval="$with_java_platform"
+
+ case "${withval}" in
+ "1"|"2")
+ JAVA_PLATFORM=${withval}
+ ;;
+ *)
+ { { echo "$as_me:$LINENO: error: invalid java platform provided" >&5
+echo "$as_me: error: invalid java platform provided" >&2;}
+ { (exit 1); exit 1; }; }
+ ;;
+ esac
+
+else
+
+ if test -n "${JAVA_PLATFORM}"; then
+ echo "$as_me:$LINENO: result: Java Platform detected - 1.${JAVA_PLATFORM}" >&5
+echo "${ECHO_T}Java Platform detected - 1.${JAVA_PLATFORM}" >&6
+ else
+ echo "$as_me:$LINENO: checking Java platform" >&5
+echo $ECHO_N "checking Java platform... $ECHO_C" >&6
+ fi
+
+fi;
+
+ echo "$as_me:$LINENO: result: ${JAVA_PLATFORM}" >&5
+echo "${ECHO_T}${JAVA_PLATFORM}" >&6
+
+ unset tempval
+
+
+ if test x"$JAVA_HOME" != x
+ then
+ # Extract the first word of "sablevm", so it can be a program name with args.
+set dummy sablevm; ac_word=$2
+echo "$as_me:$LINENO: checking for $ac_word" >&5
+echo $ECHO_N "checking for $ac_word... $ECHO_C" >&6
+if test "${ac_cv_path_SABLEVM+set}" = set; then
+ echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+ case $SABLEVM in
+ [\\/]* | ?:[\\/]*)
+ ac_cv_path_SABLEVM="$SABLEVM" # Let the user override the test with a path.
+ ;;
+ *)
+ as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $JAVA_HOME/bin
+do
+ IFS=$as_save_IFS
+ test -z "$as_dir" && as_dir=.
+ for ac_exec_ext in '' $ac_executable_extensions; do
+ if $as_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+ ac_cv_path_SABLEVM="$as_dir/$ac_word$ac_exec_ext"
+ echo "$as_me:$LINENO: found $as_dir/$ac_word$ac_exec_ext" >&5
+ break 2
+ fi
+done
+done
+
+ test -z "$ac_cv_path_SABLEVM" && ac_cv_path_SABLEVM="NONE"
+ ;;
+esac
+fi
+SABLEVM=$ac_cv_path_SABLEVM
+
+if test -n "$SABLEVM"; then
+ echo "$as_me:$LINENO: result: $SABLEVM" >&5
+echo "${ECHO_T}$SABLEVM" >&6
+else
+ echo "$as_me:$LINENO: result: no" >&5
+echo "${ECHO_T}no" >&6
+fi
+
+ if test "$SABLEVM" != "NONE"
+ then
+ echo "$as_me:$LINENO: result: Using sableVM: $SABLEVM" >&5
+echo "${ECHO_T}Using sableVM: $SABLEVM" >&6
+ CFLAGS="$CFLAGS -DHAVE_SABLEVM"
+ NEED_JNI_MD=no
+ fi
+ fi
+
+
+ if test x"$JAVA_HOME" != x
+ then
+ J9VM=`$JAVA_HOME/bin/java -version 2>&1 | grep J9VM`
+ if test x"$J9VM" != x
+ then
+ echo "$as_me:$LINENO: result: Using J9VM: $J9VM" >&5
+echo "${ECHO_T}Using J9VM: $J9VM" >&6
+ NEED_JNI_MD=no
+ fi
+ fi
+
+
+if test -d ${JAVA_HOME}/Headers; then
+ JAVA_INC=Headers
+else
+ JAVA_INC=include
+fi
+
+ if test "x$TCNATIVE_PRIV_INCLUDES" = "x"; then
+ test "x$silent" != "xyes" && echo " setting TCNATIVE_PRIV_INCLUDES to \"-I$JAVA_HOME/$JAVA_INC\""
+ TCNATIVE_PRIV_INCLUDES="-I$JAVA_HOME/$JAVA_INC"
+ else
+ apr_addto_bugger="-I$JAVA_HOME/$JAVA_INC"
+ for i in $apr_addto_bugger; do
+ apr_addto_duplicate="0"
+ for j in $TCNATIVE_PRIV_INCLUDES; do
+ if test "x$i" = "x$j"; then
+ apr_addto_duplicate="1"
+ break
+ fi
+ done
+ if test $apr_addto_duplicate = "0"; then
+ test "x$silent" != "xyes" && echo " adding \"$i\" to TCNATIVE_PRIV_INCLUDES"
+ TCNATIVE_PRIV_INCLUDES="$TCNATIVE_PRIV_INCLUDES $i"
+ fi
+ done
+ fi
+
+
+if test "$NEED_JNI_MD" = "yes"; then
+
+ tempval=""
+ JAVA_OS=""
+
+# Check whether --with-os-type or --without-os-type was given.
+if test "${with_os_type+set}" = set; then
+ withval="$with_os_type"
+
+ tempval=${withval}
+
+ if test ! -d "${JAVA_HOME}/${tempval}" ; then
+ { { echo "$as_me:$LINENO: error: Not a directory: ${JAVA_HOME}/${tempval}" >&5
+echo "$as_me: error: Not a directory: ${JAVA_HOME}/${tempval}" >&2;}
+ { (exit 1); exit 1; }; }
+ fi
+
+ JAVA_OS = ${tempval}
+
+else
+
+ echo "$as_me:$LINENO: checking os_type directory" >&5
+echo $ECHO_N "checking os_type directory... $ECHO_C" >&6
+ JAVA_OS=NONE
+ if test -f ${JAVA_HOME}/${JAVA_INC}/jni_md.h; then
+ JAVA_OS=""
+ else
+ for f in ${JAVA_HOME}/${JAVA_INC}/*/jni_md.h; do
+ if test -f $f; then
+ JAVA_OS=`dirname ${f}`
+ JAVA_OS=`basename ${JAVA_OS}`
+ echo " ${JAVA_OS}"
+ fi
+ done
+ if test "${JAVA_OS}" = "NONE"; then
+ echo "$as_me:$LINENO: result: Cannot find jni_md.h in ${JAVA_HOME}/${OS}" >&5
+echo "${ECHO_T}Cannot find jni_md.h in ${JAVA_HOME}/${OS}" >&6
+ { { echo "$as_me:$LINENO: error: You should retry --with-os-type=SUBDIR" >&5
+echo "$as_me: error: You should retry --with-os-type=SUBDIR" >&2;}
+ { (exit 1); exit 1; }; }
+ fi
+ fi
+
+fi;
+
+ if test -z "${JAVA_OS}"; then
+ echo "$as_me:$LINENO: result: jni_md.h found in $JAVA_HOME/$JAVA_INC" >&5
+echo "${ECHO_T}jni_md.h found in $JAVA_HOME/$JAVA_INC" >&6
+ else
+
+ if test "x$TCNATIVE_PRIV_INCLUDES" = "x"; then
+ test "x$silent" != "xyes" && echo " setting TCNATIVE_PRIV_INCLUDES to \"-I$JAVA_HOME/$JAVA_INC/$JAVA_OS\""
+ TCNATIVE_PRIV_INCLUDES="-I$JAVA_HOME/$JAVA_INC/$JAVA_OS"
+ else
+ apr_addto_bugger="-I$JAVA_HOME/$JAVA_INC/$JAVA_OS"
+ for i in $apr_addto_bugger; do
+ apr_addto_duplicate="0"
+ for j in $TCNATIVE_PRIV_INCLUDES; do
+ if test "x$i" = "x$j"; then
+ apr_addto_duplicate="1"
+ break
+ fi
+ done
+ if test $apr_addto_duplicate = "0"; then
+ test "x$silent" != "xyes" && echo " adding \"$i\" to TCNATIVE_PRIV_INCLUDES"
+ TCNATIVE_PRIV_INCLUDES="$TCNATIVE_PRIV_INCLUDES $i"
+ fi
+ done
+ fi
+
+ fi
+fi
+
+
+
+
+
+
+
+use_openssl=true;
+
+# Check whether --enable-openssl or --disable-openssl was given.
+if test "${enable_openssl+set}" = set; then
+ enableval="$enable_openssl"
+
+ case "${enableval}" in
+ no )
+ use_openssl=false;
+ echo "$as_me:$LINENO: result: Disabling SSL support..." >&5
+echo "${ECHO_T}Disabling SSL support..." >&6
+ ;;
+ esac
+
+fi;
+
+# Check whether --enable-ocsp or --disable-ocsp was given.
+if test "${enable_ocsp+set}" = set; then
+ enableval="$enable_ocsp"
+
+ case "${enableval}" in
+ yes )
+
+ if test "x$CFLAGS" = "x"; then
+ test "x$silent" != "xyes" && echo " setting CFLAGS to \"-DHAVE_OPENSSL_OCSP\""
+ CFLAGS="-DHAVE_OPENSSL_OCSP"
+ else
+ apr_addto_bugger="-DHAVE_OPENSSL_OCSP"
+ for i in $apr_addto_bugger; do
+ apr_addto_duplicate="0"
+ for j in $CFLAGS; do
+ if test "x$i" = "x$j"; then
+ apr_addto_duplicate="1"
+ break
+ fi
+ done
+ if test $apr_addto_duplicate = "0"; then
+ test "x$silent" != "xyes" && echo " adding \"$i\" to CFLAGS"
+ CFLAGS="$CFLAGS $i"
+ fi
+ done
+ fi
+
+ echo "$as_me:$LINENO: result: Enabling OCSP verification support..." >&5
+echo "${ECHO_T}Enabling OCSP verification support..." >&6
+ ;;
+ esac
+
+fi;
+
+if $use_openssl ; then
+ ac_ext=c
+ac_cpp='$CPP $CPPFLAGS'
+ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
+ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
+ac_compiler_gnu=$ac_cv_c_compiler_gnu
+if test -n "$ac_tool_prefix"; then
+ # Extract the first word of "${ac_tool_prefix}gcc", so it can be a program name with args.
+set dummy ${ac_tool_prefix}gcc; ac_word=$2
+echo "$as_me:$LINENO: checking for $ac_word" >&5
+echo $ECHO_N "checking for $ac_word... $ECHO_C" >&6
+if test "${ac_cv_prog_CC+set}" = set; then
+ echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+ if test -n "$CC"; then
+ ac_cv_prog_CC="$CC" # Let the user override the test.
+else
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+ IFS=$as_save_IFS
+ test -z "$as_dir" && as_dir=.
+ for ac_exec_ext in '' $ac_executable_extensions; do
+ if $as_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+ ac_cv_prog_CC="${ac_tool_prefix}gcc"
+ echo "$as_me:$LINENO: found $as_dir/$ac_word$ac_exec_ext" >&5
+ break 2
+ fi
+done
+done
+
+fi
+fi
+CC=$ac_cv_prog_CC
+if test -n "$CC"; then
+ echo "$as_me:$LINENO: result: $CC" >&5
+echo "${ECHO_T}$CC" >&6
+else
+ echo "$as_me:$LINENO: result: no" >&5
+echo "${ECHO_T}no" >&6
+fi
+
+fi
+if test -z "$ac_cv_prog_CC"; then
+ ac_ct_CC=$CC
+ # Extract the first word of "gcc", so it can be a program name with args.
+set dummy gcc; ac_word=$2
+echo "$as_me:$LINENO: checking for $ac_word" >&5
+echo $ECHO_N "checking for $ac_word... $ECHO_C" >&6
+if test "${ac_cv_prog_ac_ct_CC+set}" = set; then
+ echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+ if test -n "$ac_ct_CC"; then
+ ac_cv_prog_ac_ct_CC="$ac_ct_CC" # Let the user override the test.
+else
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+ IFS=$as_save_IFS
+ test -z "$as_dir" && as_dir=.
+ for ac_exec_ext in '' $ac_executable_extensions; do
+ if $as_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+ ac_cv_prog_ac_ct_CC="gcc"
+ echo "$as_me:$LINENO: found $as_dir/$ac_word$ac_exec_ext" >&5
+ break 2
+ fi
+done
+done
+
+fi
+fi
+ac_ct_CC=$ac_cv_prog_ac_ct_CC
+if test -n "$ac_ct_CC"; then
+ echo "$as_me:$LINENO: result: $ac_ct_CC" >&5
+echo "${ECHO_T}$ac_ct_CC" >&6
+else
+ echo "$as_me:$LINENO: result: no" >&5
+echo "${ECHO_T}no" >&6
+fi
+
+ CC=$ac_ct_CC
+else
+ CC="$ac_cv_prog_CC"
+fi
+
+if test -z "$CC"; then
+ if test -n "$ac_tool_prefix"; then
+ # Extract the first word of "${ac_tool_prefix}cc", so it can be a program name with args.
+set dummy ${ac_tool_prefix}cc; ac_word=$2
+echo "$as_me:$LINENO: checking for $ac_word" >&5
+echo $ECHO_N "checking for $ac_word... $ECHO_C" >&6
+if test "${ac_cv_prog_CC+set}" = set; then
+ echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+ if test -n "$CC"; then
+ ac_cv_prog_CC="$CC" # Let the user override the test.
+else
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+ IFS=$as_save_IFS
+ test -z "$as_dir" && as_dir=.
+ for ac_exec_ext in '' $ac_executable_extensions; do
+ if $as_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+ ac_cv_prog_CC="${ac_tool_prefix}cc"
+ echo "$as_me:$LINENO: found $as_dir/$ac_word$ac_exec_ext" >&5
+ break 2
+ fi
+done
+done
+
+fi
+fi
+CC=$ac_cv_prog_CC
+if test -n "$CC"; then
+ echo "$as_me:$LINENO: result: $CC" >&5
+echo "${ECHO_T}$CC" >&6
+else
+ echo "$as_me:$LINENO: result: no" >&5
+echo "${ECHO_T}no" >&6
+fi
+
+fi
+if test -z "$ac_cv_prog_CC"; then
+ ac_ct_CC=$CC
+ # Extract the first word of "cc", so it can be a program name with args.
+set dummy cc; ac_word=$2
+echo "$as_me:$LINENO: checking for $ac_word" >&5
+echo $ECHO_N "checking for $ac_word... $ECHO_C" >&6
+if test "${ac_cv_prog_ac_ct_CC+set}" = set; then
+ echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+ if test -n "$ac_ct_CC"; then
+ ac_cv_prog_ac_ct_CC="$ac_ct_CC" # Let the user override the test.
+else
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+ IFS=$as_save_IFS
+ test -z "$as_dir" && as_dir=.
+ for ac_exec_ext in '' $ac_executable_extensions; do
+ if $as_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+ ac_cv_prog_ac_ct_CC="cc"
+ echo "$as_me:$LINENO: found $as_dir/$ac_word$ac_exec_ext" >&5
+ break 2
+ fi
+done
+done
+
+fi
+fi
+ac_ct_CC=$ac_cv_prog_ac_ct_CC
+if test -n "$ac_ct_CC"; then
+ echo "$as_me:$LINENO: result: $ac_ct_CC" >&5
+echo "${ECHO_T}$ac_ct_CC" >&6
+else
+ echo "$as_me:$LINENO: result: no" >&5
+echo "${ECHO_T}no" >&6
+fi
+
+ CC=$ac_ct_CC
+else
+ CC="$ac_cv_prog_CC"
+fi
+
+fi
+if test -z "$CC"; then
+ # Extract the first word of "cc", so it can be a program name with args.
+set dummy cc; ac_word=$2
+echo "$as_me:$LINENO: checking for $ac_word" >&5
+echo $ECHO_N "checking for $ac_word... $ECHO_C" >&6
+if test "${ac_cv_prog_CC+set}" = set; then
+ echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+ if test -n "$CC"; then
+ ac_cv_prog_CC="$CC" # Let the user override the test.
+else
+ ac_prog_rejected=no
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+ IFS=$as_save_IFS
+ test -z "$as_dir" && as_dir=.
+ for ac_exec_ext in '' $ac_executable_extensions; do
+ if $as_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+ if test "$as_dir/$ac_word$ac_exec_ext" = "/usr/ucb/cc"; then
+ ac_prog_rejected=yes
+ continue
+ fi
+ ac_cv_prog_CC="cc"
+ echo "$as_me:$LINENO: found $as_dir/$ac_word$ac_exec_ext" >&5
+ break 2
+ fi
+done
+done
+
+if test $ac_prog_rejected = yes; then
+ # We found a bogon in the path, so make sure we never use it.
+ set dummy $ac_cv_prog_CC
+ shift
+ if test $# != 0; then
+ # We chose a different compiler from the bogus one.
+ # However, it has the same basename, so the bogon will be chosen
+ # first if we set CC to just the basename; use the full file name.
+ shift
+ ac_cv_prog_CC="$as_dir/$ac_word${1+' '}$@"
+ fi
+fi
+fi
+fi
+CC=$ac_cv_prog_CC
+if test -n "$CC"; then
+ echo "$as_me:$LINENO: result: $CC" >&5
+echo "${ECHO_T}$CC" >&6
+else
+ echo "$as_me:$LINENO: result: no" >&5
+echo "${ECHO_T}no" >&6
+fi
+
+fi
+if test -z "$CC"; then
+ if test -n "$ac_tool_prefix"; then
+ for ac_prog in cl
+ do
+ # Extract the first word of "$ac_tool_prefix$ac_prog", so it can be a program name with args.
+set dummy $ac_tool_prefix$ac_prog; ac_word=$2
+echo "$as_me:$LINENO: checking for $ac_word" >&5
+echo $ECHO_N "checking for $ac_word... $ECHO_C" >&6
+if test "${ac_cv_prog_CC+set}" = set; then
+ echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+ if test -n "$CC"; then
+ ac_cv_prog_CC="$CC" # Let the user override the test.
+else
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+ IFS=$as_save_IFS
+ test -z "$as_dir" && as_dir=.
+ for ac_exec_ext in '' $ac_executable_extensions; do
+ if $as_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+ ac_cv_prog_CC="$ac_tool_prefix$ac_prog"
+ echo "$as_me:$LINENO: found $as_dir/$ac_word$ac_exec_ext" >&5
+ break 2
+ fi
+done
+done
+
+fi
+fi
+CC=$ac_cv_prog_CC
+if test -n "$CC"; then
+ echo "$as_me:$LINENO: result: $CC" >&5
+echo "${ECHO_T}$CC" >&6
+else
+ echo "$as_me:$LINENO: result: no" >&5
+echo "${ECHO_T}no" >&6
+fi
+
+ test -n "$CC" && break
+ done
+fi
+if test -z "$CC"; then
+ ac_ct_CC=$CC
+ for ac_prog in cl
+do
+ # Extract the first word of "$ac_prog", so it can be a program name with args.
+set dummy $ac_prog; ac_word=$2
+echo "$as_me:$LINENO: checking for $ac_word" >&5
+echo $ECHO_N "checking for $ac_word... $ECHO_C" >&6
+if test "${ac_cv_prog_ac_ct_CC+set}" = set; then
+ echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+ if test -n "$ac_ct_CC"; then
+ ac_cv_prog_ac_ct_CC="$ac_ct_CC" # Let the user override the test.
+else
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+ IFS=$as_save_IFS
+ test -z "$as_dir" && as_dir=.
+ for ac_exec_ext in '' $ac_executable_extensions; do
+ if $as_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
+ ac_cv_prog_ac_ct_CC="$ac_prog"
+ echo "$as_me:$LINENO: found $as_dir/$ac_word$ac_exec_ext" >&5
+ break 2
+ fi
+done
+done
+
+fi
+fi
+ac_ct_CC=$ac_cv_prog_ac_ct_CC
+if test -n "$ac_ct_CC"; then
+ echo "$as_me:$LINENO: result: $ac_ct_CC" >&5
+echo "${ECHO_T}$ac_ct_CC" >&6
+else
+ echo "$as_me:$LINENO: result: no" >&5
+echo "${ECHO_T}no" >&6
+fi
+
+ test -n "$ac_ct_CC" && break
+done
+
+ CC=$ac_ct_CC
+fi
+
+fi
+
+
+test -z "$CC" && { { echo "$as_me:$LINENO: error: no acceptable C compiler found in \$PATH
+See \`config.log' for more details." >&5
+echo "$as_me: error: no acceptable C compiler found in \$PATH
+See \`config.log' for more details." >&2;}
+ { (exit 1); exit 1; }; }
+
+# Provide some information about the compiler.
+echo "$as_me:$LINENO:" \
+ "checking for C compiler version" >&5
+ac_compiler=`set X $ac_compile; echo $2`
+{ (eval echo "$as_me:$LINENO: \"$ac_compiler --version </dev/null >&5\"") >&5
+ (eval $ac_compiler --version </dev/null >&5) 2>&5
+ ac_status=$?
+ echo "$as_me:$LINENO: \$? = $ac_status" >&5
+ (exit $ac_status); }
+{ (eval echo "$as_me:$LINENO: \"$ac_compiler -v </dev/null >&5\"") >&5
+ (eval $ac_compiler -v </dev/null >&5) 2>&5
+ ac_status=$?
+ echo "$as_me:$LINENO: \$? = $ac_status" >&5
+ (exit $ac_status); }
+{ (eval echo "$as_me:$LINENO: \"$ac_compiler -V </dev/null >&5\"") >&5
+ (eval $ac_compiler -V </dev/null >&5) 2>&5
+ ac_status=$?
+ echo "$as_me:$LINENO: \$? = $ac_status" >&5
+ (exit $ac_status); }
+
+cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h. */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h. */
+
+int
+main ()
+{
+
+ ;
+ return 0;
+}
+_ACEOF
+ac_clean_files_save=$ac_clean_files
+ac_clean_files="$ac_clean_files a.out a.exe b.out"
+# Try to create an executable without -o first, disregard a.out.
+# It will help us diagnose broken compilers, and finding out an intuition
+# of exeext.
+echo "$as_me:$LINENO: checking for C compiler default output file name" >&5
+echo $ECHO_N "checking for C compiler default output file name... $ECHO_C" >&6
+ac_link_default=`echo "$ac_link" | sed 's/ -o *conftest[^ ]*//'`
+if { (eval echo "$as_me:$LINENO: \"$ac_link_default\"") >&5
+ (eval $ac_link_default) 2>&5
+ ac_status=$?
+ echo "$as_me:$LINENO: \$? = $ac_status" >&5
+ (exit $ac_status); }; then
+ # Find the output, starting from the most likely. This scheme is
+# not robust to junk in `.', hence go to wildcards (a.*) only as a last
+# resort.
+
+# Be careful to initialize this variable, since it used to be cached.
+# Otherwise an old cache value of `no' led to `EXEEXT = no' in a Makefile.
+ac_cv_exeext=
+# b.out is created by i960 compilers.
+for ac_file in a_out.exe a.exe conftest.exe a.out conftest a.* conftest.* b.out
+do
+ test -f "$ac_file" || continue
+ case $ac_file in
+ *.$ac_ext | *.xcoff | *.tds | *.d | *.pdb | *.xSYM | *.bb | *.bbg | *.o | *.obj )
+ ;;
+ conftest.$ac_ext )
+ # This is the source file.
+ ;;
+ [ab].out )
+ # We found the default executable, but exeext='' is most
+ # certainly right.
+ break;;
+ *.* )
+ ac_cv_exeext=`expr "$ac_file" : '[^.]*\(\..*\)'`
+ # FIXME: I believe we export ac_cv_exeext for Libtool,
+ # but it would be cool to find out if it's true. Does anybody
+ # maintain Libtool? --akim.
+ export ac_cv_exeext
+ break;;
+ * )
+ break;;
+ esac
+done
+else
+ echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+{ { echo "$as_me:$LINENO: error: C compiler cannot create executables
+See \`config.log' for more details." >&5
+echo "$as_me: error: C compiler cannot create executables
+See \`config.log' for more details." >&2;}
+ { (exit 77); exit 77; }; }
+fi
+
+ac_exeext=$ac_cv_exeext
+echo "$as_me:$LINENO: result: $ac_file" >&5
+echo "${ECHO_T}$ac_file" >&6
+
+# Check the compiler produces executables we can run. If not, either
+# the compiler is broken, or we cross compile.
+echo "$as_me:$LINENO: checking whether the C compiler works" >&5
+echo $ECHO_N "checking whether the C compiler works... $ECHO_C" >&6
+# FIXME: These cross compiler hacks should be removed for Autoconf 3.0
+# If not cross compiling, check that we can run a simple program.
+if test "$cross_compiling" != yes; then
+ if { ac_try='./$ac_file'
+ { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+ (eval $ac_try) 2>&5
+ ac_status=$?
+ echo "$as_me:$LINENO: \$? = $ac_status" >&5
+ (exit $ac_status); }; }; then
+ cross_compiling=no
+ else
+ if test "$cross_compiling" = maybe; then
+ cross_compiling=yes
+ else
+ { { echo "$as_me:$LINENO: error: cannot run C compiled programs.
+If you meant to cross compile, use \`--host'.
+See \`config.log' for more details." >&5
+echo "$as_me: error: cannot run C compiled programs.
+If you meant to cross compile, use \`--host'.
+See \`config.log' for more details." >&2;}
+ { (exit 1); exit 1; }; }
+ fi
+ fi
+fi
+echo "$as_me:$LINENO: result: yes" >&5
+echo "${ECHO_T}yes" >&6
+
+rm -f a.out a.exe conftest$ac_cv_exeext b.out
+ac_clean_files=$ac_clean_files_save
+# Check the compiler produces executables we can run. If not, either
+# the compiler is broken, or we cross compile.
+echo "$as_me:$LINENO: checking whether we are cross compiling" >&5
+echo $ECHO_N "checking whether we are cross compiling... $ECHO_C" >&6
+echo "$as_me:$LINENO: result: $cross_compiling" >&5
+echo "${ECHO_T}$cross_compiling" >&6
+
+echo "$as_me:$LINENO: checking for suffix of executables" >&5
+echo $ECHO_N "checking for suffix of executables... $ECHO_C" >&6
+if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5
+ (eval $ac_link) 2>&5
+ ac_status=$?
+ echo "$as_me:$LINENO: \$? = $ac_status" >&5
+ (exit $ac_status); }; then
+ # If both `conftest.exe' and `conftest' are `present' (well, observable)
+# catch `conftest.exe'. For instance with Cygwin, `ls conftest' will
+# work properly (i.e., refer to `conftest.exe'), while it won't with
+# `rm'.
+for ac_file in conftest.exe conftest conftest.*; do
+ test -f "$ac_file" || continue
+ case $ac_file in
+ *.$ac_ext | *.xcoff | *.tds | *.d | *.pdb | *.xSYM | *.bb | *.bbg | *.o | *.obj ) ;;
+ *.* ) ac_cv_exeext=`expr "$ac_file" : '[^.]*\(\..*\)'`
+ export ac_cv_exeext
+ break;;
+ * ) break;;
+ esac
+done
+else
+ { { echo "$as_me:$LINENO: error: cannot compute suffix of executables: cannot compile and link
+See \`config.log' for more details." >&5
+echo "$as_me: error: cannot compute suffix of executables: cannot compile and link
+See \`config.log' for more details." >&2;}
+ { (exit 1); exit 1; }; }
+fi
+
+rm -f conftest$ac_cv_exeext
+echo "$as_me:$LINENO: result: $ac_cv_exeext" >&5
+echo "${ECHO_T}$ac_cv_exeext" >&6
+
+rm -f conftest.$ac_ext
+EXEEXT=$ac_cv_exeext
+ac_exeext=$EXEEXT
+echo "$as_me:$LINENO: checking for suffix of object files" >&5
+echo $ECHO_N "checking for suffix of object files... $ECHO_C" >&6
+if test "${ac_cv_objext+set}" = set; then
+ echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+ cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h. */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h. */
+
+int
+main ()
+{
+
+ ;
+ return 0;
+}
+_ACEOF
+rm -f conftest.o conftest.obj
+if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
+ (eval $ac_compile) 2>&5
+ ac_status=$?
+ echo "$as_me:$LINENO: \$? = $ac_status" >&5
+ (exit $ac_status); }; then
+ for ac_file in `(ls conftest.o conftest.obj; ls conftest.*) 2>/dev/null`; do
+ case $ac_file in
+ *.$ac_ext | *.xcoff | *.tds | *.d | *.pdb | *.xSYM | *.bb | *.bbg ) ;;
+ *) ac_cv_objext=`expr "$ac_file" : '.*\.\(.*\)'`
+ break;;
+ esac
+done
+else
+ echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+{ { echo "$as_me:$LINENO: error: cannot compute suffix of object files: cannot compile
+See \`config.log' for more details." >&5
+echo "$as_me: error: cannot compute suffix of object files: cannot compile
+See \`config.log' for more details." >&2;}
+ { (exit 1); exit 1; }; }
+fi
+
+rm -f conftest.$ac_cv_objext conftest.$ac_ext
+fi
+echo "$as_me:$LINENO: result: $ac_cv_objext" >&5
+echo "${ECHO_T}$ac_cv_objext" >&6
+OBJEXT=$ac_cv_objext
+ac_objext=$OBJEXT
+echo "$as_me:$LINENO: checking whether we are using the GNU C compiler" >&5
+echo $ECHO_N "checking whether we are using the GNU C compiler... $ECHO_C" >&6
+if test "${ac_cv_c_compiler_gnu+set}" = set; then
+ echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+ cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h. */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h. */
+
+int
+main ()
+{
+#ifndef __GNUC__
+ choke me
+#endif
+
+ ;
+ return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext
+if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
+ (eval $ac_compile) 2>conftest.er1
+ ac_status=$?
+ grep -v '^ *+' conftest.er1 >conftest.err
+ rm -f conftest.er1
+ cat conftest.err >&5
+ echo "$as_me:$LINENO: \$? = $ac_status" >&5
+ (exit $ac_status); } &&
+ { ac_try='test -z "$ac_c_werror_flag"
+ || test ! -s conftest.err'
+ { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+ (eval $ac_try) 2>&5
+ ac_status=$?
+ echo "$as_me:$LINENO: \$? = $ac_status" >&5
+ (exit $ac_status); }; } &&
+ { ac_try='test -s conftest.$ac_objext'
+ { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+ (eval $ac_try) 2>&5
+ ac_status=$?
+ echo "$as_me:$LINENO: \$? = $ac_status" >&5
+ (exit $ac_status); }; }; then
+ ac_compiler_gnu=yes
+else
+ echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+ac_compiler_gnu=no
+fi
+rm -f conftest.err conftest.$ac_objext conftest.$ac_ext
+ac_cv_c_compiler_gnu=$ac_compiler_gnu
+
+fi
+echo "$as_me:$LINENO: result: $ac_cv_c_compiler_gnu" >&5
+echo "${ECHO_T}$ac_cv_c_compiler_gnu" >&6
+GCC=`test $ac_compiler_gnu = yes && echo yes`
+ac_test_CFLAGS=${CFLAGS+set}
+ac_save_CFLAGS=$CFLAGS
+CFLAGS="-g"
+echo "$as_me:$LINENO: checking whether $CC accepts -g" >&5
+echo $ECHO_N "checking whether $CC accepts -g... $ECHO_C" >&6
+if test "${ac_cv_prog_cc_g+set}" = set; then
+ echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+ cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h. */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h. */
+
+int
+main ()
+{
+
+ ;
+ return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext
+if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
+ (eval $ac_compile) 2>conftest.er1
+ ac_status=$?
+ grep -v '^ *+' conftest.er1 >conftest.err
+ rm -f conftest.er1
+ cat conftest.err >&5
+ echo "$as_me:$LINENO: \$? = $ac_status" >&5
+ (exit $ac_status); } &&
+ { ac_try='test -z "$ac_c_werror_flag"
+ || test ! -s conftest.err'
+ { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+ (eval $ac_try) 2>&5
+ ac_status=$?
+ echo "$as_me:$LINENO: \$? = $ac_status" >&5
+ (exit $ac_status); }; } &&
+ { ac_try='test -s conftest.$ac_objext'
+ { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+ (eval $ac_try) 2>&5
+ ac_status=$?
+ echo "$as_me:$LINENO: \$? = $ac_status" >&5
+ (exit $ac_status); }; }; then
+ ac_cv_prog_cc_g=yes
+else
+ echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+ac_cv_prog_cc_g=no
+fi
+rm -f conftest.err conftest.$ac_objext conftest.$ac_ext
+fi
+echo "$as_me:$LINENO: result: $ac_cv_prog_cc_g" >&5
+echo "${ECHO_T}$ac_cv_prog_cc_g" >&6
+if test "$ac_test_CFLAGS" = set; then
+ CFLAGS=$ac_save_CFLAGS
+elif test $ac_cv_prog_cc_g = yes; then
+ if test "$GCC" = yes; then
+ CFLAGS="-g -O2"
+ else
+ CFLAGS="-g"
+ fi
+else
+ if test "$GCC" = yes; then
+ CFLAGS="-O2"
+ else
+ CFLAGS=
+ fi
+fi
+echo "$as_me:$LINENO: checking for $CC option to accept ANSI C" >&5
+echo $ECHO_N "checking for $CC option to accept ANSI C... $ECHO_C" >&6
+if test "${ac_cv_prog_cc_stdc+set}" = set; then
+ echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+ ac_cv_prog_cc_stdc=no
+ac_save_CC=$CC
+cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h. */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h. */
+#include <stdarg.h>
+#include <stdio.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+/* Most of the following tests are stolen from RCS 5.7's src/conf.sh. */
+struct buf { int x; };
+FILE * (*rcsopen) (struct buf *, struct stat *, int);
+static char *e (p, i)
+ char **p;
+ int i;
+{
+ return p[i];
+}
+static char *f (char * (*g) (char **, int), char **p, ...)
+{
+ char *s;
+ va_list v;
+ va_start (v,p);
+ s = g (p, va_arg (v,int));
+ va_end (v);
+ return s;
+}
+
+/* OSF 4.0 Compaq cc is some sort of almost-ANSI by default. It has
+ function prototypes and stuff, but not '\xHH' hex character constants.
+ These don't provoke an error unfortunately, instead are silently treated
+ as 'x'. The following induces an error, until -std1 is added to get
+ proper ANSI mode. Curiously '\x00'!='x' always comes out true, for an
+ array size at least. It's necessary to write '\x00'==0 to get something
+ that's true only with -std1. */
+int osf4_cc_array ['\x00' == 0 ? 1 : -1];
+
+int test (int i, double x);
+struct s1 {int (*f) (int a);};
+struct s2 {int (*f) (double a);};
+int pairnames (int, char **, FILE *(*)(struct buf *, struct stat *, int), int, int);
+int argc;
+char **argv;
+int
+main ()
+{
+return f (e, argv, 0) != argv[0] || f (e, argv, 1) != argv[1];
+ ;
+ return 0;
+}
+_ACEOF
+# Don't try gcc -ansi; that turns off useful extensions and
+# breaks some systems' header files.
+# AIX -qlanglvl=ansi
+# Ultrix and OSF/1 -std1
+# HP-UX 10.20 and later -Ae
+# HP-UX older versions -Aa -D_HPUX_SOURCE
+# SVR4 -Xc -D__EXTENSIONS__
+for ac_arg in "" -qlanglvl=ansi -std1 -Ae "-Aa -D_HPUX_SOURCE" "-Xc -D__EXTENSIONS__"
+do
+ CC="$ac_save_CC $ac_arg"
+ rm -f conftest.$ac_objext
+if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
+ (eval $ac_compile) 2>conftest.er1
+ ac_status=$?
+ grep -v '^ *+' conftest.er1 >conftest.err
+ rm -f conftest.er1
+ cat conftest.err >&5
+ echo "$as_me:$LINENO: \$? = $ac_status" >&5
+ (exit $ac_status); } &&
+ { ac_try='test -z "$ac_c_werror_flag"
+ || test ! -s conftest.err'
+ { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+ (eval $ac_try) 2>&5
+ ac_status=$?
+ echo "$as_me:$LINENO: \$? = $ac_status" >&5
+ (exit $ac_status); }; } &&
+ { ac_try='test -s conftest.$ac_objext'
+ { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+ (eval $ac_try) 2>&5
+ ac_status=$?
+ echo "$as_me:$LINENO: \$? = $ac_status" >&5
+ (exit $ac_status); }; }; then
+ ac_cv_prog_cc_stdc=$ac_arg
+break
+else
+ echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+fi
+rm -f conftest.err conftest.$ac_objext
+done
+rm -f conftest.$ac_ext conftest.$ac_objext
+CC=$ac_save_CC
+
+fi
+
+case "x$ac_cv_prog_cc_stdc" in
+ x|xno)
+ echo "$as_me:$LINENO: result: none needed" >&5
+echo "${ECHO_T}none needed" >&6 ;;
+ *)
+ echo "$as_me:$LINENO: result: $ac_cv_prog_cc_stdc" >&5
+echo "${ECHO_T}$ac_cv_prog_cc_stdc" >&6
+ CC="$CC $ac_cv_prog_cc_stdc" ;;
+esac
+
+# Some people use a C++ compiler to compile C. Since we use `exit',
+# in C++ we need to declare it. In case someone uses the same compiler
+# for both compiling C and C++ we need to have the C++ compiler decide
+# the declaration of exit, since it's the most demanding environment.
+cat >conftest.$ac_ext <<_ACEOF
+#ifndef __cplusplus
+ choke me
+#endif
+_ACEOF
+rm -f conftest.$ac_objext
+if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
+ (eval $ac_compile) 2>conftest.er1
+ ac_status=$?
+ grep -v '^ *+' conftest.er1 >conftest.err
+ rm -f conftest.er1
+ cat conftest.err >&5
+ echo "$as_me:$LINENO: \$? = $ac_status" >&5
+ (exit $ac_status); } &&
+ { ac_try='test -z "$ac_c_werror_flag"
+ || test ! -s conftest.err'
+ { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+ (eval $ac_try) 2>&5
+ ac_status=$?
+ echo "$as_me:$LINENO: \$? = $ac_status" >&5
+ (exit $ac_status); }; } &&
+ { ac_try='test -s conftest.$ac_objext'
+ { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+ (eval $ac_try) 2>&5
+ ac_status=$?
+ echo "$as_me:$LINENO: \$? = $ac_status" >&5
+ (exit $ac_status); }; }; then
+ for ac_declaration in \
+ '' \
+ 'extern "C" void std::exit (int) throw (); using std::exit;' \
+ 'extern "C" void std::exit (int); using std::exit;' \
+ 'extern "C" void exit (int) throw ();' \
+ 'extern "C" void exit (int);' \
+ 'void exit (int);'
+do
+ cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h. */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h. */
+$ac_declaration
+#include <stdlib.h>
+int
+main ()
+{
+exit (42);
+ ;
+ return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext
+if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
+ (eval $ac_compile) 2>conftest.er1
+ ac_status=$?
+ grep -v '^ *+' conftest.er1 >conftest.err
+ rm -f conftest.er1
+ cat conftest.err >&5
+ echo "$as_me:$LINENO: \$? = $ac_status" >&5
+ (exit $ac_status); } &&
+ { ac_try='test -z "$ac_c_werror_flag"
+ || test ! -s conftest.err'
+ { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+ (eval $ac_try) 2>&5
+ ac_status=$?
+ echo "$as_me:$LINENO: \$? = $ac_status" >&5
+ (exit $ac_status); }; } &&
+ { ac_try='test -s conftest.$ac_objext'
+ { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+ (eval $ac_try) 2>&5
+ ac_status=$?
+ echo "$as_me:$LINENO: \$? = $ac_status" >&5
+ (exit $ac_status); }; }; then
+ :
+else
+ echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+continue
+fi
+rm -f conftest.err conftest.$ac_objext conftest.$ac_ext
+ cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h. */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h. */
+$ac_declaration
+int
+main ()
+{
+exit (42);
+ ;
+ return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext
+if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
+ (eval $ac_compile) 2>conftest.er1
+ ac_status=$?
+ grep -v '^ *+' conftest.er1 >conftest.err
+ rm -f conftest.er1
+ cat conftest.err >&5
+ echo "$as_me:$LINENO: \$? = $ac_status" >&5
+ (exit $ac_status); } &&
+ { ac_try='test -z "$ac_c_werror_flag"
+ || test ! -s conftest.err'
+ { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+ (eval $ac_try) 2>&5
+ ac_status=$?
+ echo "$as_me:$LINENO: \$? = $ac_status" >&5
+ (exit $ac_status); }; } &&
+ { ac_try='test -s conftest.$ac_objext'
+ { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+ (eval $ac_try) 2>&5
+ ac_status=$?
+ echo "$as_me:$LINENO: \$? = $ac_status" >&5
+ (exit $ac_status); }; }; then
+ break
+else
+ echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+fi
+rm -f conftest.err conftest.$ac_objext conftest.$ac_ext
+done
+rm -f conftest*
+if test -n "$ac_declaration"; then
+ echo '#ifdef __cplusplus' >>confdefs.h
+ echo $ac_declaration >>confdefs.h
+ echo '#endif' >>confdefs.h
+fi
+
+else
+ echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+fi
+rm -f conftest.err conftest.$ac_objext conftest.$ac_ext
+ac_ext=c
+ac_cpp='$CPP $CPPFLAGS'
+ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
+ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
+ac_compiler_gnu=$ac_cv_c_compiler_gnu
+
+
+
+OPENSSL_WARNING=
+echo "$as_me:$LINENO: checking for OpenSSL library" >&5
+echo $ECHO_N "checking for OpenSSL library... $ECHO_C" >&6
+
+# Check whether --with-ssl or --without-ssl was given.
+if test "${with_ssl+set}" = set; then
+ withval="$with_ssl"
+ use_openssl="$withval"
+else
+ use_openssl="auto"
+fi;
+
+openssldirs="/usr /usr/local /usr/local/ssl /usr/pkg /usr/sfw"
+if test "$use_openssl" = "auto"
+then
+ for d in $openssldirs
+ do
+ if test -f $d/include/openssl/opensslv.h
+ then
+ use_openssl=$d
+ break
+ fi
+ done
+fi
+case "$use_openssl" in
+ no)
+ echo "$as_me:$LINENO: result: no" >&5
+echo "${ECHO_T}no" >&6
+ TCN_OPENSSL_INC=""
+ USE_OPENSSL=""
+ ;;
+ auto)
+ TCN_OPENSSL_INC=""
+ USE_OPENSSL=""
+ echo "$as_me:$LINENO: result: not found" >&5
+echo "${ECHO_T}not found" >&6
+ ;;
+ *)
+ if test "$use_openssl" = "yes"
+ then
+ # User did not specify a path - guess it
+ for d in $openssldirs
+ do
+ if test -f $d/include/openssl/opensslv.h
+ then
+ use_openssl=$d
+ break
+ fi
+ done
+ if test "$use_openssl" = "yes"
+ then
+ echo "$as_me:$LINENO: result: not found" >&5
+echo "${ECHO_T}not found" >&6
+ { { echo "$as_me:$LINENO: error: OpenSSL was not found in any of $openssldirs; use --with-ssl=/path" >&5
+echo "$as_me: error: OpenSSL was not found in any of $openssldirs; use --with-ssl=/path" >&2;}
+ { (exit 1); exit 1; }; }
+ fi
+ fi
+ USE_OPENSSL='-DOPENSSL'
+
+ if test "$use_openssl" = "/usr"
+ then
+ TCN_OPENSSL_INC=""
+ TCN_OPENSSL_LIBS="-lssl -lcrypto"
+ else
+ TCN_OPENSSL_INC="-I$use_openssl/include"
+ case $host in
+ *-solaris*)
+ TCN_OPENSSL_LIBS="-L$use_openssl/lib -R$use_openssl/lib -lssl -lcrypto"
+ ;;
+ *-hp-hpux*)
+ TCN_OPENSSL_LIBS="-L$use_openssl/lib -Wl,+b: -lssl -lcrypto"
+ ;;
+ *linux*)
+ TCN_OPENSSL_LIBS="-L$use_openssl/lib -Wl,-rpath,$use_openssl/lib -lssl -lcrypto"
+ ;;
+ *)
+ TCN_OPENSSL_LIBS="-L$use_openssl/lib -lssl -lcrypto"
+ ;;
+ esac
+ fi
+ echo "$as_me:$LINENO: result: using openssl from $use_openssl/lib and $use_openssl/include" >&5
+echo "${ECHO_T}using openssl from $use_openssl/lib and $use_openssl/include" >&6
+
+ saved_cflags="$CFLAGS"
+ saved_libs="$LIBS"
+ CFLAGS="$CFLAGS $TCN_OPENSSL_INC"
+ LIBS="$LIBS $TCN_OPENSSL_LIBS"
+
+# Check whether --enable-openssl-version-check or --disable-openssl-version-check was given.
+if test "${enable_openssl_version_check+set}" = set; then
+ enableval="$enable_openssl_version_check"
+
+fi;
+case "$enable_openssl_version_check" in
+yes|'')
+ echo "$as_me:$LINENO: checking OpenSSL library version" >&5
+echo $ECHO_N "checking OpenSSL library version... $ECHO_C" >&6
+ if test "$cross_compiling" = yes; then
+ echo "$as_me:$LINENO: result: assuming target platform has compatible version" >&5
+echo "${ECHO_T}assuming target platform has compatible version" >&6
+else
+ cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h. */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h. */
+
+#include <stdio.h>
+#include <openssl/opensslv.h>
+int main() {
+ if ((OPENSSL_VERSION_NUMBER >= 0x0090701fL &&
+ OPENSSL_VERSION_NUMBER < 0x00908000L) ||
+ OPENSSL_VERSION_NUMBER >= 0x0090801fL)
+ return (0);
+ printf("\n\nFound OPENSSL_VERSION_NUMBER %#010x\n",
+ OPENSSL_VERSION_NUMBER);
+ printf("Require OPENSSL_VERSION_NUMBER 0x0090701f or greater (0.9.7a)\n"
+ "Require OPENSSL_VERSION_NUMBER 0x0090801f or greater (0.9.8a)\n\n");
+ return (1);
+}
+
+_ACEOF
+rm -f conftest$ac_exeext
+if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5
+ (eval $ac_link) 2>&5
+ ac_status=$?
+ echo "$as_me:$LINENO: \$? = $ac_status" >&5
+ (exit $ac_status); } && { ac_try='./conftest$ac_exeext'
+ { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+ (eval $ac_try) 2>&5
+ ac_status=$?
+ echo "$as_me:$LINENO: \$? = $ac_status" >&5
+ (exit $ac_status); }; }; then
+ echo "$as_me:$LINENO: result: ok" >&5
+echo "${ECHO_T}ok" >&6
+else
+ echo "$as_me: program exited with status $ac_status" >&5
+echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+( exit $ac_status )
+echo "$as_me:$LINENO: result: not compatible" >&5
+echo "${ECHO_T}not compatible" >&6
+ OPENSSL_WARNING=yes
+
+fi
+rm -f core *.core gmon.out bb.out conftest$ac_exeext conftest.$ac_objext conftest.$ac_ext
+fi
+;;
+no)
+ echo "$as_me:$LINENO: result: Skipped OpenSSL version check" >&5
+echo "${ECHO_T}Skipped OpenSSL version check" >&6
+;;
+esac
+
+ echo "$as_me:$LINENO: checking for OpenSSL DSA support" >&5
+echo $ECHO_N "checking for OpenSSL DSA support... $ECHO_C" >&6
+ if test -f $use_openssl/include/openssl/dsa.h
+ then
+ cat >>confdefs.h <<\_ACEOF
+#define HAVE_OPENSSL_DSA 1
+_ACEOF
+
+ echo "$as_me:$LINENO: result: yes" >&5
+echo "${ECHO_T}yes" >&6
+ else
+ echo "$as_me:$LINENO: result: no" >&5
+echo "${ECHO_T}no" >&6
+ fi
+ CFLAGS="$saved_cflags"
+ LIBS="$saved_libs"
+ ;;
+esac
+if test "x$USE_OPENSSL" != "x"
+then
+
+ if test "x$TCNATIVE_PRIV_INCLUDES" = "x"; then
+ test "x$silent" != "xyes" && echo " setting TCNATIVE_PRIV_INCLUDES to \"$TCN_OPENSSL_INC\""
+ TCNATIVE_PRIV_INCLUDES="$TCN_OPENSSL_INC"
+ else
+ apr_addto_bugger="$TCN_OPENSSL_INC"
+ for i in $apr_addto_bugger; do
+ apr_addto_duplicate="0"
+ for j in $TCNATIVE_PRIV_INCLUDES; do
+ if test "x$i" = "x$j"; then
+ apr_addto_duplicate="1"
+ break
+ fi
+ done
+ if test $apr_addto_duplicate = "0"; then
+ test "x$silent" != "xyes" && echo " adding \"$i\" to TCNATIVE_PRIV_INCLUDES"
+ TCNATIVE_PRIV_INCLUDES="$TCNATIVE_PRIV_INCLUDES $i"
+ fi
+ done
+ fi
+
+
+ if test "x$TCNATIVE_LDFLAGS" = "x"; then
+ test "x$silent" != "xyes" && echo " setting TCNATIVE_LDFLAGS to \"$TCN_OPENSSL_LIBS\""
+ TCNATIVE_LDFLAGS="$TCN_OPENSSL_LIBS"
+ else
+ apr_addto_bugger="$TCN_OPENSSL_LIBS"
+ for i in $apr_addto_bugger; do
+ apr_addto_duplicate="0"
+ for j in $TCNATIVE_LDFLAGS; do
+ if test "x$i" = "x$j"; then
+ apr_addto_duplicate="1"
+ break
+ fi
+ done
+ if test $apr_addto_duplicate = "0"; then
+ test "x$silent" != "xyes" && echo " adding \"$i\" to TCNATIVE_LDFLAGS"
+ TCNATIVE_LDFLAGS="$TCNATIVE_LDFLAGS $i"
+ fi
+ done
+ fi
+
+
+ if test "x$CFLAGS" = "x"; then
+ test "x$silent" != "xyes" && echo " setting CFLAGS to \"-DHAVE_OPENSSL\""
+ CFLAGS="-DHAVE_OPENSSL"
+ else
+ apr_addto_bugger="-DHAVE_OPENSSL"
+ for i in $apr_addto_bugger; do
+ apr_addto_duplicate="0"
+ for j in $CFLAGS; do
+ if test "x$i" = "x$j"; then
+ apr_addto_duplicate="1"
+ break
+ fi
+ done
+ if test $apr_addto_duplicate = "0"; then
+ test "x$silent" != "xyes" && echo " adding \"$i\" to CFLAGS"
+ CFLAGS="$CFLAGS $i"
+ fi
+ done
+ fi
+
+fi
+
+fi
+
+so_ext=$APR_SO_EXT
+lib_target=$APR_LIB_TARGET
+
+
+
+TCNATIVE_LIBNAME="tcnative${libsuffix}"
+
+
+EXTRA_OS_LINK=""
+host_alias=`uname -s`
+case "$host_alias" in
+ *AIX*|*Darwin*|*BeOS*)
+ EXTRA_OS_LINK='$(TCNATIVE_LDFLAGS) $(TCNATIVE_LIBS)'
+ ;;
+*)
+ ;;
+esac
+
+
+
+CFLAGS="${CFLAGS}"
+# Check whether --enable-maintainer-mode or --disable-maintainer-mode was given.
+if test "${enable_maintainer_mode+set}" = set; then
+ enableval="$enable_maintainer_mode"
+
+ if test "$GCC" = "yes"; then
+ CFLAGS="${CFLAGS} -DDEBUG -Wall"
+ else
+ CFLAGS="${CFLAGS} -DDEBUG"
+ fi
+echo "$as_me:$LINENO: result: ...Enabling Maintainer mode..." >&5
+echo "${ECHO_T}...Enabling Maintainer mode..." >&6
+
+fi;
+
+
+ if test "x$TCNATIVE_LIBS" = "x"; then
+ test "x$silent" != "xyes" && echo " setting TCNATIVE_LIBS to \"$LIBS\""
+ TCNATIVE_LIBS="$LIBS"
+ else
+ apr_addto_bugger="$LIBS"
+ for i in $apr_addto_bugger; do
+ apr_addto_duplicate="0"
+ for j in $TCNATIVE_LIBS; do
+ if test "x$i" = "x$j"; then
+ apr_addto_duplicate="1"
+ break
+ fi
+ done
+ if test $apr_addto_duplicate = "0"; then
+ test "x$silent" != "xyes" && echo " adding \"$i\" to TCNATIVE_LIBS"
+ TCNATIVE_LIBS="$TCNATIVE_LIBS $i"
+ fi
+ done
+ fi
+
+
+ if test "x$TCNATIVE_LIBS" = "x"; then
+ test "x$silent" != "xyes" && echo " setting TCNATIVE_LIBS to \"$APR_LIBS\""
+ TCNATIVE_LIBS="$APR_LIBS"
+ else
+ apr_addto_bugger="$APR_LIBS"
+ for i in $apr_addto_bugger; do
+ apr_addto_duplicate="0"
+ for j in $TCNATIVE_LIBS; do
+ if test "x$i" = "x$j"; then
+ apr_addto_duplicate="1"
+ break
+ fi
+ done
+ if test $apr_addto_duplicate = "0"; then
+ test "x$silent" != "xyes" && echo " adding \"$i\" to TCNATIVE_LIBS"
+ TCNATIVE_LIBS="$TCNATIVE_LIBS $i"
+ fi
+ done
+ fi
+
+
+ if test "x$TCNATIVE_LDFLAGS" = "x"; then
+ test "x$silent" != "xyes" && echo " setting TCNATIVE_LDFLAGS to \"$LDFLAGS\""
+ TCNATIVE_LDFLAGS="$LDFLAGS"
+ else
+ apr_addto_bugger="$LDFLAGS"
+ for i in $apr_addto_bugger; do
+ apr_addto_duplicate="0"
+ for j in $TCNATIVE_LDFLAGS; do
+ if test "x$i" = "x$j"; then
+ apr_addto_duplicate="1"
+ break
+ fi
+ done
+ if test $apr_addto_duplicate = "0"; then
+ test "x$silent" != "xyes" && echo " adding \"$i\" to TCNATIVE_LDFLAGS"
+ TCNATIVE_LDFLAGS="$TCNATIVE_LDFLAGS $i"
+ fi
+ done
+ fi
+
+
+# Link libkstat for Solaris
+case $host in
+ *-solaris2*)
+
+ if test "x$TCNATIVE_LIBS" = "x"; then
+ test "x$silent" != "xyes" && echo " setting TCNATIVE_LIBS to \"-lkstat\""
+ TCNATIVE_LIBS="-lkstat"
+ else
+ apr_addto_bugger="-lkstat"
+ for i in $apr_addto_bugger; do
+ apr_addto_duplicate="0"
+ for j in $TCNATIVE_LIBS; do
+ if test "x$i" = "x$j"; then
+ apr_addto_duplicate="1"
+ break
+ fi
+ done
+ if test $apr_addto_duplicate = "0"; then
+ test "x$silent" != "xyes" && echo " adding \"$i\" to TCNATIVE_LIBS"
+ TCNATIVE_LIBS="$TCNATIVE_LIBS $i"
+ fi
+ done
+ fi
+
+ ;;
+ *)
+ ;;
+esac
+
+
+
+
+
+
+
+
+
+if test ! -d ./build; then
+ $mkdir_p build
+fi
+cp $APR_BUILD_DIR/apr_rules.mk $abs_builddir/build/rules.mk
+
+
+case "$host_alias" in
+*bsdi* | BSD/OS)
+ # Check whether they've installed GNU make
+ if make --version > /dev/null 2>&1; then
+ INCLUDE_RULES="include $abs_builddir/build/rules.mk"
+ INCLUDE_OUTPUTS="include $abs_srcdir/build-outputs.mk"
+ else
+ INCLUDE_RULES=".include \"$abs_builddir/build/rules.mk\""
+ INCLUDE_OUTPUTS=".include \"$abs_srcdir/build-outputs.mk\""
+ fi
+ ;;
+*)
+ INCLUDE_RULES="include $abs_builddir/build/rules.mk"
+ INCLUDE_OUTPUTS="include $abs_srcdir/build-outputs.mk"
+ ;;
+esac
+
+
+
+
+if test -d $srcdir/test; then
+ test_Makefile="test/Makefile"
+fi
+
+MAKEFILES="Makefile"
+ ac_config_files="$ac_config_files tcnative.pc $MAKEFILES"
+ ac_config_commands="$ac_config_commands default"
+cat >confcache <<\_ACEOF
+# This file is a shell script that caches the results of configure
+# tests run on this system so they can be shared between configure
+# scripts and configure runs, see configure's option --config-cache.
+# It is not useful on other systems. If it contains results you don't
+# want to keep, you may remove or edit it.
+#
+# config.status only pays attention to the cache file if you give it
+# the --recheck option to rerun configure.
+#
+# `ac_cv_env_foo' variables (set or unset) will be overridden when
+# loading this file, other *unset* `ac_cv_foo' will be assigned the
+# following values.
+
+_ACEOF
+
+# The following way of writing the cache mishandles newlines in values,
+# but we know of no workaround that is simple, portable, and efficient.
+# So, don't put newlines in cache variables' values.
+# Ultrix sh set writes to stderr and can't be redirected directly,
+# and sets the high bit in the cache file unless we assign to the vars.
+{
+ (set) 2>&1 |
+ case `(ac_space=' '; set | grep ac_space) 2>&1` in
+ *ac_space=\ *)
+ # `set' does not quote correctly, so add quotes (double-quote
+ # substitution turns \\\\ into \\, and sed turns \\ into \).
+ sed -n \
+ "s/'/'\\\\''/g;
+ s/^\\([_$as_cr_alnum]*_cv_[_$as_cr_alnum]*\\)=\\(.*\\)/\\1='\\2'/p"
+ ;;
+ *)
+ # `set' quotes correctly as required by POSIX, so do not add quotes.
+ sed -n \
+ "s/^\\([_$as_cr_alnum]*_cv_[_$as_cr_alnum]*\\)=\\(.*\\)/\\1=\\2/p"
+ ;;
+ esac;
+} |
+ sed '
+ t clear
+ : clear
+ s/^\([^=]*\)=\(.*[{}].*\)$/test "${\1+set}" = set || &/
+ t end
+ /^ac_cv_env/!s/^\([^=]*\)=\(.*\)$/\1=${\1=\2}/
+ : end' >>confcache
+if diff $cache_file confcache >/dev/null 2>&1; then :; else
+ if test -w $cache_file; then
+ test "x$cache_file" != "x/dev/null" && echo "updating cache $cache_file"
+ cat confcache >$cache_file
+ else
+ echo "not updating unwritable cache $cache_file"
+ fi
+fi
+rm -f confcache
+
+test "x$prefix" = xNONE && prefix=$ac_default_prefix
+# Let make expand exec_prefix.
+test "x$exec_prefix" = xNONE && exec_prefix='${prefix}'
+
+# VPATH may cause trouble with some makes, so we remove $(srcdir),
+# ${srcdir} and @srcdir@ from VPATH if srcdir is ".", strip leading and
+# trailing colons and then remove the whole line if VPATH becomes empty
+# (actually we leave an empty line to preserve line numbers).
+if test "x$srcdir" = x.; then
+ ac_vpsub='/^[ ]*VPATH[ ]*=/{
+s/:*\$(srcdir):*/:/;
+s/:*\${srcdir}:*/:/;
+s/:*@srcdir@:*/:/;
+s/^\([^=]*=[ ]*\):*/\1/;
+s/:*$//;
+s/^[^=]*=[ ]*$//;
+}'
+fi
+
+# Transform confdefs.h into DEFS.
+# Protect against shell expansion while executing Makefile rules.
+# Protect against Makefile macro expansion.
+#
+# If the first sed substitution is executed (which looks for macros that
+# take arguments), then we branch to the quote section. Otherwise,
+# look for a macro that doesn't take arguments.
+cat >confdef2opt.sed <<\_ACEOF
+t clear
+: clear
+s,^[ ]*#[ ]*define[ ][ ]*\([^ (][^ (]*([^)]*)\)[ ]*\(.*\),-D\1=\2,g
+t quote
+s,^[ ]*#[ ]*define[ ][ ]*\([^ ][^ ]*\)[ ]*\(.*\),-D\1=\2,g
+t quote
+d
+: quote
+s,[ `~#$^&*(){}\\|;'"<>?],\\&,g
+s,\[,\\&,g
+s,\],\\&,g
+s,\$,$$,g
+p
+_ACEOF
+# We use echo to avoid assuming a particular line-breaking character.
+# The extra dot is to prevent the shell from consuming trailing
+# line-breaks from the sub-command output. A line-break within
+# single-quotes doesn't work because, if this script is created in a
+# platform that uses two characters for line-breaks (e.g., DOS), tr
+# would break.
+ac_LF_and_DOT=`echo; echo .`
+DEFS=`sed -n -f confdef2opt.sed confdefs.h | tr "$ac_LF_and_DOT" ' .'`
+rm -f confdef2opt.sed
+
+
+ac_libobjs=
+ac_ltlibobjs=
+for ac_i in : $LIBOBJS; do test "x$ac_i" = x: && continue
+ # 1. Remove the extension, and $U if already installed.
+ ac_i=`echo "$ac_i" |
+ sed 's/\$U\././;s/\.o$//;s/\.obj$//'`
+ # 2. Add them.
+ ac_libobjs="$ac_libobjs $ac_i\$U.$ac_objext"
+ ac_ltlibobjs="$ac_ltlibobjs $ac_i"'$U.lo'
+done
+LIBOBJS=$ac_libobjs
+
+LTLIBOBJS=$ac_ltlibobjs
+
+
+
+: ${CONFIG_STATUS=./config.status}
+ac_clean_files_save=$ac_clean_files
+ac_clean_files="$ac_clean_files $CONFIG_STATUS"
+{ echo "$as_me:$LINENO: creating $CONFIG_STATUS" >&5
+echo "$as_me: creating $CONFIG_STATUS" >&6;}
+cat >$CONFIG_STATUS <<_ACEOF
+#! $SHELL
+# Generated by $as_me.
+# Run this file to recreate the current configuration.
+# Compiler output produced by configure, useful for debugging
+# configure, is in config.log if it exists.
+
+debug=false
+ac_cs_recheck=false
+ac_cs_silent=false
+SHELL=\${CONFIG_SHELL-$SHELL}
+_ACEOF
+
+cat >>$CONFIG_STATUS <<\_ACEOF
+## --------------------- ##
+## M4sh Initialization. ##
+## --------------------- ##
+
+# Be Bourne compatible
+if test -n "${ZSH_VERSION+set}" && (emulate sh) >/dev/null 2>&1; then
+ emulate sh
+ NULLCMD=:
+ # Zsh 3.x and 4.x performs word splitting on ${1+"$@"}, which
+ # is contrary to our usage. Disable this feature.
+ alias -g '${1+"$@"}'='"$@"'
+elif test -n "${BASH_VERSION+set}" && (set -o posix) >/dev/null 2>&1; then
+ set -o posix
+fi
+DUALCASE=1; export DUALCASE # for MKS sh
+
+# Support unset when possible.
+if ( (MAIL=60; unset MAIL) || exit) >/dev/null 2>&1; then
+ as_unset=unset
+else
+ as_unset=false
+fi
+
+
+# Work around bugs in pre-3.0 UWIN ksh.
+$as_unset ENV MAIL MAILPATH
+PS1='$ '
+PS2='> '
+PS4='+ '
+
+# NLS nuisances.
+for as_var in \
+ LANG LANGUAGE LC_ADDRESS LC_ALL LC_COLLATE LC_CTYPE LC_IDENTIFICATION \
+ LC_MEASUREMENT LC_MESSAGES LC_MONETARY LC_NAME LC_NUMERIC LC_PAPER \
+ LC_TELEPHONE LC_TIME
+do
+ if (set +x; test -z "`(eval $as_var=C; export $as_var) 2>&1`"); then
+ eval $as_var=C; export $as_var
+ else
+ $as_unset $as_var
+ fi
+done
+
+# Required to use basename.
+if expr a : '\(a\)' >/dev/null 2>&1; then
+ as_expr=expr
+else
+ as_expr=false
+fi
+
+if (basename /) >/dev/null 2>&1 && test "X`basename / 2>&1`" = "X/"; then
+ as_basename=basename
+else
+ as_basename=false
+fi
+
+
+# Name of the executable.
+as_me=`$as_basename "$0" ||
+$as_expr X/"$0" : '.*/\([^/][^/]*\)/*$' \| \
+ X"$0" : 'X\(//\)$' \| \
+ X"$0" : 'X\(/\)$' \| \
+ . : '\(.\)' 2>/dev/null ||
+echo X/"$0" |
+ sed '/^.*\/\([^/][^/]*\)\/*$/{ s//\1/; q; }
+ /^X\/\(\/\/\)$/{ s//\1/; q; }
+ /^X\/\(\/\).*/{ s//\1/; q; }
+ s/.*/./; q'`
+
+
+# PATH needs CR, and LINENO needs CR and PATH.
+# Avoid depending upon Character Ranges.
+as_cr_letters='abcdefghijklmnopqrstuvwxyz'
+as_cr_LETTERS='ABCDEFGHIJKLMNOPQRSTUVWXYZ'
+as_cr_Letters=$as_cr_letters$as_cr_LETTERS
+as_cr_digits='0123456789'
+as_cr_alnum=$as_cr_Letters$as_cr_digits
+
+# The user is always right.
+if test "${PATH_SEPARATOR+set}" != set; then
+ echo "#! /bin/sh" >conf$$.sh
+ echo "exit 0" >>conf$$.sh
+ chmod +x conf$$.sh
+ if (PATH="/nonexistent;."; conf$$.sh) >/dev/null 2>&1; then
+ PATH_SEPARATOR=';'
+ else
+ PATH_SEPARATOR=:
+ fi
+ rm -f conf$$.sh
+fi
+
+
+ as_lineno_1=$LINENO
+ as_lineno_2=$LINENO
+ as_lineno_3=`(expr $as_lineno_1 + 1) 2>/dev/null`
+ test "x$as_lineno_1" != "x$as_lineno_2" &&
+ test "x$as_lineno_3" = "x$as_lineno_2" || {
+ # Find who we are. Look in the path if we contain no path at all
+ # relative or not.
+ case $0 in
+ *[\\/]* ) as_myself=$0 ;;
+ *) as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in $PATH
+do
+ IFS=$as_save_IFS
+ test -z "$as_dir" && as_dir=.
+ test -r "$as_dir/$0" && as_myself=$as_dir/$0 && break
+done
+
+ ;;
+ esac
+ # We did not find ourselves, most probably we were run as `sh COMMAND'
+ # in which case we are not to be found in the path.
+ if test "x$as_myself" = x; then
+ as_myself=$0
+ fi
+ if test ! -f "$as_myself"; then
+ { { echo "$as_me:$LINENO: error: cannot find myself; rerun with an absolute path" >&5
+echo "$as_me: error: cannot find myself; rerun with an absolute path" >&2;}
+ { (exit 1); exit 1; }; }
+ fi
+ case $CONFIG_SHELL in
+ '')
+ as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
+for as_dir in /bin$PATH_SEPARATOR/usr/bin$PATH_SEPARATOR$PATH
+do
+ IFS=$as_save_IFS
+ test -z "$as_dir" && as_dir=.
+ for as_base in sh bash ksh sh5; do
+ case $as_dir in
+ /*)
+ if ("$as_dir/$as_base" -c '
+ as_lineno_1=$LINENO
+ as_lineno_2=$LINENO
+ as_lineno_3=`(expr $as_lineno_1 + 1) 2>/dev/null`
+ test "x$as_lineno_1" != "x$as_lineno_2" &&
+ test "x$as_lineno_3" = "x$as_lineno_2" ') 2>/dev/null; then
+ $as_unset BASH_ENV || test "${BASH_ENV+set}" != set || { BASH_ENV=; export BASH_ENV; }
+ $as_unset ENV || test "${ENV+set}" != set || { ENV=; export ENV; }
+ CONFIG_SHELL=$as_dir/$as_base
+ export CONFIG_SHELL
+ exec "$CONFIG_SHELL" "$0" ${1+"$@"}
+ fi;;
+ esac
+ done
+done
+;;
+ esac
+
+ # Create $as_me.lineno as a copy of $as_myself, but with $LINENO
+ # uniformly replaced by the line number. The first 'sed' inserts a
+ # line-number line before each line; the second 'sed' does the real
+ # work. The second script uses 'N' to pair each line-number line
+ # with the numbered line, and appends trailing '-' during
+ # substitution so that $LINENO is not a special case at line end.
+ # (Raja R Harinath suggested sed '=', and Paul Eggert wrote the
+ # second 'sed' script. Blame Lee E. McMahon for sed's syntax. :-)
+ sed '=' <$as_myself |
+ sed '
+ N
+ s,$,-,
+ : loop
+ s,^\(['$as_cr_digits']*\)\(.*\)[$]LINENO\([^'$as_cr_alnum'_]\),\1\2\1\3,
+ t loop
+ s,-$,,
+ s,^['$as_cr_digits']*\n,,
+ ' >$as_me.lineno &&
+ chmod +x $as_me.lineno ||
+ { { echo "$as_me:$LINENO: error: cannot create $as_me.lineno; rerun with a POSIX shell" >&5
+echo "$as_me: error: cannot create $as_me.lineno; rerun with a POSIX shell" >&2;}
+ { (exit 1); exit 1; }; }
+
+ # Don't try to exec as it changes $[0], causing all sort of problems
+ # (the dirname of $[0] is not the place where we might find the
+ # original and so on. Autoconf is especially sensible to this).
+ . ./$as_me.lineno
+ # Exit status is that of the last command.
+ exit
+}
+
+
+case `echo "testing\c"; echo 1,2,3`,`echo -n testing; echo 1,2,3` in
+ *c*,-n*) ECHO_N= ECHO_C='
+' ECHO_T=' ' ;;
+ *c*,* ) ECHO_N=-n ECHO_C= ECHO_T= ;;
+ *) ECHO_N= ECHO_C='\c' ECHO_T= ;;
+esac
+
+if expr a : '\(a\)' >/dev/null 2>&1; then
+ as_expr=expr
+else
+ as_expr=false
+fi
+
+rm -f conf$$ conf$$.exe conf$$.file
+echo >conf$$.file
+if ln -s conf$$.file conf$$ 2>/dev/null; then
+ # We could just check for DJGPP; but this test a) works b) is more generic
+ # and c) will remain valid once DJGPP supports symlinks (DJGPP 2.04).
+ if test -f conf$$.exe; then
+ # Don't use ln at all; we don't have any links
+ as_ln_s='cp -p'
+ else
+ as_ln_s='ln -s'
+ fi
+elif ln conf$$.file conf$$ 2>/dev/null; then
+ as_ln_s=ln
+else
+ as_ln_s='cp -p'
+fi
+rm -f conf$$ conf$$.exe conf$$.file
+
+if mkdir -p . 2>/dev/null; then
+ as_mkdir_p=:
+else
+ test -d ./-p && rmdir ./-p
+ as_mkdir_p=false
+fi
+
+as_executable_p="test -f"
+
+# Sed expression to map a string onto a valid CPP name.
+as_tr_cpp="eval sed 'y%*$as_cr_letters%P$as_cr_LETTERS%;s%[^_$as_cr_alnum]%_%g'"
+
+# Sed expression to map a string onto a valid variable name.
+as_tr_sh="eval sed 'y%*+%pp%;s%[^_$as_cr_alnum]%_%g'"
+
+
+# IFS
+# We need space, tab and new line, in precisely that order.
+as_nl='
+'
+IFS=" $as_nl"
+
+# CDPATH.
+$as_unset CDPATH
+
+exec 6>&1
+
+# Open the log real soon, to keep \$[0] and so on meaningful, and to
+# report actual input values of CONFIG_FILES etc. instead of their
+# values after options handling. Logging --version etc. is OK.
+exec 5>>config.log
+{
+ echo
+ sed 'h;s/./-/g;s/^.../## /;s/...$/ ##/;p;x;p;x' <<_ASBOX
+## Running $as_me. ##
+_ASBOX
+} >&5
+cat >&5 <<_CSEOF
+
+This file was extended by $as_me, which was
+generated by GNU Autoconf 2.59. Invocation command line was
+
+ CONFIG_FILES = $CONFIG_FILES
+ CONFIG_HEADERS = $CONFIG_HEADERS
+ CONFIG_LINKS = $CONFIG_LINKS
+ CONFIG_COMMANDS = $CONFIG_COMMANDS
+ $ $0 $@
+
+_CSEOF
+echo "on `(hostname || uname -n) 2>/dev/null | sed 1q`" >&5
+echo >&5
+_ACEOF
+
+# Files that config.status was made for.
+if test -n "$ac_config_files"; then
+ echo "config_files=\"$ac_config_files\"" >>$CONFIG_STATUS
+fi
+
+if test -n "$ac_config_headers"; then
+ echo "config_headers=\"$ac_config_headers\"" >>$CONFIG_STATUS
+fi
+
+if test -n "$ac_config_links"; then
+ echo "config_links=\"$ac_config_links\"" >>$CONFIG_STATUS
+fi
+
+if test -n "$ac_config_commands"; then
+ echo "config_commands=\"$ac_config_commands\"" >>$CONFIG_STATUS
+fi
+
+cat >>$CONFIG_STATUS <<\_ACEOF
+
+ac_cs_usage="\
+\`$as_me' instantiates files from templates according to the
+current configuration.
+
+Usage: $0 [OPTIONS] [FILE]...
+
+ -h, --help print this help, then exit
+ -V, --version print version number, then exit
+ -q, --quiet do not print progress messages
+ -d, --debug don't remove temporary files
+ --recheck update $as_me by reconfiguring in the same conditions
+ --file=FILE[:TEMPLATE]
+ instantiate the configuration file FILE
+
+Configuration files:
+$config_files
+
+Configuration commands:
+$config_commands
+
+Report bugs to <bug-autoconf at gnu.org>."
+_ACEOF
+
+cat >>$CONFIG_STATUS <<_ACEOF
+ac_cs_version="\\
+config.status
+configured by $0, generated by GNU Autoconf 2.59,
+ with options \\"`echo "$ac_configure_args" | sed 's/[\\""\`\$]/\\\\&/g'`\\"
+
+Copyright (C) 2003 Free Software Foundation, Inc.
+This config.status script is free software; the Free Software Foundation
+gives unlimited permission to copy, distribute and modify it."
+srcdir=$srcdir
+INSTALL="$INSTALL"
+_ACEOF
+
+cat >>$CONFIG_STATUS <<\_ACEOF
+# If no file are specified by the user, then we need to provide default
+# value. By we need to know if files were specified by the user.
+ac_need_defaults=:
+while test $# != 0
+do
+ case $1 in
+ --*=*)
+ ac_option=`expr "x$1" : 'x\([^=]*\)='`
+ ac_optarg=`expr "x$1" : 'x[^=]*=\(.*\)'`
+ ac_shift=:
+ ;;
+ -*)
+ ac_option=$1
+ ac_optarg=$2
+ ac_shift=shift
+ ;;
+ *) # This is not an option, so the user has probably given explicit
+ # arguments.
+ ac_option=$1
+ ac_need_defaults=false;;
+ esac
+
+ case $ac_option in
+ # Handling of the options.
+_ACEOF
+cat >>$CONFIG_STATUS <<\_ACEOF
+ -recheck | --recheck | --rechec | --reche | --rech | --rec | --re | --r)
+ ac_cs_recheck=: ;;
+ --version | --vers* | -V )
+ echo "$ac_cs_version"; exit 0 ;;
+ --he | --h)
+ # Conflict between --help and --header
+ { { echo "$as_me:$LINENO: error: ambiguous option: $1
+Try \`$0 --help' for more information." >&5
+echo "$as_me: error: ambiguous option: $1
+Try \`$0 --help' for more information." >&2;}
+ { (exit 1); exit 1; }; };;
+ --help | --hel | -h )
+ echo "$ac_cs_usage"; exit 0 ;;
+ --debug | --d* | -d )
+ debug=: ;;
+ --file | --fil | --fi | --f )
+ $ac_shift
+ CONFIG_FILES="$CONFIG_FILES $ac_optarg"
+ ac_need_defaults=false;;
+ --header | --heade | --head | --hea )
+ $ac_shift
+ CONFIG_HEADERS="$CONFIG_HEADERS $ac_optarg"
+ ac_need_defaults=false;;
+ -q | -quiet | --quiet | --quie | --qui | --qu | --q \
+ | -silent | --silent | --silen | --sile | --sil | --si | --s)
+ ac_cs_silent=: ;;
+
+ # This is an error.
+ -*) { { echo "$as_me:$LINENO: error: unrecognized option: $1
+Try \`$0 --help' for more information." >&5
+echo "$as_me: error: unrecognized option: $1
+Try \`$0 --help' for more information." >&2;}
+ { (exit 1); exit 1; }; } ;;
+
+ *) ac_config_targets="$ac_config_targets $1" ;;
+
+ esac
+ shift
+done
+
+ac_configure_extra_args=
+
+if $ac_cs_silent; then
+ exec 6>/dev/null
+ ac_configure_extra_args="$ac_configure_extra_args --silent"
+fi
+
+_ACEOF
+cat >>$CONFIG_STATUS <<_ACEOF
+if \$ac_cs_recheck; then
+ echo "running $SHELL $0 " $ac_configure_args \$ac_configure_extra_args " --no-create --no-recursion" >&6
+ exec $SHELL $0 $ac_configure_args \$ac_configure_extra_args --no-create --no-recursion
+fi
+
+_ACEOF
+
+
+
+
+
+cat >>$CONFIG_STATUS <<\_ACEOF
+for ac_config_target in $ac_config_targets
+do
+ case "$ac_config_target" in
+ # Handling of arguments.
+ "tcnative.pc" ) CONFIG_FILES="$CONFIG_FILES tcnative.pc" ;;
+ "$MAKEFILES" ) CONFIG_FILES="$CONFIG_FILES $MAKEFILES" ;;
+ "default" ) CONFIG_COMMANDS="$CONFIG_COMMANDS default" ;;
+ *) { { echo "$as_me:$LINENO: error: invalid argument: $ac_config_target" >&5
+echo "$as_me: error: invalid argument: $ac_config_target" >&2;}
+ { (exit 1); exit 1; }; };;
+ esac
+done
+
+# If the user did not use the arguments to specify the items to instantiate,
+# then the envvar interface is used. Set only those that are not.
+# We use the long form for the default assignment because of an extremely
+# bizarre bug on SunOS 4.1.3.
+if $ac_need_defaults; then
+ test "${CONFIG_FILES+set}" = set || CONFIG_FILES=$config_files
+ test "${CONFIG_COMMANDS+set}" = set || CONFIG_COMMANDS=$config_commands
+fi
+
+# Have a temporary directory for convenience. Make it in the build tree
+# simply because there is no reason to put it here, and in addition,
+# creating and moving files from /tmp can sometimes cause problems.
+# Create a temporary directory, and hook for its removal unless debugging.
+$debug ||
+{
+ trap 'exit_status=$?; rm -rf $tmp && exit $exit_status' 0
+ trap '{ (exit 1); exit 1; }' 1 2 13 15
+}
+
+# Create a (secure) tmp directory for tmp files.
+
+{
+ tmp=`(umask 077 && mktemp -d -q "./confstatXXXXXX") 2>/dev/null` &&
+ test -n "$tmp" && test -d "$tmp"
+} ||
+{
+ tmp=./confstat$$-$RANDOM
+ (umask 077 && mkdir $tmp)
+} ||
+{
+ echo "$me: cannot create a temporary directory in ." >&2
+ { (exit 1); exit 1; }
+}
+
+_ACEOF
+
+cat >>$CONFIG_STATUS <<_ACEOF
+
+#
+# CONFIG_FILES section.
+#
+
+# No need to generate the scripts if there are no CONFIG_FILES.
+# This happens for instance when ./config.status config.h
+if test -n "\$CONFIG_FILES"; then
+ # Protect against being on the right side of a sed subst in config.status.
+ sed 's/,@/@@/; s/@,/@@/; s/,;t t\$/@;t t/; /@;t t\$/s/[\\\\&,]/\\\\&/g;
+ s/@@/,@/; s/@@/@,/; s/@;t t\$/,;t t/' >\$tmp/subs.sed <<\\CEOF
+s, at SHELL@,$SHELL,;t t
+s, at PATH_SEPARATOR@,$PATH_SEPARATOR,;t t
+s, at PACKAGE_NAME@,$PACKAGE_NAME,;t t
+s, at PACKAGE_TARNAME@,$PACKAGE_TARNAME,;t t
+s, at PACKAGE_VERSION@,$PACKAGE_VERSION,;t t
+s, at PACKAGE_STRING@,$PACKAGE_STRING,;t t
+s, at PACKAGE_BUGREPORT@,$PACKAGE_BUGREPORT,;t t
+s, at exec_prefix@,$exec_prefix,;t t
+s, at prefix@,$prefix,;t t
+s, at program_transform_name@,$program_transform_name,;t t
+s, at bindir@,$bindir,;t t
+s, at sbindir@,$sbindir,;t t
+s, at libexecdir@,$libexecdir,;t t
+s, at datadir@,$datadir,;t t
+s, at sysconfdir@,$sysconfdir,;t t
+s, at sharedstatedir@,$sharedstatedir,;t t
+s, at localstatedir@,$localstatedir,;t t
+s, at libdir@,$libdir,;t t
+s, at includedir@,$includedir,;t t
+s, at oldincludedir@,$oldincludedir,;t t
+s, at infodir@,$infodir,;t t
+s, at mandir@,$mandir,;t t
+s, at build_alias@,$build_alias,;t t
+s, at host_alias@,$host_alias,;t t
+s, at target_alias@,$target_alias,;t t
+s, at DEFS@,$DEFS,;t t
+s, at ECHO_C@,$ECHO_C,;t t
+s, at ECHO_N@,$ECHO_N,;t t
+s, at ECHO_T@,$ECHO_T,;t t
+s, at LIBS@,$LIBS,;t t
+s, at TCN_CONFIG_LOCATION@,$TCN_CONFIG_LOCATION,;t t
+s, at build@,$build,;t t
+s, at build_cpu@,$build_cpu,;t t
+s, at build_vendor@,$build_vendor,;t t
+s, at build_os@,$build_os,;t t
+s, at host@,$host,;t t
+s, at host_cpu@,$host_cpu,;t t
+s, at host_vendor@,$host_vendor,;t t
+s, at host_os@,$host_os,;t t
+s, at target@,$target,;t t
+s, at target_cpu@,$target_cpu,;t t
+s, at target_vendor@,$target_vendor,;t t
+s, at target_os@,$target_os,;t t
+s, at INSTALL_PROGRAM@,$INSTALL_PROGRAM,;t t
+s, at INSTALL_SCRIPT@,$INSTALL_SCRIPT,;t t
+s, at INSTALL_DATA@,$INSTALL_DATA,;t t
+s, at top_builddir@,$top_builddir,;t t
+s, at abs_srcdir@,$abs_srcdir,;t t
+s, at abs_builddir@,$abs_builddir,;t t
+s, at TCNATIVE_DOTTED_VERSION@,$TCNATIVE_DOTTED_VERSION,;t t
+s, at TCNATIVE_MAJOR_VERSION@,$TCNATIVE_MAJOR_VERSION,;t t
+s, at TCNATIVE_LIBTOOL_VERSION@,$TCNATIVE_LIBTOOL_VERSION,;t t
+s, at APR_INCLUDES@,$APR_INCLUDES,;t t
+s, at APR_LIBS@,$APR_LIBS,;t t
+s, at APR_BUILD_DIR@,$APR_BUILD_DIR,;t t
+s, at SABLEVM@,$SABLEVM,;t t
+s, at JAVA_HOME@,$JAVA_HOME,;t t
+s, at JAVA_PLATFORM@,$JAVA_PLATFORM,;t t
+s, at JAVA_OS@,$JAVA_OS,;t t
+s, at CC@,$CC,;t t
+s, at CFLAGS@,$CFLAGS,;t t
+s, at LDFLAGS@,$LDFLAGS,;t t
+s, at CPPFLAGS@,$CPPFLAGS,;t t
+s, at ac_ct_CC@,$ac_ct_CC,;t t
+s, at EXEEXT@,$EXEEXT,;t t
+s, at OBJEXT@,$OBJEXT,;t t
+s, at so_ext@,$so_ext,;t t
+s, at lib_target@,$lib_target,;t t
+s, at TCNATIVE_LIBNAME@,$TCNATIVE_LIBNAME,;t t
+s, at EXTRA_OS_LINK@,$EXTRA_OS_LINK,;t t
+s, at TCNATIVE_EXPORT_LIBS@,$TCNATIVE_EXPORT_LIBS,;t t
+s, at TCNATIVE_PRIV_INCLUDES@,$TCNATIVE_PRIV_INCLUDES,;t t
+s, at TCNATIVE_INCLUDES@,$TCNATIVE_INCLUDES,;t t
+s, at TCNATIVE_LDFLAGS@,$TCNATIVE_LDFLAGS,;t t
+s, at TCNATIVE_LIBS@,$TCNATIVE_LIBS,;t t
+s, at INCLUDE_RULES@,$INCLUDE_RULES,;t t
+s, at INCLUDE_OUTPUTS@,$INCLUDE_OUTPUTS,;t t
+s, at LIBOBJS@,$LIBOBJS,;t t
+s, at LTLIBOBJS@,$LTLIBOBJS,;t t
+CEOF
+
+_ACEOF
+
+ cat >>$CONFIG_STATUS <<\_ACEOF
+ # Split the substitutions into bite-sized pieces for seds with
+ # small command number limits, like on Digital OSF/1 and HP-UX.
+ ac_max_sed_lines=48
+ ac_sed_frag=1 # Number of current file.
+ ac_beg=1 # First line for current file.
+ ac_end=$ac_max_sed_lines # Line after last line for current file.
+ ac_more_lines=:
+ ac_sed_cmds=
+ while $ac_more_lines; do
+ if test $ac_beg -gt 1; then
+ sed "1,${ac_beg}d; ${ac_end}q" $tmp/subs.sed >$tmp/subs.frag
+ else
+ sed "${ac_end}q" $tmp/subs.sed >$tmp/subs.frag
+ fi
+ if test ! -s $tmp/subs.frag; then
+ ac_more_lines=false
+ else
+ # The purpose of the label and of the branching condition is to
+ # speed up the sed processing (if there are no `@' at all, there
+ # is no need to browse any of the substitutions).
+ # These are the two extra sed commands mentioned above.
+ (echo ':t
+ /@[a-zA-Z_][a-zA-Z_0-9]*@/!b' && cat $tmp/subs.frag) >$tmp/subs-$ac_sed_frag.sed
+ if test -z "$ac_sed_cmds"; then
+ ac_sed_cmds="sed -f $tmp/subs-$ac_sed_frag.sed"
+ else
+ ac_sed_cmds="$ac_sed_cmds | sed -f $tmp/subs-$ac_sed_frag.sed"
+ fi
+ ac_sed_frag=`expr $ac_sed_frag + 1`
+ ac_beg=$ac_end
+ ac_end=`expr $ac_end + $ac_max_sed_lines`
+ fi
+ done
+ if test -z "$ac_sed_cmds"; then
+ ac_sed_cmds=cat
+ fi
+fi # test -n "$CONFIG_FILES"
+
+_ACEOF
+cat >>$CONFIG_STATUS <<\_ACEOF
+for ac_file in : $CONFIG_FILES; do test "x$ac_file" = x: && continue
+ # Support "outfile[:infile[:infile...]]", defaulting infile="outfile.in".
+ case $ac_file in
+ - | *:- | *:-:* ) # input from stdin
+ cat >$tmp/stdin
+ ac_file_in=`echo "$ac_file" | sed 's,[^:]*:,,'`
+ ac_file=`echo "$ac_file" | sed 's,:.*,,'` ;;
+ *:* ) ac_file_in=`echo "$ac_file" | sed 's,[^:]*:,,'`
+ ac_file=`echo "$ac_file" | sed 's,:.*,,'` ;;
+ * ) ac_file_in=$ac_file.in ;;
+ esac
+
+ # Compute @srcdir@, @top_srcdir@, and @INSTALL@ for subdirectories.
+ ac_dir=`(dirname "$ac_file") 2>/dev/null ||
+$as_expr X"$ac_file" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \
+ X"$ac_file" : 'X\(//\)[^/]' \| \
+ X"$ac_file" : 'X\(//\)$' \| \
+ X"$ac_file" : 'X\(/\)' \| \
+ . : '\(.\)' 2>/dev/null ||
+echo X"$ac_file" |
+ sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ s//\1/; q; }
+ /^X\(\/\/\)[^/].*/{ s//\1/; q; }
+ /^X\(\/\/\)$/{ s//\1/; q; }
+ /^X\(\/\).*/{ s//\1/; q; }
+ s/.*/./; q'`
+ { if $as_mkdir_p; then
+ mkdir -p "$ac_dir"
+ else
+ as_dir="$ac_dir"
+ as_dirs=
+ while test ! -d "$as_dir"; do
+ as_dirs="$as_dir $as_dirs"
+ as_dir=`(dirname "$as_dir") 2>/dev/null ||
+$as_expr X"$as_dir" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \
+ X"$as_dir" : 'X\(//\)[^/]' \| \
+ X"$as_dir" : 'X\(//\)$' \| \
+ X"$as_dir" : 'X\(/\)' \| \
+ . : '\(.\)' 2>/dev/null ||
+echo X"$as_dir" |
+ sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ s//\1/; q; }
+ /^X\(\/\/\)[^/].*/{ s//\1/; q; }
+ /^X\(\/\/\)$/{ s//\1/; q; }
+ /^X\(\/\).*/{ s//\1/; q; }
+ s/.*/./; q'`
+ done
+ test ! -n "$as_dirs" || mkdir $as_dirs
+ fi || { { echo "$as_me:$LINENO: error: cannot create directory \"$ac_dir\"" >&5
+echo "$as_me: error: cannot create directory \"$ac_dir\"" >&2;}
+ { (exit 1); exit 1; }; }; }
+
+ ac_builddir=.
+
+if test "$ac_dir" != .; then
+ ac_dir_suffix=/`echo "$ac_dir" | sed 's,^\.[\\/],,'`
+ # A "../" for each directory in $ac_dir_suffix.
+ ac_top_builddir=`echo "$ac_dir_suffix" | sed 's,/[^\\/]*,../,g'`
+else
+ ac_dir_suffix= ac_top_builddir=
+fi
+
+case $srcdir in
+ .) # No --srcdir option. We are building in place.
+ ac_srcdir=.
+ if test -z "$ac_top_builddir"; then
+ ac_top_srcdir=.
+ else
+ ac_top_srcdir=`echo $ac_top_builddir | sed 's,/$,,'`
+ fi ;;
+ [\\/]* | ?:[\\/]* ) # Absolute path.
+ ac_srcdir=$srcdir$ac_dir_suffix;
+ ac_top_srcdir=$srcdir ;;
+ *) # Relative path.
+ ac_srcdir=$ac_top_builddir$srcdir$ac_dir_suffix
+ ac_top_srcdir=$ac_top_builddir$srcdir ;;
+esac
+
+# Do not use `cd foo && pwd` to compute absolute paths, because
+# the directories may not exist.
+case `pwd` in
+.) ac_abs_builddir="$ac_dir";;
+*)
+ case "$ac_dir" in
+ .) ac_abs_builddir=`pwd`;;
+ [\\/]* | ?:[\\/]* ) ac_abs_builddir="$ac_dir";;
+ *) ac_abs_builddir=`pwd`/"$ac_dir";;
+ esac;;
+esac
+case $ac_abs_builddir in
+.) ac_abs_top_builddir=${ac_top_builddir}.;;
+*)
+ case ${ac_top_builddir}. in
+ .) ac_abs_top_builddir=$ac_abs_builddir;;
+ [\\/]* | ?:[\\/]* ) ac_abs_top_builddir=${ac_top_builddir}.;;
+ *) ac_abs_top_builddir=$ac_abs_builddir/${ac_top_builddir}.;;
+ esac;;
+esac
+case $ac_abs_builddir in
+.) ac_abs_srcdir=$ac_srcdir;;
+*)
+ case $ac_srcdir in
+ .) ac_abs_srcdir=$ac_abs_builddir;;
+ [\\/]* | ?:[\\/]* ) ac_abs_srcdir=$ac_srcdir;;
+ *) ac_abs_srcdir=$ac_abs_builddir/$ac_srcdir;;
+ esac;;
+esac
+case $ac_abs_builddir in
+.) ac_abs_top_srcdir=$ac_top_srcdir;;
+*)
+ case $ac_top_srcdir in
+ .) ac_abs_top_srcdir=$ac_abs_builddir;;
+ [\\/]* | ?:[\\/]* ) ac_abs_top_srcdir=$ac_top_srcdir;;
+ *) ac_abs_top_srcdir=$ac_abs_builddir/$ac_top_srcdir;;
+ esac;;
+esac
+
+
+ case $INSTALL in
+ [\\/$]* | ?:[\\/]* ) ac_INSTALL=$INSTALL ;;
+ *) ac_INSTALL=$ac_top_builddir$INSTALL ;;
+ esac
+
+ if test x"$ac_file" != x-; then
+ { echo "$as_me:$LINENO: creating $ac_file" >&5
+echo "$as_me: creating $ac_file" >&6;}
+ rm -f "$ac_file"
+ fi
+ # Let's still pretend it is `configure' which instantiates (i.e., don't
+ # use $as_me), people would be surprised to read:
+ # /* config.h. Generated by config.status. */
+ if test x"$ac_file" = x-; then
+ configure_input=
+ else
+ configure_input="$ac_file. "
+ fi
+ configure_input=$configure_input"Generated from `echo $ac_file_in |
+ sed 's,.*/,,'` by configure."
+
+ # First look for the input files in the build tree, otherwise in the
+ # src tree.
+ ac_file_inputs=`IFS=:
+ for f in $ac_file_in; do
+ case $f in
+ -) echo $tmp/stdin ;;
+ [\\/$]*)
+ # Absolute (can't be DOS-style, as IFS=:)
+ test -f "$f" || { { echo "$as_me:$LINENO: error: cannot find input file: $f" >&5
+echo "$as_me: error: cannot find input file: $f" >&2;}
+ { (exit 1); exit 1; }; }
+ echo "$f";;
+ *) # Relative
+ if test -f "$f"; then
+ # Build tree
+ echo "$f"
+ elif test -f "$srcdir/$f"; then
+ # Source tree
+ echo "$srcdir/$f"
+ else
+ # /dev/null tree
+ { { echo "$as_me:$LINENO: error: cannot find input file: $f" >&5
+echo "$as_me: error: cannot find input file: $f" >&2;}
+ { (exit 1); exit 1; }; }
+ fi;;
+ esac
+ done` || { (exit 1); exit 1; }
+_ACEOF
+cat >>$CONFIG_STATUS <<_ACEOF
+ sed "$ac_vpsub
+$extrasub
+_ACEOF
+cat >>$CONFIG_STATUS <<\_ACEOF
+:t
+/@[a-zA-Z_][a-zA-Z_0-9]*@/!b
+s, at configure_input@,$configure_input,;t t
+s, at srcdir@,$ac_srcdir,;t t
+s, at abs_srcdir@,$ac_abs_srcdir,;t t
+s, at top_srcdir@,$ac_top_srcdir,;t t
+s, at abs_top_srcdir@,$ac_abs_top_srcdir,;t t
+s, at builddir@,$ac_builddir,;t t
+s, at abs_builddir@,$ac_abs_builddir,;t t
+s, at top_builddir@,$ac_top_builddir,;t t
+s, at abs_top_builddir@,$ac_abs_top_builddir,;t t
+s, at INSTALL@,$ac_INSTALL,;t t
+" $ac_file_inputs | (eval "$ac_sed_cmds") >$tmp/out
+ rm -f $tmp/stdin
+ if test x"$ac_file" != x-; then
+ mv $tmp/out $ac_file
+ else
+ cat $tmp/out
+ rm -f $tmp/out
+ fi
+
+done
+_ACEOF
+cat >>$CONFIG_STATUS <<\_ACEOF
+
+#
+# CONFIG_COMMANDS section.
+#
+for ac_file in : $CONFIG_COMMANDS; do test "x$ac_file" = x: && continue
+ ac_dest=`echo "$ac_file" | sed 's,:.*,,'`
+ ac_source=`echo "$ac_file" | sed 's,[^:]*:,,'`
+ ac_dir=`(dirname "$ac_dest") 2>/dev/null ||
+$as_expr X"$ac_dest" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \
+ X"$ac_dest" : 'X\(//\)[^/]' \| \
+ X"$ac_dest" : 'X\(//\)$' \| \
+ X"$ac_dest" : 'X\(/\)' \| \
+ . : '\(.\)' 2>/dev/null ||
+echo X"$ac_dest" |
+ sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ s//\1/; q; }
+ /^X\(\/\/\)[^/].*/{ s//\1/; q; }
+ /^X\(\/\/\)$/{ s//\1/; q; }
+ /^X\(\/\).*/{ s//\1/; q; }
+ s/.*/./; q'`
+ { if $as_mkdir_p; then
+ mkdir -p "$ac_dir"
+ else
+ as_dir="$ac_dir"
+ as_dirs=
+ while test ! -d "$as_dir"; do
+ as_dirs="$as_dir $as_dirs"
+ as_dir=`(dirname "$as_dir") 2>/dev/null ||
+$as_expr X"$as_dir" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \
+ X"$as_dir" : 'X\(//\)[^/]' \| \
+ X"$as_dir" : 'X\(//\)$' \| \
+ X"$as_dir" : 'X\(/\)' \| \
+ . : '\(.\)' 2>/dev/null ||
+echo X"$as_dir" |
+ sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ s//\1/; q; }
+ /^X\(\/\/\)[^/].*/{ s//\1/; q; }
+ /^X\(\/\/\)$/{ s//\1/; q; }
+ /^X\(\/\).*/{ s//\1/; q; }
+ s/.*/./; q'`
+ done
+ test ! -n "$as_dirs" || mkdir $as_dirs
+ fi || { { echo "$as_me:$LINENO: error: cannot create directory \"$ac_dir\"" >&5
+echo "$as_me: error: cannot create directory \"$ac_dir\"" >&2;}
+ { (exit 1); exit 1; }; }; }
+
+ ac_builddir=.
+
+if test "$ac_dir" != .; then
+ ac_dir_suffix=/`echo "$ac_dir" | sed 's,^\.[\\/],,'`
+ # A "../" for each directory in $ac_dir_suffix.
+ ac_top_builddir=`echo "$ac_dir_suffix" | sed 's,/[^\\/]*,../,g'`
+else
+ ac_dir_suffix= ac_top_builddir=
+fi
+
+case $srcdir in
+ .) # No --srcdir option. We are building in place.
+ ac_srcdir=.
+ if test -z "$ac_top_builddir"; then
+ ac_top_srcdir=.
+ else
+ ac_top_srcdir=`echo $ac_top_builddir | sed 's,/$,,'`
+ fi ;;
+ [\\/]* | ?:[\\/]* ) # Absolute path.
+ ac_srcdir=$srcdir$ac_dir_suffix;
+ ac_top_srcdir=$srcdir ;;
+ *) # Relative path.
+ ac_srcdir=$ac_top_builddir$srcdir$ac_dir_suffix
+ ac_top_srcdir=$ac_top_builddir$srcdir ;;
+esac
+
+# Do not use `cd foo && pwd` to compute absolute paths, because
+# the directories may not exist.
+case `pwd` in
+.) ac_abs_builddir="$ac_dir";;
+*)
+ case "$ac_dir" in
+ .) ac_abs_builddir=`pwd`;;
+ [\\/]* | ?:[\\/]* ) ac_abs_builddir="$ac_dir";;
+ *) ac_abs_builddir=`pwd`/"$ac_dir";;
+ esac;;
+esac
+case $ac_abs_builddir in
+.) ac_abs_top_builddir=${ac_top_builddir}.;;
+*)
+ case ${ac_top_builddir}. in
+ .) ac_abs_top_builddir=$ac_abs_builddir;;
+ [\\/]* | ?:[\\/]* ) ac_abs_top_builddir=${ac_top_builddir}.;;
+ *) ac_abs_top_builddir=$ac_abs_builddir/${ac_top_builddir}.;;
+ esac;;
+esac
+case $ac_abs_builddir in
+.) ac_abs_srcdir=$ac_srcdir;;
+*)
+ case $ac_srcdir in
+ .) ac_abs_srcdir=$ac_abs_builddir;;
+ [\\/]* | ?:[\\/]* ) ac_abs_srcdir=$ac_srcdir;;
+ *) ac_abs_srcdir=$ac_abs_builddir/$ac_srcdir;;
+ esac;;
+esac
+case $ac_abs_builddir in
+.) ac_abs_top_srcdir=$ac_top_srcdir;;
+*)
+ case $ac_top_srcdir in
+ .) ac_abs_top_srcdir=$ac_abs_builddir;;
+ [\\/]* | ?:[\\/]* ) ac_abs_top_srcdir=$ac_top_srcdir;;
+ *) ac_abs_top_srcdir=$ac_abs_builddir/$ac_top_srcdir;;
+ esac;;
+esac
+
+
+ { echo "$as_me:$LINENO: executing $ac_dest commands" >&5
+echo "$as_me: executing $ac_dest commands" >&6;}
+ case $ac_dest in
+ default )
+TCNATIVE_MAJOR_VERSION=$TCNATIVE_MAJOR_VERSION
+ ;;
+ esac
+done
+_ACEOF
+
+cat >>$CONFIG_STATUS <<\_ACEOF
+
+{ (exit 0); exit 0; }
+_ACEOF
+chmod +x $CONFIG_STATUS
+ac_clean_files=$ac_clean_files_save
+
+
+# configure is writing to config.log, and then calls config.status.
+# config.status does its own redirection, appending to config.log.
+# Unfortunately, on DOS this fails, as config.log is still kept open
+# by configure, so config.status won't be able to write to it; its
+# output is simply discarded. So we exec the FD to /dev/null,
+# effectively closing config.log, so it can be properly (re)opened and
+# appended to by config.status. When coming back to configure, we
+# need to make the FD available again.
+if test "$no_create" != yes; then
+ ac_cs_success=:
+ ac_config_status_args=
+ test "$silent" = yes &&
+ ac_config_status_args="$ac_config_status_args --quiet"
+ exec 5>/dev/null
+ $SHELL $CONFIG_STATUS $ac_config_status_args || ac_cs_success=false
+ exec 5>>config.log
+ # Use ||, not &&, to avoid exiting from the if with $? = 1, which
+ # would make configure fail if this is the last instruction.
+ $ac_cs_success || { (exit 1); exit 1; }
+fi
+
diff --git a/jni/native/configure.in b/jni/native/configure.in
new file mode 100644
index 0000000..e7fc117
--- /dev/null
+++ b/jni/native/configure.in
@@ -0,0 +1,277 @@
+#
+# 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.
+#
+
+dnl
+dnl Process this file with autoconf to produce a configure script
+dnl
+
+AC_PREREQ(2.50)
+AC_INIT(configure.in)
+
+AC_CONFIG_AUX_DIR(build)
+
+sinclude(build/apr_common.m4)
+sinclude(build/tcnative.m4)
+sinclude(build/find_apr.m4)
+
+dnl Generate ./config.nice for reproducing runs of configure
+dnl
+APR_CONFIG_NICE(config.nice)
+
+dnl # Some initial steps for configuration. We setup the default directory
+dnl # and which files are to be configured.
+
+dnl Absolute source/build directory
+abs_srcdir=`(cd $srcdir && pwd)`
+abs_builddir=`pwd`
+
+if test "$abs_builddir" != "$abs_srcdir"; then
+ USE_VPATH=1
+ TCN_CONFIG_LOCATION=build
+else
+ TCN_CONFIG_LOCATION=source
+fi
+
+AC_SUBST(TCN_CONFIG_LOCATION)
+AC_CANONICAL_SYSTEM
+AC_PROG_INSTALL
+
+dnl
+dnl compute the top directory of the build
+dnl note: this is needed for LIBTOOL and exporting the bundled Expat
+dnl
+top_builddir="$abs_builddir"
+AC_SUBST(top_builddir)
+AC_SUBST(abs_srcdir)
+AC_SUBST(abs_builddir)
+
+dnl Initialize mkdir -p functionality.
+APR_MKDIR_P_CHECK($abs_srcdir/build/mkdir.sh)
+
+dnl get our version information
+get_version="$abs_srcdir/build/get-version.sh"
+version_hdr="$abs_srcdir/include/tcn_version.h"
+TCNATIVE_MAJOR_VERSION="`$get_version major $version_hdr TCN`"
+TCNATIVE_DOTTED_VERSION="`$get_version all $version_hdr TCN`"
+TCNATIVE_LIBTOOL_VERSION="`$get_version libtool $version_hdr TCN`"
+
+AC_SUBST(TCNATIVE_DOTTED_VERSION)
+AC_SUBST(TCNATIVE_MAJOR_VERSION)
+AC_SUBST(TCNATIVE_LIBTOOL_VERSION)
+
+echo "Tomcat Native Version: ${TCNATIVE_DOTTED_VERSION}"
+
+dnl Enable the layout handling code, then reparse the prefix-style
+dnl arguments due to autoconf being a PITA.
+APR_ENABLE_LAYOUT(tcnative)
+APR_PARSE_ARGUMENTS
+
+dnl
+dnl set up the compilation flags and stuff
+dnl
+
+TCNATIVE_INCLUDES=""
+TCNATIVE_PRIV_INCLUDES="-I$top_builddir/include"
+
+dnl
+dnl Find the APR includes directory and (possibly) the source (base) dir.
+dnl
+TCN_FIND_APR
+
+dnl
+dnl even though we use apr_rules.mk for building apr-util, we need
+dnl to grab CC and CPP ahead of time so that apr-util config tests
+dnl use the same compiler as APR; we need the same compiler options
+dnl and feature test macros as well
+dnl
+APR_SETIFNULL(CC, `$apr_config --cc`)
+APR_SETIFNULL(CPP, `$apr_config --cpp`)
+
+AC_PROG_INSTALL
+
+dnl
+dnl Find the JVM related information
+dnl
+NEED_JNI_MD=yes
+TCN_FIND_JDK
+TCN_SABLEVM
+TCN_J9VM
+
+dnl MAC OS X does not used include but Headers
+if test -d ${JAVA_HOME}/Headers; then
+ JAVA_INC=Headers
+else
+ JAVA_INC=include
+fi
+APR_ADDTO(TCNATIVE_PRIV_INCLUDES,[-I$JAVA_HOME/$JAVA_INC])
+
+dnl sableVM does not have/need $JAVA_OS/jni_md.h
+if test "$NEED_JNI_MD" = "yes"; then
+ TCN_FIND_JDK_OS
+ if test -z "${JAVA_OS}"; then
+ AC_MSG_RESULT([jni_md.h found in $JAVA_HOME/$JAVA_INC])
+ else
+ APR_ADDTO(TCNATIVE_PRIV_INCLUDES,[-I$JAVA_HOME/$JAVA_INC/$JAVA_OS])
+ fi
+fi
+
+AC_SUBST(JAVA_HOME)
+AC_SUBST(JAVA_PLATFORM)
+AC_SUBST(JAVA_OS)
+
+
+dnl
+dnl Detect openssl toolkit installation
+dnl
+
+use_openssl=true;
+
+AC_ARG_ENABLE(openssl,
+[AS_HELP_STRING([--disable-openssl],[avoid using OpenSSL toolkit])],
+[
+ case "${enableval}" in
+ no )
+ use_openssl=false;
+ AC_MSG_RESULT([Disabling SSL support...])
+ ;;
+ esac
+])
+
+AC_ARG_ENABLE(ocsp,
+[AS_HELP_STRING([--enable-ocsp],[Turn on OpenSSL OCSP verification support])],
+[
+ case "${enableval}" in
+ yes )
+ APR_ADDTO(CFLAGS, [-DHAVE_OPENSSL_OCSP])
+ AC_MSG_RESULT([Enabling OCSP verification support...])
+ ;;
+ esac
+])
+
+if $use_openssl ; then
+ TCN_CHECK_SSL_TOOLKIT
+fi
+
+so_ext=$APR_SO_EXT
+lib_target=$APR_LIB_TARGET
+AC_SUBST(so_ext)
+AC_SUBST(lib_target)
+
+TCNATIVE_LIBNAME="tcnative${libsuffix}"
+AC_SUBST(TCNATIVE_LIBNAME)
+
+EXTRA_OS_LINK=""
+host_alias=`uname -s`
+case "$host_alias" in
+ dnl ### BeOS requires that ALL symbols resolve at LINK time!
+ dnl ###
+ dnl ### So, if we're building on BeOS then we need to add in the
+ dnl ### apr and expat libraries to the build or it'll die a truly horrible
+ dnl ### death. We now use the apr-config tool to determine the correct
+ dnl ### library to link against :)
+*AIX*|*Darwin*|*BeOS*)
+ dnl need such stuff as -liconv to be specified when building libaprutil.la
+ EXTRA_OS_LINK='$(TCNATIVE_LDFLAGS) $(TCNATIVE_LIBS)'
+ ;;
+*)
+ ;;
+esac
+
+AC_SUBST(EXTRA_OS_LINK)
+
+dnl CFLAGS for maintainer mode
+dnl it also allows the CFLAGS environment variable.
+CFLAGS="${CFLAGS}"
+AC_ARG_ENABLE(
+maintainer-mode,
+[ --enable-maintainer-mode Turn on debugging and compile time warnings],
+[
+ if test "$GCC" = "yes"; then
+ CFLAGS="${CFLAGS} -DDEBUG -Wall"
+ else
+ CFLAGS="${CFLAGS} -DDEBUG"
+ fi
+AC_MSG_RESULT([...Enabling Maintainer mode...])
+])
+
+dnl
+dnl Prep all the flags and stuff for compilation and export to other builds
+dnl
+APR_ADDTO(TCNATIVE_LIBS, [$LIBS])
+APR_ADDTO(TCNATIVE_LIBS, [$APR_LIBS])
+APR_ADDTO(TCNATIVE_LDFLAGS, [$LDFLAGS])
+
+# Link libkstat for Solaris
+case $host in
+ *-solaris2*)
+ APR_ADDTO(TCNATIVE_LIBS, -lkstat)
+ ;;
+ *)
+ ;;
+esac
+
+AC_SUBST(TCNATIVE_EXPORT_LIBS)
+AC_SUBST(TCNATIVE_PRIV_INCLUDES)
+AC_SUBST(TCNATIVE_INCLUDES)
+AC_SUBST(TCNATIVE_LDFLAGS)
+AC_SUBST(TCNATIVE_LIBS)
+AC_SUBST(CFLAGS)
+AC_SUBST(CPPFLAGS)
+
+dnl copy apr's rules.mk into our build directory.
+if test ! -d ./build; then
+ $mkdir_p build
+fi
+cp $APR_BUILD_DIR/apr_rules.mk $abs_builddir/build/rules.mk
+
+
+dnl
+dnl BSD/OS (BSDi) needs to use a different include syntax in the Makefiles
+dnl
+case "$host_alias" in
+*bsdi* | BSD/OS)
+ # Check whether they've installed GNU make
+ if make --version > /dev/null 2>&1; then
+ INCLUDE_RULES="include $abs_builddir/build/rules.mk"
+ INCLUDE_OUTPUTS="include $abs_srcdir/build-outputs.mk"
+ else
+ INCLUDE_RULES=".include \"$abs_builddir/build/rules.mk\""
+ INCLUDE_OUTPUTS=".include \"$abs_srcdir/build-outputs.mk\""
+ fi
+ ;;
+*)
+ INCLUDE_RULES="include $abs_builddir/build/rules.mk"
+ INCLUDE_OUTPUTS="include $abs_srcdir/build-outputs.mk"
+ ;;
+esac
+
+AC_SUBST(INCLUDE_RULES)
+AC_SUBST(INCLUDE_OUTPUTS)
+
+if test -d $srcdir/test; then
+ test_Makefile="test/Makefile"
+fi
+
+dnl
+dnl everything is done.
+MAKEFILES="Makefile"
+AC_OUTPUT([
+ tcnative.pc
+ $MAKEFILES
+ ],[
+TCNATIVE_MAJOR_VERSION=$TCNATIVE_MAJOR_VERSION
+])
diff --git a/jni/native/include/ssl_private.h b/jni/native/include/ssl_private.h
new file mode 100644
index 0000000..26de5ca
--- /dev/null
+++ b/jni/native/include/ssl_private.h
@@ -0,0 +1,321 @@
+/* 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: ssl_private.h 1586221 2014-04-10 05:44:09Z mturk $
+ */
+
+#ifndef SSL_PRIVATE_H
+#define SSL_PRIVATE_H
+
+/* Exclude unused OpenSSL features
+ * even if the OpenSSL supports them
+ */
+#ifndef OPENSSL_NO_IDEA
+#define OPENSSL_NO_IDEA
+#endif
+#ifndef OPENSSL_NO_KRB5
+#define OPENSSL_NO_KRB5
+#endif
+#ifndef OPENSSL_NO_MDC2
+#define OPENSSL_NO_MDC2
+#endif
+#ifndef OPENSSL_NO_RC5
+#define OPENSSL_NO_RC5
+#endif
+
+/* OpenSSL headers */
+#include <openssl/opensslv.h>
+#include <openssl/ssl.h>
+#include <openssl/err.h>
+#include <openssl/x509.h>
+#include <openssl/pem.h>
+#include <openssl/pkcs12.h>
+#include <openssl/crypto.h>
+#include <openssl/evp.h>
+#include <openssl/rand.h>
+#include <openssl/x509v3.h>
+/* Avoid tripping over an engine build installed globally and detected
+ * when the user points at an explicit non-engine flavor of OpenSSL
+ */
+#ifndef OPENSSL_NO_ENGINE
+#include <openssl/engine.h>
+#endif
+
+#ifndef RAND_MAX
+#include <limits.h>
+#define RAND_MAX INT_MAX
+#endif
+
+#define SSL_ALGO_UNKNOWN (0)
+#define SSL_ALGO_RSA (1<<0)
+#define SSL_ALGO_DSA (1<<1)
+#define SSL_ALGO_ALL (SSL_ALGO_RSA|SSL_ALGO_DSA)
+
+#define SSL_AIDX_RSA (0)
+#define SSL_AIDX_DSA (1)
+#define SSL_AIDX_MAX (2)
+
+/*
+ * Define IDs for the temporary RSA keys and DH params
+ */
+
+#define SSL_TMP_KEY_RSA_512 (0)
+#define SSL_TMP_KEY_RSA_1024 (1)
+#define SSL_TMP_KEY_RSA_2048 (2)
+#define SSL_TMP_KEY_RSA_4096 (3)
+#define SSL_TMP_KEY_DH_512 (4)
+#define SSL_TMP_KEY_DH_1024 (5)
+#define SSL_TMP_KEY_DH_2048 (6)
+#define SSL_TMP_KEY_DH_4096 (7)
+#define SSL_TMP_KEY_MAX (8)
+
+#define SSL_CRT_FORMAT_UNDEF (0)
+#define SSL_CRT_FORMAT_ASN1 (1)
+#define SSL_CRT_FORMAT_TEXT (2)
+#define SSL_CRT_FORMAT_PEM (3)
+#define SSL_CRT_FORMAT_NETSCAPE (4)
+#define SSL_CRT_FORMAT_PKCS12 (5)
+#define SSL_CRT_FORMAT_SMIME (6)
+#define SSL_CRT_FORMAT_ENGINE (7)
+/* XXX this stupid macro helps us to avoid
+ * adding yet another param to load_*key()
+ */
+#define SSL_KEY_FORMAT_IISSGC (8)
+
+/*
+ * Define the SSL options
+ */
+#define SSL_OPT_NONE (0)
+#define SSL_OPT_RELSET (1<<0)
+#define SSL_OPT_STDENVVARS (1<<1)
+#define SSL_OPT_EXPORTCERTDATA (1<<3)
+#define SSL_OPT_FAKEBASICAUTH (1<<4)
+#define SSL_OPT_STRICTREQUIRE (1<<5)
+#define SSL_OPT_OPTRENEGOTIATE (1<<6)
+#define SSL_OPT_ALL (SSL_OPT_STDENVVARS|SSL_OPT_EXPORTCERTDATA|SSL_OPT_FAKEBASICAUTH|SSL_OPT_STRICTREQUIRE|SSL_OPT_OPTRENEGOTIATE)
+
+/*
+ * Define the SSL Protocol options
+ */
+#define SSL_PROTOCOL_NONE (0)
+#define SSL_PROTOCOL_SSLV2 (1<<0)
+#define SSL_PROTOCOL_SSLV3 (1<<1)
+#define SSL_PROTOCOL_TLSV1 (1<<2)
+#define SSL_PROTOCOL_ALL (SSL_PROTOCOL_SSLV2|SSL_PROTOCOL_SSLV3|SSL_PROTOCOL_TLSV1)
+
+#define SSL_MODE_CLIENT (0)
+#define SSL_MODE_SERVER (1)
+#define SSL_MODE_COMBINED (2)
+
+#define SSL_BIO_FLAG_RDONLY (1<<0)
+#define SSL_BIO_FLAG_CALLBACK (1<<1)
+#define SSL_DEFAULT_CACHE_SIZE (256)
+#define SSL_DEFAULT_VHOST_NAME ("_default_:443")
+#define SSL_MAX_STR_LEN (2048)
+#define SSL_MAX_PASSWORD_LEN (256)
+
+#define SSL_CVERIFY_UNSET (-1)
+#define SSL_CVERIFY_NONE (0)
+#define SSL_CVERIFY_OPTIONAL (1)
+#define SSL_CVERIFY_REQUIRE (2)
+#define SSL_CVERIFY_OPTIONAL_NO_CA (3)
+#define SSL_VERIFY_PEER_STRICT (SSL_VERIFY_PEER|SSL_VERIFY_FAIL_IF_NO_PEER_CERT)
+
+#define SSL_SHUTDOWN_TYPE_UNSET (0)
+#define SSL_SHUTDOWN_TYPE_STANDARD (1)
+#define SSL_SHUTDOWN_TYPE_UNCLEAN (2)
+#define SSL_SHUTDOWN_TYPE_ACCURATE (3)
+
+#define SSL_TO_APR_ERROR(X) (APR_OS_START_USERERR + 1000 + X)
+
+#define SSL_INFO_SESSION_ID (0x0001)
+#define SSL_INFO_CIPHER (0x0002)
+#define SSL_INFO_CIPHER_USEKEYSIZE (0x0003)
+#define SSL_INFO_CIPHER_ALGKEYSIZE (0x0004)
+#define SSL_INFO_CIPHER_VERSION (0x0005)
+#define SSL_INFO_CIPHER_DESCRIPTION (0x0006)
+#define SSL_INFO_PROTOCOL (0x0007)
+
+#define SSL_INFO_CLIENT_S_DN (0x0010)
+#define SSL_INFO_CLIENT_I_DN (0x0020)
+#define SSL_INFO_SERVER_S_DN (0x0040)
+#define SSL_INFO_SERVER_I_DN (0x0080)
+
+#define SSL_INFO_DN_COUNTRYNAME (0x0001)
+#define SSL_INFO_DN_STATEORPROVINCENAME (0x0002)
+#define SSL_INFO_DN_LOCALITYNAME (0x0003)
+#define SSL_INFO_DN_ORGANIZATIONNAME (0x0004)
+#define SSL_INFO_DN_ORGANIZATIONALUNITNAME (0x0005)
+#define SSL_INFO_DN_COMMONNAME (0x0006)
+#define SSL_INFO_DN_TITLE (0x0007)
+#define SSL_INFO_DN_INITIALS (0x0008)
+#define SSL_INFO_DN_GIVENNAME (0x0009)
+#define SSL_INFO_DN_SURNAME (0x000A)
+#define SSL_INFO_DN_DESCRIPTION (0x000B)
+#define SSL_INFO_DN_UNIQUEIDENTIFIER (0x000C)
+#define SSL_INFO_DN_EMAILADDRESS (0x000D)
+
+#define SSL_INFO_CLIENT_MASK (0x0100)
+
+#define SSL_INFO_CLIENT_M_VERSION (0x0101)
+#define SSL_INFO_CLIENT_M_SERIAL (0x0102)
+#define SSL_INFO_CLIENT_V_START (0x0103)
+#define SSL_INFO_CLIENT_V_END (0x0104)
+#define SSL_INFO_CLIENT_A_SIG (0x0105)
+#define SSL_INFO_CLIENT_A_KEY (0x0106)
+#define SSL_INFO_CLIENT_CERT (0x0107)
+#define SSL_INFO_CLIENT_V_REMAIN (0x0108)
+
+#define SSL_INFO_SERVER_MASK (0x0200)
+
+#define SSL_INFO_SERVER_M_VERSION (0x0201)
+#define SSL_INFO_SERVER_M_SERIAL (0x0202)
+#define SSL_INFO_SERVER_V_START (0x0203)
+#define SSL_INFO_SERVER_V_END (0x0204)
+#define SSL_INFO_SERVER_A_SIG (0x0205)
+#define SSL_INFO_SERVER_A_KEY (0x0206)
+#define SSL_INFO_SERVER_CERT (0x0207)
+#define SSL_INFO_CLIENT_CERT_CHAIN (0x0400)
+
+#define SSL_VERIFY_ERROR_IS_OPTIONAL(errnum) \
+ ((errnum == X509_V_ERR_DEPTH_ZERO_SELF_SIGNED_CERT) \
+ || (errnum == X509_V_ERR_SELF_SIGNED_CERT_IN_CHAIN) \
+ || (errnum == X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT_LOCALLY) \
+ || (errnum == X509_V_ERR_CERT_UNTRUSTED) \
+ || (errnum == X509_V_ERR_UNABLE_TO_VERIFY_LEAF_SIGNATURE))
+
+#define SSL_DEFAULT_PASS_PROMPT "Some of your private key files are encrypted for security reasons.\n" \
+ "In order to read them you have to provide the pass phrases.\n" \
+ "Enter password :"
+
+#define OCSP_STATUS_OK 0
+#define OCSP_STATUS_REVOKED 1
+#define OCSP_STATUS_UNKNOWN 2
+
+
+/* ECC: make sure we have at least 1.0.0 */
+#if !defined(OPENSSL_NO_EC) && defined(TLSEXT_ECPOINTFORMAT_uncompressed)
+#define HAVE_ECC 1
+#endif
+
+extern void *SSL_temp_keys[SSL_TMP_KEY_MAX];
+
+typedef struct {
+ /* client can have any number of cert/key pairs */
+ const char *cert_file;
+ const char *cert_path;
+ STACK_OF(X509_INFO) *certs;
+} ssl_pkc_t;
+
+typedef struct tcn_ssl_ctxt_t tcn_ssl_ctxt_t;
+
+typedef struct {
+ char password[SSL_MAX_PASSWORD_LEN];
+ const char *prompt;
+ tcn_callback_t cb;
+} tcn_pass_cb_t;
+
+extern tcn_pass_cb_t tcn_password_callback;
+
+struct tcn_ssl_ctxt_t {
+ apr_pool_t *pool;
+ SSL_CTX *ctx;
+ BIO *bio_os;
+ BIO *bio_is;
+
+ unsigned char context_id[SHA_DIGEST_LENGTH];
+
+ int protocol;
+ /* we are one or the other */
+ int mode;
+
+ /* certificate revocation list */
+ X509_STORE *crl;
+ /* pointer to the context verify store */
+ X509_STORE *store;
+ const char *cert_files[SSL_AIDX_MAX];
+ const char *key_files[SSL_AIDX_MAX];
+ X509 *certs[SSL_AIDX_MAX];
+ EVP_PKEY *keys[SSL_AIDX_MAX];
+
+ int ca_certs;
+ int shutdown_type;
+ char *rand_file;
+
+ const char *cipher_suite;
+ /* for client or downstream server authentication */
+ int verify_depth;
+ int verify_mode;
+ tcn_pass_cb_t *cb_data;
+};
+
+
+typedef struct {
+ apr_pool_t *pool;
+ tcn_ssl_ctxt_t *ctx;
+ SSL *ssl;
+ X509 *peer;
+ int shutdown_type;
+ /* Track the handshake/renegotiation state for the connection so
+ * that all client-initiated renegotiations can be rejected, as a
+ * partial fix for CVE-2009-3555.
+ */
+ enum {
+ RENEG_INIT = 0, /* Before initial handshake */
+ RENEG_REJECT, /* After initial handshake; any client-initiated
+ * renegotiation should be rejected
+ */
+ RENEG_ALLOW, /* A server-initated renegotiation is taking
+ * place (as dictated by configuration)
+ */
+ RENEG_ABORT /* Renegotiation initiated by client, abort the
+ * connection
+ */
+ } reneg_state;
+ apr_socket_t *sock;
+ apr_pollset_t *pollset;
+} tcn_ssl_conn_t;
+
+
+#define SSL_CTX_get_extra_certs(ctx) ((ctx)->extra_certs)
+#define SSL_CTX_set_extra_certs(ctx, value) \
+ TCN_BEGIN_MACRO \
+ (ctx)->extra_certs = (value); \
+ TCN_END_MACRO
+
+/*
+ * Additional Functions
+ */
+void SSL_init_app_data2_idx(void);
+void *SSL_get_app_data2(SSL *);
+void SSL_set_app_data2(SSL *, void *);
+int SSL_password_prompt(tcn_pass_cb_t *);
+int SSL_password_callback(char *, int, int, void *);
+void SSL_BIO_close(BIO *);
+void SSL_BIO_doref(BIO *);
+DH *SSL_dh_get_tmp_param(int);
+DH *SSL_dh_get_param_from_file(const char *);
+RSA *SSL_callback_tmp_RSA(SSL *, int, int);
+DH *SSL_callback_tmp_DH(SSL *, int, int);
+void SSL_callback_handshake(const SSL *, int, int);
+int SSL_CTX_use_certificate_chain(SSL_CTX *, const char *, int);
+int SSL_callback_SSL_verify(int, X509_STORE_CTX *);
+int SSL_rand_seed(const char *file);
+
+#endif /* SSL_PRIVATE_H */
diff --git a/jni/native/include/tcn.h b/jni/native/include/tcn.h
new file mode 100644
index 0000000..9758912
--- /dev/null
+++ b/jni/native/include/tcn.h
@@ -0,0 +1,317 @@
+/* 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: tcn.h 1446443 2013-02-15 04:18:04Z rjung $
+ */
+
+#ifndef TCN_H
+#define TCN_H
+
+#include "apr.h"
+#include "apr_general.h"
+#include "apr_lib.h"
+#include "apr_pools.h"
+#include "apr_portable.h"
+#include "apr_network_io.h"
+#include "apr_poll.h"
+#include "apr_ring.h"
+#include "apr_strings.h"
+
+#ifndef APR_HAS_THREADS
+#error "Missing APR_HAS_THREADS support from APR."
+#endif
+
+#if defined(DEBUG) || defined(_DEBUG)
+/* On -DDEBUG use the statistics */
+#ifndef TCN_DO_STATISTICS
+#define TCN_DO_STATISTICS
+#endif
+#endif
+#include <stdio.h>
+#include <stdlib.h>
+#if defined(_WIN32) && !defined(__CYGWIN__)
+#include <process.h>
+#else
+#include <unistd.h>
+#endif
+
+#if !defined(APR_POLLSET_NOCOPY)
+/* Add missing API */
+#define APR_RING_FOREACH(ep, head, elem, link) \
+ for (ep = APR_RING_FIRST(head); \
+ ep != APR_RING_SENTINEL(head, elem, link); \
+ ep = APR_RING_NEXT(ep, link))
+
+#define APR_RING_FOREACH_SAFE(ep1, ep2, head, elem, link) \
+ for (ep1 = APR_RING_FIRST(head), ep2 = APR_RING_NEXT(ep1, link); \
+ ep1 != APR_RING_SENTINEL(head, elem, link); \
+ ep1 = ep2, ep2 = APR_RING_NEXT(ep1, link))
+
+#define APR_POLLSET_NOCOPY 0
+#endif
+
+#include "tcn_api.h"
+
+
+#if defined(_DEBUG) || defined(DEBUG)
+#include <assert.h>
+#define TCN_ASSERT(x) assert((x))
+#else
+#define TCN_ASSERT(x) (void)0
+#endif
+
+#ifndef APR_MAX_IOVEC_SIZE
+#define APR_MAX_IOVEC_SIZE 1024
+#endif
+
+#define TCN_TIMEUP APR_OS_START_USERERR + 1
+#define TCN_EAGAIN APR_OS_START_USERERR + 2
+#define TCN_EINTR APR_OS_START_USERERR + 3
+#define TCN_EINPROGRESS APR_OS_START_USERERR + 4
+#define TCN_ETIMEDOUT APR_OS_START_USERERR + 5
+
+#define TCN_LOG_EMERG 1
+#define TCN_LOG_ERROR 2
+#define TCN_LOG_NOTICE 3
+#define TCN_LOG_WARN 4
+#define TCN_LOG_INFO 5
+#define TCN_LOG_DEBUG 6
+
+#define TCN_ERROR_WRAP(E) \
+ if (APR_STATUS_IS_TIMEUP(E)) \
+ (E) = TCN_TIMEUP; \
+ else if (APR_STATUS_IS_EAGAIN(E)) \
+ (E) = TCN_EAGAIN; \
+ else if (APR_STATUS_IS_EINTR(E)) \
+ (E) = TCN_EINTR; \
+ else if (APR_STATUS_IS_EINPROGRESS(E)) \
+ (E) = TCN_EINPROGRESS; \
+ else if (APR_STATUS_IS_ETIMEDOUT(E)) \
+ (E) = TCN_ETIMEDOUT; \
+ else \
+ (E) = (E)
+
+#define TCN_CLASS_PATH "org/apache/tomcat/jni/"
+#define TCN_FINFO_CLASS TCN_CLASS_PATH "FileInfo"
+#define TCN_AINFO_CLASS TCN_CLASS_PATH "Sockaddr"
+#define TCN_ERROR_CLASS TCN_CLASS_PATH "Error"
+#define TCN_PARENT_IDE "TCN_PARENT_ID"
+
+#define UNREFERENCED(P) (P) = (P)
+#define UNREFERENCED_STDARGS e = e; o = o
+#ifdef WIN32
+#define LLT(X) (X)
+#else
+#define LLT(X) ((long)(X))
+#endif
+#define P2J(P) ((jlong)LLT(P))
+#define J2P(P, T) ((T)LLT((jlong)P))
+/* On stack buffer size */
+#define TCN_BUFFER_SZ 8192
+#define TCN_STDARGS JNIEnv *e, jobject o
+#define TCN_IMPARGS JNIEnv *e, jobject o, void *sock
+#define TCN_IMPCALL(X) e, o, X->opaque
+
+#define TCN_IMPLEMENT_CALL(RT, CL, FN) \
+ JNIEXPORT RT JNICALL Java_org_apache_tomcat_jni_##CL##_##FN
+
+#define TCN_IMPLEMENT_METHOD(RT, FN) \
+ static RT method_##FN
+
+#define TCN_GETNET_METHOD(FN) method_##FN
+
+#define TCN_SOCKET_UNKNOWN 0
+#define TCN_SOCKET_APR 1
+#define TCN_SOCKET_SSL 2
+#define TCN_SOCKET_UNIX 3
+#define TCN_SOCKET_NTPIPE 4
+
+#define TCN_SOCKET_GET_POOL 0
+#define TCN_SOCKET_GET_IMPL 1
+#define TCN_SOCKET_GET_APRS 2
+#define TCN_SOCKET_GET_TYPE 3
+
+typedef struct {
+ int type;
+ apr_status_t (*cleanup)(void *);
+ apr_status_t (APR_THREAD_FUNC *close) (apr_socket_t *);
+ apr_status_t (APR_THREAD_FUNC *shutdown) (apr_socket_t *, apr_shutdown_how_e);
+ apr_status_t (APR_THREAD_FUNC *opt_get)(apr_socket_t *, apr_int32_t, apr_int32_t *);
+ apr_status_t (APR_THREAD_FUNC *opt_set)(apr_socket_t *, apr_int32_t, apr_int32_t);
+ apr_status_t (APR_THREAD_FUNC *timeout_get)(apr_socket_t *, apr_interval_time_t *);
+ apr_status_t (APR_THREAD_FUNC *timeout_set)(apr_socket_t *, apr_interval_time_t);
+ apr_status_t (APR_THREAD_FUNC *send) (apr_socket_t *, const char *, apr_size_t *);
+ apr_status_t (APR_THREAD_FUNC *sendv)(apr_socket_t *, const struct iovec *, apr_int32_t, apr_size_t *);
+ apr_status_t (APR_THREAD_FUNC *recv) (apr_socket_t *, char *, apr_size_t *);
+} tcn_nlayer_t;
+
+typedef struct tcn_socket_t tcn_socket_t;
+typedef struct tcn_pfde_t tcn_pfde_t;
+
+struct tcn_pfde_t {
+ APR_RING_ENTRY(tcn_pfde_t) link;
+ apr_pollfd_t fd;
+};
+
+struct tcn_socket_t {
+ apr_pool_t *pool;
+ apr_pool_t *child;
+ apr_socket_t *sock;
+ void *opaque;
+ char *jsbbuff;
+ char *jrbbuff;
+ tcn_nlayer_t *net;
+ tcn_pfde_t *pe;
+ apr_time_t last_active;
+ apr_interval_time_t timeout;
+};
+
+/* Private helper functions */
+void tcn_Throw(JNIEnv *, const char *, ...);
+void tcn_ThrowException(JNIEnv *, const char *);
+void tcn_ThrowMemoryException(JNIEnv *, const char *, int, const char *);
+void tcn_ThrowAPRException(JNIEnv *, apr_status_t);
+jstring tcn_new_string(JNIEnv *, const char *);
+jstring tcn_new_stringn(JNIEnv *, const char *, size_t);
+jbyteArray tcn_new_arrayb(JNIEnv *, const unsigned char *, size_t);
+jobjectArray tcn_new_arrays(JNIEnv *env, size_t len);
+char *tcn_get_string(JNIEnv *, jstring);
+char *tcn_strdup(JNIEnv *, jstring);
+char *tcn_pstrdup(JNIEnv *, jstring, apr_pool_t *);
+apr_status_t tcn_load_finfo_class(JNIEnv *, jclass);
+apr_status_t tcn_load_ainfo_class(JNIEnv *, jclass);
+
+#define J2S(V) c##V
+#define J2L(V) p##V
+
+#define J2T(T) (apr_time_t)((T))
+
+#define TCN_BEGIN_MACRO if (1) {
+#define TCN_END_MACRO } else (void)(0)
+
+#define TCN_ALLOC_CSTRING(V) \
+ const char *c##V = V ? (const char *)((*e)->GetStringUTFChars(e, V, 0)) : NULL
+
+#define TCN_FREE_CSTRING(V) \
+ if (c##V) (*e)->ReleaseStringUTFChars(e, V, c##V)
+
+#define TCN_ALLOC_JSTRING(V) \
+ char *c##V = tcn_get_string(e, (V))
+
+#define AJP_TO_JSTRING(V) (*e)->NewStringUTF((e), (V))
+
+#define TCN_FREE_JSTRING(V) \
+ TCN_BEGIN_MACRO \
+ if (c##V) \
+ free(c##V); \
+ TCN_END_MACRO
+
+#define TCN_CHECK_ALLOCATED(x) \
+ if (x == NULL) { \
+ tcn_ThrowMemoryException(e, __FILE__, __LINE__, \
+ "APR memory allocation failed"); \
+ goto cleanup; \
+ } else (void)(0)
+
+#define TCN_THROW_IF_ERR(x, r) \
+ TCN_BEGIN_MACRO \
+ apr_status_t R = (x); \
+ if (R != APR_SUCCESS) { \
+ tcn_ThrowAPRException(e, R); \
+ (r) = 0; \
+ goto cleanup; \
+ } \
+ TCN_END_MACRO
+
+#define TCN_THROW_OS_ERROR(E) \
+ tcn_ThrowAPRException((E), apr_get_os_error())
+
+#define TCN_LOAD_CLASS(E, C, N, R) \
+ TCN_BEGIN_MACRO \
+ jclass _##C = (*(E))->FindClass((E), N); \
+ if (_##C == NULL) { \
+ (*(E))->ExceptionClear((E)); \
+ return R; \
+ } \
+ C = (*(E))->NewGlobalRef((E), _##C); \
+ (*(E))->DeleteLocalRef((E), _##C); \
+ TCN_END_MACRO
+
+#define TCN_UNLOAD_CLASS(E, C) \
+ (*(E))->DeleteGlobalRef((E), (C))
+
+#define TCN_IS_NULL(E, O) \
+ ((*(E))->IsSameObject((E), (O), NULL) == JNI_TRUE)
+
+#define TCN_GET_METHOD(E, C, M, N, S, R) \
+ TCN_BEGIN_MACRO \
+ M = (*(E))->GetMethodID((E), C, N, S); \
+ if (M == NULL) { \
+ return R; \
+ } \
+ TCN_END_MACRO
+
+#define TCN_MAX_METHODS 8
+
+typedef struct {
+ jobject obj;
+ jmethodID mid[TCN_MAX_METHODS];
+ void *opaque;
+} tcn_callback_t;
+
+#define TCN_MIN(a, b) ((a) < (b) ? (a) : (b))
+#define TCN_MAX(a, b) ((a) > (b) ? (a) : (b))
+
+#ifdef WIN32
+#define TCN_ALLOC_WSTRING(V) \
+ jsize wl##V = (*e)->GetStringLength(e, V); \
+ const jchar *ws##V = V ? (const jchar *)((*e)->GetStringChars(e, V, 0)) : NULL; \
+ jchar *w##V = NULL
+
+#define TCN_INIT_WSTRING(V) \
+ w##V = (jchar *)malloc((wl##V + 1) * sizeof(jchar)); \
+ wcsncpy(w##V, ws##V, wl##V); \
+ w##V[wl##V] = 0
+
+#define TCN_FREE_WSTRING(V) \
+ if (ws##V) (*e)->ReleaseStringChars(e, V, ws##V); \
+ if (ws##V) free (w##V)
+
+#define J2W(V) w##V
+
+#endif
+
+#if !APR_HAVE_IPV6
+#define APR_INET6 APR_INET
+#endif
+
+#define GET_S_FAMILY(T, F) \
+ if (F == 0) T = APR_UNSPEC; \
+ else if (F == 1) T = APR_INET; \
+ else if (F == 2) T = APR_INET6; \
+ else T = F
+
+#define GET_S_TYPE(T, F) \
+ if (F == 0) T = SOCK_STREAM; \
+ else if (F == 1) T = SOCK_DGRAM; \
+ else T = F
+
+#define TCN_NO_SOCKET_TIMEOUT -2
+
+#endif /* TCN_H */
diff --git a/jni/native/include/tcn_api.h b/jni/native/include/tcn_api.h
new file mode 100644
index 0000000..f5477fc
--- /dev/null
+++ b/jni/native/include/tcn_api.h
@@ -0,0 +1,65 @@
+/* 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: tcn_api.h 1442587 2013-02-05 13:49:48Z rjung $
+ */
+
+#ifndef TCN_API_H
+#define TCN_API_H
+
+#include "apr.h"
+#include "apr_general.h"
+#include "apr_pools.h"
+#include "apr_portable.h"
+#include "apr_network_io.h"
+#include "apr_strings.h"
+
+#ifndef APR_HAS_THREADS
+#error "Missing APR_HAS_THREADS support from APR."
+#endif
+#include <jni.h>
+
+/**
+ * @file tcn_api.h
+ * @brief
+ *
+ * Tomcat Native Public API
+ */
+
+/* Return global apr pool
+ */
+apr_pool_t *tcn_get_global_pool(void);
+
+/* Return global String class
+ */
+jclass tcn_get_string_class(void);
+
+/* Return global JVM initalized on JNI_OnLoad
+ */
+JavaVM *tcn_get_java_vm(void);
+
+/* Get current thread JNIEnv
+ */
+jint tcn_get_java_env(JNIEnv **);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* TCN_API_H */
diff --git a/jni/native/include/tcn_version.h b/jni/native/include/tcn_version.h
new file mode 100644
index 0000000..3318ae2
--- /dev/null
+++ b/jni/native/include/tcn_version.h
@@ -0,0 +1,100 @@
+/* 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: tcn_version.h 1586263 2014-04-10 10:27:08Z mturk $
+ */
+
+#ifndef TCN_VERSION_H
+#define TCN_VERSION_H
+
+#include "apr_version.h"
+
+#include "tcn.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * @file tcn_version.h
+ * @brief
+ *
+ * Tomcat Native Version
+ *
+ * There are several different mechanisms for accessing the version. There
+ * is a string form, and a set of numbers; in addition, there are constants
+ * which can be compiled into your application, and you can query the library
+ * being used for its actual version.
+ *
+ * Note that it is possible for an application to detect that it has been
+ * compiled against a different version of APU by use of the compile-time
+ * constants and the use of the run-time query function.
+ *
+ * TCN version numbering follows the guidelines specified in:
+ *
+ * http://apr.apache.org/versioning.html
+ */
+
+/* The numeric compile-time version constants. These constants are the
+ * authoritative version numbers for TCN.
+ */
+
+/** major version
+ * Major API changes that could cause compatibility problems for older
+ * programs such as structure size changes. No binary compatibility is
+ * possible across a change in the major version.
+ */
+#define TCN_MAJOR_VERSION 1
+
+/**
+ * Minor API changes that do not cause binary compatibility problems.
+ * Should be reset to 0 when upgrading TCN_MAJOR_VERSION
+ */
+#define TCN_MINOR_VERSION 1
+
+/** patch level */
+#define TCN_PATCH_VERSION 30
+
+/**
+ * This symbol is defined for internal, "development" copies of TCN. This
+ * symbol will be #undef'd for releases.
+ */
+#define TCN_IS_DEV_VERSION 0
+
+
+/** The formatted string of APU's version */
+#define TCN_VERSION_STRING \
+ APR_STRINGIFY(TCN_MAJOR_VERSION) "."\
+ APR_STRINGIFY(TCN_MINOR_VERSION) "."\
+ APR_STRINGIFY(TCN_PATCH_VERSION)\
+ TCN_IS_DEV_STRING
+
+/** Internal: string form of the "is dev" flag */
+#if TCN_IS_DEV_VERSION
+#define TCN_IS_DEV_STRING "-dev"
+#else
+#define TCN_IS_DEV_STRING ""
+#endif
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* TCN_VERSION_H */
+
diff --git a/jni/native/libtcnative.dsp b/jni/native/libtcnative.dsp
new file mode 100644
index 0000000..6b02f9f
--- /dev/null
+++ b/jni/native/libtcnative.dsp
@@ -0,0 +1,231 @@
+# Microsoft Developer Studio Project File - Name="libtcnative" - Package Owner=<4>
+# Microsoft Developer Studio Generated Build File, Format Version 6.00
+# ** DO NOT EDIT **
+
+# TARGTYPE "Win32 (x86) Dynamic-Link Library" 0x0102
+
+CFG=libtcnative - Win32 Debug
+!MESSAGE This is not a valid makefile. To build this project using NMAKE,
+!MESSAGE use the Export Makefile command and run
+!MESSAGE
+!MESSAGE NMAKE /f "libtcnative.mak".
+!MESSAGE
+!MESSAGE You can specify a configuration when running NMAKE
+!MESSAGE by defining the macro CFG on the command line. For example:
+!MESSAGE
+!MESSAGE NMAKE /f "libtcnative.mak" CFG="libtcnative - Win32 Debug"
+!MESSAGE
+!MESSAGE Possible choices for configuration are:
+!MESSAGE
+!MESSAGE "libtcnative - Win32 Release" (based on "Win32 (x86) Dynamic-Link Library")
+!MESSAGE "libtcnative - Win32 Debug" (based on "Win32 (x86) Dynamic-Link Library")
+!MESSAGE
+
+# Begin Project
+# PROP AllowPerConfigDependencies 0
+# PROP Scc_ProjName ""
+# PROP Scc_LocalPath ""
+CPP=cl.exe
+MTL=midl.exe
+RSC=rc.exe
+
+!IF "$(CFG)" == "libtcnative - Win32 Release"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 0
+# PROP BASE Output_Dir "Release"
+# PROP BASE Intermediate_Dir "Release"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 0
+# PROP Output_Dir "Release"
+# PROP Intermediate_Dir "Release"
+# PROP Ignore_Export_Lib 0
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /MD /W3 /Zi /O2 /Oy- /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /FD /c
+# ADD CPP /nologo /MD /W3 /Zi /O2 /Oy- /I "./include" /I "./srclib/apr/include" /I "./srclib/apr/include/arch/win32" /I "$(JAVA_HOME)/include" /I "$(JAVA_HOME)/include/win32" /I "./srclib/openssl/inc32" /D "NDEBUG" /D "WIN32" /D "_WINDOWS" /D "NO_IDEA" /D "NO_RC5" /D "NO_MDC2" /D "OPENSSL_NO_IDEA" /D "OPENSSL_NO_RC5" /D "OPENSSL_NO_MDC2" /D "HAVE_OPENSSL" /D HAVE_SSL_SET_STATE=1 /Fd"Release\libtcnative_src" /FD /c
+# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /o /win32 "NUL"
+# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /o /win32 "NUL"
+# ADD BASE RSC /l 0x409 /d "NDEBUG"
+# ADD RSC /l 0x409 /d "NDEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 kernel32.lib advapi32.lib ws2_32.lib mswsock.lib wldap32.lib psapi.lib ole32.lib shlwapi.lib /nologo /base:"0x6EE00000" /subsystem:windows /dll /debug /machine:I386 /opt:ref
+# ADD LINK32 kernel32.lib advapi32.lib ws2_32.lib mswsock.lib wldap32.lib psapi.lib ole32.lib shlwapi.lib rpcrt4.lib libeay32.lib ssleay32.lib /nologo /base:"0x6EE00000" /subsystem:windows /dll /debug /machine:I386 /out:"Release/libtcnative-1.dll" /libpath:"./srclib/openssl/out32" /libpath:"./srclib/openssl/out32dll" /opt:ref
+
+!ELSEIF "$(CFG)" == "libtcnative - Win32 Debug"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 1
+# PROP BASE Output_Dir "Debug"
+# PROP BASE Intermediate_Dir "Debug"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 1
+# PROP Output_Dir "Debug"
+# PROP Intermediate_Dir "Debug"
+# PROP Ignore_Export_Lib 0
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /MDd /W3 /GX /Zi /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /FD /c
+# ADD CPP /nologo /MDd /W4 /GX /Zi /Od /I "./include" /I "./srclib/apr/include" /I "./srclib/apr/include/arch/win32" /I "$(JAVA_HOME)/include" /I "$(JAVA_HOME)/include/win32" /I "./srclib/openssl/inc32" /D "_DEBUG" /D "WIN32" /D "_WINDOWS" /D "NO_IDEA" /D "NO_RC5" /D "NO_MDC2" /D "OPENSSL_NO_IDEA" /D "OPENSSL_NO_RC5" /D "OPENSSL_NO_MDC2" /D "HAVE_OPENSSL" /D HAVE_SSL_SET_STATE=1 /Fd"Debug\libtcnative_src" /FD /c
+# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /o /win32 "NUL"
+# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /o /win32 "NUL"
+# ADD BASE RSC /l 0x409 /d "_DEBUG"
+# ADD RSC /l 0x409 /d "_DEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 kernel32.lib advapi32.lib ws2_32.lib mswsock.lib wldap32.lib psapi.lib ole32.lib shlwapi.lib /nologo /base:"0x6EE00000" /subsystem:windows /dll /incremental:no /debug /machine:I386
+# ADD LINK32 kernel32.lib advapi32.lib ws2_32.lib mswsock.lib wldap32.lib psapi.lib ole32.lib shlwapi.lib rpcrt4.lib libeay32.lib ssleay32.lib /nologo /base:"0x6EE00000" /subsystem:windows /dll /incremental:no /debug /machine:I386 /out:"Debug/libtcnative-1.dll" /libpath:"./srclib/openssl/out32" /libpath:"./srclib/openssl/out32dll"
+
+!ENDIF
+
+# Begin Target
+
+# Name "libtcnative - Win32 Release"
+# Name "libtcnative - Win32 Debug"
+# Begin Group "Source Files"
+
+# PROP Default_Filter ""
+# Begin Source File
+
+SOURCE=.\src\address.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\src\dir.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\src\error.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\src\file.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\src\info.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\src\jnilib.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\src\lock.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\src\misc.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\src\mmap.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\src\multicast.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\src\network.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\src\poll.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\src\pool.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\src\proc.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\src\shm.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\src\ssl.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\src\sslcontext.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\src\sslinfo.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\src\sslnetwork.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\src\sslutils.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\src\stdlib.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\src\thread.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\src\user.c
+# End Source File
+# End Group
+# Begin Group "Generated Files"
+
+# PROP Default_Filter ""
+# End Group
+# Begin Group "Header Files"
+
+# PROP Default_Filter ""
+# Begin Source File
+
+SOURCE=.\include\ssl_private.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\include\tcn.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\include\tcn_api.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\include\tcn_version.h
+# End Source File
+# End Group
+# Begin Group "Platform Files"
+
+# PROP Default_Filter ""
+# Begin Source File
+
+SOURCE=.\os\win32\ntpipe.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\os\win32\registry.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\os\win32\system.c
+# End Source File
+# End Group
+# Begin Source File
+
+SOURCE=.\os\win32\libtcnative.rc
+# End Source File
+# End Target
+# End Project
diff --git a/jni/native/libtcnative.dsw b/jni/native/libtcnative.dsw
new file mode 100644
index 0000000..042257e
--- /dev/null
+++ b/jni/native/libtcnative.dsw
@@ -0,0 +1,71 @@
+Microsoft Developer Studio Workspace File, Format Version 6.00
+# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!
+
+###############################################################################
+
+Project: "apr"=..\apr\apr.dsp - Package Owner=<4>
+
+Package=<5>
+{{{
+}}}
+
+Package=<4>
+{{{
+}}}
+
+###############################################################################
+
+Project: "libapr"=..\apr\libapr.dsp - Package Owner=<4>
+
+Package=<5>
+{{{
+}}}
+
+Package=<4>
+{{{
+}}}
+
+###############################################################################
+
+Project: "libtcnative"=.\libtcnative.dsp - Package Owner=<4>
+
+Package=<5>
+{{{
+}}}
+
+Package=<4>
+{{{
+ Begin Project Dependency
+ Project_Dep_Name libapr
+ End Project Dependency
+}}}
+
+###############################################################################
+
+Project: "tcnative"=.\tcnative.dsp - Package Owner=<4>
+
+Package=<5>
+{{{
+}}}
+
+Package=<4>
+{{{
+ Begin Project Dependency
+ Project_Dep_Name apr
+ End Project Dependency
+}}}
+
+###############################################################################
+
+Global:
+
+Package=<5>
+{{{
+}}}
+
+Package=<3>
+{{{
+}}}
+
+###############################################################################
+
diff --git a/jni/native/os/netware/system.c b/jni/native/os/netware/system.c
new file mode 100644
index 0000000..31d835e
--- /dev/null
+++ b/jni/native/os/netware/system.c
@@ -0,0 +1,45 @@
+/* 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: system.c 1442587 2013-02-05 13:49:48Z rjung $
+ */
+
+#include "apr.h"
+#include "apr_pools.h"
+#include "apr_network_io.h"
+#include "apr_poll.h"
+
+#include "tcn.h"
+
+TCN_IMPLEMENT_CALL(jboolean, OS, is)(TCN_STDARGS, jint type)
+{
+ UNREFERENCED_STDARGS;
+ if (type == 2)
+ return JNI_TRUE;
+ else
+ return JNI_FALSE;
+}
+
+TCN_IMPLEMENT_CALL(jint, OS, info)(TCN_STDARGS,
+ jlongArray inf)
+{
+ UNREFERENCED_STDARGS;
+ UNREFERENCED(inf);
+ return APR_ENOTIMPL;
+}
diff --git a/jni/native/os/unix/system.c b/jni/native/os/unix/system.c
new file mode 100644
index 0000000..c57bd3e
--- /dev/null
+++ b/jni/native/os/unix/system.c
@@ -0,0 +1,446 @@
+/* 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: system.c 1445974 2013-02-13 23:11:53Z rjung $
+ */
+
+#include "apr.h"
+#include "apr_pools.h"
+#include "apr_network_io.h"
+#include "apr_poll.h"
+
+#include "tcn.h"
+#if defined(__linux__)
+#include <sys/sysinfo.h>
+#elif defined(sun)
+#include <unistd.h>
+#include <sys/swap.h>
+#include <procfs.h>
+#include <kstat.h>
+#include <sys/sysinfo.h>
+#endif
+
+#if defined(DARWIN)
+#include <mach/mach_init.h>
+#include <mach/mach_host.h>
+#include <mach/host_info.h>
+#include <sys/sysctl.h>
+#include <sys/stat.h>
+#endif
+
+#include <syslog.h>
+#include <stdarg.h>
+
+#ifndef LOG_WARN
+#define LOG_WARN LOG_WARNING
+#endif
+
+#if defined(sun)
+#define MAX_PROC_PATH_LEN 64
+#define MAX_CPUS 512
+#define PSINFO_T_SZ sizeof(psinfo_t)
+#define PRUSAGE_T_SZ sizeof(prusage_t)
+
+static int proc_open(const char *type)
+{
+ char proc_path[MAX_PROC_PATH_LEN+1];
+
+ sprintf(proc_path, "/proc/self/%s", type);
+ return open(proc_path, O_RDONLY);
+}
+
+static int proc_read(void *buf, const size_t size, int filedes)
+{
+ ssize_t bytes;
+
+ if (filedes >= 0) {
+ bytes = pread(filedes, buf, size, 0);
+ if (bytes != size)
+ return -1;
+ else
+ return 0;
+ }
+ else
+ return -1;
+}
+
+#endif
+
+TCN_IMPLEMENT_CALL(jboolean, OS, is)(TCN_STDARGS, jint type)
+{
+ UNREFERENCED_STDARGS;
+ if (type == 1)
+ return JNI_TRUE;
+#if defined(__linux__)
+ else if (type == 5)
+ return JNI_TRUE;
+#endif
+#if defined(sun)
+ else if (type == 6)
+ return JNI_TRUE;
+#endif
+#if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__)
+ else if (type == 7)
+ return JNI_TRUE;
+#endif
+#if defined(__APPLE__) || defined(DARWIN)
+ else if (type == 8)
+ return JNI_TRUE;
+#endif
+ else
+ return JNI_FALSE;
+}
+
+TCN_IMPLEMENT_CALL(jint, OS, info)(TCN_STDARGS,
+ jlongArray inf)
+{
+ jint rv;
+ int i;
+ jsize ilen = (*e)->GetArrayLength(e, inf);
+ jlong *pvals = (*e)->GetLongArrayElements(e, inf, NULL);
+
+ UNREFERENCED(o);
+ if (ilen < 16) {
+ return APR_EINVAL;
+ }
+ for (i = 0; i < 16; i++)
+ pvals[i] = 0;
+#if defined(__linux__)
+ {
+ struct sysinfo info;
+ if (sysinfo(&info))
+ rv = apr_get_os_error();
+ else {
+ static char buf[1024];
+ unsigned long user = 0;
+ unsigned long system = 0;
+ long idle = 0;
+ long long starttime = 0;
+ int fd;
+ int len;
+ long sys_clk_tck = sysconf(_SC_CLK_TCK); /* number of system ticks per second */
+
+ pvals[0] = (jlong)(info.totalram * info.mem_unit);
+ pvals[1] = (jlong)(info.freeram * info.mem_unit);
+ pvals[2] = (jlong)(info.totalswap * info.mem_unit);
+ pvals[3] = (jlong)(info.freeswap * info.mem_unit);
+ pvals[4] = (jlong)(info.sharedram * info.mem_unit);
+ pvals[5] = (jlong)(info.bufferram * info.mem_unit);
+ pvals[6] = (jlong)(100 - (info.freeram * 100 / info.totalram));
+
+ if (sys_clk_tck >= 0) {
+ /* Get total CPU times from /proc/stat */
+ /* Example for the first line: cpu 2095497 8176 3280198 908667841 1543576 28867 375399 0 0 */
+ /* According to the man pages, the numbers are given in units of USER_HZ:
+ * user mode, user mode with low priority (nice), system mode, and the idle task.
+ * Additional values can be ignored. */
+ fd = open("/proc/stat", O_RDONLY);
+ if (fd != -1) {
+ len = read(fd, buf, sizeof buf - 1);
+ if (len > 0) {
+ buf[len] = '\0';
+ if (sscanf(buf, "cpu %lu %*d %lu %ld", &user, &system, &idle) == 3) {
+ pvals[7] = (jlong)(idle * 1000 / sys_clk_tck * 1000); /* Idle Time in microseconds */
+ pvals[8] = (jlong)(system * 1000 / sys_clk_tck * 1000); /* Kernel Time in microseconds */
+ pvals[9] = (jlong)(user * 1000 / sys_clk_tck * 1000); /* User Time in microseconds */
+ }
+ }
+ close(fd);
+ }
+ /* Get process CPU times from /proc/self/stat */
+ /* Example for the first line:
+ * 6309 (csh) S 6308 6309 6309 34816 7124 4202496 15119 252261 1 30 21 58 1537 1447 20 0 1 0 916031966 ... */
+ /* Parsing it according to man -s 5 proci:
+ * pid %d, comm %s, state %c, ppid %d pgrp %d, session %d, tty_nr %d, tpgid %d, flags %u,
+ * minflt %lu, cminflt %lu, majflt %lu, cmajflt %lu,
+ * utime %lu (!), stime %lu (!), cutime %ld (!), cstime %ld (!),
+ * priority %ld, nice %ld, num_threads %ld, itrealvalue %ld,
+ * starttime %llu (!) */
+ fd = open("/proc/self/stat", O_RDONLY);
+ if (fd != -1) {
+ len = read(fd, buf, sizeof buf - 1);
+ if (len > 0) {
+ buf[len] = '\0';
+ if (sscanf(buf, "%*d %*s %*c %*d %*d %*d %*d %*d %*u"
+ " %*u %*u %*u %*u"
+ " %lu %lu %*d %*d"
+ " %*d %*d %*d %*d"
+ "%llu", &user, &system, &starttime) == 3) {
+ pvals[10] = (jlong)(apr_time_now() - apr_time_make(info.uptime - starttime / sys_clk_tck, 0)); /* Process creation time (apr_time_t) */
+ pvals[11] = (jlong)(system * 1000 / sys_clk_tck * 1000); /* Process System Time in microseconds */
+ pvals[12] = (jlong)(user * 1000 / sys_clk_tck * 1000); /* Process User Time in microseconds */
+ }
+ }
+ close(fd);
+ }
+ }
+
+ rv = APR_SUCCESS;
+ }
+ }
+#elif defined(sun)
+ {
+ /* static variables with basic procfs info */
+ static long creation = 0; /* unix timestamp of process creation */
+ static int psinf_fd = 0; /* file descriptor for the psinfo procfs file */
+ static int prusg_fd = 0; /* file descriptor for the usage procfs file */
+ static size_t rss = 0; /* maximum of resident set size from previous calls */
+ /* static variables with basic kstat info */
+ static kstat_ctl_t *kstat_ctl = NULL; /* kstat control object, only initialized once */
+ static kstat_t *kstat_cpu[MAX_CPUS]; /* array of kstat objects for per cpu statistics */
+ static int cpu_count = 0; /* number of cpu structures found in kstat */
+ static kid_t kid = 0; /* kstat ID, for which the kstat_ctl holds the correct chain */
+ /* non-static variables - general use */
+ int res = 0; /* general result state */
+ /* non-static variables - sysinfo/swapctl use */
+ long ret_sysconf; /* value returned from sysconf call */
+ long tck_dividend; /* factor used by transforming tick numbers to microseconds */
+ long tck_divisor; /* divisor used by transforming tick numbers to microseconds */
+ long sys_pagesize = sysconf(_SC_PAGESIZE); /* size of a system memory page in bytes */
+ long sys_clk_tck = sysconf(_SC_CLK_TCK); /* number of system ticks per second */
+ struct anoninfo info; /* structure for information about sizes in anonymous memory system */
+ /* non-static variables - procfs use */
+ psinfo_t psinf; /* psinfo structure from procfs */
+ prusage_t prusg; /* usage structure from procfs */
+ size_t new_rss = 0; /* resident set size read from procfs */
+ time_t now; /* time needed for calculating process creation time */
+ /* non-static variables - kstat use */
+ kstat_t *kstat = NULL; /* kstat working pointer */
+ cpu_sysinfo_t cpu; /* cpu sysinfo working pointer */
+ kid_t new_kid = 0; /* kstat ID returned from chain update */
+ int new_kstat = 0; /* flag indicating, if kstat structure has changed since last call */
+
+ rv = APR_SUCCESS;
+
+ if (sys_pagesize <= 0) {
+ rv = apr_get_os_error();
+ }
+ else {
+ ret_sysconf = sysconf(_SC_PHYS_PAGES);
+ if (ret_sysconf >= 0) {
+ pvals[0] = (jlong)((jlong)sys_pagesize * ret_sysconf);
+ }
+ else {
+ rv = apr_get_os_error();
+ }
+ ret_sysconf = sysconf(_SC_AVPHYS_PAGES);
+ if (ret_sysconf >= 0) {
+ pvals[1] = (jlong)((jlong)sys_pagesize * ret_sysconf);
+ }
+ else {
+ rv = apr_get_os_error();
+ }
+ res=swapctl(SC_AINFO, &info);
+ if (res >= 0) {
+ pvals[2] = (jlong)((jlong)sys_pagesize * info.ani_max);
+ pvals[3] = (jlong)((jlong)sys_pagesize * info.ani_free);
+ pvals[6] = (jlong)(100 - (jlong)info.ani_free * 100 / info.ani_max);
+ }
+ else {
+ rv = apr_get_os_error();
+ }
+ }
+
+ if (psinf_fd == 0) {
+ psinf_fd = proc_open("psinfo");
+ }
+ res = proc_read(&psinf, PSINFO_T_SZ, psinf_fd);
+ if (res >= 0) {
+ new_rss = psinf.pr_rssize*1024;
+ pvals[13] = (jlong)(new_rss);
+ if (new_rss > rss) {
+ rss = new_rss;
+ }
+ pvals[14] = (jlong)(rss);
+ }
+ else {
+ psinf_fd = 0;
+ rv = apr_get_os_error();
+ }
+ if (prusg_fd == 0) {
+ prusg_fd = proc_open("usage");
+ }
+ res = proc_read(&prusg, PRUSAGE_T_SZ, prusg_fd);
+ if (res >= 0) {
+ if (creation <= 0) {
+ time(&now);
+ creation = (long)(now - (prusg.pr_tstamp.tv_sec -
+ prusg.pr_create.tv_sec));
+ }
+ pvals[10] = (jlong)(creation * 1000000L);
+ pvals[11] = (jlong)((jlong)prusg.pr_stime.tv_sec * 1000000L +
+ (prusg.pr_stime.tv_nsec / 1000L));
+ pvals[12] = (jlong)((jlong)prusg.pr_utime.tv_sec * 1000000L +
+ (prusg.pr_utime.tv_nsec / 1000L));
+ pvals[15] = (jlong)(prusg.pr_majf);
+ }
+ else {
+ prusg_fd = 0;
+ rv = apr_get_os_error();
+ }
+
+ if (sys_clk_tck <= 0) {
+ rv = apr_get_os_error();
+ }
+ else {
+ tck_dividend = 1000000L;
+ tck_divisor = sys_clk_tck;
+ for (i = 0; i < 3; i++) {
+ if (tck_divisor % 2 == 0) {
+ tck_divisor = tck_divisor / 2;
+ tck_dividend = tck_dividend / 2;
+ }
+ if (tck_divisor % 5 == 0) {
+ tck_divisor = tck_divisor / 5;
+ tck_dividend = tck_dividend / 5;
+ }
+ }
+ if (kstat_ctl == NULL) {
+ kstat_ctl = kstat_open();
+ kid = kstat_ctl->kc_chain_id;
+ new_kstat = 1;
+ } else {
+ new_kid = kstat_chain_update(kstat_ctl);
+ if (new_kid < 0) {
+ res=kstat_close(kstat_ctl);
+ kstat_ctl = kstat_open();
+ kid = kstat_ctl->kc_chain_id;
+ new_kstat = 1;
+ } else if (new_kid > 0 && kid != new_kid) {
+ kid = new_kid;
+ new_kstat = 1;
+ }
+ }
+ if (new_kstat) {
+ cpu_count = 0;
+ for (kstat = kstat_ctl->kc_chain; kstat; kstat = kstat->ks_next) {
+ if (strncmp(kstat->ks_name, "cpu_stat", 8) == 0) {
+ kstat_cpu[cpu_count++]=kstat;
+ }
+ }
+ }
+ for (i = 0; i < cpu_count; i++) {
+ new_kid = kstat_read(kstat_ctl, kstat_cpu[i], NULL);
+ if (new_kid >= 0) {
+ cpu = ((cpu_stat_t *)kstat_cpu[i]->ks_data)->cpu_sysinfo;
+ if ( tck_divisor == 1 ) {
+ pvals[7] += (jlong)(((jlong)cpu.cpu[CPU_IDLE]) * tck_dividend);
+ pvals[7] += (jlong)(((jlong)cpu.cpu[CPU_WAIT]) * tck_dividend);
+ pvals[8] += (jlong)(((jlong)cpu.cpu[CPU_KERNEL]) * tck_dividend);
+ pvals[9] += (jlong)(((jlong)cpu.cpu[CPU_USER]) * tck_dividend);
+ } else {
+ pvals[7] += (jlong)(((jlong)cpu.cpu[CPU_IDLE]) * tck_dividend / tck_divisor);
+ pvals[7] += (jlong)(((jlong)cpu.cpu[CPU_WAIT]) * tck_dividend / tck_divisor);
+ pvals[8] += (jlong)(((jlong)cpu.cpu[CPU_KERNEL]) * tck_dividend / tck_divisor);
+ pvals[9] += (jlong)(((jlong)cpu.cpu[CPU_USER]) * tck_dividend / tck_divisor);
+ }
+ }
+ }
+ }
+
+ /*
+ * The next two are not implemented yet for Solaris
+ * inf[4] - Amount of shared memory
+ * inf[5] - Memory used by buffers
+ *
+ */
+ }
+
+#elif defined(DARWIN)
+
+ uint64_t mem_total;
+ size_t len = sizeof(mem_total);
+
+ vm_statistics_data_t vm_info;
+ mach_msg_type_number_t info_count = HOST_VM_INFO_COUNT;
+
+ sysctlbyname("hw.memsize", &mem_total, &len, NULL, 0);
+ pvals[0] = (jlong)mem_total;
+
+ host_statistics(mach_host_self (), HOST_VM_INFO, (host_info_t)&vm_info, &info_count);
+ pvals[1] = (jlong)(((double)vm_info.free_count)*vm_page_size);
+ pvals[6] = (jlong)(100 - (pvals[1] * 100 / mem_total));
+ rv = APR_SUCCESS;
+
+/* DARWIN */
+#else
+ rv = APR_ENOTIMPL;
+#endif
+ (*e)->ReleaseLongArrayElements(e, inf, pvals, 0);
+ return rv;
+}
+
+#define LOG_MSG_DOMAIN "Native"
+
+
+TCN_IMPLEMENT_CALL(jstring, OS, expand)(TCN_STDARGS, jstring val)
+{
+ jstring str;
+ TCN_ALLOC_CSTRING(val);
+
+ UNREFERENCED(o);
+
+ /* TODO: Make ${ENVAR} expansion */
+ str = (*e)->NewStringUTF(e, J2S(val));
+
+ TCN_FREE_CSTRING(val);
+ return str;
+}
+
+TCN_IMPLEMENT_CALL(void, OS, sysloginit)(TCN_STDARGS, jstring domain)
+{
+ const char *d;
+ TCN_ALLOC_CSTRING(domain);
+
+ UNREFERENCED(o);
+ if ((d = J2S(domain)) == NULL)
+ d = LOG_MSG_DOMAIN;
+
+ openlog(d, LOG_CONS | LOG_PID, LOG_LOCAL0);
+ TCN_FREE_CSTRING(domain);
+}
+
+TCN_IMPLEMENT_CALL(void, OS, syslog)(TCN_STDARGS, jint level,
+ jstring msg)
+{
+ TCN_ALLOC_CSTRING(msg);
+ int id = LOG_DEBUG;
+ UNREFERENCED(o);
+
+ switch (level) {
+ case TCN_LOG_EMERG:
+ id = LOG_EMERG;
+ break;
+ case TCN_LOG_ERROR:
+ id = LOG_ERR;
+ break;
+ case TCN_LOG_NOTICE:
+ id = LOG_NOTICE;
+ break;
+ case TCN_LOG_WARN:
+ id = LOG_WARN;
+ break;
+ case TCN_LOG_INFO:
+ id = LOG_INFO;
+ break;
+ }
+ syslog (id, "%s", J2S(msg));
+
+ TCN_FREE_CSTRING(msg);
+}
diff --git a/jni/native/os/unix/uxpipe.c b/jni/native/os/unix/uxpipe.c
new file mode 100644
index 0000000..065e426
--- /dev/null
+++ b/jni/native/os/unix/uxpipe.c
@@ -0,0 +1,355 @@
+/* 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.
+ */
+
+/** UNIX AF_LOCAL network wrapper
+ *
+ * @author Mladen Turk
+ * @version $Id: uxpipe.c 1442587 2013-02-05 13:49:48Z rjung $
+ */
+
+
+#include "tcn.h"
+#include "apr_thread_mutex.h"
+#include "apr_poll.h"
+
+/* ### should be tossed in favor of APR */
+#include <sys/stat.h>
+#include <sys/un.h> /* for sockaddr_un */
+
+#ifdef TCN_DO_STATISTICS
+#include "apr_atomic.h"
+
+static volatile apr_uint32_t uxp_created = 0;
+static volatile apr_uint32_t uxp_closed = 0;
+static volatile apr_uint32_t uxp_cleared = 0;
+static volatile apr_uint32_t uxp_accepted = 0;
+
+void uxp_network_dump_statistics()
+{
+ fprintf(stderr, "NT Network Statistics ..\n");
+ fprintf(stderr, "Sockets created : %d\n", uxp_created);
+ fprintf(stderr, "Sockets accepted : %d\n", uxp_accepted);
+ fprintf(stderr, "Sockets closed : %d\n", uxp_closed);
+ fprintf(stderr, "Sockets cleared : %d\n", uxp_cleared);
+}
+
+#endif
+
+#define DEFNAME "/var/run/tomcatnativesock"
+#define DEFNAME_FMT "/var/run/tomcatnativesock%08x%08x"
+#define DEFSIZE 8192
+#define DEFTIMEOUT 60000
+
+#define TCN_UXP_UNKNOWN 0
+#define TCN_UXP_CLIENT 1
+#define TCN_UXP_ACCEPTED 2
+#define TCN_UXP_SERVER 3
+
+#define TCN_UNIX_MAXPATH 1024
+typedef struct {
+ apr_pool_t *pool;
+ apr_socket_t *sock; /* APR socket */
+ int sd;
+ struct sockaddr_un uxaddr;
+ int timeout;
+ int mode; /* Client or server mode */
+ char name[TCN_UNIX_MAXPATH+1];
+} tcn_uxp_conn_t;
+
+static apr_status_t APR_THREAD_FUNC
+uxp_socket_timeout_set(apr_socket_t *sock, apr_interval_time_t t)
+{
+ tcn_uxp_conn_t *con = (tcn_uxp_conn_t *)sock;
+ if (t < 0)
+ con->timeout = -1;
+ else
+ con->timeout = (int)(apr_time_as_msec(t));
+ return APR_SUCCESS;
+}
+
+static apr_status_t APR_THREAD_FUNC
+uxp_socket_timeout_get(apr_socket_t *sock, apr_interval_time_t *t)
+{
+ tcn_uxp_conn_t *con = (tcn_uxp_conn_t*)sock;
+ if (con->timeout < 0)
+ *t = -1;
+ else
+ *t = con->timeout * 1000;
+ return APR_SUCCESS;
+}
+
+static APR_INLINE apr_status_t APR_THREAD_FUNC
+uxp_socket_opt_set(apr_socket_t *sock, apr_int32_t opt, apr_int32_t on)
+{
+ tcn_uxp_conn_t *con = (tcn_uxp_conn_t *)sock;
+ return apr_socket_opt_set(con->sock, opt, on);
+}
+
+static APR_INLINE apr_status_t APR_THREAD_FUNC
+uxp_socket_opt_get(apr_socket_t *sock, apr_int32_t opt, apr_int32_t *on)
+{
+ tcn_uxp_conn_t *con = (tcn_uxp_conn_t *)sock;
+ return apr_socket_opt_get(con->sock, opt, on);
+}
+
+static apr_status_t uxp_cleanup(void *data)
+{
+ tcn_uxp_conn_t *con = (tcn_uxp_conn_t *)data;
+
+ if (con) {
+ if (con->sock) {
+ apr_socket_close(con->sock);
+ con->sock = NULL;
+ }
+ if (con->mode == TCN_UXP_SERVER) {
+ unlink(con->name);
+ con->mode = TCN_UXP_UNKNOWN;
+ }
+ }
+
+#ifdef TCN_DO_STATISTICS
+ apr_atomic_inc32(&uxp_cleared);
+#endif
+ return APR_SUCCESS;
+}
+
+static apr_status_t APR_THREAD_FUNC
+uxp_socket_shutdown(apr_socket_t *sock, apr_shutdown_how_e how)
+{
+ tcn_uxp_conn_t *con = (tcn_uxp_conn_t *)sock;
+ return apr_socket_shutdown(con->sock, how);
+}
+
+static apr_status_t APR_THREAD_FUNC
+uxp_socket_close(apr_socket_t *sock)
+{
+#ifdef TCN_DO_STATISTICS
+ apr_atomic_inc32(&uxp_closed);
+#endif
+ return uxp_cleanup(sock);
+}
+
+static apr_status_t APR_THREAD_FUNC
+uxp_socket_recv(apr_socket_t *sock, char *buf, apr_size_t *len)
+{
+ tcn_uxp_conn_t *con = (tcn_uxp_conn_t *)sock;
+ return apr_socket_recv(con->sock, buf, len);
+}
+
+
+static apr_status_t APR_THREAD_FUNC
+uxp_socket_send(apr_socket_t *sock, const char *buf,
+ apr_size_t *len)
+{
+ tcn_uxp_conn_t *con = (tcn_uxp_conn_t *)sock;
+ return apr_socket_send(con->sock, buf, len);
+}
+
+static apr_status_t APR_THREAD_FUNC
+uxp_socket_sendv(apr_socket_t *sock,
+ const struct iovec *vec,
+ apr_int32_t nvec, apr_size_t *len)
+{
+ tcn_uxp_conn_t *con = (tcn_uxp_conn_t *)sock;
+ return apr_socket_sendv(con->sock, vec, nvec, len);
+}
+
+static apr_status_t uxp_socket_cleanup(void *data)
+{
+ tcn_socket_t *s = (tcn_socket_t *)data;
+
+ if (s->net->cleanup) {
+ (*s->net->cleanup)(s->opaque);
+ s->net->cleanup = NULL;
+ }
+#ifdef TCN_DO_STATISTICS
+ apr_atomic_inc32(&uxp_cleared);
+#endif
+ return APR_SUCCESS;
+}
+
+static tcn_nlayer_t uxp_socket_layer = {
+ TCN_SOCKET_UNIX,
+ uxp_cleanup,
+ uxp_socket_close,
+ uxp_socket_shutdown,
+ uxp_socket_opt_get,
+ uxp_socket_opt_set,
+ uxp_socket_timeout_get,
+ uxp_socket_timeout_set,
+ uxp_socket_send,
+ uxp_socket_sendv,
+ uxp_socket_recv
+};
+
+TCN_IMPLEMENT_CALL(jlong, Local, create)(TCN_STDARGS, jstring name,
+ jlong pool)
+{
+ apr_pool_t *p = J2P(pool, apr_pool_t *);
+ tcn_socket_t *s = NULL;
+ tcn_uxp_conn_t *con = NULL;
+ int sd;
+ TCN_ALLOC_CSTRING(name);
+
+ UNREFERENCED(o);
+ TCN_ASSERT(pool != 0);
+
+ if ((sd = socket(AF_UNIX, SOCK_STREAM, 0)) < 0) {
+ tcn_ThrowAPRException(e, apr_get_netos_error());
+ return 0;
+ }
+#ifdef TCN_DO_STATISTICS
+ uxp_created++;
+#endif
+ con = (tcn_uxp_conn_t *)apr_pcalloc(p, sizeof(tcn_uxp_conn_t));
+ con->pool = p;
+ con->mode = TCN_UXP_UNKNOWN;
+ con->timeout = DEFTIMEOUT;
+ con->sd = sd;
+ con->uxaddr.sun_family = AF_UNIX;
+ if (J2S(name)) {
+ strcpy(con->uxaddr.sun_path, J2S(name));
+ TCN_FREE_CSTRING(name);
+ }
+ else
+ strcpy(con->uxaddr.sun_path, DEFNAME);
+ s = (tcn_socket_t *)apr_pcalloc(p, sizeof(tcn_socket_t));
+ s->pool = p;
+ s->net = &uxp_socket_layer;
+ s->opaque = con;
+ apr_pool_cleanup_register(p, (const void *)s,
+ uxp_socket_cleanup,
+ apr_pool_cleanup_null);
+
+ apr_os_sock_put(&(con->sock), &(con->sd), p);
+
+ return P2J(s);
+
+}
+
+TCN_IMPLEMENT_CALL(jint, Local, bind)(TCN_STDARGS, jlong sock,
+ jlong sa)
+{
+ tcn_socket_t *s = J2P(sock, tcn_socket_t *);
+ UNREFERENCED_STDARGS;
+ UNREFERENCED(sa);
+ TCN_ASSERT(sock != 0);
+ if (s->net->type == TCN_SOCKET_UNIX) {
+ int rc;
+ tcn_uxp_conn_t *c = (tcn_uxp_conn_t *)s->opaque;
+ c->mode = TCN_UXP_SERVER;
+ rc = bind(c->sd, (struct sockaddr *)&(c->uxaddr), sizeof(c->uxaddr));
+ if (rc < 0)
+ return errno;
+ else
+ return APR_SUCCESS;
+ }
+ else
+ return APR_EINVAL;
+}
+
+TCN_IMPLEMENT_CALL(jint, Local, listen)(TCN_STDARGS, jlong sock,
+ jint backlog)
+{
+ tcn_socket_t *s = J2P(sock, tcn_socket_t *);
+ UNREFERENCED_STDARGS;
+
+ TCN_ASSERT(sock != 0);
+ if (s->net->type == TCN_SOCKET_UNIX) {
+ tcn_uxp_conn_t *c = (tcn_uxp_conn_t *)s->opaque;
+ c->mode = TCN_UXP_SERVER;
+ return apr_socket_listen(c->sock, (apr_int32_t)backlog);
+ }
+ else
+ return APR_EINVAL;
+}
+
+TCN_IMPLEMENT_CALL(jlong, Local, accept)(TCN_STDARGS, jlong sock)
+{
+ tcn_socket_t *s = J2P(sock, tcn_socket_t *);
+ apr_pool_t *p = NULL;
+ tcn_socket_t *a = NULL;
+ tcn_uxp_conn_t *con = NULL;
+
+ UNREFERENCED(o);
+ TCN_ASSERT(sock != 0);
+
+ TCN_THROW_IF_ERR(apr_pool_create(&p, s->pool), p);
+ if (s->net->type == TCN_SOCKET_UNIX) {
+ apr_socklen_t len;
+ tcn_uxp_conn_t *c = (tcn_uxp_conn_t *)s->opaque;
+ con = (tcn_uxp_conn_t *)apr_pcalloc(p, sizeof(tcn_uxp_conn_t));
+ con->pool = p;
+ con->mode = TCN_UXP_ACCEPTED;
+ con->timeout = c->timeout;
+ len = sizeof(c->uxaddr);
+ /* Block until a client connects */
+ con->sd = accept(c->sd, (struct sockaddr *)&(con->uxaddr), &len);
+ if (con->sd < 0) {
+ tcn_ThrowAPRException(e, apr_get_os_error());
+ goto cleanup;
+ }
+ }
+ else {
+ tcn_ThrowAPRException(e, APR_ENOTIMPL);
+ goto cleanup;
+ }
+ if (con) {
+#ifdef TCN_DO_STATISTICS
+ apr_atomic_inc32(&uxp_accepted);
+#endif
+ a = (tcn_socket_t *)apr_pcalloc(p, sizeof(tcn_socket_t));
+ a->pool = p;
+ a->net = &uxp_socket_layer;
+ a->opaque = con;
+ apr_pool_cleanup_register(p, (const void *)a,
+ uxp_socket_cleanup,
+ apr_pool_cleanup_null);
+ apr_os_sock_put(&(con->sock), &(con->sd), p);
+ }
+ return P2J(a);
+cleanup:
+ if (p)
+ apr_pool_destroy(p);
+ return 0;
+}
+
+TCN_IMPLEMENT_CALL(jint, Local, connect)(TCN_STDARGS, jlong sock,
+ jlong sa)
+{
+ tcn_socket_t *s = J2P(sock, tcn_socket_t *);
+ tcn_uxp_conn_t *con = NULL;
+ int rc;
+
+ UNREFERENCED(o);
+ UNREFERENCED(sa);
+ TCN_ASSERT(sock != 0);
+ if (s->net->type != TCN_SOCKET_UNIX)
+ return APR_ENOTSOCK;
+ con = (tcn_uxp_conn_t *)s->opaque;
+ if (con->mode != TCN_UXP_UNKNOWN)
+ return APR_EINVAL;
+ do {
+ rc = connect(con->sd, (const struct sockaddr *)&(con->uxaddr),
+ sizeof(con->uxaddr));
+ } while (rc == -1 && errno == EINTR);
+
+ if (rc == -1 && errno != EISCONN)
+ return errno;
+ con->mode = TCN_UXP_CLIENT;
+
+ return APR_SUCCESS;
+}
diff --git a/jni/native/os/win32/apache.ico b/jni/native/os/win32/apache.ico
new file mode 100644
index 0000000..bfb4f63
Binary files /dev/null and b/jni/native/os/win32/apache.ico differ
diff --git a/jni/native/os/win32/libtcnative.rc b/jni/native/os/win32/libtcnative.rc
new file mode 100644
index 0000000..2b9d60d
--- /dev/null
+++ b/jni/native/os/win32/libtcnative.rc
@@ -0,0 +1,71 @@
+#include <windows.h>
+
+LANGUAGE 0x9,0x1
+1 11 logmessages.bin
+
+#define TCN_COPYRIGHT "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."
+
+#define TCN_LICENSE "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\r\n\r\n" \
+ "http://www.apache.org/licenses/LICENSE-2.0\r\n\r\n" \
+ "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."
+
+#define TCN_VERSION "1.1.30"
+1000 ICON "apache.ico"
+
+1001 DIALOGEX 0, 0, 252, 51
+STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | DS_CENTER | WS_CAPTION
+CAPTION "Password prompt"
+FONT 8, "MS Shell Dlg", 0, 0, 0x0
+BEGIN
+ ICON 1000,-1,8,6,21,20
+ LTEXT "Some of your private key files are encrypted for security reasons.\nIn order to read them you have to provide the pass phrases.",
+ -1,29,5,220,19
+ LTEXT "Enter password:",-1,7,28,75,8
+ EDITTEXT 1002,67,27,174,12,ES_PASSWORD | ES_AUTOHSCROLL
+END
+
+1 VERSIONINFO
+ FILEVERSION 1,1,30,0
+ PRODUCTVERSION 1,1,30,0
+ FILEFLAGSMASK 0x3fL
+#ifdef _DEBUG
+ FILEFLAGS 0x1L
+#else
+ FILEFLAGS 0x0L
+#endif
+ FILEOS 0x40004L
+ FILETYPE 0x1L
+ FILESUBTYPE 0x0L
+BEGIN
+ BLOCK "StringFileInfo"
+ BEGIN
+ BLOCK "040904b0"
+ BEGIN
+ VALUE "Comments", TCN_LICENSE "\0"
+ VALUE "CompanyName", "Apache Software Foundation\0"
+ VALUE "FileDescription", "Tomcat Native Java Library\0"
+ VALUE "FileVersion", TCN_VERSION "\0"
+ VALUE "InternalName", "libtcnative-1\0"
+ VALUE "LegalCopyright", TCN_COPYRIGHT "\0"
+ VALUE "OriginalFilename", "libtcnative-1.dll\0"
+ VALUE "ProductName", "Tomcat Native Java Library\0"
+ VALUE "ProductVersion", TCN_VERSION "\0"
+ END
+ END
+ BLOCK "VarFileInfo"
+ BEGIN
+ VALUE "Translation", 0x409, 1200
+ END
+END
+
diff --git a/jni/native/os/win32/logmessages.bin b/jni/native/os/win32/logmessages.bin
new file mode 100644
index 0000000..44ce985
Binary files /dev/null and b/jni/native/os/win32/logmessages.bin differ
diff --git a/jni/native/os/win32/logmessages.mc b/jni/native/os/win32/logmessages.mc
new file mode 100644
index 0000000..68f86f6
--- /dev/null
+++ b/jni/native/os/win32/logmessages.mc
@@ -0,0 +1,41 @@
+MessageId=0x1
+Severity=Error
+SymbolicName=LOG_MSG_EMERG
+Language=English
+Emerg: %1
+.
+
+MessageId=0x2
+Severity=Error
+SymbolicName=LOG_MSG_ERROR
+Language=English
+Error: %1
+.
+
+MessageId=0x3
+Severity=Warning
+SymbolicName=LOG_MSG_NOTICE
+Language=English
+Notice: %1
+.
+
+MessageId=0x4
+Severity=Warning
+SymbolicName=LOG_MSG_WARN
+Language=English
+Warn: %1
+.
+
+MessageId=0x5
+Severity=Informational
+SymbolicName=LOG_MSG_INFO
+Language=English
+Info: %1
+.
+
+MessageId=0x6
+Severity=Success
+SymbolicName=LOG_MSG_DEBUG
+Language=English
+Debug: %1
+.
diff --git a/jni/native/os/win32/ntpipe.c b/jni/native/os/win32/ntpipe.c
new file mode 100644
index 0000000..07a742f
--- /dev/null
+++ b/jni/native/os/win32/ntpipe.c
@@ -0,0 +1,506 @@
+/* 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.
+ */
+
+/** NT Pipes network wrapper
+ *
+ * @author Mladen Turk
+ * @version $Id: ntpipe.c 1442587 2013-02-05 13:49:48Z rjung $
+ */
+
+
+#ifndef _WIN32_WINNT
+#define _WIN32_WINNT 0x0500
+#endif
+#define STRICT
+#include <winsock2.h>
+#include <mswsock.h>
+#include <ws2tcpip.h>
+#include <sddl.h>
+
+#include "tcn.h"
+#include "apr_thread_mutex.h"
+#include "apr_poll.h"
+
+#ifdef TCN_DO_STATISTICS
+#include "apr_atomic.h"
+
+static volatile apr_uint32_t ntp_created = 0;
+static volatile apr_uint32_t ntp_closed = 0;
+static volatile apr_uint32_t ntp_cleared = 0;
+static volatile apr_uint32_t ntp_accepted = 0;
+
+void ntp_network_dump_statistics()
+{
+ fprintf(stderr, "NT Network Statistics ..\n");
+ fprintf(stderr, "Sockets created : %d\n", ntp_created);
+ fprintf(stderr, "Sockets accepted : %d\n", ntp_accepted);
+ fprintf(stderr, "Sockets closed : %d\n", ntp_closed);
+ fprintf(stderr, "Sockets cleared : %d\n", ntp_cleared);
+}
+
+#endif
+
+#define DEFNAME "\\\\.\\PIPE\\TOMCATNATIVEPIPE"
+#define DEFNAME_FMT "\\\\.\\PIPE\\TOMCATNATIVEPIPE%08X%08X"
+#define DEFSIZE 8192
+#define DEFTIMEOUT 60000
+
+#define TCN_NTP_UNKNOWN 0
+#define TCN_NTP_CLIENT 1
+#define TCN_NTP_SERVER 2
+
+typedef struct {
+ apr_pool_t *pool;
+ apr_socket_t *sock; /* Dummy socket */
+ OVERLAPPED rd_o;
+ OVERLAPPED wr_o;
+ HANDLE h_pipe;
+ HANDLE rd_event;
+ HANDLE wr_event;
+ DWORD timeout;
+ int mode; /* Client or server mode */
+ int nmax;
+ DWORD sndbuf;
+ DWORD rcvbuf;
+ char name[MAX_PATH+1];
+ SECURITY_ATTRIBUTES sa;
+} tcn_ntp_conn_t;
+
+static const char *NTSD_STRING = "D:" /* Discretionary ACL */
+ "(D;OICI;GA;;;BG)" /* Deny access to Built-in Guests */
+ "(D;OICI;GA;;;AN)" /* Deny access to Anonymous Logon */
+ "(A;OICI;GRGWGX;;;AU)" /* Allow read/write/execute to Authenticated Users */
+ "(A;OICI;GA;;;BA)" /* Allow full control to Administrators */
+ "(A;OICI;GA;;;LS)" /* Allow full control to Local service account */
+ "(A;OICI;GA;;;SY)"; /* Allow full control to Local system */
+
+
+
+static apr_status_t APR_THREAD_FUNC
+ntp_socket_timeout_set(apr_socket_t *sock, apr_interval_time_t t)
+{
+ tcn_ntp_conn_t *con = (tcn_ntp_conn_t *)sock;
+ if (t < 0)
+ con->timeout = INFINITE;
+ else
+ con->timeout = (DWORD)(apr_time_as_msec(t));
+ return APR_SUCCESS;
+}
+
+static apr_status_t APR_THREAD_FUNC
+ntp_socket_timeout_get(apr_socket_t *sock, apr_interval_time_t *t)
+{
+ tcn_ntp_conn_t *con = (tcn_ntp_conn_t*)sock;
+ if (con->timeout == INFINITE)
+ *t = -1;
+ else
+ *t = con->timeout * 1000;
+ return APR_SUCCESS;
+}
+
+static APR_INLINE apr_status_t APR_THREAD_FUNC
+ntp_socket_opt_set(apr_socket_t *sock, apr_int32_t opt, apr_int32_t on)
+{
+ tcn_ntp_conn_t *con = (tcn_ntp_conn_t *)sock;
+ apr_status_t rv = APR_SUCCESS;
+ switch (opt) {
+ case APR_SO_SNDBUF:
+ con->sndbuf = (DWORD)on;
+ break;
+ case APR_SO_RCVBUF:
+ con->rcvbuf = (DWORD)on;
+ break;
+ default:
+ rv = APR_EINVAL;
+ break;
+ }
+ return rv;
+}
+
+static APR_INLINE apr_status_t APR_THREAD_FUNC
+ntp_socket_opt_get(apr_socket_t *sock, apr_int32_t opt, apr_int32_t *on)
+{
+ tcn_ntp_conn_t *con = (tcn_ntp_conn_t *)sock;
+ apr_status_t rv = APR_SUCCESS;
+ switch (opt) {
+ case APR_SO_SNDBUF:
+ *on = con->sndbuf;
+ break;
+ case APR_SO_RCVBUF:
+ *on = con->rcvbuf;
+ break;
+ default:
+ rv = APR_EINVAL;
+ break;
+ }
+ return rv;
+}
+
+static apr_status_t ntp_cleanup(void *data)
+{
+ tcn_ntp_conn_t *con = (tcn_ntp_conn_t *)data;
+
+ if (con) {
+ if (con->h_pipe) {
+ FlushFileBuffers(con->h_pipe);
+ CloseHandle(con->h_pipe);
+ con->h_pipe = NULL;
+ }
+ if (con->rd_event) {
+ CloseHandle(con->rd_event);
+ con->rd_event = NULL;
+ }
+ if (con->wr_event) {
+ CloseHandle(con->wr_event);
+ con->wr_event= NULL;
+ }
+ }
+
+#ifdef TCN_DO_STATISTICS
+ apr_atomic_inc32(&ntp_cleared);
+#endif
+ return APR_SUCCESS;
+}
+
+static apr_status_t APR_THREAD_FUNC
+ntp_socket_shutdown(apr_socket_t *sock, apr_shutdown_how_e how)
+{
+ UNREFERENCED(how);
+ return ntp_cleanup(sock);;
+}
+
+static apr_status_t APR_THREAD_FUNC
+ntp_socket_close(apr_socket_t *sock)
+{
+#ifdef TCN_DO_STATISTICS
+ apr_atomic_inc32(&ntp_closed);
+#endif
+ return ntp_cleanup(sock);;
+}
+
+static apr_status_t APR_THREAD_FUNC
+ntp_socket_recv(apr_socket_t *sock, char *buf, apr_size_t *len)
+{
+ tcn_ntp_conn_t *con = (tcn_ntp_conn_t *)sock;
+ DWORD readed;
+
+ if (!ReadFile(con->h_pipe, buf, (DWORD)*len, &readed, &con->rd_o)) {
+ DWORD err = GetLastError();
+ if (err == ERROR_IO_PENDING) {
+ DWORD r = WaitForSingleObject(con->rd_event, con->timeout);
+ if (r == WAIT_TIMEOUT)
+ return APR_TIMEUP;
+ else if (r != WAIT_OBJECT_0)
+ return APR_EOF;
+ }
+ else if (err == ERROR_BROKEN_PIPE || err == ERROR_NO_DATA) {
+ /* Server closed the pipe */
+ return APR_EOF;
+ }
+ GetOverlappedResult(con->h_pipe, &con->rd_o, &readed, FALSE);
+ }
+ *len = readed;
+ return APR_SUCCESS;
+}
+
+static apr_status_t APR_THREAD_FUNC
+ntp_socket_send(apr_socket_t *sock, const char *buf,
+ apr_size_t *len)
+{
+ tcn_ntp_conn_t *con = (tcn_ntp_conn_t *)sock;
+ DWORD written;
+
+ if (!WriteFile(con->h_pipe, buf, (DWORD)*len, &written, &con->wr_o)) {
+ DWORD err = GetLastError();
+ if (err == ERROR_IO_PENDING) {
+ DWORD r = WaitForSingleObject(con->wr_event, con->timeout);
+ if (r == WAIT_TIMEOUT)
+ return APR_TIMEUP;
+ else if (r != WAIT_OBJECT_0)
+ return APR_EOF;
+ }
+ else if (err == ERROR_BROKEN_PIPE || err == ERROR_NO_DATA) {
+ /* Server closed the pipe */
+ return APR_EOF;
+ }
+ GetOverlappedResult(con->h_pipe, &con->wr_o, &written, FALSE);
+ }
+ *len = written;
+ return APR_SUCCESS;
+}
+
+static apr_status_t APR_THREAD_FUNC
+ntp_socket_sendv(apr_socket_t *sock,
+ const struct iovec *vec,
+ apr_int32_t nvec, apr_size_t *len)
+{
+ tcn_ntp_conn_t *con = (tcn_ntp_conn_t *)sock;
+ apr_status_t rv;
+ apr_size_t written = 0;
+ apr_int32_t i;
+
+ for (i = 0; i < nvec; i++) {
+ apr_size_t rd = vec[i].iov_len;
+ if ((rv = ntp_socket_send((apr_socket_t *)con,
+ vec[i].iov_base, &rd)) != APR_SUCCESS) {
+ *len = written;
+ return rv;
+ }
+ written += rd;
+ }
+ *len = written;
+ return APR_SUCCESS;
+}
+
+static apr_status_t ntp_socket_cleanup(void *data)
+{
+ tcn_socket_t *s = (tcn_socket_t *)data;
+
+ if (s->net->cleanup) {
+ (*s->net->cleanup)(s->opaque);
+ s->net->cleanup = NULL;
+ }
+#ifdef TCN_DO_STATISTICS
+ apr_atomic_inc32(&ntp_cleared);
+#endif
+ return APR_SUCCESS;
+}
+
+static tcn_nlayer_t ntp_socket_layer = {
+ TCN_SOCKET_NTPIPE,
+ ntp_cleanup,
+ ntp_socket_close,
+ ntp_socket_shutdown,
+ ntp_socket_opt_get,
+ ntp_socket_opt_set,
+ ntp_socket_timeout_get,
+ ntp_socket_timeout_set,
+ ntp_socket_send,
+ ntp_socket_sendv,
+ ntp_socket_recv
+};
+
+static BOOL create_DACL(LPSECURITY_ATTRIBUTES psa)
+{
+
+ return ConvertStringSecurityDescriptorToSecurityDescriptor(
+ NTSD_STRING,
+ SDDL_REVISION_1,
+ &(psa->lpSecurityDescriptor),
+ NULL);
+}
+
+TCN_IMPLEMENT_CALL(jlong, Local, create)(TCN_STDARGS, jstring name,
+ jlong pool)
+{
+ apr_pool_t *p = J2P(pool, apr_pool_t *);
+ tcn_socket_t *s = NULL;
+ tcn_ntp_conn_t *con = NULL;
+ TCN_ALLOC_CSTRING(name);
+
+ UNREFERENCED(o);
+ TCN_ASSERT(pool != 0);
+
+#ifdef TCN_DO_STATISTICS
+ ntp_created++;
+#endif
+ con = (tcn_ntp_conn_t *)apr_pcalloc(p, sizeof(tcn_ntp_conn_t));
+ con->pool = p;
+ con->mode = TCN_NTP_UNKNOWN;
+ con->nmax = PIPE_UNLIMITED_INSTANCES;
+ con->timeout = DEFTIMEOUT;
+ con->sndbuf = DEFSIZE;
+ con->rcvbuf = DEFSIZE;
+ if (J2S(name)) {
+ strncpy(con->name, J2S(name), MAX_PATH);
+ con->name[MAX_PATH] = '\0';
+ TCN_FREE_CSTRING(name);
+ }
+ else
+ strcpy(con->name, DEFNAME);
+ con->sa.nLength = sizeof(con->sa);
+ con->sa.bInheritHandle = TRUE;
+ if (!create_DACL(&con->sa)) {
+ tcn_ThrowAPRException(e, apr_get_os_error());
+ return 0;
+ }
+
+ s = (tcn_socket_t *)apr_pcalloc(p, sizeof(tcn_socket_t));
+ s->pool = p;
+ s->net = &ntp_socket_layer;
+ s->opaque = con;
+ apr_pool_cleanup_register(p, (const void *)s,
+ ntp_socket_cleanup,
+ apr_pool_cleanup_null);
+
+ fflush(stderr);
+ return P2J(s);
+
+}
+
+TCN_IMPLEMENT_CALL(jint, Local, bind)(TCN_STDARGS, jlong sock,
+ jlong sa)
+{
+ tcn_socket_t *s = J2P(sock, tcn_socket_t *);
+ UNREFERENCED_STDARGS;
+ UNREFERENCED(sa);
+ TCN_ASSERT(sock != 0);
+ if (s->net->type == TCN_SOCKET_NTPIPE) {
+ tcn_ntp_conn_t *c = (tcn_ntp_conn_t *)s->opaque;
+ c->mode = TCN_NTP_SERVER;
+ return APR_SUCCESS;
+ }
+ else
+ return APR_EINVAL;
+}
+
+TCN_IMPLEMENT_CALL(jint, Local, listen)(TCN_STDARGS, jlong sock,
+ jint backlog)
+{
+ tcn_socket_t *s = J2P(sock, tcn_socket_t *);
+ UNREFERENCED_STDARGS;
+
+ TCN_ASSERT(sock != 0);
+ if (s->net->type == TCN_SOCKET_NTPIPE) {
+ tcn_ntp_conn_t *c = (tcn_ntp_conn_t *)s->opaque;
+ c->mode = TCN_NTP_SERVER;
+ if (backlog > 0)
+ c->nmax = backlog;
+ else
+ c->nmax = PIPE_UNLIMITED_INSTANCES;
+ return APR_SUCCESS;
+ }
+ else
+ return APR_EINVAL;
+}
+
+TCN_IMPLEMENT_CALL(jlong, Local, accept)(TCN_STDARGS, jlong sock)
+{
+ tcn_socket_t *s = J2P(sock, tcn_socket_t *);
+ apr_pool_t *p = NULL;
+ tcn_socket_t *a = NULL;
+ tcn_ntp_conn_t *con = NULL;
+
+ UNREFERENCED(o);
+ TCN_ASSERT(sock != 0);
+
+ TCN_THROW_IF_ERR(apr_pool_create(&p, s->pool), p);
+ if (s->net->type == TCN_SOCKET_NTPIPE) {
+ tcn_ntp_conn_t *c = (tcn_ntp_conn_t *)s->opaque;
+ con = (tcn_ntp_conn_t *)apr_pcalloc(p, sizeof(tcn_ntp_conn_t));
+ con->pool = p;
+ con->mode = TCN_NTP_SERVER;
+ con->nmax = c->nmax;
+ con->timeout = c->timeout;
+ strcpy(con->name, c->name);
+ con->h_pipe = CreateNamedPipe(con->name,
+ PIPE_ACCESS_DUPLEX | FILE_FLAG_OVERLAPPED,
+ PIPE_TYPE_BYTE | PIPE_READMODE_BYTE | PIPE_WAIT,
+ con->nmax,
+ con->sndbuf,
+ con->rcvbuf,
+ con->timeout,
+ &c->sa);
+ if (con->h_pipe == INVALID_HANDLE_VALUE) {
+ tcn_ThrowAPRException(e, apr_get_os_error());
+ goto cleanup;
+ }
+ /* Block until a client connects */
+ if (!ConnectNamedPipe(con->h_pipe, NULL)) {
+ DWORD err = GetLastError();
+ if (err != ERROR_PIPE_CONNECTED) {
+ CloseHandle(con->h_pipe);
+ tcn_ThrowAPRException(e, APR_FROM_OS_ERROR(err));
+ goto cleanup;
+ }
+ }
+ /* Create overlapped events */
+ con->rd_event = CreateEvent(NULL, TRUE, FALSE, NULL);
+ con->rd_o.hEvent = con->rd_event;
+ con->wr_event = CreateEvent(NULL, TRUE, FALSE, NULL);
+ con->wr_o.hEvent = con->wr_event;
+ }
+ else {
+ tcn_ThrowAPRException(e, APR_ENOTIMPL);
+ goto cleanup;
+ }
+ if (con) {
+#ifdef TCN_DO_STATISTICS
+ apr_atomic_inc32(&ntp_accepted);
+#endif
+ a = (tcn_socket_t *)apr_pcalloc(p, sizeof(tcn_socket_t));
+ a->pool = p;
+ a->net = &ntp_socket_layer;
+ a->opaque = con;
+ apr_pool_cleanup_register(p, (const void *)a,
+ ntp_socket_cleanup,
+ apr_pool_cleanup_null);
+ }
+ return P2J(a);
+cleanup:
+ if (p)
+ apr_pool_destroy(p);
+ return 0;
+}
+
+TCN_IMPLEMENT_CALL(jint, Local, connect)(TCN_STDARGS, jlong sock,
+ jlong sa)
+{
+ tcn_socket_t *s = J2P(sock, tcn_socket_t *);
+ apr_pool_t *p = NULL;
+ tcn_socket_t *a = NULL;
+ tcn_ntp_conn_t *con = NULL;
+
+ UNREFERENCED(o);
+ UNREFERENCED(sa);
+ TCN_ASSERT(sock != 0);
+ if (s->net->type != TCN_SOCKET_NTPIPE)
+ return APR_ENOTSOCK;
+ con = (tcn_ntp_conn_t *)s->opaque;
+ if (con->mode == TCN_NTP_SERVER)
+ return APR_EINVAL;
+ con->mode = TCN_NTP_CLIENT;
+
+ while (TRUE) {
+ con->h_pipe = CreateFile(con->name,
+ GENERIC_WRITE | GENERIC_READ,
+ FILE_SHARE_READ | FILE_SHARE_WRITE ,
+ NULL,
+ OPEN_EXISTING,
+ FILE_FLAG_OVERLAPPED,
+ NULL);
+ if (con->h_pipe != INVALID_HANDLE_VALUE)
+ break;
+ if (GetLastError() == ERROR_PIPE_BUSY) {
+ /* All pipe instances are busy, so wait for
+ * timeout value specified by the server process in
+ * the CreateNamedPipe function.
+ */
+ if (!WaitNamedPipe(con->name, NMPWAIT_USE_DEFAULT_WAIT))
+ return apr_get_os_error();
+ }
+ else
+ return apr_get_os_error();
+ }
+
+ /* Create overlapped events */
+ con->rd_event = CreateEvent(NULL, TRUE, FALSE, NULL);
+ con->rd_o.hEvent = con->rd_event;
+ con->wr_event = CreateEvent(NULL, TRUE, FALSE, NULL);
+ con->wr_o.hEvent = con->wr_event;
+
+ return APR_SUCCESS;
+}
diff --git a/jni/native/os/win32/registry.c b/jni/native/os/win32/registry.c
new file mode 100644
index 0000000..b031029
--- /dev/null
+++ b/jni/native/os/win32/registry.c
@@ -0,0 +1,792 @@
+/* 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: registry.c 1442587 2013-02-05 13:49:48Z rjung $
+ */
+
+#ifndef _WIN32_WINNT
+#define _WIN32_WINNT 0x0501
+#endif
+#include <winsock2.h>
+#include <mswsock.h>
+#include <ws2tcpip.h>
+#include <shlwapi.h>
+#include <tlhelp32.h>
+
+#include "apr.h"
+#include "apr_pools.h"
+#include "apr_arch_misc.h" /* for apr_os_level */
+#include "apr_arch_atime.h" /* for FileTimeToAprTime */
+
+#include "tcn.h"
+
+#define SAFE_CLOSE_KEY(k) \
+ if ((k) != NULL && (k) != INVALID_HANDLE_VALUE) { \
+ RegCloseKey((k)); \
+ (k) = NULL; \
+ }
+
+typedef struct {
+ apr_pool_t *pool;
+ HKEY root;
+ HKEY key;
+} tcn_nt_registry_t;
+
+
+#define TCN_HKEY_CLASSES_ROOT 1
+#define TCN_HKEY_CURRENT_CONFIG 2
+#define TCN_HKEY_CURRENT_USER 3
+#define TCN_HKEY_LOCAL_MACHINE 4
+#define TCN_HKEY_USERS 5
+
+static const struct {
+ HKEY k;
+} TCN_KEYS[] = {
+ INVALID_HANDLE_VALUE,
+ HKEY_CLASSES_ROOT,
+ HKEY_CURRENT_CONFIG,
+ HKEY_CURRENT_USER,
+ HKEY_LOCAL_MACHINE,
+ HKEY_USERS,
+ INVALID_HANDLE_VALUE
+};
+
+#define TCN_KEY_ALL_ACCESS 0x0001
+#define TCN_KEY_CREATE_LINK 0x0002
+#define TCN_KEY_CREATE_SUB_KEY 0x0004
+#define TCN_KEY_ENUMERATE_SUB_KEYS 0x0008
+#define TCN_KEY_EXECUTE 0x0010
+#define TCN_KEY_NOTIFY 0x0020
+#define TCN_KEY_QUERY_VALUE 0x0040
+#define TCN_KEY_READ 0x0080
+#define TCN_KEY_SET_VALUE 0x0100
+#define TCN_KEY_WOW64_64KEY 0x0200
+#define TCN_KEY_WOW64_32KEY 0x0400
+#define TCN_KEY_WRITE 0x0800
+
+#define TCN_REGSAM(s, x) \
+ s = 0; \
+ if (x & TCN_KEY_ALL_ACCESS) \
+ s |= KEY_ALL_ACCESS; \
+ if (x & TCN_KEY_CREATE_LINK) \
+ s |= KEY_CREATE_LINK; \
+ if (x & TCN_KEY_CREATE_SUB_KEY) \
+ s |= KEY_CREATE_SUB_KEY; \
+ if (x & TCN_KEY_ENUMERATE_SUB_KEYS) \
+ s |= KEY_ENUMERATE_SUB_KEYS; \
+ if (x & TCN_KEY_EXECUTE) \
+ s |= KEY_EXECUTE; \
+ if (x & TCN_KEY_NOTIFY) \
+ s |= KEY_NOTIFY; \
+ if (x & TCN_KEY_READ) \
+ s |= KEY_READ; \
+ if (x & TCN_KEY_SET_VALUE) \
+ s |= KEY_SET_VALUE; \
+ if (x & TCN_KEY_WOW64_64KEY) \
+ s |= KEY_WOW64_64KEY; \
+ if (x & TCN_KEY_WOW64_32KEY) \
+ s |= KEY_WOW64_32KEY; \
+ if (x & TCN_KEY_WRITE) \
+ s |= KEY_WRITE
+
+#define TCN_REG_BINARY 1
+#define TCN_REG_DWORD 2
+#define TCN_REG_EXPAND_SZ 3
+#define TCN_REG_MULTI_SZ 4
+#define TCN_REG_QWORD 5
+#define TCN_REG_SZ 6
+
+static const struct {
+ DWORD t;
+} TCN_REGTYPES[] = {
+ REG_NONE,
+ REG_BINARY,
+ REG_DWORD,
+ REG_EXPAND_SZ,
+ REG_MULTI_SZ,
+ REG_QWORD,
+ REG_SZ,
+ REG_NONE
+};
+
+static apr_status_t registry_cleanup(void *data)
+{
+ tcn_nt_registry_t *reg = (tcn_nt_registry_t *)data;
+
+ if (reg) {
+ SAFE_CLOSE_KEY(reg->key);
+ }
+ return APR_SUCCESS;
+}
+
+TCN_IMPLEMENT_CALL(jlong, Registry, create)(TCN_STDARGS, jint root, jstring name,
+ jint sam, jlong pool)
+{
+ apr_pool_t *p = J2P(pool, apr_pool_t *);
+ tcn_nt_registry_t *reg = NULL;
+ TCN_ALLOC_WSTRING(name);
+ HKEY key;
+ LONG rc;
+ REGSAM s;
+
+ UNREFERENCED(o);
+ TCN_ASSERT(pool != 0);
+
+ if (root < TCN_HKEY_CLASSES_ROOT || root > TCN_HKEY_USERS) {
+ tcn_ThrowException(e, "Invalid Registry Root Key");
+ goto cleanup;
+ }
+ if (sam < TCN_KEY_ALL_ACCESS || root > TCN_KEY_WRITE) {
+ tcn_ThrowException(e, "Invalid Registry Key Security");
+ goto cleanup;
+ }
+ reg = (tcn_nt_registry_t *)apr_palloc(p, sizeof(tcn_nt_registry_t));
+ reg->pool = p;
+ reg->root = TCN_KEYS[root].k;
+ reg->key = NULL;
+ TCN_INIT_WSTRING(name);
+ TCN_REGSAM(s, sam);
+ rc = RegCreateKeyExW(reg->root, J2W(name), 0, NULL, REG_OPTION_NON_VOLATILE,
+ s, NULL, &key, NULL);
+ if (rc != ERROR_SUCCESS) {
+ tcn_ThrowAPRException(e, APR_FROM_OS_ERROR(rc));
+ goto cleanup;
+ }
+ reg->key = key;
+ apr_pool_cleanup_register(p, (const void *)reg,
+ registry_cleanup,
+ apr_pool_cleanup_null);
+
+cleanup:
+ TCN_FREE_WSTRING(name);
+ return P2J(reg);
+}
+
+TCN_IMPLEMENT_CALL(jlong, Registry, open)(TCN_STDARGS, jint root, jstring name,
+ jint sam, jlong pool)
+{
+ apr_pool_t *p = J2P(pool, apr_pool_t *);
+ tcn_nt_registry_t *reg = NULL;
+ TCN_ALLOC_WSTRING(name);
+ HKEY key;
+ LONG rc;
+ REGSAM s;
+
+ UNREFERENCED(o);
+ TCN_ASSERT(pool != 0);
+
+ if (root < TCN_HKEY_CLASSES_ROOT || root > TCN_HKEY_USERS) {
+ tcn_ThrowException(e, "Invalid Registry Root Key");
+ goto cleanup;
+ }
+ if (sam < TCN_KEY_ALL_ACCESS || root > TCN_KEY_WRITE) {
+ tcn_ThrowException(e, "Invalid Registry Key Security");
+ goto cleanup;
+ }
+ reg = (tcn_nt_registry_t *)apr_palloc(p, sizeof(tcn_nt_registry_t));
+ reg->pool = p;
+ reg->root = TCN_KEYS[root].k;
+ reg->key = NULL;
+ TCN_INIT_WSTRING(name);
+ TCN_REGSAM(s, sam);
+ rc = RegOpenKeyExW(reg->root, J2W(name), 0, s, &key);
+ if (rc != ERROR_SUCCESS) {
+ tcn_ThrowAPRException(e, APR_FROM_OS_ERROR(rc));
+ goto cleanup;
+ }
+ reg->key = key;
+ apr_pool_cleanup_register(p, (const void *)reg,
+ registry_cleanup,
+ apr_pool_cleanup_null);
+
+cleanup:
+ TCN_FREE_WSTRING(name);
+ return P2J(reg);
+}
+
+TCN_IMPLEMENT_CALL(jint, Registry, close)(TCN_STDARGS, jlong reg)
+{
+ tcn_nt_registry_t *r = J2P(reg, tcn_nt_registry_t *);
+ UNREFERENCED_STDARGS;
+
+ TCN_ASSERT(reg != 0);
+
+ registry_cleanup(r);
+ apr_pool_cleanup_kill(r->pool, r, registry_cleanup);
+ return APR_SUCCESS;
+}
+
+TCN_IMPLEMENT_CALL(jint, Registry, getType)(TCN_STDARGS, jlong key,
+ jstring name)
+{
+ tcn_nt_registry_t *k = J2P(key, tcn_nt_registry_t *);
+ TCN_ALLOC_WSTRING(name);
+ LONG rc;
+ DWORD v;
+
+ UNREFERENCED(o);
+ TCN_ASSERT(key != 0);
+ TCN_INIT_WSTRING(name);
+ rc = RegQueryValueExW(k->key, J2W(name), NULL, &v, NULL, NULL);
+ if (rc != ERROR_SUCCESS)
+ v = -rc;
+ TCN_FREE_WSTRING(name);
+ switch (v) {
+ case REG_BINARY:
+ v = TCN_REG_BINARY;
+ break;
+ case REG_DWORD:
+ v = TCN_REG_DWORD;
+ break;
+ case REG_EXPAND_SZ:
+ v = TCN_REG_EXPAND_SZ;
+ break;
+ case REG_MULTI_SZ:
+ v = TCN_REG_MULTI_SZ;
+ break;
+ case REG_QWORD:
+ v = TCN_REG_QWORD;
+ break;
+ case REG_SZ:
+ v = TCN_REG_SZ;
+ break;
+ case REG_DWORD_BIG_ENDIAN:
+ v = 0;
+ break;
+ }
+ return v;
+}
+
+TCN_IMPLEMENT_CALL(jint, Registry, getSize)(TCN_STDARGS, jlong key,
+ jstring name)
+{
+ tcn_nt_registry_t *k = J2P(key, tcn_nt_registry_t *);
+ TCN_ALLOC_WSTRING(name);
+ LONG rc;
+ DWORD v;
+
+ UNREFERENCED(o);
+ TCN_ASSERT(key != 0);
+ TCN_INIT_WSTRING(name);
+ rc = RegQueryValueExW(k->key, J2W(name), NULL, NULL, NULL, &v);
+ if (rc != ERROR_SUCCESS)
+ v = -rc;
+ TCN_FREE_WSTRING(name);
+ return v;
+}
+
+TCN_IMPLEMENT_CALL(jint, Registry, getValueI)(TCN_STDARGS, jlong key,
+ jstring name)
+{
+ tcn_nt_registry_t *k = J2P(key, tcn_nt_registry_t *);
+ TCN_ALLOC_WSTRING(name);
+ LONG rc;
+ DWORD t, l;
+ DWORD v = 0;
+
+ UNREFERENCED(o);
+ TCN_ASSERT(key != 0);
+ TCN_INIT_WSTRING(name);
+ rc = RegQueryValueExW(k->key, J2W(name), NULL, &t, NULL, &l);
+ if (rc != ERROR_SUCCESS) {
+ tcn_ThrowAPRException(e, APR_FROM_OS_ERROR(rc));
+ goto cleanup;
+ }
+ if (t == REG_DWORD) {
+ l = sizeof(DWORD);
+ rc = RegQueryValueExW(k->key, J2W(name), NULL, NULL, (LPBYTE)&v, &l);
+ if (rc != ERROR_SUCCESS) {
+ tcn_ThrowAPRException(e, APR_FROM_OS_ERROR(rc));
+ goto cleanup;
+ }
+ }
+ else if (t == REG_SZ || t == REG_BINARY ||
+ t == REG_MULTI_SZ || t == REG_EXPAND_SZ)
+ v = l;
+ else {
+ v = 0;
+ tcn_ThrowException(e, "Unable to convert the value to integer");
+ }
+cleanup:
+ TCN_FREE_WSTRING(name);
+ return v;
+}
+
+TCN_IMPLEMENT_CALL(jlong, Registry, getValueJ)(TCN_STDARGS, jlong key,
+ jstring name)
+{
+ tcn_nt_registry_t *k = J2P(key, tcn_nt_registry_t *);
+ TCN_ALLOC_WSTRING(name);
+ LONG rc;
+ DWORD t, l;
+ UINT64 v = 0;
+
+ UNREFERENCED(o);
+ TCN_ASSERT(key != 0);
+ TCN_INIT_WSTRING(name);
+ rc = RegQueryValueExW(k->key, J2W(name), NULL, &t, NULL, &l);
+ if (rc != ERROR_SUCCESS) {
+ tcn_ThrowAPRException(e, APR_FROM_OS_ERROR(rc));
+ goto cleanup;
+ }
+ if (t == REG_DWORD) {
+ DWORD tv;
+ l = sizeof(DWORD);
+ rc = RegQueryValueExW(k->key, J2W(name), NULL, NULL, (LPBYTE)&tv, &l);
+ if (rc != ERROR_SUCCESS) {
+ tcn_ThrowAPRException(e, APR_FROM_OS_ERROR(rc));
+ goto cleanup;
+ }
+ v = tv;
+ }
+ else if (t == REG_QWORD) {
+ l = sizeof(UINT64);
+ rc = RegQueryValueExW(k->key, J2W(name), NULL, NULL, (LPBYTE)&v, &l);
+ if (rc != ERROR_SUCCESS) {
+ tcn_ThrowAPRException(e, APR_FROM_OS_ERROR(rc));
+ goto cleanup;
+ }
+ }
+ else if (t == REG_SZ || t == REG_BINARY ||
+ t == REG_MULTI_SZ || t == REG_EXPAND_SZ)
+ v = l;
+ else {
+ v = 0;
+ tcn_ThrowException(e, "Unable to convert the value to long");
+ }
+cleanup:
+ TCN_FREE_WSTRING(name);
+ return v;
+}
+
+TCN_IMPLEMENT_CALL(jstring, Registry, getValueS)(TCN_STDARGS, jlong key,
+ jstring name)
+{
+ tcn_nt_registry_t *k = J2P(key, tcn_nt_registry_t *);
+ TCN_ALLOC_WSTRING(name);
+ LONG rc;
+ DWORD t, l;
+ jstring v = NULL;
+
+ UNREFERENCED(o);
+ TCN_ASSERT(key != 0);
+ TCN_INIT_WSTRING(name);
+ rc = RegQueryValueExW(k->key, J2W(name), NULL, &t, NULL, &l);
+ if (rc != ERROR_SUCCESS) {
+ tcn_ThrowAPRException(e, APR_FROM_OS_ERROR(rc));
+ goto cleanup;
+ }
+ if (t == REG_SZ || t == REG_EXPAND_SZ) {
+ jchar *vw = (jchar *)malloc(l);
+ rc = RegQueryValueExW(k->key, J2W(name), NULL, NULL, (LPBYTE)vw, &l);
+ if (rc != ERROR_SUCCESS) {
+ tcn_ThrowAPRException(e, APR_FROM_OS_ERROR(rc));
+ free(vw);
+ goto cleanup;
+ }
+ v = (*e)->NewString((e), vw, lstrlenW(vw));
+ free(vw);
+ }
+cleanup:
+ TCN_FREE_WSTRING(name);
+ return v;
+}
+
+TCN_IMPLEMENT_CALL(jbyteArray, Registry, getValueB)(TCN_STDARGS, jlong key,
+ jstring name)
+{
+ tcn_nt_registry_t *k = J2P(key, tcn_nt_registry_t *);
+ TCN_ALLOC_WSTRING(name);
+ LONG rc;
+ DWORD t, l;
+ jbyteArray v = NULL;
+
+ UNREFERENCED(o);
+ TCN_ASSERT(key != 0);
+ TCN_INIT_WSTRING(name);
+ rc = RegQueryValueExW(k->key, J2W(name), NULL, &t, NULL, &l);
+ if (rc != ERROR_SUCCESS) {
+ tcn_ThrowAPRException(e, APR_FROM_OS_ERROR(rc));
+ goto cleanup;
+ }
+ if (t == REG_BINARY) {
+ BYTE *b = (BYTE *)malloc(l);
+ rc = RegQueryValueExW(k->key, J2W(name), NULL, NULL, b, &l);
+ if (rc != ERROR_SUCCESS) {
+ tcn_ThrowAPRException(e, APR_FROM_OS_ERROR(rc));
+ free(b);
+ goto cleanup;
+ }
+ v = tcn_new_arrayb(e, b, l);
+ free(b);
+ }
+cleanup:
+ TCN_FREE_WSTRING(name);
+ return v;
+}
+
+static jsize get_multi_sz_count(LPCWSTR str)
+{
+ LPCWSTR p = str;
+ jsize cnt = 0;
+ for ( ; p && *p; p++) {
+ cnt++;
+ while (*p)
+ p++;
+ }
+ return cnt;
+}
+
+TCN_IMPLEMENT_CALL(jobjectArray, Registry, getValueA)(TCN_STDARGS, jlong key,
+ jstring name)
+{
+ tcn_nt_registry_t *k = J2P(key, tcn_nt_registry_t *);
+ TCN_ALLOC_WSTRING(name);
+ LONG rc;
+ DWORD t, l;
+ jobjectArray v = NULL;
+
+ UNREFERENCED(o);
+ TCN_ASSERT(key != 0);
+ TCN_INIT_WSTRING(name);
+ rc = RegQueryValueExW(k->key, J2W(name), NULL, &t, NULL, &l);
+ if (rc != ERROR_SUCCESS) {
+ tcn_ThrowAPRException(e, APR_FROM_OS_ERROR(rc));
+ goto cleanup;
+ }
+ if (t == REG_MULTI_SZ) {
+ jsize cnt = 0;
+ jchar *p;
+ jchar *vw = (jchar *)malloc(l);
+ rc = RegQueryValueExW(k->key, J2W(name), NULL, NULL, (LPBYTE)vw, &l);
+ if (rc != ERROR_SUCCESS) {
+ tcn_ThrowAPRException(e, APR_FROM_OS_ERROR(rc));
+ free(vw);
+ goto cleanup;
+ }
+ cnt = get_multi_sz_count(vw);
+ if (cnt) {
+ jsize idx = 0;
+ v = tcn_new_arrays(e, cnt);
+ for (p = vw ; p && *p; p++) {
+ jstring s;
+ jchar *b = p;
+ while (*p)
+ p++;
+ s = (*e)->NewString((e), b, (jsize)(p - b));
+ (*e)->SetObjectArrayElement((e), v, idx++, s);
+ }
+ }
+ free(vw);
+ }
+cleanup:
+ TCN_FREE_WSTRING(name);
+ return v;
+}
+
+TCN_IMPLEMENT_CALL(jint, Registry, setValueI)(TCN_STDARGS, jlong key,
+ jstring name, jint val)
+{
+ tcn_nt_registry_t *k = J2P(key, tcn_nt_registry_t *);
+ TCN_ALLOC_WSTRING(name);
+ LONG rc;
+ DWORD v = (DWORD)val;
+
+ UNREFERENCED(o);
+ TCN_ASSERT(key != 0);
+ TCN_INIT_WSTRING(name);
+ rc = RegSetValueExW(k->key, J2W(name), 0, REG_DWORD, (CONST BYTE *)&v, sizeof(DWORD));
+ TCN_FREE_WSTRING(name);
+ return v;
+}
+
+TCN_IMPLEMENT_CALL(jint, Registry, setValueJ)(TCN_STDARGS, jlong key,
+ jstring name, jlong val)
+{
+ tcn_nt_registry_t *k = J2P(key, tcn_nt_registry_t *);
+ TCN_ALLOC_WSTRING(name);
+ LONG rc;
+ UINT64 v = (UINT64)val;
+
+ UNREFERENCED(o);
+ TCN_ASSERT(key != 0);
+ TCN_INIT_WSTRING(name);
+ rc = RegSetValueExW(k->key, J2W(name), 0, REG_QWORD, (CONST BYTE *)&v, sizeof(UINT64));
+ TCN_FREE_WSTRING(name);
+ return rc;
+}
+
+TCN_IMPLEMENT_CALL(jint, Registry, setValueS)(TCN_STDARGS, jlong key,
+ jstring name, jstring val)
+{
+ tcn_nt_registry_t *k = J2P(key, tcn_nt_registry_t *);
+ TCN_ALLOC_WSTRING(name);
+ TCN_ALLOC_WSTRING(val);
+ LONG rc;
+ DWORD len;
+
+ UNREFERENCED(o);
+ TCN_ASSERT(key != 0);
+ TCN_INIT_WSTRING(name);
+ TCN_INIT_WSTRING(val);
+ len = lstrlenW(J2W(val));
+ rc = RegSetValueExW(k->key, J2W(name), 0, REG_SZ,
+ (CONST BYTE *)J2W(val), (len + 1) * 2);
+ TCN_FREE_WSTRING(name);
+ TCN_FREE_WSTRING(val);
+ return rc;
+}
+
+TCN_IMPLEMENT_CALL(jint, Registry, setValueE)(TCN_STDARGS, jlong key,
+ jstring name, jstring val)
+{
+ tcn_nt_registry_t *k = J2P(key, tcn_nt_registry_t *);
+ TCN_ALLOC_WSTRING(name);
+ TCN_ALLOC_WSTRING(val);
+ LONG rc;
+ DWORD len;
+
+ UNREFERENCED(o);
+ TCN_ASSERT(key != 0);
+ TCN_INIT_WSTRING(name);
+ TCN_INIT_WSTRING(val);
+ len = lstrlenW(J2W(val));
+ rc = RegSetValueExW(k->key, J2W(name), 0, REG_EXPAND_SZ,
+ (CONST BYTE *)J2W(val), (len + 1) * 2);
+ TCN_FREE_WSTRING(name);
+ TCN_FREE_WSTRING(val);
+ return rc;
+}
+
+TCN_IMPLEMENT_CALL(jint, Registry, setValueA)(TCN_STDARGS, jlong key,
+ jstring name,
+ jobjectArray vals)
+{
+ tcn_nt_registry_t *k = J2P(key, tcn_nt_registry_t *);
+ TCN_ALLOC_WSTRING(name);
+ LONG rc;
+ jsize i, len;
+ jsize sl = 0;
+ jchar *msz, *p;
+ UNREFERENCED(o);
+ TCN_ASSERT(key != 0);
+ TCN_INIT_WSTRING(name);
+ len = (*e)->GetArrayLength((e), vals);
+ for (i = 0; i < len; i++) {
+ jstring s = (jstring)(*e)->GetObjectArrayElement((e), vals, i);
+ sl += (*e)->GetStringLength((e), s) + 1;
+ }
+ sl = (sl + 1) * 2;
+ p = msz = (jchar *)calloc(1, sl);
+ for (i = 0; i < len; i++) {
+ jsize l;
+ jstring s = (jstring)(*e)->GetObjectArrayElement((e), vals, i);
+ l = (*e)->GetStringLength((e), s);
+ wcsncpy(p, (*e)->GetStringChars(e, s, 0), l);
+ p += l + 1;
+ }
+ rc = RegSetValueExW(k->key, J2W(name), 0, REG_MULTI_SZ,
+ (CONST BYTE *)msz, sl);
+ TCN_FREE_WSTRING(name);
+ free(msz);
+ return rc;
+}
+
+TCN_IMPLEMENT_CALL(jint, Registry, setValueB)(TCN_STDARGS, jlong key,
+ jstring name,
+ jbyteArray val)
+{
+ tcn_nt_registry_t *k = J2P(key, tcn_nt_registry_t *);
+ TCN_ALLOC_WSTRING(name);
+ jsize nbytes = (*e)->GetArrayLength(e, val);
+ jbyte *bytes = (*e)->GetByteArrayElements(e, val, NULL);
+ LONG rc;
+
+ rc = RegSetValueExW(k->key, J2W(name), 0, REG_BINARY,
+ bytes, (DWORD)nbytes);
+ (*e)->ReleaseByteArrayElements(e, val, bytes, JNI_ABORT);
+ TCN_FREE_WSTRING(name);
+ return rc;
+}
+
+#define MAX_VALUE_NAME 4096
+
+TCN_IMPLEMENT_CALL(jobjectArray, Registry, enumKeys)(TCN_STDARGS, jlong key)
+{
+ tcn_nt_registry_t *k = J2P(key, tcn_nt_registry_t *);
+ LONG rc;
+ jobjectArray v = NULL;
+ jsize cnt = 0;
+
+ WCHAR achKey[MAX_PATH];
+ WCHAR achClass[MAX_PATH] = L"";
+ DWORD cchClassName = MAX_PATH;
+ DWORD cSubKeys;
+ DWORD cbMaxSubKey;
+ DWORD cchMaxClass;
+ DWORD cValues;
+ DWORD cchMaxValue;
+ DWORD cbMaxValueData;
+ DWORD cbSecurityDescriptor;
+ FILETIME ftLastWriteTime;
+
+ DWORD cchValue = MAX_VALUE_NAME;
+
+ UNREFERENCED(o);
+ TCN_ASSERT(key != 0);
+ rc = RegQueryInfoKeyW(k->key,
+ achClass,
+ &cchClassName,
+ NULL,
+ &cSubKeys,
+ &cbMaxSubKey,
+ &cchMaxClass,
+ &cValues,
+ &cchMaxValue,
+ &cbMaxValueData,
+ &cbSecurityDescriptor,
+ &ftLastWriteTime);
+ if (rc != ERROR_SUCCESS) {
+ tcn_ThrowAPRException(e, APR_FROM_OS_ERROR(rc));
+ goto cleanup;
+ }
+ cnt = cSubKeys;
+ if (cnt) {
+ jsize idx = 0;
+ v = tcn_new_arrays(e, cnt);
+ for (idx = 0; idx < cnt; idx++) {
+ jstring s;
+ DWORD achKeyLen = MAX_PATH;
+ rc = RegEnumKeyExW(k->key,
+ idx,
+ achKey,
+ &achKeyLen,
+ NULL,
+ NULL,
+ NULL,
+ &ftLastWriteTime);
+ if (rc == (DWORD)ERROR_SUCCESS) {
+ s = (*e)->NewString((e), achKey, lstrlenW(achKey));
+ (*e)->SetObjectArrayElement((e), v, idx, s);
+ }
+ }
+ }
+cleanup:
+ return v;
+}
+
+TCN_IMPLEMENT_CALL(jobjectArray, Registry, enumValues)(TCN_STDARGS, jlong key)
+{
+ tcn_nt_registry_t *k = J2P(key, tcn_nt_registry_t *);
+ LONG rc;
+ jobjectArray v = NULL;
+ jsize cnt = 0;
+
+ WCHAR achClass[MAX_PATH] = L"";
+ DWORD cchClassName = MAX_PATH;
+ DWORD cSubKeys;
+ DWORD cbMaxSubKey;
+ DWORD cchMaxClass;
+ DWORD cValues;
+ DWORD cchMaxValue;
+ DWORD cbMaxValueData;
+ DWORD cbSecurityDescriptor;
+ FILETIME ftLastWriteTime;
+
+ WCHAR achValue[MAX_VALUE_NAME];
+ DWORD cchValue = MAX_VALUE_NAME;
+
+ UNREFERENCED(o);
+ TCN_ASSERT(key != 0);
+ /* Get the class name and the value count. */
+ rc = RegQueryInfoKeyW(k->key,
+ achClass,
+ &cchClassName,
+ NULL,
+ &cSubKeys,
+ &cbMaxSubKey,
+ &cchMaxClass,
+ &cValues,
+ &cchMaxValue,
+ &cbMaxValueData,
+ &cbSecurityDescriptor,
+ &ftLastWriteTime);
+ if (rc != ERROR_SUCCESS) {
+ tcn_ThrowAPRException(e, APR_FROM_OS_ERROR(rc));
+ goto cleanup;
+ }
+ cnt = cValues;
+ if (cnt) {
+ jsize idx = 0;
+ v = tcn_new_arrays(e, cnt);
+ for (idx = 0; idx < cnt; idx++) {
+ jstring s;
+ cchValue = MAX_VALUE_NAME;
+ achValue[0] = '\0';
+ rc = RegEnumValueW(k->key, idx,
+ achValue,
+ &cchValue,
+ NULL,
+ NULL, // &dwType,
+ NULL, // &bData,
+ NULL); // &bcData
+ if (rc == (DWORD)ERROR_SUCCESS) {
+ s = (*e)->NewString((e), achValue, lstrlenW(achValue));
+ (*e)->SetObjectArrayElement((e), v, idx, s);
+ }
+ }
+ }
+cleanup:
+ return v;
+}
+
+TCN_IMPLEMENT_CALL(jint, Registry, deleteKey)(TCN_STDARGS, jint root, jstring name,
+ jboolean only_if_empty)
+{
+ DWORD rv;
+ TCN_ALLOC_WSTRING(name);
+
+ UNREFERENCED(o);
+ if (root < TCN_HKEY_CLASSES_ROOT || root > TCN_HKEY_USERS) {
+ rv = EBADF;
+ goto cleanup;
+ }
+ TCN_INIT_WSTRING(name);
+ if (only_if_empty)
+ rv = SHDeleteEmptyKeyW(TCN_KEYS[root].k, J2W(name));
+ else
+ rv = SHDeleteKeyW(TCN_KEYS[root].k, J2W(name));
+cleanup:
+ TCN_FREE_WSTRING(name);
+ return rv;
+}
+
+TCN_IMPLEMENT_CALL(jint, Registry, deleteValue)(TCN_STDARGS, jlong key,
+ jstring name)
+{
+ LONG rv;
+ TCN_ALLOC_WSTRING(name);
+ tcn_nt_registry_t *k = J2P(key, tcn_nt_registry_t *);
+
+ UNREFERENCED(o);
+ TCN_INIT_WSTRING(name);
+ rv = RegDeleteValueW(k->key, J2W(name));
+ TCN_FREE_WSTRING(name);
+ return (jint)rv;
+}
diff --git a/jni/native/os/win32/system.c b/jni/native/os/win32/system.c
new file mode 100644
index 0000000..35a4a15
--- /dev/null
+++ b/jni/native/os/win32/system.c
@@ -0,0 +1,468 @@
+/* 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: system.c 1442587 2013-02-05 13:49:48Z rjung $
+ */
+
+#ifndef _WIN32_WINNT
+#define _WIN32_WINNT 0x0500
+#endif
+#include <winsock2.h>
+#include <mswsock.h>
+#include <ws2tcpip.h>
+#include <tlhelp32.h>
+
+#include "apr.h"
+#include "apr_pools.h"
+#include "apr_poll.h"
+#include "apr_network_io.h"
+#include "apr_arch_misc.h" /* for apr_os_level */
+#include "apr_arch_atime.h" /* for FileTimeToAprTime */
+
+#include "tcn.h"
+#ifdef HAVE_OPENSSL
+#include "ssl_private.h"
+#endif
+
+#pragma warning(push)
+#pragma warning(disable : 4201)
+#if (_WIN32_WINNT < 0x0501)
+#include <winternl.h>
+#endif
+#include <psapi.h>
+#pragma warning(pop)
+
+
+static CRITICAL_SECTION dll_critical_section; /* dll's critical section */
+static HINSTANCE dll_instance = NULL;
+static SYSTEM_INFO dll_system_info;
+static HANDLE h_kernel = NULL;
+static HANDLE h_ntdll = NULL;
+static char dll_file_name[MAX_PATH];
+
+typedef BOOL (WINAPI *pfnGetSystemTimes)(LPFILETIME, LPFILETIME, LPFILETIME);
+static pfnGetSystemTimes fnGetSystemTimes = NULL;
+#if (_WIN32_WINNT < 0x0501)
+typedef NTSTATUS (WINAPI *pfnNtQuerySystemInformation)(SYSTEM_INFORMATION_CLASS, PVOID, ULONG, PULONG);
+static pfnNtQuerySystemInformation fnNtQuerySystemInformation = NULL;
+#endif
+
+BOOL
+WINAPI
+DllMain(
+ HINSTANCE instance,
+ DWORD reason,
+ LPVOID reserved)
+{
+
+ switch (reason) {
+ /** The DLL is loading due to process
+ * initialization or a call to LoadLibrary.
+ */
+ case DLL_PROCESS_ATTACH:
+ InitializeCriticalSection(&dll_critical_section);
+ dll_instance = instance;
+ GetSystemInfo(&dll_system_info);
+ if ((h_kernel = LoadLibrary("kernel32.dll")) != NULL)
+ fnGetSystemTimes = (pfnGetSystemTimes)GetProcAddress(h_kernel,
+ "GetSystemTimes");
+ if (fnGetSystemTimes == NULL) {
+ FreeLibrary(h_kernel);
+ h_kernel = NULL;
+#if (_WIN32_WINNT < 0x0501)
+ if ((h_ntdll = LoadLibrary("ntdll.dll")) != NULL)
+ fnNtQuerySystemInformation =
+ (pfnNtQuerySystemInformation)GetProcAddress(h_ntdll,
+ "NtQuerySystemInformation");
+
+ if (fnNtQuerySystemInformation == NULL) {
+ FreeLibrary(h_ntdll);
+ h_ntdll = NULL;
+ }
+#endif
+ }
+ GetModuleFileName(instance, dll_file_name, sizeof(dll_file_name));
+ break;
+ /** The attached process creates a new thread.
+ */
+ case DLL_THREAD_ATTACH:
+ break;
+
+ /** The thread of the attached process terminates.
+ */
+ case DLL_THREAD_DETACH:
+ break;
+
+ /** DLL unload due to process termination
+ * or FreeLibrary.
+ */
+ case DLL_PROCESS_DETACH:
+ if (h_kernel)
+ FreeLibrary(h_kernel);
+ if (h_ntdll)
+ FreeLibrary(h_ntdll);
+ DeleteCriticalSection(&dll_critical_section);
+ break;
+
+ default:
+ break;
+ }
+
+ return TRUE;
+ UNREFERENCED_PARAMETER(reserved);
+}
+
+
+TCN_IMPLEMENT_CALL(jstring, OS, syserror)(TCN_STDARGS, jint err)
+{
+ jstring str;
+ void *buf;
+
+ UNREFERENCED(o);
+ if (!FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |
+ FORMAT_MESSAGE_FROM_SYSTEM |
+ FORMAT_MESSAGE_IGNORE_INSERTS,
+ NULL,
+ err,
+ MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
+ (LPTSTR)&buf,
+ 0,
+ NULL)) {
+ str = AJP_TO_JSTRING("Unknown Error");
+ }
+ else {
+ str = AJP_TO_JSTRING((const char *)buf);
+ LocalFree(buf);
+ }
+ return str;
+}
+
+TCN_IMPLEMENT_CALL(jstring, OS, expand)(TCN_STDARGS, jstring val)
+{
+ jstring str;
+ jchar buf[TCN_BUFFER_SZ] = L"";
+ DWORD len;
+ TCN_ALLOC_WSTRING(val);
+
+ UNREFERENCED(o);
+ TCN_INIT_WSTRING(val);
+
+ len = ExpandEnvironmentStringsW(J2W(val), buf, TCN_BUFFER_SZ - 1);
+ if (len > (TCN_BUFFER_SZ - 1)) {
+ jchar *dbuf = malloc((len + 1) * 2);
+ ExpandEnvironmentStringsW(J2W(val), dbuf, len);
+ str = (*e)->NewString(e, dbuf, lstrlenW(dbuf));
+ free(dbuf);
+ }
+ else
+ str = (*e)->NewString(e, buf, lstrlenW(buf));
+
+ TCN_FREE_WSTRING(val);
+ return str;
+}
+
+#define LOG_MSG_EMERG 0xC0000001L
+#define LOG_MSG_ERROR 0xC0000002L
+#define LOG_MSG_NOTICE 0x80000003L
+#define LOG_MSG_WARN 0x80000004L
+#define LOG_MSG_INFO 0x40000005L
+#define LOG_MSG_DEBUG 0x00000006L
+#define LOG_MSG_DOMAIN "Native"
+
+static char log_domain[MAX_PATH] = "Native";
+
+static void init_log_source(const char *domain)
+{
+ HKEY key;
+ DWORD ts;
+ char event_key[MAX_PATH];
+
+ strcpy(event_key, "SYSTEM\\CurrentControlSet\\Services\\EventLog\\Application\\");
+ strcat(event_key, domain);
+ if (!RegCreateKey(HKEY_LOCAL_MACHINE, event_key, &key)) {
+ RegSetValueEx(key, "EventMessageFile", 0, REG_SZ, (LPBYTE)&dll_file_name[0],
+ lstrlenA(dll_file_name) + 1);
+ ts = EVENTLOG_ERROR_TYPE | EVENTLOG_WARNING_TYPE | EVENTLOG_INFORMATION_TYPE;
+
+ RegSetValueEx(key, "TypesSupported", 0, REG_DWORD, (LPBYTE) &ts, sizeof(DWORD));
+ RegCloseKey(key);
+ }
+ strcpy(log_domain, domain);
+}
+
+TCN_IMPLEMENT_CALL(void, OS, sysloginit)(TCN_STDARGS, jstring domain)
+{
+ const char *d;
+ TCN_ALLOC_CSTRING(domain);
+
+ UNREFERENCED(o);
+
+ if ((d = J2S(domain)) == NULL)
+ d = LOG_MSG_DOMAIN;
+ init_log_source(d);
+
+ TCN_FREE_CSTRING(domain);
+}
+
+TCN_IMPLEMENT_CALL(void, OS, syslog)(TCN_STDARGS, jint level,
+ jstring msg)
+{
+ TCN_ALLOC_CSTRING(msg);
+ DWORD id = LOG_MSG_DEBUG;
+ WORD il = EVENTLOG_SUCCESS;
+ HANDLE source;
+ const char *messages[1];
+ UNREFERENCED(o);
+
+ switch (level) {
+ case TCN_LOG_EMERG:
+ id = LOG_MSG_EMERG;
+ il = EVENTLOG_ERROR_TYPE;
+ break;
+ case TCN_LOG_ERROR:
+ id = LOG_MSG_ERROR;
+ il = EVENTLOG_ERROR_TYPE;
+ break;
+ case TCN_LOG_NOTICE:
+ id = LOG_MSG_NOTICE;
+ il = EVENTLOG_WARNING_TYPE;
+ break;
+ case TCN_LOG_WARN:
+ id = LOG_MSG_WARN;
+ il = EVENTLOG_WARNING_TYPE;
+ break;
+ case TCN_LOG_INFO:
+ id = LOG_MSG_INFO;
+ il = EVENTLOG_INFORMATION_TYPE;
+ break;
+ }
+
+ messages[0] = J2S(msg);
+ source = RegisterEventSource(NULL, log_domain);
+
+ if (source != NULL) {
+ ReportEvent(source, il,
+ 0,
+ id,
+ NULL,
+ 1, 0,
+ messages, NULL);
+ DeregisterEventSource(source);
+ }
+
+ TCN_FREE_CSTRING(msg);
+}
+
+TCN_IMPLEMENT_CALL(jboolean, OS, is)(TCN_STDARGS, jint type)
+{
+ UNREFERENCED_STDARGS;
+#ifdef _WIN64
+ if (type == 4)
+ return JNI_TRUE;
+ else
+#endif
+ if (type == 3)
+ return JNI_TRUE;
+ else
+ return JNI_FALSE;
+}
+
+TCN_IMPLEMENT_CALL(jint, OS, info)(TCN_STDARGS,
+ jlongArray inf)
+{
+ MEMORYSTATUSEX ms;
+ ULONGLONG st[4];
+ FILETIME ft[4];
+ PROCESS_MEMORY_COUNTERS pmc;
+ jint rv;
+ int i;
+ jsize ilen = (*e)->GetArrayLength(e, inf);
+ jlong *pvals = (*e)->GetLongArrayElements(e, inf, NULL);
+
+ if (ilen < 16) {
+ return APR_EINVAL;
+ }
+ for (i = 0; i < 16; i++)
+ pvals[i] = 0;
+
+ ms.dwLength = sizeof(MEMORYSTATUSEX);
+
+ UNREFERENCED(o);
+ if (GlobalMemoryStatusEx(&ms)) {
+ pvals[0] = (jlong)ms.ullTotalPhys;
+ pvals[1] = (jlong)ms.ullAvailPhys;
+ pvals[2] = (jlong)ms.ullTotalPageFile;
+ pvals[3] = (jlong)ms.ullAvailPageFile;
+ /* Slots 4 and 5 are for shared memory */
+ pvals[6] = (jlong)ms.dwMemoryLoad;
+ }
+ else
+ goto cleanup;
+
+ memset(st, 0, sizeof(st));
+
+ if (fnGetSystemTimes) {
+ if ((*fnGetSystemTimes)(&ft[0], &ft[1], &ft[2])) {
+ st[0] = (((ULONGLONG)ft[0].dwHighDateTime << 32) | ft[0].dwLowDateTime) / 10;
+ st[1] = (((ULONGLONG)ft[1].dwHighDateTime << 32) | ft[1].dwLowDateTime) / 10;
+ st[2] = (((ULONGLONG)ft[2].dwHighDateTime << 32) | ft[2].dwLowDateTime) / 10;
+ }
+ else
+ goto cleanup;
+ }
+#if (_WIN32_WINNT < 0x0501)
+ else if (fnNtQuerySystemInformation) {
+ BYTE buf[2048]; /* This should ne enough for 32 processors */
+ NTSTATUS rs = (*fnNtQuerySystemInformation)(SystemProcessorPerformanceInformation,
+ (LPVOID)buf, 2048, NULL);
+ if (rs == 0) {
+ PSYSTEM_PROCESSOR_PERFORMANCE_INFORMATION pspi = (PSYSTEM_PROCESSOR_PERFORMANCE_INFORMATION)&buf[0];
+ DWORD i;
+ /* Calculate all processors */
+ for (i = 0; i < dll_system_info.dwNumberOfProcessors; i++) {
+ st[0] += pspi[i].IdleTime.QuadPart / 10;
+ st[1] += pspi[i].KernelTime.QuadPart / 10;
+ st[2] += pspi[i].UserTime.QuadPart / 10;
+ }
+ }
+ else
+ goto cleanup;
+ }
+#endif
+ pvals[7] = st[0];
+ pvals[8] = st[1];
+ pvals[9] = st[2];
+
+ memset(st, 0, sizeof(st));
+ if (GetProcessTimes(GetCurrentProcess(), &ft[0], &ft[1], &ft[2], &ft[3])) {
+ FileTimeToAprTime((apr_time_t *)&st[0], &ft[0]);
+ st[1] = (((ULONGLONG)ft[2].dwHighDateTime << 32) | ft[2].dwLowDateTime) / 10;
+ st[2] = (((ULONGLONG)ft[3].dwHighDateTime << 32) | ft[3].dwLowDateTime) / 10;
+ }
+ pvals[10] = st[0];
+ pvals[11] = st[1];
+ pvals[12] = st[2];
+
+ if (GetProcessMemoryInfo(GetCurrentProcess(), &pmc, sizeof(pmc))) {
+ pvals[13] = pmc.WorkingSetSize;
+ pvals[14] = pmc.PeakWorkingSetSize;
+ pvals[15] = pmc.PageFaultCount;
+ }
+
+ (*e)->ReleaseLongArrayElements(e, inf, pvals, 0);
+ return APR_SUCCESS;
+cleanup:
+ rv = apr_get_os_error();
+ (*e)->ReleaseLongArrayElements(e, inf, pvals, 0);
+ return rv;
+}
+
+#ifdef HAVE_OPENSSL
+
+static DWORD WINAPI password_thread(void *data)
+{
+ tcn_pass_cb_t *cb = (tcn_pass_cb_t *)data;
+ MSG msg;
+ HWINSTA hwss;
+ HWINSTA hwsu;
+ HDESK hwds;
+ HDESK hwdu;
+ HWND hwnd;
+
+ /* Ensure connection to service window station and desktop, and
+ * save their handles.
+ */
+ GetDesktopWindow();
+ hwss = GetProcessWindowStation();
+ hwds = GetThreadDesktop(GetCurrentThreadId());
+
+ /* Impersonate the client and connect to the User's
+ * window station and desktop.
+ */
+ hwsu = OpenWindowStation("WinSta0", FALSE, MAXIMUM_ALLOWED);
+ if (hwsu == NULL) {
+ ExitThread(1);
+ return 1;
+ }
+ SetProcessWindowStation(hwsu);
+ hwdu = OpenDesktop("Default", 0, FALSE, MAXIMUM_ALLOWED);
+ if (hwdu == NULL) {
+ SetProcessWindowStation(hwss);
+ CloseWindowStation(hwsu);
+ ExitThread(1);
+ return 1;
+ }
+ SetThreadDesktop(hwdu);
+
+ hwnd = CreateDialog(dll_instance, MAKEINTRESOURCE(1001), NULL, NULL);
+ if (hwnd != NULL)
+ ShowWindow(hwnd, SW_SHOW);
+ else {
+ ExitThread(1);
+ return 1;
+ }
+ while (1) {
+ if (PeekMessage(&msg, hwnd, 0, 0, PM_REMOVE)) {
+ if (msg.message == WM_KEYUP) {
+ int nVirtKey = (int)msg.wParam;
+ if (nVirtKey == VK_ESCAPE) {
+ DestroyWindow(hwnd);
+ break;
+ }
+ else if (nVirtKey == VK_RETURN) {
+ HWND he = GetDlgItem(hwnd, 1002);
+ if (he) {
+ int n = GetWindowText(he, cb->password, SSL_MAX_PASSWORD_LEN - 1);
+ cb->password[n] = '\0';
+ }
+ DestroyWindow(hwnd);
+ break;
+ }
+ }
+ TranslateMessage(&msg);
+ DispatchMessage(&msg);
+ }
+ else
+ Sleep(100);
+ }
+ /* Restore window station and desktop.
+ */
+ SetThreadDesktop(hwds);
+ SetProcessWindowStation(hwss);
+ CloseDesktop(hwdu);
+ CloseWindowStation(hwsu);
+
+ ExitThread(0);
+ return 0;
+}
+
+int WIN32_SSL_password_prompt(tcn_pass_cb_t *data)
+{
+ DWORD id;
+ HANDLE thread;
+ /* TODO: See how to display this from service mode */
+ thread = CreateThread(NULL, 0,
+ password_thread, data,
+ 0, &id);
+ WaitForSingleObject(thread, INFINITE);
+ CloseHandle(thread);
+ return (int)strlen(data->password);
+}
+
+#endif
diff --git a/jni/native/src/address.c b/jni/native/src/address.c
new file mode 100644
index 0000000..7fa5a7d
--- /dev/null
+++ b/jni/native/src/address.c
@@ -0,0 +1,146 @@
+/* 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;
+}
diff --git a/jni/native/src/bb.c b/jni/native/src/bb.c
new file mode 100644
index 0000000..bacb91f
--- /dev/null
+++ b/jni/native/src/bb.c
@@ -0,0 +1,135 @@
+/* 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: bb.c 1442587 2013-02-05 13:49:48Z rjung $
+ */
+
+#include "tcn.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)
+{
+ 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;
+}
+
+TCN_IMPLEMENT_CALL(jobject, Buffer, pcalloc)(TCN_STDARGS, jlong pool,
+ jint size)
+{
+ 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;
+}
+
+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;
+}
+
+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);
+ return P2J((*e)->GetDirectBufferAddress(e, bb));
+}
+
+TCN_IMPLEMENT_CALL(jlong, Buffer, size)(TCN_STDARGS, jobject bb)
+{
+ UNREFERENCED(o);
+ return (*e)->GetDirectBufferCapacity(e, bb);
+}
diff --git a/jni/native/src/dir.c b/jni/native/src/dir.c
new file mode 100644
index 0000000..ebea430
--- /dev/null
+++ b/jni/native/src/dir.c
@@ -0,0 +1,105 @@
+/* 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);
+}
diff --git a/jni/native/src/error.c b/jni/native/src/error.c
new file mode 100644
index 0000000..f93d10a
--- /dev/null
+++ b/jni/native/src/error.c
@@ -0,0 +1,248 @@
+/* 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: error.c 1442587 2013-02-05 13:49:48Z rjung $
+ */
+
+#include "tcn.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.
+ */
+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);
+
+}
+
+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'};
+ va_list ap;
+
+ va_start(ap, fmt);
+ apr_vsnprintf(msg, TCN_BUFFER_SZ, fmt, ap);
+ tcn_ThrowException(env, msg);
+ 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(jint, Error, netosError)(TCN_STDARGS)
+{
+ UNREFERENCED_STDARGS;
+ return (jint)apr_get_netos_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_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;
+}
diff --git a/jni/native/src/file.c b/jni/native/src/file.c
new file mode 100644
index 0000000..05c8747
--- /dev/null
+++ b/jni/native/src/file.c
@@ -0,0 +1,601 @@
+/* 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);
+}
diff --git a/jni/native/src/info.c b/jni/native/src/info.c
new file mode 100644
index 0000000..222c27e
--- /dev/null
+++ b/jni/native/src/info.c
@@ -0,0 +1,357 @@
+/* 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;
+}
diff --git a/jni/native/src/jnilib.c b/jni/native/src/jnilib.c
new file mode 100644
index 0000000..6f4bda7
--- /dev/null
+++ b/jni/native/src/jnilib.c
@@ -0,0 +1,484 @@
+/* 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: jnilib.c 1449753 2013-02-25 15:40:08Z rjung $
+ */
+
+#include "tcn.h"
+#include "apr_version.h"
+#include "apr_file_io.h"
+#include "apr_mmap.h"
+#include "apr_atomic.h"
+
+#include "tcn_version.h"
+
+#ifdef TCN_DO_STATISTICS
+extern void sp_poll_dump_statistics();
+extern void sp_network_dump_statistics();
+extern void ssl_network_dump_statistics();
+#endif
+
+apr_pool_t *tcn_global_pool = NULL;
+static JavaVM *tcn_global_vm = NULL;
+
+static jclass jString_class;
+static jclass jFinfo_class;
+static jclass jAinfo_class;
+static jmethodID jString_init;
+static jmethodID jString_getBytes;
+
+int tcn_parent_pid = 0;
+
+/* Called by the JVM when APR_JAVA is loaded */
+JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved)
+{
+ JNIEnv *env;
+ apr_version_t apv;
+ int apvn;
+
+ UNREFERENCED(reserved);
+ if ((*vm)->GetEnv(vm, (void **)&env, JNI_VERSION_1_4)) {
+ return JNI_ERR;
+ }
+ tcn_global_vm = vm;
+
+ /* 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, "Unupported 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);
+ TCN_LOAD_CLASS(env, jFinfo_class, TCN_FINFO_CLASS, JNI_ERR);
+ TCN_LOAD_CLASS(env, jAinfo_class, TCN_AINFO_CLASS, JNI_ERR);
+
+ TCN_GET_METHOD(env, jString_class, jString_init,
+ "<init>", "([B)V", JNI_ERR);
+ TCN_GET_METHOD(env, jString_class, jString_getBytes,
+ "getBytes", "()[B", JNI_ERR);
+
+ if(tcn_load_finfo_class(env, jFinfo_class) != APR_SUCCESS)
+ return JNI_ERR;
+ if(tcn_load_ainfo_class(env, jAinfo_class) != APR_SUCCESS)
+ return JNI_ERR;
+#ifdef WIN32
+ {
+ char *ppid = getenv(TCN_PARENT_IDE);
+ if (ppid)
+ tcn_parent_pid = atoi(ppid);
+ }
+#else
+ tcn_parent_pid = getppid();
+#endif
+
+ return JNI_VERSION_1_4;
+}
+
+
+/* Called by the JVM before the APR_JAVA is unloaded */
+JNIEXPORT void JNICALL JNI_OnUnload(JavaVM *vm, void *reserved)
+{
+ JNIEnv *env;
+
+ UNREFERENCED(reserved);
+
+ if ((*vm)->GetEnv(vm, (void **)&env, JNI_VERSION_1_2)) {
+ return;
+ }
+ if (tcn_global_pool) {
+ TCN_UNLOAD_CLASS(env, jString_class);
+ TCN_UNLOAD_CLASS(env, jFinfo_class);
+ TCN_UNLOAD_CLASS(env, jAinfo_class);
+ apr_terminate();
+ }
+}
+
+jstring tcn_new_stringn(JNIEnv *env, const char *str, size_t l)
+{
+ jstring result;
+ jbyteArray bytes = 0;
+ size_t len = l;
+
+ if (!str)
+ return NULL;
+ if ((*env)->EnsureLocalCapacity(env, 2) < 0) {
+ return NULL; /* out of memory error */
+ }
+ if (l < 0)
+ len = strlen(str);
+ bytes = (*env)->NewByteArray(env, (jsize)len);
+ if (bytes != NULL) {
+ (*env)->SetByteArrayRegion(env, bytes, 0, (jint)len, (jbyte *)str);
+ result = (*env)->NewObject(env, jString_class, jString_init, bytes);
+ (*env)->DeleteLocalRef(env, bytes);
+ return result;
+ } /* else fall through */
+ return NULL;
+}
+
+jbyteArray tcn_new_arrayb(JNIEnv *env, const unsigned char *data, size_t len)
+{
+ jbyteArray bytes = (*env)->NewByteArray(env, (jsize)len);
+ if (bytes != NULL) {
+ (*env)->SetByteArrayRegion(env, bytes, 0, (jint)len, (jbyte *)data);
+ }
+ return bytes;
+}
+
+jobjectArray tcn_new_arrays(JNIEnv *env, size_t len)
+{
+ return (*env)->NewObjectArray(env, (jsize)len, jString_class, NULL);
+}
+
+jstring tcn_new_string(JNIEnv *env, const char *str)
+{
+ if (!str)
+ return NULL;
+ else
+ return (*env)->NewStringUTF(env, str);
+}
+
+char *tcn_get_string(JNIEnv *env, jstring jstr)
+{
+ jbyteArray bytes = NULL;
+ jthrowable exc;
+ char *result = NULL;
+
+ if ((*env)->EnsureLocalCapacity(env, 2) < 0) {
+ return NULL; /* out of memory error */
+ }
+ bytes = (*env)->CallObjectMethod(env, jstr, jString_getBytes);
+ exc = (*env)->ExceptionOccurred(env);
+ if (!exc) {
+ jint len = (*env)->GetArrayLength(env, bytes);
+ result = (char *)malloc(len + 1);
+ if (result == NULL) {
+ TCN_THROW_OS_ERROR(env);
+ (*env)->DeleteLocalRef(env, bytes);
+ return 0;
+ }
+ (*env)->GetByteArrayRegion(env, bytes, 0, len, (jbyte *)result);
+ result[len] = '\0'; /* NULL-terminate */
+ }
+ else {
+ (*env)->DeleteLocalRef(env, exc);
+ }
+ (*env)->DeleteLocalRef(env, bytes);
+
+ return result;
+}
+
+char *tcn_strdup(JNIEnv *env, jstring jstr)
+{
+ char *result = NULL;
+ const char *cjstr;
+
+ cjstr = (const char *)((*env)->GetStringUTFChars(env, jstr, 0));
+ if (cjstr) {
+ result = strdup(cjstr);
+ (*env)->ReleaseStringUTFChars(env, jstr, cjstr);
+ }
+ return result;
+}
+
+char *tcn_pstrdup(JNIEnv *env, jstring jstr, apr_pool_t *pool)
+{
+ char *result = NULL;
+ const char *cjstr;
+
+ cjstr = (const char *)((*env)->GetStringUTFChars(env, jstr, 0));
+ if (cjstr) {
+ result = apr_pstrdup(pool, cjstr);
+ (*env)->ReleaseStringUTFChars(env, jstr, cjstr);
+ }
+ return result;
+}
+
+TCN_IMPLEMENT_CALL(jboolean, Library, initialize)(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(void, Library, terminate)(TCN_STDARGS)
+{
+
+ UNREFERENCED_STDARGS;
+ if (tcn_global_pool) {
+ apr_pool_t *p = tcn_global_pool;
+ tcn_global_pool = NULL;
+#ifdef TCN_DO_STATISTICS
+ fprintf(stderr, "APR Statistical data ....\n");
+#endif
+ apr_pool_destroy(p);
+#ifdef TCN_DO_STATISTICS
+ sp_poll_dump_statistics();
+ sp_network_dump_statistics();
+ ssl_network_dump_statistics();
+ fprintf(stderr, "APR Terminated\n");
+#endif
+ apr_terminate();
+ }
+}
+
+TCN_IMPLEMENT_CALL(jlong, Library, globalPool)(TCN_STDARGS)
+{
+ UNREFERENCED_STDARGS;
+ return P2J(tcn_global_pool);
+}
+
+TCN_IMPLEMENT_CALL(jint, Library, version)(TCN_STDARGS, jint what)
+{
+ apr_version_t apv;
+
+ UNREFERENCED_STDARGS;
+ apr_version(&apv);
+
+ switch (what) {
+ case 0x01:
+ return TCN_MAJOR_VERSION;
+ break;
+ case 0x02:
+ return TCN_MINOR_VERSION;
+ break;
+ case 0x03:
+ return TCN_PATCH_VERSION;
+ break;
+ case 0x04:
+ return TCN_IS_DEV_VERSION;
+ break;
+ case 0x11:
+ return apv.major;
+ break;
+ case 0x12:
+ return apv.minor;
+ break;
+ case 0x13:
+ return apv.patch;
+ break;
+ case 0x14:
+ return apv.is_dev;
+ break;
+ }
+ return 0;
+}
+
+TCN_IMPLEMENT_CALL(jstring, Library, versionString)(TCN_STDARGS)
+{
+ UNREFERENCED(o);
+ return AJP_TO_JSTRING(TCN_VERSION_STRING);
+}
+
+TCN_IMPLEMENT_CALL(jstring, Library, aprVersionString)(TCN_STDARGS)
+{
+ UNREFERENCED(o);
+ return AJP_TO_JSTRING(apr_version_string());
+}
+
+TCN_IMPLEMENT_CALL(jboolean, Library, has)(TCN_STDARGS, jint what)
+{
+ jboolean rv = JNI_FALSE;
+ UNREFERENCED_STDARGS;
+ switch (what) {
+ case 0:
+#if APR_HAVE_IPV6
+ rv = JNI_TRUE;
+#endif
+ break;
+ case 1:
+#if APR_HAS_SHARED_MEMORY
+ rv = JNI_TRUE;
+#endif
+ break;
+ case 2:
+#if APR_HAS_THREADS
+ rv = JNI_TRUE;
+#endif
+ break;
+ case 3:
+#if APR_HAS_SENDFILE
+ rv = JNI_TRUE;
+#endif
+ break;
+ case 4:
+#if APR_HAS_MMAP
+ rv = JNI_TRUE;
+#endif
+ break;
+ case 5:
+#if APR_HAS_FORK
+ rv = JNI_TRUE;
+#endif
+ break;
+ case 6:
+#if APR_HAS_RANDOM
+ rv = JNI_TRUE;
+#endif
+ break;
+ case 7:
+#if APR_HAS_OTHER_CHILD
+ rv = JNI_TRUE;
+#endif
+ break;
+ case 8:
+#if APR_HAS_DSO
+ rv = JNI_TRUE;
+#endif
+ break;
+ case 9:
+#if APR_HAS_SO_ACCEPTFILTER
+ rv = JNI_TRUE;
+#endif
+ break;
+ case 10:
+#if APR_HAS_UNICODE_FS
+ rv = JNI_TRUE;
+#endif
+ break;
+ case 11:
+#if APR_HAS_PROC_INVOKED
+ rv = JNI_TRUE;
+#endif
+ break;
+ case 12:
+#if APR_HAS_USER
+ rv = JNI_TRUE;
+#endif
+ break;
+ case 13:
+#if APR_HAS_LARGE_FILES
+ rv = JNI_TRUE;
+#endif
+ break;
+ case 14:
+#if APR_HAS_XTHREAD_FILES
+ rv = JNI_TRUE;
+#endif
+ break;
+ case 15:
+#if APR_HAS_OS_UUID
+ rv = JNI_TRUE;
+#endif
+ break;
+ case 16:
+#if APR_IS_BIGENDIAN
+ rv = JNI_TRUE;
+#endif
+ break;
+
+ case 17:
+#if APR_FILES_AS_SOCKETS
+ rv = JNI_TRUE;
+#endif
+ break;
+ case 18:
+#if APR_CHARSET_EBCDIC
+ rv = JNI_TRUE;
+#endif
+ break;
+ case 19:
+#if APR_TCP_NODELAY_INHERITED
+ rv = JNI_TRUE;
+#endif
+ break;
+ case 20:
+#if APR_O_NONBLOCK_INHERITED
+ rv = JNI_TRUE;
+#endif
+ break;
+ }
+ return rv;
+}
+
+TCN_IMPLEMENT_CALL(jint, Library, size)(TCN_STDARGS, jint what)
+{
+
+ UNREFERENCED_STDARGS;
+
+ switch (what) {
+ case 1:
+ return APR_SIZEOF_VOIDP;
+ break;
+ case 2:
+ return APR_PATH_MAX;
+ break;
+ case 3:
+ return APRMAXHOSTLEN;
+ break;
+ case 4:
+ return APR_MAX_IOVEC_SIZE;
+ break;
+ case 5:
+ return APR_MAX_SECS_TO_LINGER;
+ break;
+ case 6:
+ return APR_MMAP_THRESHOLD;
+ break;
+ case 7:
+ return APR_MMAP_LIMIT;
+ break;
+
+ }
+ return 0;
+}
+
+apr_pool_t *tcn_get_global_pool()
+{
+ if (!tcn_global_pool) {
+ if (apr_pool_create(&tcn_global_pool, NULL) != APR_SUCCESS) {
+ return NULL;
+ }
+ apr_atomic_init(tcn_global_pool);
+ }
+ return tcn_global_pool;
+}
+
+jclass tcn_get_string_class()
+{
+ return jString_class;
+}
+
+JavaVM * tcn_get_java_vm()
+{
+ return tcn_global_vm;
+}
+
+jint tcn_get_java_env(JNIEnv **env)
+{
+ if ((*tcn_global_vm)->GetEnv(tcn_global_vm, (void **)env,
+ JNI_VERSION_1_4)) {
+ return JNI_ERR;
+ }
+ return JNI_OK;
+}
diff --git a/jni/native/src/lock.c b/jni/native/src/lock.c
new file mode 100644
index 0000000..c574d96
--- /dev/null
+++ b/jni/native/src/lock.c
@@ -0,0 +1,202 @@
+/* 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);
+}
+
diff --git a/jni/native/src/misc.c b/jni/native/src/misc.c
new file mode 100644
index 0000000..1db02ba
--- /dev/null
+++ b/jni/native/src/misc.c
@@ -0,0 +1,81 @@
+/* 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;
+}
diff --git a/jni/native/src/mmap.c b/jni/native/src/mmap.c
new file mode 100644
index 0000000..b560cba
--- /dev/null
+++ b/jni/native/src/mmap.c
@@ -0,0 +1,102 @@
+/* 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
+}
diff --git a/jni/native/src/multicast.c b/jni/native/src/multicast.c
new file mode 100644
index 0000000..5de988c
--- /dev/null
+++ b/jni/native/src/multicast.c
@@ -0,0 +1,75 @@
+/* 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: multicast.c 1442587 2013-02-05 13:49:48Z rjung $
+ */
+
+#include "tcn.h"
+
+TCN_IMPLEMENT_CALL(jint, Multicast, join)(TCN_STDARGS,
+ jlong sock, jlong join,
+ jlong iface, jlong source)
+{
+ tcn_socket_t *s = J2P(sock, tcn_socket_t *);
+ apr_sockaddr_t *ja = J2P(join, apr_sockaddr_t *);
+ apr_sockaddr_t *ia = J2P(iface, apr_sockaddr_t *);
+ apr_sockaddr_t *sa = J2P(source, apr_sockaddr_t *);
+ UNREFERENCED_STDARGS;
+ return (jint)apr_mcast_join(s->sock, ja, ia, sa);
+};
+
+TCN_IMPLEMENT_CALL(jint, Multicast, leave)(TCN_STDARGS,
+ jlong sock, jlong addr,
+ jlong iface, jlong source)
+{
+ tcn_socket_t *s = J2P(sock, tcn_socket_t *);
+ apr_sockaddr_t *aa = J2P(addr, apr_sockaddr_t *);
+ apr_sockaddr_t *ia = J2P(iface, apr_sockaddr_t *);
+ apr_sockaddr_t *sa = J2P(source, apr_sockaddr_t *);
+ UNREFERENCED_STDARGS;
+ return (jint)apr_mcast_leave(s->sock, aa, ia, sa);
+};
+
+TCN_IMPLEMENT_CALL(jint, Multicast, hops)(TCN_STDARGS,
+ jlong sock, jint ttl)
+{
+ tcn_socket_t *s = J2P(sock, tcn_socket_t *);
+ UNREFERENCED_STDARGS;
+ return (jint)apr_mcast_hops(s->sock, (apr_byte_t)ttl);
+};
+
+TCN_IMPLEMENT_CALL(jint, Multicast, loopback)(TCN_STDARGS,
+ jlong sock, jboolean opt)
+{
+ tcn_socket_t *s = J2P(sock, tcn_socket_t *);
+ apr_byte_t on = 0;
+ UNREFERENCED_STDARGS;
+ if (opt)
+ on = 1;
+ return (jint)apr_mcast_loopback(s->sock, on);
+};
+
+TCN_IMPLEMENT_CALL(jint, Multicast, ointerface)(TCN_STDARGS,
+ jlong sock, jlong iface)
+{
+ tcn_socket_t *s = J2P(sock, tcn_socket_t *);
+ apr_sockaddr_t *ia = J2P(iface, apr_sockaddr_t *);
+ UNREFERENCED_STDARGS;
+ return (jint)apr_mcast_interface(s->sock, ia);
+};
diff --git a/jni/native/src/network.c b/jni/native/src/network.c
new file mode 100644
index 0000000..a05132a
--- /dev/null
+++ b/jni/native/src/network.c
@@ -0,0 +1,1446 @@
+/* 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: network.c 1518225 2013-08-28 14:52:00Z schultz $
+ */
+
+#include "tcn.h"
+
+#ifdef TCN_DO_STATISTICS
+
+#include "apr_atomic.h"
+
+static volatile apr_uint32_t sp_created = 0;
+static volatile apr_uint32_t sp_closed = 0;
+static volatile apr_uint32_t sp_cleared = 0;
+static volatile apr_uint32_t sp_accepted = 0;
+static volatile apr_uint32_t sp_max_send = 0;
+static volatile apr_uint32_t sp_min_send = 10000000;
+static volatile apr_uint32_t sp_num_send = 0;
+static volatile apr_off_t sp_tot_send = 0;
+static volatile apr_uint32_t sp_max_recv = 0;
+static volatile apr_uint32_t sp_min_recv = 10000000;
+static volatile apr_uint32_t sp_num_recv = 0;
+static volatile apr_off_t sp_tot_recv = 0;
+static volatile apr_uint32_t sp_err_recv = 0;
+static volatile apr_uint32_t sp_tmo_recv = 0;
+static volatile apr_uint32_t sp_rst_recv = 0;
+static volatile apr_status_t sp_erl_recv = 0;
+
+static volatile apr_size_t sf_max_send = 0;
+static volatile apr_size_t sf_min_send = 10000000;
+static volatile apr_uint32_t sf_num_send = 0;
+static volatile apr_off_t sf_tot_send = 0;
+
+void sp_network_dump_statistics()
+{
+ fprintf(stderr, "Network Statistics ......\n");
+ fprintf(stderr, "Sockets created : %d\n", sp_created);
+ fprintf(stderr, "Sockets accepted : %d\n", sp_accepted);
+ fprintf(stderr, "Sockets closed : %d\n", sp_closed);
+ fprintf(stderr, "Sockets cleared : %d\n", sp_cleared);
+ fprintf(stderr, "Total send calls : %d\n", sp_num_send);
+ fprintf(stderr, "Minimum send length : %d\n", sp_min_send);
+ fprintf(stderr, "Maximum send length : %d\n", sp_max_send);
+ fprintf(stderr, "Average send length : %.2f\n", (double)sp_tot_send/(double)sp_num_send);
+ fprintf(stderr, "Total recv calls : %d\n", sp_num_recv);
+ fprintf(stderr, "Minimum recv length : %d\n", sp_min_recv);
+ fprintf(stderr, "Maximum recv length : %d\n", sp_max_recv);
+ fprintf(stderr, "Average recv length : %.2f\n", (double)sp_tot_recv/(double)sp_num_recv);
+ fprintf(stderr, "Receive timeouts : %d\n", sp_tmo_recv);
+ fprintf(stderr, "Receive errors : %d\n", sp_err_recv);
+ fprintf(stderr, "Receive resets : %d\n", sp_rst_recv);
+ fprintf(stderr, "Last receive error : %d\n", sp_erl_recv);
+
+ fprintf(stderr, "Total sendfile calls : %d\n", sf_num_send);
+ fprintf(stderr, "Minimum sendfile length : %" APR_SIZE_T_FMT "\n", sf_min_send);
+ fprintf(stderr, "Maximum sendfile length : %" APR_SIZE_T_FMT "\n", sf_max_send);
+
+}
+
+#endif /* TCN_DO_STATISTICS */
+
+extern apr_pool_t *tcn_global_pool;
+static apr_status_t sp_socket_cleanup(void *data)
+{
+ tcn_socket_t *s = (tcn_socket_t *)data;
+
+ if (s->net && s->net->cleanup)
+ (*s->net->cleanup)(s->opaque);
+ if (s->sock) {
+ apr_socket_t *as = s->sock;
+ s->sock = NULL;
+ apr_socket_close(as);
+ }
+#ifdef TCN_DO_STATISTICS
+ apr_atomic_inc32(&sp_cleared);
+#endif
+ return APR_SUCCESS;
+}
+
+#if defined(DEBUG) || defined(_DEBUG)
+static APR_INLINE apr_status_t APR_THREAD_FUNC
+APR_socket_send(apr_socket_t *sock, const char *buf, apr_size_t *len)
+{
+ return apr_socket_send(sock, buf, len);
+}
+
+static APR_INLINE apr_status_t APR_THREAD_FUNC
+APR_socket_recv(apr_socket_t *sock, char *buf, apr_size_t *len)
+{
+ return apr_socket_recv(sock, buf, len);
+}
+
+static APR_INLINE apr_status_t APR_THREAD_FUNC
+APR_socket_sendv(apr_socket_t *sock, const struct iovec *vec,
+ apr_int32_t nvec, apr_size_t *len)
+{
+ return apr_socket_sendv(sock, vec, nvec, len);
+}
+
+static APR_INLINE apr_status_t APR_THREAD_FUNC
+APR_socket_shutdown(apr_socket_t *sock, apr_shutdown_how_e how)
+{
+ return apr_socket_shutdown(sock, how);
+}
+
+static APR_INLINE apr_status_t APR_THREAD_FUNC
+APR_socket_timeout_set(apr_socket_t *sock, apr_interval_time_t t)
+{
+ return apr_socket_timeout_set(sock, t);
+}
+
+static APR_INLINE apr_status_t APR_THREAD_FUNC
+APR_socket_timeout_get(apr_socket_t *sock, apr_interval_time_t *t)
+{
+ return apr_socket_timeout_get(sock, t);
+}
+
+static APR_INLINE apr_status_t APR_THREAD_FUNC
+APR_socket_opt_set(apr_socket_t *sock, apr_int32_t opt, apr_int32_t on)
+{
+ return apr_socket_opt_set(sock, opt, on);
+}
+
+static APR_INLINE apr_status_t APR_THREAD_FUNC
+APR_socket_opt_get(apr_socket_t *sock, apr_int32_t opt, apr_int32_t *on)
+{
+ return apr_socket_opt_get(sock, opt, on);
+}
+
+#else
+#define APR_socket_send apr_socket_send
+#define APR_socket_recv apr_socket_recv
+#define APR_socket_sendv apr_socket_sendv
+#define APR_socket_shutdown apr_socket_shutdown
+#define APR_socket_timeout_set apr_socket_timeout_set
+#define APR_socket_timeout_get apr_socket_timeout_get
+#define APR_socket_opt_set apr_socket_opt_set
+#define APR_socket_opt_get apr_socket_opt_get
+#endif
+
+static tcn_nlayer_t apr_socket_layer = {
+ TCN_SOCKET_APR,
+ NULL,
+ NULL,
+ APR_socket_shutdown,
+ APR_socket_opt_get,
+ APR_socket_opt_set,
+ APR_socket_timeout_get,
+ APR_socket_timeout_set,
+ APR_socket_send,
+ APR_socket_sendv,
+ APR_socket_recv
+};
+
+TCN_IMPLEMENT_CALL(jlong, Socket, create)(TCN_STDARGS, jint family,
+ jint type, jint protocol,
+ jlong pool)
+{
+ apr_pool_t *p = J2P(pool, apr_pool_t *);
+ apr_pool_t *c = NULL;
+ apr_socket_t *s = NULL;
+ tcn_socket_t *a = NULL;
+ apr_int32_t f, t;
+
+ UNREFERENCED(o);
+ TCN_ASSERT(pool != 0);
+ GET_S_FAMILY(f, family);
+ GET_S_TYPE(t, type);
+
+ TCN_THROW_IF_ERR(apr_pool_create(&c, p), c);
+
+ a = (tcn_socket_t *)apr_pcalloc(c, sizeof(tcn_socket_t));
+ TCN_CHECK_ALLOCATED(a);
+ TCN_THROW_IF_ERR(apr_pool_create(&a->child, c), a->child);
+ a->pool = c;
+
+ if (family >= 0) {
+ a->net = &apr_socket_layer;
+ TCN_THROW_IF_ERR(apr_socket_create(&s,
+ f, t, protocol, c), a);
+ }
+ apr_pool_cleanup_register(c, (const void *)a,
+ sp_socket_cleanup,
+ apr_pool_cleanup_null);
+
+#ifdef TCN_DO_STATISTICS
+ sp_created++;
+#endif
+ a->sock = s;
+ if (family >= 0)
+ a->net = &apr_socket_layer;
+ a->opaque = s;
+ return P2J(a);
+cleanup:
+ if (c)
+ apr_pool_destroy(c);
+ return 0;
+
+}
+
+TCN_IMPLEMENT_CALL(void, Socket, destroy)(TCN_STDARGS, jlong sock)
+{
+ tcn_socket_t *s = J2P(sock, tcn_socket_t *);
+ apr_socket_t *as;
+ UNREFERENCED_STDARGS;
+ TCN_ASSERT(sock != 0);
+
+ as = s->sock;
+ s->sock = NULL;
+ apr_pool_cleanup_kill(s->pool, s, sp_socket_cleanup);
+ if (s->net && s->net->cleanup) {
+ (*s->net->cleanup)(s->opaque);
+ s->net = NULL;
+ }
+ if (as) {
+ apr_socket_close(as);
+ }
+
+ apr_pool_destroy(s->pool);
+}
+
+TCN_IMPLEMENT_CALL(jlong, Socket, pool)(TCN_STDARGS, jlong sock)
+{
+ tcn_socket_t *s = J2P(sock, tcn_socket_t *);
+ apr_pool_t *n;
+
+ UNREFERENCED(o);
+ TCN_ASSERT(sock != 0);
+ TCN_THROW_IF_ERR(apr_pool_create(&n, s->pool), n);
+cleanup:
+ return P2J(n);
+}
+
+TCN_IMPLEMENT_CALL(jlong, Socket, get)(TCN_STDARGS, jlong sock, jint what)
+{
+ tcn_socket_t *s = J2P(sock, tcn_socket_t *);
+ UNREFERENCED_STDARGS;
+ TCN_ASSERT(sock != 0);
+
+ switch (what) {
+ case TCN_SOCKET_GET_POOL:
+ return P2J(s->pool);
+ break;
+ case TCN_SOCKET_GET_IMPL:
+ return P2J(s->opaque);
+ break;
+ case TCN_SOCKET_GET_APRS:
+ return P2J(s->sock);
+ break;
+ case TCN_SOCKET_GET_TYPE:
+ return (jlong)(s->net->type);
+ break;
+ }
+ return 0;
+}
+
+TCN_IMPLEMENT_CALL(jint, Socket, shutdown)(TCN_STDARGS, jlong sock,
+ jint how)
+{
+ tcn_socket_t *s = J2P(sock, tcn_socket_t *);
+
+ UNREFERENCED_STDARGS;
+ TCN_ASSERT(sock != 0);
+ return (jint)(*s->net->shutdown)(s->opaque, how);
+}
+
+TCN_IMPLEMENT_CALL(jint, Socket, close)(TCN_STDARGS, jlong sock)
+{
+ tcn_socket_t *s = J2P(sock, tcn_socket_t *);
+ jint rv = APR_SUCCESS;
+ apr_socket_t *as;
+ UNREFERENCED_STDARGS;
+ TCN_ASSERT(sock != 0);
+
+ as = s->sock;
+ s->sock = NULL;
+ apr_pool_cleanup_kill(s->pool, s, sp_socket_cleanup);
+ if (s->child) {
+ apr_pool_clear(s->child);
+ }
+#ifdef TCN_DO_STATISTICS
+ apr_atomic_inc32(&sp_closed);
+#endif
+ if (s->net && s->net->close) {
+ rv = (*s->net->close)(s->opaque);
+ s->net = NULL;
+ }
+ if (as) {
+ rv = (jint)apr_socket_close(as);
+ }
+ return rv;
+}
+
+TCN_IMPLEMENT_CALL(jint, Socket, bind)(TCN_STDARGS, jlong sock,
+ jlong sa)
+{
+ jint rv = APR_SUCCESS;
+ tcn_socket_t *s = J2P(sock, tcn_socket_t *);
+ apr_sockaddr_t *a = J2P(sa, apr_sockaddr_t *);
+
+ UNREFERENCED_STDARGS;
+ TCN_ASSERT(sock != 0);
+ TCN_ASSERT(s->sock != NULL);
+ rv = (jint)apr_socket_bind(s->sock, a);
+ return rv;
+}
+
+TCN_IMPLEMENT_CALL(jint, Socket, listen)(TCN_STDARGS, jlong sock,
+ jint backlog)
+{
+ tcn_socket_t *s = J2P(sock, tcn_socket_t *);
+
+ UNREFERENCED_STDARGS;
+ TCN_ASSERT(sock != 0);
+ TCN_ASSERT(s->sock != NULL);
+ return (jint)apr_socket_listen(s->sock, backlog);
+}
+
+TCN_IMPLEMENT_CALL(jlong, Socket, acceptx)(TCN_STDARGS, jlong sock,
+ jlong pool)
+{
+ tcn_socket_t *s = J2P(sock, tcn_socket_t *);
+ apr_pool_t *p = J2P(pool, apr_pool_t *);
+ apr_socket_t *n = NULL;
+ tcn_socket_t *a = NULL;
+
+ UNREFERENCED(o);
+ TCN_ASSERT(sock != 0);
+
+ if (s->net->type == TCN_SOCKET_APR) {
+ TCN_ASSERT(s->sock != NULL);
+ a = (tcn_socket_t *)apr_pcalloc(p, sizeof(tcn_socket_t));
+ TCN_CHECK_ALLOCATED(a);
+ a->pool = p;
+ apr_pool_cleanup_register(a->pool, (const void *)a,
+ sp_socket_cleanup,
+ apr_pool_cleanup_null);
+
+ TCN_THROW_IF_ERR(apr_socket_accept(&n, s->sock, p), n);
+ }
+ else {
+ tcn_ThrowAPRException(e, APR_ENOTIMPL);
+ goto cleanup;
+ }
+ if (n) {
+#ifdef TCN_DO_STATISTICS
+ apr_atomic_inc32(&sp_accepted);
+#endif
+ a->net = &apr_socket_layer;
+ a->sock = n;
+ a->opaque = n;
+ }
+
+cleanup:
+ return P2J(a);
+}
+
+TCN_IMPLEMENT_CALL(jlong, Socket, accept)(TCN_STDARGS, jlong sock)
+{
+ tcn_socket_t *s = J2P(sock, tcn_socket_t *);
+ apr_pool_t *p = NULL;
+ apr_socket_t *n = NULL;
+ tcn_socket_t *a = NULL;
+
+ UNREFERENCED(o);
+ TCN_ASSERT(sock != 0);
+
+ TCN_THROW_IF_ERR(apr_pool_create(&p, s->child), p);
+ if (s->net->type == TCN_SOCKET_APR) {
+ TCN_ASSERT(s->sock != NULL);
+ a = (tcn_socket_t *)apr_pcalloc(p, sizeof(tcn_socket_t));
+ TCN_CHECK_ALLOCATED(a);
+ TCN_THROW_IF_ERR(apr_socket_accept(&n, s->sock, p), n);
+
+ a->pool = p;
+ apr_pool_cleanup_register(a->pool, (const void *)a,
+ sp_socket_cleanup,
+ apr_pool_cleanup_null);
+
+ }
+ else {
+ tcn_ThrowAPRException(e, APR_ENOTIMPL);
+ goto cleanup;
+ }
+ if (n) {
+#ifdef TCN_DO_STATISTICS
+ apr_atomic_inc32(&sp_accepted);
+#endif
+ a->net = &apr_socket_layer;
+ a->sock = n;
+ a->opaque = n;
+ }
+ return P2J(a);
+cleanup:
+ if (tcn_global_pool && p && s->sock)
+ apr_pool_destroy(p);
+ return 0;
+}
+
+TCN_IMPLEMENT_CALL(jint, Socket, connect)(TCN_STDARGS, jlong sock,
+ jlong sa)
+{
+ tcn_socket_t *s = J2P(sock, tcn_socket_t *);
+ apr_sockaddr_t *a = J2P(sa, apr_sockaddr_t *);
+
+ UNREFERENCED_STDARGS;
+ TCN_ASSERT(sock != 0);
+ TCN_ASSERT(s->sock != NULL);
+ return (jint)apr_socket_connect(s->sock, a);
+}
+
+TCN_IMPLEMENT_CALL(jint, Socket, send)(TCN_STDARGS, jlong sock,
+ jbyteArray buf, jint offset, jint tosend)
+{
+ tcn_socket_t *s = J2P(sock, tcn_socket_t *);
+ apr_size_t nbytes = (apr_size_t)tosend;
+ apr_status_t ss;
+
+ UNREFERENCED(o);
+ if (!sock) {
+ tcn_ThrowAPRException(e, APR_ENOTSOCK);
+ return -(jint)APR_ENOTSOCK;
+ }
+ TCN_ASSERT(s->opaque != NULL);
+ if(!s->net) {
+ tcn_ThrowAPRException(e, APR_EINVALSOCK);
+ return -(jint)APR_EINVALSOCK;
+ }
+#ifdef TCN_DO_STATISTICS
+ sp_max_send = TCN_MAX(sp_max_send, nbytes);
+ sp_min_send = TCN_MIN(sp_min_send, nbytes);
+ sp_tot_send += nbytes;
+ sp_num_send++;
+#endif
+
+ if (tosend <= TCN_BUFFER_SZ) {
+ jbyte sb[TCN_BUFFER_SZ];
+ (*e)->GetByteArrayRegion(e, buf, offset, tosend, &sb[0]);
+ ss = (*s->net->send)(s->opaque, (const char *)&sb[0], &nbytes);
+ }
+ else {
+ jbyte *sb = (jbyte *)malloc(nbytes);
+ if (sb == NULL)
+ return -APR_ENOMEM;
+ (*e)->GetByteArrayRegion(e, buf, offset, tosend, sb);
+ ss = (*s->net->send)(s->opaque, (const char *)sb, &nbytes);
+ free(sb);
+ }
+ if (ss == APR_SUCCESS || ((APR_STATUS_IS_EAGAIN(ss) || ss == TCN_EAGAIN) && nbytes > 0))
+ return (jint)nbytes;
+ else {
+ TCN_ERROR_WRAP(ss);
+ return -(jint)ss;
+ }
+}
+
+TCN_IMPLEMENT_CALL(void, Socket, setsbb)(TCN_STDARGS, jlong sock,
+ jobject buf)
+{
+ tcn_socket_t *s = J2P(sock, tcn_socket_t *);
+ UNREFERENCED(o);
+ if (!sock) {
+ tcn_ThrowAPRException(e, APR_ENOTSOCK);
+ return;
+ }
+ TCN_ASSERT(s->opaque != NULL);
+ if (buf)
+ s->jsbbuff = (char *)(*e)->GetDirectBufferAddress(e, buf);
+ else
+ s->jsbbuff = NULL;
+}
+
+TCN_IMPLEMENT_CALL(void, Socket, setrbb)(TCN_STDARGS, jlong sock,
+ jobject buf)
+{
+ tcn_socket_t *s = J2P(sock, tcn_socket_t *);
+ UNREFERENCED(o);
+ if (!sock) {
+ tcn_ThrowAPRException(e, APR_ENOTSOCK);
+ return;
+ }
+ TCN_ASSERT(s->opaque != NULL);
+ if (buf)
+ s->jrbbuff = (char *)(*e)->GetDirectBufferAddress(e, buf);
+ else
+ s->jrbbuff = NULL;
+}
+
+TCN_IMPLEMENT_CALL(jint, Socket, sendb)(TCN_STDARGS, jlong sock,
+ jobject buf, jint offset, jint len)
+{
+ tcn_socket_t *s = J2P(sock, tcn_socket_t *);
+ apr_size_t nbytes = (apr_size_t)len;
+ apr_size_t sent = 0;
+ char *bytes;
+ apr_status_t ss = APR_SUCCESS;
+
+ UNREFERENCED(o);
+ if (!sock) {
+ tcn_ThrowAPRException(e, APR_ENOTSOCK);
+ return -(jint)APR_ENOTSOCK;
+ }
+ TCN_ASSERT(s->opaque != NULL);
+ TCN_ASSERT(buf != NULL);
+ if(!s->net) {
+ tcn_ThrowAPRException(e, APR_EINVALSOCK);
+ return -(jint)APR_EINVALSOCK;
+ }
+#ifdef TCN_DO_STATISTICS
+ sp_max_send = TCN_MAX(sp_max_send, nbytes);
+ sp_min_send = TCN_MIN(sp_min_send, nbytes);
+ sp_tot_send += nbytes;
+ sp_num_send++;
+#endif
+
+ bytes = (char *)(*e)->GetDirectBufferAddress(e, buf);
+
+ while (sent < nbytes) {
+ apr_size_t wr = nbytes - sent;
+ ss = (*s->net->send)(s->opaque, bytes + offset + sent, &wr);
+ if (ss != APR_SUCCESS)
+ break;
+ sent += wr;
+ }
+
+ if (ss == APR_SUCCESS || ((APR_STATUS_IS_EAGAIN(ss) || ss == TCN_EAGAIN) && sent > 0))
+ return (jint)sent;
+ else {
+ TCN_ERROR_WRAP(ss);
+ return -(jint)ss;
+ }
+}
+
+TCN_IMPLEMENT_CALL(jint, Socket, sendib)(TCN_STDARGS, jlong sock,
+ jobject buf, jint offset, jint len)
+{
+ tcn_socket_t *s = J2P(sock, tcn_socket_t *);
+ apr_size_t nbytes = (apr_size_t)len;
+ char *bytes;
+ apr_status_t ss = APR_SUCCESS;
+
+ UNREFERENCED(o);
+ if (!sock) {
+ tcn_ThrowAPRException(e, APR_ENOTSOCK);
+ return -(jint)APR_ENOTSOCK;
+ }
+ TCN_ASSERT(s->opaque != NULL);
+ TCN_ASSERT(buf != NULL);
+ if(!s->net) {
+ tcn_ThrowAPRException(e, APR_EINVALSOCK);
+ return -(jint)APR_EINVALSOCK;
+ }
+#ifdef TCN_DO_STATISTICS
+ sp_max_send = TCN_MAX(sp_max_send, nbytes);
+ sp_min_send = TCN_MIN(sp_min_send, nbytes);
+ sp_tot_send += nbytes;
+ sp_num_send++;
+#endif
+
+ bytes = (char *)(*e)->GetDirectBufferAddress(e, buf);
+
+ ss = (*s->net->send)(s->opaque, bytes + offset, &nbytes);
+
+ if (ss == APR_SUCCESS || ((APR_STATUS_IS_EAGAIN(ss) || ss == TCN_EAGAIN) && nbytes > 0))
+ return (jint)nbytes;
+ else {
+ TCN_ERROR_WRAP(ss);
+ return -(jint)ss;
+ }
+}
+
+TCN_IMPLEMENT_CALL(jint, Socket, sendbb)(TCN_STDARGS, jlong sock,
+ jint offset, jint len)
+{
+ tcn_socket_t *s = J2P(sock, tcn_socket_t *);
+ apr_size_t nbytes = (apr_size_t)len;
+ apr_size_t sent = 0;
+ apr_status_t ss = APR_SUCCESS;
+
+ UNREFERENCED(o);
+ if (!sock) {
+ tcn_ThrowAPRException(e, APR_ENOTSOCK);
+ return -(jint)APR_ENOTSOCK;
+ }
+ TCN_ASSERT(s->opaque != NULL);
+ TCN_ASSERT(s->jsbbuff != NULL);
+ if(!s->net) {
+ tcn_ThrowAPRException(e, APR_EINVALSOCK);
+ return -(jint)APR_EINVALSOCK;
+ }
+#ifdef TCN_DO_STATISTICS
+ sp_max_send = TCN_MAX(sp_max_send, nbytes);
+ sp_min_send = TCN_MIN(sp_min_send, nbytes);
+ sp_tot_send += nbytes;
+ sp_num_send++;
+#endif
+
+ while (sent < nbytes) {
+ apr_size_t wr = nbytes - sent;
+ ss = (*s->net->send)(s->opaque, s->jsbbuff + offset + sent, &wr);
+ if (ss != APR_SUCCESS || wr == 0)
+ break;
+ sent += wr;
+ }
+ if (ss == APR_SUCCESS || ((APR_STATUS_IS_EAGAIN(ss) || ss == TCN_EAGAIN) && sent > 0))
+ return (jint)sent;
+ else {
+ TCN_ERROR_WRAP(ss);
+ return -(jint)ss;
+ }
+}
+
+TCN_IMPLEMENT_CALL(jint, Socket, sendibb)(TCN_STDARGS, jlong sock,
+ jint offset, jint len)
+{
+ tcn_socket_t *s = J2P(sock, tcn_socket_t *);
+ apr_size_t nbytes = (apr_size_t)len;
+ apr_status_t ss = APR_SUCCESS;
+
+ UNREFERENCED(o);
+ if (!sock) {
+ tcn_ThrowAPRException(e, APR_ENOTSOCK);
+ return -(jint)APR_ENOTSOCK;
+ }
+ TCN_ASSERT(s->opaque != NULL);
+ TCN_ASSERT(s->jsbbuff != NULL);
+ if(!s->net) {
+ tcn_ThrowAPRException(e, APR_EINVALSOCK);
+ return -(jint)APR_EINVALSOCK;
+ }
+#ifdef TCN_DO_STATISTICS
+ sp_max_send = TCN_MAX(sp_max_send, nbytes);
+ sp_min_send = TCN_MIN(sp_min_send, nbytes);
+ sp_tot_send += nbytes;
+ sp_num_send++;
+#endif
+
+ ss = (*s->net->send)(s->opaque, s->jsbbuff + offset, &nbytes);
+
+ if (ss == APR_SUCCESS || ((APR_STATUS_IS_EAGAIN(ss) || ss == TCN_EAGAIN) && nbytes > 0))
+ return (jint)nbytes;
+ else {
+ TCN_ERROR_WRAP(ss);
+ return -(jint)ss;
+ }
+}
+
+TCN_IMPLEMENT_CALL(jint, Socket, sendv)(TCN_STDARGS, jlong sock,
+ jobjectArray bufs)
+{
+ tcn_socket_t *s = J2P(sock, tcn_socket_t *);
+ jsize nvec;
+ 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);
+ TCN_ASSERT(sock != 0);
+ TCN_ASSERT(s->opaque != NULL);
+ if(!s->net) {
+ tcn_ThrowAPRException(e, APR_EINVALSOCK);
+ return -(jint)APR_EINVALSOCK;
+ }
+
+ nvec = (*e)->GetArrayLength(e, bufs);
+ if (nvec >= APR_MAX_IOVEC_SIZE)
+ return (jint)(-APR_ENOMEM);
+
+ 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 = (*s->net->sendv)(s->opaque, 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 || ((APR_STATUS_IS_EAGAIN(ss) || ss == TCN_EAGAIN) && written > 0))
+ return (jint)written;
+ else {
+ TCN_ERROR_WRAP(ss);
+ return -(jint)ss;
+ }
+}
+
+TCN_IMPLEMENT_CALL(jint, Socket, sendto)(TCN_STDARGS, jlong sock,
+ jlong where, jint flag,
+ jbyteArray buf, jint offset, jint tosend)
+{
+ tcn_socket_t *s = J2P(sock, tcn_socket_t *);
+ apr_sockaddr_t *w = J2P(where, apr_sockaddr_t *);
+ apr_size_t nbytes = (apr_size_t)tosend;
+ jbyte *bytes;
+ apr_int32_t nb;
+ apr_status_t ss;
+
+ UNREFERENCED(o);
+ TCN_ASSERT(sock != 0);
+ TCN_ASSERT(s->sock != NULL);
+
+ bytes = (*e)->GetByteArrayElements(e, buf, NULL);
+ TCN_ASSERT(bytes != NULL);
+ apr_socket_opt_get(s->sock, APR_SO_NONBLOCK, &nb);
+ if (nb)
+ bytes = (*e)->GetPrimitiveArrayCritical(e, buf, NULL);
+ else
+ bytes = (*e)->GetByteArrayElements(e, buf, NULL);
+ ss = apr_socket_sendto(s->sock, w, flag, (char *)(bytes + offset), &nbytes);
+
+ if (nb)
+ (*e)->ReleasePrimitiveArrayCritical(e, buf, bytes, 0);
+ else
+ (*e)->ReleaseByteArrayElements(e, buf, bytes, JNI_ABORT);
+ if (ss == APR_SUCCESS)
+ return (jint)nbytes;
+ else {
+ TCN_ERROR_WRAP(ss);
+ return -(jint)ss;
+ }
+}
+
+TCN_IMPLEMENT_CALL(jint, Socket, recv)(TCN_STDARGS, jlong sock,
+ jbyteArray buf, jint offset, jint toread)
+{
+ tcn_socket_t *s = J2P(sock, tcn_socket_t *);
+ apr_size_t nbytes = (apr_size_t)toread;
+ apr_status_t ss;
+
+ UNREFERENCED(o);
+ TCN_ASSERT(sock != 0);
+ TCN_ASSERT(s->opaque != NULL);
+ if(!s->net) {
+ tcn_ThrowAPRException(e, APR_EINVALSOCK);
+ return -(jint)APR_EINVALSOCK;
+ }
+
+ if (toread <= TCN_BUFFER_SZ) {
+ char sb[TCN_BUFFER_SZ];
+
+ if ((ss = (*s->net->recv)(s->opaque, sb, &nbytes)) == APR_SUCCESS)
+ (*e)->SetByteArrayRegion(e, buf, offset, (jsize)nbytes, (jbyte*)&sb[0]);
+ }
+ else {
+ jbyte *bytes = (*e)->GetByteArrayElements(e, buf, NULL);
+ if ((ss = (*s->net->recv)(s->opaque, (char*)(bytes + offset),
+ &nbytes)) == APR_SUCCESS)
+ (*e)->ReleaseByteArrayElements(e, buf, bytes,
+ nbytes ? 0 : JNI_ABORT);
+ }
+#ifdef TCN_DO_STATISTICS
+ if (ss == APR_SUCCESS) {
+ sp_max_recv = TCN_MAX(sp_max_recv, nbytes);
+ sp_min_recv = TCN_MIN(sp_min_recv, nbytes);
+ sp_tot_recv += nbytes;
+ sp_num_recv++;
+ }
+ else {
+ if (APR_STATUS_IS_ETIMEDOUT(ss) ||
+ APR_STATUS_IS_TIMEUP(ss))
+ sp_tmo_recv++;
+ else if (APR_STATUS_IS_ECONNABORTED(ss) ||
+ APR_STATUS_IS_ECONNRESET(ss) ||
+ APR_STATUS_IS_EOF(ss))
+ sp_rst_recv++;
+ else {
+ sp_err_recv++;
+ sp_erl_recv = ss;
+ }
+ }
+#endif
+ if (ss == APR_SUCCESS)
+ return (jint)nbytes;
+ else {
+ TCN_ERROR_WRAP(ss);
+ return -(jint)ss;
+ }
+}
+
+TCN_IMPLEMENT_CALL(jint, Socket, recvt)(TCN_STDARGS, jlong sock,
+ jbyteArray buf, jint offset,
+ jint toread, jlong timeout)
+{
+ tcn_socket_t *s = J2P(sock, tcn_socket_t *);
+ apr_size_t nbytes = (apr_size_t)toread;
+ apr_status_t ss;
+ apr_interval_time_t pt;
+ apr_interval_time_t nt = J2T(timeout);
+
+ UNREFERENCED(o);
+ TCN_ASSERT(sock != 0);
+ TCN_ASSERT(s->opaque != NULL);
+ TCN_ASSERT(buf != NULL);
+ if(!s->net) {
+ tcn_ThrowAPRException(e, APR_EINVALSOCK);
+ return -(jint)APR_EINVALSOCK;
+ }
+
+ if ((ss = (*s->net->timeout_get)(s->opaque, &pt)) != APR_SUCCESS) {
+ TCN_ERROR_WRAP(ss);
+ return -(jint)ss;
+ }
+ if (pt != nt) {
+ if ((ss = (*s->net->timeout_set)(s->opaque, nt)) != APR_SUCCESS)
+ goto cleanup;
+ }
+ if (toread <= TCN_BUFFER_SZ) {
+ jbyte sb[TCN_BUFFER_SZ];
+ if ((ss = (*s->net->recv)(s->opaque, (char *)&sb[0], &nbytes)) == APR_SUCCESS)
+ (*e)->SetByteArrayRegion(e, buf, offset, (jsize)nbytes, &sb[0]);
+ }
+ else {
+ jbyte *sb = (jbyte *)malloc(nbytes);
+ if (sb == NULL)
+ return -APR_ENOMEM;
+ if ((ss = (*s->net->recv)(s->opaque, (char *)sb, &nbytes)) == APR_SUCCESS)
+ (*e)->SetByteArrayRegion(e, buf, offset, (jsize)nbytes, &sb[0]);
+ free(sb);
+ }
+ if (pt != nt) {
+ if ((ss = (*s->net->timeout_set)(s->opaque, pt)) != APR_SUCCESS)
+ goto cleanup;
+ }
+
+#ifdef TCN_DO_STATISTICS
+ if (ss == APR_SUCCESS) {
+ sp_max_recv = TCN_MAX(sp_max_recv, nbytes);
+ sp_min_recv = TCN_MIN(sp_min_recv, nbytes);
+ sp_tot_recv += nbytes;
+ sp_num_recv++;
+ }
+ else {
+ if (APR_STATUS_IS_ETIMEDOUT(ss) ||
+ APR_STATUS_IS_TIMEUP(ss))
+ sp_tmo_recv++;
+ else if (APR_STATUS_IS_ECONNABORTED(ss) ||
+ APR_STATUS_IS_ECONNRESET(ss) ||
+ APR_STATUS_IS_EOF(ss))
+ sp_rst_recv++;
+ else {
+ sp_err_recv++;
+ sp_erl_recv = ss;
+ }
+ }
+#endif
+cleanup:
+ if (ss == APR_SUCCESS)
+ return (jint)nbytes;
+ else {
+ TCN_ERROR_WRAP(ss);
+ return -(jint)ss;
+ }
+}
+
+TCN_IMPLEMENT_CALL(jint, Socket, recvb)(TCN_STDARGS, jlong sock,
+ jobject buf, jint offset, jint len)
+{
+ tcn_socket_t *s = J2P(sock, tcn_socket_t *);
+ apr_status_t ss;
+ apr_size_t nbytes = (apr_size_t)len;
+ char *bytes;
+
+ UNREFERENCED(o);
+ if (!sock) {
+ tcn_ThrowAPRException(e, APR_ENOTSOCK);
+ return -(jint)APR_ENOTSOCK;
+ }
+ TCN_ASSERT(s->opaque != NULL);
+ TCN_ASSERT(buf != NULL);
+ if(!s->net) {
+ tcn_ThrowAPRException(e, APR_EINVALSOCK);
+ return -(jint)APR_EINVALSOCK;
+ }
+
+ bytes = (char *)(*e)->GetDirectBufferAddress(e, buf);
+ TCN_ASSERT(bytes != NULL);
+ ss = (*s->net->recv)(s->opaque, bytes + offset, &nbytes);
+#ifdef TCN_DO_STATISTICS
+ if (ss == APR_SUCCESS) {
+ sp_max_recv = TCN_MAX(sp_max_recv, nbytes);
+ sp_min_recv = TCN_MIN(sp_min_recv, nbytes);
+ sp_tot_recv += nbytes;
+ sp_num_recv++;
+ }
+ else {
+ if (APR_STATUS_IS_ETIMEDOUT(ss) ||
+ APR_STATUS_IS_TIMEUP(ss))
+ sp_tmo_recv++;
+ else if (APR_STATUS_IS_ECONNABORTED(ss) ||
+ APR_STATUS_IS_ECONNRESET(ss) ||
+ APR_STATUS_IS_EOF(ss))
+ sp_rst_recv++;
+ else {
+ sp_err_recv++;
+ sp_erl_recv = ss;
+ }
+ }
+#endif
+ if (ss == APR_SUCCESS)
+ return (jint)nbytes;
+ else {
+ TCN_ERROR_WRAP(ss);
+ return -(jint)ss;
+ }
+}
+
+TCN_IMPLEMENT_CALL(jint, Socket, recvbb)(TCN_STDARGS, jlong sock,
+ jint offset, jint len)
+{
+ tcn_socket_t *s = J2P(sock, tcn_socket_t *);
+ apr_status_t ss;
+ apr_size_t nbytes = (apr_size_t)len;
+
+ UNREFERENCED(o);
+ if (!sock) {
+ tcn_ThrowAPRException(e, APR_ENOTSOCK);
+ return -(jint)APR_ENOTSOCK;
+ }
+ TCN_ASSERT(sock != 0);
+ TCN_ASSERT(s->opaque != NULL);
+ TCN_ASSERT(s->jrbbuff != NULL);
+ if(!s->net) {
+ tcn_ThrowAPRException(e, APR_EINVALSOCK);
+ return -(jint)APR_EINVALSOCK;
+ }
+
+ ss = (*s->net->recv)(s->opaque, s->jrbbuff + offset, &nbytes);
+#ifdef TCN_DO_STATISTICS
+ if (ss == APR_SUCCESS) {
+ sp_max_recv = TCN_MAX(sp_max_recv, nbytes);
+ sp_min_recv = TCN_MIN(sp_min_recv, nbytes);
+ sp_tot_recv += nbytes;
+ sp_num_recv++;
+ }
+ else {
+ if (APR_STATUS_IS_ETIMEDOUT(ss) ||
+ APR_STATUS_IS_TIMEUP(ss))
+ sp_tmo_recv++;
+ else if (APR_STATUS_IS_ECONNABORTED(ss) ||
+ APR_STATUS_IS_ECONNRESET(ss) ||
+ APR_STATUS_IS_EOF(ss))
+ sp_rst_recv++;
+ else {
+ sp_err_recv++;
+ sp_erl_recv = ss;
+ }
+ }
+#endif
+ if (ss == APR_SUCCESS)
+ return (jint)nbytes;
+ else if (APR_STATUS_IS_EOF(ss))
+ return 0;
+ else {
+ TCN_ERROR_WRAP(ss);
+ return -(jint)ss;
+ }
+}
+
+TCN_IMPLEMENT_CALL(jint, Socket, recvbt)(TCN_STDARGS, jlong sock,
+ jobject buf, jint offset,
+ jint len, jlong timeout)
+{
+ tcn_socket_t *s = J2P(sock, tcn_socket_t *);
+ apr_status_t ss;
+ apr_size_t nbytes = (apr_size_t)len;
+ char *bytes;
+ apr_interval_time_t pt;
+ apr_interval_time_t nt = J2T(timeout);
+
+ UNREFERENCED(o);
+ if (!sock) {
+ tcn_ThrowAPRException(e, APR_ENOTSOCK);
+ return -(jint)APR_ENOTSOCK;
+ }
+ TCN_ASSERT(buf != NULL);
+ TCN_ASSERT(s->opaque != NULL);
+ if(!s->net) {
+ tcn_ThrowAPRException(e, APR_EINVALSOCK);
+ return -(jint)APR_EINVALSOCK;
+ }
+
+ bytes = (char *)(*e)->GetDirectBufferAddress(e, buf);
+ TCN_ASSERT(bytes != NULL);
+
+ if ((ss = (*s->net->timeout_get)(s->opaque, &pt)) != APR_SUCCESS) {
+ TCN_ERROR_WRAP(ss);
+ return -(jint)ss;
+ }
+ if (pt != nt) {
+ if ((ss = (*s->net->timeout_set)(s->opaque, nt)) != APR_SUCCESS) {
+ TCN_ERROR_WRAP(ss);
+ return -(jint)ss;
+ }
+ }
+ ss = (*s->net->recv)(s->opaque, bytes + offset, &nbytes);
+ if (pt != nt) {
+ if ((ss = (*s->net->timeout_set)(s->opaque, pt)) != APR_SUCCESS) {
+ TCN_ERROR_WRAP(ss);
+ return -(jint)ss;
+ }
+ }
+
+#ifdef TCN_DO_STATISTICS
+ if (ss == APR_SUCCESS) {
+ sp_max_recv = TCN_MAX(sp_max_recv, nbytes);
+ sp_min_recv = TCN_MIN(sp_min_recv, nbytes);
+ sp_tot_recv += nbytes;
+ sp_num_recv++;
+ }
+ else {
+ if (APR_STATUS_IS_ETIMEDOUT(ss) ||
+ APR_STATUS_IS_TIMEUP(ss))
+ sp_tmo_recv++;
+ else if (APR_STATUS_IS_ECONNABORTED(ss) ||
+ APR_STATUS_IS_ECONNRESET(ss) ||
+ APR_STATUS_IS_EOF(ss))
+ sp_rst_recv++;
+ else {
+ sp_err_recv++;
+ sp_erl_recv = ss;
+ }
+ }
+#endif
+ if (ss == APR_SUCCESS)
+ return (jint)nbytes;
+ else {
+ TCN_ERROR_WRAP(ss);
+ return -(jint)ss;
+ }
+}
+
+TCN_IMPLEMENT_CALL(jint, Socket, recvbbt)(TCN_STDARGS, jlong sock,
+ jint offset,
+ jint len, jlong timeout)
+{
+ tcn_socket_t *s = J2P(sock, tcn_socket_t *);
+ apr_status_t ss;
+ apr_size_t nbytes = (apr_size_t)len;
+ apr_interval_time_t pt;
+ apr_interval_time_t nt = J2T(timeout);
+
+ UNREFERENCED_STDARGS;
+ UNREFERENCED(o);
+ if (!sock) {
+ tcn_ThrowAPRException(e, APR_ENOTSOCK);
+ return -(jint)APR_ENOTSOCK;
+ }
+ TCN_ASSERT(s->jrbbuff != NULL);
+ TCN_ASSERT(s->opaque != NULL);
+ if(!s->net) {
+ tcn_ThrowAPRException(e, APR_EINVALSOCK);
+ return -(jint)APR_EINVALSOCK;
+ }
+
+ if ((ss = (*s->net->timeout_get)(s->opaque, &pt)) != APR_SUCCESS) {
+ TCN_ERROR_WRAP(ss);
+ return -(jint)ss;
+ }
+ if (pt != nt) {
+ if ((ss = (*s->net->timeout_set)(s->opaque, nt)) != APR_SUCCESS) {
+ TCN_ERROR_WRAP(ss);
+ return -(jint)ss;
+ }
+ }
+ ss = (*s->net->recv)(s->opaque, s->jrbbuff + offset, &nbytes);
+ if (pt != nt) {
+ if ((ss = (*s->net->timeout_set)(s->opaque, pt)) != APR_SUCCESS) {
+ TCN_ERROR_WRAP(ss);
+ return -(jint)ss;
+ }
+ }
+
+#ifdef TCN_DO_STATISTICS
+ if (ss == APR_SUCCESS) {
+ sp_max_recv = TCN_MAX(sp_max_recv, nbytes);
+ sp_min_recv = TCN_MIN(sp_min_recv, nbytes);
+ sp_tot_recv += nbytes;
+ sp_num_recv++;
+ }
+ else {
+ if (APR_STATUS_IS_ETIMEDOUT(ss) ||
+ APR_STATUS_IS_TIMEUP(ss))
+ sp_tmo_recv++;
+ else if (APR_STATUS_IS_ECONNABORTED(ss) ||
+ APR_STATUS_IS_ECONNRESET(ss) ||
+ APR_STATUS_IS_EOF(ss))
+ sp_rst_recv++;
+ else {
+ sp_err_recv++;
+ sp_erl_recv = ss;
+ }
+ }
+#endif
+ if (ss == APR_SUCCESS)
+ return (jint)nbytes;
+ else {
+ TCN_ERROR_WRAP(ss);
+ return -(jint)ss;
+ }
+}
+
+TCN_IMPLEMENT_CALL(jint, Socket, recvfrom)(TCN_STDARGS, jlong from,
+ jlong sock, jint flags,
+ jbyteArray buf, jint offset, jint toread)
+{
+ tcn_socket_t *s = J2P(sock, tcn_socket_t *);
+ apr_sockaddr_t *f = J2P(from, apr_sockaddr_t *);
+ apr_size_t nbytes = (apr_size_t)toread;
+ jbyte *bytes = (*e)->GetByteArrayElements(e, buf, NULL);
+ apr_status_t ss;
+
+ UNREFERENCED(o);
+ if (!sock) {
+ tcn_ThrowAPRException(e, APR_ENOTSOCK);
+ return -(jint)APR_ENOTSOCK;
+ }
+ TCN_ASSERT(s->sock != NULL);
+ TCN_ASSERT(buf != NULL);
+ ss = apr_socket_recvfrom(f, s->sock, (apr_int32_t)flags, (char*)(bytes + offset), &nbytes);
+
+ (*e)->ReleaseByteArrayElements(e, buf, bytes,
+ nbytes ? 0 : JNI_ABORT);
+ if (ss == APR_SUCCESS)
+ return (jint)nbytes;
+ else {
+ TCN_ERROR_WRAP(ss);
+ return -(jint)ss;
+ }
+}
+
+TCN_IMPLEMENT_CALL(jint, Socket, optSet)(TCN_STDARGS, jlong sock,
+ jint opt, jint on)
+{
+ tcn_socket_t *s = J2P(sock, tcn_socket_t *);
+
+ UNREFERENCED(o);
+ if (!s->sock) {
+ return APR_ENOTSOCK;
+ }
+ else
+ return (jint)(*s->net->opt_set)(s->opaque, (apr_int32_t)opt, (apr_int32_t)on);
+}
+
+TCN_IMPLEMENT_CALL(jint, Socket, optGet)(TCN_STDARGS, jlong sock,
+ jint opt)
+{
+ tcn_socket_t *s = J2P(sock, tcn_socket_t *);
+ apr_int32_t on = 0;
+
+ UNREFERENCED(o);
+ if (!s->sock)
+ tcn_ThrowAPRException(e, APR_ENOTSOCK);
+ else {
+ TCN_THROW_IF_ERR((*s->net->opt_get)(s->opaque, (apr_int32_t)opt,
+ &on), on);
+ }
+cleanup:
+ return (jint)on;
+}
+
+TCN_IMPLEMENT_CALL(jint, Socket, timeoutSet)(TCN_STDARGS, jlong sock,
+ jlong timeout)
+{
+ tcn_socket_t *s = J2P(sock, tcn_socket_t *);
+
+ UNREFERENCED(o);
+ TCN_ASSERT(s->opaque != NULL);
+ if (!sock) {
+ tcn_ThrowAPRException(e, APR_ENOTSOCK);
+ return APR_ENOTSOCK;
+ }
+ return (jint)(*s->net->timeout_set)(s->opaque, J2T(timeout));
+}
+
+TCN_IMPLEMENT_CALL(jlong, Socket, timeoutGet)(TCN_STDARGS, jlong sock)
+{
+ tcn_socket_t *s = J2P(sock, tcn_socket_t *);
+ apr_interval_time_t timeout;
+
+ UNREFERENCED(o);
+ if (!sock) {
+ tcn_ThrowAPRException(e, APR_ENOTSOCK);
+ return 0;
+ }
+ TCN_ASSERT(s->opaque != NULL);
+
+ TCN_THROW_IF_ERR((*s->net->timeout_get)(s->opaque, &timeout), timeout);
+cleanup:
+ return (jlong)timeout;
+}
+
+TCN_IMPLEMENT_CALL(jboolean, Socket, atmark)(TCN_STDARGS, jlong sock)
+{
+ tcn_socket_t *s = J2P(sock, tcn_socket_t *);
+ apr_int32_t mark;
+
+ UNREFERENCED_STDARGS;
+ TCN_ASSERT(sock != 0);
+ TCN_ASSERT(s->sock != NULL);
+
+ if (apr_socket_atmark(s->sock, &mark) != APR_SUCCESS)
+ return JNI_FALSE;
+ return mark ? JNI_TRUE : JNI_FALSE;
+}
+
+#if APR_HAS_SENDFILE
+
+TCN_IMPLEMENT_CALL(jlong, Socket, sendfile)(TCN_STDARGS, jlong sock,
+ jlong file,
+ jobjectArray headers,
+ jobjectArray trailers,
+ jlong offset, jlong len,
+ jint flags)
+{
+ tcn_socket_t *s = J2P(sock, tcn_socket_t *);
+ apr_file_t *f = J2P(file, apr_file_t *);
+ jsize nh = 0;
+ jsize nt = 0;
+ jsize i;
+ struct iovec hvec[APR_MAX_IOVEC_SIZE];
+ struct iovec tvec[APR_MAX_IOVEC_SIZE];
+ jobject hba[APR_MAX_IOVEC_SIZE];
+ jobject tba[APR_MAX_IOVEC_SIZE];
+ apr_off_t off = (apr_off_t)offset;
+ apr_size_t written = (apr_size_t)len;
+ apr_hdtr_t hdrs;
+ apr_status_t ss;
+
+ UNREFERENCED(o);
+ TCN_ASSERT(sock != 0);
+ TCN_ASSERT(file != 0);
+
+ if (s->net->type != TCN_SOCKET_APR)
+ return (jint)(-APR_ENOTIMPL);
+ if (headers)
+ nh = (*e)->GetArrayLength(e, headers);
+ if (trailers)
+ nt = (*e)->GetArrayLength(e, trailers);
+ /* Check for overflow */
+ if (nh >= APR_MAX_IOVEC_SIZE || nt >= APR_MAX_IOVEC_SIZE)
+ return (jint)(-APR_ENOMEM);
+
+ for (i = 0; i < nh; i++) {
+ hba[i] = (*e)->GetObjectArrayElement(e, headers, i);
+ hvec[i].iov_len = (*e)->GetArrayLength(e, hba[i]);
+ hvec[i].iov_base = (void *)((*e)->GetByteArrayElements(e, hba[i], NULL));
+ }
+ for (i = 0; i < nt; i++) {
+ tba[i] = (*e)->GetObjectArrayElement(e, trailers, i);
+ tvec[i].iov_len = (*e)->GetArrayLength(e, tba[i]);
+ tvec[i].iov_base = (void *)((*e)->GetByteArrayElements(e, tba[i], NULL));
+ }
+ hdrs.headers = &hvec[0];
+ hdrs.numheaders = nh;
+ hdrs.trailers = &tvec[0];
+ hdrs.numtrailers = nt;
+
+
+ ss = apr_socket_sendfile(s->sock, f, &hdrs, &off, &written, (apr_int32_t)flags);
+
+#ifdef TCN_DO_STATISTICS
+ sf_max_send = TCN_MAX(sf_max_send, written);
+ sf_min_send = TCN_MIN(sf_min_send, written);
+ sf_tot_send += written;
+ sf_num_send++;
+#endif
+
+ for (i = 0; i < nh; i++) {
+ (*e)->ReleaseByteArrayElements(e, hba[i], (jbyte*)hvec[i].iov_base, JNI_ABORT);
+ }
+
+ for (i = 0; i < nt; i++) {
+ (*e)->ReleaseByteArrayElements(e, tba[i], (jbyte*)tvec[i].iov_base, JNI_ABORT);
+ }
+ /* Return Number of bytes actually sent,
+ * including headers, file, and trailers
+ */
+ if (ss == APR_SUCCESS)
+ return (jlong)written;
+ else {
+ TCN_ERROR_WRAP(ss);
+ return -(jlong)ss;
+ }
+}
+
+TCN_IMPLEMENT_CALL(jlong, Socket, sendfilen)(TCN_STDARGS, jlong sock,
+ jlong file,
+ jlong offset, jlong len,
+ jint flags)
+{
+ tcn_socket_t *s = J2P(sock, tcn_socket_t *);
+ apr_file_t *f = J2P(file, apr_file_t *);
+ apr_off_t off = (apr_off_t)offset;
+ apr_size_t written = (apr_size_t)len;
+ apr_hdtr_t hdrs;
+ apr_status_t ss;
+
+ UNREFERENCED_STDARGS;
+ TCN_ASSERT(sock != 0);
+ TCN_ASSERT(file != 0);
+
+ if (s->net->type != TCN_SOCKET_APR)
+ return (jint)(-APR_ENOTIMPL);
+
+ hdrs.headers = NULL;
+ hdrs.numheaders = 0;
+ hdrs.trailers = NULL;
+ hdrs.numtrailers = 0;
+
+
+ ss = apr_socket_sendfile(s->sock, f, &hdrs, &off, &written, (apr_int32_t)flags);
+
+#ifdef TCN_DO_STATISTICS
+ sf_max_send = TCN_MAX(sf_max_send, written);
+ sf_min_send = TCN_MIN(sf_min_send, written);
+ sf_tot_send += written;
+ sf_num_send++;
+#endif
+
+ /* Return Number of bytes actually sent,
+ * including headers, file, and trailers
+ */
+ if (ss == APR_SUCCESS)
+ return (jlong)written;
+ else {
+ TCN_ERROR_WRAP(ss);
+ return -(jlong)ss;
+ }
+}
+
+#else /* APR_HAS_SENDIFLE */
+
+TCN_IMPLEMENT_CALL(jlong, Socket, sendfile)(TCN_STDARGS, jlong sock,
+ jlong file,
+ jobjectArray headers,
+ jobjectArray trailers,
+ jlong offset, jlong len,
+ jint flags)
+{
+
+ UNREFERENCED_STDARGS;
+ UNREFERENCED(sock);
+ UNREFERENCED(file);
+ UNREFERENCED(headers);
+ UNREFERENCED(trailers);
+ UNREFERENCED(offset);
+ UNREFERENCED(len);
+ UNREFERENCED(flags);
+ return -(jlong)APR_ENOTIMPL;
+}
+
+TCN_IMPLEMENT_CALL(jlong, Socket, sendfilen)(TCN_STDARGS, jlong sock,
+ jlong file,
+ jlong offset, jlong len,
+ jint flags)
+{
+ UNREFERENCED_STDARGS;
+ UNREFERENCED(sock);
+ UNREFERENCED(file);
+ UNREFERENCED(offset);
+ UNREFERENCED(len);
+ UNREFERENCED(flags);
+ return -(jlong)APR_ENOTIMPL;
+}
+
+#endif /* APR_HAS_SENDIFLE */
+
+
+TCN_IMPLEMENT_CALL(jint, Socket, acceptfilter)(TCN_STDARGS,
+ jlong sock,
+ jstring name,
+ jstring args)
+{
+#if APR_HAS_SO_ACCEPTFILTER
+ tcn_socket_t *s = J2P(sock, tcn_socket_t *);
+ TCN_ALLOC_CSTRING(name);
+ TCN_ALLOC_CSTRING(args);
+ apr_status_t rv;
+
+
+ UNREFERENCED(o);
+ rv = apr_socket_accept_filter(s->sock, J2S(name),
+ J2S(args) ? J2S(args) : "");
+ TCN_FREE_CSTRING(name);
+ TCN_FREE_CSTRING(args);
+ return (jint)rv;
+#else
+ UNREFERENCED_STDARGS;
+ UNREFERENCED(sock);
+ UNREFERENCED(name);
+ UNREFERENCED(args);
+ return (jint)APR_ENOTIMPL;
+#endif
+}
+
+TCN_IMPLEMENT_CALL(jint, Socket, dataSet)(TCN_STDARGS, jlong sock,
+ jstring key, jobject data)
+{
+ tcn_socket_t *s = J2P(sock, tcn_socket_t *);
+ apr_status_t rv = APR_SUCCESS;
+ TCN_ALLOC_CSTRING(key);
+
+ UNREFERENCED(o);
+ TCN_ASSERT(sock != 0);
+
+ rv = apr_socket_data_set(s->sock, data, J2S(key), NULL);
+ TCN_FREE_CSTRING(key);
+ return rv;
+}
+
+TCN_IMPLEMENT_CALL(jobject, Socket, dataGet)(TCN_STDARGS, jlong socket,
+ jstring key)
+{
+ tcn_socket_t *s = J2P(socket, tcn_socket_t *);
+ TCN_ALLOC_CSTRING(key);
+ void *rv = NULL;
+
+ UNREFERENCED(o);
+ TCN_ASSERT(socket != 0);
+
+ if (apr_socket_data_get(&rv, J2S(key), s->sock) != APR_SUCCESS) {
+ rv = NULL;
+ }
+ TCN_FREE_CSTRING(key);
+ return rv;
+}
diff --git a/jni/native/src/os.c b/jni/native/src/os.c
new file mode 100644
index 0000000..611442e
--- /dev/null
+++ b/jni/native/src/os.c
@@ -0,0 +1,40 @@
+/* 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: os.c 1442587 2013-02-05 13:49:48Z rjung $
+ */
+
+#include "tcn.h"
+
+TCN_IMPLEMENT_CALL(jstring, OS, defaultEncoding)(TCN_STDARGS, jlong pool)
+{
+ apr_pool_t *p = J2P(pool, apr_pool_t *);
+
+ UNREFERENCED(o);
+ return AJP_TO_JSTRING(apr_os_default_encoding(p));
+}
+
+TCN_IMPLEMENT_CALL(jstring, OS, localeEncoding)(TCN_STDARGS, jlong pool)
+{
+ apr_pool_t *p = J2P(pool, apr_pool_t *);
+
+ UNREFERENCED(o);
+ return AJP_TO_JSTRING(apr_os_locale_encoding(p));
+}
+
diff --git a/jni/native/src/poll.c b/jni/native/src/poll.c
new file mode 100644
index 0000000..aeb6288
--- /dev/null
+++ b/jni/native/src/poll.c
@@ -0,0 +1,481 @@
+/* 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: poll.c 1525525 2013-09-23 08:08:56Z rjung $
+ */
+
+#include "tcn.h"
+
+#ifdef TCN_DO_STATISTICS
+static int sp_created = 0;
+static int sp_destroyed = 0;
+static int sp_cleared = 0;
+#endif
+
+/* Internal poll structure for queryset
+ */
+typedef struct tcn_pollset {
+ apr_pool_t *pool;
+ apr_int32_t nelts;
+ apr_int32_t nalloc;
+ apr_pollset_t *pollset;
+ jlong *set;
+ apr_interval_time_t default_timeout;
+ /* A ring containing all of the pollfd_t that are active
+ */
+ APR_RING_HEAD(pfd_poll_ring_t, tcn_pfde_t) poll_ring;
+ /* A ring of pollfd_t that have been used, and then _remove()'d
+ */
+ APR_RING_HEAD(pfd_free_ring_t, tcn_pfde_t) free_ring;
+ /* A ring of pollfd_t where rings that have been _remove()`ed but
+ * might still be inside a _poll()
+ */
+ APR_RING_HEAD(pfd_dead_ring_t, tcn_pfde_t) dead_ring;
+#ifdef TCN_DO_STATISTICS
+ int sp_added;
+ int sp_max_count;
+ int sp_poll;
+ int sp_polled;
+ int sp_max_polled;
+ int sp_remove;
+ int sp_removed;
+ int sp_maintained;
+ int sp_max_maintained;
+ int sp_err_poll;
+ int sp_poll_timeout;
+ int sp_overflow;
+ int sp_equals;
+ int sp_eintr;
+#endif
+} tcn_pollset_t;
+
+#ifdef TCN_DO_STATISTICS
+static void sp_poll_statistics(tcn_pollset_t *p)
+{
+ fprintf(stderr, "Pollset Statistics ......\n");
+ fprintf(stderr, "Number of added sockets : %d\n", p->sp_added);
+ fprintf(stderr, "Max. number of sockets : %d\n", p->sp_max_count);
+ fprintf(stderr, "Poll calls : %d\n", p->sp_poll);
+ fprintf(stderr, "Poll timeouts : %d\n", p->sp_poll_timeout);
+ fprintf(stderr, "Poll errors : %d\n", p->sp_err_poll);
+ fprintf(stderr, "Poll overflows : %d\n", p->sp_overflow);
+ fprintf(stderr, "Polled sockets : %d\n", p->sp_polled);
+ fprintf(stderr, "Max. Polled sockets : %d\n", p->sp_max_polled);
+ fprintf(stderr, "Poll remove : %d\n", p->sp_remove);
+ fprintf(stderr, "Total removed : %d\n", p->sp_removed);
+ fprintf(stderr, "Maintained : %d\n", p->sp_maintained);
+ fprintf(stderr, "Max. maintained : %d\n", p->sp_max_maintained);
+ fprintf(stderr, "Number of duplicates : %d\n", p->sp_equals);
+ fprintf(stderr, "Number of interrupts : %d\n", p->sp_eintr);
+
+}
+
+static apr_status_t sp_poll_cleanup(void *data)
+{
+ sp_cleared++;
+ sp_poll_statistics(data);
+ return APR_SUCCESS;
+}
+
+void sp_poll_dump_statistics()
+{
+ fprintf(stderr, "Poll Statistics .........\n");
+ fprintf(stderr, "Polls created : %d\n", sp_created);
+ fprintf(stderr, "Polls destroyed : %d\n", sp_destroyed);
+ fprintf(stderr, "Polls cleared : %d\n", sp_cleared);
+}
+#endif
+
+TCN_IMPLEMENT_CALL(jlong, Poll, create)(TCN_STDARGS, jint size,
+ jlong pool, jint flags,
+ jlong default_timeout)
+{
+ apr_pool_t *p = J2P(pool, apr_pool_t *);
+ apr_pollset_t *pollset = NULL;
+ tcn_pollset_t *tps = NULL;
+ apr_uint32_t f = (apr_uint32_t)flags | APR_POLLSET_NOCOPY;
+ UNREFERENCED(o);
+ TCN_ASSERT(pool != 0);
+
+ if (f & APR_POLLSET_THREADSAFE) {
+ apr_status_t rv = apr_pollset_create(&pollset, (apr_uint32_t)size, p, f);
+ if (rv == APR_ENOTIMPL)
+ f &= ~APR_POLLSET_THREADSAFE;
+ else if (rv != APR_SUCCESS) {
+ tcn_ThrowAPRException(e, rv);
+ goto cleanup;
+ }
+ }
+ if (pollset == NULL) {
+ TCN_THROW_IF_ERR(apr_pollset_create(&pollset,
+ (apr_uint32_t)size, p, f), pollset);
+ }
+ tps = apr_pcalloc(p, sizeof(tcn_pollset_t));
+ TCN_CHECK_ALLOCATED(tps);
+ tps->pollset = pollset;
+ tps->set = apr_pcalloc(p, size * sizeof(jlong) * 2);
+ TCN_CHECK_ALLOCATED(tps->set);
+ APR_RING_INIT(&tps->poll_ring, tcn_pfde_t, link);
+ APR_RING_INIT(&tps->free_ring, tcn_pfde_t, link);
+ APR_RING_INIT(&tps->dead_ring, tcn_pfde_t, link);
+
+ tps->nelts = 0;
+ tps->nalloc = size;
+ tps->pool = p;
+ tps->default_timeout = J2T(default_timeout);
+#ifdef TCN_DO_STATISTICS
+ sp_created++;
+ apr_pool_cleanup_register(p, (const void *)tps,
+ sp_poll_cleanup,
+ apr_pool_cleanup_null);
+#endif
+cleanup:
+ return P2J(tps);
+}
+
+TCN_IMPLEMENT_CALL(jint, Poll, destroy)(TCN_STDARGS, jlong pollset)
+{
+ tcn_pollset_t *p = J2P(pollset, tcn_pollset_t *);
+
+ UNREFERENCED_STDARGS;
+ TCN_ASSERT(pollset != 0);
+#ifdef TCN_DO_STATISTICS
+ sp_destroyed++;
+ apr_pool_cleanup_kill(p->pool, p, sp_poll_cleanup);
+ sp_poll_statistics(p);
+#endif
+ return (jint)apr_pollset_destroy(p->pollset);
+}
+
+static apr_status_t do_add(tcn_pollset_t *p, tcn_socket_t *s,
+ apr_int16_t reqevents,
+ apr_interval_time_t socket_timeout)
+{
+
+ apr_status_t rv;
+ apr_interval_time_t timeout = socket_timeout;
+ tcn_pfde_t *elem = NULL;
+
+ if (p->nelts == p->nalloc) {
+#ifdef TCN_DO_STATISTICS
+ p->sp_overflow++;
+#endif
+ return APR_ENOMEM;
+ }
+ if (s->pe != NULL) {
+ /* Socket is already added to the pollset.
+ */
+#ifdef TCN_DO_STATISTICS
+ p->sp_equals++;
+#endif
+ return APR_EEXIST;
+ }
+ if (timeout == TCN_NO_SOCKET_TIMEOUT) {
+ timeout = p->default_timeout;
+ }
+ if (timeout > 0)
+ s->last_active = apr_time_now();
+ else
+ s->last_active = 0;
+ s->timeout = socket_timeout;
+ if (!APR_RING_EMPTY(&p->free_ring, tcn_pfde_t, link)) {
+ elem = APR_RING_FIRST(&p->free_ring);
+ APR_RING_REMOVE(elem, link);
+ }
+ else {
+ elem = (tcn_pfde_t *)apr_palloc(p->pool, sizeof(tcn_pfde_t));
+ APR_RING_ELEM_INIT(elem, link);
+ }
+ elem->fd.reqevents = reqevents;
+ elem->fd.desc_type = APR_POLL_SOCKET;
+ elem->fd.desc.s = s->sock;
+ elem->fd.client_data = s;
+#ifdef TCN_DO_STATISTICS
+ p->sp_added++;
+ p->sp_max_count = TCN_MAX(p->sp_max_count, p->sp_added);
+#endif
+ rv = apr_pollset_add(p->pollset, &elem->fd);
+ if (rv != APR_SUCCESS) {
+ APR_RING_INSERT_TAIL(&p->free_ring, elem, tcn_pfde_t, link);
+ }
+ else {
+ APR_RING_INSERT_TAIL(&p->poll_ring, elem, tcn_pfde_t, link);
+ s->pe = elem;
+ }
+ return rv;
+}
+
+TCN_IMPLEMENT_CALL(jint, Poll, add)(TCN_STDARGS, jlong pollset,
+ jlong socket, jint reqevents)
+{
+ tcn_pollset_t *p = J2P(pollset, tcn_pollset_t *);
+ tcn_socket_t *s = J2P(socket, tcn_socket_t *);
+
+ UNREFERENCED_STDARGS;
+ TCN_ASSERT(socket != 0);
+
+ return (jint) do_add(p, s, (apr_int16_t)reqevents, TCN_NO_SOCKET_TIMEOUT);
+}
+
+TCN_IMPLEMENT_CALL(jint, Poll, addWithTimeout)(TCN_STDARGS, jlong pollset,
+ jlong socket, jint reqevents,
+ jlong socket_timeout)
+{
+ tcn_pollset_t *p = J2P(pollset, tcn_pollset_t *);
+ tcn_socket_t *s = J2P(socket, tcn_socket_t *);
+
+ UNREFERENCED_STDARGS;
+ TCN_ASSERT(socket != 0);
+
+ return (jint) do_add(p, s, (apr_int16_t)reqevents, J2T(socket_timeout));
+}
+
+TCN_IMPLEMENT_CALL(jint, Poll, remove)(TCN_STDARGS, jlong pollset,
+ jlong socket)
+{
+ apr_pollfd_t fd;
+ apr_status_t rv;
+ tcn_pollset_t *p = J2P(pollset, tcn_pollset_t *);
+ tcn_socket_t *s = J2P(socket, tcn_socket_t *);
+
+ UNREFERENCED_STDARGS;
+ TCN_ASSERT(socket != 0);
+
+ if (s->pe == NULL) {
+ /* Already removed */
+ return APR_NOTFOUND;
+ }
+ fd.desc_type = APR_POLL_SOCKET;
+ fd.desc.s = s->sock;
+ fd.client_data = s;
+ fd.reqevents = APR_POLLIN | APR_POLLOUT;
+#ifdef TCN_DO_STATISTICS
+ p->sp_remove++;
+#endif
+
+ rv = apr_pollset_remove(p->pollset, &fd);
+ APR_RING_REMOVE(s->pe, link);
+ APR_RING_INSERT_TAIL(&p->dead_ring, s->pe, tcn_pfde_t, link);
+ s->pe = NULL;
+ p->nelts--;
+#ifdef TCN_DO_STATISTICS
+ p->sp_removed++;
+#endif
+ return rv;
+}
+
+
+TCN_IMPLEMENT_CALL(jint, Poll, poll)(TCN_STDARGS, jlong pollset,
+ jlong timeout, jlongArray set,
+ jboolean remove)
+{
+ const apr_pollfd_t *fd = NULL;
+ tcn_pollset_t *p = J2P(pollset, tcn_pollset_t *);
+ apr_int32_t i, num = 0;
+ apr_status_t rv = APR_SUCCESS;
+ apr_time_t now = 0;
+ apr_interval_time_t ptime = J2T(timeout);
+ UNREFERENCED(o);
+ TCN_ASSERT(pollset != 0);
+
+#ifdef TCN_DO_STATISTICS
+ p->sp_poll++;
+#endif
+
+ if (ptime > 0) {
+ tcn_pfde_t *ep;
+
+ now = apr_time_now();
+ /* Find the minimum timeout */
+ APR_RING_FOREACH(ep, &p->poll_ring, tcn_pfde_t, link)
+ {
+ apr_interval_time_t socket_timeout = 0;
+ tcn_socket_t *s = (tcn_socket_t *)ep->fd.client_data;
+ if (s->timeout == TCN_NO_SOCKET_TIMEOUT) {
+ socket_timeout = p->default_timeout;
+ }
+ else {
+ socket_timeout = s->timeout;
+ }
+ if (socket_timeout >= 0) {
+ apr_interval_time_t t = now - s->last_active;
+ if (t >= socket_timeout) {
+ ptime = 0;
+ break;
+ }
+ else {
+ ptime = TCN_MIN(socket_timeout - t, ptime);
+ }
+ }
+ }
+ }
+ else if (ptime < 0)
+ ptime = 0;
+ for (;;) {
+ rv = apr_pollset_poll(p->pollset, ptime, &num, &fd);
+ if (rv != APR_SUCCESS) {
+ if (APR_STATUS_IS_EINTR(rv)) {
+#ifdef TCN_DO_STATISTICS
+ p->sp_eintr++;
+#endif
+ continue;
+ }
+ TCN_ERROR_WRAP(rv);
+#ifdef TCN_DO_STATISTICS
+ if (rv == TCN_TIMEUP)
+ p->sp_poll_timeout++;
+ else
+ p->sp_err_poll++;
+#endif
+ num = (apr_int32_t)(-rv);
+ }
+ break;
+ }
+ /* Shift all PFDs in the Dead Ring to the Free Ring */
+ APR_RING_CONCAT(&p->free_ring, &p->dead_ring, tcn_pfde_t, link);
+ if (num > 0) {
+#ifdef TCN_DO_STATISTICS
+ p->sp_polled += num;
+ p->sp_max_polled = TCN_MAX(p->sp_max_polled, num);
+#endif
+ if (!remove)
+ now = apr_time_now();
+ for (i = 0; i < num; i++) {
+ tcn_socket_t *s = (tcn_socket_t *)fd->client_data;
+ p->set[i*2+0] = (jlong)(fd->rtnevents);
+ p->set[i*2+1] = P2J(s);
+ if (remove) {
+ apr_pollset_remove(p->pollset, fd);
+ APR_RING_REMOVE(s->pe, link);
+ APR_RING_INSERT_TAIL(&p->dead_ring, s->pe, tcn_pfde_t, link);
+ s->pe = NULL;
+ p->nelts--;
+#ifdef TCN_DO_STATISTICS
+ p->sp_removed++;
+#endif
+ }
+ else {
+ /* Update last active with the current time
+ * after the poll call.
+ */
+ s->last_active = now;
+ }
+ fd ++;
+ }
+ (*e)->SetLongArrayRegion(e, set, 0, num * 2, p->set);
+ }
+
+ return (jint)num;
+}
+
+TCN_IMPLEMENT_CALL(jint, Poll, maintain)(TCN_STDARGS, jlong pollset,
+ jlongArray set, jboolean remove)
+{
+ tcn_pollset_t *p = J2P(pollset, tcn_pollset_t *);
+ apr_int32_t i = 0, num = 0;
+ apr_time_t now = apr_time_now();
+ tcn_pfde_t *ep, *ip;
+
+ UNREFERENCED(o);
+ TCN_ASSERT(pollset != 0);
+
+ /* Check for timeout sockets */
+ APR_RING_FOREACH_SAFE(ep, ip, &p->poll_ring, tcn_pfde_t, link)
+ {
+ apr_interval_time_t timeout = 0;
+ tcn_socket_t *s = (tcn_socket_t *)ep->fd.client_data;
+ if (s->timeout == TCN_NO_SOCKET_TIMEOUT) {
+ timeout = p->default_timeout;
+ }
+ else {
+ timeout = s->timeout;
+ }
+ if (timeout == -1) {
+ continue;
+ }
+ if ((now - s->last_active) >= timeout) {
+ p->set[num++] = P2J(s);
+ if (remove) {
+ APR_RING_REMOVE(ep, link);
+ APR_RING_INSERT_TAIL(&p->dead_ring, ep, tcn_pfde_t, link);
+ s->pe = NULL;
+ p->nelts--;
+#ifdef TCN_DO_STATISTICS
+ p->sp_removed++;
+#endif
+ }
+ }
+ }
+ if (num) {
+#ifdef TCN_DO_STATISTICS
+ p->sp_maintained += num;
+ p->sp_max_maintained = TCN_MAX(p->sp_max_maintained, num);
+#endif
+ if (remove) {
+ for (i = 0; i < num; i++) {
+ apr_pollfd_t fd;
+ tcn_socket_t *s = J2P(p->set[i], tcn_socket_t *);
+ fd.desc_type = APR_POLL_SOCKET;
+ fd.desc.s = s->sock;
+ fd.client_data = s;
+ fd.reqevents = APR_POLLIN | APR_POLLOUT;
+ apr_pollset_remove(p->pollset, &fd);
+ }
+ }
+ (*e)->SetLongArrayRegion(e, set, 0, num, p->set);
+ }
+ return (jint)num;
+}
+
+TCN_IMPLEMENT_CALL(void, Poll, setTtl)(TCN_STDARGS, jlong pollset,
+ jlong default_timeout)
+{
+ tcn_pollset_t *p = J2P(pollset, tcn_pollset_t *);
+ UNREFERENCED_STDARGS;
+ p->default_timeout = J2T(default_timeout);
+}
+
+TCN_IMPLEMENT_CALL(jlong, Poll, getTtl)(TCN_STDARGS, jlong pollset)
+{
+ tcn_pollset_t *p = J2P(pollset, tcn_pollset_t *);
+ UNREFERENCED_STDARGS;
+ return (jlong)p->default_timeout;
+}
+
+TCN_IMPLEMENT_CALL(jint, Poll, pollset)(TCN_STDARGS, jlong pollset,
+ jlongArray set)
+{
+ tcn_pollset_t *p = J2P(pollset, tcn_pollset_t *);
+ apr_int32_t n = 0;
+ tcn_pfde_t *ep;
+
+ UNREFERENCED(o);
+ TCN_ASSERT(pollset != 0);
+
+ APR_RING_FOREACH(ep, &p->poll_ring, tcn_pfde_t, link)
+ {
+ apr_pollfd_t *fd = &ep->fd;
+ fd->rtnevents = APR_POLLHUP | APR_POLLIN;
+ p->set[n++] = (jlong)(fd->rtnevents);
+ p->set[n++] = P2J(fd->client_data);
+ }
+ if (n > 0)
+ (*e)->SetLongArrayRegion(e, set, 0, n, p->set);
+ return n / 2;
+}
diff --git a/jni/native/src/pool.c b/jni/native/src/pool.c
new file mode 100644
index 0000000..f6c31fb
--- /dev/null
+++ b/jni/native/src/pool.c
@@ -0,0 +1,250 @@
+/* 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: pool.c 1442587 2013-02-05 13:49:48Z rjung $
+ */
+
+#include "tcn.h"
+
+extern apr_pool_t *tcn_global_pool;
+
+static apr_status_t generic_pool_cleanup(void *data)
+{
+ apr_status_t rv = APR_SUCCESS;
+ tcn_callback_t *cb = (tcn_callback_t *)data;
+
+ if (data) {
+ JNIEnv *env;
+ tcn_get_java_env(&env);
+ if (!TCN_IS_NULL(env, cb->obj)) {
+ rv = (*(env))->CallIntMethod(env, cb->obj, cb->mid[0],
+ NULL);
+ TCN_UNLOAD_CLASS(env, cb->obj);
+ }
+ free(cb);
+ }
+ return rv;
+}
+
+TCN_IMPLEMENT_CALL(jlong, Pool, create)(TCN_STDARGS, jlong parent)
+{
+ apr_pool_t *p = J2P(parent, apr_pool_t *);
+ apr_pool_t *n;
+
+ UNREFERENCED(o);
+ /* Make sure our global pool is accessor for all pools */
+ if (p == NULL)
+ p = tcn_global_pool;
+ TCN_THROW_IF_ERR(apr_pool_create(&n, p), n);
+cleanup:
+ return P2J(n);
+}
+
+TCN_IMPLEMENT_CALL(void, Pool, clear)(TCN_STDARGS, jlong pool)
+{
+ apr_pool_t *p = J2P(pool, apr_pool_t *);
+ UNREFERENCED_STDARGS;
+ TCN_ASSERT(pool != 0);
+ apr_pool_clear(p);
+}
+
+TCN_IMPLEMENT_CALL(void, Pool, destroy)(TCN_STDARGS, jlong pool)
+{
+ apr_pool_t *p = J2P(pool, apr_pool_t *);
+ UNREFERENCED_STDARGS;
+ TCN_ASSERT(pool != 0);
+ apr_pool_destroy(p);
+}
+
+TCN_IMPLEMENT_CALL(jlong, Pool, parentGet)(TCN_STDARGS, jlong pool)
+{
+ apr_pool_t *p = J2P(pool, apr_pool_t *);
+ UNREFERENCED_STDARGS;
+ TCN_ASSERT(pool != 0);
+ return P2J(apr_pool_parent_get(p));
+}
+
+TCN_IMPLEMENT_CALL(jboolean, Pool, isAncestor)(TCN_STDARGS, jlong a, jlong b)
+{
+ apr_pool_t *pa = J2P(a, apr_pool_t *);
+ apr_pool_t *pb = J2P(b, apr_pool_t *);
+ UNREFERENCED_STDARGS;
+ return apr_pool_is_ancestor(pa, pb) ? JNI_TRUE : JNI_FALSE;
+}
+
+TCN_IMPLEMENT_CALL(jlong, Pool, palloc)(TCN_STDARGS, jlong pool, jint size)
+{
+ apr_pool_t *p = J2P(pool, apr_pool_t *);
+ UNREFERENCED_STDARGS;
+ return P2J(apr_palloc(p, (apr_size_t)size));
+}
+
+TCN_IMPLEMENT_CALL(jlong, Pool, pcalloc)(TCN_STDARGS, jlong pool, jint size)
+{
+ apr_pool_t *p = J2P(pool, apr_pool_t *);
+ UNREFERENCED_STDARGS;
+ return P2J(apr_pcalloc(p, (apr_size_t)size));
+}
+
+TCN_IMPLEMENT_CALL(jlong, Pool, cleanupRegister)(TCN_STDARGS, jlong pool,
+ jobject obj)
+{
+ apr_pool_t *p = J2P(pool, apr_pool_t *);
+ tcn_callback_t *cb = (tcn_callback_t *)malloc(sizeof(tcn_callback_t));
+ jclass cls;
+
+ UNREFERENCED(o);
+
+ if (cb == NULL) {
+ TCN_THROW_OS_ERROR(e);
+ return 0;
+ }
+ cls = (*e)->GetObjectClass(e, obj);
+ cb->obj = (*e)->NewGlobalRef(e, obj);
+ cb->mid[0] = (*e)->GetMethodID(e, cls, "callback", "()I");
+
+ apr_pool_cleanup_register(p, (const void *)cb,
+ generic_pool_cleanup,
+ apr_pool_cleanup_null);
+
+ return P2J(cb);
+}
+
+TCN_IMPLEMENT_CALL(void, Pool, cleanupKill)(TCN_STDARGS, jlong pool,
+ jlong data)
+{
+ apr_pool_t *p = J2P(pool, apr_pool_t *);
+ tcn_callback_t *cb = J2P(data, tcn_callback_t *);
+
+ UNREFERENCED(o);
+ TCN_ASSERT(pool != 0);
+ apr_pool_cleanup_kill(p, cb, generic_pool_cleanup);
+ (*e)->DeleteGlobalRef(e, cb->obj);
+ free(cb);
+}
+
+TCN_IMPLEMENT_CALL(jobject, Pool, alloc)(TCN_STDARGS, jlong pool,
+ jint size)
+{
+ apr_pool_t *p = J2P(pool, apr_pool_t *);
+ apr_size_t sz = (apr_size_t)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;
+}
+
+TCN_IMPLEMENT_CALL(jobject, Pool, calloc)(TCN_STDARGS, jlong pool,
+ jint size)
+{
+ apr_pool_t *p = J2P(pool, apr_pool_t *);
+ apr_size_t sz = (apr_size_t)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;
+}
+
+static apr_status_t generic_pool_data_cleanup(void *data)
+{
+ apr_status_t rv = APR_SUCCESS;
+ tcn_callback_t *cb = (tcn_callback_t *)data;
+
+ if (data) {
+ JNIEnv *env;
+ tcn_get_java_env(&env);
+
+ if (!TCN_IS_NULL(env, cb->obj)) {
+ TCN_UNLOAD_CLASS(env, cb->obj);
+ }
+ free(cb);
+ }
+ return rv;
+}
+
+TCN_IMPLEMENT_CALL(jint, Pool, dataSet)(TCN_STDARGS, jlong pool,
+ jstring key, jobject data)
+{
+ apr_pool_t *p = J2P(pool, apr_pool_t *);
+ apr_status_t rv = APR_SUCCESS;
+ void *old = NULL;
+ TCN_ALLOC_CSTRING(key);
+
+ UNREFERENCED(o);
+ TCN_ASSERT(pool != 0);
+
+ if (apr_pool_userdata_get(&old, J2S(key), p) == APR_SUCCESS) {
+ if (old)
+ apr_pool_cleanup_run(p, old, generic_pool_data_cleanup);
+ }
+ if (data) {
+ JNIEnv *e;
+ tcn_callback_t *cb = (tcn_callback_t *)malloc(sizeof(tcn_callback_t));
+ tcn_get_java_env(&e);
+ cb->obj = (*e)->NewGlobalRef(e, data);
+ if ((rv = apr_pool_userdata_set(cb, J2S(key), generic_pool_data_cleanup,
+ p)) != APR_SUCCESS) {
+ (*e)->DeleteGlobalRef(e, cb->obj);
+ free(cb);
+ }
+ }
+ else {
+ /* Clear the exiting user data */
+ rv = apr_pool_userdata_set(NULL, J2S(key), NULL, p);
+ }
+ TCN_FREE_CSTRING(key);
+ return rv;
+}
+
+TCN_IMPLEMENT_CALL(jobject, Pool, dataGet)(TCN_STDARGS, jlong pool,
+ jstring key)
+{
+ apr_pool_t *p = J2P(pool, apr_pool_t *);
+ void *old = NULL;
+ TCN_ALLOC_CSTRING(key);
+ jobject rv = NULL;
+
+ UNREFERENCED(o);
+ TCN_ASSERT(pool != 0);
+
+ if (apr_pool_userdata_get(&old, J2S(key), p) == APR_SUCCESS) {
+ if (old) {
+ tcn_callback_t *cb = (tcn_callback_t *)old;
+ rv = cb->obj;
+ }
+ }
+ TCN_FREE_CSTRING(key);
+ return rv;
+}
+
+TCN_IMPLEMENT_CALL(void, Pool, cleanupForExec)(TCN_STDARGS)
+{
+ UNREFERENCED_STDARGS;
+ apr_pool_cleanup_for_exec();
+}
diff --git a/jni/native/src/proc.c b/jni/native/src/proc.c
new file mode 100644
index 0000000..18902dc
--- /dev/null
+++ b/jni/native/src/proc.c
@@ -0,0 +1,453 @@
+/* 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: proc.c 1442587 2013-02-05 13:49:48Z rjung $
+ */
+
+#include "tcn.h"
+#include "apr_thread_proc.h"
+#include "apr_version.h"
+
+#define ERRFN_USERDATA_KEY "TCNATIVECHILDERRFN"
+
+static void generic_child_errfn(apr_pool_t *pool, apr_status_t err,
+ const char *description)
+{
+ void *data;
+ tcn_callback_t *cb;
+
+ apr_pool_userdata_get(&data, ERRFN_USERDATA_KEY, pool);
+ cb = (tcn_callback_t *)data;
+ if (cb) {
+ JNIEnv *env;
+ tcn_get_java_env(&env);
+ if (!TCN_IS_NULL(env, cb->obj)) {
+ (*(env))->CallVoidMethod(env, cb->obj, cb->mid[0],
+ P2J(pool), (jint)err,
+ (*(env))->NewStringUTF(env, description),
+ NULL);
+ }
+ }
+}
+
+static apr_status_t child_errfn_pool_cleanup(void *data)
+{
+ tcn_callback_t *cb = (tcn_callback_t *)data;
+
+ if (data) {
+ JNIEnv *env;
+ tcn_get_java_env(&env);
+ if (!TCN_IS_NULL(env, cb->obj)) {
+ TCN_UNLOAD_CLASS(env, cb->obj);
+ }
+ free(cb);
+ }
+ return APR_SUCCESS;
+}
+
+TCN_IMPLEMENT_CALL(jlong, Procattr, create)(TCN_STDARGS,
+ jlong pool)
+{
+ apr_pool_t *p = J2P(pool, apr_pool_t *);
+ apr_procattr_t *attr;
+
+
+ UNREFERENCED(o);
+ TCN_THROW_IF_ERR(apr_procattr_create(&attr, p), attr);
+
+cleanup:
+ return P2J(attr);
+}
+
+TCN_IMPLEMENT_CALL(jint, Procattr, ioSet)(TCN_STDARGS,
+ jlong attr, jint in,
+ jint out, jint err)
+{
+ apr_procattr_t *a = J2P(attr, apr_procattr_t *);
+
+ UNREFERENCED_STDARGS;
+ return (jint)apr_procattr_io_set(a, (apr_int32_t)in,
+ (apr_int32_t)out, (apr_int32_t)err);
+}
+
+TCN_IMPLEMENT_CALL(jint, Procattr, childInSet)(TCN_STDARGS,
+ jlong attr, jlong in,
+ jlong parent)
+{
+ apr_procattr_t *a = J2P(attr, apr_procattr_t *);
+ apr_file_t *f = J2P(in, apr_file_t *);
+ apr_file_t *p = J2P(parent, apr_file_t *);
+
+ UNREFERENCED_STDARGS;
+ return (jint)apr_procattr_child_in_set(a, f, p);
+}
+
+TCN_IMPLEMENT_CALL(jint, Procattr, childOutSet)(TCN_STDARGS,
+ jlong attr, jlong out,
+ jlong parent)
+{
+ apr_procattr_t *a = J2P(attr, apr_procattr_t *);
+ apr_file_t *f = J2P(out, apr_file_t *);
+ apr_file_t *p = J2P(parent, apr_file_t *);
+
+ UNREFERENCED_STDARGS;
+ return (jint)apr_procattr_child_out_set(a, f, p);
+}
+
+TCN_IMPLEMENT_CALL(jint, Procattr, childErrSet)(TCN_STDARGS,
+ jlong attr, jlong err,
+ jlong parent)
+{
+ apr_procattr_t *a = J2P(attr, apr_procattr_t *);
+ apr_file_t *f = J2P(err, apr_file_t *);
+ apr_file_t *p = J2P(parent, apr_file_t *);
+
+ UNREFERENCED_STDARGS;
+ return (jint)apr_procattr_child_in_set(a, f, p);
+}
+
+TCN_IMPLEMENT_CALL(jint, Procattr, dirSet)(TCN_STDARGS,
+ jlong attr,
+ jstring dir)
+{
+ apr_status_t rv;
+ apr_procattr_t *a = J2P(attr, apr_procattr_t *);
+ TCN_ALLOC_CSTRING(dir);
+
+ UNREFERENCED(o);
+
+ rv = apr_procattr_dir_set(a, J2S(dir));
+ TCN_FREE_CSTRING(dir);
+ return (jint) rv;
+}
+
+TCN_IMPLEMENT_CALL(jint, Procattr, cmdtypeSet)(TCN_STDARGS,
+ jlong attr, jint cmd)
+{
+ apr_procattr_t *a = J2P(attr, apr_procattr_t *);
+
+ UNREFERENCED_STDARGS;
+ return (jint)apr_procattr_cmdtype_set(a, (apr_int32_t)cmd);
+}
+
+TCN_IMPLEMENT_CALL(jint, Procattr, detachSet)(TCN_STDARGS,
+ jlong attr, jint detach)
+{
+ apr_procattr_t *a = J2P(attr, apr_procattr_t *);
+
+ UNREFERENCED_STDARGS;
+ return (jint)apr_procattr_detach_set(a, (apr_int32_t)detach);
+}
+
+TCN_IMPLEMENT_CALL(jint, Procattr, errorCheckSet)(TCN_STDARGS,
+ jlong attr, jint chk)
+{
+ apr_procattr_t *a = J2P(attr, apr_procattr_t *);
+
+ UNREFERENCED_STDARGS;
+ return (jint)apr_procattr_error_check_set(a, (apr_int32_t)chk);
+}
+
+TCN_IMPLEMENT_CALL(jint, Procattr, addrspaceSet)(TCN_STDARGS,
+ jlong attr, jint addr)
+{
+ apr_procattr_t *a = J2P(attr, apr_procattr_t *);
+
+ UNREFERENCED_STDARGS;
+ return (jint)apr_procattr_addrspace_set(a, (apr_int32_t)addr);
+}
+
+TCN_IMPLEMENT_CALL(jlong, Proc, alloc)(TCN_STDARGS,
+ jlong pool)
+{
+ apr_pool_t *p = J2P(pool, apr_pool_t *);
+ apr_proc_t *proc;
+
+ UNREFERENCED_STDARGS;
+ proc = (apr_proc_t *)apr_pcalloc(p, sizeof(apr_proc_t));
+
+ return P2J(proc);
+}
+
+#define MAX_ARGS_SIZE 1024
+#define MAX_ENV_SIZE 1024
+
+TCN_IMPLEMENT_CALL(jint, Proc, create)(TCN_STDARGS, jlong proc,
+ jstring progname,
+ jobjectArray args,
+ jobjectArray env,
+ jlong attr, jlong pool)
+{
+ apr_status_t rv;
+ apr_pool_t *p = J2P(pool, apr_pool_t *);
+ apr_procattr_t *a = J2P(attr, apr_procattr_t *);
+ apr_proc_t *np = J2P(proc, apr_proc_t *);
+ TCN_ALLOC_CSTRING(progname);
+ char *s_args[MAX_ARGS_SIZE];
+ char *s_env[MAX_ENV_SIZE];
+ const char * const *pargs = NULL;
+ const char * const *penv = NULL;
+ jsize as = 0;
+ jsize es = 0;
+ jsize i;
+
+ UNREFERENCED(o);
+ if (args)
+ as = (*e)->GetArrayLength(e, args);
+ if (env)
+ es = (*e)->GetArrayLength(e, env);
+ if (as > (MAX_ARGS_SIZE - 1) || es > (MAX_ENV_SIZE - 2)) {
+ TCN_FREE_CSTRING(progname);
+ return APR_EINVAL;
+ }
+ if (as) {
+ for (i = 0; i < as; i++) {
+ jstring str = (*e)->GetObjectArrayElement(e, args, i);
+ s_args[i] = tcn_get_string(e, str);
+ (*e)->DeleteLocalRef(e, str);
+ }
+ s_args[i] = NULL;
+ pargs = (const char * const *)&s_args[0];
+ }
+ if (es) {
+ for (i = 0; i < es; i++) {
+ jstring str = (*e)->GetObjectArrayElement(e, env, i);
+ s_env[i] = tcn_get_string(e, str);
+ (*e)->DeleteLocalRef(e, str);
+ }
+#ifdef WIN32
+ s_env[i++] = apr_psprintf(p, TCN_PARENT_IDE "=%d", getpid());
+#endif
+ s_env[i] = NULL;
+ penv = (const char * const *)&s_env[0];
+ }
+#ifdef WIN32
+ else {
+ char pps[32];
+ itoa(getpid(), pps, 10);
+ SetEnvironmentVariable(TCN_PARENT_IDE, pps);
+ }
+#endif
+ rv = apr_proc_create(np, J2S(progname), pargs,
+ penv, a, p);
+#ifdef WIN32
+ if (!es)
+ SetEnvironmentVariable(TCN_PARENT_IDE, NULL);
+#endif
+
+ /* Free local resources */
+ TCN_FREE_CSTRING(progname);
+ for (i = 0; i < as; i++) {
+ if (s_args[i])
+ free(s_args[i]);
+ }
+ for (i = 0; i < es; i++) {
+ if (s_env[i])
+ free(s_env[i]);
+ }
+ return rv;
+}
+
+TCN_IMPLEMENT_CALL(jint, Proc, wait)(TCN_STDARGS, jlong proc,
+ jintArray rvals, jint waithow)
+{
+ apr_status_t rv;
+ apr_proc_t *p = J2P(proc, apr_proc_t *);
+ int exitcode;
+ apr_exit_why_e exitwhy;
+
+ UNREFERENCED(o);
+
+ rv = apr_proc_wait(p, &exitcode, &exitwhy, (apr_wait_how_e)waithow);
+ if (rv == APR_SUCCESS && rvals) {
+ jsize n = (*e)->GetArrayLength(e, rvals);
+ if (n > 1) {
+ jint *ints = (*e)->GetIntArrayElements(e, rvals, NULL);
+ ints[0] = exitcode;
+ ints[1] = exitwhy;
+ (*e)->ReleaseIntArrayElements(e, rvals, ints, 0);
+ }
+ }
+ return rv;
+}
+
+TCN_IMPLEMENT_CALL(jint, Proc, waitAllProcs)(TCN_STDARGS,
+ jlong proc, jintArray rvals,
+ jint waithow, jlong pool)
+{
+ apr_status_t rv;
+ apr_proc_t *p = J2P(proc, apr_proc_t *);
+ apr_pool_t *c = J2P(pool, apr_pool_t *);
+ int exitcode;
+ apr_exit_why_e exitwhy;
+
+ UNREFERENCED(o);
+
+ rv = apr_proc_wait_all_procs(p, &exitcode, &exitwhy,
+ (apr_wait_how_e)waithow, c);
+ if (rv == APR_SUCCESS && rvals) {
+ jsize n = (*e)->GetArrayLength(e, rvals);
+ if (n > 1) {
+ jint *ints = (*e)->GetIntArrayElements(e, rvals, NULL);
+ ints[0] = exitcode;
+ ints[1] = exitwhy;
+ (*e)->ReleaseIntArrayElements(e, rvals, ints, 0);
+ }
+ }
+ return rv;
+}
+
+TCN_IMPLEMENT_CALL(jint, Proc, detach)(TCN_STDARGS, jint daemonize)
+{
+
+ UNREFERENCED_STDARGS;
+#if defined(WIN32) || defined (NETWARE)
+ UNREFERENCED(daemonize);
+ return APR_ENOTIMPL;
+#else
+ return (jint)apr_proc_detach(daemonize);
+#endif
+}
+
+TCN_IMPLEMENT_CALL(jint, Proc, kill)(TCN_STDARGS, jlong proc, jint sig)
+{
+ apr_proc_t *p = J2P(proc, apr_proc_t *);
+
+ UNREFERENCED_STDARGS;
+ return (jint)apr_proc_kill(p, (int)sig);
+}
+
+TCN_IMPLEMENT_CALL(void, Pool, noteSubprocess)(TCN_STDARGS, jlong pool,
+ jlong proc, jint how)
+{
+ apr_proc_t *p = J2P(proc, apr_proc_t *);
+ apr_pool_t *a = J2P(pool, apr_pool_t *);
+
+ UNREFERENCED_STDARGS;
+ apr_pool_note_subprocess(a, p, (apr_kill_conditions_e)how);
+}
+
+TCN_IMPLEMENT_CALL(jint, Proc, fork)(TCN_STDARGS,
+ jlongArray proc,
+ jlong pool)
+{
+ apr_status_t rv = APR_EINVAL;
+
+#if APR_HAS_FORK
+ apr_pool_t *p = J2P(pool, apr_pool_t *);
+ apr_proc_t *f = apr_pcalloc(p, sizeof(apr_proc_t));
+
+ UNREFERENCED(o);
+
+ rv = apr_proc_fork(f, p);
+ if (rv == APR_SUCCESS && proc) {
+ jsize n = (*e)->GetArrayLength(e, proc);
+ if (n > 0) {
+ jlong *rp = (*e)->GetLongArrayElements(e, proc, NULL);
+ rp[0] = P2J(f);
+ (*e)->ReleaseLongArrayElements(e, proc, rp, 0);
+ }
+ }
+#else
+ UNREFERENCED_STDARGS;
+ UNREFERENCED(proc);
+ UNREFERENCED(pool);
+
+#endif
+ return rv;
+}
+
+TCN_IMPLEMENT_CALL(void, Procattr, errfnSet)(TCN_STDARGS, jlong attr,
+ jlong pool, jobject obj)
+{
+ apr_procattr_t *a = J2P(attr, apr_procattr_t *);
+ apr_pool_t *p = J2P(pool, apr_pool_t *);
+ tcn_callback_t *cb = (tcn_callback_t *)malloc(sizeof(tcn_callback_t));
+ jclass cls;
+
+ UNREFERENCED(o);
+
+ if (cb == NULL) {
+ return;
+ }
+ cls = (*e)->GetObjectClass(e, obj);
+ cb->obj = (*e)->NewGlobalRef(e, obj);
+ cb->mid[0] = (*e)->GetMethodID(e, cls, "callback", "(JILjava/lang/String;)V");
+
+ apr_pool_userdata_setn(cb, ERRFN_USERDATA_KEY, child_errfn_pool_cleanup, p);
+ apr_procattr_child_errfn_set(a, generic_child_errfn);
+
+}
+
+TCN_IMPLEMENT_CALL(jint, Procattr, userSet)(TCN_STDARGS,
+ jlong attr,
+ jstring username,
+ jstring password)
+{
+
+#if ((APR_MAJOR_VERSION >= 1) && (APR_MINOR_VERSION >= 1))
+ apr_status_t rv;
+ apr_procattr_t *a = J2P(attr, apr_procattr_t *);
+ TCN_ALLOC_CSTRING(username);
+#if APR_PROCATTR_USER_SET_REQUIRES_PASSWORD
+ TCN_ALLOC_CSTRING(password);
+#else
+ const char *cpassword = NULL;
+#endif
+ UNREFERENCED(o);
+
+ rv = apr_procattr_user_set(a, J2S(username), J2S(password));
+ TCN_FREE_CSTRING(username);
+#if APR_PROCATTR_USER_SET_REQUIRES_PASSWORD
+ TCN_FREE_CSTRING(password);
+#endif
+ return (jint) rv;
+#else
+ UNREFERENCED_STDARGS;
+ UNREFERENCED(attr);
+ UNREFERENCED(username);
+ UNREFERENCED(password);
+
+ return APR_ENOTIMPL;
+#endif
+}
+
+TCN_IMPLEMENT_CALL(jint, Procattr, groupSet)(TCN_STDARGS,
+ jlong attr,
+ jstring group)
+{
+
+#if ((APR_MAJOR_VERSION >= 1) && (APR_MINOR_VERSION >= 1))
+ apr_status_t rv;
+ apr_procattr_t *a = J2P(attr, apr_procattr_t *);
+ TCN_ALLOC_CSTRING(group);
+
+ UNREFERENCED(o);
+
+ rv = apr_procattr_group_set(a, J2S(group));
+ TCN_FREE_CSTRING(group);
+ return (jint) rv;
+#else
+ UNREFERENCED_STDARGS;
+ UNREFERENCED(attr);
+ UNREFERENCED(group);
+
+ return APR_ENOTIMPL;
+#endif
+}
diff --git a/jni/native/src/shm.c b/jni/native/src/shm.c
new file mode 100644
index 0000000..a415585
--- /dev/null
+++ b/jni/native/src/shm.c
@@ -0,0 +1,127 @@
+/* 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: shm.c 1442587 2013-02-05 13:49:48Z rjung $
+ */
+
+#include "tcn.h"
+#include "apr_shm.h"
+
+TCN_IMPLEMENT_CALL(jlong, Shm, create)(TCN_STDARGS, jlong reqsize,
+ jstring filename,
+ jlong pool)
+{
+ apr_pool_t *p = J2P(pool, apr_pool_t *);
+ const char *fname = NULL;
+ apr_shm_t *shm;
+
+
+ UNREFERENCED(o);
+ if (filename)
+ fname = (const char *)((*e)->GetStringUTFChars(e, filename, 0));
+ TCN_THROW_IF_ERR(apr_shm_create(&shm, (apr_size_t)reqsize,
+ fname, p), shm);
+
+cleanup:
+ if (fname)
+ (*e)->ReleaseStringUTFChars(e, filename, fname);
+ return P2J(shm);
+}
+
+TCN_IMPLEMENT_CALL(jint, Shm, remove)(TCN_STDARGS,
+ jstring filename,
+ jlong pool)
+{
+ apr_status_t rv;
+ apr_pool_t *p = J2P(pool, apr_pool_t *);
+ TCN_ALLOC_CSTRING(filename);
+
+
+ UNREFERENCED(o);
+ rv = apr_shm_remove(J2S(filename), p);
+ TCN_FREE_CSTRING(filename);
+
+ return (jint)rv;
+}
+
+TCN_IMPLEMENT_CALL(jint, Shm, destroy)(TCN_STDARGS, jlong shm)
+{
+ apr_shm_t *s = J2P(shm, apr_shm_t *);
+
+ UNREFERENCED_STDARGS;
+ return (jint)apr_shm_destroy(s);
+}
+
+TCN_IMPLEMENT_CALL(jlong, Shm, attach)(TCN_STDARGS,
+ jstring filename,
+ jlong pool)
+{
+ apr_pool_t *p = J2P(pool, apr_pool_t *);
+ const char *fname = NULL;
+ apr_shm_t *shm;
+
+
+ UNREFERENCED(o);
+ if (filename)
+ fname = (const char *)((*e)->GetStringUTFChars(e, filename, 0));
+ TCN_THROW_IF_ERR(apr_shm_attach(&shm, fname, p), shm);
+
+cleanup:
+ if (fname)
+ (*e)->ReleaseStringUTFChars(e, filename, fname);
+ return P2J(shm);
+}
+
+TCN_IMPLEMENT_CALL(jint, Shm, detach)(TCN_STDARGS, jlong shm)
+{
+ apr_shm_t *s = J2P(shm, apr_shm_t *);
+
+ UNREFERENCED_STDARGS;
+ return (jint)apr_shm_detach(s);
+}
+
+TCN_IMPLEMENT_CALL(jlong, Shm, baseaddr)(TCN_STDARGS, jlong shm)
+{
+ apr_shm_t *s = J2P(shm, apr_shm_t *);
+
+ UNREFERENCED_STDARGS;
+ return P2J(apr_shm_baseaddr_get(s));
+}
+
+TCN_IMPLEMENT_CALL(jlong, Shm, size)(TCN_STDARGS, jlong shm)
+{
+ apr_shm_t *s = J2P(shm, apr_shm_t *);
+
+ UNREFERENCED_STDARGS;
+ return (jlong)apr_shm_size_get(s);
+}
+
+TCN_IMPLEMENT_CALL(jobject, Shm, buffer)(TCN_STDARGS, jlong shm)
+{
+ apr_shm_t *s = J2P(shm, apr_shm_t *);
+ jlong sz = (jlong)apr_shm_size_get(s);
+ void *a;
+
+ UNREFERENCED(o);
+
+ if ((a = apr_shm_baseaddr_get(s)) != NULL)
+ return (*e)->NewDirectByteBuffer(e, a, sz);
+ else
+ return NULL;
+}
diff --git a/jni/native/src/ssl.c b/jni/native/src/ssl.c
new file mode 100644
index 0000000..e8aeaa0
--- /dev/null
+++ b/jni/native/src/ssl.c
@@ -0,0 +1,1222 @@
+/* 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: ssl.c 1559182 2014-01-17 16:54:20Z schultz $
+ */
+
+#include "tcn.h"
+#include "apr_file_io.h"
+#include "apr_thread_mutex.h"
+#include "apr_atomic.h"
+#include "apr_poll.h"
+
+#ifdef HAVE_OPENSSL
+#include "ssl_private.h"
+
+static int ssl_initialized = 0;
+static char *ssl_global_rand_file = NULL;
+extern apr_pool_t *tcn_global_pool;
+
+ENGINE *tcn_ssl_engine = NULL;
+void *SSL_temp_keys[SSL_TMP_KEY_MAX];
+tcn_pass_cb_t tcn_password_callback;
+
+/* Global reference to the pool used by the dynamic mutexes */
+static apr_pool_t *dynlockpool = NULL;
+
+/* Dynamic lock structure */
+struct CRYPTO_dynlock_value {
+ apr_pool_t *pool;
+ const char* file;
+ int line;
+ apr_thread_mutex_t *mutex;
+};
+
+
+/*
+ * Handle the Temporary RSA Keys and DH Params
+ */
+
+#define SSL_TMP_KEY_FREE(type, idx) \
+ if (SSL_temp_keys[idx]) { \
+ type##_free((type *)SSL_temp_keys[idx]); \
+ SSL_temp_keys[idx] = NULL; \
+ } else (void)(0)
+
+#define SSL_TMP_KEYS_FREE(type) \
+ SSL_TMP_KEY_FREE(type, SSL_TMP_KEY_##type##_512); \
+ SSL_TMP_KEY_FREE(type, SSL_TMP_KEY_##type##_1024); \
+ SSL_TMP_KEY_FREE(type, SSL_TMP_KEY_##type##_2048); \
+ SSL_TMP_KEY_FREE(type, SSL_TMP_KEY_##type##_4096)
+
+#define SSL_TMP_KEY_INIT_RSA(bits) \
+ ssl_tmp_key_init_rsa(bits, SSL_TMP_KEY_RSA_##bits)
+
+#define SSL_TMP_KEY_INIT_DH(bits) \
+ ssl_tmp_key_init_dh(bits, SSL_TMP_KEY_DH_##bits)
+
+#define SSL_TMP_KEYS_INIT(R) \
+ SSL_temp_keys[SSL_TMP_KEY_RSA_2048] = NULL; \
+ SSL_temp_keys[SSL_TMP_KEY_RSA_4096] = NULL; \
+ R |= SSL_TMP_KEY_INIT_RSA(512); \
+ R |= SSL_TMP_KEY_INIT_RSA(1024); \
+ R |= SSL_TMP_KEY_INIT_DH(512); \
+ R |= SSL_TMP_KEY_INIT_DH(1024); \
+ R |= SSL_TMP_KEY_INIT_DH(2048); \
+ R |= SSL_TMP_KEY_INIT_DH(4096)
+
+/*
+ * supported_ssl_opts is a bitmask that contains all supported SSL_OP_*
+ * options at compile-time. This is used in hasOp to determine which
+ * SSL_OP_* options are available at runtime.
+ *
+ * Note that at least up through OpenSSL 0.9.8o, checking SSL_OP_ALL will
+ * return JNI_FALSE because SSL_OP_ALL is a mask that covers all bug
+ * workarounds for OpenSSL including future workarounds that are defined
+ * to be in the least-significant 3 nibbles of the SSL_OP_* bit space.
+ *
+ * This implementation has chosen NOT to simply set all those lower bits
+ * so that the return value for SSL_OP_FUTURE_WORKAROUND will only be
+ * reported by versions that actually support that specific workaround.
+ */
+static const jint supported_ssl_opts = 0
+/*
+ Specifically skip SSL_OP_ALL
+#ifdef SSL_OP_ALL
+ | SSL_OP_ALL
+#endif
+*/
+#ifdef SSL_OP_ALLOW_UNSAFE_LEGACY_RENEGOTIATION
+ | SSL_OP_ALLOW_UNSAFE_LEGACY_RENEGOTIATION
+#endif
+
+#ifdef SSL_OP_CIPHER_SERVER_PREFERENCE
+ | SSL_OP_CIPHER_SERVER_PREFERENCE
+#endif
+
+#ifdef SSL_OP_CRYPTOPRO_TLSEXT_BUG
+ | SSL_OP_CRYPTOPRO_TLSEXT_BUG
+#endif
+
+#ifdef SSL_OP_DONT_INSERT_EMPTY_FRAGMENTS
+ | SSL_OP_DONT_INSERT_EMPTY_FRAGMENTS
+#endif
+
+#ifdef SSL_OP_EPHEMERAL_RSA
+ | SSL_OP_EPHEMERAL_RSA
+#endif
+
+#ifdef SSL_OP_LEGACY_SERVER_CONNECT
+ | SSL_OP_LEGACY_SERVER_CONNECT
+#endif
+
+#ifdef SSL_OP_MICROSOFT_BIG_SSLV3_BUFFER
+ | SSL_OP_MICROSOFT_BIG_SSLV3_BUFFER
+#endif
+
+#ifdef SSL_OP_MICROSOFT_SESS_ID_BUG
+ | SSL_OP_MICROSOFT_SESS_ID_BUG
+#endif
+
+#ifdef SSL_OP_MSIE_SSLV2_RSA_PADDING
+ | SSL_OP_MSIE_SSLV2_RSA_PADDING
+#endif
+
+#ifdef SSL_OP_NETSCAPE_CA_DN_BUG
+ | SSL_OP_NETSCAPE_CA_DN_BUG
+#endif
+
+#ifdef SSL_OP_NETSCAPE_CHALLENGE_BUG
+ | SSL_OP_NETSCAPE_CHALLENGE_BUG
+#endif
+
+#ifdef SSL_OP_NETSCAPE_DEMO_CIPHER_CHANGE_BUG
+ | SSL_OP_NETSCAPE_DEMO_CIPHER_CHANGE_BUG
+#endif
+
+#ifdef SSL_OP_NETSCAPE_REUSE_CIPHER_CHANGE_BUG
+ | SSL_OP_NETSCAPE_REUSE_CIPHER_CHANGE_BUG
+#endif
+
+#ifdef SSL_OP_NO_COMPRESSION
+ | SSL_OP_NO_COMPRESSION
+#endif
+
+#ifdef SSL_OP_NO_QUERY_MTU
+ | SSL_OP_NO_QUERY_MTU
+#endif
+
+#ifdef SSL_OP_NO_SESSION_RESUMPTION_ON_RENEGOTIATION
+ | SSL_OP_NO_SESSION_RESUMPTION_ON_RENEGOTIATION
+#endif
+
+#ifdef SSL_OP_NO_SSLv2
+ | SSL_OP_NO_SSLv2
+#endif
+
+#ifdef SSL_OP_NO_SSLv3
+ | SSL_OP_NO_SSLv3
+#endif
+
+#ifdef SSL_OP_NO_TICKET
+ | SSL_OP_NO_TICKET
+#endif
+
+#ifdef SSL_OP_NO_TLSv1
+ | SSL_OP_NO_TLSv1
+#endif
+
+#ifdef SSL_OP_PKCS1_CHECK_1
+ | SSL_OP_PKCS1_CHECK_1
+#endif
+
+#ifdef SSL_OP_PKCS1_CHECK_2
+ | SSL_OP_PKCS1_CHECK_2
+#endif
+
+#ifdef SSL_OP_SINGLE_DH_USE
+ | SSL_OP_SINGLE_DH_USE
+#endif
+
+#ifdef SSL_OP_SINGLE_ECDH_USE
+ | SSL_OP_SINGLE_ECDH_USE
+#endif
+
+#ifdef SSL_OP_SSLEAY_080_CLIENT_DH_BUG
+ | SSL_OP_SSLEAY_080_CLIENT_DH_BUG
+#endif
+
+#ifdef SSL_OP_SSLREF2_REUSE_CERT_TYPE_BUG
+ | SSL_OP_SSLREF2_REUSE_CERT_TYPE_BUG
+#endif
+
+#ifdef SSL_OP_TLS_BLOCK_PADDING_BUG
+ | SSL_OP_TLS_BLOCK_PADDING_BUG
+#endif
+
+#ifdef SSL_OP_TLS_D5_BUG
+ | SSL_OP_TLS_D5_BUG
+#endif
+
+#ifdef SSL_OP_TLS_ROLLBACK_BUG
+ | SSL_OP_TLS_ROLLBACK_BUG
+#endif
+ | 0;
+
+static int ssl_tmp_key_init_rsa(int bits, int idx)
+{
+ if (!(SSL_temp_keys[idx] =
+ RSA_generate_key(bits, RSA_F4, NULL, NULL)))
+ return 1;
+ else
+ return 0;
+}
+
+static int ssl_tmp_key_init_dh(int bits, int idx)
+{
+ if (!(SSL_temp_keys[idx] =
+ SSL_dh_get_tmp_param(bits)))
+ return 1;
+ else
+ return 0;
+}
+
+
+TCN_IMPLEMENT_CALL(jint, SSL, version)(TCN_STDARGS)
+{
+ UNREFERENCED_STDARGS;
+ return OPENSSL_VERSION_NUMBER;
+}
+
+TCN_IMPLEMENT_CALL(jstring, SSL, versionString)(TCN_STDARGS)
+{
+ UNREFERENCED(o);
+ return AJP_TO_JSTRING(OPENSSL_VERSION_TEXT);
+}
+
+/*
+ * the various processing hooks
+ */
+static apr_status_t ssl_init_cleanup(void *data)
+{
+ UNREFERENCED(data);
+
+ if (!ssl_initialized)
+ return APR_SUCCESS;
+ ssl_initialized = 0;
+
+ if (tcn_password_callback.cb.obj) {
+ JNIEnv *env;
+ tcn_get_java_env(&env);
+ TCN_UNLOAD_CLASS(env,
+ tcn_password_callback.cb.obj);
+ }
+
+ SSL_TMP_KEYS_FREE(RSA);
+ SSL_TMP_KEYS_FREE(DH);
+ /*
+ * Try to kill the internals of the SSL library.
+ */
+#if OPENSSL_VERSION_NUMBER >= 0x00907001
+ /* Corresponds to OPENSSL_load_builtin_modules():
+ * XXX: borrowed from apps.h, but why not CONF_modules_free()
+ * which also invokes CONF_modules_finish()?
+ */
+ CONF_modules_unload(1);
+#endif
+ /* Corresponds to SSL_library_init: */
+ EVP_cleanup();
+#if HAVE_ENGINE_LOAD_BUILTIN_ENGINES
+ ENGINE_cleanup();
+#endif
+#if OPENSSL_VERSION_NUMBER >= 0x00907001
+ CRYPTO_cleanup_all_ex_data();
+#endif
+ ERR_remove_state(0);
+
+ /* Don't call ERR_free_strings here; ERR_load_*_strings only
+ * actually load the error strings once per process due to static
+ * variable abuse in OpenSSL. */
+
+ /*
+ * TODO: determine somewhere we can safely shove out diagnostics
+ * (when enabled) at this late stage in the game:
+ * CRYPTO_mem_leaks_fp(stderr);
+ */
+ return APR_SUCCESS;
+}
+
+#ifndef OPENSSL_NO_ENGINE
+/* Try to load an engine in a shareable library */
+static ENGINE *ssl_try_load_engine(const char *engine)
+{
+ ENGINE *e = ENGINE_by_id("dynamic");
+ if (e) {
+ if (!ENGINE_ctrl_cmd_string(e, "SO_PATH", engine, 0)
+ || !ENGINE_ctrl_cmd_string(e, "LOAD", NULL, 0)) {
+ ENGINE_free(e);
+ e = NULL;
+ }
+ }
+ return e;
+}
+#endif
+
+/*
+ * To ensure thread-safetyness in OpenSSL
+ */
+
+static apr_thread_mutex_t **ssl_lock_cs;
+static int ssl_lock_num_locks;
+
+static void ssl_thread_lock(int mode, int type,
+ const char *file, int line)
+{
+ UNREFERENCED(file);
+ UNREFERENCED(line);
+ if (type < ssl_lock_num_locks) {
+ if (mode & CRYPTO_LOCK) {
+ apr_thread_mutex_lock(ssl_lock_cs[type]);
+ }
+ else {
+ apr_thread_mutex_unlock(ssl_lock_cs[type]);
+ }
+ }
+}
+
+static unsigned long ssl_thread_id(void)
+{
+ /* OpenSSL needs this to return an unsigned long. On OS/390, the pthread
+ * id is a structure twice that big. Use the TCB pointer instead as a
+ * unique unsigned long.
+ */
+#ifdef __MVS__
+ struct PSA {
+ char unmapped[540];
+ unsigned long PSATOLD;
+ } *psaptr = 0;
+
+ return psaptr->PSATOLD;
+#elif defined(WIN32)
+ return (unsigned long)GetCurrentThreadId();
+#else
+ return (unsigned long)(apr_os_thread_current());
+#endif
+}
+
+static apr_status_t ssl_thread_cleanup(void *data)
+{
+ UNREFERENCED(data);
+ CRYPTO_set_locking_callback(NULL);
+ CRYPTO_set_id_callback(NULL);
+ CRYPTO_set_dynlock_create_callback(NULL);
+ CRYPTO_set_dynlock_lock_callback(NULL);
+ CRYPTO_set_dynlock_destroy_callback(NULL);
+
+ dynlockpool = NULL;
+
+ /* Let the registered mutex cleanups do their own thing
+ */
+ return APR_SUCCESS;
+}
+
+/*
+ * Dynamic lock creation callback
+ */
+static struct CRYPTO_dynlock_value *ssl_dyn_create_function(const char *file,
+ int line)
+{
+ struct CRYPTO_dynlock_value *value;
+ apr_pool_t *p;
+ apr_status_t rv;
+
+ /*
+ * We need a pool to allocate our mutex. Since we can't clear
+ * allocated memory from a pool, create a subpool that we can blow
+ * away in the destruction callback.
+ */
+ rv = apr_pool_create(&p, dynlockpool);
+ if (rv != APR_SUCCESS) {
+ /* TODO log that fprintf(stderr, "Failed to create subpool for dynamic lock"); */
+ return NULL;
+ }
+
+ value = (struct CRYPTO_dynlock_value *)apr_palloc(p,
+ sizeof(struct CRYPTO_dynlock_value));
+ if (!value) {
+ /* TODO log that fprintf(stderr, "Failed to allocate dynamic lock structure"); */
+ return NULL;
+ }
+
+ value->pool = p;
+ /* Keep our own copy of the place from which we were created,
+ using our own pool. */
+ value->file = apr_pstrdup(p, file);
+ value->line = line;
+ rv = apr_thread_mutex_create(&(value->mutex), APR_THREAD_MUTEX_DEFAULT,
+ p);
+ if (rv != APR_SUCCESS) {
+ /* TODO log that fprintf(stderr, "Failed to create thread mutex for dynamic lock"); */
+ apr_pool_destroy(p);
+ return NULL;
+ }
+ return value;
+}
+
+/*
+ * Dynamic locking and unlocking function
+ */
+
+static void ssl_dyn_lock_function(int mode, struct CRYPTO_dynlock_value *l,
+ const char *file, int line)
+{
+
+
+ if (mode & CRYPTO_LOCK) {
+ apr_thread_mutex_lock(l->mutex);
+ }
+ else {
+ apr_thread_mutex_unlock(l->mutex);
+ }
+}
+
+/*
+ * Dynamic lock destruction callback
+ */
+static void ssl_dyn_destroy_function(struct CRYPTO_dynlock_value *l,
+ const char *file, int line)
+{
+ apr_status_t rv;
+ rv = apr_thread_mutex_destroy(l->mutex);
+ if (rv != APR_SUCCESS) {
+ /* TODO log that fprintf(stderr, "Failed to destroy mutex for dynamic lock %s:%d", l->file, l->line); */
+ }
+
+ /* Trust that whomever owned the CRYPTO_dynlock_value we were
+ * passed has no future use for it...
+ */
+ apr_pool_destroy(l->pool);
+}
+static void ssl_thread_setup(apr_pool_t *p)
+{
+ int i;
+
+ ssl_lock_num_locks = CRYPTO_num_locks();
+ ssl_lock_cs = apr_palloc(p, ssl_lock_num_locks * sizeof(*ssl_lock_cs));
+
+ for (i = 0; i < ssl_lock_num_locks; i++) {
+ apr_thread_mutex_create(&(ssl_lock_cs[i]),
+ APR_THREAD_MUTEX_DEFAULT, p);
+ }
+
+ CRYPTO_set_id_callback(ssl_thread_id);
+ CRYPTO_set_locking_callback(ssl_thread_lock);
+
+ /* Set up dynamic locking scaffolding for OpenSSL to use at its
+ * convenience.
+ */
+ dynlockpool = p;
+ CRYPTO_set_dynlock_create_callback(ssl_dyn_create_function);
+ CRYPTO_set_dynlock_lock_callback(ssl_dyn_lock_function);
+ CRYPTO_set_dynlock_destroy_callback(ssl_dyn_destroy_function);
+
+ apr_pool_cleanup_register(p, NULL, ssl_thread_cleanup,
+ apr_pool_cleanup_null);
+}
+
+static int ssl_rand_choosenum(int l, int h)
+{
+ int i;
+ char buf[50];
+
+ apr_snprintf(buf, sizeof(buf), "%.0f",
+ (((double)(rand()%RAND_MAX)/RAND_MAX)*(h-l)));
+ i = atoi(buf)+1;
+ if (i < l) i = l;
+ if (i > h) i = h;
+ return i;
+}
+
+static int ssl_rand_load_file(const char *file)
+{
+ char buffer[APR_PATH_MAX];
+ int n;
+
+ if (file == NULL)
+ file = ssl_global_rand_file;
+ if (file && (strcmp(file, "builtin") == 0))
+ return -1;
+ if (file == NULL)
+ file = RAND_file_name(buffer, sizeof(buffer));
+ if (file) {
+ if (strncmp(file, "egd:", 4) == 0) {
+ if ((n = RAND_egd(file + 4)) > 0)
+ return n;
+ else
+ return -1;
+ }
+ if ((n = RAND_load_file(file, -1)) > 0)
+ return n;
+ }
+ return -1;
+}
+
+/*
+ * writes a number of random bytes (currently 1024) to
+ * file which can be used to initialize the PRNG by calling
+ * RAND_load_file() in a later session
+ */
+static int ssl_rand_save_file(const char *file)
+{
+ char buffer[APR_PATH_MAX];
+ int n;
+
+ if (file == NULL)
+ file = RAND_file_name(buffer, sizeof(buffer));
+ else if ((n = RAND_egd(file)) > 0) {
+ return 0;
+ }
+ if (file == NULL || !RAND_write_file(file))
+ return 0;
+ else
+ return 1;
+}
+
+int SSL_rand_seed(const char *file)
+{
+ unsigned char stackdata[256];
+ static volatile apr_uint32_t counter = 0;
+
+ if (ssl_rand_load_file(file) < 0) {
+ int n;
+ struct {
+ apr_time_t t;
+ pid_t p;
+ unsigned long i;
+ apr_uint32_t u;
+ } _ssl_seed;
+ if (counter == 0) {
+ apr_generate_random_bytes(stackdata, 256);
+ RAND_seed(stackdata, 128);
+ }
+ _ssl_seed.t = apr_time_now();
+ _ssl_seed.p = getpid();
+ _ssl_seed.i = ssl_thread_id();
+ apr_atomic_inc32(&counter);
+ _ssl_seed.u = counter;
+ RAND_seed((unsigned char *)&_ssl_seed, sizeof(_ssl_seed));
+ /*
+ * seed in some current state of the run-time stack (128 bytes)
+ */
+ n = ssl_rand_choosenum(0, sizeof(stackdata)-128-1);
+ RAND_seed(stackdata + n, 128);
+ }
+ return RAND_status();
+}
+
+static int ssl_rand_make(const char *file, int len, int base64)
+{
+ int r;
+ int num = len;
+ BIO *out = NULL;
+
+ out = BIO_new(BIO_s_file());
+ if (out == NULL)
+ return 0;
+ if ((r = BIO_write_filename(out, (char *)file)) < 0) {
+ BIO_free_all(out);
+ return 0;
+ }
+ if (base64) {
+ BIO *b64 = BIO_new(BIO_f_base64());
+ if (b64 == NULL) {
+ BIO_free_all(out);
+ return 0;
+ }
+ out = BIO_push(b64, out);
+ }
+ while (num > 0) {
+ unsigned char buf[4096];
+ int len = num;
+ if (len > sizeof(buf))
+ len = sizeof(buf);
+ r = RAND_bytes(buf, len);
+ if (r <= 0) {
+ BIO_free_all(out);
+ return 0;
+ }
+ BIO_write(out, buf, len);
+ num -= len;
+ }
+ r = BIO_flush(out);
+ BIO_free_all(out);
+ return r > 0 ? 1 : 0;
+}
+
+TCN_IMPLEMENT_CALL(jint, SSL, initialize)(TCN_STDARGS, jstring engine)
+{
+ int r = 0;
+ TCN_ALLOC_CSTRING(engine);
+
+ UNREFERENCED(o);
+ if (!tcn_global_pool) {
+ TCN_FREE_CSTRING(engine);
+ tcn_ThrowAPRException(e, APR_EINVAL);
+ return (jint)APR_EINVAL;
+ }
+ /* Check if already initialized */
+ if (ssl_initialized++) {
+ TCN_FREE_CSTRING(engine);
+ return (jint)APR_SUCCESS;
+ }
+ if (SSLeay() < 0x0090700L) {
+ TCN_FREE_CSTRING(engine);
+ tcn_ThrowAPRException(e, APR_EINVAL);
+ ssl_initialized = 0;
+ return (jint)APR_EINVAL;
+ }
+ /* We must register the library in full, to ensure our configuration
+ * code can successfully test the SSL environment.
+ */
+ CRYPTO_malloc_init();
+ ERR_load_crypto_strings();
+ SSL_load_error_strings();
+ SSL_library_init();
+ OpenSSL_add_all_algorithms();
+#if HAVE_ENGINE_LOAD_BUILTIN_ENGINES
+ ENGINE_load_builtin_engines();
+#endif
+#if OPENSSL_VERSION_NUMBER >= 0x00907001
+ OPENSSL_load_builtin_modules();
+#endif
+
+ /* Initialize thread support */
+ ssl_thread_setup(tcn_global_pool);
+
+#ifndef OPENSSL_NO_ENGINE
+ if (J2S(engine)) {
+ ENGINE *ee = NULL;
+ apr_status_t err = APR_SUCCESS;
+ if(strcmp(J2S(engine), "auto") == 0) {
+ ENGINE_register_all_complete();
+ }
+ else {
+ if ((ee = ENGINE_by_id(J2S(engine))) == NULL
+ && (ee = ssl_try_load_engine(J2S(engine))) == NULL)
+ err = APR_ENOTIMPL;
+ else {
+ if (strcmp(J2S(engine), "chil") == 0)
+ ENGINE_ctrl(ee, ENGINE_CTRL_CHIL_SET_FORKCHECK, 1, 0, 0);
+ if (!ENGINE_set_default(ee, ENGINE_METHOD_ALL))
+ err = APR_ENOTIMPL;
+ }
+ /* Free our "structural" reference. */
+ if (ee)
+ ENGINE_free(ee);
+ }
+ if (err != APR_SUCCESS) {
+ TCN_FREE_CSTRING(engine);
+ ssl_init_cleanup(NULL);
+ tcn_ThrowAPRException(e, err);
+ return (jint)err;
+ }
+ tcn_ssl_engine = ee;
+ }
+#endif
+
+ memset(&tcn_password_callback, 0, sizeof(tcn_pass_cb_t));
+ /* Initialize PRNG
+ * This will in most cases call the builtin
+ * low entropy seed.
+ */
+ SSL_rand_seed(NULL);
+ /* For SSL_get_app_data2() at request time */
+ SSL_init_app_data2_idx();
+
+ SSL_TMP_KEYS_INIT(r);
+ if (r) {
+ TCN_FREE_CSTRING(engine);
+ ssl_init_cleanup(NULL);
+ tcn_ThrowAPRException(e, APR_ENOTIMPL);
+ return APR_ENOTIMPL;
+ }
+ /*
+ * Let us cleanup the ssl library when the library is unloaded
+ */
+ apr_pool_cleanup_register(tcn_global_pool, NULL,
+ ssl_init_cleanup,
+ apr_pool_cleanup_null);
+ TCN_FREE_CSTRING(engine);
+ return (jint)APR_SUCCESS;
+}
+
+TCN_IMPLEMENT_CALL(jboolean, SSL, randLoad)(TCN_STDARGS, jstring file)
+{
+ TCN_ALLOC_CSTRING(file);
+ int r;
+ UNREFERENCED(o);
+ r = SSL_rand_seed(J2S(file));
+ TCN_FREE_CSTRING(file);
+ return r ? JNI_TRUE : JNI_FALSE;
+}
+
+TCN_IMPLEMENT_CALL(jboolean, SSL, randSave)(TCN_STDARGS, jstring file)
+{
+ TCN_ALLOC_CSTRING(file);
+ int r;
+ UNREFERENCED(o);
+ r = ssl_rand_save_file(J2S(file));
+ TCN_FREE_CSTRING(file);
+ return r ? JNI_TRUE : JNI_FALSE;
+}
+
+TCN_IMPLEMENT_CALL(jboolean, SSL, randMake)(TCN_STDARGS, jstring file,
+ jint length, jboolean base64)
+{
+ TCN_ALLOC_CSTRING(file);
+ int r;
+ UNREFERENCED(o);
+ r = ssl_rand_make(J2S(file), length, base64);
+ TCN_FREE_CSTRING(file);
+ return r ? JNI_TRUE : JNI_FALSE;
+}
+
+TCN_IMPLEMENT_CALL(void, SSL, randSet)(TCN_STDARGS, jstring file)
+{
+ TCN_ALLOC_CSTRING(file);
+ UNREFERENCED(o);
+ if (J2S(file)) {
+ ssl_global_rand_file = apr_pstrdup(tcn_global_pool, J2S(file));
+ }
+ TCN_FREE_CSTRING(file);
+}
+
+TCN_IMPLEMENT_CALL(jint, SSL, fipsModeGet)(TCN_STDARGS)
+{
+ UNREFERENCED(o);
+#ifdef OPENSSL_FIPS
+ return FIPS_mode();
+#else
+ /* FIPS is unavailable */
+ tcn_ThrowException(e, "FIPS was not available to tcnative at build time. You will need to re-build tcnative against an OpenSSL with FIPS.");
+
+ return 0;
+#endif
+}
+
+TCN_IMPLEMENT_CALL(jint, SSL, fipsModeSet)(TCN_STDARGS, jint mode)
+{
+ int r = 0;
+ UNREFERENCED(o);
+
+#ifdef OPENSSL_FIPS
+ if(1 != (r = (jint)FIPS_mode_set((int)mode))) {
+ /* arrange to get a human-readable error message */
+ unsigned long err = ERR_get_error();
+ char msg[256];
+
+ /* ERR_load_crypto_strings() already called in initialize() */
+
+ ERR_error_string_n(err, msg, 256);
+
+ tcn_ThrowException(e, msg);
+ }
+#else
+ /* FIPS is unavailable */
+ tcn_ThrowException(e, "FIPS was not available to tcnative at build time. You will need to re-build tcnative against an OpenSSL with FIPS.");
+#endif
+
+ return r;
+}
+
+/* OpenSSL Java Stream BIO */
+
+typedef struct {
+ int refcount;
+ apr_pool_t *pool;
+ tcn_callback_t cb;
+} BIO_JAVA;
+
+
+static apr_status_t generic_bio_cleanup(void *data)
+{
+ BIO *b = (BIO *)data;
+
+ if (b) {
+ BIO_free(b);
+ }
+ return APR_SUCCESS;
+}
+
+void SSL_BIO_close(BIO *bi)
+{
+ if (bi == NULL)
+ return;
+ if (bi->ptr != NULL && (bi->flags & SSL_BIO_FLAG_CALLBACK)) {
+ BIO_JAVA *j = (BIO_JAVA *)bi->ptr;
+ j->refcount--;
+ if (j->refcount == 0) {
+ if (j->pool)
+ apr_pool_cleanup_run(j->pool, bi, generic_bio_cleanup);
+ else
+ BIO_free(bi);
+ }
+ }
+ else
+ BIO_free(bi);
+}
+
+void SSL_BIO_doref(BIO *bi)
+{
+ if (bi == NULL)
+ return;
+ if (bi->ptr != NULL && (bi->flags & SSL_BIO_FLAG_CALLBACK)) {
+ BIO_JAVA *j = (BIO_JAVA *)bi->ptr;
+ j->refcount++;
+ }
+}
+
+
+static int jbs_new(BIO *bi)
+{
+ BIO_JAVA *j;
+
+ if ((j = OPENSSL_malloc(sizeof(BIO_JAVA))) == NULL)
+ return 0;
+ j->pool = NULL;
+ j->refcount = 1;
+ bi->shutdown = 1;
+ bi->init = 0;
+ bi->num = -1;
+ bi->ptr = (char *)j;
+
+ return 1;
+}
+
+static int jbs_free(BIO *bi)
+{
+ if (bi == NULL)
+ return 0;
+ if (bi->ptr != NULL) {
+ BIO_JAVA *j = (BIO_JAVA *)bi->ptr;
+ if (bi->init) {
+ JNIEnv *e = NULL;
+ bi->init = 0;
+ tcn_get_java_env(&e);
+ TCN_UNLOAD_CLASS(e, j->cb.obj);
+ }
+ OPENSSL_free(bi->ptr);
+ }
+ bi->ptr = NULL;
+ return 1;
+}
+
+static int jbs_write(BIO *b, const char *in, int inl)
+{
+ jint ret = 0;
+ if (b->init && in != NULL) {
+ BIO_JAVA *j = (BIO_JAVA *)b->ptr;
+ JNIEnv *e = NULL;
+ jbyteArray jb = (*e)->NewByteArray(e, inl);
+ tcn_get_java_env(&e);
+ if (!(*e)->ExceptionOccurred(e)) {
+ (*e)->SetByteArrayRegion(e, jb, 0, inl, (jbyte *)in);
+ ret = (*e)->CallIntMethod(e, j->cb.obj,
+ j->cb.mid[0], jb);
+ (*e)->ReleaseByteArrayElements(e, jb, (jbyte *)in, JNI_ABORT);
+ (*e)->DeleteLocalRef(e, jb);
+ }
+ }
+ return ret;
+}
+
+static int jbs_read(BIO *b, char *out, int outl)
+{
+ jint ret = 0;
+ if (b->init && out != NULL) {
+ BIO_JAVA *j = (BIO_JAVA *)b->ptr;
+ JNIEnv *e = NULL;
+ jbyteArray jb = (*e)->NewByteArray(e, outl);
+ tcn_get_java_env(&e);
+ if (!(*e)->ExceptionOccurred(e)) {
+ ret = (*e)->CallIntMethod(e, j->cb.obj,
+ j->cb.mid[1], jb);
+ if (ret > 0) {
+ jbyte *jout = (*e)->GetPrimitiveArrayCritical(e, jb, NULL);
+ memcpy(out, jout, ret);
+ (*e)->ReleasePrimitiveArrayCritical(e, jb, jout, 0);
+ }
+ (*e)->DeleteLocalRef(e, jb);
+ }
+ }
+ return ret;
+}
+
+static int jbs_puts(BIO *b, const char *in)
+{
+ int ret = 0;
+ if (b->init && in != NULL) {
+ BIO_JAVA *j = (BIO_JAVA *)b->ptr;
+ JNIEnv *e = NULL;
+ tcn_get_java_env(&e);
+ ret = (*e)->CallIntMethod(e, j->cb.obj,
+ j->cb.mid[2],
+ tcn_new_string(e, in));
+ }
+ return ret;
+}
+
+static int jbs_gets(BIO *b, char *out, int outl)
+{
+ int ret = 0;
+ if (b->init && out != NULL) {
+ BIO_JAVA *j = (BIO_JAVA *)b->ptr;
+ JNIEnv *e = NULL;
+ jobject o;
+ tcn_get_java_env(&e);
+ if ((o = (*e)->CallObjectMethod(e, j->cb.obj,
+ j->cb.mid[3], (jint)(outl - 1)))) {
+ TCN_ALLOC_CSTRING(o);
+ if (J2S(o)) {
+ int l = (int)strlen(J2S(o));
+ if (l < outl) {
+ strcpy(out, J2S(o));
+ ret = outl;
+ }
+ }
+ TCN_FREE_CSTRING(o);
+ }
+ }
+ return ret;
+}
+
+static long jbs_ctrl(BIO *b, int cmd, long num, void *ptr)
+{
+ return 0;
+}
+
+static BIO_METHOD jbs_methods = {
+ BIO_TYPE_FILE,
+ "Java Callback",
+ jbs_write,
+ jbs_read,
+ jbs_puts,
+ jbs_gets,
+ jbs_ctrl,
+ jbs_new,
+ jbs_free,
+ NULL
+};
+
+static BIO_METHOD *BIO_jbs()
+{
+ return(&jbs_methods);
+}
+
+TCN_IMPLEMENT_CALL(jlong, SSL, newBIO)(TCN_STDARGS, jlong pool,
+ jobject callback)
+{
+ BIO *bio = NULL;
+ BIO_JAVA *j;
+ jclass cls;
+
+ UNREFERENCED(o);
+
+ if ((bio = BIO_new(BIO_jbs())) == NULL) {
+ tcn_ThrowException(e, "Create BIO failed");
+ goto init_failed;
+ }
+ j = (BIO_JAVA *)bio->ptr;
+ if ((j = (BIO_JAVA *)bio->ptr) == NULL) {
+ tcn_ThrowException(e, "Create BIO failed");
+ goto init_failed;
+ }
+ j->pool = J2P(pool, apr_pool_t *);
+ if (j->pool) {
+ apr_pool_cleanup_register(j->pool, (const void *)bio,
+ generic_bio_cleanup,
+ apr_pool_cleanup_null);
+ }
+
+ cls = (*e)->GetObjectClass(e, callback);
+ j->cb.mid[0] = (*e)->GetMethodID(e, cls, "write", "([B)I");
+ j->cb.mid[1] = (*e)->GetMethodID(e, cls, "read", "([B)I");
+ j->cb.mid[2] = (*e)->GetMethodID(e, cls, "puts", "(Ljava/lang/String;)I");
+ j->cb.mid[3] = (*e)->GetMethodID(e, cls, "gets", "(I)Ljava/lang/String;");
+ /* TODO: Check if method id's are valid */
+ j->cb.obj = (*e)->NewGlobalRef(e, callback);
+
+ bio->init = 1;
+ bio->flags = SSL_BIO_FLAG_CALLBACK;
+ return P2J(bio);
+init_failed:
+ return 0;
+}
+
+TCN_IMPLEMENT_CALL(jint, SSL, closeBIO)(TCN_STDARGS, jlong bio)
+{
+ BIO *b = J2P(bio, BIO *);
+ UNREFERENCED_STDARGS;
+ SSL_BIO_close(b);
+ return APR_SUCCESS;
+}
+
+TCN_IMPLEMENT_CALL(void, SSL, setPasswordCallback)(TCN_STDARGS,
+ jobject callback)
+{
+ jclass cls;
+
+ UNREFERENCED(o);
+ if (tcn_password_callback.cb.obj) {
+ TCN_UNLOAD_CLASS(e,
+ tcn_password_callback.cb.obj);
+ }
+ cls = (*e)->GetObjectClass(e, callback);
+ tcn_password_callback.cb.mid[0] = (*e)->GetMethodID(e, cls, "callback",
+ "(Ljava/lang/String;)Ljava/lang/String;");
+ /* TODO: Check if method id is valid */
+ tcn_password_callback.cb.obj = (*e)->NewGlobalRef(e, callback);
+
+}
+
+TCN_IMPLEMENT_CALL(void, SSL, setPassword)(TCN_STDARGS, jstring password)
+{
+ TCN_ALLOC_CSTRING(password);
+ UNREFERENCED(o);
+ if (J2S(password)) {
+ strncpy(tcn_password_callback.password, J2S(password), SSL_MAX_PASSWORD_LEN);
+ tcn_password_callback.password[SSL_MAX_PASSWORD_LEN-1] = '\0';
+ }
+ TCN_FREE_CSTRING(password);
+}
+
+TCN_IMPLEMENT_CALL(jboolean, SSL, generateRSATempKey)(TCN_STDARGS, jint idx)
+{
+ int r = 1;
+ UNREFERENCED_STDARGS;
+ SSL_TMP_KEY_FREE(RSA, idx);
+ switch (idx) {
+ case SSL_TMP_KEY_RSA_512:
+ r = SSL_TMP_KEY_INIT_RSA(512);
+ break;
+ case SSL_TMP_KEY_RSA_1024:
+ r = SSL_TMP_KEY_INIT_RSA(1024);
+ break;
+ case SSL_TMP_KEY_RSA_2048:
+ r = SSL_TMP_KEY_INIT_RSA(2048);
+ break;
+ case SSL_TMP_KEY_RSA_4096:
+ r = SSL_TMP_KEY_INIT_RSA(4096);
+ break;
+ }
+ return r ? JNI_FALSE : JNI_TRUE;
+}
+
+TCN_IMPLEMENT_CALL(jboolean, SSL, loadDSATempKey)(TCN_STDARGS, jint idx,
+ jstring file)
+{
+ jboolean r = JNI_FALSE;
+ TCN_ALLOC_CSTRING(file);
+ DH *dh;
+ UNREFERENCED(o);
+
+ if (!J2S(file))
+ return JNI_FALSE;
+ SSL_TMP_KEY_FREE(DSA, idx);
+ if ((dh = SSL_dh_get_param_from_file(J2S(file)))) {
+ SSL_temp_keys[idx] = dh;
+ r = JNI_TRUE;
+ }
+ TCN_FREE_CSTRING(file);
+ return r;
+}
+
+TCN_IMPLEMENT_CALL(jstring, SSL, getLastError)(TCN_STDARGS)
+{
+ char buf[256];
+ UNREFERENCED(o);
+ ERR_error_string(ERR_get_error(), buf);
+ return tcn_new_string(e, buf);
+}
+
+TCN_IMPLEMENT_CALL(jboolean, SSL, hasOp)(TCN_STDARGS, jint op)
+{
+ return op == (op & supported_ssl_opts) ? JNI_TRUE : JNI_FALSE;
+}
+
+#else
+/* OpenSSL is not supported.
+ * Create empty stubs.
+ */
+
+TCN_IMPLEMENT_CALL(jint, SSL, version)(TCN_STDARGS)
+{
+ UNREFERENCED_STDARGS;
+ return 0;
+}
+
+TCN_IMPLEMENT_CALL(jstring, SSL, versionString)(TCN_STDARGS)
+{
+ UNREFERENCED_STDARGS;
+ return NULL;
+}
+
+TCN_IMPLEMENT_CALL(jint, SSL, initialize)(TCN_STDARGS, jstring engine)
+{
+ UNREFERENCED(o);
+ UNREFERENCED(engine);
+ tcn_ThrowAPRException(e, APR_ENOTIMPL);
+ return (jint)APR_ENOTIMPL;
+}
+
+TCN_IMPLEMENT_CALL(jboolean, SSL, randLoad)(TCN_STDARGS, jstring file)
+{
+ UNREFERENCED_STDARGS;
+ UNREFERENCED(file);
+ return JNI_FALSE;
+}
+
+TCN_IMPLEMENT_CALL(jboolean, SSL, randSave)(TCN_STDARGS, jstring file)
+{
+ UNREFERENCED_STDARGS;
+ return JNI_FALSE;
+}
+
+TCN_IMPLEMENT_CALL(jboolean, SSL, randMake)(TCN_STDARGS, jstring file,
+ jint length, jboolean base64)
+{
+ UNREFERENCED_STDARGS;
+ UNREFERENCED(file);
+ UNREFERENCED(length);
+ UNREFERENCED(base64);
+ return JNI_FALSE;
+}
+
+TCN_IMPLEMENT_CALL(void, SSL, randSet)(TCN_STDARGS, jstring file)
+{
+ UNREFERENCED_STDARGS;
+ UNREFERENCED(file);
+}
+
+TCN_IMPLEMENT_CALL(jint, SSL, fipsModeSet)(TCN_STDARGS, jint mode)
+{
+ UNREFERENCED_STDARGS;
+ UNREFERENCED(mode);
+
+ return 0;
+}
+
+TCN_IMPLEMENT_CALL(jlong, SSL, newBIO)(TCN_STDARGS, jlong pool,
+ jobject callback)
+{
+ UNREFERENCED_STDARGS;
+ UNREFERENCED(pool);
+ UNREFERENCED(callback);
+ return 0;
+}
+
+TCN_IMPLEMENT_CALL(jint, SSL, closeBIO)(TCN_STDARGS, jlong bio)
+{
+ UNREFERENCED_STDARGS;
+ UNREFERENCED(bio);
+ return (jint)APR_ENOTIMPL;
+}
+
+TCN_IMPLEMENT_CALL(void, SSL, setPasswordCallback)(TCN_STDARGS,
+ jobject callback)
+{
+ UNREFERENCED_STDARGS;
+ UNREFERENCED(callback);
+}
+
+TCN_IMPLEMENT_CALL(void, SSL, setPassword)(TCN_STDARGS, jstring password)
+{
+ UNREFERENCED_STDARGS;
+ UNREFERENCED(password);
+}
+
+TCN_IMPLEMENT_CALL(jboolean, SSL, generateRSATempKey)(TCN_STDARGS, jint idx)
+{
+ UNREFERENCED_STDARGS;
+ UNREFERENCED(idx);
+ return JNI_FALSE;
+}
+
+TCN_IMPLEMENT_CALL(jboolean, SSL, loadDSATempKey)(TCN_STDARGS, jint idx,
+ jstring file)
+{
+ UNREFERENCED_STDARGS;
+ UNREFERENCED(idx);
+ UNREFERENCED(file);
+ return JNI_FALSE;
+}
+
+TCN_IMPLEMENT_CALL(jstring, SSL, getLastError)(TCN_STDARGS)
+{
+ UNREFERENCED_STDARGS;
+ return NULL;
+}
+
+TCN_IMPLEMENT_CALL(jboolean, SSL, hasOp)(TCN_STDARGS, jint op)
+{
+ UNREFERENCED_STDARGS;
+ UNREFERENCED(op);
+ return JNI_FALSE;
+}
+#endif
diff --git a/jni/native/src/sslcontext.c b/jni/native/src/sslcontext.c
new file mode 100644
index 0000000..3f3450c
--- /dev/null
+++ b/jni/native/src/sslcontext.c
@@ -0,0 +1,812 @@
+/* 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.
+ */
+
+/** SSL Context wrapper
+ *
+ * @author Mladen Turk
+ * @version $Id: sslcontext.c 1585957 2014-04-09 12:54:25Z mturk $
+ */
+
+#include "tcn.h"
+
+#include "apr_file_io.h"
+#include "apr_thread_mutex.h"
+#include "apr_poll.h"
+
+#ifdef HAVE_OPENSSL
+#include "ssl_private.h"
+
+static apr_status_t ssl_context_cleanup(void *data)
+{
+ tcn_ssl_ctxt_t *c = (tcn_ssl_ctxt_t *)data;
+ if (c) {
+ int i;
+ if (c->crl)
+ X509_STORE_free(c->crl);
+ c->crl = NULL;
+ if (c->ctx)
+ SSL_CTX_free(c->ctx);
+ c->ctx = NULL;
+ for (i = 0; i < SSL_AIDX_MAX; i++) {
+ if (c->certs[i]) {
+ X509_free(c->certs[i]);
+ c->certs[i] = NULL;
+ }
+ if (c->keys[i]) {
+ EVP_PKEY_free(c->keys[i]);
+ c->keys[i] = NULL;
+ }
+ }
+ if (c->bio_is) {
+ SSL_BIO_close(c->bio_is);
+ c->bio_is = NULL;
+ }
+ if (c->bio_os) {
+ SSL_BIO_close(c->bio_os);
+ c->bio_os = NULL;
+ }
+ }
+ return APR_SUCCESS;
+}
+
+/* Initialize server context */
+TCN_IMPLEMENT_CALL(jlong, SSLContext, make)(TCN_STDARGS, jlong pool,
+ jint protocol, jint mode)
+{
+ apr_pool_t *p = J2P(pool, apr_pool_t *);
+ tcn_ssl_ctxt_t *c = NULL;
+ SSL_CTX *ctx = NULL;
+ UNREFERENCED(o);
+
+ switch (protocol) {
+ case SSL_PROTOCOL_SSLV2:
+ if (mode == SSL_MODE_CLIENT)
+ ctx = SSL_CTX_new(SSLv2_client_method());
+ else if (mode == SSL_MODE_SERVER)
+ ctx = SSL_CTX_new(SSLv2_server_method());
+ else
+ ctx = SSL_CTX_new(SSLv2_method());
+ break;
+ case SSL_PROTOCOL_SSLV3:
+ if (mode == SSL_MODE_CLIENT)
+ ctx = SSL_CTX_new(SSLv3_client_method());
+ else if (mode == SSL_MODE_SERVER)
+ ctx = SSL_CTX_new(SSLv3_server_method());
+ else
+ ctx = SSL_CTX_new(SSLv3_method());
+ break;
+ case SSL_PROTOCOL_SSLV2 | SSL_PROTOCOL_SSLV3:
+ case SSL_PROTOCOL_SSLV2 | SSL_PROTOCOL_TLSV1:
+ case SSL_PROTOCOL_ALL:
+ case SSL_PROTOCOL_SSLV3 | SSL_PROTOCOL_TLSV1:
+ if (mode == SSL_MODE_CLIENT)
+ ctx = SSL_CTX_new(SSLv23_client_method());
+ else if (mode == SSL_MODE_SERVER)
+ ctx = SSL_CTX_new(SSLv23_server_method());
+ else
+ ctx = SSL_CTX_new(SSLv23_method());
+ break;
+ case SSL_PROTOCOL_TLSV1:
+ if (mode == SSL_MODE_CLIENT)
+ ctx = SSL_CTX_new(TLSv1_client_method());
+ else if (mode == SSL_MODE_SERVER)
+ ctx = SSL_CTX_new(TLSv1_server_method());
+ else
+ ctx = SSL_CTX_new(TLSv1_method());
+ break;
+ }
+ if (!ctx) {
+ char err[256];
+ ERR_error_string(ERR_get_error(), err);
+ tcn_Throw(e, "Invalid Server SSL Protocol (%s)", err);
+ goto init_failed;
+ }
+ if ((c = apr_pcalloc(p, sizeof(tcn_ssl_ctxt_t))) == NULL) {
+ tcn_ThrowAPRException(e, apr_get_os_error());
+ goto init_failed;
+ }
+
+ c->protocol = protocol;
+ c->mode = mode;
+ c->ctx = ctx;
+ c->pool = p;
+ c->bio_os = BIO_new(BIO_s_file());
+ if (c->bio_os != NULL)
+ BIO_set_fp(c->bio_os, stderr, BIO_NOCLOSE | BIO_FP_TEXT);
+ SSL_CTX_set_options(c->ctx, SSL_OP_ALL);
+ if (!(protocol & SSL_PROTOCOL_SSLV2))
+ SSL_CTX_set_options(c->ctx, SSL_OP_NO_SSLv2);
+ if (!(protocol & SSL_PROTOCOL_SSLV3))
+ SSL_CTX_set_options(c->ctx, SSL_OP_NO_SSLv3);
+ if (!(protocol & SSL_PROTOCOL_TLSV1))
+ SSL_CTX_set_options(c->ctx, SSL_OP_NO_TLSv1);
+ /*
+ * Configure additional context ingredients
+ */
+ SSL_CTX_set_options(c->ctx, SSL_OP_SINGLE_DH_USE);
+#ifdef HAVE_ECC
+ SSL_CTX_set_options(c->ctx, SSL_OP_SINGLE_ECDH_USE);
+#endif
+
+#ifdef SSL_OP_NO_SESSION_RESUMPTION_ON_RENEGOTIATION
+ /*
+ * Disallow a session from being resumed during a renegotiation,
+ * so that an acceptable cipher suite can be negotiated.
+ */
+ SSL_CTX_set_options(c->ctx, SSL_OP_NO_SESSION_RESUMPTION_ON_RENEGOTIATION);
+#endif
+ /* Default session context id and cache size */
+ SSL_CTX_sess_set_cache_size(c->ctx, SSL_DEFAULT_CACHE_SIZE);
+ EVP_Digest((const unsigned char *)SSL_DEFAULT_VHOST_NAME,
+ (unsigned long)((sizeof SSL_DEFAULT_VHOST_NAME) - 1),
+ &(c->context_id[0]), NULL, EVP_sha1(), NULL);
+ if (mode) {
+#ifdef HAVE_ECC
+ /* Set default (nistp256) elliptic curve for ephemeral ECDH keys */
+ EC_KEY *ecdh = EC_KEY_new_by_curve_name(NID_X9_62_prime256v1);
+ SSL_CTX_set_tmp_ecdh(c->ctx, ecdh);
+ EC_KEY_free(ecdh);
+#endif
+ SSL_CTX_set_tmp_rsa_callback(c->ctx, SSL_callback_tmp_RSA);
+ SSL_CTX_set_tmp_dh_callback(c->ctx, SSL_callback_tmp_DH);
+ }
+ /* Set default Certificate verification level
+ * and depth for the Client Authentication
+ */
+ c->verify_depth = 1;
+ c->verify_mode = SSL_CVERIFY_UNSET;
+ c->shutdown_type = SSL_SHUTDOWN_TYPE_UNSET;
+
+ /* Set default password callback */
+ SSL_CTX_set_default_passwd_cb(c->ctx, (pem_password_cb *)SSL_password_callback);
+ SSL_CTX_set_default_passwd_cb_userdata(c->ctx, (void *)(&tcn_password_callback));
+ SSL_CTX_set_info_callback(c->ctx, SSL_callback_handshake);
+ /*
+ * Let us cleanup the ssl context when the pool is destroyed
+ */
+ apr_pool_cleanup_register(p, (const void *)c,
+ ssl_context_cleanup,
+ apr_pool_cleanup_null);
+
+ return P2J(c);
+init_failed:
+ return 0;
+}
+
+TCN_IMPLEMENT_CALL(jint, SSLContext, free)(TCN_STDARGS, jlong ctx)
+{
+ tcn_ssl_ctxt_t *c = J2P(ctx, tcn_ssl_ctxt_t *);
+ UNREFERENCED_STDARGS;
+ TCN_ASSERT(ctx != 0);
+ /* Run and destroy the cleanup callback */
+ return apr_pool_cleanup_run(c->pool, c, ssl_context_cleanup);
+}
+
+TCN_IMPLEMENT_CALL(void, SSLContext, setContextId)(TCN_STDARGS, jlong ctx,
+ jstring id)
+{
+ tcn_ssl_ctxt_t *c = J2P(ctx, tcn_ssl_ctxt_t *);
+ TCN_ALLOC_CSTRING(id);
+
+ TCN_ASSERT(ctx != 0);
+ UNREFERENCED(o);
+ if (J2S(id)) {
+ EVP_Digest((const unsigned char *)J2S(id),
+ (unsigned long)strlen(J2S(id)),
+ &(c->context_id[0]), NULL, EVP_sha1(), NULL);
+ }
+ TCN_FREE_CSTRING(id);
+}
+
+TCN_IMPLEMENT_CALL(void, SSLContext, setBIO)(TCN_STDARGS, jlong ctx,
+ jlong bio, jint dir)
+{
+ tcn_ssl_ctxt_t *c = J2P(ctx, tcn_ssl_ctxt_t *);
+ BIO *bio_handle = J2P(bio, BIO *);
+
+ UNREFERENCED_STDARGS;
+ TCN_ASSERT(ctx != 0);
+ if (dir == 0) {
+ if (c->bio_os && c->bio_os != bio_handle)
+ SSL_BIO_close(c->bio_os);
+ c->bio_os = bio_handle;
+ }
+ else if (dir == 1) {
+ if (c->bio_is && c->bio_is != bio_handle)
+ SSL_BIO_close(c->bio_is);
+ c->bio_is = bio_handle;
+ }
+ else
+ return;
+ SSL_BIO_doref(bio_handle);
+}
+
+TCN_IMPLEMENT_CALL(void, SSLContext, setOptions)(TCN_STDARGS, jlong ctx,
+ jint opt)
+{
+ tcn_ssl_ctxt_t *c = J2P(ctx, tcn_ssl_ctxt_t *);
+
+ UNREFERENCED_STDARGS;
+ TCN_ASSERT(ctx != 0);
+#ifndef SSL_OP_ALLOW_UNSAFE_LEGACY_RENEGOTIATION
+ /* Clear the flag if not supported */
+ if (opt & 0x00040000)
+ opt &= ~0x00040000;
+#endif
+ SSL_CTX_set_options(c->ctx, opt);
+}
+
+TCN_IMPLEMENT_CALL(void, SSLContext, clearOptions)(TCN_STDARGS, jlong ctx,
+ jint opt)
+{
+ tcn_ssl_ctxt_t *c = J2P(ctx, tcn_ssl_ctxt_t *);
+
+ UNREFERENCED_STDARGS;
+ TCN_ASSERT(ctx != 0);
+ SSL_CTX_clear_options(c->ctx, opt);
+}
+
+TCN_IMPLEMENT_CALL(void, SSLContext, setQuietShutdown)(TCN_STDARGS, jlong ctx,
+ jboolean mode)
+{
+ tcn_ssl_ctxt_t *c = J2P(ctx, tcn_ssl_ctxt_t *);
+
+ UNREFERENCED_STDARGS;
+ TCN_ASSERT(ctx != 0);
+ SSL_CTX_set_quiet_shutdown(c->ctx, mode ? 1 : 0);
+}
+
+TCN_IMPLEMENT_CALL(jboolean, SSLContext, setCipherSuite)(TCN_STDARGS, jlong ctx,
+ jstring ciphers)
+{
+ tcn_ssl_ctxt_t *c = J2P(ctx, tcn_ssl_ctxt_t *);
+ TCN_ALLOC_CSTRING(ciphers);
+ jboolean rv = JNI_TRUE;
+
+ UNREFERENCED(o);
+ TCN_ASSERT(ctx != 0);
+ if (!J2S(ciphers))
+ return JNI_FALSE;
+
+ if (!SSL_CTX_set_cipher_list(c->ctx, J2S(ciphers))) {
+ char err[256];
+ ERR_error_string(ERR_get_error(), err);
+ tcn_Throw(e, "Unable to configure permitted SSL ciphers (%s)", err);
+ rv = JNI_FALSE;
+ }
+ TCN_FREE_CSTRING(ciphers);
+ return rv;
+}
+
+TCN_IMPLEMENT_CALL(jboolean, SSLContext, setCARevocation)(TCN_STDARGS, jlong ctx,
+ jstring file,
+ jstring path)
+{
+ tcn_ssl_ctxt_t *c = J2P(ctx, tcn_ssl_ctxt_t *);
+ TCN_ALLOC_CSTRING(file);
+ TCN_ALLOC_CSTRING(path);
+ jboolean rv = JNI_FALSE;
+ X509_LOOKUP *lookup;
+ char err[256];
+
+ UNREFERENCED(o);
+ TCN_ASSERT(ctx != 0);
+ if (J2S(file) == NULL && J2S(path) == NULL)
+ return JNI_FALSE;
+
+ if (!c->crl) {
+ if ((c->crl = X509_STORE_new()) == NULL)
+ goto cleanup;
+ }
+ if (J2S(file)) {
+ lookup = X509_STORE_add_lookup(c->crl, X509_LOOKUP_file());
+ if (lookup == NULL) {
+ ERR_error_string(ERR_get_error(), err);
+ X509_STORE_free(c->crl);
+ c->crl = NULL;
+ tcn_Throw(e, "Lookup failed for file %s (%s)", J2S(file), err);
+ goto cleanup;
+ }
+ X509_LOOKUP_load_file(lookup, J2S(file), X509_FILETYPE_PEM);
+ }
+ if (J2S(path)) {
+ lookup = X509_STORE_add_lookup(c->crl, X509_LOOKUP_hash_dir());
+ if (lookup == NULL) {
+ ERR_error_string(ERR_get_error(), err);
+ X509_STORE_free(c->crl);
+ c->crl = NULL;
+ tcn_Throw(e, "Lookup failed for path %s (%s)", J2S(file), err);
+ goto cleanup;
+ }
+ X509_LOOKUP_add_dir(lookup, J2S(path), X509_FILETYPE_PEM);
+ }
+ rv = JNI_TRUE;
+cleanup:
+ TCN_FREE_CSTRING(file);
+ TCN_FREE_CSTRING(path);
+ return rv;
+}
+
+TCN_IMPLEMENT_CALL(jboolean, SSLContext, setCertificateChainFile)(TCN_STDARGS, jlong ctx,
+ jstring file,
+ jboolean skipfirst)
+{
+ tcn_ssl_ctxt_t *c = J2P(ctx, tcn_ssl_ctxt_t *);
+ jboolean rv = JNI_FALSE;
+ TCN_ALLOC_CSTRING(file);
+
+ UNREFERENCED(o);
+ TCN_ASSERT(ctx != 0);
+ if (!J2S(file))
+ return JNI_FALSE;
+ if (SSL_CTX_use_certificate_chain(c->ctx, J2S(file), skipfirst) > 0)
+ rv = JNI_TRUE;
+ TCN_FREE_CSTRING(file);
+ return rv;
+}
+
+TCN_IMPLEMENT_CALL(jboolean, SSLContext, setCACertificate)(TCN_STDARGS,
+ jlong ctx,
+ jstring file,
+ jstring path)
+{
+ tcn_ssl_ctxt_t *c = J2P(ctx, tcn_ssl_ctxt_t *);
+ jboolean rv = JNI_TRUE;
+ TCN_ALLOC_CSTRING(file);
+ TCN_ALLOC_CSTRING(path);
+
+ UNREFERENCED(o);
+ TCN_ASSERT(ctx != 0);
+ if (file == NULL && path == NULL)
+ return JNI_FALSE;
+
+ /*
+ * Configure Client Authentication details
+ */
+ if (!SSL_CTX_load_verify_locations(c->ctx,
+ J2S(file), J2S(path))) {
+ char err[256];
+ ERR_error_string(ERR_get_error(), err);
+ tcn_Throw(e, "Unable to configure locations "
+ "for client authentication (%s)", err);
+ rv = JNI_FALSE;
+ goto cleanup;
+ }
+ c->store = SSL_CTX_get_cert_store(c->ctx);
+ if (c->mode) {
+ STACK_OF(X509_NAME) *ca_certs;
+ c->ca_certs++;
+ ca_certs = SSL_CTX_get_client_CA_list(c->ctx);
+ if (ca_certs == NULL) {
+ SSL_load_client_CA_file(J2S(file));
+ if (ca_certs != NULL)
+ SSL_CTX_set_client_CA_list(c->ctx, ca_certs);
+ }
+ else {
+ if (!SSL_add_file_cert_subjects_to_stack(ca_certs, J2S(file)))
+ ca_certs = NULL;
+ }
+ if (ca_certs == NULL && c->verify_mode == SSL_CVERIFY_REQUIRE) {
+ /*
+ * Give a warning when no CAs were configured but client authentication
+ * should take place. This cannot work.
+ */
+ BIO_printf(c->bio_os,
+ "[WARN] Oops, you want to request client "
+ "authentication, but no CAs are known for "
+ "verification!?");
+ }
+ }
+cleanup:
+ TCN_FREE_CSTRING(file);
+ TCN_FREE_CSTRING(path);
+ return rv;
+}
+
+TCN_IMPLEMENT_CALL(void, SSLContext, setShutdownType)(TCN_STDARGS, jlong ctx,
+ jint type)
+{
+ tcn_ssl_ctxt_t *c = J2P(ctx, tcn_ssl_ctxt_t *);
+
+ UNREFERENCED_STDARGS;
+ TCN_ASSERT(ctx != 0);
+ c->shutdown_type = type;
+}
+
+TCN_IMPLEMENT_CALL(void, SSLContext, setVerify)(TCN_STDARGS, jlong ctx,
+ jint level, jint depth)
+{
+ tcn_ssl_ctxt_t *c = J2P(ctx, tcn_ssl_ctxt_t *);
+ int verify = SSL_VERIFY_NONE;
+
+ UNREFERENCED(o);
+ TCN_ASSERT(ctx != 0);
+ c->verify_mode = level;
+
+ if (c->verify_mode == SSL_CVERIFY_UNSET)
+ c->verify_mode = SSL_CVERIFY_NONE;
+ if (depth > 0)
+ c->verify_depth = depth;
+ /*
+ * Configure callbacks for SSL context
+ */
+ if (c->verify_mode == SSL_CVERIFY_REQUIRE)
+ verify |= SSL_VERIFY_PEER_STRICT;
+ if ((c->verify_mode == SSL_CVERIFY_OPTIONAL) ||
+ (c->verify_mode == SSL_CVERIFY_OPTIONAL_NO_CA))
+ verify |= SSL_VERIFY_PEER;
+ if (!c->store) {
+ if (SSL_CTX_set_default_verify_paths(c->ctx)) {
+ c->store = SSL_CTX_get_cert_store(c->ctx);
+ X509_STORE_set_flags(c->store, 0);
+ }
+ else {
+ /* XXX: See if this is fatal */
+ }
+ }
+
+ SSL_CTX_set_verify(c->ctx, verify, SSL_callback_SSL_verify);
+}
+
+static EVP_PKEY *load_pem_key(tcn_ssl_ctxt_t *c, const char *file)
+{
+ BIO *bio = NULL;
+ EVP_PKEY *key = NULL;
+ tcn_pass_cb_t *cb_data = c->cb_data;
+ int i;
+
+ if ((bio = BIO_new(BIO_s_file())) == NULL) {
+ return NULL;
+ }
+ if (BIO_read_filename(bio, file) <= 0) {
+ BIO_free(bio);
+ return NULL;
+ }
+ if (!cb_data)
+ cb_data = &tcn_password_callback;
+ for (i = 0; i < 3; i++) {
+ key = PEM_read_bio_PrivateKey(bio, NULL,
+ (pem_password_cb *)SSL_password_callback,
+ (void *)cb_data);
+ if (key)
+ break;
+ cb_data->password[0] = '\0';
+ BIO_ctrl(bio, BIO_CTRL_RESET, 0, NULL);
+ }
+ BIO_free(bio);
+ return key;
+}
+
+static X509 *load_pem_cert(tcn_ssl_ctxt_t *c, const char *file)
+{
+ BIO *bio = NULL;
+ X509 *cert = NULL;
+ tcn_pass_cb_t *cb_data = c->cb_data;
+
+ if ((bio = BIO_new(BIO_s_file())) == NULL) {
+ return NULL;
+ }
+ if (BIO_read_filename(bio, file) <= 0) {
+ BIO_free(bio);
+ return NULL;
+ }
+ if (!cb_data)
+ cb_data = &tcn_password_callback;
+ cert = PEM_read_bio_X509_AUX(bio, NULL,
+ (pem_password_cb *)SSL_password_callback,
+ (void *)cb_data);
+ if (cert == NULL &&
+ (ERR_GET_REASON(ERR_peek_last_error()) == PEM_R_NO_START_LINE)) {
+ ERR_clear_error();
+ BIO_ctrl(bio, BIO_CTRL_RESET, 0, NULL);
+ cert = d2i_X509_bio(bio, NULL);
+ }
+ BIO_free(bio);
+ return cert;
+}
+
+static int ssl_load_pkcs12(tcn_ssl_ctxt_t *c, const char *file,
+ EVP_PKEY **pkey, X509 **cert, STACK_OF(X509) **ca)
+{
+ const char *pass;
+ char buff[PEM_BUFSIZE];
+ int len, rc = 0;
+ PKCS12 *p12;
+ BIO *in;
+ tcn_pass_cb_t *cb_data = c->cb_data;
+
+ if ((in = BIO_new(BIO_s_file())) == 0)
+ return 0;
+ if (BIO_read_filename(in, file) <= 0) {
+ BIO_free(in);
+ return 0;
+ }
+ p12 = d2i_PKCS12_bio(in, 0);
+ if (p12 == 0) {
+ /* Error loading PKCS12 file */
+ goto cleanup;
+ }
+ /* See if an empty password will do */
+ if (PKCS12_verify_mac(p12, "", 0) || PKCS12_verify_mac(p12, 0, 0)) {
+ pass = "";
+ }
+ else {
+ if (!cb_data)
+ cb_data = &tcn_password_callback;
+ len = SSL_password_callback(buff, PEM_BUFSIZE, 0, cb_data);
+ if (len < 0) {
+ /* Passpharse callback error */
+ goto cleanup;
+ }
+ if (!PKCS12_verify_mac(p12, buff, len)) {
+ /* Mac verify error (wrong password?) in PKCS12 file */
+ goto cleanup;
+ }
+ pass = buff;
+ }
+ rc = PKCS12_parse(p12, pass, pkey, cert, ca);
+cleanup:
+ if (p12 != 0)
+ PKCS12_free(p12);
+ BIO_free(in);
+ return rc;
+}
+
+TCN_IMPLEMENT_CALL(void, SSLContext, setRandom)(TCN_STDARGS, jlong ctx,
+ jstring file)
+{
+ tcn_ssl_ctxt_t *c = J2P(ctx, tcn_ssl_ctxt_t *);
+ TCN_ALLOC_CSTRING(file);
+
+ TCN_ASSERT(ctx != 0);
+ UNREFERENCED(o);
+ if (J2S(file))
+ c->rand_file = apr_pstrdup(c->pool, J2S(file));
+ TCN_FREE_CSTRING(file);
+}
+
+TCN_IMPLEMENT_CALL(jboolean, SSLContext, setCertificate)(TCN_STDARGS, jlong ctx,
+ jstring cert, jstring key,
+ jstring password, jint idx)
+{
+ tcn_ssl_ctxt_t *c = J2P(ctx, tcn_ssl_ctxt_t *);
+ jboolean rv = JNI_TRUE;
+ TCN_ALLOC_CSTRING(cert);
+ TCN_ALLOC_CSTRING(key);
+ TCN_ALLOC_CSTRING(password);
+ const char *key_file, *cert_file;
+ const char *p;
+ char err[256];
+
+ UNREFERENCED(o);
+ TCN_ASSERT(ctx != 0);
+
+ if (idx < 0 || idx >= SSL_AIDX_MAX) {
+ /* TODO: Throw something */
+ rv = JNI_FALSE;
+ goto cleanup;
+ }
+ if (J2S(password)) {
+ if (!c->cb_data)
+ c->cb_data = &tcn_password_callback;
+ strncpy(c->cb_data->password, J2S(password), SSL_MAX_PASSWORD_LEN);
+ c->cb_data->password[SSL_MAX_PASSWORD_LEN-1] = '\0';
+ }
+ key_file = J2S(key);
+ cert_file = J2S(cert);
+ if (!key_file)
+ key_file = cert_file;
+ if (!key_file || !cert_file) {
+ tcn_Throw(e, "No Certificate file specified or invalid file format");
+ rv = JNI_FALSE;
+ goto cleanup;
+ }
+ if ((p = strrchr(cert_file, '.')) != NULL && strcmp(p, ".pkcs12") == 0) {
+ if (!ssl_load_pkcs12(c, cert_file, &c->keys[idx], &c->certs[idx], 0)) {
+ ERR_error_string(ERR_get_error(), err);
+ tcn_Throw(e, "Unable to load certificate %s (%s)",
+ cert_file, err);
+ rv = JNI_FALSE;
+ goto cleanup;
+ }
+ }
+ else {
+ if ((c->keys[idx] = load_pem_key(c, key_file)) == NULL) {
+ ERR_error_string(ERR_get_error(), err);
+ tcn_Throw(e, "Unable to load certificate key %s (%s)",
+ key_file, err);
+ rv = JNI_FALSE;
+ goto cleanup;
+ }
+ if ((c->certs[idx] = load_pem_cert(c, cert_file)) == NULL) {
+ ERR_error_string(ERR_get_error(), err);
+ tcn_Throw(e, "Unable to load certificate %s (%s)",
+ cert_file, err);
+ rv = JNI_FALSE;
+ goto cleanup;
+ }
+ }
+ if (SSL_CTX_use_certificate(c->ctx, c->certs[idx]) <= 0) {
+ ERR_error_string(ERR_get_error(), err);
+ tcn_Throw(e, "Error setting certificate (%s)", err);
+ rv = JNI_FALSE;
+ goto cleanup;
+ }
+ if (SSL_CTX_use_PrivateKey(c->ctx, c->keys[idx]) <= 0) {
+ ERR_error_string(ERR_get_error(), err);
+ tcn_Throw(e, "Error setting private key (%s)", err);
+ rv = JNI_FALSE;
+ goto cleanup;
+ }
+ if (SSL_CTX_check_private_key(c->ctx) <= 0) {
+ ERR_error_string(ERR_get_error(), err);
+ tcn_Throw(e, "Private key does not match the certificate public key (%s)",
+ err);
+ rv = JNI_FALSE;
+ goto cleanup;
+ }
+cleanup:
+ TCN_FREE_CSTRING(cert);
+ TCN_FREE_CSTRING(key);
+ TCN_FREE_CSTRING(password);
+ return rv;
+}
+
+#else
+/* OpenSSL is not supported.
+ * Create empty stubs.
+ */
+
+TCN_IMPLEMENT_CALL(jlong, SSLContext, make)(TCN_STDARGS, jlong pool,
+ jint protocol, jint mode)
+{
+ UNREFERENCED_STDARGS;
+ UNREFERENCED(pool);
+ UNREFERENCED(protocol);
+ UNREFERENCED(mode);
+ return 0;
+}
+
+TCN_IMPLEMENT_CALL(jint, SSLContext, free)(TCN_STDARGS, jlong ctx)
+{
+ UNREFERENCED_STDARGS;
+ UNREFERENCED(ctx);
+ return APR_ENOTIMPL;
+}
+
+TCN_IMPLEMENT_CALL(void, SSLContext, setContextId)(TCN_STDARGS, jlong ctx,
+ jstring id)
+{
+ UNREFERENCED_STDARGS;
+ UNREFERENCED(ctx);
+ UNREFERENCED(id);
+}
+
+TCN_IMPLEMENT_CALL(void, SSLContext, setBIO)(TCN_STDARGS, jlong ctx,
+ jlong bio, jint dir)
+{
+ UNREFERENCED_STDARGS;
+ UNREFERENCED(ctx);
+ UNREFERENCED(bio);
+ UNREFERENCED(dir);
+}
+
+TCN_IMPLEMENT_CALL(void, SSLContext, setOptions)(TCN_STDARGS, jlong ctx,
+ jint opt)
+{
+ UNREFERENCED_STDARGS;
+ UNREFERENCED(ctx);
+ UNREFERENCED(opt);
+}
+
+TCN_IMPLEMENT_CALL(void, SSLContext, clearOptions)(TCN_STDARGS, jlong ctx,
+ jint opt)
+{
+ UNREFERENCED_STDARGS;
+ UNREFERENCED(ctx);
+ UNREFERENCED(opt);
+}
+
+TCN_IMPLEMENT_CALL(void, SSLContext, setQuietShutdown)(TCN_STDARGS, jlong ctx,
+ jboolean mode)
+{
+ UNREFERENCED_STDARGS;
+ UNREFERENCED(ctx);
+ UNREFERENCED(mode);
+}
+
+TCN_IMPLEMENT_CALL(jboolean, SSLContext, setCipherSuite)(TCN_STDARGS, jlong ctx,
+ jstring ciphers)
+{
+ UNREFERENCED_STDARGS;
+ UNREFERENCED(ctx);
+ UNREFERENCED(ciphers);
+ return JNI_FALSE;
+}
+
+TCN_IMPLEMENT_CALL(jboolean, SSLContext, setCARevocation)(TCN_STDARGS, jlong ctx,
+ jstring file,
+ jstring path)
+{
+ UNREFERENCED_STDARGS;
+ UNREFERENCED(ctx);
+ UNREFERENCED(file);
+ UNREFERENCED(path);
+ return JNI_FALSE;
+}
+
+TCN_IMPLEMENT_CALL(jboolean, SSLContext, setCertificateChainFile)(TCN_STDARGS, jlong ctx,
+ jstring file,
+ jboolean skipfirst)
+{
+ UNREFERENCED_STDARGS;
+ UNREFERENCED(ctx);
+ UNREFERENCED(file);
+ UNREFERENCED(skipfirst);
+ return JNI_FALSE;
+}
+
+TCN_IMPLEMENT_CALL(jboolean, SSLContext, setCACertificate)(TCN_STDARGS,
+ jlong ctx,
+ jstring file,
+ jstring path)
+{
+ UNREFERENCED_STDARGS;
+ UNREFERENCED(ctx);
+ UNREFERENCED(file);
+ UNREFERENCED(path);
+ return JNI_FALSE;
+}
+
+TCN_IMPLEMENT_CALL(void, SSLContext, setShutdownType)(TCN_STDARGS, jlong ctx,
+ jint type)
+{
+ UNREFERENCED_STDARGS;
+ UNREFERENCED(ctx);
+ UNREFERENCED(type);
+}
+
+TCN_IMPLEMENT_CALL(void, SSLContext, setVerify)(TCN_STDARGS, jlong ctx,
+ jint level, jint depth)
+{
+ UNREFERENCED_STDARGS;
+ UNREFERENCED(ctx);
+ UNREFERENCED(level);
+ UNREFERENCED(depth);
+}
+
+TCN_IMPLEMENT_CALL(void, SSLContext, setRandom)(TCN_STDARGS, jlong ctx,
+ jstring file)
+{
+ UNREFERENCED_STDARGS;
+ UNREFERENCED(ctx);
+ UNREFERENCED(file);
+}
+
+TCN_IMPLEMENT_CALL(jboolean, SSLContext, setCertificate)(TCN_STDARGS, jlong ctx,
+ jstring cert, jstring key,
+ jstring password, jint idx)
+{
+ UNREFERENCED_STDARGS;
+ UNREFERENCED(ctx);
+ UNREFERENCED(cert);
+ UNREFERENCED(key);
+ UNREFERENCED(password);
+ UNREFERENCED(idx);
+ return JNI_FALSE;
+}
+
+#endif
diff --git a/jni/native/src/sslinfo.c b/jni/native/src/sslinfo.c
new file mode 100644
index 0000000..ba2b80d
--- /dev/null
+++ b/jni/native/src/sslinfo.c
@@ -0,0 +1,589 @@
+/* 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.
+ */
+
+/** SSL info wrapper
+ *
+ * @author Mladen Turk
+ * @version $Id: sslinfo.c 1442587 2013-02-05 13:49:48Z rjung $
+ */
+
+#include "tcn.h"
+#include "apr_file_io.h"
+#include "apr_thread_mutex.h"
+#include "apr_poll.h"
+
+#ifdef HAVE_OPENSSL
+#include "ssl_private.h"
+
+static const char *hex_basis = "0123456789ABCDEF";
+
+static char *convert_to_hex(const void *buf, size_t len)
+{
+ const unsigned char *p = ( const unsigned char *)buf;
+ char *str, *s;
+ size_t i;
+
+ if ((len < 1) || ((str = malloc(len * 2 + 1)) == NULL))
+ return NULL;
+ for (i = 0, s = str; i < len; i++) {
+ unsigned char c = *p++;
+ *s++ = hex_basis[c >> 4];
+ *s++ = hex_basis[c & 0x0F];
+ }
+ *s = '\0';
+ return str;
+}
+
+#define DIGIT2NUM(x) (((x)[0] - '0') * 10 + (x)[1] - '0')
+
+static int get_days_remaining(ASN1_UTCTIME *tm)
+{
+ apr_time_t then, now = apr_time_now();
+ apr_time_exp_t exp = {0};
+ int diff;
+
+ /* Fail if the time isn't a valid ASN.1 UTCTIME; RFC3280 mandates
+ * that the seconds digits are present even though ASN.1
+ * doesn't. */
+ if (tm->length < 11 || !ASN1_UTCTIME_check(tm))
+ return 0;
+
+ exp.tm_year = DIGIT2NUM(tm->data);
+ exp.tm_mon = DIGIT2NUM(tm->data + 2) - 1;
+ exp.tm_mday = DIGIT2NUM(tm->data + 4) + 1;
+ exp.tm_hour = DIGIT2NUM(tm->data + 6);
+ exp.tm_min = DIGIT2NUM(tm->data + 8);
+ exp.tm_sec = DIGIT2NUM(tm->data + 10);
+
+ if (exp.tm_year <= 50)
+ exp.tm_year += 100;
+ if (apr_time_exp_gmt_get(&then, &exp) != APR_SUCCESS)
+ return 0;
+
+ diff = (int)((apr_time_sec(then) - apr_time_sec(now)) / (60*60*24));
+ return diff > 0 ? diff : 0;
+}
+
+static char *get_cert_valid(ASN1_UTCTIME *tm)
+{
+ char *result;
+ BIO* bio;
+ int n;
+
+ if ((bio = BIO_new(BIO_s_mem())) == NULL)
+ return NULL;
+ ASN1_UTCTIME_print(bio, tm);
+ n = BIO_pending(bio);
+ result = malloc(n+1);
+ n = BIO_read(bio, result, n);
+ result[n] = '\0';
+ BIO_free(bio);
+ return result;
+}
+
+static char *get_cert_PEM(X509 *xs)
+{
+ char *result = NULL;
+ BIO *bio;
+
+ if ((bio = BIO_new(BIO_s_mem())) == NULL)
+ return NULL;
+ if (PEM_write_bio_X509(bio, xs)) {
+ int n = BIO_pending(bio);
+ result = malloc(n+1);
+ n = BIO_read(bio, result, n);
+ result[n] = '\0';
+ }
+ BIO_free(bio);
+ return result;
+}
+
+static unsigned char *get_cert_ASN1(X509 *xs, int *len)
+{
+ unsigned char *result = NULL;
+ BIO *bio;
+
+ *len = 0;
+ if ((bio = BIO_new(BIO_s_mem())) == NULL)
+ return NULL;
+ if (i2d_X509_bio(bio, xs)) {
+ int n = BIO_pending(bio);
+ result = malloc(n);
+ n = BIO_read(bio, result, n);
+ *len = n;
+ }
+ BIO_free(bio);
+ return result;
+}
+
+
+static char *get_cert_serial(X509 *xs)
+{
+ char *result;
+ BIO *bio;
+ int n;
+
+ if ((bio = BIO_new(BIO_s_mem())) == NULL)
+ return NULL;
+ i2a_ASN1_INTEGER(bio, X509_get_serialNumber(xs));
+ n = BIO_pending(bio);
+ result = malloc(n+1);
+ n = BIO_read(bio, result, n);
+ result[n] = '\0';
+ BIO_free(bio);
+ return result;
+}
+
+static const struct {
+ int fid;
+ int nid;
+} info_cert_dn_rec[] = {
+ { SSL_INFO_DN_COUNTRYNAME, NID_countryName },
+ { SSL_INFO_DN_STATEORPROVINCENAME, NID_stateOrProvinceName },
+ { SSL_INFO_DN_LOCALITYNAME, NID_localityName },
+ { SSL_INFO_DN_ORGANIZATIONNAME, NID_organizationName },
+ { SSL_INFO_DN_ORGANIZATIONALUNITNAME, NID_organizationalUnitName },
+ { SSL_INFO_DN_COMMONNAME, NID_commonName },
+ { SSL_INFO_DN_TITLE, NID_title },
+ { SSL_INFO_DN_INITIALS, NID_initials },
+ { SSL_INFO_DN_GIVENNAME, NID_givenName },
+ { SSL_INFO_DN_SURNAME, NID_surname },
+ { SSL_INFO_DN_DESCRIPTION, NID_description },
+ { SSL_INFO_DN_UNIQUEIDENTIFIER, NID_x500UniqueIdentifier },
+ { SSL_INFO_DN_EMAILADDRESS, NID_pkcs9_emailAddress },
+ { 0, 0 }
+};
+
+static char *lookup_ssl_cert_dn(X509_NAME *xsname, int dnidx)
+{
+ char *result;
+ X509_NAME_ENTRY *xsne;
+ int i, j, n, idx = 0;
+
+ result = NULL;
+
+ for (i = 0; info_cert_dn_rec[i].fid != 0; i++) {
+ if (info_cert_dn_rec[i].fid == dnidx) {
+ for (j = 0; j < sk_X509_NAME_ENTRY_num((STACK_OF(X509_NAME_ENTRY) *)
+ (xsname->entries)); j++) {
+ xsne = sk_X509_NAME_ENTRY_value((STACK_OF(X509_NAME_ENTRY) *)
+ (xsname->entries), j);
+
+ n =OBJ_obj2nid((ASN1_OBJECT *)X509_NAME_ENTRY_get_object(xsne));
+ if (n == info_cert_dn_rec[i].nid && idx-- == 0) {
+ result = malloc(xsne->value->length + 1);
+ memcpy(result, xsne->value->data,
+ xsne->value->length);
+ result[xsne->value->length] = '\0';
+
+#if APR_CHARSET_EBCDIC
+ ap_xlate_proto_from_ascii(result, xsne->value->length);
+#endif /* APR_CHARSET_EBCDIC */
+ break;
+ }
+ }
+ break;
+ }
+ }
+ return result;
+}
+
+TCN_IMPLEMENT_CALL(jobject, SSLSocket, getInfoB)(TCN_STDARGS, jlong sock,
+ jint what)
+{
+ tcn_socket_t *a = J2P(sock, tcn_socket_t *);
+ tcn_ssl_conn_t *s;
+ jbyteArray array = NULL;
+ apr_status_t rv = APR_SUCCESS;
+
+ UNREFERENCED(o);
+ TCN_ASSERT(sock != 0);
+
+ s = (tcn_ssl_conn_t *)(a->opaque);
+ switch (what) {
+ case SSL_INFO_SESSION_ID:
+ {
+ SSL_SESSION *session = SSL_get_session(s->ssl);
+ if (session) {
+ array = tcn_new_arrayb(e, &session->session_id[0],
+ session->session_id_length);
+ }
+ }
+ break;
+ default:
+ rv = APR_EINVAL;
+ break;
+ }
+ if (what & SSL_INFO_CLIENT_MASK) {
+ X509 *xs;
+ unsigned char *result;
+ int len;
+ if ((xs = SSL_get_peer_certificate(s->ssl)) != NULL) {
+ switch (what) {
+ case SSL_INFO_CLIENT_CERT:
+ if ((result = get_cert_ASN1(xs, &len))) {
+ array = tcn_new_arrayb(e, result, len);
+ free(result);
+ }
+ break;
+ }
+ X509_free(xs);
+ }
+ rv = APR_SUCCESS;
+ }
+ else if (what & SSL_INFO_SERVER_MASK) {
+ X509 *xs;
+ unsigned char *result;
+ int len;
+ if ((xs = SSL_get_certificate(s->ssl)) != NULL) {
+ switch (what) {
+ case SSL_INFO_SERVER_CERT:
+ if ((result = get_cert_ASN1(xs, &len))) {
+ array = tcn_new_arrayb(e, result, len);
+ free(result);
+ }
+ break;
+ }
+ /* XXX: No need to call the X509_free(xs); */
+ }
+ rv = APR_SUCCESS;
+ }
+ else if (what & SSL_INFO_CLIENT_CERT_CHAIN) {
+ X509 *xs;
+ unsigned char *result;
+ STACK_OF(X509) *sk = SSL_get_peer_cert_chain(s->ssl);
+ int len, n = what & 0x0F;
+ if (n < sk_X509_num(sk)) {
+ xs = sk_X509_value(sk, n);
+ if ((result = get_cert_ASN1(xs, &len))) {
+ array = tcn_new_arrayb(e, result, len);
+ free(result);
+ }
+ }
+ rv = APR_SUCCESS;
+ }
+ if (rv != APR_SUCCESS)
+ tcn_ThrowAPRException(e, rv);
+
+ return array;
+}
+
+TCN_IMPLEMENT_CALL(jstring, SSLSocket, getInfoS)(TCN_STDARGS, jlong sock,
+ jint what)
+{
+ tcn_socket_t *a = J2P(sock, tcn_socket_t *);
+ tcn_ssl_conn_t *s;
+ jstring value = NULL;
+ apr_status_t rv = APR_SUCCESS;
+
+ UNREFERENCED(o);
+ TCN_ASSERT(sock != 0);
+
+ s = (tcn_ssl_conn_t *)(a->opaque);
+ switch (what) {
+ case SSL_INFO_SESSION_ID:
+ {
+ SSL_SESSION *session = SSL_get_session(s->ssl);
+ if (session) {
+ char *hs = convert_to_hex(&session->session_id[0],
+ session->session_id_length);
+ if (hs) {
+ value = tcn_new_string(e, hs);
+ free(hs);
+ }
+ }
+ }
+ break;
+ case SSL_INFO_PROTOCOL:
+ value = tcn_new_string(e, SSL_get_version(s->ssl));
+ break;
+ case SSL_INFO_CIPHER:
+ value = tcn_new_string(e, SSL_get_cipher_name(s->ssl));
+ break;
+ case SSL_INFO_CIPHER_VERSION:
+ value = tcn_new_string(e, SSL_get_cipher_version(s->ssl));
+ break;
+ case SSL_INFO_CIPHER_DESCRIPTION:
+ {
+ SSL_CIPHER *cipher = (SSL_CIPHER *)SSL_get_current_cipher(s->ssl);
+ if (cipher) {
+ char buf[256];
+ const char *desc = SSL_CIPHER_description(cipher, buf, 256);
+ value = tcn_new_string(e, desc);
+ }
+ }
+ break;
+ default:
+ rv = APR_EINVAL;
+ break;
+ }
+ if (what & (SSL_INFO_CLIENT_S_DN | SSL_INFO_CLIENT_I_DN)) {
+ X509 *xs;
+ X509_NAME *xsname;
+ if ((xs = SSL_get_peer_certificate(s->ssl)) != NULL) {
+ char *result;
+ int idx = what & 0x0F;
+ if (what & SSL_INFO_CLIENT_S_DN)
+ xsname = X509_get_subject_name(xs);
+ else
+ xsname = X509_get_issuer_name(xs);
+ if (idx) {
+ result = lookup_ssl_cert_dn(xsname, idx);
+ if (result) {
+ value = tcn_new_string(e, result);
+ free(result);
+ }
+ }
+ else
+ value = tcn_new_string(e, X509_NAME_oneline(xsname, NULL, 0));
+ X509_free(xs);
+ }
+ rv = APR_SUCCESS;
+ }
+ else if (what & (SSL_INFO_SERVER_S_DN | SSL_INFO_SERVER_I_DN)) {
+ X509 *xs;
+ X509_NAME *xsname;
+ if ((xs = SSL_get_certificate(s->ssl)) != NULL) {
+ char *result;
+ int idx = what & 0x0F;
+ if (what & SSL_INFO_SERVER_S_DN)
+ xsname = X509_get_subject_name(xs);
+ else
+ xsname = X509_get_issuer_name(xs);
+ if (idx) {
+ result = lookup_ssl_cert_dn(xsname, what & 0x0F);
+ if (result) {
+ value = tcn_new_string(e, result);
+ free(result);
+ }
+ }
+ else
+ value = tcn_new_string(e, X509_NAME_oneline(xsname, NULL, 0));
+ /* XXX: No need to call the X509_free(xs); */
+ }
+ rv = APR_SUCCESS;
+ }
+ else if (what & SSL_INFO_CLIENT_MASK) {
+ X509 *xs;
+ char *result;
+ int nid;
+ if ((xs = SSL_get_peer_certificate(s->ssl)) != NULL) {
+ switch (what) {
+ case SSL_INFO_CLIENT_V_START:
+ if ((result = get_cert_valid(X509_get_notBefore(xs)))) {
+ value = tcn_new_string(e, result);
+ free(result);
+ }
+ break;
+ case SSL_INFO_CLIENT_V_END:
+ if ((result = get_cert_valid(X509_get_notAfter(xs)))) {
+ value = tcn_new_string(e, result);
+ free(result);
+ }
+ break;
+ case SSL_INFO_CLIENT_A_SIG:
+ nid = OBJ_obj2nid((ASN1_OBJECT *)xs->cert_info->signature->algorithm);
+ if (nid == NID_undef)
+ value = tcn_new_string(e, "UNKNOWN");
+ else
+ value = tcn_new_string(e, OBJ_nid2ln(nid));
+ break;
+ case SSL_INFO_CLIENT_A_KEY:
+ nid = OBJ_obj2nid((ASN1_OBJECT *)xs->cert_info->key->algor->algorithm);
+ if (nid == NID_undef)
+ value = tcn_new_string(e, "UNKNOWN");
+ else
+ value = tcn_new_string(e, OBJ_nid2ln(nid));
+ break;
+ case SSL_INFO_CLIENT_CERT:
+ if ((result = get_cert_PEM(xs))) {
+ value = tcn_new_string(e, result);
+ free(result);
+ }
+ break;
+ case SSL_INFO_CLIENT_M_SERIAL:
+ if ((result = get_cert_serial(xs))) {
+ value = tcn_new_string(e, result);
+ free(result);
+ }
+ break;
+ }
+ X509_free(xs);
+ }
+ rv = APR_SUCCESS;
+ }
+ else if (what & SSL_INFO_SERVER_MASK) {
+ X509 *xs;
+ char *result;
+ int nid;
+ if ((xs = SSL_get_certificate(s->ssl)) != NULL) {
+ switch (what) {
+ case SSL_INFO_SERVER_V_START:
+ if ((result = get_cert_valid(X509_get_notBefore(xs)))) {
+ value = tcn_new_string(e, result);
+ free(result);
+ }
+ break;
+ case SSL_INFO_SERVER_V_END:
+ if ((result = get_cert_valid(X509_get_notAfter(xs)))) {
+ value = tcn_new_string(e, result);
+ free(result);
+ }
+ break;
+ case SSL_INFO_SERVER_A_SIG:
+ nid = OBJ_obj2nid((ASN1_OBJECT *)xs->cert_info->signature->algorithm);
+ if (nid == NID_undef)
+ value = tcn_new_string(e, "UNKNOWN");
+ else
+ value = tcn_new_string(e, OBJ_nid2ln(nid));
+ break;
+ case SSL_INFO_SERVER_A_KEY:
+ nid = OBJ_obj2nid((ASN1_OBJECT *)xs->cert_info->key->algor->algorithm);
+ if (nid == NID_undef)
+ value = tcn_new_string(e, "UNKNOWN");
+ else
+ value = tcn_new_string(e, OBJ_nid2ln(nid));
+ break;
+ case SSL_INFO_SERVER_CERT:
+ if ((result = get_cert_PEM(xs))) {
+ value = tcn_new_string(e, result);
+ free(result);
+ }
+ break;
+ case SSL_INFO_SERVER_M_SERIAL:
+ if ((result = get_cert_serial(xs))) {
+ value = tcn_new_string(e, result);
+ free(result);
+ }
+ break;
+ }
+ /* XXX: No need to call the X509_free(xs); */
+ }
+ rv = APR_SUCCESS;
+ }
+ else if (what & SSL_INFO_CLIENT_CERT_CHAIN) {
+ X509 *xs;
+ char *result;
+ STACK_OF(X509) *sk = SSL_get_peer_cert_chain(s->ssl);
+ int n = what & 0x0F;
+ if (n < sk_X509_num(sk)) {
+ xs = sk_X509_value(sk, n);
+ if ((result = get_cert_PEM(xs))) {
+ value = tcn_new_string(e, result);
+ free(result);
+ }
+ }
+ rv = APR_SUCCESS;
+ }
+ if (rv != APR_SUCCESS)
+ tcn_ThrowAPRException(e, rv);
+
+ return value;
+}
+
+TCN_IMPLEMENT_CALL(jint, SSLSocket, getInfoI)(TCN_STDARGS, jlong sock,
+ jint what)
+{
+ tcn_socket_t *a = J2P(sock, tcn_socket_t *);
+ tcn_ssl_conn_t *s;
+ apr_status_t rv = APR_SUCCESS;
+ jint value = -1;
+
+ UNREFERENCED(o);
+ TCN_ASSERT(sock != 0);
+
+ s = (tcn_ssl_conn_t *)(a->opaque);
+
+ switch (what) {
+ case SSL_INFO_CIPHER_USEKEYSIZE:
+ case SSL_INFO_CIPHER_ALGKEYSIZE:
+ {
+ int usekeysize = 0;
+ int algkeysize = 0;
+ const SSL_CIPHER *cipher = SSL_get_current_cipher(s->ssl);
+ if (cipher) {
+ usekeysize = SSL_CIPHER_get_bits(cipher, &algkeysize);
+ if (what == SSL_INFO_CIPHER_USEKEYSIZE)
+ value = usekeysize;
+ else
+ value = algkeysize;
+ }
+ }
+ break;
+ case SSL_INFO_CLIENT_CERT_CHAIN:
+ {
+ STACK_OF(X509) *sk = SSL_get_peer_cert_chain(s->ssl);
+ value = sk_X509_num(sk);
+ }
+ break;
+ default:
+ rv = APR_EINVAL;
+ break;
+ }
+ if (what & SSL_INFO_CLIENT_MASK) {
+ X509 *xs;
+ if ((xs = SSL_get_peer_certificate(s->ssl)) != NULL) {
+ switch (what) {
+ case SSL_INFO_CLIENT_V_REMAIN:
+ value = get_days_remaining(X509_get_notAfter(xs));
+ rv = APR_SUCCESS;
+ break;
+ default:
+ rv = APR_EINVAL;
+ break;
+ }
+ X509_free(xs);
+ }
+ }
+
+ if (rv != APR_SUCCESS)
+ tcn_ThrowAPRException(e, rv);
+ return value;
+}
+
+#else
+/* OpenSSL is not supported.
+ * Create empty stubs.
+ */
+
+TCN_IMPLEMENT_CALL(jobject, SSLSocket, getInfoB)(TCN_STDARGS, jlong sock,
+ jint what)
+{
+ UNREFERENCED_STDARGS;
+ UNREFERENCED(sock);
+ UNREFERENCED(what);
+ return NULL;
+}
+
+TCN_IMPLEMENT_CALL(jstring, SSLSocket, getInfoS)(TCN_STDARGS, jlong sock,
+ jint what)
+{
+ UNREFERENCED_STDARGS;
+ UNREFERENCED(sock);
+ UNREFERENCED(what);
+ return NULL;
+}
+
+TCN_IMPLEMENT_CALL(jint, SSLSocket, getInfoI)(TCN_STDARGS, jlong sock,
+ jint what)
+{
+ UNREFERENCED_STDARGS;
+ UNREFERENCED(sock);
+ UNREFERENCED(what);
+ return 0;
+}
+
+#endif
diff --git a/jni/native/src/sslnetwork.c b/jni/native/src/sslnetwork.c
new file mode 100644
index 0000000..e1468cf
--- /dev/null
+++ b/jni/native/src/sslnetwork.c
@@ -0,0 +1,733 @@
+/* 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.
+ */
+
+/** SSL network wrapper
+ *
+ * @author Mladen Turk
+ * @version $Id: sslnetwork.c 1456353 2013-03-14 07:35:56Z mturk $
+ */
+
+#include "tcn.h"
+#include "apr_thread_mutex.h"
+#include "apr_poll.h"
+
+
+#ifdef HAVE_OPENSSL
+#include "ssl_private.h"
+
+#ifdef TCN_DO_STATISTICS
+#include "apr_atomic.h"
+
+static volatile apr_uint32_t ssl_created = 0;
+static volatile apr_uint32_t ssl_closed = 0;
+static volatile apr_uint32_t ssl_cleared = 0;
+static volatile apr_uint32_t ssl_accepted = 0;
+
+void ssl_network_dump_statistics()
+{
+ fprintf(stderr, "SSL Network Statistics ..\n");
+ fprintf(stderr, "Sockets created : %d\n", ssl_created);
+ fprintf(stderr, "Sockets accepted : %d\n", ssl_accepted);
+ fprintf(stderr, "Sockets closed : %d\n", ssl_closed);
+ fprintf(stderr, "Sockets cleared : %d\n", ssl_cleared);
+}
+
+#endif
+
+static int ssl_smart_shutdown(SSL *ssl, int shutdown_type)
+{
+ int i;
+ int rc = 0;
+
+ switch (shutdown_type) {
+ case SSL_SHUTDOWN_TYPE_UNCLEAN:
+ /* perform no close notify handshake at all
+ * (violates the SSL/TLS standard!)
+ */
+ shutdown_type = SSL_SENT_SHUTDOWN|SSL_RECEIVED_SHUTDOWN;
+ break;
+ case SSL_SHUTDOWN_TYPE_ACCURATE:
+ /* send close notify and wait for clients close notify
+ * (standard compliant, but usually causes connection hangs)
+ */
+ shutdown_type = 0;
+ break;
+ default:
+ /*
+ * case SSL_SHUTDOWN_TYPE_UNSET:
+ * case SSL_SHUTDOWN_TYPE_STANDARD:
+ * send close notify, but don't wait for clients close notify
+ * (standard compliant and safe, so it's the DEFAULT!)
+ */
+ shutdown_type = SSL_RECEIVED_SHUTDOWN;
+ break;
+ }
+
+ SSL_set_shutdown(ssl, shutdown_type);
+ /*
+ * Repeat the calls, because SSL_shutdown internally dispatches through a
+ * little state machine. Usually only one or two interation should be
+ * needed, so we restrict the total number of restrictions in order to
+ * avoid process hangs in case the client played bad with the socket
+ * connection and OpenSSL cannot recognize it.
+ * max 2x pending + 2x data = 4
+ */
+ for (i = 0; i < 4; i++) {
+ if ((rc = SSL_shutdown(ssl)))
+ break;
+ }
+ return rc;
+}
+
+static apr_status_t ssl_cleanup(void *data)
+{
+ tcn_ssl_conn_t *con = (tcn_ssl_conn_t *)data;
+
+ if (con) {
+ /* Pollset was already destroyed by
+ * the pool cleanup/destroy.
+ */
+ con->pollset = NULL;
+ if (con->ssl) {
+ SSL *ssl = con->ssl;
+ con->ssl = NULL;
+ ssl_smart_shutdown(ssl, con->shutdown_type);
+ SSL_free(ssl);
+ }
+ if (con->peer) {
+ X509_free(con->peer);
+ con->peer = NULL;
+ }
+ }
+
+#ifdef TCN_DO_STATISTICS
+ apr_atomic_inc32(&ssl_cleared);
+#endif
+ return APR_SUCCESS;
+}
+
+static tcn_ssl_conn_t *ssl_create(JNIEnv *env, tcn_ssl_ctxt_t *ctx, apr_pool_t *pool)
+{
+ tcn_ssl_conn_t *con;
+ SSL *ssl;
+
+ if ((con = apr_pcalloc(pool, sizeof(tcn_ssl_conn_t))) == NULL) {
+ tcn_ThrowAPRException(env, apr_get_os_error());
+ return NULL;
+ }
+ if ((ssl = SSL_new(ctx->ctx)) == NULL) {
+ char err[256];
+ ERR_error_string(ERR_get_error(), err);
+ tcn_Throw(env, "SSL_new failed (%s)", err);
+ con = NULL;
+ return NULL;
+ }
+ SSL_clear(ssl);
+ con->pool = pool;
+ con->ctx = ctx;
+ con->ssl = ssl;
+ con->shutdown_type = ctx->shutdown_type;
+ apr_pollset_create(&(con->pollset), 1, pool, 0);
+
+ SSL_set_app_data(ssl, (void *)con);
+
+ if (ctx->mode) {
+ /*
+ * Configure callbacks for SSL connection
+ */
+ SSL_set_tmp_rsa_callback(ssl, SSL_callback_tmp_RSA);
+ SSL_set_tmp_dh_callback(ssl, SSL_callback_tmp_DH);
+ SSL_set_session_id_context(ssl, &(ctx->context_id[0]),
+ sizeof ctx->context_id);
+ }
+ SSL_set_verify_result(ssl, X509_V_OK);
+ SSL_rand_seed(ctx->rand_file);
+
+#ifdef TCN_DO_STATISTICS
+ ssl_created++;
+#endif
+ return con;
+}
+
+#ifdef WIN32
+#define APR_INVALID_SOCKET INVALID_SOCKET
+#else
+#define APR_INVALID_SOCKET -1
+#endif
+
+static apr_status_t wait_for_io_or_timeout(tcn_ssl_conn_t *con,
+ int for_what,
+ apr_interval_time_t timeout)
+{
+ apr_pollfd_t pfd;
+ int type;
+ apr_status_t status;
+ apr_os_sock_t sock;
+
+ if (!con->pollset)
+ return APR_ENOPOLL;
+ if (!con->sock)
+ return APR_ENOTSOCK;
+ if (con->reneg_state == RENEG_ABORT) {
+ con->shutdown_type = SSL_SHUTDOWN_TYPE_UNCLEAN;
+ return APR_ECONNABORTED;
+ }
+
+ /* Check if the socket was already closed
+ */
+ apr_os_sock_get(&sock, con->sock);
+ if (sock == APR_INVALID_SOCKET)
+ return APR_ENOTSOCK;
+
+ /* Figure out the the poll direction */
+ switch (for_what) {
+ case SSL_ERROR_WANT_WRITE:
+ case SSL_ERROR_WANT_CONNECT:
+ case SSL_ERROR_WANT_ACCEPT:
+ type = APR_POLLOUT;
+ break;
+ case SSL_ERROR_WANT_READ:
+ type = APR_POLLIN;
+ break;
+ default:
+ return APR_EINVAL;
+ break;
+ }
+ if (timeout <= 0) {
+ /* Waiting on zero or infinite timeouts is not allowed
+ */
+ return APR_EAGAIN;
+ }
+ pfd.desc_type = APR_POLL_SOCKET;
+ pfd.desc.s = con->sock;
+ pfd.reqevents = type;
+
+ /* Remove the object if it was in the pollset, then add in the new
+ * object with the correct reqevents value. Ignore the status result
+ * on the remove, because it might not be in there (yet).
+ */
+ apr_pollset_remove(con->pollset, &pfd);
+
+ /* ### check status code */
+ apr_pollset_add(con->pollset, &pfd);
+
+ do {
+ int numdesc;
+ const apr_pollfd_t *pdesc;
+
+ status = apr_pollset_poll(con->pollset, timeout, &numdesc, &pdesc);
+ if (numdesc == 1 && (pdesc[0].rtnevents & type) != 0)
+ return APR_SUCCESS;
+ } while (APR_STATUS_IS_EINTR(status));
+
+ return status;
+}
+
+static apr_status_t APR_THREAD_FUNC
+ssl_socket_timeout_set(apr_socket_t *sock, apr_interval_time_t t)
+{
+ tcn_ssl_conn_t *con = (tcn_ssl_conn_t *)sock;
+ return apr_socket_timeout_set(con->sock, t);
+}
+
+static apr_status_t APR_THREAD_FUNC
+ssl_socket_timeout_get(apr_socket_t *sock, apr_interval_time_t *t)
+{
+ tcn_ssl_conn_t *con = (tcn_ssl_conn_t *)sock;
+ return apr_socket_timeout_get(con->sock, t);
+}
+
+static APR_INLINE apr_status_t APR_THREAD_FUNC
+ssl_socket_opt_set(apr_socket_t *sock, apr_int32_t opt, apr_int32_t on)
+{
+ tcn_ssl_conn_t *con = (tcn_ssl_conn_t *)sock;
+ return apr_socket_opt_set(con->sock, opt, on);
+}
+
+static APR_INLINE apr_status_t APR_THREAD_FUNC
+ssl_socket_opt_get(apr_socket_t *sock, apr_int32_t opt, apr_int32_t *on)
+{
+ tcn_ssl_conn_t *con = (tcn_ssl_conn_t *)sock;
+ return apr_socket_opt_get(con->sock, opt, on);
+}
+
+static apr_status_t APR_THREAD_FUNC
+ssl_socket_shutdown(apr_socket_t *sock, apr_shutdown_how_e how)
+{
+ apr_status_t rv = APR_SUCCESS;
+ tcn_ssl_conn_t *con = (tcn_ssl_conn_t *)sock;
+
+ if (con->ssl) {
+ SSL *ssl = con->ssl;
+ con->ssl = NULL;
+ if (how < 1)
+ how = con->shutdown_type;
+ rv = ssl_smart_shutdown(ssl, how);
+ /* TODO: Translate OpenSSL Error codes */
+ SSL_free(ssl);
+ }
+ return rv;
+}
+
+static apr_status_t APR_THREAD_FUNC
+ssl_socket_close(apr_socket_t *sock)
+{
+ tcn_ssl_conn_t *con = (tcn_ssl_conn_t *)sock;
+ apr_status_t rv = APR_SUCCESS;
+
+#ifdef TCN_DO_STATISTICS
+ apr_atomic_inc32(&ssl_closed);
+#endif
+ if (con->ssl) {
+ SSL *ssl = con->ssl;
+ con->ssl = NULL;
+ rv = ssl_smart_shutdown(ssl, con->shutdown_type);
+ SSL_free(ssl);
+ }
+ if (con->peer) {
+ X509_free(con->peer);
+ con->peer = NULL;
+ }
+ return rv;
+}
+
+TCN_IMPLEMENT_CALL(jint, SSLSocket, handshake)(TCN_STDARGS, jlong sock)
+{
+ tcn_socket_t *ss = J2P(sock, tcn_socket_t *);
+ tcn_ssl_conn_t *con;
+ apr_interval_time_t timeout;
+ int s, i;
+ long vr;
+ apr_status_t rv;
+ X509 *peer;
+
+ UNREFERENCED_STDARGS;
+ TCN_ASSERT(sock != 0);
+ if (ss->net->type != TCN_SOCKET_SSL)
+ return APR_EINVAL;
+ con = (tcn_ssl_conn_t *)ss->opaque;
+
+ apr_socket_timeout_get(con->sock, &timeout);
+ while (!SSL_is_init_finished(con->ssl)) {
+ ERR_clear_error();
+ if ((s = SSL_do_handshake(con->ssl)) <= 0) {
+ if (!con->ssl)
+ return APR_ENOTSOCK;
+ rv = apr_get_netos_error();
+ i = SSL_get_error(con->ssl, s);
+ switch (i) {
+ case SSL_ERROR_NONE:
+ con->shutdown_type = SSL_SHUTDOWN_TYPE_STANDARD;
+ return APR_SUCCESS;
+ break;
+ case SSL_ERROR_WANT_READ:
+ case SSL_ERROR_WANT_WRITE:
+ if ((rv = wait_for_io_or_timeout(con, i, timeout)) != APR_SUCCESS) {
+ con->shutdown_type = SSL_SHUTDOWN_TYPE_UNCLEAN;
+ return rv;
+ }
+ break;
+ case SSL_ERROR_SYSCALL:
+#if !defined(_WIN32)
+ if (APR_STATUS_IS_EINTR(rv)) {
+ /* Interrupted by signal */
+ continue;
+ }
+#endif
+ /* Fall trough */
+ default:
+ /*
+ * Anything else is a fatal error
+ */
+ con->shutdown_type = SSL_SHUTDOWN_TYPE_UNCLEAN;
+ return SSL_TO_APR_ERROR(i);
+ break;
+ }
+ }
+ if (!con->ssl)
+ return APR_ENOTSOCK;
+
+ /*
+ * Check for failed client authentication
+ */
+ if ((vr = SSL_get_verify_result(con->ssl)) != X509_V_OK) {
+ if (SSL_VERIFY_ERROR_IS_OPTIONAL(vr) &&
+ con->ctx->verify_mode == SSL_CVERIFY_OPTIONAL_NO_CA) {
+ /* TODO: Log optionalNoCA */
+ }
+ else {
+ /* TODO: Log SSL client authentication failed */
+ con->shutdown_type = SSL_SHUTDOWN_TYPE_UNCLEAN;
+ /* TODO: Figure out the correct return value */
+ return APR_EGENERAL;
+ }
+ }
+
+ /*
+ * Remember the peer certificate
+ */
+ if ((peer = SSL_get_peer_certificate(con->ssl)) != NULL) {
+ if (con->peer)
+ X509_free(con->peer);
+ con->peer = peer;
+ }
+ }
+ return APR_SUCCESS;
+}
+
+static apr_status_t APR_THREAD_FUNC
+ssl_socket_recv(apr_socket_t *sock, char *buf, apr_size_t *len)
+{
+ tcn_ssl_conn_t *con = (tcn_ssl_conn_t *)sock;
+ int s, i, rd = (int)(*len);
+ apr_status_t rv;
+ apr_interval_time_t timeout;
+
+ *len = 0;
+ if (con->reneg_state == RENEG_ABORT) {
+ con->shutdown_type = SSL_SHUTDOWN_TYPE_UNCLEAN;
+ return APR_ECONNABORTED;
+ }
+ apr_socket_timeout_get(con->sock, &timeout);
+ for (;;) {
+ ERR_clear_error();
+ if ((s = SSL_read(con->ssl, buf, rd)) <= 0) {
+ if (!con->ssl)
+ return APR_ENOTSOCK;
+ rv = apr_get_netos_error();
+ i = SSL_get_error(con->ssl, s);
+ /* Special case if the "close notify" alert send by peer */
+ if (s == 0 && (con->ssl->shutdown & SSL_RECEIVED_SHUTDOWN)) {
+ con->shutdown_type = SSL_SHUTDOWN_TYPE_STANDARD;
+ return APR_EOF;
+ }
+ switch (i) {
+ case SSL_ERROR_WANT_READ:
+ case SSL_ERROR_WANT_WRITE:
+ if ((rv = wait_for_io_or_timeout(con, i, timeout)) != APR_SUCCESS) {
+ con->shutdown_type = SSL_SHUTDOWN_TYPE_UNCLEAN;
+ return rv;
+ }
+ break;
+ case SSL_ERROR_SYSCALL:
+ if (APR_STATUS_IS_EPIPE(rv) || APR_STATUS_IS_ECONNRESET(rv)) {
+ con->shutdown_type = SSL_SHUTDOWN_TYPE_STANDARD;
+ return APR_EOF;
+ }
+#if !defined(_WIN32)
+ else if (APR_STATUS_IS_EINTR(rv)) {
+ /* Interrupted by signal
+ */
+ continue;
+ }
+#endif
+ /* Fall trough */
+ case SSL_ERROR_ZERO_RETURN:
+ if (s == 0) {
+ con->shutdown_type = SSL_SHUTDOWN_TYPE_STANDARD;
+ return APR_EOF;
+ }
+ /* Fall trough */
+ default:
+ con->shutdown_type = SSL_SHUTDOWN_TYPE_UNCLEAN;
+ return APR_EGENERAL;
+ break;
+ }
+ }
+ else {
+ *len = s;
+ con->shutdown_type = SSL_SHUTDOWN_TYPE_STANDARD;
+ break;
+ }
+ }
+ return APR_SUCCESS;
+}
+
+static apr_status_t APR_THREAD_FUNC
+ssl_socket_send(apr_socket_t *sock, const char *buf,
+ apr_size_t *len)
+{
+ tcn_ssl_conn_t *con = (tcn_ssl_conn_t *)sock;
+ int s, i, wr = (int)(*len);
+ apr_status_t rv;
+ apr_interval_time_t timeout;
+
+ *len = 0;
+ if (con->reneg_state == RENEG_ABORT) {
+ con->shutdown_type = SSL_SHUTDOWN_TYPE_UNCLEAN;
+ return APR_ECONNABORTED;
+ }
+ if (!SSL_is_init_finished(con->ssl)) {
+ /* XXX: Is this a correct retval ? */
+ return APR_EINPROGRESS;
+ }
+ if (wr == 0) {
+ /* According to docs calling SSL_write() with num=0 bytes
+ * to be sent the behaviour is undefined.
+ */
+ return APR_EINVAL;
+ }
+ apr_socket_timeout_get(con->sock, &timeout);
+ for (;;) {
+ ERR_clear_error();
+ if ((s = SSL_write(con->ssl, buf, wr)) <= 0) {
+ if (!con->ssl)
+ return APR_ENOTSOCK;
+ rv = apr_get_netos_error();
+ i = SSL_get_error(con->ssl, s);
+ switch (i) {
+ case SSL_ERROR_WANT_READ:
+ case SSL_ERROR_WANT_WRITE:
+ if ((rv = wait_for_io_or_timeout(con, i, timeout)) != APR_SUCCESS) {
+ con->shutdown_type = SSL_SHUTDOWN_TYPE_UNCLEAN;
+ return rv;
+ }
+ break;
+ case SSL_ERROR_SYSCALL:
+ if (s == -1) {
+ if (APR_STATUS_IS_EPIPE(rv) || APR_STATUS_IS_ECONNRESET(rv)) {
+ con->shutdown_type = SSL_SHUTDOWN_TYPE_STANDARD;
+ return APR_EOF;
+ }
+#if !defined(_WIN32)
+ else if (APR_STATUS_IS_EINTR(rv)) {
+ /* Interrupted by signal
+ */
+ continue;
+ }
+#endif
+ }
+ con->shutdown_type = SSL_SHUTDOWN_TYPE_UNCLEAN;
+ return rv;
+ break;
+ case SSL_ERROR_SSL:
+ /* Probably caused by buffer missmatch */
+ rv = APR_EINVAL;
+ case SSL_ERROR_ZERO_RETURN:
+ if (s == 0) {
+ con->shutdown_type = SSL_SHUTDOWN_TYPE_STANDARD;
+ return APR_EOF;
+ }
+ /* Fall trough */
+ default:
+ con->shutdown_type = SSL_SHUTDOWN_TYPE_UNCLEAN;
+ return rv;
+ break;
+ }
+ }
+ else {
+ *len = s;
+ break;
+ }
+ }
+ return APR_SUCCESS;
+}
+
+static apr_status_t APR_THREAD_FUNC
+ssl_socket_sendv(apr_socket_t *sock,
+ const struct iovec *vec,
+ apr_int32_t nvec, apr_size_t *len)
+{
+ tcn_ssl_conn_t *con = (tcn_ssl_conn_t *)sock;
+ apr_status_t rv;
+ apr_size_t written = 0;
+ apr_int32_t i;
+
+ for (i = 0; i < nvec; i++) {
+ apr_size_t rd = vec[i].iov_len;
+ if ((rv = ssl_socket_send((apr_socket_t *)con,
+ vec[i].iov_base, &rd)) != APR_SUCCESS) {
+ *len = written;
+ return rv;
+ }
+ written += rd;
+ }
+ *len = written;
+ return APR_SUCCESS;
+}
+
+static tcn_nlayer_t ssl_socket_layer = {
+ TCN_SOCKET_SSL,
+ ssl_cleanup,
+ ssl_socket_close,
+ ssl_socket_shutdown,
+ ssl_socket_opt_get,
+ ssl_socket_opt_set,
+ ssl_socket_timeout_get,
+ ssl_socket_timeout_set,
+ ssl_socket_send,
+ ssl_socket_sendv,
+ ssl_socket_recv
+};
+
+
+TCN_IMPLEMENT_CALL(jint, SSLSocket, attach)(TCN_STDARGS, jlong ctx,
+ jlong sock)
+{
+ tcn_ssl_ctxt_t *c = J2P(ctx, tcn_ssl_ctxt_t *);
+ tcn_socket_t *s = J2P(sock, tcn_socket_t *);
+ tcn_ssl_conn_t *con;
+ apr_os_sock_t oss;
+ apr_status_t rv;
+
+ UNREFERENCED(o);
+ TCN_ASSERT(ctx != 0);
+ TCN_ASSERT(sock != 0);
+
+ if (!s->sock)
+ return APR_ENOTSOCK;
+
+ if ((rv = apr_os_sock_get(&oss, s->sock)) != APR_SUCCESS)
+ return rv;
+ if (oss == APR_INVALID_SOCKET)
+ return APR_ENOTSOCK;
+
+ if ((con = ssl_create(e, c, s->pool)) == NULL)
+ return APR_EGENERAL;
+ con->sock = s->sock;
+
+ SSL_set_fd(con->ssl, (int)oss);
+ if (c->mode)
+ SSL_set_accept_state(con->ssl);
+ else
+ SSL_set_connect_state(con->ssl);
+ /* Change socket type */
+ s->net = &ssl_socket_layer;
+ s->opaque = con;
+
+ return APR_SUCCESS;
+}
+
+TCN_IMPLEMENT_CALL(jint, SSLSocket, renegotiate)(TCN_STDARGS,
+ jlong sock)
+{
+ tcn_socket_t *s = J2P(sock, tcn_socket_t *);
+ tcn_ssl_conn_t *con;
+ int retVal;
+ int ecode = SSL_ERROR_WANT_READ;
+ apr_status_t rv;
+ apr_interval_time_t timeout;
+
+ UNREFERENCED_STDARGS;
+ TCN_ASSERT(sock != 0);
+ con = (tcn_ssl_conn_t *)s->opaque;
+
+ /* Sequence to renegotiate is
+ * SSL_renegotiate()
+ * SSL_do_handshake()
+ * ssl->state = SSL_ST_ACCEPT
+ * SSL_do_handshake()
+ */
+
+ /* Toggle the renegotiation state to allow the new
+ * handshake to proceed.
+ */
+ con->reneg_state = RENEG_ALLOW;
+ retVal = SSL_renegotiate(con->ssl);
+ if (retVal <= 0)
+ return APR_EGENERAL;
+
+ retVal = SSL_do_handshake(con->ssl);
+ if (retVal <= 0)
+ return APR_EGENERAL;
+
+ if (SSL_get_state(con->ssl) != SSL_ST_OK) {
+ return APR_EGENERAL;
+ }
+ con->ssl->state = SSL_ST_ACCEPT;
+
+ apr_socket_timeout_get(con->sock, &timeout);
+ ecode = SSL_ERROR_WANT_READ;
+ while (ecode == SSL_ERROR_WANT_READ) {
+ retVal = SSL_do_handshake(con->ssl);
+ if (retVal <= 0) {
+ ecode = SSL_get_error(con->ssl, retVal);
+ if (ecode == SSL_ERROR_WANT_READ) {
+ if ((rv = wait_for_io_or_timeout(con, ecode, timeout)) != APR_SUCCESS)
+ return rv; /* Can't wait */
+ continue; /* It should be ok now */
+ }
+ else
+ return APR_EGENERAL;
+ } else
+ break;
+ }
+ con->reneg_state = RENEG_REJECT;
+
+ if (SSL_get_state(con->ssl) != SSL_ST_OK) {
+ return APR_EGENERAL;
+ }
+
+ return APR_SUCCESS;
+}
+
+TCN_IMPLEMENT_CALL(void, SSLSocket, setVerify)(TCN_STDARGS,
+ jlong sock,
+ jint cverify,
+ jint depth)
+{
+ tcn_socket_t *s = J2P(sock, tcn_socket_t *);
+ tcn_ssl_conn_t *con;
+ int verify = SSL_VERIFY_NONE;
+
+ UNREFERENCED_STDARGS;
+ TCN_ASSERT(sock != 0);
+ con = (tcn_ssl_conn_t *)s->opaque;
+
+ if (cverify == SSL_CVERIFY_UNSET)
+ cverify = SSL_CVERIFY_NONE;
+ if (depth > 0)
+ SSL_set_verify_depth(con->ssl, depth);
+
+ if (cverify == SSL_CVERIFY_REQUIRE)
+ verify |= SSL_VERIFY_PEER_STRICT;
+ if ((cverify == SSL_CVERIFY_OPTIONAL) ||
+ (cverify == SSL_CVERIFY_OPTIONAL_NO_CA))
+ verify |= SSL_VERIFY_PEER;
+
+ SSL_set_verify(con->ssl, verify, NULL);
+}
+
+#else
+/* OpenSSL is not supported.
+ * Create empty stubs.
+ */
+
+TCN_IMPLEMENT_CALL(jint, SSLSocket, handshake)(TCN_STDARGS, jlong sock)
+{
+ UNREFERENCED_STDARGS;
+ UNREFERENCED(sock);
+ return (jint)APR_ENOTIMPL;
+}
+
+TCN_IMPLEMENT_CALL(jint, SSLSocket, attach)(TCN_STDARGS, jlong ctx,
+ jlong sock)
+{
+ UNREFERENCED_STDARGS;
+ UNREFERENCED(ctx);
+ UNREFERENCED(sock);
+ return (jint)APR_ENOTIMPL;
+}
+
+TCN_IMPLEMENT_CALL(jint, SSLSocket, renegotiate)(TCN_STDARGS,
+ jlong sock)
+{
+ UNREFERENCED_STDARGS;
+ UNREFERENCED(sock);
+ return (jint)APR_ENOTIMPL;
+}
+
+#endif
diff --git a/jni/native/src/sslutils.c b/jni/native/src/sslutils.c
new file mode 100644
index 0000000..23b2be0
--- /dev/null
+++ b/jni/native/src/sslutils.c
@@ -0,0 +1,1244 @@
+/* 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.
+ */
+
+/** SSL Utilities
+ *
+ * @author Mladen Turk
+ * @version $Id: sslutils.c 1507125 2013-07-25 21:01:25Z schultz $
+ */
+
+#include "tcn.h"
+
+#ifdef HAVE_OPENSSL
+#include "apr_poll.h"
+#include "ssl_private.h"
+
+#ifdef WIN32
+extern int WIN32_SSL_password_prompt(tcn_pass_cb_t *data);
+#endif
+
+#ifdef HAVE_OPENSSL_OCSP
+#include <openssl/bio.h>
+#include <openssl/ocsp.h>
+/* defines with the values as seen by the asn1parse -dump openssl command */
+#define ASN1_SEQUENCE 0x30
+#define ASN1_OID 0x06
+#define ASN1_STRING 0x86
+#pragma message("Using OCSP")
+static int ssl_verify_OCSP(int ok, X509_STORE_CTX *ctx);
+static int ssl_ocsp_request(X509 *cert, X509 *issuer);
+#endif
+
+/* _________________________________________________________________
+**
+** Additional High-Level Functions for OpenSSL
+** _________________________________________________________________
+*/
+
+/* we initialize this index at startup time
+ * and never write to it at request time,
+ * so this static is thread safe.
+ * also note that OpenSSL increments at static variable when
+ * SSL_get_ex_new_index() is called, so we _must_ do this at startup.
+ */
+static int SSL_app_data2_idx = -1;
+
+void SSL_init_app_data2_idx(void)
+{
+ int i;
+
+ if (SSL_app_data2_idx > -1) {
+ return;
+ }
+
+ /* we _do_ need to call this twice */
+ for (i = 0; i <= 1; i++) {
+ SSL_app_data2_idx =
+ SSL_get_ex_new_index(0,
+ "Second Application Data for SSL",
+ NULL, NULL, NULL);
+ }
+}
+
+void *SSL_get_app_data2(SSL *ssl)
+{
+ return (void *)SSL_get_ex_data(ssl, SSL_app_data2_idx);
+}
+
+void SSL_set_app_data2(SSL *ssl, void *arg)
+{
+ SSL_set_ex_data(ssl, SSL_app_data2_idx, (char *)arg);
+ return;
+}
+
+/* Simple echo password prompting */
+int SSL_password_prompt(tcn_pass_cb_t *data)
+{
+ int rv = 0;
+ data->password[0] = '\0';
+ if (data->cb.obj) {
+ JNIEnv *e;
+ jobject o;
+ jstring prompt;
+ tcn_get_java_env(&e);
+ prompt = AJP_TO_JSTRING(data->prompt);
+ if ((o = (*e)->CallObjectMethod(e, data->cb.obj,
+ data->cb.mid[0], prompt))) {
+ TCN_ALLOC_CSTRING(o);
+ if (J2S(o)) {
+ strncpy(data->password, J2S(o), SSL_MAX_PASSWORD_LEN);
+ data->password[SSL_MAX_PASSWORD_LEN-1] = '\0';
+ rv = (int)strlen(data->password);
+ }
+ TCN_FREE_CSTRING(o);
+ }
+ }
+ else {
+#ifdef WIN32
+ rv = WIN32_SSL_password_prompt(data);
+#else
+ EVP_read_pw_string(data->password, SSL_MAX_PASSWORD_LEN,
+ data->prompt, 0);
+#endif
+ rv = (int)strlen(data->password);
+ }
+ if (rv > 0) {
+ /* Remove LF char if present */
+ char *r = strchr(data->password, '\n');
+ if (r) {
+ *r = '\0';
+ rv--;
+ }
+#ifdef WIN32
+ if ((r = strchr(data->password, '\r'))) {
+ *r = '\0';
+ rv--;
+ }
+#endif
+ }
+ return rv;
+}
+
+int SSL_password_callback(char *buf, int bufsiz, int verify,
+ void *cb)
+{
+ tcn_pass_cb_t *cb_data = (tcn_pass_cb_t *)cb;
+
+ if (buf == NULL)
+ return 0;
+ *buf = '\0';
+ if (cb_data == NULL)
+ cb_data = &tcn_password_callback;
+ if (!cb_data->prompt)
+ cb_data->prompt = SSL_DEFAULT_PASS_PROMPT;
+ if (cb_data->password[0]) {
+ /* Return already obtained password */
+ strncpy(buf, cb_data->password, bufsiz);
+ buf[bufsiz - 1] = '\0';
+ return (int)strlen(buf);
+ }
+ else {
+ if (SSL_password_prompt(cb_data) > 0)
+ strncpy(buf, cb_data->password, bufsiz);
+ }
+ buf[bufsiz - 1] = '\0';
+ return (int)strlen(buf);
+}
+
+static unsigned char dh0512_p[]={
+ 0xD9,0xBA,0xBF,0xFD,0x69,0x38,0xC9,0x51,0x2D,0x19,0x37,0x39,
+ 0xD7,0x7D,0x7E,0x3E,0x25,0x58,0x55,0x94,0x90,0x60,0x93,0x7A,
+ 0xF2,0xD5,0x61,0x5F,0x06,0xE8,0x08,0xB4,0x57,0xF4,0xCF,0xB4,
+ 0x41,0xCC,0xC4,0xAC,0xD4,0xF0,0x45,0x88,0xC9,0xD1,0x21,0x4C,
+ 0xB6,0x72,0x48,0xBD,0x73,0x80,0xE0,0xDD,0x88,0x41,0xA0,0xF1,
+ 0xEA,0x4B,0x71,0x13
+};
+static unsigned char dh1024_p[]={
+ 0xA2,0x95,0x7E,0x7C,0xA9,0xD5,0x55,0x1D,0x7C,0x77,0x11,0xAC,
+ 0xFD,0x48,0x8C,0x3B,0x94,0x1B,0xC5,0xC0,0x99,0x93,0xB5,0xDC,
+ 0xDC,0x06,0x76,0x9E,0xED,0x1E,0x3D,0xBB,0x9A,0x29,0xD6,0x8B,
+ 0x1F,0xF6,0xDA,0xC9,0xDF,0xD5,0x02,0x4F,0x09,0xDE,0xEC,0x2C,
+ 0x59,0x1E,0x82,0x32,0x80,0x9B,0xED,0x51,0x68,0xD2,0xFB,0x1E,
+ 0x25,0xDB,0xDF,0x9C,0x11,0x70,0xDF,0xCA,0x19,0x03,0x3D,0x3D,
+ 0xC1,0xAC,0x28,0x88,0x4F,0x13,0xAF,0x16,0x60,0x6B,0x5B,0x2F,
+ 0x56,0xC7,0x5B,0x5D,0xDE,0x8F,0x50,0x08,0xEC,0xB1,0xB9,0x29,
+ 0xAA,0x54,0xF4,0x05,0xC9,0xDF,0x95,0x9D,0x79,0xC6,0xEA,0x3F,
+ 0xC9,0x70,0x42,0xDA,0x90,0xC7,0xCC,0x12,0xB9,0x87,0x86,0x39,
+ 0x1E,0x1A,0xCE,0xF7,0x3F,0x15,0xB5,0x2B
+};
+static unsigned char dh2048_p[]={
+ 0xF2,0x4A,0xFC,0x7E,0x73,0x48,0x21,0x03,0xD1,0x1D,0xA8,0x16,
+ 0x87,0xD0,0xD2,0xDC,0x42,0xA8,0xD2,0x73,0xE3,0xA9,0x21,0x31,
+ 0x70,0x5D,0x69,0xC7,0x8F,0x95,0x0C,0x9F,0xB8,0x0E,0x37,0xAE,
+ 0xD1,0x6F,0x36,0x1C,0x26,0x63,0x2A,0x36,0xBA,0x0D,0x2A,0xF5,
+ 0x1A,0x0F,0xE8,0xC0,0xEA,0xD1,0xB5,0x52,0x47,0x1F,0x9A,0x0C,
+ 0x0F,0xED,0x71,0x51,0xED,0xE6,0x62,0xD5,0xF8,0x81,0x93,0x55,
+ 0xC1,0x0F,0xB4,0x72,0x64,0xB3,0x73,0xAA,0x90,0x9A,0x81,0xCE,
+ 0x03,0xFD,0x6D,0xB1,0x27,0x7D,0xE9,0x90,0x5E,0xE2,0x10,0x74,
+ 0x4F,0x94,0xC3,0x05,0x21,0x73,0xA9,0x12,0x06,0x9B,0x0E,0x20,
+ 0xD1,0x5F,0xF7,0xC9,0x4C,0x9D,0x4F,0xFA,0xCA,0x4D,0xFD,0xFF,
+ 0x6A,0x62,0x9F,0xF0,0x0F,0x3B,0xA9,0x1D,0xF2,0x69,0x29,0x00,
+ 0xBD,0xE9,0xB0,0x9D,0x88,0xC7,0x4A,0xAE,0xB0,0x53,0xAC,0xA2,
+ 0x27,0x40,0x88,0x58,0x8F,0x26,0xB2,0xC2,0x34,0x7D,0xA2,0xCF,
+ 0x92,0x60,0x9B,0x35,0xF6,0xF3,0x3B,0xC3,0xAA,0xD8,0x58,0x9C,
+ 0xCF,0x5D,0x9F,0xDB,0x14,0x93,0xFA,0xA3,0xFA,0x44,0xB1,0xB2,
+ 0x4B,0x0F,0x08,0x70,0x44,0x71,0x3A,0x73,0x45,0x8E,0x6D,0x9C,
+ 0x56,0xBC,0x9A,0xB5,0xB1,0x3D,0x8B,0x1F,0x1E,0x2B,0x0E,0x93,
+ 0xC2,0x9B,0x84,0xE2,0xE8,0xFC,0x29,0x85,0x83,0x8D,0x2E,0x5C,
+ 0xDD,0x9A,0xBB,0xFD,0xF0,0x87,0xBF,0xAF,0xC4,0xB6,0x1D,0xE7,
+ 0xF9,0x46,0x50,0x7F,0xC3,0xAC,0xFD,0xC9,0x8C,0x9D,0x66,0x6B,
+ 0x4C,0x6A,0xC9,0x3F,0x0C,0x0A,0x74,0x94,0x41,0x85,0x26,0x8F,
+ 0x9F,0xF0,0x7C,0x0B
+};
+static unsigned char dh4096_p[] = {
+ 0x8D,0xD3,0x8F,0x77,0x6F,0x6F,0xB0,0x74,0x3F,0x22,0xE9,0xD1,
+ 0x17,0x15,0x69,0xD8,0x24,0x85,0xCD,0xC4,0xE4,0x0E,0xF6,0x52,
+ 0x40,0xF7,0x1C,0x34,0xD0,0xA5,0x20,0x77,0xE2,0xFC,0x7D,0xA1,
+ 0x82,0xF1,0xF3,0x78,0x95,0x05,0x5B,0xB8,0xDB,0xB3,0xE4,0x17,
+ 0x93,0xD6,0x68,0xA7,0x0A,0x0C,0xC5,0xBB,0x9C,0x5E,0x1E,0x83,
+ 0x72,0xB3,0x12,0x81,0xA2,0xF5,0xCD,0x44,0x67,0xAA,0xE8,0xAD,
+ 0x1E,0x8F,0x26,0x25,0xF2,0x8A,0xA0,0xA5,0xF4,0xFB,0x95,0xAE,
+ 0x06,0x50,0x4B,0xD0,0xE7,0x0C,0x55,0x88,0xAA,0xE6,0xB8,0xF6,
+ 0xE9,0x2F,0x8D,0xA7,0xAD,0x84,0xBC,0x8D,0x4C,0xFE,0x76,0x60,
+ 0xCD,0xC8,0xED,0x7C,0xBF,0xF3,0xC1,0xF8,0x6A,0xED,0xEC,0xE9,
+ 0x13,0x7D,0x4E,0x72,0x20,0x77,0x06,0xA4,0x12,0xF8,0xD2,0x34,
+ 0x6F,0xDC,0x97,0xAB,0xD3,0xA0,0x45,0x8E,0x7D,0x21,0xA9,0x35,
+ 0x6E,0xE4,0xC9,0xC4,0x53,0xFF,0xE5,0xD9,0x72,0x61,0xC4,0x8A,
+ 0x75,0x78,0x36,0x97,0x1A,0xAB,0x92,0x85,0x74,0x61,0x7B,0xE0,
+ 0x92,0xB8,0xC6,0x12,0xA1,0x72,0xBB,0x5B,0x61,0xAA,0xE6,0x2C,
+ 0x2D,0x9F,0x45,0x79,0x9E,0xF4,0x41,0x93,0x93,0xEF,0x8B,0xEF,
+ 0xB7,0xBF,0x6D,0xF0,0x91,0x11,0x4F,0x7C,0x71,0x84,0xB5,0x88,
+ 0xA3,0x8C,0x1A,0xD5,0xD0,0x81,0x9C,0x50,0xAC,0xA9,0x2B,0xE9,
+ 0x92,0x2D,0x73,0x7C,0x0A,0xA3,0xFA,0xD3,0x6C,0x91,0x43,0xA6,
+ 0x80,0x7F,0xD7,0xC4,0xD8,0x6F,0x85,0xF8,0x15,0xFD,0x08,0xA6,
+ 0xF8,0x7B,0x3A,0xF4,0xD3,0x50,0xB4,0x2F,0x75,0xC8,0x48,0xB8,
+ 0xA8,0xFD,0xCA,0x8F,0x62,0xF1,0x4C,0x89,0xB7,0x18,0x67,0xB2,
+ 0x93,0x2C,0xC4,0xD4,0x71,0x29,0xA9,0x26,0x20,0xED,0x65,0x37,
+ 0x06,0x87,0xFC,0xFB,0x65,0x02,0x1B,0x3C,0x52,0x03,0xA1,0xBB,
+ 0xCF,0xE7,0x1B,0xA4,0x1A,0xE3,0x94,0x97,0x66,0x06,0xBF,0xA9,
+ 0xCE,0x1B,0x07,0x10,0xBA,0xF8,0xD4,0xD4,0x05,0xCF,0x53,0x47,
+ 0x16,0x2C,0xA1,0xFC,0x6B,0xEF,0xF8,0x6C,0x23,0x34,0xEF,0xB7,
+ 0xD3,0x3F,0xC2,0x42,0x5C,0x53,0x9A,0x00,0x52,0xCF,0xAC,0x42,
+ 0xD3,0x3B,0x2E,0xB6,0x04,0x32,0xE1,0x09,0xED,0x64,0xCD,0x6A,
+ 0x63,0x58,0xB8,0x43,0x56,0x5A,0xBE,0xA4,0x9F,0x68,0xD4,0xF7,
+ 0xC9,0x04,0xDF,0xCD,0xE5,0x93,0xB0,0x2F,0x06,0x19,0x3E,0xB8,
+ 0xAB,0x7E,0xF8,0xE7,0xE7,0xC8,0x53,0xA2,0x06,0xC3,0xC7,0xF9,
+ 0x18,0x3B,0x51,0xC3,0x9B,0xFF,0x8F,0x00,0x0E,0x87,0x19,0x68,
+ 0x2F,0x40,0xC0,0x68,0xFA,0x12,0xAE,0x57,0xB5,0xF0,0x97,0xCA,
+ 0x78,0x23,0x31,0xAB,0x67,0x7B,0x10,0x6B,0x59,0x32,0x9C,0x64,
+ 0x20,0x38,0x1F,0xC5,0x07,0x84,0x9E,0xC4,0x49,0xB1,0xDF,0xED,
+ 0x7A,0x8A,0xC3,0xE0,0xDD,0x30,0x55,0xFF,0x95,0x45,0xA6,0xEE,
+ 0xCB,0xE4,0x26,0xB9,0x8E,0x89,0x37,0x63,0xD4,0x02,0x3D,0x5B,
+ 0x4F,0xE5,0x90,0xF6,0x72,0xF8,0x10,0xEE,0x31,0x04,0x54,0x17,
+ 0xE3,0xD5,0x63,0x84,0x80,0x62,0x54,0x46,0x85,0x6C,0xD2,0xC1,
+ 0x3E,0x19,0xBD,0xE2,0x80,0x11,0x86,0xC7,0x4B,0x7F,0x67,0x86,
+ 0x47,0xD2,0x38,0xCD,0x8F,0xFE,0x65,0x3C,0x11,0xCD,0x96,0x99,
+ 0x4E,0x45,0xEB,0xEC,0x1D,0x94,0x8C,0x53,
+};
+static unsigned char dhxxx2_g[]={
+ 0x02
+};
+
+static DH *get_dh(int idx)
+{
+ DH *dh;
+
+ if ((dh = DH_new()) == NULL)
+ return NULL;
+ switch (idx) {
+ case SSL_TMP_KEY_DH_512:
+ dh->p = BN_bin2bn(dh0512_p, sizeof(dh0512_p), NULL);
+ break;
+ case SSL_TMP_KEY_DH_1024:
+ dh->p = BN_bin2bn(dh1024_p, sizeof(dh1024_p), NULL);
+ break;
+ case SSL_TMP_KEY_DH_2048:
+ dh->p = BN_bin2bn(dh2048_p, sizeof(dh2048_p), NULL);
+ break;
+ case SSL_TMP_KEY_DH_4096:
+ dh->p = BN_bin2bn(dh4096_p, sizeof(dh2048_p), NULL);
+ break;
+ }
+ dh->g = BN_bin2bn(dhxxx2_g, sizeof(dhxxx2_g), NULL);
+ if ((dh->p == NULL) || (dh->g == NULL)) {
+ DH_free(dh);
+ return NULL;
+ }
+ else
+ return dh;
+}
+
+DH *SSL_dh_get_tmp_param(int key_len)
+{
+ DH *dh;
+
+ if (key_len == 512)
+ dh = get_dh(SSL_TMP_KEY_DH_512);
+ else if (key_len == 1024)
+ dh = get_dh(SSL_TMP_KEY_DH_1024);
+ else if (key_len == 2048)
+ dh = get_dh(SSL_TMP_KEY_DH_2048);
+ else if (key_len == 4096)
+ dh = get_dh(SSL_TMP_KEY_DH_4096);
+ else
+ dh = get_dh(SSL_TMP_KEY_DH_1024);
+ return dh;
+}
+
+DH *SSL_dh_get_param_from_file(const char *file)
+{
+ DH *dh = NULL;
+ BIO *bio;
+
+ if ((bio = BIO_new_file(file, "r")) == NULL)
+ return NULL;
+ dh = PEM_read_bio_DHparams(bio, NULL, NULL, NULL);
+ BIO_free(bio);
+ return dh;
+}
+
+/*
+ * Handle out temporary RSA private keys on demand
+ *
+ * The background of this as the TLSv1 standard explains it:
+ *
+ * | D.1. Temporary RSA keys
+ * |
+ * | US Export restrictions limit RSA keys used for encryption to 512
+ * | bits, but do not place any limit on lengths of RSA keys used for
+ * | signing operations. Certificates often need to be larger than 512
+ * | bits, since 512-bit RSA keys are not secure enough for high-value
+ * | transactions or for applications requiring long-term security. Some
+ * | certificates are also designated signing-only, in which case they
+ * | cannot be used for key exchange.
+ * |
+ * | When the public key in the certificate cannot be used for encryption,
+ * | the server signs a temporary RSA key, which is then exchanged. In
+ * | exportable applications, the temporary RSA key should be the maximum
+ * | allowable length (i.e., 512 bits). Because 512-bit RSA keys are
+ * | relatively insecure, they should be changed often. For typical
+ * | electronic commerce applications, it is suggested that keys be
+ * | changed daily or every 500 transactions, and more often if possible.
+ * | Note that while it is acceptable to use the same temporary key for
+ * | multiple transactions, it must be signed each time it is used.
+ * |
+ * | RSA key generation is a time-consuming process. In many cases, a
+ * | low-priority process can be assigned the task of key generation.
+ * | Whenever a new key is completed, the existing temporary key can be
+ * | replaced with the new one.
+ *
+ * XXX: base on comment above, if thread support is enabled,
+ * we should spawn a low-priority thread to generate new keys
+ * on the fly.
+ *
+ * So we generated 512 and 1024 bit temporary keys on startup
+ * which we now just hand out on demand....
+ */
+
+RSA *SSL_callback_tmp_RSA(SSL *ssl, int export, int keylen)
+{
+ int idx;
+
+ /* doesn't matter if export flag is on,
+ * we won't be asked for keylen > 512 in that case.
+ * if we are asked for a keylen > 1024, it is too expensive
+ * to generate on the fly.
+ */
+
+ switch (keylen) {
+ case 512:
+ idx = SSL_TMP_KEY_RSA_512;
+ break;
+ case 2048:
+ idx = SSL_TMP_KEY_RSA_2048;
+ if (SSL_temp_keys[idx] == NULL)
+ idx = SSL_TMP_KEY_RSA_1024;
+ break;
+ case 4096:
+ idx = SSL_TMP_KEY_RSA_4096;
+ if (SSL_temp_keys[idx] == NULL)
+ idx = SSL_TMP_KEY_RSA_2048;
+ break;
+ case 1024:
+ default:
+ idx = SSL_TMP_KEY_RSA_1024;
+ break;
+ }
+ return (RSA *)SSL_temp_keys[idx];
+}
+
+/*
+ * Hand out the already generated DH parameters...
+ */
+DH *SSL_callback_tmp_DH(SSL *ssl, int export, int keylen)
+{
+ int idx;
+ switch (keylen) {
+ case 512:
+ idx = SSL_TMP_KEY_DH_512;
+ break;
+ case 2048:
+ idx = SSL_TMP_KEY_DH_2048;
+ break;
+ case 4096:
+ idx = SSL_TMP_KEY_DH_4096;
+ break;
+ case 1024:
+ default:
+ idx = SSL_TMP_KEY_DH_1024;
+ break;
+ }
+ return (DH *)SSL_temp_keys[idx];
+}
+
+/*
+ * Read a file that optionally contains the server certificate in PEM
+ * format, possibly followed by a sequence of CA certificates that
+ * should be sent to the peer in the SSL Certificate message.
+ */
+int SSL_CTX_use_certificate_chain(SSL_CTX *ctx, const char *file,
+ int skipfirst)
+{
+ BIO *bio;
+ X509 *x509;
+ unsigned long err;
+ int n;
+ STACK_OF(X509) *extra_certs;
+
+ if ((bio = BIO_new(BIO_s_file_internal())) == NULL)
+ return -1;
+ if (BIO_read_filename(bio, file) <= 0) {
+ BIO_free(bio);
+ return -1;
+ }
+ /* optionally skip a leading server certificate */
+ if (skipfirst) {
+ if ((x509 = PEM_read_bio_X509(bio, NULL, NULL, NULL)) == NULL) {
+ BIO_free(bio);
+ return -1;
+ }
+ X509_free(x509);
+ }
+ /* free a perhaps already configured extra chain */
+ extra_certs = SSL_CTX_get_extra_certs(ctx);
+ if (extra_certs != NULL) {
+ sk_X509_pop_free(extra_certs, X509_free);
+ SSL_CTX_set_extra_certs(ctx,NULL);
+ }
+ /* create new extra chain by loading the certs */
+ n = 0;
+ while ((x509 = PEM_read_bio_X509(bio, NULL, NULL, NULL)) != NULL) {
+ if (!SSL_CTX_add_extra_chain_cert(ctx, x509)) {
+ X509_free(x509);
+ BIO_free(bio);
+ return -1;
+ }
+ n++;
+ }
+ /* Make sure that only the error is just an EOF */
+ if ((err = ERR_peek_error()) > 0) {
+ if (!( ERR_GET_LIB(err) == ERR_LIB_PEM
+ && ERR_GET_REASON(err) == PEM_R_NO_START_LINE)) {
+ BIO_free(bio);
+ return -1;
+ }
+ while (ERR_get_error() > 0) ;
+ }
+ BIO_free(bio);
+ return n;
+}
+
+static int ssl_X509_STORE_lookup(X509_STORE *store, int yype,
+ X509_NAME *name, X509_OBJECT *obj)
+{
+ X509_STORE_CTX ctx;
+ int rc;
+
+ X509_STORE_CTX_init(&ctx, store, NULL, NULL);
+ rc = X509_STORE_get_by_subject(&ctx, yype, name, obj);
+ X509_STORE_CTX_cleanup(&ctx);
+ return rc;
+}
+
+static int ssl_verify_CRL(int ok, X509_STORE_CTX *ctx, tcn_ssl_conn_t *con)
+{
+ X509_OBJECT obj;
+ X509_NAME *subject, *issuer;
+ X509 *cert;
+ X509_CRL *crl;
+ EVP_PKEY *pubkey;
+ int i, n, rc;
+
+ /*
+ * Determine certificate ingredients in advance
+ */
+ cert = X509_STORE_CTX_get_current_cert(ctx);
+ subject = X509_get_subject_name(cert);
+ issuer = X509_get_issuer_name(cert);
+
+ /*
+ * OpenSSL provides the general mechanism to deal with CRLs but does not
+ * use them automatically when verifying certificates, so we do it
+ * explicitly here. We will check the CRL for the currently checked
+ * certificate, if there is such a CRL in the store.
+ *
+ * We come through this procedure for each certificate in the certificate
+ * chain, starting with the root-CA's certificate. At each step we've to
+ * both verify the signature on the CRL (to make sure it's a valid CRL)
+ * and it's revocation list (to make sure the current certificate isn't
+ * revoked). But because to check the signature on the CRL we need the
+ * public key of the issuing CA certificate (which was already processed
+ * one round before), we've a little problem. But we can both solve it and
+ * at the same time optimize the processing by using the following
+ * verification scheme (idea and code snippets borrowed from the GLOBUS
+ * project):
+ *
+ * 1. We'll check the signature of a CRL in each step when we find a CRL
+ * through the _subject_ name of the current certificate. This CRL
+ * itself will be needed the first time in the next round, of course.
+ * But we do the signature processing one round before this where the
+ * public key of the CA is available.
+ *
+ * 2. We'll check the revocation list of a CRL in each step when
+ * we find a CRL through the _issuer_ name of the current certificate.
+ * This CRLs signature was then already verified one round before.
+ *
+ * This verification scheme allows a CA to revoke its own certificate as
+ * well, of course.
+ */
+
+ /*
+ * Try to retrieve a CRL corresponding to the _subject_ of
+ * the current certificate in order to verify it's integrity.
+ */
+ memset((char *)&obj, 0, sizeof(obj));
+ rc = ssl_X509_STORE_lookup(con->ctx->crl,
+ X509_LU_CRL, subject, &obj);
+ crl = obj.data.crl;
+
+ if ((rc > 0) && crl) {
+ /*
+ * Log information about CRL
+ * (A little bit complicated because of ASN.1 and BIOs...)
+ */
+ /*
+ * Verify the signature on this CRL
+ */
+ pubkey = X509_get_pubkey(cert);
+ rc = X509_CRL_verify(crl, pubkey);
+ /* Only refcounted in OpenSSL */
+ if (pubkey)
+ EVP_PKEY_free(pubkey);
+ if (rc <= 0) {
+ /* TODO: Log Invalid signature on CRL */
+ X509_STORE_CTX_set_error(ctx, X509_V_ERR_CRL_SIGNATURE_FAILURE);
+ X509_OBJECT_free_contents(&obj);
+ return 0;
+ }
+
+ /*
+ * Check date of CRL to make sure it's not expired
+ */
+ i = X509_cmp_current_time(X509_CRL_get_nextUpdate(crl));
+
+ if (i == 0) {
+ /* TODO: Log Found CRL has invalid nextUpdate field */
+
+ X509_STORE_CTX_set_error(ctx,
+ X509_V_ERR_ERROR_IN_CRL_NEXT_UPDATE_FIELD);
+ X509_OBJECT_free_contents(&obj);
+ return 0;
+ }
+
+ if (i < 0) {
+ /* TODO: Log Found CRL is expired */
+ X509_STORE_CTX_set_error(ctx, X509_V_ERR_CRL_HAS_EXPIRED);
+ X509_OBJECT_free_contents(&obj);
+
+ return 0;
+ }
+
+ X509_OBJECT_free_contents(&obj);
+ }
+
+ /*
+ * Try to retrieve a CRL corresponding to the _issuer_ of
+ * the current certificate in order to check for revocation.
+ */
+ memset((char *)&obj, 0, sizeof(obj));
+ rc = ssl_X509_STORE_lookup(con->ctx->crl,
+ X509_LU_CRL, issuer, &obj);
+
+ crl = obj.data.crl;
+ if ((rc > 0) && crl) {
+ /*
+ * Check if the current certificate is revoked by this CRL
+ */
+ n = sk_X509_REVOKED_num(X509_CRL_get_REVOKED(crl));
+
+ for (i = 0; i < n; i++) {
+ X509_REVOKED *revoked =
+ sk_X509_REVOKED_value(X509_CRL_get_REVOKED(crl), i);
+
+ ASN1_INTEGER *sn = revoked->serialNumber;
+
+ if (!ASN1_INTEGER_cmp(sn, X509_get_serialNumber(cert))) {
+ X509_STORE_CTX_set_error(ctx, X509_V_ERR_CERT_REVOKED);
+ X509_OBJECT_free_contents(&obj);
+
+ return 0;
+ }
+ }
+
+ X509_OBJECT_free_contents(&obj);
+ }
+
+ return ok;
+}
+
+/*
+ * This OpenSSL callback function is called when OpenSSL
+ * does client authentication and verifies the certificate chain.
+ */
+
+
+int SSL_callback_SSL_verify(int ok, X509_STORE_CTX *ctx)
+{
+ /* Get Apache context back through OpenSSL context */
+ SSL *ssl = X509_STORE_CTX_get_ex_data(ctx,
+ SSL_get_ex_data_X509_STORE_CTX_idx());
+ tcn_ssl_conn_t *con = (tcn_ssl_conn_t *)SSL_get_app_data(ssl);
+ /* Get verify ingredients */
+ int errnum = X509_STORE_CTX_get_error(ctx);
+ int errdepth = X509_STORE_CTX_get_error_depth(ctx);
+ int verify = con->ctx->verify_mode;
+ int depth = con->ctx->verify_depth;
+ int skip_crl = 0;
+
+ if (verify == SSL_CVERIFY_UNSET ||
+ verify == SSL_CVERIFY_NONE)
+ return 1;
+
+ if (SSL_VERIFY_ERROR_IS_OPTIONAL(errnum) &&
+ (verify == SSL_CVERIFY_OPTIONAL_NO_CA)) {
+ ok = 1;
+ SSL_set_verify_result(ssl, X509_V_OK);
+ }
+
+#ifdef HAVE_OPENSSL_OCSP
+ /* First perform OCSP validation if possible */
+ if (ok) {
+ /* If there was an optional verification error, it's not
+ * possible to perform OCSP validation since the issuer may be
+ * missing/untrusted. Fail in that case.
+ */
+ if (SSL_VERIFY_ERROR_IS_OPTIONAL(errnum)) {
+ X509_STORE_CTX_set_error(ctx, X509_V_ERR_APPLICATION_VERIFICATION);
+ errnum = X509_V_ERR_APPLICATION_VERIFICATION;
+ ok = 0;
+ }
+ else {
+ int ocsp_response = ssl_verify_OCSP(ok, ctx);
+ if (ocsp_response == OCSP_STATUS_OK) {
+ skip_crl = 1; /* we know it is valid we skip crl evaluation */
+ }
+ else if (ocsp_response == OCSP_STATUS_REVOKED) {
+ ok = 0 ;
+ errnum = X509_STORE_CTX_get_error(ctx);
+ }
+ else if (ocsp_response == OCSP_STATUS_UNKNOWN) {
+ /* TODO: do nothing for time being, continue with CRL */
+ ;
+ }
+ }
+ }
+#endif
+ /*
+ * Additionally perform CRL-based revocation checks
+ */
+ if (ok && con->ctx->crl && !skip_crl) {
+ if (!(ok = ssl_verify_CRL(ok, ctx, con))) {
+ errnum = X509_STORE_CTX_get_error(ctx);
+ /* TODO: Log something */
+ }
+ }
+ /*
+ * If we already know it's not ok, log the real reason
+ */
+ if (!ok) {
+ /* TODO: Some logging
+ * Certificate Verification: Error
+ */
+ if (con->peer) {
+ X509_free(con->peer);
+ con->peer = NULL;
+ }
+ }
+ if (errdepth > depth) {
+ /* TODO: Some logging
+ * Certificate Verification: Certificate Chain too long
+ */
+ ok = 0;
+ }
+ return ok;
+}
+
+/*
+ * This callback function is executed while OpenSSL processes the SSL
+ * handshake and does SSL record layer stuff. It's used to trap
+ * client-initiated renegotiations, and for dumping everything to the
+ * log.
+ */
+void SSL_callback_handshake(const SSL *ssl, int where, int rc)
+{
+ tcn_ssl_conn_t *con = (tcn_ssl_conn_t *)SSL_get_app_data(ssl);
+
+ /* Retrieve the conn_rec and the associated SSLConnRec. */
+ if (con == NULL) {
+ return;
+ }
+
+
+ /* If the reneg state is to reject renegotiations, check the SSL
+ * state machine and move to ABORT if a Client Hello is being
+ * read. */
+ if ((where & SSL_CB_ACCEPT_LOOP) && con->reneg_state == RENEG_REJECT) {
+ int state = SSL_get_state(ssl);
+
+ if (state == SSL3_ST_SR_CLNT_HELLO_A
+ || state == SSL23_ST_SR_CLNT_HELLO_A) {
+ con->reneg_state = RENEG_ABORT;
+ /* XXX: rejecting client initiated renegotiation
+ */
+ }
+ }
+ /* If the first handshake is complete, change state to reject any
+ * subsequent client-initated renegotiation. */
+ else if ((where & SSL_CB_HANDSHAKE_DONE) && con->reneg_state == RENEG_INIT) {
+ con->reneg_state = RENEG_REJECT;
+ }
+
+}
+
+#ifdef HAVE_OPENSSL_OCSP
+
+/* Function that is used to do the OCSP verification */
+static int ssl_verify_OCSP(int ok, X509_STORE_CTX *ctx)
+{
+ X509 *cert, *issuer;
+ int r = OCSP_STATUS_UNKNOWN;
+
+ cert = X509_STORE_CTX_get_current_cert(ctx);
+ /* if we can't get the issuer, we cannot perform OCSP verification */
+ if (X509_STORE_CTX_get1_issuer(&issuer, ctx, cert) == 1 ) {
+ r = ssl_ocsp_request(cert, issuer);
+ if (r == OCSP_STATUS_REVOKED) {
+ /* we set the error if we know that it is revoked */
+ X509_STORE_CTX_set_error(ctx, X509_V_ERR_CERT_REVOKED);
+ }
+ else {
+ /* else we return unknown, so that we can continue with the crl */
+ r = OCSP_STATUS_UNKNOWN;
+ }
+ X509_free(issuer); /* It appears that we should free issuer since
+ * X509_STORE_CTX_get1_issuer() calls X509_OBJECT_up_ref_count()
+ * on the issuer object (unline X509_STORE_CTX_get_current_cert()
+ * that just returns the pointer
+ */
+ }
+ return r;
+}
+
+
+/* Helps with error handling or realloc */
+static void *apr_xrealloc(void *buf, size_t oldlen, size_t len, apr_pool_t *p)
+{
+ void *newp = apr_palloc(p, len);
+
+ if(newp)
+ memcpy(newp, buf, oldlen);
+ return newp;
+}
+
+/* parses the ocsp url and updates the ocsp_urls and nocsp_urls variables
+ returns 0 on success, 1 on failure */
+static int parse_ocsp_url(unsigned char *asn1, char ***ocsp_urls,
+ int *nocsp_urls, apr_pool_t *p)
+{
+ char **new_ocsp_urls, *ocsp_url;
+ int len, err = 0, new_nocsp_urls;
+
+ if (*asn1 == ASN1_STRING) {
+ len = *++asn1;
+ asn1++;
+ new_nocsp_urls = *nocsp_urls+1;
+ if ((new_ocsp_urls = apr_xrealloc(*ocsp_urls,*nocsp_urls, new_nocsp_urls, p)) == NULL)
+ err = 1;
+ if (!err) {
+ *ocsp_urls = new_ocsp_urls;
+ *nocsp_urls = new_nocsp_urls;
+ *(*ocsp_urls + *nocsp_urls) = NULL;
+ if ((ocsp_url = apr_palloc(p, len + 1)) == NULL) {
+ err = 1;
+ }
+ else {
+ memcpy(ocsp_url, asn1, len);
+ ocsp_url[len] = '\0';
+ *(*ocsp_urls + *nocsp_urls - 1) = ocsp_url;
+ }
+ }
+ }
+ return err;
+
+}
+
+/* parses the ANS1 OID and if it is an OCSP OID then calls the parse_ocsp_url function */
+static int parse_ASN1_OID(unsigned char *asn1, char ***ocsp_urls, int *nocsp_urls, apr_pool_t *p)
+{
+ int len, err = 0 ;
+ const unsigned char OCSP_OID[] = {0x2b, 0x06, 0x01, 0x05, 0x05, 0x07, 0x30, 0x01};
+
+ len = *++asn1;
+ asn1++;
+ if (memcmp(asn1, OCSP_OID, len) == 0) {
+ asn1+=len;
+ err = parse_ocsp_url(asn1, ocsp_urls, nocsp_urls, p);
+ }
+ return err;
+}
+
+
+/* Parses an ASN1 Sequence. It is a recursive function, since if it finds a sequence
+ within the sequence it calls recursively itself. This function stops when it finds
+ the end of the ASN1 sequence (marked by '\0'), so if there are other sequences within
+ the same sequence the while loop parses the sequences */
+
+/* This algo was developed with AIA in mind so it was tested only with this extension */
+static int parse_ASN1_Sequence(unsigned char *asn1, char ***ocsp_urls,
+ int *nocsp_urls, apr_pool_t *p)
+{
+ int len = 0 , err = 0;
+
+ while (!err && *asn1 != '\0') {
+ switch(*asn1) {
+ case ASN1_SEQUENCE:
+ len = *++asn1;
+ asn1++;
+ err = parse_ASN1_Sequence(asn1, ocsp_urls, nocsp_urls, p);
+ break;
+ case ASN1_OID:
+ err = parse_ASN1_OID(asn1,ocsp_urls,nocsp_urls, p);
+ return 0;
+ break;
+ default:
+ err = 1; /* we shouldn't have any errors */
+ break;
+ }
+ asn1+=len;
+ }
+ return err;
+}
+
+/* the main function that gets the ASN1 encoding string and returns
+ a pointer to a NULL terminated "array" of char *, that contains
+ the ocsp_urls */
+static char **decode_OCSP_url(ASN1_OCTET_STRING *os, apr_pool_t *p)
+{
+ char **response = NULL;
+ unsigned char *ocsp_urls;
+ int len, numofresponses = 0 ;
+
+ len = ASN1_STRING_length(os);
+
+ ocsp_urls = apr_palloc(p, len + 1);
+ memcpy(ocsp_urls,os->data, len);
+ ocsp_urls[len] = '\0';
+
+ if ((response = apr_pcalloc(p, sizeof(char *))) == NULL)
+ return NULL;
+ if (parse_ASN1_Sequence(ocsp_urls, &response, &numofresponses, p))
+ response = NULL;
+ return response;
+}
+
+
+/* stolen from openssl ocsp command */
+static int add_ocsp_cert(OCSP_REQUEST **req, X509 *cert, X509 *issuer,
+ STACK_OF(OCSP_CERTID) *ids)
+{
+ OCSP_CERTID *id;
+
+ if (!issuer)
+ return 0;
+ if (!*req)
+ *req = OCSP_REQUEST_new();
+ if (!*req)
+ return 0;
+ id = OCSP_cert_to_id(NULL, cert, issuer);
+ if (!id || !sk_OCSP_CERTID_push(ids, id))
+ return 0;
+ if (!OCSP_request_add0_id(*req, id))
+ return 0;
+ else
+ return 1;
+}
+
+
+/* Creates the APR socket and connect to the hostname. Returns the
+ socket or NULL if there is an error.
+*/
+static apr_socket_t *make_socket(char *hostname, int port, apr_pool_t *mp)
+{
+ apr_sockaddr_t *sa_in;
+ apr_status_t status;
+ apr_socket_t *sock = NULL;
+
+
+ status = apr_sockaddr_info_get(&sa_in, hostname, APR_INET, port, 0, mp);
+
+ if (status == APR_SUCCESS)
+ status = apr_socket_create(&sock, sa_in->family, SOCK_STREAM, APR_PROTO_TCP, mp);
+ if (status == APR_SUCCESS)
+ status = apr_socket_connect(sock, sa_in);
+
+ if (status == APR_SUCCESS)
+ return sock;
+ return NULL;
+}
+
+
+/* Creates the request in a memory BIO in order to send it to the OCSP server.
+ Most parts of this function are taken from mod_ssl support for OCSP (with some
+ minor modifications
+*/
+static BIO *serialize_request(OCSP_REQUEST *req, char *host, int port, char *path)
+{
+ BIO *bio;
+ int len;
+
+ len = i2d_OCSP_REQUEST(req, NULL);
+
+ bio = BIO_new(BIO_s_mem());
+
+ BIO_printf(bio, "POST %s HTTP/1.0\r\n"
+ "Host: %s:%d\r\n"
+ "Content-Type: application/ocsp-request\r\n"
+ "Content-Length: %d\r\n"
+ "\r\n",
+ path, host, port, len);
+
+ if (i2d_OCSP_REQUEST_bio(bio, req) != 1) {
+ BIO_free(bio);
+ return NULL;
+ }
+
+ return bio;
+}
+
+
+/* Send the OCSP request to the OCSP server. Taken from mod_ssl OCSP support */
+static int ocsp_send_req(apr_socket_t *sock, BIO *req)
+{
+ int len;
+ char buf[TCN_BUFFER_SZ];
+ apr_status_t rv;
+ int ok = 1;
+
+ while ((len = BIO_read(req, buf, sizeof buf)) > 0) {
+ char *wbuf = buf;
+ apr_size_t remain = len;
+
+ do {
+ apr_size_t wlen = remain;
+ rv = apr_socket_send(sock, wbuf, &wlen);
+ wbuf += remain;
+ remain -= wlen;
+ } while (rv == APR_SUCCESS && remain > 0);
+
+ if (rv != APR_SUCCESS) {
+ apr_socket_close(sock);
+ ok = 0;
+ }
+ }
+
+ return ok;
+}
+
+
+
+/* Parses the buffer from the response and extracts the OCSP response.
+ Taken from openssl library */
+static OCSP_RESPONSE *parse_ocsp_resp(char *buf, int len)
+{
+ BIO *mem = NULL;
+ char tmpbuf[1024];
+ OCSP_RESPONSE *resp = NULL;
+ char *p, *q, *r;
+ int retcode;
+
+ mem = BIO_new(BIO_s_mem());
+ if(mem == NULL)
+ return NULL;
+
+ BIO_write(mem, buf, len); /* write the buffer to the bio */
+ if (BIO_gets(mem, tmpbuf, 512) <= 0) {
+ OCSPerr(OCSP_F_OCSP_SENDREQ_BIO,OCSP_R_SERVER_RESPONSE_PARSE_ERROR);
+ goto err;
+ }
+ /* Parse the HTTP response. This will look like this:
+ * "HTTP/1.0 200 OK". We need to obtain the numeric code and
+ * (optional) informational message.
+ */
+
+ /* Skip to first white space (passed protocol info) */
+ for (p = tmpbuf; *p && !apr_isspace(*p); p++)
+ continue;
+ if (!*p) {
+ goto err;
+ }
+ /* Skip past white space to start of response code */
+ while (apr_isspace(*p))
+ p++;
+ if (!*p) {
+ goto err;
+ }
+ /* Find end of response code: first whitespace after start of code */
+ for (q = p; *q && !apr_isspace(*q); q++)
+ continue;
+ if (!*q) {
+ goto err;
+ }
+ /* Set end of response code and start of message */
+ *q++ = 0;
+ /* Attempt to parse numeric code */
+ retcode = strtoul(p, &r, 10);
+ if (*r)
+ goto err;
+ /* Skip over any leading white space in message */
+ while (apr_isspace(*q))
+ q++;
+ if (*q) {
+ /* Finally zap any trailing white space in message (include CRLF) */
+ /* We know q has a non white space character so this is OK */
+ for(r = q + strlen(q) - 1; apr_isspace(*r); r--) *r = 0;
+ }
+ if (retcode != 200) {
+ goto err;
+ }
+ /* Find blank line marking beginning of content */
+ while (BIO_gets(mem, tmpbuf, 512) > 0) {
+ for (p = tmpbuf; apr_isspace(*p); p++)
+ continue;
+ if (!*p)
+ break;
+ }
+ if (*p) {
+ goto err;
+ }
+ if (!(resp = d2i_OCSP_RESPONSE_bio(mem, NULL))) {
+ goto err;
+ }
+err:
+ BIO_free(mem);
+ return resp;
+}
+
+
+/* Reads the respnse from the APR socket to a buffer, and parses the buffer to
+ return the OCSP response */
+#define ADDLEN 512
+static OCSP_RESPONSE *ocsp_get_resp(apr_socket_t *sock)
+{
+ int buflen;
+ apr_size_t totalread = 0;
+ apr_size_t readlen;
+ char *buf, tmpbuf[ADDLEN];
+ apr_status_t rv = APR_SUCCESS;
+ apr_pool_t *p;
+ OCSP_RESPONSE *resp;
+
+ apr_pool_create(&p, NULL);
+ buflen = ADDLEN;
+ buf = apr_palloc(p, buflen);
+ if (buf == NULL) {
+ apr_pool_destroy(p);
+ return NULL;
+ }
+
+ while (rv == APR_SUCCESS ) {
+ readlen = sizeof(tmpbuf);
+ rv = apr_socket_recv(sock, tmpbuf, &readlen);
+ if (rv == APR_SUCCESS) { /* if we have read something .. we can put it in the buffer*/
+ if ((totalread + readlen) >= buflen) {
+ buf = apr_xrealloc(buf, buflen, buflen + ADDLEN, p);
+ if (buf == NULL) {
+ apr_pool_destroy(p);
+ return NULL;
+ }
+ buflen += ADDLEN; /* if needed we enlarge the buffer */
+ }
+ memcpy(buf + totalread, tmpbuf, readlen); /* the copy to the buffer */
+ totalread += readlen; /* update the total bytes read */
+ }
+ else {
+ if (rv == APR_EOF && readlen == 0)
+ ; /* EOF, normal situation */
+ else if (readlen == 0) {
+ /* Not success, and readlen == 0 .. some error */
+ apr_pool_destroy(p);
+ return NULL;
+ }
+ }
+ }
+
+ resp = parse_ocsp_resp(buf, buflen);
+ apr_pool_destroy(p);
+ return resp;
+}
+
+/* Creates and OCSP request and returns the OCSP_RESPONSE */
+static OCSP_RESPONSE *get_ocsp_response(X509 *cert, X509 *issuer, char *url)
+{
+ OCSP_RESPONSE *ocsp_resp = NULL;
+ OCSP_REQUEST *ocsp_req = NULL;
+ BIO *bio_req;
+ char *hostname, *path, *c_port;
+ int port, use_ssl;
+ STACK_OF(OCSP_CERTID) *ids = NULL;
+ int ok = 0;
+ apr_socket_t *apr_sock = NULL;
+ apr_pool_t *mp;
+
+ apr_pool_create(&mp, NULL);
+ ids = sk_OCSP_CERTID_new_null();
+
+ /* problem parsing the URL */
+ if (OCSP_parse_url(url,&hostname, &c_port, &path, &use_ssl) == 0 ) {
+ sk_OCSP_CERTID_free(ids);
+ return NULL;
+ }
+
+ /* Create the OCSP request */
+ if (sscanf(c_port, "%d", &port) != 1)
+ goto end;
+ ocsp_req = OCSP_REQUEST_new();
+ if (ocsp_req == NULL)
+ return NULL;
+ if (add_ocsp_cert(&ocsp_req,cert,issuer,ids) == 0 )
+ goto free_req;
+
+ /* create the BIO with the request to send */
+ bio_req = serialize_request(ocsp_req, hostname, port, path);
+ if (bio_req == NULL) {
+ goto free_req;
+ }
+
+ apr_sock = make_socket(hostname, port, mp);
+ if (apr_sock == NULL) {
+ ocsp_resp = NULL;
+ goto free_bio;
+ }
+
+ ok = ocsp_send_req(apr_sock, bio_req);
+ if (ok)
+ ocsp_resp = ocsp_get_resp(apr_sock);
+
+free_bio:
+ BIO_free(bio_req);
+
+free_req:
+ if(apr_sock && ok) /* if ok == 0 we have already closed the socket */
+ apr_socket_close(apr_sock);
+
+ apr_pool_destroy(mp);
+
+ sk_OCSP_CERTID_free(ids);
+ OCSP_REQUEST_free(ocsp_req);
+
+end:
+ return ocsp_resp;
+}
+
+/* Process the OCSP_RESPONSE and returns the corresponding
+ answert according to the status.
+*/
+static int process_ocsp_response(OCSP_RESPONSE *ocsp_resp)
+{
+ int r, o = V_OCSP_CERTSTATUS_UNKNOWN, i;
+ OCSP_BASICRESP *bs;
+ OCSP_SINGLERESP *ss;
+
+ r = OCSP_response_status(ocsp_resp);
+
+ if (r != OCSP_RESPONSE_STATUS_SUCCESSFUL) {
+ OCSP_RESPONSE_free(ocsp_resp);
+ return OCSP_STATUS_UNKNOWN;
+ }
+ bs = OCSP_response_get1_basic(ocsp_resp);
+
+ ss = OCSP_resp_get0(bs,0); /* we know we have only 1 request */
+
+ i = OCSP_single_get0_status(ss, NULL, NULL, NULL, NULL);
+ if (i == V_OCSP_CERTSTATUS_GOOD)
+ o = OCSP_STATUS_OK;
+ else if (i == V_OCSP_CERTSTATUS_REVOKED)
+ o = OCSP_STATUS_REVOKED;
+ else if (i == V_OCSP_CERTSTATUS_UNKNOWN)
+ o = OCSP_STATUS_UNKNOWN;
+
+ /* we clean up */
+ OCSP_RESPONSE_free(ocsp_resp);
+ return o;
+}
+
+static int ssl_ocsp_request(X509 *cert, X509 *issuer)
+{
+ char **ocsp_urls = NULL;
+ int nid;
+ X509_EXTENSION *ext;
+ ASN1_OCTET_STRING *os;
+ apr_pool_t *p;
+
+ apr_pool_create(&p, NULL);
+
+ /* Get the proper extension */
+ nid = X509_get_ext_by_NID(cert,NID_info_access,-1);
+ if (nid >= 0 ) {
+ ext = X509_get_ext(cert,nid);
+ os = X509_EXTENSION_get_data(ext);
+
+ ocsp_urls = decode_OCSP_url(os, p);
+ }
+
+ /* if we find the extensions and we can parse it check
+ the ocsp status. Otherwise, return OCSP_STATUS_UNKNOWN */
+ if (ocsp_urls != NULL) {
+ OCSP_RESPONSE *resp;
+ /* for the time being just check for the fist response .. a better
+ approach is to iterate for all the possible ocsp urls */
+ resp = get_ocsp_response(cert, issuer, ocsp_urls[0]);
+
+ if (resp != NULL) {
+ apr_pool_destroy(p);
+ return process_ocsp_response(resp);
+ }
+ }
+ apr_pool_destroy(p);
+ return OCSP_STATUS_UNKNOWN;
+}
+
+#endif /* HAS_OCSP_ENABLED */
+#endif /* HAVE_OPENSSL */
diff --git a/jni/native/src/stdlib.c b/jni/native/src/stdlib.c
new file mode 100644
index 0000000..3295934
--- /dev/null
+++ b/jni/native/src/stdlib.c
@@ -0,0 +1,120 @@
+/* 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: stdlib.c 1442587 2013-02-05 13:49:48Z rjung $
+ */
+
+#include "tcn.h"
+
+extern int tcn_parent_pid;
+
+TCN_IMPLEMENT_CALL(jlong, Stdlib, malloc)(TCN_STDARGS, jint size)
+{
+ UNREFERENCED_STDARGS;
+ if (size)
+ return P2J(malloc((size_t)size));
+ else
+ return 0;
+}
+
+TCN_IMPLEMENT_CALL(jlong, Stdlib, realloc)(TCN_STDARGS, jlong mem, jint size)
+{
+ void *ptr = J2P(mem, void *);
+ UNREFERENCED_STDARGS;
+ if (size)
+ return P2J(realloc(ptr, (size_t)size));
+ else
+ return 0;
+}
+
+TCN_IMPLEMENT_CALL(jlong, Stdlib, calloc)(TCN_STDARGS, jint num, jint size)
+{
+ UNREFERENCED_STDARGS;
+ if (num && size)
+ return P2J(calloc((size_t)num, (size_t)size));
+ else
+ return 0;
+}
+
+TCN_IMPLEMENT_CALL(void, Stdlib, free)(TCN_STDARGS, jlong mem)
+{
+ void *ptr = J2P(mem, void *);
+
+ UNREFERENCED_STDARGS;
+ if (ptr)
+ free(ptr);
+}
+
+TCN_IMPLEMENT_CALL(jboolean, Stdlib, memread)(TCN_STDARGS,
+ jbyteArray dst,
+ jlong src, jint sz)
+{
+ jbyte *s = J2P(src, jbyte *);
+ jbyte *dest = (*e)->GetPrimitiveArrayCritical(e, dst, NULL);
+
+ UNREFERENCED(o);
+ if (s && dest) {
+ memcpy(dest, s, (size_t)sz);
+ (*e)->ReleasePrimitiveArrayCritical(e, dst, dest, 0);
+ return JNI_TRUE;
+ }
+ else
+ return JNI_FALSE;
+}
+
+TCN_IMPLEMENT_CALL(jboolean, Stdlib, memwrite)(TCN_STDARGS, jlong dst,
+ jbyteArray src, jint sz)
+{
+ jbyte *dest = J2P(dst, jbyte *);
+ jbyte *s = (*e)->GetPrimitiveArrayCritical(e, src, NULL);
+
+ UNREFERENCED(o);
+ if (s && dest) {
+ memcpy(dest, s, (size_t)sz);
+ (*e)->ReleasePrimitiveArrayCritical(e, src, s, JNI_ABORT);
+ return JNI_TRUE;
+ }
+ else
+ return JNI_FALSE;
+}
+
+TCN_IMPLEMENT_CALL(jboolean, Stdlib, memset)(TCN_STDARGS, jlong dst,
+ jint c, jint sz)
+{
+ jbyte *dest = J2P(dst, jbyte *);
+
+ UNREFERENCED_STDARGS;
+ if (memset(dest, (int)c, (size_t)sz))
+ return JNI_TRUE;
+ else
+ return JNI_FALSE;
+}
+
+TCN_IMPLEMENT_CALL(jint, Stdlib, getpid)(TCN_STDARGS)
+{
+ UNREFERENCED_STDARGS;
+ return (jint)getpid();
+}
+
+TCN_IMPLEMENT_CALL(jint, Stdlib, getppid)(TCN_STDARGS)
+{
+ UNREFERENCED_STDARGS;
+ return (jint)tcn_parent_pid;
+}
+
diff --git a/jni/native/src/thread.c b/jni/native/src/thread.c
new file mode 100644
index 0000000..ccd6c78
--- /dev/null
+++ b/jni/native/src/thread.c
@@ -0,0 +1,29 @@
+/* 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: thread.c 1442587 2013-02-05 13:49:48Z rjung $
+ */
+
+#include "tcn.h"
+
+TCN_IMPLEMENT_CALL(jlong, Thread, current)(TCN_STDARGS)
+{
+ UNREFERENCED_STDARGS;
+ return (jlong)((unsigned long)apr_os_thread_current());
+}
diff --git a/jni/native/src/user.c b/jni/native/src/user.c
new file mode 100644
index 0000000..d3e7d2a
--- /dev/null
+++ b/jni/native/src/user.c
@@ -0,0 +1,163 @@
+/* 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: user.c 1442587 2013-02-05 13:49:48Z rjung $
+ */
+
+#include "tcn.h"
+#include "apr_user.h"
+#include "apr_network_io.h"
+
+TCN_IMPLEMENT_CALL(jlong, User, uidCurrent)(TCN_STDARGS, jlong pool)
+{
+ apr_pool_t *p = J2P(pool, apr_pool_t *);
+ apr_uid_t uid;
+ apr_gid_t gid;
+
+ UNREFERENCED(o);
+ TCN_THROW_IF_ERR(apr_uid_current(&uid, &gid, p), uid);
+
+cleanup:
+ return (jlong)uid;
+}
+
+TCN_IMPLEMENT_CALL(jlong, User, gidCurrent)(TCN_STDARGS, jlong pool)
+{
+ apr_pool_t *p = J2P(pool, apr_pool_t *);
+ apr_uid_t uid;
+ apr_gid_t gid;
+
+ UNREFERENCED(o);
+ TCN_THROW_IF_ERR(apr_uid_current(&uid, &gid, p), gid);
+
+cleanup:
+ return (jlong)gid;
+}
+
+TCN_IMPLEMENT_CALL(jlong, User, uid)(TCN_STDARGS, jstring uname, jlong pool)
+{
+ apr_pool_t *p = J2P(pool, apr_pool_t *);
+ apr_uid_t uid;
+ apr_gid_t gid;
+ TCN_ALLOC_CSTRING(uname);
+
+ UNREFERENCED(o);
+ TCN_THROW_IF_ERR(apr_uid_get(&uid, &gid, J2S(uname), p), uid);
+
+cleanup:
+ TCN_FREE_CSTRING(uname);
+ return (jlong)uid;
+}
+
+TCN_IMPLEMENT_CALL(jlong, User, usergid)(TCN_STDARGS, jstring uname,
+ jlong pool)
+{
+ apr_pool_t *p = J2P(pool, apr_pool_t *);
+ apr_uid_t uid;
+ apr_gid_t gid;
+ TCN_ALLOC_CSTRING(uname);
+
+ UNREFERENCED(o);
+ TCN_THROW_IF_ERR(apr_uid_get(&uid, &gid, J2S(uname), p), gid);
+
+cleanup:
+ TCN_FREE_CSTRING(uname);
+ return (jlong)gid;
+}
+
+TCN_IMPLEMENT_CALL(jlong, User, gid)(TCN_STDARGS, jstring gname, jlong pool)
+{
+ apr_pool_t *p = J2P(pool, apr_pool_t *);
+ apr_gid_t gid;
+ TCN_ALLOC_CSTRING(gname);
+
+ UNREFERENCED(o);
+ TCN_THROW_IF_ERR( apr_gid_get(&gid, J2S(gname), p), gid);
+
+cleanup:
+ TCN_FREE_CSTRING(gname);
+ return (jlong)gid;
+}
+
+TCN_IMPLEMENT_CALL(jstring, User, username)(TCN_STDARGS, jlong userid, jlong pool)
+{
+ apr_pool_t *p = J2P(pool, apr_pool_t *);
+ apr_uid_t uid = (apr_uid_t)userid;
+ char *uname = NULL;
+
+ UNREFERENCED(o);
+ TCN_THROW_IF_ERR(apr_uid_name_get(&uname, uid, p), uname);
+
+cleanup:
+ if (uname)
+ return AJP_TO_JSTRING(uname);
+ else
+ return NULL;
+}
+
+TCN_IMPLEMENT_CALL(jstring, User, groupname)(TCN_STDARGS, jlong grpid, jlong pool)
+{
+ apr_pool_t *p = J2P(pool, apr_pool_t *);
+ apr_gid_t gid = (apr_uid_t)grpid;
+ char *gname = NULL;
+
+ UNREFERENCED(o);
+ TCN_THROW_IF_ERR(apr_gid_name_get(&gname, gid, p), gname);
+
+cleanup:
+ if (gname)
+ return AJP_TO_JSTRING(gname);
+ else
+ return NULL;
+}
+
+TCN_IMPLEMENT_CALL(jint, User,uidcompare)(TCN_STDARGS, jlong left, jlong right)
+{
+
+ UNREFERENCED_STDARGS;
+ return (int)apr_uid_compare((apr_uid_t)left,
+ (apr_uid_t)right);
+}
+
+TCN_IMPLEMENT_CALL(jint, User,gidcompare)(TCN_STDARGS, jlong left, jlong right)
+{
+
+ UNREFERENCED_STDARGS;
+ return (int)apr_gid_compare((apr_gid_t)left,
+ (apr_gid_t)right);
+}
+
+TCN_IMPLEMENT_CALL(jstring, User, homepath)(TCN_STDARGS, jstring uname, jlong pool)
+{
+ apr_pool_t *p = J2P(pool, apr_pool_t *);
+ char *dirname = NULL;
+ TCN_ALLOC_CSTRING(uname);
+
+ UNREFERENCED(o);
+ TCN_THROW_IF_ERR(apr_uid_homepath_get(&dirname, J2S(uname),
+ p), dirname);
+
+cleanup:
+ TCN_FREE_CSTRING(uname);
+ if (dirname)
+ return AJP_TO_JSTRING(dirname);
+ else
+ return NULL;
+}
+
diff --git a/jni/native/srclib/BUILDING b/jni/native/srclib/BUILDING
new file mode 100644
index 0000000..d718bfa
--- /dev/null
+++ b/jni/native/srclib/BUILDING
@@ -0,0 +1,42 @@
+Building apr on windows
+-----------------------
+
+Apply apr-enable-ipv6.patch.
+This will enable IPV6 support for windows builds.
+
+Open Visual Studio command prompt and execute
+nmake -f NMAKEMakefile BUILD_CPU=x86 APR_DECLARE_STATIC=1
+
+For building 64-bit version execute
+nmake -f NMAKEMakefile BUILD_CPU=x64 APR_DECLARE_STATIC=1
+
+Make sure you select the correct Visual Studio command prompt
+environment before calling nmake so that correct
+compiler is setup for the target architecture.
+
+
+Building OpenSSL
+----------------
+
+Apply openssl-msvcrt.patch
+
+This patch makes sure that static version of OpenSSL libraries
+is linked to msvcrt.dll instead statically linking msvcrt.
+Without that patch it won't be possible to create statically linked
+Tomcat native .dll
+
+Then follow the standard OpenSSL make procedure ...
+
+> perl Configure VC-WIN32
+> ms\do_nasm
+> nmake -f ms\nt.mak
+
+For 64-bit Windows use
+> perl Configure VC-WIN64A
+> ms\do_win64a
+> nmake -f ms\nt.mak
+
+For 64-bit Windows on Itanium processor use
+> perl Configure VC-WIN64I
+> ms\do_win64i
+> nmake -f ms\nt.mak
diff --git a/jni/native/srclib/VERSIONS b/jni/native/srclib/VERSIONS
new file mode 100644
index 0000000..8e00653
--- /dev/null
+++ b/jni/native/srclib/VERSIONS
@@ -0,0 +1,4 @@
+Use the following version of the libraries
+
+- APR 1.4.8, http://apr.apache.org
+- OpenSSL 1.0.1g, http://www.openssl.org
diff --git a/jni/native/srclib/apr/NMAKEmakefile b/jni/native/srclib/apr/NMAKEmakefile
new file mode 100644
index 0000000..f2ae3f8
--- /dev/null
+++ b/jni/native/srclib/apr/NMAKEmakefile
@@ -0,0 +1,234 @@
+# 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.
+#
+# ====================================================================
+#
+# NMAKEmakefile Master APR makefile.
+# Usage:
+# DLL=1 Build DLL version
+# DEBUG=1 Build DEBUG version of APR
+#
+# Originally contributed by Mladen Turk <mturk redhat.com>
+#
+# ====================================================================
+#
+
+!IF !DEFINED(APR_DECLARE_STATIC) || "$(APR_DECLARE_STATIC)" == ""
+TARGET=DLL
+EXTRA_CFLAGS = -DAPR_DECLARE_EXPORT
+PROJECT = libapr-1
+!ELSE
+TARGET=LIB
+EXTRA_CFLAGS = -DAPR_DECLARE_STATIC
+PROJECT = apr-1
+!ENDIF
+
+!IF !DEFINED(SRCDIR) || "$(SRCDIR)" == ""
+SRCDIR = .
+!ENDIF
+
+!include <..\..\NMAKEMakefile.inc>
+
+
+!IF "$(TARGET)" != "LIB"
+LFLAGS = $(LFLAGS) /version:1.4
+!ENDIF
+INCLUDES = -I$(SRCDIR)\include -I$(SRCDIR)\include\arch -I$(SRCDIR)\include\arch\win32 -I$(SRCDIR)\include\arch\unix
+PDBFLAGS = -Fo$(WORKDIR)\ -Fd$(WORKDIR)\$(PROJECT)-src
+OBJECTS = \
+ $(WORKDIR)\apr_atomic.obj \
+ $(WORKDIR)\dso.obj \
+ $(WORKDIR)\buffer.obj \
+ $(WORKDIR)\copy.obj \
+ $(WORKDIR)\dir.obj \
+ $(WORKDIR)\fileacc.obj \
+ $(WORKDIR)\filedup.obj \
+ $(WORKDIR)\filepath.obj \
+ $(WORKDIR)\filepath_util.obj \
+ $(WORKDIR)\filestat.obj \
+ $(WORKDIR)\filesys.obj \
+ $(WORKDIR)\flock.obj \
+ $(WORKDIR)\fullrw.obj \
+ $(WORKDIR)\mktemp.obj \
+ $(WORKDIR)\open.obj \
+ $(WORKDIR)\pipe.obj \
+ $(WORKDIR)\readwrite.obj \
+ $(WORKDIR)\seek.obj \
+ $(WORKDIR)\tempdir.obj \
+ $(WORKDIR)\proc_mutex.obj \
+ $(WORKDIR)\thread_cond.obj \
+ $(WORKDIR)\thread_mutex.obj \
+ $(WORKDIR)\thread_rwlock.obj \
+ $(WORKDIR)\apr_pools.obj \
+ $(WORKDIR)\apr_app.obj \
+ $(WORKDIR)\charset.obj \
+ $(WORKDIR)\env.obj \
+ $(WORKDIR)\errorcodes.obj \
+ $(WORKDIR)\getopt.obj \
+ $(WORKDIR)\internal.obj \
+ $(WORKDIR)\misc.obj \
+ $(WORKDIR)\otherchild.obj \
+ $(WORKDIR)\rand.obj \
+ $(WORKDIR)\start.obj \
+ $(WORKDIR)\utf8.obj \
+ $(WORKDIR)\version.obj \
+ $(WORKDIR)\common.obj \
+ $(WORKDIR)\mmap.obj \
+ $(WORKDIR)\inet_ntop.obj \
+ $(WORKDIR)\inet_pton.obj \
+ $(WORKDIR)\multicast.obj \
+ $(WORKDIR)\sendrecv.obj \
+ $(WORKDIR)\sockaddr.obj \
+ $(WORKDIR)\sockets.obj \
+ $(WORKDIR)\socket_util.obj \
+ $(WORKDIR)\sockopt.obj \
+ $(WORKDIR)\apr_getpass.obj \
+ $(WORKDIR)\poll.obj \
+ $(WORKDIR)\pollcb.obj \
+ $(WORKDIR)\pollset.obj \
+ $(WORKDIR)\select.obj \
+ $(WORKDIR)\apr_random.obj \
+ $(WORKDIR)\sha2.obj \
+ $(WORKDIR)\sha2_glue.obj \
+ $(WORKDIR)\shm.obj \
+ $(WORKDIR)\apr_cpystrn.obj \
+ $(WORKDIR)\apr_fnmatch.obj \
+ $(WORKDIR)\apr_snprintf.obj \
+ $(WORKDIR)\apr_strings.obj \
+ $(WORKDIR)\apr_strnatcmp.obj \
+ $(WORKDIR)\apr_strtok.obj \
+ $(WORKDIR)\apr_hash.obj \
+ $(WORKDIR)\apr_tables.obj \
+ $(WORKDIR)\proc.obj \
+ $(WORKDIR)\signals.obj \
+ $(WORKDIR)\thread.obj \
+ $(WORKDIR)\threadpriv.obj \
+ $(WORKDIR)\time.obj \
+ $(WORKDIR)\timestr.obj \
+ $(WORKDIR)\groupinfo.obj \
+ $(WORKDIR)\userinfo.obj
+
+BUILDINC = $(PREFIX)\include\apr-1
+BUILDLIB = $(PREFIX)\lib
+!IF "$(TARGET)" == "DLL"
+BUILDBIN = $(WORKDIR)\$(PROJECT).dll
+BUILDPDB = $(WORKDIR)\$(PROJECT).pdb
+BUILDRES = $(WORKDIR)\$(PROJECT).res
+BUILDMAN = $(BUILDBIN).manifest
+!ELSE
+BUILDBIN = $(WORKDIR)\$(PROJECT).lib
+!ENDIF
+
+all : $(WORKDIR) $(BUILDBIN)
+
+$(BUILDINC) :
+ @if not exist "$(BUILDINC)\arch\win32\$(NULL)" mkdir "$(BUILDINC)\arch\win32"
+
+$(BUILDLIB) :
+ @if not exist "$(BUILDLIB)\$(NULL)" mkdir "$(BUILDLIB)"
+
+$(WORKDIR) :
+ @$(MAKEWORKDIR)
+
+$(SRCDIR)\include\apr.h: $(SRCDIR)\include\apr.hw
+ - at copy $(SRCDIR)\include\apr.hw $(SRCDIR)\include\apr.h
+
+{$(SRCDIR)\atomic\win32}.c{$(WORKDIR)}.obj:
+ $(CC) $(CFLAGS) $(INCLUDES) $(PDBFLAGS) $<
+
+{$(SRCDIR)\dso\win32}.c{$(WORKDIR)}.obj:
+ $(CC) $(CFLAGS) $(INCLUDES) $(PDBFLAGS) $<
+
+{$(SRCDIR)\file_io\unix}.c{$(WORKDIR)}.obj:
+ $(CC) $(CFLAGS) $(INCLUDES) $(PDBFLAGS) $<
+
+{$(SRCDIR)\file_io\win32}.c{$(WORKDIR)}.obj:
+ $(CC) $(CFLAGS) $(INCLUDES) $(PDBFLAGS) $<
+
+{$(SRCDIR)\locks\win32}.c{$(WORKDIR)}.obj:
+ $(CC) $(CFLAGS) $(INCLUDES) $(PDBFLAGS) $<
+
+{$(SRCDIR)\memory\unix}.c{$(WORKDIR)}.obj:
+ $(CC) $(CFLAGS) $(INCLUDES) $(PDBFLAGS) $<
+
+{$(SRCDIR)\misc\unix}.c{$(WORKDIR)}.obj:
+ $(CC) $(CFLAGS) $(INCLUDES) $(PDBFLAGS) $<
+
+{$(SRCDIR)\misc\win32}.c{$(WORKDIR)}.obj:
+ $(CC) $(CFLAGS) $(INCLUDES) $(PDBFLAGS) $<
+
+{$(SRCDIR)\mmap\unix}.c{$(WORKDIR)}.obj:
+ $(CC) $(CFLAGS) $(INCLUDES) $(PDBFLAGS) $<
+
+{$(SRCDIR)\mmap\win32}.c{$(WORKDIR)}.obj:
+ $(CC) $(CFLAGS) $(INCLUDES) $(PDBFLAGS) $<
+
+{$(SRCDIR)\network_io\unix}.c{$(WORKDIR)}.obj:
+ $(CC) $(CFLAGS) $(INCLUDES) $(PDBFLAGS) $<
+
+{$(SRCDIR)\network_io\win32}.c{$(WORKDIR)}.obj:
+ $(CC) $(CFLAGS) $(INCLUDES) $(PDBFLAGS) $<
+
+{$(SRCDIR)\passwd}.c{$(WORKDIR)}.obj:
+ $(CC) $(CFLAGS) $(INCLUDES) $(PDBFLAGS) $<
+
+{$(SRCDIR)\poll\unix}.c{$(WORKDIR)}.obj:
+ $(CC) $(CFLAGS) $(INCLUDES) $(PDBFLAGS) $<
+
+{$(SRCDIR)\random\unix}.c{$(WORKDIR)}.obj:
+ $(CC) $(CFLAGS) $(INCLUDES) $(PDBFLAGS) $<
+
+{$(SRCDIR)\shmem\win32}.c{$(WORKDIR)}.obj:
+ $(CC) $(CFLAGS) $(INCLUDES) $(PDBFLAGS) $<
+
+{$(SRCDIR)\strings}.c{$(WORKDIR)}.obj:
+ $(CC) $(CFLAGS) $(INCLUDES) $(PDBFLAGS) $<
+
+{$(SRCDIR)\tables}.c{$(WORKDIR)}.obj:
+ $(CC) $(CFLAGS) $(INCLUDES) $(PDBFLAGS) $<
+
+{$(SRCDIR)\threadproc\win32}.c{$(WORKDIR)}.obj:
+ $(CC) $(CFLAGS) $(INCLUDES) $(PDBFLAGS) $<
+
+{$(SRCDIR)\time\win32}.c{$(WORKDIR)}.obj:
+ $(CC) $(CFLAGS) $(INCLUDES) $(PDBFLAGS) $<
+
+{$(SRCDIR)\user\win32}.c{$(WORKDIR)}.obj:
+ $(CC) $(CFLAGS) $(INCLUDES) $(PDBFLAGS) $<
+
+$(OBJECTS): $(SRCDIR)\include\apr.h
+
+!IF "$(TARGET)" == "DLL"
+$(BUILDRES): libapr.rc $(SRCDIR)\include\apr.h
+ $(RC) $(RCFLAGS) /i "$(SRCDIR)\include" /d "APR_VERSION_ONLY" /fo $(BUILDRES) libapr.rc
+$(BUILDBIN): $(WORKDIR) $(OBJECTS) $(BUILDRES)
+ $(LINK) $(LFLAGS) $(OBJECTS) $(BUILDRES) $(LIBS) /pdb:$(BUILDPDB) /out:$(BUILDBIN)
+ IF EXIST $(BUILDMAN) \
+ mt -nologo -manifest $(BUILDMAN) -outputresource:$(BUILDBIN);2
+!ELSE
+$(BUILDBIN): $(WORKDIR) $(OBJECTS)
+ $(LINK) $(LFLAGS) $(OBJECTS) /out:$(BUILDBIN)
+!ENDIF
+
+clean:
+ @$(CLEANTARGET)
+
+install: $(BUILDINC) $(BUILDLIB) $(WORKDIR) $(BUILDBIN)
+ @xcopy "$(SRCDIR)\include\*.h" "$(BUILDINC)" /Y /Q
+ @xcopy "$(SRCDIR)\include\arch\apr_private_common.h" "$(BUILDINC)\arch" /Y /Q
+ @xcopy "$(SRCDIR)\include\arch\win32\*.h" "$(BUILDINC)\arch\win32" /Y /Q
+ @xcopy "$(WORKDIR)\*.lib" "$(BUILDLIB)" /Y /Q
+ @xcopy "$(WORKDIR)\*.dll" "$(BUILDLIB)" /Y /Q 2>NUL
+
diff --git a/jni/native/srclib/apr/apr-enable-ipv6.patch b/jni/native/srclib/apr/apr-enable-ipv6.patch
new file mode 100644
index 0000000..5c98a12
--- /dev/null
+++ b/jni/native/srclib/apr/apr-enable-ipv6.patch
@@ -0,0 +1,20 @@
+--- include/apr.hw
++++ include/apr.hw
+@@ -276,7 +276,7 @@
+ #define APR_HAVE_IN_ADDR 1
+ #define APR_HAVE_INET_ADDR 1
+ #define APR_HAVE_INET_NETWORK 0
+-#define APR_HAVE_IPV6 0
++#define APR_HAVE_IPV6 1
+ #define APR_HAVE_MEMMOVE 1
+ #define APR_HAVE_SETRLIMIT 0
+ #define APR_HAVE_SIGACTION 0
+@@ -340,7 +340,7 @@
+ /* If we have a TCP implementation that can be "corked", what flag
+ * do we use?
+ */
+-#define APR_TCP_NOPUSH_FLAG @apr_tcp_nopush_flag@
++#define APR_TCP_NOPUSH_FLAG 0
+
+ /* Is the TCP_NODELAY socket option inherited from listening sockets?
+ */
diff --git a/jni/native/srclib/openssl/openssl-msvcrt.patch b/jni/native/srclib/openssl/openssl-msvcrt.patch
new file mode 100644
index 0000000..c0ea602
--- /dev/null
+++ b/jni/native/srclib/openssl/openssl-msvcrt.patch
@@ -0,0 +1,28 @@
+--- util/pl/VC-32.pl
++++ util/pl/VC-32.pl
+@@ -43,7 +43,7 @@
+ # considered safe to ignore.
+ #
+ $base_cflags= " $mf_cflag";
+- my $f = $shlib || $fips ?' /MD':' /MT';
++ my $f = ' /MD';
+ $lib_cflag='/Zl' if (!$shlib); # remove /DEFAULTLIBs from static lib
+ $opt_cflags=$f.' /Ox';
+ $dbg_cflags=$f.'d /Od -DDEBUG -D_DEBUG';
+@@ -124,7 +124,7 @@
+ else # Win32
+ {
+ $base_cflags= " $mf_cflag";
+- my $f = $shlib || $fips ?' /MD':' /MT';
++ my $f = ' /MD';
+ $lib_cflag='/Zl' if (!$shlib); # remove /DEFAULTLIBs from static lib
+ $opt_cflags=$f.' /Ox /O2 /Ob2';
+ $dbg_cflags=$f.'d /Od -DDEBUG -D_DEBUG';
+@@ -175,6 +175,7 @@
+ {
+ $ex_libs.=' gdi32.lib advapi32.lib crypt32.lib user32.lib';
+ $ex_libs.=' bufferoverflowu.lib' if ($FLAVOR =~ /WIN64/ and `cl 2>&1` =~ /14\.00\.4[0-9]{4}\./);
++ $ex_libs.=' $(EXTRA_LIBS)';
+ # WIN32 UNICODE build gets linked with unicows.lib for
+ # backward compatibility with Win9x.
+ $ex_libs="unicows.lib $ex_libs" if ($FLAVOR =~ /WIN32/ and $cflags =~ /\-DUNICODE/);
diff --git a/jni/native/tcnative.dsp b/jni/native/tcnative.dsp
new file mode 100644
index 0000000..fe3bec2
--- /dev/null
+++ b/jni/native/tcnative.dsp
@@ -0,0 +1,231 @@
+# Microsoft Developer Studio Project File - Name="tcnative" - Package Owner=<4>
+# Microsoft Developer Studio Generated Build File, Format Version 6.00
+# ** DO NOT EDIT **
+
+# TARGTYPE "Win32 (x86) Dynamic-Link Library" 0x0102
+
+CFG=tcnative - Win32 Debug
+!MESSAGE This is not a valid makefile. To build this project using NMAKE,
+!MESSAGE use the Export Makefile command and run
+!MESSAGE
+!MESSAGE NMAKE /f "tcnative.mak".
+!MESSAGE
+!MESSAGE You can specify a configuration when running NMAKE
+!MESSAGE by defining the macro CFG on the command line. For example:
+!MESSAGE
+!MESSAGE NMAKE /f "tcnative.mak" CFG="tcnative - Win32 Debug"
+!MESSAGE
+!MESSAGE Possible choices for configuration are:
+!MESSAGE
+!MESSAGE "tcnative - Win32 Release" (based on "Win32 (x86) Dynamic-Link Library")
+!MESSAGE "tcnative - Win32 Debug" (based on "Win32 (x86) Dynamic-Link Library")
+!MESSAGE
+
+# Begin Project
+# PROP AllowPerConfigDependencies 0
+# PROP Scc_ProjName ""
+# PROP Scc_LocalPath ""
+CPP=cl.exe
+MTL=midl.exe
+RSC=rc.exe
+
+!IF "$(CFG)" == "tcnative - Win32 Release"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 0
+# PROP BASE Output_Dir "Release"
+# PROP BASE Intermediate_Dir "Release"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 0
+# PROP Output_Dir "LibR"
+# PROP Intermediate_Dir "LibR"
+# PROP Ignore_Export_Lib 0
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /MD /W3 /Zi /O2 /Oy- /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /FD /c
+# ADD CPP /nologo /MD /W3 /Zi /O2 /Oy- /I "./include" /I "./srclib/apr/include" /I "./srclib/apr/include/arch/win32" /I "$(JAVA_HOME)/include" /I "$(JAVA_HOME)/include/win32" /I "./srclib/openssl/inc32" /D "NDEBUG" /D "WIN32" /D "_WINDOWS" /D "APR_DECLARE_STATIC" /D "NO_IDEA" /D "NO_RC5" /D "NO_MDC2" /D "OPENSSL_NO_IDEA" /D "OPENSSL_NO_RC5" /D "OPENSSL_NO_MDC2" /D "HAVE_OPENSSL" /D HAVE_SSL_SET_STATE=1 /Fd"LibR\tcnative_src" /FD /c
+# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /o /win32 "NUL"
+# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /o /win32 "NUL"
+# ADD BASE RSC /l 0x409 /d "NDEBUG"
+# ADD RSC /l 0x409 /d "NDEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 kernel32.lib advapi32.lib ws2_32.lib mswsock.lib wldap32.lib psapi.lib ole32.lib shlwapi.lib /nologo /base:"0x6EE00000" /subsystem:windows /dll /debug /machine:I386 /opt:ref
+# ADD LINK32 kernel32.lib advapi32.lib ws2_32.lib mswsock.lib wldap32.lib psapi.lib ole32.lib shlwapi.lib rpcrt4.lib libeay32.lib ssleay32.lib /nologo /base:"0x6EE00000" /subsystem:windows /dll /debug /machine:I386 /out:"LibR/tcnative-1.dll" /libpath:"./srclib/openssl/out32" /libpath:"./srclib/openssl/out32dll" /opt:ref
+
+!ELSEIF "$(CFG)" == "tcnative - Win32 Debug"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 1
+# PROP BASE Output_Dir "Debug"
+# PROP BASE Intermediate_Dir "Debug"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 1
+# PROP Output_Dir "LibD"
+# PROP Intermediate_Dir "LibD"
+# PROP Ignore_Export_Lib 0
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /MDd /W3 /GX /Zi /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /FD /c
+# ADD CPP /nologo /MDd /W4 /GX /Zi /Od /I "./include" /I "./srclib/apr/include" /I "./srclib/apr/include/arch/win32" /I "$(JAVA_HOME)/include" /I "$(JAVA_HOME)/include/win32" /I "./srclib/openssl/inc32" /D "_DEBUG" /D "WIN32" /D "_WINDOWS" /D "APR_DECLARE_STATIC" /D "NO_IDEA" /D "NO_RC5" /D "NO_MDC2" /D "OPENSSL_NO_IDEA" /D "OPENSSL_NO_RC5" /D "OPENSSL_NO_MDC2" /D "HAVE_OPENSSL" /D HAVE_SSL_SET_STATE=1 /Fd"LibD\tcnative_src" /FD /c
+# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /o /win32 "NUL"
+# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /o /win32 "NUL"
+# ADD BASE RSC /l 0x409 /d "_DEBUG"
+# ADD RSC /l 0x409 /d "_DEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 kernel32.lib advapi32.lib ws2_32.lib mswsock.lib wldap32.lib psapi.lib ole32.lib shlwapi.lib /nologo /base:"0x6EE00000" /subsystem:windows /dll /incremental:no /debug /machine:I386
+# ADD LINK32 kernel32.lib advapi32.lib ws2_32.lib mswsock.lib wldap32.lib psapi.lib ole32.lib shlwapi.lib rpcrt4.lib libeay32.lib ssleay32.lib /nologo /base:"0x6EE00000" /subsystem:windows /dll /incremental:no /debug /machine:I386 /out:"LibD/tcnative-1.dll" /libpath:"./srclib/openssl/out32" /libpath:"./srclib/openssl/out32dll"
+
+!ENDIF
+
+# Begin Target
+
+# Name "tcnative - Win32 Release"
+# Name "tcnative - Win32 Debug"
+# Begin Group "Source Files"
+
+# PROP Default_Filter ""
+# Begin Source File
+
+SOURCE=.\src\address.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\src\dir.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\src\error.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\src\file.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\src\info.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\src\jnilib.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\src\lock.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\src\misc.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\src\mmap.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\src\multicast.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\src\network.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\src\poll.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\src\pool.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\src\proc.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\src\shm.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\src\ssl.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\src\sslcontext.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\src\sslinfo.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\src\sslnetwork.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\src\sslutils.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\src\stdlib.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\src\thread.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\src\user.c
+# End Source File
+# End Group
+# Begin Group "Generated Files"
+
+# PROP Default_Filter ""
+# End Group
+# Begin Group "Header Files"
+
+# PROP Default_Filter ""
+# Begin Source File
+
+SOURCE=.\include\ssl_private.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\include\tcn.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\include\tcn_api.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\include\tcn_version.h
+# End Source File
+# End Group
+# Begin Group "Platform Files"
+
+# PROP Default_Filter ""
+# Begin Source File
+
+SOURCE=.\os\win32\ntpipe.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\os\win32\registry.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\os\win32\system.c
+# End Source File
+# End Group
+# Begin Source File
+
+SOURCE=.\os\win32\libtcnative.rc
+# End Source File
+# End Target
+# End Project
diff --git a/jni/native/tcnative.pc.in b/jni/native/tcnative.pc.in
new file mode 100644
index 0000000..d593df1
--- /dev/null
+++ b/jni/native/tcnative.pc.in
@@ -0,0 +1,30 @@
+#
+# 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.
+#
+
+prefix=@prefix@
+exec_prefix=@exec_prefix@
+libdir=@libdir@
+TCNATIVE_MAJOR_VERSION=@TCNATIVE_MAJOR_VERSION@
+includedir=@includedir@
+
+Name: Tomcat native Java
+Description: Companion Native Java library
+Version: @TCNATIVE_DOTTED_VERSION@
+# assume that tcnative requires libapr of same major version
+Requires: apr- at TCNATIVE_MAJOR_VERSION@
+Libs: -L${libdir} -l at TCNATIVE_LIBNAME@ @TCNATIVE_EXPORT_LIBS@
+Cflags: -I${includedir}
diff --git a/jni/native/tcnative.spec b/jni/native/tcnative.spec
new file mode 100644
index 0000000..480dd37
--- /dev/null
+++ b/jni/native/tcnative.spec
@@ -0,0 +1,97 @@
+#
+# 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.
+#
+
+%define tcnver 1
+%define aprver 1
+
+Summary: Tomcat Native Java library
+Name: tcnative
+Version: 1.1.30
+Release: 1
+License: Apache Software License
+Group: System Environment/Libraries
+URL: http://apr.apache.org/
+Source0: %{name}-%{version}.tar.gz
+BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-buildroot
+BuildPrereq: autoconf, libtool, doxygen, apr-devel >= 0:{version}-{release}, openssl >= 0.9.7
+
+%description
+The mission of the Tomcat Native Library (TCN) is to provide a
+free library of C data structures and routines. This library
+contains additional utility interfaces for Java.
+
+%package devel
+Group: Development/Libraries
+Summary: Tomcat Native development kit
+Requires: tcnative = %{version}-%{release}, apr-devel >= 0:{version}-{release}, openssl-devel >= 0.9.7
+
+%description devel
+The mission of the Tomcat Native Library (TCN) is to provide a
+free library of C data structures and routines. This library
+contains additional utility interfaces for Java.
+
+%prep
+%setup -q
+
+%build
+%configure --with-apr=%{_prefix} \
+ --includedir=%{_includedir}/apr-%{aprver}
+make %{?_smp_mflags} && make dox
+
+%check
+# Run non-interactive tests
+pushd test
+make %{?_smp_mflags} testall CFLAGS=-fno-strict-aliasing
+./testall -v || exit 1
+popd
+
+%install
+rm -rf $RPM_BUILD_ROOT
+make install DESTDIR=$RPM_BUILD_ROOT
+
+# Documentation
+mv docs/dox/html html
+
+# Unpackaged files
+rm -f $RPM_BUILD_ROOT%{_libdir}/tcnative.exp
+
+%clean
+rm -rf $RPM_BUILD_ROOT
+
+%post -p /sbin/ldconfig
+
+%postun -p /sbin/ldconfig
+
+%files
+%defattr(-,root,root,-)
+%doc CHANGES LICENSE NOTICE
+%{_libdir}/libtcnative-%{tcnver}.so.*
+
+%files devel
+%defattr(-,root,root,-)
+%{_libdir}/libtcnative-%{tcnver}.*a
+%{_libdir}/libtcnative-%{tcnver}.so
+%{_libdir}/pkgconfig/tcnative-%{tcnver}.pc
+%{_includedir}/apr-%{aprver}/*.h
+%doc --parents html
+
+%changelog
+* Mon Jan 04 2010 Rainer Jung <rjung at apache.org> 1.0.0-2
+- Decouple apr major lib version form tcnative lib version
+* Tue Jun 22 2004 Mladen Turk <mturk at jboss.com> 1.0.0-1
+- update to support v1.0.2 of APR
+
diff --git a/jni/test/org/apache/tomcat/jni/FileTestSuite.java b/jni/test/org/apache/tomcat/jni/FileTestSuite.java
new file mode 100644
index 0000000..91cc43a
--- /dev/null
+++ b/jni/test/org/apache/tomcat/jni/FileTestSuite.java
@@ -0,0 +1,43 @@
+/*
+ * 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.
+ */
+
+package org.apache.tomcat.jni;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+import junit.textui.TestRunner;
+
+/**
+ * A basic test suite that tests File IO.
+ *
+ * @author Mladen Turk
+ * @version $Id: FileTestSuite.java 1442587 2013-02-05 13:49:48Z rjung $
+ * @see org.apache.tomcat.jni
+ */
+public class FileTestSuite
+{
+
+ public static void main(String[] args) {
+ TestRunner.run(suite());
+ }
+
+ public static Test suite()
+ {
+ TestSuite suite = new TestSuite( "Tomcat Native File IO" );
+ return suite;
+ }
+}
diff --git a/jni/test/org/apache/tomcat/jni/SocketServerTestBind.java b/jni/test/org/apache/tomcat/jni/SocketServerTestBind.java
new file mode 100644
index 0000000..291f4a0
--- /dev/null
+++ b/jni/test/org/apache/tomcat/jni/SocketServerTestBind.java
@@ -0,0 +1,132 @@
+/*
+ * 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.
+ */
+
+package org.apache.tomcat.jni;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+import junit.textui.TestRunner;
+import junit.framework.TestCase;
+
+import java.io.OutputStream;
+import java.io.InputStream;
+import java.net.NetworkInterface;
+import java.net.InetAddress;
+import java.util.*;
+
+/**
+ * A basic test suite that tests Socket Server feature.
+ *
+ * @author Jean-Frederic Clere
+ * @version $Id: SocketServerTestBind.java 1442587 2013-02-05 13:49:48Z rjung $
+ * @see org.apache.tomcat.jni
+ */
+public class SocketServerTestBind extends TestCase {
+
+ private long serverSock = 0;
+ private int port=6666;
+ private String host=null;
+
+ public static long serverPool = 0;
+
+ public void testSocketServerTestBind() throws Exception {
+
+ System.out.println("Starting: testSocketServerTestBind");
+ /* Load APR library */
+ Library.initialize(null);
+
+ /* Create the server socket and listen on it */
+ serverPool = Pool.create(0);
+ long inetAddress = Address.info(host, Socket.APR_UNSPEC,
+ port, 0, serverPool);
+ serverSock = Socket.create(Address.getInfo(inetAddress).family,
+ Socket.SOCK_STREAM,
+ Socket.APR_PROTO_TCP, serverPool);
+ int rc = Socket.bind(serverSock, inetAddress);
+ if (rc != 0) {
+ throw(new Exception("Can't bind: " + Error.strerror(rc)));
+ }
+ Socket.listen(serverSock, 5);
+
+ /* Start the client that connects to the server */
+ Client client = new Client();
+ client.start();
+ java.lang.Thread.sleep(100);
+
+ boolean running = true;
+ while (running) {
+ /* Accept it */
+ long clientSock = Socket.accept(serverSock);
+ Socket.timeoutSet(clientSock, 10000);
+ byte [] buf = new byte[1];
+ while (Socket.recv(clientSock, buf, 0, 1) == 1) {
+ if (buf[0] == 'A') {
+ buf[0] = 'Z';
+ Socket.send(clientSock, buf, 0, 1);
+ }
+ }
+ Socket.close(clientSock);
+ if (buf[0] != 'Z')
+ running = false;
+ }
+ client.join();
+ Library.terminate();
+ System.out.println("Done: testSocketServerTestBind");
+ }
+
+ /* small client that connects and sends one byte */
+ private class Client extends java.lang.Thread {
+ public void run() {
+ try {
+ Enumeration nets = NetworkInterface.getNetworkInterfaces();
+ while (nets.hasMoreElements()) {
+ NetworkInterface net = (NetworkInterface) nets.nextElement();
+
+ Enumeration addrs = net.getInetAddresses();
+
+ while (addrs.hasMoreElements()) {
+ InetAddress ia = (InetAddress)addrs.nextElement();
+ System.out.println("Trying: " + ia.getHostAddress());
+ java.net.Socket sock = new java.net.Socket(ia, port);
+ sock.setSoTimeout(10000);
+ OutputStream ou = sock.getOutputStream();
+ InputStream in = sock.getInputStream();
+ ou.write('A');
+ ou.flush();
+ int rep = in.read();
+ sock.close();
+ if (rep != 'Z')
+ throw new Exception("Read wrong data");
+ }
+ }
+ } catch(Exception ex ) {
+ ex.printStackTrace();
+ }
+
+ /* Now use localhost to write 'E' */
+ try {
+ java.net.Socket sock = new java.net.Socket("localhost", port);
+ OutputStream ou = sock.getOutputStream();
+ ou.write('E');
+ ou.flush();
+ sock.close();
+ } catch(Exception ex ) {
+ ex.printStackTrace();
+ }
+ }
+ }
+}
diff --git a/jni/test/org/apache/tomcat/jni/SocketServerTestSuite.java b/jni/test/org/apache/tomcat/jni/SocketServerTestSuite.java
new file mode 100644
index 0000000..55ef465
--- /dev/null
+++ b/jni/test/org/apache/tomcat/jni/SocketServerTestSuite.java
@@ -0,0 +1,206 @@
+/*
+ * 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.
+ */
+
+package org.apache.tomcat.jni;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+import junit.textui.TestRunner;
+import junit.framework.TestCase;
+
+import java.io.OutputStream;
+
+/**
+ * A basic test suite that tests Socket Server feature.
+ *
+ * @author Jean-Frederic Clere
+ * @version $Id: SocketServerTestSuite.java 1442587 2013-02-05 13:49:48Z rjung $
+ * @see org.apache.tomcat.jni
+ */
+public class SocketServerTestSuite extends TestCase {
+
+ private long serverSock = 0;
+ private int port=6666;
+ private String host="localhost";
+
+ public static long serverPool = 0;
+
+ public void testSocketServerTestSuite() throws Exception {
+
+ /* Load APR library */
+ Library.initialize(null);
+
+ /* Create the server socket and listen on it */
+ serverPool = Pool.create(0);
+ long inetAddress = Address.info(host, Socket.APR_INET,
+ port, 0, serverPool);
+ serverSock = Socket.create(Socket.APR_INET, Socket.SOCK_STREAM,
+ Socket.APR_PROTO_TCP, serverPool);
+ int rc = Socket.bind(serverSock, inetAddress);
+ if (rc != 0) {
+ Socket.close(serverSock);
+ throw(new Exception("Can't bind: " + Error.strerror(rc)));
+ }
+ Socket.listen(serverSock, 5);
+
+ /* Start the client that connects to the server */
+ Client client = new Client();
+ client.start();
+ java.lang.Thread.sleep(100);
+
+ /* Accept it */
+ long clientSock = Socket.accept(serverSock);
+
+ /* Try 2 milliseconds timeout */
+ Socket.timeoutSet(clientSock, 2000);
+ long timeout = Socket.timeoutGet(clientSock);
+ if (timeout != 2000) {
+ Socket.close(clientSock);
+ Socket.close(serverSock);
+ throw new Exception("Socket.timeoutGet clientSock failed");
+ }
+
+ long start = System.currentTimeMillis();
+ byte [] buf = new byte[1];
+ while (Socket.recv(clientSock, buf, 0, 1) == 1) {
+ }
+ long wait = System.currentTimeMillis() - start;
+ /* allow some margin between set timeout and observed return time */
+ if (wait < 1 || wait > 12) {
+ Socket.close(clientSock);
+ Socket.close(serverSock);
+ throw new Exception("2 milliseconds client Socket.timeoutSet failed");
+ }
+
+ /* Try 2 milliseconds timeout on accept socket */
+ Socket.timeoutSet(serverSock, 2000);
+ timeout = Socket.timeoutGet(serverSock);
+ if (timeout != 2000) {
+ Socket.close(serverSock);
+ throw new Exception("Socket.timeoutGet serverSock failed");
+ }
+
+ start = System.currentTimeMillis();
+ boolean ok = false;
+ try {
+ clientSock = Socket.accept(serverSock);
+ } catch (Exception ex) {
+ ok = true;
+ }
+ wait = System.currentTimeMillis() - start;
+ /* allow some margin between set timeout and observed return time */
+ if (wait < 1 || wait > 12 && ! ok) {
+ Socket.close(clientSock);
+ Socket.close(serverSock);
+ throw new Exception("2 milliseconds accept Socket.timeoutSet failed");
+ }
+
+ /* Try APR_SO_NONBLOCK */
+ Socket.optSet(serverSock, Socket.APR_SO_NONBLOCK, 1);
+ int val = Socket.optGet(serverSock, Socket.APR_SO_NONBLOCK);
+ if (val != 1) {
+ Socket.close(serverSock);
+ throw new Exception("Socket.optGet serverSock failed");
+ }
+
+ start = System.currentTimeMillis();
+ ok = false;
+ try {
+ clientSock = Socket.accept(serverSock);
+ } catch (Exception ex) {
+ ok = true;
+ }
+ wait = System.currentTimeMillis() - start;
+ if (wait > 1 && ! ok) {
+ Socket.close(clientSock);
+ Socket.close(serverSock);
+ throw new Exception("non_blocking accept Socket.APR_SO_NONBLOCK failed");
+ }
+ client.join();
+ Socket.close(clientSock);
+
+ /* Try the same on client socket */
+ client = new Client();
+ client.start();
+ java.lang.Thread.sleep(100);
+ clientSock = Socket.accept(serverSock);
+ Socket.optSet(clientSock, Socket.APR_SO_NONBLOCK, 1);
+ val = Socket.optGet(clientSock, Socket.APR_SO_NONBLOCK);
+ if (val != 1) {
+ Socket.close(clientSock);
+ Socket.close(serverSock);
+ throw new Exception("Socket.optGet clientSock failed");
+ }
+ start = System.currentTimeMillis();
+ while (Socket.recv(clientSock, buf, 0, 1) == 1) {
+ }
+ wait = System.currentTimeMillis() - start;
+ if (wait > 1) {
+ Socket.close(clientSock);
+ Socket.close(serverSock);
+ throw new Exception("non_blocking client Socket.APR_SO_NONBLOCK failed");
+ }
+
+ /* Now blocking */
+ Socket.optSet(clientSock, Socket.APR_SO_NONBLOCK, 0);
+ start = System.currentTimeMillis();
+ while (Socket.recv(clientSock, buf, 0, 1) == 1) {
+ }
+ wait = System.currentTimeMillis() - start;
+ if (wait < 1) {
+ Socket.close(clientSock);
+ Socket.close(serverSock);
+ throw new Exception("non_blocking client Socket.APR_SO_NONBLOCK false failed");
+ }
+
+ client.join();
+ Socket.close(clientSock);
+ Socket.close(serverSock);
+ Library.terminate();
+ }
+
+ /* small client that connects and sends one byte */
+ private class Client extends java.lang.Thread {
+ java.net.Socket sock;
+ public Client() throws Exception {
+ sock = new java.net.Socket(host, port);
+ }
+ public void run() {
+ try {
+ OutputStream ou = sock.getOutputStream();
+ ou.write('A');
+ ou.flush();
+ java.lang.Thread.sleep(10000);
+ sock.close();
+ } catch(Exception ex ) {
+ ex.printStackTrace();
+ }
+ }
+ }
+
+ public static void main(String[] args) {
+ TestRunner.run(suite());
+ }
+
+ public static Test suite()
+ {
+ TestSuite suite = new TestSuite( "Tomcat Native Server Socket" );
+ suite.addTest(new TestSuite(SocketServerTestSuite.class));
+ suite.addTest(new TestSuite(SocketServerTestBind.class));
+ return suite;
+ }
+}
diff --git a/jni/xdocs/build.xml b/jni/xdocs/build.xml
new file mode 100644
index 0000000..caebe8b
--- /dev/null
+++ b/jni/xdocs/build.xml
@@ -0,0 +1,137 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ 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.
+-->
+<project name="tomcat-docs" default="build-main" basedir=".">
+
+
+ <!-- ===================== Initialize Property Values =================== -->
+
+ <!-- See "build.properties.sample" in the top level directory for all -->
+ <!-- property values you must customize for successful building!!! -->
+ <property file="build.properties"/>
+ <property file="../build.properties"/>
+ <property file="../../build.properties"/>
+ <property file="${user.home}/build.properties"/>
+
+ <property name="build.compiler" value="modern"/>
+ <property name="build.dir" value="../build"/>
+ <property name="dist.dir" value="../dist"/>
+ <property name="dist.name" value="docs"/>
+
+
+ <!-- =================== BUILD: Create Directories ====================== -->
+ <target name="build-prepare">
+ <mkdir dir="${build.dir}"/>
+ <mkdir dir="${build.dir}/${dist.name}"/>
+ </target>
+
+
+ <!-- ================ BUILD: Copy Static Files ========================== -->
+ <target name="build-static" depends="build-prepare">
+
+ <!-- Top Level Static Files -->
+ <copy todir="${build.dir}/${dist.name}">
+ <fileset dir=".">
+ <include name="style.css"/>
+ </fileset>
+ </copy>
+ <copy todir="${build.dir}/${dist.name}">
+ <fileset dir="." includes="**/*.html"/>
+ </copy>
+
+ <!-- Images Subdirectory -->
+ <mkdir dir="${build.dir}/${dist.name}/images"/>
+ <copy todir="${build.dir}/${dist.name}/images">
+ <fileset dir="images"/>
+ </copy>
+
+ <!-- Miscellaneous Documentation -->
+ <xslt basedir="miscellaneous"
+ destdir="${build.dir}/${dist.name}/miscellaneous"
+ extension=".html"
+ style="style.xsl"
+ excludes="project.xml"
+ includes="*.xml">
+ <param name="relative-path" expression=".."/>
+ </xslt>
+
+ <!-- News -->
+ <xslt basedir="news"
+ destdir="${build.dir}/${dist.name}/news"
+ extension=".html"
+ style="style.xsl"
+ excludes="project.xml"
+ includes="*.xml">
+ <param name="relative-path" expression=".."/>
+ </xslt>
+
+ </target>
+
+
+ <!-- ================= BUILD: XML-HTML Generation ======================= -->
+ <target name="build-main" depends="build-static">
+
+ <!-- Top Level Directory -->
+ <xslt basedir="."
+ destdir="${build.dir}/${dist.name}"
+ extension=".html"
+ style="style.xsl"
+ excludes="build.xml project.xml empty.xml"
+ includes="*.xml">
+ <param name="relative-path" expression="."/>
+ </xslt>
+
+ </target>
+
+
+ <!-- ==================== BUILD: Rebuild Everything ===================== -->
+ <target name="all" depends="build-clean,build-main"
+ description="Clean and build documentation"/>
+
+
+ <!-- ======================= BUILD: Clean Directory ===================== -->
+ <target name="build-clean">
+ <delete dir="${build.dir}/${dist.name}"/>
+ </target>
+
+
+ <!-- ======================= DIST: Create Directories =================== -->
+ <target name="dist-prepare">
+ <mkdir dir="${dist.dir}"/>
+ </target>
+
+
+ <!-- ======================= DIST: Create Distribution Files ============ -->
+ <target name="dist" depends="build-main,dist-prepare"
+ description="Create documentation binary distribution">
+ <jar jarfile="${dist.dir}/${dist.name}.war"
+ basedir="${build.dir}/${dist.name}" includes="**"/>
+ </target>
+
+
+ <!-- ======================= DIST: Clean Directory ====================== -->
+ <target name="dist-clean">
+ <delete dir="${dist.dir}/${dist.name}"/>
+ </target>
+
+
+ <!-- ====================== Convenient Synonyms ========================= -->
+ <target name="clean" depends="build-clean,dist-clean"
+ description="Clean build and dist directories"/>
+
+
+</project>
diff --git a/jni/xdocs/images/add.gif b/jni/xdocs/images/add.gif
new file mode 100644
index 0000000..0774d07
Binary files /dev/null and b/jni/xdocs/images/add.gif differ
diff --git a/jni/xdocs/images/asf-feather.png b/jni/xdocs/images/asf-feather.png
new file mode 100644
index 0000000..7b596e6
Binary files /dev/null and b/jni/xdocs/images/asf-feather.png differ
diff --git a/jni/xdocs/images/code.gif b/jni/xdocs/images/code.gif
new file mode 100644
index 0000000..d27307b
Binary files /dev/null and b/jni/xdocs/images/code.gif differ
diff --git a/jni/xdocs/images/design.gif b/jni/xdocs/images/design.gif
new file mode 100644
index 0000000..f5db0a9
Binary files /dev/null and b/jni/xdocs/images/design.gif differ
diff --git a/jni/xdocs/images/docs-stylesheet.css b/jni/xdocs/images/docs-stylesheet.css
new file mode 100644
index 0000000..3269df5
--- /dev/null
+++ b/jni/xdocs/images/docs-stylesheet.css
@@ -0,0 +1,293 @@
+ at charset "utf-8";
+/*
+ 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.
+*/
+
+
+/* General style */
+
+body {
+ margin: 0;
+}
+
+body, input {
+ font-family: 'Lucida Sans Unicode', Arial, Helvetica, sans-serif;
+ font-size: 10.5pt;
+}
+
+code, pre {
+ font-family: Consolas, monospace;
+}
+
+img {
+ border: 0;
+}
+
+table {
+ border-collapse: collapse;
+ text-align: left;
+}
+table *:not(table) {
+ /* Prevent border-collapsing for table child elements like <div> */
+ border-collapse: separate;
+}
+
+main {
+ /* Remove this once all IEs support <main> element */
+ display: block;
+}
+
+
+/* Layout */
+
+#wrapper {
+ min-width: 400px;
+}
+
+#header {
+ border-bottom: 1px solid #bbb;
+}
+
+ at media not print {
+ #header {
+ box-shadow: 0 0 7px #aaa;
+ }
+}
+
+#header > div {
+ padding-left: 15px;
+ padding-right: 15px;
+
+ /* Work-around for old browsers: */
+ background-color: #F8F3E4;
+ background: linear-gradient(to bottom, #ffffff -10%, #F8F3E4 100%);
+ position: relative;
+}
+
+#header .logo {
+ float: left;
+ padding-top: 10px;
+ min-width: 190px;
+}
+
+#header .logo img{
+ /* To avoid that the Font Descender being added to the parent div's height */
+ vertical-align: middle;
+}
+
+#header .asfLogo {
+ float: right;
+ position: relative;
+ top: 8px;
+}
+
+#header h1 {
+ margin-top: 0.6em;
+ margin-bottom: 0;
+}
+
+#header .versionInfo {
+ font-size: 13pt;
+ margin-bottom: 1em;
+}
+
+#middle {
+ display: table;
+ table-layout: fixed;
+ margin: 0;
+ width: 100%;
+}
+#middle > div { display: table-row; }
+#middle > div > div { display: table-cell; vertical-align: top; }
+
+
+
+#mainLeft {
+ width: 190px;
+}
+
+#mainLeft > div {
+ margin-top: -1px; /* to overwrite border of element above */
+ padding-left: 16px;
+ padding-right: 14px;
+ padding-top: 6px;
+ padding-bottom: 15px;
+ background-color: #F8F3E4;
+ border-right: 1px solid #bbb;
+ border-bottom: 1px solid #bbb;
+ font-size: 10pt;
+ border-bottom-right-radius: 20px;
+ box-shadow: 0 0 5px #aaa;
+}
+
+#mainLeft h2 {
+ margin-bottom: 0.2em;
+ font-size: 1.2em;
+}
+
+#mainLeft ul {
+ padding: 0;
+ margin: 0;
+ list-style-type: none;
+}
+
+#mainLeft ul a {
+ text-indent: -0.6em;
+ padding-left: 1.4em;
+ display: block;
+ text-decoration: none;
+ color: #444;
+}
+#mainLeft ul a:hover {
+ color: #000;
+ background-color: #D1c9b9;
+}
+
+#mainRight {
+ padding-left: 14px;
+ padding-right: 20px;
+
+}
+
+#footer {
+ margin-top: 30px;
+ padding-top: 20px;
+ padding-bottom: 20px;
+ padding-left: 20px;
+ padding-right: 20px;
+ border-top: 1px solid #ccc;
+ color: #444;
+ text-align: center;
+ /* font-style: italic; */
+ font-size: 9pt;
+}
+
+
+/* Content */
+
+#content div.text {
+ padding-left: 1em;
+ padding-left: 1em;
+}
+
+#content h3, #content h4, #content h5, #content h6 {
+ padding-left: 5px;
+ padding-right: 5px;
+ background-color: #eaeaea;
+}
+
+ at media not print {
+ #content h3, #content h4, #content h5, #content h6 {
+ border: 1px solid #ccc;
+ border-radius: 4px;
+ }
+}
+
+#content h4, #content h5, #content h6 {
+ background-color: #f6f6f6;
+}
+
+code {
+ background-color: rgb(224,255,255);
+}
+
+div.codeBox pre code, code.attributeName, code.propertyName, code.noHighlight, .noHighlight code {
+ background-color: transparent;
+}
+div.codeBox {
+ overflow: auto;
+ margin: 1em 0;
+}
+div.codeBox pre {
+ margin: 0;
+ padding: 4px;
+ border: 1px solid #999;
+ border-radius: 5px;
+ background-color: #eff8ff;
+ display: table; /* To prevent <pre>s from taking the complete available width. */
+ /*
+ When it is officially supported, use the following CSS instead of display: table
+ to prevent big <pre>s from exceeding the browser window:
+ max-width: available;
+ width: min-content;
+ */
+}
+
+div.codeBox pre.wrap {
+ white-space: pre-wrap;
+}
+
+
+table.defaultTable tr, table.detail-table tr {
+ border: 1px solid #CCC;
+}
+
+table.defaultTable tr:nth-child(even), table.detail-table tr:nth-child(even) {
+ background-color: #FAFBFF;
+}
+
+table.defaultTable tr:nth-child(odd), table.detail-table tr:nth-child(odd) {
+ background-color: #EEEFFF;
+}
+
+table.defaultTable th, table.detail-table th {
+ background-color: #88b;
+ color: #fff;
+}
+
+table.defaultTable th, table.defaultTable td, table.detail-table th, table.detail-table td {
+ padding: 5px 8px;
+}
+
+
+p.notice {
+ border: 1px solid rgb(255, 0, 0);
+ background-color: rgb(238, 238, 238);
+ color: rgb(0, 51, 102);
+ padding: 0.5em;
+ margin: 1em 2em 1em 1em;
+}
+
+
+/* Changelog-Styles */
+
+ul.changelog {
+ padding-left: 1em;
+ list-style-type: none;
+}
+
+ul.changelog li{
+ padding-top: 5px;
+ padding-bottom: 5px;
+}
+
+ul.changelog img {
+ vertical-align: middle
+}
+
+
+/* Printer-only Styles */
+ at media print {
+ .noPrint { display: none; }
+ #middle > div > div#mainLeft { display: none; }
+ a { color: inherit; text-decoration: none; }
+}
+
+/* Fix for Comments section which contains a <h4> */
+#comments_thread h1, #comments_thread h2, #comments_thread h3, #comments_thread h4, #comments_thread h5, #comments_thread h6 {
+ border: none;
+ background-color: transparent;
+}
\ No newline at end of file
diff --git a/jni/xdocs/images/docs.gif b/jni/xdocs/images/docs.gif
new file mode 100644
index 0000000..d64a4a1
Binary files /dev/null and b/jni/xdocs/images/docs.gif differ
diff --git a/jni/xdocs/images/fix.gif b/jni/xdocs/images/fix.gif
new file mode 100644
index 0000000..d59ad64
Binary files /dev/null and b/jni/xdocs/images/fix.gif differ
diff --git a/jni/xdocs/images/printer.gif b/jni/xdocs/images/printer.gif
new file mode 100644
index 0000000..5021187
Binary files /dev/null and b/jni/xdocs/images/printer.gif differ
diff --git a/jni/xdocs/images/style.css b/jni/xdocs/images/style.css
new file mode 100644
index 0000000..89c3066
--- /dev/null
+++ b/jni/xdocs/images/style.css
@@ -0,0 +1,23 @@
+/*
+ * 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.
+ */
+
+p.todo {
+ margin-left: 20px;
+ margin-right: 10px;
+ text-align: justify;
+ font-size: smaller;
+}
diff --git a/jni/xdocs/images/tomcat.gif b/jni/xdocs/images/tomcat.gif
new file mode 100644
index 0000000..f2aa6f8
Binary files /dev/null and b/jni/xdocs/images/tomcat.gif differ
diff --git a/jni/xdocs/images/tomcat.png b/jni/xdocs/images/tomcat.png
new file mode 100644
index 0000000..f40a9de
Binary files /dev/null and b/jni/xdocs/images/tomcat.png differ
diff --git a/jni/xdocs/images/update.gif b/jni/xdocs/images/update.gif
new file mode 100644
index 0000000..31e22ab
Binary files /dev/null and b/jni/xdocs/images/update.gif differ
diff --git a/jni/xdocs/images/void.gif b/jni/xdocs/images/void.gif
new file mode 100644
index 0000000..e565824
Binary files /dev/null and b/jni/xdocs/images/void.gif differ
diff --git a/jni/xdocs/index.xml b/jni/xdocs/index.xml
new file mode 100644
index 0000000..5d7bbca
--- /dev/null
+++ b/jni/xdocs/index.xml
@@ -0,0 +1,231 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ 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.
+-->
+<!DOCTYPE document [
+ <!ENTITY project SYSTEM "project.xml">
+]>
+<document url="index.html">
+
+ &project;
+
+ <properties>
+ <author email="jfclere at apache.org">Jean-Frederic Clere</author>
+ <title>Documentation Index</title>
+ </properties>
+
+<body>
+
+<section name="Introduction">
+
+ <p>
+ The Apache Tomcat Native Library is an optional component for use with
+ Apache Tomcat that allows Tomcat to use certain native resources
+ for performance, compatibility, etc.
+ </p>
+
+ <p>
+ Specifically, the Apache Tomcat Native Library gives Tomcat access to
+ the Apache Portable Runtime (APR) library's network connection (socket)
+ implementation and random-number generator.
+ See the Apache Tomcat documentation for more information on how to
+ configure Tomcat to use the APR connector.
+ </p>
+
+ <p>
+ Features of the APR connector:
+ </p>
+ <ul>
+ <li>Non-blocking I/O for Keep-Alive requests (between requests)</li>
+ <li>Uses OpenSSL for TLS/SSL capabilities (if supported by linked APR library)</li>
+ <li>FIPS 140-2 support for TLS/SSL (if supported by linked OpenSSL library)</li>
+ </ul>
+
+
+<p>Select one of the links from the navigation menu (to the left) to drill
+down to the more detailed documentation that is available. Each available
+manual is described in more detail below.</p>
+
+</section>
+
+<section name="Headlines">
+<ul>
+
+<li><a href="news/2013.html#20131015.1">15 October 2013 - <b>TC-Native-1.1.29 released</b></a>
+<p>The Apache Tomcat team is proud to announce the immediate availability of Tomcat Native 1.1.29 Stable.
+</p>
+<p>
+ The sources and the binaries for selected platforms are available from the
+ <a href="../download-native.cgi">Download page</a>.
+</p>
+<p>
+ Please see the <a href="miscellaneous/changelog.html">ChangeLog</a> for a full list of changes.
+</p>
+</li>
+</ul>
+</section>
+
+<section name="Building">
+<subsection name="Requirements">
+ <p>
+ Build tc-native requires three components to be installed:
+ </p>
+ <ul>
+ <li>APR library</li>
+ <li>OpenSSL libraries</li>
+ <li>Java SE Development Kit (JDK)</li>
+ </ul>
+
+ <p>
+ In debian based Linux those dependencies could be installed by something like:
+ </p>
+ <source>apt-get install libapr1.0-dev libssl-dev</source>
+ <p>
+ In rpm based Linux those dependencies could be installed by something like:
+ </p>
+ <source>yum install apr-devel openssl-devel</source>
+</subsection>
+
+<subsection name="UNIX">
+ <p>
+ On all the POSIX systems (Linux, Solaris, HP-UX, AIX etc...) a well-known
+ configure and make is used to build tc-native.<br/>
+ In the jni/native runs:
+ </p>
+ <source>./configure --help</source>
+ <p>to read the description of all the parameters.</p>
+ <source
+>./configure --with-apr=$HOME/APR \
+ --with-java-home=$JAVA_HOME \
+ --with-ssl=$HOME/OPENSSL \
+ --prefix=$CATALINA_HOME</source>
+ <p>
+ to create the includes and makefiles to be able to build tc-native.<br/>
+ Where:<br/>
+ <code>$HOME/APR</code> is something like /usr/bin/apr-1-config or the path where apr is
+ installed.<br/>
+ <code>$JAVA_HOME</code> is something /home/jfclere/JAVA/jdk1.5.0_09 path to a JDK
+ installation. Any JDK should work but it is advisable to use the same
+ JVM version the JVM you use with Tomcat.<br/>
+ <code>$HOME/OPENSSL</code> is the path where OpenSSL is installed.<br/>
+ <code>$CATALINA_HOME</code> is the path where the produced libraries will be
+ installed. Something like $HOME/apache-tomcat-6.0.16/<br/>
+ <br/>
+ The configure is able to guess most of OpenSSL standard installations.
+ So most of the time the following will be enough:
+ </p>
+ <source
+>./configure --with-apr=/usr/bin/apr-1-config \
+ --with-java-home=/home/jfclere/JAVA/jdk1.5.0_09/ \
+ --with-ssl=yes \
+ --prefix=$CATALINA_HOME</source>
+ <p>
+ To build the libraries and install them:
+ </p>
+ <source>make && make install</source>
+ <p>
+ The libraries will be found in $CATALINA_HOME/lib
+ </p>
+</subsection>
+
+<subsection name="Windows">
+ <p>
+ Download the windows sources of tc-native and extract them.
+ </p>
+ <p>
+ Download OpenSSL sources (See <a href="http://www.openssl.org/related/binaries.html"><b>Binary Distributions</b></a>)
+ OpenSSL is a crypto software so check if you are allowed to download it. If not you can still use tc-native without SSL.
+ </p>
+ <p>
+ Download APR sources for Windows. (See <a href="http://apr.apache.org/download.cgi"><b>Download</b></a>)
+ Extract them in jni and rename the apr-1.x.y directory to apr.
+ </p>
+ <p>
+ Use MS Visual Studio to open the workspace of the APR sources and build the library (libapr).
+ </p>
+ <p>
+ Use MS Visual Studio to open the workspace of the tc-native sources, adjust the OpenSSL includes and libraries location
+ change the name of the libraries libeay32 and libssleay to libeay32MT and libssleayMT and build the tcn-native library.
+ That should create a tcnative-1.dll.
+ </p>
+</subsection>
+
+</section>
+
+<section name="Install and tests">
+ <subsection name="Configuring Tomcat">
+ <p>
+ Apache Tomcat comes with the <code>AprLifecycleListener</code> enabled
+ by default. Still, you should check your <code>conf/server.xml</code>
+ to ensure that something like the following is present, and uncommented:
+ </p>
+
+ <source wrapped="true"
+ ><![CDATA[<Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="on" />]]></source>
+ <p>
+ Please see the Apache Tomcat documentation for configuration specifics.
+ </p>
+ </subsection>
+
+<subsection name="UNIX">
+ <p>
+ Edit $CATALINA_HOME/bin/setenv.sh (creating the file if necessary) and add
+ the path to the tc-native libraries to LD_LIBRARY_PATH. Something like:
+ </p>
+ <source>LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$CATALINA_HOME/lib
+export LD_LIBRARY_PATH</source>
+ <p>
+ Start tomcat and check for the messages like this ones:
+ </p>
+ <source wrapped="true"
+>Feb 8, 2008 12:27:41 PM org.apache.catalina.core.AprLifecycleListener init
+INFO: Loaded APR based Apache Tomcat Native library 1.x.y.
+Feb 8, 2008 12:27:41 PM org.apache.catalina.core.AprLifecycleListener init
+INFO: APR capabilities: IPv6 [true], sendfile [true], accept filters [false], random [true].
+Feb 8, 2008 12:27:41 PM org.apache.coyote.http11.Http11AprProtocol init
+INFO: Initializing Coyote HTTP/1.1 on http-8080</source>
+ <p>
+ Refer to the tomcat documentation to configure the connectors
+ (See <a href="http://tomcat.apache.org/tomcat-6.0-doc/apr.html">Tomcat6.0.x</a>
+ and <a href="http://tomcat.apache.org/tomcat-5.5-doc/apr.html">Tomcat5.5.x</a>)
+ </p>
+</subsection>
+
+<subsection name="Windows">
+ <p>
+ Edit $CATALINA_BASE\bin\setenv.bat (creating the file if necessary) and add
+ the path to the tc-native libraries, apr and OpenSSL to PATH. For example:
+ </p>
+
+ <source wrapped="true"
+ >set PATH=%PATH;C:\cygwin\home\support\tomcat-native-current-win32-src\jni\native\Debug;C:\cygwin\home\support\tomcat-native-current-win32-src\jni\apr\Debug;C:\OpenSSL\lib\VC</source>
+ <p>
+ Start tomcat and check for the messages like this ones:
+ </p>
+ <source wrapped="true"
+>Feb 8, 2008 2:48:17 PM org.apache.catalina.core.AprLifecycleListener init
+INFO: Loaded APR based Apache Tomcat Native library 1.x.y.
+Feb 8, 2008 2:48:17 PM org.apache.catalina.core.AprLifecycleListener init
+INFO: APR capabilities: IPv6 [false], sendfile [true], accept filters [false], random [true].
+Feb 8, 2008 2:48:18 PM org.apache.coyote.http11.Http11AprProtocol init
+INFO: Initializing Coyote HTTP/1.1 on http-8080</source>
+
+</subsection>
+
+</section>
+
+</body>
+</document>
diff --git a/jni/xdocs/miscellaneous/changelog.xml b/jni/xdocs/miscellaneous/changelog.xml
new file mode 100644
index 0000000..0b5e0c4
--- /dev/null
+++ b/jni/xdocs/miscellaneous/changelog.xml
@@ -0,0 +1,339 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ 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.
+-->
+<!DOCTYPE document [
+ <!ENTITY project SYSTEM "project.xml">
+]>
+<document url="changelog.html">
+
+ &project;
+
+ <properties>
+ <author email="jfclere at apache.org">Jean-Frederic Clere</author>
+ </properties>
+
+<body>
+
+<section name="Preface">
+ <p>
+ This is the Changelog for Tomcat Native. This changelog
+ does not contain all updates and fixes to the Tomcat Native (yet).
+ It should contain fixes made only after December 19th 2007, when the
+ new documentation project for Tomcat Native was started.
+ </p>
+</section>
+<section name="Changes between 1.1.29 and 1.1.30">
+ <changelog>
+ <fix>
+ <bug>56363</bug>: Use OpenSSL 1.0.1g with Windows binaries. (mturk)
+ </fix>
+ <fix>
+ <bug>55915</bug>: Apply Mike Noordermeer's patch for ECDHE support. (mturk)
+ </fix>
+ <fix>
+ <bug>55663</bug>: Minor correction to the wording of the NOTICE file
+ to align it with the <a
+ href="http://www.apache.org/legal/src-headers.html#notice">requirements
+ for NOTICE files</a>. (kkolinko)
+ </fix>
+ <fix>
+ <bug>56027</bug>: Partial fix includes new <code>fipsModeGet</code>
+ function to get the current state of OpenSSL FIPS mode.
+ </fix>
+ </changelog>
+</section>
+<section name="Changes between 1.1.28 and 1.1.29">
+ <changelog>
+ <fix>
+ Change return code when removing a socket from a poller, that was
+ actually not in the poller from APR_SUCCESS to APR_NOTFOUND. (rjung)
+ </fix>
+ </changelog>
+</section>
+<section name="Changes between 1.1.27 and 1.1.28">
+ <changelog>
+ <update>
+ Java classes in package org.apache.tomcat.jni are now taken
+ from Tomcat trunk using svn:externals. (rjung)
+ </update>
+ <update>
+ Minimum supported APR version is now again 1.2.1. Version 1.3.0
+ of APR improves performance. (rjung)
+ </update>
+ <fix>
+ <bug>29422</bug>: Fixed double-free in <code>ssl_ocsp_request</code>.
+ Patch provided by Aristotelis. (schultz)
+ </fix>
+ <fix>
+ <bug>51655</bug>: Added a decent description of what tcnative actually is.
+ (schultz)
+ </fix>
+ <fix>
+ <bug>51813</bug>: Add NULL-checking for <code>s->net</code> to
+ avoid SIGSEGV in situations where it appears a socket has been recycled.
+ (schultz)
+ </fix>
+ </changelog>
+</section>
+<section name="Changes between 1.1.26 and 1.1.27">
+ <changelog>
+ <fix>
+ <bug>54513</bug>: Fix regression in pollset return value. (mturk)
+ </fix>
+ <fix>
+ Switch CPU information on Solaris from milliseconds to
+ microseconds. Make consistent with OS.java and Linux impl. (rjung)
+ </fix>
+ </changelog>
+</section>
+<section name="Changes between 1.1.25 and 1.1.26 (not released)">
+ <changelog>
+ <fix>
+ <bug>54468</bug>: Fix FIPS mode for listeners when using OpenSSL 1.0.1c
+ and later; resolves 'Low level API call to digest MD5 forbidden in FIPS
+ mode!' errors. (wrowe)
+ </fix>
+ <update>
+ Add clearOptions function to allow access to OpenSSL's
+ SSL_CTX_clear_options function. (schultz)
+ </update>
+ </changelog>
+</section>
+<section name="Changes between 1.1.24 and 1.1.25 (not released)">
+ <changelog>
+ <update>
+ Minimum supported APR version is now 1.3.0. (mturk)
+ </update>
+ <fix>
+ <bug>52856</bug>: Fix high CPU usage when client changes IP address or
+ has high latency. (mturk)
+ </fix>
+ <update>
+ Add CPU information to OS info for Linux.
+ This was already available under Windows and Solaris. (rjung)
+ </update>
+ <fix>
+ <bug>53969</bug>: ssl.c::hasOp could only check for
+ SSL_OP_ALLOW_UNSAFE_LEGACY_RENEGOTIATION. Now it can check
+ for any SSL_OP_* available at compile-time. (schultz)
+ </fix>
+ </changelog>
+</section>
+<section name="Changes between 1.1.23 and 1.1.24">
+ <changelog>
+ <update>
+ Add support for per-socket timeouts inside poller. (markt, mturk)
+ </update>
+ </changelog>
+</section>
+<section name="Changes between 1.1.22 and 1.1.23">
+ <changelog>
+ <update>
+ <bug>45392</bug>: Add support for OCSP verification. Based upon a patch
+ from Aristotelis. (mturk)
+ </update>
+ <fix>
+ <bug>52119</bug>: Autodetect Diablo JDK on FreeBSD and Java7+. Based upon a patch
+ from Michael Osipov. (mturk)
+ </fix>
+ <fix>
+ <bug>52717</bug>: Set scope_id for IPv6 addresses if provided. (mturk)
+ </fix>
+ <update>
+ <bug>50570</bug>: Allow explicit use of FIPS mode in APR lifecycle
+ listener (native support only in this update; Java support to follow).
+ Based upon a patch from Chris Beckey. (schultz)
+ </update>
+ </changelog>
+</section>
+<section name="Changes between 1.1.21 and 1.1.22">
+ <changelog>
+ <fix>
+ Arrange release packaging script. (jfclere).
+ </fix>
+ <fix>
+ Fix typos in the changelog. (markt).
+ </fix>
+ </changelog>
+</section>
+<section name="Changes between 1.1.20 and 1.1.21 (not released)">
+ <changelog>
+ <fix>
+ <bug>50394</bug>: InternalAprInputBuffer.fill() doesn't deal correctly with EOF. (jfclere)
+ </fix>
+ <fix>
+ Support arbitrary protocol combinations of SSLv2, SSLv3 and TLSv1. (rjung)
+ </fix>
+ <fix>
+ <bug>51437</bug>: Try loading certificate in DER format if PEM was invalid. (mturk)
+ </fix>
+ <fix>
+ <bug>49557</bug>: index error in the loop to get the env info in the proc.create function. (kkolinko, jfclere)
+ </fix>
+ <fix>
+ <bug>49851</bug>: JNI Registry.deleteKey and Registry.deleteValue corrupt Windows registry. (jfclere)
+ </fix>
+ <fix>
+ <bug>48253</bug>: adding dynamic locking callbacks for openssl engines. (jfclere)
+ </fix>
+ <update>
+ Make the non blocking write really no blocking. (jfclere)
+ </update>
+ <update>
+ Add support for unsafe legacy renegotiation. (mturk)
+ </update>
+ </changelog>
+</section>
+<section name="Changes between 1.1.19 and 1.1.20">
+ <changelog>
+ <fix>
+ <bug>48584</bug>: Prevent crashing JVM on shutdown. (mturk)
+ </fix>
+ </changelog>
+</section>
+<section name="Changes between 1.1.18 and 1.1.19">
+ <changelog>
+ <fix>
+ Update windows resource files to correct version. (mturk)
+ </fix>
+ <fix>
+ <bug>48129</bug>: Fix build with OpenSSL 1.0.0-beta3.
+ Patch provided by Tomas Mraz. (mturk, rjung)
+ </fix>
+ <update>
+ Add detection of the Mac OS X JVM. (rjung)
+ </update>
+ </changelog>
+</section>
+<section name="Changes between 1.1.17 and 1.1.18">
+ <changelog>
+ <fix>
+ Fix CVE-2009-3555 SSL-Man-In-The-Middle attack. (mturk)
+ </fix>
+ </changelog>
+</section>
+<section name="Changes between 1.1.16 and 1.1.17">
+ <changelog>
+ <update>
+ Arrange build after svn reorganisation (rjung)
+ </update>
+ <fix>
+ <bug>47852</bug>: Fix some Javadoc errors. Patch provided by Sebb. (rjung)
+ </fix>
+ <fix>
+ <bug>46950</bug>: Fix SSL renegotiation in combination with client
+ certificates. The complete solution also needs a fix in Tomcat's Java code. (markt)
+ </fix>
+ <fix>
+ Align method names and signatures of native C code and java code. (markt, rjung)
+ </fix>
+ <fix>
+ <bug>42728</bug>: Remove memory leak. (markt)
+ </fix>
+ <fix>
+ <bug>46457</bug>: Fix use of multicast. (markt)
+ </fix>
+ <fix>
+ Fix API name for recvfrom (mturk)
+ </fix>
+ <fix>
+ Allow building against APR 1.3 (mturk)
+ </fix>
+ <fix>
+ Improve fix for <bug>43327</bug> with better handling for IPv6
+ addresses (markt)
+ </fix>
+ </changelog>
+</section>
+
+<section name="Changes between 1.1.15 and 1.1.16">
+ <changelog>
+ <fix>
+ Fix API name for recvfrom (mturk)
+ </fix>
+ <fix>
+ Allow building against APR 1.3 (mturk)
+ </fix>
+ <fix>
+ Improve fix for <bug>43327</bug> with better handling for IPv6
+ addresses (markt)
+ </fix>
+ </changelog>
+</section>
+
+<section name="Changes between 1.1.14 and 1.1.15">
+ <changelog>
+ <fix>
+ <bug>43327</bug>: Socket bind fail because mixing IPv4/IPv6 (markt, jfclere)
+ </fix>
+ <fix>
+ <bug>44864</bug>: Use additional check for SSL verify like
+ with mod_ssl for SSLVerifyClient=optionalNoCA. (mturk)
+ </fix>
+ </changelog>
+</section>
+
+<section name="Changes between 1.1.13 and 1.1.14">
+ <changelog>
+ <fix>
+ <bug>45071</bug>: Reset ttl when Poll.pool remove is false.
+ Additional patch was provided by Alex Barclay. (mturk)
+ </fix>
+ <fix>
+ Fix optGet that was always throwing exceptions. (jfclere)
+ </fix>
+ <fix>
+ Fix optSet don't throw exception as JAVA prototype doesn't. (jfclere)
+ </fix>
+ </changelog>
+</section>
+<section name="Changes between 1.1.12 and 1.1.13">
+ <changelog>
+ <fix>
+ IFS problem in native/build/tcnative.m4 (rjung)
+ </fix>
+ <fix>
+ Wrong gcc link flag in native/build/tcnative.m4 (rjung)
+ </fix>
+ </changelog>
+</section>
+<section name="Changes between 1.1.11 and 1.1.12">
+ <changelog>
+ <update>
+ Add support of J9VM based JVM. (jfclere)
+ </update>
+ <update>
+ Arrange licence in source files. (markt)
+ </update>
+ <update>
+ Add two new 'immediate' methods for sending the data.
+ It is the responsibility of the Java callee to deal with
+ the returned values and retry if the error was non-fatal. (mturk)
+ </update>
+ <fix>
+ Arrange the check of openssl version. It was failing on Linux. (jfclere)
+ </fix>
+ <fix>
+ Prevent returning APR_SUCCESS when there is something wrong in ssl layer. (jfclere)
+ </fix>
+ <fix>
+ <bug>44087</bug>: Fix it. (jfclere)
+ </fix>
+ </changelog>
+</section>
+</body>
+</document>
diff --git a/jni/xdocs/miscellaneous/project.xml b/jni/xdocs/miscellaneous/project.xml
new file mode 100644
index 0000000..d8ab94a
--- /dev/null
+++ b/jni/xdocs/miscellaneous/project.xml
@@ -0,0 +1,47 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ 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.
+-->
+<project name="Apache Tomcat Native Documentation - Miscellaneous Documentation"
+ href="http://tomcat.apache.org/">
+
+ <title>The Apache Tomcat Native - Miscellaneous Documentation</title>
+
+ <logo href="/images/tomcat.gif">
+ The Apache Tomcat Native - Miscellaneous Documentation
+ </logo>
+<body>
+
+ <menu name="Links">
+ <item name="Docs Home" href="../index.html"/>
+ </menu>
+
+ <menu name="Miscellaneous Documentation">
+ <item name="Changelog" href="../miscellaneous/changelog.html"/>
+ </menu>
+
+ <menu name="News">
+ <item name="2014" href="../news/2014.html"/>
+ <item name="2013" href="../news/2013.html"/>
+ <item name="2012" href="../news/2012.html"/>
+ <item name="2011" href="../news/2011.html"/>
+ <item name="2010" href="../news/2010.html"/>
+ <item name="2009" href="../news/2009.html"/>
+ <item name="2008" href="../news/2008.html"/>
+ </menu>
+
+</body>
+</project>
diff --git a/jni/xdocs/news/2008.xml b/jni/xdocs/news/2008.xml
new file mode 100644
index 0000000..554b5fb
--- /dev/null
+++ b/jni/xdocs/news/2008.xml
@@ -0,0 +1,58 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ 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.
+-->
+<!DOCTYPE document [
+ <!ENTITY project SYSTEM "project.xml">
+]>
+<document url="2008.html">
+
+ &project;
+
+ <properties>
+ <author email="general.AT.tomcat.DOT.apache.DOT.org">Apache Tomcat Native Project</author>
+ <title>2008 News and Status</title>
+ </properties>
+
+<body>
+
+<section name="2008 News & Status">
+<subsection anchor="20081118.1" name="18 November - TC-Native-1.1.16 released">
+<p>The Apache Tomcat team is proud to announce the immediate availability
+of Tomcat Native 1.1.16. This is a stable release adding some bug fixes.
+</p>
+</subsection>
+<subsection anchor="20080911.1" name="11 September - TC-Native-1.1.15 released">
+<p>The Apache Tomcat team is proud to announce the immediate availability
+of Tomcat Native 1.1.15. This is a stable release adding some bug fixes.
+</p>
+</subsection>
+<subsection anchor="20080704.1" name="4 July - TC-Native-1.1.14 released">
+<p>The Apache Tomcat team is proud to announce the immediate availability
+of Tomcat Native 1.1.14. This is a stable release adding some bug fixes.
+</p>
+</subsection>
+<subsection anchor="20080115.1" name="15 February - TC-Native-1.1.13 released">
+<p>The Apache Tomcat team is proud to announce the immediate availability
+of Tomcat Native 1.1.13. This is a stable release adding few new features
+and some bug fixes.
+</p><p>
+ Please see the <a href="../miscellaneous/changelog.html">ChangeLog</a> for a full list of changes.
+</p>
+</subsection>
+</section>
+</body>
+</document>
diff --git a/jni/xdocs/news/2009.xml b/jni/xdocs/news/2009.xml
new file mode 100644
index 0000000..bb96f9f
--- /dev/null
+++ b/jni/xdocs/news/2009.xml
@@ -0,0 +1,42 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ 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.
+-->
+<!DOCTYPE document [
+ <!ENTITY project SYSTEM "project.xml">
+]>
+<document url="2009.html">
+
+ &project;
+
+ <properties>
+ <author email="general.AT.tomcat.DOT.apache.DOT.org">Apache Tomcat Native Project</author>
+ <title>2009 News and Status</title>
+ </properties>
+
+<body>
+
+<section name="2009 News & Status">
+<subsection anchor="20091123.1" name="23 November - TC-Native-1.1.18 released">
+<p>The Apache Tomcat team is proud to announce the immediate availability
+of Tomcat Native 1.1.18. This is a stable release adding some bug fixes.
+</p><p>
+ Please see the <a href="../miscellaneous/changelog.html">ChangeLog</a> for a full list of changes.
+</p>
+</subsection>
+</section>
+</body>
+</document>
diff --git a/jni/xdocs/news/2010.xml b/jni/xdocs/news/2010.xml
new file mode 100644
index 0000000..ad202d5
--- /dev/null
+++ b/jni/xdocs/news/2010.xml
@@ -0,0 +1,47 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ 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.
+-->
+<!DOCTYPE document [
+ <!ENTITY project SYSTEM "project.xml">
+]>
+<document url="2010.html">
+
+ &project;
+
+ <properties>
+ <author email="general.AT.tomcat.DOT.apache.DOT.org">Apache Tomcat Native Project</author>
+ <title>2010 News and Status</title>
+ </properties>
+
+<body>
+
+<section name="2010 News & Status">
+<subsection anchor="20100217.1" name="17 February - TC-Native-1.1.20 released">
+<p>The Apache Tomcat team is proud to announce the immediate availability
+of Tomcat Native 1.1.20. This is a stable release adding some bug fixes.
+</p>
+</subsection>
+<subsection anchor="20100108.1" name="8 January - TC-Native-1.1.19 released">
+<p>The Apache Tomcat team is proud to announce the immediate availability
+of Tomcat Native 1.1.19. This is a stable release adding some bug fixes.
+</p><p>
+ Please see the <a href="../miscellaneous/changelog.html">ChangeLog</a> for a full list of changes.
+</p>
+</subsection>
+</section>
+</body>
+</document>
diff --git a/jni/xdocs/news/2011.xml b/jni/xdocs/news/2011.xml
new file mode 100644
index 0000000..6b2ede0
--- /dev/null
+++ b/jni/xdocs/news/2011.xml
@@ -0,0 +1,43 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ 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.
+-->
+<!DOCTYPE document [
+ <!ENTITY project SYSTEM "project.xml">
+]>
+<document url="2011.html">
+
+ &project;
+
+ <properties>
+ <author email="general.AT.tomcat.DOT.apache.DOT.org">Apache Tomcat Native Project</author>
+ <title>2011 News and Status</title>
+ </properties>
+
+<body>
+
+<section name="2011 News & Status">
+<subsection anchor="20110808.1" name="08 August - TC-Native-1.1.22 released">
+<p>The Apache Tomcat team is proud to announce the immediate availability
+of Tomcat Native 1.1.22. This is a stable release adding some bug fixes.
+</p>
+<p>
+ Please see the <a href="../miscellaneous/changelog.html">ChangeLog</a> for a full list of changes.
+</p>
+</subsection>
+</section>
+</body>
+</document>
diff --git a/jni/xdocs/news/2012.xml b/jni/xdocs/news/2012.xml
new file mode 100644
index 0000000..a23d374
--- /dev/null
+++ b/jni/xdocs/news/2012.xml
@@ -0,0 +1,53 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ 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.
+-->
+<!DOCTYPE document [
+ <!ENTITY project SYSTEM "project.xml">
+]>
+<document url="2012.html">
+
+ &project;
+
+ <properties>
+ <author email="general.AT.tomcat.DOT.apache.DOT.org">Apache Tomcat Native Project</author>
+ <title>2012 News and Status</title>
+ </properties>
+
+<body>
+
+<section name="2012 News & Status">
+<subsection anchor="20120613.1" name="13 June - TC-Native-1.1.24 released">
+<p>The Apache Tomcat team is proud to announce the immediate availability
+of Tomcat Native 1.1.24. This is a feature-add release adding support for
+per-socket Poller timeouts.
+</p>
+<p>
+ Please see the <a href="../miscellaneous/changelog.html">ChangeLog</a> for a full list of changes.
+</p>
+</subsection>
+<subsection anchor="20120302.1" name="02 March - TC-Native-1.1.23 released">
+<p>The Apache Tomcat team is proud to announce the immediate availability
+of Tomcat Native 1.1.23. This is a stable release adding some bug fixes and
+experimental support for OCSP and PKCS12 certificates.
+</p>
+<p>
+ Please see the <a href="../miscellaneous/changelog.html">ChangeLog</a> for a full list of changes.
+</p>
+</subsection>
+</section>
+</body>
+</document>
diff --git a/jni/xdocs/news/2013.xml b/jni/xdocs/news/2013.xml
new file mode 100644
index 0000000..875fdd5
--- /dev/null
+++ b/jni/xdocs/news/2013.xml
@@ -0,0 +1,56 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ 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.
+-->
+<!DOCTYPE document [
+ <!ENTITY project SYSTEM "project.xml">
+]>
+<document url="2013.html">
+
+ &project;
+
+ <properties>
+ <author email="general.AT.tomcat.DOT.apache.DOT.org">Apache Tomcat Native Project</author>
+ <title>2013 News and Status</title>
+ </properties>
+
+<body>
+
+<section name="2013 News & Status">
+<subsection anchor="20131015.1" name="15 October - TC-Native-1.1.29 released">
+<p>The Apache Tomcat team is proud to announce the immediate availability
+of Tomcat Native 1.1.29. This is a bug fixing release.
+</p>
+</subsection>
+<subsection anchor="20130916.1" name="16 September - TC-Native-1.1.28 released">
+<p>The Apache Tomcat team is proud to announce the immediate availability
+of Tomcat Native 1.1.28. This is a bug fixing release.
+</p>
+<p>
+ Please see the <a href="../miscellaneous/changelog.html">ChangeLog</a> for a full list of changes.
+</p>
+</subsection>
+<subsection anchor="20130212.1" name="12 February - TC-Native-1.1.27 released">
+<p>The Apache Tomcat team is proud to announce the immediate availability
+of Tomcat Native 1.1.27. This is a bug fixing release.
+</p>
+<p>
+ Please see the <a href="../miscellaneous/changelog.html">ChangeLog</a> for a full list of changes.
+</p>
+</subsection>
+</section>
+</body>
+</document>
diff --git a/jni/xdocs/news/2014.xml b/jni/xdocs/news/2014.xml
new file mode 100644
index 0000000..c387cce
--- /dev/null
+++ b/jni/xdocs/news/2014.xml
@@ -0,0 +1,35 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ 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.
+-->
+<!DOCTYPE document [
+ <!ENTITY project SYSTEM "project.xml">
+]>
+<document url="2014.html">
+
+ &project;
+
+ <properties>
+ <author email="general.AT.tomcat.DOT.apache.DOT.org">Apache Tomcat Native Project</author>
+ <title>2013 News and Status</title>
+ </properties>
+
+<body>
+
+<section name="2014 News & Status">
+</section>
+</body>
+</document>
diff --git a/jni/xdocs/news/project.xml b/jni/xdocs/news/project.xml
new file mode 100644
index 0000000..3e303c1
--- /dev/null
+++ b/jni/xdocs/news/project.xml
@@ -0,0 +1,47 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ 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.
+-->
+<project name="Apache Tomcat Native Documentation - News"
+ href="http://tomcat.apache.org/">
+
+ <title>The Apache Tomcat Native - News</title>
+
+ <logo href="/images/tomcat.gif">
+ The Apache Tomcat Native - News
+ </logo>
+<body>
+
+ <menu name="Links">
+ <item name="Docs Home" href="../index.html"/>
+ </menu>
+
+ <menu name="Miscellaneous Documentation">
+ <item name="Changelog" href="../miscellaneous/changelog.html"/>
+ </menu>
+
+ <menu name="News">
+ <item name="2014" href="../news/2014.html"/>
+ <item name="2013" href="../news/2013.html"/>
+ <item name="2012" href="../news/2012.html"/>
+ <item name="2011" href="../news/2011.html"/>
+ <item name="2010" href="../news/2010.html"/>
+ <item name="2009" href="../news/2009.html"/>
+ <item name="2008" href="../news/2008.html"/>
+ </menu>
+
+</body>
+</project>
diff --git a/jni/xdocs/project.xml b/jni/xdocs/project.xml
new file mode 100644
index 0000000..2262014
--- /dev/null
+++ b/jni/xdocs/project.xml
@@ -0,0 +1,47 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ 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.
+-->
+<project name="Apache Tomcat Native Documentation"
+ href="http://tomcat.apache.org/">
+
+ <title>Apache Tomcat Native Library</title>
+
+ <logo href="/images/tomcat.gif">
+ Apache Tomcat Native Library
+ </logo>
+<body>
+
+ <menu name="Links">
+ <item name="Docs Home" href="index.html"/>
+ </menu>
+
+ <menu name="Miscellaneous Documentation">
+ <item name="Changelog" href="miscellaneous/changelog.html"/>
+ </menu>
+
+ <menu name="News">
+ <item name="2014" href="news/2014.html"/>
+ <item name="2013" href="news/2013.html"/>
+ <item name="2012" href="news/2012.html"/>
+ <item name="2011" href="news/2011.html"/>
+ <item name="2010" href="news/2010.html"/>
+ <item name="2009" href="news/2009.html"/>
+ <item name="2008" href="news/2008.html"/>
+ </menu>
+
+</body>
+</project>
diff --git a/jni/xdocs/style.xsl b/jni/xdocs/style.xsl
new file mode 100644
index 0000000..261bcc7
--- /dev/null
+++ b/jni/xdocs/style.xsl
@@ -0,0 +1,361 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ 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.
+-->
+<!-- Content Stylesheet for "tomcat-docs" Documentation -->
+
+<!-- $Id: style.xsl 572120 2007-09-02 19:32:11Z markt $ -->
+
+<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+ version="3.0">
+
+
+ <!-- Output method -->
+ <xsl:output method="html"
+ html-version="5.0"
+ encoding="UTF-8"
+ indent="no"
+ doctype-system="about:legacy-compat"/>
+
+
+ <!-- Defined parameters (overrideable) -->
+ <xsl:param name="home-name" select="'Apache Tomcat'"/>
+ <xsl:param name="home-href" select="'http://tomcat.apache.org/'"/>
+ <xsl:param name="home-logo" select="'/images/tomcat.png'"/>
+ <xsl:param name="home-stylesheet" select="'/images/docs-stylesheet.css'"/>
+ <xsl:param name="apache-logo" select="'/images/asf-feather.png'"/>
+ <xsl:param name="relative-path" select="'.'"/>
+ <xsl:param name="buglink" select="'http://issues.apache.org/bugzilla/show_bug.cgi?id='"/>
+
+ <!-- Defined variables (non-overrideable) -->
+
+
+ <!-- Process an entire document into an HTML page -->
+ <xsl:template match="document">
+<html lang="en">
+<head>
+ <!-- Note: XLST seems to always output a
+ <META http-equiv="Content-Type" content="text/html; charset=UTF-8">
+ when method="html",
+ therefore we can't use
+ <meta charset="UTF-8"/>.
+
+ In XHTML, this is not needed as the encoding will be
+ specified in the XML declaration.
+ -->
+
+ <xsl:variable name="css-src">
+ <xsl:value-of select="$relative-path"/><xsl:value-of select="$home-stylesheet"/>
+ </xsl:variable>
+ <link href="{$css-src}" rel="stylesheet" type="text/css"/>
+ <link href="{$relative-path}/images/style.css" rel="stylesheet" type="text/css"/>
+ <title><xsl:value-of select="project/title"/> - <xsl:value-of select="properties/title"/></title>
+ <xsl:for-each select="properties/author">
+ <xsl:variable name="name">
+ <xsl:value-of select="."/>
+ </xsl:variable>
+ <xsl:variable name="email">
+ <xsl:value-of select="@email"/>
+ </xsl:variable>
+ <meta name="author" content="{$name}"/>
+ </xsl:for-each>
+ </head>
+
+ <body>
+ <div id="wrapper">
+ <!-- Header -->
+ <header><div id="header">
+ <div>
+ <div>
+ <xsl:if test="project/logo">
+ <xsl:variable name="src">
+ <xsl:value-of select="$relative-path"/><xsl:value-of select="$home-logo"/>
+ </xsl:variable>
+ <div class="logo noPrint">
+ <a href="{project/@href}"><img alt="Tomcat Home" src="{$src}"/></a>
+ </div>
+ </xsl:if>
+
+ <div style="height: 1px;"/>
+ <xsl:variable name="src">
+ <xsl:value-of select="$relative-path"/><xsl:value-of select="$apache-logo"/>
+ </xsl:variable>
+ <div class="asfLogo noPrint">
+ <a href="http://www.apache.org/" target="_blank"><img src="{$src}" alt="The Apache Software Foundation" style="width: 266px; height: 83px;"/></a>
+ </div>
+ <h1><xsl:value-of select="project/title"/></h1>
+ <div style="height: 1px;"/>
+ <div style="clear: left;"/>
+ </div>
+ </div>
+ </div></header>
+
+ <div id="middle">
+ <div>
+ <div id="mainLeft" class="noprint">
+ <div>
+ <!-- Navigation -->
+ <nav>
+ <xsl:apply-templates select="project/body/menu"/>
+ </nav>
+ </div>
+ </div>
+ <div id="mainRight">
+ <div id="content">
+ <!-- Main Part -->
+ <h2><xsl:value-of select="properties/title"/></h2>
+ <xsl:apply-templates select="body/section"/>
+
+
+ </div>
+ </div>
+ </div>
+ </div>
+
+ <!-- Footer -->
+ <footer><div id="footer">
+ Copyright © 2008-2014, The Apache Software Foundation
+ </div></footer>
+</div>
+</body>
+</html>
+
+
+ </xsl:template>
+
+
+ <!-- Process a menu for the navigation bar -->
+ <xsl:template match="menu">
+ <div>
+ <h2><strong><xsl:value-of select="@name"/></strong></h2>
+ <ul>
+ <xsl:apply-templates select="item"/>
+ </ul>
+ </div>
+ </xsl:template>
+
+
+ <!-- Process a menu item for the navigation bar -->
+ <xsl:template match="item">
+ <xsl:variable name="href">
+ <xsl:value-of select="@href"/>
+ </xsl:variable>
+ <li><a href="{$href}"><xsl:value-of select="@name"/></a></li>
+ </xsl:template>
+
+
+ <!-- Process a documentation section -->
+ <xsl:template match="section">
+ <xsl:variable name="name2">
+ <xsl:choose>
+ <xsl:when test="@anchor">
+ <xsl:value-of select="@anchor" />
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:value-of select="@name"/>
+ </xsl:otherwise>
+ </xsl:choose>
+ </xsl:variable>
+ <xsl:variable name="name">
+ <xsl:value-of select="translate($name2, ' #', '__')"/>
+ </xsl:variable>
+
+
+ <!-- Section heading -->
+ <h3 id="{$name}">
+ <xsl:if test="@rtext">
+ <!-- Additional right-aligned text cell in section heading. It is used by changelog.xml -->
+ <span style="float: right;">
+ <xsl:value-of select="@rtext"/>
+ </span><xsl:text> </xsl:text> <!-- Ensure a space follows after </span> -->
+ </xsl:if>
+ <xsl:value-of select="@name"/>
+ </h3>
+ <!-- Section body -->
+ <div class="text">
+ <xsl:apply-templates/>
+ </div>
+
+ </xsl:template>
+
+
+ <!-- Process a documentation subsection -->
+ <xsl:template match="subsection">
+ <xsl:variable name="name2">
+ <xsl:choose>
+ <xsl:when test="@anchor">
+ <xsl:value-of select="@anchor" />
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:if test="
+ count(//*[(local-name()='section' or local-name()='subsection') and @name=current()/@name]) > 1
+ ">
+ <xsl:value-of select="concat(ancestor::section/@name, '/')"/>
+ </xsl:if>
+ <xsl:value-of select="@name"/>
+ </xsl:otherwise>
+ </xsl:choose>
+ </xsl:variable>
+ <xsl:variable name="name">
+ <xsl:value-of select="translate($name2, ' #', '__')"/>
+ </xsl:variable>
+
+
+ <div class="subsection">
+ <!-- Subsection heading -->
+ <!-- TODO: When a <subsection> is nested in another <subsection>,
+ the output should be <h5>, not <h4>. Same with <h6>. -->
+ <h4 id="{$name}">
+ <xsl:value-of select="@name"/>
+ </h4>
+ <!-- Subsection body -->
+ <div class="text">
+ <xsl:apply-templates/>
+ </div>
+ </div>
+
+ </xsl:template>
+
+
+ <!-- Process a source code example -->
+ <xsl:template match="source">
+ <div class="codeBox">
+ <pre>
+ <xsl:if test="@wrapped='true'">
+ <xsl:attribute name="class">wrap</xsl:attribute>
+ </xsl:if>
+ <code><xsl:apply-templates/></code>
+ </pre>
+ </div>
+ </xsl:template>
+
+
+ <!-- Process an attributes list with nested attribute elements -->
+ <xsl:template match="attributes">
+ <table class="defaultTable">
+ <tr>
+ <th style="width: 15%;">
+ Attribute
+ </th>
+ <th style="width: 85%;">
+ Description
+ </th>
+ </tr>
+ <xsl:for-each select="attribute">
+ <tr>
+ <td>
+ <xsl:if test="@required = 'true'">
+ <strong><code class="attributeName"><xsl:value-of select="@name"/></code></strong>
+ </xsl:if>
+ <xsl:if test="@required != 'true'">
+ <code class="attributeName"><xsl:value-of select="@name"/></code>
+ </xsl:if>
+ </td>
+ <td>
+ <xsl:apply-templates/>
+ </td>
+ </tr>
+ </xsl:for-each>
+ </table>
+ </xsl:template>
+
+
+ <!-- Warning -->
+ <xsl:template match="warn">
+ <p>
+ <span style="color: #ff0000;">
+ <xsl:apply-templates/>
+ </span>
+ </p>
+ </xsl:template>
+
+ <!-- Changelog related tags -->
+ <xsl:template match="changelog">
+ <ul class="changelog">
+ <xsl:apply-templates/>
+ </ul>
+ </xsl:template>
+
+ <xsl:template match="changelog/add">
+ <xsl:variable name="src"><xsl:value-of select="$relative-path"/>/images/add.gif</xsl:variable>
+ <li>
+ <img alt="Add: " class="icon" src="{$src}"/><xsl:apply-templates/>
+ </li>
+ </xsl:template>
+
+ <xsl:template match="changelog/update">
+ <xsl:variable name="src"><xsl:value-of select="$relative-path"/>/images/update.gif</xsl:variable>
+ <li>
+ <img alt="Update: " class="icon" src="{$src}"/><xsl:apply-templates/>
+ </li>
+ </xsl:template>
+
+ <xsl:template match="changelog/design">
+ <xsl:variable name="src"><xsl:value-of select="$relative-path"/>/images/design.gif</xsl:variable>
+ <li>
+ <img alt="Design: " class="icon" src="{$src}"/><xsl:apply-templates/>
+ </li>
+ </xsl:template>
+
+ <xsl:template match="changelog/docs">
+ <xsl:variable name="src"><xsl:value-of select="$relative-path"/>/images/docs.gif</xsl:variable>
+ <li>
+ <img alt="Docs: " class="icon" src="{$src}"/><xsl:apply-templates/>
+ </li>
+ </xsl:template>
+
+ <xsl:template match="changelog/fix">
+ <xsl:variable name="src"><xsl:value-of select="$relative-path"/>/images/fix.gif</xsl:variable>
+ <li>
+ <img alt="Fix: " class="icon" src="{$src}"/><xsl:apply-templates/>
+ </li>
+ </xsl:template>
+
+ <xsl:template match="changelog/scode">
+ <xsl:variable name="src"><xsl:value-of select="$relative-path"/>/images/code.gif</xsl:variable>
+ <li>
+ <img alt="Code: " class="icon" src="{$src}"/><xsl:apply-templates/>
+ </li>
+ </xsl:template>
+
+ <!-- Link to a bug report -->
+ <xsl:template match="bug">
+ <xsl:variable name="link"><xsl:value-of select="$buglink"/><xsl:value-of select="text()"/></xsl:variable>
+ <a href="{$link}"><xsl:apply-templates/></a>
+ </xsl:template>
+
+
+
+ <xsl:template match="todo">
+ <p class="todo">
+ This paragraph has not been written yet, but <b>you</b> can contribute to it.
+ <xsl:if test="string-length(@note) > 0">
+ The original author left a note attached to this TO-DO item:
+ <b><xsl:value-of select="@note"/></b>
+ </xsl:if>
+ </p>
+ </xsl:template>
+
+
+
+ <!-- Process everything else by just passing it through -->
+ <xsl:template match="*|@*">
+ <xsl:copy>
+ <xsl:apply-templates select="@*|*|text()"/>
+ </xsl:copy>
+ </xsl:template>
+
+</xsl:stylesheet>
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-java/tomcat-native.git
More information about the pkg-java-commits
mailing list