]> git.ipfire.org Git - thirdparty/strongswan.git/commitdiff
Remove eap_vendor_type_from_string(), and make vendor_type_t private
authorMartin Willi <martin@revosec.ch>
Fri, 31 Aug 2012 12:06:21 +0000 (14:06 +0200)
committerMartin Willi <martin@revosec.ch>
Mon, 3 Sep 2012 08:25:15 +0000 (10:25 +0200)
We will add vendor support to eap_type_from_string() directly in
a follow up commit.

src/libcharon/plugins/eap_dynamic/eap_dynamic.c
src/libcharon/plugins/stroke/stroke_config.c
src/libstrongswan/eap/eap.c
src/libstrongswan/eap/eap.h

index d24cbd12814fa1960fe175d7afdec4ce5c97d112..79177088afbadbc94452bcc91718e3bba9e023de 100644 (file)
@@ -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,
index e3c78f75032ab0f23d5c9531cca0753bb76e84af..4d54f644b83a5a78603d7f200f778ac5d886460a 100644 (file)
@@ -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)
index 1e4cf11bff44696342a9d360a197469db63d1308..2ae3393a4fa5b82f155d6c2cd5cddcf22d949570 100644 (file)
@@ -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;
-}
index 0e144b1236f54e5157f3b2c51181a4e53d9811a0..73f6d7f27556302a7d39b39328d52615f64cb52f 100644 (file)
@@ -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 <library.h>
 
@@ -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_ @}*/