- skeleton implementation of ike_header
authorMartin Willi <martin@strongswan.org>
Mon, 14 Nov 2005 07:15:43 +0000 (07:15 -0000)
committerMartin Willi <martin@strongswan.org>
Mon, 14 Nov 2005 07:15:43 +0000 (07:15 -0000)
Source/charon/payloads/ike_header.c
Source/charon/payloads/ike_header.h
Source/charon/payloads/payload.c
Source/charon/payloads/payload.h
Source/charon/types.h

index ab4b984..2591a25 100644 (file)
 /* 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;
+}
+
+
index 8110e13..9aef952 100644 (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_*/
index dad260f..e244460 100644 (file)
 
 #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;
+       }
+}
+
index af98c4c..bfb8df8 100644 (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_*/
index 6abd44f..dace7d5 100644 (file)
@@ -25,6 +25,7 @@
 #define TYPES_H_
 
 #include <sys/types.h>
+#include <stdlib.h>
 
 typedef enum status_e {
        SUCCESS,