aboutsummaryrefslogtreecommitdiffstats
path: root/Source
diff options
context:
space:
mode:
Diffstat (limited to 'Source')
-rw-r--r--Source/charon/definitions.c40
-rw-r--r--Source/charon/definitions.h56
-rw-r--r--Source/charon/encodings.c26
-rw-r--r--Source/charon/encodings.h7
4 files changed, 129 insertions, 0 deletions
diff --git a/Source/charon/definitions.c b/Source/charon/definitions.c
new file mode 100644
index 000000000..a866cc525
--- /dev/null
+++ b/Source/charon/definitions.c
@@ -0,0 +1,40 @@
+/**
+ * @file definitions.c
+ *
+ * @brief general purpose functions used in definitions.h
+ *
+ */
+
+/*
+ * Copyright (C) 2005 Jan Hutter, Martin Willi
+ * Hochschule fuer Technik Rapperswil
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2 of the License, or (at your
+ * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * for more details.
+ */
+
+#include "definitions.h"
+
+/*
+ * see header
+ */
+char *mapping_find(mapping_t * maps, int value)
+{
+ int i = 0;
+ while (maps[i].value > MAPPING_END)
+ {
+ i++;
+ if (maps[i].value == value)
+ {
+ return maps[i].string;
+ }
+ }
+ return "INVALID MAPPING";
+}
diff --git a/Source/charon/definitions.h b/Source/charon/definitions.h
new file mode 100644
index 000000000..790899015
--- /dev/null
+++ b/Source/charon/definitions.h
@@ -0,0 +1,56 @@
+/**
+ * @file definitions.h
+ *
+ * @brief general purpose definitions and macros
+ *
+ */
+
+/*
+ * Copyright (C) 2005 Jan Hutter, Martin Willi
+ * Hochschule fuer Technik Rapperswil
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2 of the License, or (at your
+ * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * for more details.
+ */
+
+#ifndef DEFINITIONS_H_
+#define DEFINITIONS_H_
+
+
+#define MAPPING_END -1
+
+/**
+ * @brief mapping entry, where enum-to-string mappings are stored
+ */
+typedef struct mapping_s mapping_t;
+struct mapping_s
+{
+ /**
+ * enumeration value
+ */
+ int value;
+ /**
+ * mapped string
+ */
+ char *string;
+};
+
+
+/**
+ * @brief find a mapping_string in the mapping[]
+ *
+ * @param mappings mappings array
+ * @param value enum-value to get the string from
+ *
+ */
+char *mapping_find(mapping_t *mappings, int value);
+
+
+#endif /*DEFINITIONS_H_*/
diff --git a/Source/charon/encodings.c b/Source/charon/encodings.c
index 99b272211..7ac3bfd5b 100644
--- a/Source/charon/encodings.c
+++ b/Source/charon/encodings.c
@@ -34,6 +34,32 @@
extern payload_info_t ike_header_info;
+/*
+ * build the mappings for payload_type_t
+ */
+mapping_t payload_type_t_mappings[] = {
+ {NO_PAYLOAD, "NO_PAYLOAD"},
+ {SECURITY_ASSOCIATION, "SECURITY_ASSOCIATION"},
+ {KEY_EXCHANGE, "KEY_EXCHANGE"},
+ {ID_INITIATOR, "ID_INITIATOR"},
+ {ID_RESPONDER, "ID_RESPONDER"},
+ {CERTIFICATE, "CERTIFICATE"},
+ {CERTIFICATE_REQUEST, "CERTIFICATE_REQUEST"},
+ {AUTHENTICATION, "AUTHENTICATION"},
+ {NONCE, "NONCE"},
+ {NOTIFY, "NOTIFY"},
+ {DELETE, "DELETE"},
+ {VENDOR_ID, "VENDOR_ID"},
+ {TRAFFIC_SELECTOR_INITIATOR, "TRAFFIC_SELECTOR_INITIATOR"},
+ {TRAFFIC_SELECTOR_RESPONDER, "TRAFFIC_SELECTOR_RESPONDER"},
+ {ENCRYPTED, "ENCRYPTED"},
+ {CONFIGURATION, "CONFIGURATION"},
+ {EXTENSIBLE_AUTHENTICATION, "EXTENSIBLE_AUTHENTICATION"},
+ {HEADER, "HEADER"},
+ {MAPPING_END, NULL}
+};
+
+
/**
* List containing all payload informations
* supported by parser and generator.
diff --git a/Source/charon/encodings.h b/Source/charon/encodings.h
index 07762e1ad..356a73d5f 100644
--- a/Source/charon/encodings.h
+++ b/Source/charon/encodings.h
@@ -30,6 +30,7 @@
#define ENCODINGS_H_
#include "types.h"
+#include "definitions.h"
/**
@@ -289,6 +290,12 @@ enum payload_type_e{
HEADER = 140
};
+
+/*
+ * build string mapping array for payload_type_t
+ */
+extern mapping_t payload_type_t_mappings[];
+
/**
* Information of a specific payload are stored in this struct
*