diff options
Diffstat (limited to 'Source/charon')
24 files changed, 92 insertions, 122 deletions
diff --git a/Source/charon/config/configuration_manager.c b/Source/charon/config/configuration_manager.c index 294dd3b8e..e39d7c8e8 100644 --- a/Source/charon/config/configuration_manager.c +++ b/Source/charon/config/configuration_manager.c @@ -227,7 +227,7 @@ static status_t select_proposals_for_host(private_configuration_manager_t *this, in->current(in,(void **) &first_suggested_proposal); - first_suggested_proposal->clone(first_suggested_proposal,&selected_proposal); + selected_proposal = first_suggested_proposal->clone(first_suggested_proposal); out->insert_after(out,selected_proposal); return SUCCESS; diff --git a/Source/charon/encoding/generator.c b/Source/charon/encoding/generator.c index f4ae72294..cb646fa59 100644 --- a/Source/charon/encoding/generator.c +++ b/Source/charon/encoding/generator.c @@ -771,7 +771,7 @@ static void generate_payload (private_generator_t *this,payload_t *payload) iterator_t *iterator; /* create forward iterator */ - proposals->create_iterator(proposals,&iterator,TRUE); + iterator = proposals->create_iterator(proposals,TRUE); /* every proposal is processed (iterative call )*/ while (iterator->has_next(iterator)) { @@ -805,7 +805,7 @@ static void generate_payload (private_generator_t *this,payload_t *payload) iterator_t *iterator; /* create forward iterator */ - transforms->create_iterator(transforms,&iterator,TRUE); + iterator = transforms->create_iterator(transforms,TRUE); while (iterator->has_next(iterator)) { payload_t *current_transform; @@ -840,7 +840,7 @@ static void generate_payload (private_generator_t *this,payload_t *payload) iterator_t *iterator; /* create forward iterator */ - transform_attributes->create_iterator(transform_attributes,&iterator,TRUE); + iterator = transform_attributes->create_iterator(transform_attributes,TRUE); while (iterator->has_next(iterator)) { payload_t *current_attribute; diff --git a/Source/charon/encoding/message.c b/Source/charon/encoding/message.c index 700790b48..37e9a55f1 100644 --- a/Source/charon/encoding/message.c +++ b/Source/charon/encoding/message.c @@ -429,9 +429,9 @@ static void get_destination(private_message_t *this, host_t **host) /** * Implementation of message_t.get_destination. */ -static void get_payload_iterator(private_message_t *this, iterator_t **iterator) +static iterator_t *get_payload_iterator(private_message_t *this) { - this->payloads->create_iterator(this->payloads, iterator, TRUE); + return this->payloads->create_iterator(this->payloads, TRUE); } @@ -477,7 +477,7 @@ static status_t generate(private_message_t *this, crypter_t *crypter, signer_t* payload = (payload_t*)ike_header; - this->payloads->create_iterator(this->payloads, &iterator, TRUE); + iterator = this->payloads->create_iterator(this->payloads, TRUE); /* generate every payload, except last one */ while(iterator->has_next(iterator)) @@ -666,9 +666,7 @@ static status_t verify(private_message_t *this) this->logger->log(this->logger, ERROR, "could not get supported payloads: %s"); return status; } - - this->payloads->create_iterator(this->payloads,&iterator,TRUE); - + iterator = this->payloads->create_iterator(this->payloads,TRUE); /* check for payloads with wrong count*/ for (i = 0; i < supported_payloads_count;i++) { @@ -683,6 +681,7 @@ static status_t verify(private_message_t *this) { payload_t *current_payload; iterator->current(iterator,(void **)¤t_payload); + if (current_payload->get_type(current_payload) == payload_type) { @@ -725,7 +724,7 @@ static void destroy (private_message_t *this) this->ike_sa_id->destroy(this->ike_sa_id); } - this->payloads->create_iterator(this->payloads, &iterator, TRUE); + iterator = this->payloads->create_iterator(this->payloads, TRUE); while (iterator->has_next(iterator)) { payload_t *payload; @@ -748,10 +747,6 @@ static void destroy (private_message_t *this) message_t *message_create_from_packet(packet_t *packet) { private_message_t *this = allocator_alloc_thing(private_message_t); - if (this == NULL) - { - return NULL; - } /* public functions */ this->public.set_major_version = (void(*)(message_t*, u_int8_t))set_major_version; @@ -773,7 +768,7 @@ message_t *message_create_from_packet(packet_t *packet) this->public.get_source = (void (*) (message_t*,host_t**)) get_source; this->public.set_destination = (void (*) (message_t*,host_t*)) set_destination; this->public.get_destination = (void (*) (message_t*,host_t**)) get_destination; - this->public.get_payload_iterator = (void (*) (message_t *, iterator_t **)) get_payload_iterator; + this->public.get_payload_iterator = (iterator_t * (*) (message_t *)) get_payload_iterator; this->public.parse_header = (status_t (*) (message_t *)) parse_header; this->public.parse_body = (status_t (*) (message_t *,crypter_t*,signer_t*)) parse_body; this->public.verify = (status_t (*) (message_t*)) verify; @@ -794,36 +789,13 @@ message_t *message_create_from_packet(packet_t *packet) { packet = packet_create(); } - if (packet == NULL) - { - allocator_free(this); - return NULL; - } this->packet = packet; this->payloads = linked_list_create(); - if (this->payloads == NULL) - { - allocator_free(this); - return NULL; - } /* parser is created from data of packet */ this->parser = parser_create(this->packet->data); - if (this->parser == NULL) - { - this->payloads->destroy(this->payloads); - allocator_free(this); - return NULL; - } this->logger = global_logger_manager->create_logger(global_logger_manager, MESSAGE, NULL); - if (this->logger == NULL) - { - this->parser->destroy(this->parser); - this->payloads->destroy(this->payloads); - allocator_free(this); - return NULL; - } return (&this->public); } diff --git a/Source/charon/encoding/message.h b/Source/charon/encoding/message.h index 8ee069528..68558d575 100644 --- a/Source/charon/encoding/message.h +++ b/Source/charon/encoding/message.h @@ -226,7 +226,7 @@ struct message_t { void (*set_source) (message_t *this, host_t *host); void (*get_destination) (message_t *this, host_t **host); void (*set_destination) (message_t *this, host_t *host); - void (*get_payload_iterator) (message_t *this, iterator_t **iterator); + iterator_t * (*get_payload_iterator) (message_t *this); /** * @brief Destroys a message and all including objects diff --git a/Source/charon/encoding/payloads/encryption_payload.c b/Source/charon/encoding/payloads/encryption_payload.c index 6bef3bf1b..08722f83f 100644 --- a/Source/charon/encoding/payloads/encryption_payload.c +++ b/Source/charon/encoding/payloads/encryption_payload.c @@ -287,9 +287,9 @@ static size_t get_length(private_encryption_payload_t *this) /** * Implementation of payload_t.create_payload_iterator. */ -static void create_payload_iterator (private_encryption_payload_t *this, iterator_t **iterator, bool forward) +static iterator_t *create_payload_iterator (private_encryption_payload_t *this, bool forward) { - this->payloads->create_iterator(this->payloads, iterator, forward); + return (this->payloads->create_iterator(this->payloads, forward)); } /** @@ -506,7 +506,7 @@ static void generate(private_encryption_payload_t *this) iterator_t *iterator; /* create iterator */ - this->payloads->create_iterator(this->payloads, &iterator, TRUE); + iterator = this->payloads->create_iterator(this->payloads, TRUE); /* get first payload */ if (iterator->has_next(iterator)) @@ -598,7 +598,7 @@ static void compute_length(private_encryption_payload_t *this) { iterator_t *iterator; size_t length = ENCRYPTION_PAYLOAD_HEADER_LENGTH; - this->payloads->create_iterator(this->payloads, &iterator, TRUE); + iterator = this->payloads->create_iterator(this->payloads, TRUE); while (iterator->has_next(iterator)) { @@ -629,7 +629,7 @@ encryption_payload_t *encryption_payload_create() this->public.payload_interface.destroy = (void (*) (payload_t *))destroy; /* public functions */ - this->public.create_payload_iterator = (void (*) (encryption_payload_t *,iterator_t **,bool)) create_payload_iterator; + this->public.create_payload_iterator = (iterator_t * (*) (encryption_payload_t *,bool)) create_payload_iterator; this->public.add_payload = (void (*) (encryption_payload_t *,payload_t *)) add_payload; this->public.encrypt = (status_t (*) (encryption_payload_t *, crypter_t*)) encrypt; this->public.decrypt = (status_t (*) (encryption_payload_t *, crypter_t*)) decrypt; diff --git a/Source/charon/encoding/payloads/encryption_payload.h b/Source/charon/encoding/payloads/encryption_payload.h index 398adbaee..caf7e6b06 100644 --- a/Source/charon/encoding/payloads/encryption_payload.h +++ b/Source/charon/encoding/payloads/encryption_payload.h @@ -49,12 +49,14 @@ struct encryption_payload_t { /** * @brief Creates an iterator for all contained payloads. + * + * @warning iterator_t object has to get destroyed by the caller. * * @param this calling encryption_payload_t object - * @param iterator the created iterator is stored at the pointed pointer * @param[in] forward iterator direction (TRUE: front to end) + * return created iterator_t object */ - void (*create_payload_iterator) (encryption_payload_t *this, iterator_t **iterator, bool forward); + iterator_t *(*create_payload_iterator) (encryption_payload_t *this, bool forward); /** * @brief Adds a payload to this encryption payload. diff --git a/Source/charon/encoding/payloads/proposal_substructure.c b/Source/charon/encoding/payloads/proposal_substructure.c index 765fd1d0d..c80880d77 100644 --- a/Source/charon/encoding/payloads/proposal_substructure.c +++ b/Source/charon/encoding/payloads/proposal_substructure.c @@ -205,9 +205,9 @@ static size_t get_length(private_proposal_substructure_t *this) /** * Implementation of proposal_substructure_t.create_transform_substructure_iterator. */ -static void create_transform_substructure_iterator (private_proposal_substructure_t *this,iterator_t **iterator,bool forward) +static iterator_t *create_transform_substructure_iterator (private_proposal_substructure_t *this,bool forward) { - this->transforms->create_iterator(this->transforms,iterator,forward); + return (this->transforms->create_iterator(this->transforms,forward)); } /** @@ -304,7 +304,7 @@ static status_t get_info_for_transform_type (private_proposal_substructure_t *th u_int16_t found_transform_id; u_int16_t found_key_length; - this->transforms->create_iterator(this->transforms,&iterator,TRUE); + iterator = this->transforms->create_iterator(this->transforms,TRUE); while (iterator->has_next(iterator)) { @@ -337,7 +337,7 @@ static void compute_length (private_proposal_substructure_t *this) iterator_t *iterator; size_t transforms_count = 0; size_t length = PROPOSAL_SUBSTRUCTURE_HEADER_LENGTH; - this->transforms->create_iterator(this->transforms,&iterator,TRUE); + iterator = this->transforms->create_iterator(this->transforms,TRUE); while (iterator->has_next(iterator)) { payload_t * current_transform; @@ -356,7 +356,7 @@ static void compute_length (private_proposal_substructure_t *this) /** * Implementation of proposal_substructure_t.clone. */ -static void clone(private_proposal_substructure_t *this, private_proposal_substructure_t **clone) +static private_proposal_substructure_t* clone(private_proposal_substructure_t *this) { private_proposal_substructure_t * new_clone; iterator_t *transforms; @@ -373,7 +373,7 @@ static void clone(private_proposal_substructure_t *this, private_proposal_substr new_clone->spi.len = this->spi.len; } - this->transforms->create_iterator(this->transforms,&transforms,FALSE); + transforms = this->transforms->create_iterator(this->transforms,FALSE); while (transforms->has_next(transforms)) { @@ -382,14 +382,14 @@ static void clone(private_proposal_substructure_t *this, private_proposal_substr transforms->current(transforms,(void **) ¤t_transform); - current_transform->clone(current_transform,¤t_transform_clone); + current_transform_clone = current_transform->clone(current_transform); new_clone->public.add_transform_substructure(&(new_clone->public),current_transform_clone); } transforms->destroy(transforms); - *clone = new_clone; + return new_clone; } /** @@ -437,7 +437,7 @@ proposal_substructure_t *proposal_substructure_create() this->public.payload_interface.destroy = (void (*) (payload_t *))destroy; /* public functions */ - this->public.create_transform_substructure_iterator = (void (*) (proposal_substructure_t *,iterator_t **,bool)) create_transform_substructure_iterator; + this->public.create_transform_substructure_iterator = (iterator_t* (*) (proposal_substructure_t *,bool)) create_transform_substructure_iterator; this->public.add_transform_substructure = (void (*) (proposal_substructure_t *,transform_substructure_t *)) add_transform_substructure; this->public.set_proposal_number = (void (*) (proposal_substructure_t *,u_int8_t))set_proposal_number; this->public.get_proposal_number = (u_int8_t (*) (proposal_substructure_t *)) get_proposal_number; @@ -446,7 +446,7 @@ proposal_substructure_t *proposal_substructure_create() this->public.get_info_for_transform_type = (status_t (*) (proposal_substructure_t *,transform_type_t,u_int16_t *, u_int16_t *))get_info_for_transform_type; this->public.set_spi = (void (*) (proposal_substructure_t *,chunk_t))set_spi; this->public.get_spi = (chunk_t (*) (proposal_substructure_t *)) get_spi; - this->public.clone = (void (*) (proposal_substructure_t *, proposal_substructure_t **)) clone; + this->public.clone = (proposal_substructure_t * (*) (proposal_substructure_t *)) clone; this->public.destroy = (void (*) (proposal_substructure_t *)) destroy; diff --git a/Source/charon/encoding/payloads/proposal_substructure.h b/Source/charon/encoding/payloads/proposal_substructure.h index d92a92c0e..f131cf74c 100644 --- a/Source/charon/encoding/payloads/proposal_substructure.h +++ b/Source/charon/encoding/payloads/proposal_substructure.h @@ -74,10 +74,10 @@ struct proposal_substructure_t { * get_size to make sure the length and number values are ok. * * @param this calling proposal_substructure_t object - * @param iterator the created iterator is stored at the pointed pointer * @param[in] forward iterator direction (TRUE: front to end) + * @return created iterator_t object */ - void (*create_transform_substructure_iterator) (proposal_substructure_t *this,iterator_t **iterator, bool forward); + iterator_t * (*create_transform_substructure_iterator) (proposal_substructure_t *this, bool forward); /** * @brief Adds a transform_substructure_t object to this object. @@ -161,9 +161,9 @@ struct proposal_substructure_t { * @brief Clones an proposal_substructure_t object. * * @param this proposal_substructure_t object to clone - * @param clone cloned object will be written there + * @return cloned object */ - void (*clone) (proposal_substructure_t *this,proposal_substructure_t **clone); + proposal_substructure_t* (*clone) (proposal_substructure_t *this); /** * @brief Destroys an proposal_substructure_t object. diff --git a/Source/charon/encoding/payloads/sa_payload.c b/Source/charon/encoding/payloads/sa_payload.c index 92e08a042..d9175de60 100644 --- a/Source/charon/encoding/payloads/sa_payload.c +++ b/Source/charon/encoding/payloads/sa_payload.c @@ -126,7 +126,7 @@ static status_t verify(private_sa_payload_t *this) } /* check proposal numbering */ - this->proposals->create_iterator(this->proposals,&iterator,TRUE); + iterator = this->proposals->create_iterator(this->proposals,TRUE); while(iterator->has_next(iterator)) { @@ -230,9 +230,9 @@ static size_t get_length(private_sa_payload_t *this) /** * Implementation of sa_payload_t.create_proposal_substructure_iterator. */ -static void create_proposal_substructure_iterator (private_sa_payload_t *this,iterator_t **iterator,bool forward) +static iterator_t *create_proposal_substructure_iterator (private_sa_payload_t *this,bool forward) { - this->proposals->create_iterator(this->proposals,iterator,forward); + return this->proposals->create_iterator(this->proposals,forward); } /** @@ -251,7 +251,7 @@ static void compute_length (private_sa_payload_t *this) { iterator_t *iterator; size_t length = SA_PAYLOAD_HEADER_LENGTH; - this->proposals->create_iterator(this->proposals,&iterator,TRUE); + iterator = this->proposals->create_iterator(this->proposals,TRUE); while (iterator->has_next(iterator)) { payload_t *current_proposal; @@ -280,7 +280,7 @@ sa_payload_t *sa_payload_create() this->public.payload_interface.destroy = (void (*) (payload_t *))destroy; /* public functions */ - this->public.create_proposal_substructure_iterator = (void (*) (sa_payload_t *,iterator_t **,bool)) create_proposal_substructure_iterator; + this->public.create_proposal_substructure_iterator = (iterator_t* (*) (sa_payload_t *,bool)) create_proposal_substructure_iterator; this->public.add_proposal_substructure = (void (*) (sa_payload_t *,proposal_substructure_t *)) add_proposal_substructure; this->public.destroy = (void (*) (sa_payload_t *)) destroy; diff --git a/Source/charon/encoding/payloads/sa_payload.h b/Source/charon/encoding/payloads/sa_payload.h index 5e5d94550..dbd0bd1c3 100644 --- a/Source/charon/encoding/payloads/sa_payload.h +++ b/Source/charon/encoding/payloads/sa_payload.h @@ -67,10 +67,10 @@ struct sa_payload_t { * by calling get_length()! * * @param this calling sa_payload_t object - * @param iterator the created iterator is stored at the pointed pointer * @param[in] forward iterator direction (TRUE: front to end) + * @return created iterator_t object */ - void (*create_proposal_substructure_iterator) (sa_payload_t *this,iterator_t **iterator, bool forward); + iterator_t *(*create_proposal_substructure_iterator) (sa_payload_t *this, bool forward); /** * @brief Adds a proposal_substructure_t object to this object. diff --git a/Source/charon/encoding/payloads/transform_attribute.c b/Source/charon/encoding/payloads/transform_attribute.c index 40f06bd8c..c85895fc6 100644 --- a/Source/charon/encoding/payloads/transform_attribute.c +++ b/Source/charon/encoding/payloads/transform_attribute.c @@ -255,7 +255,7 @@ static u_int16_t get_attribute_type (private_transform_attribute_t *this) /** * Implementation of transform_attribute_t.clone. */ -static void clone(private_transform_attribute_t *this,transform_attribute_t **clone) +static transform_attribute_t * clone(private_transform_attribute_t *this) { private_transform_attribute_t *new_clone; @@ -271,7 +271,7 @@ static void clone(private_transform_attribute_t *this,transform_attribute_t **cl new_clone->attribute_value.len = this->attribute_value.len; } - *clone = (transform_attribute_t *) new_clone; + return (transform_attribute_t *) new_clone; } /** @@ -309,7 +309,7 @@ transform_attribute_t *transform_attribute_create() this->public.get_value = (u_int16_t (*) (transform_attribute_t *)) get_value; this->public.set_attribute_type = (void (*) (transform_attribute_t *,u_int16_t type)) set_attribute_type; this->public.get_attribute_type = (u_int16_t (*) (transform_attribute_t *)) get_attribute_type; - this->public.clone = (void (*) (transform_attribute_t *,transform_attribute_t **)) clone; + this->public.clone = (transform_attribute_t * (*) (transform_attribute_t *)) clone; this->public.destroy = (void (*) (transform_attribute_t *)) destroy; /* set default values of the fields */ diff --git a/Source/charon/encoding/payloads/transform_attribute.h b/Source/charon/encoding/payloads/transform_attribute.h index c436012ce..8a0deb765 100644 --- a/Source/charon/encoding/payloads/transform_attribute.h +++ b/Source/charon/encoding/payloads/transform_attribute.h @@ -119,9 +119,9 @@ struct transform_attribute_t { * @brief Clones an transform_attribute_t object. * * @param this transform_attribute_t object to clone - * @param clone the new clone will be written there + * @return cloned transform_attribute_t object */ - void (*clone) (transform_attribute_t *this,transform_attribute_t **clone); + transform_attribute_t * (*clone) (transform_attribute_t *this); /** * @brief Destroys an transform_attribute_t object. diff --git a/Source/charon/encoding/payloads/transform_substructure.c b/Source/charon/encoding/payloads/transform_substructure.c index cbbfb41e9..4e3655b15 100644 --- a/Source/charon/encoding/payloads/transform_substructure.c +++ b/Source/charon/encoding/payloads/transform_substructure.c @@ -261,9 +261,9 @@ static size_t get_length(private_transform_substructure_t *this) /** * Implementation of transform_substructure_t.create_transform_attribute_iterator. */ -static void create_transform_attribute_iterator (private_transform_substructure_t *this,iterator_t **iterator,bool forward) +static iterator_t *create_transform_attribute_iterator (private_transform_substructure_t *this,bool forward) { - this->attributes->create_iterator(this->attributes,iterator,forward); + return this->attributes->create_iterator(this->attributes,forward); } /** @@ -337,7 +337,7 @@ static void compute_length (private_transform_substructure_t *this) { iterator_t *iterator; size_t length = TRANSFORM_SUBSTRUCTURE_HEADER_LENGTH; - this->attributes->create_iterator(this->attributes,&iterator,TRUE); + iterator = this->attributes->create_iterator(this->attributes,TRUE); while (iterator->has_next(iterator)) { payload_t * current_attribute; @@ -353,7 +353,7 @@ static void compute_length (private_transform_substructure_t *this) /** * Implementation of transform_substructure_t.clone. */ -static void clone(private_transform_substructure_t *this,transform_substructure_t **clone) +static transform_substructure_t *clone(private_transform_substructure_t *this) { private_transform_substructure_t *new_clone; iterator_t *attributes; @@ -364,7 +364,7 @@ static void clone(private_transform_substructure_t *this,transform_substructure_ new_clone->transform_type = this->transform_type; new_clone->transform_id = this->transform_id; - this->attributes->create_iterator(this->attributes,&attributes,FALSE); + attributes = this->attributes->create_iterator(this->attributes,FALSE); while (attributes->has_next(attributes)) { @@ -372,14 +372,14 @@ static void clone(private_transform_substructure_t *this,transform_substructure_ transform_attribute_t *current_attribute_clone; attributes->current(attributes,(void **) ¤t_attribute); - current_attribute->clone(current_attribute,¤t_attribute_clone); + current_attribute_clone = current_attribute->clone(current_attribute); new_clone->public.add_transform_attribute(&(new_clone->public),current_attribute_clone); } attributes->destroy(attributes); - *clone = &(new_clone->public); + return &(new_clone->public); } @@ -390,7 +390,7 @@ static status_t get_key_length(private_transform_substructure_t *this, u_int16_t { iterator_t *attributes; - this->attributes->create_iterator(this->attributes,&attributes,TRUE); + attributes = this->attributes->create_iterator(this->attributes,TRUE); while (attributes->has_next(attributes)) { @@ -445,7 +445,7 @@ transform_substructure_t *transform_substructure_create() this->public.payload_interface.destroy = (void (*) (payload_t *))destroy; /* public functions */ - this->public.create_transform_attribute_iterator = (void (*) (transform_substructure_t *,iterator_t **,bool)) create_transform_attribute_iterator; + this->public.create_transform_attribute_iterator = (iterator_t * (*) (transform_substructure_t *,bool)) create_transform_attribute_iterator; this->public.add_transform_attribute = (void (*) (transform_substructure_t *,transform_attribute_t *)) add_transform_attribute; this->public.set_is_last_transform = (void (*) (transform_substructure_t *,bool)) set_is_last_transform; this->public.get_is_last_transform = (bool (*) (transform_substructure_t *)) get_is_last_transform; @@ -454,7 +454,7 @@ transform_substructure_t *transform_substructure_create() this->public.set_transform_id = (void (*) (transform_substructure_t *,u_int16_t)) set_transform_id; this->public.get_transform_id = (u_int16_t (*) (transform_substructure_t *)) get_transform_id; this->public.get_key_length = (status_t (*) (transform_substructure_t *,u_int16_t *)) get_key_length; - this->public.clone = (void (*) (transform_substructure_t *,transform_substructure_t **)) clone; + this->public.clone = (transform_substructure_t* (*) (transform_substructure_t *)) clone; this->public.destroy = (void (*) (transform_substructure_t *)) destroy; /* private functions */ diff --git a/Source/charon/encoding/payloads/transform_substructure.h b/Source/charon/encoding/payloads/transform_substructure.h index 39f642620..ac8684cc1 100644 --- a/Source/charon/encoding/payloads/transform_substructure.h +++ b/Source/charon/encoding/payloads/transform_substructure.h @@ -117,10 +117,10 @@ struct transform_substructure_t { * by calling get_length()! * * @param this calling transform_substructure_t object - * @param iterator the created iterator is stored at the pointed pointer * @param[in] forward iterator direction (TRUE: front to end) + * @return created iterator_t object. */ - void (*create_transform_attribute_iterator) (transform_substructure_t *this,iterator_t **iterator, bool forward); + iterator_t * (*create_transform_attribute_iterator) (transform_substructure_t *this, bool forward); /** * @brief Adds a transform_attribute_t object to this object. @@ -200,10 +200,9 @@ struct transform_substructure_t { * @brief Clones an transform_substructure_t object. * * @param this transform_substructure_t object to clone - * @param clone pointer to a transform_substructure_t object pointer - * where the new object is stored to. + * @return cloned transform_substructure_t object */ - void (*clone) (transform_substructure_t *this,transform_substructure_t **clone); + transform_substructure_t* (*clone) (transform_substructure_t *this); /** * @brief Destroys an transform_substructure_t object. diff --git a/Source/charon/queues/event_queue.c b/Source/charon/queues/event_queue.c index 6954bf2eb..7c76aa682 100644 --- a/Source/charon/queues/event_queue.c +++ b/Source/charon/queues/event_queue.c @@ -253,7 +253,7 @@ static void add_absolute(private_event_queue_t *this, job_t *job, timeval_t time iterator_t * iterator; - this->list->create_iterator(this->list,&iterator,TRUE); + iterator = this->list->create_iterator(this->list,TRUE); iterator->has_next(iterator); /* first element has not to be checked (already done) */ diff --git a/Source/charon/sa/ike_sa_manager.c b/Source/charon/sa/ike_sa_manager.c index 943502dcb..34b2a09b3 100644 --- a/Source/charon/sa/ike_sa_manager.c +++ b/Source/charon/sa/ike_sa_manager.c @@ -209,7 +209,7 @@ static status_t get_entry_by_id(private_ike_sa_manager_t *this, ike_sa_id_t *ike status_t status; /* create iterator over list of ike_sa's */ - list->create_iterator(list, &iterator, TRUE); + iterator = list->create_iterator(list, TRUE); /* default status */ status = NOT_FOUND; @@ -252,7 +252,7 @@ static status_t get_entry_by_sa(private_ike_sa_manager_t *this, ike_sa_t *ike_sa iterator_t *iterator; status_t status; - list->create_iterator(list, &iterator, TRUE); + iterator = list->create_iterator(list, TRUE); /* default status */ status = NOT_FOUND; @@ -284,7 +284,7 @@ static status_t delete_entry(private_ike_sa_manager_t *this, ike_sa_entry_t *ent iterator_t *iterator; status_t status; - list->create_iterator(list, &iterator, TRUE); + iterator = list->create_iterator(list, TRUE); status = NOT_FOUND; @@ -606,7 +606,7 @@ static void destroy(private_ike_sa_manager_t *this) this->logger->log(this->logger,CONTROL | MORE,"Going to destroy IKE_SA manager and all managed IKE_SA's"); /* Step 1: drive out all waiting threads */ - list->create_iterator(list, &iterator, TRUE); + iterator = list->create_iterator(list, TRUE); this->logger->log(this->logger,CONTROL | MOST,"Set driveout flags for all stored IKE_SA's"); while (iterator->has_next(iterator)) diff --git a/Source/charon/sa/states/ike_sa_init_requested.c b/Source/charon/sa/states/ike_sa_init_requested.c index d682a769c..d5ad12cf4 100644 --- a/Source/charon/sa/states/ike_sa_init_requested.c +++ b/Source/charon/sa/states/ike_sa_init_requested.c @@ -120,7 +120,7 @@ static status_t process_message(private_ike_sa_init_requested_t *this, message_t ike_sa_id->set_responder_spi(ike_sa_id,responder_spi); /* iterate over incoming payloads */ - message->get_payload_iterator(message, &payloads); + payloads = message->get_payload_iterator(message); while (payloads->has_next(payloads)) { payload_t *payload; @@ -138,7 +138,7 @@ static status_t process_message(private_ike_sa_init_requested_t *this, message_t /* get the list of suggested proposals */ - sa_payload->create_proposal_substructure_iterator(sa_payload, &suggested_proposals, TRUE); + suggested_proposals = sa_payload->create_proposal_substructure_iterator(sa_payload, TRUE); /* now let the configuration-manager check the selected proposals*/ diff --git a/Source/charon/sa/states/initiator_init.c b/Source/charon/sa/states/initiator_init.c index b1e25a4c5..ade422fb1 100644 --- a/Source/charon/sa/states/initiator_init.c +++ b/Source/charon/sa/states/initiator_init.c @@ -174,7 +174,7 @@ static status_t initiate_connection (private_initiator_init_t *this, char *name) } /* get proposals */ - this->proposals->create_iterator(this->proposals, &proposal_iterator, FALSE); + proposal_iterator = this->proposals->create_iterator(this->proposals, FALSE); status = global_configuration_manager->get_proposals_for_host(global_configuration_manager, this->ike_sa->get_other_host(this->ike_sa), proposal_iterator); proposal_iterator->destroy(proposal_iterator); if (status != SUCCESS) @@ -292,7 +292,7 @@ static void build_sa_payload(private_initiator_init_t *this, payload_t **payload */ this->logger->log(this->logger, CONTROL|MORE, "building sa payload"); - this->proposals->create_iterator(this->proposals, &proposal_iterator, FALSE); + proposal_iterator = this->proposals->create_iterator(this->proposals, FALSE); sa_payload = sa_payload_create(); @@ -302,7 +302,7 @@ static void build_sa_payload(private_initiator_init_t *this, payload_t **payload proposal_substructure_t *current_proposal_clone; proposal_iterator->current(proposal_iterator,(void **) ¤t_proposal); - current_proposal->clone(current_proposal,¤t_proposal_clone); + current_proposal_clone = current_proposal->clone(current_proposal); sa_payload->add_proposal_substructure(sa_payload,current_proposal_clone); } diff --git a/Source/charon/sa/states/responder_init.c b/Source/charon/sa/states/responder_init.c index 57e75037b..b528be0e2 100644 --- a/Source/charon/sa/states/responder_init.c +++ b/Source/charon/sa/states/responder_init.c @@ -179,9 +179,8 @@ static status_t process_message(private_responder_init_t *this, message_t *messa this->logger->log(this->logger, ERROR | MORE, "Could not parse body of request message"); return status; } - /* iterate over incoming payloads. We can be sure, the message contains only accepted payloads! */ - message->get_payload_iterator(message, &payloads); + payloads = message->get_payload_iterator(message); while (payloads->has_next(payloads)) { @@ -199,10 +198,10 @@ static status_t process_message(private_responder_init_t *this, message_t *messa iterator_t *suggested_proposals, *accepted_proposals; proposal_substructure_t *accepted_proposal; - this->proposals->create_iterator(this->proposals, &accepted_proposals, FALSE); + accepted_proposals = this->proposals->create_iterator(this->proposals, FALSE); /* get the list of suggested proposals */ - sa_payload->create_proposal_substructure_iterator(sa_payload, &suggested_proposals, TRUE); + suggested_proposals = sa_payload->create_proposal_substructure_iterator(sa_payload, TRUE); /* now let the configuration-manager select a subset of the proposals */ status = global_configuration_manager->select_proposals_for_host(global_configuration_manager, @@ -395,7 +394,7 @@ static void build_sa_payload(private_responder_init_t *this, payload_t **payload this->logger->log(this->logger, CONTROL|MORE, "building sa payload"); - this->proposals->create_iterator(this->proposals, &proposal_iterator, FALSE); + proposal_iterator = this->proposals->create_iterator(this->proposals, FALSE); sa_payload = sa_payload_create(); @@ -405,7 +404,7 @@ static void build_sa_payload(private_responder_init_t *this, payload_t **payload proposal_substructure_t *current_proposal_clone; proposal_iterator->current(proposal_iterator,(void **) ¤t_proposal); - current_proposal->clone(current_proposal,¤t_proposal_clone); + current_proposal_clone = current_proposal->clone(current_proposal); sa_payload->add_proposal_substructure(sa_payload,current_proposal_clone); } diff --git a/Source/charon/testcases/linked_list_test.c b/Source/charon/testcases/linked_list_test.c index aa6d1d600..6dedb3184 100644 --- a/Source/charon/testcases/linked_list_test.c +++ b/Source/charon/testcases/linked_list_test.c @@ -105,7 +105,7 @@ void test_linked_list_iterator(tester_t *tester) iterator_t * iterator2; - linked_list->create_iterator(linked_list,&iterator,TRUE); + iterator = linked_list->create_iterator(linked_list,TRUE); tester->assert_true(tester,iterator->has_next(iterator), "it 1 has_next value check"); iterator->current(iterator,&value); @@ -115,7 +115,7 @@ void test_linked_list_iterator(tester_t *tester) iterator->current(iterator,&value); tester->assert_true(tester,(strcmp((char *) value,"four") == 0), "it 1 current value check"); - linked_list->create_iterator(linked_list,&iterator2,FALSE); + iterator2 = linked_list->create_iterator(linked_list,FALSE); tester->assert_true(tester,iterator2->has_next(iterator2), "it 2 has_next value check"); iterator2->current(iterator2,&value); @@ -170,7 +170,7 @@ void test_linked_list_insert_and_remove(tester_t *tester) - linked_list->create_iterator(linked_list,&iterator,TRUE); + iterator = linked_list->create_iterator(linked_list,TRUE); iterator->has_next(iterator); iterator->has_next(iterator); diff --git a/Source/charon/testcases/parser_test.c b/Source/charon/testcases/parser_test.c index 861eb556d..70560b25b 100644 --- a/Source/charon/testcases/parser_test.c +++ b/Source/charon/testcases/parser_test.c @@ -129,7 +129,7 @@ void test_parser_with_sa_payload(tester_t *tester) } - sa_payload->create_proposal_substructure_iterator(sa_payload, &proposals, TRUE); + proposals = sa_payload->create_proposal_substructure_iterator(sa_payload, TRUE); while (proposals->has_next(proposals)) { proposal_substructure_t *proposal; @@ -142,7 +142,7 @@ void test_parser_with_sa_payload(tester_t *tester) spi = proposal->get_spi(proposal); tester->assert_false(tester,(memcmp(&spi_should, spi.ptr, spi.len)),"proposal spi"); - proposal->create_transform_substructure_iterator(proposal, &transforms, TRUE); + transforms = proposal->create_transform_substructure_iterator(proposal, TRUE); while(transforms->has_next(transforms)) { transform_substructure_t *transform; @@ -150,7 +150,7 @@ void test_parser_with_sa_payload(tester_t *tester) transforms->current(transforms, (void**)&transform); tester->assert_true(tester,(transform->get_transform_type(transform) == 7),"transform type"); tester->assert_true(tester,(transform->get_transform_id(transform) == 3),"transform id"); - transform->create_transform_attribute_iterator(transform, &attributes, TRUE); + attributes = transform->create_transform_attribute_iterator(transform, TRUE); loopi = 0; while (attributes->has_next(attributes)) { diff --git a/Source/charon/utils/linked_list.c b/Source/charon/utils/linked_list.c index ca5dc60af..35599b33f 100644 --- a/Source/charon/utils/linked_list.c +++ b/Source/charon/utils/linked_list.c @@ -482,7 +482,7 @@ static status_t get_last(private_linked_list_t *this, void **item) /** * Implementation of linked_list_t.create_iterator. */ -static void create_iterator (private_linked_list_t *linked_list, iterator_t **iterator,bool forward) +static iterator_t *create_iterator (private_linked_list_t *linked_list,bool forward) { private_iterator_t *this = allocator_alloc_thing(private_iterator_t); @@ -498,7 +498,7 @@ static void create_iterator (private_linked_list_t *linked_list, iterator_t **it this->current = NULL; this->list = linked_list; - *iterator = &(this->public); + return &(this->public); } /** @@ -525,7 +525,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 = (void (*) (linked_list_t *linked_list, iterator_t **iterator,bool forward)) create_iterator; + this->public.create_iterator = (iterator_t * (*) (linked_list_t *linked_list,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 = (void (*) (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 e1b08511a..ee07ce487 100644 --- a/Source/charon/utils/linked_list.h +++ b/Source/charon/utils/linked_list.h @@ -51,13 +51,13 @@ struct linked_list_t { /** * @brief Creates a iterator for the given list. * - * @warning Created iterator has to get destroyed by the caller. + * @warning Created iterator_t object has to get destroyed by the caller. * * @param linked_list calling object - * @param[out] iterator place where the iterator is written * @param[in] forward iterator direction (TRUE: front to end) + * @return new iterator_t object */ - void (*create_iterator) (linked_list_t *linked_list, iterator_t **iterator, bool forward); + iterator_t * (*create_iterator) (linked_list_t *linked_list, bool forward); /** * @brief Inserts a new item at the beginning of the list. @@ -128,8 +128,6 @@ struct linked_list_t { * memory leaks! * * @param linked_list calling object - * @return - * - SUCCESS */ void (*destroy) (linked_list_t *linked_list); }; diff --git a/Source/charon/utils/logger_manager.c b/Source/charon/utils/logger_manager.c index 5c3a69547..d030d5cbe 100644 --- a/Source/charon/utils/logger_manager.c +++ b/Source/charon/utils/logger_manager.c @@ -205,7 +205,7 @@ static logger_level_t get_logger_level (private_logger_manager_t *this, logger_c pthread_mutex_lock(&(this->mutex)); - this->logger_levels->create_iterator(this->logger_levels, &iterator,TRUE); + iterator = this->logger_levels->create_iterator(this->logger_levels,TRUE); /* check for existing logger_level entry */ while (iterator->has_next(iterator)) { @@ -232,7 +232,7 @@ static void destroy_logger(private_logger_manager_t *this,logger_t *logger) pthread_mutex_lock(&(this->mutex)); - this->loggers->create_iterator(this->loggers,&iterator,TRUE); + iterator = this->loggers->create_iterator(this->loggers,TRUE); while (iterator->has_next(iterator)) { loggers_entry_t * entry; @@ -258,7 +258,7 @@ static void set_logger_level(private_logger_manager_t *this, logger_context_t co bool found = FALSE; pthread_mutex_lock(&(this->mutex)); - this->logger_levels->create_iterator(this->logger_levels,&iterator,TRUE); + iterator = this->logger_levels->create_iterator(this->logger_levels,TRUE); /* find existing logger_level entry */ while (iterator->has_next(iterator)) @@ -292,7 +292,7 @@ static void set_logger_level(private_logger_manager_t *this, logger_context_t co this->logger_levels->insert_last(this->logger_levels,entry); } - this->loggers->create_iterator(this->loggers,&iterator,TRUE); + iterator = this->loggers->create_iterator(this->loggers,TRUE); while (iterator->has_next(iterator)) { loggers_entry_t * entry; |