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
+3 -12
View File
@@ -240,20 +240,11 @@ static config_type_t get_config_type (private_cp_payload_t *this)
/**
* Implementation of payload_t.destroy and cp_payload_t.destroy.
*/
static status_t destroy(private_cp_payload_t *this)
static void destroy(private_cp_payload_t *this)
{
/* all attributes are getting destroyed */
while (this->attributes->get_count(this->attributes) > 0)
{
configuration_attribute_t *current_attribute;
this->attributes->remove_last(this->attributes,(void **)&current_attribute);
current_attribute->destroy(current_attribute);
}
this->attributes->destroy(this->attributes);
this->attributes->destroy_offset(this->attributes,
offsetof(configuration_attribute_t, destroy));
free(this);
return SUCCESS;
}
/*
@@ -600,14 +600,7 @@ static status_t verify_signature(private_encryption_payload_t *this, chunk_t dat
*/
static void destroy(private_encryption_payload_t *this)
{
/* all proposals are getting destroyed */
while (this->payloads->get_count(this->payloads) > 0)
{
payload_t *current_payload;
this->payloads->remove_last(this->payloads,(void **)&current_payload);
current_payload->destroy(current_payload);
}
this->payloads->destroy(this->payloads);
this->payloads->destroy_offset(this->payloads, offsetof(payload_t, destroy));
free(this->encrypted.ptr);
free(this->decrypted.ptr);
free(this);
@@ -472,28 +472,12 @@ static private_proposal_substructure_t* clone_(private_proposal_substructure_t *
* Implements payload_t's and proposal_substructure_t's destroy function.
* See #payload_s.destroy or proposal_substructure_s.destroy for description.
*/
static status_t destroy(private_proposal_substructure_t *this)
static void destroy(private_proposal_substructure_t *this)
{
/* all proposals are getting destroyed */
while (this->transforms->get_count(this->transforms) > 0)
{
transform_substructure_t *current_transform;
if (this->transforms->remove_last(this->transforms,(void **)&current_transform) != SUCCESS)
{
break;
}
current_transform->destroy(current_transform);
}
this->transforms->destroy(this->transforms);
if (this->spi.ptr != NULL)
{
free(this->spi.ptr);
}
this->transforms->destroy_offset(this->transforms,
offsetof(transform_substructure_t, destroy));
chunk_free(&this->spi);
free(this);
return SUCCESS;
}
/*
+2 -10
View File
@@ -165,17 +165,9 @@ static status_t verify(private_sa_payload_t *this)
*/
static status_t destroy(private_sa_payload_t *this)
{
/* all proposals are getting destroyed */
while (this->proposals->get_count(this->proposals) > 0)
{
proposal_substructure_t *current_proposal;
this->proposals->remove_last(this->proposals,(void **)&current_proposal);
current_proposal->destroy(current_proposal);
}
this->proposals->destroy(this->proposals);
this->proposals->destroy_offset(this->proposals,
offsetof(proposal_substructure_t, destroy));
free(this);
return SUCCESS;
}
@@ -354,15 +354,8 @@ static status_t get_key_length(private_transform_substructure_t *this, u_int16_t
*/
static void destroy(private_transform_substructure_t *this)
{
/* all proposals are getting destroyed */
while (this->attributes->get_count(this->attributes) > 0)
{
transform_attribute_t *current_attribute;
this->attributes->remove_last(this->attributes,(void **)&current_attribute);
current_attribute->destroy(current_attribute);
}
this->attributes->destroy(this->attributes);
this->attributes->destroy_offset(this->attributes,
offsetof(transform_attribute_t, destroy));
free(this);
}
+3 -12
View File
@@ -280,18 +280,9 @@ static linked_list_t *get_traffic_selectors(private_ts_payload_t *this)
*/
static void destroy(private_ts_payload_t *this)
{
while (this->traffic_selectors->get_count(this->traffic_selectors) > 0)
{
payload_t *current_traffic_selector;
this->traffic_selectors->remove_last(this->traffic_selectors,(void **) &current_traffic_selector);
current_traffic_selector->destroy(current_traffic_selector);
}
this->traffic_selectors->destroy(this->traffic_selectors);
free(this);
this->traffic_selectors->destroy_offset(this->traffic_selectors,
offsetof(payload_t, destroy));
free(this);
}
/*