commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mt...@apache.org
Subject svn commit: r1171565 - /commons/sandbox/runtime/trunk/src/main/native/modules/openssl/bio.c
Date Fri, 16 Sep 2011 13:55:28 GMT
Author: mturk
Date: Fri Sep 16 13:55:27 2011
New Revision: 1171565

URL: http://svn.apache.org/viewvc?rev=1171565&view=rev
Log:
Add missing bio methods

Modified:
    commons/sandbox/runtime/trunk/src/main/native/modules/openssl/bio.c

Modified: commons/sandbox/runtime/trunk/src/main/native/modules/openssl/bio.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/modules/openssl/bio.c?rev=1171565&r1=1171564&r2=1171565&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/modules/openssl/bio.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/modules/openssl/bio.c Fri Sep 16 13:55:27
2011
@@ -127,7 +127,7 @@ static int bio_j_free(BIO *bi)
 {
     if (bi == 0)
         return 0;
-    if (bi->ptr != NULL) {
+    if (bi->ptr != 0) {
         acr_bio_t *bp = (acr_bio_t *)bi->ptr;
         if (bi->init) {
             bi->init = 0;
@@ -144,18 +144,145 @@ static int bio_j_free(BIO *bi)
     return 1;
 }
 
-static long bio_j_ctrl(BIO *b, int cmd, long num, void *ptr)
+static long bio_j_ctrl(BIO *bi, int cmd, long num, void *ptr)
 {
     return 0;
 }
 
+static int bio_j_write(BIO *bi, const char *in, int inl)
+{
+    int rv = -1;
+
+    if (bi == 0 || in == 0)
+        return -1;
+    if (bi->init) {
+        jobject    obj;
+        acr_bio_t *bp  = (acr_bio_t *)bi->ptr;
+        JNIEnv    *env = AcrGetJNIEnv();
+        jbyteArray ba;
+        if (env == 0)
+            return -1;
+        if ((obj = (*env)->NewLocalRef(env, bp->obj)) == 0)
+            return -1;
+        ba = (*env)->NewByteArray(env, inl);
+        if (ba != 0) {
+            (*env)->SetByteArrayRegion(env, ba, 0, inl, (jbyte *)in);
+            rv = CALL_METHOD1(Int, 0001, obj, ba);
+            (*env)->DeleteLocalRef(env, ba);
+        }
+        (*env)->DeleteLocalRef(env, obj);
+        if ((*env)->ExceptionCheck(env)) {
+            /* Clear any pending exceptions */
+            (*env)->ExceptionClear(env);
+            rv = -1;
+        }
+    }
+    return rv;
+}
+
+static int bio_j_read(BIO *bi, char *in, int inl)
+{
+    int rv = -1;
+
+    if (bi == 0 || in == 0)
+        return -1;
+    if (bi->init) {
+        jobject    obj;
+        acr_bio_t *bp  = (acr_bio_t *)bi->ptr;
+        JNIEnv    *env = AcrGetJNIEnv();
+        jbyteArray ba;
+        if (env == 0)
+            return -1;
+        if ((obj = (*env)->NewLocalRef(env, bp->obj)) == 0)
+            return -1;
+        ba = (*env)->NewByteArray(env, inl);
+        if (ba != 0) {
+            rv = CALL_METHOD1(Int, 0002, obj, ba);
+            if (rv > 0)
+                (*env)->GetByteArrayRegion(env, ba, 0, rv, (jbyte *)in);
+            (*env)->DeleteLocalRef(env, ba);
+        }
+        (*env)->DeleteLocalRef(env, obj);
+        if ((*env)->ExceptionCheck(env)) {
+            /* Clear any pending exceptions */
+            (*env)->ExceptionClear(env);
+            rv = -1;
+        }
+    }
+    return rv;
+}
+
+static int bio_j_puts(BIO *bi, const char *in)
+{
+    int rv = -1;
+
+    if (bi == 0)
+        return -1;
+    if (bi->init) {
+        jobject    obj;
+        acr_bio_t *bp  = (acr_bio_t *)bi->ptr;
+        JNIEnv    *env = AcrGetJNIEnv();
+        jstring    str = 0;
+        if (env == 0)
+            return -1;
+        if ((obj = (*env)->NewLocalRef(env, bp->obj)) == 0)
+            return -1;
+        if (in != 0)
+            str = AcrNewJavaStringA(env, in);
+        rv = CALL_METHOD1(Int, 0003, obj, str);
+        if (str != 0)
+            (*env)->DeleteLocalRef(env, str);
+        (*env)->DeleteLocalRef(env, obj);
+        if ((*env)->ExceptionCheck(env)) {
+            /* Clear any pending exceptions */
+            (*env)->ExceptionClear(env);
+            rv = -1;
+        }
+    }
+    return rv;
+}
+
+static int bio_j_gets(BIO *bi, char *in, int inl)
+{
+    int rv = -1;
+
+    if (bi == 0 || in == 0)
+        return -1;
+    if (bi->init) {
+        jobject    obj;
+        acr_bio_t *bp  = (acr_bio_t *)bi->ptr;
+        JNIEnv    *env = AcrGetJNIEnv();
+        jstring    str = 0;
+        if (env == 0)
+            return -1;
+        if ((obj = (*env)->NewLocalRef(env, bp->obj)) == 0)
+            return -1;
+        str = CALL_METHOD1(Object, 0004, obj, inl);
+        if (str != 0) {
+            char *rs = AcrGetJavaStringA(env, str, 0);
+            if (rs != 0) {
+                rv = strlcpy(in, rs, inl);
+                AcrFree(rs);
+            }
+            (*env)->DeleteLocalRef(env, str);
+        }
+        (*env)->DeleteLocalRef(env, obj);
+        if ((*env)->ExceptionCheck(env)) {
+            /* Clear any pending exceptions */
+            (*env)->ExceptionClear(env);
+            rv = -1;
+        }
+    }
+    return rv;
+}
+
 static BIO_METHOD bio_j_methods = {
     BIO_TYPE_FILE,
     "Java OpenSSL BIO",
-    0,
-    0,
-    0,
-    0,
+    bio_j_write,
+    bio_j_read,
+    bio_j_puts,
+    bio_j_gets,
     bio_j_ctrl,
     bio_j_new,
     bio_j_free,
@@ -183,6 +310,8 @@ ACR_SSL_EXPORT(jlong, SSLBio, new0)(JNI_
         ACR_THROW(ACR_EX_ENOMEM, 0);
         return 0;
     }
+    bi->init  = 1;
+    bi->flags = SSL_BIO_FLAG_CALLBACK;
 
     return P2J(bi);
 }



Mime
View raw message