The introduced SHA1_NOFINAL hasher was not sufficient for EAP-AKA,
[strongswan.git] / src / libstrongswan / enum.h
1 /*
2 * Copyright (C) 2006-2008 Martin Willi
3 * Hochschule fuer Technik Rapperswil
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the
7 * Free Software Foundation; either version 2 of the License, or (at your
8 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 * for more details.
14 *
15 * $Id$
16 */
17
18 /**
19 * @defgroup enum enum
20 * @{ @ingroup libstrongswan
21 */
22
23 #ifndef ENUM_H_
24 #define ENUM_H_
25
26 #include <printf_hook.h>
27
28 typedef struct enum_name_t enum_name_t;
29
30 /**
31 * Struct to store names for enums.
32 *
33 * To print the string representation of enumeration values, the strings
34 * are stored in these structures. Every enum_name contains a range
35 * of strings, multiple ranges are linked together.
36 * Use the convenience macros to define these linked ranges.
37 *
38 * For a single range, use:
39 * @code
40 ENUM(name, first, last, string1, string2, ...)
41 @endcode
42 * For multiple linked ranges, use:
43 * @code
44 ENUM_BEGIN(name, first, last, string1, string2, ...)
45 ENUM_NEXT(name, first, last, last_from_previous, string3, ...)
46 ENUM_NEXT(name, first, last, last_from_previous, string4, ...)
47 ENUM_END(name, last_from_previous)
48 @endcode
49 * The ENUM and the ENUM_END define a enum_name_t pointer with the name supplied
50 * in "name".
51 *
52 * Resolving of enum names is done using a printf hook. A printf fromat
53 * character %N is replaced by the enum string. Printf needs two arguments to
54 * resolve a %N, the enum_name_t* (the defined name in ENUM_BEGIN) followed
55 * by the numerical enum value.
56 */
57 struct enum_name_t {
58 /** value of the first enum string */
59 int first;
60 /** value of the last enum string */
61 int last;
62 /** next enum_name_t in list */
63 enum_name_t *next;
64 /** array of strings containing names from first to last */
65 char *names[];
66 };
67
68 /**
69 * Begin a new enum_name list.
70 *
71 * @param name name of the enum_name list
72 * @param first enum value of the first enum string
73 * @param last enum value of the last enum string
74 * @param ... a list of strings
75 */
76 #define ENUM_BEGIN(name, first, last, ...) static enum_name_t name##last = {first, last, NULL, { __VA_ARGS__ }}
77
78 /**
79 * Continue a enum name list startetd with ENUM_BEGIN.
80 *
81 * @param name name of the enum_name list
82 * @param first enum value of the first enum string
83 * @param last enum value of the last enum string
84 * @param prev enum value of the "last" defined in ENUM_BEGIN/previous ENUM_NEXT
85 * @param ... a list of strings
86 */
87 #define ENUM_NEXT(name, first, last, prev, ...) static enum_name_t name##last = {first, last, &name##prev, { __VA_ARGS__ }}
88
89 /**
90 * Complete enum name list started with ENUM_BEGIN.
91 *
92 * @param name name of the enum_name list
93 * @param prev enum value of the "last" defined in ENUM_BEGIN/previous ENUM_NEXT
94 */
95 #define ENUM_END(name, prev) enum_name_t *name = &name##prev;
96
97 /**
98 * Define a enum name with only one range.
99 *
100 * This is a convenience macro to use when a enum_name list contains only
101 * one range, and is equal as defining ENUM_BEGIN followed by ENUM_END.
102 *
103 * @param name name of the enum_name list
104 * @param first enum value of the first enum string
105 * @param last enum value of the last enum string
106 * @param ... a list of strings
107 */
108 #define ENUM(name, first, last, ...) ENUM_BEGIN(name, first, last, __VA_ARGS__); ENUM_END(name, last)
109
110 /**
111 * Get printf hook functions for enum_names_t.
112 *
113 * The handler takes the arguments: enum_names_t *names, int value
114 *
115 * @return printf hook functions
116 */
117 printf_hook_functions_t enum_get_printf_hooks();
118
119 #endif /* ENUM_H_ @}*/