diff options
author | Jan Hutter <jhutter@hsr.ch> | 2005-11-14 16:03:26 +0000 |
---|---|---|
committer | Jan Hutter <jhutter@hsr.ch> | 2005-11-14 16:03:26 +0000 |
commit | b3fd2b7207ed8ae037fc8d5bf24f948b042ef2f3 (patch) | |
tree | 5e923f7bcdc7d99969afdca410f6749c6d625b4e /Source | |
parent | f3c01a28fe461847662ed15ac4709752c93f7d66 (diff) | |
download | strongswan-b3fd2b7207ed8ae037fc8d5bf24f948b042ef2f3.tar.bz2 strongswan-b3fd2b7207ed8ae037fc8d5bf24f948b042ef2f3.tar.xz |
- compute_length written
Diffstat (limited to 'Source')
-rw-r--r-- | Source/charon/payloads/transform_attribute.c | 9 | ||||
-rw-r--r-- | Source/charon/payloads/transform_substructure.c | 53 |
2 files changed, 47 insertions, 15 deletions
diff --git a/Source/charon/payloads/transform_attribute.c b/Source/charon/payloads/transform_attribute.c index dfdd4072b..b3128e82e 100644 --- a/Source/charon/payloads/transform_attribute.c +++ b/Source/charon/payloads/transform_attribute.c @@ -150,6 +150,15 @@ static size_t get_length(private_transform_attribute_t *this) */ static status_t set_value (private_transform_attribute_t *this, chunk_t value) { + if (this->attribute_value.ptr != NULL) + { + /* free existing value */ + allocator_free(this->attribute_value.ptr); + this->attribute_value.ptr = NULL; + this->attribute_value.len = 0; + + } + if (value.len > 2) { this->attribute_value.ptr = allocator_clone_bytes(value.ptr,value.len); diff --git a/Source/charon/payloads/transform_substructure.c b/Source/charon/payloads/transform_substructure.c index 9313ff5d6..b8574e731 100644 --- a/Source/charon/payloads/transform_substructure.c +++ b/Source/charon/payloads/transform_substructure.c @@ -71,6 +71,15 @@ struct private_transform_substructure_s { * Transforms Attributes are stored in a linked_list_t */ linked_list_t *attributes; + + /** + * @brief Computes the length of this substructure. + * + * @param this calling private_transform_substructure_t object + * @return + * SUCCESS in any case + */ + status_t (*compute_length) (private_transform_substructure_t *this); }; @@ -158,20 +167,7 @@ static payload_type_t get_next_type(private_transform_substructure_t *this) */ static size_t get_length(private_transform_substructure_t *this) { - linked_list_iterator_t *iterator; - status_t status; - size_t length = TRANSFORM_SUBSTRUCTURE_HEADER_LENGTH; - status = this->attributes->create_iterator(this->attributes,&iterator,TRUE); - if (status != SUCCESS) - return length; - while (iterator->has_next(iterator)) - { - payload_t * current_attribute; - iterator->current(iterator,(void **) ¤t_attribute); - length += current_attribute->get_length(current_attribute); - } - - this->transform_length = length; + this->compute_length(this); return this->transform_length; } @@ -192,7 +188,7 @@ static status_t create_transform_attribute_iterator (private_transform_substruct static status_t add_transform_attribute (private_transform_substructure_t *this,transform_attribute_t *attribute) { return (this->attributes->insert_last(this->attributes,(void *) attribute)); - this->transform_length += ((payload_t *)this->attributes)->get_length(((payload_t *)this->attributes)); + this->compute_length(this); return SUCCESS; } @@ -253,6 +249,30 @@ static u_int16_t get_transform_id (private_transform_substructure_t *this) return this->transform_id; } +/** + * Implements private_transform_substructure_t's compute_length function. + * See #private_transform_substructure_s.compute_length for description. + */ +static status_t compute_length (private_transform_substructure_t *this) +{ + linked_list_iterator_t *iterator; + status_t status; + size_t length = TRANSFORM_SUBSTRUCTURE_HEADER_LENGTH; + status = this->attributes->create_iterator(this->attributes,&iterator,TRUE); + if (status != SUCCESS) + { + return length; + } + while (iterator->has_next(iterator)) + { + payload_t * current_attribute; + iterator->current(iterator,(void **) ¤t_attribute); + length += current_attribute->get_length(current_attribute); + } + + return SUCCESS; +} + /* * Described in header */ @@ -279,6 +299,9 @@ transform_substructure_t *transform_substructure_create() this->public.get_transform_id = (u_int16_t (*) (transform_substructure_t *)) get_transform_id; this->public.destroy = (status_t (*) (transform_substructure_t *)) destroy; + /* private functions */ + this->compute_length = compute_length; + /* set default values of the fields */ this->next_payload = NO_PAYLOAD; this->transform_length = TRANSFORM_SUBSTRUCTURE_HEADER_LENGTH; |