summaryrefslogtreecommitdiff
path: root/src/libstrongswan/utils/enum.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/libstrongswan/utils/enum.h')
-rw-r--r--src/libstrongswan/utils/enum.h25
1 files changed, 23 insertions, 2 deletions
diff --git a/src/libstrongswan/utils/enum.h b/src/libstrongswan/utils/enum.h
index a2f97d05e..3c03c2a7b 100644
--- a/src/libstrongswan/utils/enum.h
+++ b/src/libstrongswan/utils/enum.h
@@ -120,9 +120,30 @@ char *enum_to_name(enum_name_t *e, int val);
*
* @param e enum names for this enum value
* @param name name to get enum value for
- * @return enum value, -1 if not found
+ * @param valp variable sized pointer receiving value
+ * @return TRUE if enum name found, FALSE otherwise
*/
-int enum_from_name(enum_name_t *e, char *name);
+#define enum_from_name(e, name, valp) ({ \
+ int _val; \
+ int _found = enum_from_name_as_int(e, name, &_val); \
+ if (_found) \
+ { \
+ *(valp) = _val; \
+ } \
+ _found; })
+
+/**
+ * Convert a enum string back to its enum value, integer pointer variant.
+ *
+ * This variant takes integer pointer only, use enum_from_name() to pass
+ * enum type pointers for the result.
+ *
+ * @param e enum names for this enum value
+ * @param name name to get enum value for
+ * @param val integer pointer receiving value
+ * @return TRUE if enum name found, FALSE otherwise
+ */
+bool enum_from_name_as_int(enum_name_t *e, const char *name, int *val);
/**
* printf hook function for enum_names_t.