diff options
author | Martin Willi <martin@strongswan.org> | 2006-10-24 08:46:17 +0000 |
---|---|---|
committer | Martin Willi <martin@strongswan.org> | 2006-10-24 08:46:17 +0000 |
commit | 55bbff11ec96f74b27afc36dd8ca3e34ff425b40 (patch) | |
tree | 9d0ff1aad70e01718405a8da314d22a86b072947 /src/charon/config | |
parent | 5c4cc9a4e328d86867959dec0e082f7e4f098a6e (diff) | |
download | strongswan-55bbff11ec96f74b27afc36dd8ca3e34ff425b40.tar.bz2 strongswan-55bbff11ec96f74b27afc36dd8ca3e34ff425b40.tar.xz |
linked list cleanups
added list methods invoke(), destroy_offset(), destroy_function()
simplified list destruction when destroying its items
Diffstat (limited to 'src/charon/config')
-rw-r--r-- | src/charon/config/connections/connection.c | 9 | ||||
-rw-r--r-- | src/charon/config/connections/local_connection_store.c | 8 | ||||
-rw-r--r-- | src/charon/config/credentials/local_credential_store.c | 59 | ||||
-rw-r--r-- | src/charon/config/policies/local_policy_store.c | 15 | ||||
-rw-r--r-- | src/charon/config/policies/policy.c | 25 | ||||
-rw-r--r-- | src/charon/config/proposal.c | 25 |
6 files changed, 19 insertions, 122 deletions
diff --git a/src/charon/config/connections/connection.c b/src/charon/config/connections/connection.c index 5dfc00eb2..dcc433c9f 100644 --- a/src/charon/config/connections/connection.c +++ b/src/charon/config/connections/connection.c @@ -333,14 +333,7 @@ static void destroy(private_connection_t *this) { if (ref_put(&this->refcount)) { - proposal_t *proposal; - - while (this->proposals->remove_last(this->proposals, (void**)&proposal) == SUCCESS) - { - proposal->destroy(proposal); - } - this->proposals->destroy(this->proposals); - + this->proposals->destroy_offset(this->proposals, offsetof(proposal_t, destroy)); this->my_host->destroy(this->my_host); this->other_host->destroy(this->other_host); free(this->name); diff --git a/src/charon/config/connections/local_connection_store.c b/src/charon/config/connections/local_connection_store.c index 8748fb730..30e7e9c8a 100644 --- a/src/charon/config/connections/local_connection_store.c +++ b/src/charon/config/connections/local_connection_store.c @@ -215,14 +215,8 @@ static iterator_t* create_iterator(private_local_connection_store_t *this) */ static void destroy (private_local_connection_store_t *this) { - connection_t *connection; - pthread_mutex_lock(&(this->mutex)); - while (this->connections->remove_last(this->connections, (void**)&connection) == SUCCESS) - { - connection->destroy(connection); - } - this->connections->destroy(this->connections); + this->connections->destroy_offset(this->connections, offsetof(connection_t, destroy)); pthread_mutex_unlock(&(this->mutex)); free(this); } diff --git a/src/charon/config/credentials/local_credential_store.c b/src/charon/config/credentials/local_credential_store.c index be9ac6acb..309f4a2fe 100644 --- a/src/charon/config/credentials/local_credential_store.c +++ b/src/charon/config/credentials/local_credential_store.c @@ -63,16 +63,8 @@ struct shared_key_t { */ static void shared_key_destroy(shared_key_t *this) { - identification_t *id; - - /* destroy peer id list */ - while (this->peers->remove_last(this->peers, (void**)&id) == SUCCESS) - { - id->destroy(id); - } - this->peers->destroy(this->peers); + this->peers->destroy_offset(this->peers, offsetof(identification_t, destroy)); chunk_free(&this->secret); - free(this); } @@ -1077,48 +1069,11 @@ error: */ static void destroy(private_local_credential_store_t *this) { - x509_t *cert; - crl_t *crl; - rsa_private_key_t *key; - shared_key_t *shared_key; - - /* destroy cert list */ - while (this->certs->remove_last(this->certs, (void**)&cert) == SUCCESS) - { - cert->destroy(cert); - } - this->certs->destroy(this->certs); - - /* destroy ca cert list */ - while (this->ca_certs->remove_last(this->ca_certs, (void**)&cert) == SUCCESS) - { - cert->destroy(cert); - } - this->ca_certs->destroy(this->ca_certs); - - /* destroy crl list */ - pthread_mutex_lock(&(this->crls_mutex)); - while (this->crls->remove_last(this->crls, (void**)&crl) == SUCCESS) - { - crl->destroy(crl); - } - this->crls->destroy(this->crls); - pthread_mutex_unlock(&(this->crls_mutex)); - - /* destroy private key list */ - while (this->private_keys->remove_last(this->private_keys, (void**)&key) == SUCCESS) - { - key->destroy(key); - } - this->private_keys->destroy(this->private_keys); - - /* destroy shared keys list */ - while (this->shared_keys->remove_last(this->shared_keys, (void**)&shared_key) == SUCCESS) - { - shared_key_destroy(shared_key); - } - this->shared_keys->destroy(this->shared_keys); - + this->certs->destroy_offset(this->certs, offsetof(x509_t, destroy)); + this->ca_certs->destroy_offset(this->ca_certs, offsetof(x509_t, destroy)); + this->crls->destroy_offset(this->crls, offsetof(crl_t, destroy)); + this->private_keys->destroy_offset(this->private_keys, offsetof(rsa_private_key_t, destroy)); + this->shared_keys->destroy_function(this->shared_keys, (void*)shared_key_destroy); free(this); } @@ -1128,7 +1083,7 @@ static void destroy(private_local_credential_store_t *this) local_credential_store_t * local_credential_store_create(bool strict) { private_local_credential_store_t *this = malloc_thing(private_local_credential_store_t); - + this->public.credential_store.get_shared_key = (status_t (*) (credential_store_t*,identification_t*,identification_t*,chunk_t*))get_shared_key; this->public.credential_store.get_rsa_public_key = (rsa_public_key_t*(*)(credential_store_t*,identification_t*))get_rsa_public_key; this->public.credential_store.get_rsa_private_key = (rsa_private_key_t* (*) (credential_store_t*,rsa_public_key_t*))get_rsa_private_key; diff --git a/src/charon/config/policies/local_policy_store.c b/src/charon/config/policies/local_policy_store.c index 577b83a28..1fca08107 100644 --- a/src/charon/config/policies/local_policy_store.c +++ b/src/charon/config/policies/local_policy_store.c @@ -69,7 +69,6 @@ static bool contains_traffic_selectors(policy_t *policy, bool mine, { linked_list_t *selected; bool contains = FALSE; - traffic_selector_t *to; if (mine) { @@ -83,11 +82,7 @@ static bool contains_traffic_selectors(policy_t *policy, bool mine, { contains = TRUE; } - while (selected->remove_last(selected, (void**)&to) == SUCCESS) - { - to->destroy(to); - } - selected->destroy(selected); + selected->destroy_offset(selected, offsetof(traffic_selector_t, destroy)); return contains; } @@ -249,14 +244,8 @@ static iterator_t* create_iterator(private_local_policy_store_t *this) */ static void destroy(private_local_policy_store_t *this) { - policy_t *policy; - pthread_mutex_lock(&(this->mutex)); - while (this->policies->remove_last(this->policies, (void**)&policy) == SUCCESS) - { - policy->destroy(policy); - } - this->policies->destroy(this->policies); + this->policies->destroy_offset(this->policies, offsetof(policy_t, destroy)); pthread_mutex_unlock(&(this->mutex)); free(this); } diff --git a/src/charon/config/policies/policy.c b/src/charon/config/policies/policy.c index dcae0504c..c9ac7884b 100644 --- a/src/charon/config/policies/policy.c +++ b/src/charon/config/policies/policy.c @@ -432,29 +432,10 @@ static void destroy(private_policy_t *this) { if (ref_put(&this->refcount)) { - proposal_t *proposal; - traffic_selector_t *traffic_selector; - /* delete proposals */ - while(this->proposals->remove_last(this->proposals, (void**)&proposal) == SUCCESS) - { - proposal->destroy(proposal); - } - this->proposals->destroy(this->proposals); - - /* delete traffic selectors */ - while(this->my_ts->remove_last(this->my_ts, (void**)&traffic_selector) == SUCCESS) - { - traffic_selector->destroy(traffic_selector); - } - this->my_ts->destroy(this->my_ts); - - /* delete traffic selectors */ - while(this->other_ts->remove_last(this->other_ts, (void**)&traffic_selector) == SUCCESS) - { - traffic_selector->destroy(traffic_selector); - } - this->other_ts->destroy(this->other_ts); + this->proposals->destroy_offset(this->proposals, offsetof(proposal_t, destroy)); + this->my_ts->destroy_offset(this->my_ts, offsetof(traffic_selector_t, destroy)); + this->other_ts->destroy_offset(this->other_ts, offsetof(traffic_selector_t, destroy)); /* delete certification authorities */ if (this->my_ca) diff --git a/src/charon/config/proposal.c b/src/charon/config/proposal.c index fac0e31c2..6b45d48bf 100644 --- a/src/charon/config/proposal.c +++ b/src/charon/config/proposal.c @@ -392,21 +392,6 @@ static proposal_t *clone_(private_proposal_t *this) return &clone->public; } -/** - * Frees all list items and destroys the list - */ -static void free_algo_list(linked_list_t *list) -{ - algorithm_t *algo; - - while(list->get_count(list) > 0) - { - list->remove_last(list, (void**)&algo); - free(algo); - } - list->destroy(list); -} - static status_t add_string_algo(private_proposal_t *this, chunk_t alg) { if (strncmp(alg.ptr, "aes128", alg.len) == 0) @@ -489,11 +474,11 @@ static status_t add_string_algo(private_proposal_t *this, chunk_t alg) */ static void destroy(private_proposal_t *this) { - free_algo_list(this->encryption_algos); - free_algo_list(this->integrity_algos); - free_algo_list(this->prf_algos); - free_algo_list(this->dh_groups); - free_algo_list(this->esns); + this->encryption_algos->destroy_function(this->encryption_algos, free); + this->integrity_algos->destroy_function(this->integrity_algos, free); + this->prf_algos->destroy_function(this->prf_algos, free); + this->dh_groups->destroy_function(this->dh_groups, free); + this->esns->destroy_function(this->esns, free); free(this); } |