From: Martin Willi Date: Fri, 31 Aug 2012 13:13:44 +0000 (+0200) Subject: Use a callback function to print unknown eap_type enum_names X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=720c9b3a805a3f4bda59e9100e68a5e4e47d1cd2;p=thirdparty%2Fstrongswan.git Use a callback function to print unknown eap_type enum_names --- diff --git a/src/libstrongswan/eap/eap.c b/src/libstrongswan/eap/eap.c index 712276c8bf..a566626329 100644 --- a/src/libstrongswan/eap/eap.c +++ b/src/libstrongswan/eap/eap.c @@ -21,6 +21,12 @@ #include +/** + * Forward declaration of enum name fallback callback. + */ +static int eap_type_names_cb(printf_hook_data_t *data, int vendor, + enum_name_t *e, int type); + ENUM(eap_code_names, EAP_REQUEST, EAP_FAILURE, "EAP_REQUEST", "EAP_RESPONSE", @@ -93,15 +99,31 @@ ENUM_NEXT(eap_type_short_names, EAP_EXPANDED, EAP_DYNAMIC, EAP_TNC, "DYN"); ENUM_END(eap_type_short_names, EAP_DYNAMIC); -ENUM(eap_vendor_names_unknown, 0, 0, - "(0)", +ENUM_CB(eap_vendor_names_unknown, eap_type_names_cb, 1, 0, ); -ENUM(eap_vendor_names_ms, EAP_MS_SOH, EAP_MS_CAPABILITES, +ENUM_CB(eap_vendor_names_ms, eap_type_names_cb, EAP_MS_SOH, EAP_MS_CAPABILITES, "MS-SOH", "MS-CAP", ); +/** + * Callback function if mapping EAP type to enum name failed + */ +static int eap_type_names_cb(printf_hook_data_t *data, int vendor, + enum_name_t *e, int type) +{ + if (e == eap_type_short_names) + { + return print_in_hook(data, "%d", type); + } + if (e == eap_vendor_names_ms) + { + return print_in_hook(data, "MS-%d", type); + } + return print_in_hook(data, "%d-%d", type, vendor); +} + /* * See header */