some message code cleanups
This commit is contained in:
@@ -710,6 +710,20 @@ static chunk_t get_packet_data (private_message_t *this)
|
|||||||
return chunk_clone(this->packet->get_data(this->packet));
|
return chunk_clone(this->packet->get_data(this->packet));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Implementation of message_t.is_encoded.
|
||||||
|
*/
|
||||||
|
static bool is_encoded(private_message_t *this)
|
||||||
|
{
|
||||||
|
chunk_t data = this->packet->get_data(this->packet);
|
||||||
|
|
||||||
|
if (data.ptr == NULL)
|
||||||
|
{
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Implementation of message_t.parse_header.
|
* Implementation of message_t.parse_header.
|
||||||
*/
|
*/
|
||||||
@@ -1232,6 +1246,7 @@ message_t *message_create_from_packet(packet_t *packet)
|
|||||||
this->public.parse_body = (status_t (*) (message_t *,crypter_t*,signer_t*)) parse_body;
|
this->public.parse_body = (status_t (*) (message_t *,crypter_t*,signer_t*)) parse_body;
|
||||||
this->public.get_packet = (packet_t * (*) (message_t*)) get_packet;
|
this->public.get_packet = (packet_t * (*) (message_t*)) get_packet;
|
||||||
this->public.get_packet_data = (chunk_t (*) (message_t *this)) get_packet_data;
|
this->public.get_packet_data = (chunk_t (*) (message_t *this)) get_packet_data;
|
||||||
|
this->public.is_encoded = (bool (*) (message_t *this)) is_encoded;
|
||||||
this->public.destroy = (void(*)(message_t*))destroy;
|
this->public.destroy = (void(*)(message_t*))destroy;
|
||||||
|
|
||||||
/* private values */
|
/* private values */
|
||||||
@@ -1272,24 +1287,3 @@ message_t *message_create()
|
|||||||
{
|
{
|
||||||
return message_create_from_packet(NULL);
|
return message_create_from_packet(NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* Described in Header.
|
|
||||||
*/
|
|
||||||
message_t *message_create_notify_reply(host_t *source, host_t *destination, exchange_type_t exchange_type, bool original_initiator,ike_sa_id_t *ike_sa_id,notify_message_type_t notify_type)
|
|
||||||
{
|
|
||||||
message_t *message = message_create_from_packet(NULL);
|
|
||||||
notify_payload_t *payload;
|
|
||||||
|
|
||||||
message->set_source(message, source->clone(source));
|
|
||||||
message->set_destination(message, destination->clone(destination));
|
|
||||||
message->set_exchange_type(message, exchange_type);
|
|
||||||
message->set_request(message, FALSE);
|
|
||||||
message->set_message_id(message,0);
|
|
||||||
message->set_ike_sa_id(message, ike_sa_id);
|
|
||||||
|
|
||||||
payload = notify_payload_create_from_protocol_and_type(PROTO_NONE, notify_type);
|
|
||||||
message->add_payload(message,(payload_t *) payload);
|
|
||||||
|
|
||||||
return message;
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -306,7 +306,7 @@ struct message_t {
|
|||||||
iterator_t * (*get_payload_iterator) (message_t *this);
|
iterator_t * (*get_payload_iterator) (message_t *this);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a clone of the internal stored packet_t object.
|
* @brief Returns a clone of the internal stored packet_t object.
|
||||||
*
|
*
|
||||||
* @param this message_t object
|
* @param this message_t object
|
||||||
* @return packet_t object as clone of internal one
|
* @return packet_t object as clone of internal one
|
||||||
@@ -314,13 +314,25 @@ struct message_t {
|
|||||||
packet_t * (*get_packet) (message_t *this);
|
packet_t * (*get_packet) (message_t *this);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a clone of the internal stored packet_t data.
|
* @brief Returns a clone of the internal stored packet_t data.
|
||||||
*
|
*
|
||||||
* @param this message_t object
|
* @param this message_t object
|
||||||
* @return clone of the internal stored packet_t data.
|
* @return clone of the internal stored packet_t data.
|
||||||
*/
|
*/
|
||||||
chunk_t (*get_packet_data) (message_t *this);
|
chunk_t (*get_packet_data) (message_t *this);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Check if a message is encoded.
|
||||||
|
*
|
||||||
|
* Check if the packet is in a generated (and encrypted) form available
|
||||||
|
* and can be passed down to the socket. If not, it has to be generated
|
||||||
|
* first.
|
||||||
|
*
|
||||||
|
* @param this message_t object
|
||||||
|
* @return TRUE if encoded, FALSE if not
|
||||||
|
*/
|
||||||
|
bool (*is_encoded) (message_t *this);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Destroys a message and all including objects.
|
* @brief Destroys a message and all including objects.
|
||||||
@@ -364,13 +376,4 @@ message_t * message_create_from_packet(packet_t *packet);
|
|||||||
*/
|
*/
|
||||||
message_t * message_create(void);
|
message_t * message_create(void);
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Creates an message_t object of type reply containing a notify payload.
|
|
||||||
*
|
|
||||||
* @return message_t object
|
|
||||||
*
|
|
||||||
* @ingroup encoding
|
|
||||||
*/
|
|
||||||
message_t *message_create_notify_reply(host_t *source, host_t *destination, exchange_type_t exchange_type, bool original_initiator,ike_sa_id_t *ike_sa_id,notify_message_type_t notify_type);
|
|
||||||
|
|
||||||
#endif /*MESSAGE_H_*/
|
#endif /*MESSAGE_H_*/
|
||||||
|
|||||||
@@ -89,15 +89,26 @@ static status_t execute(private_incoming_packet_job_t *this)
|
|||||||
message->get_minor_version(message));
|
message->get_minor_version(message));
|
||||||
if ((message->get_exchange_type(message) == IKE_SA_INIT) && (message->get_request(message)))
|
if ((message->get_exchange_type(message) == IKE_SA_INIT) && (message->get_request(message)))
|
||||||
{
|
{
|
||||||
|
notify_payload_t *notify;
|
||||||
message_t *response;
|
message_t *response;
|
||||||
|
host_t *src, *dst;
|
||||||
|
|
||||||
message->get_ike_sa_id(message, &ike_sa_id);
|
message->get_ike_sa_id(message, &ike_sa_id);
|
||||||
ike_sa_id->switch_initiator(ike_sa_id);
|
ike_sa_id->switch_initiator(ike_sa_id);
|
||||||
response = message_create_notify_reply(message->get_destination(message),
|
|
||||||
message->get_source(message),
|
response = message_create();
|
||||||
IKE_SA_INIT, FALSE, ike_sa_id,
|
src = message->get_source(message);
|
||||||
INVALID_MAJOR_VERSION);
|
dst = message->get_destination(message);
|
||||||
message->destroy(message);
|
response->set_source(response, src->clone(src));
|
||||||
ike_sa_id->destroy(ike_sa_id);
|
response->set_destination(response, dst->clone(dst));
|
||||||
|
response->set_exchange_type(response, IKE_SA_INIT);
|
||||||
|
response->set_request(response, FALSE);
|
||||||
|
response->set_message_id(response, 0);
|
||||||
|
response->set_ike_sa_id(response, ike_sa_id);
|
||||||
|
|
||||||
|
notify = notify_payload_create_from_protocol_and_type(PROTO_NONE, INVALID_MAJOR_VERSION);
|
||||||
|
response->add_payload(response, (payload_t *)notify);
|
||||||
|
|
||||||
status = response->generate(response, NULL, NULL, &packet);
|
status = response->generate(response, NULL, NULL, &packet);
|
||||||
if (status != SUCCESS)
|
if (status != SUCCESS)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user