- started to implement message

This commit is contained in:
Jan Hutter
2005-11-10 15:38:38 +00:00
parent 3818e5c858
commit c64d7032fe
2 changed files with 62 additions and 14 deletions
+36 -6
View File
@@ -1,7 +1,7 @@
/** /**
* @file message.c * @file message.c
* *
* @brief Class message_t. Object of this type represents an IKEv2-Message * @brief Class message_t. Object of this type represents an IKEv2-Message.
* *
*/ */
@@ -25,6 +25,7 @@
#include "allocator.h" #include "allocator.h"
#include "types.h" #include "types.h"
#include "message.h" #include "message.h"
#include "linked_list.h"
/** /**
* Private data of an message_t object * Private data of an message_t object
@@ -41,17 +42,30 @@ struct private_message_s {
/* Private values */ /* Private values */
/**
* Assigned UDP packet.
*
* Stores incoming packet or last generated one.
*/
packet_t *packet;
/**
* Linked List where payload data are stored in
*/
linked_list_t *payloads;
}; };
/** /**
* @brief implements function destroy of message_t * Implements message_t's destroy function.
* See #message_s.destroy.
*/ */
static status_t destroy (private_message_t *this) static status_t destroy (private_message_t *this)
{ {
if (this == NULL) if (this->packet != NULL)
{ {
return FAILED; this->packet->destroy(this->packet);
} }
this->payloads->destroy(this->payloads);
allocator_free(this); allocator_free(this);
return SUCCESS; return SUCCESS;
} }
@@ -59,7 +73,7 @@ static status_t destroy (private_message_t *this)
/* /*
* Described in Header-File * Described in Header-File
*/ */
message_t * message_create() message_t *message_create_from_packet(packet_t *packet)
{ {
private_message_t *this = allocator_alloc_thing(private_message_t); private_message_t *this = allocator_alloc_thing(private_message_t);
if (this == NULL) if (this == NULL)
@@ -67,9 +81,25 @@ message_t * message_create()
return NULL; return NULL;
} }
/* Public functions */ /* public functions */
this->public.destroy = (status_t(*)(message_t*))destroy; this->public.destroy = (status_t(*)(message_t*))destroy;
/* private values */
this->packet = packet;
this->payloads = linked_list_create();
if (this->payloads == NULL)
{
allocator_free(this);
return NULL;
}
return (&this->public); return (&this->public);
} }
/*
* Described in Header-File
*/
message_t *message_create()
{
return message_create_from_packet(NULL);
}
+25 -7
View File
@@ -1,7 +1,7 @@
/** /**
* @file message.h * @file message.h
* *
* @brief Class message_t. Object of this type represents an IKEv2-Message * @brief Class message_t. Object of this type represents an IKEv2-Message.
* *
*/ */
@@ -24,6 +24,7 @@
#define MESSAGE_H_ #define MESSAGE_H_
#include "types.h" #include "types.h"
#include "packet.h"
/** /**
* @brief This class is used to represent an IKEv2-Message. * @brief This class is used to represent an IKEv2-Message.
@@ -35,20 +36,37 @@ typedef struct message_s message_t;
struct message_s { struct message_s {
/** /**
* @brief Destroys a message object * @brief Destroys a message and all including objects
* *
* @param this message_t object * @param this message_t object
* @return SUCCESSFUL if succeeded, FAILED otherwise * @return
* - SUCCESSFUL if succeeded
*/ */
status_t (*destroy) (message_t *this); status_t (*destroy) (message_t *this);
}; };
/** /**
* Creates an message_t object * Creates an message_t object from a incoming UDP Packet.
* *
* @return created message_t object * @warning the given packet_t object is not copied and gets
* destroyed in message_t's destroy call.
*
* @param packet packet_t object which is assigned to message
*
* @return
* - created message_t object
* - NULL if out of ressources
*/
message_t * message_create_from_packet(packet_t *packet);
/**
* Creates an empty message_t object.
*
* @return
* - created message_t object
* - NULL if out of ressources
*/ */
message_t * message_create(); message_t * message_create();
#endif /*MESSAGE_H_*/ #endif /*MESSAGE_H_*/