- mapping for payload_type_t added
authorMartin Willi <martin@strongswan.org>
Fri, 11 Nov 2005 12:27:53 +0000 (12:27 -0000)
committerMartin Willi <martin@strongswan.org>
Fri, 11 Nov 2005 12:27:53 +0000 (12:27 -0000)
Source/charon/definitions.c [new file with mode: 0644]
Source/charon/definitions.h [new file with mode: 0644]
Source/charon/encodings.c
Source/charon/encodings.h

diff --git a/Source/charon/definitions.c b/Source/charon/definitions.c
new file mode 100644 (file)
index 0000000..a866cc5
--- /dev/null
@@ -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 (file)
index 0000000..7908990
--- /dev/null
@@ -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_*/
index 99b2722..7ac3bfd 100644 (file)
 
 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.
index 07762e1..356a73d 100644 (file)
@@ -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
  *