This is an automated email from the ASF dual-hosted git repository.

markt-asf pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/tomcat-native.git


The following commit(s) were added to refs/heads/main by this push:
     new 1edc30910 Remove unused code
1edc30910 is described below

commit 1edc309108a8df8e4326096a48b7310b71dd6655
Author: Mark Thomas <[email protected]>
AuthorDate: Thu Aug 27 11:32:09 2026 +0100

    Remove unused code
---
 native/include/ssl_private.h |   4 -
 native/include/tcn.h         |   8 --
 native/src/jnilib.c          |  22 -----
 native/src/ssl.c             | 215 -------------------------------------------
 native/src/sslcontext.c      |   4 +-
 5 files changed, 2 insertions(+), 251 deletions(-)

diff --git a/native/include/ssl_private.h b/native/include/ssl_private.h
index 3546d5aef..7f4865044 100644
--- a/native/include/ssl_private.h
+++ b/native/include/ssl_private.h
@@ -81,8 +81,6 @@
 #define SSL_MODE_SERVER         (1)
 #define SSL_MODE_COMBINED       (2)
 
-#define SSL_BIO_FLAG_RDONLY     (1<<0)
-#define SSL_BIO_FLAG_CALLBACK   (1<<1)
 #define SSL_DEFAULT_CACHE_SIZE  (256)
 #define SSL_DEFAULT_VHOST_NAME  ("_default_:443")
 #define SSL_MAX_STR_LEN         (2048)
@@ -311,8 +309,6 @@ void       *SSL_get_app_data4(const SSL *);
 void        SSL_set_app_data4(SSL *, void *);
 int         SSL_password_prompt(tcn_pass_cb_t *);
 int         SSL_password_callback(char *, int, int, void *);
-void        SSL_BIO_close(BIO *);
-void        SSL_BIO_doref(BIO *);
 DH         *SSL_get_dh_params(unsigned keylen);
 EVP_PKEY   *SSL_dh_GetParamFromFile(const char *);
 #ifdef HAVE_ECC
diff --git a/native/include/tcn.h b/native/include/tcn.h
index e1d50d439..d4900fb7b 100644
--- a/native/include/tcn.h
+++ b/native/include/tcn.h
@@ -164,8 +164,6 @@ void            tcn_ThrowMemoryException(JNIEnv *, const 
char *, int, const char
 void            tcn_ThrowAPRException(JNIEnv *, apr_status_t);
 jstring         tcn_new_string(JNIEnv *, const char *);
 jstring         tcn_new_stringn(JNIEnv *, const char *, size_t);
-jbyteArray      tcn_new_arrayb(JNIEnv *, const unsigned char *, size_t);
-jobjectArray    tcn_new_arrays(JNIEnv *env, size_t len);
 char           *tcn_get_string(JNIEnv *, jstring);
 char           *tcn_strdup(JNIEnv *, jstring);
 char           *tcn_pstrdup(JNIEnv *, jstring, apr_pool_t *);
@@ -245,12 +243,6 @@ unsigned long   tcn_get_thread_id(void);
 
 #define TCN_MAX_METHODS 8
 
-typedef struct {
-    jobject     obj;
-    jmethodID   mid[TCN_MAX_METHODS];
-    void        *opaque;
-} tcn_callback_t;
-
 #define TCN_MIN(a, b) ((a) < (b) ? (a) : (b))
 #define TCN_MAX(a, b) ((a) > (b) ? (a) : (b))
 
diff --git a/native/src/jnilib.c b/native/src/jnilib.c
index 511994cf4..3a50d489d 100644
--- a/native/src/jnilib.c
+++ b/native/src/jnilib.c
@@ -131,28 +131,6 @@ jstring tcn_new_stringn(JNIEnv *env, const char *str, 
size_t l)
     return NULL;
 }
 
-jbyteArray tcn_new_arrayb(JNIEnv *env, const unsigned char *data, size_t len)
-{
-    jbyteArray bytes = 0;
-    
-    if ((*env)->EnsureLocalCapacity(env, 1) < 0) {
-        return NULL; /* out of memory error */
-    }
-    bytes = (*env)->NewByteArray(env, (jsize)len);
-    if (bytes != NULL) {
-        (*env)->SetByteArrayRegion(env, bytes, 0, (jint)len, (jbyte *)data);
-    }
-    return bytes;
-}
-
-jobjectArray tcn_new_arrays(JNIEnv *env, size_t len)
-{
-    if ((*env)->EnsureLocalCapacity(env, 1) < 0) {
-        return NULL; /* out of memory error */
-    }
-    return (*env)->NewObjectArray(env, (jsize)len, jString_class, NULL);
-}
-
 jstring tcn_new_string(JNIEnv *env, const char *str)
 {
     if (!str) {
diff --git a/native/src/ssl.c b/native/src/ssl.c
index e3a939a34..0c74cb22a 100644
--- a/native/src/ssl.c
+++ b/native/src/ssl.c
@@ -49,9 +49,6 @@ void SSL_callback_add_keylog(SSL_CTX *ctx)
     }
 }
 
-static void init_bio_methods(void);
-static void free_bio_methods(void);
-
 TCN_IMPLEMENT_CALL(jint, SSL, version)(TCN_STDARGS)
 {
     UNREFERENCED_STDARGS;
@@ -75,8 +72,6 @@ static apr_status_t ssl_init_cleanup(void *data)
         return APR_SUCCESS;
     ssl_initialized = 0;
 
-    free_bio_methods();
-
     /* Openssl v1.1+ handles all termination automatically. */
 
     if (key_log_file) {
@@ -204,8 +199,6 @@ TCN_IMPLEMENT_CALL(jint, SSL, initialize)(TCN_STDARGS, 
jstring engine)
     /* For SSL_get_app_data2(), SSL_get_app_data3() and SSL_get_app_data4() at 
request time */
     SSL_init_app_data_idx();
 
-    init_bio_methods();
-
     /*
      * Let us cleanup the ssl library when the library is unloaded
      */
@@ -289,214 +282,6 @@ TCN_IMPLEMENT_CALL(jint, SSL, fipsModeSet)(TCN_STDARGS, 
jint mode)
     return r;
 }
 
-/* OpenSSL Java Stream BIO */
-
-typedef struct  {
-    int            refcount;
-    apr_pool_t     *pool;
-    tcn_callback_t cb;
-} BIO_JAVA;
-
-
-static apr_status_t generic_bio_cleanup(void *data)
-{
-    BIO *b = (BIO *)data;
-
-    if (b) {
-        BIO_free(b);
-    }
-    return APR_SUCCESS;
-}
-
-void SSL_BIO_close(BIO *bi)
-{
-    BIO_JAVA *j;
-    if (bi == NULL)
-        return;
-    j = (BIO_JAVA *)BIO_get_data(bi);
-    if (j != NULL && BIO_test_flags(bi, SSL_BIO_FLAG_CALLBACK)) {
-        j->refcount--;
-        if (j->refcount == 0) {
-            if (j->pool)
-                apr_pool_cleanup_run(j->pool, bi, generic_bio_cleanup);
-            else
-                BIO_free(bi);
-        }
-    }
-    else
-        BIO_free(bi);
-}
-
-void SSL_BIO_doref(BIO *bi)
-{
-    BIO_JAVA *j;
-    if (bi == NULL)
-        return;
-    j = (BIO_JAVA *)BIO_get_data(bi);
-    if (j != NULL && BIO_test_flags(bi, SSL_BIO_FLAG_CALLBACK)) {
-        j->refcount++;
-    }
-}
-
-
-static int jbs_new(BIO *bi)
-{
-    BIO_JAVA *j;
-
-    if ((j = OPENSSL_malloc(sizeof(BIO_JAVA))) == NULL)
-        return 0;
-    j->pool      = NULL;
-    j->refcount  = 1;
-    BIO_set_shutdown(bi, 1);
-    BIO_set_init(bi, 0);
-    BIO_set_data(bi, (void *)j);
-
-    return 1;
-}
-
-static int jbs_free(BIO *bi)
-{
-    BIO_JAVA *j;
-    if (bi == NULL)
-        return 0;
-    j = (BIO_JAVA *)BIO_get_data(bi);
-    if (j != NULL) {
-        if (BIO_get_init(bi)) {
-            JNIEnv   *e = NULL;
-            BIO_set_init(bi, 0);
-            tcn_get_java_env(&e);
-            TCN_UNLOAD_CLASS(e, j->cb.obj);
-        }
-        OPENSSL_free(j);
-    }
-    BIO_set_data(bi, NULL);
-    return 1;
-}
-
-static int jbs_write(BIO *b, const char *in, int inl)
-{
-    jint ret = -1;
-    if (BIO_get_init(b) && in != NULL) {
-        BIO_JAVA *j = (BIO_JAVA *)BIO_get_data(b);
-        JNIEnv   *e = NULL;
-        jbyteArray jb;
-        tcn_get_java_env(&e);
-        jb = (*e)->NewByteArray(e, inl);
-        if (!(*e)->ExceptionOccurred(e)) {
-            BIO_clear_retry_flags(b);
-            (*e)->SetByteArrayRegion(e, jb, 0, inl, (jbyte *)in);
-            ret = (*e)->CallIntMethod(e, j->cb.obj,
-                                      j->cb.mid[0], jb);
-            (*e)->ReleaseByteArrayElements(e, jb, (jbyte *)in, JNI_ABORT);
-            (*e)->DeleteLocalRef(e, jb);
-        }
-    }
-    /* From netty-tc-native, in the AF we were returning 0 */
-    if (ret == 0) {
-        BIO_set_retry_write(b);
-        ret = -1;
-    }
-    return ret;
-}
-
-static int jbs_read(BIO *b, char *out, int outl)
-{
-    jint ret = 0;
-    if (BIO_get_init(b) && out != NULL) {
-        BIO_JAVA *j = (BIO_JAVA *)BIO_get_data(b);
-        JNIEnv   *e = NULL;
-        jbyteArray jb;
-        tcn_get_java_env(&e);
-        jb = (*e)->NewByteArray(e, outl);
-        if (!(*e)->ExceptionOccurred(e)) {
-            BIO_clear_retry_flags(b);
-            ret = (*e)->CallIntMethod(e, j->cb.obj,
-                                      j->cb.mid[1], jb);
-            if (ret > 0) {
-                jbyte *jout = (*e)->GetPrimitiveArrayCritical(e, jb, NULL);
-                memcpy(out, jout, ret);
-                (*e)->ReleasePrimitiveArrayCritical(e, jb, jout, 0);
-            } else if (outl != 0) {
-                ret = -1;
-                BIO_set_retry_read(b);
-            }
-            (*e)->DeleteLocalRef(e, jb);
-        }
-    }
-    return ret;
-}
-
-static int jbs_puts(BIO *b, const char *in)
-{
-    int ret = 0;
-    if (BIO_get_init(b) && in != NULL) {
-        BIO_JAVA *j = (BIO_JAVA *)BIO_get_data(b);
-        JNIEnv   *e = NULL;
-        tcn_get_java_env(&e);
-        ret = (*e)->CallIntMethod(e, j->cb.obj,
-                                  j->cb.mid[2],
-                                  tcn_new_string(e, in));
-    }
-    return ret;
-}
-
-static int jbs_gets(BIO *b, char *out, int outl)
-{
-    int ret = 0;
-    if (BIO_get_init(b) && out != NULL) {
-        BIO_JAVA *j = (BIO_JAVA *)BIO_get_data(b);
-        JNIEnv   *e = NULL;
-        jobject  o;
-        tcn_get_java_env(&e);
-        if ((o = (*e)->CallObjectMethod(e, j->cb.obj,
-                            j->cb.mid[3], (jint)(outl - 1)))) {
-            TCN_ALLOC_CSTRING(o);
-            if (J2S(o)) {
-                int l = (int)strlen(J2S(o));
-                if (l < outl) {
-                    strcpy(out, J2S(o));
-                    ret = outl;
-                }
-            }
-            TCN_FREE_CSTRING(o);
-        }
-    }
-    return ret;
-}
-
-static long jbs_ctrl(BIO *b, int cmd, long num, void *ptr)
-{
-    int ret = 0;
-    switch (cmd) {
-        case BIO_CTRL_FLUSH:
-            ret = 1;
-            break;
-        default:
-            ret = 0;
-            break;
-    }
-    return ret;
-}
-
-static BIO_METHOD *jbs_methods = NULL;
-
-static void init_bio_methods(void)
-{
-    jbs_methods = BIO_meth_new(BIO_TYPE_FILE, "Java Callback");
-    BIO_meth_set_write(jbs_methods, &jbs_write);
-    BIO_meth_set_read(jbs_methods, &jbs_read);
-    BIO_meth_set_puts(jbs_methods, &jbs_puts);
-    BIO_meth_set_gets(jbs_methods, &jbs_gets);
-    BIO_meth_set_ctrl(jbs_methods, &jbs_ctrl);
-    BIO_meth_set_create(jbs_methods, &jbs_new);
-    BIO_meth_set_destroy(jbs_methods, &jbs_free);
-}
-
-static void free_bio_methods(void)
-{
-    BIO_meth_free(jbs_methods);
-}
-
 /*** Begin Twitter 1:1 API addition ***/
 TCN_IMPLEMENT_CALL(jint, SSL, getLastErrorNumber)(TCN_STDARGS) {
     UNREFERENCED_STDARGS;
diff --git a/native/src/sslcontext.c b/native/src/sslcontext.c
index cc86da503..05bc68ec7 100644
--- a/native/src/sslcontext.c
+++ b/native/src/sslcontext.c
@@ -49,11 +49,11 @@ static apr_status_t ssl_context_cleanup(void *data)
             }
         }
         if (c->bio_is) {
-            SSL_BIO_close(c->bio_is);
+            BIO_free(c->bio_is);
             c->bio_is = NULL;
         }
         if (c->bio_os) {
-            SSL_BIO_close(c->bio_os);
+            BIO_free(c->bio_os);
             c->bio_os = NULL;
         }
 


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to