Replaced more complex iterator usages.
This commit is contained in:
parent
67405ce808
commit
47daa0e6fe
|
@ -138,26 +138,26 @@ METHOD(ike_cfg_t, get_proposals, linked_list_t*,
|
|||
METHOD(ike_cfg_t, select_proposal, proposal_t*,
|
||||
private_ike_cfg_t *this, linked_list_t *proposals, bool private)
|
||||
{
|
||||
iterator_t *stored_iter, *supplied_iter;
|
||||
enumerator_t *stored_enum, *supplied_enum;
|
||||
proposal_t *stored, *supplied, *selected;
|
||||
|
||||
stored_iter = this->proposals->create_iterator(this->proposals, TRUE);
|
||||
supplied_iter = proposals->create_iterator(proposals, TRUE);
|
||||
stored_enum = this->proposals->create_enumerator(this->proposals);
|
||||
supplied_enum = proposals->create_enumerator(proposals);
|
||||
|
||||
|
||||
/* compare all stored proposals with all supplied. Stored ones are preferred.*/
|
||||
while (stored_iter->iterate(stored_iter, (void**)&stored))
|
||||
while (stored_enum->enumerate(stored_enum, (void**)&stored))
|
||||
{
|
||||
supplied_iter->reset(supplied_iter);
|
||||
proposals->reset_enumerator(proposals, supplied_enum);
|
||||
|
||||
while (supplied_iter->iterate(supplied_iter, (void**)&supplied))
|
||||
while (supplied_enum->enumerate(supplied_enum, (void**)&supplied))
|
||||
{
|
||||
selected = stored->select(stored, supplied, private);
|
||||
if (selected)
|
||||
{
|
||||
/* they match, return */
|
||||
stored_iter->destroy(stored_iter);
|
||||
supplied_iter->destroy(supplied_iter);
|
||||
stored_enum->destroy(stored_enum);
|
||||
supplied_enum->destroy(supplied_enum);
|
||||
DBG2(DBG_CFG, "received proposals: %#P", proposals);
|
||||
DBG2(DBG_CFG, "configured proposals: %#P", this->proposals);
|
||||
DBG2(DBG_CFG, "selected proposal: %P", selected);
|
||||
|
@ -166,8 +166,8 @@ METHOD(ike_cfg_t, select_proposal, proposal_t*,
|
|||
}
|
||||
}
|
||||
/* no proposal match :-(, will result in a NO_PROPOSAL_CHOSEN... */
|
||||
stored_iter->destroy(stored_iter);
|
||||
supplied_iter->destroy(supplied_iter);
|
||||
stored_enum->destroy(stored_enum);
|
||||
supplied_enum->destroy(supplied_enum);
|
||||
DBG1(DBG_CFG, "received proposals: %#P", proposals);
|
||||
DBG1(DBG_CFG, "configured proposals: %#P", this->proposals);
|
||||
|
||||
|
|
|
@ -628,35 +628,30 @@ static linked_list_t* create_unique_cert_list(certificate_type_t type)
|
|||
|
||||
while (enumerator->enumerate(enumerator, (void**)&cert))
|
||||
{
|
||||
iterator_t *iterator = list->create_iterator(list, TRUE);
|
||||
enumerator_t *added = list->create_enumerator(list);
|
||||
identification_t *issuer = cert->get_issuer(cert);
|
||||
bool previous_same, same = FALSE, last = TRUE;
|
||||
bool previous_same, same = FALSE, found = FALSE;
|
||||
certificate_t *list_cert;
|
||||
|
||||
while (iterator->iterate(iterator, (void**)&list_cert))
|
||||
while (added->enumerate(added, (void**)&list_cert))
|
||||
{
|
||||
/* exit if we have a duplicate? */
|
||||
if (list_cert->equals(list_cert, cert))
|
||||
{
|
||||
last = FALSE;
|
||||
{ /* stop if we found a duplicate*/
|
||||
found = TRUE;
|
||||
break;
|
||||
}
|
||||
/* group certificates with same issuer */
|
||||
previous_same = same;
|
||||
same = list_cert->has_issuer(list_cert, issuer);
|
||||
if (previous_same && !same)
|
||||
{
|
||||
iterator->insert_before(iterator, (void *)cert->get_ref(cert));
|
||||
last = FALSE;
|
||||
{ /* group certificates with same issuer */
|
||||
break;
|
||||
}
|
||||
}
|
||||
iterator->destroy(iterator);
|
||||
|
||||
if (last)
|
||||
if (!found)
|
||||
{
|
||||
list->insert_last(list, (void *)cert->get_ref(cert));
|
||||
list->insert_before(list, added, cert->get_ref(cert));
|
||||
}
|
||||
added->destroy(added);
|
||||
}
|
||||
enumerator->destroy(enumerator);
|
||||
return list;
|
||||
|
|
|
@ -550,26 +550,15 @@ static status_t endpoints_contain(linked_list_t *endpoints, host_t *host,
|
|||
*/
|
||||
static void insert_pair_by_priority(linked_list_t *pairs, endpoint_pair_t *pair)
|
||||
{
|
||||
iterator_t *iterator;
|
||||
enumerator_t *enumerator = pairs->create_enumerator(pairs);
|
||||
endpoint_pair_t *current;
|
||||
bool inserted = FALSE;
|
||||
|
||||
iterator = pairs->create_iterator(pairs, TRUE);
|
||||
while (iterator->iterate(iterator, (void**)¤t))
|
||||
while (enumerator->enumerate(enumerator, (void**)¤t) &&
|
||||
current->priority >= pair->priority)
|
||||
{
|
||||
if (current->priority < pair->priority)
|
||||
{
|
||||
iterator->insert_before(iterator, pair);
|
||||
inserted = TRUE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
iterator->destroy(iterator);
|
||||
|
||||
if (!inserted)
|
||||
{
|
||||
pairs->insert_last(pairs, pair);
|
||||
continue;
|
||||
}
|
||||
pairs->insert_before(pairs, enumerator, pair);
|
||||
enumerator->destroy(enumerator);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -679,17 +668,17 @@ static void print_checklist(check_list_t *checklist)
|
|||
*/
|
||||
static void prune_pairs(linked_list_t *pairs)
|
||||
{
|
||||
iterator_t *iterator, *search;
|
||||
enumerator_t *enumerator, *search;
|
||||
endpoint_pair_t *current, *other;
|
||||
u_int32_t id = 0;
|
||||
|
||||
iterator = pairs->create_iterator(pairs, TRUE);
|
||||
search = pairs->create_iterator(pairs, TRUE);
|
||||
while (iterator->iterate(iterator, (void**)¤t))
|
||||
enumerator = pairs->create_enumerator(pairs);
|
||||
search = pairs->create_enumerator(pairs);
|
||||
while (enumerator->enumerate(enumerator, (void**)¤t))
|
||||
{
|
||||
current->id = ++id;
|
||||
|
||||
while (search->iterate(search, (void**)&other))
|
||||
while (search->enumerate(search, (void**)&other))
|
||||
{
|
||||
if (current == other)
|
||||
{
|
||||
|
@ -705,14 +694,14 @@ static void prune_pairs(linked_list_t *pairs)
|
|||
* 'current', remove it */
|
||||
DBG1(DBG_IKE, "pruning endpoint pair %#H - %#H with priority %d",
|
||||
other->local, other->remote, other->priority);
|
||||
search->remove(search);
|
||||
pairs->remove_at(pairs, search);
|
||||
endpoint_pair_destroy(other);
|
||||
}
|
||||
}
|
||||
search->reset(search);
|
||||
pairs->reset_enumerator(pairs, search);
|
||||
}
|
||||
search->destroy(search);
|
||||
iterator->destroy(iterator);
|
||||
enumerator->destroy(enumerator);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -410,34 +410,24 @@ static void ietf_attributes_add(private_ietf_attributes_t *this,
|
|||
ietf_attr_t *attr)
|
||||
{
|
||||
ietf_attr_t *current_attr;
|
||||
bool found = FALSE;
|
||||
iterator_t *iterator;
|
||||
enumerator_t *enumerator;
|
||||
int cmp = -1;
|
||||
|
||||
iterator = this->list->create_iterator(this->list, TRUE);
|
||||
while (iterator->iterate(iterator, (void **)¤t_attr))
|
||||
enumerator = this->list->create_enumerator(this->list);
|
||||
while (enumerator->enumerate(enumerator, (void **)¤t_attr) &&
|
||||
(cmp = attr->compare(attr, current_attr)) > 0)
|
||||
{
|
||||
int cmp = attr->compare(attr, current_attr);
|
||||
|
||||
if (cmp > 0)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (cmp == 0)
|
||||
{
|
||||
attr->destroy(attr);
|
||||
}
|
||||
else
|
||||
{
|
||||
iterator->insert_before(iterator, attr);
|
||||
}
|
||||
found = TRUE;
|
||||
break;
|
||||
continue;
|
||||
}
|
||||
iterator->destroy(iterator);
|
||||
if (!found)
|
||||
if (cmp == 0)
|
||||
{
|
||||
this->list->insert_last(this->list, attr);
|
||||
attr->destroy(attr);
|
||||
}
|
||||
else
|
||||
{ /* the enumerator either points to the end or to the attribute > attr */
|
||||
this->list->insert_before(this->list, enumerator, attr);
|
||||
}
|
||||
enumerator->destroy(enumerator);
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
Loading…
Reference in New Issue