- introduced set_next_type call for payload_t objects

This commit is contained in:
Jan Hutter 2005-11-15 09:14:45 +00:00
parent 2b9dd4678d
commit 32cbc7bc82
9 changed files with 109 additions and 28 deletions

View file

@ -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;

View file

@ -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
*

View file

@ -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

View file

@ -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;

View file

@ -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 **) &current_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;

View file

@ -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

View file

@ -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;

View file

@ -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;

View file

@ -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