Author: mturk
Date: Fri Aug 19 18:34:27 2011
New Revision: 1159735

URL: http://svn.apache.org/viewvc?rev=1159735&view=rev
Log:
Move openssl to modules directory

Added:
    commons/sandbox/runtime/trunk/src/main/native/modules/
    commons/sandbox/runtime/trunk/src/main/native/modules/openssl/
    commons/sandbox/runtime/trunk/src/main/native/modules/openssl/api.c   (with 
props)
Removed:
    commons/sandbox/runtime/trunk/src/main/native/srclib/openssl/
Modified:
    commons/sandbox/runtime/trunk/src/main/native/Makefile.msc.in
    commons/sandbox/runtime/trunk/src/main/native/Makefile.unx.in
    commons/sandbox/runtime/trunk/src/main/native/include/acr/descriptor.h
    commons/sandbox/runtime/trunk/src/main/native/os/unix/arch_sync.h
    commons/sandbox/runtime/trunk/src/main/native/os/win32/arch_sync.h

Modified: commons/sandbox/runtime/trunk/src/main/native/Makefile.msc.in
URL: 
http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/Makefile.msc.in?rev=1159735&r1=1159734&r2=1159735&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/Makefile.msc.in (original)
+++ commons/sandbox/runtime/trunk/src/main/native/Makefile.msc.in Fri Aug 19 
18:34:27 2011
@@ -19,9 +19,9 @@
 SRCDIRS=\
        $(TOPDIR)\os\win32 \
        $(TOPDIR)\port \
+       $(TOPDIR)\modules\openssl \
        $(TOPDIR)\shared \
        $(TOPDIR)\srclib\bzip2 \
-       $(TOPDIR)\srclib\openssl \
        $(TOPDIR)\srclib\zlib \
        $(TOPDIR)\srclib\zlib\win32
 
@@ -150,7 +150,7 @@ LIBSOURCES=\
        $(TOPDIR)\shared\buildmark.c
 
 SSLSOURCES=\
-       $(TOPDIR)\srclib\openssl\api.c
+       $(TOPDIR)\modules\openssl\api.c
 
 CXXSOURCES=
 

Modified: commons/sandbox/runtime/trunk/src/main/native/Makefile.unx.in
URL: 
http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/Makefile.unx.in?rev=1159735&r1=1159734&r2=1159735&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/Makefile.unx.in (original)
+++ commons/sandbox/runtime/trunk/src/main/native/Makefile.unx.in Fri Aug 19 
18:34:27 2011
@@ -21,10 +21,10 @@ include @topdir@/Makedefs
 SRCDIRS=\
        $(TOPDIR)/os/$(HOSTSRC) \
        $(TOPDIR)/os/unix \
+       $(TOPDIR)/modules/openssl \
        $(TOPDIR)/port \
        $(TOPDIR)/shared \
        $(TOPDIR)/srclib/bzip2 \
-       $(TOPDIR)/srclib/openssl \
        $(TOPDIR)/srclib/zlib \
        $(TOPDIR)/srclib/zlib/unix
 
@@ -145,7 +145,7 @@ LIBSOURCES=\
        $(TOPDIR)/shared/buildmark.c
 
 SSLSOURCES=\
-       $(TOPDIR)/srclib/openssl/api.c
+       $(TOPDIR)/modules/openssl/api.c
 
 CXXSOURCES=
 

Modified: commons/sandbox/runtime/trunk/src/main/native/include/acr/descriptor.h
URL: 
http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/include/acr/descriptor.h?rev=1159735&r1=1159734&r2=1159735&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/include/acr/descriptor.h 
(original)
+++ commons/sandbox/runtime/trunk/src/main/native/include/acr/descriptor.h Fri 
Aug 19 18:34:27 2011
@@ -18,6 +18,7 @@
 #define _ACR_DESCRIPTOR_H
 
 #include "acr/jniapi.h"
+#include "acr/memory.h"
 
 /**
  * Socket flags

Added: commons/sandbox/runtime/trunk/src/main/native/modules/openssl/api.c
URL: 
http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/modules/openssl/api.c?rev=1159735&view=auto
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/modules/openssl/api.c (added)
+++ commons/sandbox/runtime/trunk/src/main/native/modules/openssl/api.c Fri Aug 
19 18:34:27 2011
@@ -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.
+ */
+
+#include "acr/clazz.h"
+#include "acr/error.h"
+#include "acr/misc.h"
+#include "acr/dso.h"
+#include "arch_sync.h"
+#include "acr/ssl.h"
+
+#if !HAVE_OPENSSL
+#error "Cannot compile this file without HAVE_OPENSSL defined"
+#endif
+
+#if defined(WINDOWS)
+#define SSL_DSO_NAME       L"ssleay32.dll"
+#define CRYPTO_DSO_NAME    L"libeay32.dll"
+#else
+#define SSL_DSO_NAME       "libssl" PACKAGE_DLLEXT
+#define CRYPTO_DSO_NAME    "libcrypto" PACKAGE_DLLEXT
+#endif
+
+#if HAVE_OPENSSL_STATIC
+
+ACR_JNI_EXPORT(jboolean, Native, ldopenssl0)(JNI_STDARGS)
+{
+    return JNI_TRUE;
+}
+
+#else /* !HAVE_OPENSSL_STATIC */
+/**
+ * Dynamic OpenSSL API loader
+ */
+
+#define LIBSSL_FPLOAD(fN)                                       \
+    fname  = #fN;                                               \
+    SSLapi.fp##fN = AcrGetProcAddress(libssldso, fname);        \
+    if (SSLapi.fp##fN == 0) goto failed
+
+#define CRYPTO_FPLOAD(fN)                                       \
+    fname  = #fN;                                               \
+    SSLapi.fp##fN = AcrGetProcAddress(cryptodso, fname);        \
+    if (SSLapi.fp##fN == 0) goto failed
+
+#define SSLAPI_LINK(fN) (*SSLapi.fp##fN)
+
+struct SSLAPIst {
+    unsigned long       (*fpSSLeay)(void);
+    const char*         (*fpSSLeay_version)(int);
+
+    SSL_CTX*            (*fpSSL_CTX_new)(const SSL_METHOD *);
+    void                (*fpSSL_CTX_free)(SSL_CTX *);
+
+};
+
+static struct SSLAPIst SSLapi;
+static acr_dso_t       libssldso;
+static acr_dso_t       cryptodso;
+
+ACR_JNI_EXPORT(jboolean, Native, ldopenssl0)(JNI_STDARGS)
+{
+    char b[512];
+    const char *fname = "";
+    const char *dname = SSL_DSO_NAME;
+
+    if ((cryptodso = AcrDsoLoad(CRYPTO_DSO_NAME)) == 0) {
+        ACR_THROW_SYS_ERRNO();
+        return JNI_FALSE;
+    }
+    if ((libssldso = AcrDsoLoad(SSL_DSO_NAME)) == 0) {
+        ACR_THROW_SYS_ERRNO();
+        return JNI_FALSE;
+    }    
+    LIBSSL_FPLOAD(SSLeay);
+    LIBSSL_FPLOAD(SSLeay_version);
+    if (SSLeay() < 0x00908000L) {
+        AcrThrow(env, ACR_EX_ERUNTIME,
+                 "OpenSSL 0.9.8 or greater is required");
+        return JNI_FALSE;
+    }
+    LIBSSL_FPLOAD(SSL_CTX_new);
+    LIBSSL_FPLOAD(SSL_CTX_free);
+    
+    return JNI_TRUE;
+failed:
+    snprintf(b, sizeof(b), "Cannot find %s::%s()", dname, fname);
+    AcrThrow(env, ACR_EX_ENOENT, b);
+    return JNI_FALSE;
+}
+
+/* Dynamic OpenSSL library wrappers
+ * This allows to dynamically link to libssl.so and libcrypto.so
+ * while preserving statically linked API.
+ *
+ * Wrappers are currently manually maintained, so if any
+ * additional OpenSSL function is used it has to be added
+ * to the SSLapi struct and locally declared.
+ * 
+ */
+unsigned long SSLeay()
+{
+    return SSLAPI_LINK(SSLeay)();
+}
+
+const char *SSLeay_version(int type)
+{
+    return SSLAPI_LINK(SSLeay_version)(type);
+}
+
+SSL_CTX *SSL_CTX_new(const SSL_METHOD *meth)
+{
+    return SSLAPI_LINK(SSL_CTX_new)(meth);
+}
+
+void SSL_CTX_free(SSL_CTX *ctx)
+{
+    SSLAPI_LINK(SSL_CTX_free)(ctx);
+}
+
+#endif /* HAVE_OPENSSL_STATIC */

Propchange: commons/sandbox/runtime/trunk/src/main/native/modules/openssl/api.c
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: commons/sandbox/runtime/trunk/src/main/native/os/unix/arch_sync.h
URL: 
http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/unix/arch_sync.h?rev=1159735&r1=1159734&r2=1159735&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/unix/arch_sync.h (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/unix/arch_sync.h Fri Aug 
19 18:34:27 2011
@@ -18,15 +18,76 @@
 #define _ACR_ARCH_SYNC_H_
 
 #include "acr/stddefs.h"
+#include "acr/descriptor.h"
 
 #if defined(_SOLARIS)
 #include <atomic.h>
 #endif
 
+#if !defined(PTHREAD_MUTEX_RECURSIVE)
+#define PTHREAD_MUTEX_RECURSIVE 1
+#endif
+typedef pthread_mutex_t     acr_mutex_t;
+
 #ifdef __cplusplus
 extern "C" {
 #endif
 
+ACR_INLINE(int) AcrThreadMutexInit(acr_mutex_t *mutex)
+{
+    int rc;
+#if defined(PTHREAD_MUTEX_RECURSIVE)
+    pthread_mutexattr_t mattr;
+#endif
+
+#if defined(PTHREAD_MUTEX_RECURSIVE)
+    if ((rc = pthread_mutexattr_init(&mattr)))
+        return rc;
+    rc = pthread_mutexattr_settype(&mattr, PTHREAD_MUTEX_RECURSIVE);
+    if (rc) {
+        pthread_mutexattr_destroy(&mattr);
+        return rc;
+    }
+    rc = pthread_mutex_init(mutex, &mattr);
+    pthread_mutexattr_destroy(&mattr);
+#else
+    rc = pthread_mutex_init(mutex, 0);
+#endif
+    return rc;
+}
+
+ACR_INLINE(int) AcrThreadMutexCreate(acr_mutex_t **mutex)
+{
+    int rc;
+    acr_mutex_t *m;
+
+    if ((m = malloc(sizeof(acr_mutex_t))) == 0)
+        return ACR_ENOMEM;
+    if ((rc = AcrThreadMutexInit(m)) != 0)
+        free(m);
+    else
+        *mutex = m;
+    return rc;
+}
+
+ACR_INLINE(void) AcrTreadMutexDestroy(acr_mutex_t *mutex)
+{
+    if (mutex != 0)
+        pthread_mutex_destroy(mutex);
+}
+
+ACR_INLINE(void) AcrTreadMutexLock(acr_mutex_t *mutex)
+{
+    if (mutex != 0)
+        pthread_mutex_lock(mutex);
+}
+
+ACR_INLINE(void) AcrTreadMutexUnlock(acr_mutex_t *mutex)
+{
+    if (mutex != 0)
+        pthread_mutex_unlock(mutex);
+}
+
 #if defined(__GNUC__)
 # if (__GNUC__ >= 4) && (__GNUC_MINOR__ >= 1)
 # else

Modified: commons/sandbox/runtime/trunk/src/main/native/os/win32/arch_sync.h
URL: 
http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/win32/arch_sync.h?rev=1159735&r1=1159734&r2=1159735&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/win32/arch_sync.h 
(original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/win32/arch_sync.h Fri Aug 
19 18:34:27 2011
@@ -18,6 +18,7 @@
 #define _ACR_ARCH_SYNC_H_
 
 #include "acr/stddefs.h"
+#include "acr/descriptor.h"
 
 #if HAVE_INTRIN_H
 # include <intrin.h>
@@ -31,6 +32,51 @@
 #define USE_ATOMICS_WRAPPER     0
 #define USE_BUILTIN_ATOMICS     1
 
+typedef CRITICAL_SECTION        acr_mutex_t;
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+ACR_INLINE(int) AcrThreadMutexInit(acr_mutex_t *mutex)
+{
+    InitializeCriticalSectionAndSpinCount(mutex, 4000);
+    return 0;
+}
+
+ACR_INLINE(int) AcrThreadMutexCreate(acr_mutex_t **mutex)
+{
+    int rc;
+    acr_mutex_t *m;
+
+    if ((m = malloc(sizeof(acr_mutex_t))) == 0)
+        return ACR_ENOMEM;
+    if ((rc = AcrThreadMutexInit(m)) != 0)
+        free(m);
+    else
+        *mutex = m;
+    return rc;
+}
+
+ACR_INLINE(void) AcrTreadMutexDestroy(acr_mutex_t *mutex)
+{
+    if (mutex != 0)
+        DeleteCriticalSection(mutex);
+}
+
+ACR_INLINE(void) AcrTreadMutexLock(acr_mutex_t *mutex)
+{
+    if (mutex != 0)
+        EnterCriticalSection(mutex);
+}
+
+ACR_INLINE(void) AcrTreadMutexUnlock(acr_mutex_t *mutex)
+{
+    if (mutex != 0)
+        LeaveCriticalSection(mutex);
+}
+
+
 ACR_INLINE(void) AcrCpuFence()
 {
     _PR_COMPILER_FENCE();
@@ -98,4 +144,7 @@ ACR_INLINE(int)    AcrSdRelease(acr_sd_t
         return 1;
 }
 
+#ifdef __cplusplus
+}
+#endif
 #endif /* _ACR_ARCH_SYNC_H_ */


Reply via email to