&& (store = get_default_method_store(libctx)) == NULL)
return 0;
- if (methdata->refcnt_up_method(method)
- && ossl_method_store_add(store, methid, propdef, method,
- methdata->destruct_method))
- return 1;
- return 0;
+ return ossl_method_store_add(store, methid, propdef, method,
+ methdata->refcnt_up_method,
+ methdata->destruct_method);
}
static void *construct_method(const char *name, const OSSL_DISPATCH *fns,
}
int ossl_method_store_add(OSSL_METHOD_STORE *store,
- int nid, const char *properties,
- void *method, void (*method_destruct)(void *))
+ int nid, const char *properties, void *method,
+ int (*method_up_ref)(void *),
+ void (*method_destruct)(void *))
{
ALGORITHM *alg = NULL;
IMPLEMENTATION *impl;
impl = OPENSSL_malloc(sizeof(*impl));
if (impl == NULL)
return 0;
+ if (method_up_ref != NULL && !method_up_ref(method))
+ return 0;
impl->method = method;
impl->method_destruct = method_destruct;
int ossl_method_store_init(OPENSSL_CTX *ctx);
void ossl_method_store_cleanup(OPENSSL_CTX *ctx);
int ossl_method_store_add(OSSL_METHOD_STORE *store,
- int nid, const char *properties,
- void *method, void (*method_destruct)(void *));
+ int nid, const char *properties, void *method,
+ int (*method_up_ref)(void *),
+ void (*method_destruct)(void *));
int ossl_method_store_remove(OSSL_METHOD_STORE *store,
int nid, const void *method);
int ossl_method_store_fetch(OSSL_METHOD_STORE *store,
ossl_method_store_add() adds the B<method> to the B<store> as an instance of an
algorithm indicated by B<nid> and the property definition B<properties>.
-The optional B<method_destruct> function is called when B<method> is being
-released from B<store>.
+If the B<method_up_ref> function is given, it's called to increment the
+reference count of the method.
+If the B<method_destruct> function is given, it's called when this function
+fails to add the method to the store, or later on when it is being released from
+the B<store>.
ossl_method_store_remove() removes the B<method> identified by B<nid> from the
B<store>.
void ossl_method_store_free(OSSL_METHOD_STORE *store);
int ossl_method_store_add(OSSL_METHOD_STORE *store, int nid,
const char *properties, void *implementation,
+ int (*implementation_up_ref)(void *),
void (*implementation_destruct)(void *));
int ossl_method_store_remove(OSSL_METHOD_STORE *store,
int nid, const void *implementation);
for (i = 0; i < OSSL_NELEM(impls); i++)
if (!TEST_true(ossl_method_store_add(store, impls[i].nid, impls[i].prop,
- impls[i].impl, NULL))) {
+ impls[i].impl, NULL, NULL))) {
TEST_note("iteration %zd", i + 1);
goto err;
}
for (i = 0; i < OSSL_NELEM(impls); i++)
if (!TEST_true(ossl_method_store_add(store, impls[i].nid, impls[i].prop,
- impls[i].impl, NULL))) {
+ impls[i].impl, NULL, NULL))) {
TEST_note("iteration %zd", i + 1);
goto err;
}
for (i = 1; i <= max; i++) {
v[i] = 2 * i;
BIO_snprintf(buf, sizeof(buf), "n=%d\n", i);
- if (!TEST_true(ossl_method_store_add(store, i, buf, "abc", NULL))
+ if (!TEST_true(ossl_method_store_add(store, i, buf, "abc", NULL, NULL))
|| !TEST_true(ossl_method_store_cache_set(store, i, buf, v + i))
|| !TEST_true(ossl_method_store_cache_set(store, i, "n=1234",
"miss"))) {