Added a generic callback to register EAP methods using plugin features
authorMartin Willi <martin@revosec.ch>
Tue, 13 Sep 2011 13:55:59 +0000 (15:55 +0200)
committerMartin Willi <martin@revosec.ch>
Fri, 14 Oct 2011 08:05:44 +0000 (10:05 +0200)
src/libcharon/sa/authenticators/eap/eap_method.c
src/libcharon/sa/authenticators/eap/eap_method.h

index 0fa4a00..536dab7 100644 (file)
 
 #include "eap_method.h"
 
+#include <daemon.h>
+
 ENUM(eap_role_names, EAP_SERVER, EAP_PEER,
        "EAP_SERVER",
        "EAP_PEER",
 );
 
+/**
+ * See header
+ */
+bool eap_method_register(plugin_t *plugin, plugin_feature_t *feature,
+                                                bool reg, void *data)
+{
+       if (reg)
+       {
+               charon->eap->add_method(charon->eap, feature->eap, 0,
+                                       feature->type == FEATURE_EAP_SERVER ? EAP_SERVER : EAP_PEER,
+                                       (eap_constructor_t)data);
+       }
+       else
+       {
+               charon->eap->remove_method(charon->eap, (eap_constructor_t)data);
+       }
+       return TRUE;
+}
index 0eab2b5..6242a5a 100644 (file)
@@ -25,6 +25,7 @@ typedef struct eap_method_t eap_method_t;
 typedef enum eap_role_t eap_role_t;
 
 #include <library.h>
+#include <plugins/plugin.h>
 #include <utils/identification.h>
 #include <eap/eap.h>
 #include <encoding/payloads/eap_payload.h>
@@ -159,4 +160,18 @@ struct eap_method_t {
 typedef eap_method_t *(*eap_constructor_t)(identification_t *server,
                                                                                   identification_t *peer);
 
+/**
+ * Helper function to (un-)register EAP methods from plugin features.
+ *
+ * This function is a plugin_feature_callback_t and can be used with the
+ * PLUGIN_CALLBACK macro to register a EAP method constructor.
+ *
+ * @param plugin               plugin registering the EAP method constructor
+ * @param feature              associated plugin feature
+ * @param reg                  TRUE to register, FALSE to unregister.
+ * @param data                 data passed to callback, an eap_constructor_t
+ */
+bool eap_method_register(plugin_t *plugin, plugin_feature_t *feature,
+                                                bool reg, void *data);
+
 #endif /** EAP_METHOD_H_ @}*/