diff options
author | Martin Willi <martin@strongswan.org> | 2006-10-24 14:20:45 +0000 |
---|---|---|
committer | Martin Willi <martin@strongswan.org> | 2006-10-24 14:20:45 +0000 |
commit | 191a26a6a713e81361bd677bb0297744f03e4f36 (patch) | |
tree | 95bbdbc6be919e5748ddcab93d985592f264e593 /src/charon/encoding/payloads | |
parent | 55bbff11ec96f74b27afc36dd8ca3e34ff425b40 (diff) | |
download | strongswan-191a26a6a713e81361bd677bb0297744f03e4f36.tar.bz2 strongswan-191a26a6a713e81361bd677bb0297744f03e4f36.tar.xz |
removed deprecated iterator methods (has_next & current)
added iterator hook to manipulate iterator the clean way
Diffstat (limited to 'src/charon/encoding/payloads')
-rw-r--r-- | src/charon/encoding/payloads/cp_payload.c | 17 | ||||
-rw-r--r-- | src/charon/encoding/payloads/encryption_payload.c | 11 | ||||
-rw-r--r-- | src/charon/encoding/payloads/proposal_substructure.c | 86 | ||||
-rw-r--r-- | src/charon/encoding/payloads/sa_payload.c | 23 | ||||
-rw-r--r-- | src/charon/encoding/payloads/transform_substructure.c | 52 | ||||
-rw-r--r-- | src/charon/encoding/payloads/ts_payload.c | 21 |
6 files changed, 83 insertions, 127 deletions
diff --git a/src/charon/encoding/payloads/cp_payload.c b/src/charon/encoding/payloads/cp_payload.c index 580a0c64a..bd16abc22 100644 --- a/src/charon/encoding/payloads/cp_payload.c +++ b/src/charon/encoding/payloads/cp_payload.c @@ -125,20 +125,17 @@ static status_t verify(private_cp_payload_t *this) { status_t status = SUCCESS; iterator_t *iterator; - - iterator = this->attributes->create_iterator(this->attributes,TRUE); + configuration_attribute_t *attribute; - while(iterator->has_next(iterator)) + iterator = this->attributes->create_iterator(this->attributes,TRUE); + while(iterator->iterate(iterator, (void**)&attribute)) { - configuration_attribute_t *attribute; - iterator->current(iterator,(void **)&attribute); - status = attribute->payload_interface.verify(&(attribute->payload_interface)); + status = attribute->payload_interface.verify(&attribute->payload_interface); if (status != SUCCESS) { break; } } - iterator->destroy(iterator); return status; } @@ -182,12 +179,12 @@ static void set_next_type(private_cp_payload_t *this,payload_type_t type) static void compute_length(private_cp_payload_t *this) { iterator_t *iterator; + payload_t *current_attribute; size_t length = CP_PAYLOAD_HEADER_LENGTH; + iterator = this->attributes->create_iterator(this->attributes,TRUE); - while (iterator->has_next(iterator)) + while (iterator->iterate(iterator, (void**)¤t_attribute)) { - payload_t *current_attribute; - iterator->current(iterator,(void **) ¤t_attribute); length += current_attribute->get_length(current_attribute); } iterator->destroy(iterator); diff --git a/src/charon/encoding/payloads/encryption_payload.c b/src/charon/encoding/payloads/encryption_payload.c index c33bea781..bec94d620 100644 --- a/src/charon/encoding/payloads/encryption_payload.c +++ b/src/charon/encoding/payloads/encryption_payload.c @@ -188,14 +188,13 @@ static void set_next_type(private_encryption_payload_t *this, payload_type_t typ static void compute_length(private_encryption_payload_t *this) { iterator_t *iterator; + payload_t *current_payload; size_t block_size, length = 0; iterator = this->payloads->create_iterator(this->payloads, TRUE); /* count payload length */ - while (iterator->has_next(iterator)) + while (iterator->iterate(iterator, (void **) ¤t_payload)) { - payload_t *current_payload; - iterator->current(iterator, (void **) ¤t_payload); length += current_payload->get_length(current_payload); } iterator->destroy(iterator); @@ -285,9 +284,8 @@ static void generate(private_encryption_payload_t *this) iterator = this->payloads->create_iterator(this->payloads, TRUE); /* get first payload */ - if (iterator->has_next(iterator)) + if (iterator->iterate(iterator, (void**)¤t_payload)) { - iterator->current(iterator, (void**)¤t_payload); this->next_payload = current_payload->get_type(current_payload); } else @@ -303,9 +301,8 @@ static void generate(private_encryption_payload_t *this) generator = generator_create(); /* build all payload, except last */ - while(iterator->has_next(iterator)) + while(iterator->iterate(iterator, (void**)&next_payload)) { - iterator->current(iterator, (void**)&next_payload); current_payload->set_next_type(current_payload, next_payload->get_type(next_payload)); generator->generate_payload(generator, current_payload); current_payload = next_payload; diff --git a/src/charon/encoding/payloads/proposal_substructure.c b/src/charon/encoding/payloads/proposal_substructure.c index 5842f6e8b..3351c8a14 100644 --- a/src/charon/encoding/payloads/proposal_substructure.c +++ b/src/charon/encoding/payloads/proposal_substructure.c @@ -142,6 +142,7 @@ static status_t verify(private_proposal_substructure_t *this) { status_t status = SUCCESS; iterator_t *iterator; + payload_t *current_transform; if ((this->next_payload != NO_PAYLOAD) && (this->next_payload != 2)) { @@ -186,11 +187,8 @@ static status_t verify(private_proposal_substructure_t *this) } iterator = this->transforms->create_iterator(this->transforms,TRUE); - while(iterator->has_next(iterator)) + while(iterator->iterate(iterator, (void**)¤t_transform)) { - payload_t *current_transform; - iterator->current(iterator,(void **)¤t_transform); - status = current_transform->verify(current_transform); if (status != SUCCESS) { @@ -242,13 +240,13 @@ static void set_next_type(private_proposal_substructure_t *this,payload_type_t t static void compute_length(private_proposal_substructure_t *this) { iterator_t *iterator; + payload_t *current_transform; size_t transforms_count = 0; size_t length = PROPOSAL_SUBSTRUCTURE_HEADER_LENGTH; + iterator = this->transforms->create_iterator(this->transforms,TRUE); - while (iterator->has_next(iterator)) + while (iterator->iterate(iterator, (void**)¤t_transform)) { - payload_t * current_transform; - iterator->current(iterator,(void **) ¤t_transform); length += current_transform->get_length(current_transform); transforms_count++; } @@ -390,21 +388,19 @@ static size_t get_spi_size (private_proposal_substructure_t *this) proposal_t* get_proposal(private_proposal_substructure_t *this) { iterator_t *iterator; + transform_substructure_t *transform; proposal_t *proposal; u_int64_t spi; proposal = proposal_create(this->protocol_id); iterator = this->transforms->create_iterator(this->transforms, TRUE); - while (iterator->has_next(iterator)) + while (iterator->iterate(iterator, (void**)&transform)) { - transform_substructure_t *transform; transform_type_t transform_type; u_int16_t transform_id; u_int16_t key_length = 0; - iterator->current(iterator, (void**)&transform); - transform_type = transform->get_transform_type(transform); transform_id = transform->get_transform_id(transform); transform->get_key_length(transform, &key_length); @@ -434,38 +430,30 @@ proposal_t* get_proposal(private_proposal_substructure_t *this) */ static private_proposal_substructure_t* clone_(private_proposal_substructure_t *this) { - private_proposal_substructure_t * new_clone; + private_proposal_substructure_t *clone; iterator_t *transforms; + transform_substructure_t *current_transform; - new_clone = (private_proposal_substructure_t *) proposal_substructure_create(); - - new_clone->next_payload = this->next_payload; - new_clone->proposal_number = this->proposal_number; - new_clone->protocol_id = this->protocol_id; - new_clone->spi_size = this->spi_size; + clone = (private_proposal_substructure_t *) proposal_substructure_create(); + clone->next_payload = this->next_payload; + clone->proposal_number = this->proposal_number; + clone->protocol_id = this->protocol_id; + clone->spi_size = this->spi_size; if (this->spi.ptr != NULL) { - new_clone->spi.ptr = clalloc(this->spi.ptr,this->spi.len); - new_clone->spi.len = this->spi.len; + clone->spi.ptr = clalloc(this->spi.ptr,this->spi.len); + clone->spi.len = this->spi.len; } transforms = this->transforms->create_iterator(this->transforms,FALSE); - - while (transforms->has_next(transforms)) + while (transforms->iterate(transforms, (void**)¤t_transform)) { - transform_substructure_t *current_transform; - transform_substructure_t *current_transform_clone; - - transforms->current(transforms,(void **) ¤t_transform); - - current_transform_clone = current_transform->clone(current_transform); - - new_clone->public.add_transform_substructure(&(new_clone->public),current_transform_clone); + current_transform = current_transform->clone(current_transform); + clone->public.add_transform_substructure(&clone->public, current_transform); } - transforms->destroy(transforms); - return new_clone; + return clone; } /** @@ -533,49 +521,46 @@ proposal_substructure_t *proposal_substructure_create() */ proposal_substructure_t *proposal_substructure_create_from_proposal(proposal_t *proposal) { - private_proposal_substructure_t *this = (private_proposal_substructure_t*)proposal_substructure_create(); + private_proposal_substructure_t *this = (private_proposal_substructure_t*) + proposal_substructure_create(); iterator_t *iterator; algorithm_t *algo; transform_substructure_t *transform; /* encryption algorithm is only availble in ESP */ iterator = proposal->create_algorithm_iterator(proposal, ENCRYPTION_ALGORITHM); - while (iterator->has_next(iterator)) + while (iterator->iterate(iterator, (void**)&algo)) { - iterator->current(iterator, (void**)&algo); - transform = transform_substructure_create_type(ENCRYPTION_ALGORITHM, algo->algorithm, algo->key_size); + transform = transform_substructure_create_type(ENCRYPTION_ALGORITHM, + algo->algorithm, algo->key_size); this->public.add_transform_substructure(&(this->public), transform); } iterator->destroy(iterator); /* integrity algorithms */ iterator = proposal->create_algorithm_iterator(proposal, INTEGRITY_ALGORITHM); - while (iterator->has_next(iterator)) + while (iterator->iterate(iterator, (void**)&algo)) { - algorithm_t *algo; - iterator->current(iterator, (void**)&algo); - transform = transform_substructure_create_type(INTEGRITY_ALGORITHM, algo->algorithm, algo->key_size); + transform = transform_substructure_create_type(INTEGRITY_ALGORITHM, + algo->algorithm, algo->key_size); this->public.add_transform_substructure(&(this->public), transform); } iterator->destroy(iterator); /* prf algorithms */ iterator = proposal->create_algorithm_iterator(proposal, PSEUDO_RANDOM_FUNCTION); - while (iterator->has_next(iterator)) + while (iterator->iterate(iterator, (void**)&algo)) { - algorithm_t *algo; - iterator->current(iterator, (void**)&algo); - transform = transform_substructure_create_type(PSEUDO_RANDOM_FUNCTION, algo->algorithm, algo->key_size); + transform = transform_substructure_create_type(PSEUDO_RANDOM_FUNCTION, + algo->algorithm, algo->key_size); this->public.add_transform_substructure(&(this->public), transform); } iterator->destroy(iterator); /* dh groups */ iterator = proposal->create_algorithm_iterator(proposal, DIFFIE_HELLMAN_GROUP); - while (iterator->has_next(iterator)) + while (iterator->iterate(iterator, (void**)&algo)) { - algorithm_t *algo; - iterator->current(iterator, (void**)&algo); transform = transform_substructure_create_type(DIFFIE_HELLMAN_GROUP, algo->algorithm, 0); this->public.add_transform_substructure(&(this->public), transform); } @@ -583,11 +568,10 @@ proposal_substructure_t *proposal_substructure_create_from_proposal(proposal_t * /* extended sequence numbers */ iterator = proposal->create_algorithm_iterator(proposal, EXTENDED_SEQUENCE_NUMBERS); - while (iterator->has_next(iterator)) + while (iterator->iterate(iterator, (void**)&algo)) { - algorithm_t *algo; - iterator->current(iterator, (void**)&algo); - transform = transform_substructure_create_type(EXTENDED_SEQUENCE_NUMBERS, algo->algorithm, 0); + transform = transform_substructure_create_type(EXTENDED_SEQUENCE_NUMBERS, + algo->algorithm, 0); this->public.add_transform_substructure(&(this->public), transform); } iterator->destroy(iterator); diff --git a/src/charon/encoding/payloads/sa_payload.c b/src/charon/encoding/payloads/sa_payload.c index f0a13eb58..751e83297 100644 --- a/src/charon/encoding/payloads/sa_payload.c +++ b/src/charon/encoding/payloads/sa_payload.c @@ -110,19 +110,18 @@ static status_t verify(private_sa_payload_t *this) int expected_number = 1, current_number; status_t status = SUCCESS; iterator_t *iterator; + proposal_substructure_t *current_proposal; bool first = TRUE; - /* check proposal numbering */ + /* check proposal numbering */ iterator = this->proposals->create_iterator(this->proposals,TRUE); - while(iterator->has_next(iterator)) + while(iterator->iterate(iterator, (void**)¤t_proposal)) { - proposal_substructure_t *current_proposal; - iterator->current(iterator,(void **)¤t_proposal); current_number = current_proposal->get_proposal_number(current_proposal); if (current_number > expected_number) { - if (first) + if (first) { DBG1(SIG_DBG_ENC, "first proposal is not proposal #1"); status = FAILED; @@ -210,12 +209,12 @@ static void set_next_type(private_sa_payload_t *this,payload_type_t type) static void compute_length (private_sa_payload_t *this) { iterator_t *iterator; + payload_t *current_proposal; size_t length = SA_PAYLOAD_HEADER_LENGTH; + iterator = this->proposals->create_iterator(this->proposals,TRUE); - while (iterator->has_next(iterator)) + while (iterator->iterate(iterator, (void **)¤t_proposal)) { - payload_t *current_proposal; - iterator->current(iterator,(void **) ¤t_proposal); length += current_proposal->get_length(current_proposal); } iterator->destroy(iterator); @@ -280,6 +279,7 @@ static linked_list_t *get_proposals(private_sa_payload_t *this) int struct_number = 0; int ignore_struct_number = 0; iterator_t *iterator; + proposal_substructure_t *proposal_struct; linked_list_t *proposal_list; /* this list will hold our proposals */ @@ -291,12 +291,10 @@ static linked_list_t *get_proposals(private_sa_payload_t *this) * protocols. */ iterator = this->proposals->create_iterator(this->proposals, TRUE); - while (iterator->has_next(iterator)) + while (iterator->iterate(iterator, (void **)&proposal_struct)) { proposal_t *proposal; - proposal_substructure_t *proposal_struct; - iterator->current(iterator, (void **)&proposal_struct); /* check if a proposal has a single protocol */ if (proposal_struct->get_proposal_number(proposal_struct) == struct_number) { @@ -362,9 +360,8 @@ sa_payload_t *sa_payload_create_from_proposal_list(linked_list_t *proposals) /* add every payload from the list */ iterator = proposals->create_iterator(proposals, TRUE); - while (iterator->has_next(iterator)) + while (iterator->iterate(iterator, (void**)&proposal)) { - iterator->current(iterator, (void**)&proposal); add_proposal((private_sa_payload_t*)sa_payload, proposal); } iterator->destroy(iterator); diff --git a/src/charon/encoding/payloads/transform_substructure.c b/src/charon/encoding/payloads/transform_substructure.c index 944336cc7..f165507df 100644 --- a/src/charon/encoding/payloads/transform_substructure.c +++ b/src/charon/encoding/payloads/transform_substructure.c @@ -120,6 +120,7 @@ static status_t verify(private_transform_substructure_t *this) { status_t status = SUCCESS; iterator_t *iterator; + payload_t *current_attributes; if ((this->next_payload != NO_PAYLOAD) && (this->next_payload != 3)) { @@ -146,11 +147,8 @@ static status_t verify(private_transform_substructure_t *this) } iterator = this->attributes->create_iterator(this->attributes,TRUE); - while(iterator->has_next(iterator)) + while(iterator->iterate(iterator, (void**)¤t_attributes)) { - payload_t *current_attributes; - iterator->current(iterator,(void **)¤t_attributes); - status = current_attributes->verify(current_attributes); if (status != SUCCESS) { @@ -194,12 +192,12 @@ static payload_type_t get_next_type(private_transform_substructure_t *this) static void compute_length (private_transform_substructure_t *this) { iterator_t *iterator; + payload_t *current_attribute; size_t length = TRANSFORM_SUBSTRUCTURE_HEADER_LENGTH; + iterator = this->attributes->create_iterator(this->attributes,TRUE); - while (iterator->has_next(iterator)) + while (iterator->iterate(iterator, (void**)¤t_attribute)) { - payload_t * current_attribute; - iterator->current(iterator,(void **) ¤t_attribute); length += current_attribute->get_length(current_attribute); } iterator->destroy(iterator); @@ -293,31 +291,24 @@ static u_int16_t get_transform_id (private_transform_substructure_t *this) */ static transform_substructure_t *clone_(private_transform_substructure_t *this) { - private_transform_substructure_t *new_clone; + private_transform_substructure_t *clone; iterator_t *attributes; + transform_attribute_t *current_attribute; - new_clone = (private_transform_substructure_t *) transform_substructure_create(); + clone = (private_transform_substructure_t *) transform_substructure_create(); + clone->next_payload = this->next_payload; + clone->transform_type = this->transform_type; + clone->transform_id = this->transform_id; - new_clone->next_payload = this->next_payload; - new_clone->transform_type = this->transform_type; - new_clone->transform_id = this->transform_id; - - attributes = this->attributes->create_iterator(this->attributes,FALSE); - - while (attributes->has_next(attributes)) + attributes = this->attributes->create_iterator(this->attributes, FALSE); + while (attributes->iterate(attributes, (void**)¤t_attribute)) { - transform_attribute_t *current_attribute; - transform_attribute_t *current_attribute_clone; - attributes->current(attributes,(void **) ¤t_attribute); - - current_attribute_clone = current_attribute->clone(current_attribute); - - new_clone->public.add_transform_attribute(&(new_clone->public),current_attribute_clone); + current_attribute = current_attribute->clone(current_attribute); + clone->public.add_transform_attribute(&clone->public, current_attribute); } - attributes->destroy(attributes); - return &(new_clone->public); + return &clone->public; } @@ -327,24 +318,19 @@ static transform_substructure_t *clone_(private_transform_substructure_t *this) static status_t get_key_length(private_transform_substructure_t *this, u_int16_t *key_length) { iterator_t *attributes; + transform_attribute_t *current_attribute; - attributes = this->attributes->create_iterator(this->attributes,TRUE); - - while (attributes->has_next(attributes)) + attributes = this->attributes->create_iterator(this->attributes, TRUE); + while (attributes->iterate(attributes, (void**)¤t_attribute)) { - transform_attribute_t *current_attribute; - attributes->current(attributes,(void **) ¤t_attribute); - if (current_attribute->get_attribute_type(current_attribute) == KEY_LENGTH) { *key_length = current_attribute->get_value(current_attribute); attributes->destroy(attributes); return SUCCESS; } - } attributes->destroy(attributes); - return FAILED; } diff --git a/src/charon/encoding/payloads/ts_payload.c b/src/charon/encoding/payloads/ts_payload.c index cce2fc282..ae89919f6 100644 --- a/src/charon/encoding/payloads/ts_payload.c +++ b/src/charon/encoding/payloads/ts_payload.c @@ -123,6 +123,7 @@ encoding_rule_t ts_payload_encodings[] = { static status_t verify(private_ts_payload_t *this) { iterator_t *iterator; + payload_t *current_traffic_selector; status_t status = SUCCESS; if (this->number_of_traffic_selectors != (this->traffic_selectors->get_count(this->traffic_selectors))) @@ -132,11 +133,8 @@ static status_t verify(private_ts_payload_t *this) } iterator = this->traffic_selectors->create_iterator(this->traffic_selectors,TRUE); - while(iterator->has_next(iterator)) + while(iterator->iterate(iterator, (void**)¤t_traffic_selector)) { - payload_t *current_traffic_selector; - iterator->current(iterator,(void **)¤t_traffic_selector); - status = current_traffic_selector->verify(current_traffic_selector); if (status != SUCCESS) { @@ -196,11 +194,11 @@ static void compute_length (private_ts_payload_t *this) iterator_t *iterator; size_t ts_count = 0; size_t length = TS_PAYLOAD_HEADER_LENGTH; + payload_t *current_traffic_selector; + iterator = this->traffic_selectors->create_iterator(this->traffic_selectors,TRUE); - while (iterator->has_next(iterator)) + while (iterator->iterate(iterator, (void**)¤t_traffic_selector)) { - payload_t * current_traffic_selector; - iterator->current(iterator,(void **) ¤t_traffic_selector); length += current_traffic_selector->get_length(current_traffic_selector); ts_count++; } @@ -208,7 +206,6 @@ static void compute_length (private_ts_payload_t *this) this->number_of_traffic_selectors= ts_count; this->payload_length = length; - } /** @@ -260,13 +257,12 @@ static linked_list_t *get_traffic_selectors(private_ts_payload_t *this) { traffic_selector_t *ts; iterator_t *iterator; + traffic_selector_substructure_t *ts_substructure; linked_list_t *ts_list = linked_list_create(); iterator = this->traffic_selectors->create_iterator(this->traffic_selectors, TRUE); - while (iterator->has_next(iterator)) + while (iterator->iterate(iterator, (void**)&ts_substructure)) { - traffic_selector_substructure_t *ts_substructure; - iterator->current(iterator, (void**)&ts_substructure); ts = ts_substructure->get_traffic_selector(ts_substructure); ts_list->insert_last(ts_list, (void*)ts); } @@ -333,9 +329,8 @@ ts_payload_t *ts_payload_create_from_traffic_selectors(bool is_initiator, linked this = (private_ts_payload_t*)ts_payload_create(is_initiator); iterator = traffic_selectors->create_iterator(traffic_selectors, TRUE); - while (iterator->has_next(iterator)) + while (iterator->iterate(iterator, (void**)&ts)) { - iterator->current(iterator, (void**)&ts); ts_substructure = traffic_selector_substructure_create_from_traffic_selector(ts); this->public.add_traffic_selector_substructure(&(this->public), ts_substructure); } |