apr-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From minf...@apache.org
Subject svn commit: r1211987 - in /apr/apr/trunk: crypto/apr_crypto.c crypto/apr_crypto_nss.c crypto/apr_crypto_openssl.c include/private/apr_crypto_internal.h
Date Thu, 08 Dec 2011 17:11:06 GMT
Author: minfrin
Date: Thu Dec  8 17:11:05 2011
New Revision: 1211987

URL: http://svn.apache.org/viewvc?rev=1211987&view=rev
Log:
apr_crypto: Move the static initialisation of DRIVER_LOAD from
apr_crypto_init() to apr_crypto_get_driver(), so that we don't lose
the parameters.

Modified:
    apr/apr/trunk/crypto/apr_crypto.c
    apr/apr/trunk/crypto/apr_crypto_nss.c
    apr/apr/trunk/crypto/apr_crypto_openssl.c
    apr/apr/trunk/include/private/apr_crypto_internal.h

Modified: apr/apr/trunk/crypto/apr_crypto.c
URL: http://svn.apache.org/viewvc/apr/apr/trunk/crypto/apr_crypto.c?rev=1211987&r1=1211986&r2=1211987&view=diff
==============================================================================
--- apr/apr/trunk/crypto/apr_crypto.c (original)
+++ apr/apr/trunk/crypto/apr_crypto.c Thu Dec  8 17:11:05 2011
@@ -62,12 +62,12 @@ typedef struct apr_crypto_clear_t {
 } apr_crypto_clear_t;
 
 #if !APR_HAVE_MODULAR_DSO
-#define DRIVER_LOAD(name,driver,pool,params) \
+#define DRIVER_LOAD(name,driver,pool,params,rv,result) \
     {   \
         extern const apr_crypto_driver_t driver; \
         apr_hash_set(drivers,name,APR_HASH_KEY_STRING,&driver); \
         if (driver.init) {     \
-            driver.init(pool, params); \
+            rv = driver.init(pool, params, result); \
         }  \
     }
 #endif
@@ -101,22 +101,6 @@ APR_DECLARE(apr_status_t) apr_crypto_ini
 #endif
     drivers = apr_hash_make(pool);
 
-#if !APR_HAVE_MODULAR_DSO
-    /* Load statically-linked drivers: */
-#if APU_HAVE_OPENSSL
-    DRIVER_LOAD("openssl", apr_crypto_openssl_driver, pool, params);
-#endif
-#if APU_HAVE_NSS
-    DRIVER_LOAD("nss", apr_crypto_nss_driver, pool, params);
-#endif
-#if APU_HAVE_MSCAPI
-    DRIVER_LOAD("mscapi", apr_crypto_mscapi_driver, pool, params);
-#endif
-#if APU_HAVE_MSCNG
-    DRIVER_LOAD("mscng", apr_crypto_mscng_driver, pool, params);
-#endif
-#endif /* APR_HAVE_MODULAR_DSO */
-
     apr_pool_cleanup_register(pool, NULL, apr_crypto_term,
             apr_pool_cleanup_null);
 
@@ -159,7 +143,10 @@ APR_DECLARE(apr_status_t) apr_crypto_get
     apr_dso_handle_sym_t symbol;
 #endif
     apr_status_t rv;
-    int rc = 0;
+
+    if (result) {
+        *result = NULL; /* until further notice */
+    }
 
 #if APR_HAVE_MODULAR_DSO
     rv = apu_dso_mutex_lock();
@@ -201,27 +188,51 @@ APR_DECLARE(apr_status_t) apr_crypto_get
     }
     *driver = symbol;
     if ((*driver)->init) {
-        rv = (*driver)->init(pool, params, &rc);
+        rv = (*driver)->init(pool, params, result);
+    }
+    if (rv == APR_SUCCESS) {
+        name = apr_pstrdup(pool, name);
+        apr_hash_set(drivers, name, APR_HASH_KEY_STRING, *driver);
     }
-    name = apr_pstrdup(pool, name);
-    apr_hash_set(drivers, name, APR_HASH_KEY_STRING, *driver);
 
     unlock: apu_dso_mutex_unlock();
 
-    if (APR_SUCCESS != rv && result) {
+    if (APR_SUCCESS != rv && result && !*result) {
         char *buffer = apr_pcalloc(pool, ERROR_SIZE);
         apu_err_t *err = apr_pcalloc(pool, sizeof(apu_err_t));
         if (err && buffer) {
             apr_dso_error(dso, buffer, ERROR_SIZE - 1);
             err->msg = buffer;
             err->reason = modname;
-            err->rc = rc;
             *result = err;
         }
     }
 
 #else /* not builtin and !APR_HAS_DSO => not implemented */
     rv = APR_ENOTIMPL;
+
+    /* Load statically-linked drivers: */
+#if APU_HAVE_OPENSSL
+    if (name[0] == 'o' && !strcmp(name, "openssl")) {
+        DRIVER_LOAD("openssl", apr_crypto_openssl_driver, pool, params, rv, result);
+    }
+#endif
+#if APU_HAVE_NSS
+    else if (name[0] == 'n' && !strcmp(name, "nss")) {
+        DRIVER_LOAD("nss", apr_crypto_nss_driver, pool, params, rv, result);
+    }
+#endif
+#if APU_HAVE_MSCAPI
+    else if (name[0] == 'm' && !strcmp(name, "mscapi")) {
+        DRIVER_LOAD("mscapi", apr_crypto_mscapi_driver, pool, params, rv, result);
+    }
+#endif
+#if APU_HAVE_MSCNG
+    else if (name[0] == 'm' && !strcmp(name, "mscng")) {
+        DRIVER_LOAD("mscng", apr_crypto_mscng_driver, pool, params, rv, result);
+    }
+#endif
+
 #endif
 
     return rv;

Modified: apr/apr/trunk/crypto/apr_crypto_nss.c
URL: http://svn.apache.org/viewvc/apr/apr/trunk/crypto/apr_crypto_nss.c?rev=1211987&r1=1211986&r2=1211987&view=diff
==============================================================================
--- apr/apr/trunk/crypto/apr_crypto_nss.c (original)
+++ apr/apr/trunk/crypto/apr_crypto_nss.c Thu Dec  8 17:11:05 2011
@@ -120,7 +120,8 @@ static apr_status_t crypto_shutdown_help
 /**
  * Initialise the crypto library and perform one time initialisation.
  */
-static apr_status_t crypto_init(apr_pool_t *pool, const char *params, int *rc)
+static apr_status_t crypto_init(apr_pool_t *pool, const char *params,
+        const apu_err_t **result)
 {
     SECStatus s;
     const char *dir = NULL;
@@ -208,8 +209,12 @@ static apr_status_t crypto_init(apr_pool
         s = NSS_NoDB_Init(NULL);
     }
     if (s != SECSuccess) {
-        if (rc) {
-            *rc = PR_GetError();
+        if (result) {
+            apu_err_t *err = apr_pcalloc(pool, sizeof(apu_err_t));
+            err->rc = PR_GetError();
+            err->msg = PR_ErrorToName(s);
+            err->reason = "Error during 'nss' initialisation";
+            *result = err;
         }
         return APR_ECRYPT;
     }

Modified: apr/apr/trunk/crypto/apr_crypto_openssl.c
URL: http://svn.apache.org/viewvc/apr/apr/trunk/crypto/apr_crypto_openssl.c?rev=1211987&r1=1211986&r2=1211987&view=diff
==============================================================================
--- apr/apr/trunk/crypto/apr_crypto_openssl.c (original)
+++ apr/apr/trunk/crypto/apr_crypto_openssl.c Thu Dec  8 17:11:05 2011
@@ -109,7 +109,8 @@ static apr_status_t crypto_shutdown_help
 /**
  * Initialise the crypto library and perform one time initialisation.
  */
-static apr_status_t crypto_init(apr_pool_t *pool, const char *params, int *rc)
+static apr_status_t crypto_init(apr_pool_t *pool, const char *params,
+        const apu_err_t **result)
 {
     CRYPTO_malloc_init();
     ERR_load_crypto_strings();

Modified: apr/apr/trunk/include/private/apr_crypto_internal.h
URL: http://svn.apache.org/viewvc/apr/apr/trunk/include/private/apr_crypto_internal.h?rev=1211987&r1=1211986&r2=1211987&view=diff
==============================================================================
--- apr/apr/trunk/include/private/apr_crypto_internal.h (original)
+++ apr/apr/trunk/include/private/apr_crypto_internal.h Thu Dec  8 17:11:05 2011
@@ -39,7 +39,8 @@ struct apr_crypto_driver_t {
      * @param params Optional init parameter string.
      * @param rc Driver-specific additional error code
      */
-    apr_status_t (*init)(apr_pool_t *pool, const char *params, int *rc);
+    apr_status_t (*init)(apr_pool_t *pool, const char *params,
+            const apu_err_t **result);
 
     /**
      * @brief Create a context for supporting encryption. Keys, certificates,



Mime
View raw message