diff --git a/Source/charon/payloads/ike_header.c b/Source/charon/payloads/ike_header.c index 49f228f0b..3a1f23ff9 100644 --- a/Source/charon/payloads/ike_header.c +++ b/Source/charon/payloads/ike_header.c @@ -134,23 +134,14 @@ encoding_rule_t ike_header_encodings[] = { }; /** - * Implements ike_header_t's get_next_payload fuction. - * See #ike_header_t.get_next_payload for description. + * Implements payload_t's set_next_type function. + * See #payload_s.set_next_type for description. */ -static u_int8_t get_next_payload(private_ike_header_t *this) +static status_t set_next_type(payload_t *this,payload_type_t type) { - return this->next_payload; + ((private_ike_header_t *)this)->next_payload = type; + return SUCCESS; } - -/** - * Implements ike_header_t's set_next_payload fuction. - * See #ike_header_t.set_next_payload for description. - */ -static void set_next_payload(private_ike_header_t *this, u_int8_t next_payload) -{ - this->next_payload = next_payload; -} - /** * Implements ike_header_t's get_initiator_spi fuction. * See #ike_header_t.get_initiator_spi for description. @@ -350,13 +341,11 @@ ike_header_t *ike_header_create() this->public.payload_interface.get_encoding_rules = get_encoding_rules; this->public.payload_interface.get_length = get_length; this->public.payload_interface.get_next_type = get_next_type; + this->public.payload_interface.set_next_type = set_next_type; this->public.payload_interface.get_type = get_type; this->public.payload_interface.destroy = (status_t (*) (payload_t *))destroy; this->public.destroy = destroy; - - this->public.get_next_payload = (u_int8_t (*) (ike_header_t*))get_next_payload; - this->public.set_next_payload = (void (*) (ike_header_t*,u_int8_t))set_next_payload; this->public.get_initiator_spi = (u_int64_t (*) (ike_header_t*))get_initiator_spi; this->public.set_initiator_spi = (void (*) (ike_header_t*,u_int64_t))set_initiator_spi; this->public.get_responder_spi = (u_int64_t (*) (ike_header_t*))get_responder_spi; diff --git a/Source/charon/payloads/ike_header.h b/Source/charon/payloads/ike_header.h index aa1d8f983..76f0e793b 100644 --- a/Source/charon/payloads/ike_header.h +++ b/Source/charon/payloads/ike_header.h @@ -97,14 +97,6 @@ struct ike_header_s { */ payload_t payload_interface; - /** - * @brief get the next payload type - * - * @param this ike_header_t object - * @return next payload type - */ - u_int8_t (*get_next_payload) (ike_header_t *this); - /** * @brief set the next payload * diff --git a/Source/charon/payloads/payload.h b/Source/charon/payloads/payload.h index f7b36fcff..2995a1631 100644 --- a/Source/charon/payloads/payload.h +++ b/Source/charon/payloads/payload.h @@ -194,6 +194,15 @@ struct payload_s { * @return type of next payload */ payload_type_t (*get_next_type) (payload_t *this); + + /** + * @brief set type of next payload + * + * @param this calling object + * @param type type of next payload + * @return SUCCESS in any case + */ + status_t (*set_next_type) (payload_t *this,payload_type_t type); /** * @brief get length of payload diff --git a/Source/charon/payloads/proposal_substructure.c b/Source/charon/payloads/proposal_substructure.c index ce9e2047c..8947b7446 100644 --- a/Source/charon/payloads/proposal_substructure.c +++ b/Source/charon/payloads/proposal_substructure.c @@ -184,6 +184,15 @@ static payload_type_t get_next_type(private_proposal_substructure_t *this) return (this->next_payload); } +/** + * Implements payload_t's set_next_type function. + * See #payload_s.set_next_type for description. + */ +static status_t set_next_type(private_proposal_substructure_t *this,payload_type_t type) +{ + return SUCCESS; +} + /** * Implements payload_t's get_length function. * See #payload_s.get_length for description. @@ -349,6 +358,7 @@ proposal_substructure_t *proposal_substructure_create() this->public.payload_interface.get_encoding_rules = (status_t (*) (payload_t *, encoding_rule_t **, size_t *) ) get_encoding_rules; this->public.payload_interface.get_length = (size_t (*) (payload_t *)) get_length; this->public.payload_interface.get_next_type = (payload_type_t (*) (payload_t *)) get_next_type; + this->public.payload_interface.set_next_type = (status_t (*) (payload_t *,payload_type_t)) set_next_type; this->public.payload_interface.get_type = (payload_type_t (*) (payload_t *)) get_type; this->public.payload_interface.destroy = (status_t (*) (payload_t *))destroy; this->public.create_transform_substructure_iterator = (status_t (*) (proposal_substructure_t *,linked_list_iterator_t **,bool)) create_transform_substructure_iterator; diff --git a/Source/charon/payloads/sa_payload.c b/Source/charon/payloads/sa_payload.c index 34c75a25b..ab66e602e 100644 --- a/Source/charon/payloads/sa_payload.c +++ b/Source/charon/payloads/sa_payload.c @@ -64,6 +64,15 @@ struct private_sa_payload_s { * Proposals in this payload are stored in a linked_list_t */ linked_list_t * proposals; + + /** + * @brief Computes the length of this payload. + * + * @param this calling private_sa_payload_t object + * @return + * SUCCESS in any case + */ + status_t (*compute_length) (private_sa_payload_t *this); }; /** @@ -146,12 +155,23 @@ static payload_type_t get_next_type(private_sa_payload_t *this) return (this->next_payload); } +/** + * Implements payload_t's set_next_type function. + * See #payload_s.set_next_type for description. + */ +static status_t set_next_type(private_sa_payload_t *this,payload_type_t type) +{ + this->next_payload = type; + return SUCCESS; +} + /** * Implements payload_t's get_length function. * See #payload_s.get_length for description. */ static size_t get_length(private_sa_payload_t *this) { + this->compute_length(this); return this->payload_length; } @@ -170,7 +190,37 @@ static status_t create_proposal_substructure_iterator (private_sa_payload_t *thi */ static status_t add_proposal_substructure (private_sa_payload_t *this,proposal_substructure_t *proposal) { - return (this->proposals->insert_last(this->proposals,(void *) proposal)); + status_t status; + status = this->proposals->insert_last(this->proposals,(void *) proposal); + this->compute_length(this); + return status; +} + +/** + * Implements private_sa_payload_t's compute_length function. + * See #private_sa_payload_s.compute_length for description. + */ +static status_t compute_length (private_sa_payload_t *this) +{ + linked_list_iterator_t *iterator; + status_t status; + size_t length = SA_PAYLOAD_HEADER_LENGTH; + status = this->proposals->create_iterator(this->proposals,&iterator,TRUE); + if (status != SUCCESS) + { + return length; + } + while (iterator->has_next(iterator)) + { + payload_t *current_proposal; + iterator->current(iterator,(void **) ¤t_proposal); + length += current_proposal->get_length(current_proposal); + } + iterator->destroy(iterator); + + this->payload_length = length; + + return SUCCESS; } /* @@ -187,12 +237,16 @@ sa_payload_t *sa_payload_create() this->public.payload_interface.get_encoding_rules = (status_t (*) (payload_t *, encoding_rule_t **, size_t *) ) get_encoding_rules; this->public.payload_interface.get_length = (size_t (*) (payload_t *)) get_length; this->public.payload_interface.get_next_type = (payload_type_t (*) (payload_t *)) get_next_type; + this->public.payload_interface.set_next_type = (status_t (*) (payload_t *,payload_type_t)) set_next_type; this->public.payload_interface.get_type = (payload_type_t (*) (payload_t *)) get_type; this->public.payload_interface.destroy = (status_t (*) (payload_t *))destroy; this->public.create_proposal_substructure_iterator = (status_t (*) (sa_payload_t *,linked_list_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; + /* private functions */ + this->compute_length = compute_length; + /* set default values of the fields */ this->critical = SA_PAYLOAD_CRITICAL_FLAG; this->next_payload = NO_PAYLOAD; diff --git a/Source/charon/payloads/sa_payload.h b/Source/charon/payloads/sa_payload.h index 51f283473..f589a1046 100644 --- a/Source/charon/payloads/sa_payload.h +++ b/Source/charon/payloads/sa_payload.h @@ -59,6 +59,10 @@ struct sa_payload_s { * @brief Creates an iterator of stored proposal_substructure_t objects. * * @warning The created iterator has to get destroyed by the caller! + * + * @warning When deleting an proposal using this iterator, + * the length of this transform substructure has to be refreshed + * by calling get_length()! * * @param this calling sa_payload_t object * @param iterator the created iterator is stored at the pointed pointer diff --git a/Source/charon/payloads/transform_attribute.c b/Source/charon/payloads/transform_attribute.c index b3128e82e..3dc714e78 100644 --- a/Source/charon/payloads/transform_attribute.c +++ b/Source/charon/payloads/transform_attribute.c @@ -131,6 +131,15 @@ static payload_type_t get_next_type(private_transform_attribute_t *this) return (NO_PAYLOAD); } +/** + * Implements payload_t's set_next_type function. + * See #payload_s.set_next_type for description. + */ +static status_t set_next_type(private_transform_attribute_t *this,payload_type_t type) +{ + return SUCCESS; +} + /** * Implements payload_t's get_length function. * See #payload_s.get_length for description. @@ -233,6 +242,7 @@ transform_attribute_t *transform_attribute_create() this->public.payload_interface.get_encoding_rules = (status_t (*) (payload_t *, encoding_rule_t **, size_t *) ) get_encoding_rules; this->public.payload_interface.get_length = (size_t (*) (payload_t *)) get_length; this->public.payload_interface.get_next_type = (payload_type_t (*) (payload_t *)) get_next_type; + this->public.payload_interface.set_next_type = (status_t (*) (payload_t *,payload_type_t)) set_next_type; this->public.payload_interface.get_type = (payload_type_t (*) (payload_t *)) get_type; this->public.payload_interface.destroy = (status_t (*) (payload_t *))destroy; this->public.set_value = (status_t (*) (transform_attribute_t *,chunk_t value)) set_value; diff --git a/Source/charon/payloads/transform_substructure.c b/Source/charon/payloads/transform_substructure.c index 995f96ec7..bb7718a57 100644 --- a/Source/charon/payloads/transform_substructure.c +++ b/Source/charon/payloads/transform_substructure.c @@ -212,6 +212,15 @@ static bool get_is_last_transform (private_transform_substructure_t *this) return ((this->next_payload == TRANSFORM_TYPE_VALUE) ? FALSE : TRUE); } +/** + * Implements payload_t's set_next_type function. + * See #payload_s.set_next_type for description. + */ +static status_t set_next_type(private_transform_substructure_t *this,payload_type_t type) +{ + return SUCCESS; +} + /** * Implements transform_substructure_t's set_transform_type function. * See #transform_substructure_s.set_transform_type for description. @@ -271,6 +280,8 @@ static status_t compute_length (private_transform_substructure_t *this) length += current_attribute->get_length(current_attribute); } iterator->destroy(iterator); + + this->transform_length = length; return SUCCESS; } @@ -289,6 +300,7 @@ transform_substructure_t *transform_substructure_create() this->public.payload_interface.get_encoding_rules = (status_t (*) (payload_t *, encoding_rule_t **, size_t *) ) get_encoding_rules; this->public.payload_interface.get_length = (size_t (*) (payload_t *)) get_length; this->public.payload_interface.get_next_type = (payload_type_t (*) (payload_t *)) get_next_type; + this->public.payload_interface.set_next_type = (status_t (*) (payload_t *,payload_type_t)) set_next_type; this->public.payload_interface.get_type = (payload_type_t (*) (payload_t *)) get_type; this->public.payload_interface.destroy = (status_t (*) (payload_t *))destroy; this->public.create_transform_attribute_iterator = (status_t (*) (transform_substructure_t *,linked_list_iterator_t **,bool)) create_transform_attribute_iterator; diff --git a/Source/charon/payloads/transform_substructure.h b/Source/charon/payloads/transform_substructure.h index ba4988073..661c94fec 100644 --- a/Source/charon/payloads/transform_substructure.h +++ b/Source/charon/payloads/transform_substructure.h @@ -59,8 +59,9 @@ struct transform_substructure_s { * * @warning The created iterator has to get destroyed by the caller! * - * @warning When deleting an transform attribute, the length of this transform substructure - * has to be refreshed with get_length! + * @warning When deleting an transform attribute using this iterator, + * the length of this transform substructure has to be refreshed + * by calling get_length()! * * @param this calling transform_substructure_t object * @param iterator the created iterator is stored at the pointed pointer