aboutsummaryrefslogtreecommitdiffstats
path: root/src/charon/encoding
diff options
context:
space:
mode:
Diffstat (limited to 'src/charon/encoding')
-rw-r--r--src/charon/encoding/generator.c48
-rw-r--r--src/charon/encoding/message.c36
-rw-r--r--src/charon/encoding/payloads/cp_payload.c17
-rw-r--r--src/charon/encoding/payloads/encryption_payload.c11
-rw-r--r--src/charon/encoding/payloads/proposal_substructure.c86
-rw-r--r--src/charon/encoding/payloads/sa_payload.c23
-rw-r--r--src/charon/encoding/payloads/transform_substructure.c52
-rw-r--r--src/charon/encoding/payloads/ts_payload.c21
8 files changed, 108 insertions, 186 deletions
diff --git a/src/charon/encoding/generator.c b/src/charon/encoding/generator.c
index 392a4602d..6eb3c5d66 100644
--- a/src/charon/encoding/generator.c
+++ b/src/charon/encoding/generator.c
@@ -803,19 +803,17 @@ static void generate_payload (private_generator_t *this,payload_t *payload)
u_int16_t int16_val;
/* proposals are stored in a linked list and so accessed */
linked_list_t *proposals = *((linked_list_t **)(this->data_struct + rules[i].offset));
-
iterator_t *iterator;
+ payload_t *current_proposal;
+
/* create forward iterator */
iterator = proposals->create_iterator(proposals,TRUE);
/* every proposal is processed (iterative call )*/
- while (iterator->has_next(iterator))
+ while (iterator->iterate(iterator, (void**)&current_proposal))
{
- payload_t *current_proposal;
u_int32_t before_generate_position_offset;
u_int32_t after_generate_position_offset;
- iterator->current(iterator,(void **)&current_proposal);
-
before_generate_position_offset = this->get_current_buffer_offset(this);
this->public.generate_payload(&(this->public),current_proposal);
after_generate_position_offset = this->get_current_buffer_offset(this);
@@ -828,26 +826,24 @@ static void generate_payload (private_generator_t *this,payload_t *payload)
int16_val = htons(length_of_sa_payload);
this->write_bytes_to_buffer_at_offset(this,&int16_val,sizeof(u_int16_t),payload_length_position_offset);
break;
- }
+ }
case TRANSFORMS:
- {
+ {
/* before iterative generate the transforms, store the current length position */
u_int32_t payload_length_position_offset = this->last_payload_length_position_offset;
u_int16_t length_of_proposal = PROPOSAL_SUBSTRUCTURE_HEADER_LENGTH + this->last_spi_size;
u_int16_t int16_val;
linked_list_t *transforms = *((linked_list_t **)(this->data_struct + rules[i].offset));
iterator_t *iterator;
-
+ payload_t *current_transform;
+
/* create forward iterator */
iterator = transforms->create_iterator(transforms,TRUE);
- while (iterator->has_next(iterator))
+ while (iterator->iterate(iterator, (void**)&current_transform))
{
- payload_t *current_transform;
u_int32_t before_generate_position_offset;
u_int32_t after_generate_position_offset;
- iterator->current(iterator,(void **)&current_transform);
-
before_generate_position_offset = this->get_current_buffer_offset(this);
this->public.generate_payload(&(this->public),current_transform);
after_generate_position_offset = this->get_current_buffer_offset(this);
@@ -857,7 +853,7 @@ static void generate_payload (private_generator_t *this,payload_t *payload)
}
iterator->destroy(iterator);
-
+
int16_val = htons(length_of_proposal);
this->write_bytes_to_buffer_at_offset(this,&int16_val,sizeof(u_int16_t),payload_length_position_offset);
@@ -867,22 +863,19 @@ static void generate_payload (private_generator_t *this,payload_t *payload)
{
/* before iterative generate the transform attributes, store the current length position */
u_int32_t transform_length_position_offset = this->last_payload_length_position_offset;
-
u_int16_t length_of_transform = TRANSFORM_SUBSTRUCTURE_HEADER_LENGTH;
u_int16_t int16_val;
linked_list_t *transform_attributes =*((linked_list_t **)(this->data_struct + rules[i].offset));
-
iterator_t *iterator;
+ payload_t *current_attribute;
+
/* create forward iterator */
iterator = transform_attributes->create_iterator(transform_attributes,TRUE);
- while (iterator->has_next(iterator))
+ while (iterator->iterate(iterator, (void**)&current_attribute))
{
- payload_t *current_attribute;
u_int32_t before_generate_position_offset;
u_int32_t after_generate_position_offset;
- iterator->current(iterator,(void **)&current_attribute);
-
before_generate_position_offset = this->get_current_buffer_offset(this);
this->public.generate_payload(&(this->public),current_attribute);
after_generate_position_offset = this->get_current_buffer_offset(this);
@@ -902,22 +895,19 @@ static void generate_payload (private_generator_t *this,payload_t *payload)
{
/* before iterative generate the configuration attributes, store the current length position */
u_int32_t configurations_length_position_offset = this->last_payload_length_position_offset;
-
u_int16_t length_of_configurations = CP_PAYLOAD_HEADER_LENGTH;
u_int16_t int16_val;
linked_list_t *configuration_attributes =*((linked_list_t **)(this->data_struct + rules[i].offset));
-
iterator_t *iterator;
+ payload_t *current_attribute;
+
/* create forward iterator */
iterator = configuration_attributes->create_iterator(configuration_attributes,TRUE);
- while (iterator->has_next(iterator))
+ while (iterator->iterate(iterator, (void**)&current_attribute))
{
- payload_t *current_attribute;
u_int32_t before_generate_position_offset;
u_int32_t after_generate_position_offset;
- iterator->current(iterator,(void **)&current_attribute);
-
before_generate_position_offset = this->get_current_buffer_offset(this);
this->public.generate_payload(&(this->public),current_attribute);
after_generate_position_offset = this->get_current_buffer_offset(this);
@@ -974,18 +964,16 @@ static void generate_payload (private_generator_t *this,payload_t *payload)
u_int16_t int16_val;
/* traffic selectors are stored in a linked list and so accessed */
linked_list_t *traffic_selectors = *((linked_list_t **)(this->data_struct + rules[i].offset));
-
iterator_t *iterator;
+ payload_t *current_traffic_selector_substructure;
+
/* create forward iterator */
iterator = traffic_selectors->create_iterator(traffic_selectors,TRUE);
/* every proposal is processed (iterative call )*/
- while (iterator->has_next(iterator))
+ while (iterator->iterate(iterator, (void **)&current_traffic_selector_substructure))
{
- payload_t *current_traffic_selector_substructure;
u_int32_t before_generate_position_offset;
u_int32_t after_generate_position_offset;
-
- iterator->current(iterator,(void **)&current_traffic_selector_substructure);
before_generate_position_offset = this->get_current_buffer_offset(this);
this->public.generate_payload(&(this->public),current_traffic_selector_substructure);
diff --git a/src/charon/encoding/message.c b/src/charon/encoding/message.c
index 65e4729b3..44850313c 100644
--- a/src/charon/encoding/message.c
+++ b/src/charon/encoding/message.c
@@ -751,9 +751,8 @@ static status_t generate(private_message_t *this, crypter_t *crypter, signer_t*
/* generate every payload expect last one, this is doen later*/
iterator = this->payloads->create_iterator(this->payloads, TRUE);
- while(iterator->has_next(iterator))
+ while(iterator->iterate(iterator, (void**)&next_payload))
{
- iterator->current(iterator, (void**)&next_payload);
payload->set_next_type(payload, next_payload->get_type(next_payload));
generator->generate_payload(generator, payload);
payload = next_payload;
@@ -878,19 +877,16 @@ static status_t decrypt_payloads(private_message_t *this,crypter_t *crypter, sig
payload_t *previous_payload = NULL;
int payload_number = 1;
iterator_t *iterator;
+ payload_t *current_payload;
status_t status;
iterator = this->payloads->create_iterator(this->payloads,TRUE);
/* process each payload and decrypt a encryption payload */
- while(iterator->has_next(iterator))
+ while(iterator->iterate(iterator, (void**)&current_payload))
{
payload_rule_t *payload_rule;
payload_type_t current_payload_type;
- payload_t *current_payload;
-
- /* get current payload */
- iterator->current(iterator,(void **)&current_payload);
/* needed to check */
current_payload_type = current_payload->get_type(current_payload);
@@ -1020,6 +1016,7 @@ static status_t verify(private_message_t *this)
{
int i;
iterator_t *iterator;
+ payload_t *current_payload;
size_t total_found_payloads = 0;
DBG2(SIG_DBG_ENC, "verifying message structure");
@@ -1033,14 +1030,11 @@ static status_t verify(private_message_t *this)
/* check all payloads for specific rule */
iterator->reset(iterator);
- while(iterator->has_next(iterator))
+ while(iterator->iterate(iterator,(void **)&current_payload))
{
- payload_t *current_payload;
payload_type_t current_payload_type;
- iterator->current(iterator,(void **)&current_payload);
current_payload_type = current_payload->get_type(current_payload);
-
if (current_payload_type == UNKNOWN_PAYLOAD)
{
/* unknown payloads are ignored, IF they are not critical */
@@ -1177,26 +1171,10 @@ static status_t parse_body(private_message_t *this, crypter_t *crypter, signer_t
*/
static void destroy (private_message_t *this)
{
- iterator_t *iterator;
-
+ DESTROY_IF(this->ike_sa_id);
+ this->payloads->destroy_offset(this->payloads, offsetof(payload_t, destroy));
this->packet->destroy(this->packet);
-
- if (this->ike_sa_id != NULL)
- {
- this->ike_sa_id->destroy(this->ike_sa_id);
- }
-
- iterator = this->payloads->create_iterator(this->payloads, TRUE);
- while (iterator->has_next(iterator))
- {
- payload_t *payload;
- iterator->current(iterator, (void**)&payload);
- payload->destroy(payload);
- }
- iterator->destroy(iterator);
- this->payloads->destroy(this->payloads);
this->parser->destroy(this->parser);
-
free(this);
}
diff --git a/src/charon/encoding/payloads/cp_payload.c b/src/charon/encoding/payloads/cp_payload.c
index 580a0c64a..bd16abc22 100644
--- a/src/charon/encoding/payloads/cp_payload.c
+++ b/src/charon/encoding/payloads/cp_payload.c
@@ -125,20 +125,17 @@ static status_t verify(private_cp_payload_t *this)
{
status_t status = SUCCESS;
iterator_t *iterator;
-
- iterator = this->attributes->create_iterator(this->attributes,TRUE);
+ configuration_attribute_t *attribute;
- while(iterator->has_next(iterator))
+ iterator = this->attributes->create_iterator(this->attributes,TRUE);
+ while(iterator->iterate(iterator, (void**)&attribute))
{
- configuration_attribute_t *attribute;
- iterator->current(iterator,(void **)&attribute);
- status = attribute->payload_interface.verify(&(attribute->payload_interface));
+ status = attribute->payload_interface.verify(&attribute->payload_interface);
if (status != SUCCESS)
{
break;
}
}
-
iterator->destroy(iterator);
return status;
}
@@ -182,12 +179,12 @@ static void set_next_type(private_cp_payload_t *this,payload_type_t type)
static void compute_length(private_cp_payload_t *this)
{
iterator_t *iterator;
+ payload_t *current_attribute;
size_t length = CP_PAYLOAD_HEADER_LENGTH;
+
iterator = this->attributes->create_iterator(this->attributes,TRUE);
- while (iterator->has_next(iterator))
+ while (iterator->iterate(iterator, (void**)&current_attribute))
{
- payload_t *current_attribute;
- iterator->current(iterator,(void **) &current_attribute);
length += current_attribute->get_length(current_attribute);
}
iterator->destroy(iterator);
diff --git a/src/charon/encoding/payloads/encryption_payload.c b/src/charon/encoding/payloads/encryption_payload.c
index c33bea781..bec94d620 100644
--- a/src/charon/encoding/payloads/encryption_payload.c
+++ b/src/charon/encoding/payloads/encryption_payload.c
@@ -188,14 +188,13 @@ static void set_next_type(private_encryption_payload_t *this, payload_type_t typ
static void compute_length(private_encryption_payload_t *this)
{
iterator_t *iterator;
+ payload_t *current_payload;
size_t block_size, length = 0;
iterator = this->payloads->create_iterator(this->payloads, TRUE);
/* count payload length */
- while (iterator->has_next(iterator))
+ while (iterator->iterate(iterator, (void **) &current_payload))
{
- payload_t *current_payload;
- iterator->current(iterator, (void **) &current_payload);
length += current_payload->get_length(current_payload);
}
iterator->destroy(iterator);
@@ -285,9 +284,8 @@ static void generate(private_encryption_payload_t *this)
iterator = this->payloads->create_iterator(this->payloads, TRUE);
/* get first payload */
- if (iterator->has_next(iterator))
+ if (iterator->iterate(iterator, (void**)&current_payload))
{
- iterator->current(iterator, (void**)&current_payload);
this->next_payload = current_payload->get_type(current_payload);
}
else
@@ -303,9 +301,8 @@ static void generate(private_encryption_payload_t *this)
generator = generator_create();
/* build all payload, except last */
- while(iterator->has_next(iterator))
+ while(iterator->iterate(iterator, (void**)&next_payload))
{
- iterator->current(iterator, (void**)&next_payload);
current_payload->set_next_type(current_payload, next_payload->get_type(next_payload));
generator->generate_payload(generator, current_payload);
current_payload = next_payload;
diff --git a/src/charon/encoding/payloads/proposal_substructure.c b/src/charon/encoding/payloads/proposal_substructure.c
index 5842f6e8b..3351c8a14 100644
--- a/src/charon/encoding/payloads/proposal_substructure.c
+++ b/src/charon/encoding/payloads/proposal_substructure.c
@@ -142,6 +142,7 @@ static status_t verify(private_proposal_substructure_t *this)
{
status_t status = SUCCESS;
iterator_t *iterator;
+ payload_t *current_transform;
if ((this->next_payload != NO_PAYLOAD) && (this->next_payload != 2))
{
@@ -186,11 +187,8 @@ static status_t verify(private_proposal_substructure_t *this)
}
iterator = this->transforms->create_iterator(this->transforms,TRUE);
- while(iterator->has_next(iterator))
+ while(iterator->iterate(iterator, (void**)&current_transform))
{
- payload_t *current_transform;
- iterator->current(iterator,(void **)&current_transform);
-
status = current_transform->verify(current_transform);
if (status != SUCCESS)
{
@@ -242,13 +240,13 @@ static void set_next_type(private_proposal_substructure_t *this,payload_type_t t
static void compute_length(private_proposal_substructure_t *this)
{
iterator_t *iterator;
+ payload_t *current_transform;
size_t transforms_count = 0;
size_t length = PROPOSAL_SUBSTRUCTURE_HEADER_LENGTH;
+
iterator = this->transforms->create_iterator(this->transforms,TRUE);
- while (iterator->has_next(iterator))
+ while (iterator->iterate(iterator, (void**)&current_transform))
{
- payload_t * current_transform;
- iterator->current(iterator,(void **) &current_transform);
length += current_transform->get_length(current_transform);
transforms_count++;
}
@@ -390,21 +388,19 @@ static size_t get_spi_size (private_proposal_substructure_t *this)
proposal_t* get_proposal(private_proposal_substructure_t *this)
{
iterator_t *iterator;
+ transform_substructure_t *transform;
proposal_t *proposal;
u_int64_t spi;
proposal = proposal_create(this->protocol_id);
iterator = this->transforms->create_iterator(this->transforms, TRUE);
- while (iterator->has_next(iterator))
+ while (iterator->iterate(iterator, (void**)&transform))
{
- transform_substructure_t *transform;
transform_type_t transform_type;
u_int16_t transform_id;
u_int16_t key_length = 0;
- iterator->current(iterator, (void**)&transform);
-
transform_type = transform->get_transform_type(transform);
transform_id = transform->get_transform_id(transform);
transform->get_key_length(transform, &key_length);
@@ -434,38 +430,30 @@ proposal_t* get_proposal(private_proposal_substructure_t *this)
*/
static private_proposal_substructure_t* clone_(private_proposal_substructure_t *this)
{
- private_proposal_substructure_t * new_clone;
+ private_proposal_substructure_t *clone;
iterator_t *transforms;
+ transform_substructure_t *current_transform;
- new_clone = (private_proposal_substructure_t *) proposal_substructure_create();
-
- new_clone->next_payload = this->next_payload;
- new_clone->proposal_number = this->proposal_number;
- new_clone->protocol_id = this->protocol_id;
- new_clone->spi_size = this->spi_size;
+ clone = (private_proposal_substructure_t *) proposal_substructure_create();
+ clone->next_payload = this->next_payload;
+ clone->proposal_number = this->proposal_number;
+ clone->protocol_id = this->protocol_id;
+ clone->spi_size = this->spi_size;
if (this->spi.ptr != NULL)
{
- new_clone->spi.ptr = clalloc(this->spi.ptr,this->spi.len);
- new_clone->spi.len = this->spi.len;
+ clone->spi.ptr = clalloc(this->spi.ptr,this->spi.len);
+ clone->spi.len = this->spi.len;
}
transforms = this->transforms->create_iterator(this->transforms,FALSE);
-
- while (transforms->has_next(transforms))
+ while (transforms->iterate(transforms, (void**)&current_transform))
{
- transform_substructure_t *current_transform;
- transform_substructure_t *current_transform_clone;
-
- transforms->current(transforms,(void **) &current_transform);
-
- current_transform_clone = current_transform->clone(current_transform);
-
- new_clone->public.add_transform_substructure(&(new_clone->public),current_transform_clone);
+ current_transform = current_transform->clone(current_transform);
+ clone->public.add_transform_substructure(&clone->public, current_transform);
}
-
transforms->destroy(transforms);
- return new_clone;
+ return clone;
}
/**
@@ -533,49 +521,46 @@ proposal_substructure_t *proposal_substructure_create()
*/
proposal_substructure_t *proposal_substructure_create_from_proposal(proposal_t *proposal)
{
- private_proposal_substructure_t *this = (private_proposal_substructure_t*)proposal_substructure_create();
+ private_proposal_substructure_t *this = (private_proposal_substructure_t*)
+ proposal_substructure_create();
iterator_t *iterator;
algorithm_t *algo;
transform_substructure_t *transform;
/* encryption algorithm is only availble in ESP */
iterator = proposal->create_algorithm_iterator(proposal, ENCRYPTION_ALGORITHM);
- while (iterator->has_next(iterator))
+ while (iterator->iterate(iterator, (void**)&algo))
{
- iterator->current(iterator, (void**)&algo);
- transform = transform_substructure_create_type(ENCRYPTION_ALGORITHM, algo->algorithm, algo->key_size);
+ transform = transform_substructure_create_type(ENCRYPTION_ALGORITHM,
+ algo->algorithm, algo->key_size);
this->public.add_transform_substructure(&(this->public), transform);
}
iterator->destroy(iterator);
/* integrity algorithms */
iterator = proposal->create_algorithm_iterator(proposal, INTEGRITY_ALGORITHM);
- while (iterator->has_next(iterator))
+ while (iterator->iterate(iterator, (void**)&algo))
{
- algorithm_t *algo;
- iterator->current(iterator, (void**)&algo);
- transform = transform_substructure_create_type(INTEGRITY_ALGORITHM, algo->algorithm, algo->key_size);
+ transform = transform_substructure_create_type(INTEGRITY_ALGORITHM,
+ algo->algorithm, algo->key_size);
this->public.add_transform_substructure(&(this->public), transform);
}
iterator->destroy(iterator);
/* prf algorithms */
iterator = proposal->create_algorithm_iterator(proposal, PSEUDO_RANDOM_FUNCTION);
- while (iterator->has_next(iterator))
+ while (iterator->iterate(iterator, (void**)&algo))
{
- algorithm_t *algo;
- iterator->current(iterator, (void**)&algo);
- transform = transform_substructure_create_type(PSEUDO_RANDOM_FUNCTION, algo->algorithm, algo->key_size);
+ transform = transform_substructure_create_type(PSEUDO_RANDOM_FUNCTION,
+ algo->algorithm, algo->key_size);
this->public.add_transform_substructure(&(this->public), transform);
}
iterator->destroy(iterator);
/* dh groups */
iterator = proposal->create_algorithm_iterator(proposal, DIFFIE_HELLMAN_GROUP);
- while (iterator->has_next(iterator))
+ while (iterator->iterate(iterator, (void**)&algo))
{
- algorithm_t *algo;
- iterator->current(iterator, (void**)&algo);
transform = transform_substructure_create_type(DIFFIE_HELLMAN_GROUP, algo->algorithm, 0);
this->public.add_transform_substructure(&(this->public), transform);
}
@@ -583,11 +568,10 @@ proposal_substructure_t *proposal_substructure_create_from_proposal(proposal_t *
/* extended sequence numbers */
iterator = proposal->create_algorithm_iterator(proposal, EXTENDED_SEQUENCE_NUMBERS);
- while (iterator->has_next(iterator))
+ while (iterator->iterate(iterator, (void**)&algo))
{
- algorithm_t *algo;
- iterator->current(iterator, (void**)&algo);
- transform = transform_substructure_create_type(EXTENDED_SEQUENCE_NUMBERS, algo->algorithm, 0);
+ transform = transform_substructure_create_type(EXTENDED_SEQUENCE_NUMBERS,
+ algo->algorithm, 0);
this->public.add_transform_substructure(&(this->public), transform);
}
iterator->destroy(iterator);
diff --git a/src/charon/encoding/payloads/sa_payload.c b/src/charon/encoding/payloads/sa_payload.c
index f0a13eb58..751e83297 100644
--- a/src/charon/encoding/payloads/sa_payload.c
+++ b/src/charon/encoding/payloads/sa_payload.c
@@ -110,19 +110,18 @@ static status_t verify(private_sa_payload_t *this)
int expected_number = 1, current_number;
status_t status = SUCCESS;
iterator_t *iterator;
+ proposal_substructure_t *current_proposal;
bool first = TRUE;
- /* check proposal numbering */
+ /* check proposal numbering */
iterator = this->proposals->create_iterator(this->proposals,TRUE);
- while(iterator->has_next(iterator))
+ while(iterator->iterate(iterator, (void**)&current_proposal))
{
- proposal_substructure_t *current_proposal;
- iterator->current(iterator,(void **)&current_proposal);
current_number = current_proposal->get_proposal_number(current_proposal);
if (current_number > expected_number)
{
- if (first)
+ if (first)
{
DBG1(SIG_DBG_ENC, "first proposal is not proposal #1");
status = FAILED;
@@ -210,12 +209,12 @@ static void set_next_type(private_sa_payload_t *this,payload_type_t type)
static void compute_length (private_sa_payload_t *this)
{
iterator_t *iterator;
+ payload_t *current_proposal;
size_t length = SA_PAYLOAD_HEADER_LENGTH;
+
iterator = this->proposals->create_iterator(this->proposals,TRUE);
- while (iterator->has_next(iterator))
+ while (iterator->iterate(iterator, (void **)&current_proposal))
{
- payload_t *current_proposal;
- iterator->current(iterator,(void **) &current_proposal);
length += current_proposal->get_length(current_proposal);
}
iterator->destroy(iterator);
@@ -280,6 +279,7 @@ static linked_list_t *get_proposals(private_sa_payload_t *this)
int struct_number = 0;
int ignore_struct_number = 0;
iterator_t *iterator;
+ proposal_substructure_t *proposal_struct;
linked_list_t *proposal_list;
/* this list will hold our proposals */
@@ -291,12 +291,10 @@ static linked_list_t *get_proposals(private_sa_payload_t *this)
* protocols.
*/
iterator = this->proposals->create_iterator(this->proposals, TRUE);
- while (iterator->has_next(iterator))
+ while (iterator->iterate(iterator, (void **)&proposal_struct))
{
proposal_t *proposal;
- proposal_substructure_t *proposal_struct;
- iterator->current(iterator, (void **)&proposal_struct);
/* check if a proposal has a single protocol */
if (proposal_struct->get_proposal_number(proposal_struct) == struct_number)
{
@@ -362,9 +360,8 @@ sa_payload_t *sa_payload_create_from_proposal_list(linked_list_t *proposals)
/* add every payload from the list */
iterator = proposals->create_iterator(proposals, TRUE);
- while (iterator->has_next(iterator))
+ while (iterator->iterate(iterator, (void**)&proposal))
{
- iterator->current(iterator, (void**)&proposal);
add_proposal((private_sa_payload_t*)sa_payload, proposal);
}
iterator->destroy(iterator);
diff --git a/src/charon/encoding/payloads/transform_substructure.c b/src/charon/encoding/payloads/transform_substructure.c
index 944336cc7..f165507df 100644
--- a/src/charon/encoding/payloads/transform_substructure.c
+++ b/src/charon/encoding/payloads/transform_substructure.c
@@ -120,6 +120,7 @@ static status_t verify(private_transform_substructure_t *this)
{
status_t status = SUCCESS;
iterator_t *iterator;
+ payload_t *current_attributes;
if ((this->next_payload != NO_PAYLOAD) && (this->next_payload != 3))
{
@@ -146,11 +147,8 @@ static status_t verify(private_transform_substructure_t *this)
}
iterator = this->attributes->create_iterator(this->attributes,TRUE);
- while(iterator->has_next(iterator))
+ while(iterator->iterate(iterator, (void**)&current_attributes))
{
- payload_t *current_attributes;
- iterator->current(iterator,(void **)&current_attributes);
-
status = current_attributes->verify(current_attributes);
if (status != SUCCESS)
{
@@ -194,12 +192,12 @@ static payload_type_t get_next_type(private_transform_substructure_t *this)
static void compute_length (private_transform_substructure_t *this)
{
iterator_t *iterator;
+ payload_t *current_attribute;
size_t length = TRANSFORM_SUBSTRUCTURE_HEADER_LENGTH;
+
iterator = this->attributes->create_iterator(this->attributes,TRUE);
- while (iterator->has_next(iterator))
+ while (iterator->iterate(iterator, (void**)&current_attribute))
{
- payload_t * current_attribute;
- iterator->current(iterator,(void **) &current_attribute);
length += current_attribute->get_length(current_attribute);
}
iterator->destroy(iterator);
@@ -293,31 +291,24 @@ static u_int16_t get_transform_id (private_transform_substructure_t *this)
*/
static transform_substructure_t *clone_(private_transform_substructure_t *this)
{
- private_transform_substructure_t *new_clone;
+ private_transform_substructure_t *clone;
iterator_t *attributes;
+ transform_attribute_t *current_attribute;
- new_clone = (private_transform_substructure_t *) transform_substructure_create();
+ clone = (private_transform_substructure_t *) transform_substructure_create();
+ clone->next_payload = this->next_payload;
+ clone->transform_type = this->transform_type;
+ clone->transform_id = this->transform_id;
- new_clone->next_payload = this->next_payload;
- new_clone->transform_type = this->transform_type;
- new_clone->transform_id = this->transform_id;
-
- attributes = this->attributes->create_iterator(this->attributes,FALSE);
-
- while (attributes->has_next(attributes))
+ attributes = this->attributes->create_iterator(this->attributes, FALSE);
+ while (attributes->iterate(attributes, (void**)&current_attribute))
{
- transform_attribute_t *current_attribute;
- transform_attribute_t *current_attribute_clone;
- attributes->current(attributes,(void **) &current_attribute);
-
- current_attribute_clone = current_attribute->clone(current_attribute);
-
- new_clone->public.add_transform_attribute(&(new_clone->public),current_attribute_clone);
+ current_attribute = current_attribute->clone(current_attribute);
+ clone->public.add_transform_attribute(&clone->public, current_attribute);
}
-
attributes->destroy(attributes);
- return &(new_clone->public);
+ return &clone->public;
}
@@ -327,24 +318,19 @@ static transform_substructure_t *clone_(private_transform_substructure_t *this)
static status_t get_key_length(private_transform_substructure_t *this, u_int16_t *key_length)
{
iterator_t *attributes;
+ transform_attribute_t *current_attribute;
- attributes = this->attributes->create_iterator(this->attributes,TRUE);
-
- while (attributes->has_next(attributes))
+ attributes = this->attributes->create_iterator(this->attributes, TRUE);
+ while (attributes->iterate(attributes, (void**)&current_attribute))
{
- transform_attribute_t *current_attribute;
- attributes->current(attributes,(void **) &current_attribute);
-
if (current_attribute->get_attribute_type(current_attribute) == KEY_LENGTH)
{
*key_length = current_attribute->get_value(current_attribute);
attributes->destroy(attributes);
return SUCCESS;
}
-
}
attributes->destroy(attributes);
-
return FAILED;
}
diff --git a/src/charon/encoding/payloads/ts_payload.c b/src/charon/encoding/payloads/ts_payload.c
index cce2fc282..ae89919f6 100644
--- a/src/charon/encoding/payloads/ts_payload.c
+++ b/src/charon/encoding/payloads/ts_payload.c
@@ -123,6 +123,7 @@ encoding_rule_t ts_payload_encodings[] = {
static status_t verify(private_ts_payload_t *this)
{
iterator_t *iterator;
+ payload_t *current_traffic_selector;
status_t status = SUCCESS;
if (this->number_of_traffic_selectors != (this->traffic_selectors->get_count(this->traffic_selectors)))
@@ -132,11 +133,8 @@ static status_t verify(private_ts_payload_t *this)
}
iterator = this->traffic_selectors->create_iterator(this->traffic_selectors,TRUE);
- while(iterator->has_next(iterator))
+ while(iterator->iterate(iterator, (void**)&current_traffic_selector))
{
- payload_t *current_traffic_selector;
- iterator->current(iterator,(void **)&current_traffic_selector);
-
status = current_traffic_selector->verify(current_traffic_selector);
if (status != SUCCESS)
{
@@ -196,11 +194,11 @@ static void compute_length (private_ts_payload_t *this)
iterator_t *iterator;
size_t ts_count = 0;
size_t length = TS_PAYLOAD_HEADER_LENGTH;
+ payload_t *current_traffic_selector;
+
iterator = this->traffic_selectors->create_iterator(this->traffic_selectors,TRUE);
- while (iterator->has_next(iterator))
+ while (iterator->iterate(iterator, (void**)&current_traffic_selector))
{
- payload_t * current_traffic_selector;
- iterator->current(iterator,(void **) &current_traffic_selector);
length += current_traffic_selector->get_length(current_traffic_selector);
ts_count++;
}
@@ -208,7 +206,6 @@ static void compute_length (private_ts_payload_t *this)
this->number_of_traffic_selectors= ts_count;
this->payload_length = length;
-
}
/**
@@ -260,13 +257,12 @@ static linked_list_t *get_traffic_selectors(private_ts_payload_t *this)
{
traffic_selector_t *ts;
iterator_t *iterator;
+ traffic_selector_substructure_t *ts_substructure;
linked_list_t *ts_list = linked_list_create();
iterator = this->traffic_selectors->create_iterator(this->traffic_selectors, TRUE);
- while (iterator->has_next(iterator))
+ while (iterator->iterate(iterator, (void**)&ts_substructure))
{
- traffic_selector_substructure_t *ts_substructure;
- iterator->current(iterator, (void**)&ts_substructure);
ts = ts_substructure->get_traffic_selector(ts_substructure);
ts_list->insert_last(ts_list, (void*)ts);
}
@@ -333,9 +329,8 @@ ts_payload_t *ts_payload_create_from_traffic_selectors(bool is_initiator, linked
this = (private_ts_payload_t*)ts_payload_create(is_initiator);
iterator = traffic_selectors->create_iterator(traffic_selectors, TRUE);
- while (iterator->has_next(iterator))
+ while (iterator->iterate(iterator, (void**)&ts))
{
- iterator->current(iterator, (void**)&ts);
ts_substructure = traffic_selector_substructure_create_from_traffic_selector(ts);
this->public.add_traffic_selector_substructure(&(this->public), ts_substructure);
}