aboutsummaryrefslogtreecommitdiffstats
path: root/Source
diff options
context:
space:
mode:
Diffstat (limited to 'Source')
-rw-r--r--Source/charon/payloads/ike_header.c56
-rw-r--r--Source/charon/payloads/ike_header.h2
-rw-r--r--Source/charon/payloads/payload.c22
-rw-r--r--Source/charon/payloads/payload.h4
-rw-r--r--Source/charon/types.h1
5 files changed, 73 insertions, 12 deletions
diff --git a/Source/charon/payloads/ike_header.c b/Source/charon/payloads/ike_header.c
index ab4b98439..2591a25ca 100644
--- a/Source/charon/payloads/ike_header.c
+++ b/Source/charon/payloads/ike_header.c
@@ -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;
+}
+
+
diff --git a/Source/charon/payloads/ike_header.h b/Source/charon/payloads/ike_header.h
index 8110e1331..9aef9529a 100644
--- a/Source/charon/payloads/ike_header.h
+++ b/Source/charon/payloads/ike_header.h
@@ -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_*/
diff --git a/Source/charon/payloads/payload.c b/Source/charon/payloads/payload.c
index dad260f76..e24446026 100644
--- a/Source/charon/payloads/payload.c
+++ b/Source/charon/payloads/payload.c
@@ -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;
+ }
+}
+
diff --git a/Source/charon/payloads/payload.h b/Source/charon/payloads/payload.h
index af98c4cbc..bfb8df81e 100644
--- a/Source/charon/payloads/payload.h
+++ b/Source/charon/payloads/payload.h
@@ -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_*/
diff --git a/Source/charon/types.h b/Source/charon/types.h
index 6abd44f4f..dace7d542 100644
--- a/Source/charon/types.h
+++ b/Source/charon/types.h
@@ -25,6 +25,7 @@
#define TYPES_H_
#include <sys/types.h>
+#include <stdlib.h>
typedef enum status_e {
SUCCESS,