- wrote public functions to set and get important values of a message
This commit is contained in:
+76
-1
@@ -25,6 +25,7 @@
|
||||
#include "allocator.h"
|
||||
#include "types.h"
|
||||
#include "message.h"
|
||||
#include "ike_sa_id.h"
|
||||
#include "linked_list.h"
|
||||
#include "encodings.h"
|
||||
|
||||
@@ -76,6 +77,21 @@ struct private_message_s {
|
||||
*/
|
||||
bool is_request;
|
||||
|
||||
/**
|
||||
* First Payload type following the header
|
||||
*/
|
||||
payload_type_t first_payload_type;
|
||||
|
||||
/**
|
||||
* Message ID of this message
|
||||
*/
|
||||
u_int32_t message_id;
|
||||
|
||||
/**
|
||||
* ID of assigned IKE_SA
|
||||
*/
|
||||
ike_sa_id_t *ike_sa_id;
|
||||
|
||||
/**
|
||||
* Assigned UDP packet.
|
||||
*
|
||||
@@ -89,6 +105,55 @@ struct private_message_s {
|
||||
linked_list_t *payloads;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Implements message_t's set_ike_sa_id function.
|
||||
* See #message_s.set_ike_sa_id.
|
||||
*/
|
||||
static status_t set_ike_sa_id (private_message_t *this,ike_sa_id_t *ike_sa_id)
|
||||
{
|
||||
status_t status;
|
||||
status = ike_sa_id->clone(ike_sa_id,&(this->ike_sa_id));
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements message_t's get_ike_sa_id function.
|
||||
* See #message_s.get_ike_sa_id.
|
||||
*/
|
||||
static status_t get_ike_sa_id (private_message_t *this,ike_sa_id_t **ike_sa_id)
|
||||
{
|
||||
status_t status;
|
||||
if (this->ike_sa_id == NULL)
|
||||
{
|
||||
return FAILED;
|
||||
}
|
||||
status = this->ike_sa_id->clone(this->ike_sa_id,ike_sa_id);
|
||||
return status;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Implements message_t's set_message_id function.
|
||||
* See #message_s.set_message_id.
|
||||
*/
|
||||
static status_t set_message_id (private_message_t *this,u_int32_t message_id)
|
||||
{
|
||||
this->message_id = message_id;
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Implements message_t's set_message_id function.
|
||||
* See #message_s.set_message_id.
|
||||
*/
|
||||
static u_int32_t get_message_id (private_message_t *this)
|
||||
{
|
||||
return this->message_id;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Implements message_t's set_exchange_type function.
|
||||
* See #message_s.set_exchange_type.
|
||||
@@ -158,7 +223,6 @@ static status_t generate_packet (private_message_t *this, packet_t **packet)
|
||||
return EXCHANGE_TYPE_NOT_SET;
|
||||
}
|
||||
|
||||
|
||||
|
||||
return SUCCESS;
|
||||
}
|
||||
@@ -173,6 +237,10 @@ static status_t destroy (private_message_t *this)
|
||||
{
|
||||
this->packet->destroy(this->packet);
|
||||
}
|
||||
if (this->ike_sa_id != NULL)
|
||||
{
|
||||
this->ike_sa_id->destroy(this->ike_sa_id);
|
||||
}
|
||||
this->payloads->destroy(this->payloads);
|
||||
allocator_free(this);
|
||||
return SUCCESS;
|
||||
@@ -190,6 +258,10 @@ message_t *message_create_from_packet(packet_t *packet)
|
||||
}
|
||||
|
||||
/* public functions */
|
||||
this->public.set_message_id = (status_t(*)(message_t*, u_int32_t))set_message_id;
|
||||
this->public.get_message_id = (u_int32_t(*)(message_t*))get_message_id;
|
||||
this->public.set_ike_sa_id = (status_t(*)(message_t*, ike_sa_id_t *))set_ike_sa_id;
|
||||
this->public.get_ike_sa_id = (status_t(*)(message_t*, ike_sa_id_t **))get_ike_sa_id;
|
||||
this->public.set_exchange_type = (status_t(*)(message_t*, exchange_type_t))set_exchange_type;
|
||||
this->public.get_exchange_type = (exchange_type_t(*)(message_t*))get_exchange_type;
|
||||
this->public.set_original_initiator = (status_t(*)(message_t*, bool))set_original_initiator;
|
||||
@@ -203,6 +275,9 @@ message_t *message_create_from_packet(packet_t *packet)
|
||||
this->exchange_type = NOT_SET;
|
||||
this->original_initiator = TRUE;
|
||||
this->is_request = TRUE;
|
||||
this->first_payload_type = NO_PAYLOAD;
|
||||
this->ike_sa_id = NULL;
|
||||
this->message_id = 0;
|
||||
|
||||
/* private values */
|
||||
this->packet = packet;
|
||||
|
||||
@@ -25,7 +25,23 @@
|
||||
|
||||
#include "types.h"
|
||||
#include "packet.h"
|
||||
#include "ike_sa_id.h"
|
||||
|
||||
|
||||
/**
|
||||
* Major version of IKEv2-Protocol. Always 2
|
||||
*/
|
||||
#define IKE_V2_MAJOR_VERSION 2
|
||||
|
||||
/**
|
||||
* Minor version of IKEv2-Protocol. Always 0
|
||||
*/
|
||||
#define IKE_V2_MINOR_VERSION 0
|
||||
|
||||
/**
|
||||
* Flag in IKEv2-Header. Always 0
|
||||
*/
|
||||
#define HIGHER_VERSION_SUPPORTED_FLAG 0
|
||||
/**
|
||||
* @brief Different types of IKE-Exchanges.
|
||||
*
|
||||
@@ -67,6 +83,53 @@ typedef struct message_s message_t;
|
||||
|
||||
struct message_s {
|
||||
|
||||
/**
|
||||
* @brief Sets the Message ID of the message.
|
||||
*
|
||||
* @param this message_t object
|
||||
* @param message_id message_id to set
|
||||
* @return SUCCESS
|
||||
*/
|
||||
status_t (*set_message_id) (message_t *this,u_int32_t message_id);
|
||||
|
||||
/**
|
||||
* @brief Gets the Message ID of the message.
|
||||
*
|
||||
* @param this message_t object
|
||||
* @return message_id type of the message
|
||||
*/
|
||||
u_int32_t (*get_message_id) (message_t *this);
|
||||
|
||||
/**
|
||||
* @brief Sets the IKE_SA ID of the message.
|
||||
*
|
||||
* @warning ike_sa_id gets cloned internaly and
|
||||
* so can be destroyed afterwards.
|
||||
*
|
||||
* @param this message_t object
|
||||
* @param ike_sa_id ike_sa_id to set
|
||||
* @return
|
||||
* - SUCCESS
|
||||
* - OUT_OF_RES
|
||||
* @return SUCCESS
|
||||
*/
|
||||
status_t (*set_ike_sa_id) (message_t *this,ike_sa_id_t * ike_sa_id);
|
||||
|
||||
/**
|
||||
* @brief Gets the IKE_SA ID of the message.
|
||||
*
|
||||
* @warning The returned ike_sa_id is a clone of the internal one.
|
||||
* So it has to be destroyed by the caller.
|
||||
*
|
||||
* @param this message_t object
|
||||
* @param ike_sa_id pointer to ike_sa_id pointer which will be set
|
||||
* @return
|
||||
* - SUCCESS
|
||||
* - OUT_OF_RES
|
||||
* - FAILED if no ike_sa_id is set
|
||||
*/
|
||||
status_t (*get_ike_sa_id) (message_t *this,ike_sa_id_t **ike_sa_id);
|
||||
|
||||
/**
|
||||
* @brief Sets the exchange type of the message.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user