Replaced more complex iterator usages.
This commit is contained in:
@@ -138,26 +138,26 @@ METHOD(ike_cfg_t, get_proposals, linked_list_t*,
|
|||||||
METHOD(ike_cfg_t, select_proposal, proposal_t*,
|
METHOD(ike_cfg_t, select_proposal, proposal_t*,
|
||||||
private_ike_cfg_t *this, linked_list_t *proposals, bool private)
|
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;
|
proposal_t *stored, *supplied, *selected;
|
||||||
|
|
||||||
stored_iter = this->proposals->create_iterator(this->proposals, TRUE);
|
stored_enum = this->proposals->create_enumerator(this->proposals);
|
||||||
supplied_iter = proposals->create_iterator(proposals, TRUE);
|
supplied_enum = proposals->create_enumerator(proposals);
|
||||||
|
|
||||||
|
|
||||||
/* compare all stored proposals with all supplied. Stored ones are preferred.*/
|
/* 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);
|
selected = stored->select(stored, supplied, private);
|
||||||
if (selected)
|
if (selected)
|
||||||
{
|
{
|
||||||
/* they match, return */
|
/* they match, return */
|
||||||
stored_iter->destroy(stored_iter);
|
stored_enum->destroy(stored_enum);
|
||||||
supplied_iter->destroy(supplied_iter);
|
supplied_enum->destroy(supplied_enum);
|
||||||
DBG2(DBG_CFG, "received proposals: %#P", proposals);
|
DBG2(DBG_CFG, "received proposals: %#P", proposals);
|
||||||
DBG2(DBG_CFG, "configured proposals: %#P", this->proposals);
|
DBG2(DBG_CFG, "configured proposals: %#P", this->proposals);
|
||||||
DBG2(DBG_CFG, "selected proposal: %P", selected);
|
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... */
|
/* no proposal match :-(, will result in a NO_PROPOSAL_CHOSEN... */
|
||||||
stored_iter->destroy(stored_iter);
|
stored_enum->destroy(stored_enum);
|
||||||
supplied_iter->destroy(supplied_iter);
|
supplied_enum->destroy(supplied_enum);
|
||||||
DBG1(DBG_CFG, "received proposals: %#P", proposals);
|
DBG1(DBG_CFG, "received proposals: %#P", proposals);
|
||||||
DBG1(DBG_CFG, "configured proposals: %#P", this->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))
|
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);
|
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;
|
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))
|
if (list_cert->equals(list_cert, cert))
|
||||||
{
|
{ /* stop if we found a duplicate*/
|
||||||
last = FALSE;
|
found = TRUE;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
/* group certificates with same issuer */
|
|
||||||
previous_same = same;
|
previous_same = same;
|
||||||
same = list_cert->has_issuer(list_cert, issuer);
|
same = list_cert->has_issuer(list_cert, issuer);
|
||||||
if (previous_same && !same)
|
if (previous_same && !same)
|
||||||
{
|
{ /* group certificates with same issuer */
|
||||||
iterator->insert_before(iterator, (void *)cert->get_ref(cert));
|
|
||||||
last = FALSE;
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
iterator->destroy(iterator);
|
if (!found)
|
||||||
|
|
||||||
if (last)
|
|
||||||
{
|
{
|
||||||
list->insert_last(list, (void *)cert->get_ref(cert));
|
list->insert_before(list, added, cert->get_ref(cert));
|
||||||
}
|
}
|
||||||
|
added->destroy(added);
|
||||||
}
|
}
|
||||||
enumerator->destroy(enumerator);
|
enumerator->destroy(enumerator);
|
||||||
return list;
|
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)
|
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;
|
endpoint_pair_t *current;
|
||||||
bool inserted = FALSE;
|
while (enumerator->enumerate(enumerator, (void**)¤t) &&
|
||||||
|
current->priority >= pair->priority)
|
||||||
iterator = pairs->create_iterator(pairs, TRUE);
|
|
||||||
while (iterator->iterate(iterator, (void**)¤t))
|
|
||||||
{
|
{
|
||||||
if (current->priority < pair->priority)
|
continue;
|
||||||
{
|
|
||||||
iterator->insert_before(iterator, pair);
|
|
||||||
inserted = TRUE;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
iterator->destroy(iterator);
|
|
||||||
|
|
||||||
if (!inserted)
|
|
||||||
{
|
|
||||||
pairs->insert_last(pairs, pair);
|
|
||||||
}
|
}
|
||||||
|
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)
|
static void prune_pairs(linked_list_t *pairs)
|
||||||
{
|
{
|
||||||
iterator_t *iterator, *search;
|
enumerator_t *enumerator, *search;
|
||||||
endpoint_pair_t *current, *other;
|
endpoint_pair_t *current, *other;
|
||||||
u_int32_t id = 0;
|
u_int32_t id = 0;
|
||||||
|
|
||||||
iterator = pairs->create_iterator(pairs, TRUE);
|
enumerator = pairs->create_enumerator(pairs);
|
||||||
search = pairs->create_iterator(pairs, TRUE);
|
search = pairs->create_enumerator(pairs);
|
||||||
while (iterator->iterate(iterator, (void**)¤t))
|
while (enumerator->enumerate(enumerator, (void**)¤t))
|
||||||
{
|
{
|
||||||
current->id = ++id;
|
current->id = ++id;
|
||||||
|
|
||||||
while (search->iterate(search, (void**)&other))
|
while (search->enumerate(search, (void**)&other))
|
||||||
{
|
{
|
||||||
if (current == other)
|
if (current == other)
|
||||||
{
|
{
|
||||||
@@ -705,14 +694,14 @@ static void prune_pairs(linked_list_t *pairs)
|
|||||||
* 'current', remove it */
|
* 'current', remove it */
|
||||||
DBG1(DBG_IKE, "pruning endpoint pair %#H - %#H with priority %d",
|
DBG1(DBG_IKE, "pruning endpoint pair %#H - %#H with priority %d",
|
||||||
other->local, other->remote, other->priority);
|
other->local, other->remote, other->priority);
|
||||||
search->remove(search);
|
pairs->remove_at(pairs, search);
|
||||||
endpoint_pair_destroy(other);
|
endpoint_pair_destroy(other);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
search->reset(search);
|
pairs->reset_enumerator(pairs, search);
|
||||||
}
|
}
|
||||||
search->destroy(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 *attr)
|
||||||
{
|
{
|
||||||
ietf_attr_t *current_attr;
|
ietf_attr_t *current_attr;
|
||||||
bool found = FALSE;
|
enumerator_t *enumerator;
|
||||||
iterator_t *iterator;
|
int cmp = -1;
|
||||||
|
|
||||||
iterator = this->list->create_iterator(this->list, TRUE);
|
enumerator = this->list->create_enumerator(this->list);
|
||||||
while (iterator->iterate(iterator, (void **)¤t_attr))
|
while (enumerator->enumerate(enumerator, (void **)¤t_attr) &&
|
||||||
|
(cmp = attr->compare(attr, current_attr)) > 0)
|
||||||
{
|
{
|
||||||
int cmp = attr->compare(attr, current_attr);
|
continue;
|
||||||
|
|
||||||
if (cmp > 0)
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (cmp == 0)
|
|
||||||
{
|
|
||||||
attr->destroy(attr);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
iterator->insert_before(iterator, attr);
|
|
||||||
}
|
|
||||||
found = TRUE;
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
iterator->destroy(iterator);
|
if (cmp == 0)
|
||||||
if (!found)
|
|
||||||
{
|
{
|
||||||
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|||||||
Reference in New Issue
Block a user