aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Source/charon/config/configuration_manager.c14
-rw-r--r--Source/charon/config/configuration_manager.h6
-rw-r--r--Source/charon/encoding/generator.c6
-rw-r--r--Source/charon/encoding/message.c10
-rw-r--r--Source/charon/encoding/message.h2
-rw-r--r--Source/charon/encoding/payloads/proposal_substructure.c8
-rw-r--r--Source/charon/encoding/payloads/proposal_substructure.h2
-rw-r--r--Source/charon/encoding/payloads/sa_payload.c8
-rw-r--r--Source/charon/encoding/payloads/sa_payload.h2
-rw-r--r--Source/charon/encoding/payloads/transform_substructure.c8
-rw-r--r--Source/charon/encoding/payloads/transform_substructure.h2
-rw-r--r--Source/charon/queues/event_queue.c2
-rw-r--r--Source/charon/sa/ike_sa_manager.c8
-rw-r--r--Source/charon/sa/states/ike_sa_init_requested.c4
-rw-r--r--Source/charon/sa/states/initiator_init.c4
-rw-r--r--Source/charon/sa/states/responder_init.c6
-rw-r--r--Source/charon/testcases/linked_list_test.c6
-rw-r--r--Source/charon/testcases/parser_test.c2
-rw-r--r--Source/charon/testcases/testcases.c4
-rw-r--r--Source/charon/utils/iterator.h124
-rw-r--r--Source/charon/utils/linked_list.c40
-rw-r--r--Source/charon/utils/linked_list.h83
-rw-r--r--Source/charon/utils/logger_manager.c6
23 files changed, 201 insertions, 156 deletions
diff --git a/Source/charon/config/configuration_manager.c b/Source/charon/config/configuration_manager.c
index 72e801a18..cc547dbbd 100644
--- a/Source/charon/config/configuration_manager.c
+++ b/Source/charon/config/configuration_manager.c
@@ -128,7 +128,7 @@ static status_t get_dh_group_number(private_configuration_manager_t *this,char *
/**
* Implements function configuration_manager_t.get_proposals_for_host.
*/
-static status_t get_proposals_for_host(private_configuration_manager_t *this, host_t *host, linked_list_iterator_t *iterator)
+static status_t get_proposals_for_host(private_configuration_manager_t *this, host_t *host, iterator_t *iterator)
{
/*
* Currently the following hard coded proposal is created and returned for all hosts:
@@ -278,7 +278,7 @@ static status_t get_proposals_for_host(private_configuration_manager_t *this, ho
/**
* Implements function configuration_manager_t.select_proposals_for_host.
*/
-static status_t select_proposals_for_host(private_configuration_manager_t *this, host_t *host, linked_list_iterator_t *in, linked_list_iterator_t *out)
+static status_t select_proposals_for_host(private_configuration_manager_t *this, host_t *host, iterator_t *in, iterator_t *out)
{
/* Currently the first suggested proposal is selected, cloned and then returned*/
status_t status;
@@ -318,7 +318,7 @@ static status_t select_proposals_for_host(private_configuration_manager_t *this,
/**
* Implements function configuration_manager_t.get_transforms_for_host_and_proposals.
*/
-static status_t get_transforms_for_host_and_proposals (private_configuration_manager_t *this, host_t *host, linked_list_iterator_t *proposals,encryption_algorithm_t *encryption_algorithm,pseudo_random_function_t *pseudo_random_function, integrity_algorithm_t *integrity_algorithm)
+static status_t get_transforms_for_host_and_proposals (private_configuration_manager_t *this, host_t *host, iterator_t *proposals,encryption_algorithm_t *encryption_algorithm,pseudo_random_function_t *pseudo_random_function, integrity_algorithm_t *integrity_algorithm)
{
/*
* Currently the given proposals are not checked if they are valid for specific host!
@@ -330,7 +330,7 @@ static status_t get_transforms_for_host_and_proposals (private_configuration_man
pseudo_random_function_t selected_pseudo_random_function = PRF_UNDEFINED;
integrity_algorithm_t selected_integrity_algorithm = AUTH_UNDEFINED;
proposal_substructure_t *proposal;
- linked_list_iterator_t *transforms;
+ iterator_t *transforms;
status_t status;
this->logger->log(this->logger,ERROR, "Going to get transforms for given proposal");
@@ -466,9 +466,9 @@ configuration_manager_t *configuration_manager_create()
this->public.get_remote_host = (status_t(*)(configuration_manager_t*,char*,host_t**))get_remote_host;
this->public.get_local_host = (status_t(*)(configuration_manager_t*,char*,host_t**))get_local_host;
this->public.get_dh_group_number = (status_t(*)(configuration_manager_t*,char*,u_int16_t *, u_int16_t))get_dh_group_number;
- this->public.get_proposals_for_host = (status_t(*)(configuration_manager_t*,host_t*,linked_list_iterator_t*))get_proposals_for_host;
- this->public.select_proposals_for_host = (status_t(*)(configuration_manager_t*,host_t*,linked_list_iterator_t*,linked_list_iterator_t*))select_proposals_for_host;
- this->public.get_transforms_for_host_and_proposals = (status_t (*) (configuration_manager_t *, host_t *, linked_list_iterator_t *,encryption_algorithm_t *,pseudo_random_function_t *, integrity_algorithm_t *)) get_transforms_for_host_and_proposals;
+ this->public.get_proposals_for_host = (status_t(*)(configuration_manager_t*,host_t*,iterator_t*))get_proposals_for_host;
+ this->public.select_proposals_for_host = (status_t(*)(configuration_manager_t*,host_t*,iterator_t*,iterator_t*))select_proposals_for_host;
+ this->public.get_transforms_for_host_and_proposals = (status_t (*) (configuration_manager_t *, host_t *, iterator_t *,encryption_algorithm_t *,pseudo_random_function_t *, integrity_algorithm_t *)) get_transforms_for_host_and_proposals;
this->public.is_dh_group_allowed_for_host = (status_t(*)(configuration_manager_t*,host_t*,diffie_hellman_group_t,bool*)) is_dh_group_allowed_for_host;
/* private variables */
diff --git a/Source/charon/config/configuration_manager.h b/Source/charon/config/configuration_manager.h
index 54d302d60..fe0e5cc43 100644
--- a/Source/charon/config/configuration_manager.h
+++ b/Source/charon/config/configuration_manager.h
@@ -114,7 +114,7 @@ struct configuration_manager_t {
* - NOT_FOUND (not yet implemented)
* - SUCCESS
*/
- status_t (*get_proposals_for_host) (configuration_manager_t *this, host_t *host, linked_list_iterator_t *list);
+ status_t (*get_proposals_for_host) (configuration_manager_t *this, host_t *host, iterator_t *list);
/**
* Checks the suggested proposals passed as iterator in and selects one proposal to be sent as selection
@@ -134,7 +134,7 @@ struct configuration_manager_t {
* - NOT_FOUND (not yet implemented)
* - SUCCESS
*/
- status_t (*select_proposals_for_host) (configuration_manager_t *this, host_t *host, linked_list_iterator_t *in, linked_list_iterator_t *out);
+ status_t (*select_proposals_for_host) (configuration_manager_t *this, host_t *host, iterator_t *in, iterator_t *out);
/**
* Returns the transforms of type crypter_t, signer_t and prf_t as specified in given proposal.
@@ -153,7 +153,7 @@ struct configuration_manager_t {
* - NOT_FOUND (not yet implemented)
* - SUCCESS
*/
- status_t (*get_transforms_for_host_and_proposals) (configuration_manager_t *this, host_t *host, linked_list_iterator_t *proposals,encryption_algorithm_t *encryption_algorithm,pseudo_random_function_t *pseudo_random_function, integrity_algorithm_t *integrity_algorithm);
+ status_t (*get_transforms_for_host_and_proposals) (configuration_manager_t *this, host_t *host, iterator_t *proposals,encryption_algorithm_t *encryption_algorithm,pseudo_random_function_t *pseudo_random_function, integrity_algorithm_t *integrity_algorithm);
/**
* Checks if a given dh_group number is allowed for a specific host
diff --git a/Source/charon/encoding/generator.c b/Source/charon/encoding/generator.c
index 0d047c277..5ba7ee14f 100644
--- a/Source/charon/encoding/generator.c
+++ b/Source/charon/encoding/generator.c
@@ -870,7 +870,7 @@ static status_t generate_payload (private_generator_t *this,payload_t *payload)
/* proposals are stored in a linked list and so accessed */
linked_list_t *proposals = *((linked_list_t **)(this->data_struct + rules[i].offset));
- linked_list_iterator_t *iterator;
+ iterator_t *iterator;
/* create forward iterator */
status = proposals->create_iterator(proposals,&iterator,TRUE);
if (status != SUCCESS)
@@ -922,7 +922,7 @@ static status_t generate_payload (private_generator_t *this,payload_t *payload)
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));
- linked_list_iterator_t *iterator;
+ iterator_t *iterator;
/* create forward iterator */
status = transforms->create_iterator(transforms,&iterator,TRUE);
@@ -972,7 +972,7 @@ static status_t generate_payload (private_generator_t *this,payload_t *payload)
u_int16_t int16_val;
linked_list_t *transform_attributes =*((linked_list_t **)(this->data_struct + rules[i].offset));
- linked_list_iterator_t *iterator;
+ iterator_t *iterator;
/* create forward iterator */
status = transform_attributes->create_iterator(transform_attributes,&iterator,TRUE);
if (status != SUCCESS)
diff --git a/Source/charon/encoding/message.c b/Source/charon/encoding/message.c
index 4ec78050e..27fd7f5d5 100644
--- a/Source/charon/encoding/message.c
+++ b/Source/charon/encoding/message.c
@@ -445,7 +445,7 @@ static status_t get_destination(private_message_t *this, host_t **host)
}
-static status_t get_payload_iterator(private_message_t *this, linked_list_iterator_t **iterator)
+static status_t get_payload_iterator(private_message_t *this, iterator_t **iterator)
{
return this->payloads->create_iterator(this->payloads, iterator, TRUE);
}
@@ -460,7 +460,7 @@ static status_t generate(private_message_t *this, packet_t **packet)
generator_t *generator;
ike_header_t *ike_header;
payload_t *payload, *next_payload;
- linked_list_iterator_t *iterator;
+ iterator_t *iterator;
status_t status;
@@ -692,7 +692,7 @@ static status_t parse_body (private_message_t *this)
}
else
{
- linked_list_iterator_t *iterator;
+ iterator_t *iterator;
status = this->payloads->create_iterator(this->payloads,&iterator,TRUE);
if (status != SUCCESS)
@@ -756,7 +756,7 @@ static status_t parse_body (private_message_t *this)
*/
static status_t destroy (private_message_t *this)
{
- linked_list_iterator_t *iterator;
+ iterator_t *iterator;
this->packet->destroy(this->packet);
@@ -814,7 +814,7 @@ message_t *message_create_from_packet(packet_t *packet)
this->public.get_source = (status_t (*) (message_t*,host_t**)) get_source;
this->public.set_destination = (status_t (*) (message_t*,host_t*)) set_destination;
this->public.get_destination = (status_t (*) (message_t*,host_t**)) get_destination;
- this->public.get_payload_iterator = (status_t (*) (message_t *, linked_list_iterator_t **)) get_payload_iterator;
+ this->public.get_payload_iterator = (status_t (*) (message_t *, iterator_t **)) get_payload_iterator;
this->public.parse_header = (status_t (*) (message_t *)) parse_header;
this->public.parse_body = (status_t (*) (message_t *)) parse_body;
this->public.destroy = (status_t(*)(message_t*))destroy;
diff --git a/Source/charon/encoding/message.h b/Source/charon/encoding/message.h
index 3ec1daf81..2b2a14a1c 100644
--- a/Source/charon/encoding/message.h
+++ b/Source/charon/encoding/message.h
@@ -234,7 +234,7 @@ struct message_t {
status_t (*set_source) (message_t *this, host_t *host);
status_t (*get_destination) (message_t *this, host_t **host);
status_t (*set_destination) (message_t *this, host_t *host);
- status_t (*get_payload_iterator) (message_t *this, linked_list_iterator_t **iterator);
+ status_t (*get_payload_iterator) (message_t *this, iterator_t **iterator);
/**
* @brief Destroys a message and all including objects
diff --git a/Source/charon/encoding/payloads/proposal_substructure.c b/Source/charon/encoding/payloads/proposal_substructure.c
index 5cdd3b25b..ab575d425 100644
--- a/Source/charon/encoding/payloads/proposal_substructure.c
+++ b/Source/charon/encoding/payloads/proposal_substructure.c
@@ -221,7 +221,7 @@ static size_t get_length(private_proposal_substructure_t *this)
* Implements proposal_substructure_t's create_transform_substructure_iterator function.
* See #proposal_substructure_s.create_transform_substructure_iterator for description.
*/
-static status_t create_transform_substructure_iterator (private_proposal_substructure_t *this,linked_list_iterator_t **iterator,bool forward)
+static status_t create_transform_substructure_iterator (private_proposal_substructure_t *this,iterator_t **iterator,bool forward)
{
return (this->transforms->create_iterator(this->transforms,iterator,forward));
}
@@ -333,7 +333,7 @@ static chunk_t get_spi (private_proposal_substructure_t *this)
*/
static status_t compute_length (private_proposal_substructure_t *this)
{
- linked_list_iterator_t *iterator;
+ iterator_t *iterator;
status_t status;
size_t transforms_count = 0;
size_t length = PROPOSAL_SUBSTRUCTURE_HEADER_LENGTH;
@@ -365,7 +365,7 @@ static status_t compute_length (private_proposal_substructure_t *this)
static status_t clone(private_proposal_substructure_t *this, private_proposal_substructure_t **clone)
{
private_proposal_substructure_t * new_clone;
- linked_list_iterator_t *transforms;
+ iterator_t *transforms;
status_t status;
new_clone = (private_proposal_substructure_t *) proposal_substructure_create();
@@ -477,7 +477,7 @@ proposal_substructure_t *proposal_substructure_create()
this->public.payload_interface.destroy = (status_t (*) (payload_t *))destroy;
/* public functions */
- this->public.create_transform_substructure_iterator = (status_t (*) (proposal_substructure_t *,linked_list_iterator_t **,bool)) create_transform_substructure_iterator;
+ this->public.create_transform_substructure_iterator = (status_t (*) (proposal_substructure_t *,iterator_t **,bool)) create_transform_substructure_iterator;
this->public.add_transform_substructure = (status_t (*) (proposal_substructure_t *,transform_substructure_t *)) add_transform_substructure;
this->public.set_proposal_number = (status_t (*) (proposal_substructure_t *,u_int8_t))set_proposal_number;
this->public.get_proposal_number = (u_int8_t (*) (proposal_substructure_t *)) get_proposal_number;
diff --git a/Source/charon/encoding/payloads/proposal_substructure.h b/Source/charon/encoding/payloads/proposal_substructure.h
index 134c4776e..d6f90e403 100644
--- a/Source/charon/encoding/payloads/proposal_substructure.h
+++ b/Source/charon/encoding/payloads/proposal_substructure.h
@@ -77,7 +77,7 @@ struct proposal_substructure_t {
* - SUCCESS or
* - OUT_OF_RES if iterator could not be created
*/
- status_t (*create_transform_substructure_iterator) (proposal_substructure_t *this,linked_list_iterator_t **iterator, bool forward);
+ status_t (*create_transform_substructure_iterator) (proposal_substructure_t *this,iterator_t **iterator, bool forward);
/**
* @brief Adds a transform_substructure_t object to this object.
diff --git a/Source/charon/encoding/payloads/sa_payload.c b/Source/charon/encoding/payloads/sa_payload.c
index 7a8b71452..c760dc3a2 100644
--- a/Source/charon/encoding/payloads/sa_payload.c
+++ b/Source/charon/encoding/payloads/sa_payload.c
@@ -122,7 +122,7 @@ static status_t verify(private_sa_payload_t *this)
{
int proposal_number = 1;
status_t status;
- linked_list_iterator_t *iterator;
+ iterator_t *iterator;
bool first = TRUE;
if (this->critical)
@@ -253,7 +253,7 @@ static size_t get_length(private_sa_payload_t *this)
* Implements sa_payload_t's create_proposal_substructure_iterator function.
* See #sa_payload_s.create_proposal_substructure_iterator for description.
*/
-static status_t create_proposal_substructure_iterator (private_sa_payload_t *this,linked_list_iterator_t **iterator,bool forward)
+static status_t create_proposal_substructure_iterator (private_sa_payload_t *this,iterator_t **iterator,bool forward)
{
return (this->proposals->create_iterator(this->proposals,iterator,forward));
}
@@ -276,7 +276,7 @@ static status_t add_proposal_substructure (private_sa_payload_t *this,proposal_s
*/
static status_t compute_length (private_sa_payload_t *this)
{
- linked_list_iterator_t *iterator;
+ iterator_t *iterator;
status_t status;
size_t length = SA_PAYLOAD_HEADER_LENGTH;
status = this->proposals->create_iterator(this->proposals,&iterator,TRUE);
@@ -318,7 +318,7 @@ sa_payload_t *sa_payload_create()
this->public.payload_interface.destroy = (status_t (*) (payload_t *))destroy;
/* public functions */
- this->public.create_proposal_substructure_iterator = (status_t (*) (sa_payload_t *,linked_list_iterator_t **,bool)) create_proposal_substructure_iterator;
+ this->public.create_proposal_substructure_iterator = (status_t (*) (sa_payload_t *,iterator_t **,bool)) create_proposal_substructure_iterator;
this->public.add_proposal_substructure = (status_t (*) (sa_payload_t *,proposal_substructure_t *)) add_proposal_substructure;
this->public.destroy = (status_t (*) (sa_payload_t *)) destroy;
diff --git a/Source/charon/encoding/payloads/sa_payload.h b/Source/charon/encoding/payloads/sa_payload.h
index 2f882d0d8..7eada847c 100644
--- a/Source/charon/encoding/payloads/sa_payload.h
+++ b/Source/charon/encoding/payloads/sa_payload.h
@@ -71,7 +71,7 @@ struct sa_payload_t {
* - SUCCESS or
* - OUT_OF_RES if iterator could not be created
*/
- status_t (*create_proposal_substructure_iterator) (sa_payload_t *this,linked_list_iterator_t **iterator, bool forward);
+ status_t (*create_proposal_substructure_iterator) (sa_payload_t *this,iterator_t **iterator, bool forward);
/**
* @brief Adds a proposal_substructure_t object to this object.
diff --git a/Source/charon/encoding/payloads/transform_substructure.c b/Source/charon/encoding/payloads/transform_substructure.c
index 0d931c984..e81aae57e 100644
--- a/Source/charon/encoding/payloads/transform_substructure.c
+++ b/Source/charon/encoding/payloads/transform_substructure.c
@@ -334,7 +334,7 @@ static size_t get_length(private_transform_substructure_t *this)
* Implements transform_substructure_t's create_transform_attribute_iterator function.
* See #transform_substructure_s.create_transform_attribute_iterator for description.
*/
-static status_t create_transform_attribute_iterator (private_transform_substructure_t *this,linked_list_iterator_t **iterator,bool forward)
+static status_t create_transform_attribute_iterator (private_transform_substructure_t *this,iterator_t **iterator,bool forward)
{
return (this->attributes->create_iterator(this->attributes,iterator,forward));
}
@@ -423,7 +423,7 @@ static u_int16_t get_transform_id (private_transform_substructure_t *this)
*/
static status_t compute_length (private_transform_substructure_t *this)
{
- linked_list_iterator_t *iterator;
+ iterator_t *iterator;
status_t status;
size_t length = TRANSFORM_SUBSTRUCTURE_HEADER_LENGTH;
status = this->attributes->create_iterator(this->attributes,&iterator,TRUE);
@@ -451,7 +451,7 @@ static status_t compute_length (private_transform_substructure_t *this)
static status_t clone(private_transform_substructure_t *this,transform_substructure_t **clone)
{
private_transform_substructure_t *new_clone;
- linked_list_iterator_t *attributes;
+ iterator_t *attributes;
status_t status;
new_clone = (private_transform_substructure_t *) transform_substructure_create();
@@ -547,7 +547,7 @@ transform_substructure_t *transform_substructure_create()
this->public.payload_interface.destroy = (status_t (*) (payload_t *))destroy;
/* public functions */
- this->public.create_transform_attribute_iterator = (status_t (*) (transform_substructure_t *,linked_list_iterator_t **,bool)) create_transform_attribute_iterator;
+ this->public.create_transform_attribute_iterator = (status_t (*) (transform_substructure_t *,iterator_t **,bool)) create_transform_attribute_iterator;
this->public.add_transform_attribute = (status_t (*) (transform_substructure_t *,transform_attribute_t *)) add_transform_attribute;
this->public.set_is_last_transform = (status_t (*) (transform_substructure_t *,bool)) set_is_last_transform;
this->public.get_is_last_transform = (bool (*) (transform_substructure_t *)) get_is_last_transform;
diff --git a/Source/charon/encoding/payloads/transform_substructure.h b/Source/charon/encoding/payloads/transform_substructure.h
index 9cd94775b..e4b503ab9 100644
--- a/Source/charon/encoding/payloads/transform_substructure.h
+++ b/Source/charon/encoding/payloads/transform_substructure.h
@@ -194,7 +194,7 @@ struct transform_substructure_t {
* - SUCCESS or
* - OUT_OF_RES if iterator could not be created
*/
- status_t (*create_transform_attribute_iterator) (transform_substructure_t *this,linked_list_iterator_t **iterator, bool forward);
+ status_t (*create_transform_attribute_iterator) (transform_substructure_t *this,iterator_t **iterator, bool forward);
/**
* @brief Adds a transform_attribute_t object to this object.
diff --git a/Source/charon/queues/event_queue.c b/Source/charon/queues/event_queue.c
index 20802d3e8..eb33330f0 100644
--- a/Source/charon/queues/event_queue.c
+++ b/Source/charon/queues/event_queue.c
@@ -264,7 +264,7 @@ static status_t add_absolute(private_event_queue_t *this, job_t *job, timeval_t
break;
}
- linked_list_iterator_t * iterator;
+ iterator_t * iterator;
status = this->list->create_iterator(this->list,&iterator,TRUE);
if (status != SUCCESS)
diff --git a/Source/charon/sa/ike_sa_manager.c b/Source/charon/sa/ike_sa_manager.c
index 669bcec16..31bc74a2f 100644
--- a/Source/charon/sa/ike_sa_manager.c
+++ b/Source/charon/sa/ike_sa_manager.c
@@ -226,7 +226,7 @@ struct private_ike_sa_manager_t {
static status_t get_entry_by_id(private_ike_sa_manager_t *this, ike_sa_id_t *ike_sa_id, ike_sa_entry_t **entry)
{
linked_list_t *list = this->ike_sa_list;
- linked_list_iterator_t *iterator;
+ iterator_t *iterator;
status_t status;
/* create iterator over list of ike_sa's */
@@ -279,7 +279,7 @@ static status_t get_entry_by_id(private_ike_sa_manager_t *this, ike_sa_id_t *ike
static status_t get_entry_by_sa(private_ike_sa_manager_t *this, ike_sa_t *ike_sa, ike_sa_entry_t **entry)
{
linked_list_t *list = this->ike_sa_list;
- linked_list_iterator_t *iterator;
+ iterator_t *iterator;
status_t status;
status = list->create_iterator(list, &iterator, TRUE);
@@ -315,7 +315,7 @@ static status_t get_entry_by_sa(private_ike_sa_manager_t *this, ike_sa_t *ike_sa
static status_t delete_entry(private_ike_sa_manager_t *this, ike_sa_entry_t *entry)
{
linked_list_t *list = this->ike_sa_list;
- linked_list_iterator_t *iterator;
+ iterator_t *iterator;
status_t status;
status = list->create_iterator(list, &iterator, TRUE);
@@ -686,7 +686,7 @@ static status_t destroy(private_ike_sa_manager_t *this)
{
/* destroy all list entries */
linked_list_t *list = this->ike_sa_list;
- linked_list_iterator_t *iterator;
+ iterator_t *iterator;
status_t status;
ike_sa_entry_t *entry;
diff --git a/Source/charon/sa/states/ike_sa_init_requested.c b/Source/charon/sa/states/ike_sa_init_requested.c
index a42b57ed4..040942aee 100644
--- a/Source/charon/sa/states/ike_sa_init_requested.c
+++ b/Source/charon/sa/states/ike_sa_init_requested.c
@@ -88,7 +88,7 @@ struct private_ike_sa_init_requested_t {
static status_t process_message(private_ike_sa_init_requested_t *this, message_t *message, state_t **new_state)
{
status_t status;
- linked_list_iterator_t *payloads;
+ iterator_t *payloads;
exchange_type_t exchange_type;
u_int64_t responder_spi;
@@ -134,7 +134,7 @@ static status_t process_message(private_ike_sa_init_requested_t *this, message_t
case SECURITY_ASSOCIATION:
{
sa_payload_t *sa_payload = (sa_payload_t*)payload;
- linked_list_iterator_t *suggested_proposals;
+ iterator_t *suggested_proposals;
encryption_algorithm_t encryption_algorithm = ENCR_UNDEFINED;
pseudo_random_function_t pseudo_random_function = PRF_UNDEFINED;
integrity_algorithm_t integrity_algorithm = AUTH_UNDEFINED;
diff --git a/Source/charon/sa/states/initiator_init.c b/Source/charon/sa/states/initiator_init.c
index 5825eb2a0..f71c2834f 100644
--- a/Source/charon/sa/states/initiator_init.c
+++ b/Source/charon/sa/states/initiator_init.c
@@ -148,7 +148,7 @@ struct private_initiator_init_t {
*/
static status_t initiate_connection (private_initiator_init_t *this, char *name, state_t **new_state)
{
- linked_list_iterator_t *proposal_iterator;
+ iterator_t *proposal_iterator;
ike_sa_init_requested_t *next_state;
message_t *message;
packet_t *packet;
@@ -370,7 +370,7 @@ static status_t build_ike_sa_init_request (private_initiator_init_t *this, messa
static status_t build_sa_payload(private_initiator_init_t *this, payload_t **payload)
{
sa_payload_t* sa_payload;
- linked_list_iterator_t *proposal_iterator;
+ iterator_t *proposal_iterator;
status_t status;
/* SA payload takes proposals from this->ike_sa_init_data.proposals and writes them to the created sa_payload */
diff --git a/Source/charon/sa/states/responder_init.c b/Source/charon/sa/states/responder_init.c
index 885e0d7f4..ffb010f67 100644
--- a/Source/charon/sa/states/responder_init.c
+++ b/Source/charon/sa/states/responder_init.c
@@ -144,7 +144,7 @@ struct private_responder_init_t {
*/
static status_t process_message(private_responder_init_t *this, message_t *message, state_t **new_state)
{
- linked_list_iterator_t *payloads;
+ iterator_t *payloads;
host_t *source, *destination;
status_t status;
message_t *response;
@@ -204,7 +204,7 @@ static status_t process_message(private_responder_init_t *this, message_t *messa
case SECURITY_ASSOCIATION:
{
sa_payload_t *sa_payload = (sa_payload_t*)payload;
- linked_list_iterator_t *suggested_proposals, *accepted_proposals;
+ iterator_t *suggested_proposals, *accepted_proposals;
encryption_algorithm_t encryption_algorithm = ENCR_UNDEFINED;
pseudo_random_function_t pseudo_random_function = PRF_UNDEFINED;
integrity_algorithm_t integrity_algorithm = AUTH_UNDEFINED;
@@ -490,7 +490,7 @@ static status_t process_message(private_responder_init_t *this, message_t *messa
static status_t build_sa_payload(private_responder_init_t *this, payload_t **payload)
{
sa_payload_t* sa_payload;
- linked_list_iterator_t *proposal_iterator;
+ iterator_t *proposal_iterator;
status_t status;
diff --git a/Source/charon/testcases/linked_list_test.c b/Source/charon/testcases/linked_list_test.c
index c13aedf93..85a84e2b5 100644
--- a/Source/charon/testcases/linked_list_test.c
+++ b/Source/charon/testcases/linked_list_test.c
@@ -101,8 +101,8 @@ void test_linked_list_iterator(tester_t *tester)
linked_list->insert_first(linked_list,"four");
linked_list->insert_first(linked_list,"five");
- linked_list_iterator_t * iterator;
- linked_list_iterator_t * iterator2;
+ iterator_t * iterator;
+ iterator_t * iterator2;
tester->assert_true(tester,(linked_list->create_iterator(linked_list,&iterator,TRUE) == SUCCESS), "create_iterator for it 1 call check");
@@ -160,7 +160,7 @@ void test_linked_list_iterator(tester_t *tester)
void test_linked_list_insert_and_remove(tester_t *tester)
{
void *value;
- linked_list_iterator_t * iterator;
+ iterator_t * iterator;
linked_list_t *linked_list = linked_list_create();
linked_list->insert_first(linked_list,"one");
diff --git a/Source/charon/testcases/parser_test.c b/Source/charon/testcases/parser_test.c
index 5ef5e5bf7..0cc9a2920 100644
--- a/Source/charon/testcases/parser_test.c
+++ b/Source/charon/testcases/parser_test.c
@@ -96,7 +96,7 @@ void test_parser_with_sa_payload(tester_t *tester)
sa_payload_t *sa_payload;
status_t status;
chunk_t sa_chunk;
- linked_list_iterator_t *proposals, *transforms, *attributes;
+ iterator_t *proposals, *transforms, *attributes;
u_int8_t sa_bytes[] = {
0x00,0x80,0x00,0x24, /* payload header*/
diff --git a/Source/charon/testcases/testcases.c b/Source/charon/testcases/testcases.c
index 937f2f05d..ed9a6fbc9 100644
--- a/Source/charon/testcases/testcases.c
+++ b/Source/charon/testcases/testcases.c
@@ -65,7 +65,7 @@ test_t linked_list_test = {test_linked_list,"Linked List"};
/**
* Test for linked_list_t with iterator
*/
-test_t linked_list_iterator_test = {test_linked_list_iterator,"Linked List Iterator"};
+test_t iterator_test = {test_linked_list_iterator,"Linked List Iterator"};
/**
* Test for linked_list_t insert and remove
@@ -243,7 +243,7 @@ logger_manager_t *global_logger_manager;
test_t *all_tests[] ={
&linked_list_test,
- &linked_list_iterator_test,
+ &iterator_test,
&linked_list_insert_and_remove_test,
&thread_pool_test,
&job_queue_test1,
diff --git a/Source/charon/utils/iterator.h b/Source/charon/utils/iterator.h
new file mode 100644
index 000000000..17deb630c
--- /dev/null
+++ b/Source/charon/utils/iterator.h
@@ -0,0 +1,124 @@
+/**
+ * @file iterator.h
+ *
+ * @brief Interface iterator_t.
+ *
+ */
+
+/*
+ * Copyright (C) 2005 Jan Hutter, Martin Willi
+ * Hochschule fuer Technik Rapperswil
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2 of the License, or (at your
+ * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * for more details.
+ */
+
+#ifndef ITERATOR_H_
+#define ITERATOR_H_
+
+typedef struct iterator_t iterator_t;
+
+/**
+ * @brief Iterator interface, allows iteration over collections.
+ *
+ * iterator_t defines an interface for iterating over collections.
+ * It allows searching, deleting, updating and inserting.
+ *
+ */
+struct iterator_t {
+
+ /**
+ * @brief Moves to the next element, if available.
+ *
+ * @param this calling object
+ * @return
+ * - TRUE, if more elements are avaiable,
+ * - FALSE otherwise
+ */
+ bool (*has_next) (iterator_t *this);
+
+ /**
+ * @brief Returns the current value at the iterator position.
+ *
+ * @param this calling object
+ * @param [out]value value is set to the current value at iterator position
+ * @return
+ * - SUCCESS, or
+ * - FAILED if iterator is on an invalid state
+ */
+ status_t (*current) (iterator_t *this, void **value);
+
+ /**
+ * @brief Inserts a new item before the given iterator position.
+ *
+ * The iterator position is not changed after inserting
+ *
+ * @param this calling iterator
+ * @param [in]item value to insert in list
+ * @return
+ * - SUCCESS if succeeded,
+ * - FAILED otherwise
+ */
+ status_t (*insert_before) (iterator_t *this, void *item);
+
+ /**
+ * @brief Inserts a new item after the given iterator position.
+ *
+ * The iterator position is not changed after inserting.
+ *
+ * @param this calling iterator
+ * @param [in]item value to insert in list
+ * @return
+ * - SUCCESS if succeeded,
+ * - FAILED otherwise
+ */
+ status_t (*insert_after) (iterator_t *this, void *item);
+
+ /**
+ * @brief removes an element from list at the given iterator position.
+ *
+ * The position of the iterator is set in the following order:
+ * - to the item before, if available
+ * - otherwise to the item after, if available
+ * - otherwise it gets reseted
+ *
+ * @param linked_list calling object
+ * @return
+ * - SUCCESS if succeeded,
+ * - FAILED otherwise
+ */
+ status_t (*remove) (iterator_t *iterator);
+
+ /**
+ * @brief Resets the iterator position.
+ *
+ * After reset, the iterator stands NOT on an element.
+ * A call to has_next is necessary to do any other operations
+ * with the resetted iterator.
+ *
+ * @param this calling object
+ * @return
+ * - SUCCESS if succeeded,
+ * - FAILED otherwise
+ */
+ status_t (*reset) (iterator_t *this);
+
+ /**
+ * @brief Destroys an iterator.
+ *
+ * @param this iterator to destroy
+ * @return
+ * - SUCCESS if succeeded,
+ * - FAILED otherwise
+ */
+ status_t (*destroy) (iterator_t *this);
+};
+
+#endif /*ITERATOR_H_*/
diff --git a/Source/charon/utils/linked_list.c b/Source/charon/utils/linked_list.c
index 2c6776c96..63a177c05 100644
--- a/Source/charon/utils/linked_list.c
+++ b/Source/charon/utils/linked_list.c
@@ -135,13 +135,13 @@ struct private_linked_list_t {
* Private variables and functions of linked list iterator
*
*/
-typedef struct private_linked_list_iterator_t private_linked_list_iterator_t;
+typedef struct private_iterator_t private_iterator_t;
-struct private_linked_list_iterator_t {
+struct private_iterator_t {
/**
* Public part of linked list iterator
*/
- linked_list_iterator_t public;
+ iterator_t public;
/**
* associated linked list
@@ -162,7 +162,7 @@ struct private_linked_list_iterator_t {
/**
* Implements function has_next of linked_list_iteratr
*/
-bool iterator_has_next(private_linked_list_iterator_t *this)
+bool iterator_has_next(private_iterator_t *this)
{
if (this->list->count == 0)
{
@@ -194,7 +194,7 @@ bool iterator_has_next(private_linked_list_iterator_t *this)
/**
* Implements function current of linked_list_iteratr
*/
-static status_t iterator_current(private_linked_list_iterator_t *this, void **value)
+static status_t iterator_current(private_iterator_t *this, void **value)
{
if (this == NULL)
{
@@ -211,7 +211,7 @@ static status_t iterator_current(private_linked_list_iterator_t *this, void **va
/**
* Implements function current of linked_list_iteratr
*/
-static status_t iterator_reset(private_linked_list_iterator_t *this)
+static status_t iterator_reset(private_iterator_t *this)
{
if (this == NULL)
{
@@ -224,7 +224,7 @@ static status_t iterator_reset(private_linked_list_iterator_t *this)
/**
* Implements function destroy of linked_list_iteratr
*/
-static status_t iterator_destroy(private_linked_list_iterator_t *this)
+static status_t iterator_destroy(private_iterator_t *this)
{
if (this == NULL)
{
@@ -457,7 +457,7 @@ static status_t get_last(private_linked_list_t *this, void **item)
/**
* @brief implements function insert_before of linked_list_t
*/
-static status_t insert_before(private_linked_list_iterator_t * iterator, void *item)
+static status_t insert_before(private_iterator_t * iterator, void *item)
{
if (iterator->current == NULL)
{
@@ -499,7 +499,7 @@ static status_t insert_before(private_linked_list_iterator_t * iterator, void *i
/**
* @brief implements function insert_after of linked_list_t
*/
-static status_t insert_after(private_linked_list_iterator_t * iterator, void *item)
+static status_t insert_after(private_iterator_t * iterator, void *item)
{
if (iterator->current == NULL)
{
@@ -541,7 +541,7 @@ static status_t insert_after(private_linked_list_iterator_t * iterator, void *it
/**
* @brief implements function remove of linked_list_t.
*/
-static status_t remove(private_linked_list_iterator_t *this)
+static status_t remove(private_iterator_t *this)
{
linked_list_element_t *new_current;
@@ -600,22 +600,22 @@ static status_t remove(private_linked_list_iterator_t *this)
return SUCCESS;
}
-static status_t create_iterator (private_linked_list_t *linked_list, linked_list_iterator_t **iterator,bool forward)
+static status_t create_iterator (private_linked_list_t *linked_list, iterator_t **iterator,bool forward)
{
- private_linked_list_iterator_t *this = allocator_alloc_thing(private_linked_list_iterator_t);
+ private_iterator_t *this = allocator_alloc_thing(private_iterator_t);
if (this == NULL)
{
return FAILED;
}
- this->public.has_next = (bool (*) (linked_list_iterator_t *this)) iterator_has_next;
- this->public.current = (status_t (*) (linked_list_iterator_t *this, void **value)) iterator_current;
- this->public.insert_before = (status_t (*) (linked_list_iterator_t *this, void *item)) insert_before;
- this->public.insert_after = (status_t (*) (linked_list_iterator_t *this, void *item)) insert_after;
- this->public.remove = (status_t (*) (linked_list_iterator_t *this)) remove;
- this->public.reset = (status_t (*) (linked_list_iterator_t *this)) iterator_reset;
- this->public.destroy = (status_t (*) (linked_list_iterator_t *this)) iterator_destroy;
+ this->public.has_next = (bool (*) (iterator_t *this)) iterator_has_next;
+ this->public.current = (status_t (*) (iterator_t *this, void **value)) iterator_current;
+ this->public.insert_before = (status_t (*) (iterator_t *this, void *item)) insert_before;
+ this->public.insert_after = (status_t (*) (iterator_t *this, void *item)) insert_after;
+ this->public.remove = (status_t (*) (iterator_t *this)) remove;
+ this->public.reset = (status_t (*) (iterator_t *this)) iterator_reset;
+ this->public.destroy = (status_t (*) (iterator_t *this)) iterator_destroy;
this->forward = forward;
@@ -661,7 +661,7 @@ linked_list_t *linked_list_create()
private_linked_list_t *this = allocator_alloc_thing(private_linked_list_t);
this->public.get_count = (int (*) (linked_list_t *linked_list)) get_count;
- this->public.create_iterator = (status_t (*) (linked_list_t *linked_list, linked_list_iterator_t **iterator,bool forward)) create_iterator;
+ this->public.create_iterator = (status_t (*) (linked_list_t *linked_list, iterator_t **iterator,bool forward)) create_iterator;
this->public.get_first = (status_t (*) (linked_list_t *linked_list, void **item)) get_first;
this->public.get_last = (status_t (*) (linked_list_t *linked_list, void **item)) get_last;
this->public.insert_first = (status_t (*) (linked_list_t *linked_list, void *item)) insert_first;
diff --git a/Source/charon/utils/linked_list.h b/Source/charon/utils/linked_list.h
index 71fdfd45e..10891352d 100644
--- a/Source/charon/utils/linked_list.h
+++ b/Source/charon/utils/linked_list.h
@@ -24,90 +24,11 @@
#define LINKED_LIST_H_
#include <types.h>
+#include <utils/iterator.h>
-typedef struct linked_list_iterator_t linked_list_iterator_t;
-
-/**
- * @brief Iterator for a linked list.
- *
- * This element holds a pointer to the current element in the linked list
- *
- * @warning the iterator is NOT thread-save
- */
-struct linked_list_iterator_t {
-
- /**
- * @brief returns TRUE if more elements are available
- *
- * @param this calling object
- * @return if more elements are avaiable TRUE, FALSE otherwise
- */
- bool (*has_next) (linked_list_iterator_t *this);
-
- /**
- * @brief returns the current value at the iterator position
- *
- * @param this calling object
- * @param[out] value value is set to the current value at iterator position
- * @return SUCCESS if succeeded, FAILED otherwise
- */
- status_t (*current) (linked_list_iterator_t *this, void **value);
-
- /**
- * @brief inserts a new item before the given iterator position
- *
- * The iterator position is not changed after inserting
- *
- * @param this calling iterator
- * @param[in] item value to insert in list
- * @return SUCCESS if succeeded, FAILED otherwise
- */
- status_t (*insert_before) (linked_list_iterator_t *this, void *item);
-
- /**
- * @brief inserts a new item after the given iterator position
- *
- * The iterator position is not changed after inserting
- *
- * @param this calling iterator
- * @param[in] item value to insert in list
- * @return SUCCESS if succeeded, FAILED otherwise
- */
- status_t (*insert_after) (linked_list_iterator_t *this, void *item);
-
- /**
- * @brief removes an element from list at the given iterator position.
- *
- * The position of the iterator is set in the following order:
- * - to the item before, if available
- * - otherwise to the item after, if available
- * - otherwise it gets reseted
- *
- * @param linked_list calling object
- * @param iterator iterator holding the position of the element to remove
- * @return SUCCESS if succeeded, FAILED otherwise
- */
- status_t (*remove) (linked_list_iterator_t *iterator);
- /**
- * @brief Resets a linked_list_iterator object
- *
- * @param this calling object
- * @return SUCCESS if succeeded, FAILED otherwise
- */
- status_t (*reset) (linked_list_iterator_t *this);
-
- /**
- * @brief Destroys a linked_list_iterator object
- *
- * @param this calling object
- * @return SUCCESS if succeeded, FAILED otherwise
- */
- status_t (*destroy) (linked_list_iterator_t *this);
-};
typedef struct linked_list_t linked_list_t;
-
/**
* @brief Double Linked List (named only as linked list).
*
@@ -137,7 +58,7 @@ struct linked_list_t {
* @param[in] forward iterator direction (TRUE: front to end)
* @return SUCCESS if succeeded, FAILED otherwise
*/
- status_t (*create_iterator) (linked_list_t *linked_list, linked_list_iterator_t **iterator,bool forward);
+ status_t (*create_iterator) (linked_list_t *linked_list, iterator_t **iterator,bool forward);
/**
* @brief inserts a new item at the beginning of the list
diff --git a/Source/charon/utils/logger_manager.c b/Source/charon/utils/logger_manager.c
index b145b279e..5f97bce8a 100644
--- a/Source/charon/utils/logger_manager.c
+++ b/Source/charon/utils/logger_manager.c
@@ -194,7 +194,7 @@ static logger_t *create_logger(private_logger_manager_t *this, logger_context_t
*/
static logger_level_t get_logger_level (private_logger_manager_t *this, logger_context_t context)
{
- linked_list_iterator_t *iterator;
+ iterator_t *iterator;
/* set logger_level to default logger_level */
logger_level_t logger_level = this->default_log_level;
@@ -235,7 +235,7 @@ static logger_level_t get_logger_level (private_logger_manager_t *this, logger_c
static status_t destroy_logger (private_logger_manager_t *this,logger_t *logger)
{
- linked_list_iterator_t *iterator;
+ iterator_t *iterator;
status_t status = NOT_FOUND;
pthread_mutex_lock(&(this->mutex));
@@ -275,7 +275,7 @@ static status_t destroy_logger (private_logger_manager_t *this,logger_t *logger)
*/
static status_t set_logger_level (private_logger_manager_t *this, logger_context_t context,logger_level_t logger_level,bool enable)
{
- linked_list_iterator_t *iterator;
+ iterator_t *iterator;
status_t status;
pthread_mutex_lock(&(this->mutex));