- moved linked_list_iterator_t to iterator_t, located in iterator.h
authorMartin Willi <martin@strongswan.org>
Thu, 24 Nov 2005 14:22:29 +0000 (14:22 -0000)
committerMartin Willi <martin@strongswan.org>
Thu, 24 Nov 2005 14:22:29 +0000 (14:22 -0000)
23 files changed:
Source/charon/config/configuration_manager.c
Source/charon/config/configuration_manager.h
Source/charon/encoding/generator.c
Source/charon/encoding/message.c
Source/charon/encoding/message.h
Source/charon/encoding/payloads/proposal_substructure.c
Source/charon/encoding/payloads/proposal_substructure.h
Source/charon/encoding/payloads/sa_payload.c
Source/charon/encoding/payloads/sa_payload.h
Source/charon/encoding/payloads/transform_substructure.c
Source/charon/encoding/payloads/transform_substructure.h
Source/charon/queues/event_queue.c
Source/charon/sa/ike_sa_manager.c
Source/charon/sa/states/ike_sa_init_requested.c
Source/charon/sa/states/initiator_init.c
Source/charon/sa/states/responder_init.c
Source/charon/testcases/linked_list_test.c
Source/charon/testcases/parser_test.c
Source/charon/testcases/testcases.c
Source/charon/utils/iterator.h [new file with mode: 0644]
Source/charon/utils/linked_list.c
Source/charon/utils/linked_list.h
Source/charon/utils/logger_manager.c

index 72e801a..cc547db 100644 (file)
@@ -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 */
index 54d302d..fe0e5cc 100644 (file)
@@ -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
index 0d047c2..5ba7ee1 100644 (file)
@@ -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)
index 4ec7805..27fd7f5 100644 (file)
@@ -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;
index 3ec1daf..2b2a14a 100644 (file)
@@ -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
index 5cdd3b2..ab575d4 100644 (file)
@@ -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;
index 134c477..d6f90e4 100644 (file)
@@ -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.
index 7a8b714..c760dc3 100644 (file)
@@ -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;
        
index 2f882d0..7eada84 100644 (file)
@@ -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.
index 0d931c9..e81aae5 100644 (file)
@@ -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;
index 9cd9477..e4b503a 100644 (file)
@@ -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.
index 20802d3..eb33330 100644 (file)
@@ -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)
index 669bcec..31bc74a 100644 (file)
@@ -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;
        
index a42b57e..040942a 100644 (file)
@@ -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;
index 5825eb2..f71c283 100644 (file)
@@ -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 */
index 885e0d7..ffb010f 100644 (file)
@@ -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;
        
        
index c13aedf..85a84e2 100644 (file)
@@ -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");
index 5ef5e5b..0cc9a29 100644 (file)
@@ -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*/
index 937f2f0..ed9a6fb 100644 (file)
@@ -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 (file)
index 0000000..17deb63
--- /dev/null
@@ -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_*/
index 2c6776c..63a177c 100644 (file)
@@ -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;
index 71fdfd4..1089135 100644 (file)
 #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
index b145b27..5f97bce 100644 (file)
@@ -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));