- skeleton implementation of ike_header

This commit is contained in:
Martin Willi 2005-11-14 07:15:43 +00:00
parent c0211a292b
commit cc0fbc3c24
5 changed files with 73 additions and 12 deletions

View file

@ -24,8 +24,10 @@
/* offsetof macro */
#include <stddef.h>
#include "encodings.h"
#include "ike_header.h"
#include "ike_header.h"
#include "encodings.h"
#include "../utils/allocator.h"
/**
* Encoding rules to parse or generate a IKEv2-Header
@ -65,3 +67,53 @@ encoding_rule_t ike_header_encodings[] = {
};
status_t destroy(payload_t *this)
{
allocator_free(this);
return SUCCESS;
}
status_t get_encoding_rules(payload_t *this, encoding_rule_t **rules, size_t *rule_count)
{
*rules = ike_header_encodings;
*rule_count = sizeof(ike_header_encodings) / sizeof(encoding_rule_t);
return SUCCESS;
}
payload_type_t get_type(payload_t *this)
{
return HEADER;
}
payload_type_t get_next_type(payload_t *this)
{
return (((ike_header_t*)this)->next_payload);
}
size_t get_length(payload_t *this)
{
return sizeof(ike_header_t);
}
ike_header_t *ike_header_create()
{
ike_header_t *this = allocator_alloc_thing(ike_header_t);
if (this == NULL)
{
return NULL;
}
this->payload_interface.get_encoding_rules = get_encoding_rules;
this->payload_interface.get_length = get_length;
this->payload_interface.get_next_type = get_next_type;
this->payload_interface.get_type = get_type;
this->payload_interface.destroy = destroy;
return this;
}

View file

@ -106,6 +106,6 @@ struct ike_header_s {
* - NULL if failed
*/
ike_header_t *create_ike_header();
ike_header_t *ike_header_create();
#endif /*IKE_HEADER_H_*/

View file

@ -24,13 +24,7 @@
#include "payload.h"
#include "ike_header.h"
@ -61,3 +55,17 @@ mapping_t payload_type_t_mappings[] = {
{MAPPING_END, NULL}
};
/*
* see header
*/
payload_t *create_payload(payload_type_t type)
{
switch (type)
{
case HEADER:
return (payload_t*)ike_header_create();
default:
return NULL;
}
}

View file

@ -177,7 +177,7 @@ struct payload_s {
* @param this calling object
* @return length of this payload
*/
payload_type_t (*get_length) (payload_t *this);
size_t (*get_length) (payload_t *this);
};
/**
@ -192,6 +192,6 @@ struct payload_s {
* - NULL if failed
*/
payload_t *create_empty_payload(payload_type_t type);
payload_t *create_payload(payload_type_t type);
#endif /*PAYLOAD_H_*/

View file

@ -25,6 +25,7 @@
#define TYPES_H_
#include <sys/types.h>
#include <stdlib.h>
typedef enum status_e {
SUCCESS,