aboutsummaryrefslogtreecommitdiffstats
path: root/src/charon/encoding
diff options
context:
space:
mode:
authorMartin Willi <martin@strongswan.org>2006-10-24 08:46:17 +0000
committerMartin Willi <martin@strongswan.org>2006-10-24 08:46:17 +0000
commit55bbff11ec96f74b27afc36dd8ca3e34ff425b40 (patch)
tree9d0ff1aad70e01718405a8da314d22a86b072947 /src/charon/encoding
parent5c4cc9a4e328d86867959dec0e082f7e4f098a6e (diff)
downloadstrongswan-55bbff11ec96f74b27afc36dd8ca3e34ff425b40.tar.bz2
strongswan-55bbff11ec96f74b27afc36dd8ca3e34ff425b40.tar.xz
linked list cleanups
added list methods invoke(), destroy_offset(), destroy_function() simplified list destruction when destroying its items
Diffstat (limited to 'src/charon/encoding')
-rw-r--r--src/charon/encoding/payloads/cp_payload.c15
-rw-r--r--src/charon/encoding/payloads/encryption_payload.c9
-rw-r--r--src/charon/encoding/payloads/proposal_substructure.c24
-rw-r--r--src/charon/encoding/payloads/sa_payload.c12
-rw-r--r--src/charon/encoding/payloads/transform_substructure.c11
-rw-r--r--src/charon/encoding/payloads/ts_payload.c15
6 files changed, 15 insertions, 71 deletions
diff --git a/src/charon/encoding/payloads/cp_payload.c b/src/charon/encoding/payloads/cp_payload.c
index f1297e444..580a0c64a 100644
--- a/src/charon/encoding/payloads/cp_payload.c
+++ b/src/charon/encoding/payloads/cp_payload.c
@@ -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;
}
/*
diff --git a/src/charon/encoding/payloads/encryption_payload.c b/src/charon/encoding/payloads/encryption_payload.c
index d32e6c902..c33bea781 100644
--- a/src/charon/encoding/payloads/encryption_payload.c
+++ b/src/charon/encoding/payloads/encryption_payload.c
@@ -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);
diff --git a/src/charon/encoding/payloads/proposal_substructure.c b/src/charon/encoding/payloads/proposal_substructure.c
index 58c1dd29b..5842f6e8b 100644
--- a/src/charon/encoding/payloads/proposal_substructure.c
+++ b/src/charon/encoding/payloads/proposal_substructure.c
@@ -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;
}
/*
diff --git a/src/charon/encoding/payloads/sa_payload.c b/src/charon/encoding/payloads/sa_payload.c
index e03770d1e..f0a13eb58 100644
--- a/src/charon/encoding/payloads/sa_payload.c
+++ b/src/charon/encoding/payloads/sa_payload.c
@@ -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;
}
diff --git a/src/charon/encoding/payloads/transform_substructure.c b/src/charon/encoding/payloads/transform_substructure.c
index 59e335a74..944336cc7 100644
--- a/src/charon/encoding/payloads/transform_substructure.c
+++ b/src/charon/encoding/payloads/transform_substructure.c
@@ -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);
}
diff --git a/src/charon/encoding/payloads/ts_payload.c b/src/charon/encoding/payloads/ts_payload.c
index 7cd08eeed..cce2fc282 100644
--- a/src/charon/encoding/payloads/ts_payload.c
+++ b/src/charon/encoding/payloads/ts_payload.c
@@ -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);
}
/*