You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by ma...@apache.org on 2022/06/01 15:06:36 UTC
[tomcat-native] branch main updated: Remove unused code
This is an automated email from the ASF dual-hosted git repository.
markt pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/tomcat-native.git
The following commit(s) were added to refs/heads/main by this push:
new 34604c6b5 Remove unused code
34604c6b5 is described below
commit 34604c6b5b7735384fa7937f3373a2a80bb50ccf
Author: Mark Thomas <ma...@apache.org>
AuthorDate: Tue May 24 21:50:00 2022 +0100
Remove unused code
---
native/NMAKEmakefile | 21 -
native/include/ssl_private.h | 4 -
native/libtcnative.dsp | 84 ---
native/os/unix/system.c | 440 -----------
native/os/unix/uxpipe.c | 352 ---------
native/os/win32/ntpipe.c | 503 -------------
native/os/win32/registry.c | 786 --------------------
native/os/win32/system.c | 465 ------------
native/src/address.c | 140 ----
native/src/bb.c | 102 ---
native/src/dir.c | 99 ---
native/src/error.c | 106 ---
native/src/file.c | 587 ---------------
native/src/info.c | 354 ---------
native/src/jnilib.c | 16 -
native/src/lock.c | 185 -----
native/src/misc.c | 75 --
native/src/mmap.c | 96 ---
native/src/multicast.c | 69 --
native/src/network.c | 1480 -------------------------------------
native/src/os.c | 34 -
native/src/poll.c | 560 --------------
native/src/pool.c | 215 ------
native/src/proc.c | 447 -----------
native/src/shm.c | 121 ---
native/src/sslinfo.c | 603 ---------------
native/src/sslnetwork.c | 821 --------------------
native/src/stdlib.c | 114 ---
native/src/thread.c | 24 -
native/src/user.c | 157 ----
native/tcnative.dsp | 84 ---
xdocs/miscellaneous/changelog.xml | 5 +
32 files changed, 5 insertions(+), 9144 deletions(-)
diff --git a/native/NMAKEmakefile b/native/NMAKEmakefile
index e32c69e6c..530e6a339 100644
--- a/native/NMAKEmakefile
+++ b/native/NMAKEmakefile
@@ -88,35 +88,14 @@ CFLAGS = $(CFLAGS) -DZLIB_WINAPI -DNO_IDEA -DNO_RC5 -DNO_MDC2 -DOPENSSL_NO_IDEA
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)\sslconf.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
!IF DEFINED(WITH_FIPS)
OBJECTS = $(OBJECTS) srclib\openssl\tmp32\fips_premain.obj
!ENDIF
diff --git a/native/include/ssl_private.h b/native/include/ssl_private.h
index 3a14ce01f..a79f6b99b 100644
--- a/native/include/ssl_private.h
+++ b/native/include/ssl_private.h
@@ -221,7 +221,6 @@ extern ENGINE *tcn_ssl_engine;
#define OpenSSL_version_num SSLeay
#define OPENSSL_VERSION SSLEAY_VERSION
#define OPENSSL_malloc_init CRYPTO_malloc_init
-#define BN_get_rfc2409_prime_768 get_rfc2409_prime_768
#define BN_get_rfc2409_prime_1024 get_rfc2409_prime_1024
#define BN_get_rfc3526_prime_1536 get_rfc3526_prime_1536
#define BN_get_rfc3526_prime_2048 get_rfc3526_prime_2048
@@ -234,10 +233,7 @@ extern ENGINE *tcn_ssl_engine;
#define BIO_get_data(x) (x->ptr)
#define BIO_set_data(x,v) (x->ptr=v)
#define BIO_set_shutdown(x,v) (x->shutdown=v)
-#define X509_REVOKED_get0_serialNumber(x) x->serialNumber
#define X509_STORE_CTX_get0_untrusted(x) (x->untrusted)
-#define X509_OBJECT_free(x) {X509_OBJECT_free_contents(obj);\
- OPENSSL_free(obj);}
#define TLS_method SSLv23_method
#define TLS_client_method SSLv23_client_method
#define TLS_server_method SSLv23_server_method
diff --git a/native/libtcnative.dsp b/native/libtcnative.dsp
index d4f79e8e8..214370f70 100644
--- a/native/libtcnative.dsp
+++ b/native/libtcnative.dsp
@@ -92,74 +92,22 @@ LINK32=link.exe
# PROP Default_Filter ""
# Begin Source File
-SOURCE=.\src\address.c
-# End Source File
-# Begin Source File
-
SOURCE=.\src\bb.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\os.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
@@ -172,28 +120,8 @@ SOURCE=.\src\sslconf.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"
@@ -222,18 +150,6 @@ SOURCE=.\include\tcn_version.h
# 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
diff --git a/native/os/unix/system.c b/native/os/unix/system.c
deleted file mode 100644
index c32d342d8..000000000
--- a/native/os/unix/system.c
+++ /dev/null
@@ -1,440 +0,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.
- */
-
-#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/native/os/unix/uxpipe.c b/native/os/unix/uxpipe.c
deleted file mode 100644
index 69a7ddcb0..000000000
--- a/native/os/unix/uxpipe.c
+++ /dev/null
@@ -1,352 +0,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.
- */
-
-/** UNIX AF_LOCAL network wrapper
- */
-
-
-#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/native/os/win32/ntpipe.c b/native/os/win32/ntpipe.c
deleted file mode 100644
index 544756736..000000000
--- a/native/os/win32/ntpipe.c
+++ /dev/null
@@ -1,503 +0,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.
- */
-
-/** NT Pipes network wrapper
- */
-
-
-#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/native/os/win32/registry.c b/native/os/win32/registry.c
deleted file mode 100644
index 71312ef24..000000000
--- a/native/os/win32/registry.c
+++ /dev/null
@@ -1,786 +0,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.
- */
-
-#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/native/os/win32/system.c b/native/os/win32/system.c
deleted file mode 100644
index 4731d17bf..000000000
--- a/native/os/win32/system.c
+++ /dev/null
@@ -1,465 +0,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.
- */
-
-#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:
-#ifdef HAVE_OPENSSL
- ERR_remove_thread_state(NULL);
-#endif
- 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/native/src/address.c b/native/src/address.c
deleted file mode 100644
index 87a877178..000000000
--- a/native/src/address.c
+++ /dev/null
@@ -1,140 +0,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.
- */
-
-#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/native/src/bb.c b/native/src/bb.c
index 616ea78c7..3e48c9b04 100644
--- a/native/src/bb.c
+++ b/native/src/bb.c
@@ -20,110 +20,8 @@
* 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/native/src/dir.c b/native/src/dir.c
deleted file mode 100644
index 33c04fabf..000000000
--- a/native/src/dir.c
+++ /dev/null
@@ -1,99 +0,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.
- */
-
-#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/native/src/error.c b/native/src/error.c
index d365084bf..a0a2b1fbf 100644
--- a/native/src/error.c
+++ b/native/src/error.c
@@ -134,109 +134,3 @@ void tcn_ThrowAPRException(JNIEnv *e, apr_status_t err)
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/native/src/file.c b/native/src/file.c
deleted file mode 100644
index 9a7acea62..000000000
--- a/native/src/file.c
+++ /dev/null
@@ -1,587 +0,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.
- */
-
-#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);
- 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);
- 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));
- }
- ss = apr_file_writev_full(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, 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/native/src/info.c b/native/src/info.c
deleted file mode 100644
index 4734e542b..000000000
--- a/native/src/info.c
+++ /dev/null
@@ -1,354 +0,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.
- */
-
-#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;
-#ifdef APR_UNIX
- else if (info->family == APR_UNIX) f = 3;
-#endif
- 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 = {0};
-
- 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 = {0};
- 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 = {0};
-
- 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 = {0};
-
- 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 = {0};
-
- 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/native/src/jnilib.c b/native/src/jnilib.c
index 97284fb1c..414d7f365 100644
--- a/native/src/jnilib.c
+++ b/native/src/jnilib.c
@@ -48,8 +48,6 @@ 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;
@@ -82,18 +80,12 @@ JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved)
/* 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);
@@ -122,8 +114,6 @@ JNIEXPORT void JNICALL JNI_OnUnload(JavaVM *vm, void *reserved)
if (tcn_global_pool) {
env = (JNIEnv *)ppe;
TCN_UNLOAD_CLASS(env, jString_class);
- TCN_UNLOAD_CLASS(env, jFinfo_class);
- TCN_UNLOAD_CLASS(env, jAinfo_class);
apr_terminate();
}
}
@@ -261,12 +251,6 @@ TCN_IMPLEMENT_CALL(void, Library, terminate)(TCN_STDARGS)
}
}
-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;
diff --git a/native/src/lock.c b/native/src/lock.c
deleted file mode 100644
index 05874f797..000000000
--- a/native/src/lock.c
+++ /dev/null
@@ -1,185 +0,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.
- */
-
-#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);
-}
-
-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/native/src/misc.c b/native/src/misc.c
deleted file mode 100644
index e1b0a2d15..000000000
--- a/native/src/misc.c
+++ /dev/null
@@ -1,75 +0,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.
- */
-
-#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/native/src/mmap.c b/native/src/mmap.c
deleted file mode 100644
index 7880c06cb..000000000
--- a/native/src/mmap.c
+++ /dev/null
@@ -1,96 +0,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.
- */
-
-#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/native/src/multicast.c b/native/src/multicast.c
deleted file mode 100644
index 747227a8a..000000000
--- a/native/src/multicast.c
+++ /dev/null
@@ -1,69 +0,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.
- */
-
-#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/native/src/network.c b/native/src/network.c
deleted file mode 100644
index 05f0fd201..000000000
--- a/native/src/network.c
+++ /dev/null
@@ -1,1480 +0,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.
- */
-
-#include "tcn.h"
-
-#ifdef TCN_DO_STATISTICS
-
-#include "apr_atomic.h"
-#include "apr_file_io.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 */
-
-static apr_status_t sp_socket_remove(void *data)
-{
-#ifdef APR_UNIX
- tcn_socket_t *s = (tcn_socket_t *)data;
-
- if (s->sock) {
- apr_sockaddr_t *sa = NULL;
- apr_socket_addr_get(&sa, APR_LOCAL, s->sock);
- if (sa && sa->family == APR_UNIX) {
- char *path = NULL;
- apr_getnameinfo(&path, sa, 0);
- if (path) {
- apr_file_remove(path, s->pool);
- }
- }
- }
-#endif
- return APR_SUCCESS;
-}
-
-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);
- GET_S_FAMILY(f, family);
- GET_S_TYPE(t, type);
-
- if (p == NULL) {
- TCN_THROW_IF_ERR(apr_pool_create_unmanaged(&c), c);
- }
- else {
- 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_pre_cleanup_register(c, (const void *)a,
- sp_socket_cleanup);
-
-#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);
-
- apr_pool_cleanup_register(s->pool, (const void *)s,
- sp_socket_remove,
- apr_pool_cleanup_null);
-
- 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_unmanaged(&p), 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_pre_cleanup_register(a->pool, (const void *)a,
- sp_socket_cleanup);
- }
- 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:
- TCN_ASSERT(p != 0);
- 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);
-
- 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);
- TCN_ASSERT(bytes != 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);
- ss = (*s->net->recv)(s->opaque, (char*)(bytes + offset), &nbytes);
- if (ss == APR_SUCCESS) {
- (*e)->ReleaseByteArrayElements(e, buf, bytes, nbytes ? 0 : JNI_ABORT);
- } else {
- (*e)->ReleaseByteArrayElements(e, buf, bytes, 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;
- }
- if(!s->net) {
- return -(jint)APR_EINVALSOCK;
- }
- 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);
- return APR_ENOTSOCK;
- }
- if(!s->net) {
- tcn_ThrowAPRException(e, APR_EINVALSOCK);
- return -(jint)APR_EINVALSOCK;
- }
- 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) {
- return APR_ENOTSOCK;
- }
- if(!s->net) {
- return -(jint)APR_EINVALSOCK;
- }
- 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;
- }
- if(!s->net) {
- tcn_ThrowAPRException(e, APR_EINVALSOCK);
- return -(jint)APR_EINVALSOCK;
- }
- 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/native/src/os.c b/native/src/os.c
deleted file mode 100644
index 256a6977c..000000000
--- a/native/src/os.c
+++ /dev/null
@@ -1,34 +0,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.
- */
-
-#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/native/src/poll.c b/native/src/poll.c
deleted file mode 100644
index 4414ec821..000000000
--- a/native/src/poll.c
+++ /dev/null
@@ -1,560 +0,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.
- */
-
-#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;
- jboolean wakeable;
- /* 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 defined(APR_POLLSET_WAKEABLE)
- /* By default all pollsets are wakeable.
- * XXX: See if wee need to define that in Java API when calling this
- * method.
- */
- f |= APR_POLLSET_WAKEABLE;
-#endif
- if (f & APR_POLLSET_THREADSAFE) {
- apr_status_t rv = apr_pollset_create(&pollset, (apr_uint32_t)size,
- p, f);
- /* Pass the ENOTIMPL to java, as described in javadocs. Java must clean the
- flag, will know it's not supported.
- */
- if (rv != APR_SUCCESS) {
- tcn_ThrowAPRException(e, rv);
- goto cleanup;
- }
- }
- if (pollset == NULL) {
- apr_status_t rv = apr_pollset_create(&pollset, (apr_uint32_t)size,
- p, f);
-#if defined(APR_POLLSET_WAKEABLE)
- /* If case we fallback to select provider remove the
- * APR_POLLSET_WAKEABLE which causes size + 1 elements
- * and try again if APR_EINVAL is returned.
- */
- if (rv == APR_EINVAL)
- f &= ~APR_POLLSET_WAKEABLE;
- else if (rv != APR_SUCCESS) {
- tcn_ThrowAPRException(e, rv);
- goto cleanup;
- }
-#else
- if (rv != APR_SUCCESS) {
- tcn_ThrowAPRException(e, rv);
- goto cleanup;
- }
-#endif
- }
-#if defined(APR_POLLSET_WAKEABLE)
- if (pollset == NULL) {
- apr_status_t rv = apr_pollset_create(&pollset, (apr_uint32_t)size,
- p, f);
- if (rv != APR_SUCCESS) {
- tcn_ThrowAPRException(e, rv);
- goto cleanup;
- }
- }
-#endif
- 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);
-#if defined(APR_POLLSET_WAKEABLE)
- if (f & APR_POLLSET_WAKEABLE)
- tps->wakeable = JNI_TRUE;
- else
-#endif
- tps->wakeable = JNI_FALSE;
-#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
- /* Pass it to the caller - interrupt() was called */
- }
- 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 a socket is registered for multiple events and the poller has
- multiple events to return it may do as a single pair in this
- array or as multiple pairs depending on implementation. On OSX at
- least, multiple pairs have been observed. In this case do not try
- and remove socket from the pollset for a second time else a crash
- will result. */
- if (remove) {
- if (s->pe) {
- 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;
-}
-
-TCN_IMPLEMENT_CALL(jboolean, Poll, wakeable)(TCN_STDARGS, jlong pollset)
-{
-
- tcn_pollset_t *p = J2P(pollset, tcn_pollset_t *);
- UNREFERENCED_STDARGS;
-
- return p->wakeable;
-}
-
-#if defined(APR_POLLSET_WAKEABLE)
-
-TCN_IMPLEMENT_CALL(jint, Poll, interrupt)(TCN_STDARGS, jlong pollset)
-{
- tcn_pollset_t *p = J2P(pollset, tcn_pollset_t *);
-
- UNREFERENCED_STDARGS;
- TCN_ASSERT(pollset != 0);
-
- return (jint)apr_pollset_wakeup(p->pollset);
-}
-#else
-
-TCN_IMPLEMENT_CALL(jint, Poll, interrupt)(TCN_STDARGS, jlong pollset)
-{
-
- UNREFERENCED_STDARGS;
- UNREFERENCED(pollset);
-
- return APR_ENOTIMPL;
-}
-
-#endif
diff --git a/native/src/pool.c b/native/src/pool.c
index 901ed0206..45df89b23 100644
--- a/native/src/pool.c
+++ b/native/src/pool.c
@@ -18,24 +18,6 @@
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 *);
@@ -50,24 +32,6 @@ cleanup:
return P2J(n);
}
-TCN_IMPLEMENT_CALL(jlong, Pool, unmanaged)(TCN_STDARGS)
-{
- apr_pool_t *n;
-
- UNREFERENCED(o);
- TCN_THROW_IF_ERR(apr_pool_create_unmanaged(&n), 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 *);
@@ -76,182 +40,3 @@ TCN_IMPLEMENT_CALL(void, Pool, destroy)(TCN_STDARGS, jlong pool)
if (tcn_global_pool)
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);
- TCN_ASSERT(key != 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);
- TCN_ASSERT(key != 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/native/src/proc.c b/native/src/proc.c
deleted file mode 100644
index 298f3baae..000000000
--- a/native/src/proc.c
+++ /dev/null
@@ -1,447 +0,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.
- */
-
-#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)
- 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/native/src/shm.c b/native/src/shm.c
deleted file mode 100644
index b6ab80895..000000000
--- a/native/src/shm.c
+++ /dev/null
@@ -1,121 +0,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.
- */
-
-#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/native/src/sslinfo.c b/native/src/sslinfo.c
deleted file mode 100644
index 68e402461..000000000
--- a/native/src/sslinfo.c
+++ /dev/null
@@ -1,603 +0,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.
- */
-
-/** SSL info wrapper
- */
-
-#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 < X509_NAME_entry_count(xsname); j++) {
- xsne = X509_NAME_get_entry(xsname, j);
- n = OBJ_obj2nid(X509_NAME_ENTRY_get_object(xsne));
- if (n == info_cert_dn_rec[i].nid && idx-- == 0) {
- ASN1_STRING *adata = X509_NAME_ENTRY_get_data(xsne);
- int len = ASN1_STRING_length(adata);
- result = malloc(len + 1);
-#if OPENSSL_VERSION_NUMBER < 0x10100000L || defined(LIBRESSL_VERSION_NUMBER)
- memcpy(result, ASN1_STRING_data(adata), len);
-#else
- memcpy(result, ASN1_STRING_get0_data(adata), len);
-#endif
- result[len] = '\0';
-
-#if APR_CHARSET_EBCDIC
- ap_xlate_proto_from_ascii(result, len);
-#endif /* APR_CHARSET_EBCDIC */
- break;
- }
- }
- break;
- }
- }
- return result;
-}
-
-TCN_IMPLEMENT_CALL(jbyteArray, 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) {
- unsigned int len;
- const unsigned char *id = SSL_SESSION_get_id(session, &len);
- array = tcn_new_arrayb(e, id, len);
- }
- }
- 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) {
- unsigned int len;
- const unsigned char *id = SSL_SESSION_get_id(session, &len);
- char *hs = convert_to_hex(id, len);
- 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;
- ASN1_OBJECT *paobj;
- 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:
-#if defined(LIBRESSL_VERSION_NUMBER)
- value = tcn_new_string(e, "UNKNOWN");
-#else
- nid = X509_get_signature_nid(xs);
- if (nid == NID_undef)
- value = tcn_new_string(e, "UNKNOWN");
- else
- value = tcn_new_string(e, OBJ_nid2ln(nid));
-#endif
- break;
- case SSL_INFO_CLIENT_A_KEY:
- X509_PUBKEY_get0_param(&paobj, NULL, 0, NULL, X509_get_X509_PUBKEY(xs));
- nid = OBJ_obj2nid(paobj);
- 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;
- ASN1_OBJECT *paobj;
- 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:
-#if defined(LIBRESSL_VERSION_NUMBER)
- value = tcn_new_string(e, "UNKNOWN");
-#else
- nid = X509_get_signature_nid(xs);
- if (nid == NID_undef)
- value = tcn_new_string(e, "UNKNOWN");
- else
- value = tcn_new_string(e, OBJ_nid2ln(nid));
-#endif
- break;
- case SSL_INFO_SERVER_A_KEY:
- X509_PUBKEY_get0_param(&paobj, NULL, 0, NULL, X509_get_X509_PUBKEY(xs));
- nid = OBJ_obj2nid(paobj);
- 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(jbyteArray, 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/native/src/sslnetwork.c b/native/src/sslnetwork.c
deleted file mode 100644
index 6e5960f91..000000000
--- a/native/src/sslnetwork.c
+++ /dev/null
@@ -1,821 +0,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.
- */
-
-/** SSL network wrapper
- */
-
-#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(SSL_ERR_get(), 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);
-
- /* store for later usage in SSL_callback_SSL_verify */
- SSL_set_app_data2(ssl, ctx);
-
- if (ctx->mode) {
- /*
- * Configure callbacks for SSL connection
- */
- 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)) {
- SSL_ERR_clear();
- 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 (APR_STATUS_IS_EAGAIN(rv)) {
- return APR_EAGAIN;
- }
-#if !defined(_WIN32)
- else if (APR_STATUS_IS_EINTR(rv)) {
- /* Interrupted by signal */
- continue;
- }
-#endif
- /* Fall through */
- 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 (con->ctx->verify_mode != SSL_VERIFY_NONE &&
- (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 (;;) {
- SSL_ERR_clear();
- 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 && (SSL_get_shutdown(con->ssl) & 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;
- }
- else if (APR_STATUS_IS_EAGAIN(rv)) {
- return APR_EAGAIN;
- }
-#if !defined(_WIN32)
- else if (APR_STATUS_IS_EINTR(rv)) {
- /* Interrupted by signal
- */
- continue;
- }
-#endif
- /* Fall through */
- case SSL_ERROR_ZERO_RETURN:
- if (s == 0) {
- con->shutdown_type = SSL_SHUTDOWN_TYPE_STANDARD;
- return APR_EOF;
- }
- /* Fall through */
- 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 (;;) {
- SSL_ERR_clear();
- 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 through */
- 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;
-}
-
-static int ssl_do_renegotiate(tcn_ssl_conn_t *con, int use_pha)
-{
- int retVal;
- int error = 0;
- char peekbuf[1];
- apr_interval_time_t timeout;
-
- apr_socket_timeout_get(con->sock, &timeout);
-
- /* Trigger reading of the certs from the client.
- * Peeking 0 bytes actually works.
- * Before TLS 1.3 this will result in a renegotiation.
- * for TLS 1.3 in PHA.
- * See: http://marc.info/?t=145493359200002&r=1&w=2
- *
- * This will normally return SSL_ERROR_WANT_READ whether the renegotiation
- * has been completed or not. Afterwards, need to determine if I/O needs to
- * be triggered or not.
- */
- retVal = SSL_peek(con->ssl, peekbuf, 0);
- if (retVal < 1) {
- error = SSL_get_error(con->ssl, retVal);
- }
-
- // If the certs have not been received, then need to wait for I/O
- while ((use_pha && con->pha_state == PHA_STARTED) || (!use_pha && SSL_renegotiate_pending(con->ssl))) {
- // SSL_ERROR_WANT_READ is expected. Anything else is an error.
- if (error == SSL_ERROR_WANT_READ) {
- retVal = wait_for_io_or_timeout(con, error, timeout);
- /*
- * Since this is blocking I/O, anything other than APR_SUCCESS is an
- * error.
- */
- if (retVal != APR_SUCCESS) {
- con->shutdown_type = SSL_SHUTDOWN_TYPE_UNCLEAN;
- return retVal;
- }
- } else {
- return APR_EGENERAL;
- }
-
- // Re-try SSL_peek after I/O
- retVal = SSL_peek(con->ssl, peekbuf, 0);
- if (retVal < 1) {
- error = SSL_get_error(con->ssl, retVal);
- } else {
- /*
- * Reset error to handle case where SSL_Peek returns 0 but
- * the pha resp. renegotiation state has not changed.
- * This will trigger an error to be returned.
- */
- error = 0;
- }
- }
- 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;
-#if defined(SSL_OP_NO_TLSv1_3)
- const SSL_SESSION *session;
-#endif
-
- UNREFERENCED_STDARGS;
- TCN_ASSERT(sock != 0);
- con = (tcn_ssl_conn_t *)s->opaque;
-
-#if defined(SSL_OP_NO_TLSv1_3)
- session = SSL_get_session(con->ssl);
- if (SSL_SESSION_get_protocol_version(session) == TLS1_3_VERSION) {
- // TLS 1.3 renegotiation
- retVal = SSL_verify_client_post_handshake(con->ssl);
- if (retVal <= 0) {
- return APR_EGENERAL;
- }
-
- con->pha_state = PHA_STARTED;
-
- // Need to trigger a write operation to sent the cert request to the
- // client. As per OpenSSL docs, use SSL_do_handshake() for this.
- retVal = SSL_do_handshake(con->ssl);
- if (retVal <= 0) {
- return APR_EGENERAL;
- }
- retVal = ssl_do_renegotiate(con, 1);
- if (retVal != APR_SUCCESS) {
- return retVal;
- }
-
- } else {
-#endif
- // TLS 1.2 and earlier renegotiation
-
- /* Toggle the renegotiation state to allow the new
- * handshake to proceed.
- */
- con->reneg_state = RENEG_ALLOW;
-
- // Schedule a renegotiation request
- retVal = SSL_renegotiate(con->ssl);
- if (retVal <= 0) {
- return APR_EGENERAL;
- }
- retVal = ssl_do_renegotiate(con, 0);
- if (retVal != APR_SUCCESS) {
- return retVal;
- }
-
- con->reneg_state = RENEG_REJECT;
-#if defined(SSL_OP_NO_TLSv1_3)
- }
-#endif
- 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);
-}
-
-TCN_IMPLEMENT_CALL(jint, SSLSocket, getALPN)(TCN_STDARGS, jlong sock, jbyteArray buf)
-{
- const unsigned char *alpn;
- unsigned alpn_len;
- int len;
- tcn_socket_t *s = J2P(sock, tcn_socket_t *);
- tcn_ssl_conn_t *tcssl = (tcn_ssl_conn_t *)s->opaque;
- int bufLen = (*e)->GetArrayLength(e, buf);
-
- SSL_get0_alpn_selected(tcssl->ssl, &alpn, &alpn_len);
-
- if (alpn_len == 0 || bufLen < alpn_len) {
- return 0;
- }
- len = (int)alpn_len;
- (*e)->SetByteArrayRegion(e, buf, 0, len, (jbyte *)alpn);
-
- return len;
-}
-
-#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;
-}
-
-TCN_IMPLEMENT_CALL(jint, SSLSocket, getALPN)(TCN_STDARGS, jlong sock, jbyteArray buf)
-{
- UNREFERENCED(sock);
- UNREFERENCED(buf);
- return (jint)APR_ENOTIMPL;
-}
-
-#endif
diff --git a/native/src/stdlib.c b/native/src/stdlib.c
deleted file mode 100644
index 78a95e548..000000000
--- a/native/src/stdlib.c
+++ /dev/null
@@ -1,114 +0,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.
- */
-
-#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/native/src/thread.c b/native/src/thread.c
deleted file mode 100644
index 6696dc0f6..000000000
--- a/native/src/thread.c
+++ /dev/null
@@ -1,24 +0,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.
- */
-
-#include "tcn.h"
-
-TCN_IMPLEMENT_CALL(jlong, Thread, current)(TCN_STDARGS)
-{
- UNREFERENCED_STDARGS;
- return (jlong)tcn_get_thread_id();
-}
-
diff --git a/native/src/user.c b/native/src/user.c
deleted file mode 100644
index bc4b420b4..000000000
--- a/native/src/user.c
+++ /dev/null
@@ -1,157 +0,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.
- */
-
-#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/native/tcnative.dsp b/native/tcnative.dsp
index 64755c341..9b9e45609 100644
--- a/native/tcnative.dsp
+++ b/native/tcnative.dsp
@@ -92,74 +92,22 @@ LINK32=link.exe
# PROP Default_Filter ""
# Begin Source File
-SOURCE=.\src\address.c
-# End Source File
-# Begin Source File
-
SOURCE=.\src\bb.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\os.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
@@ -172,28 +120,8 @@ SOURCE=.\src\sslconf.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"
@@ -222,18 +150,6 @@ SOURCE=.\include\tcn_version.h
# 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
diff --git a/xdocs/miscellaneous/changelog.xml b/xdocs/miscellaneous/changelog.xml
index ce0b03557..50e78669d 100644
--- a/xdocs/miscellaneous/changelog.xml
+++ b/xdocs/miscellaneous/changelog.xml
@@ -52,6 +52,11 @@
Add support for using OpenSSL when the FIPS provider is configured as the
default provider. (markt)
</add>
+ <design>
+ Remove all API methods (and supporting code) that are not used by Tomcat
+ 10.1.x to support the use of OpenSSL as a replacement for JSSE to provide
+ TLS functionality. (markt)
+ </design>
</changelog>
</section>
<section name="Changes in 1.2.x">
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org