- transform_substructure fully implemented

- generator now generates ransform_substructure and containing attributes
- test for transform substructure written
This commit is contained in:
Jan Hutter
2005-11-14 15:29:35 +00:00
parent f561c205e8
commit f3c01a28fe
6 changed files with 353 additions and 12 deletions
@@ -65,12 +65,12 @@ struct private_transform_substructure_s {
/**
* Transform ID
*/
u_int8_t transform_id;
u_int16_t transform_id;
/**
* Transforms Attributes are stored in a linked_list_t
*/
linked_list_t * attributes;
linked_list_t *attributes;
};
@@ -93,7 +93,7 @@ encoding_rule_t transform_substructure_encodings[] = {
/* Reserved Byte is skipped */
{ RESERVED_BYTE, 0 },
/* tranform ID is a number of 8 bit */
{ U_INT_8, offsetof(private_transform_substructure_t, transform_id) },
{ U_INT_16, offsetof(private_transform_substructure_t, transform_id) },
/* Attributes are stored in a transform attribute,
offset points to a linked_list_t pointer */
{ TRANSFORM_ATTRIBUTES, offsetof(private_transform_substructure_t, attributes) }
@@ -158,6 +158,21 @@ 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 **) &current_attribute);
length += current_attribute->get_length(current_attribute);
}
this->transform_length = length;
return this->transform_length;
}
@@ -177,8 +192,66 @@ 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));
return SUCCESS;
}
/**
* Implements transform_substructure_t's set_is_last_transform function.
* See #transform_substructure_s.set_is_last_transform for description.
*/
static status_t set_is_last_transform (private_transform_substructure_t *this, bool is_last)
{
this->next_payload = (is_last) ? 0 : TRANSFORM_TYPE_VALUE;
return SUCCESS;
}
/**
* Implements transform_substructure_t's get_is_last_transform function.
* See #transform_substructure_s.get_is_last_transform for description.
*/
static bool get_is_last_transform (private_transform_substructure_t *this)
{
return ((this->next_payload == TRANSFORM_TYPE_VALUE) ? FALSE : TRUE);
}
/**
* Implements transform_substructure_t's set_transform_type function.
* See #transform_substructure_s.set_transform_type for description.
*/
static status_t set_transform_type (private_transform_substructure_t *this,u_int8_t type)
{
this->transform_type = type;
return SUCCESS;
}
/**
* Implements transform_substructure_t's get_transform_type function.
* See #transform_substructure_s.get_transform_type for description.
*/
static u_int8_t get_transform_type (private_transform_substructure_t *this)
{
return this->transform_type;
}
/**
* Implements transform_substructure_t's set_transform_id function.
* See #transform_substructure_s.set_transform_id for description.
*/
static status_t set_transform_id (private_transform_substructure_t *this,u_int16_t id)
{
this->transform_id = id;
return SUCCESS;
}
/**
* Implements transform_substructure_t's get_transform_id function.
* See #transform_substructure_s.get_transform_id for description.
*/
static u_int16_t get_transform_id (private_transform_substructure_t *this)
{
return this->transform_id;
}
/*
* Described in header
@@ -198,11 +271,17 @@ transform_substructure_t *transform_substructure_create()
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;
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;
this->public.set_transform_type = (status_t (*) (transform_substructure_t *,u_int8_t)) set_transform_type;
this->public.get_transform_type = (u_int8_t (*) (transform_substructure_t *)) get_transform_type;
this->public.set_transform_id = (status_t (*) (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.destroy = (status_t (*) (transform_substructure_t *)) destroy;
/* set default values of the fields */
this->next_payload = NO_PAYLOAD;
this->transform_length = 0;
this->transform_length = TRANSFORM_SUBSTRUCTURE_HEADER_LENGTH;
this->transform_id = 0;
this->transform_type = 0;
@@ -30,6 +30,16 @@
#include "../utils/linked_list.h"
#include "transform_attribute.h"
/**
* IKEv1 Value for a transform payload
*/
#define TRANSFORM_TYPE_VALUE 3
/**
* Length of the transform substructure header in bytes
*/
#define TRANSFORM_SUBSTRUCTURE_HEADER_LENGTH 8
/**
* Object representing an IKEv2- TRANSFORM SUBSTRUCTURE
*
@@ -48,6 +58,9 @@ struct transform_substructure_s {
* @brief Creates an iterator of stored transform_attribute_t objects.
*
* @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!
*
* @param this calling transform_substructure_t object
* @param iterator the created iterator is stored at the pointed pointer
@@ -71,6 +84,60 @@ struct transform_substructure_s {
*/
status_t (*add_transform_attribute) (transform_substructure_t *this,transform_attribute_t *attribute);
/**
* @brief Sets the next_payload field of this substructure
*
* If this is the last transform, next payload field is set to 0,
* otherwise to 3 (payload type of transform in IKEv1)
*
* @param this calling transform_substructure_t object
* @param is_last When TRUE, next payload field is set to 0, otherwise to 3
* @return - SUCCESS
*/
status_t (*set_is_last_transform) (transform_substructure_t *this, bool is_last);
/**
* @brief Checks if this is the last transform.
*
* @param this calling transform_substructure_t object
* @return TRUE if this is the last Transform, FALSE otherwise
*/
bool (*get_is_last_transform) (transform_substructure_t *this);
/**
* @brief Sets transform type of the current transform substructure.
*
* @param this calling transform_substructure_t object
* @param type type value to set
* @return - SUCCESS
*/
status_t (*set_transform_type) (transform_substructure_t *this,u_int8_t type);
/**
* @brief get transform type of the current transform.
*
* @param this calling transform_substructure_t object
* @return Transform type of current transform substructure.
*/
u_int8_t (*get_transform_type) (transform_substructure_t *this);
/**
* @brief Sets transform id of the current transform substructure.
*
* @param this calling transform_substructure_t object
* @param id transform id to set
* @return - SUCCESS
*/
status_t (*set_transform_id) (transform_substructure_t *this,u_int16_t id);
/**
* @brief get transform id of the current transform.
*
* @param this calling transform_substructure_t object
* @return Transform id of current transform substructure.
*/
u_int16_t (*get_transform_id) (transform_substructure_t *this);
/**
* @brief Destroys an transform_substructure_t object.
*