diff options
Diffstat (limited to 'contrib/apr-util/crypto/apr_crypto.c')
-rw-r--r-- | contrib/apr-util/crypto/apr_crypto.c | 80 |
1 files changed, 42 insertions, 38 deletions
diff --git a/contrib/apr-util/crypto/apr_crypto.c b/contrib/apr-util/crypto/apr_crypto.c index 4a1049c..7643b94 100644 --- a/contrib/apr-util/crypto/apr_crypto.c +++ b/contrib/apr-util/crypto/apr_crypto.c @@ -68,13 +68,14 @@ typedef struct apr_crypto_clear_t { } apr_crypto_clear_t; #if !APU_DSO_BUILD -#define DRIVER_LOAD(name,driver,pool,params) \ +#define DRIVER_LOAD(name,driver_name,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); \ + extern const apr_crypto_driver_t driver_name; \ + apr_hash_set(drivers,name,APR_HASH_KEY_STRING,&driver_name); \ + if (driver_name.init) { \ + rv = driver_name.init(pool, params, result); \ } \ + *driver = &driver_name; \ } #endif @@ -107,22 +108,6 @@ APU_DECLARE(apr_status_t) apr_crypto_init(apr_pool_t *pool) #endif drivers = apr_hash_make(pool); -#if !APU_DSO_BUILD - /* 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 /* APU_DSO_BUILD */ - apr_pool_cleanup_register(pool, NULL, apr_crypto_term, apr_pool_cleanup_null); @@ -165,7 +150,10 @@ APU_DECLARE(apr_status_t) apr_crypto_get_driver( apr_dso_handle_sym_t symbol; #endif apr_status_t rv; - int rc = 0; + + if (result) { + *result = NULL; /* until further notice */ + } #if APU_DSO_BUILD rv = apu_dso_mutex_lock(); @@ -197,37 +185,53 @@ APU_DECLARE(apr_status_t) apr_crypto_get_driver( #endif apr_snprintf(symname, sizeof(symname), "apr_crypto_%s_driver", name); rv = apu_dso_load(&dso, &symbol, modname, symname, pool); - if (rv != APR_SUCCESS) { /* APR_EDSOOPEN or APR_ESYMNOTFOUND? */ - if (rv == APR_EINIT) { /* previously loaded?!? */ - name = apr_pstrdup(pool, name); - apr_hash_set(drivers, name, APR_HASH_KEY_STRING, *driver); - rv = APR_SUCCESS; + if (rv == APR_SUCCESS || rv == APR_EINIT) { /* previously loaded?!? */ + *driver = symbol; + name = apr_pstrdup(pool, name); + apr_hash_set(drivers, name, APR_HASH_KEY_STRING, *driver); + rv = APR_SUCCESS; + if ((*driver)->init) { + rv = (*driver)->init(pool, params, result); } - goto unlock; - } - *driver = symbol; - if ((*driver)->init) { - rv = (*driver)->init(pool, params, &rc); } - name = apr_pstrdup(pool, name); - apr_hash_set(drivers, name, APR_HASH_KEY_STRING, *driver); - - unlock: apu_dso_mutex_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 + if (name[0] == 'n' && !strcmp(name, "nss")) { + DRIVER_LOAD("nss", apr_crypto_nss_driver, pool, params, rv, result); + } +#endif +#if APU_HAVE_MSCAPI + if (name[0] == 'm' && !strcmp(name, "mscapi")) { + DRIVER_LOAD("mscapi", apr_crypto_mscapi_driver, pool, params, rv, result); + } +#endif +#if APU_HAVE_MSCNG + if (name[0] == 'm' && !strcmp(name, "mscng")) { + DRIVER_LOAD("mscng", apr_crypto_mscng_driver, pool, params, rv, result); + } +#endif + #endif return rv; |