removed deprecated iterator methods (has_next & current)

added iterator hook to manipulate iterator the clean way
This commit is contained in:
Martin Willi
2006-10-24 14:20:45 +00:00
parent 55bbff11ec
commit 191a26a6a7
31 changed files with 366 additions and 529 deletions
+5 -10
View File
@@ -196,14 +196,12 @@ static proposal_t *select_proposal(private_connection_t *this, linked_list_t *pr
supplied_iter = proposals->create_iterator(proposals, TRUE);
/* compare all stored proposals with all supplied. Stored ones are preferred. */
while (stored_iter->has_next(stored_iter))
while (stored_iter->iterate(stored_iter, (void**)&stored))
{
supplied_iter->reset(supplied_iter);
stored_iter->current(stored_iter, (void**)&stored);
while (supplied_iter->has_next(supplied_iter))
while (supplied_iter->iterate(supplied_iter, (void**)&supplied))
{
supplied_iter->current(supplied_iter, (void**)&supplied);
selected = stored->select(stored, supplied);
if (selected)
{
@@ -256,9 +254,8 @@ static diffie_hellman_group_t get_dh_group(private_connection_t *this)
diffie_hellman_group_t dh_group = MODP_NONE;
iterator = this->proposals->create_iterator(this->proposals, TRUE);
while (iterator->has_next(iterator))
while (iterator->iterate(iterator, (void**)&proposal))
{
iterator->current(iterator, (void**)&proposal);
if (proposal->get_algorithm(proposal, DIFFIE_HELLMAN_GROUP, &algo))
{
dh_group = algo->algorithm;
@@ -279,13 +276,11 @@ static bool check_dh_group(private_connection_t *this, diffie_hellman_group_t dh
algorithm_t *algo;
prop_iter = this->proposals->create_iterator(this->proposals, TRUE);
while (prop_iter->has_next(prop_iter))
while (prop_iter->iterate(prop_iter, (void**)&proposal))
{
prop_iter->current(prop_iter, (void**)&proposal);
alg_iter = proposal->create_algorithm_iterator(proposal, DIFFIE_HELLMAN_GROUP);
while (alg_iter->has_next(alg_iter))
while (alg_iter->iterate(alg_iter, (void**)&algo))
{
alg_iter->current(alg_iter, (void**)&algo);
if (algo->algorithm == dh_group)
{
prop_iter->destroy(prop_iter);
@@ -75,14 +75,12 @@ static connection_t *get_connection_by_hosts(private_local_connection_store_t *t
pthread_mutex_lock(&(this->mutex));
iterator = this->connections->create_iterator(this->connections, TRUE);
/* determine closest matching connection */
while (iterator->has_next(iterator))
while (iterator->iterate(iterator, (void**)&candidate))
{
host_t *candidate_my_host;
host_t *candidate_other_host;
iterator->current(iterator, (void**)&candidate);
candidate_my_host = candidate->get_my_host(candidate);
candidate_my_host = candidate->get_my_host(candidate);
candidate_other_host = candidate->get_other_host(candidate);
/* my_host addresses must match*/
@@ -138,9 +136,8 @@ static connection_t *get_connection_by_name(private_local_connection_store_t *th
pthread_mutex_lock(&(this->mutex));
iterator = this->connections->create_iterator(this->connections, TRUE);
while (iterator->has_next(iterator))
while (iterator->iterate(iterator, (void**)&current))
{
iterator->current(iterator, (void**)&current);
if (strcmp(name, current->get_name(current)) == 0)
{
found = current;
@@ -169,9 +166,8 @@ static status_t delete_connection(private_local_connection_store_t *this, char *
pthread_mutex_lock(&(this->mutex));
iterator = this->connections->create_iterator(this->connections, TRUE);
while (iterator->has_next(iterator))
while (iterator->iterate(iterator, (void **)&current))
{
iterator->current(iterator, (void **)&current);
if (strcmp(current->get_name(current), name) == 0)
{
/* remove connection from list, and destroy it */
@@ -140,7 +140,9 @@ struct private_local_credential_store_t {
/**
* Implementation of local_credential_store_t.get_shared_key.
*/
static status_t get_shared_key(private_local_credential_store_t *this, identification_t *my_id, identification_t *other_id, chunk_t *secret)
static status_t get_shared_key(private_local_credential_store_t *this,
identification_t *my_id,
identification_t *other_id, chunk_t *secret)
{
typedef enum {
PRIO_UNDEFINED= 0x00,
@@ -151,18 +153,16 @@ static status_t get_shared_key(private_local_credential_store_t *this, identific
prio_t best_prio = PRIO_UNDEFINED;
chunk_t found = CHUNK_INITIALIZER;
shared_key_t *shared_key;
iterator_t *iterator = this->shared_keys->create_iterator(this->shared_keys, TRUE);
while (iterator->has_next(iterator))
while (iterator->iterate(iterator, (void**)&shared_key))
{
shared_key_t *shared_key;
iterator_t *peer_iterator;
identification_t *peer_id;
prio_t prio = PRIO_UNDEFINED;
iterator->current(iterator, (void**)&shared_key);
peer_iterator = shared_key->peers->create_iterator(shared_key->peers, TRUE);
if (peer_iterator->get_count(peer_iterator) == 0)
@@ -172,12 +172,8 @@ static status_t get_shared_key(private_local_credential_store_t *this, identific
}
else
{
while (peer_iterator->has_next(peer_iterator))
while (peer_iterator->iterate(peer_iterator, (void**)&peer_id))
{
identification_t *peer_id;
peer_iterator->current(peer_iterator, (void**)&peer_id);
if (my_id->equals(my_id, peer_id))
{
prio |= PRIO_MY_MATCH;
@@ -212,19 +208,17 @@ static status_t get_shared_key(private_local_credential_store_t *this, identific
/**
* Implementation of credential_store_t.get_certificate.
*/
static x509_t* get_certificate(private_local_credential_store_t *this, identification_t * id)
static x509_t* get_certificate(private_local_credential_store_t *this,
identification_t * id)
{
x509_t *found = NULL;
x509_t *found = NULL, *cert;
iterator_t *iterator = this->certs->create_iterator(this->certs, TRUE);
while (iterator->has_next(iterator))
while (iterator->iterate(iterator, (void**)&cert))
{
x509_t *cert;
iterator->current(iterator, (void**)&cert);
if (id->equals(id, cert->get_subject(cert)) || cert->equals_subjectAltName(cert, id))
if (id->equals(id, cert->get_subject(cert)) ||
cert->equals_subjectAltName(cert, id))
{
found = cert;
break;
@@ -237,7 +231,8 @@ static x509_t* get_certificate(private_local_credential_store_t *this, identific
/**
* Implementation of local_credential_store_t.get_rsa_public_key.
*/
static rsa_public_key_t *get_rsa_public_key(private_local_credential_store_t *this, identification_t *id)
static rsa_public_key_t *get_rsa_public_key(private_local_credential_store_t *this,
identification_t *id)
{
x509_t *cert = get_certificate(this, id);
@@ -247,7 +242,8 @@ static rsa_public_key_t *get_rsa_public_key(private_local_credential_store_t *th
/**
* Implementation of local_credential_store_t.get_trusted_public_key.
*/
static rsa_public_key_t *get_trusted_public_key(private_local_credential_store_t *this, identification_t *id)
static rsa_public_key_t *get_trusted_public_key(private_local_credential_store_t *this,
identification_t *id)
{
cert_status_t status;
err_t ugh;
@@ -282,17 +278,15 @@ static rsa_public_key_t *get_trusted_public_key(private_local_credential_store_t
/**
* Implementation of local_credential_store_t.get_rsa_private_key.
*/
static rsa_private_key_t *get_rsa_private_key(private_local_credential_store_t *this, rsa_public_key_t *pubkey)
static rsa_private_key_t *get_rsa_private_key(private_local_credential_store_t *this,
rsa_public_key_t *pubkey)
{
rsa_private_key_t *found = NULL;
rsa_private_key_t *current;
rsa_private_key_t *found = NULL, *current;
iterator_t *iterator = this->private_keys->create_iterator(this->private_keys, TRUE);
while (iterator->has_next(iterator))
while (iterator->iterate(iterator, (void**)&current))
{
iterator->current(iterator, (void**)&current);
if (current->belongs_to(current, pubkey))
{
found = current->clone(current);
@@ -313,10 +307,8 @@ static bool has_rsa_private_key(private_local_credential_store_t *this, rsa_publ
iterator_t *iterator = this->private_keys->create_iterator(this->private_keys, TRUE);
while (iterator->has_next(iterator))
while (iterator->iterate(iterator, (void**)&current))
{
iterator->current(iterator, (void**)&current);
if (current->belongs_to(current, pubkey))
{
found = TRUE;
@@ -330,17 +322,14 @@ static bool has_rsa_private_key(private_local_credential_store_t *this, rsa_publ
/**
* Implementation of credential_store_t.get_issuer_certificate.
*/
static x509_t* get_issuer_certificate(private_local_credential_store_t *this, const x509_t *cert)
static x509_t* get_issuer_certificate(private_local_credential_store_t *this,
const x509_t *cert)
{
x509_t *issuer_cert = NULL;
x509_t *issuer_cert = NULL, *current_cert;;
iterator_t *iterator = this->ca_certs->create_iterator(this->ca_certs, TRUE);
while (iterator->has_next(iterator))
while (iterator->iterate(iterator, (void**)&current_cert))
{
x509_t *current_cert;
iterator->current(iterator, (void**)&current_cert);
if (cert->is_issuer(cert, current_cert))
{
issuer_cert = current_cert;
@@ -357,15 +346,12 @@ static x509_t* get_issuer_certificate(private_local_credential_store_t *this, co
*/
static crl_t* get_crl(private_local_credential_store_t *this, const x509_t *issuer)
{
crl_t *crl = NULL;
crl_t *crl = NULL, *current_crl;
iterator_t *iterator = this->crls->create_iterator(this->crls, TRUE);
while (iterator->has_next(iterator))
while (iterator->iterate(iterator, (void**)&current_crl))
{
crl_t *current_crl;
iterator->current(iterator, (void**)&current_crl);
if (current_crl->is_issuer(current_crl, issuer))
{
crl = current_crl;
@@ -430,15 +416,12 @@ static cert_status_t verify_by_ocsp(private_local_credential_store_t* this,
*/
static x509_t* find_certificate_copy(linked_list_t *certs, x509_t *cert)
{
x509_t *found_cert = NULL;
x509_t *found_cert = NULL, *current_cert;
iterator_t *iterator = certs->create_iterator(certs, TRUE);
while (iterator->has_next(iterator))
while (iterator->iterate(iterator, (void**)&current_cert))
{
x509_t *current_cert;
iterator->current(iterator, (void**)&current_cert);
if (cert->equals(cert, current_cert))
{
found_cert = current_cert;
@@ -733,21 +716,19 @@ static void load_ca_certificates(private_local_credential_store_t *this)
static crl_t* add_crl(linked_list_t *crls, crl_t *crl)
{
bool found = FALSE;
crl_t *current_crl;
iterator_t *iterator = crls->create_iterator(crls, TRUE);
while (iterator->has_next(iterator))
while (iterator->iterate(iterator, (void**)&current_crl))
{
crl_t *current_crl;
iterator->current(iterator, (void**)&current_crl);
if (crl->equals_issuer(crl, current_crl))
{
found = TRUE;
if (crl->is_newer(crl, current_crl))
{
crl_t *old_crl = NULL;
iterator->replace(iterator, (void**)&old_crl, (void*)crl);
if (old_crl != NULL)
{
@@ -112,13 +112,11 @@ static policy_t *get_policy(private_local_policy_store_t *this,
iterator = this->policies->create_iterator(this->policies, TRUE);
/* determine closest matching policy */
while (iterator->has_next(iterator))
while (iterator->iterate(iterator, (void**)&candidate))
{
identification_t *candidate_my_id;
identification_t *candidate_other_id;
int wildcards;
iterator->current(iterator, (void**)&candidate);
candidate_my_id = candidate->get_my_id(candidate);
candidate_other_id = candidate->get_other_id(candidate);
@@ -182,9 +180,8 @@ static policy_t *get_policy_by_name(private_local_policy_store_t *this, char *na
pthread_mutex_lock(&(this->mutex));
iterator = this->policies->create_iterator(this->policies, TRUE);
while (iterator->has_next(iterator))
while (iterator->iterate(iterator, (void **)&current))
{
iterator->current(iterator, (void **)&current);
if (strcmp(current->get_name(current), name) == 0)
{
found = current;
@@ -209,9 +206,8 @@ static status_t delete_policy(private_local_policy_store_t *this, char *name)
pthread_mutex_lock(&(this->mutex));
iterator = this->policies->create_iterator(this->policies, TRUE);
while (iterator->has_next(iterator))
while (iterator->iterate(iterator, (void **)&current))
{
iterator->current(iterator, (void **)&current);
if (strcmp(current->get_name(current), name) == 0)
{
/* remove policy from list, and destroy it */
+2 -5
View File
@@ -313,14 +313,11 @@ static proposal_t *select_proposal(private_policy_t *this, linked_list_t *propos
supplied_iter = proposals->create_iterator(proposals, TRUE);
/* compare all stored proposals with all supplied. Stored ones are preferred. */
while (stored_iter->has_next(stored_iter))
while (stored_iter->iterate(stored_iter, (void**)&stored))
{
supplied_iter->reset(supplied_iter);
stored_iter->current(stored_iter, (void**)&stored);
while (supplied_iter->has_next(supplied_iter))
while (supplied_iter->iterate(supplied_iter, (void**)&supplied))
{
supplied_iter->current(supplied_iter, (void**)&supplied);
selected = stored->select(stored, supplied);
if (selected)
{
+3 -6
View File
@@ -216,13 +216,11 @@ static bool select_algo(linked_list_t *first, linked_list_t *second, bool *add,
first_iter = first->create_iterator(first, TRUE);
second_iter = second->create_iterator(second, TRUE);
/* compare algs, order of algs in "first" is preferred */
while (first_iter->has_next(first_iter))
while (first_iter->iterate(first_iter, (void**)&first_alg))
{
first_iter->current(first_iter, (void**)&first_alg);
second_iter->reset(second_iter);
while (second_iter->has_next(second_iter))
while (second_iter->iterate(second_iter, (void**)&second_alg))
{
second_iter->current(second_iter, (void**)&second_alg);
if (first_alg->algorithm == second_alg->algorithm &&
first_alg->key_size == second_alg->key_size)
{
@@ -364,9 +362,8 @@ static void clone_algo_list(linked_list_t *list, linked_list_t *clone_list)
{
algorithm_t *algo, *clone_algo;
iterator_t *iterator = list->create_iterator(list, TRUE);
while (iterator->has_next(iterator))
while (iterator->iterate(iterator, (void**)&algo))
{
iterator->current(iterator, (void**)&algo);
clone_algo = malloc_thing(algorithm_t);
memcpy(clone_algo, algo, sizeof(algorithm_t));
clone_list->insert_last(clone_list, (void*)clone_algo);