Move test-runners has_feature() function to plugin loader
authorMartin Willi <martin@revosec.ch>
Wed, 19 Jun 2013 12:52:52 +0000 (14:52 +0200)
committerMartin Willi <martin@revosec.ch>
Fri, 21 Jun 2013 08:53:22 +0000 (10:53 +0200)
src/libstrongswan/plugins/plugin_loader.c
src/libstrongswan/plugins/plugin_loader.h
src/libstrongswan/tests/test_runner.c

index 0549b37..cd5f93f 100644 (file)
@@ -387,6 +387,35 @@ METHOD(plugin_loader_t, create_plugin_enumerator, enumerator_t*,
                                                        (void*)plugin_filter, NULL, NULL);
 }
 
+METHOD(plugin_loader_t, has_feature, bool,
+       private_plugin_loader_t *this, plugin_feature_t feature)
+{
+       enumerator_t *plugins, *features;
+       plugin_t *plugin;
+       linked_list_t *list;
+       plugin_feature_t *current;
+       bool found = FALSE;
+
+       plugins = create_plugin_enumerator(this);
+       while (plugins->enumerate(plugins, &plugin, &list))
+       {
+               features = list->create_enumerator(list);
+               while (features->enumerate(features, &current))
+               {
+                       if (plugin_feature_matches(&feature, current))
+                       {
+                               found = TRUE;
+                               break;
+                       }
+               }
+               features->destroy(features);
+               list->destroy(list);
+       }
+       plugins->destroy(plugins);
+
+       return found;
+}
+
 /**
  * Create a list of the names of all loaded plugins
  */
@@ -1085,6 +1114,7 @@ plugin_loader_t *plugin_loader_create()
                        .reload = _reload,
                        .unload = _unload,
                        .create_plugin_enumerator = _create_plugin_enumerator,
+                       .has_feature = _has_feature,
                        .loaded_plugins = _loaded_plugins,
                        .destroy = _destroy,
                },
index 857bb2d..6bb9d6e 100644 (file)
@@ -93,6 +93,14 @@ struct plugin_loader_t {
        enumerator_t* (*create_plugin_enumerator)(plugin_loader_t *this);
 
        /**
+        * Check if the given feature is available and loaded.
+        *
+        * @param feature               feature to check
+        * @return                              TRUE if feature available
+        */
+       bool (*has_feature)(plugin_loader_t *this, struct plugin_feature_t feature);
+
+       /**
         * Get a simple list the names of all loaded plugins.
         *
         * The function returns internal data, do not free.
index 305ddeb..b5b784a 100644 (file)
 #include <library.h>
 #include <plugins/plugin_feature.h>
 
-/**
- * Check if the plugin configuration provides a specific feature
- */
-static bool has_feature(plugin_feature_t feature)
-{
-       enumerator_t *plugins, *features;
-       plugin_t *plugin;
-       linked_list_t *list;
-       plugin_feature_t *current;
-       bool found = FALSE;
-
-       plugins = lib->plugins->create_plugin_enumerator(lib->plugins);
-       while (plugins->enumerate(plugins, &plugin, &list))
-       {
-               features = list->create_enumerator(list);
-               while (features->enumerate(features, &current))
-               {
-                       if (plugin_feature_matches(&feature, current))
-                       {
-                               found = TRUE;
-                               break;
-                       }
-               }
-               features->destroy(features);
-               list->destroy(list);
-       }
-       plugins->destroy(plugins);
-
-       return found;
-}
-
 int main()
 {
        SRunner *sr;
@@ -83,7 +52,8 @@ int main()
        srunner_add_suite(sr, threading_suite_create());
        srunner_add_suite(sr, utils_suite_create());
        srunner_add_suite(sr, vectors_suite_create());
-       if (has_feature(PLUGIN_DEPENDS(PRIVKEY_GEN, KEY_ECDSA)))
+       if (lib->plugins->has_feature(lib->plugins,
+                                                                 PLUGIN_DEPENDS(PRIVKEY_GEN, KEY_ECDSA)))
        {
                srunner_add_suite(sr, ecdsa_suite_create());
        }