init
This commit is contained in:
114
java/org/apache/tomcat/jni/Address.java
Normal file
114
java/org/apache/tomcat/jni/Address.java
Normal file
@@ -0,0 +1,114 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.apache.tomcat.jni;
|
||||
|
||||
/** Address
|
||||
*
|
||||
* @author Mladen Turk
|
||||
*/
|
||||
public class Address {
|
||||
|
||||
public static final String APR_ANYADDR = "0.0.0.0";
|
||||
/**
|
||||
* Fill the Sockaddr class from apr_sockaddr_t
|
||||
* @param info Sockaddr class to fill
|
||||
* @param sa Structure pointer
|
||||
* @return <code>true</code> if the operation was successful
|
||||
*/
|
||||
public static native boolean fill(Sockaddr info, long sa);
|
||||
|
||||
/**
|
||||
* Create the Sockaddr object from apr_sockaddr_t
|
||||
* @param sa Structure pointer
|
||||
* @return the socket address
|
||||
*/
|
||||
public static native Sockaddr getInfo(long sa);
|
||||
|
||||
/**
|
||||
* Create apr_sockaddr_t from hostname, address family, and port.
|
||||
* @param hostname The hostname or numeric address string to resolve/parse, or
|
||||
* NULL to build an address that corresponds to 0.0.0.0 or ::
|
||||
* @param family The address family to use, or APR_UNSPEC if the system should
|
||||
* decide.
|
||||
* @param port The port number.
|
||||
* @param flags Special processing flags:
|
||||
* <PRE>
|
||||
* APR_IPV4_ADDR_OK first query for IPv4 addresses; only look
|
||||
* for IPv6 addresses if the first query failed;
|
||||
* only valid if family is APR_UNSPEC and hostname
|
||||
* isn't NULL; mutually exclusive with
|
||||
* APR_IPV6_ADDR_OK
|
||||
* APR_IPV6_ADDR_OK first query for IPv6 addresses; only look
|
||||
* for IPv4 addresses if the first query failed;
|
||||
* only valid if family is APR_UNSPEC and hostname
|
||||
* isn't NULL and APR_HAVE_IPV6; mutually exclusive
|
||||
* with APR_IPV4_ADDR_OK
|
||||
* </PRE>
|
||||
* @param p The pool for the apr_sockaddr_t and associated storage.
|
||||
* @return The new apr_sockaddr_t.
|
||||
* @throws Exception Operation failed
|
||||
*/
|
||||
public static native long info(String hostname, int family,
|
||||
int port, int flags, long p)
|
||||
throws Exception;
|
||||
/**
|
||||
* Look up the host name from an apr_sockaddr_t.
|
||||
* @param sa The apr_sockaddr_t.
|
||||
* @param flags Special processing flags.
|
||||
* @return The hostname.
|
||||
*/
|
||||
public static native String getnameinfo(long sa, int flags);
|
||||
|
||||
/**
|
||||
* Return the IP address (in numeric address string format) in
|
||||
* an APR socket address. APR will allocate storage for the IP address
|
||||
* string from the pool of the apr_sockaddr_t.
|
||||
* @param sa The socket address to reference.
|
||||
* @return The IP address.
|
||||
*/
|
||||
public static native String getip(long sa);
|
||||
|
||||
/**
|
||||
* Given an apr_sockaddr_t and a service name, set the port for the service
|
||||
* @param sockaddr The apr_sockaddr_t that will have its port set
|
||||
* @param servname The name of the service you wish to use
|
||||
* @return APR status code.
|
||||
*/
|
||||
public static native int getservbyname(long sockaddr, String servname);
|
||||
|
||||
/**
|
||||
* Return an apr_sockaddr_t from an apr_socket_t
|
||||
* @param which Which interface do we want the apr_sockaddr_t for?
|
||||
* @param sock The socket to use
|
||||
* @return The returned apr_sockaddr_t.
|
||||
* @throws Exception An error occurred
|
||||
*/
|
||||
public static native long get(int which, long sock)
|
||||
throws Exception;
|
||||
|
||||
/**
|
||||
* See if the IP addresses in two APR socket addresses are
|
||||
* equivalent. Appropriate logic is present for comparing
|
||||
* IPv4-mapped IPv6 addresses with IPv4 addresses.
|
||||
*
|
||||
* @param a One of the APR socket addresses.
|
||||
* @param b The other APR socket address.
|
||||
* @return <code>true</code> if the addresses are equal
|
||||
*/
|
||||
public static native boolean equal(long a, long b);
|
||||
|
||||
}
|
||||
54
java/org/apache/tomcat/jni/BIOCallback.java
Normal file
54
java/org/apache/tomcat/jni/BIOCallback.java
Normal file
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.apache.tomcat.jni;
|
||||
|
||||
/** Open SSL BIO Callback Interface
|
||||
*
|
||||
* @author Mladen Turk
|
||||
*/
|
||||
public interface BIOCallback {
|
||||
|
||||
/**
|
||||
* Write data
|
||||
* @param buf containing the bytes to write.
|
||||
* @return Number of characters written.
|
||||
*/
|
||||
public int write(byte [] buf);
|
||||
|
||||
/**
|
||||
* Read data
|
||||
* @param buf buffer to store the read bytes.
|
||||
* @return number of bytes read.
|
||||
*/
|
||||
public int read(byte [] buf);
|
||||
|
||||
/**
|
||||
* Puts string
|
||||
* @param data String to write
|
||||
* @return Number of characters written
|
||||
*/
|
||||
public int puts(String data);
|
||||
|
||||
/**
|
||||
* Read string up to the len or CLRLF
|
||||
* @param len Maximum number of characters to read
|
||||
* @return String with up to len bytes read
|
||||
*/
|
||||
public String gets(int len);
|
||||
|
||||
}
|
||||
91
java/org/apache/tomcat/jni/Buffer.java
Normal file
91
java/org/apache/tomcat/jni/Buffer.java
Normal file
@@ -0,0 +1,91 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.apache.tomcat.jni;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
/** Buffer
|
||||
*
|
||||
* @author Mladen Turk
|
||||
*/
|
||||
public class Buffer {
|
||||
|
||||
/**
|
||||
* Allocate a new ByteBuffer from memory
|
||||
* @param size The amount of memory to allocate
|
||||
* @return The ByteBuffer with allocated memory
|
||||
*/
|
||||
public static native ByteBuffer malloc(int size);
|
||||
|
||||
/**
|
||||
* Allocate a new ByteBuffer from memory and set all of the memory to 0
|
||||
* @param num Number of elements.
|
||||
* @param size Length in bytes of each element.
|
||||
* @return The ByteBuffer with allocated memory
|
||||
*/
|
||||
public static native ByteBuffer calloc(int num, int size);
|
||||
|
||||
/**
|
||||
* Allocate a new ByteBuffer from a pool
|
||||
* @param p The pool to allocate from
|
||||
* @param size The amount of memory to allocate
|
||||
* @return The ByteBuffer with allocated memory
|
||||
*/
|
||||
public static native ByteBuffer palloc(long p, int size);
|
||||
|
||||
/**
|
||||
* Allocate a new ByteBuffer from a pool and set all of the memory to 0
|
||||
* @param p The pool to allocate from
|
||||
* @param size The amount of memory to allocate
|
||||
* @return The ByteBuffer with allocated memory
|
||||
*/
|
||||
public static native ByteBuffer pcalloc(long p, int size);
|
||||
|
||||
/**
|
||||
* Allocate a new ByteBuffer from already allocated memory.
|
||||
* <br>Allocated memory must be provided from call to the
|
||||
* Stdlib.alloc or Stdlib.calloc methods.
|
||||
* @param mem The memory to use
|
||||
* @param size The amount of memory to use
|
||||
* @return The ByteBuffer with attached memory
|
||||
*/
|
||||
public static native ByteBuffer create(long mem, int size);
|
||||
|
||||
/**
|
||||
* Deallocates or frees a memory block used by ByteBuffer
|
||||
* <br><b>Warning :</b> Call this method only on ByteBuffers
|
||||
* that were created by calling Buffer.alloc or Buffer.calloc.
|
||||
* @param buf Previously allocated ByteBuffer to be freed.
|
||||
*/
|
||||
public static native void free(ByteBuffer buf);
|
||||
|
||||
/**
|
||||
* Returns the memory address of the ByteBuffer.
|
||||
* @param buf Previously allocated ByteBuffer.
|
||||
* @return the memory address
|
||||
*/
|
||||
public static native long address(ByteBuffer buf);
|
||||
|
||||
/**
|
||||
* Returns the allocated memory size of the ByteBuffer.
|
||||
* @param buf Previously allocated ByteBuffer.
|
||||
* @return the size
|
||||
*/
|
||||
public static native long size(ByteBuffer buf);
|
||||
|
||||
}
|
||||
34
java/org/apache/tomcat/jni/CertificateVerifier.java
Normal file
34
java/org/apache/tomcat/jni/CertificateVerifier.java
Normal file
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.apache.tomcat.jni;
|
||||
|
||||
/**
|
||||
* Is called during handshake and hooked into openssl via {@code SSL_CTX_set_cert_verify_callback}.
|
||||
*/
|
||||
public interface CertificateVerifier {
|
||||
|
||||
/**
|
||||
* Returns {@code true} if the passed in certificate chain could be verified and so the handshake
|
||||
* should be successful, {@code false} otherwise.
|
||||
*
|
||||
* @param ssl the SSL instance
|
||||
* @param x509 the {@code X509} certificate chain
|
||||
* @param authAlgorithm the auth algorithm
|
||||
* @return verified {@code true} if verified successful, {@code false} otherwise
|
||||
*/
|
||||
boolean verify(long ssl, byte[][] x509, String authAlgorithm);
|
||||
}
|
||||
102
java/org/apache/tomcat/jni/Directory.java
Normal file
102
java/org/apache/tomcat/jni/Directory.java
Normal file
@@ -0,0 +1,102 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.apache.tomcat.jni;
|
||||
|
||||
/** Directory
|
||||
*
|
||||
* @author Mladen Turk
|
||||
*/
|
||||
public class Directory {
|
||||
|
||||
/**
|
||||
* Create a new directory on the file system.
|
||||
* @param path the path for the directory to be created. (use / on all systems)
|
||||
* @param perm Permissions for the new directory.
|
||||
* @param pool the pool to use.
|
||||
* @return the operation result
|
||||
*/
|
||||
public static native int make(String path, int perm, long pool);
|
||||
|
||||
/**
|
||||
* Creates a new directory on the file system, but behaves like
|
||||
* 'mkdir -p'. Creates intermediate directories as required. No error
|
||||
* will be reported if PATH already exists.
|
||||
* @param path the path for the directory to be created. (use / on all systems)
|
||||
* @param perm Permissions for the new directory.
|
||||
* @param pool the pool to use.
|
||||
* @return the operation result
|
||||
*/
|
||||
public static native int makeRecursive(String path, int perm, long pool);
|
||||
|
||||
/**
|
||||
* Remove directory from the file system.
|
||||
* @param path the path for the directory to be removed. (use / on all systems)
|
||||
* @param pool the pool to use.
|
||||
* @return the operation result
|
||||
*/
|
||||
public static native int remove(String path, long pool);
|
||||
|
||||
/**
|
||||
* Find an existing directory suitable as a temporary storage location.
|
||||
* @param pool The pool to use for any necessary allocations.
|
||||
* @return The temp directory.
|
||||
*
|
||||
* This function uses an algorithm to search for a directory that an
|
||||
* an application can use for temporary storage. Once such a
|
||||
* directory is found, that location is cached by the library. Thus,
|
||||
* callers only pay the cost of this algorithm once if that one time
|
||||
* is successful.
|
||||
*/
|
||||
public static native String tempGet(long pool);
|
||||
|
||||
/**
|
||||
* Open the specified directory.
|
||||
* @param dirname The full path to the directory (use / on all systems)
|
||||
* @param pool The pool to use.
|
||||
* @return The opened directory descriptor.
|
||||
* @throws Error An error occurred
|
||||
*/
|
||||
public static native long open(String dirname, long pool)
|
||||
throws Error;
|
||||
|
||||
/**
|
||||
* close the specified directory.
|
||||
* @param thedir the directory descriptor to close.
|
||||
* @return the operation result
|
||||
*/
|
||||
public static native int close(long thedir);
|
||||
|
||||
/**
|
||||
* Rewind the directory to the first entry.
|
||||
* @param thedir the directory descriptor to rewind.
|
||||
* @return the operation result
|
||||
*/
|
||||
public static native int rewind(long thedir);
|
||||
|
||||
|
||||
/**
|
||||
* Read the next entry from the specified directory.
|
||||
* @param finfo the file info structure and filled in by apr_dir_read
|
||||
* @param wanted The desired apr_finfo_t fields, as a bit flag of APR_FINFO_ values
|
||||
* @param thedir the directory descriptor returned from apr_dir_open
|
||||
* No ordering is guaranteed for the entries read.
|
||||
* @return the operation result
|
||||
*/
|
||||
public static native int read(FileInfo finfo, int wanted, long thedir);
|
||||
|
||||
}
|
||||
96
java/org/apache/tomcat/jni/Error.java
Normal file
96
java/org/apache/tomcat/jni/Error.java
Normal file
@@ -0,0 +1,96 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.apache.tomcat.jni;
|
||||
|
||||
/** Error
|
||||
*
|
||||
* @author Mladen Turk
|
||||
*/
|
||||
public class Error extends Exception {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* APR error type.
|
||||
*/
|
||||
private final int error;
|
||||
|
||||
/**
|
||||
* A description of the problem.
|
||||
*/
|
||||
private final String description;
|
||||
|
||||
/**
|
||||
* Construct an APRException.
|
||||
*
|
||||
* @param error one of the value in Error
|
||||
* @param description error message
|
||||
*/
|
||||
private Error(int error, String description)
|
||||
{
|
||||
super(error + ": " + description);
|
||||
this.error = error;
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the APR error code of the exception.
|
||||
*
|
||||
* @return error of the Exception
|
||||
*/
|
||||
public int getError()
|
||||
{
|
||||
return error;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the APR description of the exception.
|
||||
*
|
||||
* @return description of the Exception
|
||||
*/
|
||||
public String getDescription()
|
||||
{
|
||||
return description;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the last platform error.
|
||||
* @return apr_status_t the last platform error, folded into apr_status_t, on most platforms
|
||||
* This retrieves errno, or calls a GetLastError() style function, and
|
||||
* folds it with APR_FROM_OS_ERROR. Some platforms (such as OS2) have no
|
||||
* such mechanism, so this call may be unsupported. Do NOT use this
|
||||
* call for socket errors from socket, send, recv etc!
|
||||
*/
|
||||
public static native int osError();
|
||||
|
||||
/**
|
||||
* Get the last platform socket error.
|
||||
* @return the last socket error, folded into apr_status_t, on all platforms
|
||||
* This retrieves errno or calls a GetLastSocketError() style function,
|
||||
* and folds it with APR_FROM_OS_ERROR.
|
||||
*/
|
||||
public static native int netosError();
|
||||
|
||||
/**
|
||||
* Return a human readable string describing the specified error.
|
||||
* @param statcode The error code the get a string for.
|
||||
* @return The error string.
|
||||
*/
|
||||
public static native String strerror(int statcode);
|
||||
|
||||
}
|
||||
746
java/org/apache/tomcat/jni/File.java
Normal file
746
java/org/apache/tomcat/jni/File.java
Normal file
File diff suppressed because it is too large
Load Diff
65
java/org/apache/tomcat/jni/FileInfo.java
Normal file
65
java/org/apache/tomcat/jni/FileInfo.java
Normal file
@@ -0,0 +1,65 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.apache.tomcat.jni;
|
||||
|
||||
/** Fileinfo
|
||||
*
|
||||
* @author Mladen Turk
|
||||
*/
|
||||
public class FileInfo {
|
||||
|
||||
/** Allocates memory and closes lingering handles in the specified pool */
|
||||
public long pool;
|
||||
/** The bitmask describing valid fields of this apr_finfo_t structure
|
||||
* including all available 'wanted' fields and potentially more */
|
||||
public int valid;
|
||||
/** The access permissions of the file. Mimics Unix access rights. */
|
||||
public int protection;
|
||||
/** The type of file. One of APR_REG, APR_DIR, APR_CHR, APR_BLK, APR_PIPE,
|
||||
* APR_LNK or APR_SOCK. If the type is undetermined, the value is APR_NOFILE.
|
||||
* If the type cannot be determined, the value is APR_UNKFILE.
|
||||
*/
|
||||
public int filetype;
|
||||
/** The user id that owns the file */
|
||||
public int user;
|
||||
/** The group id that owns the file */
|
||||
public int group;
|
||||
/** The inode of the file. */
|
||||
public int inode;
|
||||
/** The id of the device the file is on. */
|
||||
public int device;
|
||||
/** The number of hard links to the file. */
|
||||
public int nlink;
|
||||
/** The size of the file */
|
||||
public long size;
|
||||
/** The storage size consumed by the file */
|
||||
public long csize;
|
||||
/** The time the file was last accessed */
|
||||
public long atime;
|
||||
/** The time the file was last modified */
|
||||
public long mtime;
|
||||
/** The time the file was created, or the inode was last changed */
|
||||
public long ctime;
|
||||
/** The pathname of the file (possibly unrooted) */
|
||||
public String fname;
|
||||
/** The file's name (no path) in filesystem case */
|
||||
public String name;
|
||||
/** The file's handle, if accessed (can be submitted to apr_duphandle) */
|
||||
public long filehand;
|
||||
|
||||
}
|
||||
100
java/org/apache/tomcat/jni/Global.java
Normal file
100
java/org/apache/tomcat/jni/Global.java
Normal file
@@ -0,0 +1,100 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.apache.tomcat.jni;
|
||||
|
||||
/** Global
|
||||
*
|
||||
* @author Mladen Turk
|
||||
*/
|
||||
public class Global {
|
||||
|
||||
/**
|
||||
* Create and initialize a mutex that can be used to synchronize both
|
||||
* processes and threads. Note: There is considerable overhead in using
|
||||
* this API if only cross-process or cross-thread mutual exclusion is
|
||||
* required. See apr_proc_mutex.h and apr_thread_mutex.h for more
|
||||
* specialized lock routines.
|
||||
* <br><b>Warning :</b> Check APR_HAS_foo_SERIALIZE defines to see if the platform supports
|
||||
* APR_LOCK_foo. Only APR_LOCK_DEFAULT is portable.
|
||||
* @param fname A file name to use if the lock mechanism requires one. This
|
||||
* argument should always be provided. The lock code itself will
|
||||
* determine if it should be used.
|
||||
* @param mech The mechanism to use for the interprocess lock, if any; one of
|
||||
* <PRE>
|
||||
* APR_LOCK_FCNTL
|
||||
* APR_LOCK_FLOCK
|
||||
* APR_LOCK_SYSVSEM
|
||||
* APR_LOCK_POSIXSEM
|
||||
* APR_LOCK_PROC_PTHREAD
|
||||
* APR_LOCK_DEFAULT pick the default mechanism for the platform
|
||||
* </PRE>
|
||||
* @param pool the pool from which to allocate the mutex.
|
||||
* @return Newly created mutex.
|
||||
* @throws Error If an error occurred
|
||||
*/
|
||||
public static native long create(String fname, int mech, long pool)
|
||||
throws Error;
|
||||
|
||||
/**
|
||||
* Re-open a mutex in a child process.
|
||||
* @param fname A file name to use if the mutex mechanism requires one. This
|
||||
* argument should always be provided. The mutex code itself will
|
||||
* determine if it should be used. This filename should be the
|
||||
* same one that was passed to apr_proc_mutex_create().
|
||||
* @param pool The pool to operate on.
|
||||
* This function must be called to maintain portability, even
|
||||
* if the underlying lock mechanism does not require it.
|
||||
* @return Newly opened mutex.
|
||||
* @throws Error If an error occurred
|
||||
*/
|
||||
public static native long childInit(String fname, long pool)
|
||||
throws Error;
|
||||
|
||||
/**
|
||||
* Acquire the lock for the given mutex. If the mutex is already locked,
|
||||
* the current thread will be put to sleep until the lock becomes available.
|
||||
* @param mutex the mutex on which to acquire the lock.
|
||||
* @return the operation status
|
||||
*/
|
||||
public static native int lock(long mutex);
|
||||
|
||||
/**
|
||||
* Attempt to acquire the lock for the given mutex. If the mutex has already
|
||||
* been acquired, the call returns immediately with APR_EBUSY. Note: it
|
||||
* is important that the APR_STATUS_IS_EBUSY(s) macro be used to determine
|
||||
* if the return value was APR_EBUSY, for portability reasons.
|
||||
* @param mutex the mutex on which to attempt the lock acquiring.
|
||||
* @return the operation status
|
||||
*/
|
||||
public static native int trylock(long mutex);
|
||||
|
||||
/**
|
||||
* Release the lock for the given mutex.
|
||||
* @param mutex the mutex from which to release the lock.
|
||||
* @return the operation status
|
||||
*/
|
||||
public static native int unlock(long mutex);
|
||||
|
||||
/**
|
||||
* Destroy the mutex and free the memory associated with the lock.
|
||||
* @param mutex the mutex to destroy.
|
||||
* @return the operation status
|
||||
*/
|
||||
public static native int destroy(long mutex);
|
||||
|
||||
}
|
||||
266
java/org/apache/tomcat/jni/Library.java
Normal file
266
java/org/apache/tomcat/jni/Library.java
Normal file
@@ -0,0 +1,266 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.apache.tomcat.jni;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
/** Library
|
||||
*
|
||||
* @author Mladen Turk
|
||||
*/
|
||||
public final class Library {
|
||||
|
||||
/* Default library names */
|
||||
private static final String [] NAMES = {"tcnative-1", "libtcnative-1"};
|
||||
/*
|
||||
* A handle to the unique Library singleton instance.
|
||||
*/
|
||||
private static Library _instance = null;
|
||||
|
||||
private Library() throws Exception {
|
||||
boolean loaded = false;
|
||||
String path = System.getProperty("java.library.path");
|
||||
String [] paths = path.split(File.pathSeparator);
|
||||
StringBuilder err = new StringBuilder();
|
||||
for (int i = 0; i < NAMES.length; i++) {
|
||||
try {
|
||||
System.loadLibrary(NAMES[i]);
|
||||
loaded = true;
|
||||
} catch (ThreadDeath t) {
|
||||
throw t;
|
||||
} catch (VirtualMachineError t) {
|
||||
// Don't use a Java 7 multiple exception catch so we can keep
|
||||
// the JNI code identical between Tomcat 6/7/8/9
|
||||
throw t;
|
||||
} catch (Throwable t) {
|
||||
String name = System.mapLibraryName(NAMES[i]);
|
||||
for (int j = 0; j < paths.length; j++) {
|
||||
java.io.File fd = new java.io.File(paths[j] , name);
|
||||
if (fd.exists()) {
|
||||
// File exists but failed to load
|
||||
throw t;
|
||||
}
|
||||
}
|
||||
if (i > 0) {
|
||||
err.append(", ");
|
||||
}
|
||||
err.append(t.getMessage());
|
||||
}
|
||||
if (loaded) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!loaded) {
|
||||
StringBuilder names = new StringBuilder();
|
||||
for (String name : NAMES) {
|
||||
names.append(name);
|
||||
names.append(", ");
|
||||
}
|
||||
throw new LibraryNotFoundError(names.substring(0, names.length() -2), err.toString());
|
||||
}
|
||||
}
|
||||
|
||||
private Library(String libraryName)
|
||||
{
|
||||
System.loadLibrary(libraryName);
|
||||
}
|
||||
|
||||
/* create global TCN's APR pool
|
||||
* This has to be the first call to TCN library.
|
||||
*/
|
||||
private static native boolean initialize();
|
||||
/* destroy global TCN's APR pool
|
||||
* This has to be the last call to TCN library.
|
||||
*/
|
||||
public static native void terminate();
|
||||
/* Internal function for loading APR Features */
|
||||
private static native boolean has(int what);
|
||||
/* Internal function for loading APR Features */
|
||||
private static native int version(int what);
|
||||
/* Internal function for loading APR sizes */
|
||||
private static native int size(int what);
|
||||
|
||||
/* TCN_MAJOR_VERSION */
|
||||
public static int TCN_MAJOR_VERSION = 0;
|
||||
/* TCN_MINOR_VERSION */
|
||||
public static int TCN_MINOR_VERSION = 0;
|
||||
/* TCN_PATCH_VERSION */
|
||||
public static int TCN_PATCH_VERSION = 0;
|
||||
/* TCN_IS_DEV_VERSION */
|
||||
public static int TCN_IS_DEV_VERSION = 0;
|
||||
/* APR_MAJOR_VERSION */
|
||||
public static int APR_MAJOR_VERSION = 0;
|
||||
/* APR_MINOR_VERSION */
|
||||
public static int APR_MINOR_VERSION = 0;
|
||||
/* APR_PATCH_VERSION */
|
||||
public static int APR_PATCH_VERSION = 0;
|
||||
/* APR_IS_DEV_VERSION */
|
||||
public static int APR_IS_DEV_VERSION = 0;
|
||||
|
||||
/* TCN_VERSION_STRING */
|
||||
public static native String versionString();
|
||||
/* APR_VERSION_STRING */
|
||||
public static native String aprVersionString();
|
||||
|
||||
/* APR Feature Macros */
|
||||
public static boolean APR_HAVE_IPV6 = false;
|
||||
public static boolean APR_HAS_SHARED_MEMORY = false;
|
||||
public static boolean APR_HAS_THREADS = false;
|
||||
public static boolean APR_HAS_SENDFILE = false;
|
||||
public static boolean APR_HAS_MMAP = false;
|
||||
public static boolean APR_HAS_FORK = false;
|
||||
public static boolean APR_HAS_RANDOM = false;
|
||||
public static boolean APR_HAS_OTHER_CHILD = false;
|
||||
public static boolean APR_HAS_DSO = false;
|
||||
public static boolean APR_HAS_SO_ACCEPTFILTER = false;
|
||||
public static boolean APR_HAS_UNICODE_FS = false;
|
||||
public static boolean APR_HAS_PROC_INVOKED = false;
|
||||
public static boolean APR_HAS_USER = false;
|
||||
public static boolean APR_HAS_LARGE_FILES = false;
|
||||
public static boolean APR_HAS_XTHREAD_FILES = false;
|
||||
public static boolean APR_HAS_OS_UUID = false;
|
||||
/* Are we big endian? */
|
||||
public static boolean APR_IS_BIGENDIAN = false;
|
||||
/* APR sets APR_FILES_AS_SOCKETS to 1 on systems where it is possible
|
||||
* to poll on files/pipes.
|
||||
*/
|
||||
public static boolean APR_FILES_AS_SOCKETS = false;
|
||||
/* This macro indicates whether or not EBCDIC is the native character set.
|
||||
*/
|
||||
public static boolean APR_CHARSET_EBCDIC = false;
|
||||
/* Is the TCP_NODELAY socket option inherited from listening sockets?
|
||||
*/
|
||||
public static boolean APR_TCP_NODELAY_INHERITED = false;
|
||||
/* Is the O_NONBLOCK flag inherited from listening sockets?
|
||||
*/
|
||||
public static boolean APR_O_NONBLOCK_INHERITED = false;
|
||||
|
||||
|
||||
public static int APR_SIZEOF_VOIDP;
|
||||
public static int APR_PATH_MAX;
|
||||
public static int APRMAXHOSTLEN;
|
||||
public static int APR_MAX_IOVEC_SIZE;
|
||||
public static int APR_MAX_SECS_TO_LINGER;
|
||||
public static int APR_MMAP_THRESHOLD;
|
||||
public static int APR_MMAP_LIMIT;
|
||||
|
||||
/* return global TCN's APR pool */
|
||||
public static native long globalPool();
|
||||
|
||||
/**
|
||||
* Setup any APR internal data structures. This MUST be the first function
|
||||
* called for any APR library.
|
||||
* @param libraryName the name of the library to load
|
||||
*
|
||||
* @return {@code true} if the native code was initialized successfully
|
||||
* otherwise {@code false}
|
||||
*
|
||||
* @throws Exception if a problem occurred during initialization
|
||||
*/
|
||||
public static synchronized boolean initialize(String libraryName) throws Exception {
|
||||
if (_instance == null) {
|
||||
if (libraryName == null)
|
||||
_instance = new Library();
|
||||
else
|
||||
_instance = new Library(libraryName);
|
||||
TCN_MAJOR_VERSION = version(0x01);
|
||||
TCN_MINOR_VERSION = version(0x02);
|
||||
TCN_PATCH_VERSION = version(0x03);
|
||||
TCN_IS_DEV_VERSION = version(0x04);
|
||||
APR_MAJOR_VERSION = version(0x11);
|
||||
APR_MINOR_VERSION = version(0x12);
|
||||
APR_PATCH_VERSION = version(0x13);
|
||||
APR_IS_DEV_VERSION = version(0x14);
|
||||
|
||||
APR_SIZEOF_VOIDP = size(1);
|
||||
APR_PATH_MAX = size(2);
|
||||
APRMAXHOSTLEN = size(3);
|
||||
APR_MAX_IOVEC_SIZE = size(4);
|
||||
APR_MAX_SECS_TO_LINGER = size(5);
|
||||
APR_MMAP_THRESHOLD = size(6);
|
||||
APR_MMAP_LIMIT = size(7);
|
||||
|
||||
APR_HAVE_IPV6 = has(0);
|
||||
APR_HAS_SHARED_MEMORY = has(1);
|
||||
APR_HAS_THREADS = has(2);
|
||||
APR_HAS_SENDFILE = has(3);
|
||||
APR_HAS_MMAP = has(4);
|
||||
APR_HAS_FORK = has(5);
|
||||
APR_HAS_RANDOM = has(6);
|
||||
APR_HAS_OTHER_CHILD = has(7);
|
||||
APR_HAS_DSO = has(8);
|
||||
APR_HAS_SO_ACCEPTFILTER = has(9);
|
||||
APR_HAS_UNICODE_FS = has(10);
|
||||
APR_HAS_PROC_INVOKED = has(11);
|
||||
APR_HAS_USER = has(12);
|
||||
APR_HAS_LARGE_FILES = has(13);
|
||||
APR_HAS_XTHREAD_FILES = has(14);
|
||||
APR_HAS_OS_UUID = has(15);
|
||||
APR_IS_BIGENDIAN = has(16);
|
||||
APR_FILES_AS_SOCKETS = has(17);
|
||||
APR_CHARSET_EBCDIC = has(18);
|
||||
APR_TCP_NODELAY_INHERITED = has(19);
|
||||
APR_O_NONBLOCK_INHERITED = has(20);
|
||||
if (APR_MAJOR_VERSION < 1) {
|
||||
throw new UnsatisfiedLinkError("Unsupported APR Version (" +
|
||||
aprVersionString() + ")");
|
||||
}
|
||||
if (!APR_HAS_THREADS) {
|
||||
throw new UnsatisfiedLinkError("Missing APR_HAS_THREADS");
|
||||
}
|
||||
}
|
||||
return initialize();
|
||||
}
|
||||
|
||||
/**
|
||||
* Calls System.load(filename). System.load() associates the
|
||||
* loaded library with the class loader of the class that called
|
||||
* the System method. A native library may not be loaded by more
|
||||
* than one class loader, so calling the System method from a class that
|
||||
* was loaded by a Webapp class loader will make it impossible for
|
||||
* other Webapps to load it.
|
||||
*
|
||||
* Using this method will load the native library via a shared class
|
||||
* loader (typically the Common class loader, but may vary in some
|
||||
* configurations), so that it can be loaded by multiple Webapps.
|
||||
*
|
||||
* @param filename - absolute path of the native library
|
||||
*/
|
||||
public static void load(String filename){
|
||||
System.load(filename);
|
||||
}
|
||||
|
||||
/**
|
||||
* Calls System.loadLibrary(libname). System.loadLibrary() associates the
|
||||
* loaded library with the class loader of the class that called
|
||||
* the System method. A native library may not be loaded by more
|
||||
* than one class loader, so calling the System method from a class that
|
||||
* was loaded by a Webapp class loader will make it impossible for
|
||||
* other Webapps to load it.
|
||||
*
|
||||
* Using this method will load the native library via a shared class
|
||||
* loader (typically the Common class loader, but may vary in some
|
||||
* configurations), so that it can be loaded by multiple Webapps.
|
||||
*
|
||||
* @param libname - the name of the native library
|
||||
*/
|
||||
public static void loadLibrary(String libname){
|
||||
System.loadLibrary(libname);
|
||||
}
|
||||
|
||||
}
|
||||
40
java/org/apache/tomcat/jni/LibraryNotFoundError.java
Normal file
40
java/org/apache/tomcat/jni/LibraryNotFoundError.java
Normal file
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.apache.tomcat.jni;
|
||||
|
||||
public class LibraryNotFoundError extends UnsatisfiedLinkError {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private final String libraryNames;
|
||||
|
||||
/**
|
||||
*
|
||||
* @param libraryNames A list of the file names of the native libraries that
|
||||
* failed to load
|
||||
* @param errors A list of the error messages received when trying to load
|
||||
* each of the libraries
|
||||
*/
|
||||
public LibraryNotFoundError(String libraryNames, String errors){
|
||||
super(errors);
|
||||
this.libraryNames = libraryNames;
|
||||
}
|
||||
|
||||
public String getLibraryNames(){
|
||||
return libraryNames;
|
||||
}
|
||||
}
|
||||
78
java/org/apache/tomcat/jni/Local.java
Normal file
78
java/org/apache/tomcat/jni/Local.java
Normal file
@@ -0,0 +1,78 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.apache.tomcat.jni;
|
||||
|
||||
/**
|
||||
* Local socket.
|
||||
*
|
||||
* @author Mladen Turk
|
||||
*/
|
||||
public class Local {
|
||||
|
||||
/**
|
||||
* Create a socket.
|
||||
* @param path The address of the new socket.
|
||||
* @param cont The parent pool to use
|
||||
* @return The new socket that has been set up.
|
||||
* @throws Exception If socket creation failed
|
||||
*/
|
||||
public static native long create(String path, long cont)
|
||||
throws Exception;
|
||||
|
||||
/**
|
||||
* Bind the socket to its associated port
|
||||
* @param sock The socket to bind
|
||||
* @param sa The socket address to bind to
|
||||
* This may be where we will find out if there is any other process
|
||||
* using the selected port.
|
||||
* @return the operation status
|
||||
*/
|
||||
public static native int bind(long sock, long sa);
|
||||
|
||||
/**
|
||||
* Listen to a bound socket for connections.
|
||||
* @param sock The socket to listen on
|
||||
* @param backlog The number of outstanding connections allowed in the sockets
|
||||
* listen queue. If this value is less than zero, for NT pipes
|
||||
* the number of instances is unlimited.
|
||||
* @return the operation status
|
||||
*/
|
||||
public static native int listen(long sock, int backlog);
|
||||
|
||||
/**
|
||||
* Accept a new connection request
|
||||
* @param sock The socket we are listening on.
|
||||
* @return A copy of the socket that is connected to the socket that
|
||||
* made the connection request. This is the socket which should
|
||||
* be used for all future communication.
|
||||
* @throws Exception If accept failed
|
||||
*/
|
||||
public static native long accept(long sock)
|
||||
throws Exception;
|
||||
|
||||
/**
|
||||
* Issue a connection request to a socket either on the same machine
|
||||
* or a different one.
|
||||
* @param sock The socket we wish to use for our side of the connection
|
||||
* @param sa The address of the machine we wish to connect to.
|
||||
* Unused for NT Pipes.
|
||||
* @return the operation status
|
||||
*/
|
||||
public static native int connect(long sock, long sa);
|
||||
|
||||
}
|
||||
131
java/org/apache/tomcat/jni/Lock.java
Normal file
131
java/org/apache/tomcat/jni/Lock.java
Normal file
@@ -0,0 +1,131 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.apache.tomcat.jni;
|
||||
|
||||
/** Lock
|
||||
*
|
||||
* @author Mladen Turk
|
||||
*/
|
||||
public class Lock {
|
||||
|
||||
/**
|
||||
* Enumerated potential types for APR process locking methods
|
||||
* <br><b>Warning :</b> Check APR_HAS_foo_SERIALIZE defines to see if the platform supports
|
||||
* APR_LOCK_foo. Only APR_LOCK_DEFAULT is portable.
|
||||
*/
|
||||
|
||||
public static final int APR_LOCK_FCNTL = 0; /** fcntl() */
|
||||
public static final int APR_LOCK_FLOCK = 1; /** flock() */
|
||||
public static final int APR_LOCK_SYSVSEM = 2; /** System V Semaphores */
|
||||
public static final int APR_LOCK_PROC_PTHREAD = 3; /** POSIX pthread process-based locking */
|
||||
public static final int APR_LOCK_POSIXSEM = 4; /** POSIX semaphore process-based locking */
|
||||
public static final int APR_LOCK_DEFAULT = 5; /** Use the default process lock */
|
||||
|
||||
/**
|
||||
* Create and initialize a mutex that can be used to synchronize processes.
|
||||
* <br><b>Warning :</b> Check APR_HAS_foo_SERIALIZE defines to see if the platform supports
|
||||
* APR_LOCK_foo. Only APR_LOCK_DEFAULT is portable.
|
||||
* @param fname A file name to use if the lock mechanism requires one. This
|
||||
* argument should always be provided. The lock code itself will
|
||||
* determine if it should be used.
|
||||
* @param mech The mechanism to use for the interprocess lock, if any; one of
|
||||
* <PRE>
|
||||
* APR_LOCK_FCNTL
|
||||
* APR_LOCK_FLOCK
|
||||
* APR_LOCK_SYSVSEM
|
||||
* APR_LOCK_POSIXSEM
|
||||
* APR_LOCK_PROC_PTHREAD
|
||||
* APR_LOCK_DEFAULT pick the default mechanism for the platform
|
||||
* </PRE>
|
||||
* @param pool the pool from which to allocate the mutex.
|
||||
* @return Newly created mutex.
|
||||
* @throws Error An error occurred
|
||||
*/
|
||||
public static native long create(String fname, int mech, long pool)
|
||||
throws Error;
|
||||
|
||||
/**
|
||||
* Re-open a mutex in a child process.
|
||||
* This function must be called to maintain portability, even
|
||||
* if the underlying lock mechanism does not require it.
|
||||
* @param fname A file name to use if the mutex mechanism requires one. This
|
||||
* argument should always be provided. The mutex code itself will
|
||||
* determine if it should be used. This filename should be the
|
||||
* same one that was passed to apr_proc_mutex_create().
|
||||
* @param pool The pool to operate on.
|
||||
* @return Newly opened mutex.
|
||||
* @throws Error An error occurred
|
||||
*/
|
||||
public static native long childInit(String fname, long pool)
|
||||
throws Error;
|
||||
|
||||
/**
|
||||
* Acquire the lock for the given mutex. If the mutex is already locked,
|
||||
* the current thread will be put to sleep until the lock becomes available.
|
||||
* @param mutex the mutex on which to acquire the lock.
|
||||
* @return the operation status
|
||||
*/
|
||||
public static native int lock(long mutex);
|
||||
|
||||
/**
|
||||
* Attempt to acquire the lock for the given mutex. If the mutex has already
|
||||
* been acquired, the call returns immediately with APR_EBUSY. Note: it
|
||||
* is important that the APR_STATUS_IS_EBUSY(s) macro be used to determine
|
||||
* if the return value was APR_EBUSY, for portability reasons.
|
||||
* @param mutex the mutex on which to attempt the lock acquiring.
|
||||
* @return the operation status
|
||||
*/
|
||||
public static native int trylock(long mutex);
|
||||
|
||||
/**
|
||||
* Release the lock for the given mutex.
|
||||
* @param mutex the mutex from which to release the lock.
|
||||
* @return the operation status
|
||||
*/
|
||||
public static native int unlock(long mutex);
|
||||
|
||||
/**
|
||||
* Destroy the mutex and free the memory associated with the lock.
|
||||
* @param mutex the mutex to destroy.
|
||||
* @return the operation status
|
||||
*/
|
||||
public static native int destroy(long mutex);
|
||||
|
||||
/**
|
||||
* Return the name of the lockfile for the mutex, or NULL
|
||||
* if the mutex doesn't use a lock file
|
||||
* @param mutex the name of the mutex
|
||||
* @return the name of the lock file
|
||||
*/
|
||||
public static native String lockfile(long mutex);
|
||||
|
||||
/**
|
||||
* Display the name of the mutex, as it relates to the actual method used.
|
||||
* This matches the valid options for Apache's AcceptMutex directive
|
||||
* @param mutex the name of the mutex
|
||||
* @return the name of the mutex
|
||||
*/
|
||||
public static native String name(long mutex);
|
||||
|
||||
/**
|
||||
* Display the name of the default mutex: APR_LOCK_DEFAULT
|
||||
* @return the default name
|
||||
*/
|
||||
public static native String defname();
|
||||
|
||||
}
|
||||
75
java/org/apache/tomcat/jni/Mmap.java
Normal file
75
java/org/apache/tomcat/jni/Mmap.java
Normal file
@@ -0,0 +1,75 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.apache.tomcat.jni;
|
||||
|
||||
/** Mmap
|
||||
*
|
||||
* @author Mladen Turk
|
||||
*/
|
||||
public class Mmap {
|
||||
/** MMap opened for reading */
|
||||
public static final int APR_MMAP_READ = 1;
|
||||
/** MMap opened for writing */
|
||||
public static final int APR_MMAP_WRITE = 2;
|
||||
|
||||
|
||||
/**
|
||||
* Create a new mmap'ed file out of an existing APR file.
|
||||
* @param file The file turn into an mmap.
|
||||
* @param offset The offset into the file to start the data pointer at.
|
||||
* @param size The size of the file
|
||||
* @param flag bit-wise or of:
|
||||
* <PRE>
|
||||
* APR_MMAP_READ MMap opened for reading
|
||||
* APR_MMAP_WRITE MMap opened for writing
|
||||
* </PRE>
|
||||
* @param pool The pool to use when creating the mmap.
|
||||
* @return The newly created mmap'ed file.
|
||||
* @throws Error Error creating memory mapping
|
||||
*/
|
||||
public static native long create(long file, long offset, long size, int flag, long pool)
|
||||
throws Error;
|
||||
|
||||
/**
|
||||
* Duplicate the specified MMAP.
|
||||
* @param mmap The mmap to duplicate.
|
||||
* @param pool The pool to use for new_mmap.
|
||||
* @return Duplicated mmap'ed file.
|
||||
* @throws Error Error duplicating memory mapping
|
||||
*/
|
||||
public static native long dup(long mmap, long pool)
|
||||
throws Error;
|
||||
|
||||
/**
|
||||
* Remove a mmap'ed.
|
||||
* @param mm The mmap'ed file.
|
||||
* @return the operation status
|
||||
*/
|
||||
public static native int delete(long mm);
|
||||
|
||||
/**
|
||||
* Move the pointer into the mmap'ed file to the specified offset.
|
||||
* @param mm The mmap'ed file.
|
||||
* @param offset The offset to move to.
|
||||
* @return The pointer to the offset specified.
|
||||
* @throws Error Error reading file
|
||||
*/
|
||||
public static native long offset(long mm, long offset)
|
||||
throws Error;
|
||||
|
||||
}
|
||||
81
java/org/apache/tomcat/jni/Multicast.java
Normal file
81
java/org/apache/tomcat/jni/Multicast.java
Normal file
@@ -0,0 +1,81 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.apache.tomcat.jni;
|
||||
|
||||
/** Multicast
|
||||
*
|
||||
* @author Mladen Turk
|
||||
*/
|
||||
public class Multicast {
|
||||
|
||||
/**
|
||||
* Join a Multicast Group
|
||||
* @param sock The socket to join a multicast group
|
||||
* @param join The address of the multicast group to join
|
||||
* @param iface Address of the interface to use. If NULL is passed, the
|
||||
* default multicast interface will be used. (OS Dependent)
|
||||
* @param source Source Address to accept transmissions from (non-NULL
|
||||
* implies Source-Specific Multicast)
|
||||
* @return the operation status
|
||||
*/
|
||||
public static native int join(long sock, long join,
|
||||
long iface, long source);
|
||||
|
||||
/**
|
||||
* Leave a Multicast Group. All arguments must be the same as
|
||||
* apr_mcast_join.
|
||||
* @param sock The socket to leave a multicast group
|
||||
* @param addr The address of the multicast group to leave
|
||||
* @param iface Address of the interface to use. If NULL is passed, the
|
||||
* default multicast interface will be used. (OS Dependent)
|
||||
* @param source Source Address to accept transmissions from (non-NULL
|
||||
* implies Source-Specific Multicast)
|
||||
* @return the operation status
|
||||
*/
|
||||
public static native int leave(long sock, long addr,
|
||||
long iface, long source);
|
||||
|
||||
/**
|
||||
* Set the Multicast Time to Live (ttl) for a multicast transmission.
|
||||
* @param sock The socket to set the multicast ttl
|
||||
* @param ttl Time to live to Assign. 0-255, default=1
|
||||
* <br><b>Remark :</b> If the TTL is 0, packets will only be seen
|
||||
* by sockets on the local machine,
|
||||
* and only when multicast loopback is enabled.
|
||||
* @return the operation status
|
||||
*/
|
||||
public static native int hops(long sock, int ttl);
|
||||
|
||||
/**
|
||||
* Toggle IP Multicast Loopback
|
||||
* @param sock The socket to set multicast loopback
|
||||
* @param opt false=disable, true=enable
|
||||
* @return the operation status
|
||||
*/
|
||||
public static native int loopback(long sock, boolean opt);
|
||||
|
||||
|
||||
/**
|
||||
* Set the Interface to be used for outgoing Multicast Transmissions.
|
||||
* @param sock The socket to set the multicast interface on
|
||||
* @param iface Address of the interface to use for Multicast
|
||||
* @return the operation status
|
||||
*/
|
||||
public static native int ointerface(long sock, long iface);
|
||||
|
||||
}
|
||||
132
java/org/apache/tomcat/jni/OS.java
Normal file
132
java/org/apache/tomcat/jni/OS.java
Normal file
@@ -0,0 +1,132 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.apache.tomcat.jni;
|
||||
|
||||
/** OS
|
||||
*
|
||||
* @author Mladen Turk
|
||||
*/
|
||||
public class OS {
|
||||
|
||||
/* OS Enums */
|
||||
private static final int UNIX = 1;
|
||||
private static final int NETWARE = 2;
|
||||
private static final int WIN32 = 3;
|
||||
private static final int WIN64 = 4;
|
||||
private static final int LINUX = 5;
|
||||
private static final int SOLARIS = 6;
|
||||
private static final int BSD = 7;
|
||||
private static final int MACOSX = 8;
|
||||
|
||||
public static final int LOG_EMERG = 1;
|
||||
public static final int LOG_ERROR = 2;
|
||||
public static final int LOG_NOTICE = 3;
|
||||
public static final int LOG_WARN = 4;
|
||||
public static final int LOG_INFO = 5;
|
||||
public static final int LOG_DEBUG = 6;
|
||||
|
||||
/**
|
||||
* Check for OS type.
|
||||
* @param type OS type to test.
|
||||
*/
|
||||
private static native boolean is(int type);
|
||||
|
||||
public static final boolean IS_UNIX = is(UNIX);
|
||||
public static final boolean IS_NETWARE = is(NETWARE);
|
||||
public static final boolean IS_WIN32 = is(WIN32);
|
||||
public static final boolean IS_WIN64 = is(WIN64);
|
||||
public static final boolean IS_LINUX = is(LINUX);
|
||||
public static final boolean IS_SOLARIS = is(SOLARIS);
|
||||
public static final boolean IS_BSD = is(BSD);
|
||||
public static final boolean IS_MACOSX = is(MACOSX);
|
||||
|
||||
/**
|
||||
* Get the name of the system default character set.
|
||||
* @param pool the pool to allocate the name from, if needed
|
||||
* @return the encoding
|
||||
*/
|
||||
public static native String defaultEncoding(long pool);
|
||||
|
||||
/**
|
||||
* Get the name of the current locale character set.
|
||||
* Defers to apr_os_default_encoding if the current locale's
|
||||
* data can't be retrieved on this system.
|
||||
* @param pool the pool to allocate the name from, if needed
|
||||
* @return the encoding
|
||||
*/
|
||||
public static native String localeEncoding(long pool);
|
||||
|
||||
/**
|
||||
* Generate random bytes.
|
||||
* @param buf Buffer to fill with random bytes
|
||||
* @param len Length of buffer in bytes
|
||||
* @return the operation status
|
||||
*/
|
||||
public static native int random(byte [] buf, int len);
|
||||
|
||||
/**
|
||||
* Gather system info.
|
||||
* <PRE>
|
||||
* On exit the inf array will be filled with:
|
||||
* inf[0] - Total usable main memory size
|
||||
* inf[1] - Available memory size
|
||||
* inf[2] - Total page file/swap space size
|
||||
* inf[3] - Page file/swap space still available
|
||||
* inf[4] - Amount of shared memory
|
||||
* inf[5] - Memory used by buffers
|
||||
* inf[6] - Memory Load
|
||||
*
|
||||
* inf[7] - Idle Time in microseconds
|
||||
* inf[8] - Kernel Time in microseconds
|
||||
* inf[9] - User Time in microseconds
|
||||
*
|
||||
* inf[10] - Process creation time (apr_time_t)
|
||||
* inf[11] - Process Kernel Time in microseconds
|
||||
* inf[12] - Process User Time in microseconds
|
||||
*
|
||||
* inf[13] - Current working set size.
|
||||
* inf[14] - Peak working set size.
|
||||
* inf[15] - Number of page faults.
|
||||
* </PRE>
|
||||
* @param inf array that will be filled with system information.
|
||||
* Array length must be at least 16.
|
||||
* @return the operation status
|
||||
*/
|
||||
public static native int info(long [] inf);
|
||||
|
||||
/**
|
||||
* Expand environment variables.
|
||||
* @param str String to expand
|
||||
* @return Expanded string with replaced environment variables.
|
||||
*/
|
||||
public static native String expand(String str);
|
||||
|
||||
/**
|
||||
* Initialize system logging.
|
||||
* @param domain String that will be prepended to every message
|
||||
*/
|
||||
public static native void sysloginit(String domain);
|
||||
|
||||
/**
|
||||
* Log message.
|
||||
* @param level Log message severity. See LOG_XXX enums.
|
||||
* @param message Message to log
|
||||
*/
|
||||
public static native void syslog(int level, String message);
|
||||
|
||||
}
|
||||
32
java/org/apache/tomcat/jni/PasswordCallback.java
Normal file
32
java/org/apache/tomcat/jni/PasswordCallback.java
Normal file
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.apache.tomcat.jni;
|
||||
|
||||
/** PasswordCallback Interface
|
||||
*
|
||||
* @author Mladen Turk
|
||||
*/
|
||||
public interface PasswordCallback {
|
||||
|
||||
/**
|
||||
* Called when the password is required
|
||||
* @param prompt Password prompt
|
||||
* @return Valid password or null
|
||||
*/
|
||||
public String callback(String prompt);
|
||||
}
|
||||
188
java/org/apache/tomcat/jni/Poll.java
Normal file
188
java/org/apache/tomcat/jni/Poll.java
Normal file
@@ -0,0 +1,188 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.apache.tomcat.jni;
|
||||
|
||||
/** Poll
|
||||
*
|
||||
* @author Mladen Turk
|
||||
*/
|
||||
public class Poll {
|
||||
|
||||
/**
|
||||
* Poll return values
|
||||
*/
|
||||
/** Can read without blocking */
|
||||
public static final int APR_POLLIN = 0x001;
|
||||
/** Priority data available */
|
||||
public static final int APR_POLLPRI = 0x002;
|
||||
/** Can write without blocking */
|
||||
public static final int APR_POLLOUT = 0x004;
|
||||
/** Pending error */
|
||||
public static final int APR_POLLERR = 0x010;
|
||||
/** Hangup occurred */
|
||||
public static final int APR_POLLHUP = 0x020;
|
||||
/** Descriptor invalid */
|
||||
public static final int APR_POLLNVAL = 0x040;
|
||||
|
||||
/**
|
||||
* Pollset Flags
|
||||
*/
|
||||
/** Adding or Removing a Descriptor is thread safe */
|
||||
public static final int APR_POLLSET_THREADSAFE = 0x001;
|
||||
|
||||
|
||||
/** Used in apr_pollfd_t to determine what the apr_descriptor is
|
||||
* apr_datatype_e enum
|
||||
*/
|
||||
public static final int APR_NO_DESC = 0; /** nothing here */
|
||||
public static final int APR_POLL_SOCKET = 1; /** descriptor refers to a socket */
|
||||
public static final int APR_POLL_FILE = 2; /** descriptor refers to a file */
|
||||
public static final int APR_POLL_LASTDESC = 3; /** descriptor is the last one in the list */
|
||||
|
||||
/**
|
||||
* Setup a pollset object.
|
||||
* If flags equals APR_POLLSET_THREADSAFE, then a pollset is
|
||||
* created on which it is safe to make concurrent calls to
|
||||
* apr_pollset_add(), apr_pollset_remove() and apr_pollset_poll() from
|
||||
* separate threads. This feature is only supported on some
|
||||
* platforms; the apr_pollset_create() call will fail with
|
||||
* APR_ENOTIMPL on platforms where it is not supported.
|
||||
* @param size The maximum number of descriptors that this pollset can hold
|
||||
* @param p The pool from which to allocate the pollset
|
||||
* @param flags Optional flags to modify the operation of the pollset.
|
||||
* @param ttl Maximum time to live for a particular socket.
|
||||
* @return The pointer in which to return the newly created object
|
||||
* @throws Error Pollset creation failed
|
||||
*/
|
||||
public static native long create(int size, long p, int flags, long ttl)
|
||||
throws Error;
|
||||
/**
|
||||
* Destroy a pollset object
|
||||
* @param pollset The pollset to destroy
|
||||
* @return the operation status
|
||||
*/
|
||||
public static native int destroy(long pollset);
|
||||
|
||||
/**
|
||||
* Add a socket to a pollset with the default timeout.
|
||||
* @param pollset The pollset to which to add the socket
|
||||
* @param sock The sockets to add
|
||||
* @param reqevents requested events
|
||||
* @return the operation status
|
||||
*/
|
||||
public static native int add(long pollset, long sock,
|
||||
int reqevents);
|
||||
|
||||
/**
|
||||
* Add a socket to a pollset with a specific timeout.
|
||||
* @param pollset The pollset to which to add the socket
|
||||
* @param sock The sockets to add
|
||||
* @param reqevents requested events
|
||||
* @param timeout requested timeout in microseconds (-1 for infinite)
|
||||
* @return the operation status
|
||||
*/
|
||||
public static native int addWithTimeout(long pollset, long sock,
|
||||
int reqevents, long timeout);
|
||||
|
||||
/**
|
||||
* Remove a descriptor from a pollset
|
||||
* @param pollset The pollset from which to remove the descriptor
|
||||
* @param sock The socket to remove
|
||||
* @return the operation status
|
||||
*/
|
||||
public static native int remove(long pollset, long sock);
|
||||
|
||||
/**
|
||||
* Block for activity on the descriptor(s) in a pollset
|
||||
* @param pollset The pollset to use
|
||||
* @param timeout Timeout in microseconds
|
||||
* @param descriptors Array of signaled descriptors (output parameter)
|
||||
* The descriptor array must be two times the size of pollset.
|
||||
* and are populated as follows:
|
||||
* <PRE>
|
||||
* descriptors[2n + 0] -> returned events
|
||||
* descriptors[2n + 1] -> socket
|
||||
* </PRE>
|
||||
* @param remove Remove signaled descriptors from pollset
|
||||
* @return Number of signaled descriptors (output parameter)
|
||||
* or negative APR error code.
|
||||
*/
|
||||
public static native int poll(long pollset, long timeout,
|
||||
long [] descriptors, boolean remove);
|
||||
|
||||
/**
|
||||
* Maintain on the descriptor(s) in a pollset
|
||||
* @param pollset The pollset to use
|
||||
* @param descriptors Array of signaled descriptors (output parameter)
|
||||
* The descriptor array must be the size of pollset.
|
||||
* and are populated as follows:
|
||||
* <PRE>
|
||||
* descriptors[n] -> socket
|
||||
* </PRE>
|
||||
* @param remove Remove signaled descriptors from pollset
|
||||
* @return Number of signaled descriptors (output parameter)
|
||||
* or negative APR error code.
|
||||
*/
|
||||
public static native int maintain(long pollset, long [] descriptors,
|
||||
boolean remove);
|
||||
|
||||
/**
|
||||
* Set the socket time to live.
|
||||
* @param pollset The pollset to use
|
||||
* @param ttl Timeout in microseconds
|
||||
*/
|
||||
public static native void setTtl(long pollset, long ttl);
|
||||
|
||||
/**
|
||||
* Get the socket time to live.
|
||||
* @param pollset The pollset to use
|
||||
* @return Timeout in microseconds
|
||||
*/
|
||||
public static native long getTtl(long pollset);
|
||||
|
||||
/**
|
||||
* Return all descriptor(s) in a pollset
|
||||
* @param pollset The pollset to use
|
||||
* @param descriptors Array of descriptors (output parameter)
|
||||
* The descriptor array must be two times the size of pollset.
|
||||
* and are populated as follows:
|
||||
* <PRE>
|
||||
* descriptors[2n + 0] -> returned events
|
||||
* descriptors[2n + 1] -> socket
|
||||
* </PRE>
|
||||
* @return Number of descriptors (output parameter) in the Poll
|
||||
* or negative APR error code.
|
||||
*/
|
||||
public static native int pollset(long pollset, long [] descriptors);
|
||||
|
||||
/**
|
||||
* Make poll() return.
|
||||
*
|
||||
* @param pollset The pollset to use
|
||||
* @return Negative APR error code
|
||||
*/
|
||||
public static native int interrupt(long pollset);
|
||||
|
||||
/**
|
||||
* Check if interrupt() is allowed.
|
||||
*
|
||||
* @param pollset The pollset to use
|
||||
* @return <code>true</code> if {@link #interrupt(long)} is allowed, else
|
||||
* <code>false</code>
|
||||
*/
|
||||
public static native boolean wakeable(long pollset);
|
||||
}
|
||||
163
java/org/apache/tomcat/jni/Pool.java
Normal file
163
java/org/apache/tomcat/jni/Pool.java
Normal file
@@ -0,0 +1,163 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.apache.tomcat.jni;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
/** Pool
|
||||
*
|
||||
* @author Mladen Turk
|
||||
*/
|
||||
public class Pool {
|
||||
|
||||
/**
|
||||
* Create a new pool.
|
||||
* @param parent The parent pool. If this is 0, the new pool is a root
|
||||
* pool. If it is non-zero, the new pool will inherit all
|
||||
* of its parent pool's attributes, except the apr_pool_t will
|
||||
* be a sub-pool.
|
||||
* @return The pool we have just created.
|
||||
*/
|
||||
public static native long create(long parent);
|
||||
|
||||
/**
|
||||
* Clear all memory in the pool and run all the cleanups. This also destroys all
|
||||
* subpools.
|
||||
* @param pool The pool to clear
|
||||
* This does not actually free the memory, it just allows the pool
|
||||
* to re-use this memory for the next allocation.
|
||||
*/
|
||||
public static native void clear(long pool);
|
||||
|
||||
/**
|
||||
* Destroy the pool. This takes similar action as apr_pool_clear() and then
|
||||
* frees all the memory.
|
||||
* This will actually free the memory
|
||||
* @param pool The pool to destroy
|
||||
*/
|
||||
public static native void destroy(long pool);
|
||||
|
||||
/**
|
||||
* Get the parent pool of the specified pool.
|
||||
* @param pool The pool for retrieving the parent pool.
|
||||
* @return The parent of the given pool.
|
||||
*/
|
||||
public static native long parentGet(long pool);
|
||||
|
||||
/**
|
||||
* Determine if pool a is an ancestor of pool b
|
||||
* @param a The pool to search
|
||||
* @param b The pool to search for
|
||||
* @return True if a is an ancestor of b, NULL is considered an ancestor
|
||||
* of all pools.
|
||||
*/
|
||||
public static native boolean isAncestor(long a, long b);
|
||||
|
||||
|
||||
/*
|
||||
* Cleanup
|
||||
*
|
||||
* Cleanups are performed in the reverse order they were registered. That is:
|
||||
* Last In, First Out. A cleanup function can safely allocate memory from
|
||||
* the pool that is being cleaned up. It can also safely register additional
|
||||
* cleanups which will be run LIFO, directly after the current cleanup
|
||||
* terminates. Cleanups have to take caution in calling functions that
|
||||
* create subpools. Subpools, created during cleanup will NOT automatically
|
||||
* be cleaned up. In other words, cleanups are to clean up after themselves.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Register a function to be called when a pool is cleared or destroyed
|
||||
* @param pool The pool register the cleanup with
|
||||
* @param o The object to call when the pool is cleared
|
||||
* or destroyed
|
||||
* @return The cleanup handler.
|
||||
*/
|
||||
public static native long cleanupRegister(long pool, Object o);
|
||||
|
||||
/**
|
||||
* Remove a previously registered cleanup function
|
||||
* @param pool The pool remove the cleanup from
|
||||
* @param data The cleanup handler to remove from cleanup
|
||||
*/
|
||||
public static native void cleanupKill(long pool, long data);
|
||||
|
||||
/**
|
||||
* Register a process to be killed when a pool dies.
|
||||
* @param a The pool to use to define the processes lifetime
|
||||
* @param proc The process to register
|
||||
* @param how How to kill the process, one of:
|
||||
* <PRE>
|
||||
* APR_KILL_NEVER -- process is never sent any signals
|
||||
* APR_KILL_ALWAYS -- process is sent SIGKILL on apr_pool_t cleanup
|
||||
* APR_KILL_AFTER_TIMEOUT -- SIGTERM, wait 3 seconds, SIGKILL
|
||||
* APR_JUST_WAIT -- wait forever for the process to complete
|
||||
* APR_KILL_ONLY_ONCE -- send SIGTERM and then wait
|
||||
* </PRE>
|
||||
*/
|
||||
public static native void noteSubprocess(long a, long proc, int how);
|
||||
|
||||
/**
|
||||
* Allocate a block of memory from a pool
|
||||
* @param p The pool to allocate from
|
||||
* @param size The amount of memory to allocate
|
||||
* @return The ByteBuffer with allocated memory
|
||||
*/
|
||||
public static native ByteBuffer alloc(long p, int size);
|
||||
|
||||
/**
|
||||
* Allocate a block of memory from a pool and set all of the memory to 0
|
||||
* @param p The pool to allocate from
|
||||
* @param size The amount of memory to allocate
|
||||
* @return The ByteBuffer with allocated memory
|
||||
*/
|
||||
public static native ByteBuffer calloc(long p, int size);
|
||||
|
||||
/*
|
||||
* User data management
|
||||
*/
|
||||
|
||||
/**
|
||||
* Set the data associated with the current pool
|
||||
* @param data The user data associated with the pool.
|
||||
* @param key The key to use for association
|
||||
* @param pool The current pool
|
||||
* <br><b>Warning :</b>
|
||||
* The data to be attached to the pool should have a life span
|
||||
* at least as long as the pool it is being attached to.
|
||||
* Object attached to the pool will be globally referenced
|
||||
* until the pool is cleared or dataSet is called with the null data.
|
||||
* @return APR Status code.
|
||||
*/
|
||||
public static native int dataSet(long pool, String key, Object data);
|
||||
|
||||
/**
|
||||
* Return the data associated with the current pool.
|
||||
* @param key The key for the data to retrieve
|
||||
* @param pool The current pool.
|
||||
* @return the data
|
||||
*/
|
||||
public static native Object dataGet(long pool, String key);
|
||||
|
||||
/**
|
||||
* Run all of the child_cleanups, so that any unnecessary files are
|
||||
* closed because we are about to exec a new program
|
||||
*/
|
||||
public static native void cleanupForExec();
|
||||
|
||||
}
|
||||
31
java/org/apache/tomcat/jni/PoolCallback.java
Normal file
31
java/org/apache/tomcat/jni/PoolCallback.java
Normal file
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.apache.tomcat.jni;
|
||||
|
||||
/** PoolCallback Interface
|
||||
*
|
||||
* @author Mladen Turk
|
||||
*/
|
||||
public interface PoolCallback {
|
||||
|
||||
/**
|
||||
* Called when the pool is destroyed or cleared
|
||||
* @return Function must return APR_SUCCESS
|
||||
*/
|
||||
public int callback();
|
||||
}
|
||||
213
java/org/apache/tomcat/jni/Proc.java
Normal file
213
java/org/apache/tomcat/jni/Proc.java
Normal file
@@ -0,0 +1,213 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.apache.tomcat.jni;
|
||||
|
||||
/** Proc
|
||||
*
|
||||
* @author Mladen Turk
|
||||
*/
|
||||
public class Proc {
|
||||
|
||||
/*
|
||||
* apr_cmdtype_e enum
|
||||
*/
|
||||
public static final int APR_SHELLCM = 0; /** use the shell to invoke the program */
|
||||
public static final int APR_PROGRAM = 1; /** invoke the program directly, no copied env */
|
||||
public static final int APR_PROGRAM_ENV = 2; /** invoke the program, replicating our environment */
|
||||
public static final int APR_PROGRAM_PATH = 3; /** find program on PATH, use our environment */
|
||||
public static final int APR_SHELLCMD_ENV = 4; /** use the shell to invoke the program,
|
||||
* replicating our environment
|
||||
*/
|
||||
|
||||
/*
|
||||
* apr_wait_how_e enum
|
||||
*/
|
||||
public static final int APR_WAIT = 0; /** wait for the specified process to finish */
|
||||
public static final int APR_NOWAIT = 1; /** do not wait -- just see if it has finished */
|
||||
|
||||
/*
|
||||
* apr_exit_why_e enum
|
||||
*/
|
||||
public static final int APR_PROC_EXIT = 1; /** process exited normally */
|
||||
public static final int APR_PROC_SIGNAL = 2; /** process exited due to a signal */
|
||||
public static final int APR_PROC_SIGNAL_CORE = 4; /** process exited and dumped a core file */
|
||||
|
||||
public static final int APR_NO_PIPE = 0;
|
||||
public static final int APR_FULL_BLOCK = 1;
|
||||
public static final int APR_FULL_NONBLOCK = 2;
|
||||
public static final int APR_PARENT_BLOCK = 3;
|
||||
public static final int APR_CHILD_BLOCK = 4;
|
||||
|
||||
public static final int APR_LIMIT_CPU = 0;
|
||||
public static final int APR_LIMIT_MEM = 1;
|
||||
public static final int APR_LIMIT_NPROC = 2;
|
||||
public static final int APR_LIMIT_NOFILE = 3;
|
||||
|
||||
|
||||
/** child has died, caller must call unregister still */
|
||||
public static final int APR_OC_REASON_DEATH = 0;
|
||||
/** write_fd is unwritable */
|
||||
public static final int APR_OC_REASON_UNWRITABLE = 1;
|
||||
/** a restart is occurring, perform any necessary cleanup (including
|
||||
* sending a special signal to child)
|
||||
*/
|
||||
public static final int APR_OC_REASON_RESTART = 2;
|
||||
/** unregister has been called, do whatever is necessary (including
|
||||
* kill the child)
|
||||
*/
|
||||
public static final int APR_OC_REASON_UNREGISTER = 3;
|
||||
/** somehow the child exited without us knowing ... buggy os? */
|
||||
public static final int APR_OC_REASON_LOST = 4;
|
||||
/** a health check is occurring, for most maintenance functions
|
||||
* this is a no-op.
|
||||
*/
|
||||
public static final int APR_OC_REASON_RUNNING = 5;
|
||||
|
||||
/* apr_kill_conditions_e enumeration */
|
||||
/** process is never sent any signals */
|
||||
public static final int APR_KILL_NEVER = 0;
|
||||
/** process is sent SIGKILL on apr_pool_t cleanup */
|
||||
public static final int APR_KILL_ALWAYS = 1;
|
||||
/** SIGTERM, wait 3 seconds, SIGKILL */
|
||||
public static final int APR_KILL_AFTER_TIMEOUT = 2;
|
||||
/** wait forever for the process to complete */
|
||||
public static final int APR_JUST_WAIT = 3;
|
||||
/** send SIGTERM and then wait */
|
||||
public static final int APR_KILL_ONLY_ONCE = 4;
|
||||
|
||||
public static final int APR_PROC_DETACH_FOREGROUND = 0; /** Do not detach */
|
||||
public static final int APR_PROC_DETACH_DAEMONIZE = 1; /** Detach */
|
||||
|
||||
/* Maximum number of arguments for create process call */
|
||||
public static final int MAX_ARGS_SIZE = 1024;
|
||||
/* Maximum number of environment variables for create process call */
|
||||
public static final int MAX_ENV_SIZE = 1024;
|
||||
|
||||
/**
|
||||
* Allocate apr_proc_t structure from pool
|
||||
* This is not an apr function.
|
||||
* @param cont The pool to use.
|
||||
* @return the pointer
|
||||
*/
|
||||
public static native long alloc(long cont);
|
||||
|
||||
/**
|
||||
* This is currently the only non-portable call in APR. This executes
|
||||
* a standard unix fork.
|
||||
* @param proc The resulting process handle.
|
||||
* @param cont The pool to use.
|
||||
* @return APR_INCHILD for the child, and APR_INPARENT for the parent
|
||||
* or an error.
|
||||
*/
|
||||
public static native int fork(long [] proc, long cont);
|
||||
|
||||
/**
|
||||
* Create a new process and execute a new program within that process.
|
||||
* This function returns without waiting for the new process to terminate;
|
||||
* use apr_proc_wait for that.
|
||||
* @param proc The process handle
|
||||
* @param progname The program to run
|
||||
* @param args The arguments to pass to the new program. The first
|
||||
* one should be the program name.
|
||||
* @param env The new environment table for the new process. This
|
||||
* should be a list of NULL-terminated strings. This argument
|
||||
* is ignored for APR_PROGRAM_ENV, APR_PROGRAM_PATH, and
|
||||
* APR_SHELLCMD_ENV types of commands.
|
||||
* @param attr The procattr we should use to determine how to create the new
|
||||
* process
|
||||
* @param pool The pool to use.
|
||||
* @return The resulting process handle.
|
||||
*/
|
||||
public static native int create(long proc, String progname,
|
||||
String [] args, String [] env,
|
||||
long attr, long pool);
|
||||
|
||||
/**
|
||||
* Wait for a child process to die
|
||||
* @param proc The process handle that corresponds to the desired child process
|
||||
* @param exit exit[0] The returned exit status of the child, if a child process
|
||||
* dies, or the signal that caused the child to die.
|
||||
* On platforms that don't support obtaining this information,
|
||||
* the status parameter will be returned as APR_ENOTIMPL.
|
||||
* exit[1] Why the child died, the bitwise or of:
|
||||
* <PRE>
|
||||
* APR_PROC_EXIT -- process terminated normally
|
||||
* APR_PROC_SIGNAL -- process was killed by a signal
|
||||
* APR_PROC_SIGNAL_CORE -- process was killed by a signal, and
|
||||
* generated a core dump.
|
||||
* </PRE>
|
||||
* @param waithow How should we wait. One of:
|
||||
* <PRE>
|
||||
* APR_WAIT -- block until the child process dies.
|
||||
* APR_NOWAIT -- return immediately regardless of if the
|
||||
* child is dead or not.
|
||||
* </PRE>
|
||||
* @return The childs status is in the return code to this process. It is one of:
|
||||
* <PRE>
|
||||
* APR_CHILD_DONE -- child is no longer running.
|
||||
* APR_CHILD_NOTDONE -- child is still running.
|
||||
* </PRE>
|
||||
*/
|
||||
public static native int wait(long proc, int [] exit, int waithow);
|
||||
|
||||
/**
|
||||
* Wait for any current child process to die and return information
|
||||
* about that child.
|
||||
* @param proc Pointer to NULL on entry, will be filled out with child's
|
||||
* information
|
||||
* @param exit exit[0] The returned exit status of the child, if a child process
|
||||
* dies, or the signal that caused the child to die.
|
||||
* On platforms that don't support obtaining this information,
|
||||
* the status parameter will be returned as APR_ENOTIMPL.
|
||||
* exit[1] Why the child died, the bitwise or of:
|
||||
* <PRE>
|
||||
* APR_PROC_EXIT -- process terminated normally
|
||||
* APR_PROC_SIGNAL -- process was killed by a signal
|
||||
* APR_PROC_SIGNAL_CORE -- process was killed by a signal, and
|
||||
* generated a core dump.
|
||||
* </PRE>
|
||||
* @param waithow How should we wait. One of:
|
||||
* <PRE>
|
||||
* APR_WAIT -- block until the child process dies.
|
||||
* APR_NOWAIT -- return immediately regardless of if the
|
||||
* child is dead or not.
|
||||
* </PRE>
|
||||
* @param pool Pool to allocate child information out of.
|
||||
* @return the operation status
|
||||
*/
|
||||
public static native int waitAllProcs(long proc, int [] exit,
|
||||
int waithow, long pool);
|
||||
|
||||
/**
|
||||
* Detach the process from the controlling terminal.
|
||||
* @param daemonize set to non-zero if the process should daemonize
|
||||
* and become a background process, else it will
|
||||
* stay in the foreground.
|
||||
* @return the operation status
|
||||
*/
|
||||
public static native int detach(int daemonize);
|
||||
|
||||
/**
|
||||
* Terminate a process.
|
||||
* @param proc The process to terminate.
|
||||
* @param sig How to kill the process.
|
||||
* @return the operation status
|
||||
*/
|
||||
public static native int kill(long proc, int sig);
|
||||
|
||||
}
|
||||
36
java/org/apache/tomcat/jni/ProcErrorCallback.java
Normal file
36
java/org/apache/tomcat/jni/ProcErrorCallback.java
Normal file
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.apache.tomcat.jni;
|
||||
|
||||
/** ProcErrorCallback Interface
|
||||
*
|
||||
* @author Mladen Turk
|
||||
*/
|
||||
public interface ProcErrorCallback {
|
||||
|
||||
/**
|
||||
* Called in the child process if APR encounters an error
|
||||
* in the child prior to running the specified program.
|
||||
* @param pool Pool associated with the apr_proc_t. If your child
|
||||
* error function needs user data, associate it with this
|
||||
* pool.
|
||||
* @param err APR error code describing the error
|
||||
* @param description Text description of type of processing which failed
|
||||
*/
|
||||
public void callback(long pool, int err, String description);
|
||||
}
|
||||
182
java/org/apache/tomcat/jni/Procattr.java
Normal file
182
java/org/apache/tomcat/jni/Procattr.java
Normal file
@@ -0,0 +1,182 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.apache.tomcat.jni;
|
||||
|
||||
/** Procattr
|
||||
*
|
||||
* @author Mladen Turk
|
||||
*/
|
||||
public class Procattr {
|
||||
|
||||
/**
|
||||
* Create and initialize a new procattr variable
|
||||
* @param cont The pool to use
|
||||
* @return The newly created procattr.
|
||||
* @throws Error An error occurred
|
||||
*/
|
||||
public static native long create(long cont)
|
||||
throws Error;
|
||||
|
||||
/**
|
||||
* Determine if any of stdin, stdout, or stderr should be linked to pipes
|
||||
* when starting a child process.
|
||||
* @param attr The procattr we care about.
|
||||
* @param in Should stdin be a pipe back to the parent?
|
||||
* @param out Should stdout be a pipe back to the parent?
|
||||
* @param err Should stderr be a pipe back to the parent?
|
||||
* @return the operation status
|
||||
*/
|
||||
public static native int ioSet(long attr, int in, int out, int err);
|
||||
|
||||
/**
|
||||
* Set the child_in and/or parent_in values to existing apr_file_t values.
|
||||
* <br>
|
||||
* This is NOT a required initializer function. This is
|
||||
* useful if you have already opened a pipe (or multiple files)
|
||||
* that you wish to use, perhaps persistently across multiple
|
||||
* process invocations - such as a log file. You can save some
|
||||
* extra function calls by not creating your own pipe since this
|
||||
* creates one in the process space for you.
|
||||
* @param attr The procattr we care about.
|
||||
* @param in apr_file_t value to use as child_in. Must be a valid file.
|
||||
* @param parent apr_file_t value to use as parent_in. Must be a valid file.
|
||||
* @return the operation status
|
||||
*/
|
||||
public static native int childInSet(long attr, long in, long parent);
|
||||
|
||||
/**
|
||||
* Set the child_out and parent_out values to existing apr_file_t values.
|
||||
* <br>
|
||||
* This is NOT a required initializer function. This is
|
||||
* useful if you have already opened a pipe (or multiple files)
|
||||
* that you wish to use, perhaps persistently across multiple
|
||||
* process invocations - such as a log file.
|
||||
* @param attr The procattr we care about.
|
||||
* @param out apr_file_t value to use as child_out. Must be a valid file.
|
||||
* @param parent apr_file_t value to use as parent_out. Must be a valid file.
|
||||
* @return the operation status
|
||||
*/
|
||||
public static native int childOutSet(long attr, long out, long parent);
|
||||
|
||||
/**
|
||||
* Set the child_err and parent_err values to existing apr_file_t values.
|
||||
* <br>
|
||||
* This is NOT a required initializer function. This is
|
||||
* useful if you have already opened a pipe (or multiple files)
|
||||
* that you wish to use, perhaps persistently across multiple
|
||||
* process invocations - such as a log file.
|
||||
* @param attr The procattr we care about.
|
||||
* @param err apr_file_t value to use as child_err. Must be a valid file.
|
||||
* @param parent apr_file_t value to use as parent_err. Must be a valid file.
|
||||
* @return the operation status
|
||||
*/
|
||||
public static native int childErrSet(long attr, long err, long parent);
|
||||
|
||||
/**
|
||||
* Set which directory the child process should start executing in.
|
||||
* @param attr The procattr we care about.
|
||||
* @param dir Which dir to start in. By default, this is the same dir as
|
||||
* the parent currently resides in, when the createprocess call
|
||||
* is made.
|
||||
* @return the operation status
|
||||
*/
|
||||
public static native int dirSet(long attr, String dir);
|
||||
|
||||
/**
|
||||
* Set what type of command the child process will call.
|
||||
* @param attr The procattr we care about.
|
||||
* @param cmd The type of command. One of:
|
||||
* <PRE>
|
||||
* APR_SHELLCMD -- Anything that the shell can handle
|
||||
* APR_PROGRAM -- Executable program (default)
|
||||
* APR_PROGRAM_ENV -- Executable program, copy environment
|
||||
* APR_PROGRAM_PATH -- Executable program on PATH, copy env
|
||||
* </PRE>
|
||||
* @return the operation status
|
||||
*/
|
||||
public static native int cmdtypeSet(long attr, int cmd);
|
||||
|
||||
/**
|
||||
* Determine if the child should start in detached state.
|
||||
* @param attr The procattr we care about.
|
||||
* @param detach Should the child start in detached state? Default is no.
|
||||
* @return the operation status
|
||||
*/
|
||||
public static native int detachSet(long attr, int detach);
|
||||
|
||||
/**
|
||||
* Specify that apr_proc_create() should do whatever it can to report
|
||||
* failures to the caller of apr_proc_create(), rather than find out in
|
||||
* the child.
|
||||
* @param attr The procattr describing the child process to be created.
|
||||
* @param chk Flag to indicate whether or not extra work should be done
|
||||
* to try to report failures to the caller.
|
||||
* <br>
|
||||
* This flag only affects apr_proc_create() on platforms where
|
||||
* fork() is used. This leads to extra overhead in the calling
|
||||
* process, but that may help the application handle such
|
||||
* errors more gracefully.
|
||||
* @return the operation status
|
||||
*/
|
||||
public static native int errorCheckSet(long attr, int chk);
|
||||
|
||||
/**
|
||||
* Determine if the child should start in its own address space or using the
|
||||
* current one from its parent
|
||||
* @param attr The procattr we care about.
|
||||
* @param addrspace Should the child start in its own address space? Default
|
||||
* is no on NetWare and yes on other platforms.
|
||||
* @return the operation status
|
||||
*/
|
||||
public static native int addrspaceSet(long attr, int addrspace);
|
||||
|
||||
/**
|
||||
* Specify an error function to be called in the child process if APR
|
||||
* encounters an error in the child prior to running the specified program.
|
||||
* @param attr The procattr describing the child process to be created.
|
||||
* @param pool The the pool to use.
|
||||
* @param o The Object to call in the child process.
|
||||
* <br>
|
||||
* At the present time, it will only be called from apr_proc_create()
|
||||
* on platforms where fork() is used. It will never be called on other
|
||||
* platforms, on those platforms apr_proc_create() will return the error
|
||||
* in the parent process rather than invoke the callback in the now-forked
|
||||
* child process.
|
||||
*/
|
||||
public static native void errfnSet(long attr, long pool, Object o);
|
||||
|
||||
/**
|
||||
* Set the username used for running process
|
||||
* @param attr The procattr we care about.
|
||||
* @param username The username used
|
||||
* @param password User password if needed. Password is needed on WIN32
|
||||
* or any other platform having
|
||||
* APR_PROCATTR_USER_SET_REQUIRES_PASSWORD set.
|
||||
* @return the operation status
|
||||
*/
|
||||
public static native int userSet(long attr, String username, String password);
|
||||
|
||||
/**
|
||||
* Set the group used for running process
|
||||
* @param attr The procattr we care about.
|
||||
* @param groupname The group name used
|
||||
* @return the operation status
|
||||
*/
|
||||
public static native int groupSet(long attr, String groupname);
|
||||
|
||||
}
|
||||
243
java/org/apache/tomcat/jni/Registry.java
Normal file
243
java/org/apache/tomcat/jni/Registry.java
Normal file
@@ -0,0 +1,243 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.apache.tomcat.jni;
|
||||
|
||||
/** Windows Registry support
|
||||
*
|
||||
* @author Mladen Turk
|
||||
*/
|
||||
public class Registry {
|
||||
|
||||
/* Registry Enums */
|
||||
public static final int HKEY_CLASSES_ROOT = 1;
|
||||
public static final int HKEY_CURRENT_CONFIG = 2;
|
||||
public static final int HKEY_CURRENT_USER = 3;
|
||||
public static final int HKEY_LOCAL_MACHINE = 4;
|
||||
public static final int HKEY_USERS = 5;
|
||||
|
||||
public static final int KEY_ALL_ACCESS = 0x0001;
|
||||
public static final int KEY_CREATE_LINK = 0x0002;
|
||||
public static final int KEY_CREATE_SUB_KEY = 0x0004;
|
||||
public static final int KEY_ENUMERATE_SUB_KEYS = 0x0008;
|
||||
public static final int KEY_EXECUTE = 0x0010;
|
||||
public static final int KEY_NOTIFY = 0x0020;
|
||||
public static final int KEY_QUERY_VALUE = 0x0040;
|
||||
public static final int KEY_READ = 0x0080;
|
||||
public static final int KEY_SET_VALUE = 0x0100;
|
||||
public static final int KEY_WOW64_64KEY = 0x0200;
|
||||
public static final int KEY_WOW64_32KEY = 0x0400;
|
||||
public static final int KEY_WRITE = 0x0800;
|
||||
|
||||
public static final int REG_BINARY = 1;
|
||||
public static final int REG_DWORD = 2;
|
||||
public static final int REG_EXPAND_SZ = 3;
|
||||
public static final int REG_MULTI_SZ = 4;
|
||||
public static final int REG_QWORD = 5;
|
||||
public static final int REG_SZ = 6;
|
||||
|
||||
/**
|
||||
* Create or open a Registry Key.
|
||||
* @param name Registry Subkey to open
|
||||
* @param root Root key, one of HKEY_*
|
||||
* @param sam Access mask that specifies the access rights for the key.
|
||||
* @param pool Pool used for native memory allocation
|
||||
* @return Opened Registry key
|
||||
* @throws Error An error occurred
|
||||
*/
|
||||
public static native long create(int root, String name, int sam, long pool)
|
||||
throws Error;
|
||||
|
||||
/**
|
||||
* Opens the specified Registry Key.
|
||||
* @param name Registry Subkey to open
|
||||
* @param root Root key, one of HKEY_*
|
||||
* @param sam Access mask that specifies the access rights for the key.
|
||||
* @param pool Pool used for native memory allocation
|
||||
* @return Opened Registry key
|
||||
* @throws Error An error occurred
|
||||
*/
|
||||
public static native long open(int root, String name, int sam, long pool)
|
||||
throws Error;
|
||||
|
||||
/**
|
||||
* Close the specified Registry key.
|
||||
* @param key The Registry key descriptor to close.
|
||||
* @return the operation status
|
||||
*/
|
||||
public static native int close(long key);
|
||||
|
||||
/**
|
||||
* Get the Registry key type.
|
||||
* @param key The Registry key descriptor to use.
|
||||
* @param name The name of the value to query
|
||||
* @return Value type or negative error value
|
||||
*/
|
||||
public static native int getType(long key, String name);
|
||||
|
||||
/**
|
||||
* Get the Registry value for REG_DWORD
|
||||
* @param key The Registry key descriptor to use.
|
||||
* @param name The name of the value to query
|
||||
* @return Registry key value
|
||||
* @throws Error An error occurred
|
||||
*/
|
||||
public static native int getValueI(long key, String name)
|
||||
throws Error;
|
||||
|
||||
/**
|
||||
* Get the Registry value for REG_QWORD or REG_DWORD
|
||||
* @param key The Registry key descriptor to use.
|
||||
* @param name The name of the value to query
|
||||
* @return Registry key value
|
||||
* @throws Error An error occurred
|
||||
*/
|
||||
public static native long getValueJ(long key, String name)
|
||||
throws Error;
|
||||
|
||||
/**
|
||||
* Get the Registry key length.
|
||||
* @param key The Registry key descriptor to use.
|
||||
* @param name The name of the value to query
|
||||
* @return Value size or negative error value
|
||||
*/
|
||||
public static native int getSize(long key, String name);
|
||||
|
||||
/**
|
||||
* Get the Registry value for REG_SZ or REG_EXPAND_SZ
|
||||
* @param key The Registry key descriptor to use.
|
||||
* @param name The name of the value to query
|
||||
* @return Registry key value
|
||||
* @throws Error An error occurred
|
||||
*/
|
||||
public static native String getValueS(long key, String name)
|
||||
throws Error;
|
||||
|
||||
/**
|
||||
* Get the Registry value for REG_MULTI_SZ
|
||||
* @param key The Registry key descriptor to use.
|
||||
* @param name The name of the value to query
|
||||
* @return Registry key value
|
||||
* @throws Error An error occurred
|
||||
*/
|
||||
public static native String[] getValueA(long key, String name)
|
||||
throws Error;
|
||||
|
||||
/**
|
||||
* Get the Registry value for REG_BINARY
|
||||
* @param key The Registry key descriptor to use.
|
||||
* @param name The name of the value to query
|
||||
* @return Registry key value
|
||||
* @throws Error An error occurred
|
||||
*/
|
||||
public static native byte[] getValueB(long key, String name)
|
||||
throws Error;
|
||||
|
||||
|
||||
/**
|
||||
* Set the Registry value for REG_DWORD
|
||||
* @param key The Registry key descriptor to use.
|
||||
* @param name The name of the value to set
|
||||
* @param val The the value to set
|
||||
* @return If the function succeeds, the return value is 0
|
||||
*/
|
||||
public static native int setValueI(long key, String name, int val);
|
||||
|
||||
/**
|
||||
* Set the Registry value for REG_QWORD
|
||||
* @param key The Registry key descriptor to use.
|
||||
* @param name The name of the value to set
|
||||
* @param val The the value to set
|
||||
* @return If the function succeeds, the return value is 0
|
||||
*/
|
||||
public static native int setValueJ(long key, String name, long val);
|
||||
|
||||
/**
|
||||
* Set the Registry value for REG_SZ
|
||||
* @param key The Registry key descriptor to use.
|
||||
* @param name The name of the value to set
|
||||
* @param val The the value to set
|
||||
* @return If the function succeeds, the return value is 0
|
||||
*/
|
||||
public static native int setValueS(long key, String name, String val);
|
||||
|
||||
/**
|
||||
* Set the Registry value for REG_EXPAND_SZ
|
||||
* @param key The Registry key descriptor to use.
|
||||
* @param name The name of the value to set
|
||||
* @param val The the value to set
|
||||
* @return If the function succeeds, the return value is 0
|
||||
*/
|
||||
public static native int setValueE(long key, String name, String val);
|
||||
|
||||
/**
|
||||
* Set the Registry value for REG_MULTI_SZ
|
||||
* @param key The Registry key descriptor to use.
|
||||
* @param name The name of the value to set
|
||||
* @param val The the value to set
|
||||
* @return If the function succeeds, the return value is 0
|
||||
*/
|
||||
public static native int setValueA(long key, String name, String[] val);
|
||||
|
||||
/**
|
||||
* Set the Registry value for REG_BINARY
|
||||
* @param key The Registry key descriptor to use.
|
||||
* @param name The name of the value to set
|
||||
* @param val The the value to set
|
||||
* @return If the function succeeds, the return value is 0
|
||||
*/
|
||||
public static native int setValueB(long key, String name, byte[] val);
|
||||
|
||||
/**
|
||||
* Enumerate the Registry subkeys
|
||||
* @param key The Registry key descriptor to use.
|
||||
* @return Array of all subkey names
|
||||
* @throws Error An error occurred
|
||||
*/
|
||||
public static native String[] enumKeys(long key)
|
||||
throws Error;
|
||||
|
||||
/**
|
||||
* Enumerate the Registry values
|
||||
* @param key The Registry key descriptor to use.
|
||||
* @return Array of all value names
|
||||
* @throws Error An error occurred
|
||||
*/
|
||||
public static native String[] enumValues(long key)
|
||||
throws Error;
|
||||
|
||||
/**
|
||||
* Delete the Registry value
|
||||
* @param key The Registry key descriptor to use.
|
||||
* @param name The name of the value to delete
|
||||
* @return If the function succeeds, the return value is 0
|
||||
*/
|
||||
public static native int deleteValue(long key, String name);
|
||||
|
||||
/**
|
||||
* Delete the Registry subkey
|
||||
* @param root Root key, one of HKEY_*
|
||||
* @param name Subkey to delete
|
||||
* @param onlyIfEmpty If true will not delete a key if
|
||||
* it contains any subkeys or values
|
||||
* @return If the function succeeds, the return value is 0
|
||||
*/
|
||||
public static native int deleteKey(int root, String name,
|
||||
boolean onlyIfEmpty);
|
||||
|
||||
|
||||
}
|
||||
725
java/org/apache/tomcat/jni/SSL.java
Normal file
725
java/org/apache/tomcat/jni/SSL.java
Normal file
File diff suppressed because it is too large
Load Diff
113
java/org/apache/tomcat/jni/SSLConf.java
Normal file
113
java/org/apache/tomcat/jni/SSLConf.java
Normal file
@@ -0,0 +1,113 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.apache.tomcat.jni;
|
||||
|
||||
/** SSL Conf
|
||||
*/
|
||||
public final class SSLConf {
|
||||
|
||||
/**
|
||||
* Create a new SSL_CONF context.
|
||||
*
|
||||
* @param pool The pool to use.
|
||||
* @param flags The SSL_CONF flags to use. It can be any combination of
|
||||
* the following:
|
||||
* <PRE>
|
||||
* {@link SSL#SSL_CONF_FLAG_CMDLINE}
|
||||
* {@link SSL#SSL_CONF_FLAG_FILE}
|
||||
* {@link SSL#SSL_CONF_FLAG_CLIENT}
|
||||
* {@link SSL#SSL_CONF_FLAG_SERVER}
|
||||
* {@link SSL#SSL_CONF_FLAG_SHOW_ERRORS}
|
||||
* {@link SSL#SSL_CONF_FLAG_CERTIFICATE}
|
||||
* </PRE>
|
||||
*
|
||||
* @return The Java representation of a pointer to the newly created
|
||||
* SSL_CONF Context
|
||||
*
|
||||
* @throws Exception If the SSL_CONF context could not be created
|
||||
*
|
||||
* @see <a href="https://www.openssl.org/docs/man1.0.2/ssl/SSL_CONF_CTX_new.html">OpenSSL SSL_CONF_CTX_new</a>
|
||||
* @see <a href="https://www.openssl.org/docs/man1.0.2/ssl/SSL_CONF_CTX_set_flags.html">OpenSSL SSL_CONF_CTX_set_flags</a>
|
||||
*/
|
||||
public static native long make(long pool, int flags) throws Exception;
|
||||
|
||||
/**
|
||||
* Free the resources used by the context
|
||||
*
|
||||
* @param cctx SSL_CONF context to free.
|
||||
*
|
||||
* @see <a href="https://www.openssl.org/docs/man1.0.2/ssl/SSL_CONF_CTX_new.html">OpenSSL SSL_CONF_CTX_free</a>
|
||||
*/
|
||||
public static native void free(long cctx);
|
||||
|
||||
/**
|
||||
* Check a command with an SSL_CONF context.
|
||||
*
|
||||
* @param cctx SSL_CONF context to use.
|
||||
* @param name command name.
|
||||
* @param value command value.
|
||||
*
|
||||
* @return The result of the check based on the {@code SSL_CONF_cmd_value_type}
|
||||
* call. Unknown types will result in an exception, as well as
|
||||
* file and directory types with invalid file or directory names.
|
||||
*
|
||||
* @throws Exception If the check fails.
|
||||
*
|
||||
* @see <a href="https://www.openssl.org/docs/man1.0.2/ssl/SSL_CONF_cmd.html">OpenSSL SSL_CONF_cmd_value_type</a>
|
||||
*/
|
||||
public static native int check(long cctx, String name, String value) throws Exception;
|
||||
|
||||
/**
|
||||
* Assign an SSL context to an SSL_CONF context.
|
||||
* All following calls to {@link #apply(long, String, String)} will be
|
||||
* applied to this SSL context.
|
||||
*
|
||||
* @param cctx SSL_CONF context to use.
|
||||
* @param ctx SSL context to assign to the given SSL_CONF context.
|
||||
*
|
||||
* @see <a href="https://www.openssl.org/docs/man1.0.2/ssl/SSL_CONF_CTX_set_ssl_ctx.html">OpenSSL SSL_CONF_CTX_set_ssl_ctx</a>
|
||||
*/
|
||||
public static native void assign(long cctx, long ctx);
|
||||
|
||||
/**
|
||||
* Apply a command to an SSL_CONF context.
|
||||
*
|
||||
* @param cctx SSL_CONF context to use.
|
||||
* @param name command name.
|
||||
* @param value command value.
|
||||
*
|
||||
* @return The result of the native {@code SSL_CONF_cmd} call
|
||||
*
|
||||
* @throws Exception If the SSL_CONF context is {@code 0}
|
||||
*
|
||||
* @see <a href="https://www.openssl.org/docs/man1.0.2/ssl/SSL_CONF_cmd.html">OpenSSL SSL_CONF_cmd</a>
|
||||
*/
|
||||
public static native int apply(long cctx, String name, String value) throws Exception;
|
||||
|
||||
/**
|
||||
* Finish commands for an SSL_CONF context.
|
||||
*
|
||||
* @param cctx SSL_CONF context to use.
|
||||
*
|
||||
* @return The result of the native {@code SSL_CONF_CTX_finish} call
|
||||
*
|
||||
* @see <a href="https://www.openssl.org/docs/man1.0.2/ssl/SSL_CONF_CTX_set_flags.html">OpenSSL SSL_CONF_CTX_finish</a>
|
||||
*/
|
||||
public static native int finish(long cctx);
|
||||
|
||||
}
|
||||
584
java/org/apache/tomcat/jni/SSLContext.java
Normal file
584
java/org/apache/tomcat/jni/SSLContext.java
Normal file
File diff suppressed because it is too large
Load Diff
131
java/org/apache/tomcat/jni/SSLSocket.java
Normal file
131
java/org/apache/tomcat/jni/SSLSocket.java
Normal file
@@ -0,0 +1,131 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.apache.tomcat.jni;
|
||||
|
||||
/** SSL Socket
|
||||
*
|
||||
* @author Mladen Turk
|
||||
*/
|
||||
public class SSLSocket {
|
||||
|
||||
/**
|
||||
* Attach APR socket on an SSL connection.
|
||||
* @param ctx SSLContext to use.
|
||||
* @param sock APR Socket that already did physical connect or accept.
|
||||
* @return APR_STATUS code.
|
||||
* @throws Exception An error occurred
|
||||
*/
|
||||
public static native int attach(long ctx, long sock)
|
||||
throws Exception;
|
||||
|
||||
/**
|
||||
* Do an SSL handshake.
|
||||
* @param thesocket The socket to use
|
||||
* @return the handshake status
|
||||
*/
|
||||
public static native int handshake(long thesocket);
|
||||
|
||||
/**
|
||||
* Do an SSL renegotiation.
|
||||
* SSL supports per-directory re-configuration of SSL parameters.
|
||||
* This is implemented by performing an SSL renegotiation of the
|
||||
* re-configured parameters after the request is read, but before the
|
||||
* response is sent. In more detail: the renegotiation happens after the
|
||||
* request line and MIME headers were read, but _before_ the attached
|
||||
* request body is read. The reason simply is that in the HTTP protocol
|
||||
* usually there is no acknowledgment step between the headers and the
|
||||
* body (there is the 100-continue feature and the chunking facility
|
||||
* only), so Apache has no API hook for this step.
|
||||
*
|
||||
* @param thesocket The socket to use
|
||||
* @return the operation status
|
||||
*/
|
||||
public static native int renegotiate(long thesocket);
|
||||
|
||||
/**
|
||||
* Set Type of Client Certificate verification and Maximum depth of CA
|
||||
* Certificates in Client Certificate verification.
|
||||
* <br>
|
||||
* This is used to change the verification level for a connection prior to
|
||||
* starting a re-negotiation.
|
||||
* <br>
|
||||
* The following levels are available for level:
|
||||
* <PRE>
|
||||
* SSL_CVERIFY_NONE - No client Certificate is required at all
|
||||
* SSL_CVERIFY_OPTIONAL - The client may present a valid Certificate
|
||||
* SSL_CVERIFY_REQUIRE - The client has to present a valid
|
||||
* Certificate
|
||||
* SSL_CVERIFY_OPTIONAL_NO_CA - The client may present a valid Certificate
|
||||
* but it need not to be (successfully)
|
||||
* verifiable
|
||||
* </PRE>
|
||||
* <br>
|
||||
* @param sock The socket to change.
|
||||
* @param level Type of Client Certificate verification.
|
||||
* @param depth Maximum number of certificates to permit in chain from
|
||||
* client to trusted CA. Use a value of 0 or less to leave the
|
||||
* current value unchanged
|
||||
*/
|
||||
public static native void setVerify(long sock, int level, int depth);
|
||||
|
||||
/**
|
||||
* Return SSL Info parameter as byte array.
|
||||
*
|
||||
* @param sock The socket to read the data from.
|
||||
* @param id Parameter id.
|
||||
* @return Byte array containing info id value.
|
||||
* @throws Exception An error occurred
|
||||
*/
|
||||
public static native byte[] getInfoB(long sock, int id)
|
||||
throws Exception;
|
||||
|
||||
/**
|
||||
* Return SSL Info parameter as String.
|
||||
*
|
||||
* @param sock The socket to read the data from.
|
||||
* @param id Parameter id.
|
||||
* @return String containing info id value.
|
||||
* @throws Exception An error occurred
|
||||
*/
|
||||
public static native String getInfoS(long sock, int id)
|
||||
throws Exception;
|
||||
|
||||
/**
|
||||
* Return SSL Info parameter as integer.
|
||||
*
|
||||
* @param sock The socket to read the data from.
|
||||
* @param id Parameter id.
|
||||
* @return Integer containing info id value or -1 on error.
|
||||
* @throws Exception An error occurred
|
||||
*/
|
||||
public static native int getInfoI(long sock, int id)
|
||||
throws Exception;
|
||||
|
||||
|
||||
/**
|
||||
* Obtain the name of the protocol negotiated via ALPN. Only valid after the
|
||||
* TLS handshake has completed.
|
||||
*
|
||||
* @param sock Socket
|
||||
* @param negotiatedProtocol Byte array in which to store agreed protocol
|
||||
*
|
||||
* @return Length of agreed protocol. Zero means no protocol agreed.
|
||||
*/
|
||||
public static native int getALPN(long sock, byte[] negotiatedProtocol);
|
||||
|
||||
}
|
||||
127
java/org/apache/tomcat/jni/Shm.java
Normal file
127
java/org/apache/tomcat/jni/Shm.java
Normal file
@@ -0,0 +1,127 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.apache.tomcat.jni;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
/** Shm
|
||||
*
|
||||
* @author Mladen Turk
|
||||
*/
|
||||
public class Shm {
|
||||
|
||||
/**
|
||||
* Create and make accessible a shared memory segment.
|
||||
* <br>
|
||||
* A note about Anonymous vs. Named shared memory segments:<br>
|
||||
* Not all platforms support anonymous shared memory segments, but in
|
||||
* some cases it is preferred over other types of shared memory
|
||||
* implementations. Passing a NULL 'file' parameter to this function
|
||||
* will cause the subsystem to use anonymous shared memory segments.
|
||||
* If such a system is not available, APR_ENOTIMPL is returned.
|
||||
* <br>
|
||||
* A note about allocation sizes:<br>
|
||||
* On some platforms it is necessary to store some metainformation
|
||||
* about the segment within the actual segment. In order to supply
|
||||
* the caller with the requested size it may be necessary for the
|
||||
* implementation to request a slightly greater segment length
|
||||
* from the subsystem. In all cases, the apr_shm_baseaddr_get()
|
||||
* function will return the first usable byte of memory.
|
||||
* @param reqsize The desired size of the segment.
|
||||
* @param filename The file to use for shared memory on platforms that
|
||||
* require it.
|
||||
* @param pool the pool from which to allocate the shared memory
|
||||
* structure.
|
||||
* @return The created shared memory structure.
|
||||
* @throws Error An error occurred
|
||||
*/
|
||||
public static native long create(long reqsize, String filename, long pool)
|
||||
throws Error;
|
||||
|
||||
/**
|
||||
* Remove shared memory segment associated with a filename.
|
||||
* <br>
|
||||
* This function is only supported on platforms which support
|
||||
* name-based shared memory segments, and will return APR_ENOTIMPL on
|
||||
* platforms without such support.
|
||||
* @param filename The filename associated with shared-memory segment which
|
||||
* needs to be removed
|
||||
* @param pool The pool used for file operations
|
||||
* @return the operation status
|
||||
*/
|
||||
public static native int remove(String filename, long pool);
|
||||
|
||||
/**
|
||||
* Destroy a shared memory segment and associated memory.
|
||||
* @param m The shared memory segment structure to destroy.
|
||||
* @return the operation status
|
||||
*/
|
||||
public static native int destroy(long m);
|
||||
|
||||
/**
|
||||
* Attach to a shared memory segment that was created
|
||||
* by another process.
|
||||
* @param filename The file used to create the original segment.
|
||||
* (This MUST match the original filename.)
|
||||
* @param pool the pool from which to allocate the shared memory
|
||||
* structure for this process.
|
||||
* @return The created shared memory structure.
|
||||
* @throws Error An error occurred
|
||||
*/
|
||||
public static native long attach(String filename, long pool)
|
||||
throws Error;
|
||||
|
||||
/**
|
||||
* Detach from a shared memory segment without destroying it.
|
||||
* @param m The shared memory structure representing the segment
|
||||
* to detach from.
|
||||
* @return the operation status
|
||||
*/
|
||||
public static native int detach(long m);
|
||||
|
||||
/**
|
||||
* Retrieve the base address of the shared memory segment.
|
||||
* NOTE: This address is only usable within the callers address
|
||||
* space, since this API does not guarantee that other attaching
|
||||
* processes will maintain the same address mapping.
|
||||
* @param m The shared memory segment from which to retrieve
|
||||
* the base address.
|
||||
* @return address, aligned by APR_ALIGN_DEFAULT.
|
||||
*/
|
||||
public static native long baseaddr(long m);
|
||||
|
||||
/**
|
||||
* Retrieve the length of a shared memory segment in bytes.
|
||||
* @param m The shared memory segment from which to retrieve
|
||||
* the segment length.
|
||||
* @return the length of the segment
|
||||
*/
|
||||
public static native long size(long m);
|
||||
|
||||
/**
|
||||
* Retrieve new ByteBuffer base address of the shared memory segment.
|
||||
* NOTE: This address is only usable within the callers address
|
||||
* space, since this API does not guarantee that other attaching
|
||||
* processes will maintain the same address mapping.
|
||||
* @param m The shared memory segment from which to retrieve
|
||||
* the base address.
|
||||
* @return address, aligned by APR_ALIGN_DEFAULT.
|
||||
*/
|
||||
public static native ByteBuffer buffer(long m);
|
||||
|
||||
}
|
||||
40
java/org/apache/tomcat/jni/Sockaddr.java
Normal file
40
java/org/apache/tomcat/jni/Sockaddr.java
Normal file
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.apache.tomcat.jni;
|
||||
|
||||
/** Sockaddr
|
||||
*
|
||||
* @author Mladen Turk
|
||||
*/
|
||||
public class Sockaddr {
|
||||
|
||||
/** The pool to use... */
|
||||
public long pool;
|
||||
/** The hostname */
|
||||
public String hostname;
|
||||
/** Either a string of the port number or the service name for the port */
|
||||
public String servname;
|
||||
/** The numeric port */
|
||||
public int port;
|
||||
/** The family */
|
||||
public int family;
|
||||
/** If multiple addresses were found by apr_sockaddr_info_get(), this
|
||||
* points to a representation of the next address. */
|
||||
public long next;
|
||||
|
||||
}
|
||||
629
java/org/apache/tomcat/jni/Socket.java
Normal file
629
java/org/apache/tomcat/jni/Socket.java
Normal file
File diff suppressed because it is too large
Load Diff
263
java/org/apache/tomcat/jni/Status.java
Normal file
263
java/org/apache/tomcat/jni/Status.java
Normal file
@@ -0,0 +1,263 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.apache.tomcat.jni;
|
||||
|
||||
/** Status
|
||||
*
|
||||
* @author Mladen Turk
|
||||
*/
|
||||
public class Status {
|
||||
|
||||
/**
|
||||
* APR_OS_START_ERROR is where the APR specific error values start.
|
||||
*/
|
||||
public static final int APR_OS_START_ERROR = 20000;
|
||||
/**
|
||||
* APR_OS_ERRSPACE_SIZE is the maximum number of errors you can fit
|
||||
* into one of the error/status ranges below -- except for
|
||||
* APR_OS_START_USERERR, which see.
|
||||
*/
|
||||
public static final int APR_OS_ERRSPACE_SIZE = 50000;
|
||||
/**
|
||||
* APR_OS_START_STATUS is where the APR specific status codes start.
|
||||
*/
|
||||
public static final int APR_OS_START_STATUS = (APR_OS_START_ERROR + APR_OS_ERRSPACE_SIZE);
|
||||
|
||||
/**
|
||||
* APR_OS_START_USERERR are reserved for applications that use APR that
|
||||
* layer their own error codes along with APR's. Note that the
|
||||
* error immediately following this one is set ten times farther
|
||||
* away than usual, so that users of apr have a lot of room in
|
||||
* which to declare custom error codes.
|
||||
*/
|
||||
public static final int APR_OS_START_USERERR = (APR_OS_START_STATUS + APR_OS_ERRSPACE_SIZE);
|
||||
/**
|
||||
* APR_OS_START_USEERR is obsolete, defined for compatibility only.
|
||||
* Use APR_OS_START_USERERR instead.
|
||||
*/
|
||||
public static final int APR_OS_START_USEERR = APR_OS_START_USERERR;
|
||||
/**
|
||||
* APR_OS_START_CANONERR is where APR versions of errno values are defined
|
||||
* on systems which don't have the corresponding errno.
|
||||
*/
|
||||
public static final int APR_OS_START_CANONERR = (APR_OS_START_USERERR + (APR_OS_ERRSPACE_SIZE * 10));
|
||||
|
||||
/**
|
||||
* APR_OS_START_EAIERR folds EAI_ error codes from getaddrinfo() into
|
||||
* apr_status_t values.
|
||||
*/
|
||||
public static final int APR_OS_START_EAIERR = (APR_OS_START_CANONERR + APR_OS_ERRSPACE_SIZE);
|
||||
/**
|
||||
* APR_OS_START_SYSERR folds platform-specific system error values into
|
||||
* apr_status_t values.
|
||||
*/
|
||||
public static final int APR_OS_START_SYSERR = (APR_OS_START_EAIERR + APR_OS_ERRSPACE_SIZE);
|
||||
|
||||
/** no error. */
|
||||
public static final int APR_SUCCESS = 0;
|
||||
|
||||
/**
|
||||
* APR Error Values
|
||||
* <PRE>
|
||||
* <b>APR ERROR VALUES</b>
|
||||
* APR_ENOSTAT APR was unable to perform a stat on the file
|
||||
* APR_ENOPOOL APR was not provided a pool with which to allocate memory
|
||||
* APR_EBADDATE APR was given an invalid date
|
||||
* APR_EINVALSOCK APR was given an invalid socket
|
||||
* APR_ENOPROC APR was not given a process structure
|
||||
* APR_ENOTIME APR was not given a time structure
|
||||
* APR_ENODIR APR was not given a directory structure
|
||||
* APR_ENOLOCK APR was not given a lock structure
|
||||
* APR_ENOPOLL APR was not given a poll structure
|
||||
* APR_ENOSOCKET APR was not given a socket
|
||||
* APR_ENOTHREAD APR was not given a thread structure
|
||||
* APR_ENOTHDKEY APR was not given a thread key structure
|
||||
* APR_ENOSHMAVAIL There is no more shared memory available
|
||||
* APR_EDSOOPEN APR was unable to open the dso object. For more
|
||||
* information call apr_dso_error().
|
||||
* APR_EGENERAL General failure (specific information not available)
|
||||
* APR_EBADIP The specified IP address is invalid
|
||||
* APR_EBADMASK The specified netmask is invalid
|
||||
* APR_ESYMNOTFOUND Could not find the requested symbol
|
||||
* </PRE>
|
||||
*
|
||||
*/
|
||||
public static final int APR_ENOSTAT = (APR_OS_START_ERROR + 1);
|
||||
public static final int APR_ENOPOOL = (APR_OS_START_ERROR + 2);
|
||||
public static final int APR_EBADDATE = (APR_OS_START_ERROR + 4);
|
||||
public static final int APR_EINVALSOCK = (APR_OS_START_ERROR + 5);
|
||||
public static final int APR_ENOPROC = (APR_OS_START_ERROR + 6);
|
||||
public static final int APR_ENOTIME = (APR_OS_START_ERROR + 7);
|
||||
public static final int APR_ENODIR = (APR_OS_START_ERROR + 8);
|
||||
public static final int APR_ENOLOCK = (APR_OS_START_ERROR + 9);
|
||||
public static final int APR_ENOPOLL = (APR_OS_START_ERROR + 10);
|
||||
public static final int APR_ENOSOCKET = (APR_OS_START_ERROR + 11);
|
||||
public static final int APR_ENOTHREAD = (APR_OS_START_ERROR + 12);
|
||||
public static final int APR_ENOTHDKEY = (APR_OS_START_ERROR + 13);
|
||||
public static final int APR_EGENERAL = (APR_OS_START_ERROR + 14);
|
||||
public static final int APR_ENOSHMAVAIL = (APR_OS_START_ERROR + 15);
|
||||
public static final int APR_EBADIP = (APR_OS_START_ERROR + 16);
|
||||
public static final int APR_EBADMASK = (APR_OS_START_ERROR + 17);
|
||||
public static final int APR_EDSOOPEN = (APR_OS_START_ERROR + 19);
|
||||
public static final int APR_EABSOLUTE = (APR_OS_START_ERROR + 20);
|
||||
public static final int APR_ERELATIVE = (APR_OS_START_ERROR + 21);
|
||||
public static final int APR_EINCOMPLETE = (APR_OS_START_ERROR + 22);
|
||||
public static final int APR_EABOVEROOT = (APR_OS_START_ERROR + 23);
|
||||
public static final int APR_EBADPATH = (APR_OS_START_ERROR + 24);
|
||||
public static final int APR_EPATHWILD = (APR_OS_START_ERROR + 25);
|
||||
public static final int APR_ESYMNOTFOUND = (APR_OS_START_ERROR + 26);
|
||||
public static final int APR_EPROC_UNKNOWN = (APR_OS_START_ERROR + 27);
|
||||
public static final int APR_ENOTENOUGHENTROPY = (APR_OS_START_ERROR + 28);
|
||||
|
||||
/** APR Status Values
|
||||
* <PRE>
|
||||
* <b>APR STATUS VALUES</b>
|
||||
* APR_INCHILD Program is currently executing in the child
|
||||
* APR_INPARENT Program is currently executing in the parent
|
||||
* APR_DETACH The thread is detached
|
||||
* APR_NOTDETACH The thread is not detached
|
||||
* APR_CHILD_DONE The child has finished executing
|
||||
* APR_CHILD_NOTDONE The child has not finished executing
|
||||
* APR_TIMEUP The operation did not finish before the timeout
|
||||
* APR_INCOMPLETE The operation was incomplete although some processing
|
||||
* was performed and the results are partially valid
|
||||
* APR_BADCH Getopt found an option not in the option string
|
||||
* APR_BADARG Getopt found an option that is missing an argument
|
||||
* and an argument was specified in the option string
|
||||
* APR_EOF APR has encountered the end of the file
|
||||
* APR_NOTFOUND APR was unable to find the socket in the poll structure
|
||||
* APR_ANONYMOUS APR is using anonymous shared memory
|
||||
* APR_FILEBASED APR is using a file name as the key to the shared memory
|
||||
* APR_KEYBASED APR is using a shared key as the key to the shared memory
|
||||
* APR_EINIT Initializer value. If no option has been found, but
|
||||
* the status variable requires a value, this should be used
|
||||
* APR_ENOTIMPL The APR function has not been implemented on this
|
||||
* platform, either because nobody has gotten to it yet,
|
||||
* or the function is impossible on this platform.
|
||||
* APR_EMISMATCH Two passwords do not match.
|
||||
* APR_EBUSY The given lock was busy.
|
||||
* </PRE>
|
||||
*
|
||||
*/
|
||||
public static final int APR_INCHILD = (APR_OS_START_STATUS + 1);
|
||||
public static final int APR_INPARENT = (APR_OS_START_STATUS + 2);
|
||||
public static final int APR_DETACH = (APR_OS_START_STATUS + 3);
|
||||
public static final int APR_NOTDETACH = (APR_OS_START_STATUS + 4);
|
||||
public static final int APR_CHILD_DONE = (APR_OS_START_STATUS + 5);
|
||||
public static final int APR_CHILD_NOTDONE = (APR_OS_START_STATUS + 6);
|
||||
public static final int APR_TIMEUP = (APR_OS_START_STATUS + 7);
|
||||
public static final int APR_INCOMPLETE = (APR_OS_START_STATUS + 8);
|
||||
public static final int APR_BADCH = (APR_OS_START_STATUS + 12);
|
||||
public static final int APR_BADARG = (APR_OS_START_STATUS + 13);
|
||||
public static final int APR_EOF = (APR_OS_START_STATUS + 14);
|
||||
public static final int APR_NOTFOUND = (APR_OS_START_STATUS + 15);
|
||||
public static final int APR_ANONYMOUS = (APR_OS_START_STATUS + 19);
|
||||
public static final int APR_FILEBASED = (APR_OS_START_STATUS + 20);
|
||||
public static final int APR_KEYBASED = (APR_OS_START_STATUS + 21);
|
||||
public static final int APR_EINIT = (APR_OS_START_STATUS + 22);
|
||||
public static final int APR_ENOTIMPL = (APR_OS_START_STATUS + 23);
|
||||
public static final int APR_EMISMATCH = (APR_OS_START_STATUS + 24);
|
||||
public static final int APR_EBUSY = (APR_OS_START_STATUS + 25);
|
||||
|
||||
public static final int TIMEUP = (APR_OS_START_USERERR + 1);
|
||||
public static final int EAGAIN = (APR_OS_START_USERERR + 2);
|
||||
public static final int EINTR = (APR_OS_START_USERERR + 3);
|
||||
public static final int EINPROGRESS = (APR_OS_START_USERERR + 4);
|
||||
public static final int ETIMEDOUT = (APR_OS_START_USERERR + 5);
|
||||
|
||||
private static native boolean is(int err, int idx);
|
||||
/*
|
||||
* APR_STATUS_IS Status Value Tests
|
||||
* <br><b>Warning :</b> For any particular error condition, more than one of these tests
|
||||
* may match. This is because platform-specific error codes may not
|
||||
* always match the semantics of the POSIX codes these tests (and the
|
||||
* corresponding APR error codes) are named after. A notable example
|
||||
* are the APR_STATUS_IS_ENOENT and APR_STATUS_IS_ENOTDIR tests on
|
||||
* Win32 platforms. The programmer should always be aware of this and
|
||||
* adjust the order of the tests accordingly.
|
||||
*
|
||||
*/
|
||||
public static final boolean APR_STATUS_IS_ENOSTAT(int s) { return is(s, 1); }
|
||||
public static final boolean APR_STATUS_IS_ENOPOOL(int s) { return is(s, 2); }
|
||||
/* empty slot: +3 */
|
||||
public static final boolean APR_STATUS_IS_EBADDATE(int s) { return is(s, 4); }
|
||||
public static final boolean APR_STATUS_IS_EINVALSOCK(int s) { return is(s, 5); }
|
||||
public static final boolean APR_STATUS_IS_ENOPROC(int s) { return is(s, 6); }
|
||||
public static final boolean APR_STATUS_IS_ENOTIME(int s) { return is(s, 7); }
|
||||
public static final boolean APR_STATUS_IS_ENODIR(int s) { return is(s, 8); }
|
||||
public static final boolean APR_STATUS_IS_ENOLOCK(int s) { return is(s, 9); }
|
||||
public static final boolean APR_STATUS_IS_ENOPOLL(int s) { return is(s, 10); }
|
||||
public static final boolean APR_STATUS_IS_ENOSOCKET(int s) { return is(s, 11); }
|
||||
public static final boolean APR_STATUS_IS_ENOTHREAD(int s) { return is(s, 12); }
|
||||
public static final boolean APR_STATUS_IS_ENOTHDKEY(int s) { return is(s, 13); }
|
||||
public static final boolean APR_STATUS_IS_EGENERAL(int s) { return is(s, 14); }
|
||||
public static final boolean APR_STATUS_IS_ENOSHMAVAIL(int s){ return is(s, 15); }
|
||||
public static final boolean APR_STATUS_IS_EBADIP(int s) { return is(s, 16); }
|
||||
public static final boolean APR_STATUS_IS_EBADMASK(int s) { return is(s, 17); }
|
||||
/* empty slot: +18 */
|
||||
public static final boolean APR_STATUS_IS_EDSOPEN(int s) { return is(s, 19); }
|
||||
public static final boolean APR_STATUS_IS_EABSOLUTE(int s) { return is(s, 20); }
|
||||
public static final boolean APR_STATUS_IS_ERELATIVE(int s) { return is(s, 21); }
|
||||
public static final boolean APR_STATUS_IS_EINCOMPLETE(int s){ return is(s, 22); }
|
||||
public static final boolean APR_STATUS_IS_EABOVEROOT(int s) { return is(s, 23); }
|
||||
public static final boolean APR_STATUS_IS_EBADPATH(int s) { return is(s, 24); }
|
||||
public static final boolean APR_STATUS_IS_EPATHWILD(int s) { return is(s, 25); }
|
||||
public static final boolean APR_STATUS_IS_ESYMNOTFOUND(int s) { return is(s, 26); }
|
||||
public static final boolean APR_STATUS_IS_EPROC_UNKNOWN(int s) { return is(s, 27); }
|
||||
public static final boolean APR_STATUS_IS_ENOTENOUGHENTROPY(int s) { return is(s, 28); }
|
||||
|
||||
/*
|
||||
* APR_Error
|
||||
*/
|
||||
public static final boolean APR_STATUS_IS_INCHILD(int s) { return is(s, 51); }
|
||||
public static final boolean APR_STATUS_IS_INPARENT(int s) { return is(s, 52); }
|
||||
public static final boolean APR_STATUS_IS_DETACH(int s) { return is(s, 53); }
|
||||
public static final boolean APR_STATUS_IS_NOTDETACH(int s) { return is(s, 54); }
|
||||
public static final boolean APR_STATUS_IS_CHILD_DONE(int s) { return is(s, 55); }
|
||||
public static final boolean APR_STATUS_IS_CHILD_NOTDONE(int s) { return is(s, 56); }
|
||||
public static final boolean APR_STATUS_IS_TIMEUP(int s) { return is(s, 57); }
|
||||
public static final boolean APR_STATUS_IS_INCOMPLETE(int s) { return is(s, 58); }
|
||||
/* empty slot: +9 */
|
||||
/* empty slot: +10 */
|
||||
/* empty slot: +11 */
|
||||
public static final boolean APR_STATUS_IS_BADCH(int s) { return is(s, 62); }
|
||||
public static final boolean APR_STATUS_IS_BADARG(int s) { return is(s, 63); }
|
||||
public static final boolean APR_STATUS_IS_EOF(int s) { return is(s, 64); }
|
||||
public static final boolean APR_STATUS_IS_NOTFOUND(int s) { return is(s, 65); }
|
||||
/* empty slot: +16 */
|
||||
/* empty slot: +17 */
|
||||
/* empty slot: +18 */
|
||||
public static final boolean APR_STATUS_IS_ANONYMOUS(int s) { return is(s, 69); }
|
||||
public static final boolean APR_STATUS_IS_FILEBASED(int s) { return is(s, 70); }
|
||||
public static final boolean APR_STATUS_IS_KEYBASED(int s) { return is(s, 71); }
|
||||
public static final boolean APR_STATUS_IS_EINIT(int s) { return is(s, 72); }
|
||||
public static final boolean APR_STATUS_IS_ENOTIMPL(int s) { return is(s, 73); }
|
||||
public static final boolean APR_STATUS_IS_EMISMATCH(int s) { return is(s, 74); }
|
||||
public static final boolean APR_STATUS_IS_EBUSY(int s) { return is(s, 75); }
|
||||
|
||||
/* Socket errors */
|
||||
public static final boolean APR_STATUS_IS_EAGAIN(int s) { return is(s, 90); }
|
||||
public static final boolean APR_STATUS_IS_ETIMEDOUT(int s) { return is(s, 91); }
|
||||
public static final boolean APR_STATUS_IS_ECONNABORTED(int s) { return is(s, 92); }
|
||||
public static final boolean APR_STATUS_IS_ECONNRESET(int s) { return is(s, 93); }
|
||||
public static final boolean APR_STATUS_IS_EINPROGRESS(int s) { return is(s, 94); }
|
||||
public static final boolean APR_STATUS_IS_EINTR(int s) { return is(s, 95); }
|
||||
public static final boolean APR_STATUS_IS_ENOTSOCK(int s) { return is(s, 96); }
|
||||
public static final boolean APR_STATUS_IS_EINVAL(int s) { return is(s, 97); }
|
||||
|
||||
}
|
||||
94
java/org/apache/tomcat/jni/Stdlib.java
Normal file
94
java/org/apache/tomcat/jni/Stdlib.java
Normal file
@@ -0,0 +1,94 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.apache.tomcat.jni;
|
||||
|
||||
/** Stdlib
|
||||
*
|
||||
* @author Mladen Turk
|
||||
*/
|
||||
public class Stdlib {
|
||||
|
||||
/**
|
||||
* Read from plain memory
|
||||
* @param dst Destination byte array
|
||||
* @param src Source memory address
|
||||
* @param sz Number of bytes to copy.
|
||||
* @return <code>true</code> if the operation was successful
|
||||
*/
|
||||
public static native boolean memread(byte [] dst, long src, int sz);
|
||||
|
||||
/**
|
||||
* Write to plain memory
|
||||
* @param dst Destination memory address
|
||||
* @param src Source byte array
|
||||
* @param sz Number of bytes to copy.
|
||||
* @return <code>true</code> if the operation was successful
|
||||
*/
|
||||
public static native boolean memwrite(long dst, byte [] src, int sz);
|
||||
|
||||
/**
|
||||
* Sets buffers to a specified character
|
||||
* @param dst Destination memory address
|
||||
* @param c Character to set.
|
||||
* @param sz Number of characters.
|
||||
* @return <code>true</code> if the operation was successful
|
||||
*/
|
||||
public static native boolean memset(long dst, int c, int sz);
|
||||
|
||||
/**
|
||||
* Allocates memory blocks.
|
||||
* @param sz Bytes to allocate.
|
||||
* @return a pointer
|
||||
*/
|
||||
public static native long malloc(int sz);
|
||||
|
||||
/**
|
||||
* Reallocate memory blocks.
|
||||
* @param mem Pointer to previously allocated memory block.
|
||||
* @param sz New size in bytes.
|
||||
* @return a pointer
|
||||
*/
|
||||
public static native long realloc(long mem, int sz);
|
||||
|
||||
/**
|
||||
* Allocates an array in memory with elements initialized to 0.
|
||||
* @param num Number of elements.
|
||||
* @param sz Length in bytes of each element.
|
||||
* @return a pointer
|
||||
*/
|
||||
public static native long calloc(int num, int sz);
|
||||
|
||||
/**
|
||||
* Deallocates or frees a memory block.
|
||||
* @param mem Previously allocated memory block to be freed.
|
||||
*/
|
||||
public static native void free(long mem);
|
||||
|
||||
/**
|
||||
* Get current process pid.
|
||||
* @return current pid or < 1 in case of error.
|
||||
*/
|
||||
public static native int getpid();
|
||||
|
||||
/**
|
||||
* Get current process parent pid.
|
||||
* @return parent pid or < 1 in case of error.
|
||||
*/
|
||||
public static native int getppid();
|
||||
|
||||
}
|
||||
31
java/org/apache/tomcat/jni/Thread.java
Normal file
31
java/org/apache/tomcat/jni/Thread.java
Normal file
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.apache.tomcat.jni;
|
||||
|
||||
/** Thread
|
||||
*
|
||||
* @author Mladen Turk
|
||||
*/
|
||||
public class Thread {
|
||||
|
||||
/**
|
||||
* @return the current thread ID handle.
|
||||
*/
|
||||
public static native long current();
|
||||
|
||||
}
|
||||
80
java/org/apache/tomcat/jni/Time.java
Normal file
80
java/org/apache/tomcat/jni/Time.java
Normal file
@@ -0,0 +1,80 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.apache.tomcat.jni;
|
||||
|
||||
/** Time
|
||||
*
|
||||
* @author Mladen Turk
|
||||
*/
|
||||
public class Time {
|
||||
|
||||
/** number of microseconds per second */
|
||||
public static final long APR_USEC_PER_SEC = 1000000L;
|
||||
/** number of milliseconds per microsecond */
|
||||
public static final long APR_MSEC_PER_USEC = 1000L;
|
||||
|
||||
/**
|
||||
* @param t The time
|
||||
* @return apr_time_t as a second
|
||||
*/
|
||||
public static long sec(long t)
|
||||
{
|
||||
return t / APR_USEC_PER_SEC;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param t The time
|
||||
* @return apr_time_t as a msec
|
||||
*/
|
||||
public static long msec(long t)
|
||||
{
|
||||
return t / APR_MSEC_PER_USEC;
|
||||
}
|
||||
|
||||
/**
|
||||
* number of microseconds since 00:00:00 January 1, 1970 UTC
|
||||
* @return the current time
|
||||
*/
|
||||
public static native long now();
|
||||
|
||||
/**
|
||||
* Formats dates in the RFC822
|
||||
* format in an efficient manner.
|
||||
* @param t the time to convert
|
||||
* @return the formatted date
|
||||
*/
|
||||
public static native String rfc822(long t);
|
||||
|
||||
/**
|
||||
* Formats dates in the ctime() format
|
||||
* in an efficient manner.
|
||||
* Unlike ANSI/ISO C ctime(), apr_ctime() does not include
|
||||
* a \n at the end of the string.
|
||||
* @param t the time to convert
|
||||
* @return the formatted date
|
||||
*/
|
||||
public static native String ctime(long t);
|
||||
|
||||
/**
|
||||
* Sleep for the specified number of micro-seconds.
|
||||
* <br><b>Warning :</b> May sleep for longer than the specified time.
|
||||
* @param t desired amount of time to sleep.
|
||||
*/
|
||||
public static native void sleep(long t);
|
||||
|
||||
}
|
||||
133
java/org/apache/tomcat/jni/User.java
Normal file
133
java/org/apache/tomcat/jni/User.java
Normal file
@@ -0,0 +1,133 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.apache.tomcat.jni;
|
||||
|
||||
/** User
|
||||
*
|
||||
* @author Mladen Turk
|
||||
*/
|
||||
public class User {
|
||||
|
||||
/**
|
||||
* Get the userid (and groupid) of the calling process
|
||||
* This function is available only if APR_HAS_USER is defined.
|
||||
* @param p The pool from which to allocate working space
|
||||
* @return Returns the user id
|
||||
* @throws Error If an error occurred
|
||||
*/
|
||||
public static native long uidCurrent(long p)
|
||||
throws Error;
|
||||
|
||||
/**
|
||||
* Get the groupid of the calling process
|
||||
* This function is available only if APR_HAS_USER is defined.
|
||||
* @param p The pool from which to allocate working space
|
||||
* @return Returns the group id
|
||||
* @throws Error If an error occurred
|
||||
*/
|
||||
public static native long gidCurrent(long p)
|
||||
throws Error;
|
||||
|
||||
|
||||
/**
|
||||
* Get the userid for the specified username
|
||||
* This function is available only if APR_HAS_USER is defined.
|
||||
* @param username The username to lookup
|
||||
* @param p The pool from which to allocate working space
|
||||
* @return Returns the user id
|
||||
* @throws Error If an error occurred
|
||||
*/
|
||||
public static native long uid(String username, long p)
|
||||
throws Error;
|
||||
|
||||
/**
|
||||
* Get the groupid for the specified username
|
||||
* This function is available only if APR_HAS_USER is defined.
|
||||
* @param username The username to lookup
|
||||
* @param p The pool from which to allocate working space
|
||||
* @return Returns the user's group id
|
||||
* @throws Error If an error occurred
|
||||
*/
|
||||
public static native long usergid(String username, long p)
|
||||
throws Error;
|
||||
|
||||
/**
|
||||
* Get the groupid for a specified group name
|
||||
* This function is available only if APR_HAS_USER is defined.
|
||||
* @param groupname The group name to look up
|
||||
* @param p The pool from which to allocate working space
|
||||
* @return Returns the user's group id
|
||||
* @throws Error If an error occurred
|
||||
*/
|
||||
public static native long gid(String groupname, long p)
|
||||
throws Error;
|
||||
|
||||
/**
|
||||
* Get the user name for a specified userid
|
||||
* This function is available only if APR_HAS_USER is defined.
|
||||
* @param userid The userid
|
||||
* @param p The pool from which to allocate the string
|
||||
* @return New string containing user name
|
||||
* @throws Error If an error occurred
|
||||
*/
|
||||
public static native String username(long userid, long p)
|
||||
throws Error;
|
||||
|
||||
/**
|
||||
* Get the group name for a specified groupid
|
||||
* This function is available only if APR_HAS_USER is defined.
|
||||
* @param groupid The groupid
|
||||
* @param p The pool from which to allocate the string
|
||||
* @return New string containing group name
|
||||
* @throws Error If an error occurred
|
||||
*/
|
||||
public static native String groupname(long groupid, long p)
|
||||
throws Error;
|
||||
|
||||
/**
|
||||
* Compare two user identifiers for equality.
|
||||
* This function is available only if APR_HAS_USER is defined.
|
||||
* @param left One uid to test
|
||||
* @param right Another uid to test
|
||||
* @return APR_SUCCESS if the apr_uid_t structures identify the same user,
|
||||
* APR_EMISMATCH if not, APR_BADARG if an apr_uid_t is invalid.
|
||||
*/
|
||||
public static native int uidcompare(long left, long right);
|
||||
|
||||
/**
|
||||
* Compare two group identifiers for equality.
|
||||
* This function is available only if APR_HAS_USER is defined.
|
||||
* @param left One gid to test
|
||||
* @param right Another gid to test
|
||||
* @return APR_SUCCESS if the apr_gid_t structures identify the same group,
|
||||
* APR_EMISMATCH if not, APR_BADARG if an apr_gid_t is invalid.
|
||||
*/
|
||||
public static native int gidcompare(long left, long right);
|
||||
|
||||
/**
|
||||
* Get the home directory for the named user
|
||||
* This function is available only if APR_HAS_USER is defined.
|
||||
* @param username The named user
|
||||
* @param p The pool from which to allocate the string
|
||||
* @return New string containing directory name
|
||||
* @throws Error If an error occurred
|
||||
*/
|
||||
public static native String homepath(String username, long p)
|
||||
throws Error;
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user