From: Martin Willi Date: Fri, 31 Aug 2012 12:06:21 +0000 (+0200) Subject: Remove eap_vendor_type_from_string(), and make vendor_type_t private X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6adf1d78eed6915e3ddc05c4108b09d0d3a0d75e;p=thirdparty%2Fstrongswan.git Remove eap_vendor_type_from_string(), and make vendor_type_t private We will add vendor support to eap_type_from_string() directly in a follow up commit. --- diff --git a/src/libcharon/plugins/eap_dynamic/eap_dynamic.c b/src/libcharon/plugins/eap_dynamic/eap_dynamic.c index d24cbd1281..79177088af 100644 --- a/src/libcharon/plugins/eap_dynamic/eap_dynamic.c +++ b/src/libcharon/plugins/eap_dynamic/eap_dynamic.c @@ -41,7 +41,7 @@ struct private_eap_dynamic_t { identification_t *peer; /** - * Our supported EAP types (as eap_vendor_type_t*) + * Our supported EAP types (as entry_t*) */ linked_list_t *types; @@ -62,9 +62,19 @@ struct private_eap_dynamic_t { }; /** - * Compare two eap_vendor_type_t objects + * Struct that stores EAP type and vendor ID */ -static bool entry_matches(eap_vendor_type_t *item, eap_vendor_type_t *other) +typedef struct { + /** EAP type */ + eap_type_t type; + /** Vendor Id */ + u_int32_t vendor; +} entry_t; + +/** + * Compare two entry_t objects + */ +static bool entry_matches(entry_t *item, entry_t *other) { return item->type == other->type && item->vendor == other->vendor; } @@ -99,7 +109,7 @@ static eap_method_t *load_method(private_eap_dynamic_t *this, */ static void select_method(private_eap_dynamic_t *this) { - eap_vendor_type_t *entry; + entry_t *entry; linked_list_t *outer = this->types, *inner = this->other_types; char *who = "peer"; @@ -192,7 +202,7 @@ METHOD(eap_method_t, process, status_t, enumerator = in->get_types(in); while (enumerator->enumerate(enumerator, &type, &vendor)) { - eap_vendor_type_t *entry; + entry_t *entry; if (!type) { @@ -292,7 +302,8 @@ static void handle_preferred_eap_types(private_eap_dynamic_t *this, char *methods) { enumerator_t *enumerator; - eap_vendor_type_t *type, *entry; + eap_type_t type; + entry_t *entry, *pref_entry; linked_list_t *preferred; char *method; @@ -301,28 +312,31 @@ static void handle_preferred_eap_types(private_eap_dynamic_t *this, enumerator = enumerator_create_token(methods, ",", " "); while (enumerator->enumerate(enumerator, &method)) { - type = eap_vendor_type_from_string(method); + type = eap_type_from_string(method); if (type) { - preferred->insert_last(preferred, type); + INIT(entry, + .type = type, + ); + preferred->insert_last(preferred, entry); } } enumerator->destroy(enumerator); enumerator = this->types->create_enumerator(this->types); - while (preferred->remove_last(preferred, (void**)&type) == SUCCESS) + while (preferred->remove_last(preferred, (void**)&pref_entry) == SUCCESS) { /* move (supported) types to the front, maintain the preferred order */ this->types->reset_enumerator(this->types, enumerator); while (enumerator->enumerate(enumerator, &entry)) { - if (entry_matches(entry, type)) + if (entry_matches(entry, pref_entry)) { this->types->remove_at(this->types, enumerator); this->types->insert_first(this->types, entry); break; } } - free(type); + free(pref_entry); } enumerator->destroy(enumerator); preferred->destroy(preferred); @@ -340,7 +354,7 @@ static void get_supported_eap_types(private_eap_dynamic_t *this) enumerator = charon->eap->create_enumerator(charon->eap, EAP_SERVER); while (enumerator->enumerate(enumerator, &type, &vendor)) { - eap_vendor_type_t *entry; + entry_t *entry; INIT(entry, .type = type, diff --git a/src/libcharon/plugins/stroke/stroke_config.c b/src/libcharon/plugins/stroke/stroke_config.c index e3c78f7503..4d54f644b8 100644 --- a/src/libcharon/plugins/stroke/stroke_config.c +++ b/src/libcharon/plugins/stroke/stroke_config.c @@ -568,19 +568,19 @@ static auth_cfg_t *build_auth_cfg(private_stroke_config_t *this, } else if (strneq(auth, "eap", 3)) { - eap_vendor_type_t *type; + eap_type_t type; + u_int32_t vendor = 0; cfg->add(cfg, AUTH_RULE_AUTH_CLASS, AUTH_CLASS_EAP); - type = eap_vendor_type_from_string(auth); + type = eap_type_from_string(auth); if (type) { - cfg->add(cfg, AUTH_RULE_EAP_TYPE, type->type); - if (type->vendor) + cfg->add(cfg, AUTH_RULE_EAP_TYPE, type); + if (vendor) { - cfg->add(cfg, AUTH_RULE_EAP_VENDOR, type->vendor); + cfg->add(cfg, AUTH_RULE_EAP_VENDOR, vendor); } - free(type); } if (msg->add_conn.eap_identity) diff --git a/src/libstrongswan/eap/eap.c b/src/libstrongswan/eap/eap.c index 1e4cf11bff..2ae3393a4f 100644 --- a/src/libstrongswan/eap/eap.c +++ b/src/libstrongswan/eap/eap.c @@ -127,56 +127,3 @@ eap_type_t eap_type_from_string(char *name) } return 0; } - -/* - * See header - */ -eap_vendor_type_t *eap_vendor_type_from_string(char *str) -{ - enumerator_t *enumerator; - eap_vendor_type_t *result = NULL; - eap_type_t type = 0; - u_int32_t vendor = 0; - char *part, *end; - - /* parse EAP method string of the form: [eap-]type[-vendor] */ - enumerator = enumerator_create_token(str, "-", " "); - while (enumerator->enumerate(enumerator, &part)) - { - if (!type) - { - if (streq(part, "eap")) - { /* skip 'eap' at the beginning */ - continue; - } - type = eap_type_from_string(part); - if (!type) - { - type = strtoul(part, &end, 0); - if (*end != '\0' || errno) - { - DBG1(DBG_LIB, "unknown or invalid EAP method: %s", part); - break; - } - } - continue; - } - vendor = strtoul(part, &end, 0); - if (*end != '\0' || errno) - { - DBG1(DBG_LIB, "invalid EAP vendor: %s", part); - type = 0; - } - break; - } - enumerator->destroy(enumerator); - - if (type) - { - INIT(result, - .type = type, - .vendor = vendor, - ); - } - return result; -} diff --git a/src/libstrongswan/eap/eap.h b/src/libstrongswan/eap/eap.h index 0e144b1236..73f6d7f275 100644 --- a/src/libstrongswan/eap/eap.h +++ b/src/libstrongswan/eap/eap.h @@ -25,7 +25,6 @@ typedef enum eap_code_t eap_code_t; typedef enum eap_type_t eap_type_t; -typedef struct eap_vendor_type_t eap_vendor_type_t; #include @@ -85,22 +84,6 @@ extern enum_name_t *eap_type_names; */ extern enum_name_t *eap_type_short_names; -/** - * Struct that stores EAP type and vendor ID - */ -struct eap_vendor_type_t { - - /** - * EAP type - */ - eap_type_t type; - - /** - * Vendor Id - */ - u_int32_t vendor; -}; - /** * EAP packet format */ @@ -120,12 +103,4 @@ typedef struct __attribute__((packed)) { */ eap_type_t eap_type_from_string(char *name); -/** - * Parse a string of the form [eap-]type[-vendor]. - * - * @param str EAP method string - * @return parsed type (gets allocated), NULL if unknown or failed - */ -eap_vendor_type_t *eap_vendor_type_from_string(char *str); - #endif /** EAP_H_ @}*/