Add a plugin feature registration callback for SIM/AKA backends
authorMartin Willi <martin@revosec.ch>
Thu, 13 Oct 2011 11:03:10 +0000 (13:03 +0200)
committerMartin Willi <martin@revosec.ch>
Fri, 14 Oct 2011 08:05:48 +0000 (10:05 +0200)
src/libsimaka/simaka_manager.c
src/libsimaka/simaka_manager.h

index 71daf6c..c314b79 100644 (file)
@@ -531,3 +531,88 @@ simaka_manager_t *simaka_manager_create()
 
        return &this->public;
 }
+
+/**
+ * (Un-)register a provider to a simaka manager
+ */
+static bool register_card(char *mgr_name, bool reg, simaka_card_t *card)
+{
+       simaka_manager_t *mgr;
+
+       if (!card)
+       {
+               return FALSE;
+       }
+       mgr = lib->get(lib, mgr_name);
+       if (mgr)
+       {
+               if (reg)
+               {
+                       mgr->add_card(mgr, card);
+               }
+               else
+               {
+                       mgr->remove_card(mgr, card);
+               }
+               return TRUE;
+       }
+       return FALSE;
+}
+
+/**
+ * (Un-)register a provider to a simaka manager
+ */
+static bool register_provider(char *mgr_name, bool reg,
+                                                         simaka_provider_t *provider)
+{
+       simaka_manager_t *mgr;
+
+       if (!provider)
+       {
+               return FALSE;
+       }
+       mgr = lib->get(lib, mgr_name);
+       if (mgr)
+       {
+               if (reg)
+               {
+                       mgr->add_provider(mgr, provider);
+               }
+               else
+               {
+                       mgr->remove_provider(mgr, provider);
+               }
+               return TRUE;
+       }
+       return FALSE;
+}
+
+/**
+ * See header
+ */
+bool simaka_manager_register(plugin_t *plugin, plugin_feature_t *feature,
+                                                        bool reg, void *data)
+{
+       simaka_manager_register_cb_t get = (simaka_manager_register_cb_t)data;
+
+       if (feature->type == FEATURE_CUSTOM)
+       {
+               if (streq(feature->arg.custom, "aka-card"))
+               {
+                       return register_card("aka-manager", reg, get(plugin));
+               }
+               else if (streq(feature->arg.custom, "aka-provider"))
+               {
+                       return register_provider("aka-manager", reg, get(plugin));
+               }
+               else if (streq(feature->arg.custom, "sim-card"))
+               {
+                       return register_card("sim-manager", reg, get(plugin));
+               }
+               else if (streq(feature->arg.custom, "sim-provider"))
+               {
+                       return register_provider("sim-manager", reg, get(plugin));
+               }
+       }
+       return FALSE;
+}
index 403d10a..da8b78b 100644 (file)
@@ -24,6 +24,7 @@
 #include <crypto/hashers/hasher.h>
 #include <utils/identification.h>
 #include <utils/enumerator.h>
+#include <plugins/plugin.h>
 
 typedef struct simaka_manager_t simaka_manager_t;
 
@@ -284,4 +285,26 @@ struct simaka_manager_t {
  */
 simaka_manager_t *simaka_manager_create();
 
+/**
+ * Callback for the simaka_manager_register_cb_t, provides backend to register.
+ *
+ * @param plugin               plugin registering a backend (card or provider)
+ * @return                             a simaka_card_t* or simaka_provider_t*, NULL on failure
+ */
+typedef void* (*simaka_manager_register_cb_t)(plugin_t *plugin);
+
+/**
+ * Helper function to (un-)register SIM/AKA backend plugin features.
+ *
+ * This function is a plugin_feature_callback_t and can be used with the
+ * PLUGIN_CALLBACK macro to register a SIM/AKA backend.
+ *
+ * @param plugin               plugin registering the SIM/AKA backend
+ * @param feature              associated plugin feature
+ * @param reg                  TRUE to register, FALSE to unregister.
+ * @param data                 data passed to callback, an simaka_manager_register_cb_t
+ */
+bool simaka_manager_register(plugin_t *plugin, plugin_feature_t *feature,
+                                                        bool reg, void *data);
+
 #endif /** SIMAKA_MANAGER_H_ @}*/