- added clone functionality
This commit is contained in:
@@ -169,34 +169,6 @@ static status_t verify(private_proposal_substructure_t *this)
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements payload_t's and proposal_substructure_t's destroy function.
|
||||
* See #payload_s.destroy or proposal_substructure_s.destroy for description.
|
||||
*/
|
||||
static status_t destroy(private_proposal_substructure_t *this)
|
||||
{
|
||||
/* all proposals are getting destroyed */
|
||||
while (this->transforms->get_count(this->transforms) > 0)
|
||||
{
|
||||
transform_substructure_t *current_transform;
|
||||
if (this->transforms->remove_last(this->transforms,(void **)¤t_transform) != SUCCESS)
|
||||
{
|
||||
break;
|
||||
}
|
||||
current_transform->destroy(current_transform);
|
||||
}
|
||||
this->transforms->destroy(this->transforms);
|
||||
|
||||
if (this->spi.ptr != NULL)
|
||||
{
|
||||
allocator_free(this->spi.ptr);
|
||||
}
|
||||
|
||||
allocator_free(this);
|
||||
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements payload_t's get_encoding_rules function.
|
||||
* See #payload_s.get_encoding_rules for description.
|
||||
@@ -386,6 +358,103 @@ static status_t compute_length (private_proposal_substructure_t *this)
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements proposal_substructure_t's clone function.
|
||||
* See #proposal_substructure_s.clone for description.
|
||||
*/
|
||||
static status_t clone(private_proposal_substructure_t *this, private_proposal_substructure_t **clone)
|
||||
{
|
||||
private_proposal_substructure_t * new_clone;
|
||||
linked_list_iterator_t *transforms;
|
||||
status_t status;
|
||||
|
||||
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;
|
||||
if (this->spi.ptr != NULL)
|
||||
{
|
||||
new_clone->spi.ptr = allocator_clone_bytes(this->spi.ptr,this->spi.len);
|
||||
if (new_clone->spi.ptr == NULL)
|
||||
{
|
||||
new_clone->public.destroy(&(new_clone->public));
|
||||
return OUT_OF_RES;
|
||||
}
|
||||
new_clone->spi.len = this->spi.len;
|
||||
}
|
||||
|
||||
status = this->transforms->create_iterator(this->transforms,&transforms,FALSE);
|
||||
if (status != SUCCESS)
|
||||
{
|
||||
new_clone->public.destroy(&(new_clone->public));
|
||||
return status;
|
||||
}
|
||||
|
||||
while (transforms->has_next(transforms))
|
||||
{
|
||||
transform_substructure_t *current_transform;
|
||||
transform_substructure_t *current_transform_clone;
|
||||
status = transforms->current(transforms,(void **) ¤t_transform);
|
||||
if (status != SUCCESS)
|
||||
{
|
||||
transforms->destroy(transforms);
|
||||
new_clone->public.destroy(&(new_clone->public));
|
||||
return status;
|
||||
}
|
||||
status = current_transform->clone(current_transform,¤t_transform_clone);
|
||||
if (status != SUCCESS)
|
||||
{
|
||||
transforms->destroy(transforms);
|
||||
new_clone->public.destroy(&(new_clone->public));
|
||||
return status;
|
||||
}
|
||||
|
||||
status = new_clone->public.add_transform_substructure(&(new_clone->public),current_transform_clone);
|
||||
if (status != SUCCESS)
|
||||
{
|
||||
transforms->destroy(transforms);
|
||||
current_transform_clone->destroy(current_transform_clone);
|
||||
new_clone->public.destroy(&(new_clone->public));
|
||||
return status;
|
||||
}
|
||||
}
|
||||
|
||||
transforms->destroy(transforms);
|
||||
|
||||
*clone = new_clone;
|
||||
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements payload_t's and proposal_substructure_t's destroy function.
|
||||
* See #payload_s.destroy or proposal_substructure_s.destroy for description.
|
||||
*/
|
||||
static status_t destroy(private_proposal_substructure_t *this)
|
||||
{
|
||||
/* all proposals are getting destroyed */
|
||||
while (this->transforms->get_count(this->transforms) > 0)
|
||||
{
|
||||
transform_substructure_t *current_transform;
|
||||
if (this->transforms->remove_last(this->transforms,(void **)¤t_transform) != SUCCESS)
|
||||
{
|
||||
break;
|
||||
}
|
||||
current_transform->destroy(current_transform);
|
||||
}
|
||||
this->transforms->destroy(this->transforms);
|
||||
|
||||
if (this->spi.ptr != NULL)
|
||||
{
|
||||
allocator_free(this->spi.ptr);
|
||||
}
|
||||
|
||||
allocator_free(this);
|
||||
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
/*
|
||||
* Described in header
|
||||
@@ -416,6 +485,7 @@ proposal_substructure_t *proposal_substructure_create()
|
||||
this->public.get_protocol_id = (u_int8_t (*) (proposal_substructure_t *)) get_protocol_id;
|
||||
this->public.set_spi = (status_t (*) (proposal_substructure_t *,chunk_t))set_spi;
|
||||
this->public.get_spi = (chunk_t (*) (proposal_substructure_t *)) get_spi;
|
||||
this->public.clone = (status_t (*) (proposal_substructure_t *, proposal_substructure_t **)) clone;
|
||||
this->public.destroy = (status_t (*) (proposal_substructure_t *)) destroy;
|
||||
|
||||
/* private functions */
|
||||
|
||||
@@ -150,6 +150,17 @@ struct proposal_substructure_s {
|
||||
*/
|
||||
status_t (*set_spi) (proposal_substructure_t *this, chunk_t spi);
|
||||
|
||||
/**
|
||||
* @brief Clones an proposal_substructure_t object.
|
||||
*
|
||||
* @param this proposal_substructure_t object to clone
|
||||
* @param clone cloned object will be written there
|
||||
* @return
|
||||
* - SUCCESS
|
||||
* - OUT_OF_RES
|
||||
*/
|
||||
status_t (*clone) (proposal_substructure_t *this,proposal_substructure_t **clone);
|
||||
|
||||
/**
|
||||
* @brief Destroys an proposal_substructure_t object.
|
||||
*
|
||||
|
||||
@@ -122,21 +122,6 @@ static status_t verify(private_transform_attribute_t *this)
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements payload_t's and transform_attribute_t's destroy function.
|
||||
* See #payload_s.destroy or transform_attribute_s.destroy for description.
|
||||
*/
|
||||
static status_t destroy(private_transform_attribute_t *this)
|
||||
{
|
||||
if (this->attribute_value.ptr != NULL)
|
||||
{
|
||||
allocator_free(this->attribute_value.ptr);
|
||||
}
|
||||
allocator_free(this);
|
||||
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements payload_t's get_encoding_rules function.
|
||||
* See #payload_s.get_encoding_rules for description.
|
||||
@@ -292,6 +277,50 @@ static u_int16_t get_attribute_type (private_transform_attribute_t *this)
|
||||
return this->attribute_type;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements transform_attribute_t's clone function.
|
||||
* See transform_attribute_s.clone for description.
|
||||
*/
|
||||
static status_t clone(private_transform_attribute_t *this,transform_attribute_t **clone)
|
||||
{
|
||||
private_transform_attribute_t *new_clone;
|
||||
|
||||
new_clone = (private_transform_attribute_t *) transform_attribute_create();
|
||||
|
||||
new_clone->attribute_format = this->attribute_format;
|
||||
new_clone->attribute_type = this->attribute_type;
|
||||
new_clone->attribute_length_or_value = this->attribute_length_or_value;
|
||||
|
||||
if (!new_clone->attribute_format)
|
||||
{
|
||||
new_clone->attribute_value.ptr = allocator_clone_bytes(this->attribute_value.ptr,this->attribute_value.len);
|
||||
new_clone->attribute_value.len = this->attribute_value.len;
|
||||
if (new_clone->attribute_value.ptr == NULL)
|
||||
{
|
||||
new_clone->public.destroy(&(new_clone->public));
|
||||
return OUT_OF_RES;
|
||||
}
|
||||
}
|
||||
|
||||
*clone = (transform_attribute_t *) new_clone;
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements payload_t's and transform_attribute_t's destroy function.
|
||||
* See #payload_s.destroy or transform_attribute_s.destroy for description.
|
||||
*/
|
||||
static status_t destroy(private_transform_attribute_t *this)
|
||||
{
|
||||
if (this->attribute_value.ptr != NULL)
|
||||
{
|
||||
allocator_free(this->attribute_value.ptr);
|
||||
}
|
||||
allocator_free(this);
|
||||
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
/*
|
||||
* Described in header
|
||||
*/
|
||||
@@ -319,6 +348,7 @@ transform_attribute_t *transform_attribute_create()
|
||||
this->public.get_value = (u_int16_t (*) (transform_attribute_t *)) get_value;
|
||||
this->public.set_attribute_type = (status_t (*) (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 = (status_t (*) (transform_attribute_t *,transform_attribute_t **)) clone;
|
||||
this->public.destroy = (status_t (*) (transform_attribute_t *)) destroy;
|
||||
|
||||
/* set default values of the fields */
|
||||
|
||||
@@ -119,6 +119,17 @@ struct transform_attribute_s {
|
||||
*/
|
||||
u_int16_t (*get_attribute_type) (transform_attribute_t *this);
|
||||
|
||||
/**
|
||||
* @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
|
||||
* - OUT_OF_RES
|
||||
* - SUCCESS
|
||||
*/
|
||||
status_t (*clone) (transform_attribute_t *this,transform_attribute_t **clone);
|
||||
|
||||
/**
|
||||
* @brief Destroys an transform_attribute_t object.
|
||||
*
|
||||
|
||||
@@ -288,29 +288,6 @@ static status_t verify(private_transform_substructure_t *this)
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements payload_t's and transform_substructure_t's destroy function.
|
||||
* See #payload_s.destroy or transform_substructure_s.destroy for description.
|
||||
*/
|
||||
static status_t destroy(private_transform_substructure_t *this)
|
||||
{
|
||||
/* all proposals are getting destroyed */
|
||||
while (this->attributes->get_count(this->attributes) > 0)
|
||||
{
|
||||
transform_attribute_t *current_attribute;
|
||||
if (this->attributes->remove_last(this->attributes,(void **)¤t_attribute) != SUCCESS)
|
||||
{
|
||||
break;
|
||||
}
|
||||
current_attribute->destroy(current_attribute);
|
||||
}
|
||||
this->attributes->destroy(this->attributes);
|
||||
|
||||
allocator_free(this);
|
||||
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements payload_t's get_encoding_rules function.
|
||||
* See #payload_s.get_encoding_rules for description.
|
||||
@@ -466,6 +443,88 @@ static status_t compute_length (private_transform_substructure_t *this)
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements transform_substructure_t's clone function.
|
||||
* See transform_substructure_s.clone for description.
|
||||
*/
|
||||
static status_t clone(private_transform_substructure_t *this,transform_substructure_t **clone)
|
||||
{
|
||||
private_transform_substructure_t *new_clone;
|
||||
linked_list_iterator_t *attributes;
|
||||
status_t status;
|
||||
|
||||
new_clone = (private_transform_substructure_t *) transform_substructure_create();
|
||||
|
||||
new_clone->next_payload = this->next_payload;
|
||||
new_clone->transform_type = this->transform_type;
|
||||
new_clone->transform_id = this->transform_id;
|
||||
|
||||
status = this->attributes->create_iterator(this->attributes,&attributes,FALSE);
|
||||
if (status != SUCCESS)
|
||||
{
|
||||
new_clone->public.destroy(&(new_clone->public));
|
||||
return status;
|
||||
}
|
||||
|
||||
while (attributes->has_next(attributes))
|
||||
{
|
||||
transform_attribute_t *current_attribute;
|
||||
transform_attribute_t *current_attribute_clone;
|
||||
status = attributes->current(attributes,(void **) ¤t_attribute);
|
||||
if (status != SUCCESS)
|
||||
{
|
||||
attributes->destroy(attributes);
|
||||
new_clone->public.destroy(&(new_clone->public));
|
||||
return status;
|
||||
}
|
||||
status = current_attribute->clone(current_attribute,¤t_attribute_clone);
|
||||
if (status != SUCCESS)
|
||||
{
|
||||
attributes->destroy(attributes);
|
||||
new_clone->public.destroy(&(new_clone->public));
|
||||
return status;
|
||||
}
|
||||
|
||||
status = new_clone->public.add_transform_attribute(&(new_clone->public),current_attribute_clone);
|
||||
if (status != SUCCESS)
|
||||
{
|
||||
attributes->destroy(attributes);
|
||||
current_attribute_clone->destroy(current_attribute_clone);
|
||||
new_clone->public.destroy(&(new_clone->public));
|
||||
return status;
|
||||
}
|
||||
}
|
||||
|
||||
attributes->destroy(attributes);
|
||||
|
||||
*clone = new_clone;
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Implements payload_t's and transform_substructure_t's destroy function.
|
||||
* See #payload_s.destroy or transform_substructure_s.destroy for description.
|
||||
*/
|
||||
static status_t destroy(private_transform_substructure_t *this)
|
||||
{
|
||||
/* all proposals are getting destroyed */
|
||||
while (this->attributes->get_count(this->attributes) > 0)
|
||||
{
|
||||
transform_attribute_t *current_attribute;
|
||||
if (this->attributes->remove_last(this->attributes,(void **)¤t_attribute) != SUCCESS)
|
||||
{
|
||||
break;
|
||||
}
|
||||
current_attribute->destroy(current_attribute);
|
||||
}
|
||||
this->attributes->destroy(this->attributes);
|
||||
|
||||
allocator_free(this);
|
||||
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
/*
|
||||
* Described in header
|
||||
*/
|
||||
@@ -495,6 +554,7 @@ transform_substructure_t *transform_substructure_create()
|
||||
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.clone = (status_t (*) (transform_substructure_t *,transform_substructure_t **)) clone;
|
||||
this->public.destroy = (status_t (*) (transform_substructure_t *)) destroy;
|
||||
|
||||
/* private functions */
|
||||
|
||||
@@ -263,6 +263,18 @@ struct transform_substructure_s {
|
||||
*/
|
||||
u_int16_t (*get_transform_id) (transform_substructure_t *this);
|
||||
|
||||
/**
|
||||
* @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
|
||||
* - OUT_OF_RES
|
||||
* - SUCCESS in any case
|
||||
*/
|
||||
status_t (*clone) (transform_substructure_t *this,transform_substructure_t **clone);
|
||||
|
||||
/**
|
||||
* @brief Destroys an transform_substructure_t object.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user