linked list cleanups

added list methods invoke(), destroy_offset(), destroy_function()
simplified list destruction when destroying its items
This commit is contained in:
Martin Willi
2006-10-24 08:46:17 +00:00
parent 5c4cc9a4e3
commit 55bbff11ec
26 changed files with 312 additions and 551 deletions
+11 -42
View File
@@ -182,37 +182,6 @@ static void set_init_messages(private_ike_auth_t *this, chunk_t init_request, ch
this->init_response = init_response;
}
/**
* destroy a list of traffic selectors
*/
static void destroy_ts_list(linked_list_t *list)
{
if (list)
{
traffic_selector_t *ts;
while (list->remove_last(list, (void**)&ts) == SUCCESS)
{
ts->destroy(ts);
}
list->destroy(list);
}
}
/**
* destroy a list of proposals
*/
static void destroy_proposal_list(linked_list_t *list)
{
proposal_t *proposal;
while (list->remove_last(list, (void**)&proposal) == SUCCESS)
{
proposal->destroy(proposal);
}
list->destroy(list);
}
/**
* Implementation of transaction_t.get_request.
*/
@@ -330,7 +299,7 @@ static status_t get_request(private_ike_auth_t *this, message_t **result)
return DESTROY_ME;
}
sa_payload = sa_payload_create_from_proposal_list(proposal_list);
destroy_proposal_list(proposal_list);
proposal_list->destroy_offset(proposal_list, offsetof(proposal_t, destroy));
request->add_payload(request, (payload_t*)sa_payload);
}
@@ -340,7 +309,7 @@ static status_t get_request(private_ike_auth_t *this, message_t **result)
ts_list = this->policy->get_my_traffic_selectors(this->policy, me);
ts_payload = ts_payload_create_from_traffic_selectors(TRUE, ts_list);
destroy_ts_list(ts_list);
ts_list->destroy_offset(ts_list, offsetof(traffic_selector_t, destroy));
request->add_payload(request, (payload_t*)ts_payload);
}
@@ -351,7 +320,7 @@ static status_t get_request(private_ike_auth_t *this, message_t **result)
ts_list = this->policy->get_other_traffic_selectors(this->policy, other);
ts_payload = ts_payload_create_from_traffic_selectors(FALSE, ts_list);
destroy_ts_list(ts_list);
ts_list->destroy_offset(ts_list, offsetof(traffic_selector_t, destroy));
request->add_payload(request, (payload_t*)ts_payload);
}
@@ -663,8 +632,8 @@ static status_t get_response(private_ike_auth_t *this, message_t *request,
this->tsr = this->policy->select_my_traffic_selectors(this->policy, my_ts, me);
this->tsi = this->policy->select_other_traffic_selectors(this->policy, other_ts, other);
}
destroy_ts_list(my_ts);
destroy_ts_list(other_ts);
my_ts->destroy_offset(my_ts, offsetof(traffic_selector_t, destroy));
other_ts->destroy_offset(other_ts, offsetof(traffic_selector_t, destroy));
/* TODO: We should check somehow if we have a policy, but with other
* traffic selectors. Then we would create a IKE_SA without a CHILD_SA. */
@@ -762,7 +731,7 @@ static status_t get_response(private_ike_auth_t *this, message_t *request,
proposal_list = sa_request->get_proposals(sa_request);
DBG2(SIG_DBG_IKE, "selecting proposals:");
this->proposal = this->policy->select_proposal(this->policy, proposal_list);
destroy_proposal_list(proposal_list);
proposal_list->destroy_offset(proposal_list, offsetof(proposal_t, destroy));
/* do we have a proposal? */
if (this->proposal == NULL)
@@ -947,13 +916,13 @@ static status_t conclude(private_ike_auth_t *this, message_t *response,
{ /* process traffic selectors for us */
linked_list_t *ts_received = tsi_payload->get_traffic_selectors(tsi_payload);
this->tsi = this->policy->select_my_traffic_selectors(this->policy, ts_received, me);
destroy_ts_list(ts_received);
ts_received->destroy_offset(ts_received, offsetof(traffic_selector_t, destroy));
}
{ /* process traffic selectors for other */
linked_list_t *ts_received = tsr_payload->get_traffic_selectors(tsr_payload);
this->tsr = this->policy->select_other_traffic_selectors(this->policy, ts_received, other);
destroy_ts_list(ts_received);
ts_received->destroy_offset(ts_received, offsetof(traffic_selector_t, destroy));
}
{ /* process sa payload */
@@ -962,7 +931,7 @@ static status_t conclude(private_ike_auth_t *this, message_t *response,
proposal_list = sa_payload->get_proposals(sa_payload);
/* we have to re-check here if other's selection is valid */
this->proposal = this->policy->select_proposal(this->policy, proposal_list);
destroy_proposal_list(proposal_list);
proposal_list->destroy_offset(proposal_list, offsetof(proposal_t, destroy));
/* everything fine to create CHILD? */
if (this->proposal == NULL ||
@@ -995,8 +964,8 @@ static void destroy(private_ike_auth_t *this)
DESTROY_IF(this->child_sa);
DESTROY_IF(this->policy);
DESTROY_IF(this->connection);
destroy_ts_list(this->tsi);
destroy_ts_list(this->tsr);
this->tsi->destroy_offset(this->tsi, offsetof(traffic_selector_t, destroy));
this->tsr->destroy_offset(this->tsr, offsetof(traffic_selector_t, destroy));
chunk_free(&this->nonce_i);
chunk_free(&this->nonce_r);
chunk_free(&this->init_request);